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 static 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
;
42 extern LexerModule lmLua
;
63 //----------------------------------------------------------------------
65 const wxChar
* wxSTCNameStr
= "stcwindow";
67 BEGIN_EVENT_TABLE(wxStyledTextCtrl
, wxControl
)
68 EVT_PAINT (wxStyledTextCtrl::OnPaint
)
69 EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin
)
70 EVT_SIZE (wxStyledTextCtrl::OnSize
)
71 EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown
)
72 EVT_MOTION (wxStyledTextCtrl::OnMouseMove
)
73 EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp
)
74 EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp
)
75 EVT_CHAR (wxStyledTextCtrl::OnChar
)
76 EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown
)
77 EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus
)
78 EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus
)
79 EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged
)
80 EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground
)
81 EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu
)
82 EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox
)
86 IMPLEMENT_CLASS(wxStyledTextCtrl
, wxControl
)
87 IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent
, wxCommandEvent
)
89 //----------------------------------------------------------------------
90 // Constructor and Destructor
92 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow
*parent
,
97 const wxString
& name
) :
98 wxControl(parent
, id
, pos
, size
,
99 style
| wxVSCROLL
| wxHSCROLL
| wxWANTS_CHARS
,
100 wxDefaultValidator
, name
)
102 m_swx
= new ScintillaWX(this);
103 // m_keywords = new WordList;
106 m_undoType
= wxSTC_UndoCollectAutoStart
;
110 wxStyledTextCtrl::~wxStyledTextCtrl() {
112 // delete m_keywords;
116 //----------------------------------------------------------------------
118 long wxStyledTextCtrl::SendMsg(int msg
, long wp
, long lp
) {
120 return m_swx
->WndProc(msg
, wp
, lp
);
124 //----------------------------------------------------------------------
125 // Text retrieval and modification
127 wxString
wxStyledTextCtrl::GetText() {
129 int len
= GetTextLength();
130 char* buff
= text
.GetWriteBuf(len
+1);
132 SendMsg(SCI_GETTEXT
, len
, (long)buff
);
134 text
.UngetWriteBuf();
139 bool wxStyledTextCtrl::SetText(const wxString
& text
) {
140 return SendMsg(SCI_SETTEXT
, 0, (long)text
.c_str()) != 0;
144 wxString
wxStyledTextCtrl::GetLine(int line
) {
146 int len
= GetLineLength(line
);
147 char* buff
= text
.GetWriteBuf(len
+1);
149 SendMsg(SCI_GETLINE
, line
, (long)buff
);
151 text
.UngetWriteBuf();
156 void wxStyledTextCtrl::ReplaceSelection(const wxString
& text
) {
157 SendMsg(SCI_REPLACESEL
, 0, (long)text
.c_str());
161 void wxStyledTextCtrl::SetReadOnly(bool readOnly
) {
162 SendMsg(SCI_SETREADONLY
, (long)readOnly
);
163 m_readOnly
= readOnly
;
167 bool wxStyledTextCtrl::GetReadOnly() {
168 // TODO: need support in Scintilla to do this right,
169 // until then we'll track it ourselves
174 void wxStyledTextCtrl::GetTextRange(int startPos
, int endPos
, char* buff
) {
177 tr
.chrg
.cpMin
= startPos
;
178 tr
.chrg
.cpMax
= endPos
;
179 SendMsg(SCI_GETTEXTRANGE
, 0, (long)&tr
);
183 wxString
wxStyledTextCtrl::GetTextRange(int startPos
, int endPos
) {
185 int len
= endPos
- startPos
;
186 char* buff
= text
.GetWriteBuf(len
+1);
187 GetTextRange(startPos
, endPos
, buff
);
188 text
.UngetWriteBuf();
193 void wxStyledTextCtrl::GetStyledTextRange(int startPos
, int endPos
, char* buff
) {
196 tr
.chrg
.cpMin
= startPos
;
197 tr
.chrg
.cpMax
= endPos
;
198 SendMsg(SCI_GETSTYLEDTEXT
, 0, (long)&tr
);
202 wxString
wxStyledTextCtrl::GetStyledTextRange(int startPos
, int endPos
) {
204 int len
= endPos
- startPos
;
205 char* buff
= text
.GetWriteBuf(len
*2+1);
206 GetStyledTextRange(startPos
, endPos
, buff
);
207 text
.UngetWriteBuf(len
*2);
212 void wxStyledTextCtrl::AddText(const wxString
& text
) {
213 SendMsg(SCI_ADDTEXT
, text
.Len(), (long)text
.c_str());
217 void wxStyledTextCtrl::AddStyledText(const wxString
& text
) {
218 SendMsg(SCI_ADDSTYLEDTEXT
, text
.Len(), (long)text
.c_str());
222 void wxStyledTextCtrl::InsertText(int pos
, const wxString
& text
) {
223 SendMsg(SCI_INSERTTEXT
, pos
, (long)text
.c_str());
227 void wxStyledTextCtrl::ClearAll() {
228 SendMsg(SCI_CLEARALL
);
232 char wxStyledTextCtrl::GetCharAt(int pos
) {
233 return SendMsg(SCI_GETCHARAT
, pos
);
237 char wxStyledTextCtrl::GetStyleAt(int pos
) {
238 return SendMsg(SCI_GETSTYLEAT
, pos
);
242 void wxStyledTextCtrl::SetStyleBits(int bits
) {
243 SendMsg(SCI_SETSTYLEBITS
, bits
);
247 int wxStyledTextCtrl::GetStyleBits() {
248 return SendMsg(SCI_GETSTYLEBITS
);
252 //----------------------------------------------------------------------
256 void wxStyledTextCtrl::Cut() {
261 void wxStyledTextCtrl::Copy() {
266 void wxStyledTextCtrl::Paste() {
271 bool wxStyledTextCtrl::CanPaste() {
272 return SendMsg(SCI_CANPASTE
) != 0;
276 void wxStyledTextCtrl::ClearClipbrd() {
282 //----------------------------------------------------------------------
285 void wxStyledTextCtrl::Undo() {
290 bool wxStyledTextCtrl::CanUndo() {
291 return SendMsg(SCI_CANUNDO
) != 0;
295 void wxStyledTextCtrl::EmptyUndoBuffer() {
296 SendMsg(SCI_EMPTYUNDOBUFFER
);
300 void wxStyledTextCtrl::Redo() {
305 bool wxStyledTextCtrl::CanRedo() {
306 return SendMsg(SCI_CANREDO
) != 0;
310 void wxStyledTextCtrl::SetUndoCollection(wxSTC_UndoType type
) {
311 SendMsg(SCI_SETUNDOCOLLECTION
, type
);
316 wxSTC_UndoType
wxStyledTextCtrl::GetUndoCollection() {
317 // TODO: need support in Scintilla to do this right,
318 // until then we'll track it ourselves
323 void wxStyledTextCtrl::BeginUndoAction() {
324 SendMsg(SCI_BEGINUNDOACTION
);
328 void wxStyledTextCtrl::EndUndoAction() {
329 SendMsg(SCI_ENDUNDOACTION
);
335 //----------------------------------------------------------------------
336 // Selection and information
339 void wxStyledTextCtrl::GetSelection(int* startPos
, int* endPos
) {
340 // SendMsg(EM_GETSEL, (long)startPos, (long)endPos);
341 *startPos
= SendMsg(SCI_GETSELECTIONSTART
);
342 *endPos
= SendMsg(SCI_GETSELECTIONEND
);
346 void wxStyledTextCtrl::SetSelection(int startPos
, int endPos
) {
347 SendMsg(SCI_SETSEL
, startPos
, endPos
);
351 wxString
wxStyledTextCtrl::GetSelectedText() {
356 GetSelection(&start
, &end
);
357 int len
= end
- start
;
358 char* buff
= text
.GetWriteBuf(len
+1);
360 SendMsg(SCI_GETSELTEXT
, 0, (long)buff
);
361 text
.UngetWriteBuf();
366 void wxStyledTextCtrl::HideSelection(bool hide
) {
367 SendMsg(SCI_HIDESELECTION
, hide
);
371 bool wxStyledTextCtrl::GetHideSelection() {
372 return m_swx
->GetHideSelection();
376 int wxStyledTextCtrl::GetTextLength() {
377 return SendMsg(SCI_GETTEXTLENGTH
);
381 int wxStyledTextCtrl::GetFirstVisibleLine() {
382 return SendMsg(SCI_GETFIRSTVISIBLELINE
);
386 int wxStyledTextCtrl::GetLineCount() {
387 return SendMsg(SCI_GETLINECOUNT
);
391 bool wxStyledTextCtrl::GetModified() {
392 return SendMsg(SCI_GETMODIFY
) != 0;
396 int wxStyledTextCtrl::GetLineFromPos(int pos
) {
397 return SendMsg(SCI_LINEFROMPOSITION
, pos
);
401 int wxStyledTextCtrl::GetLineStartPos(int line
) {
402 return SendMsg(SCI_POSITIONFROMLINE
, line
);
406 int wxStyledTextCtrl::GetLineLength(int line
) {
407 return SendMsg(SCI_LINELENGTH
, line
);
411 int wxStyledTextCtrl::GetCurrentLine() {
412 int line
= GetLineFromPos(GetCurrentPos());
417 wxString
wxStyledTextCtrl::GetCurrentLineText(int* linePos
) {
419 int len
= GetLineLength(GetCurrentLine());
420 char* buff
= text
.GetWriteBuf(len
+1);
422 int pos
= SendMsg(SCI_GETCURLINE
, len
, (long)buff
);
423 text
.UngetWriteBuf();
432 int wxStyledTextCtrl::PositionFromPoint(wxPoint pt
) {
433 return SendMsg(SCI_POSITIONFROMPOINT
, pt
.x
, pt
.y
);
437 wxPoint
wxStyledTextCtrl::PointFromPosition(int pos
) {
438 int x
= SendMsg(SCI_POINTXFROMPOSITION
, 0, pos
);
439 int y
= SendMsg(SCI_POINTYFROMPOSITION
, 0, pos
);
440 return wxPoint(x
, y
);
444 int wxStyledTextCtrl::GetCurrentPos() {
445 return SendMsg(SCI_GETCURRENTPOS
);
449 int wxStyledTextCtrl::GetAnchor() {
450 return SendMsg(SCI_GETANCHOR
);
454 void wxStyledTextCtrl::SelectAll() {
455 SendMsg(SCI_SELECTALL
);
459 void wxStyledTextCtrl::SetCurrentPosition(int pos
) {
460 SendMsg(SCI_GOTOPOS
, pos
);
464 void wxStyledTextCtrl::SetAnchor(int pos
) {
465 SendMsg(SCI_SETANCHOR
, pos
);
469 void wxStyledTextCtrl::GotoPos(int pos
) {
470 SendMsg(SCI_GOTOPOS
, pos
);
474 void wxStyledTextCtrl::GotoLine(int line
) {
475 SendMsg(SCI_GOTOLINE
, line
);
479 void wxStyledTextCtrl::ChangePosition(int delta
, bool extendSelection
) {
480 // TODO: Is documented but doesn't seem to be implemented
481 //SendMsg(SCI_CHANGEPOSITION, delta, extendSelection);
485 void wxStyledTextCtrl::PageMove(int cmdKey
, bool extendSelection
) {
486 // TODO: Is documented but doesn't seem to be implemented
487 //SendMsg(SCI_PAGEMOVE, cmdKey, extendSelection);
491 void wxStyledTextCtrl::ScrollBy(int columnDelta
, int lineDelta
) {
492 SendMsg(SCI_LINESCROLL
, columnDelta
, lineDelta
);
495 void wxStyledTextCtrl::ScrollToLine(int line
) {
496 m_swx
->DoScrollToLine(line
);
500 void wxStyledTextCtrl::ScrollToColumn(int column
) {
501 m_swx
->DoScrollToColumn(column
);
505 void wxStyledTextCtrl::EnsureCaretVisible() {
506 SendMsg(SCI_SCROLLCARET
);
510 void wxStyledTextCtrl::SetCaretPolicy(int policy
, int slop
) {
511 SendMsg(SCI_SETCARETPOLICY
, policy
, slop
);
515 int wxStyledTextCtrl::GetLinesOnScreen() {
516 return SendMsg(SCI_LINESONSCREEN
);
520 bool wxStyledTextCtrl::IsSelectionRectangle() {
521 return SendMsg(SCI_SELECTIONISRECTANGLE
) != 0;
525 void wxStyledTextCtrl::SetUseHorizontalScrollBar(bool use
) {
526 SendMsg(SCI_SETHSCROLLBAR
, use
);
530 bool wxStyledTextCtrl::GetUseHorizontalScrollBar() {
531 return SendMsg(SCI_GETHSCROLLBAR
) != 0;
538 //----------------------------------------------------------------------
541 int wxStyledTextCtrl::FindText(int minPos
, int maxPos
,
542 const wxString
& text
,
543 bool caseSensitive
, bool wholeWord
) {
547 flags
|= caseSensitive
? SCFIND_MATCHCASE
: 0;
548 flags
|= wholeWord
? SCFIND_WHOLEWORD
: 0;
549 ft
.chrg
.cpMin
= minPos
;
550 ft
.chrg
.cpMax
= maxPos
;
551 ft
.lpstrText
= (char*)text
.c_str();
553 return SendMsg(SCI_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
? SCFIND_MATCHCASE
: 0;
565 flags
|= wholeWord
? SCFIND_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
? SCFIND_MATCHCASE
: 0;
574 flags
|= wholeWord
? SCFIND_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 void wxStyledTextCtrl::SetLineState(int line
, int value
) {
644 SendMsg(SCI_SETLINESTATE
, line
, value
);
648 int wxStyledTextCtrl::GetLineState(int line
) {
649 return SendMsg(SCI_GETLINESTATE
, line
);
653 //----------------------------------------------------------------------
657 static long wxColourAsLong(const wxColour
& co
) {
658 return (((long)co
.Blue() << 16) |
659 ((long)co
.Green() << 8) |
663 static wxColour
wxColourFromLong(long c
) {
665 clr
.Set(c
& 0xff, (c
>> 8) & 0xff, (c
>> 16) & 0xff);
670 static wxColour
wxColourFromSpec(const wxString
& spec
) {
671 // spec should be #RRGGBB
673 int red
= strtol(spec
.Mid(1,2), &junk
, 16);
674 int green
= strtol(spec
.Mid(3,2), &junk
, 16);
675 int blue
= strtol(spec
.Mid(5,2), &junk
, 16);
676 return wxColour(red
, green
, blue
);
680 void wxStyledTextCtrl::StyleClearAll() {
681 SendMsg(SCI_STYLECLEARALL
);
685 void wxStyledTextCtrl::StyleResetDefault() {
686 SendMsg(SCI_STYLERESETDEFAULT
);
691 // Extract style settings from a spec-string which is composed of one or
692 // more of the following comma separated elements:
694 // bold turns on bold
695 // italic turns on italics
696 // fore:#RRGGBB sets the foreground colour
697 // back:#RRGGBB sets the background colour
698 // face:[facename] sets the font face name to use
699 // size:[num] sets the font size in points
700 // eol turns on eol filling
701 // underline turns on underlining
704 void wxStyledTextCtrl::StyleSetSpec(int styleNum
, const wxString
& spec
) {
706 wxStringTokenizer
tkz(spec
, ",");
707 while (tkz
.HasMoreTokens()) {
708 wxString token
= tkz
.GetNextToken();
710 wxString option
= token
.BeforeFirst(':');
711 wxString val
= token
.AfterFirst(':');
713 if (option
== "bold")
714 StyleSetBold(styleNum
, true);
716 else if (option
== "italic")
717 StyleSetItalic(styleNum
, true);
719 else if (option
== "underline")
720 StyleSetUnderline(styleNum
, true);
722 else if (option
== "eol")
723 StyleSetEOLFilled(styleNum
, true);
725 else if (option
== "size") {
727 if (val
.ToLong(&points
))
728 StyleSetSize(styleNum
, points
);
731 else if (option
== "face")
732 StyleSetFaceName(styleNum
, val
);
734 else if (option
== "fore")
735 StyleSetForeground(styleNum
, wxColourFromSpec(val
));
737 else if (option
== "back")
738 StyleSetBackground(styleNum
, wxColourFromSpec(val
));
743 void wxStyledTextCtrl::StyleSetForeground(int styleNum
, const wxColour
& colour
) {
744 SendMsg(SCI_STYLESETFORE
, styleNum
, wxColourAsLong(colour
));
748 void wxStyledTextCtrl::StyleSetBackground(int styleNum
, const wxColour
& colour
) {
749 SendMsg(SCI_STYLESETBACK
, styleNum
, wxColourAsLong(colour
));
753 void wxStyledTextCtrl::StyleSetFont(int styleNum
, wxFont
& font
) {
754 int size
= font
.GetPointSize();
755 wxString faceName
= font
.GetFaceName();
756 bool bold
= font
.GetWeight() == wxBOLD
;
757 bool italic
= font
.GetStyle() != wxNORMAL
;
758 bool under
= font
.GetUnderlined();
760 StyleSetFontAttr(styleNum
, size
, faceName
, bold
, italic
, under
);
764 void wxStyledTextCtrl::StyleSetFontAttr(int styleNum
, int size
,
765 const wxString
& faceName
,
766 bool bold
, bool italic
,
768 StyleSetSize(styleNum
, size
);
769 StyleSetFaceName(styleNum
, faceName
);
770 StyleSetBold(styleNum
, bold
);
771 StyleSetItalic(styleNum
, italic
);
772 StyleSetUnderline(styleNum
, underline
);
776 void wxStyledTextCtrl::StyleSetBold(int styleNum
, bool bold
) {
777 SendMsg(SCI_STYLESETBOLD
, styleNum
, bold
);
781 void wxStyledTextCtrl::StyleSetItalic(int styleNum
, bool italic
) {
782 SendMsg(SCI_STYLESETITALIC
, styleNum
, italic
);
786 void wxStyledTextCtrl::StyleSetFaceName(int styleNum
, const wxString
& faceName
) {
787 SendMsg(SCI_STYLESETFONT
, styleNum
, (long)faceName
.c_str());
791 void wxStyledTextCtrl::StyleSetSize(int styleNum
, int pointSize
) {
792 SendMsg(SCI_STYLESETSIZE
, styleNum
, pointSize
);
796 void wxStyledTextCtrl::StyleSetEOLFilled(int styleNum
, bool fillEOL
) {
797 SendMsg(SCI_STYLESETEOLFILLED
, styleNum
, fillEOL
);
801 void wxStyledTextCtrl::StyleSetUnderline(int styleNum
, bool underline
) {
802 SendMsg(SCI_STYLESETUNDERLINE
, styleNum
, underline
);
806 //----------------------------------------------------------------------
807 // Margins in the edit area
809 int wxStyledTextCtrl::GetLeftMargin() {
810 return SendMsg(SCI_GETMARGINLEFT
);
814 int wxStyledTextCtrl::GetRightMargin() {
815 return SendMsg(SCI_GETMARGINRIGHT
);
819 void wxStyledTextCtrl::SetMargins(int left
, int right
) {
823 SendMsg(SCI_SETMARGINRIGHT
, 0, right
);
826 SendMsg(SCI_SETMARGINLEFT
, 0, left
);
831 //----------------------------------------------------------------------
832 // Margins for selection, markers, etc.
834 void wxStyledTextCtrl::SetMarginType(int margin
, int type
) {
835 SendMsg(SCI_SETMARGINTYPEN
, margin
, type
);
839 int wxStyledTextCtrl::GetMarginType(int margin
) {
840 return SendMsg(SCI_GETMARGINTYPEN
, margin
);
844 void wxStyledTextCtrl::SetMarginWidth(int margin
, int pixelWidth
) {
845 SendMsg(SCI_SETMARGINWIDTHN
, margin
, pixelWidth
);
849 int wxStyledTextCtrl::GetMarginWidth(int margin
) {
850 return SendMsg(SCI_GETMARGINWIDTHN
, margin
);
854 void wxStyledTextCtrl::SetMarginMask(int margin
, int mask
) {
855 SendMsg(SCI_SETMARGINMASKN
, margin
, mask
);
859 int wxStyledTextCtrl::GetMarginMask(int margin
) {
860 return SendMsg(SCI_GETMARGINMASKN
, margin
);
864 void wxStyledTextCtrl::SetMarginSensitive(int margin
, bool sensitive
) {
865 SendMsg(SCI_SETMARGINSENSITIVEN
, margin
, sensitive
);
869 bool wxStyledTextCtrl::GetMarginSensitive(int margin
) {
870 return SendMsg(SCI_GETMARGINSENSITIVEN
, margin
) != 0;
876 //----------------------------------------------------------------------
877 // Selection and Caret styles
880 void wxStyledTextCtrl::SetSelectionForeground(const wxColour
& colour
) {
881 SendMsg(SCI_SETSELFORE
, 0, wxColourAsLong(colour
));
885 void wxStyledTextCtrl::SetSelectionBackground(const wxColour
& colour
) {
886 SendMsg(SCI_SETSELBACK
, 0, wxColourAsLong(colour
));
890 void wxStyledTextCtrl::SetCaretForeground(const wxColour
& colour
) {
891 SendMsg(SCI_SETCARETFORE
, wxColourAsLong(colour
));
895 int wxStyledTextCtrl::GetCaretPeriod() {
896 return SendMsg(SCI_GETCARETPERIOD
);
900 void wxStyledTextCtrl::SetCaretPeriod(int milliseconds
) {
901 SendMsg(SCI_SETCARETPERIOD
, milliseconds
);
906 //----------------------------------------------------------------------
910 void wxStyledTextCtrl::SetBufferedDraw(bool isBuffered
) {
911 SendMsg(SCI_SETBUFFEREDDRAW
, isBuffered
);
915 void wxStyledTextCtrl::SetTabWidth(int numChars
) {
916 SendMsg(SCI_SETTABWIDTH
, numChars
);
920 void wxStyledTextCtrl::SetIndent(int numChars
) {
921 SendMsg(SCI_SETINDENT
, numChars
);
925 void wxStyledTextCtrl::SetUseTabs(bool usetabs
) {
926 SendMsg(SCI_SETUSETABS
, usetabs
);
930 void wxStyledTextCtrl::SetLineIndentation(int line
, int indentation
) {
931 SendMsg(SCI_SETLINEINDENTATION
, line
, indentation
);
935 int wxStyledTextCtrl:: GetLineIndentation(int line
) {
936 return SendMsg(SCI_GETLINEINDENTATION
, line
);
940 int wxStyledTextCtrl::GetLineIndentationPos(int line
) {
941 return SendMsg(SCI_GETLINEINDENTPOSITION
, line
);
945 void wxStyledTextCtrl::SetWordChars(const wxString
& wordChars
) {
946 SendMsg(SCI_SETTABWIDTH
, 0, (long)wordChars
.c_str());
950 void wxStyledTextCtrl::SetUsePop(bool usepopup
) {
951 SendMsg(SCI_USEPOPUP
, usepopup
);
955 //----------------------------------------------------------------------
956 // Brace highlighting
959 void wxStyledTextCtrl::BraceHighlight(int pos1
, int pos2
) {
960 SendMsg(SCI_BRACEHIGHLIGHT
, pos1
, pos2
);
964 void wxStyledTextCtrl::BraceBadlight(int pos
) {
965 SendMsg(SCI_BRACEBADLIGHT
, pos
);
969 int wxStyledTextCtrl::BraceMatch(int pos
, int maxReStyle
) {
970 return SendMsg(SCI_BRACEMATCH
, pos
, maxReStyle
);
975 //----------------------------------------------------------------------
978 void wxStyledTextCtrl::MarkerDefine(int markerNumber
, int markerSymbol
,
979 const wxColour
& foreground
,
980 const wxColour
& background
) {
981 MarkerSetType(markerNumber
, markerSymbol
);
982 MarkerSetForeground(markerNumber
, foreground
);
983 MarkerSetBackground(markerNumber
, background
);
987 void wxStyledTextCtrl::MarkerSetType(int markerNumber
, int markerSymbol
) {
988 SendMsg(SCI_MARKERDEFINE
, markerNumber
, markerSymbol
);
992 void wxStyledTextCtrl::MarkerSetForeground(int markerNumber
, const wxColour
& colour
) {
993 SendMsg(SCI_MARKERSETFORE
, markerNumber
, wxColourAsLong(colour
));
997 void wxStyledTextCtrl::MarkerSetBackground(int markerNumber
, const wxColour
& colour
) {
998 SendMsg(SCI_MARKERSETBACK
, markerNumber
, wxColourAsLong(colour
));
1002 int wxStyledTextCtrl::MarkerAdd(int line
, int markerNumber
) {
1003 return SendMsg(SCI_MARKERADD
, line
, markerNumber
);
1007 void wxStyledTextCtrl::MarkerDelete(int line
, int markerNumber
) {
1008 SendMsg(SCI_MARKERDELETE
, line
, markerNumber
);
1012 void wxStyledTextCtrl::MarkerDeleteAll(int markerNumber
) {
1013 SendMsg(SCI_MARKERDELETEALL
, markerNumber
);
1017 int wxStyledTextCtrl::MarkerGet(int line
) {
1018 return SendMsg(SCI_MARKERGET
);
1022 int wxStyledTextCtrl::MarkerGetNextLine(int lineStart
, int markerMask
) {
1023 return SendMsg(SCI_MARKERNEXT
, lineStart
, markerMask
);
1027 int wxStyledTextCtrl::MarkerGetPrevLine(int lineStart
, int markerMask
) {
1028 // return SendMsg(SCI_MARKERPREV, lineStart, markerMask);
1033 int wxStyledTextCtrl::MarkerLineFromHandle(int handle
) {
1034 return SendMsg(SCI_MARKERLINEFROMHANDLE
, handle
);
1038 void wxStyledTextCtrl::MarkerDeleteHandle(int handle
) {
1039 SendMsg(SCI_MARKERDELETEHANDLE
, handle
);
1044 //----------------------------------------------------------------------
1048 void wxStyledTextCtrl::IndicatorSetStyle(int indicNum
, int indicStyle
) {
1049 SendMsg(SCI_INDICSETSTYLE
, indicNum
, indicStyle
);
1053 int wxStyledTextCtrl::IndicatorGetStyle(int indicNum
) {
1054 return SendMsg(SCI_INDICGETSTYLE
, indicNum
);
1058 void wxStyledTextCtrl::IndicatorSetColour(int indicNum
, const wxColour
& colour
) {
1059 SendMsg(SCI_INDICSETFORE
, indicNum
, wxColourAsLong(colour
));
1064 //----------------------------------------------------------------------
1068 void wxStyledTextCtrl::AutoCompShow(const wxString
& listOfWords
) {
1069 SendMsg(SCI_AUTOCSHOW
, 0, (long)listOfWords
.c_str());
1073 void wxStyledTextCtrl::AutoCompCancel() {
1074 SendMsg(SCI_AUTOCCANCEL
);
1078 bool wxStyledTextCtrl::AutoCompActive() {
1079 return SendMsg(SCI_AUTOCACTIVE
) != 0;
1083 int wxStyledTextCtrl::AutoCompPosAtStart() {
1084 return SendMsg(SCI_AUTOCPOSSTART
);
1088 void wxStyledTextCtrl::AutoCompComplete() {
1089 SendMsg(SCI_AUTOCCOMPLETE
);
1093 void wxStyledTextCtrl::AutoCompStopChars(const wxString
& stopChars
) {
1094 SendMsg(SCI_AUTOCSHOW
, 0, (long)stopChars
.c_str());
1098 void wxStyledTextCtrl::AutoCompSetSeparator(char separator
) {
1099 SendMsg(SCI_AUTOCSETSEPARATOR
, separator
);
1103 char wxStyledTextCtrl::AutoCompGetSeparator() {
1104 return SendMsg(SCI_AUTOCGETSEPARATOR
);
1108 void wxStyledTextCtrl::AutoCompSelect(const wxString
& stringtoselect
) {
1109 SendMsg(SCI_AUTOCSELECT
, (long)stringtoselect
.c_str());
1113 //----------------------------------------------------------------------
1116 void wxStyledTextCtrl::CallTipShow(int pos
, const wxString
& text
) {
1117 SendMsg(SCI_CALLTIPSHOW
, pos
, (long)text
.c_str());
1121 void wxStyledTextCtrl::CallTipCancel() {
1122 SendMsg(SCI_CALLTIPCANCEL
);
1126 bool wxStyledTextCtrl::CallTipActive() {
1127 return SendMsg(SCI_CALLTIPACTIVE
) != 0;
1131 int wxStyledTextCtrl::CallTipPosAtStart() {
1132 return SendMsg(SCI_CALLTIPPOSSTART
);
1136 void wxStyledTextCtrl::CallTipSetHighlight(int start
, int end
) {
1137 SendMsg(SCI_CALLTIPSETHLT
, start
, end
);
1141 void wxStyledTextCtrl::CallTipSetBackground(const wxColour
& colour
) {
1142 SendMsg(SCI_CALLTIPSETBACK
, wxColourAsLong(colour
));
1146 //----------------------------------------------------------------------
1149 #define MAKELONG(a, b) ((a) | ((b) << 16))
1151 void wxStyledTextCtrl::CmdKeyAssign(int key
, int modifiers
, int cmd
) {
1152 SendMsg(SCI_ASSIGNCMDKEY
, MAKELONG(key
, modifiers
), cmd
);
1156 void wxStyledTextCtrl::CmdKeyClear(int key
, int modifiers
) {
1157 SendMsg(SCI_CLEARCMDKEY
, MAKELONG(key
, modifiers
));
1161 void wxStyledTextCtrl::CmdKeyClearAll() {
1162 SendMsg(SCI_CLEARALLCMDKEYS
);
1166 void wxStyledTextCtrl::CmdKeyExecute(int cmd
) {
1172 //----------------------------------------------------------------------
1176 wxStyledTextCtrl::FormatRange(bool doDraw
,
1180 wxDC
* target
, // Why does it use two? Can they be the same?
1186 fr
.hdcTarget
= target
;
1187 fr
.rc
.top
= renderRect
.GetTop();
1188 fr
.rc
.left
= renderRect
.GetLeft();
1189 fr
.rc
.right
= renderRect
.GetRight();
1190 fr
.rc
.bottom
= renderRect
.GetBottom();
1191 fr
.rcPage
.top
= pageRect
.GetTop();
1192 fr
.rcPage
.left
= pageRect
.GetLeft();
1193 fr
.rcPage
.right
= pageRect
.GetRight();
1194 fr
.rcPage
.bottom
= pageRect
.GetBottom();
1195 fr
.chrg
.cpMin
= startPos
;
1196 fr
.chrg
.cpMax
= endPos
;
1198 return SendMsg(SCI_FORMATRANGE
, doDraw
, (long)&fr
);
1202 //----------------------------------------------------------------------
1205 void* wxStyledTextCtrl::GetDocument() {
1206 return (void*)SendMsg(SCI_GETDOCPOINTER
);
1210 void wxStyledTextCtrl::SetDocument(void* document
) {
1211 SendMsg(SCI_SETDOCPOINTER
, 0, (long)document
);
1215 //----------------------------------------------------------------------
1218 int wxStyledTextCtrl::VisibleFromDocLine(int docLine
) {
1219 return SendMsg(SCI_VISIBLEFROMDOCLINE
, docLine
);
1223 int wxStyledTextCtrl::DocLineFromVisible(int displayLine
) {
1224 return SendMsg(SCI_DOCLINEFROMVISIBLE
, displayLine
);
1228 int wxStyledTextCtrl::SetFoldLevel(int line
, int level
) {
1229 return SendMsg(SCI_SETFOLDLEVEL
, line
, level
);
1233 int wxStyledTextCtrl::GetFoldLevel(int line
) {
1234 return SendMsg(SCI_GETFOLDLEVEL
, line
);
1238 int wxStyledTextCtrl::GetLastChild(int line
, int level
) {
1239 return SendMsg(SCI_GETLASTCHILD
, line
, level
);
1243 int wxStyledTextCtrl::GetFoldParent(int line
) {
1244 return SendMsg(SCI_GETFOLDPARENT
, line
);
1248 void wxStyledTextCtrl::ShowLines(int lineStart
, int lineEnd
) {
1249 SendMsg(SCI_SHOWLINES
, lineStart
, lineEnd
);
1253 void wxStyledTextCtrl::HideLines(int lineStart
, int lineEnd
) {
1254 SendMsg(SCI_HIDELINES
, lineStart
, lineEnd
);
1258 bool wxStyledTextCtrl::GetLineVisible(int line
) {
1259 return SendMsg(SCI_GETLINEVISIBLE
, line
) != 0;
1263 void wxStyledTextCtrl::SetFoldExpanded(int line
, bool expanded
) {
1264 SendMsg(SCI_SETFOLDEXPANDED
, line
, expanded
);
1268 bool wxStyledTextCtrl::GetFoldExpanded(int line
) {
1269 return SendMsg(SCI_GETFOLDEXPANDED
, line
) != 0;
1273 void wxStyledTextCtrl::ToggleFold(int line
) {
1274 SendMsg(SCI_TOGGLEFOLD
, line
);
1278 void wxStyledTextCtrl::EnsureVisible(int line
) {
1279 SendMsg(SCI_ENSUREVISIBLE
, line
);
1283 void wxStyledTextCtrl::SetFoldFlags(int flags
) {
1284 SendMsg(SCI_SETFOLDFLAGS
, flags
);
1288 //----------------------------------------------------------------------
1291 void wxStyledTextCtrl::ZoomIn() {
1292 SendMsg(SCI_ZOOMIN
);
1296 void wxStyledTextCtrl::ZoomOut() {
1297 SendMsg(SCI_ZOOMOUT
);
1301 void wxStyledTextCtrl::SetZoom(int zoom
) {
1302 SendMsg(SCI_SETZOOM
, zoom
);
1306 int wxStyledTextCtrl::GetZoom() {
1307 return SendMsg(SCI_GETZOOM
);
1310 //----------------------------------------------------------------------
1313 int wxStyledTextCtrl::GetEdgeColumn() {
1314 return SendMsg(SCI_GETEDGECOLUMN
);
1317 void wxStyledTextCtrl::SetEdgeColumn(int column
) {
1318 SendMsg(SCI_SETEDGECOLUMN
, column
);
1321 wxSTC_EDGE
wxStyledTextCtrl::GetEdgeMode() {
1322 return (wxSTC_EDGE
) SendMsg(SCI_GETEDGEMODE
);
1325 void wxStyledTextCtrl::SetEdgeMode(wxSTC_EDGE mode
){
1326 SendMsg(SCI_SETEDGEMODE
, mode
);
1329 wxColour
wxStyledTextCtrl::GetEdgeColour() {
1330 long c
= SendMsg(SCI_GETEDGECOLOUR
);
1331 return wxColourFromLong(c
);
1334 void wxStyledTextCtrl::SetEdgeColour(const wxColour
& colour
) {
1335 SendMsg(SCI_SETEDGECOLOUR
, wxColourAsLong(colour
));
1339 //----------------------------------------------------------------------
1342 void wxStyledTextCtrl::SetLexer(wxSTC_LEX lexer
) {
1343 SendMsg(SCI_SETLEXER
, lexer
);
1347 wxSTC_LEX
wxStyledTextCtrl::GetLexer() {
1348 return (wxSTC_LEX
)SendMsg(SCI_GETLEXER
);
1352 void wxStyledTextCtrl::Colourise(int start
, int end
) {
1353 SendMsg(SCI_COLOURISE
, start
, end
);
1357 void wxStyledTextCtrl::SetProperty(const wxString
& key
, const wxString
& value
) {
1358 SendMsg(SCI_SETPROPERTY
, (long)key
.c_str(), (long)value
.c_str());
1362 void wxStyledTextCtrl::SetKeywords(int keywordSet
, const wxString
& keywordList
) {
1363 SendMsg(SCI_SETKEYWORDS
, keywordSet
, (long)keywordList
.c_str());
1368 //----------------------------------------------------------------------
1369 // Event mask for Modified Event
1371 void wxStyledTextCtrl::SetModEventMask(int mask
) {
1372 SendMsg(SCI_SETMODEVENTMASK
, mask
);
1376 //int wxStyledTextCtrl::GetModEventMask() {
1377 // return SendMsg(SCI_GETMODEVENTMASK);
1380 //----------------------------------------------------------------------
1383 void wxStyledTextCtrl::OnPaint(wxPaintEvent
& evt
) {
1385 wxRegion region
= GetUpdateRegion();
1387 m_swx
->DoPaint(&dc
, region
.GetBox());
1390 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent
& evt
) {
1391 if (evt
.GetOrientation() == wxHORIZONTAL
)
1392 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
1394 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
1397 void wxStyledTextCtrl::OnSize(wxSizeEvent
& evt
) {
1398 wxSize sz
= GetClientSize();
1399 m_swx
->DoSize(sz
.x
, sz
.y
);
1402 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent
& evt
) {
1403 wxPoint pt
= evt
.GetPosition();
1404 m_swx
->DoButtonDown(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1405 evt
.ShiftDown(), evt
.ControlDown(), evt
.AltDown());
1408 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent
& evt
) {
1409 wxPoint pt
= evt
.GetPosition();
1410 m_swx
->DoButtonMove(Point(pt
.x
, pt
.y
));
1413 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent
& evt
) {
1414 wxPoint pt
= evt
.GetPosition();
1415 m_swx
->DoButtonUp(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1420 void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent
& evt
) {
1421 wxPoint pt
= evt
.GetPosition();
1422 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
1425 void wxStyledTextCtrl::OnChar(wxKeyEvent
& evt
) {
1426 long key
= evt
.KeyCode();
1427 if ((key
> WXK_ESCAPE
) &&
1428 (key
!= WXK_DELETE
) && (key
< 255) &&
1429 !evt
.ControlDown() && !evt
.AltDown()) {
1431 m_swx
->DoAddChar(key
);
1438 void wxStyledTextCtrl::OnKeyDown(wxKeyEvent
& evt
) {
1439 long key
= evt
.KeyCode();
1441 int processed
= m_swx
->DoKeyDown(key
, evt
.ShiftDown(),
1442 evt
.ControlDown(), evt
.AltDown());
1447 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent
& evt
) {
1448 m_swx
->DoLoseFocus();
1451 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent
& evt
) {
1452 m_swx
->DoGainFocus();
1455 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& evt
) {
1456 m_swx
->DoSysColourChange();
1459 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent
& evt
) {
1460 // do nothing to help avoid flashing
1465 void wxStyledTextCtrl::OnMenu(wxCommandEvent
& evt
) {
1466 m_swx
->DoCommand(evt
.GetId());
1470 void wxStyledTextCtrl::OnListBox(wxCommandEvent
& evt
) {
1471 m_swx
->DoOnListBox();
1475 //----------------------------------------------------------------------
1476 // Turn notifications from Scintilla into events
1479 void wxStyledTextCtrl::NotifyChange() {
1480 wxStyledTextEvent
evt(wxEVT_STC_CHANGE
, GetId());
1481 GetEventHandler()->ProcessEvent(evt
);
1484 void wxStyledTextCtrl::NotifyParent(SCNotification
* _scn
) {
1485 SCNotification
& scn
= *_scn
;
1487 switch (scn
.nmhdr
.code
) {
1488 case SCN_STYLENEEDED
:
1489 eventType
= wxEVT_STC_STYLENEEDED
;
1492 eventType
= wxEVT_STC_CHARADDED
;
1495 eventType
= wxEVT_STC_UPDATEUI
;
1497 case SCN_SAVEPOINTREACHED
:
1498 eventType
= wxEVT_STC_SAVEPOINTREACHED
;
1500 case SCN_SAVEPOINTLEFT
:
1501 eventType
= wxEVT_STC_SAVEPOINTLEFT
;
1503 case SCN_MODIFYATTEMPTRO
:
1504 eventType
= wxEVT_STC_ROMODIFYATTEMPT
;
1506 case SCN_DOUBLECLICK
:
1507 eventType
= wxEVT_STC_DOUBLECLICK
;
1510 eventType
= wxEVT_STC_MODIFIED
;
1513 eventType
= wxEVT_STC_KEY
;
1515 case SCN_MACRORECORD
:
1516 eventType
= wxEVT_STC_MACRORECORD
;
1518 case SCN_MARGINCLICK
:
1519 eventType
= wxEVT_STC_MARGINCLICK
;
1522 eventType
= wxEVT_STC_NEEDSHOWN
;
1526 wxStyledTextEvent
evt(eventType
, GetId());
1527 evt
.SetPosition(scn
.position
);
1529 evt
.SetModifiers(scn
.modifiers
);
1530 if (eventType
== wxEVT_STC_MODIFIED
) {
1531 evt
.SetModificationType(scn
.modificationType
);
1533 evt
.SetText(wxString(scn
.text
, scn
.length
));
1534 evt
.SetLength(scn
.length
);
1535 evt
.SetLinesAdded(scn
.linesAdded
);
1536 evt
.SetLine(scn
.line
);
1537 evt
.SetFoldLevelNow(scn
.foldLevelNow
);
1538 evt
.SetFoldLevelPrev(scn
.foldLevelPrev
);
1540 if (eventType
== wxEVT_STC_MARGINCLICK
)
1541 evt
.SetMargin(scn
.margin
);
1542 if (eventType
== wxEVT_STC_MACRORECORD
) {
1543 evt
.SetMessage(scn
.message
);
1544 evt
.SetWParam(scn
.wParam
);
1545 evt
.SetLParam(scn
.lParam
);
1548 GetEventHandler()->ProcessEvent(evt
);
1554 //----------------------------------------------------------------------
1555 //----------------------------------------------------------------------
1556 //----------------------------------------------------------------------
1558 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType
, int id
)
1559 : wxCommandEvent(commandType
, id
)
1564 m_modificationType
= 0;
1569 m_foldLevelPrev
= 0;
1578 bool wxStyledTextEvent::GetShift() const { return (m_modifiers
& SCI_SHIFT
) != 0; }
1579 bool wxStyledTextEvent::GetControl() const { return (m_modifiers
& SCI_CTRL
) != 0; }
1580 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers
& SCI_ALT
) != 0; }
1582 void wxStyledTextEvent::CopyObject(wxObject
& obj
) const {
1583 wxCommandEvent::CopyObject(obj
);
1585 wxStyledTextEvent
* o
= (wxStyledTextEvent
*)&obj
;
1586 o
->m_position
= m_position
;
1588 o
->m_modifiers
= m_modifiers
;
1589 o
->m_modificationType
= m_modificationType
;
1591 o
->m_length
= m_length
;
1592 o
->m_linesAdded
= m_linesAdded
;
1594 o
->m_foldLevelNow
= m_foldLevelNow
;
1595 o
->m_foldLevelPrev
= m_foldLevelPrev
;
1597 o
->m_margin
= m_margin
;
1599 o
->m_message
= m_message
;
1600 o
->m_wParam
= m_wParam
;
1601 o
->m_lParam
= m_lParam
;
1607 //----------------------------------------------------------------------
1608 //----------------------------------------------------------------------