Update Scintilla to version 3.4.1
[geany-mirror.git] / scintilla / src / ScintillaBase.cxx
blobdc154ec6d5660c19c1f65abdc6c5ac484449d63d
1 // Scintilla source code edit control
2 /** @file ScintillaBase.cxx
3 ** An enhanced subclass of Editor with calltips, autocomplete and context menu.
4 **/
5 // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
8 #include <stdlib.h>
9 #include <string.h>
10 #include <stdio.h>
11 #include <ctype.h>
12 #include <assert.h>
14 #include <string>
15 #include <vector>
16 #include <map>
17 #include <algorithm>
19 #include "Platform.h"
21 #include "ILexer.h"
22 #include "Scintilla.h"
24 #include "PropSetSimple.h"
25 #ifdef SCI_LEXER
26 #include "SciLexer.h"
27 #include "LexerModule.h"
28 #include "Catalogue.h"
29 #endif
30 #include "SplitVector.h"
31 #include "Partitioning.h"
32 #include "RunStyles.h"
33 #include "ContractionState.h"
34 #include "CellBuffer.h"
35 #include "CallTip.h"
36 #include "KeyMap.h"
37 #include "Indicator.h"
38 #include "XPM.h"
39 #include "LineMarker.h"
40 #include "Style.h"
41 #include "ViewStyle.h"
42 #include "AutoComplete.h"
43 #include "CharClassify.h"
44 #include "Decoration.h"
45 #include "CaseFolder.h"
46 #include "Document.h"
47 #include "Selection.h"
48 #include "PositionCache.h"
49 #include "Editor.h"
50 #include "ScintillaBase.h"
52 #ifdef SCI_NAMESPACE
53 using namespace Scintilla;
54 #endif
56 ScintillaBase::ScintillaBase() {
57 displayPopupMenu = true;
58 listType = 0;
59 maxListWidth = 0;
62 ScintillaBase::~ScintillaBase() {
65 void ScintillaBase::Finalise() {
66 Editor::Finalise();
67 popup.Destroy();
70 void ScintillaBase::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) {
71 bool isFillUp = ac.Active() && ac.IsFillUpChar(*s);
72 if (!isFillUp) {
73 Editor::AddCharUTF(s, len, treatAsDBCS);
75 if (ac.Active()) {
76 AutoCompleteCharacterAdded(s[0]);
77 // For fill ups add the character after the autocompletion has
78 // triggered so containers see the key so can display a calltip.
79 if (isFillUp) {
80 Editor::AddCharUTF(s, len, treatAsDBCS);
85 void ScintillaBase::Command(int cmdId) {
87 switch (cmdId) {
89 case idAutoComplete: // Nothing to do
91 break;
93 case idCallTip: // Nothing to do
95 break;
97 case idcmdUndo:
98 WndProc(SCI_UNDO, 0, 0);
99 break;
101 case idcmdRedo:
102 WndProc(SCI_REDO, 0, 0);
103 break;
105 case idcmdCut:
106 WndProc(SCI_CUT, 0, 0);
107 break;
109 case idcmdCopy:
110 WndProc(SCI_COPY, 0, 0);
111 break;
113 case idcmdPaste:
114 WndProc(SCI_PASTE, 0, 0);
115 break;
117 case idcmdDelete:
118 WndProc(SCI_CLEAR, 0, 0);
119 break;
121 case idcmdSelectAll:
122 WndProc(SCI_SELECTALL, 0, 0);
123 break;
127 int ScintillaBase::KeyCommand(unsigned int iMessage) {
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(ac.lb->GetVisibleRows());
140 return 0;
141 case SCI_PAGEUP:
142 AutoCompleteMove(-ac.lb->GetVisibleRows());
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:
151 DelCharBack(true);
152 AutoCompleteCharacterDeleted();
153 EnsureCaretVisible();
154 return 0;
155 case SCI_DELETEBACKNOTLINE:
156 DelCharBack(false);
157 AutoCompleteCharacterDeleted();
158 EnsureCaretVisible();
159 return 0;
160 case SCI_TAB:
161 AutoCompleteCompleted();
162 return 0;
163 case SCI_NEWLINE:
164 AutoCompleteCompleted();
165 return 0;
167 default:
168 AutoCompleteCancel();
172 if (ct.inCallTipMode) {
173 if (
174 (iMessage != SCI_CHARLEFT) &&
175 (iMessage != SCI_CHARLEFTEXTEND) &&
176 (iMessage != SCI_CHARRIGHT) &&
177 (iMessage != SCI_CHARRIGHTEXTEND) &&
178 (iMessage != SCI_EDITTOGGLEOVERTYPE) &&
179 (iMessage != SCI_DELETEBACK) &&
180 (iMessage != SCI_DELETEBACKNOTLINE)
182 ct.CallTipCancel();
184 if ((iMessage == SCI_DELETEBACK) || (iMessage == SCI_DELETEBACKNOTLINE)) {
185 if (sel.MainCaret() <= ct.posStartCallTip) {
186 ct.CallTipCancel();
190 return Editor::KeyCommand(iMessage);
193 void ScintillaBase::AutoCompleteDoubleClick(void *p) {
194 ScintillaBase *sci = reinterpret_cast<ScintillaBase *>(p);
195 sci->AutoCompleteCompleted();
198 void ScintillaBase::AutoCompleteInsert(Position startPos, int removeLen, const char *text, int textLen) {
199 UndoGroup ug(pdoc);
200 pdoc->DeleteChars(startPos, removeLen);
201 pdoc->InsertString(startPos, text, textLen);
202 SetEmptySelection(startPos + textLen);
205 void ScintillaBase::AutoCompleteStart(int lenEntered, const char *list) {
206 //Platform::DebugPrintf("AutoComplete %s\n", list);
207 ct.CallTipCancel();
209 if (ac.chooseSingle && (listType == 0)) {
210 if (list && !strchr(list, ac.GetSeparator())) {
211 const char *typeSep = strchr(list, ac.GetTypesep());
212 int lenInsert = typeSep ?
213 static_cast<int>(typeSep-list) : static_cast<int>(strlen(list));
214 if (ac.ignoreCase) {
215 // May need to convert the case before invocation, so remove lenEntered characters
216 AutoCompleteInsert(sel.MainCaret() - lenEntered, lenEntered, list, lenInsert);
217 } else {
218 AutoCompleteInsert(sel.MainCaret(), 0, list + lenEntered, lenInsert - lenEntered);
220 ac.Cancel();
221 return;
224 ac.Start(wMain, idAutoComplete, sel.MainCaret(), PointMainCaret(),
225 lenEntered, vs.lineHeight, IsUnicodeMode(), technology);
227 PRectangle rcClient = GetClientRectangle();
228 Point pt = LocationFromPosition(sel.MainCaret() - lenEntered);
229 PRectangle rcPopupBounds = wMain.GetMonitorRect(pt);
230 if (rcPopupBounds.Height() == 0)
231 rcPopupBounds = rcClient;
233 int heightLB = ac.heightLBDefault;
234 int widthLB = ac.widthLBDefault;
235 if (pt.x >= rcClient.right - widthLB) {
236 HorizontalScrollTo(xOffset + pt.x - rcClient.right + widthLB);
237 Redraw();
238 pt = PointMainCaret();
240 if (wMargin.GetID()) {
241 Point ptOrigin = GetVisibleOriginInMain();
242 pt.x += ptOrigin.x;
243 pt.y += ptOrigin.y;
245 PRectangle rcac;
246 rcac.left = pt.x - ac.lb->CaretFromEdge();
247 if (pt.y >= rcPopupBounds.bottom - heightLB && // Wont fit below.
248 pt.y >= (rcPopupBounds.bottom + rcPopupBounds.top) / 2) { // and there is more room above.
249 rcac.top = pt.y - heightLB;
250 if (rcac.top < rcPopupBounds.top) {
251 heightLB -= (rcPopupBounds.top - rcac.top);
252 rcac.top = rcPopupBounds.top;
254 } else {
255 rcac.top = pt.y + vs.lineHeight;
257 rcac.right = rcac.left + widthLB;
258 rcac.bottom = Platform::Minimum(rcac.top + heightLB, rcPopupBounds.bottom);
259 ac.lb->SetPositionRelative(rcac, wMain);
260 ac.lb->SetFont(vs.styles[STYLE_DEFAULT].font);
261 unsigned int aveCharWidth = vs.styles[STYLE_DEFAULT].aveCharWidth;
262 ac.lb->SetAverageCharWidth(aveCharWidth);
263 ac.lb->SetDoubleClickAction(AutoCompleteDoubleClick, this);
265 ac.SetList(list ? list : "");
267 // Fiddle the position of the list so it is right next to the target and wide enough for all its strings
268 PRectangle rcList = ac.lb->GetDesiredRect();
269 int heightAlloced = rcList.bottom - rcList.top;
270 widthLB = Platform::Maximum(widthLB, rcList.right - rcList.left);
271 if (maxListWidth != 0)
272 widthLB = Platform::Minimum(widthLB, aveCharWidth*maxListWidth);
273 // Make an allowance for large strings in list
274 rcList.left = pt.x - ac.lb->CaretFromEdge();
275 rcList.right = rcList.left + widthLB;
276 if (((pt.y + vs.lineHeight) >= (rcPopupBounds.bottom - heightAlloced)) && // Wont fit below.
277 ((pt.y + vs.lineHeight / 2) >= (rcPopupBounds.bottom + rcPopupBounds.top) / 2)) { // and there is more room above.
278 rcList.top = pt.y - heightAlloced;
279 } else {
280 rcList.top = pt.y + vs.lineHeight;
282 rcList.bottom = rcList.top + heightAlloced;
283 ac.lb->SetPositionRelative(rcList, wMain);
284 ac.Show(true);
285 if (lenEntered != 0) {
286 AutoCompleteMoveToCurrentWord();
290 void ScintillaBase::AutoCompleteCancel() {
291 if (ac.Active()) {
292 SCNotification scn = {};
293 scn.nmhdr.code = SCN_AUTOCCANCELLED;
294 scn.wParam = 0;
295 scn.listType = 0;
296 NotifyParent(scn);
298 ac.Cancel();
301 void ScintillaBase::AutoCompleteMove(int delta) {
302 ac.Move(delta);
305 void ScintillaBase::AutoCompleteMoveToCurrentWord() {
306 std::string wordCurrent = RangeText(ac.posStart - ac.startLen, sel.MainCaret());
307 ac.Select(wordCurrent.c_str());
310 void ScintillaBase::AutoCompleteCharacterAdded(char ch) {
311 if (ac.IsFillUpChar(ch)) {
312 AutoCompleteCompleted();
313 } else if (ac.IsStopChar(ch)) {
314 AutoCompleteCancel();
315 } else {
316 AutoCompleteMoveToCurrentWord();
320 void ScintillaBase::AutoCompleteCharacterDeleted() {
321 if (sel.MainCaret() < ac.posStart - ac.startLen) {
322 AutoCompleteCancel();
323 } else if (ac.cancelAtStartPos && (sel.MainCaret() <= ac.posStart)) {
324 AutoCompleteCancel();
325 } else {
326 AutoCompleteMoveToCurrentWord();
328 SCNotification scn = {};
329 scn.nmhdr.code = SCN_AUTOCCHARDELETED;
330 scn.wParam = 0;
331 scn.listType = 0;
332 NotifyParent(scn);
335 void ScintillaBase::AutoCompleteCompleted() {
336 int item = ac.GetSelection();
337 if (item == -1) {
338 AutoCompleteCancel();
339 return;
341 const std::string selected = ac.GetValue(item);
343 ac.Show(false);
345 SCNotification scn = {};
346 scn.nmhdr.code = listType > 0 ? SCN_USERLISTSELECTION : SCN_AUTOCSELECTION;
347 scn.message = 0;
348 scn.wParam = listType;
349 scn.listType = listType;
350 Position firstPos = ac.posStart - ac.startLen;
351 scn.position = firstPos;
352 scn.lParam = firstPos;
353 scn.text = selected.c_str();
354 NotifyParent(scn);
356 if (!ac.Active())
357 return;
358 ac.Cancel();
360 if (listType > 0)
361 return;
363 Position endPos = sel.MainCaret();
364 if (ac.dropRestOfWord)
365 endPos = pdoc->ExtendWordSelect(endPos, 1, true);
366 if (endPos < firstPos)
367 return;
368 AutoCompleteInsert(firstPos, endPos - firstPos, selected.c_str(), static_cast<int>(selected.length()));
369 SetLastXChosen();
372 int ScintillaBase::AutoCompleteGetCurrent() const {
373 if (!ac.Active())
374 return -1;
375 return ac.GetSelection();
378 int ScintillaBase::AutoCompleteGetCurrentText(char *buffer) const {
379 if (ac.Active()) {
380 int item = ac.GetSelection();
381 if (item != -1) {
382 const std::string selected = ac.GetValue(item);
383 if (buffer != NULL)
384 memcpy(buffer, selected.c_str(), selected.length()+1);
385 return static_cast<int>(selected.length());
388 if (buffer != NULL)
389 *buffer = '\0';
390 return 0;
393 void ScintillaBase::CallTipShow(Point pt, const char *defn) {
394 ac.Cancel();
395 // If container knows about STYLE_CALLTIP then use it in place of the
396 // STYLE_DEFAULT for the face name, size and character set. Also use it
397 // for the foreground and background colour.
398 int ctStyle = ct.UseStyleCallTip() ? STYLE_CALLTIP : STYLE_DEFAULT;
399 if (ct.UseStyleCallTip()) {
400 ct.SetForeBack(vs.styles[STYLE_CALLTIP].fore, vs.styles[STYLE_CALLTIP].back);
402 if (wMargin.GetID()) {
403 Point ptOrigin = GetVisibleOriginInMain();
404 pt.x += ptOrigin.x;
405 pt.y += ptOrigin.y;
407 PRectangle rc = ct.CallTipStart(sel.MainCaret(), pt,
408 vs.lineHeight,
409 defn,
410 vs.styles[ctStyle].fontName,
411 vs.styles[ctStyle].sizeZoomed,
412 CodePage(),
413 vs.styles[ctStyle].characterSet,
414 vs.technology,
415 wMain);
416 // If the call-tip window would be out of the client
417 // space
418 PRectangle rcClient = GetClientRectangle();
419 int offset = vs.lineHeight + rc.Height();
420 // adjust so it displays above the text.
421 if (rc.bottom > rcClient.bottom) {
422 rc.top -= offset;
423 rc.bottom -= offset;
425 // adjust so it displays below the text.
426 if (rc.top < rcClient.top) {
427 rc.top += offset;
428 rc.bottom += offset;
430 // Now display the window.
431 CreateCallTipWindow(rc);
432 ct.wCallTip.SetPositionRelative(rc, wMain);
433 ct.wCallTip.Show();
436 void ScintillaBase::CallTipClick() {
437 SCNotification scn = {};
438 scn.nmhdr.code = SCN_CALLTIPCLICK;
439 scn.position = ct.clickPlace;
440 NotifyParent(scn);
443 void ScintillaBase::ContextMenu(Point pt) {
444 if (displayPopupMenu) {
445 bool writable = !WndProc(SCI_GETREADONLY, 0, 0);
446 popup.CreatePopUp();
447 AddToPopUp("Undo", idcmdUndo, writable && pdoc->CanUndo());
448 AddToPopUp("Redo", idcmdRedo, writable && pdoc->CanRedo());
449 AddToPopUp("");
450 AddToPopUp("Cut", idcmdCut, writable && !sel.Empty());
451 AddToPopUp("Copy", idcmdCopy, !sel.Empty());
452 AddToPopUp("Paste", idcmdPaste, writable && WndProc(SCI_CANPASTE, 0, 0));
453 AddToPopUp("Delete", idcmdDelete, writable && !sel.Empty());
454 AddToPopUp("");
455 AddToPopUp("Select All", idcmdSelectAll);
456 popup.Show(pt, wMain);
460 void ScintillaBase::CancelModes() {
461 AutoCompleteCancel();
462 ct.CallTipCancel();
463 Editor::CancelModes();
466 void ScintillaBase::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifiers) {
467 CancelModes();
468 Editor::ButtonDownWithModifiers(pt, curTime, modifiers);
471 void ScintillaBase::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) {
472 ButtonDownWithModifiers(pt, curTime, ModifierFlags(shift, ctrl, alt));
475 #ifdef SCI_LEXER
477 #ifdef SCI_NAMESPACE
478 namespace Scintilla {
479 #endif
481 class LexState : public LexInterface {
482 const LexerModule *lexCurrent;
483 void SetLexerModule(const LexerModule *lex);
484 PropSetSimple props;
485 int interfaceVersion;
486 public:
487 int lexLanguage;
489 explicit LexState(Document *pdoc_);
490 virtual ~LexState();
491 void SetLexer(uptr_t wParam);
492 void SetLexerLanguage(const char *languageName);
493 const char *DescribeWordListSets();
494 void SetWordList(int n, const char *wl);
495 int GetStyleBitsNeeded() const;
496 const char *GetName() const;
497 void *PrivateCall(int operation, void *pointer);
498 const char *PropertyNames();
499 int PropertyType(const char *name);
500 const char *DescribeProperty(const char *name);
501 void PropSet(const char *key, const char *val);
502 const char *PropGet(const char *key) const;
503 int PropGetInt(const char *key, int defaultValue=0) const;
504 int PropGetExpanded(const char *key, char *result) const;
506 int LineEndTypesSupported();
507 int AllocateSubStyles(int styleBase, int numberStyles);
508 int SubStylesStart(int styleBase);
509 int SubStylesLength(int styleBase);
510 int StyleFromSubStyle(int subStyle);
511 int PrimaryStyleFromStyle(int style);
512 void FreeSubStyles();
513 void SetIdentifiers(int style, const char *identifiers);
514 int DistanceToSecondaryStyles();
515 const char *GetSubStyleBases();
518 #ifdef SCI_NAMESPACE
520 #endif
522 LexState::LexState(Document *pdoc_) : LexInterface(pdoc_) {
523 lexCurrent = 0;
524 performingStyle = false;
525 interfaceVersion = lvOriginal;
526 lexLanguage = SCLEX_CONTAINER;
529 LexState::~LexState() {
530 if (instance) {
531 instance->Release();
532 instance = 0;
536 LexState *ScintillaBase::DocumentLexState() {
537 if (!pdoc->pli) {
538 pdoc->pli = new LexState(pdoc);
540 return static_cast<LexState *>(pdoc->pli);
543 void LexState::SetLexerModule(const LexerModule *lex) {
544 if (lex != lexCurrent) {
545 if (instance) {
546 instance->Release();
547 instance = 0;
549 interfaceVersion = lvOriginal;
550 lexCurrent = lex;
551 if (lexCurrent) {
552 instance = lexCurrent->Create();
553 interfaceVersion = instance->Version();
555 pdoc->LexerChanged();
559 void LexState::SetLexer(uptr_t wParam) {
560 lexLanguage = wParam;
561 if (lexLanguage == SCLEX_CONTAINER) {
562 SetLexerModule(0);
563 } else {
564 const LexerModule *lex = Catalogue::Find(lexLanguage);
565 if (!lex)
566 lex = Catalogue::Find(SCLEX_NULL);
567 SetLexerModule(lex);
571 void LexState::SetLexerLanguage(const char *languageName) {
572 const LexerModule *lex = Catalogue::Find(languageName);
573 if (!lex)
574 lex = Catalogue::Find(SCLEX_NULL);
575 if (lex)
576 lexLanguage = lex->GetLanguage();
577 SetLexerModule(lex);
580 const char *LexState::DescribeWordListSets() {
581 if (instance) {
582 return instance->DescribeWordListSets();
583 } else {
584 return 0;
588 void LexState::SetWordList(int n, const char *wl) {
589 if (instance) {
590 int firstModification = instance->WordListSet(n, wl);
591 if (firstModification >= 0) {
592 pdoc->ModifiedAt(firstModification);
597 int LexState::GetStyleBitsNeeded() const {
598 return lexCurrent ? lexCurrent->GetStyleBitsNeeded() : 5;
601 const char *LexState::GetName() const {
602 return lexCurrent ? lexCurrent->languageName : "";
605 void *LexState::PrivateCall(int operation, void *pointer) {
606 if (pdoc && instance) {
607 return instance->PrivateCall(operation, pointer);
608 } else {
609 return 0;
613 const char *LexState::PropertyNames() {
614 if (instance) {
615 return instance->PropertyNames();
616 } else {
617 return 0;
621 int LexState::PropertyType(const char *name) {
622 if (instance) {
623 return instance->PropertyType(name);
624 } else {
625 return SC_TYPE_BOOLEAN;
629 const char *LexState::DescribeProperty(const char *name) {
630 if (instance) {
631 return instance->DescribeProperty(name);
632 } else {
633 return 0;
637 void LexState::PropSet(const char *key, const char *val) {
638 props.Set(key, val);
639 if (instance) {
640 int firstModification = instance->PropertySet(key, val);
641 if (firstModification >= 0) {
642 pdoc->ModifiedAt(firstModification);
647 const char *LexState::PropGet(const char *key) const {
648 return props.Get(key);
651 int LexState::PropGetInt(const char *key, int defaultValue) const {
652 return props.GetInt(key, defaultValue);
655 int LexState::PropGetExpanded(const char *key, char *result) const {
656 return props.GetExpanded(key, result);
659 int LexState::LineEndTypesSupported() {
660 if (instance && (interfaceVersion >= lvSubStyles)) {
661 return static_cast<ILexerWithSubStyles *>(instance)->LineEndTypesSupported();
663 return 0;
666 int LexState::AllocateSubStyles(int styleBase, int numberStyles) {
667 if (instance && (interfaceVersion >= lvSubStyles)) {
668 return static_cast<ILexerWithSubStyles *>(instance)->AllocateSubStyles(styleBase, numberStyles);
670 return -1;
673 int LexState::SubStylesStart(int styleBase) {
674 if (instance && (interfaceVersion >= lvSubStyles)) {
675 return static_cast<ILexerWithSubStyles *>(instance)->SubStylesStart(styleBase);
677 return -1;
680 int LexState::SubStylesLength(int styleBase) {
681 if (instance && (interfaceVersion >= lvSubStyles)) {
682 return static_cast<ILexerWithSubStyles *>(instance)->SubStylesLength(styleBase);
684 return 0;
687 int LexState::StyleFromSubStyle(int subStyle) {
688 if (instance && (interfaceVersion >= lvSubStyles)) {
689 return static_cast<ILexerWithSubStyles *>(instance)->StyleFromSubStyle(subStyle);
691 return 0;
694 int LexState::PrimaryStyleFromStyle(int style) {
695 if (instance && (interfaceVersion >= lvSubStyles)) {
696 return static_cast<ILexerWithSubStyles *>(instance)->PrimaryStyleFromStyle(style);
698 return 0;
701 void LexState::FreeSubStyles() {
702 if (instance && (interfaceVersion >= lvSubStyles)) {
703 static_cast<ILexerWithSubStyles *>(instance)->FreeSubStyles();
707 void LexState::SetIdentifiers(int style, const char *identifiers) {
708 if (instance && (interfaceVersion >= lvSubStyles)) {
709 static_cast<ILexerWithSubStyles *>(instance)->SetIdentifiers(style, identifiers);
713 int LexState::DistanceToSecondaryStyles() {
714 if (instance && (interfaceVersion >= lvSubStyles)) {
715 return static_cast<ILexerWithSubStyles *>(instance)->DistanceToSecondaryStyles();
717 return 0;
720 const char *LexState::GetSubStyleBases() {
721 if (instance && (interfaceVersion >= lvSubStyles)) {
722 return static_cast<ILexerWithSubStyles *>(instance)->GetSubStyleBases();
724 return "";
727 #endif
729 void ScintillaBase::NotifyStyleToNeeded(int endStyleNeeded) {
730 #ifdef SCI_LEXER
731 if (DocumentLexState()->lexLanguage != SCLEX_CONTAINER) {
732 int lineEndStyled = pdoc->LineFromPosition(pdoc->GetEndStyled());
733 int endStyled = pdoc->LineStart(lineEndStyled);
734 DocumentLexState()->Colourise(endStyled, endStyleNeeded);
735 return;
737 #endif
738 Editor::NotifyStyleToNeeded(endStyleNeeded);
741 void ScintillaBase::NotifyLexerChanged(Document *, void *) {
742 #ifdef SCI_LEXER
743 int bits = DocumentLexState()->GetStyleBitsNeeded();
744 vs.EnsureStyle((1 << bits) - 1);
745 #endif
748 sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
749 switch (iMessage) {
750 case SCI_AUTOCSHOW:
751 listType = 0;
752 AutoCompleteStart(wParam, reinterpret_cast<const char *>(lParam));
753 break;
755 case SCI_AUTOCCANCEL:
756 ac.Cancel();
757 break;
759 case SCI_AUTOCACTIVE:
760 return ac.Active();
762 case SCI_AUTOCPOSSTART:
763 return ac.posStart;
765 case SCI_AUTOCCOMPLETE:
766 AutoCompleteCompleted();
767 break;
769 case SCI_AUTOCSETSEPARATOR:
770 ac.SetSeparator(static_cast<char>(wParam));
771 break;
773 case SCI_AUTOCGETSEPARATOR:
774 return ac.GetSeparator();
776 case SCI_AUTOCSTOPS:
777 ac.SetStopChars(reinterpret_cast<char *>(lParam));
778 break;
780 case SCI_AUTOCSELECT:
781 ac.Select(reinterpret_cast<char *>(lParam));
782 break;
784 case SCI_AUTOCGETCURRENT:
785 return AutoCompleteGetCurrent();
787 case SCI_AUTOCGETCURRENTTEXT:
788 return AutoCompleteGetCurrentText(reinterpret_cast<char *>(lParam));
790 case SCI_AUTOCSETCANCELATSTART:
791 ac.cancelAtStartPos = wParam != 0;
792 break;
794 case SCI_AUTOCGETCANCELATSTART:
795 return ac.cancelAtStartPos;
797 case SCI_AUTOCSETFILLUPS:
798 ac.SetFillUpChars(reinterpret_cast<char *>(lParam));
799 break;
801 case SCI_AUTOCSETCHOOSESINGLE:
802 ac.chooseSingle = wParam != 0;
803 break;
805 case SCI_AUTOCGETCHOOSESINGLE:
806 return ac.chooseSingle;
808 case SCI_AUTOCSETIGNORECASE:
809 ac.ignoreCase = wParam != 0;
810 break;
812 case SCI_AUTOCGETIGNORECASE:
813 return ac.ignoreCase;
815 case SCI_AUTOCSETCASEINSENSITIVEBEHAVIOUR:
816 ac.ignoreCaseBehaviour = wParam;
817 break;
819 case SCI_AUTOCGETCASEINSENSITIVEBEHAVIOUR:
820 return ac.ignoreCaseBehaviour;
822 case SCI_AUTOCSETORDER:
823 ac.autoSort = wParam;
824 break;
826 case SCI_AUTOCGETORDER:
827 return ac.autoSort;
829 case SCI_USERLISTSHOW:
830 listType = wParam;
831 AutoCompleteStart(0, reinterpret_cast<const char *>(lParam));
832 break;
834 case SCI_AUTOCSETAUTOHIDE:
835 ac.autoHide = wParam != 0;
836 break;
838 case SCI_AUTOCGETAUTOHIDE:
839 return ac.autoHide;
841 case SCI_AUTOCSETDROPRESTOFWORD:
842 ac.dropRestOfWord = wParam != 0;
843 break;
845 case SCI_AUTOCGETDROPRESTOFWORD:
846 return ac.dropRestOfWord;
848 case SCI_AUTOCSETMAXHEIGHT:
849 ac.lb->SetVisibleRows(wParam);
850 break;
852 case SCI_AUTOCGETMAXHEIGHT:
853 return ac.lb->GetVisibleRows();
855 case SCI_AUTOCSETMAXWIDTH:
856 maxListWidth = wParam;
857 break;
859 case SCI_AUTOCGETMAXWIDTH:
860 return maxListWidth;
862 case SCI_REGISTERIMAGE:
863 ac.lb->RegisterImage(wParam, reinterpret_cast<const char *>(lParam));
864 break;
866 case SCI_REGISTERRGBAIMAGE:
867 ac.lb->RegisterRGBAImage(wParam, sizeRGBAImage.x, sizeRGBAImage.y, reinterpret_cast<unsigned char *>(lParam));
868 break;
870 case SCI_CLEARREGISTEREDIMAGES:
871 ac.lb->ClearRegisteredImages();
872 break;
874 case SCI_AUTOCSETTYPESEPARATOR:
875 ac.SetTypesep(static_cast<char>(wParam));
876 break;
878 case SCI_AUTOCGETTYPESEPARATOR:
879 return ac.GetTypesep();
881 case SCI_CALLTIPSHOW:
882 CallTipShow(LocationFromPosition(wParam),
883 reinterpret_cast<const char *>(lParam));
884 break;
886 case SCI_CALLTIPCANCEL:
887 ct.CallTipCancel();
888 break;
890 case SCI_CALLTIPACTIVE:
891 return ct.inCallTipMode;
893 case SCI_CALLTIPPOSSTART:
894 return ct.posStartCallTip;
896 case SCI_CALLTIPSETPOSSTART:
897 ct.posStartCallTip = wParam;
898 break;
900 case SCI_CALLTIPSETHLT:
901 ct.SetHighlight(wParam, lParam);
902 break;
904 case SCI_CALLTIPSETBACK:
905 ct.colourBG = ColourDesired(wParam);
906 vs.styles[STYLE_CALLTIP].back = ct.colourBG;
907 InvalidateStyleRedraw();
908 break;
910 case SCI_CALLTIPSETFORE:
911 ct.colourUnSel = ColourDesired(wParam);
912 vs.styles[STYLE_CALLTIP].fore = ct.colourUnSel;
913 InvalidateStyleRedraw();
914 break;
916 case SCI_CALLTIPSETFOREHLT:
917 ct.colourSel = ColourDesired(wParam);
918 InvalidateStyleRedraw();
919 break;
921 case SCI_CALLTIPUSESTYLE:
922 ct.SetTabSize((int)wParam);
923 InvalidateStyleRedraw();
924 break;
926 case SCI_CALLTIPSETPOSITION:
927 ct.SetPosition(wParam != 0);
928 InvalidateStyleRedraw();
929 break;
931 case SCI_USEPOPUP:
932 displayPopupMenu = wParam != 0;
933 break;
935 #ifdef SCI_LEXER
936 case SCI_SETLEXER:
937 DocumentLexState()->SetLexer(wParam);
938 break;
940 case SCI_GETLEXER:
941 return DocumentLexState()->lexLanguage;
943 case SCI_COLOURISE:
944 if (DocumentLexState()->lexLanguage == SCLEX_CONTAINER) {
945 pdoc->ModifiedAt(wParam);
946 NotifyStyleToNeeded((lParam == -1) ? pdoc->Length() : lParam);
947 } else {
948 DocumentLexState()->Colourise(wParam, lParam);
950 Redraw();
951 break;
953 case SCI_SETPROPERTY:
954 DocumentLexState()->PropSet(reinterpret_cast<const char *>(wParam),
955 reinterpret_cast<const char *>(lParam));
956 break;
958 case SCI_GETPROPERTY:
959 return StringResult(lParam, DocumentLexState()->PropGet(reinterpret_cast<const char *>(wParam)));
961 case SCI_GETPROPERTYEXPANDED:
962 return DocumentLexState()->PropGetExpanded(reinterpret_cast<const char *>(wParam),
963 reinterpret_cast<char *>(lParam));
965 case SCI_GETPROPERTYINT:
966 return DocumentLexState()->PropGetInt(reinterpret_cast<const char *>(wParam), lParam);
968 case SCI_SETKEYWORDS:
969 DocumentLexState()->SetWordList(wParam, reinterpret_cast<const char *>(lParam));
970 break;
972 case SCI_SETLEXERLANGUAGE:
973 DocumentLexState()->SetLexerLanguage(reinterpret_cast<const char *>(lParam));
974 break;
976 case SCI_GETLEXERLANGUAGE:
977 return StringResult(lParam, DocumentLexState()->GetName());
979 case SCI_PRIVATELEXERCALL:
980 return reinterpret_cast<sptr_t>(
981 DocumentLexState()->PrivateCall(wParam, reinterpret_cast<void *>(lParam)));
983 case SCI_GETSTYLEBITSNEEDED:
984 return DocumentLexState()->GetStyleBitsNeeded();
986 case SCI_PROPERTYNAMES:
987 return StringResult(lParam, DocumentLexState()->PropertyNames());
989 case SCI_PROPERTYTYPE:
990 return DocumentLexState()->PropertyType(reinterpret_cast<const char *>(wParam));
992 case SCI_DESCRIBEPROPERTY:
993 return StringResult(lParam, DocumentLexState()->DescribeProperty(reinterpret_cast<const char *>(wParam)));
995 case SCI_DESCRIBEKEYWORDSETS:
996 return StringResult(lParam, DocumentLexState()->DescribeWordListSets());
998 case SCI_GETLINEENDTYPESSUPPORTED:
999 return DocumentLexState()->LineEndTypesSupported();
1001 case SCI_ALLOCATESUBSTYLES:
1002 return DocumentLexState()->AllocateSubStyles(wParam, lParam);
1004 case SCI_GETSUBSTYLESSTART:
1005 return DocumentLexState()->SubStylesStart(wParam);
1007 case SCI_GETSUBSTYLESLENGTH:
1008 return DocumentLexState()->SubStylesLength(wParam);
1010 case SCI_GETSTYLEFROMSUBSTYLE:
1011 return DocumentLexState()->StyleFromSubStyle(wParam);
1013 case SCI_GETPRIMARYSTYLEFROMSTYLE:
1014 return DocumentLexState()->PrimaryStyleFromStyle(wParam);
1016 case SCI_FREESUBSTYLES:
1017 DocumentLexState()->FreeSubStyles();
1018 break;
1020 case SCI_SETIDENTIFIERS:
1021 DocumentLexState()->SetIdentifiers(wParam, reinterpret_cast<const char *>(lParam));
1022 break;
1024 case SCI_DISTANCETOSECONDARYSTYLES:
1025 return DocumentLexState()->DistanceToSecondaryStyles();
1027 case SCI_GETSUBSTYLEBASES:
1028 return StringResult(lParam, DocumentLexState()->GetSubStyleBases());
1029 #endif
1031 default:
1032 return Editor::WndProc(iMessage, wParam, lParam);
1034 return 0l;