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 itentifiers from Scintilla.
12 // Created: 13-Jan-2000
14 // Copyright: (c) 2000 by Total Control Software
15 // Licence: wxWindows license
16 /////////////////////////////////////////////////////////////////////////////
18 #include "wx/stc/stc.h"
19 #include "ScintillaWX.h"
21 #include <wx/tokenzr.h>
23 //----------------------------------------------------------------------
25 const wxChar
* wxSTCNameStr
= "stcwindow";
27 BEGIN_EVENT_TABLE(wxStyledTextCtrl
, wxControl
)
28 EVT_PAINT (wxStyledTextCtrl::OnPaint
)
29 EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin
)
30 EVT_SIZE (wxStyledTextCtrl::OnSize
)
31 EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown
)
32 EVT_MOTION (wxStyledTextCtrl::OnMouseMove
)
33 EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp
)
34 EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp
)
35 EVT_CHAR (wxStyledTextCtrl::OnChar
)
36 EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus
)
37 EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus
)
38 EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged
)
39 EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground
)
40 EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu
)
43 //----------------------------------------------------------------------
44 // Constructor and Destructor
46 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow
*parent
,
51 const wxString
& name
) :
52 wxControl(parent
, id
, pos
, size
,
53 style
| wxVSCROLL
| wxHSCROLL
| wxWANTS_CHARS
,
54 wxDefaultValidator
, name
)
56 m_swx
= new ScintillaWX(this);
57 // m_keywords = new WordList;
60 m_undoType
= wxSTC_UndoCollectAutoStart
;
64 wxStyledTextCtrl::~wxStyledTextCtrl() {
70 //----------------------------------------------------------------------
72 inline long wxStyledTextCtrl::SendMsg(int msg
, long wp
, long lp
) {
74 return m_swx
->WndProc(msg
, wp
, lp
);
78 //----------------------------------------------------------------------
79 // Text retrieval and modification
81 wxString
wxStyledTextCtrl::GetText() {
83 int len
= GetTextLength();
84 char* buff
= text
.GetWriteBuf(len
);
86 SendMsg(WM_GETTEXT
, len
, (long)buff
);
92 bool wxStyledTextCtrl::SetText(const wxString
& text
) {
93 return SendMsg(WM_SETTEXT
, 0, (long)text
.c_str()) != 0;
97 wxString
wxStyledTextCtrl::GetLine(int line
) {
99 int len
= GetLineLength(line
);
100 char* buff
= text
.GetWriteBuf(len
+1);
102 *((WORD
*)buff
) = len
+1;
103 SendMsg(EM_GETLINE
, line
, (long)buff
);
104 text
.UngetWriteBuf();
109 void wxStyledTextCtrl::ReplaceSelection(const wxString
& text
) {
110 SendMsg(EM_REPLACESEL
, 0, (long)text
.c_str());
114 void wxStyledTextCtrl::SetReadOnly(bool readOnly
) {
115 SendMsg(EM_SETREADONLY
, (long)readOnly
);
116 m_readOnly
= readOnly
;
120 bool wxStyledTextCtrl::GetReadOnly() {
121 // TODO: need support in Scintilla to do this right,
122 // until then we'll track it ourselves
127 void wxStyledTextCtrl::GetTextRange(int startPos
, int endPos
, char* buff
) {
130 tr
.chrg
.cpMin
= startPos
;
131 tr
.chrg
.cpMax
= endPos
;
132 SendMsg(EM_GETTEXTRANGE
, 0, (long)&tr
);
136 wxString
wxStyledTextCtrl::GetTextRange(int startPos
, int endPos
) {
138 int len
= endPos
- startPos
;
139 char* buff
= text
.GetWriteBuf(len
);
140 GetTextRange(startPos
, endPos
, buff
);
141 text
.UngetWriteBuf();
146 void wxStyledTextCtrl::GetStyledTextRange(int startPos
, int endPos
, char* buff
) {
149 tr
.chrg
.cpMin
= startPos
;
150 tr
.chrg
.cpMax
= endPos
;
151 SendMsg(SCI_GETSTYLEDTEXT
, 0, (long)&tr
);
155 wxString
wxStyledTextCtrl::GetStyledTextRange(int startPos
, int endPos
) {
157 int len
= endPos
- startPos
;
158 char* buff
= text
.GetWriteBuf(len
*2);
159 GetStyledTextRange(startPos
, endPos
, buff
);
160 text
.UngetWriteBuf(len
*2);
165 void wxStyledTextCtrl::AddText(const wxString
& text
) {
166 SendMsg(SCI_ADDTEXT
, text
.Len(), (long)text
.c_str());
170 void wxStyledTextCtrl::AddStyledText(const wxString
& text
) {
171 SendMsg(SCI_ADDSTYLEDTEXT
, text
.Len(), (long)text
.c_str());
175 void wxStyledTextCtrl::InsertText(int pos
, const wxString
& text
) {
176 SendMsg(SCI_INSERTTEXT
, pos
, (long)text
.c_str());
180 void wxStyledTextCtrl::ClearAll() {
181 SendMsg(SCI_CLEARALL
);
185 char wxStyledTextCtrl::GetCharAt(int pos
) {
186 return SendMsg(SCI_GETCHARAT
, pos
);
190 char wxStyledTextCtrl::GetStyleAt(int pos
) {
191 return SendMsg(SCI_GETSTYLEAT
, pos
);
195 void wxStyledTextCtrl::SetStyleBits(int bits
) {
196 SendMsg(SCI_SETSTYLEBITS
, bits
);
200 int wxStyledTextCtrl::GetStyleBits() {
201 return SendMsg(SCI_GETSTYLEBITS
);
205 //----------------------------------------------------------------------
209 void wxStyledTextCtrl::Cut() {
214 void wxStyledTextCtrl::Copy() {
219 void wxStyledTextCtrl::Paste() {
224 bool wxStyledTextCtrl::CanPaste() {
225 return SendMsg(EM_CANPASTE
) != 0;
229 void wxStyledTextCtrl::ClearClipbrd() {
235 //----------------------------------------------------------------------
238 void wxStyledTextCtrl::Undo() {
243 bool wxStyledTextCtrl::CanUndo() {
244 return SendMsg(EM_CANUNDO
) != 0;
248 void wxStyledTextCtrl::EmptyUndoBuffer() {
249 SendMsg(EM_EMPTYUNDOBUFFER
);
253 void wxStyledTextCtrl::Redo() {
258 bool wxStyledTextCtrl::CanRedo() {
259 return SendMsg(SCI_CANREDO
) != 0;
263 void wxStyledTextCtrl::SetUndoCollection(wxSTC_UndoType type
) {
264 SendMsg(SCI_SETUNDOCOLLECTION
, type
);
269 wxSTC_UndoType
wxStyledTextCtrl::GetUndoCollection() {
270 // TODO: need support in Scintilla to do this right,
271 // until then we'll track it ourselves
276 void wxStyledTextCtrl::BeginUndoAction() {
277 SendMsg(SCI_BEGINUNDOACTION
);
281 void wxStyledTextCtrl::EndUndoAction() {
282 SendMsg(SCI_ENDUNDOACTION
);
288 //----------------------------------------------------------------------
289 // Selection and information
292 void wxStyledTextCtrl::GetSelection(int* startPos
, int* endPos
) {
293 SendMsg(EM_GETSEL
, (long)startPos
, (long)endPos
);
297 void wxStyledTextCtrl::SetSelection(int startPos
, int endPos
) {
298 SendMsg(EM_SETSEL
, startPos
, endPos
);
302 wxString
wxStyledTextCtrl::GetSelectedText() {
307 GetSelection(&start
, &end
);
308 int len
= end
- start
;
309 char* buff
= text
.GetWriteBuf(len
);
311 SendMsg(EM_GETSELTEXT
, 0, (long)buff
);
312 text
.UngetWriteBuf();
317 void wxStyledTextCtrl::HideSelection(bool hide
) {
318 SendMsg(EM_HIDESELECTION
, hide
);
322 bool wxStyledTextCtrl::GetHideSelection() {
323 return m_swx
->GetHideSelection();
327 int wxStyledTextCtrl::GetTextLength() {
328 return SendMsg(WM_GETTEXTLENGTH
);
332 int wxStyledTextCtrl::GetFirstVisibleLine() {
333 return SendMsg(EM_GETFIRSTVISIBLELINE
);
337 int wxStyledTextCtrl::GetLineCount() {
338 return SendMsg(EM_GETLINECOUNT
);
342 bool wxStyledTextCtrl::GetModified() {
343 return SendMsg(EM_GETMODIFY
) != 0;
347 wxRect
wxStyledTextCtrl::GetRect() {
349 SendMsg(EM_GETRECT
, 0, (long)&pr
);
351 wxRect rect
= wxRectFromPRectangle(pr
);
356 int wxStyledTextCtrl::GetLineFromPos(int pos
) {
357 return SendMsg(EM_LINEFROMCHAR
, pos
);
361 int wxStyledTextCtrl::GetLineStartPos(int line
) {
362 return SendMsg(EM_LINEINDEX
, line
);
366 int wxStyledTextCtrl::GetLineLengthAtPos(int pos
) {
367 return SendMsg(EM_LINELENGTH
, pos
);
371 int wxStyledTextCtrl::GetLineLength(int line
) {
372 return SendMsg(SCI_LINELENGTH
, line
);
376 int wxStyledTextCtrl::GetCurrentLine() {
377 int line
= GetLineFromPos(GetCurrentPos());
382 wxString
wxStyledTextCtrl::GetCurrentLineText(int* linePos
) {
384 int len
= GetLineLength(GetCurrentLine());
385 char* buff
= text
.GetWriteBuf(len
+1);
387 int pos
= SendMsg(SCI_GETCURLINE
, len
+1, (long)buff
);
388 text
.UngetWriteBuf();
397 int wxStyledTextCtrl::PositionFromPoint(wxPoint pt
) {
398 Point
spt(pt
.x
, pt
.y
);
399 long rv
= SendMsg(EM_CHARFROMPOS
, 0, (long)&spt
);
404 int wxStyledTextCtrl::LineFromPoint(wxPoint pt
) {
405 Point
spt(pt
.x
, pt
.y
);
406 long rv
= SendMsg(EM_CHARFROMPOS
, 0, (long)&spt
);
411 wxPoint
wxStyledTextCtrl::PointFromPosition(int pos
) {
413 SendMsg(EM_POSFROMCHAR
, pos
, (long)&pt
);
414 return wxPoint(pt
.x
, pt
.y
);
418 int wxStyledTextCtrl::GetCurrentPos() {
419 return SendMsg(SCI_GETCURRENTPOS
);
423 int wxStyledTextCtrl::GetAnchor() {
424 return SendMsg(SCI_GETANCHOR
);
428 void wxStyledTextCtrl::SelectAll() {
429 SendMsg(SCI_SELECTALL
);
433 void wxStyledTextCtrl::SetCurrentPosition(int pos
) {
434 SendMsg(SCI_GOTOPOS
, pos
);
438 void wxStyledTextCtrl::SetAnchor(int pos
) {
439 SendMsg(SCI_SETANCHOR
, pos
);
443 void wxStyledTextCtrl::GotoPos(int pos
) {
444 SendMsg(SCI_GOTOPOS
, pos
);
448 void wxStyledTextCtrl::GotoLine(int line
) {
449 SendMsg(SCI_GOTOLINE
, line
);
453 void wxStyledTextCtrl::ChangePosition(int delta
, bool extendSelection
) {
454 // TODO: Is documented but doesn't seem to be implemented
455 //SendMsg(SCI_CHANGEPOSITION, delta, extendSelection);
459 void wxStyledTextCtrl::PageMove(int cmdKey
, bool extendSelection
) {
460 // TODO: Is documented but doesn't seem to be implemented
461 //SendMsg(SCI_PAGEMOVE, cmdKey, extendSelection);
465 void wxStyledTextCtrl::ScrollBy(int columnDelta
, int lineDelta
) {
466 SendMsg(EM_LINESCROLL
, columnDelta
, lineDelta
);
469 void wxStyledTextCtrl::ScrollToLine(int line
) {
470 m_swx
->DoScrollToLine(line
);
474 void wxStyledTextCtrl::ScrollToColumn(int column
) {
475 m_swx
->DoScrollToColumn(column
);
479 void wxStyledTextCtrl::EnsureCaretVisible() {
480 SendMsg(EM_SCROLLCARET
);
484 void wxStyledTextCtrl::SetCaretPolicy(int policy
, int slop
) {
485 SendMsg(SCI_SETCARETPOLICY
, policy
, slop
);
489 int wxStyledTextCtrl::GetSelectionType() {
490 return SendMsg(EM_SELECTIONTYPE
);
496 //----------------------------------------------------------------------
499 int wxStyledTextCtrl::FindText(int minPos
, int maxPos
,
500 const wxString
& text
,
501 bool caseSensitive
, bool wholeWord
) {
505 flags
|= caseSensitive
? FR_MATCHCASE
: 0;
506 flags
|= wholeWord
? FR_WHOLEWORD
: 0;
507 ft
.chrg
.cpMin
= minPos
;
508 ft
.chrg
.cpMax
= maxPos
;
509 ft
.lpstrText
= (char*)text
.c_str();
511 return SendMsg(EM_FINDTEXT
, flags
, (long)&ft
);
515 void wxStyledTextCtrl::SearchAnchor() {
516 SendMsg(SCI_SEARCHANCHOR
);
520 int wxStyledTextCtrl::SearchNext(const wxString
& text
, bool caseSensitive
, bool wholeWord
) {
522 flags
|= caseSensitive
? FR_MATCHCASE
: 0;
523 flags
|= wholeWord
? FR_WHOLEWORD
: 0;
525 return SendMsg(SCI_SEARCHNEXT
, flags
, (long)text
.c_str());
529 int wxStyledTextCtrl::SearchPrev(const wxString
& text
, bool caseSensitive
, bool wholeWord
) {
531 flags
|= caseSensitive
? FR_MATCHCASE
: 0;
532 flags
|= wholeWord
? FR_WHOLEWORD
: 0;
534 return SendMsg(SCI_SEARCHPREV
, flags
, (long)text
.c_str());
537 //----------------------------------------------------------------------
538 // Visible whitespace
541 bool wxStyledTextCtrl::GetViewWhitespace() {
542 return SendMsg(SCI_GETVIEWWS
) != 0;
546 void wxStyledTextCtrl::SetViewWhitespace(bool visible
) {
547 SendMsg(SCI_SETVIEWWS
, visible
);
552 //----------------------------------------------------------------------
555 wxSTC_EOL
wxStyledTextCtrl::GetEOLMode() {
556 return (wxSTC_EOL
)SendMsg(SCI_GETEOLMODE
);
560 void wxStyledTextCtrl::SetEOLMode(wxSTC_EOL mode
) {
561 SendMsg(SCI_SETEOLMODE
, mode
);
565 bool wxStyledTextCtrl::GetViewEOL() {
566 return SendMsg(SCI_GETVIEWEOL
) != 0;
570 void wxStyledTextCtrl::SetViewEOL(bool visible
) {
571 SendMsg(SCI_SETVIEWEOL
, visible
);
574 void wxStyledTextCtrl::ConvertEOL(wxSTC_EOL mode
) {
575 SendMsg(SCI_CONVERTEOLS
, mode
);
578 //----------------------------------------------------------------------
581 int wxStyledTextCtrl::GetEndStyled() {
582 return SendMsg(SCI_GETENDSTYLED
);
586 void wxStyledTextCtrl::StartStyling(int pos
, int mask
) {
587 SendMsg(SCI_STARTSTYLING
, pos
, mask
);
591 void wxStyledTextCtrl::SetStyleFor(int length
, int style
) {
592 SendMsg(SCI_SETSTYLING
, length
, style
);
596 void wxStyledTextCtrl::SetStyleBytes(int length
, char* styleBytes
) {
597 SendMsg(SCI_SETSTYLINGEX
, length
, (long)styleBytes
);
601 //----------------------------------------------------------------------
605 static long wxColourAsLong(const wxColour
& co
) {
606 return (((long)co
.Blue() << 16) |
607 ((long)co
.Green() << 8) |
611 static wxColour
wxColourFromLong(long c
) {
613 clr
.Set(c
& 0xff, (c
>> 8) & 0xff, (c
>> 16) & 0xff);
618 static wxColour
wxColourFromSpec(const wxString
& spec
) {
619 // spec should be #RRGGBB
621 int red
= strtol(spec
.Mid(1,2), &junk
, 16);
622 int green
= strtol(spec
.Mid(3,2), &junk
, 16);
623 int blue
= strtol(spec
.Mid(5,2), &junk
, 16);
624 return wxColour(red
, green
, blue
);
628 void wxStyledTextCtrl::StyleClearAll() {
629 SendMsg(SCI_STYLECLEARALL
);
633 void wxStyledTextCtrl::StyleResetDefault() {
634 SendMsg(SCI_STYLERESETDEFAULT
);
639 // Extract style settings from a spec-string which is composed of one or
640 // more of the following comma separated elements:
642 // bold turns on bold
643 // italic turns on italics
644 // fore:#RRGGBB sets the foreground colour
645 // back:#RRGGBB sets the background colour
646 // face:[facename] sets the font face name to use
647 // size:[num] sets the font size in points
648 // eol turns on eol filling
651 void wxStyledTextCtrl::StyleSetSpec(int styleNum
, const wxString
& spec
) {
653 wxStringTokenizer
tkz(spec
, ",");
654 while (tkz
.HasMoreTokens()) {
655 wxString token
= tkz
.GetNextToken();
657 wxString option
= token
.BeforeFirst(':');
658 wxString val
= token
.AfterFirst(':');
660 if (option
== "bold")
661 StyleSetBold(styleNum
, true);
663 else if (option
== "italic")
664 StyleSetItalic(styleNum
, true);
666 else if (option
== "eol")
667 StyleSetEOLFilled(styleNum
, true);
669 else if (option
== "size") {
671 if (val
.ToLong(&points
))
672 StyleSetSize(styleNum
, points
);
675 else if (option
== "face")
676 StyleSetFaceName(styleNum
, val
);
678 else if (option
== "fore")
679 StyleSetForeground(styleNum
, wxColourFromSpec(val
));
681 else if (option
== "back")
682 StyleSetBackground(styleNum
, wxColourFromSpec(val
));
687 void wxStyledTextCtrl::StyleSetForeground(int styleNum
, const wxColour
& colour
) {
688 SendMsg(SCI_STYLESETFORE
, styleNum
, wxColourAsLong(colour
));
692 void wxStyledTextCtrl::StyleSetBackground(int styleNum
, const wxColour
& colour
) {
693 SendMsg(SCI_STYLESETBACK
, styleNum
, wxColourAsLong(colour
));
697 void wxStyledTextCtrl::StyleSetFont(int styleNum
, wxFont
& font
) {
698 int size
= font
.GetPointSize();
699 wxString faceName
= font
.GetFaceName();
700 bool bold
= font
.GetWeight() == wxBOLD
;
701 bool italic
= font
.GetStyle() != wxNORMAL
;
703 StyleSetFontAttr(styleNum
, size
, faceName
, bold
, italic
);
707 void wxStyledTextCtrl::StyleSetFontAttr(int styleNum
, int size
,
708 const wxString
& faceName
,
709 bool bold
, bool italic
) {
710 StyleSetSize(styleNum
, size
);
711 StyleSetFaceName(styleNum
, faceName
);
712 StyleSetBold(styleNum
, bold
);
713 StyleSetItalic(styleNum
, italic
);
717 void wxStyledTextCtrl::StyleSetBold(int styleNum
, bool bold
) {
718 SendMsg(SCI_STYLESETBOLD
, styleNum
, bold
);
722 void wxStyledTextCtrl::StyleSetItalic(int styleNum
, bool italic
) {
723 SendMsg(SCI_STYLESETITALIC
, styleNum
, italic
);
727 void wxStyledTextCtrl::StyleSetFaceName(int styleNum
, const wxString
& faceName
) {
728 SendMsg(SCI_STYLESETFONT
, styleNum
, (long)faceName
.c_str());
732 void wxStyledTextCtrl::StyleSetSize(int styleNum
, int pointSize
) {
733 SendMsg(SCI_STYLESETSIZE
, styleNum
, pointSize
);
737 void wxStyledTextCtrl::StyleSetEOLFilled(int styleNum
, bool fillEOL
) {
738 SendMsg(SCI_STYLESETEOLFILLED
, styleNum
, fillEOL
);
742 //----------------------------------------------------------------------
743 // Margins in the edit area
745 int wxStyledTextCtrl::GetLeftMargin() {
746 return LOWORD(SendMsg(EM_GETMARGINS
));
750 int wxStyledTextCtrl::GetRightMargin() {
751 return HIWORD(SendMsg(EM_GETMARGINS
));
755 void wxStyledTextCtrl::SetMargins(int left
, int right
) {
760 flag
|= EC_RIGHTMARGIN
;
764 flag
|= EC_LEFTMARGIN
;
765 val
|= (left
& 0xffff);
768 SendMsg(EM_SETMARGINS
, flag
, val
);
772 //----------------------------------------------------------------------
773 // Margins for selection, markers, etc.
775 void wxStyledTextCtrl::SetMarginType(int margin
, int type
) {
776 SendMsg(SCI_SETMARGINTYPEN
, margin
, type
);
780 int wxStyledTextCtrl::GetMarginType(int margin
) {
781 return SendMsg(SCI_GETMARGINTYPEN
, margin
);
785 void wxStyledTextCtrl::SetMarginWidth(int margin
, int pixelWidth
) {
786 SendMsg(SCI_SETMARGINWIDTHN
, margin
, pixelWidth
);
790 int wxStyledTextCtrl::GetMarginWidth(int margin
) {
791 return SendMsg(SCI_GETMARGINWIDTHN
, margin
);
795 void wxStyledTextCtrl::SetMarginMask(int margin
, int mask
) {
796 SendMsg(SCI_SETMARGINMASKN
, margin
, mask
);
800 int wxStyledTextCtrl::GetMarginMask(int margin
) {
801 return SendMsg(SCI_GETMARGINMASKN
, margin
);
805 void wxStyledTextCtrl::SetMarginSensitive(int margin
, bool sensitive
) {
806 SendMsg(SCI_SETMARGINSENSITIVEN
, margin
, sensitive
);
810 bool wxStyledTextCtrl::GetMarginSensitive(int margin
) {
811 return SendMsg(SCI_GETMARGINSENSITIVEN
, margin
) != 0;
817 //----------------------------------------------------------------------
818 // Selection and Caret styles
821 void wxStyledTextCtrl::SetSelectionForeground(const wxColour
& colour
) {
822 SendMsg(SCI_SETSELFORE
, 0, wxColourAsLong(colour
));
826 void wxStyledTextCtrl::SetSelectionBackground(const wxColour
& colour
) {
827 SendMsg(SCI_SETSELBACK
, 0, wxColourAsLong(colour
));
831 void wxStyledTextCtrl::SetCaretForeground(const wxColour
& colour
) {
832 SendMsg(SCI_SETCARETFORE
, 0, wxColourAsLong(colour
));
836 int wxStyledTextCtrl::GetCaretPeriod() {
837 return SendMsg(SCI_GETCARETPERIOD
);
841 void wxStyledTextCtrl::SetCaretPeriod(int milliseconds
) {
842 SendMsg(SCI_SETCARETPERIOD
, milliseconds
);
847 //----------------------------------------------------------------------
851 void wxStyledTextCtrl::SetBufferedDraw(bool isBuffered
) {
852 SendMsg(SCI_SETBUFFEREDDRAW
, isBuffered
);
856 void wxStyledTextCtrl::SetTabWidth(int numChars
) {
857 SendMsg(SCI_SETTABWIDTH
, numChars
);
861 void wxStyledTextCtrl::SetWordChars(const wxString
& wordChars
) {
862 SendMsg(SCI_SETTABWIDTH
, 0, (long)wordChars
.c_str());
866 //----------------------------------------------------------------------
867 // Brace highlighting
870 void wxStyledTextCtrl::BraceHighlight(int pos1
, int pos2
) {
871 SendMsg(SCI_BRACEHIGHLIGHT
, pos1
, pos2
);
875 void wxStyledTextCtrl::BraceBadlight(int pos
) {
876 SendMsg(SCI_BRACEBADLIGHT
, pos
);
880 int wxStyledTextCtrl::BraceMatch(int pos
, int maxReStyle
) {
881 return SendMsg(SCI_BRACEMATCH
, pos
, maxReStyle
);
886 //----------------------------------------------------------------------
889 void wxStyledTextCtrl::MarkerDefine(int markerNumber
, int markerSymbol
,
890 const wxColour
& foreground
,
891 const wxColour
& background
) {
892 MarkerSetType(markerNumber
, markerSymbol
);
893 MarkerSetForeground(markerNumber
, foreground
);
894 MarkerSetBackground(markerNumber
, background
);
898 void wxStyledTextCtrl::MarkerSetType(int markerNumber
, int markerSymbol
) {
899 SendMsg(SCI_MARKERDEFINE
, markerNumber
, markerSymbol
);
903 void wxStyledTextCtrl::MarkerSetForeground(int markerNumber
, const wxColour
& colour
) {
904 SendMsg(SCI_MARKERSETFORE
, markerNumber
, wxColourAsLong(colour
));
908 void wxStyledTextCtrl::MarkerSetBackground(int markerNumber
, const wxColour
& colour
) {
909 SendMsg(SCI_MARKERSETBACK
, markerNumber
, wxColourAsLong(colour
));
913 int wxStyledTextCtrl::MarkerAdd(int line
, int markerNumber
) {
914 return SendMsg(SCI_MARKERADD
, line
, markerNumber
);
918 void wxStyledTextCtrl::MarkerDelete(int line
, int markerNumber
) {
919 SendMsg(SCI_MARKERDELETE
, line
, markerNumber
);
923 void wxStyledTextCtrl::MarkerDeleteAll(int markerNumber
) {
924 SendMsg(SCI_MARKERDELETEALL
, markerNumber
);
928 int wxStyledTextCtrl::MarkerGet(int line
) {
929 return SendMsg(SCI_MARKERGET
);
933 int wxStyledTextCtrl::MarkerGetNextLine(int lineStart
, int markerMask
) {
934 return SendMsg(SCI_MARKERNEXT
, lineStart
, markerMask
);
938 int wxStyledTextCtrl::MarkerGetPrevLine(int lineStart
, int markerMask
) {
939 // return SendMsg(SCI_MARKERPREV, lineStart, markerMask);
944 int wxStyledTextCtrl::MarkerLineFromHandle(int handle
) {
945 return SendMsg(SCI_MARKERLINEFROMHANDLE
, handle
);
949 void wxStyledTextCtrl::MarkerDeleteHandle(int handle
) {
950 SendMsg(SCI_MARKERDELETEHANDLE
, handle
);
955 //----------------------------------------------------------------------
959 void wxStyledTextCtrl::IndicatorSetStyle(int indicNum
, int indicStyle
) {
960 SendMsg(SCI_INDICSETSTYLE
, indicNum
, indicStyle
);
964 int wxStyledTextCtrl::IndicatorGetStyle(int indicNum
) {
965 return SendMsg(SCI_INDICGETSTYLE
, indicNum
);
969 void wxStyledTextCtrl::IndicatorSetColour(int indicNum
, const wxColour
& colour
) {
970 SendMsg(SCI_INDICSETSTYLE
, indicNum
, wxColourAsLong(colour
));
975 //----------------------------------------------------------------------
979 void wxStyledTextCtrl::AutoCompShow(const wxString
& listOfWords
) {
980 SendMsg(SCI_AUTOCSHOW
, 0, (long)listOfWords
.c_str());
984 void wxStyledTextCtrl::AutoCompCancel() {
985 SendMsg(SCI_AUTOCCANCEL
);
989 bool wxStyledTextCtrl::AutoCompActive() {
990 return SendMsg(SCI_AUTOCACTIVE
) != 0;
994 int wxStyledTextCtrl::AutoCompPosAtStart() {
995 return SendMsg(SCI_AUTOCPOSSTART
);
999 void wxStyledTextCtrl::AutoCompComplete() {
1000 SendMsg(SCI_AUTOCCOMPLETE
);
1004 void wxStyledTextCtrl::AutoCompStopChars(const wxString
& stopChars
) {
1005 SendMsg(SCI_AUTOCSHOW
, 0, (long)stopChars
.c_str());
1009 //----------------------------------------------------------------------
1012 void wxStyledTextCtrl::CallTipShow(int pos
, const wxString
& text
) {
1013 SendMsg(SCI_CALLTIPSHOW
, pos
, (long)text
.c_str());
1017 void wxStyledTextCtrl::CallTipCancel() {
1018 SendMsg(SCI_CALLTIPCANCEL
);
1022 bool wxStyledTextCtrl::CallTipActive() {
1023 return SendMsg(SCI_CALLTIPACTIVE
) != 0;
1027 int wxStyledTextCtrl::CallTipPosAtStart() {
1028 return SendMsg(SCI_CALLTIPPOSSTART
);
1032 void wxStyledTextCtrl::CallTipSetHighlight(int start
, int end
) {
1033 SendMsg(SCI_CALLTIPSETHLT
, start
, end
);
1037 void wxStyledTextCtrl::CallTipSetBackground(const wxColour
& colour
) {
1038 SendMsg(SCI_CALLTIPSETBACK
, wxColourAsLong(colour
));
1042 //----------------------------------------------------------------------
1045 void wxStyledTextCtrl::CmdKeyAssign(int key
, int modifiers
, int cmd
) {
1046 SendMsg(SCI_ASSIGNCMDKEY
, MAKELONG(key
, modifiers
), cmd
);
1050 void wxStyledTextCtrl::CmdKeyClear(int key
, int modifiers
) {
1051 SendMsg(SCI_CLEARCMDKEY
, MAKELONG(key
, modifiers
));
1055 void wxStyledTextCtrl::CmdKeyClearAll() {
1056 SendMsg(SCI_CLEARALLCMDKEYS
);
1060 void wxStyledTextCtrl::CmdKeyExecute(int cmd
) {
1066 //----------------------------------------------------------------------
1070 wxStyledTextCtrl::FormatRange(bool doDraw
,
1074 wxDC
* target
, // Why does it use two? Can they be the same?
1080 fr
.hdcTarget
= target
;
1081 fr
.rc
.top
= renderRect
.GetTop();
1082 fr
.rc
.left
= renderRect
.GetLeft();
1083 fr
.rc
.right
= renderRect
.GetRight();
1084 fr
.rc
.bottom
= renderRect
.GetBottom();
1085 fr
.rcPage
.top
= pageRect
.GetTop();
1086 fr
.rcPage
.left
= pageRect
.GetLeft();
1087 fr
.rcPage
.right
= pageRect
.GetRight();
1088 fr
.rcPage
.bottom
= pageRect
.GetBottom();
1089 fr
.chrg
.cpMin
= startPos
;
1090 fr
.chrg
.cpMax
= endPos
;
1092 return SendMsg(EM_FORMATRANGE
, doDraw
, (long)&fr
);
1096 //----------------------------------------------------------------------
1099 void* wxStyledTextCtrl::GetDocument() {
1100 return (void*)SendMsg(SCI_GETDOCPOINTER
);
1104 void wxStyledTextCtrl::SetDocument(void* document
) {
1105 SendMsg(SCI_SETDOCPOINTER
, 0, (long)document
);
1109 //----------------------------------------------------------------------
1112 int wxStyledTextCtrl::VisibleFromDocLine(int docLine
) {
1113 return SendMsg(SCI_VISIBLEFROMDOCLINE
, docLine
);
1117 int wxStyledTextCtrl::DocLineFromVisible(int displayLine
) {
1118 return SendMsg(SCI_DOCLINEFROMVISIBLE
, displayLine
);
1122 int wxStyledTextCtrl::SetFoldLevel(int line
, int level
) {
1123 return SendMsg(SCI_SETFOLDLEVEL
, line
, level
);
1127 int wxStyledTextCtrl::GetFoldLevel(int line
) {
1128 return SendMsg(SCI_GETFOLDLEVEL
, line
);
1132 int wxStyledTextCtrl::GetLastChild(int line
) {
1133 return SendMsg(SCI_GETLASTCHILD
, line
);
1137 int wxStyledTextCtrl::GetFoldParent(int line
) {
1138 return SendMsg(SCI_GETFOLDPARENT
, line
);
1142 void wxStyledTextCtrl::ShowLines(int lineStart
, int lineEnd
) {
1143 SendMsg(SCI_SHOWLINES
, lineStart
, lineEnd
);
1147 void wxStyledTextCtrl::HideLines(int lineStart
, int lineEnd
) {
1148 SendMsg(SCI_HIDELINES
, lineStart
, lineEnd
);
1152 bool wxStyledTextCtrl::GetLineVisible(int line
) {
1153 return SendMsg(SCI_GETLINEVISIBLE
, line
) != 0;
1157 void wxStyledTextCtrl::SetFoldExpanded(int line
) {
1158 SendMsg(SCI_SETFOLDEXPANDED
, line
);
1162 bool wxStyledTextCtrl::GetFoldExpanded(int line
) {
1163 return SendMsg(SCI_GETFOLDEXPANDED
, line
) != 0;
1167 void wxStyledTextCtrl::ToggleFold(int line
) {
1168 SendMsg(SCI_TOGGLEFOLD
, line
);
1172 void wxStyledTextCtrl::EnsureVisible(int line
) {
1173 SendMsg(SCI_ENSUREVISIBLE
, line
);
1177 //----------------------------------------------------------------------
1180 int wxStyledTextCtrl::GetEdgeColumn() {
1181 return SendMsg(SCI_GETEDGECOLUMN
);
1184 void wxStyledTextCtrl::SetEdgeColumn(int column
) {
1185 SendMsg(SCI_SETEDGECOLUMN
, column
);
1188 wxSTC_EDGE
wxStyledTextCtrl::GetEdgeMode() {
1189 return (wxSTC_EDGE
) SendMsg(SCI_GETEDGEMODE
);
1192 void wxStyledTextCtrl::SetEdgeMode(wxSTC_EDGE mode
){
1193 SendMsg(SCI_SETEDGEMODE
, mode
);
1196 wxColour
wxStyledTextCtrl::GetEdgeColour() {
1197 long c
= SendMsg(SCI_GETEDGECOLOUR
);
1198 return wxColourFromLong(c
);
1201 void wxStyledTextCtrl::SetEdgeColour(const wxColour
& colour
) {
1202 SendMsg(SCI_SETEDGECOLOUR
, wxColourAsLong(colour
));
1206 //----------------------------------------------------------------------
1209 void wxStyledTextCtrl::SetLexer(wxSTC_LEX lexer
) {
1210 SendMsg(SCI_SETLEXER
, lexer
);
1214 wxSTC_LEX
wxStyledTextCtrl::GetLexer() {
1215 return (wxSTC_LEX
)SendMsg(SCI_GETLEXER
);
1219 void wxStyledTextCtrl::Colourise(int start
, int end
) {
1220 SendMsg(SCI_COLOURISE
, start
, end
);
1224 void wxStyledTextCtrl::SetProperty(const wxString
& key
, const wxString
& value
) {
1225 SendMsg(SCI_SETPROPERTY
, (long)key
.c_str(), (long)value
.c_str());
1229 void wxStyledTextCtrl::SetKeywords(int keywordSet
, const wxString
& keywordList
) {
1230 SendMsg(SCI_SETKEYWORDS
, keywordSet
, (long)keywordList
.c_str());
1235 //----------------------------------------------------------------------
1238 void wxStyledTextCtrl::OnPaint(wxPaintEvent
& evt
) {
1240 wxRegion region
= GetUpdateRegion();
1242 m_swx
->DoPaint(&dc
, region
.GetBox());
1245 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent
& evt
) {
1246 if (evt
.GetOrientation() == wxHORIZONTAL
)
1247 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
1249 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
1252 void wxStyledTextCtrl::OnSize(wxSizeEvent
& evt
) {
1253 wxSize sz
= GetClientSize();
1254 m_swx
->DoSize(sz
.x
, sz
.y
);
1257 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent
& evt
) {
1258 wxPoint pt
= evt
.GetPosition();
1259 m_swx
->DoButtonDown(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1260 evt
.ShiftDown(), evt
.ControlDown(), evt
.AltDown());
1263 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent
& evt
) {
1264 wxPoint pt
= evt
.GetPosition();
1265 m_swx
->DoButtonMove(Point(pt
.x
, pt
.y
));
1268 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent
& evt
) {
1269 wxPoint pt
= evt
.GetPosition();
1270 m_swx
->DoButtonUp(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1275 void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent
& evt
) {
1276 wxPoint pt
= evt
.GetPosition();
1277 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
1280 void wxStyledTextCtrl::OnChar(wxKeyEvent
& evt
) {
1282 long key
= evt
.KeyCode();
1283 if ((key
> WXK_ESCAPE
) &&
1284 (key
!= WXK_DELETE
) && (key
< 255) &&
1285 !evt
.ControlDown() && !evt
.AltDown()) {
1287 m_swx
->DoAddChar(key
);
1292 processed
= m_swx
->DoKeyDown(key
, evt
.ShiftDown(),
1293 evt
.ControlDown(), evt
.AltDown());
1299 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent
& evt
) {
1300 m_swx
->DoLoseFocus();
1303 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent
& evt
) {
1304 m_swx
->DoGainFocus();
1307 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& evt
) {
1308 m_swx
->DoSysColourChange();
1311 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent
& evt
) {
1312 // do nothing to help avoid flashing
1317 void wxStyledTextCtrl::OnMenu(wxCommandEvent
& evt
) {
1318 m_swx
->DoCommand(evt
.GetId());
1322 //----------------------------------------------------------------------
1323 // Turn notifications from Scintilla into events
1325 void wxStyledTextCtrl::NotifyChange() {
1326 wxStyledTextEvent
evt(wxEVT_STC_CHANGE
, GetId());
1327 GetEventHandler()->ProcessEvent(evt
);
1330 void wxStyledTextCtrl::NotifyParent(SCNotification
* _scn
) {
1331 SCNotification
& scn
= *_scn
;
1333 switch (scn
.nmhdr
.code
) {
1334 case SCN_STYLENEEDED
:
1335 eventType
= wxEVT_STC_STYLENEEDED
;
1338 eventType
= wxEVT_STC_CHARADDED
;
1341 eventType
= wxEVT_STC_UPDATEUI
;
1343 case SCN_SAVEPOINTREACHED
:
1344 eventType
= wxEVT_STC_SAVEPOINTREACHED
;
1346 case SCN_SAVEPOINTLEFT
:
1347 eventType
= wxEVT_STC_SAVEPOINTLEFT
;
1349 case SCN_MODIFYATTEMPTRO
:
1350 eventType
= wxEVT_STC_ROMODIFYATTEMPT
;
1352 case SCN_DOUBLECLICK
:
1353 eventType
= wxEVT_STC_DOUBLECLICK
;
1356 eventType
= wxEVT_STC_MODIFIED
;
1359 eventType
= wxEVT_STC_KEY
;
1361 case SCN_MACRORECORD
:
1362 eventType
= wxEVT_STC_MACRORECORD
;
1364 case SCN_MARGINCLICK
:
1365 eventType
= wxEVT_STC_MARGINCLICK
;
1368 eventType
= wxEVT_STC_NEEDSHOWN
;
1372 wxStyledTextEvent
evt(eventType
, GetId());
1373 evt
.SetPosition(scn
.position
);
1375 evt
.SetModifiers(scn
.modifiers
);
1376 if (eventType
== wxEVT_STC_MODIFIED
) {
1377 evt
.SetModificationType(scn
.modificationType
);
1378 evt
.SetText(scn
.text
);
1379 evt
.SetLength(scn
.length
);
1380 evt
.SetLinesAdded(scn
.linesAdded
);
1381 evt
.SetLine(scn
.line
);
1382 evt
.SetFoldLevelNow(scn
.foldLevelNow
);
1383 evt
.SetFoldLevelPrev(scn
.foldLevelPrev
);
1385 if (eventType
== wxEVT_STC_MARGINCLICK
)
1386 evt
.SetMargin(scn
.margin
);
1387 if (eventType
== wxEVT_STC_MACRORECORD
) {
1388 evt
.SetMessage(scn
.message
);
1389 evt
.SetWParam(scn
.wParam
);
1390 evt
.SetLParam(scn
.lParam
);
1393 GetEventHandler()->ProcessEvent(evt
);
1399 //----------------------------------------------------------------------
1400 //----------------------------------------------------------------------
1401 //----------------------------------------------------------------------
1403 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType
, int id
)
1404 : wxCommandEvent(commandType
, id
)
1409 m_modificationType
= 0;
1414 m_foldLevelPrev
= 0;
1423 bool wxStyledTextEvent::GetShift() const { return (m_modifiers
& SCI_SHIFT
) != 0; }
1424 bool wxStyledTextEvent::GetControl() const { return (m_modifiers
& SCI_CTRL
) != 0; }
1425 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers
& SCI_ALT
) != 0; }
1427 void wxStyledTextEvent::CopyObject(wxObject
& obj
) const {
1428 wxCommandEvent::CopyObject(obj
);
1430 wxStyledTextEvent
* o
= (wxStyledTextEvent
*)&obj
;
1431 o
->m_position
= m_position
;
1433 o
->m_modifiers
= m_modifiers
;
1434 o
->m_modificationType
= m_modificationType
;
1436 o
->m_length
= m_length
;
1437 o
->m_linesAdded
= m_linesAdded
;
1439 o
->m_foldLevelNow
= m_foldLevelNow
;
1440 o
->m_foldLevelPrev
= m_foldLevelPrev
;
1442 o
->m_margin
= m_margin
;
1444 o
->m_message
= m_message
;
1445 o
->m_wParam
= m_wParam
;
1446 o
->m_lParam
= m_lParam
;
1452 //----------------------------------------------------------------------
1453 //----------------------------------------------------------------------