📄 scintillaeditview.cpp
字号:
//this file is part of notepad++
//Copyright (C)2003 Don HO ( donho@altern.org )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <windows.h>
#include <ShellAPI.h>
#include "ScintillaEditView.h"
#include "Parameters.h"
// initialize the static variable
HINSTANCE ScintillaEditView::_hLib = ::LoadLibrary("SciLexer.DLL");
int ScintillaEditView::_refCount = 0;
UserDefineDialog ScintillaEditView::_userDefineDlg;
const int ScintillaEditView::_SC_MARGE_LINENUMBER = 0;
const int ScintillaEditView::_SC_MARGE_SYBOLE = 1;
const int ScintillaEditView::_SC_MARGE_FOLDER = 2;
const int ScintillaEditView::_MARGE_LINENUMBER_NB_CHIFFRE = 5;
/*
SC_MARKNUM_* | Arrow Plus/minus Circle tree Box tree
-------------------------------------------------------------------------------------------------------------
FOLDEROPEN | SC_MARK_ARROWDOWN SC_MARK_MINUS SC_MARK_CIRCLEMINUS SC_MARK_BOXMINUS
FOLDER | SC_MARK_ARROW SC_MARK_PLUS SC_MARK_CIRCLEPLUS SC_MARK_BOXPLUS
FOLDERSUB | SC_MARK_EMPTY SC_MARK_EMPTY SC_MARK_VLINE SC_MARK_VLINE
FOLDERTAIL | SC_MARK_EMPTY SC_MARK_EMPTY SC_MARK_LCORNERCURVE SC_MARK_LCORNER
FOLDEREND | SC_MARK_EMPTY SC_MARK_EMPTY SC_MARK_CIRCLEPLUSCONNECTED SC_MARK_BOXPLUSCONNECTED
FOLDEROPENMID | SC_MARK_EMPTY SC_MARK_EMPTY SC_MARK_CIRCLEMINUSCONNECTED SC_MARK_BOXMINUSCONNECTED
FOLDERMIDTAIL | SC_MARK_EMPTY SC_MARK_EMPTY SC_MARK_TCORNERCURVE SC_MARK_TCORNER
*/
const int ScintillaEditView::_markersArray[][NB_FOLDER_STATE] = {
{SC_MARKNUM_FOLDEROPEN, SC_MARKNUM_FOLDER, SC_MARKNUM_FOLDERSUB, SC_MARKNUM_FOLDERTAIL, SC_MARKNUM_FOLDEREND, SC_MARKNUM_FOLDEROPENMID, SC_MARKNUM_FOLDERMIDTAIL},
{SC_MARK_MINUS, SC_MARK_PLUS, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY},
{SC_MARK_ARROWDOWN, SC_MARK_ARROW, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY},
{SC_MARK_CIRCLEMINUS, SC_MARK_CIRCLEPLUS, SC_MARK_VLINE, SC_MARK_LCORNERCURVE, SC_MARK_CIRCLEPLUSCONNECTED, SC_MARK_CIRCLEMINUSCONNECTED, SC_MARK_TCORNERCURVE},
{SC_MARK_BOXMINUS, SC_MARK_BOXPLUS, SC_MARK_VLINE, SC_MARK_LCORNER, SC_MARK_BOXPLUSCONNECTED, SC_MARK_BOXMINUSCONNECTED, SC_MARK_TCORNER}
};
//const int MASK_RED = 0xFF0000;
//const int MASK_GREEN = 0x00FF00;
//const int MASK_BLUE = 0x0000FF;
void ScintillaEditView::init(HINSTANCE hInst, HWND hPere)
{
if (!_hLib)
{
MessageBox( NULL, "can't not load the dynamic library", "SYS ERR : ", MB_OK | MB_ICONSTOP);
throw int(106901);
}
Window::init(hInst, hPere);
_hSelf = ::CreateWindowEx(
WS_EX_CLIENTEDGE,\
"Scintilla",\
"Notepad++",\
WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPCHILDREN,\
0, 0, 100, 100,\
_hParent,\
NULL,\
_hInst,\
NULL);
if (!_hSelf)
{
systemMessage("System Err");
throw int(106901);
}
_pScintillaFunc = (SCINTILLA_FUNC)::SendMessage(_hSelf, SCI_GETDIRECTFUNCTION, 0, 0);
_pScintillaPtr = (SCINTILLA_PTR)::SendMessage(_hSelf, SCI_GETDIRECTPOINTER, 0, 0);
_userDefineDlg.init(_hInst, _hParent, this);
if (!_pScintillaFunc || !_pScintillaPtr)
{
systemMessage("System Err");
throw int(106901);
}
execute(SCI_SETMARGINMASKN, _SC_MARGE_FOLDER, SC_MASK_FOLDERS);
//execute(SCI_SETMARGINWIDTHN, _SC_MARGE_FOLDER, 16);
showMargin(_SC_MARGE_FOLDER, true);
//execute(SCI_SETFOLDMARGINCOLOUR, true, red);
execute(SCI_SETFOLDMARGINHICOLOUR, false, red);
execute(SCI_SETMARGINSENSITIVEN, _SC_MARGE_FOLDER, true);
execute(SCI_SETMARGINSENSITIVEN, _SC_MARGE_SYBOLE, true);
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold"), reinterpret_cast<LPARAM>("1"));
//execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.compact"), reinterpret_cast<LPARAM>("1"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.html"), reinterpret_cast<LPARAM>("1"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.comment"), reinterpret_cast<LPARAM>("1"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.preprocessor"), reinterpret_cast<LPARAM>("1"));
execute(SCI_SETFOLDFLAGS, 16, 0);
for (int i = 0 ; i < NB_FOLDER_STATE ; i++)
defineMarker(_markersArray[FOLDER_TYPE][i], _markersArray[_folderStyle][i], white, black);
_codepage = ::GetACP();
_pParameter = NppParameters::getInstance();
};
void ScintillaEditView::setStyle(int styleID, COLORREF fgColour, COLORREF bgColour, const char *fontName, int fontStyle, int fontSize)
{
if (!((fgColour >> 24) & 0xFF))
execute(SCI_STYLESETFORE, styleID, fgColour);
if (!((bgColour >> 24) & 0xFF))
execute(SCI_STYLESETBACK, styleID, bgColour);
if ((!fontName)||(strcmp(fontName, "")))
execute(SCI_STYLESETFONT, (WPARAM)styleID, (LPARAM)fontName);
if ((fontStyle != -1) && (fontStyle != 0))
{
if (fontStyle & FONTSTYLE_BOLD)
execute(SCI_STYLESETBOLD, (WPARAM)styleID, (LPARAM)true);
if (fontStyle & FONTSTYLE_ITALIC)
execute(SCI_STYLESETITALIC, (WPARAM)styleID, (LPARAM)true);
}
if (fontSize > 0)
execute(SCI_STYLESETSIZE, styleID, fontSize);
}
void ScintillaEditView::setM30Lexer()
{/*
std::string commandM30, macroM30, commandLabel, macroLabel;
_pParameter->getWordList(commandM30, LANG_M30, LANG_INDEX_INSTR);
_pParameter->getWordList(macroM30, LANG_M30, LANG_INDEX_INSTR2);
_pParameter->getWordList(commandLabel, LANG_M30, LANG_INDEX_TYPE);
_pParameter->getWordList(macroLabel, LANG_M30, LANG_INDEX_TYPE2);
execute(SCI_SETLEXER, SCLEX_M30);
// 0 => SCE_M30_CMD
execute(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(commandM30.c_str()));
// 1 => SCE_M30_MACRO
execute(SCI_SETKEYWORDS, 1, reinterpret_cast<LPARAM>(macroM30.c_str()));
// 2 => SCE_M30_CMD_LABEL
execute(SCI_SETKEYWORDS, 2, reinterpret_cast<LPARAM>(commandLabel.c_str()));
// 3 => SCE_M30_MACRO_LABEL
execute(SCI_SETKEYWORDS, 3, reinterpret_cast<LPARAM>(macroLabel.c_str()));
setStyle(SCE_M30_CMD, blue);
setStyle(SCE_M30_MACRO, orange);
setStyle(SCE_M30_CMD_LABEL, red);
setStyle(SCE_M30_MACRO_LABEL, red);
setFont(SCE_M30_NUMBER, "Courier New");
setStyle(SCE_M30_NUMBER, cyan); //red by default
setStyle(SCE_M30_COMMENTLINE, darkGreen); // blue by default
*/}
void ScintillaEditView::setPcomLexer()
{/*
std::string pcomNativeCmd, pcomExtCmd, pcomDefaultBuf;
_pParameter->getWordList(pcomNativeCmd, LANG_PCOM, LANG_INDEX_INSTR);
_pParameter->getWordList(pcomExtCmd, LANG_PCOM, LANG_INDEX_INSTR2);
_pParameter->getWordList(pcomDefaultBuf, LANG_PCOM, LANG_INDEX_TYPE);
execute(SCI_SETLEXER, SCLEX_PCOM);
execute(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(pcomNativeCmd.c_str()));
execute(SCI_SETKEYWORDS, 1, reinterpret_cast<LPARAM>(pcomExtCmd.c_str()));
execute(SCI_SETKEYWORDS, 2, reinterpret_cast<LPARAM>(pcomDefaultBuf.c_str()));
execute(SCI_SETKEYWORDS, 3, reinterpret_cast<LPARAM>(""));
setStyle(STYLE_DEFAULT, black, white);
setFont(SCE_PCOM_NUMBER, "Courier New");
setStyle(SCE_PCOM_NUMBER, red); //red by default
setStyle(SCE_PCOM_COMMENTLINE, darkGreen); // blue by default
setFont(SCE_PCOM_NATIVE_CMD, NULL, true);
setStyle(SCE_PCOM_NATIVE_CMD, darkBlue);
setStyle(SCE_PCOM_EXT_CMD, blue);
setFont(SCE_PCOM_DEFAULT_BUF, NULL, true, true);
setStyle(SCE_PCOM_DEFAULT_BUF, purple);
setStyle(SCE_PCOM_MACRO, orange);
setStyle(SCE_PCOM_NCFORMAT_MACRO, grey);
*/}
void ScintillaEditView::setXmlLexer(LangType type)
{
execute(SCI_SETSTYLEBITS, 7, 0);
if (type == L_XML)
{
execute(SCI_SETLEXER, SCLEX_HTML);
for (int i = 0 ; i < 4 ; i++)
execute(SCI_SETKEYWORDS, i, reinterpret_cast<LPARAM>(""));
makeStyle("xml");
}
else if ((type == L_HTML) || (type == L_PHP) || (type == L_ASP))
{
execute(SCI_SETLEXER, SCLEX_XML);
const char *htmlKeyWords =_pParameter->getWordList(LANG_HTML, LANG_INDEX_INSTR);
execute(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(htmlKeyWords?htmlKeyWords:""));
makeStyle("html");
setEmbeddedJSLexer();
setPhpEmbeddedLexer();
setEmbeddedAspLexer();
}
}
void ScintillaEditView::setEmbeddedJSLexer()
{
const char *JSKeyWords = _pParameter->getWordList(LANG_JS, LANG_INDEX_INSTR);
execute(SCI_SETKEYWORDS, 1, reinterpret_cast<LPARAM>(JSKeyWords?JSKeyWords:""));
makeStyle("javascript");
execute(SCI_STYLESETEOLFILLED, SCE_HJ_DEFAULT, true);
execute(SCI_STYLESETEOLFILLED, SCE_HJ_COMMENT, true);
execute(SCI_STYLESETEOLFILLED, SCE_HJ_COMMENTDOC, true);
}
void ScintillaEditView::setPhpEmbeddedLexer()
{
const char *PHPKeyWords = _pParameter->getWordList(LANG_JS, LANG_INDEX_INSTR);
execute(SCI_SETKEYWORDS, 4, reinterpret_cast<LPARAM>(PHPKeyWords?PHPKeyWords:""));
makeStyle("php");
execute(SCI_STYLESETEOLFILLED, SCE_HPHP_DEFAULT, true);
execute(SCI_STYLESETEOLFILLED, SCE_HPHP_COMMENT, true);
}
void ScintillaEditView::setEmbeddedAspLexer()
{
const char *AspKeyWords = _pParameter->getWordList(LANG_VB, LANG_INDEX_INSTR);
execute(SCI_SETKEYWORDS, 2, reinterpret_cast<LPARAM>(AspKeyWords?AspKeyWords:""));
makeStyle("asp");
execute(SCI_STYLESETEOLFILLED, SCE_HBA_DEFAULT, true);
}
void ScintillaEditView::setUserLexer()
{
execute(SCI_SETLEXER, SCLEX_USER);
UserLangContainer & userLangContainer = *(_userDefineDlg._pCurrentUserLang);
for (int i = 0 ; i < userLangContainer.getNbKeywordList() ; i++)
{
execute(SCI_SETKEYWORDS, i, reinterpret_cast<LPARAM>(userLangContainer._keywordLists[i]));
}
for (int i = 0 ; i < userLangContainer._styleArray.getNbStyler() ; i++)
{
Style & style = userLangContainer._styleArray.getStyler(i);
setStyle(style._styleID, style._fgColor, style._bgColor, style._fontName, style._fontStyle, style._fontSize);
}
}
void ScintillaEditView::setUserLexer(const char *userLangName)
{
execute(SCI_SETLEXER, SCLEX_USER);
UserLangContainer & userLangContainer = NppParameters::getInstance()->getULCFromName(userLangName);
//getULCFromName(userLangName);
for (int i = 0 ; i < userLangContainer.getNbKeywordList() ; i++)
{
execute(SCI_SETKEYWORDS, i, reinterpret_cast<LPARAM>(userLangContainer._keywordLists[i]));
}
for (int i = 0 ; i < userLangContainer._styleArray.getNbStyler() ; i++)
{
Style & style = userLangContainer._styleArray.getStyler(i);
setStyle(style._styleID, style._fgColor, style._bgColor, style._fontName, style._fontStyle, style._fontSize);
}
}
void ScintillaEditView::setIniLexer()
{
execute(SCI_SETLEXER, SCLEX_PROPERTIES);
execute(SCI_STYLESETEOLFILLED, SCE_PROPS_SECTION, true);
makeStyle("ini");
}
void ScintillaEditView::setBatchLexer()
{
execute(SCI_SETLEXER, SCLEX_BATCH);
const char *batKeyWords = _pParameter->getWordList(LANG_BATCH, LANG_INDEX_INSTR);
execute(SCI_SETKEYWORDS, 0, (LPARAM)(batKeyWords?batKeyWords:""));
makeStyle("batch");
}
void ScintillaEditView::setSqlLexer()
{
execute(SCI_SETLEXER, SCLEX_SQL);
const char *SQLKeyWords = _pParameter->getWordList(LANG_SQL, LANG_INDEX_INSTR);
execute(SCI_SETKEYWORDS, 0, (LPARAM)(SQLKeyWords?SQLKeyWords:""));
makeStyle("sql");
}
void ScintillaEditView::setVBLexer()
{
execute(SCI_SETLEXER, SCLEX_VB);
const char *VBKeyWords = _pParameter->getWordList(LANG_VB, LANG_INDEX_INSTR);
execute(SCI_SETKEYWORDS, 0, (LPARAM)(VBKeyWords?VBKeyWords:""));
makeStyle("vb");
}
void ScintillaEditView::setPascalLexer()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -