1 ////////////////////////////////////////////////////////////////////////////
3 // Purpose: A wxWindows implementation of Scintilla. This class is the
4 // one meant to be used directly by wx applications. It does not
5 // derive directly from the Scintilla classes, but instead
6 // delegates most things to the real Scintilla class.
7 // This allows the use of Scintilla without polluting the
8 // namespace with all the classes and identifiers from Scintilla.
12 // Created: 13-Jan-2000
14 // Copyright: (c) 2000 by Total Control Software
15 // Licence: wxWindows license
16 /////////////////////////////////////////////////////////////////////////////
20 #include "wx/stc/stc.h"
21 #include "ScintillaWX.h"
23 #include <wx/tokenzr.h>
25 // The following code forces a reference to all of the Scintilla lexers.
26 // If we don't do something like this, then the linker tends to "optimize"
27 // them away. (eric@sourcegear.com)
29 int wxForceScintillaLexers(void)
31 extern LexerModule lmCPP
;
32 extern LexerModule lmHTML
;
33 extern LexerModule lmXML
;
34 extern LexerModule lmProps
;
35 extern LexerModule lmErrorList
;
36 extern LexerModule lmMake
;
37 extern LexerModule lmBatch
;
38 extern LexerModule lmPerl
;
39 extern LexerModule lmPython
;
40 extern LexerModule lmSQL
;
41 extern LexerModule lmVB
;
65 //----------------------------------------------------------------------
67 const wxChar
* wxSTCNameStr
= "stcwindow";
69 BEGIN_EVENT_TABLE(wxStyledTextCtrl
, wxControl
)
70 EVT_PAINT (wxStyledTextCtrl::OnPaint
)
71 EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin
)
72 EVT_SIZE (wxStyledTextCtrl::OnSize
)
73 EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown
)
74 EVT_MOTION (wxStyledTextCtrl::OnMouseMove
)
75 EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp
)
76 EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp
)
77 EVT_CHAR (wxStyledTextCtrl::OnChar
)
78 EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus
)
79 EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus
)
80 EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged
)
81 EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground
)
82 EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu
)
85 //----------------------------------------------------------------------
86 // Constructor and Destructor
88 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow
*parent
,
93 const wxString
& name
) :
94 wxControl(parent
, id
, pos
, size
,
95 style
| wxVSCROLL
| wxHSCROLL
| wxWANTS_CHARS
,
96 wxDefaultValidator
, name
)
98 m_swx
= new ScintillaWX(this);
99 // m_keywords = new WordList;
102 m_undoType
= wxSTC_UndoCollectAutoStart
;
106 wxStyledTextCtrl::~wxStyledTextCtrl() {
108 // delete m_keywords;
112 //----------------------------------------------------------------------
114 inline long wxStyledTextCtrl::SendMsg(int msg
, long wp
, long lp
) {
116 return m_swx
->WndProc(msg
, wp
, lp
);
120 //----------------------------------------------------------------------
121 // Text retrieval and modification
123 wxString
wxStyledTextCtrl::GetText() {
125 int len
= GetTextLength();
126 char* buff
= text
.GetWriteBuf(len
);
128 SendMsg(WM_GETTEXT
, len
, (long)buff
);
129 text
.UngetWriteBuf();
134 bool wxStyledTextCtrl::SetText(const wxString
& text
) {
135 return SendMsg(WM_SETTEXT
, 0, (long)text
.c_str()) != 0;
139 wxString
wxStyledTextCtrl::GetLine(int line
) {
141 int len
= GetLineLength(line
);
142 char* buff
= text
.GetWriteBuf(len
+1);
144 *((WORD
*)buff
) = len
+1;
145 SendMsg(EM_GETLINE
, line
, (long)buff
);
146 text
.UngetWriteBuf();
151 void wxStyledTextCtrl::ReplaceSelection(const wxString
& text
) {
152 SendMsg(EM_REPLACESEL
, 0, (long)text
.c_str());
156 void wxStyledTextCtrl::SetReadOnly(bool readOnly
) {
157 SendMsg(EM_SETREADONLY
, (long)readOnly
);
158 m_readOnly
= readOnly
;
162 bool wxStyledTextCtrl::GetReadOnly() {
163 // TODO: need support in Scintilla to do this right,
164 // until then we'll track it ourselves
169 void wxStyledTextCtrl::GetTextRange(int startPos
, int endPos
, char* buff
) {
172 tr
.chrg
.cpMin
= startPos
;
173 tr
.chrg
.cpMax
= endPos
;
174 SendMsg(EM_GETTEXTRANGE
, 0, (long)&tr
);
178 wxString
wxStyledTextCtrl::GetTextRange(int startPos
, int endPos
) {
180 int len
= endPos
- startPos
;
181 char* buff
= text
.GetWriteBuf(len
);
182 GetTextRange(startPos
, endPos
, buff
);
183 text
.UngetWriteBuf();
188 void wxStyledTextCtrl::GetStyledTextRange(int startPos
, int endPos
, char* buff
) {
191 tr
.chrg
.cpMin
= startPos
;
192 tr
.chrg
.cpMax
= endPos
;
193 SendMsg(SCI_GETSTYLEDTEXT
, 0, (long)&tr
);
197 wxString
wxStyledTextCtrl::GetStyledTextRange(int startPos
, int endPos
) {
199 int len
= endPos
- startPos
;
200 char* buff
= text
.GetWriteBuf(len
*2);
201 GetStyledTextRange(startPos
, endPos
, buff
);
202 text
.UngetWriteBuf(len
*2);
207 void wxStyledTextCtrl::AddText(const wxString
& text
) {
208 SendMsg(SCI_ADDTEXT
, text
.Len(), (long)text
.c_str());
212 void wxStyledTextCtrl::AddStyledText(const wxString
& text
) {
213 SendMsg(SCI_ADDSTYLEDTEXT
, text
.Len(), (long)text
.c_str());
217 void wxStyledTextCtrl::InsertText(int pos
, const wxString
& text
) {
218 SendMsg(SCI_INSERTTEXT
, pos
, (long)text
.c_str());
222 void wxStyledTextCtrl::ClearAll() {
223 SendMsg(SCI_CLEARALL
);
227 char wxStyledTextCtrl::GetCharAt(int pos
) {
228 return SendMsg(SCI_GETCHARAT
, pos
);
232 char wxStyledTextCtrl::GetStyleAt(int pos
) {
233 return SendMsg(SCI_GETSTYLEAT
, pos
);
237 void wxStyledTextCtrl::SetStyleBits(int bits
) {
238 SendMsg(SCI_SETSTYLEBITS
, bits
);
242 int wxStyledTextCtrl::GetStyleBits() {
243 return SendMsg(SCI_GETSTYLEBITS
);
247 //----------------------------------------------------------------------
251 void wxStyledTextCtrl::Cut() {
256 void wxStyledTextCtrl::Copy() {
261 void wxStyledTextCtrl::Paste() {
266 bool wxStyledTextCtrl::CanPaste() {
267 return SendMsg(EM_CANPASTE
) != 0;
271 void wxStyledTextCtrl::ClearClipbrd() {
277 //----------------------------------------------------------------------
280 void wxStyledTextCtrl::Undo() {
285 bool wxStyledTextCtrl::CanUndo() {
286 return SendMsg(EM_CANUNDO
) != 0;
290 void wxStyledTextCtrl::EmptyUndoBuffer() {
291 SendMsg(EM_EMPTYUNDOBUFFER
);
295 void wxStyledTextCtrl::Redo() {
300 bool wxStyledTextCtrl::CanRedo() {
301 return SendMsg(SCI_CANREDO
) != 0;
305 void wxStyledTextCtrl::SetUndoCollection(wxSTC_UndoType type
) {
306 SendMsg(SCI_SETUNDOCOLLECTION
, type
);
311 wxSTC_UndoType
wxStyledTextCtrl::GetUndoCollection() {
312 // TODO: need support in Scintilla to do this right,
313 // until then we'll track it ourselves
318 void wxStyledTextCtrl::BeginUndoAction() {
319 SendMsg(SCI_BEGINUNDOACTION
);
323 void wxStyledTextCtrl::EndUndoAction() {
324 SendMsg(SCI_ENDUNDOACTION
);
330 //----------------------------------------------------------------------
331 // Selection and information
334 void wxStyledTextCtrl::GetSelection(int* startPos
, int* endPos
) {
335 SendMsg(EM_GETSEL
, (long)startPos
, (long)endPos
);
339 void wxStyledTextCtrl::SetSelection(int startPos
, int endPos
) {
340 SendMsg(EM_SETSEL
, startPos
, endPos
);
344 wxString
wxStyledTextCtrl::GetSelectedText() {
349 GetSelection(&start
, &end
);
350 int len
= end
- start
;
351 char* buff
= text
.GetWriteBuf(len
);
353 SendMsg(EM_GETSELTEXT
, 0, (long)buff
);
354 text
.UngetWriteBuf();
359 void wxStyledTextCtrl::HideSelection(bool hide
) {
360 SendMsg(EM_HIDESELECTION
, hide
);
364 bool wxStyledTextCtrl::GetHideSelection() {
365 return m_swx
->GetHideSelection();
369 int wxStyledTextCtrl::GetTextLength() {
370 return SendMsg(WM_GETTEXTLENGTH
);
374 int wxStyledTextCtrl::GetFirstVisibleLine() {
375 return SendMsg(EM_GETFIRSTVISIBLELINE
);
379 int wxStyledTextCtrl::GetLineCount() {
380 return SendMsg(EM_GETLINECOUNT
);
384 bool wxStyledTextCtrl::GetModified() {
385 return SendMsg(EM_GETMODIFY
) != 0;
389 wxRect
wxStyledTextCtrl::GetRect() {
391 SendMsg(EM_GETRECT
, 0, (long)&pr
);
393 wxRect rect
= wxRectFromPRectangle(pr
);
398 int wxStyledTextCtrl::GetLineFromPos(int pos
) {
399 return SendMsg(EM_LINEFROMCHAR
, pos
);
403 int wxStyledTextCtrl::GetLineStartPos(int line
) {
404 return SendMsg(EM_LINEINDEX
, line
);
408 int wxStyledTextCtrl::GetLineLengthAtPos(int pos
) {
409 return SendMsg(EM_LINELENGTH
, pos
);
413 int wxStyledTextCtrl::GetLineLength(int line
) {
414 return SendMsg(SCI_LINELENGTH
, line
);
418 int wxStyledTextCtrl::GetCurrentLine() {
419 int line
= GetLineFromPos(GetCurrentPos());
424 wxString
wxStyledTextCtrl::GetCurrentLineText(int* linePos
) {
426 int len
= GetLineLength(GetCurrentLine());
427 char* buff
= text
.GetWriteBuf(len
+1);
429 int pos
= SendMsg(SCI_GETCURLINE
, len
+1, (long)buff
);
430 text
.UngetWriteBuf();
439 int wxStyledTextCtrl::PositionFromPoint(wxPoint pt
) {
440 Point
spt(pt
.x
, pt
.y
);
441 long rv
= SendMsg(EM_CHARFROMPOS
, 0, (long)&spt
);
446 int wxStyledTextCtrl::LineFromPoint(wxPoint pt
) {
447 Point
spt(pt
.x
, pt
.y
);
448 long rv
= SendMsg(EM_CHARFROMPOS
, 0, (long)&spt
);
453 wxPoint
wxStyledTextCtrl::PointFromPosition(int pos
) {
455 SendMsg(EM_POSFROMCHAR
, pos
, (long)&pt
);
456 return wxPoint(pt
.x
, pt
.y
);
460 int wxStyledTextCtrl::GetCurrentPos() {
461 return SendMsg(SCI_GETCURRENTPOS
);
465 int wxStyledTextCtrl::GetAnchor() {
466 return SendMsg(SCI_GETANCHOR
);
470 void wxStyledTextCtrl::SelectAll() {
471 SendMsg(SCI_SELECTALL
);
475 void wxStyledTextCtrl::SetCurrentPosition(int pos
) {
476 SendMsg(SCI_GOTOPOS
, pos
);
480 void wxStyledTextCtrl::SetAnchor(int pos
) {
481 SendMsg(SCI_SETANCHOR
, pos
);
485 void wxStyledTextCtrl::GotoPos(int pos
) {
486 SendMsg(SCI_GOTOPOS
, pos
);
490 void wxStyledTextCtrl::GotoLine(int line
) {
491 SendMsg(SCI_GOTOLINE
, line
);
495 void wxStyledTextCtrl::ChangePosition(int delta
, bool extendSelection
) {
496 // TODO: Is documented but doesn't seem to be implemented
497 //SendMsg(SCI_CHANGEPOSITION, delta, extendSelection);
501 void wxStyledTextCtrl::PageMove(int cmdKey
, bool extendSelection
) {
502 // TODO: Is documented but doesn't seem to be implemented
503 //SendMsg(SCI_PAGEMOVE, cmdKey, extendSelection);
507 void wxStyledTextCtrl::ScrollBy(int columnDelta
, int lineDelta
) {
508 SendMsg(EM_LINESCROLL
, columnDelta
, lineDelta
);
511 void wxStyledTextCtrl::ScrollToLine(int line
) {
512 m_swx
->DoScrollToLine(line
);
516 void wxStyledTextCtrl::ScrollToColumn(int column
) {
517 m_swx
->DoScrollToColumn(column
);
521 void wxStyledTextCtrl::EnsureCaretVisible() {
522 SendMsg(EM_SCROLLCARET
);
526 void wxStyledTextCtrl::SetCaretPolicy(int policy
, int slop
) {
527 SendMsg(SCI_SETCARETPOLICY
, policy
, slop
);
531 int wxStyledTextCtrl::GetSelectionType() {
532 return SendMsg(EM_SELECTIONTYPE
);
538 //----------------------------------------------------------------------
541 int wxStyledTextCtrl::FindText(int minPos
, int maxPos
,
542 const wxString
& text
,
543 bool caseSensitive
, bool wholeWord
) {
547 flags
|= caseSensitive
? FR_MATCHCASE
: 0;
548 flags
|= wholeWord
? FR_WHOLEWORD
: 0;
549 ft
.chrg
.cpMin
= minPos
;
550 ft
.chrg
.cpMax
= maxPos
;
551 ft
.lpstrText
= (char*)text
.c_str();
553 return SendMsg(EM_FINDTEXT
, flags
, (long)&ft
);
557 void wxStyledTextCtrl::SearchAnchor() {
558 SendMsg(SCI_SEARCHANCHOR
);
562 int wxStyledTextCtrl::SearchNext(const wxString
& text
, bool caseSensitive
, bool wholeWord
) {
564 flags
|= caseSensitive
? FR_MATCHCASE
: 0;
565 flags
|= wholeWord
? FR_WHOLEWORD
: 0;
567 return SendMsg(SCI_SEARCHNEXT
, flags
, (long)text
.c_str());
571 int wxStyledTextCtrl::SearchPrev(const wxString
& text
, bool caseSensitive
, bool wholeWord
) {
573 flags
|= caseSensitive
? FR_MATCHCASE
: 0;
574 flags
|= wholeWord
? FR_WHOLEWORD
: 0;
576 return SendMsg(SCI_SEARCHPREV
, flags
, (long)text
.c_str());
579 //----------------------------------------------------------------------
580 // Visible whitespace
583 bool wxStyledTextCtrl::GetViewWhitespace() {
584 return SendMsg(SCI_GETVIEWWS
) != 0;
588 void wxStyledTextCtrl::SetViewWhitespace(bool visible
) {
589 SendMsg(SCI_SETVIEWWS
, visible
);
594 //----------------------------------------------------------------------
597 wxSTC_EOL
wxStyledTextCtrl::GetEOLMode() {
598 return (wxSTC_EOL
)SendMsg(SCI_GETEOLMODE
);
602 void wxStyledTextCtrl::SetEOLMode(wxSTC_EOL mode
) {
603 SendMsg(SCI_SETEOLMODE
, mode
);
607 bool wxStyledTextCtrl::GetViewEOL() {
608 return SendMsg(SCI_GETVIEWEOL
) != 0;
612 void wxStyledTextCtrl::SetViewEOL(bool visible
) {
613 SendMsg(SCI_SETVIEWEOL
, visible
);
616 void wxStyledTextCtrl::ConvertEOL(wxSTC_EOL mode
) {
617 SendMsg(SCI_CONVERTEOLS
, mode
);
620 //----------------------------------------------------------------------
623 int wxStyledTextCtrl::GetEndStyled() {
624 return SendMsg(SCI_GETENDSTYLED
);
628 void wxStyledTextCtrl::StartStyling(int pos
, int mask
) {
629 SendMsg(SCI_STARTSTYLING
, pos
, mask
);
633 void wxStyledTextCtrl::SetStyleFor(int length
, int style
) {
634 SendMsg(SCI_SETSTYLING
, length
, style
);
638 void wxStyledTextCtrl::SetStyleBytes(int length
, char* styleBytes
) {
639 SendMsg(SCI_SETSTYLINGEX
, length
, (long)styleBytes
);
643 //----------------------------------------------------------------------
647 static long wxColourAsLong(const wxColour
& co
) {
648 return (((long)co
.Blue() << 16) |
649 ((long)co
.Green() << 8) |
653 static wxColour
wxColourFromLong(long c
) {
655 clr
.Set(c
& 0xff, (c
>> 8) & 0xff, (c
>> 16) & 0xff);
660 static wxColour
wxColourFromSpec(const wxString
& spec
) {
661 // spec should be #RRGGBB
663 int red
= strtol(spec
.Mid(1,2), &junk
, 16);
664 int green
= strtol(spec
.Mid(3,2), &junk
, 16);
665 int blue
= strtol(spec
.Mid(5,2), &junk
, 16);
666 return wxColour(red
, green
, blue
);
670 void wxStyledTextCtrl::StyleClearAll() {
671 SendMsg(SCI_STYLECLEARALL
);
675 void wxStyledTextCtrl::StyleResetDefault() {
676 SendMsg(SCI_STYLERESETDEFAULT
);
681 // Extract style settings from a spec-string which is composed of one or
682 // more of the following comma separated elements:
684 // bold turns on bold
685 // italic turns on italics
686 // fore:#RRGGBB sets the foreground colour
687 // back:#RRGGBB sets the background colour
688 // face:[facename] sets the font face name to use
689 // size:[num] sets the font size in points
690 // eol turns on eol filling
693 void wxStyledTextCtrl::StyleSetSpec(int styleNum
, const wxString
& spec
) {
695 wxStringTokenizer
tkz(spec
, ",");
696 while (tkz
.HasMoreTokens()) {
697 wxString token
= tkz
.GetNextToken();
699 wxString option
= token
.BeforeFirst(':');
700 wxString val
= token
.AfterFirst(':');
702 if (option
== "bold")
703 StyleSetBold(styleNum
, true);
705 else if (option
== "italic")
706 StyleSetItalic(styleNum
, true);
708 else if (option
== "eol")
709 StyleSetEOLFilled(styleNum
, true);
711 else if (option
== "size") {
713 if (val
.ToLong(&points
))
714 StyleSetSize(styleNum
, points
);
717 else if (option
== "face")
718 StyleSetFaceName(styleNum
, val
);
720 else if (option
== "fore")
721 StyleSetForeground(styleNum
, wxColourFromSpec(val
));
723 else if (option
== "back")
724 StyleSetBackground(styleNum
, wxColourFromSpec(val
));
729 void wxStyledTextCtrl::StyleSetForeground(int styleNum
, const wxColour
& colour
) {
730 SendMsg(SCI_STYLESETFORE
, styleNum
, wxColourAsLong(colour
));
734 void wxStyledTextCtrl::StyleSetBackground(int styleNum
, const wxColour
& colour
) {
735 SendMsg(SCI_STYLESETBACK
, styleNum
, wxColourAsLong(colour
));
739 void wxStyledTextCtrl::StyleSetFont(int styleNum
, wxFont
& font
) {
740 int size
= font
.GetPointSize();
741 wxString faceName
= font
.GetFaceName();
742 bool bold
= font
.GetWeight() == wxBOLD
;
743 bool italic
= font
.GetStyle() != wxNORMAL
;
745 StyleSetFontAttr(styleNum
, size
, faceName
, bold
, italic
);
749 void wxStyledTextCtrl::StyleSetFontAttr(int styleNum
, int size
,
750 const wxString
& faceName
,
751 bool bold
, bool italic
) {
752 StyleSetSize(styleNum
, size
);
753 StyleSetFaceName(styleNum
, faceName
);
754 StyleSetBold(styleNum
, bold
);
755 StyleSetItalic(styleNum
, italic
);
759 void wxStyledTextCtrl::StyleSetBold(int styleNum
, bool bold
) {
760 SendMsg(SCI_STYLESETBOLD
, styleNum
, bold
);
764 void wxStyledTextCtrl::StyleSetItalic(int styleNum
, bool italic
) {
765 SendMsg(SCI_STYLESETITALIC
, styleNum
, italic
);
769 void wxStyledTextCtrl::StyleSetFaceName(int styleNum
, const wxString
& faceName
) {
770 SendMsg(SCI_STYLESETFONT
, styleNum
, (long)faceName
.c_str());
774 void wxStyledTextCtrl::StyleSetSize(int styleNum
, int pointSize
) {
775 SendMsg(SCI_STYLESETSIZE
, styleNum
, pointSize
);
779 void wxStyledTextCtrl::StyleSetEOLFilled(int styleNum
, bool fillEOL
) {
780 SendMsg(SCI_STYLESETEOLFILLED
, styleNum
, fillEOL
);
784 //----------------------------------------------------------------------
785 // Margins in the edit area
787 int wxStyledTextCtrl::GetLeftMargin() {
788 return LOWORD(SendMsg(EM_GETMARGINS
));
792 int wxStyledTextCtrl::GetRightMargin() {
793 return HIWORD(SendMsg(EM_GETMARGINS
));
797 void wxStyledTextCtrl::SetMargins(int left
, int right
) {
802 flag
|= EC_RIGHTMARGIN
;
806 flag
|= EC_LEFTMARGIN
;
807 val
|= (left
& 0xffff);
810 SendMsg(EM_SETMARGINS
, flag
, val
);
814 //----------------------------------------------------------------------
815 // Margins for selection, markers, etc.
817 void wxStyledTextCtrl::SetMarginType(int margin
, int type
) {
818 SendMsg(SCI_SETMARGINTYPEN
, margin
, type
);
822 int wxStyledTextCtrl::GetMarginType(int margin
) {
823 return SendMsg(SCI_GETMARGINTYPEN
, margin
);
827 void wxStyledTextCtrl::SetMarginWidth(int margin
, int pixelWidth
) {
828 SendMsg(SCI_SETMARGINWIDTHN
, margin
, pixelWidth
);
832 int wxStyledTextCtrl::GetMarginWidth(int margin
) {
833 return SendMsg(SCI_GETMARGINWIDTHN
, margin
);
837 void wxStyledTextCtrl::SetMarginMask(int margin
, int mask
) {
838 SendMsg(SCI_SETMARGINMASKN
, margin
, mask
);
842 int wxStyledTextCtrl::GetMarginMask(int margin
) {
843 return SendMsg(SCI_GETMARGINMASKN
, margin
);
847 void wxStyledTextCtrl::SetMarginSensitive(int margin
, bool sensitive
) {
848 SendMsg(SCI_SETMARGINSENSITIVEN
, margin
, sensitive
);
852 bool wxStyledTextCtrl::GetMarginSensitive(int margin
) {
853 return SendMsg(SCI_GETMARGINSENSITIVEN
, margin
) != 0;
859 //----------------------------------------------------------------------
860 // Selection and Caret styles
863 void wxStyledTextCtrl::SetSelectionForeground(const wxColour
& colour
) {
864 SendMsg(SCI_SETSELFORE
, 0, wxColourAsLong(colour
));
868 void wxStyledTextCtrl::SetSelectionBackground(const wxColour
& colour
) {
869 SendMsg(SCI_SETSELBACK
, 0, wxColourAsLong(colour
));
873 void wxStyledTextCtrl::SetCaretForeground(const wxColour
& colour
) {
874 SendMsg(SCI_SETCARETFORE
, 0, wxColourAsLong(colour
));
878 int wxStyledTextCtrl::GetCaretPeriod() {
879 return SendMsg(SCI_GETCARETPERIOD
);
883 void wxStyledTextCtrl::SetCaretPeriod(int milliseconds
) {
884 SendMsg(SCI_SETCARETPERIOD
, milliseconds
);
889 //----------------------------------------------------------------------
893 void wxStyledTextCtrl::SetBufferedDraw(bool isBuffered
) {
894 SendMsg(SCI_SETBUFFEREDDRAW
, isBuffered
);
898 void wxStyledTextCtrl::SetTabWidth(int numChars
) {
899 SendMsg(SCI_SETTABWIDTH
, numChars
);
903 void wxStyledTextCtrl::SetWordChars(const wxString
& wordChars
) {
904 SendMsg(SCI_SETTABWIDTH
, 0, (long)wordChars
.c_str());
908 //----------------------------------------------------------------------
909 // Brace highlighting
912 void wxStyledTextCtrl::BraceHighlight(int pos1
, int pos2
) {
913 SendMsg(SCI_BRACEHIGHLIGHT
, pos1
, pos2
);
917 void wxStyledTextCtrl::BraceBadlight(int pos
) {
918 SendMsg(SCI_BRACEBADLIGHT
, pos
);
922 int wxStyledTextCtrl::BraceMatch(int pos
, int maxReStyle
) {
923 return SendMsg(SCI_BRACEMATCH
, pos
, maxReStyle
);
928 //----------------------------------------------------------------------
931 void wxStyledTextCtrl::MarkerDefine(int markerNumber
, int markerSymbol
,
932 const wxColour
& foreground
,
933 const wxColour
& background
) {
934 MarkerSetType(markerNumber
, markerSymbol
);
935 MarkerSetForeground(markerNumber
, foreground
);
936 MarkerSetBackground(markerNumber
, background
);
940 void wxStyledTextCtrl::MarkerSetType(int markerNumber
, int markerSymbol
) {
941 SendMsg(SCI_MARKERDEFINE
, markerNumber
, markerSymbol
);
945 void wxStyledTextCtrl::MarkerSetForeground(int markerNumber
, const wxColour
& colour
) {
946 SendMsg(SCI_MARKERSETFORE
, markerNumber
, wxColourAsLong(colour
));
950 void wxStyledTextCtrl::MarkerSetBackground(int markerNumber
, const wxColour
& colour
) {
951 SendMsg(SCI_MARKERSETBACK
, markerNumber
, wxColourAsLong(colour
));
955 int wxStyledTextCtrl::MarkerAdd(int line
, int markerNumber
) {
956 return SendMsg(SCI_MARKERADD
, line
, markerNumber
);
960 void wxStyledTextCtrl::MarkerDelete(int line
, int markerNumber
) {
961 SendMsg(SCI_MARKERDELETE
, line
, markerNumber
);
965 void wxStyledTextCtrl::MarkerDeleteAll(int markerNumber
) {
966 SendMsg(SCI_MARKERDELETEALL
, markerNumber
);
970 int wxStyledTextCtrl::MarkerGet(int line
) {
971 return SendMsg(SCI_MARKERGET
);
975 int wxStyledTextCtrl::MarkerGetNextLine(int lineStart
, int markerMask
) {
976 return SendMsg(SCI_MARKERNEXT
, lineStart
, markerMask
);
980 int wxStyledTextCtrl::MarkerGetPrevLine(int lineStart
, int markerMask
) {
981 // return SendMsg(SCI_MARKERPREV, lineStart, markerMask);
986 int wxStyledTextCtrl::MarkerLineFromHandle(int handle
) {
987 return SendMsg(SCI_MARKERLINEFROMHANDLE
, handle
);
991 void wxStyledTextCtrl::MarkerDeleteHandle(int handle
) {
992 SendMsg(SCI_MARKERDELETEHANDLE
, handle
);
997 //----------------------------------------------------------------------
1001 void wxStyledTextCtrl::IndicatorSetStyle(int indicNum
, int indicStyle
) {
1002 SendMsg(SCI_INDICSETSTYLE
, indicNum
, indicStyle
);
1006 int wxStyledTextCtrl::IndicatorGetStyle(int indicNum
) {
1007 return SendMsg(SCI_INDICGETSTYLE
, indicNum
);
1011 void wxStyledTextCtrl::IndicatorSetColour(int indicNum
, const wxColour
& colour
) {
1012 SendMsg(SCI_INDICSETSTYLE
, indicNum
, wxColourAsLong(colour
));
1017 //----------------------------------------------------------------------
1021 void wxStyledTextCtrl::AutoCompShow(const wxString
& listOfWords
) {
1022 SendMsg(SCI_AUTOCSHOW
, 0, (long)listOfWords
.c_str());
1026 void wxStyledTextCtrl::AutoCompCancel() {
1027 SendMsg(SCI_AUTOCCANCEL
);
1031 bool wxStyledTextCtrl::AutoCompActive() {
1032 return SendMsg(SCI_AUTOCACTIVE
) != 0;
1036 int wxStyledTextCtrl::AutoCompPosAtStart() {
1037 return SendMsg(SCI_AUTOCPOSSTART
);
1041 void wxStyledTextCtrl::AutoCompComplete() {
1042 SendMsg(SCI_AUTOCCOMPLETE
);
1046 void wxStyledTextCtrl::AutoCompStopChars(const wxString
& stopChars
) {
1047 SendMsg(SCI_AUTOCSHOW
, 0, (long)stopChars
.c_str());
1051 //----------------------------------------------------------------------
1054 void wxStyledTextCtrl::CallTipShow(int pos
, const wxString
& text
) {
1055 SendMsg(SCI_CALLTIPSHOW
, pos
, (long)text
.c_str());
1059 void wxStyledTextCtrl::CallTipCancel() {
1060 SendMsg(SCI_CALLTIPCANCEL
);
1064 bool wxStyledTextCtrl::CallTipActive() {
1065 return SendMsg(SCI_CALLTIPACTIVE
) != 0;
1069 int wxStyledTextCtrl::CallTipPosAtStart() {
1070 return SendMsg(SCI_CALLTIPPOSSTART
);
1074 void wxStyledTextCtrl::CallTipSetHighlight(int start
, int end
) {
1075 SendMsg(SCI_CALLTIPSETHLT
, start
, end
);
1079 void wxStyledTextCtrl::CallTipSetBackground(const wxColour
& colour
) {
1080 SendMsg(SCI_CALLTIPSETBACK
, wxColourAsLong(colour
));
1084 //----------------------------------------------------------------------
1087 void wxStyledTextCtrl::CmdKeyAssign(int key
, int modifiers
, int cmd
) {
1088 SendMsg(SCI_ASSIGNCMDKEY
, MAKELONG(key
, modifiers
), cmd
);
1092 void wxStyledTextCtrl::CmdKeyClear(int key
, int modifiers
) {
1093 SendMsg(SCI_CLEARCMDKEY
, MAKELONG(key
, modifiers
));
1097 void wxStyledTextCtrl::CmdKeyClearAll() {
1098 SendMsg(SCI_CLEARALLCMDKEYS
);
1102 void wxStyledTextCtrl::CmdKeyExecute(int cmd
) {
1108 //----------------------------------------------------------------------
1112 wxStyledTextCtrl::FormatRange(bool doDraw
,
1116 wxDC
* target
, // Why does it use two? Can they be the same?
1122 fr
.hdcTarget
= target
;
1123 fr
.rc
.top
= renderRect
.GetTop();
1124 fr
.rc
.left
= renderRect
.GetLeft();
1125 fr
.rc
.right
= renderRect
.GetRight();
1126 fr
.rc
.bottom
= renderRect
.GetBottom();
1127 fr
.rcPage
.top
= pageRect
.GetTop();
1128 fr
.rcPage
.left
= pageRect
.GetLeft();
1129 fr
.rcPage
.right
= pageRect
.GetRight();
1130 fr
.rcPage
.bottom
= pageRect
.GetBottom();
1131 fr
.chrg
.cpMin
= startPos
;
1132 fr
.chrg
.cpMax
= endPos
;
1134 return SendMsg(EM_FORMATRANGE
, doDraw
, (long)&fr
);
1138 //----------------------------------------------------------------------
1141 void* wxStyledTextCtrl::GetDocument() {
1142 return (void*)SendMsg(SCI_GETDOCPOINTER
);
1146 void wxStyledTextCtrl::SetDocument(void* document
) {
1147 SendMsg(SCI_SETDOCPOINTER
, 0, (long)document
);
1151 //----------------------------------------------------------------------
1154 int wxStyledTextCtrl::VisibleFromDocLine(int docLine
) {
1155 return SendMsg(SCI_VISIBLEFROMDOCLINE
, docLine
);
1159 int wxStyledTextCtrl::DocLineFromVisible(int displayLine
) {
1160 return SendMsg(SCI_DOCLINEFROMVISIBLE
, displayLine
);
1164 int wxStyledTextCtrl::SetFoldLevel(int line
, int level
) {
1165 return SendMsg(SCI_SETFOLDLEVEL
, line
, level
);
1169 int wxStyledTextCtrl::GetFoldLevel(int line
) {
1170 return SendMsg(SCI_GETFOLDLEVEL
, line
);
1174 int wxStyledTextCtrl::GetLastChild(int line
) {
1175 return SendMsg(SCI_GETLASTCHILD
, line
);
1179 int wxStyledTextCtrl::GetFoldParent(int line
) {
1180 return SendMsg(SCI_GETFOLDPARENT
, line
);
1184 void wxStyledTextCtrl::ShowLines(int lineStart
, int lineEnd
) {
1185 SendMsg(SCI_SHOWLINES
, lineStart
, lineEnd
);
1189 void wxStyledTextCtrl::HideLines(int lineStart
, int lineEnd
) {
1190 SendMsg(SCI_HIDELINES
, lineStart
, lineEnd
);
1194 bool wxStyledTextCtrl::GetLineVisible(int line
) {
1195 return SendMsg(SCI_GETLINEVISIBLE
, line
) != 0;
1199 void wxStyledTextCtrl::SetFoldExpanded(int line
) {
1200 SendMsg(SCI_SETFOLDEXPANDED
, line
);
1204 bool wxStyledTextCtrl::GetFoldExpanded(int line
) {
1205 return SendMsg(SCI_GETFOLDEXPANDED
, line
) != 0;
1209 void wxStyledTextCtrl::ToggleFold(int line
) {
1210 SendMsg(SCI_TOGGLEFOLD
, line
);
1214 void wxStyledTextCtrl::EnsureVisible(int line
) {
1215 SendMsg(SCI_ENSUREVISIBLE
, line
);
1219 //----------------------------------------------------------------------
1222 int wxStyledTextCtrl::GetEdgeColumn() {
1223 return SendMsg(SCI_GETEDGECOLUMN
);
1226 void wxStyledTextCtrl::SetEdgeColumn(int column
) {
1227 SendMsg(SCI_SETEDGECOLUMN
, column
);
1230 wxSTC_EDGE
wxStyledTextCtrl::GetEdgeMode() {
1231 return (wxSTC_EDGE
) SendMsg(SCI_GETEDGEMODE
);
1234 void wxStyledTextCtrl::SetEdgeMode(wxSTC_EDGE mode
){
1235 SendMsg(SCI_SETEDGEMODE
, mode
);
1238 wxColour
wxStyledTextCtrl::GetEdgeColour() {
1239 long c
= SendMsg(SCI_GETEDGECOLOUR
);
1240 return wxColourFromLong(c
);
1243 void wxStyledTextCtrl::SetEdgeColour(const wxColour
& colour
) {
1244 SendMsg(SCI_SETEDGECOLOUR
, wxColourAsLong(colour
));
1248 //----------------------------------------------------------------------
1251 void wxStyledTextCtrl::SetLexer(wxSTC_LEX lexer
) {
1252 SendMsg(SCI_SETLEXER
, lexer
);
1256 wxSTC_LEX
wxStyledTextCtrl::GetLexer() {
1257 return (wxSTC_LEX
)SendMsg(SCI_GETLEXER
);
1261 void wxStyledTextCtrl::Colourise(int start
, int end
) {
1262 SendMsg(SCI_COLOURISE
, start
, end
);
1266 void wxStyledTextCtrl::SetProperty(const wxString
& key
, const wxString
& value
) {
1267 SendMsg(SCI_SETPROPERTY
, (long)key
.c_str(), (long)value
.c_str());
1271 void wxStyledTextCtrl::SetKeywords(int keywordSet
, const wxString
& keywordList
) {
1272 SendMsg(SCI_SETKEYWORDS
, keywordSet
, (long)keywordList
.c_str());
1277 //----------------------------------------------------------------------
1280 void wxStyledTextCtrl::OnPaint(wxPaintEvent
& evt
) {
1282 wxRegion region
= GetUpdateRegion();
1284 m_swx
->DoPaint(&dc
, region
.GetBox());
1287 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent
& evt
) {
1288 if (evt
.GetOrientation() == wxHORIZONTAL
)
1289 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
1291 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
1294 void wxStyledTextCtrl::OnSize(wxSizeEvent
& evt
) {
1295 wxSize sz
= GetClientSize();
1296 m_swx
->DoSize(sz
.x
, sz
.y
);
1299 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent
& evt
) {
1300 wxPoint pt
= evt
.GetPosition();
1301 m_swx
->DoButtonDown(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1302 evt
.ShiftDown(), evt
.ControlDown(), evt
.AltDown());
1305 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent
& evt
) {
1306 wxPoint pt
= evt
.GetPosition();
1307 m_swx
->DoButtonMove(Point(pt
.x
, pt
.y
));
1310 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent
& evt
) {
1311 wxPoint pt
= evt
.GetPosition();
1312 m_swx
->DoButtonUp(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1317 void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent
& evt
) {
1318 wxPoint pt
= evt
.GetPosition();
1319 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
1322 void wxStyledTextCtrl::OnChar(wxKeyEvent
& evt
) {
1324 long key
= evt
.KeyCode();
1325 if ((key
> WXK_ESCAPE
) &&
1326 (key
!= WXK_DELETE
) && (key
< 255) &&
1327 !evt
.ControlDown() && !evt
.AltDown()) {
1329 m_swx
->DoAddChar(key
);
1334 processed
= m_swx
->DoKeyDown(key
, evt
.ShiftDown(),
1335 evt
.ControlDown(), evt
.AltDown());
1341 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent
& evt
) {
1342 m_swx
->DoLoseFocus();
1345 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent
& evt
) {
1346 m_swx
->DoGainFocus();
1349 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& evt
) {
1350 m_swx
->DoSysColourChange();
1353 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent
& evt
) {
1354 // do nothing to help avoid flashing
1359 void wxStyledTextCtrl::OnMenu(wxCommandEvent
& evt
) {
1360 m_swx
->DoCommand(evt
.GetId());
1364 //----------------------------------------------------------------------
1365 // Turn notifications from Scintilla into events
1367 void wxStyledTextCtrl::NotifyChange() {
1368 wxStyledTextEvent
evt(wxEVT_STC_CHANGE
, GetId());
1369 GetEventHandler()->ProcessEvent(evt
);
1372 void wxStyledTextCtrl::NotifyParent(SCNotification
* _scn
) {
1373 SCNotification
& scn
= *_scn
;
1375 switch (scn
.nmhdr
.code
) {
1376 case SCN_STYLENEEDED
:
1377 eventType
= wxEVT_STC_STYLENEEDED
;
1380 eventType
= wxEVT_STC_CHARADDED
;
1383 eventType
= wxEVT_STC_UPDATEUI
;
1385 case SCN_SAVEPOINTREACHED
:
1386 eventType
= wxEVT_STC_SAVEPOINTREACHED
;
1388 case SCN_SAVEPOINTLEFT
:
1389 eventType
= wxEVT_STC_SAVEPOINTLEFT
;
1391 case SCN_MODIFYATTEMPTRO
:
1392 eventType
= wxEVT_STC_ROMODIFYATTEMPT
;
1394 case SCN_DOUBLECLICK
:
1395 eventType
= wxEVT_STC_DOUBLECLICK
;
1398 eventType
= wxEVT_STC_MODIFIED
;
1401 eventType
= wxEVT_STC_KEY
;
1403 case SCN_MACRORECORD
:
1404 eventType
= wxEVT_STC_MACRORECORD
;
1406 case SCN_MARGINCLICK
:
1407 eventType
= wxEVT_STC_MARGINCLICK
;
1410 eventType
= wxEVT_STC_NEEDSHOWN
;
1414 wxStyledTextEvent
evt(eventType
, GetId());
1415 evt
.SetPosition(scn
.position
);
1417 evt
.SetModifiers(scn
.modifiers
);
1418 if (eventType
== wxEVT_STC_MODIFIED
) {
1419 evt
.SetModificationType(scn
.modificationType
);
1420 evt
.SetText(scn
.text
);
1421 evt
.SetLength(scn
.length
);
1422 evt
.SetLinesAdded(scn
.linesAdded
);
1423 evt
.SetLine(scn
.line
);
1424 evt
.SetFoldLevelNow(scn
.foldLevelNow
);
1425 evt
.SetFoldLevelPrev(scn
.foldLevelPrev
);
1427 if (eventType
== wxEVT_STC_MARGINCLICK
)
1428 evt
.SetMargin(scn
.margin
);
1429 if (eventType
== wxEVT_STC_MACRORECORD
) {
1430 evt
.SetMessage(scn
.message
);
1431 evt
.SetWParam(scn
.wParam
);
1432 evt
.SetLParam(scn
.lParam
);
1435 GetEventHandler()->ProcessEvent(evt
);
1441 //----------------------------------------------------------------------
1442 //----------------------------------------------------------------------
1443 //----------------------------------------------------------------------
1445 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType
, int id
)
1446 : wxCommandEvent(commandType
, id
)
1451 m_modificationType
= 0;
1456 m_foldLevelPrev
= 0;
1465 bool wxStyledTextEvent::GetShift() const { return (m_modifiers
& SCI_SHIFT
) != 0; }
1466 bool wxStyledTextEvent::GetControl() const { return (m_modifiers
& SCI_CTRL
) != 0; }
1467 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers
& SCI_ALT
) != 0; }
1469 void wxStyledTextEvent::CopyObject(wxObject
& obj
) const {
1470 wxCommandEvent::CopyObject(obj
);
1472 wxStyledTextEvent
* o
= (wxStyledTextEvent
*)&obj
;
1473 o
->m_position
= m_position
;
1475 o
->m_modifiers
= m_modifiers
;
1476 o
->m_modificationType
= m_modificationType
;
1478 o
->m_length
= m_length
;
1479 o
->m_linesAdded
= m_linesAdded
;
1481 o
->m_foldLevelNow
= m_foldLevelNow
;
1482 o
->m_foldLevelPrev
= m_foldLevelPrev
;
1484 o
->m_margin
= m_margin
;
1486 o
->m_message
= m_message
;
1487 o
->m_wParam
= m_wParam
;
1488 o
->m_lParam
= m_lParam
;
1494 //----------------------------------------------------------------------
1495 //----------------------------------------------------------------------