2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns=
"http://www.w3.org/1999/xhtml">
6 <meta name=
"generator" content=
"HTML Tidy, see www.w3.org" />
7 <meta name=
"generator" content=
"SciTE" />
8 <meta http-equiv=
"Content-Type" content=
"text/html; charset=iso-8859-1" />
12 <style type=
"text/css">
14 font-family: Verdana, Arial, Helvetica;
19 font-family: Verdana, Arial, Helvetica;
22 font-family: Comic Sans MS, Times New Roman, Times;
27 font-family: Comic Sans MS, Times New Roman, Times;
32 font-family: Verdana, Arial, Helvetica;
36 font-family: Verdana, Arial, Helvetica;
42 font-family: Verdana, Arial, Helvetica;
46 font-family: Courier New, Courier;
50 font-family: Courier New, Courier;
63 <body bgcolor=
"#FFFFFF" text=
"#000000">
64 <table bgcolor=
"#000000" width=
"100%" cellspacing=
"0" cellpadding=
"0" border=
"0">
67 <img src=
"SciTEIco.png" border=
"3" height=
"64" width=
"64" alt=
"Scintilla icon" />
70 <a href=
"index.html" style=
"color:white;text-decoration:none"><font size=
"5">Scintilla
71 Usage Notes
</font></a>
76 Implementing Auto-Indent
79 The key idea is to use the SCN_CHARADDED notification to add indentation after a newline.
82 The lParam on the notification is a pointer to a SCNotification structure whose ch member
83 specifies the character added. If a newline was added, the previous line can be retrieved and
84 the same indentation can be added to the new line.
87 Here is the relevant portion of code from SciTE: (SciTE.cxx SciTEWindow::CharAdded)
89 <span class='S5'
>if
</span><span class='S0'
> </span> <span class='S10'
>(
</span><span
90 class='S11'
>ch
</span><span class='S0'
> </span> <span class='S10'
>==
</span><span
91 class='S0'
> </span> <span class='S7'
>'\r'
</span><span class='S0'
> </span> <span
92 class='S10'
>||
</span><span class='S0'
> </span> <span class='S11'
>ch
</span><span
93 class='S0'
> </span> <span class='S10'
>==
</span><span class='S0'
> </span> <span
94 class='S7'
>'\n'
</span><span class='S10'
>)
</span><span class='S0'
> </span> <span
95 class='S10'
>{
</span><span class='S0'
><br />
96 </span> <span class='S5'
>char
</span><span class='S0'
> </span>
97 <span class='S11'
>linebuf
</span><span class='S10'
>[
</span><span class='S4'
>1000</span><span
98 class='S10'
>];
</span><span class='S0'
><br />
99 </span> <span class='S5'
>int
</span><span class='S0'
> </span>
100 <span class='S11'
>curLine
</span><span class='S0'
> </span> <span class='S10'
>=
</span><span
101 class='S0'
> </span> <span class='S11'
>GetCurrentLineNumber
</span><span
102 class='S10'
>();
</span><span class='S0'
><br />
103 </span> <span class='S5'
>int
</span><span class='S0'
> </span>
104 <span class='S11'
>lineLength
</span><span class='S0'
> </span> <span class='S10'
>
105 =
</span><span class='S0'
> </span> <span class='S11'
>SendEditor
</span><span
106 class='S10'
>(
</span><span class='S11'
>SCI_LINELENGTH
</span><span class='S10'
>,
</span><span
107 class='S0'
> </span> <span class='S11'
>curLine
</span><span class='S10'
>);
</span><span
109 </span> <span class='S2'
>
110 //Platform::DebugPrintf(
"[CR] %d len = %d\n",
curLine,
lineLength);
</span><span
112 </span> <span class='S5'
>if
</span><span class='S0'
> </span> <span
113 class='S10'
>(
</span><span class='S11'
>curLine
</span><span class='S0'
> </span> <span
114 class='S10'
>></span><span class='S0'
> </span> <span class='S4'
>0</span><span
115 class='S0'
> </span> <span class='S10'
>&&</span><span class='S0'
> </span>
116 <span class='S11'
>lineLength
</span><span class='S0'
> </span> <span class='S10'
>
117 <=
</span><span class='S0'
> </span> <span class='S4'
>2</span><span
118 class='S10'
>)
</span><span class='S0'
> </span> <span class='S10'
>{
</span><span
120 </span> <span class='S5'
>int
</span><span class='S0'
> </span>
121 <span class='S11'
>prevLineLength
</span><span class='S0'
> </span> <span class='S10'
>
122 =
</span><span class='S0'
> </span> <span class='S11'
>SendEditor
</span><span
123 class='S10'
>(
</span><span class='S11'
>SCI_LINELENGTH
</span><span class='S10'
>,
</span><span
124 class='S0'
> </span> <span class='S11'
>curLine
</span><span class='S0'
> </span> <span
125 class='S10'
>-
</span><span class='S0'
> </span> <span class='S4'
>1</span><span
126 class='S10'
>);
</span><span class='S0'
><br />
127 </span> <span class='S5'
>if
</span><span class='S0'
> </span> <span
128 class='S10'
>(
</span><span class='S11'
>prevLineLength
</span><span class='S0'
> </span> <span
129 class='S10'
><</span><span class='S0'
> </span> <span class='S5'
>sizeof
</span><span
130 class='S10'
>(
</span><span class='S11'
>linebuf
</span><span class='S10'
>))
</span><span
131 class='S0'
> </span> <span class='S10'
>{
</span><span class='S0'
><br />
132 </span> <span class='S11'
>WORD
</span><span
133 class='S0'
> </span> <span class='S11'
>buflen
</span><span class='S0'
> </span> <span
134 class='S10'
>=
</span><span class='S0'
> </span> <span class='S5'
>sizeof
</span><span
135 class='S10'
>(
</span><span class='S11'
>linebuf
</span><span class='S10'
>);
</span><span
137 </span> <span class='S11'
>memcpy
</span><span
138 class='S10'
>(
</span><span class='S11'
>linebuf
</span><span class='S10'
>,
</span><span
139 class='S0'
> </span> <span class='S10'
>&</span><span class='S11'
>buflen
</span><span
140 class='S10'
>,
</span><span class='S0'
> </span> <span class='S5'
>sizeof
</span><span
141 class='S10'
>(
</span><span class='S11'
>buflen
</span><span class='S10'
>));
</span><span
143 </span> <span class='S11'
>
144 SendEditor
</span><span class='S10'
>(
</span><span class='S11'
>EM_GETLINE
</span><span
145 class='S10'
>,
</span><span class='S0'
> </span> <span class='S11'
>curLine
</span><span
146 class='S0'
> </span> <span class='S10'
>-
</span><span class='S0'
> </span> <span
147 class='S4'
>1</span><span class='S10'
>,
</span><span class='S0'
><br />
148 </span>
149 <span class='S5'
>reinterpret_cast
</span><span class='S10'
><</span><span
150 class='S11'
>LPARAM
</span><span class='S10'
>>(
</span><span class='S5'
>static_cast
</span><span
151 class='S10'
><</span><span class='S5'
>char
</span><span class='S0'
> </span> <span
152 class='S10'
>*
>(
</span><span class='S11'
>linebuf
</span><span class='S10'
>)));
</span><span
154 </span> <span class='S11'
>linebuf
</span><span
155 class='S10'
>[
</span><span class='S11'
>prevLineLength
</span><span class='S10'
>]
</span><span
156 class='S0'
> </span> <span class='S10'
>=
</span><span class='S0'
> </span> <span
157 class='S7'
>'\
0'
</span><span class='S10'
>;
</span><span class='S0'
><br />
158 </span> <span class='S5'
>for
</span><span
159 class='S0'
> </span> <span class='S10'
>(
</span><span class='S5'
>int
</span><span
160 class='S0'
> </span> <span class='S11'
>pos
</span><span class='S0'
> </span> <span
161 class='S10'
>=
</span><span class='S0'
> </span> <span class='S4'
>0</span><span
162 class='S10'
>;
</span><span class='S0'
> </span> <span class='S11'
>linebuf
</span><span
163 class='S10'
>[
</span><span class='S11'
>pos
</span><span class='S10'
>];
</span><span
164 class='S0'
> </span> <span class='S11'
>pos
</span><span class='S10'
>++)
</span><span
165 class='S0'
> </span> <span class='S10'
>{
</span><span class='S0'
><br />
166 </span> <span
167 class='S5'
>if
</span><span class='S0'
> </span> <span class='S10'
>(
</span><span
168 class='S11'
>linebuf
</span><span class='S10'
>[
</span><span class='S11'
>pos
</span><span
169 class='S10'
>]
</span><span class='S0'
> </span> <span class='S10'
>!=
</span><span
170 class='S0'
> </span> <span class='S7'
>'
'
</span><span class='S0'
> </span> <span
171 class='S10'
>&&</span><span class='S0'
> </span> <span class='S11'
>
172 linebuf
</span><span class='S10'
>[
</span><span class='S11'
>pos
</span><span
173 class='S10'
>]
</span><span class='S0'
> </span> <span class='S10'
>!=
</span><span
174 class='S0'
> </span> <span class='S7'
>'\t'
</span><span class='S10'
>)
</span><span
176 </span>
177 <span class='S11'
>linebuf
</span><span class='S10'
>[
</span><span class='S11'
>pos
</span><span
178 class='S10'
>]
</span><span class='S0'
> </span> <span class='S10'
>=
</span><span
179 class='S0'
> </span> <span class='S7'
>'\
0'
</span><span class='S10'
>;
</span><span
181 </span> <span class='S10'
>}
</span><span
183 </span> <span class='S11'
>
184 SendEditor
</span><span class='S10'
>(
</span><span class='S11'
>EM_REPLACESEL
</span><span
185 class='S10'
>,
</span><span class='S0'
> </span> <span class='S4'
>0</span><span
186 class='S10'
>,
</span><span class='S0'
> </span> <span class='S5'
>
187 reinterpret_cast
</span><span class='S10'
><</span><span class='S11'
>LPARAM
</span><span
188 class='S10'
>>(
</span><span class='S5'
>static_cast
</span><span class='S10'
><</span><span
189 class='S5'
>char
</span><span class='S0'
> </span> <span class='S10'
>*
>(
</span><span
190 class='S11'
>linebuf
</span><span class='S10'
>)));
</span><span class='S0'
><br />
191 </span> <span class='S10'
>}
</span><span class='S0'
><br />
192 </span> <span class='S10'
>}
</span><br />
194 <p style=
"margin-bottom: 0in">
195 Of course, fancier handling could be implemented. For example, if the previous line was the
196 start of a control construct, the next line could be automatically indented one tab further.
197 (Assuming that is your indenting style.)
200 Implementing Syntax Styling
203 Syntax styling is handled by the SCN_STYLENEEDED notification. Scintilla keeps track of the
204 end of the styled text - this is retrieved with SCI_GETENDSTYLED. In response to the
205 SCN_STYLENEEDED notification, you should apply styles to the text from ENDSTYLED to the
206 position specified by the notification.
209 Here is the relevant portion of code from SciTE: (SciTE.cxx)
211 <span class='S5'
>void
</span><span class='S0'
> </span> <span class='S11'
>
212 SciTEWindow
</span><span class='S10'
>::
</span><span class='S11'
>Notify
</span><span
213 class='S10'
>(
</span><span class='S11'
>SCNotification
</span><span class='S0'
> </span> <span
214 class='S10'
>*
</span><span class='S11'
>notification
</span><span class='S10'
>)
</span><span
215 class='S0'
> </span> <span class='S10'
>{
</span><span class='S0'
><br />
216 </span> <span class='S5'
>switch
</span><span class='S0'
> </span>
217 <span class='S10'
>(
</span><span class='S11'
>notification
</span><span
218 class='S10'
>-
></span><span class='S11'
>nmhdr.code
</span><span class='S10'
>)
</span><span
219 class='S0'
> </span> <span class='S10'
>{
</span><span class='S0'
><br />
220 </span> <span class='S5'
>case
</span><span class='S0'
> </span>
221 <span class='S11'
>SCN_STYLENEEDED
</span><span class='S10'
>:
</span><span
222 class='S0'
> </span> <span class='S10'
>{
</span><span class='S0'
><br />
223 </span> <span
224 class='S5'
>if
</span><span class='S0'
> </span> <span class='S10'
>(
</span><span
225 class='S11'
>notification
</span><span class='S10'
>-
></span><span
226 class='S11'
>nmhdr.idFrom
</span><span class='S0'
> </span> <span class='S10'
>==
</span><span
227 class='S0'
> </span> <span class='S11'
>IDM_SRCWIN
</span><span class='S10'
>)
</span><span
228 class='S0'
> </span> <span class='S10'
>{
</span><span class='S0'
><br />
229 </span>
230 <span class='S5'
>int
</span><span class='S0'
> </span> <span class='S11'
>
231 endStyled
</span><span class='S0'
> </span> <span class='S10'
>=
</span><span
232 class='S0'
> </span> <span class='S11'
>SendEditor
</span><span class='S10'
>(
</span><span
233 class='S11'
>SCI_GETENDSTYLED
</span><span class='S10'
>);
</span><span class='S0'
><br />
234 </span>
235 <span class='S5'
>int
</span><span class='S0'
> </span> <span class='S11'
>
236 lineEndStyled
</span><span class='S0'
> </span> <span class='S10'
>=
</span><span
237 class='S0'
> </span> <span class='S11'
>SendEditor
</span><span class='S10'
>(
</span><span
238 class='S11'
>EM_LINEFROMCHAR
</span><span class='S10'
>,
</span><span class='S0'
> </span>
239 <span class='S11'
>endStyled
</span><span class='S10'
>);
</span><span class='S0'
><br />
240 </span>
241 <span class='S11'
>endStyled
</span><span class='S0'
> </span> <span class='S10'
>
242 =
</span><span class='S0'
> </span> <span class='S11'
>SendEditor
</span><span
243 class='S10'
>(
</span><span class='S11'
>EM_LINEINDEX
</span><span class='S10'
>,
</span><span
244 class='S0'
> </span> <span class='S11'
>lineEndStyled
</span><span class='S10'
>);
</span><span
246 </span>
247 <span class='S11'
>Colourise
</span><span class='S10'
>(
</span><span
248 class='S11'
>endStyled
</span><span class='S10'
>,
</span><span class='S0'
> </span> <span
249 class='S11'
>notification
</span><span class='S10'
>-
></span><span
250 class='S11'
>position
</span><span class='S10'
>);
</span><br />
253 Colourize(start, end) retrieves the specified range of text and then calls ColourizeDoc in
254 keywords.cxx. It starts the process by calling:
256 <span class='S11'
>SendMessage
</span><span class='S10'
>(
</span><span
257 class='S11'
>hwnd
</span><span class='S10'
>,
</span><span class='S0'
> </span> <span
258 class='S11'
>SCI_STARTSTYLING
</span><span class='S10'
>,
</span><span class='S0'
> </span>
259 <span class='S11'
>startPos
</span><span class='S10'
>,
</span><span class='S0'
> </span> <span
260 class='S4'
>31</span><span class='S10'
>);
</span><br />
263 and then for each token of the text, calling:
265 <span class='S11'
>SendMessage
</span><span class='S10'
>(
</span><span
266 class='S11'
>hwnd
</span><span class='S10'
>,
</span><span class='S0'
> </span> <span
267 class='S11'
>SCI_SETSTYLING
</span><span class='S10'
>,
</span><span class='S0'
> </span> <span
268 class='S11'
>length
</span><span class='S10'
>,
</span><span class='S0'
> </span> <span
269 class='S11'
>style
</span><span class='S10'
>);
</span><br />
272 where style is a number from
0 to
31 whose appearance has been defined using the
273 SCI_STYLESET... messages.
276 Implementing Calltips
279 Again, the SCN_CHARADDED notification is used to catch when an opening parenthesis is added.
280 The preceding word can then be retrieved from the current line:
282 <span class='S5'
>char
</span><span class='S0'
> </span> <span
283 class='S11'
>linebuf
</span><span class='S10'
>[
</span><span class='S4'
>1000</span><span
284 class='S10'
>];
</span><span class='S0'
><br />
285 </span> <span class='S5'
>int
</span><span class='S0'
> </span> <span
286 class='S11'
>current
</span><span class='S0'
> </span> <span class='S10'
>=
</span><span
287 class='S0'
> </span> <span class='S11'
>SendEditor
</span><span class='S10'
>(
</span><span
288 class='S11'
>SCI_GETCURLINE
</span><span class='S10'
>,
</span><span class='S0'
> </span> <span
289 class='S5'
>sizeof
</span><span class='S10'
>(
</span><span class='S11'
>linebuf
</span><span
290 class='S10'
>),
</span><span class='S0'
><br />
291 </span> <span class='S5'
>
292 reinterpret_cast
</span><span class='S10'
><</span><span class='S11'
>LPARAM
</span><span
293 class='S10'
>>(
</span><span class='S5'
>static_cast
</span><span class='S10'
><</span><span
294 class='S5'
>char
</span><span class='S0'
> </span> <span class='S10'
>*
>(
</span><span
295 class='S11'
>linebuf
</span><span class='S10'
>)));
</span><span class='S0'
><br />
296 </span> <span class='S5'
>int
</span><span class='S0'
> </span> <span
297 class='S11'
>pos
</span><span class='S0'
> </span> <span class='S10'
>=
</span><span
298 class='S0'
> </span> <span class='S11'
>SendEditor
</span><span class='S10'
>(
</span><span
299 class='S11'
>SCI_GETCURRENTPOS
</span><span class='S10'
>);
</span><span class='S0'
><br />
301 </span> <span class='S5'
>int
</span><span class='S0'
> </span> <span
302 class='S11'
>startword
</span><span class='S0'
> </span> <span class='S10'
>=
</span><span
303 class='S0'
> </span> <span class='S11'
>current
</span><span class='S0'
> </span> <span
304 class='S10'
>-
</span><span class='S0'
> </span> <span class='S4'
>1</span><span
305 class='S10'
>;
</span><span class='S0'
><br />
306 </span> <span class='S5'
>while
</span><span class='S0'
> </span>
307 <span class='S10'
>(
</span><span class='S11'
>startword
</span><span class='S0'
> </span>
308 <span class='S10'
>></span><span class='S0'
> </span> <span class='S4'
>0</span><span
309 class='S0'
> </span> <span class='S10'
>&&</span><span class='S0'
> </span>
310 <span class='S11'
>isalpha
</span><span class='S10'
>(
</span><span class='S11'
>linebuf
</span><span
311 class='S10'
>[
</span><span class='S11'
>startword
</span><span class='S0'
> </span> <span
312 class='S10'
>-
</span><span class='S0'
> </span> <span class='S4'
>1</span><span
313 class='S10'
>]))
</span><span class='S0'
><br />
314 </span> <span class='S11'
>
315 startword
</span><span class='S10'
>--;
</span><span class='S0'
><br />
316 </span> <span class='S11'
>linebuf
</span><span class='S10'
>[
</span><span
317 class='S11'
>current
</span><span class='S0'
> </span> <span class='S10'
>-
</span><span
318 class='S0'
> </span> <span class='S4'
>1</span><span class='S10'
>]
</span><span
319 class='S0'
> </span> <span class='S10'
>=
</span><span class='S0'
> </span> <span
320 class='S7'
>'\
0'
</span><span class='S10'
>;
</span><span class='S0'
><br />
321 </span> <span class='S5'
>char
</span><span class='S10'
>*
</span><span
322 class='S0'
> </span> <span class='S11'
>word
</span><span class='S0'
> </span> <span
323 class='S10'
>=
</span><span class='S0'
> </span> <span class='S11'
>linebuf
</span><span
324 class='S0'
> </span> <span class='S10'
>+
</span><span class='S0'
> </span> <span
325 class='S11'
>startword
</span><span class='S10'
>;
</span><br />
328 Then if a calltip is available it can be displayed. The calltip appears immediately below
329 the position specified. The calltip can be multiple lines separated by newlines (\n).
331 <span class='S11'
>pos
</span><span class='S0'
> </span> <span
332 class='S10'
>=
</span><span class='S0'
> </span> <span class='S11'
>SendMessage
</span><span
333 class='S10'
>(
</span><span class='S11'
>hwnd
</span><span class='S10'
>,
</span><span
334 class='S0'
> </span> <span class='S11'
>SCI_GETCURRENTPOS
</span><span
335 class='S10'
>,
</span><span class='S0'
> </span> <span class='S4'
>0</span><span
336 class='S10'
>,
</span><span class='S0'
> </span> <span class='S4'
>0</span><span
337 class='S10'
>);
</span><span class='S0'
><br />
338 </span> <span class='S11'
>SendMessageText
</span><span
339 class='S10'
>(
</span><span class='S11'
>hwnd
</span><span class='S10'
>,
</span><span
340 class='S0'
> </span> <span class='S11'
>SCI_CALLTIPSHOW
</span><span
341 class='S10'
>,
</span><span class='S0'
> </span> <span class='S11'
>pos
</span><span
342 class='S0'
> </span> <span class='S10'
>-
</span><span class='S0'
> </span> <span
343 class='S11'
>wordLen
</span><span class='S0'
> </span> <span class='S10'
>-
</span><span
344 class='S0'
> </span> <span class='S4'
>1</span><span class='S10'
>,
</span><span
345 class='S0'
> </span> <span class='S11'
>calltip
</span><span class='S10'
>);
</span><br />
348 The calltip can be removed when a closing parenthesis is entered:
350 <span class='S5'
>if
</span><span class='S0'
> </span> <span
351 class='S10'
>(
</span><span class='S11'
>SendMessage
</span><span class='S10'
>(
</span><span
352 class='S11'
>hwnd
</span><span class='S10'
>,
</span><span class='S0'
> </span> <span
353 class='S11'
>SCI_CALLTIPACTIVE
</span><span class='S10'
>,
</span><span class='S0'
> </span>
354 <span class='S4'
>0</span><span class='S10'
>,
</span><span class='S0'
> </span> <span
355 class='S4'
>0</span><span class='S10'
>))
</span><span class='S0'
><br />
356 </span> <span class='S11'
>
357 SendMessage
</span><span class='S10'
>(
</span><span class='S11'
>hwnd
</span><span
358 class='S10'
>,
</span><span class='S0'
> </span> <span class='S11'
>
359 SCI_CALLTIPCANCEL
</span><span class='S10'
>,
</span><span class='S0'
> </span> <span
360 class='S4'
>0</span><span class='S10'
>,
</span><span class='S0'
> </span> <span class='S4'
>
361 0</span><span class='S10'
>);
</span><br />
364 Obviously, it is up the application to look after supplying the appropriate calltip text.
367 SciTE goes one step further, counting the commas between arguments and highlighting the
368 corresponding part of the calltip. This code is in ContinueCallTip.
371 <i>Page contributed by Andrew McKinlay.
</i>