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_KEY_DOWN (wxStyledTextCtrl::OnKeyDown
)
79 EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus
)
80 EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus
)
81 EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged
)
82 EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground
)
83 EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu
)
84 EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox
)
88 IMPLEMENT_CLASS(wxStyledTextCtrl
, wxControl
)
89 IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent
, wxCommandEvent
)
91 //----------------------------------------------------------------------
92 // Constructor and Destructor
94 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow
*parent
,
99 const wxString
& name
) :
100 wxControl(parent
, id
, pos
, size
,
101 style
| wxVSCROLL
| wxHSCROLL
| wxWANTS_CHARS
,
102 wxDefaultValidator
, name
)
104 m_swx
= new ScintillaWX(this);
105 // m_keywords = new WordList;
108 m_undoType
= wxSTC_UndoCollectAutoStart
;
112 wxStyledTextCtrl::~wxStyledTextCtrl() {
114 // delete m_keywords;
118 //----------------------------------------------------------------------
120 long wxStyledTextCtrl::SendMsg(int msg
, long wp
, long lp
) {
122 return m_swx
->WndProc(msg
, wp
, lp
);
126 //----------------------------------------------------------------------
127 // Text retrieval and modification
129 wxString
wxStyledTextCtrl::GetText() {
131 int len
= GetTextLength();
132 char* buff
= text
.GetWriteBuf(len
+1);
134 SendMsg(WM_GETTEXT
, len
, (long)buff
);
136 text
.UngetWriteBuf();
141 bool wxStyledTextCtrl::SetText(const wxString
& text
) {
142 return SendMsg(WM_SETTEXT
, 0, (long)text
.c_str()) != 0;
146 wxString
wxStyledTextCtrl::GetLine(int line
) {
148 int len
= GetLineLength(line
);
149 char* buff
= text
.GetWriteBuf(len
+1);
151 *((WORD
*)buff
) = len
;
152 SendMsg(EM_GETLINE
, line
, (long)buff
);
154 text
.UngetWriteBuf();
159 void wxStyledTextCtrl::ReplaceSelection(const wxString
& text
) {
160 SendMsg(EM_REPLACESEL
, 0, (long)text
.c_str());
164 void wxStyledTextCtrl::SetReadOnly(bool readOnly
) {
165 SendMsg(EM_SETREADONLY
, (long)readOnly
);
166 m_readOnly
= readOnly
;
170 bool wxStyledTextCtrl::GetReadOnly() {
171 // TODO: need support in Scintilla to do this right,
172 // until then we'll track it ourselves
177 void wxStyledTextCtrl::GetTextRange(int startPos
, int endPos
, char* buff
) {
180 tr
.chrg
.cpMin
= startPos
;
181 tr
.chrg
.cpMax
= endPos
;
182 SendMsg(EM_GETTEXTRANGE
, 0, (long)&tr
);
186 wxString
wxStyledTextCtrl::GetTextRange(int startPos
, int endPos
) {
188 int len
= endPos
- startPos
;
189 char* buff
= text
.GetWriteBuf(len
);
190 GetTextRange(startPos
, endPos
, buff
);
191 text
.UngetWriteBuf();
196 void wxStyledTextCtrl::GetStyledTextRange(int startPos
, int endPos
, char* buff
) {
199 tr
.chrg
.cpMin
= startPos
;
200 tr
.chrg
.cpMax
= endPos
;
201 SendMsg(SCI_GETSTYLEDTEXT
, 0, (long)&tr
);
205 wxString
wxStyledTextCtrl::GetStyledTextRange(int startPos
, int endPos
) {
207 int len
= endPos
- startPos
;
208 char* buff
= text
.GetWriteBuf(len
*2);
209 GetStyledTextRange(startPos
, endPos
, buff
);
210 text
.UngetWriteBuf(len
*2);
215 void wxStyledTextCtrl::AddText(const wxString
& text
) {
216 SendMsg(SCI_ADDTEXT
, text
.Len(), (long)text
.c_str());
220 void wxStyledTextCtrl::AddStyledText(const wxString
& text
) {
221 SendMsg(SCI_ADDSTYLEDTEXT
, text
.Len(), (long)text
.c_str());
225 void wxStyledTextCtrl::InsertText(int pos
, const wxString
& text
) {
226 SendMsg(SCI_INSERTTEXT
, pos
, (long)text
.c_str());
230 void wxStyledTextCtrl::ClearAll() {
231 SendMsg(SCI_CLEARALL
);
235 char wxStyledTextCtrl::GetCharAt(int pos
) {
236 return SendMsg(SCI_GETCHARAT
, pos
);
240 char wxStyledTextCtrl::GetStyleAt(int pos
) {
241 return SendMsg(SCI_GETSTYLEAT
, pos
);
245 void wxStyledTextCtrl::SetStyleBits(int bits
) {
246 SendMsg(SCI_SETSTYLEBITS
, bits
);
250 int wxStyledTextCtrl::GetStyleBits() {
251 return SendMsg(SCI_GETSTYLEBITS
);
255 //----------------------------------------------------------------------
259 void wxStyledTextCtrl::Cut() {
264 void wxStyledTextCtrl::Copy() {
269 void wxStyledTextCtrl::Paste() {
274 bool wxStyledTextCtrl::CanPaste() {
275 return SendMsg(EM_CANPASTE
) != 0;
279 void wxStyledTextCtrl::ClearClipbrd() {
285 //----------------------------------------------------------------------
288 void wxStyledTextCtrl::Undo() {
293 bool wxStyledTextCtrl::CanUndo() {
294 return SendMsg(EM_CANUNDO
) != 0;
298 void wxStyledTextCtrl::EmptyUndoBuffer() {
299 SendMsg(EM_EMPTYUNDOBUFFER
);
303 void wxStyledTextCtrl::Redo() {
308 bool wxStyledTextCtrl::CanRedo() {
309 return SendMsg(SCI_CANREDO
) != 0;
313 void wxStyledTextCtrl::SetUndoCollection(wxSTC_UndoType type
) {
314 SendMsg(SCI_SETUNDOCOLLECTION
, type
);
319 wxSTC_UndoType
wxStyledTextCtrl::GetUndoCollection() {
320 // TODO: need support in Scintilla to do this right,
321 // until then we'll track it ourselves
326 void wxStyledTextCtrl::BeginUndoAction() {
327 SendMsg(SCI_BEGINUNDOACTION
);
331 void wxStyledTextCtrl::EndUndoAction() {
332 SendMsg(SCI_ENDUNDOACTION
);
338 //----------------------------------------------------------------------
339 // Selection and information
342 void wxStyledTextCtrl::GetSelection(int* startPos
, int* endPos
) {
343 SendMsg(EM_GETSEL
, (long)startPos
, (long)endPos
);
347 void wxStyledTextCtrl::SetSelection(int startPos
, int endPos
) {
348 SendMsg(EM_SETSEL
, startPos
, endPos
);
352 wxString
wxStyledTextCtrl::GetSelectedText() {
357 GetSelection(&start
, &end
);
358 int len
= end
- start
;
359 char* buff
= text
.GetWriteBuf(len
);
361 SendMsg(EM_GETSELTEXT
, 0, (long)buff
);
362 text
.UngetWriteBuf();
367 void wxStyledTextCtrl::HideSelection(bool hide
) {
368 SendMsg(EM_HIDESELECTION
, hide
);
372 bool wxStyledTextCtrl::GetHideSelection() {
373 return m_swx
->GetHideSelection();
377 int wxStyledTextCtrl::GetTextLength() {
378 return SendMsg(WM_GETTEXTLENGTH
);
382 int wxStyledTextCtrl::GetFirstVisibleLine() {
383 return SendMsg(EM_GETFIRSTVISIBLELINE
);
387 int wxStyledTextCtrl::GetLineCount() {
388 return SendMsg(EM_GETLINECOUNT
);
392 bool wxStyledTextCtrl::GetModified() {
393 return SendMsg(EM_GETMODIFY
) != 0;
397 wxRect
wxStyledTextCtrl::GetRect() {
399 SendMsg(EM_GETRECT
, 0, (long)&pr
);
401 wxRect rect
= wxRectFromPRectangle(pr
);
406 int wxStyledTextCtrl::GetLineFromPos(int pos
) {
407 return SendMsg(EM_LINEFROMCHAR
, pos
);
411 int wxStyledTextCtrl::GetLineStartPos(int line
) {
412 return SendMsg(EM_LINEINDEX
, line
);
416 int wxStyledTextCtrl::GetLineLengthAtPos(int pos
) {
417 return SendMsg(EM_LINELENGTH
, pos
);
421 int wxStyledTextCtrl::GetLineLength(int line
) {
422 return SendMsg(SCI_LINELENGTH
, line
);
426 int wxStyledTextCtrl::GetCurrentLine() {
427 int line
= GetLineFromPos(GetCurrentPos());
432 wxString
wxStyledTextCtrl::GetCurrentLineText(int* linePos
) {
434 int len
= GetLineLength(GetCurrentLine());
435 char* buff
= text
.GetWriteBuf(len
+1);
437 int pos
= SendMsg(SCI_GETCURLINE
, len
, (long)buff
);
438 text
.UngetWriteBuf();
447 int wxStyledTextCtrl::PositionFromPoint(wxPoint pt
) {
448 Point
spt(pt
.x
, pt
.y
);
449 long rv
= SendMsg(EM_CHARFROMPOS
, 0, (long)&spt
);
454 int wxStyledTextCtrl::LineFromPoint(wxPoint pt
) {
455 Point
spt(pt
.x
, pt
.y
);
456 long rv
= SendMsg(EM_CHARFROMPOS
, 0, (long)&spt
);
461 wxPoint
wxStyledTextCtrl::PointFromPosition(int pos
) {
463 SendMsg(EM_POSFROMCHAR
, (long)&pt
, pos
);
464 return wxPoint(pt
.x
, pt
.y
);
468 int wxStyledTextCtrl::GetCurrentPos() {
469 return SendMsg(SCI_GETCURRENTPOS
);
473 int wxStyledTextCtrl::GetAnchor() {
474 return SendMsg(SCI_GETANCHOR
);
478 void wxStyledTextCtrl::SelectAll() {
479 SendMsg(SCI_SELECTALL
);
483 void wxStyledTextCtrl::SetCurrentPosition(int pos
) {
484 SendMsg(SCI_GOTOPOS
, pos
);
488 void wxStyledTextCtrl::SetAnchor(int pos
) {
489 SendMsg(SCI_SETANCHOR
, pos
);
493 void wxStyledTextCtrl::GotoPos(int pos
) {
494 SendMsg(SCI_GOTOPOS
, pos
);
498 void wxStyledTextCtrl::GotoLine(int line
) {
499 SendMsg(SCI_GOTOLINE
, line
);
503 void wxStyledTextCtrl::ChangePosition(int delta
, bool extendSelection
) {
504 // TODO: Is documented but doesn't seem to be implemented
505 //SendMsg(SCI_CHANGEPOSITION, delta, extendSelection);
509 void wxStyledTextCtrl::PageMove(int cmdKey
, bool extendSelection
) {
510 // TODO: Is documented but doesn't seem to be implemented
511 //SendMsg(SCI_PAGEMOVE, cmdKey, extendSelection);
515 void wxStyledTextCtrl::ScrollBy(int columnDelta
, int lineDelta
) {
516 SendMsg(EM_LINESCROLL
, columnDelta
, lineDelta
);
519 void wxStyledTextCtrl::ScrollToLine(int line
) {
520 m_swx
->DoScrollToLine(line
);
524 void wxStyledTextCtrl::ScrollToColumn(int column
) {
525 m_swx
->DoScrollToColumn(column
);
529 void wxStyledTextCtrl::EnsureCaretVisible() {
530 SendMsg(EM_SCROLLCARET
);
534 void wxStyledTextCtrl::SetCaretPolicy(int policy
, int slop
) {
535 SendMsg(SCI_SETCARETPOLICY
, policy
, slop
);
539 int wxStyledTextCtrl::GetSelectionType() {
540 return SendMsg(EM_SELECTIONTYPE
);
544 int wxStyledTextCtrl::GetLinesOnScreen() {
545 return SendMsg(SCI_LINESONSCREEN
);
549 bool wxStyledTextCtrl::IsSelectionRectangle() {
550 return SendMsg(SCI_SELECTIONISRECTANGLE
) != 0;
554 void wxStyledTextCtrl::SetUseHorizontalScrollBar(bool use
) {
555 SendMsg(SCI_SETHSCROLLBAR
, use
);
559 bool wxStyledTextCtrl::GetUseHorizontalScrollBar() {
560 return SendMsg(SCI_GETHSCROLLBAR
) != 0;
567 //----------------------------------------------------------------------
570 int wxStyledTextCtrl::FindText(int minPos
, int maxPos
,
571 const wxString
& text
,
572 bool caseSensitive
, bool wholeWord
) {
576 flags
|= caseSensitive
? FR_MATCHCASE
: 0;
577 flags
|= wholeWord
? FR_WHOLEWORD
: 0;
578 ft
.chrg
.cpMin
= minPos
;
579 ft
.chrg
.cpMax
= maxPos
;
580 ft
.lpstrText
= (char*)text
.c_str();
582 return SendMsg(EM_FINDTEXT
, flags
, (long)&ft
);
586 void wxStyledTextCtrl::SearchAnchor() {
587 SendMsg(SCI_SEARCHANCHOR
);
591 int wxStyledTextCtrl::SearchNext(const wxString
& text
, bool caseSensitive
, bool wholeWord
) {
593 flags
|= caseSensitive
? FR_MATCHCASE
: 0;
594 flags
|= wholeWord
? FR_WHOLEWORD
: 0;
596 return SendMsg(SCI_SEARCHNEXT
, flags
, (long)text
.c_str());
600 int wxStyledTextCtrl::SearchPrev(const wxString
& text
, bool caseSensitive
, bool wholeWord
) {
602 flags
|= caseSensitive
? FR_MATCHCASE
: 0;
603 flags
|= wholeWord
? FR_WHOLEWORD
: 0;
605 return SendMsg(SCI_SEARCHPREV
, flags
, (long)text
.c_str());
608 //----------------------------------------------------------------------
609 // Visible whitespace
612 bool wxStyledTextCtrl::GetViewWhitespace() {
613 return SendMsg(SCI_GETVIEWWS
) != 0;
617 void wxStyledTextCtrl::SetViewWhitespace(bool visible
) {
618 SendMsg(SCI_SETVIEWWS
, visible
);
623 //----------------------------------------------------------------------
626 wxSTC_EOL
wxStyledTextCtrl::GetEOLMode() {
627 return (wxSTC_EOL
)SendMsg(SCI_GETEOLMODE
);
631 void wxStyledTextCtrl::SetEOLMode(wxSTC_EOL mode
) {
632 SendMsg(SCI_SETEOLMODE
, mode
);
636 bool wxStyledTextCtrl::GetViewEOL() {
637 return SendMsg(SCI_GETVIEWEOL
) != 0;
641 void wxStyledTextCtrl::SetViewEOL(bool visible
) {
642 SendMsg(SCI_SETVIEWEOL
, visible
);
645 void wxStyledTextCtrl::ConvertEOL(wxSTC_EOL mode
) {
646 SendMsg(SCI_CONVERTEOLS
, mode
);
649 //----------------------------------------------------------------------
652 int wxStyledTextCtrl::GetEndStyled() {
653 return SendMsg(SCI_GETENDSTYLED
);
657 void wxStyledTextCtrl::StartStyling(int pos
, int mask
) {
658 SendMsg(SCI_STARTSTYLING
, pos
, mask
);
662 void wxStyledTextCtrl::SetStyleFor(int length
, int style
) {
663 SendMsg(SCI_SETSTYLING
, length
, style
);
667 void wxStyledTextCtrl::SetStyleBytes(int length
, char* styleBytes
) {
668 SendMsg(SCI_SETSTYLINGEX
, length
, (long)styleBytes
);
672 void wxStyledTextCtrl::SetLineState(int line
, int value
) {
673 SendMsg(SCI_SETLINESTATE
, line
, value
);
677 int wxStyledTextCtrl::GetLineState(int line
) {
678 return SendMsg(SCI_GETLINESTATE
, line
);
682 //----------------------------------------------------------------------
686 static long wxColourAsLong(const wxColour
& co
) {
687 return (((long)co
.Blue() << 16) |
688 ((long)co
.Green() << 8) |
692 static wxColour
wxColourFromLong(long c
) {
694 clr
.Set(c
& 0xff, (c
>> 8) & 0xff, (c
>> 16) & 0xff);
699 static wxColour
wxColourFromSpec(const wxString
& spec
) {
700 // spec should be #RRGGBB
702 int red
= strtol(spec
.Mid(1,2), &junk
, 16);
703 int green
= strtol(spec
.Mid(3,2), &junk
, 16);
704 int blue
= strtol(spec
.Mid(5,2), &junk
, 16);
705 return wxColour(red
, green
, blue
);
709 void wxStyledTextCtrl::StyleClearAll() {
710 SendMsg(SCI_STYLECLEARALL
);
714 void wxStyledTextCtrl::StyleResetDefault() {
715 SendMsg(SCI_STYLERESETDEFAULT
);
720 // Extract style settings from a spec-string which is composed of one or
721 // more of the following comma separated elements:
723 // bold turns on bold
724 // italic turns on italics
725 // fore:#RRGGBB sets the foreground colour
726 // back:#RRGGBB sets the background colour
727 // face:[facename] sets the font face name to use
728 // size:[num] sets the font size in points
729 // eol turns on eol filling
730 // underline turns on underlining
733 void wxStyledTextCtrl::StyleSetSpec(int styleNum
, const wxString
& spec
) {
735 wxStringTokenizer
tkz(spec
, ",");
736 while (tkz
.HasMoreTokens()) {
737 wxString token
= tkz
.GetNextToken();
739 wxString option
= token
.BeforeFirst(':');
740 wxString val
= token
.AfterFirst(':');
742 if (option
== "bold")
743 StyleSetBold(styleNum
, true);
745 else if (option
== "italic")
746 StyleSetItalic(styleNum
, true);
748 else if (option
== "underline")
749 StyleSetUnderline(styleNum
, true);
751 else if (option
== "eol")
752 StyleSetEOLFilled(styleNum
, true);
754 else if (option
== "size") {
756 if (val
.ToLong(&points
))
757 StyleSetSize(styleNum
, points
);
760 else if (option
== "face")
761 StyleSetFaceName(styleNum
, val
);
763 else if (option
== "fore")
764 StyleSetForeground(styleNum
, wxColourFromSpec(val
));
766 else if (option
== "back")
767 StyleSetBackground(styleNum
, wxColourFromSpec(val
));
772 void wxStyledTextCtrl::StyleSetForeground(int styleNum
, const wxColour
& colour
) {
773 SendMsg(SCI_STYLESETFORE
, styleNum
, wxColourAsLong(colour
));
777 void wxStyledTextCtrl::StyleSetBackground(int styleNum
, const wxColour
& colour
) {
778 SendMsg(SCI_STYLESETBACK
, styleNum
, wxColourAsLong(colour
));
782 void wxStyledTextCtrl::StyleSetFont(int styleNum
, wxFont
& font
) {
783 int size
= font
.GetPointSize();
784 wxString faceName
= font
.GetFaceName();
785 bool bold
= font
.GetWeight() == wxBOLD
;
786 bool italic
= font
.GetStyle() != wxNORMAL
;
787 bool under
= font
.GetUnderlined();
789 StyleSetFontAttr(styleNum
, size
, faceName
, bold
, italic
, under
);
793 void wxStyledTextCtrl::StyleSetFontAttr(int styleNum
, int size
,
794 const wxString
& faceName
,
795 bool bold
, bool italic
,
797 StyleSetSize(styleNum
, size
);
798 StyleSetFaceName(styleNum
, faceName
);
799 StyleSetBold(styleNum
, bold
);
800 StyleSetItalic(styleNum
, italic
);
801 StyleSetUnderline(styleNum
, underline
);
805 void wxStyledTextCtrl::StyleSetBold(int styleNum
, bool bold
) {
806 SendMsg(SCI_STYLESETBOLD
, styleNum
, bold
);
810 void wxStyledTextCtrl::StyleSetItalic(int styleNum
, bool italic
) {
811 SendMsg(SCI_STYLESETITALIC
, styleNum
, italic
);
815 void wxStyledTextCtrl::StyleSetFaceName(int styleNum
, const wxString
& faceName
) {
816 SendMsg(SCI_STYLESETFONT
, styleNum
, (long)faceName
.c_str());
820 void wxStyledTextCtrl::StyleSetSize(int styleNum
, int pointSize
) {
821 SendMsg(SCI_STYLESETSIZE
, styleNum
, pointSize
);
825 void wxStyledTextCtrl::StyleSetEOLFilled(int styleNum
, bool fillEOL
) {
826 SendMsg(SCI_STYLESETEOLFILLED
, styleNum
, fillEOL
);
830 void wxStyledTextCtrl::StyleSetUnderline(int styleNum
, bool underline
) {
831 SendMsg(SCI_STYLESETUNDERLINE
, styleNum
, underline
);
835 //----------------------------------------------------------------------
836 // Margins in the edit area
838 int wxStyledTextCtrl::GetLeftMargin() {
839 return LOWORD(SendMsg(EM_GETMARGINS
));
843 int wxStyledTextCtrl::GetRightMargin() {
844 return HIWORD(SendMsg(EM_GETMARGINS
));
848 void wxStyledTextCtrl::SetMargins(int left
, int right
) {
853 flag
|= EC_RIGHTMARGIN
;
857 flag
|= EC_LEFTMARGIN
;
858 val
|= (left
& 0xffff);
861 SendMsg(EM_SETMARGINS
, flag
, val
);
865 //----------------------------------------------------------------------
866 // Margins for selection, markers, etc.
868 void wxStyledTextCtrl::SetMarginType(int margin
, int type
) {
869 SendMsg(SCI_SETMARGINTYPEN
, margin
, type
);
873 int wxStyledTextCtrl::GetMarginType(int margin
) {
874 return SendMsg(SCI_GETMARGINTYPEN
, margin
);
878 void wxStyledTextCtrl::SetMarginWidth(int margin
, int pixelWidth
) {
879 SendMsg(SCI_SETMARGINWIDTHN
, margin
, pixelWidth
);
883 int wxStyledTextCtrl::GetMarginWidth(int margin
) {
884 return SendMsg(SCI_GETMARGINWIDTHN
, margin
);
888 void wxStyledTextCtrl::SetMarginMask(int margin
, int mask
) {
889 SendMsg(SCI_SETMARGINMASKN
, margin
, mask
);
893 int wxStyledTextCtrl::GetMarginMask(int margin
) {
894 return SendMsg(SCI_GETMARGINMASKN
, margin
);
898 void wxStyledTextCtrl::SetMarginSensitive(int margin
, bool sensitive
) {
899 SendMsg(SCI_SETMARGINSENSITIVEN
, margin
, sensitive
);
903 bool wxStyledTextCtrl::GetMarginSensitive(int margin
) {
904 return SendMsg(SCI_GETMARGINSENSITIVEN
, margin
) != 0;
910 //----------------------------------------------------------------------
911 // Selection and Caret styles
914 void wxStyledTextCtrl::SetSelectionForeground(const wxColour
& colour
) {
915 SendMsg(SCI_SETSELFORE
, 0, wxColourAsLong(colour
));
919 void wxStyledTextCtrl::SetSelectionBackground(const wxColour
& colour
) {
920 SendMsg(SCI_SETSELBACK
, 0, wxColourAsLong(colour
));
924 void wxStyledTextCtrl::SetCaretForeground(const wxColour
& colour
) {
925 SendMsg(SCI_SETCARETFORE
, wxColourAsLong(colour
));
929 int wxStyledTextCtrl::GetCaretPeriod() {
930 return SendMsg(SCI_GETCARETPERIOD
);
934 void wxStyledTextCtrl::SetCaretPeriod(int milliseconds
) {
935 SendMsg(SCI_SETCARETPERIOD
, milliseconds
);
940 //----------------------------------------------------------------------
944 void wxStyledTextCtrl::SetBufferedDraw(bool isBuffered
) {
945 SendMsg(SCI_SETBUFFEREDDRAW
, isBuffered
);
949 void wxStyledTextCtrl::SetTabWidth(int numChars
) {
950 SendMsg(SCI_SETTABWIDTH
, numChars
);
954 void wxStyledTextCtrl::SetIndent(int numChars
) {
955 SendMsg(SCI_SETINDENT
, numChars
);
959 void wxStyledTextCtrl::SetUseTabs(bool usetabs
) {
960 SendMsg(SCI_SETUSETABS
, usetabs
);
964 void wxStyledTextCtrl::SetLineIndentation(int line
, int indentation
) {
965 SendMsg(SCI_SETLINEINDENTATION
, line
, indentation
);
969 int wxStyledTextCtrl:: GetLineIndentation(int line
) {
970 return SendMsg(SCI_GETLINEINDENTATION
, line
);
974 int wxStyledTextCtrl::GetLineIndentationPos(int line
) {
975 return SendMsg(SCI_GETLINEINDENTPOSITION
, line
);
979 void wxStyledTextCtrl::SetWordChars(const wxString
& wordChars
) {
980 SendMsg(SCI_SETTABWIDTH
, 0, (long)wordChars
.c_str());
984 void wxStyledTextCtrl::SetUsePop(bool usepopup
) {
985 SendMsg(SCI_USEPOPUP
, usepopup
);
989 //----------------------------------------------------------------------
990 // Brace highlighting
993 void wxStyledTextCtrl::BraceHighlight(int pos1
, int pos2
) {
994 SendMsg(SCI_BRACEHIGHLIGHT
, pos1
, pos2
);
998 void wxStyledTextCtrl::BraceBadlight(int pos
) {
999 SendMsg(SCI_BRACEBADLIGHT
, pos
);
1003 int wxStyledTextCtrl::BraceMatch(int pos
, int maxReStyle
) {
1004 return SendMsg(SCI_BRACEMATCH
, pos
, maxReStyle
);
1009 //----------------------------------------------------------------------
1012 void wxStyledTextCtrl::MarkerDefine(int markerNumber
, int markerSymbol
,
1013 const wxColour
& foreground
,
1014 const wxColour
& background
) {
1015 MarkerSetType(markerNumber
, markerSymbol
);
1016 MarkerSetForeground(markerNumber
, foreground
);
1017 MarkerSetBackground(markerNumber
, background
);
1021 void wxStyledTextCtrl::MarkerSetType(int markerNumber
, int markerSymbol
) {
1022 SendMsg(SCI_MARKERDEFINE
, markerNumber
, markerSymbol
);
1026 void wxStyledTextCtrl::MarkerSetForeground(int markerNumber
, const wxColour
& colour
) {
1027 SendMsg(SCI_MARKERSETFORE
, markerNumber
, wxColourAsLong(colour
));
1031 void wxStyledTextCtrl::MarkerSetBackground(int markerNumber
, const wxColour
& colour
) {
1032 SendMsg(SCI_MARKERSETBACK
, markerNumber
, wxColourAsLong(colour
));
1036 int wxStyledTextCtrl::MarkerAdd(int line
, int markerNumber
) {
1037 return SendMsg(SCI_MARKERADD
, line
, markerNumber
);
1041 void wxStyledTextCtrl::MarkerDelete(int line
, int markerNumber
) {
1042 SendMsg(SCI_MARKERDELETE
, line
, markerNumber
);
1046 void wxStyledTextCtrl::MarkerDeleteAll(int markerNumber
) {
1047 SendMsg(SCI_MARKERDELETEALL
, markerNumber
);
1051 int wxStyledTextCtrl::MarkerGet(int line
) {
1052 return SendMsg(SCI_MARKERGET
);
1056 int wxStyledTextCtrl::MarkerGetNextLine(int lineStart
, int markerMask
) {
1057 return SendMsg(SCI_MARKERNEXT
, lineStart
, markerMask
);
1061 int wxStyledTextCtrl::MarkerGetPrevLine(int lineStart
, int markerMask
) {
1062 // return SendMsg(SCI_MARKERPREV, lineStart, markerMask);
1067 int wxStyledTextCtrl::MarkerLineFromHandle(int handle
) {
1068 return SendMsg(SCI_MARKERLINEFROMHANDLE
, handle
);
1072 void wxStyledTextCtrl::MarkerDeleteHandle(int handle
) {
1073 SendMsg(SCI_MARKERDELETEHANDLE
, handle
);
1078 //----------------------------------------------------------------------
1082 void wxStyledTextCtrl::IndicatorSetStyle(int indicNum
, int indicStyle
) {
1083 SendMsg(SCI_INDICSETSTYLE
, indicNum
, indicStyle
);
1087 int wxStyledTextCtrl::IndicatorGetStyle(int indicNum
) {
1088 return SendMsg(SCI_INDICGETSTYLE
, indicNum
);
1092 void wxStyledTextCtrl::IndicatorSetColour(int indicNum
, const wxColour
& colour
) {
1093 SendMsg(SCI_INDICSETFORE
, indicNum
, wxColourAsLong(colour
));
1098 //----------------------------------------------------------------------
1102 void wxStyledTextCtrl::AutoCompShow(const wxString
& listOfWords
) {
1103 SendMsg(SCI_AUTOCSHOW
, 0, (long)listOfWords
.c_str());
1107 void wxStyledTextCtrl::AutoCompCancel() {
1108 SendMsg(SCI_AUTOCCANCEL
);
1112 bool wxStyledTextCtrl::AutoCompActive() {
1113 return SendMsg(SCI_AUTOCACTIVE
) != 0;
1117 int wxStyledTextCtrl::AutoCompPosAtStart() {
1118 return SendMsg(SCI_AUTOCPOSSTART
);
1122 void wxStyledTextCtrl::AutoCompComplete() {
1123 SendMsg(SCI_AUTOCCOMPLETE
);
1127 void wxStyledTextCtrl::AutoCompStopChars(const wxString
& stopChars
) {
1128 SendMsg(SCI_AUTOCSHOW
, 0, (long)stopChars
.c_str());
1132 void wxStyledTextCtrl::AutoCompSetSeparator(char separator
) {
1133 SendMsg(SCI_AUTOCSETSEPARATOR
, separator
);
1137 char wxStyledTextCtrl::AutoCompGetSeparator() {
1138 return SendMsg(SCI_AUTOCGETSEPARATOR
);
1142 void wxStyledTextCtrl::AutoCompSelect(const wxString
& stringtoselect
) {
1143 SendMsg(SCI_AUTOCSELECT
, (long)stringtoselect
.c_str());
1147 //----------------------------------------------------------------------
1150 void wxStyledTextCtrl::CallTipShow(int pos
, const wxString
& text
) {
1151 SendMsg(SCI_CALLTIPSHOW
, pos
, (long)text
.c_str());
1155 void wxStyledTextCtrl::CallTipCancel() {
1156 SendMsg(SCI_CALLTIPCANCEL
);
1160 bool wxStyledTextCtrl::CallTipActive() {
1161 return SendMsg(SCI_CALLTIPACTIVE
) != 0;
1165 int wxStyledTextCtrl::CallTipPosAtStart() {
1166 return SendMsg(SCI_CALLTIPPOSSTART
);
1170 void wxStyledTextCtrl::CallTipSetHighlight(int start
, int end
) {
1171 SendMsg(SCI_CALLTIPSETHLT
, start
, end
);
1175 void wxStyledTextCtrl::CallTipSetBackground(const wxColour
& colour
) {
1176 SendMsg(SCI_CALLTIPSETBACK
, wxColourAsLong(colour
));
1180 //----------------------------------------------------------------------
1183 void wxStyledTextCtrl::CmdKeyAssign(int key
, int modifiers
, int cmd
) {
1184 SendMsg(SCI_ASSIGNCMDKEY
, MAKELONG(key
, modifiers
), cmd
);
1188 void wxStyledTextCtrl::CmdKeyClear(int key
, int modifiers
) {
1189 SendMsg(SCI_CLEARCMDKEY
, MAKELONG(key
, modifiers
));
1193 void wxStyledTextCtrl::CmdKeyClearAll() {
1194 SendMsg(SCI_CLEARALLCMDKEYS
);
1198 void wxStyledTextCtrl::CmdKeyExecute(int cmd
) {
1204 //----------------------------------------------------------------------
1208 wxStyledTextCtrl::FormatRange(bool doDraw
,
1212 wxDC
* target
, // Why does it use two? Can they be the same?
1218 fr
.hdcTarget
= target
;
1219 fr
.rc
.top
= renderRect
.GetTop();
1220 fr
.rc
.left
= renderRect
.GetLeft();
1221 fr
.rc
.right
= renderRect
.GetRight();
1222 fr
.rc
.bottom
= renderRect
.GetBottom();
1223 fr
.rcPage
.top
= pageRect
.GetTop();
1224 fr
.rcPage
.left
= pageRect
.GetLeft();
1225 fr
.rcPage
.right
= pageRect
.GetRight();
1226 fr
.rcPage
.bottom
= pageRect
.GetBottom();
1227 fr
.chrg
.cpMin
= startPos
;
1228 fr
.chrg
.cpMax
= endPos
;
1230 return SendMsg(EM_FORMATRANGE
, doDraw
, (long)&fr
);
1234 //----------------------------------------------------------------------
1237 void* wxStyledTextCtrl::GetDocument() {
1238 return (void*)SendMsg(SCI_GETDOCPOINTER
);
1242 void wxStyledTextCtrl::SetDocument(void* document
) {
1243 SendMsg(SCI_SETDOCPOINTER
, 0, (long)document
);
1247 //----------------------------------------------------------------------
1250 int wxStyledTextCtrl::VisibleFromDocLine(int docLine
) {
1251 return SendMsg(SCI_VISIBLEFROMDOCLINE
, docLine
);
1255 int wxStyledTextCtrl::DocLineFromVisible(int displayLine
) {
1256 return SendMsg(SCI_DOCLINEFROMVISIBLE
, displayLine
);
1260 int wxStyledTextCtrl::SetFoldLevel(int line
, int level
) {
1261 return SendMsg(SCI_SETFOLDLEVEL
, line
, level
);
1265 int wxStyledTextCtrl::GetFoldLevel(int line
) {
1266 return SendMsg(SCI_GETFOLDLEVEL
, line
);
1270 int wxStyledTextCtrl::GetLastChild(int line
, int level
) {
1271 return SendMsg(SCI_GETLASTCHILD
, line
, level
);
1275 int wxStyledTextCtrl::GetFoldParent(int line
) {
1276 return SendMsg(SCI_GETFOLDPARENT
, line
);
1280 void wxStyledTextCtrl::ShowLines(int lineStart
, int lineEnd
) {
1281 SendMsg(SCI_SHOWLINES
, lineStart
, lineEnd
);
1285 void wxStyledTextCtrl::HideLines(int lineStart
, int lineEnd
) {
1286 SendMsg(SCI_HIDELINES
, lineStart
, lineEnd
);
1290 bool wxStyledTextCtrl::GetLineVisible(int line
) {
1291 return SendMsg(SCI_GETLINEVISIBLE
, line
) != 0;
1295 void wxStyledTextCtrl::SetFoldExpanded(int line
, bool expanded
) {
1296 SendMsg(SCI_SETFOLDEXPANDED
, line
, expanded
);
1300 bool wxStyledTextCtrl::GetFoldExpanded(int line
) {
1301 return SendMsg(SCI_GETFOLDEXPANDED
, line
) != 0;
1305 void wxStyledTextCtrl::ToggleFold(int line
) {
1306 SendMsg(SCI_TOGGLEFOLD
, line
);
1310 void wxStyledTextCtrl::EnsureVisible(int line
) {
1311 SendMsg(SCI_ENSUREVISIBLE
, line
);
1315 void wxStyledTextCtrl::SetFoldFlags(int flags
) {
1316 SendMsg(SCI_SETFOLDFLAGS
, flags
);
1320 //----------------------------------------------------------------------
1323 void wxStyledTextCtrl::ZoomIn() {
1324 SendMsg(SCI_ZOOMIN
);
1328 void wxStyledTextCtrl::ZoomOut() {
1329 SendMsg(SCI_ZOOMOUT
);
1333 void wxStyledTextCtrl::SetZoom(int zoom
) {
1334 SendMsg(SCI_SETZOOM
, zoom
);
1338 int wxStyledTextCtrl::GetZoom() {
1339 return SendMsg(SCI_GETZOOM
);
1342 //----------------------------------------------------------------------
1345 int wxStyledTextCtrl::GetEdgeColumn() {
1346 return SendMsg(SCI_GETEDGECOLUMN
);
1349 void wxStyledTextCtrl::SetEdgeColumn(int column
) {
1350 SendMsg(SCI_SETEDGECOLUMN
, column
);
1353 wxSTC_EDGE
wxStyledTextCtrl::GetEdgeMode() {
1354 return (wxSTC_EDGE
) SendMsg(SCI_GETEDGEMODE
);
1357 void wxStyledTextCtrl::SetEdgeMode(wxSTC_EDGE mode
){
1358 SendMsg(SCI_SETEDGEMODE
, mode
);
1361 wxColour
wxStyledTextCtrl::GetEdgeColour() {
1362 long c
= SendMsg(SCI_GETEDGECOLOUR
);
1363 return wxColourFromLong(c
);
1366 void wxStyledTextCtrl::SetEdgeColour(const wxColour
& colour
) {
1367 SendMsg(SCI_SETEDGECOLOUR
, wxColourAsLong(colour
));
1371 //----------------------------------------------------------------------
1374 void wxStyledTextCtrl::SetLexer(wxSTC_LEX lexer
) {
1375 SendMsg(SCI_SETLEXER
, lexer
);
1379 wxSTC_LEX
wxStyledTextCtrl::GetLexer() {
1380 return (wxSTC_LEX
)SendMsg(SCI_GETLEXER
);
1384 void wxStyledTextCtrl::Colourise(int start
, int end
) {
1385 SendMsg(SCI_COLOURISE
, start
, end
);
1389 void wxStyledTextCtrl::SetProperty(const wxString
& key
, const wxString
& value
) {
1390 SendMsg(SCI_SETPROPERTY
, (long)key
.c_str(), (long)value
.c_str());
1394 void wxStyledTextCtrl::SetKeywords(int keywordSet
, const wxString
& keywordList
) {
1395 SendMsg(SCI_SETKEYWORDS
, keywordSet
, (long)keywordList
.c_str());
1400 //----------------------------------------------------------------------
1401 // Event mask for Modified Event
1403 void wxStyledTextCtrl::SetModEventMask(int mask
) {
1404 SendMsg(SCI_SETMODEVENTMASK
, mask
);
1408 //int wxStyledTextCtrl::GetModEventMask() {
1409 // return SendMsg(SCI_GETMODEVENTMASK);
1412 //----------------------------------------------------------------------
1415 void wxStyledTextCtrl::OnPaint(wxPaintEvent
& evt
) {
1417 wxRegion region
= GetUpdateRegion();
1419 m_swx
->DoPaint(&dc
, region
.GetBox());
1422 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent
& evt
) {
1423 if (evt
.GetOrientation() == wxHORIZONTAL
)
1424 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
1426 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
1429 void wxStyledTextCtrl::OnSize(wxSizeEvent
& evt
) {
1430 wxSize sz
= GetClientSize();
1431 m_swx
->DoSize(sz
.x
, sz
.y
);
1434 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent
& evt
) {
1435 wxPoint pt
= evt
.GetPosition();
1436 m_swx
->DoButtonDown(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1437 evt
.ShiftDown(), evt
.ControlDown(), evt
.AltDown());
1440 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent
& evt
) {
1441 wxPoint pt
= evt
.GetPosition();
1442 m_swx
->DoButtonMove(Point(pt
.x
, pt
.y
));
1445 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent
& evt
) {
1446 wxPoint pt
= evt
.GetPosition();
1447 m_swx
->DoButtonUp(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1452 void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent
& evt
) {
1453 wxPoint pt
= evt
.GetPosition();
1454 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
1457 void wxStyledTextCtrl::OnChar(wxKeyEvent
& evt
) {
1458 long key
= evt
.KeyCode();
1459 if ((key
> WXK_ESCAPE
) &&
1460 (key
!= WXK_DELETE
) && (key
< 255) &&
1461 !evt
.ControlDown() && !evt
.AltDown()) {
1463 m_swx
->DoAddChar(key
);
1470 void wxStyledTextCtrl::OnKeyDown(wxKeyEvent
& evt
) {
1471 long key
= evt
.KeyCode();
1473 int processed
= m_swx
->DoKeyDown(key
, evt
.ShiftDown(),
1474 evt
.ControlDown(), evt
.AltDown());
1479 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent
& evt
) {
1480 m_swx
->DoLoseFocus();
1483 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent
& evt
) {
1484 m_swx
->DoGainFocus();
1487 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& evt
) {
1488 m_swx
->DoSysColourChange();
1491 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent
& evt
) {
1492 // do nothing to help avoid flashing
1497 void wxStyledTextCtrl::OnMenu(wxCommandEvent
& evt
) {
1498 m_swx
->DoCommand(evt
.GetId());
1502 void wxStyledTextCtrl::OnListBox(wxCommandEvent
& evt
) {
1503 m_swx
->DoOnListBox();
1507 //----------------------------------------------------------------------
1508 // Turn notifications from Scintilla into events
1511 void wxStyledTextCtrl::NotifyChange() {
1512 wxStyledTextEvent
evt(wxEVT_STC_CHANGE
, GetId());
1513 GetEventHandler()->ProcessEvent(evt
);
1516 void wxStyledTextCtrl::NotifyParent(SCNotification
* _scn
) {
1517 SCNotification
& scn
= *_scn
;
1519 switch (scn
.nmhdr
.code
) {
1520 case SCN_STYLENEEDED
:
1521 eventType
= wxEVT_STC_STYLENEEDED
;
1524 eventType
= wxEVT_STC_CHARADDED
;
1527 eventType
= wxEVT_STC_UPDATEUI
;
1529 case SCN_SAVEPOINTREACHED
:
1530 eventType
= wxEVT_STC_SAVEPOINTREACHED
;
1532 case SCN_SAVEPOINTLEFT
:
1533 eventType
= wxEVT_STC_SAVEPOINTLEFT
;
1535 case SCN_MODIFYATTEMPTRO
:
1536 eventType
= wxEVT_STC_ROMODIFYATTEMPT
;
1538 case SCN_DOUBLECLICK
:
1539 eventType
= wxEVT_STC_DOUBLECLICK
;
1542 eventType
= wxEVT_STC_MODIFIED
;
1545 eventType
= wxEVT_STC_KEY
;
1547 case SCN_MACRORECORD
:
1548 eventType
= wxEVT_STC_MACRORECORD
;
1550 case SCN_MARGINCLICK
:
1551 eventType
= wxEVT_STC_MARGINCLICK
;
1554 eventType
= wxEVT_STC_NEEDSHOWN
;
1558 wxStyledTextEvent
evt(eventType
, GetId());
1559 evt
.SetPosition(scn
.position
);
1561 evt
.SetModifiers(scn
.modifiers
);
1562 if (eventType
== wxEVT_STC_MODIFIED
) {
1563 evt
.SetModificationType(scn
.modificationType
);
1565 evt
.SetText(wxString(scn
.text
, scn
.length
));
1566 evt
.SetLength(scn
.length
);
1567 evt
.SetLinesAdded(scn
.linesAdded
);
1568 evt
.SetLine(scn
.line
);
1569 evt
.SetFoldLevelNow(scn
.foldLevelNow
);
1570 evt
.SetFoldLevelPrev(scn
.foldLevelPrev
);
1572 if (eventType
== wxEVT_STC_MARGINCLICK
)
1573 evt
.SetMargin(scn
.margin
);
1574 if (eventType
== wxEVT_STC_MACRORECORD
) {
1575 evt
.SetMessage(scn
.message
);
1576 evt
.SetWParam(scn
.wParam
);
1577 evt
.SetLParam(scn
.lParam
);
1580 GetEventHandler()->ProcessEvent(evt
);
1586 //----------------------------------------------------------------------
1587 //----------------------------------------------------------------------
1588 //----------------------------------------------------------------------
1590 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType
, int id
)
1591 : wxCommandEvent(commandType
, id
)
1596 m_modificationType
= 0;
1601 m_foldLevelPrev
= 0;
1610 bool wxStyledTextEvent::GetShift() const { return (m_modifiers
& SCI_SHIFT
) != 0; }
1611 bool wxStyledTextEvent::GetControl() const { return (m_modifiers
& SCI_CTRL
) != 0; }
1612 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers
& SCI_ALT
) != 0; }
1614 void wxStyledTextEvent::CopyObject(wxObject
& obj
) const {
1615 wxCommandEvent::CopyObject(obj
);
1617 wxStyledTextEvent
* o
= (wxStyledTextEvent
*)&obj
;
1618 o
->m_position
= m_position
;
1620 o
->m_modifiers
= m_modifiers
;
1621 o
->m_modificationType
= m_modificationType
;
1623 o
->m_length
= m_length
;
1624 o
->m_linesAdded
= m_linesAdded
;
1626 o
->m_foldLevelNow
= m_foldLevelNow
;
1627 o
->m_foldLevelPrev
= m_foldLevelPrev
;
1629 o
->m_margin
= m_margin
;
1631 o
->m_message
= m_message
;
1632 o
->m_wParam
= m_wParam
;
1633 o
->m_lParam
= m_lParam
;
1639 //----------------------------------------------------------------------
1640 //----------------------------------------------------------------------