]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/stc.cpp
Added project files for STC; fixed wxStringList memory leaks; small doc changes;
[wxWidgets.git] / contrib / src / stc / stc.cpp
1 ////////////////////////////////////////////////////////////////////////////
2 // Name: stc.cpp
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.
9 //
10 // Author: Robin Dunn
11 //
12 // Created: 13-Jan-2000
13 // RCS-ID: $Id$
14 // Copyright: (c) 2000 by Total Control Software
15 // Licence: wxWindows license
16 /////////////////////////////////////////////////////////////////////////////
17
18 #include "wx/stc/stc.h"
19 #include "ScintillaWX.h"
20
21 #include <wx/tokenzr.h>
22
23 //----------------------------------------------------------------------
24
25 const wxChar* wxSTCNameStr = "stcwindow";
26
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)
41 END_EVENT_TABLE()
42
43 //----------------------------------------------------------------------
44 // Constructor and Destructor
45
46 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent,
47 wxWindowID id,
48 const wxPoint& pos,
49 const wxSize& size,
50 long style,
51 const wxString& name) :
52 wxControl(parent, id, pos, size,
53 style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS,
54 wxDefaultValidator, name)
55 {
56 m_swx = new ScintillaWX(this);
57 // m_keywords = new WordList;
58 m_stopWatch.Start();
59 m_readOnly = false;
60 m_undoType = wxSTC_UndoCollectAutoStart;
61 }
62
63
64 wxStyledTextCtrl::~wxStyledTextCtrl() {
65 delete m_swx;
66 // delete m_keywords;
67 }
68
69
70 //----------------------------------------------------------------------
71
72 inline long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) {
73
74 return m_swx->WndProc(msg, wp, lp);
75 }
76
77
78 //----------------------------------------------------------------------
79 // Text retrieval and modification
80
81 wxString wxStyledTextCtrl::GetText() {
82 wxString text;
83 int len = GetTextLength();
84 char* buff = text.GetWriteBuf(len);
85
86 SendMsg(WM_GETTEXT, len, (long)buff);
87 text.UngetWriteBuf();
88 return text;
89 }
90
91
92 bool wxStyledTextCtrl::SetText(const wxString& text) {
93 return SendMsg(WM_SETTEXT, 0, (long)text.c_str()) != 0;
94 }
95
96
97 wxString wxStyledTextCtrl::GetLine(int line) {
98 wxString text;
99 int len = GetLineLength(line);
100 char* buff = text.GetWriteBuf(len+1);
101
102 *((WORD*)buff) = len+1;
103 SendMsg(EM_GETLINE, line, (long)buff);
104 text.UngetWriteBuf();
105 return text;
106 }
107
108
109 void wxStyledTextCtrl::ReplaceSelection(const wxString& text) {
110 SendMsg(EM_REPLACESEL, 0, (long)text.c_str());
111 }
112
113
114 void wxStyledTextCtrl::SetReadOnly(bool readOnly) {
115 SendMsg(EM_SETREADONLY, (long)readOnly);
116 m_readOnly = readOnly;
117 }
118
119
120 bool wxStyledTextCtrl::GetReadOnly() {
121 // TODO: need support in Scintilla to do this right,
122 // until then we'll track it ourselves
123 return m_readOnly;
124 }
125
126
127 void wxStyledTextCtrl::GetTextRange(int startPos, int endPos, char* buff) {
128 TEXTRANGE tr;
129 tr.lpstrText = buff;
130 tr.chrg.cpMin = startPos;
131 tr.chrg.cpMax = endPos;
132 SendMsg(EM_GETTEXTRANGE, 0, (long)&tr);
133 }
134
135
136 wxString wxStyledTextCtrl::GetTextRange(int startPos, int endPos) {
137 wxString text;
138 int len = endPos - startPos;
139 char* buff = text.GetWriteBuf(len);
140 GetTextRange(startPos, endPos, buff);
141 text.UngetWriteBuf();
142 return text;
143 }
144
145
146 void wxStyledTextCtrl::GetStyledTextRange(int startPos, int endPos, char* buff) {
147 TEXTRANGE tr;
148 tr.lpstrText = buff;
149 tr.chrg.cpMin = startPos;
150 tr.chrg.cpMax = endPos;
151 SendMsg(SCI_GETSTYLEDTEXT, 0, (long)&tr);
152 }
153
154
155 wxString wxStyledTextCtrl::GetStyledTextRange(int startPos, int endPos) {
156 wxString text;
157 int len = endPos - startPos;
158 char* buff = text.GetWriteBuf(len*2);
159 GetStyledTextRange(startPos, endPos, buff);
160 text.UngetWriteBuf(len*2);
161 return text;
162 }
163
164
165 void wxStyledTextCtrl::AddText(const wxString& text) {
166 SendMsg(SCI_ADDTEXT, text.Len(), (long)text.c_str());
167 }
168
169
170 void wxStyledTextCtrl::AddStyledText(const wxString& text) {
171 SendMsg(SCI_ADDSTYLEDTEXT, text.Len(), (long)text.c_str());
172 }
173
174
175 void wxStyledTextCtrl::InsertText(int pos, const wxString& text) {
176 SendMsg(SCI_INSERTTEXT, pos, (long)text.c_str());
177 }
178
179
180 void wxStyledTextCtrl::ClearAll() {
181 SendMsg(SCI_CLEARALL);
182 }
183
184
185 char wxStyledTextCtrl::GetCharAt(int pos) {
186 return SendMsg(SCI_GETCHARAT, pos);
187 }
188
189
190 char wxStyledTextCtrl::GetStyleAt(int pos) {
191 return SendMsg(SCI_GETSTYLEAT, pos);
192 }
193
194
195 void wxStyledTextCtrl::SetStyleBits(int bits) {
196 SendMsg(SCI_SETSTYLEBITS, bits);
197 }
198
199
200 int wxStyledTextCtrl::GetStyleBits() {
201 return SendMsg(SCI_GETSTYLEBITS);
202 }
203
204
205 //----------------------------------------------------------------------
206 // Clipboard
207
208
209 void wxStyledTextCtrl::Cut() {
210 SendMsg(WM_CUT);
211 }
212
213
214 void wxStyledTextCtrl::Copy() {
215 SendMsg(WM_COPY);
216 }
217
218
219 void wxStyledTextCtrl::Paste() {
220 SendMsg(WM_PASTE);
221 }
222
223
224 bool wxStyledTextCtrl::CanPaste() {
225 return SendMsg(EM_CANPASTE) != 0;
226 }
227
228
229 void wxStyledTextCtrl::ClearClipbrd() {
230 SendMsg(WM_CLEAR);
231 }
232
233
234
235 //----------------------------------------------------------------------
236 // Undo and Redo
237
238 void wxStyledTextCtrl::Undo() {
239 SendMsg(WM_UNDO);
240 }
241
242
243 bool wxStyledTextCtrl::CanUndo() {
244 return SendMsg(EM_CANUNDO) != 0;
245 }
246
247
248 void wxStyledTextCtrl::EmptyUndoBuffer() {
249 SendMsg(EM_EMPTYUNDOBUFFER);
250 }
251
252
253 void wxStyledTextCtrl::Redo() {
254 SendMsg(SCI_REDO);
255 }
256
257
258 bool wxStyledTextCtrl::CanRedo() {
259 return SendMsg(SCI_CANREDO) != 0;
260 }
261
262
263 void wxStyledTextCtrl::SetUndoCollection(wxSTC_UndoType type) {
264 SendMsg(SCI_SETUNDOCOLLECTION, type);
265 m_undoType = type;
266 }
267
268
269 wxSTC_UndoType wxStyledTextCtrl::GetUndoCollection() {
270 // TODO: need support in Scintilla to do this right,
271 // until then we'll track it ourselves
272 return m_undoType;
273 }
274
275
276 void wxStyledTextCtrl::BeginUndoAction() {
277 SendMsg(SCI_BEGINUNDOACTION);
278 }
279
280
281 void wxStyledTextCtrl::EndUndoAction() {
282 SendMsg(SCI_ENDUNDOACTION);
283 }
284
285
286
287
288 //----------------------------------------------------------------------
289 // Selection and information
290
291
292 void wxStyledTextCtrl::GetSelection(int* startPos, int* endPos) {
293 SendMsg(EM_GETSEL, (long)startPos, (long)endPos);
294 }
295
296
297 void wxStyledTextCtrl::SetSelection(int startPos, int endPos) {
298 SendMsg(EM_SETSEL, startPos, endPos);
299 }
300
301
302 wxString wxStyledTextCtrl::GetSelectedText() {
303 wxString text;
304 int start;
305 int end;
306
307 GetSelection(&start, &end);
308 int len = end - start;
309 char* buff = text.GetWriteBuf(len);
310
311 SendMsg(EM_GETSELTEXT, 0, (long)buff);
312 text.UngetWriteBuf();
313 return text;
314 }
315
316
317 void wxStyledTextCtrl::HideSelection(bool hide) {
318 SendMsg(EM_HIDESELECTION, hide);
319 }
320
321
322 bool wxStyledTextCtrl::GetHideSelection() {
323 return m_swx->GetHideSelection();
324 }
325
326
327 int wxStyledTextCtrl::GetTextLength() {
328 return SendMsg(WM_GETTEXTLENGTH);
329 }
330
331
332 int wxStyledTextCtrl::GetFirstVisibleLine() {
333 return SendMsg(EM_GETFIRSTVISIBLELINE);
334 }
335
336
337 int wxStyledTextCtrl::GetLineCount() {
338 return SendMsg(EM_GETLINECOUNT);
339 }
340
341
342 bool wxStyledTextCtrl::GetModified() {
343 return SendMsg(EM_GETMODIFY) != 0;
344 }
345
346
347 wxRect wxStyledTextCtrl::GetRect() {
348 PRectangle pr;
349 SendMsg(EM_GETRECT, 0, (long)&pr);
350
351 wxRect rect = wxRectFromPRectangle(pr);
352 return rect;
353 }
354
355
356 int wxStyledTextCtrl::GetLineFromPos(int pos) {
357 return SendMsg(EM_LINEFROMCHAR, pos);
358 }
359
360
361 int wxStyledTextCtrl::GetLineStartPos(int line) {
362 return SendMsg(EM_LINEINDEX, line);
363 }
364
365
366 int wxStyledTextCtrl::GetLineLengthAtPos(int pos) {
367 return SendMsg(EM_LINELENGTH, pos);
368 }
369
370
371 int wxStyledTextCtrl::GetLineLength(int line) {
372 return SendMsg(SCI_LINELENGTH, line);
373 }
374
375
376 int wxStyledTextCtrl::GetCurrentLine() {
377 int line = GetLineFromPos(GetCurrentPos());
378 return line;
379 }
380
381
382 wxString wxStyledTextCtrl::GetCurrentLineText(int* linePos) {
383 wxString text;
384 int len = GetLineLength(GetCurrentLine());
385 char* buff = text.GetWriteBuf(len+1);
386
387 int pos = SendMsg(SCI_GETCURLINE, len+1, (long)buff);
388 text.UngetWriteBuf();
389
390 if (linePos)
391 *linePos = pos;
392
393 return text;
394 }
395
396
397 int wxStyledTextCtrl::PositionFromPoint(wxPoint pt) {
398 Point spt(pt.x, pt.y);
399 long rv = SendMsg(EM_CHARFROMPOS, 0, (long)&spt);
400 return LOWORD(rv);
401 }
402
403
404 int wxStyledTextCtrl::LineFromPoint(wxPoint pt) {
405 Point spt(pt.x, pt.y);
406 long rv = SendMsg(EM_CHARFROMPOS, 0, (long)&spt);
407 return HIWORD(rv);
408 }
409
410
411 wxPoint wxStyledTextCtrl::PointFromPosition(int pos) {
412 Point pt;
413 SendMsg(EM_POSFROMCHAR, pos, (long)&pt);
414 return wxPoint(pt.x, pt.y);
415 }
416
417
418 int wxStyledTextCtrl::GetCurrentPos() {
419 return SendMsg(SCI_GETCURRENTPOS);
420 }
421
422
423 int wxStyledTextCtrl::GetAnchor() {
424 return SendMsg(SCI_GETANCHOR);
425 }
426
427
428 void wxStyledTextCtrl::SelectAll() {
429 SendMsg(SCI_SELECTALL);
430 }
431
432
433 void wxStyledTextCtrl::SetCurrentPosition(int pos) {
434 SendMsg(SCI_GOTOPOS, pos);
435 }
436
437
438 void wxStyledTextCtrl::SetAnchor(int pos) {
439 SendMsg(SCI_SETANCHOR, pos);
440 }
441
442
443 void wxStyledTextCtrl::GotoPos(int pos) {
444 SendMsg(SCI_GOTOPOS, pos);
445 }
446
447
448 void wxStyledTextCtrl::GotoLine(int line) {
449 SendMsg(SCI_GOTOLINE, line);
450 }
451
452
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);
456 }
457
458
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);
462 }
463
464
465 void wxStyledTextCtrl::ScrollBy(int columnDelta, int lineDelta) {
466 SendMsg(EM_LINESCROLL, columnDelta, lineDelta);
467 }
468
469 void wxStyledTextCtrl::ScrollToLine(int line) {
470 m_swx->DoScrollToLine(line);
471 }
472
473
474 void wxStyledTextCtrl::ScrollToColumn(int column) {
475 m_swx->DoScrollToColumn(column);
476 }
477
478
479 void wxStyledTextCtrl::EnsureCaretVisible() {
480 SendMsg(EM_SCROLLCARET);
481 }
482
483
484 void wxStyledTextCtrl::SetCaretPolicy(int policy, int slop) {
485 SendMsg(SCI_SETCARETPOLICY, policy, slop);
486 }
487
488
489 int wxStyledTextCtrl::GetSelectionType() {
490 return SendMsg(EM_SELECTIONTYPE);
491 }
492
493
494
495
496 //----------------------------------------------------------------------
497 // Searching
498
499 int wxStyledTextCtrl::FindText(int minPos, int maxPos,
500 const wxString& text,
501 bool caseSensitive, bool wholeWord) {
502 FINDTEXTEX ft;
503 int flags = 0;
504
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();
510
511 return SendMsg(EM_FINDTEXT, flags, (long)&ft);
512 }
513
514
515 void wxStyledTextCtrl::SearchAnchor() {
516 SendMsg(SCI_SEARCHANCHOR);
517 }
518
519
520 int wxStyledTextCtrl::SearchNext(const wxString& text, bool caseSensitive, bool wholeWord) {
521 int flags = 0;
522 flags |= caseSensitive ? FR_MATCHCASE : 0;
523 flags |= wholeWord ? FR_WHOLEWORD : 0;
524
525 return SendMsg(SCI_SEARCHNEXT, flags, (long)text.c_str());
526 }
527
528
529 int wxStyledTextCtrl::SearchPrev(const wxString& text, bool caseSensitive, bool wholeWord) {
530 int flags = 0;
531 flags |= caseSensitive ? FR_MATCHCASE : 0;
532 flags |= wholeWord ? FR_WHOLEWORD : 0;
533
534 return SendMsg(SCI_SEARCHPREV, flags, (long)text.c_str());
535 }
536
537 //----------------------------------------------------------------------
538 // Visible whitespace
539
540
541 bool wxStyledTextCtrl::GetViewWhitespace() {
542 return SendMsg(SCI_GETVIEWWS) != 0;
543 }
544
545
546 void wxStyledTextCtrl::SetViewWhitespace(bool visible) {
547 SendMsg(SCI_SETVIEWWS, visible);
548 }
549
550
551
552 //----------------------------------------------------------------------
553 // Line endings
554
555 wxSTC_EOL wxStyledTextCtrl::GetEOLMode() {
556 return (wxSTC_EOL)SendMsg(SCI_GETEOLMODE);
557 }
558
559
560 void wxStyledTextCtrl::SetEOLMode(wxSTC_EOL mode) {
561 SendMsg(SCI_SETEOLMODE, mode);
562 }
563
564
565 bool wxStyledTextCtrl::GetViewEOL() {
566 return SendMsg(SCI_GETVIEWEOL) != 0;
567 }
568
569
570 void wxStyledTextCtrl::SetViewEOL(bool visible) {
571 SendMsg(SCI_SETVIEWEOL, visible);
572 }
573
574 void wxStyledTextCtrl::ConvertEOL(wxSTC_EOL mode) {
575 SendMsg(SCI_CONVERTEOLS, mode);
576 }
577
578 //----------------------------------------------------------------------
579 // Styling
580
581 int wxStyledTextCtrl::GetEndStyled() {
582 return SendMsg(SCI_GETENDSTYLED);
583 }
584
585
586 void wxStyledTextCtrl::StartStyling(int pos, int mask) {
587 SendMsg(SCI_STARTSTYLING, pos, mask);
588 }
589
590
591 void wxStyledTextCtrl::SetStyleFor(int length, int style) {
592 SendMsg(SCI_SETSTYLING, length, style);
593 }
594
595
596 void wxStyledTextCtrl::SetStyleBytes(int length, char* styleBytes) {
597 SendMsg(SCI_SETSTYLINGEX, length, (long)styleBytes);
598 }
599
600
601 //----------------------------------------------------------------------
602 // Style Definition
603
604
605 static long wxColourAsLong(const wxColour& co) {
606 return (((long)co.Blue() << 16) |
607 ((long)co.Green() << 8) |
608 ((long)co.Red()));
609 }
610
611 static wxColour wxColourFromLong(long c) {
612 wxColour clr;
613 clr.Set(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff);
614 return clr;
615 }
616
617
618 static wxColour wxColourFromSpec(const wxString& spec) {
619 // spec should be #RRGGBB
620 char* junk;
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);
625 }
626
627
628 void wxStyledTextCtrl::StyleClearAll() {
629 SendMsg(SCI_STYLECLEARALL);
630 }
631
632
633 void wxStyledTextCtrl::StyleResetDefault() {
634 SendMsg(SCI_STYLERESETDEFAULT);
635 }
636
637
638
639 // Extract style settings from a spec-string which is composed of one or
640 // more of the following comma separated elements:
641 //
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
649 //
650
651 void wxStyledTextCtrl::StyleSetSpec(int styleNum, const wxString& spec) {
652
653 wxStringTokenizer tkz(spec, ",");
654 while (tkz.HasMoreTokens()) {
655 wxString token = tkz.GetNextToken();
656
657 wxString option = token.BeforeFirst(':');
658 wxString val = token.AfterFirst(':');
659
660 if (option == "bold")
661 StyleSetBold(styleNum, true);
662
663 else if (option == "italic")
664 StyleSetItalic(styleNum, true);
665
666 else if (option == "eol")
667 StyleSetEOLFilled(styleNum, true);
668
669 else if (option == "size") {
670 long points;
671 if (val.ToLong(&points))
672 StyleSetSize(styleNum, points);
673 }
674
675 else if (option == "face")
676 StyleSetFaceName(styleNum, val);
677
678 else if (option == "fore")
679 StyleSetForeground(styleNum, wxColourFromSpec(val));
680
681 else if (option == "back")
682 StyleSetBackground(styleNum, wxColourFromSpec(val));
683 }
684 }
685
686
687 void wxStyledTextCtrl::StyleSetForeground(int styleNum, const wxColour& colour) {
688 SendMsg(SCI_STYLESETFORE, styleNum, wxColourAsLong(colour));
689 }
690
691
692 void wxStyledTextCtrl::StyleSetBackground(int styleNum, const wxColour& colour) {
693 SendMsg(SCI_STYLESETBACK, styleNum, wxColourAsLong(colour));
694 }
695
696
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;
702
703 StyleSetFontAttr(styleNum, size, faceName, bold, italic);
704 }
705
706
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);
714 }
715
716
717 void wxStyledTextCtrl::StyleSetBold(int styleNum, bool bold) {
718 SendMsg(SCI_STYLESETBOLD, styleNum, bold);
719 }
720
721
722 void wxStyledTextCtrl::StyleSetItalic(int styleNum, bool italic) {
723 SendMsg(SCI_STYLESETITALIC, styleNum, italic);
724 }
725
726
727 void wxStyledTextCtrl::StyleSetFaceName(int styleNum, const wxString& faceName) {
728 SendMsg(SCI_STYLESETFONT, styleNum, (long)faceName.c_str());
729 }
730
731
732 void wxStyledTextCtrl::StyleSetSize(int styleNum, int pointSize) {
733 SendMsg(SCI_STYLESETSIZE, styleNum, pointSize);
734 }
735
736
737 void wxStyledTextCtrl::StyleSetEOLFilled(int styleNum, bool fillEOL) {
738 SendMsg(SCI_STYLESETEOLFILLED, styleNum, fillEOL);
739 }
740
741
742 //----------------------------------------------------------------------
743 // Margins in the edit area
744
745 int wxStyledTextCtrl::GetLeftMargin() {
746 return LOWORD(SendMsg(EM_GETMARGINS));
747 }
748
749
750 int wxStyledTextCtrl::GetRightMargin() {
751 return HIWORD(SendMsg(EM_GETMARGINS));
752 }
753
754
755 void wxStyledTextCtrl::SetMargins(int left, int right) {
756 int flag = 0;
757 int val = 0;
758
759 if (right != -1) {
760 flag |= EC_RIGHTMARGIN;
761 val = right << 16;
762 }
763 if (left != -1) {
764 flag |= EC_LEFTMARGIN;
765 val |= (left & 0xffff);
766 }
767
768 SendMsg(EM_SETMARGINS, flag, val);
769 }
770
771
772 //----------------------------------------------------------------------
773 // Margins for selection, markers, etc.
774
775 void wxStyledTextCtrl::SetMarginType(int margin, int type) {
776 SendMsg(SCI_SETMARGINTYPEN, margin, type);
777 }
778
779
780 int wxStyledTextCtrl::GetMarginType(int margin) {
781 return SendMsg(SCI_GETMARGINTYPEN, margin);
782 }
783
784
785 void wxStyledTextCtrl::SetMarginWidth(int margin, int pixelWidth) {
786 SendMsg(SCI_SETMARGINWIDTHN, margin, pixelWidth);
787 }
788
789
790 int wxStyledTextCtrl::GetMarginWidth(int margin) {
791 return SendMsg(SCI_GETMARGINWIDTHN, margin);
792 }
793
794
795 void wxStyledTextCtrl::SetMarginMask(int margin, int mask) {
796 SendMsg(SCI_SETMARGINMASKN, margin, mask);
797 }
798
799
800 int wxStyledTextCtrl::GetMarginMask(int margin) {
801 return SendMsg(SCI_GETMARGINMASKN, margin);
802 }
803
804
805 void wxStyledTextCtrl::SetMarginSensitive(int margin, bool sensitive) {
806 SendMsg(SCI_SETMARGINSENSITIVEN, margin, sensitive);
807 }
808
809
810 bool wxStyledTextCtrl::GetMarginSensitive(int margin) {
811 return SendMsg(SCI_GETMARGINSENSITIVEN, margin);
812 }
813
814
815
816
817 //----------------------------------------------------------------------
818 // Selection and Caret styles
819
820
821 void wxStyledTextCtrl::SetSelectionForeground(const wxColour& colour) {
822 SendMsg(SCI_SETSELFORE, 0, wxColourAsLong(colour));
823 }
824
825
826 void wxStyledTextCtrl::SetSelectionBackground(const wxColour& colour) {
827 SendMsg(SCI_SETSELBACK, 0, wxColourAsLong(colour));
828 }
829
830
831 void wxStyledTextCtrl::SetCaretForeground(const wxColour& colour) {
832 SendMsg(SCI_SETCARETFORE, 0, wxColourAsLong(colour));
833 }
834
835
836 int wxStyledTextCtrl::GetCaretPeriod() {
837 return SendMsg(SCI_GETCARETPERIOD);
838 }
839
840
841 void wxStyledTextCtrl::SetCaretPeriod(int milliseconds) {
842 SendMsg(SCI_SETCARETPERIOD, milliseconds);
843 }
844
845
846
847 //----------------------------------------------------------------------
848 // Other settings
849
850
851 void wxStyledTextCtrl::SetBufferedDraw(bool isBuffered) {
852 SendMsg(SCI_SETBUFFEREDDRAW, isBuffered);
853 }
854
855
856 void wxStyledTextCtrl::SetTabWidth(int numChars) {
857 SendMsg(SCI_SETTABWIDTH, numChars);
858 }
859
860
861 void wxStyledTextCtrl::SetWordChars(const wxString& wordChars) {
862 SendMsg(SCI_SETTABWIDTH, 0, (long)wordChars.c_str());
863 }
864
865
866 //----------------------------------------------------------------------
867 // Brace highlighting
868
869
870 void wxStyledTextCtrl::BraceHighlight(int pos1, int pos2) {
871 SendMsg(SCI_BRACEHIGHLIGHT, pos1, pos2);
872 }
873
874
875 void wxStyledTextCtrl::BraceBadlight(int pos) {
876 SendMsg(SCI_BRACEBADLIGHT, pos);
877 }
878
879
880 int wxStyledTextCtrl::BraceMatch(int pos, int maxReStyle) {
881 return SendMsg(SCI_BRACEMATCH, pos, maxReStyle);
882 }
883
884
885
886 //----------------------------------------------------------------------
887 // Markers
888
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);
895 }
896
897
898 void wxStyledTextCtrl::MarkerSetType(int markerNumber, int markerSymbol) {
899 SendMsg(SCI_MARKERDEFINE, markerNumber, markerSymbol);
900 }
901
902
903 void wxStyledTextCtrl::MarkerSetForeground(int markerNumber, const wxColour& colour) {
904 SendMsg(SCI_MARKERSETFORE, markerNumber, wxColourAsLong(colour));
905 }
906
907
908 void wxStyledTextCtrl::MarkerSetBackground(int markerNumber, const wxColour& colour) {
909 SendMsg(SCI_MARKERSETBACK, markerNumber, wxColourAsLong(colour));
910 }
911
912
913 int wxStyledTextCtrl::MarkerAdd(int line, int markerNumber) {
914 return SendMsg(SCI_MARKERADD, line, markerNumber);
915 }
916
917
918 void wxStyledTextCtrl::MarkerDelete(int line, int markerNumber) {
919 SendMsg(SCI_MARKERDELETE, line, markerNumber);
920 }
921
922
923 void wxStyledTextCtrl::MarkerDeleteAll(int markerNumber) {
924 SendMsg(SCI_MARKERDELETEALL, markerNumber);
925 }
926
927
928 int wxStyledTextCtrl::MarkerGet(int line) {
929 return SendMsg(SCI_MARKERGET);
930 }
931
932
933 int wxStyledTextCtrl::MarkerGetNextLine(int lineStart, int markerMask) {
934 return SendMsg(SCI_MARKERNEXT, lineStart, markerMask);
935 }
936
937
938 int wxStyledTextCtrl::MarkerGetPrevLine(int lineStart, int markerMask) {
939 // return SendMsg(SCI_MARKERPREV, lineStart, markerMask);
940 return 0;
941 }
942
943
944 int wxStyledTextCtrl::MarkerLineFromHandle(int handle) {
945 return SendMsg(SCI_MARKERLINEFROMHANDLE, handle);
946 }
947
948
949 void wxStyledTextCtrl::MarkerDeleteHandle(int handle) {
950 SendMsg(SCI_MARKERDELETEHANDLE, handle);
951 }
952
953
954
955 //----------------------------------------------------------------------
956 // Indicators
957
958
959 void wxStyledTextCtrl::IndicatorSetStyle(int indicNum, int indicStyle) {
960 SendMsg(SCI_INDICSETSTYLE, indicNum, indicStyle);
961 }
962
963
964 int wxStyledTextCtrl::IndicatorGetStyle(int indicNum) {
965 return SendMsg(SCI_INDICGETSTYLE, indicNum);
966 }
967
968
969 void wxStyledTextCtrl::IndicatorSetColour(int indicNum, const wxColour& colour) {
970 SendMsg(SCI_INDICSETSTYLE, indicNum, wxColourAsLong(colour));
971 }
972
973
974
975 //----------------------------------------------------------------------
976 // Auto completion
977
978
979 void wxStyledTextCtrl::AutoCompShow(const wxString& listOfWords) {
980 SendMsg(SCI_AUTOCSHOW, 0, (long)listOfWords.c_str());
981 }
982
983
984 void wxStyledTextCtrl::AutoCompCancel() {
985 SendMsg(SCI_AUTOCCANCEL);
986 }
987
988
989 bool wxStyledTextCtrl::AutoCompActive() {
990 return SendMsg(SCI_AUTOCACTIVE) != 0;
991 }
992
993
994 int wxStyledTextCtrl::AutoCompPosAtStart() {
995 return SendMsg(SCI_AUTOCPOSSTART);
996 }
997
998
999 void wxStyledTextCtrl::AutoCompComplete() {
1000 SendMsg(SCI_AUTOCCOMPLETE);
1001 }
1002
1003
1004 void wxStyledTextCtrl::AutoCompStopChars(const wxString& stopChars) {
1005 SendMsg(SCI_AUTOCSHOW, 0, (long)stopChars.c_str());
1006 }
1007
1008
1009 //----------------------------------------------------------------------
1010 // Call tips
1011
1012 void wxStyledTextCtrl::CallTipShow(int pos, const wxString& text) {
1013 SendMsg(SCI_CALLTIPSHOW, pos, (long)text.c_str());
1014 }
1015
1016
1017 void wxStyledTextCtrl::CallTipCancel() {
1018 SendMsg(SCI_CALLTIPCANCEL);
1019 }
1020
1021
1022 bool wxStyledTextCtrl::CallTipActive() {
1023 return SendMsg(SCI_CALLTIPACTIVE) != 0;
1024 }
1025
1026
1027 int wxStyledTextCtrl::CallTipPosAtStart() {
1028 return SendMsg(SCI_CALLTIPPOSSTART);
1029 }
1030
1031
1032 void wxStyledTextCtrl::CallTipSetHighlight(int start, int end) {
1033 SendMsg(SCI_CALLTIPSETHLT, start, end);
1034 }
1035
1036
1037 void wxStyledTextCtrl::CallTipSetBackground(const wxColour& colour) {
1038 SendMsg(SCI_CALLTIPSETBACK, wxColourAsLong(colour));
1039 }
1040
1041
1042 //----------------------------------------------------------------------
1043 // Key bindings
1044
1045 void wxStyledTextCtrl::CmdKeyAssign(int key, int modifiers, int cmd) {
1046 SendMsg(SCI_ASSIGNCMDKEY, MAKELONG(key, modifiers), cmd);
1047 }
1048
1049
1050 void wxStyledTextCtrl::CmdKeyClear(int key, int modifiers) {
1051 SendMsg(SCI_CLEARCMDKEY, MAKELONG(key, modifiers));
1052 }
1053
1054
1055 void wxStyledTextCtrl::CmdKeyClearAll() {
1056 SendMsg(SCI_CLEARALLCMDKEYS);
1057 }
1058
1059
1060 void wxStyledTextCtrl::CmdKeyExecute(int cmd) {
1061 SendMsg(cmd);
1062 }
1063
1064
1065
1066 //----------------------------------------------------------------------
1067 // Print formatting
1068
1069 int
1070 wxStyledTextCtrl::FormatRange(bool doDraw,
1071 int startPos,
1072 int endPos,
1073 wxDC* draw,
1074 wxDC* target, // Why does it use two? Can they be the same?
1075 wxRect renderRect,
1076 wxRect pageRect) {
1077 FORMATRANGE fr;
1078
1079 fr.hdc = draw;
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;
1091
1092 return SendMsg(EM_FORMATRANGE, doDraw, (long)&fr);
1093 }
1094
1095
1096 //----------------------------------------------------------------------
1097 // Document Sharing
1098
1099 void* wxStyledTextCtrl::GetDocument() {
1100 return (void*)SendMsg(SCI_GETDOCPOINTER);
1101 }
1102
1103
1104 void wxStyledTextCtrl::SetDocument(void* document) {
1105 SendMsg(SCI_SETDOCPOINTER, 0, (long)document);
1106 }
1107
1108
1109 //----------------------------------------------------------------------
1110 // Long Lines
1111
1112 int wxStyledTextCtrl::GetEdgeColumn() {
1113 return SendMsg(SCI_GETEDGECOLUMN);
1114 }
1115
1116 void wxStyledTextCtrl::SetEdgeColumn(int column) {
1117 SendMsg(SCI_SETEDGECOLUMN, column);
1118 }
1119
1120 wxSTC_EDGE wxStyledTextCtrl::GetEdgeMode() {
1121 return (wxSTC_EDGE) SendMsg(SCI_GETEDGEMODE);
1122 }
1123
1124 void wxStyledTextCtrl::SetEdgeMode(wxSTC_EDGE mode){
1125 SendMsg(SCI_SETEDGEMODE, mode);
1126 }
1127
1128 wxColour wxStyledTextCtrl::GetEdgeColour() {
1129 long c = SendMsg(SCI_GETEDGECOLOUR);
1130 return wxColourFromLong(c);
1131 }
1132
1133 void wxStyledTextCtrl::SetEdgeColour(const wxColour& colour) {
1134 SendMsg(SCI_SETEDGECOLOUR, wxColourAsLong(colour));
1135 }
1136
1137
1138 //----------------------------------------------------------------------
1139 // Lexer
1140
1141 void wxStyledTextCtrl::SetLexer(wxSTC_LEX lexer) {
1142 SendMsg(SCI_SETLEXER, lexer);
1143 }
1144
1145
1146 wxSTC_LEX wxStyledTextCtrl::GetLexer() {
1147 return (wxSTC_LEX)SendMsg(SCI_GETLEXER);
1148 }
1149
1150
1151 void wxStyledTextCtrl::Colourise(int start, int end) {
1152 SendMsg(SCI_COLOURISE, start, end);
1153 }
1154
1155
1156 void wxStyledTextCtrl::SetProperty(const wxString& key, const wxString& value) {
1157 SendMsg(SCI_SETPROPERTY, (long)key.c_str(), (long)value.c_str());
1158 }
1159
1160
1161 void wxStyledTextCtrl::SetKeywords(int keywordSet, const wxString& keywordList) {
1162 SendMsg(SCI_SETKEYWORDS, keywordSet, (long)keywordList.c_str());
1163 }
1164
1165
1166
1167 //----------------------------------------------------------------------
1168 // Event handlers
1169
1170 void wxStyledTextCtrl::OnPaint(wxPaintEvent& evt) {
1171 wxPaintDC dc(this);
1172 wxRegion region = GetUpdateRegion();
1173
1174 m_swx->DoPaint(&dc, region.GetBox());
1175 }
1176
1177 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent& evt) {
1178 if (evt.GetOrientation() == wxHORIZONTAL)
1179 m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition());
1180 else
1181 m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition());
1182 }
1183
1184 void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) {
1185 wxSize sz = GetClientSize();
1186 m_swx->DoSize(sz.x, sz.y);
1187 }
1188
1189 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) {
1190 wxPoint pt = evt.GetPosition();
1191 m_swx->DoButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(),
1192 evt.ShiftDown(), evt.ControlDown(), evt.AltDown());
1193 }
1194
1195 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) {
1196 wxPoint pt = evt.GetPosition();
1197 m_swx->DoButtonMove(Point(pt.x, pt.y));
1198 }
1199
1200 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) {
1201 wxPoint pt = evt.GetPosition();
1202 m_swx->DoButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(),
1203 evt.ControlDown());
1204 }
1205
1206
1207 void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) {
1208 wxPoint pt = evt.GetPosition();
1209 m_swx->DoContextMenu(Point(pt.x, pt.y));
1210 }
1211
1212 void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) {
1213 int processed = 0;
1214 long key = evt.KeyCode();
1215 if ((key > WXK_ESCAPE) &&
1216 (key != WXK_DELETE) && (key < 255) &&
1217 !evt.ControlDown() && !evt.AltDown()) {
1218
1219 m_swx->DoAddChar(key);
1220 processed = true;
1221 }
1222 else {
1223 key = toupper(key);
1224 processed = m_swx->DoKeyDown(key, evt.ShiftDown(),
1225 evt.ControlDown(), evt.AltDown());
1226 }
1227 if (! processed)
1228 evt.Skip();
1229 }
1230
1231 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent& evt) {
1232 m_swx->DoLoseFocus();
1233 }
1234
1235 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) {
1236 m_swx->DoGainFocus();
1237 }
1238
1239 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& evt) {
1240 m_swx->DoSysColourChange();
1241 }
1242
1243 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent& evt) {
1244 // do nothing to help avoid flashing
1245 }
1246
1247
1248
1249 void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) {
1250 m_swx->DoCommand(evt.GetId());
1251 }
1252
1253
1254 //----------------------------------------------------------------------
1255 // Turn notifications from Scintilla into events
1256
1257 void wxStyledTextCtrl::NotifyChange() {
1258 wxStyledTextEvent evt(wxEVT_STC_CHANGE, GetId());
1259 GetEventHandler()->ProcessEvent(evt);
1260 }
1261
1262 void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) {
1263 SCNotification& scn = *_scn;
1264 int eventType = 0;
1265 switch (scn.nmhdr.code) {
1266 case SCN_STYLENEEDED:
1267 eventType = wxEVT_STC_STYLENEEDED;
1268 break;
1269 case SCN_CHARADDED:
1270 eventType = wxEVT_STC_CHARADDED;
1271 break;
1272 case SCN_UPDATEUI:
1273 eventType = wxEVT_STC_UPDATEUI;
1274 break;
1275 case SCN_SAVEPOINTREACHED:
1276 eventType = wxEVT_STC_SAVEPOINTREACHED;
1277 break;
1278 case SCN_SAVEPOINTLEFT:
1279 eventType = wxEVT_STC_SAVEPOINTLEFT;
1280 break;
1281 case SCN_MODIFYATTEMPTRO:
1282 eventType = wxEVT_STC_ROMODIFYATTEMPT;
1283 break;
1284 case SCN_DOUBLECLICK:
1285 eventType = wxEVT_STC_DOUBLECLICK;
1286 break;
1287 case SCN_MODIFIED:
1288 eventType = wxEVT_STC_MODIFIED;
1289 break;
1290 case SCN_KEY:
1291 eventType = wxEVT_STC_KEY;
1292 break;
1293 case SCN_MACRORECORD:
1294 eventType = wxEVT_STC_MACRORECORD;
1295 break;
1296 case SCN_MARGINCLICK:
1297 eventType = wxEVT_STC_MARGINCLICK;
1298 break;
1299 case SCN_NEEDSHOWN:
1300 eventType = wxEVT_STC_NEEDSHOWN;
1301 break;
1302 }
1303 if (eventType) {
1304 wxStyledTextEvent evt(eventType, GetId());
1305 evt.SetPosition(scn.position);
1306 evt.SetKey(scn.ch);
1307 evt.SetModifiers(scn.modifiers);
1308 if (eventType == wxEVT_STC_MODIFIED) {
1309 evt.SetModificationType(scn.modificationType);
1310 evt.SetText(scn.text);
1311 evt.SetLength(scn.length);
1312 evt.SetLinesAdded(scn.linesAdded);
1313 evt.SetLine(scn.line);
1314 evt.SetFoldLevelNow(scn.foldLevelNow);
1315 evt.SetFoldLevelPrev(scn.foldLevelPrev);
1316 }
1317 if (eventType == wxEVT_STC_MARGINCLICK)
1318 evt.SetMargin(scn.margin);
1319 if (eventType == wxEVT_STC_MACRORECORD) {
1320 evt.SetMessage(scn.message);
1321 evt.SetWParam(scn.wParam);
1322 evt.SetLParam(scn.lParam);
1323 }
1324
1325 GetEventHandler()->ProcessEvent(evt);
1326 }
1327 }
1328
1329
1330
1331 //----------------------------------------------------------------------
1332 //----------------------------------------------------------------------
1333 //----------------------------------------------------------------------
1334
1335 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id)
1336 : wxCommandEvent(commandType, id)
1337 {
1338 m_position = 0;
1339 m_key = 0;
1340 m_modifiers = 0;
1341 m_modificationType = 0;
1342 m_length = 0;
1343 m_linesAdded = 0;
1344 m_line = 0;
1345 m_foldLevelNow = 0;
1346 m_foldLevelPrev = 0;
1347 m_margin = 0;
1348 m_message = 0;
1349 m_wParam = 0;
1350 m_lParam = 0;
1351
1352
1353 }
1354
1355 bool wxStyledTextEvent::GetShift() const { return (m_modifiers & SCI_SHIFT) != 0; }
1356 bool wxStyledTextEvent::GetControl() const { return (m_modifiers & SCI_CTRL) != 0; }
1357 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers & SCI_ALT) != 0; }
1358
1359 void wxStyledTextEvent::CopyObject(wxObject& obj) const {
1360 wxCommandEvent::CopyObject(obj);
1361
1362 wxStyledTextEvent* o = (wxStyledTextEvent*)&obj;
1363 o->m_position = m_position;
1364 o->m_key = m_key;
1365 o->m_modifiers = m_modifiers;
1366 o->m_modificationType = m_modificationType;
1367 o->m_text = m_text;
1368 o->m_length = m_length;
1369 o->m_linesAdded = m_linesAdded;
1370 o->m_line = m_line;
1371 o->m_foldLevelNow = m_foldLevelNow;
1372 o->m_foldLevelPrev = m_foldLevelPrev;
1373
1374 o->m_margin = m_margin;
1375
1376 o->m_message = m_message;
1377 o->m_wParam = m_wParam;
1378 o->m_lParam = m_lParam;
1379
1380
1381
1382 }
1383
1384 //----------------------------------------------------------------------
1385 //----------------------------------------------------------------------
1386