Scintilla User Guide (1) - Introduction

黄舟
Release: 2023-03-04 21:08:01
Original
2539 people have browsed it

Scintilla is an open source editing component that not only has the usual editing functions, but also provides syntax styles, code folding, tags, code auto-completion and prompts.
The Windows version of Scintilla is a standard Windows component. Users can send messages and interact with it through the SendMessage function. The SendMessage function interface is as follows:

LRESULT SendMessage(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
Copy after login


The GTK+ version of Scintilla uses a similar method to the Windows version to transmit messages. The following introduction will focus on the Windows version.
Scintilla provides a large number of message APIs, each message can have 0, 1 or 2 parameters. The message in the SendMessage function usually has two parameters: wParam and lParam. Therefore, for unused parameters, it is strongly recommended to set them to 0 to ensure compatibility with future versions. For most SCI_SETxxxxx setting messages, there will be a corresponding SCI_GETxxxxx query message.

Parameter type

The parameter type in the message is as shown in the following table:

Parameter type                                                                                                                               ’ s ’ s ’ s ’ s ‐ ‐ ‐ ‐ ‐ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ Parameter description

The parameter type in the message is as shown in the following table:


BOOL 0 means false, 1 represents True


# int 32 -bit with symbolic integer


常 常*Constitution string pointer, the string may end with 0, or pass another via another A parameter indicates the length


CHAR*character buffer pointer, Scintilla will use the querying character data to fill. In some cases, the buffer size is specified through another parameter; in other cases, you must ensure that the buffer is large enough to accommodate the character data being queried. If you pass in a null pointer 0, the message will return the queried character data size.


colour Color value in RGB format. Each color has a value of 0 - 255. Red, green, and blue are combined as follows to obtain the color value: color = red | (green << 8) | (blue << 16). 0x000000, black; 0xff0000, blue; 0x00ff00, green; 0x0000ff, red; 0xffffff, white.

Alpha Alpha channel value, which means the semi-transparentness of the color, the range of the value is: 0 (completely transparent, SC_ALPHA_TRANSParent)-255 (opaque, sc_alpha_opaque). A value of 256 (C_ALPHA_NOALPHA) means not to use the alpha channel. Not all platforms support alpha channels, and only some messages implement alpha effects. The default alpha value of the message is 256, and no alpha channel is used.

                                                                                                                                                                                                                                                                          # The following data structures are used:

CharacterRange

The character range data structure is the same as the WIN32 data structure CHARRANGE.

struct CharacterRange {

long cpMin;
long cpMax;
};
Copy after login

TextRange

Text range data structure, mainly used to obtain a specified range of text from the Scintilla component, the same as the WIN32 data structure TEXTRANGE.

struct TextRange {
struct CharacterRange chrg;
char *lpstrText;
};
Copy after login


TextToFind

Search text data structure, the same as WIN32 data structure FINDTEXTEX.

struct TextToFind {struct CharacterRange chrg; 
// 搜索范围char *lpstrText; // 搜索文本struct CharacterRange chrgText; // 匹配文本};
Copy after login

SCNotification

Event notification data structure. In Windows, Scintilla will send a WM_NOTIFY message to its parent window; in GTK+, Scintilla will send a notify signal to its parent window.

struct NotifyHeader { // 与WIN32数据结构NMHDR相同
void *hwndFrom; // 发送通知的窗口句柄
uptr_t idFrom; // 发送通知的控件ID
unsigned int code; // SCN_*通知事件代码
};
struct SCNotification {
struct NotifyHeader nmhdr;
// SCN_STYLENEEDED, SCN_DOUBLECLICK, SCN_MODIFIED, SCN_DWELLSTART,
// SCN_DWELLEND, SCN_CALLTIPCLICK, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK
int position;
int ch; // SCN_CHARADDED, SCN_KEY
// SCN_KEY, SCN_DOUBLECLICK, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK
int modifiers;
int modificationType; // SCN_MODIFIED
// SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION
const char *text;
int length; // SCN_MODIFIED
int linesAdded; // SCN_MODIFIED
int message; // SCN_MACRORECORD
uptr_t wParam; // SCN_MACRORECORD
sptr_t lParam; // SCN_MACRORECORD
int line; // SCN_MODIFIED, SCN_DOUBLECLICK
int foldLevelNow; // SCN_MODIFIED
int foldLevelPrev; // SCN_MODIFIED
int margin; // SCN_MARGINCLICK
int listType; // SCN_USERLISTSELECTION, SCN_AUTOCSELECTION
int x; // SCN_DWELLSTART, SCN_DWELLEND
int y; // SCN_DWELLSTART, SCN_DWELLEND
};
Copy after login


Integration with MFC

对于MFC应用程序向导创建的多文档程序,只需添加很少的代码,就可以将Scintilla控件嵌入到View中。假设工程名为EasyEdit,则相关的类分别为CEasyEditApp、CEasyEditDoc、CEasyEditView、CChildFrame。
首先,在CEasyEditApp中添加私有成员变量HMODULE m_hmodule和虚函数int ExitInstance(),并增加加载DLL代码和释放DLL代码:

BOOL CEasyEditApp::InitInstance()
{
m_hmodule = LoadLibrary(_T("SciLexer.dll"));
if (NULL == m_hmodule)
{
::MessageBox(NULL, _T("The Scintilla DLL could not be loaded."),
_T("Error loading Scintilla"), MB_OK | MB_ICONERROR);
}
…
return TRUE;
};
int CEasyEditApp::ExitInstance()
{
// TODO: 在此添加专用代码和/或调用基类
if (m_hmodule)
{
FreeLibrary(m_hmodule);
}
return CWinApp::ExitInstance();
}
Copy after login

然后,在CEasyEditView中,增加WM_PAINT消息处理函数void OnPaint(),并在BOOL PreCreateWindow(CREATESTRUCT& cs)和void OnPaint()函数中增加代码:

BOOL CEasyEditView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
cs.lpszClass = _T("Scintilla");
return CView::PreCreateWindow(cs);
}
void CEasyEditView::OnPaint()
{
// CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用CView::OnPaint()
Default();
}
Copy after login

这样,Scintilla控件就已经集成到View中了。
为了处理Scintilla控件发送的事件通知,在CChildFrame中,增加WM_NOTIFY消息处理函数BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult):

BOOL CChildFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
// TODO: 在此添加专用代码和/或调用基类
SCNotification *pSCNotification = (SCNotification*)lParam;
CEasyEditView *pView = (CEasyEditView*)GetActiveView();
switch (pSCNotification->nmhdr.code)
{
…
}
return CMDIChildWnd::OnNotify(wParam, lParam, pResult);
}
Copy after login

以上就是Scintilla,简介的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!