]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/stc/stc.cpp
Reformatting.
[wxWidgets.git] / contrib / src / stc / stc.cpp
CommitLineData
9ce192d4
RD
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
f6bcfd97 8// namespace with all the classes and identifiers from Scintilla.
9ce192d4
RD
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
f6bcfd97
BP
18#include <ctype.h>
19
9ce192d4
RD
20#include "wx/stc/stc.h"
21#include "ScintillaWX.h"
22
23#include <wx/tokenzr.h>
24
f6bcfd97
BP
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)
28
29int wxForceScintillaLexers(void)
30{
31 extern LexerModule lmCPP;
32 extern LexerModule lmHTML;
33 extern LexerModule lmXML;
34 extern LexerModule lmProps;
35 extern LexerModule lmErrorList;
36 extern LexerModule lmMake;
37 extern LexerModule lmBatch;
38 extern LexerModule lmPerl;
39 extern LexerModule lmPython;
40 extern LexerModule lmSQL;
41 extern LexerModule lmVB;
42
43 if (
44 &lmCPP
45 && &lmHTML
46 && &lmXML
47 && &lmProps
48 && &lmErrorList
49 && &lmMake
50 && &lmBatch
51 && &lmPerl
52 && &lmPython
53 && &lmSQL
54 && &lmVB
55 )
56 {
57 return 1;
58 }
59 else
60 {
61 return 0;
62 }
63}
64
9ce192d4
RD
65//----------------------------------------------------------------------
66
67const wxChar* wxSTCNameStr = "stcwindow";
68
69BEGIN_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)
f6bcfd97 78 EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown)
9ce192d4
RD
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)
f6bcfd97 84 EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox)
9ce192d4
RD
85END_EVENT_TABLE()
86
f6bcfd97
BP
87
88IMPLEMENT_CLASS(wxStyledTextCtrl, wxControl)
89IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent, wxCommandEvent)
90
9ce192d4
RD
91//----------------------------------------------------------------------
92// Constructor and Destructor
93
94wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent,
95 wxWindowID id,
96 const wxPoint& pos,
97 const wxSize& size,
98 long style,
99 const wxString& name) :
100 wxControl(parent, id, pos, size,
101 style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS,
102 wxDefaultValidator, name)
103{
104 m_swx = new ScintillaWX(this);
105 // m_keywords = new WordList;
106 m_stopWatch.Start();
107 m_readOnly = false;
108 m_undoType = wxSTC_UndoCollectAutoStart;
109}
110
111
112wxStyledTextCtrl::~wxStyledTextCtrl() {
113 delete m_swx;
114 // delete m_keywords;
115}
116
117
118//----------------------------------------------------------------------
119
f6bcfd97 120long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) {
9ce192d4
RD
121
122 return m_swx->WndProc(msg, wp, lp);
123}
124
125
126//----------------------------------------------------------------------
127// Text retrieval and modification
128
129wxString wxStyledTextCtrl::GetText() {
130 wxString text;
131 int len = GetTextLength();
f6bcfd97 132 char* buff = text.GetWriteBuf(len+1);
9ce192d4
RD
133
134 SendMsg(WM_GETTEXT, len, (long)buff);
f6bcfd97 135 buff[len] = 0;
9ce192d4
RD
136 text.UngetWriteBuf();
137 return text;
138}
139
140
141bool wxStyledTextCtrl::SetText(const wxString& text) {
142 return SendMsg(WM_SETTEXT, 0, (long)text.c_str()) != 0;
143}
144
145
146wxString wxStyledTextCtrl::GetLine(int line) {
147 wxString text;
148 int len = GetLineLength(line);
149 char* buff = text.GetWriteBuf(len+1);
150
f6bcfd97 151 *((WORD*)buff) = len;
9ce192d4 152 SendMsg(EM_GETLINE, line, (long)buff);
f6bcfd97 153 buff[len] = 0;
9ce192d4
RD
154 text.UngetWriteBuf();
155 return text;
156}
157
158
159void wxStyledTextCtrl::ReplaceSelection(const wxString& text) {
160 SendMsg(EM_REPLACESEL, 0, (long)text.c_str());
161}
162
163
164void wxStyledTextCtrl::SetReadOnly(bool readOnly) {
165 SendMsg(EM_SETREADONLY, (long)readOnly);
166 m_readOnly = readOnly;
167}
168
169
170bool wxStyledTextCtrl::GetReadOnly() {
171 // TODO: need support in Scintilla to do this right,
172 // until then we'll track it ourselves
173 return m_readOnly;
174}
175
176
177void wxStyledTextCtrl::GetTextRange(int startPos, int endPos, char* buff) {
178 TEXTRANGE tr;
179 tr.lpstrText = buff;
180 tr.chrg.cpMin = startPos;
181 tr.chrg.cpMax = endPos;
182 SendMsg(EM_GETTEXTRANGE, 0, (long)&tr);
183}
184
185
186wxString wxStyledTextCtrl::GetTextRange(int startPos, int endPos) {
187 wxString text;
188 int len = endPos - startPos;
189 char* buff = text.GetWriteBuf(len);
190 GetTextRange(startPos, endPos, buff);
191 text.UngetWriteBuf();
192 return text;
193}
194
195
196void wxStyledTextCtrl::GetStyledTextRange(int startPos, int endPos, char* buff) {
197 TEXTRANGE tr;
198 tr.lpstrText = buff;
199 tr.chrg.cpMin = startPos;
200 tr.chrg.cpMax = endPos;
201 SendMsg(SCI_GETSTYLEDTEXT, 0, (long)&tr);
202}
203
204
205wxString wxStyledTextCtrl::GetStyledTextRange(int startPos, int endPos) {
206 wxString text;
207 int len = endPos - startPos;
208 char* buff = text.GetWriteBuf(len*2);
209 GetStyledTextRange(startPos, endPos, buff);
210 text.UngetWriteBuf(len*2);
211 return text;
212}
213
214
215void wxStyledTextCtrl::AddText(const wxString& text) {
216 SendMsg(SCI_ADDTEXT, text.Len(), (long)text.c_str());
217}
218
219
220void wxStyledTextCtrl::AddStyledText(const wxString& text) {
221 SendMsg(SCI_ADDSTYLEDTEXT, text.Len(), (long)text.c_str());
222}
223
224
225void wxStyledTextCtrl::InsertText(int pos, const wxString& text) {
226 SendMsg(SCI_INSERTTEXT, pos, (long)text.c_str());
227}
228
229
230void wxStyledTextCtrl::ClearAll() {
231 SendMsg(SCI_CLEARALL);
232}
233
234
235char wxStyledTextCtrl::GetCharAt(int pos) {
236 return SendMsg(SCI_GETCHARAT, pos);
237}
238
239
240char wxStyledTextCtrl::GetStyleAt(int pos) {
241 return SendMsg(SCI_GETSTYLEAT, pos);
242}
243
244
245void wxStyledTextCtrl::SetStyleBits(int bits) {
246 SendMsg(SCI_SETSTYLEBITS, bits);
247}
248
249
250int wxStyledTextCtrl::GetStyleBits() {
251 return SendMsg(SCI_GETSTYLEBITS);
252}
253
254
255//----------------------------------------------------------------------
256// Clipboard
257
258
259void wxStyledTextCtrl::Cut() {
260 SendMsg(WM_CUT);
261}
262
263
264void wxStyledTextCtrl::Copy() {
265 SendMsg(WM_COPY);
266}
267
268
269void wxStyledTextCtrl::Paste() {
270 SendMsg(WM_PASTE);
271}
272
273
274bool wxStyledTextCtrl::CanPaste() {
275 return SendMsg(EM_CANPASTE) != 0;
276}
277
278
279void wxStyledTextCtrl::ClearClipbrd() {
280 SendMsg(WM_CLEAR);
281}
282
283
284
285//----------------------------------------------------------------------
286// Undo and Redo
287
288void wxStyledTextCtrl::Undo() {
289 SendMsg(WM_UNDO);
290}
291
292
293bool wxStyledTextCtrl::CanUndo() {
294 return SendMsg(EM_CANUNDO) != 0;
295}
296
297
298void wxStyledTextCtrl::EmptyUndoBuffer() {
299 SendMsg(EM_EMPTYUNDOBUFFER);
300}
301
302
303void wxStyledTextCtrl::Redo() {
304 SendMsg(SCI_REDO);
305}
306
307
308bool wxStyledTextCtrl::CanRedo() {
309 return SendMsg(SCI_CANREDO) != 0;
310}
311
312
313void wxStyledTextCtrl::SetUndoCollection(wxSTC_UndoType type) {
314 SendMsg(SCI_SETUNDOCOLLECTION, type);
315 m_undoType = type;
316}
317
318
319wxSTC_UndoType wxStyledTextCtrl::GetUndoCollection() {
320 // TODO: need support in Scintilla to do this right,
321 // until then we'll track it ourselves
322 return m_undoType;
323}
324
325
326void wxStyledTextCtrl::BeginUndoAction() {
327 SendMsg(SCI_BEGINUNDOACTION);
328}
329
330
331void wxStyledTextCtrl::EndUndoAction() {
332 SendMsg(SCI_ENDUNDOACTION);
333}
334
335
336
337
338//----------------------------------------------------------------------
339// Selection and information
340
341
342void wxStyledTextCtrl::GetSelection(int* startPos, int* endPos) {
343 SendMsg(EM_GETSEL, (long)startPos, (long)endPos);
344}
345
346
347void wxStyledTextCtrl::SetSelection(int startPos, int endPos) {
348 SendMsg(EM_SETSEL, startPos, endPos);
349}
350
351
352wxString wxStyledTextCtrl::GetSelectedText() {
353 wxString text;
354 int start;
355 int end;
356
357 GetSelection(&start, &end);
358 int len = end - start;
359 char* buff = text.GetWriteBuf(len);
360
361 SendMsg(EM_GETSELTEXT, 0, (long)buff);
362 text.UngetWriteBuf();
363 return text;
364}
365
366
367void wxStyledTextCtrl::HideSelection(bool hide) {
368 SendMsg(EM_HIDESELECTION, hide);
369}
370
371
372bool wxStyledTextCtrl::GetHideSelection() {
373 return m_swx->GetHideSelection();
374}
375
376
377int wxStyledTextCtrl::GetTextLength() {
378 return SendMsg(WM_GETTEXTLENGTH);
379}
380
381
382int wxStyledTextCtrl::GetFirstVisibleLine() {
383 return SendMsg(EM_GETFIRSTVISIBLELINE);
384}
385
386
387int wxStyledTextCtrl::GetLineCount() {
388 return SendMsg(EM_GETLINECOUNT);
389}
390
391
392bool wxStyledTextCtrl::GetModified() {
393 return SendMsg(EM_GETMODIFY) != 0;
394}
395
396
397wxRect wxStyledTextCtrl::GetRect() {
398 PRectangle pr;
399 SendMsg(EM_GETRECT, 0, (long)&pr);
400
401 wxRect rect = wxRectFromPRectangle(pr);
402 return rect;
403}
404
405
406int wxStyledTextCtrl::GetLineFromPos(int pos) {
407 return SendMsg(EM_LINEFROMCHAR, pos);
408}
409
410
411int wxStyledTextCtrl::GetLineStartPos(int line) {
412 return SendMsg(EM_LINEINDEX, line);
413}
414
415
416int wxStyledTextCtrl::GetLineLengthAtPos(int pos) {
417 return SendMsg(EM_LINELENGTH, pos);
418}
419
420
421int wxStyledTextCtrl::GetLineLength(int line) {
422 return SendMsg(SCI_LINELENGTH, line);
423}
424
425
426int wxStyledTextCtrl::GetCurrentLine() {
427 int line = GetLineFromPos(GetCurrentPos());
428 return line;
429}
430
431
432wxString wxStyledTextCtrl::GetCurrentLineText(int* linePos) {
433 wxString text;
434 int len = GetLineLength(GetCurrentLine());
435 char* buff = text.GetWriteBuf(len+1);
436
f6bcfd97 437 int pos = SendMsg(SCI_GETCURLINE, len, (long)buff);
9ce192d4
RD
438 text.UngetWriteBuf();
439
440 if (linePos)
441 *linePos = pos;
442
443 return text;
444}
445
446
447int wxStyledTextCtrl::PositionFromPoint(wxPoint pt) {
448 Point spt(pt.x, pt.y);
449 long rv = SendMsg(EM_CHARFROMPOS, 0, (long)&spt);
450 return LOWORD(rv);
451}
452
453
454int wxStyledTextCtrl::LineFromPoint(wxPoint pt) {
455 Point spt(pt.x, pt.y);
456 long rv = SendMsg(EM_CHARFROMPOS, 0, (long)&spt);
457 return HIWORD(rv);
458}
459
460
461wxPoint wxStyledTextCtrl::PointFromPosition(int pos) {
462 Point pt;
f6bcfd97 463 SendMsg(EM_POSFROMCHAR, (long)&pt, pos);
9ce192d4
RD
464 return wxPoint(pt.x, pt.y);
465}
466
467
468int wxStyledTextCtrl::GetCurrentPos() {
469 return SendMsg(SCI_GETCURRENTPOS);
470}
471
472
473int wxStyledTextCtrl::GetAnchor() {
474 return SendMsg(SCI_GETANCHOR);
475}
476
477
478void wxStyledTextCtrl::SelectAll() {
479 SendMsg(SCI_SELECTALL);
480}
481
482
483void wxStyledTextCtrl::SetCurrentPosition(int pos) {
484 SendMsg(SCI_GOTOPOS, pos);
485}
486
487
488void wxStyledTextCtrl::SetAnchor(int pos) {
489 SendMsg(SCI_SETANCHOR, pos);
490}
491
492
493void wxStyledTextCtrl::GotoPos(int pos) {
494 SendMsg(SCI_GOTOPOS, pos);
495}
496
497
498void wxStyledTextCtrl::GotoLine(int line) {
499 SendMsg(SCI_GOTOLINE, line);
500}
501
502
503void wxStyledTextCtrl::ChangePosition(int delta, bool extendSelection) {
504 // TODO: Is documented but doesn't seem to be implemented
505 //SendMsg(SCI_CHANGEPOSITION, delta, extendSelection);
506}
507
508
509void wxStyledTextCtrl::PageMove(int cmdKey, bool extendSelection) {
510 // TODO: Is documented but doesn't seem to be implemented
511 //SendMsg(SCI_PAGEMOVE, cmdKey, extendSelection);
512}
513
514
515void wxStyledTextCtrl::ScrollBy(int columnDelta, int lineDelta) {
516 SendMsg(EM_LINESCROLL, columnDelta, lineDelta);
517}
518
519void wxStyledTextCtrl::ScrollToLine(int line) {
520 m_swx->DoScrollToLine(line);
521}
522
523
524void wxStyledTextCtrl::ScrollToColumn(int column) {
525 m_swx->DoScrollToColumn(column);
526}
527
528
529void wxStyledTextCtrl::EnsureCaretVisible() {
530 SendMsg(EM_SCROLLCARET);
531}
532
533
534void wxStyledTextCtrl::SetCaretPolicy(int policy, int slop) {
535 SendMsg(SCI_SETCARETPOLICY, policy, slop);
536}
537
538
539int wxStyledTextCtrl::GetSelectionType() {
540 return SendMsg(EM_SELECTIONTYPE);
541}
542
543
f6bcfd97
BP
544int wxStyledTextCtrl::GetLinesOnScreen() {
545 return SendMsg(SCI_LINESONSCREEN);
546}
547
548
549bool wxStyledTextCtrl::IsSelectionRectangle() {
550 return SendMsg(SCI_SELECTIONISRECTANGLE) != 0;
551}
552
553
554void wxStyledTextCtrl::SetUseHorizontalScrollBar(bool use) {
555 SendMsg(SCI_SETHSCROLLBAR, use);
556}
557
558
559bool wxStyledTextCtrl::GetUseHorizontalScrollBar() {
560 return SendMsg(SCI_GETHSCROLLBAR) != 0;
561}
562
563
564
9ce192d4
RD
565
566
567//----------------------------------------------------------------------
568// Searching
569
570int wxStyledTextCtrl::FindText(int minPos, int maxPos,
571 const wxString& text,
572 bool caseSensitive, bool wholeWord) {
573 FINDTEXTEX ft;
574 int flags = 0;
575
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();
581
582 return SendMsg(EM_FINDTEXT, flags, (long)&ft);
583}
584
585
586void wxStyledTextCtrl::SearchAnchor() {
587 SendMsg(SCI_SEARCHANCHOR);
588}
589
590
591int wxStyledTextCtrl::SearchNext(const wxString& text, bool caseSensitive, bool wholeWord) {
592 int flags = 0;
593 flags |= caseSensitive ? FR_MATCHCASE : 0;
594 flags |= wholeWord ? FR_WHOLEWORD : 0;
595
596 return SendMsg(SCI_SEARCHNEXT, flags, (long)text.c_str());
597}
598
599
600int wxStyledTextCtrl::SearchPrev(const wxString& text, bool caseSensitive, bool wholeWord) {
601 int flags = 0;
602 flags |= caseSensitive ? FR_MATCHCASE : 0;
603 flags |= wholeWord ? FR_WHOLEWORD : 0;
604
605 return SendMsg(SCI_SEARCHPREV, flags, (long)text.c_str());
606}
607
608//----------------------------------------------------------------------
609// Visible whitespace
610
611
612bool wxStyledTextCtrl::GetViewWhitespace() {
613 return SendMsg(SCI_GETVIEWWS) != 0;
614}
615
616
617void wxStyledTextCtrl::SetViewWhitespace(bool visible) {
618 SendMsg(SCI_SETVIEWWS, visible);
619}
620
621
622
623//----------------------------------------------------------------------
624// Line endings
625
626wxSTC_EOL wxStyledTextCtrl::GetEOLMode() {
627 return (wxSTC_EOL)SendMsg(SCI_GETEOLMODE);
628}
629
630
631void wxStyledTextCtrl::SetEOLMode(wxSTC_EOL mode) {
632 SendMsg(SCI_SETEOLMODE, mode);
633}
634
635
636bool wxStyledTextCtrl::GetViewEOL() {
637 return SendMsg(SCI_GETVIEWEOL) != 0;
638}
639
640
641void wxStyledTextCtrl::SetViewEOL(bool visible) {
642 SendMsg(SCI_SETVIEWEOL, visible);
643}
644
645void wxStyledTextCtrl::ConvertEOL(wxSTC_EOL mode) {
646 SendMsg(SCI_CONVERTEOLS, mode);
647}
648
649//----------------------------------------------------------------------
650// Styling
651
652int wxStyledTextCtrl::GetEndStyled() {
653 return SendMsg(SCI_GETENDSTYLED);
654}
655
656
657void wxStyledTextCtrl::StartStyling(int pos, int mask) {
658 SendMsg(SCI_STARTSTYLING, pos, mask);
659}
660
661
662void wxStyledTextCtrl::SetStyleFor(int length, int style) {
663 SendMsg(SCI_SETSTYLING, length, style);
664}
665
666
667void wxStyledTextCtrl::SetStyleBytes(int length, char* styleBytes) {
668 SendMsg(SCI_SETSTYLINGEX, length, (long)styleBytes);
669}
670
671
f6bcfd97
BP
672void wxStyledTextCtrl::SetLineState(int line, int value) {
673 SendMsg(SCI_SETLINESTATE, line, value);
674}
675
676
677int wxStyledTextCtrl::GetLineState(int line) {
678 return SendMsg(SCI_GETLINESTATE, line);
679}
680
681
9ce192d4
RD
682//----------------------------------------------------------------------
683// Style Definition
684
685
686static long wxColourAsLong(const wxColour& co) {
687 return (((long)co.Blue() << 16) |
688 ((long)co.Green() << 8) |
689 ((long)co.Red()));
690}
691
692static wxColour wxColourFromLong(long c) {
693 wxColour clr;
694 clr.Set(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff);
695 return clr;
696}
697
698
699static wxColour wxColourFromSpec(const wxString& spec) {
700 // spec should be #RRGGBB
701 char* junk;
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);
706}
707
708
709void wxStyledTextCtrl::StyleClearAll() {
710 SendMsg(SCI_STYLECLEARALL);
711}
712
713
714void wxStyledTextCtrl::StyleResetDefault() {
715 SendMsg(SCI_STYLERESETDEFAULT);
716}
717
718
719
720// Extract style settings from a spec-string which is composed of one or
721// more of the following comma separated elements:
722//
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
f6bcfd97 730// underline turns on underlining
9ce192d4
RD
731//
732
733void wxStyledTextCtrl::StyleSetSpec(int styleNum, const wxString& spec) {
734
735 wxStringTokenizer tkz(spec, ",");
736 while (tkz.HasMoreTokens()) {
737 wxString token = tkz.GetNextToken();
738
739 wxString option = token.BeforeFirst(':');
740 wxString val = token.AfterFirst(':');
741
742 if (option == "bold")
743 StyleSetBold(styleNum, true);
744
745 else if (option == "italic")
746 StyleSetItalic(styleNum, true);
747
f6bcfd97
BP
748 else if (option == "underline")
749 StyleSetUnderline(styleNum, true);
750
9ce192d4
RD
751 else if (option == "eol")
752 StyleSetEOLFilled(styleNum, true);
753
754 else if (option == "size") {
755 long points;
756 if (val.ToLong(&points))
757 StyleSetSize(styleNum, points);
758 }
759
760 else if (option == "face")
761 StyleSetFaceName(styleNum, val);
762
763 else if (option == "fore")
764 StyleSetForeground(styleNum, wxColourFromSpec(val));
765
766 else if (option == "back")
767 StyleSetBackground(styleNum, wxColourFromSpec(val));
768 }
769}
770
771
772void wxStyledTextCtrl::StyleSetForeground(int styleNum, const wxColour& colour) {
773 SendMsg(SCI_STYLESETFORE, styleNum, wxColourAsLong(colour));
774}
775
776
777void wxStyledTextCtrl::StyleSetBackground(int styleNum, const wxColour& colour) {
778 SendMsg(SCI_STYLESETBACK, styleNum, wxColourAsLong(colour));
779}
780
781
782void 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;
f6bcfd97 787 bool under = font.GetUnderlined();
9ce192d4 788
f6bcfd97 789 StyleSetFontAttr(styleNum, size, faceName, bold, italic, under);
9ce192d4
RD
790}
791
792
793void wxStyledTextCtrl::StyleSetFontAttr(int styleNum, int size,
794 const wxString& faceName,
f6bcfd97
BP
795 bool bold, bool italic,
796 bool underline) {
9ce192d4
RD
797 StyleSetSize(styleNum, size);
798 StyleSetFaceName(styleNum, faceName);
799 StyleSetBold(styleNum, bold);
800 StyleSetItalic(styleNum, italic);
f6bcfd97 801 StyleSetUnderline(styleNum, underline);
9ce192d4
RD
802}
803
804
805void wxStyledTextCtrl::StyleSetBold(int styleNum, bool bold) {
806 SendMsg(SCI_STYLESETBOLD, styleNum, bold);
807}
808
809
810void wxStyledTextCtrl::StyleSetItalic(int styleNum, bool italic) {
811 SendMsg(SCI_STYLESETITALIC, styleNum, italic);
812}
813
814
815void wxStyledTextCtrl::StyleSetFaceName(int styleNum, const wxString& faceName) {
816 SendMsg(SCI_STYLESETFONT, styleNum, (long)faceName.c_str());
817}
818
819
820void wxStyledTextCtrl::StyleSetSize(int styleNum, int pointSize) {
821 SendMsg(SCI_STYLESETSIZE, styleNum, pointSize);
822}
823
824
825void wxStyledTextCtrl::StyleSetEOLFilled(int styleNum, bool fillEOL) {
826 SendMsg(SCI_STYLESETEOLFILLED, styleNum, fillEOL);
827}
828
829
f6bcfd97
BP
830void wxStyledTextCtrl::StyleSetUnderline(int styleNum, bool underline) {
831 SendMsg(SCI_STYLESETUNDERLINE, styleNum, underline);
832}
833
834
9ce192d4
RD
835//----------------------------------------------------------------------
836// Margins in the edit area
837
838int wxStyledTextCtrl::GetLeftMargin() {
839 return LOWORD(SendMsg(EM_GETMARGINS));
840}
841
842
843int wxStyledTextCtrl::GetRightMargin() {
844 return HIWORD(SendMsg(EM_GETMARGINS));
845}
846
847
848void wxStyledTextCtrl::SetMargins(int left, int right) {
849 int flag = 0;
850 int val = 0;
851
852 if (right != -1) {
853 flag |= EC_RIGHTMARGIN;
854 val = right << 16;
855 }
856 if (left != -1) {
857 flag |= EC_LEFTMARGIN;
858 val |= (left & 0xffff);
859 }
860
861 SendMsg(EM_SETMARGINS, flag, val);
862}
863
864
865//----------------------------------------------------------------------
866// Margins for selection, markers, etc.
867
868void wxStyledTextCtrl::SetMarginType(int margin, int type) {
869 SendMsg(SCI_SETMARGINTYPEN, margin, type);
870}
871
872
873int wxStyledTextCtrl::GetMarginType(int margin) {
874 return SendMsg(SCI_GETMARGINTYPEN, margin);
875}
876
877
878void wxStyledTextCtrl::SetMarginWidth(int margin, int pixelWidth) {
879 SendMsg(SCI_SETMARGINWIDTHN, margin, pixelWidth);
880}
881
882
883int wxStyledTextCtrl::GetMarginWidth(int margin) {
884 return SendMsg(SCI_GETMARGINWIDTHN, margin);
885}
886
887
888void wxStyledTextCtrl::SetMarginMask(int margin, int mask) {
889 SendMsg(SCI_SETMARGINMASKN, margin, mask);
890}
891
892
893int wxStyledTextCtrl::GetMarginMask(int margin) {
894 return SendMsg(SCI_GETMARGINMASKN, margin);
895}
896
897
898void wxStyledTextCtrl::SetMarginSensitive(int margin, bool sensitive) {
899 SendMsg(SCI_SETMARGINSENSITIVEN, margin, sensitive);
900}
901
902
903bool wxStyledTextCtrl::GetMarginSensitive(int margin) {
67003d1a 904 return SendMsg(SCI_GETMARGINSENSITIVEN, margin) != 0;
9ce192d4
RD
905}
906
907
908
909
910//----------------------------------------------------------------------
911// Selection and Caret styles
912
913
914void wxStyledTextCtrl::SetSelectionForeground(const wxColour& colour) {
915 SendMsg(SCI_SETSELFORE, 0, wxColourAsLong(colour));
916}
917
918
919void wxStyledTextCtrl::SetSelectionBackground(const wxColour& colour) {
920 SendMsg(SCI_SETSELBACK, 0, wxColourAsLong(colour));
921}
922
923
924void wxStyledTextCtrl::SetCaretForeground(const wxColour& colour) {
f6bcfd97 925 SendMsg(SCI_SETCARETFORE, wxColourAsLong(colour));
9ce192d4
RD
926}
927
928
929int wxStyledTextCtrl::GetCaretPeriod() {
930 return SendMsg(SCI_GETCARETPERIOD);
931}
932
933
934void wxStyledTextCtrl::SetCaretPeriod(int milliseconds) {
935 SendMsg(SCI_SETCARETPERIOD, milliseconds);
936}
937
938
939
940//----------------------------------------------------------------------
941// Other settings
942
943
944void wxStyledTextCtrl::SetBufferedDraw(bool isBuffered) {
945 SendMsg(SCI_SETBUFFEREDDRAW, isBuffered);
946}
947
948
949void wxStyledTextCtrl::SetTabWidth(int numChars) {
950 SendMsg(SCI_SETTABWIDTH, numChars);
951}
952
953
f6bcfd97
BP
954void wxStyledTextCtrl::SetIndent(int numChars) {
955 SendMsg(SCI_SETINDENT, numChars);
956}
957
958
959void wxStyledTextCtrl::SetUseTabs(bool usetabs) {
960 SendMsg(SCI_SETUSETABS, usetabs);
961}
962
963
964void wxStyledTextCtrl::SetLineIndentation(int line, int indentation) {
965 SendMsg(SCI_SETLINEINDENTATION, line, indentation);
966}
967
968
969int wxStyledTextCtrl:: GetLineIndentation(int line) {
970 return SendMsg(SCI_GETLINEINDENTATION, line);
971}
972
973
974int wxStyledTextCtrl::GetLineIndentationPos(int line) {
975 return SendMsg(SCI_GETLINEINDENTPOSITION, line);
976}
977
978
9ce192d4
RD
979void wxStyledTextCtrl::SetWordChars(const wxString& wordChars) {
980 SendMsg(SCI_SETTABWIDTH, 0, (long)wordChars.c_str());
981}
982
983
f6bcfd97
BP
984void wxStyledTextCtrl::SetUsePop(bool usepopup) {
985 SendMsg(SCI_USEPOPUP, usepopup);
986}
987
988
9ce192d4
RD
989//----------------------------------------------------------------------
990// Brace highlighting
991
992
993void wxStyledTextCtrl::BraceHighlight(int pos1, int pos2) {
994 SendMsg(SCI_BRACEHIGHLIGHT, pos1, pos2);
995}
996
997
998void wxStyledTextCtrl::BraceBadlight(int pos) {
999 SendMsg(SCI_BRACEBADLIGHT, pos);
1000}
1001
1002
1003int wxStyledTextCtrl::BraceMatch(int pos, int maxReStyle) {
1004 return SendMsg(SCI_BRACEMATCH, pos, maxReStyle);
1005}
1006
1007
1008
1009//----------------------------------------------------------------------
1010// Markers
1011
1012void 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);
1018}
1019
1020
1021void wxStyledTextCtrl::MarkerSetType(int markerNumber, int markerSymbol) {
1022 SendMsg(SCI_MARKERDEFINE, markerNumber, markerSymbol);
1023}
1024
1025
1026void wxStyledTextCtrl::MarkerSetForeground(int markerNumber, const wxColour& colour) {
1027 SendMsg(SCI_MARKERSETFORE, markerNumber, wxColourAsLong(colour));
1028}
1029
1030
1031void wxStyledTextCtrl::MarkerSetBackground(int markerNumber, const wxColour& colour) {
1032 SendMsg(SCI_MARKERSETBACK, markerNumber, wxColourAsLong(colour));
1033}
1034
1035
1036int wxStyledTextCtrl::MarkerAdd(int line, int markerNumber) {
1037 return SendMsg(SCI_MARKERADD, line, markerNumber);
1038}
1039
1040
1041void wxStyledTextCtrl::MarkerDelete(int line, int markerNumber) {
1042 SendMsg(SCI_MARKERDELETE, line, markerNumber);
1043}
1044
1045
1046void wxStyledTextCtrl::MarkerDeleteAll(int markerNumber) {
1047 SendMsg(SCI_MARKERDELETEALL, markerNumber);
1048}
1049
1050
1051int wxStyledTextCtrl::MarkerGet(int line) {
1052 return SendMsg(SCI_MARKERGET);
1053}
1054
1055
1056int wxStyledTextCtrl::MarkerGetNextLine(int lineStart, int markerMask) {
1057 return SendMsg(SCI_MARKERNEXT, lineStart, markerMask);
1058}
1059
1060
1061int wxStyledTextCtrl::MarkerGetPrevLine(int lineStart, int markerMask) {
1062// return SendMsg(SCI_MARKERPREV, lineStart, markerMask);
1063 return 0;
1064}
1065
1066
1067int wxStyledTextCtrl::MarkerLineFromHandle(int handle) {
1068 return SendMsg(SCI_MARKERLINEFROMHANDLE, handle);
1069}
1070
1071
1072void wxStyledTextCtrl::MarkerDeleteHandle(int handle) {
1073 SendMsg(SCI_MARKERDELETEHANDLE, handle);
1074}
1075
1076
1077
1078//----------------------------------------------------------------------
1079// Indicators
1080
1081
1082void wxStyledTextCtrl::IndicatorSetStyle(int indicNum, int indicStyle) {
1083 SendMsg(SCI_INDICSETSTYLE, indicNum, indicStyle);
1084}
1085
1086
1087int wxStyledTextCtrl::IndicatorGetStyle(int indicNum) {
1088 return SendMsg(SCI_INDICGETSTYLE, indicNum);
1089}
1090
1091
1092void wxStyledTextCtrl::IndicatorSetColour(int indicNum, const wxColour& colour) {
f6bcfd97 1093 SendMsg(SCI_INDICSETFORE, indicNum, wxColourAsLong(colour));
9ce192d4
RD
1094}
1095
1096
1097
1098//----------------------------------------------------------------------
1099// Auto completion
1100
1101
1102void wxStyledTextCtrl::AutoCompShow(const wxString& listOfWords) {
1103 SendMsg(SCI_AUTOCSHOW, 0, (long)listOfWords.c_str());
1104}
1105
1106
1107void wxStyledTextCtrl::AutoCompCancel() {
1108 SendMsg(SCI_AUTOCCANCEL);
1109}
1110
1111
1112bool wxStyledTextCtrl::AutoCompActive() {
1113 return SendMsg(SCI_AUTOCACTIVE) != 0;
1114}
1115
1116
1117int wxStyledTextCtrl::AutoCompPosAtStart() {
1118 return SendMsg(SCI_AUTOCPOSSTART);
1119}
1120
1121
1122void wxStyledTextCtrl::AutoCompComplete() {
1123 SendMsg(SCI_AUTOCCOMPLETE);
1124}
1125
1126
1127void wxStyledTextCtrl::AutoCompStopChars(const wxString& stopChars) {
1128 SendMsg(SCI_AUTOCSHOW, 0, (long)stopChars.c_str());
1129}
1130
1131
f6bcfd97
BP
1132void wxStyledTextCtrl::AutoCompSetSeparator(char separator) {
1133 SendMsg(SCI_AUTOCSETSEPARATOR, separator);
1134}
1135
1136
1137char wxStyledTextCtrl::AutoCompGetSeparator() {
1138 return SendMsg(SCI_AUTOCGETSEPARATOR);
1139}
1140
1141
1142void wxStyledTextCtrl::AutoCompSelect(const wxString& stringtoselect) {
1143 SendMsg(SCI_AUTOCSELECT, (long)stringtoselect.c_str());
1144}
1145
1146
9ce192d4
RD
1147//----------------------------------------------------------------------
1148// Call tips
1149
1150void wxStyledTextCtrl::CallTipShow(int pos, const wxString& text) {
1151 SendMsg(SCI_CALLTIPSHOW, pos, (long)text.c_str());
1152}
1153
1154
1155void wxStyledTextCtrl::CallTipCancel() {
1156 SendMsg(SCI_CALLTIPCANCEL);
1157}
1158
1159
1160bool wxStyledTextCtrl::CallTipActive() {
1161 return SendMsg(SCI_CALLTIPACTIVE) != 0;
1162}
1163
1164
1165int wxStyledTextCtrl::CallTipPosAtStart() {
1166 return SendMsg(SCI_CALLTIPPOSSTART);
1167}
1168
1169
1170void wxStyledTextCtrl::CallTipSetHighlight(int start, int end) {
1171 SendMsg(SCI_CALLTIPSETHLT, start, end);
1172}
1173
1174
1175void wxStyledTextCtrl::CallTipSetBackground(const wxColour& colour) {
1176 SendMsg(SCI_CALLTIPSETBACK, wxColourAsLong(colour));
1177}
1178
1179
1180//----------------------------------------------------------------------
1181// Key bindings
1182
1183void wxStyledTextCtrl::CmdKeyAssign(int key, int modifiers, int cmd) {
1184 SendMsg(SCI_ASSIGNCMDKEY, MAKELONG(key, modifiers), cmd);
1185}
1186
1187
1188void wxStyledTextCtrl::CmdKeyClear(int key, int modifiers) {
1189 SendMsg(SCI_CLEARCMDKEY, MAKELONG(key, modifiers));
1190}
1191
1192
1193void wxStyledTextCtrl::CmdKeyClearAll() {
1194 SendMsg(SCI_CLEARALLCMDKEYS);
1195}
1196
1197
1198void wxStyledTextCtrl::CmdKeyExecute(int cmd) {
1199 SendMsg(cmd);
1200}
1201
1202
1203
1204//----------------------------------------------------------------------
1205// Print formatting
1206
1207int
1208wxStyledTextCtrl::FormatRange(bool doDraw,
1209 int startPos,
1210 int endPos,
1211 wxDC* draw,
1212 wxDC* target, // Why does it use two? Can they be the same?
1213 wxRect renderRect,
1214 wxRect pageRect) {
1215 FORMATRANGE fr;
1216
1217 fr.hdc = draw;
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;
1229
1230 return SendMsg(EM_FORMATRANGE, doDraw, (long)&fr);
1231}
1232
1233
1234//----------------------------------------------------------------------
1235// Document Sharing
1236
1237void* wxStyledTextCtrl::GetDocument() {
1238 return (void*)SendMsg(SCI_GETDOCPOINTER);
1239}
1240
1241
1242void wxStyledTextCtrl::SetDocument(void* document) {
1243 SendMsg(SCI_SETDOCPOINTER, 0, (long)document);
1244}
1245
1246
67003d1a
RD
1247//----------------------------------------------------------------------
1248// Folding
1249
1250int wxStyledTextCtrl::VisibleFromDocLine(int docLine) {
1251 return SendMsg(SCI_VISIBLEFROMDOCLINE, docLine);
1252}
1253
1254
1255int wxStyledTextCtrl::DocLineFromVisible(int displayLine) {
1256 return SendMsg(SCI_DOCLINEFROMVISIBLE, displayLine);
1257}
1258
1259
1260int wxStyledTextCtrl::SetFoldLevel(int line, int level) {
1261 return SendMsg(SCI_SETFOLDLEVEL, line, level);
1262}
1263
1264
1265int wxStyledTextCtrl::GetFoldLevel(int line) {
1266 return SendMsg(SCI_GETFOLDLEVEL, line);
1267}
1268
1269
f6bcfd97
BP
1270int wxStyledTextCtrl::GetLastChild(int line, int level) {
1271 return SendMsg(SCI_GETLASTCHILD, line, level);
67003d1a
RD
1272}
1273
1274
1275int wxStyledTextCtrl::GetFoldParent(int line) {
1276 return SendMsg(SCI_GETFOLDPARENT, line);
1277}
1278
1279
1280void wxStyledTextCtrl::ShowLines(int lineStart, int lineEnd) {
1281 SendMsg(SCI_SHOWLINES, lineStart, lineEnd);
1282}
1283
1284
1285void wxStyledTextCtrl::HideLines(int lineStart, int lineEnd) {
1286 SendMsg(SCI_HIDELINES, lineStart, lineEnd);
1287}
1288
1289
1290bool wxStyledTextCtrl::GetLineVisible(int line) {
1291 return SendMsg(SCI_GETLINEVISIBLE, line) != 0;
1292}
1293
1294
f6bcfd97
BP
1295void wxStyledTextCtrl::SetFoldExpanded(int line, bool expanded) {
1296 SendMsg(SCI_SETFOLDEXPANDED, line, expanded);
67003d1a
RD
1297}
1298
1299
1300bool wxStyledTextCtrl::GetFoldExpanded(int line) {
1301 return SendMsg(SCI_GETFOLDEXPANDED, line) != 0;
1302}
1303
1304
1305void wxStyledTextCtrl::ToggleFold(int line) {
1306 SendMsg(SCI_TOGGLEFOLD, line);
1307}
1308
1309
1310void wxStyledTextCtrl::EnsureVisible(int line) {
1311 SendMsg(SCI_ENSUREVISIBLE, line);
1312}
1313
1314
f6bcfd97
BP
1315void wxStyledTextCtrl::SetFoldFlags(int flags) {
1316 SendMsg(SCI_SETFOLDFLAGS, flags);
1317}
1318
1319
1320//----------------------------------------------------------------------
1321// Zooming
1322
1323void wxStyledTextCtrl::ZoomIn() {
1324 SendMsg(SCI_ZOOMIN);
1325}
1326
1327
1328void wxStyledTextCtrl::ZoomOut() {
1329 SendMsg(SCI_ZOOMOUT);
1330}
1331
1332
1333void wxStyledTextCtrl::SetZoom(int zoom) {
1334 SendMsg(SCI_SETZOOM, zoom);
1335}
1336
1337
1338int wxStyledTextCtrl::GetZoom() {
1339 return SendMsg(SCI_GETZOOM);
1340}
1341
9ce192d4
RD
1342//----------------------------------------------------------------------
1343// Long Lines
1344
1345int wxStyledTextCtrl::GetEdgeColumn() {
1346 return SendMsg(SCI_GETEDGECOLUMN);
1347}
1348
1349void wxStyledTextCtrl::SetEdgeColumn(int column) {
1350 SendMsg(SCI_SETEDGECOLUMN, column);
1351}
1352
1353wxSTC_EDGE wxStyledTextCtrl::GetEdgeMode() {
1354 return (wxSTC_EDGE) SendMsg(SCI_GETEDGEMODE);
1355}
1356
1357void wxStyledTextCtrl::SetEdgeMode(wxSTC_EDGE mode){
1358 SendMsg(SCI_SETEDGEMODE, mode);
1359}
1360
1361wxColour wxStyledTextCtrl::GetEdgeColour() {
1362 long c = SendMsg(SCI_GETEDGECOLOUR);
1363 return wxColourFromLong(c);
1364}
1365
1366void wxStyledTextCtrl::SetEdgeColour(const wxColour& colour) {
1367 SendMsg(SCI_SETEDGECOLOUR, wxColourAsLong(colour));
1368}
1369
1370
1371//----------------------------------------------------------------------
1372// Lexer
1373
1374void wxStyledTextCtrl::SetLexer(wxSTC_LEX lexer) {
1375 SendMsg(SCI_SETLEXER, lexer);
1376}
1377
1378
1379wxSTC_LEX wxStyledTextCtrl::GetLexer() {
1380 return (wxSTC_LEX)SendMsg(SCI_GETLEXER);
1381}
1382
1383
1384void wxStyledTextCtrl::Colourise(int start, int end) {
1385 SendMsg(SCI_COLOURISE, start, end);
1386}
1387
1388
1389void wxStyledTextCtrl::SetProperty(const wxString& key, const wxString& value) {
1390 SendMsg(SCI_SETPROPERTY, (long)key.c_str(), (long)value.c_str());
1391}
1392
1393
1394void wxStyledTextCtrl::SetKeywords(int keywordSet, const wxString& keywordList) {
1395 SendMsg(SCI_SETKEYWORDS, keywordSet, (long)keywordList.c_str());
1396}
1397
1398
1399
f6bcfd97
BP
1400//----------------------------------------------------------------------
1401// Event mask for Modified Event
1402
1403void wxStyledTextCtrl::SetModEventMask(int mask) {
1404 SendMsg(SCI_SETMODEVENTMASK, mask);
1405}
1406
1407
1408//int wxStyledTextCtrl::GetModEventMask() {
1409// return SendMsg(SCI_GETMODEVENTMASK);
1410//}
1411
9ce192d4
RD
1412//----------------------------------------------------------------------
1413// Event handlers
1414
1415void wxStyledTextCtrl::OnPaint(wxPaintEvent& evt) {
1416 wxPaintDC dc(this);
1417 wxRegion region = GetUpdateRegion();
1418
1419 m_swx->DoPaint(&dc, region.GetBox());
1420}
1421
1422void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent& evt) {
1423 if (evt.GetOrientation() == wxHORIZONTAL)
1424 m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition());
1425 else
1426 m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition());
1427}
1428
1429void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) {
1430 wxSize sz = GetClientSize();
1431 m_swx->DoSize(sz.x, sz.y);
1432}
1433
1434void 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());
1438}
1439
1440void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) {
1441 wxPoint pt = evt.GetPosition();
1442 m_swx->DoButtonMove(Point(pt.x, pt.y));
1443}
1444
1445void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) {
1446 wxPoint pt = evt.GetPosition();
1447 m_swx->DoButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(),
1448 evt.ControlDown());
1449}
1450
1451
1452void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) {
1453 wxPoint pt = evt.GetPosition();
1454 m_swx->DoContextMenu(Point(pt.x, pt.y));
1455}
1456
1457void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) {
9ce192d4
RD
1458 long key = evt.KeyCode();
1459 if ((key > WXK_ESCAPE) &&
1460 (key != WXK_DELETE) && (key < 255) &&
1461 !evt.ControlDown() && !evt.AltDown()) {
1462
1463 m_swx->DoAddChar(key);
9ce192d4
RD
1464 }
1465 else {
f6bcfd97 1466 evt.Skip();
9ce192d4 1467 }
f6bcfd97
BP
1468}
1469
1470void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) {
1471 long key = evt.KeyCode();
1472 key = toupper(key);
1473 int processed = m_swx->DoKeyDown(key, evt.ShiftDown(),
1474 evt.ControlDown(), evt.AltDown());
9ce192d4
RD
1475 if (! processed)
1476 evt.Skip();
1477}
1478
1479void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent& evt) {
1480 m_swx->DoLoseFocus();
1481}
1482
1483void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) {
1484 m_swx->DoGainFocus();
1485}
1486
1487void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& evt) {
1488 m_swx->DoSysColourChange();
1489}
1490
1491void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent& evt) {
1492 // do nothing to help avoid flashing
1493}
1494
1495
1496
1497void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) {
1498 m_swx->DoCommand(evt.GetId());
1499}
1500
1501
f6bcfd97
BP
1502void wxStyledTextCtrl::OnListBox(wxCommandEvent& evt) {
1503 m_swx->DoOnListBox();
1504}
1505
1506
9ce192d4
RD
1507//----------------------------------------------------------------------
1508// Turn notifications from Scintilla into events
1509
f6bcfd97 1510
9ce192d4
RD
1511void wxStyledTextCtrl::NotifyChange() {
1512 wxStyledTextEvent evt(wxEVT_STC_CHANGE, GetId());
1513 GetEventHandler()->ProcessEvent(evt);
1514}
1515
1516void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) {
1517 SCNotification& scn = *_scn;
1518 int eventType = 0;
1519 switch (scn.nmhdr.code) {
1520 case SCN_STYLENEEDED:
1521 eventType = wxEVT_STC_STYLENEEDED;
1522 break;
1523 case SCN_CHARADDED:
1524 eventType = wxEVT_STC_CHARADDED;
1525 break;
1526 case SCN_UPDATEUI:
1527 eventType = wxEVT_STC_UPDATEUI;
1528 break;
1529 case SCN_SAVEPOINTREACHED:
1530 eventType = wxEVT_STC_SAVEPOINTREACHED;
1531 break;
1532 case SCN_SAVEPOINTLEFT:
1533 eventType = wxEVT_STC_SAVEPOINTLEFT;
1534 break;
1535 case SCN_MODIFYATTEMPTRO:
1536 eventType = wxEVT_STC_ROMODIFYATTEMPT;
1537 break;
1538 case SCN_DOUBLECLICK:
1539 eventType = wxEVT_STC_DOUBLECLICK;
1540 break;
1541 case SCN_MODIFIED:
1542 eventType = wxEVT_STC_MODIFIED;
1543 break;
1544 case SCN_KEY:
1545 eventType = wxEVT_STC_KEY;
1546 break;
1547 case SCN_MACRORECORD:
1548 eventType = wxEVT_STC_MACRORECORD;
1549 break;
1550 case SCN_MARGINCLICK:
1551 eventType = wxEVT_STC_MARGINCLICK;
1552 break;
1553 case SCN_NEEDSHOWN:
1554 eventType = wxEVT_STC_NEEDSHOWN;
1555 break;
1556 }
1557 if (eventType) {
1558 wxStyledTextEvent evt(eventType, GetId());
1559 evt.SetPosition(scn.position);
1560 evt.SetKey(scn.ch);
1561 evt.SetModifiers(scn.modifiers);
1562 if (eventType == wxEVT_STC_MODIFIED) {
1563 evt.SetModificationType(scn.modificationType);
f6bcfd97
BP
1564 if (scn.text)
1565 evt.SetText(wxString(scn.text, scn.length));
9ce192d4
RD
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);
1571 }
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);
1578 }
1579
1580 GetEventHandler()->ProcessEvent(evt);
1581 }
1582}
1583
1584
1585
1586//----------------------------------------------------------------------
1587//----------------------------------------------------------------------
1588//----------------------------------------------------------------------
1589
1590wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id)
1591 : wxCommandEvent(commandType, id)
1592{
1593 m_position = 0;
1594 m_key = 0;
1595 m_modifiers = 0;
1596 m_modificationType = 0;
1597 m_length = 0;
1598 m_linesAdded = 0;
1599 m_line = 0;
1600 m_foldLevelNow = 0;
1601 m_foldLevelPrev = 0;
1602 m_margin = 0;
1603 m_message = 0;
1604 m_wParam = 0;
1605 m_lParam = 0;
1606
1607
1608}
1609
1610bool wxStyledTextEvent::GetShift() const { return (m_modifiers & SCI_SHIFT) != 0; }
1611bool wxStyledTextEvent::GetControl() const { return (m_modifiers & SCI_CTRL) != 0; }
1612bool wxStyledTextEvent::GetAlt() const { return (m_modifiers & SCI_ALT) != 0; }
1613
1614void wxStyledTextEvent::CopyObject(wxObject& obj) const {
1615 wxCommandEvent::CopyObject(obj);
1616
1617 wxStyledTextEvent* o = (wxStyledTextEvent*)&obj;
1618 o->m_position = m_position;
1619 o->m_key = m_key;
1620 o->m_modifiers = m_modifiers;
1621 o->m_modificationType = m_modificationType;
1622 o->m_text = m_text;
1623 o->m_length = m_length;
1624 o->m_linesAdded = m_linesAdded;
1625 o->m_line = m_line;
1626 o->m_foldLevelNow = m_foldLevelNow;
1627 o->m_foldLevelPrev = m_foldLevelPrev;
1628
1629 o->m_margin = m_margin;
1630
1631 o->m_message = m_message;
1632 o->m_wParam = m_wParam;
1633 o->m_lParam = m_lParam;
1634
1635
1636
1637}
1638
1639//----------------------------------------------------------------------
1640//----------------------------------------------------------------------
1641