]>
Commit | Line | Data |
---|---|---|
9ce192d4 | 1 | // Scintilla source code edit control |
65ec6247 RD |
2 | /** @file ScintillaBase.cxx |
3 | ** An enhanced subclass of Editor with calltips, autocomplete and context menu. | |
4 | **/ | |
9e730a78 | 5 | // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org> |
9ce192d4 RD |
6 | // The License.txt file describes the conditions under which this software may be distributed. |
7 | ||
8 | #include <stdlib.h> | |
9 | #include <string.h> | |
10 | #include <stdio.h> | |
11 | #include <ctype.h> | |
12 | ||
13 | #include "Platform.h" | |
14 | ||
15 | #include "Scintilla.h" | |
d134f170 | 16 | #include "PropSet.h" |
9ce192d4 RD |
17 | #ifdef SCI_LEXER |
18 | #include "SciLexer.h" | |
9ce192d4 | 19 | #include "Accessor.h" |
f6bcfd97 | 20 | #include "DocumentAccessor.h" |
9ce192d4 RD |
21 | #include "KeyWords.h" |
22 | #endif | |
23 | #include "ContractionState.h" | |
24 | #include "SVector.h" | |
25 | #include "CellBuffer.h" | |
26 | #include "CallTip.h" | |
27 | #include "KeyMap.h" | |
28 | #include "Indicator.h" | |
9e730a78 | 29 | #include "XPM.h" |
9ce192d4 RD |
30 | #include "LineMarker.h" |
31 | #include "Style.h" | |
32 | #include "ViewStyle.h" | |
33 | #include "AutoComplete.h" | |
b8193d80 | 34 | #include "CharClassify.h" |
9ce192d4 RD |
35 | #include "Document.h" |
36 | #include "Editor.h" | |
37 | #include "ScintillaBase.h" | |
38 | ||
39 | ScintillaBase::ScintillaBase() { | |
b8b0e402 | 40 | displayPopupMenu = true; |
65ec6247 | 41 | listType = 0; |
1e9bafca | 42 | maxListWidth = 0; |
65ec6247 | 43 | #ifdef SCI_LEXER |
9ce192d4 | 44 | lexLanguage = SCLEX_CONTAINER; |
1e9bafca | 45 | performingStyle = false; |
65ec6247 RD |
46 | lexCurrent = 0; |
47 | for (int wl = 0;wl < numWordLists;wl++) | |
9ce192d4 | 48 | keyWordLists[wl] = new WordList; |
65ec6247 | 49 | keyWordLists[numWordLists] = 0; |
9ce192d4 RD |
50 | #endif |
51 | } | |
52 | ||
d134f170 | 53 | ScintillaBase::~ScintillaBase() { |
65ec6247 RD |
54 | #ifdef SCI_LEXER |
55 | for (int wl = 0;wl < numWordLists;wl++) | |
d134f170 RD |
56 | delete keyWordLists[wl]; |
57 | #endif | |
58 | } | |
9ce192d4 RD |
59 | |
60 | void ScintillaBase::Finalise() { | |
65ec6247 | 61 | Editor::Finalise(); |
9ce192d4 RD |
62 | popup.Destroy(); |
63 | } | |
64 | ||
65 | void ScintillaBase::RefreshColourPalette(Palette &pal, bool want) { | |
66 | Editor::RefreshColourPalette(pal, want); | |
67 | ct.RefreshColourPalette(pal, want); | |
68 | } | |
69 | ||
1a2fb4cd | 70 | void ScintillaBase::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) { |
a834585d RD |
71 | bool isFillUp = ac.Active() && ac.IsFillUpChar(*s); |
72 | if (!isFillUp) { | |
1a2fb4cd | 73 | Editor::AddCharUTF(s, len, treatAsDBCS); |
a834585d RD |
74 | } |
75 | if (ac.Active()) { | |
f114b858 | 76 | AutoCompleteCharacterAdded(s[0]); |
2b5f62a0 | 77 | // For fill ups add the character after the autocompletion has |
a834585d RD |
78 | // triggered so containers see the key so can display a calltip. |
79 | if (isFillUp) { | |
80 | Editor::AddCharUTF(s, len, treatAsDBCS); | |
81 | } | |
82 | } | |
9ce192d4 RD |
83 | } |
84 | ||
85 | void ScintillaBase::Command(int cmdId) { | |
86 | ||
87 | switch (cmdId) { | |
88 | ||
65ec6247 RD |
89 | case idAutoComplete: // Nothing to do |
90 | ||
9ce192d4 RD |
91 | break; |
92 | ||
65ec6247 RD |
93 | case idCallTip: // Nothing to do |
94 | ||
9ce192d4 RD |
95 | break; |
96 | ||
97 | case idcmdUndo: | |
d134f170 | 98 | WndProc(SCI_UNDO, 0, 0); |
9ce192d4 RD |
99 | break; |
100 | ||
101 | case idcmdRedo: | |
102 | WndProc(SCI_REDO, 0, 0); | |
103 | break; | |
104 | ||
105 | case idcmdCut: | |
d134f170 | 106 | WndProc(SCI_CUT, 0, 0); |
9ce192d4 RD |
107 | break; |
108 | ||
109 | case idcmdCopy: | |
d134f170 | 110 | WndProc(SCI_COPY, 0, 0); |
9ce192d4 RD |
111 | break; |
112 | ||
113 | case idcmdPaste: | |
d134f170 | 114 | WndProc(SCI_PASTE, 0, 0); |
9ce192d4 RD |
115 | break; |
116 | ||
117 | case idcmdDelete: | |
d134f170 | 118 | WndProc(SCI_CLEAR, 0, 0); |
9ce192d4 RD |
119 | break; |
120 | ||
121 | case idcmdSelectAll: | |
122 | WndProc(SCI_SELECTALL, 0, 0); | |
123 | break; | |
124 | } | |
125 | } | |
126 | ||
d134f170 | 127 | int ScintillaBase::KeyCommand(unsigned int iMessage) { |
9ce192d4 RD |
128 | // Most key commands cancel autocompletion mode |
129 | if (ac.Active()) { | |
130 | switch (iMessage) { | |
131 | // Except for these | |
132 | case SCI_LINEDOWN: | |
133 | AutoCompleteMove(1); | |
134 | return 0; | |
135 | case SCI_LINEUP: | |
136 | AutoCompleteMove( -1); | |
137 | return 0; | |
138 | case SCI_PAGEDOWN: | |
139 | AutoCompleteMove(5); | |
140 | return 0; | |
141 | case SCI_PAGEUP: | |
142 | AutoCompleteMove( -5); | |
143 | return 0; | |
144 | case SCI_VCHOME: | |
145 | AutoCompleteMove( -5000); | |
146 | return 0; | |
147 | case SCI_LINEEND: | |
148 | AutoCompleteMove(5000); | |
149 | return 0; | |
150 | case SCI_DELETEBACK: | |
1a2fb4cd | 151 | DelCharBack(true); |
f114b858 | 152 | AutoCompleteCharacterDeleted(); |
1a2fb4cd RD |
153 | EnsureCaretVisible(); |
154 | return 0; | |
155 | case SCI_DELETEBACKNOTLINE: | |
156 | DelCharBack(false); | |
f114b858 | 157 | AutoCompleteCharacterDeleted(); |
9ce192d4 RD |
158 | EnsureCaretVisible(); |
159 | return 0; | |
160 | case SCI_TAB: | |
161 | AutoCompleteCompleted(); | |
162 | return 0; | |
d134f170 RD |
163 | case SCI_NEWLINE: |
164 | AutoCompleteCompleted(); | |
165 | return 0; | |
9ce192d4 RD |
166 | |
167 | default: | |
168 | ac.Cancel(); | |
169 | } | |
170 | } | |
171 | ||
172 | if (ct.inCallTipMode) { | |
173 | if ( | |
174 | (iMessage != SCI_CHARLEFT) && | |
175 | (iMessage != SCI_CHARLEFTEXTEND) && | |
176 | (iMessage != SCI_CHARRIGHT) && | |
177 | (iMessage != SCI_CHARLEFTEXTEND) && | |
178 | (iMessage != SCI_EDITTOGGLEOVERTYPE) && | |
1a2fb4cd RD |
179 | (iMessage != SCI_DELETEBACK) && |
180 | (iMessage != SCI_DELETEBACKNOTLINE) | |
9ce192d4 RD |
181 | ) { |
182 | ct.CallTipCancel(); | |
183 | } | |
1a2fb4cd | 184 | if ((iMessage == SCI_DELETEBACK) || (iMessage == SCI_DELETEBACKNOTLINE)) { |
9ce192d4 RD |
185 | if (currentPos <= ct.posStartCallTip) { |
186 | ct.CallTipCancel(); | |
187 | } | |
188 | } | |
189 | } | |
190 | return Editor::KeyCommand(iMessage); | |
191 | } | |
192 | ||
1a2fb4cd RD |
193 | void ScintillaBase::AutoCompleteDoubleClick(void* p) { |
194 | ScintillaBase* sci = reinterpret_cast<ScintillaBase*>(p); | |
195 | sci->AutoCompleteCompleted(); | |
196 | } | |
197 | ||
9ce192d4 | 198 | void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) { |
d134f170 | 199 | //Platform::DebugPrintf("AutoComplete %s\n", list); |
9ce192d4 RD |
200 | ct.CallTipCancel(); |
201 | ||
65ec6247 | 202 | if (ac.chooseSingle && (listType == 0)) { |
d134f170 | 203 | if (list && !strchr(list, ac.GetSeparator())) { |
8e54aaed RD |
204 | const char *typeSep = strchr(list, ac.GetTypesep()); |
205 | size_t lenInsert = (typeSep) ? (typeSep-list) : strlen(list); | |
d134f170 RD |
206 | if (ac.ignoreCase) { |
207 | SetEmptySelection(currentPos - lenEntered); | |
208 | pdoc->DeleteChars(currentPos, lenEntered); | |
209 | SetEmptySelection(currentPos); | |
8e54aaed RD |
210 | pdoc->InsertString(currentPos, list, lenInsert); |
211 | SetEmptySelection(currentPos + lenInsert); | |
d134f170 RD |
212 | } else { |
213 | SetEmptySelection(currentPos); | |
8e54aaed RD |
214 | pdoc->InsertString(currentPos, list + lenEntered, lenInsert - lenEntered); |
215 | SetEmptySelection(currentPos + lenInsert - lenEntered); | |
d134f170 | 216 | } |
1a2fb4cd | 217 | return; |
d134f170 RD |
218 | } |
219 | } | |
1e9bafca RD |
220 | ac.Start(wMain, idAutoComplete, currentPos, LocationFromPosition(currentPos), |
221 | lenEntered, vs.lineHeight, IsUnicodeMode()); | |
9ce192d4 RD |
222 | |
223 | PRectangle rcClient = GetClientRectangle(); | |
65ec6247 | 224 | Point pt = LocationFromPosition(currentPos - lenEntered); |
9ce192d4 | 225 | |
9ce192d4 RD |
226 | int heightLB = 100; |
227 | int widthLB = 100; | |
228 | if (pt.x >= rcClient.right - widthLB) { | |
229 | HorizontalScrollTo(xOffset + pt.x - rcClient.right + widthLB); | |
230 | Redraw(); | |
231 | pt = LocationFromPosition(currentPos); | |
232 | } | |
233 | PRectangle rcac; | |
9e730a78 | 234 | rcac.left = pt.x - ac.lb->CaretFromEdge(); |
65ec6247 RD |
235 | if (pt.y >= rcClient.bottom - heightLB && // Wont fit below. |
236 | pt.y >= (rcClient.bottom + rcClient.top) / 2) { // and there is more room above. | |
9ce192d4 RD |
237 | rcac.top = pt.y - heightLB; |
238 | if (rcac.top < 0) { | |
239 | heightLB += rcac.top; | |
240 | rcac.top = 0; | |
241 | } | |
242 | } else { | |
243 | rcac.top = pt.y + vs.lineHeight; | |
244 | } | |
245 | rcac.right = rcac.left + widthLB; | |
246 | rcac.bottom = Platform::Minimum(rcac.top + heightLB, rcClient.bottom); | |
9e730a78 RD |
247 | ac.lb->SetPositionRelative(rcac, wMain); |
248 | ac.lb->SetFont(vs.styles[STYLE_DEFAULT].font); | |
1e9bafca RD |
249 | unsigned int aveCharWidth = vs.styles[STYLE_DEFAULT].aveCharWidth; |
250 | ac.lb->SetAverageCharWidth(aveCharWidth); | |
9e730a78 | 251 | ac.lb->SetDoubleClickAction(AutoCompleteDoubleClick, this); |
9ce192d4 | 252 | |
d134f170 | 253 | ac.SetList(list); |
9ce192d4 RD |
254 | |
255 | // Fiddle the position of the list so it is right next to the target and wide enough for all its strings | |
9e730a78 | 256 | PRectangle rcList = ac.lb->GetDesiredRect(); |
9ce192d4 | 257 | int heightAlloced = rcList.bottom - rcList.top; |
d134f170 | 258 | widthLB = Platform::Maximum(widthLB, rcList.right - rcList.left); |
1e9bafca RD |
259 | if (maxListWidth != 0) |
260 | widthLB = Platform::Minimum(widthLB, aveCharWidth*maxListWidth); | |
9ce192d4 | 261 | // Make an allowance for large strings in list |
9e730a78 | 262 | rcList.left = pt.x - ac.lb->CaretFromEdge(); |
d134f170 | 263 | rcList.right = rcList.left + widthLB; |
f114b858 RD |
264 | if (((pt.y + vs.lineHeight) >= (rcClient.bottom - heightAlloced)) && // Wont fit below. |
265 | ((pt.y + vs.lineHeight / 2) >= (rcClient.bottom + rcClient.top) / 2)) { // and there is more room above. | |
9ce192d4 RD |
266 | rcList.top = pt.y - heightAlloced; |
267 | } else { | |
268 | rcList.top = pt.y + vs.lineHeight; | |
269 | } | |
270 | rcList.bottom = rcList.top + heightAlloced; | |
9e730a78 | 271 | ac.lb->SetPositionRelative(rcList, wMain); |
1e9bafca | 272 | ac.Show(true); |
d134f170 RD |
273 | if (lenEntered != 0) { |
274 | AutoCompleteMoveToCurrentWord(); | |
65ec6247 | 275 | } |
9ce192d4 RD |
276 | } |
277 | ||
278 | void ScintillaBase::AutoCompleteCancel() { | |
279 | ac.Cancel(); | |
280 | } | |
281 | ||
282 | void ScintillaBase::AutoCompleteMove(int delta) { | |
283 | ac.Move(delta); | |
284 | } | |
285 | ||
d134f170 RD |
286 | void ScintillaBase::AutoCompleteMoveToCurrentWord() { |
287 | char wordCurrent[1000]; | |
288 | int i; | |
289 | int startWord = ac.posStart - ac.startLen; | |
a33203cb | 290 | for (i = startWord; i < currentPos && i - startWord < 1000; i++) |
d134f170 | 291 | wordCurrent[i - startWord] = pdoc->CharAt(i); |
a33203cb | 292 | wordCurrent[Platform::Minimum(i - startWord, 999)] = '\0'; |
d134f170 RD |
293 | ac.Select(wordCurrent); |
294 | } | |
295 | ||
f114b858 | 296 | void ScintillaBase::AutoCompleteCharacterAdded(char ch) { |
d134f170 | 297 | if (ac.IsFillUpChar(ch)) { |
a834585d | 298 | AutoCompleteCompleted(); |
f114b858 | 299 | } else if (ac.IsStopChar(ch)) { |
d134f170 | 300 | ac.Cancel(); |
f114b858 RD |
301 | } else { |
302 | AutoCompleteMoveToCurrentWord(); | |
303 | } | |
304 | } | |
305 | ||
306 | void ScintillaBase::AutoCompleteCharacterDeleted() { | |
591d01be | 307 | if (currentPos < ac.posStart - ac.startLen) { |
9ce192d4 | 308 | ac.Cancel(); |
f114b858 | 309 | } else if (ac.cancelAtStartPos && (currentPos <= ac.posStart)) { |
9ce192d4 RD |
310 | ac.Cancel(); |
311 | } else { | |
d134f170 | 312 | AutoCompleteMoveToCurrentWord(); |
9ce192d4 RD |
313 | } |
314 | } | |
315 | ||
a834585d | 316 | void ScintillaBase::AutoCompleteCompleted() { |
9e730a78 | 317 | int item = ac.lb->GetSelection(); |
d134f170 | 318 | char selected[1000]; |
9e730a78 | 319 | selected[0] = '\0'; |
9ce192d4 | 320 | if (item != -1) { |
9e730a78 | 321 | ac.lb->GetValue(item, selected, sizeof(selected)); |
1e9bafca RD |
322 | } else { |
323 | ac.Cancel(); | |
324 | return; | |
9ce192d4 | 325 | } |
1e9bafca RD |
326 | |
327 | ac.Show(false); | |
328 | ||
329 | listSelected = selected; | |
330 | SCNotification scn = {0}; | |
331 | scn.nmhdr.code = listType > 0 ? SCN_USERLISTSELECTION : SCN_AUTOCSELECTION; | |
332 | scn.message = 0; | |
333 | scn.wParam = listType; | |
334 | scn.listType = listType; | |
335 | Position firstPos = ac.posStart - ac.startLen; | |
336 | scn.lParam = firstPos; | |
337 | scn.text = listSelected.c_str(); | |
338 | NotifyParent(scn); | |
339 | ||
340 | if (!ac.Active()) | |
591d01be | 341 | return; |
1e9bafca | 342 | ac.Cancel(); |
65ec6247 | 343 | |
1e9bafca | 344 | if (listType > 0) |
1a2fb4cd | 345 | return; |
65ec6247 | 346 | |
1a2fb4cd RD |
347 | Position endPos = currentPos; |
348 | if (ac.dropRestOfWord) | |
349 | endPos = pdoc->ExtendWordSelect(endPos, 1, true); | |
350 | if (endPos < firstPos) | |
351 | return; | |
352 | pdoc->BeginUndoAction(); | |
353 | if (endPos != firstPos) { | |
354 | pdoc->DeleteChars(firstPos, endPos - firstPos); | |
65ec6247 RD |
355 | } |
356 | SetEmptySelection(ac.posStart); | |
357 | if (item != -1) { | |
358 | SString piece = selected; | |
65ec6247 | 359 | pdoc->InsertString(firstPos, piece.c_str()); |
88a8b04e | 360 | SetEmptySelection(firstPos + static_cast<int>(piece.length())); |
9ce192d4 | 361 | } |
1a2fb4cd | 362 | pdoc->EndUndoAction(); |
9ce192d4 RD |
363 | } |
364 | ||
8e54aaed RD |
365 | int ScintillaBase::AutoCompleteGetCurrent() { |
366 | return ac.lb->GetSelection(); | |
367 | } | |
368 | ||
9e730a78 RD |
369 | void ScintillaBase::CallTipShow(Point pt, const char *defn) { |
370 | AutoCompleteCancel(); | |
371 | pt.y += vs.lineHeight; | |
b8193d80 RD |
372 | // If container knows about STYLE_CALLTIP then use it in place of the |
373 | // STYLE_DEFAULT for the face name, size and character set. Also use it | |
374 | // for the foreground and background colour. | |
375 | int ctStyle = ct.UseStyleCallTip() ? STYLE_CALLTIP : STYLE_DEFAULT; | |
376 | if (ct.UseStyleCallTip()) { | |
377 | ct.SetForeBack(vs.styles[STYLE_CALLTIP].fore, vs.styles[STYLE_CALLTIP].back); | |
378 | } | |
9e730a78 | 379 | PRectangle rc = ct.CallTipStart(currentPos, pt, |
a33203cb | 380 | defn, |
b8193d80 RD |
381 | vs.styles[ctStyle].fontName, |
382 | vs.styles[ctStyle].sizeZoomed, | |
a33203cb | 383 | CodePage(), |
b8193d80 | 384 | vs.styles[ctStyle].characterSet, |
a33203cb | 385 | wMain); |
9e730a78 RD |
386 | // If the call-tip window would be out of the client |
387 | // space, adjust so it displays above the text. | |
388 | PRectangle rcClient = GetClientRectangle(); | |
389 | if (rc.bottom > rcClient.bottom) { | |
390 | int offset = vs.lineHeight + rc.Height(); | |
391 | rc.top -= offset; | |
392 | rc.bottom -= offset; | |
393 | } | |
394 | // Now display the window. | |
395 | CreateCallTipWindow(rc); | |
396 | ct.wCallTip.SetPositionRelative(rc, wMain); | |
397 | ct.wCallTip.Show(); | |
398 | } | |
399 | ||
400 | void ScintillaBase::CallTipClick() { | |
1e9bafca | 401 | SCNotification scn = {0}; |
9e730a78 RD |
402 | scn.nmhdr.code = SCN_CALLTIPCLICK; |
403 | scn.position = ct.clickPlace; | |
404 | NotifyParent(scn); | |
405 | } | |
406 | ||
9ce192d4 | 407 | void ScintillaBase::ContextMenu(Point pt) { |
a834585d RD |
408 | if (displayPopupMenu) { |
409 | bool writable = !WndProc(SCI_GETREADONLY, 0, 0); | |
410 | popup.CreatePopUp(); | |
411 | AddToPopUp("Undo", idcmdUndo, writable && pdoc->CanUndo()); | |
412 | AddToPopUp("Redo", idcmdRedo, writable && pdoc->CanRedo()); | |
413 | AddToPopUp(""); | |
414 | AddToPopUp("Cut", idcmdCut, writable && currentPos != anchor); | |
415 | AddToPopUp("Copy", idcmdCopy, currentPos != anchor); | |
416 | AddToPopUp("Paste", idcmdPaste, writable && WndProc(SCI_CANPASTE, 0, 0)); | |
417 | AddToPopUp("Delete", idcmdDelete, writable && currentPos != anchor); | |
418 | AddToPopUp(""); | |
419 | AddToPopUp("Select All", idcmdSelectAll); | |
420 | popup.Show(pt, wMain); | |
421 | } | |
9ce192d4 RD |
422 | } |
423 | ||
d134f170 | 424 | void ScintillaBase::CancelModes() { |
9ce192d4 RD |
425 | AutoCompleteCancel(); |
426 | ct.CallTipCancel(); | |
d134f170 RD |
427 | Editor::CancelModes(); |
428 | } | |
429 | ||
430 | void ScintillaBase::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) { | |
431 | CancelModes(); | |
9ce192d4 RD |
432 | Editor::ButtonDown(pt, curTime, shift, ctrl, alt); |
433 | } | |
434 | ||
435 | #ifdef SCI_LEXER | |
65ec6247 RD |
436 | void ScintillaBase::SetLexer(uptr_t wParam) { |
437 | lexLanguage = wParam; | |
438 | lexCurrent = LexerModule::Find(lexLanguage); | |
439 | if (!lexCurrent) | |
440 | lexCurrent = LexerModule::Find(SCLEX_NULL); | |
441 | } | |
442 | ||
443 | void ScintillaBase::SetLexerLanguage(const char *languageName) { | |
444 | lexLanguage = SCLEX_CONTAINER; | |
445 | lexCurrent = LexerModule::Find(languageName); | |
446 | if (!lexCurrent) | |
447 | lexCurrent = LexerModule::Find(SCLEX_NULL); | |
448 | if (lexCurrent) | |
449 | lexLanguage = lexCurrent->GetLanguage(); | |
450 | } | |
451 | ||
9ce192d4 | 452 | void ScintillaBase::Colourise(int start, int end) { |
1e9bafca RD |
453 | if (!performingStyle) { |
454 | // Protect against reentrance, which may occur, for example, when | |
455 | // fold points are discovered while performing styling and the folding | |
456 | // code looks for child lines which may trigger styling. | |
457 | performingStyle = true; | |
458 | ||
459 | int lengthDoc = pdoc->Length(); | |
460 | if (end == -1) | |
461 | end = lengthDoc; | |
462 | int len = end - start; | |
463 | ||
464 | PLATFORM_ASSERT(len >= 0); | |
465 | PLATFORM_ASSERT(start + len <= lengthDoc); | |
466 | ||
467 | //WindowAccessor styler(wMain.GetID(), props); | |
468 | DocumentAccessor styler(pdoc, props, wMain.GetID()); | |
469 | ||
470 | int styleStart = 0; | |
471 | if (start > 0) | |
b8193d80 | 472 | styleStart = styler.StyleAt(start - 1) & pdoc->stylingBitsMask; |
1e9bafca RD |
473 | styler.SetCodePage(pdoc->dbcsCodePage); |
474 | ||
475 | if (lexCurrent && (len > 0)) { // Should always succeed as null lexer should always be available | |
476 | lexCurrent->Lex(start, len, styleStart, keyWordLists, styler); | |
65ec6247 | 477 | styler.Flush(); |
1e9bafca RD |
478 | if (styler.GetPropertyInt("fold")) { |
479 | lexCurrent->Fold(start, len, styleStart, keyWordLists, styler); | |
480 | styler.Flush(); | |
481 | } | |
65ec6247 | 482 | } |
1e9bafca RD |
483 | |
484 | performingStyle = false; | |
65ec6247 | 485 | } |
9ce192d4 RD |
486 | } |
487 | #endif | |
488 | ||
f6bcfd97 | 489 | void ScintillaBase::NotifyStyleToNeeded(int endStyleNeeded) { |
9ce192d4 RD |
490 | #ifdef SCI_LEXER |
491 | if (lexLanguage != SCLEX_CONTAINER) { | |
65ec6247 RD |
492 | int endStyled = WndProc(SCI_GETENDSTYLED, 0, 0); |
493 | int lineEndStyled = WndProc(SCI_LINEFROMPOSITION, endStyled, 0); | |
494 | endStyled = WndProc(SCI_POSITIONFROMLINE, lineEndStyled, 0); | |
9ce192d4 | 495 | Colourise(endStyled, endStyleNeeded); |
1a2fb4cd | 496 | return; |
9ce192d4 RD |
497 | } |
498 | #endif | |
f6bcfd97 | 499 | Editor::NotifyStyleToNeeded(endStyleNeeded); |
9ce192d4 RD |
500 | } |
501 | ||
65ec6247 | 502 | sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { |
9ce192d4 RD |
503 | switch (iMessage) { |
504 | case SCI_AUTOCSHOW: | |
65ec6247 | 505 | listType = 0; |
9ce192d4 RD |
506 | AutoCompleteStart(wParam, reinterpret_cast<const char *>(lParam)); |
507 | break; | |
508 | ||
509 | case SCI_AUTOCCANCEL: | |
510 | AutoCompleteCancel(); | |
511 | break; | |
512 | ||
513 | case SCI_AUTOCACTIVE: | |
514 | return ac.Active(); | |
515 | ||
516 | case SCI_AUTOCPOSSTART: | |
517 | return ac.posStart; | |
518 | ||
519 | case SCI_AUTOCCOMPLETE: | |
520 | AutoCompleteCompleted(); | |
521 | break; | |
522 | ||
f6bcfd97 | 523 | case SCI_AUTOCSETSEPARATOR: |
d134f170 | 524 | ac.SetSeparator(static_cast<char>(wParam)); |
f6bcfd97 BP |
525 | break; |
526 | ||
527 | case SCI_AUTOCGETSEPARATOR: | |
528 | return ac.GetSeparator(); | |
529 | ||
9ce192d4 RD |
530 | case SCI_AUTOCSTOPS: |
531 | ac.SetStopChars(reinterpret_cast<char *>(lParam)); | |
532 | break; | |
65ec6247 | 533 | |
f6bcfd97 BP |
534 | case SCI_AUTOCSELECT: |
535 | ac.Select(reinterpret_cast<char *>(lParam)); | |
536 | break; | |
65ec6247 | 537 | |
8e54aaed RD |
538 | case SCI_AUTOCGETCURRENT: |
539 | return AutoCompleteGetCurrent(); | |
540 | ||
d134f170 | 541 | case SCI_AUTOCSETCANCELATSTART: |
1a2fb4cd | 542 | ac.cancelAtStartPos = wParam != 0; |
d134f170 | 543 | break; |
65ec6247 | 544 | |
d134f170 RD |
545 | case SCI_AUTOCGETCANCELATSTART: |
546 | return ac.cancelAtStartPos; | |
547 | ||
548 | case SCI_AUTOCSETFILLUPS: | |
549 | ac.SetFillUpChars(reinterpret_cast<char *>(lParam)); | |
550 | break; | |
551 | ||
552 | case SCI_AUTOCSETCHOOSESINGLE: | |
1a2fb4cd | 553 | ac.chooseSingle = wParam != 0; |
d134f170 | 554 | break; |
9ce192d4 | 555 | |
d134f170 RD |
556 | case SCI_AUTOCGETCHOOSESINGLE: |
557 | return ac.chooseSingle; | |
65ec6247 | 558 | |
d134f170 | 559 | case SCI_AUTOCSETIGNORECASE: |
1a2fb4cd | 560 | ac.ignoreCase = wParam != 0; |
d134f170 | 561 | break; |
65ec6247 | 562 | |
d134f170 RD |
563 | case SCI_AUTOCGETIGNORECASE: |
564 | return ac.ignoreCase; | |
65ec6247 RD |
565 | |
566 | case SCI_USERLISTSHOW: | |
567 | listType = wParam; | |
568 | AutoCompleteStart(0, reinterpret_cast<const char *>(lParam)); | |
569 | break; | |
570 | ||
571 | case SCI_AUTOCSETAUTOHIDE: | |
1a2fb4cd | 572 | ac.autoHide = wParam != 0; |
65ec6247 RD |
573 | break; |
574 | ||
575 | case SCI_AUTOCGETAUTOHIDE: | |
576 | return ac.autoHide; | |
577 | ||
1a2fb4cd RD |
578 | case SCI_AUTOCSETDROPRESTOFWORD: |
579 | ac.dropRestOfWord = wParam != 0; | |
580 | break; | |
581 | ||
582 | case SCI_AUTOCGETDROPRESTOFWORD: | |
583 | return ac.dropRestOfWord; | |
584 | ||
1e9bafca RD |
585 | case SCI_AUTOCSETMAXHEIGHT: |
586 | ac.lb->SetVisibleRows(wParam); | |
587 | break; | |
588 | ||
589 | case SCI_AUTOCGETMAXHEIGHT: | |
590 | return ac.lb->GetVisibleRows(); | |
591 | ||
592 | case SCI_AUTOCSETMAXWIDTH: | |
593 | maxListWidth = wParam; | |
594 | break; | |
595 | ||
596 | case SCI_AUTOCGETMAXWIDTH: | |
597 | return maxListWidth; | |
598 | ||
9e730a78 RD |
599 | case SCI_REGISTERIMAGE: |
600 | ac.lb->RegisterImage(wParam, reinterpret_cast<const char *>(lParam)); | |
601 | break; | |
602 | ||
603 | case SCI_CLEARREGISTEREDIMAGES: | |
604 | ac.lb->ClearRegisteredImages(); | |
605 | break; | |
606 | ||
607 | case SCI_AUTOCSETTYPESEPARATOR: | |
608 | ac.SetTypesep(static_cast<char>(wParam)); | |
609 | break; | |
610 | ||
611 | case SCI_AUTOCGETTYPESEPARATOR: | |
612 | return ac.GetTypesep(); | |
613 | ||
614 | case SCI_CALLTIPSHOW: | |
8e54aaed | 615 | CallTipShow(LocationFromPosition(wParam), |
9e730a78 | 616 | reinterpret_cast<const char *>(lParam)); |
9ce192d4 RD |
617 | break; |
618 | ||
619 | case SCI_CALLTIPCANCEL: | |
620 | ct.CallTipCancel(); | |
621 | break; | |
622 | ||
623 | case SCI_CALLTIPACTIVE: | |
624 | return ct.inCallTipMode; | |
625 | ||
626 | case SCI_CALLTIPPOSSTART: | |
627 | return ct.posStartCallTip; | |
628 | ||
629 | case SCI_CALLTIPSETHLT: | |
630 | ct.SetHighlight(wParam, lParam); | |
631 | break; | |
632 | ||
633 | case SCI_CALLTIPSETBACK: | |
1a2fb4cd | 634 | ct.colourBG = ColourDesired(wParam); |
b8193d80 | 635 | vs.styles[STYLE_CALLTIP].fore = ct.colourBG; |
9ce192d4 RD |
636 | InvalidateStyleRedraw(); |
637 | break; | |
65ec6247 | 638 | |
9e730a78 RD |
639 | case SCI_CALLTIPSETFORE: |
640 | ct.colourUnSel = ColourDesired(wParam); | |
b8193d80 | 641 | vs.styles[STYLE_CALLTIP].fore = ct.colourUnSel; |
9e730a78 RD |
642 | InvalidateStyleRedraw(); |
643 | break; | |
644 | ||
645 | case SCI_CALLTIPSETFOREHLT: | |
646 | ct.colourSel = ColourDesired(wParam); | |
647 | InvalidateStyleRedraw(); | |
648 | break; | |
649 | ||
b8193d80 RD |
650 | case SCI_CALLTIPUSESTYLE: |
651 | ct.SetTabSize((int)wParam); | |
652 | InvalidateStyleRedraw(); | |
653 | break; | |
654 | ||
b8b0e402 | 655 | case SCI_USEPOPUP: |
1a2fb4cd | 656 | displayPopupMenu = wParam != 0; |
b8b0e402 RD |
657 | break; |
658 | ||
9ce192d4 RD |
659 | #ifdef SCI_LEXER |
660 | case SCI_SETLEXER: | |
65ec6247 | 661 | SetLexer(wParam); |
9ce192d4 RD |
662 | lexLanguage = wParam; |
663 | break; | |
65ec6247 | 664 | |
9ce192d4 RD |
665 | case SCI_GETLEXER: |
666 | return lexLanguage; | |
65ec6247 | 667 | |
9ce192d4 | 668 | case SCI_COLOURISE: |
1e9bafca RD |
669 | if (lexLanguage == SCLEX_CONTAINER) { |
670 | pdoc->ModifiedAt(wParam); | |
671 | NotifyStyleToNeeded((lParam == -1) ? pdoc->Length() : lParam); | |
672 | } else { | |
673 | Colourise(wParam, lParam); | |
674 | } | |
f6bcfd97 | 675 | Redraw(); |
9ce192d4 | 676 | break; |
65ec6247 | 677 | |
9ce192d4 | 678 | case SCI_SETPROPERTY: |
65ec6247 RD |
679 | props.Set(reinterpret_cast<const char *>(wParam), |
680 | reinterpret_cast<const char *>(lParam)); | |
9ce192d4 | 681 | break; |
65ec6247 | 682 | |
1e9bafca RD |
683 | case SCI_GETPROPERTY: { |
684 | SString val = props.Get(reinterpret_cast<const char *>(wParam)); | |
685 | const int n = val.length(); | |
686 | if (lParam != 0) { | |
687 | char *ptr = reinterpret_cast<char *>(lParam); | |
688 | memcpy(ptr, val.c_str(), n); | |
689 | ptr[n] = '\0'; // terminate | |
690 | } | |
691 | return n; // Not including NUL | |
692 | } | |
693 | ||
694 | case SCI_GETPROPERTYEXPANDED: { | |
695 | SString val = props.GetExpanded(reinterpret_cast<const char *>(wParam)); | |
696 | const int n = val.length(); | |
697 | if (lParam != 0) { | |
698 | char *ptr = reinterpret_cast<char *>(lParam); | |
699 | memcpy(ptr, val.c_str(), n); | |
700 | ptr[n] = '\0'; // terminate | |
701 | } | |
702 | return n; // Not including NUL | |
703 | } | |
704 | ||
705 | case SCI_GETPROPERTYINT: | |
706 | return props.GetInt(reinterpret_cast<const char *>(wParam), lParam); | |
707 | ||
9ce192d4 | 708 | case SCI_SETKEYWORDS: |
f6bcfd97 | 709 | if (wParam < numWordLists) { |
9ce192d4 RD |
710 | keyWordLists[wParam]->Clear(); |
711 | keyWordLists[wParam]->Set(reinterpret_cast<const char *>(lParam)); | |
712 | } | |
713 | break; | |
65ec6247 RD |
714 | |
715 | case SCI_SETLEXERLANGUAGE: | |
716 | SetLexerLanguage(reinterpret_cast<const char *>(lParam)); | |
717 | break; | |
718 | ||
1e9bafca RD |
719 | case SCI_GETSTYLEBITSNEEDED: |
720 | return lexCurrent ? lexCurrent->GetStyleBitsNeeded() : 5; | |
9ce192d4 RD |
721 | #endif |
722 | ||
723 | default: | |
724 | return Editor::WndProc(iMessage, wParam, lParam); | |
725 | } | |
726 | return 0l; | |
727 | } |