]> git.saurik.com Git - wxWidgets.git/blob - src/stc/stc.cpp
fixed GTK critical warning when closing MDI child (patch 529369)
[wxWidgets.git] / 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 identifiers 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 <ctype.h>
19
20 #include "wx/stc/stc.h"
21 #include "ScintillaWX.h"
22
23 #include <wx/tokenzr.h>
24
25
26 //----------------------------------------------------------------------
27
28 const wxChar* wxSTCNameStr = "stcwindow";
29
30 DEFINE_EVENT_TYPE( wxEVT_STC_CHANGE )
31 DEFINE_EVENT_TYPE( wxEVT_STC_STYLENEEDED )
32 DEFINE_EVENT_TYPE( wxEVT_STC_CHARADDED )
33 DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTREACHED )
34 DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTLEFT )
35 DEFINE_EVENT_TYPE( wxEVT_STC_ROMODIFYATTEMPT )
36 DEFINE_EVENT_TYPE( wxEVT_STC_KEY )
37 DEFINE_EVENT_TYPE( wxEVT_STC_DOUBLECLICK )
38 DEFINE_EVENT_TYPE( wxEVT_STC_UPDATEUI )
39 DEFINE_EVENT_TYPE( wxEVT_STC_MODIFIED )
40 DEFINE_EVENT_TYPE( wxEVT_STC_MACRORECORD )
41 DEFINE_EVENT_TYPE( wxEVT_STC_MARGINCLICK )
42 DEFINE_EVENT_TYPE( wxEVT_STC_NEEDSHOWN )
43 DEFINE_EVENT_TYPE( wxEVT_STC_POSCHANGED )
44 DEFINE_EVENT_TYPE( wxEVT_STC_PAINTED )
45 DEFINE_EVENT_TYPE( wxEVT_STC_USERLISTSELECTION )
46 DEFINE_EVENT_TYPE( wxEVT_STC_URIDROPPED )
47 DEFINE_EVENT_TYPE( wxEVT_STC_DWELLSTART )
48 DEFINE_EVENT_TYPE( wxEVT_STC_DWELLEND )
49 DEFINE_EVENT_TYPE( wxEVT_STC_START_DRAG )
50 DEFINE_EVENT_TYPE( wxEVT_STC_DRAG_OVER )
51 DEFINE_EVENT_TYPE( wxEVT_STC_DO_DROP )
52
53
54 BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl)
55 EVT_PAINT (wxStyledTextCtrl::OnPaint)
56 EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin)
57 EVT_SCROLL (wxStyledTextCtrl::OnScroll)
58 EVT_SIZE (wxStyledTextCtrl::OnSize)
59 EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown)
60 #ifdef __WXMSW__
61 // Let Scintilla see the double click as a second click
62 EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown)
63 #endif
64 EVT_MOTION (wxStyledTextCtrl::OnMouseMove)
65 EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp)
66 #ifdef __WXGTK__
67 EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp)
68 #else
69 EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu)
70 #endif
71 EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel)
72 EVT_CHAR (wxStyledTextCtrl::OnChar)
73 EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown)
74 EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus)
75 EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus)
76 EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged)
77 EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground)
78 EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu)
79 EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox)
80 END_EVENT_TABLE()
81
82
83 IMPLEMENT_CLASS(wxStyledTextCtrl, wxControl)
84 IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent, wxCommandEvent)
85
86 // forces the linking of the lexer modules
87 int Scintilla_LinkLexers();
88
89 //----------------------------------------------------------------------
90 // Constructor and Destructor
91
92 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent,
93 wxWindowID id,
94 const wxPoint& pos,
95 const wxSize& size,
96 long style,
97 const wxString& name) :
98 wxControl(parent, id, pos, size,
99 style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS | wxCLIP_CHILDREN,
100 wxDefaultValidator, name)
101 {
102 Scintilla_LinkLexers();
103 m_swx = new ScintillaWX(this);
104 m_stopWatch.Start();
105 m_lastKeyDownConsumed = FALSE;
106 m_vScrollBar = NULL;
107 m_hScrollBar = NULL;
108 }
109
110
111 wxStyledTextCtrl::~wxStyledTextCtrl() {
112 delete m_swx;
113 }
114
115
116 //----------------------------------------------------------------------
117
118 long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) {
119
120 return m_swx->WndProc(msg, wp, lp);
121 }
122
123
124 #ifdef MAKELONG
125 #undef MAKELONG
126 #endif
127
128 #define MAKELONG(a, b) ((a) | ((b) << 16))
129
130
131 static long wxColourAsLong(const wxColour& co) {
132 return (((long)co.Blue() << 16) |
133 ((long)co.Green() << 8) |
134 ((long)co.Red()));
135 }
136
137 static wxColour wxColourFromLong(long c) {
138 wxColour clr;
139 clr.Set(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff);
140 return clr;
141 }
142
143
144 static wxColour wxColourFromSpec(const wxString& spec) {
145 // spec should be #RRGGBB
146 char* junk;
147 int red = strtol(spec.Mid(1,2), &junk, 16);
148 int green = strtol(spec.Mid(3,2), &junk, 16);
149 int blue = strtol(spec.Mid(5,2), &junk, 16);
150 return wxColour(red, green, blue);
151 }
152
153
154 //----------------------------------------------------------------------
155 // BEGIN generated section. The following code is automatically generated
156 // by gen_iface.py from the contents of Scintilla.iface. Do not edit
157 // this file. Edit stc.cpp.in or gen_iface.py instead and regenerate.
158
159
160 // Add text to the document
161 void wxStyledTextCtrl::AddText(const wxString& text) {
162 SendMsg(2001, text.Len(), (long)text.c_str());
163 }
164
165 // Add array of cells to document
166 void wxStyledTextCtrl::AddStyledText(const wxString& text) {
167 SendMsg(2002, text.Len(), (long)text.c_str());
168 }
169
170 // Insert string at a position
171 void wxStyledTextCtrl::InsertText(int pos, const wxString& text) {
172 SendMsg(2003, pos, (long)text.c_str());
173 }
174
175 // Delete all text in the document
176 void wxStyledTextCtrl::ClearAll() {
177 SendMsg(2004, 0, 0);
178 }
179
180 // Set all style bytes to 0, remove all folding information
181 void wxStyledTextCtrl::ClearDocumentStyle() {
182 SendMsg(2005, 0, 0);
183 }
184
185 // The number of characters in the document
186 int wxStyledTextCtrl::GetLength() {
187 return SendMsg(2006, 0, 0);
188 }
189
190 // Returns the character byte at the position
191 int wxStyledTextCtrl::GetCharAt(int pos) {
192 return SendMsg(2007, pos, 0);
193 }
194
195 // Returns the position of the caret
196 int wxStyledTextCtrl::GetCurrentPos() {
197 return SendMsg(2008, 0, 0);
198 }
199
200 // Returns the position of the opposite end of the selection to the caret
201 int wxStyledTextCtrl::GetAnchor() {
202 return SendMsg(2009, 0, 0);
203 }
204
205 // Returns the style byte at the position
206 int wxStyledTextCtrl::GetStyleAt(int pos) {
207 return SendMsg(2010, pos, 0);
208 }
209
210 // Redoes the next action on the undo history
211 void wxStyledTextCtrl::Redo() {
212 SendMsg(2011, 0, 0);
213 }
214
215 // Choose between collecting actions into the undo
216 // history and discarding them.
217 void wxStyledTextCtrl::SetUndoCollection(bool collectUndo) {
218 SendMsg(2012, collectUndo, 0);
219 }
220
221 // Select all the text in the document.
222 void wxStyledTextCtrl::SelectAll() {
223 SendMsg(2013, 0, 0);
224 }
225
226 // Remember the current position in the undo history as the position
227 // at which the document was saved.
228 void wxStyledTextCtrl::SetSavePoint() {
229 SendMsg(2014, 0, 0);
230 }
231
232 // Retrieve a buffer of cells.
233 wxString wxStyledTextCtrl::GetStyledText(int startPos, int endPos) {
234 wxString text;
235 if (endPos < startPos) {
236 int temp = startPos;
237 startPos = endPos;
238 endPos = temp;
239 }
240 int len = endPos - startPos;
241 if (!len) return "";
242 TextRange tr;
243 tr.lpstrText = text.GetWriteBuf(len*2);
244 tr.chrg.cpMin = startPos;
245 tr.chrg.cpMax = endPos;
246 SendMsg(2015, 0, (long)&tr);
247 text.UngetWriteBuf(len*2);
248 return text;
249 }
250
251 // Are there any redoable actions in the undo history.
252 bool wxStyledTextCtrl::CanRedo() {
253 return SendMsg(2016, 0, 0) != 0;
254 }
255
256 // Retrieve the line number at which a particular marker is located
257 int wxStyledTextCtrl::MarkerLineFromHandle(int handle) {
258 return SendMsg(2017, handle, 0);
259 }
260
261 // Delete a marker.
262 void wxStyledTextCtrl::MarkerDeleteHandle(int handle) {
263 SendMsg(2018, handle, 0);
264 }
265
266 // Is undo history being collected?
267 bool wxStyledTextCtrl::GetUndoCollection() {
268 return SendMsg(2019, 0, 0) != 0;
269 }
270
271 // Are white space characters currently visible?
272 // Returns one of SCWS_* constants.
273 int wxStyledTextCtrl::GetViewWhiteSpace() {
274 return SendMsg(2020, 0, 0);
275 }
276
277 // Make white space characters invisible, always visible or visible outside indentation.
278 void wxStyledTextCtrl::SetViewWhiteSpace(int viewWS) {
279 SendMsg(2021, viewWS, 0);
280 }
281
282 // Find the position from a point within the window.
283 int wxStyledTextCtrl::PositionFromPoint(wxPoint pt) {
284 return SendMsg(2022, pt.x, pt.y);
285 }
286
287 // Find the position from a point within the window but return
288 // INVALID_POSITION if not close to text.
289 int wxStyledTextCtrl::PositionFromPointClose(int x, int y) {
290 return SendMsg(2023, x, y);
291 }
292
293 // Set caret to start of a line and ensure it is visible.
294 void wxStyledTextCtrl::GotoLine(int line) {
295 SendMsg(2024, line, 0);
296 }
297
298 // Set caret to a position and ensure it is visible.
299 void wxStyledTextCtrl::GotoPos(int pos) {
300 SendMsg(2025, pos, 0);
301 }
302
303 // Set the selection anchor to a position. The anchor is the opposite
304 // end of the selection from the caret.
305 void wxStyledTextCtrl::SetAnchor(int posAnchor) {
306 SendMsg(2026, posAnchor, 0);
307 }
308
309 // Retrieve the text of the line containing the caret.
310 // Returns the index of the caret on the line.
311 wxString wxStyledTextCtrl::GetCurLine(int* linePos) {
312 wxString text;
313 int len = LineLength(GetCurrentLine());
314 if (!len) {
315 if (linePos) *linePos = 0;
316 return "";
317 }
318 // Need an extra byte because SCI_GETCURLINE writes a null to the string
319 char* buf = text.GetWriteBuf(len+1);
320
321 int pos = SendMsg(2027, len+1, (long)buf);
322 text.UngetWriteBuf(len);
323 if (linePos) *linePos = pos;
324
325 return text;
326 }
327
328 // Retrieve the position of the last correctly styled character.
329 int wxStyledTextCtrl::GetEndStyled() {
330 return SendMsg(2028, 0, 0);
331 }
332
333 // Convert all line endings in the document to one mode.
334 void wxStyledTextCtrl::ConvertEOLs(int eolMode) {
335 SendMsg(2029, eolMode, 0);
336 }
337
338 // Retrieve the current end of line mode - one of CRLF, CR, or LF.
339 int wxStyledTextCtrl::GetEOLMode() {
340 return SendMsg(2030, 0, 0);
341 }
342
343 // Set the current end of line mode.
344 void wxStyledTextCtrl::SetEOLMode(int eolMode) {
345 SendMsg(2031, eolMode, 0);
346 }
347
348 // Set the current styling position to pos and the styling mask to mask.
349 // The styling mask can be used to protect some bits in each styling byte from
350 // modification.
351 void wxStyledTextCtrl::StartStyling(int pos, int mask) {
352 SendMsg(2032, pos, mask);
353 }
354
355 // Change style from current styling position for length characters to a style
356 // and move the current styling position to after this newly styled segment.
357 void wxStyledTextCtrl::SetStyling(int length, int style) {
358 SendMsg(2033, length, style);
359 }
360
361 // Is drawing done first into a buffer or direct to the screen.
362 bool wxStyledTextCtrl::GetBufferedDraw() {
363 return SendMsg(2034, 0, 0) != 0;
364 }
365
366 // If drawing is buffered then each line of text is drawn into a bitmap buffer
367 // before drawing it to the screen to avoid flicker.
368 void wxStyledTextCtrl::SetBufferedDraw(bool buffered) {
369 SendMsg(2035, buffered, 0);
370 }
371
372 // Change the visible size of a tab to be a multiple of the width of a space
373 // character.
374 void wxStyledTextCtrl::SetTabWidth(int tabWidth) {
375 SendMsg(2036, tabWidth, 0);
376 }
377
378 // Retrieve the visible size of a tab.
379 int wxStyledTextCtrl::GetTabWidth() {
380 return SendMsg(2121, 0, 0);
381 }
382
383 // Set the code page used to interpret the bytes of the document as characters.
384 // The SC_CP_UTF8 value can be used to enter Unicode mode.
385 void wxStyledTextCtrl::SetCodePage(int codePage) {
386 SendMsg(2037, codePage, 0);
387 }
388
389 // Set the symbol used for a particular marker number,
390 // and optionally the fore and background colours.
391 void wxStyledTextCtrl::MarkerDefine(int markerNumber, int markerSymbol,
392 const wxColour& foreground,
393 const wxColour& background) {
394
395 SendMsg(2040, markerNumber, markerSymbol);
396 if (foreground.Ok())
397 MarkerSetForeground(markerNumber, foreground);
398 if (background.Ok())
399 MarkerSetBackground(markerNumber, background);
400 }
401
402 // Set the foreground colour used for a particular marker number.
403 void wxStyledTextCtrl::MarkerSetForeground(int markerNumber, const wxColour& fore) {
404 SendMsg(2041, markerNumber, wxColourAsLong(fore));
405 }
406
407 // Set the background colour used for a particular marker number.
408 void wxStyledTextCtrl::MarkerSetBackground(int markerNumber, const wxColour& back) {
409 SendMsg(2042, markerNumber, wxColourAsLong(back));
410 }
411
412 // Add a marker to a line, returning an ID which can be used to find or delete the marker.
413 int wxStyledTextCtrl::MarkerAdd(int line, int markerNumber) {
414 return SendMsg(2043, line, markerNumber);
415 }
416
417 // Delete a marker from a line
418 void wxStyledTextCtrl::MarkerDelete(int line, int markerNumber) {
419 SendMsg(2044, line, markerNumber);
420 }
421
422 // Delete all markers with a particular number from all lines
423 void wxStyledTextCtrl::MarkerDeleteAll(int markerNumber) {
424 SendMsg(2045, markerNumber, 0);
425 }
426
427 // Get a bit mask of all the markers set on a line.
428 int wxStyledTextCtrl::MarkerGet(int line) {
429 return SendMsg(2046, line, 0);
430 }
431
432 // Find the next line after lineStart that includes a marker in mask.
433 int wxStyledTextCtrl::MarkerNext(int lineStart, int markerMask) {
434 return SendMsg(2047, lineStart, markerMask);
435 }
436
437 // Find the previous line before lineStart that includes a marker in mask.
438 int wxStyledTextCtrl::MarkerPrevious(int lineStart, int markerMask) {
439 return SendMsg(2048, lineStart, markerMask);
440 }
441
442 // Set a margin to be either numeric or symbolic.
443 void wxStyledTextCtrl::SetMarginType(int margin, int marginType) {
444 SendMsg(2240, margin, marginType);
445 }
446
447 // Retrieve the type of a margin.
448 int wxStyledTextCtrl::GetMarginType(int margin) {
449 return SendMsg(2241, margin, 0);
450 }
451
452 // Set the width of a margin to a width expressed in pixels.
453 void wxStyledTextCtrl::SetMarginWidth(int margin, int pixelWidth) {
454 SendMsg(2242, margin, pixelWidth);
455 }
456
457 // Retrieve the width of a margin in pixels.
458 int wxStyledTextCtrl::GetMarginWidth(int margin) {
459 return SendMsg(2243, margin, 0);
460 }
461
462 // Set a mask that determines which markers are displayed in a margin.
463 void wxStyledTextCtrl::SetMarginMask(int margin, int mask) {
464 SendMsg(2244, margin, mask);
465 }
466
467 // Retrieve the marker mask of a margin.
468 int wxStyledTextCtrl::GetMarginMask(int margin) {
469 return SendMsg(2245, margin, 0);
470 }
471
472 // Make a margin sensitive or insensitive to mouse clicks.
473 void wxStyledTextCtrl::SetMarginSensitive(int margin, bool sensitive) {
474 SendMsg(2246, margin, sensitive);
475 }
476
477 // Retrieve the mouse click sensitivity of a margin.
478 bool wxStyledTextCtrl::GetMarginSensitive(int margin) {
479 return SendMsg(2247, margin, 0) != 0;
480 }
481
482 // Clear all the styles and make equivalent to the global default style.
483 void wxStyledTextCtrl::StyleClearAll() {
484 SendMsg(2050, 0, 0);
485 }
486
487 // Set the foreground colour of a style.
488 void wxStyledTextCtrl::StyleSetForeground(int style, const wxColour& fore) {
489 SendMsg(2051, style, wxColourAsLong(fore));
490 }
491
492 // Set the background colour of a style.
493 void wxStyledTextCtrl::StyleSetBackground(int style, const wxColour& back) {
494 SendMsg(2052, style, wxColourAsLong(back));
495 }
496
497 // Set a style to be bold or not.
498 void wxStyledTextCtrl::StyleSetBold(int style, bool bold) {
499 SendMsg(2053, style, bold);
500 }
501
502 // Set a style to be italic or not.
503 void wxStyledTextCtrl::StyleSetItalic(int style, bool italic) {
504 SendMsg(2054, style, italic);
505 }
506
507 // Set the size of characters of a style.
508 void wxStyledTextCtrl::StyleSetSize(int style, int sizePoints) {
509 SendMsg(2055, style, sizePoints);
510 }
511
512 // Set the font of a style.
513 void wxStyledTextCtrl::StyleSetFaceName(int style, const wxString& fontName) {
514 SendMsg(2056, style, (long)fontName.c_str());
515 }
516
517 // Set a style to have its end of line filled or not.
518 void wxStyledTextCtrl::StyleSetEOLFilled(int style, bool filled) {
519 SendMsg(2057, style, filled);
520 }
521
522 // Reset the default style to its state at startup
523 void wxStyledTextCtrl::StyleResetDefault() {
524 SendMsg(2058, 0, 0);
525 }
526
527 // Set a style to be underlined or not.
528 void wxStyledTextCtrl::StyleSetUnderline(int style, bool underline) {
529 SendMsg(2059, style, underline);
530 }
531
532 // Set a style to be mixed case, or to force upper or lower case.
533 void wxStyledTextCtrl::StyleSetCase(int style, int caseForce) {
534 SendMsg(2060, style, caseForce);
535 }
536
537 // Set the foreground colour of the selection and whether to use this setting.
538 void wxStyledTextCtrl::SetSelForeground(bool useSetting, const wxColour& fore) {
539 SendMsg(2067, useSetting, wxColourAsLong(fore));
540 }
541
542 // Set the background colour of the selection and whether to use this setting.
543 void wxStyledTextCtrl::SetSelBackground(bool useSetting, const wxColour& back) {
544 SendMsg(2068, useSetting, wxColourAsLong(back));
545 }
546
547 // Set the foreground colour of the caret.
548 void wxStyledTextCtrl::SetCaretForeground(const wxColour& fore) {
549 SendMsg(2069, wxColourAsLong(fore), 0);
550 }
551
552 // When key+modifier combination km is pressed perform msg.
553 void wxStyledTextCtrl::CmdKeyAssign(int key, int modifiers, int cmd) {
554 SendMsg(2070, MAKELONG(key, modifiers), cmd);
555 }
556
557 // When key+modifier combination km do nothing.
558 void wxStyledTextCtrl::CmdKeyClear(int key, int modifiers) {
559 SendMsg(2071, MAKELONG(key, modifiers));
560 }
561
562 // Drop all key mappings.
563 void wxStyledTextCtrl::CmdKeyClearAll() {
564 SendMsg(2072, 0, 0);
565 }
566
567 // Set the styles for a segment of the document.
568 void wxStyledTextCtrl::SetStyleBytes(int length, char* styleBytes) {
569 SendMsg(2073, length, (long)styleBytes);
570 }
571
572 // Set a style to be visible or not.
573 void wxStyledTextCtrl::StyleSetVisible(int style, bool visible) {
574 SendMsg(2074, style, visible);
575 }
576
577 // Get the time in milliseconds that the caret is on and off.
578 int wxStyledTextCtrl::GetCaretPeriod() {
579 return SendMsg(2075, 0, 0);
580 }
581
582 // Get the time in milliseconds that the caret is on and off. 0 = steady on.
583 void wxStyledTextCtrl::SetCaretPeriod(int periodMilliseconds) {
584 SendMsg(2076, periodMilliseconds, 0);
585 }
586
587 // Set the set of characters making up words for when moving or selecting
588 // by word.
589 void wxStyledTextCtrl::SetWordChars(const wxString& characters) {
590 SendMsg(2077, 0, (long)characters.c_str());
591 }
592
593 // Start a sequence of actions that is undone and redone as a unit.
594 // May be nested.
595 void wxStyledTextCtrl::BeginUndoAction() {
596 SendMsg(2078, 0, 0);
597 }
598
599 // End a sequence of actions that is undone and redone as a unit.
600 void wxStyledTextCtrl::EndUndoAction() {
601 SendMsg(2079, 0, 0);
602 }
603
604 // Set an indicator to plain, squiggle or TT.
605 void wxStyledTextCtrl::IndicatorSetStyle(int indic, int style) {
606 SendMsg(2080, indic, style);
607 }
608
609 // Retrieve the style of an indicator.
610 int wxStyledTextCtrl::IndicatorGetStyle(int indic) {
611 return SendMsg(2081, indic, 0);
612 }
613
614 // Set the foreground colour of an indicator.
615 void wxStyledTextCtrl::IndicatorSetForeground(int indic, const wxColour& fore) {
616 SendMsg(2082, indic, wxColourAsLong(fore));
617 }
618
619 // Retrieve the foreground colour of an indicator.
620 wxColour wxStyledTextCtrl::IndicatorGetForeground(int indic) {
621 long c = SendMsg(2083, indic, 0);
622 return wxColourFromLong(c);
623 }
624
625 // Divide each styling byte into lexical class bits (default:5) and indicator
626 // bits (default:3). If a lexer requires more than 32 lexical states, then this
627 // is used to expand the possible states.
628 void wxStyledTextCtrl::SetStyleBits(int bits) {
629 SendMsg(2090, bits, 0);
630 }
631
632 // Retrieve number of bits in style bytes used to hold the lexical state.
633 int wxStyledTextCtrl::GetStyleBits() {
634 return SendMsg(2091, 0, 0);
635 }
636
637 // Used to hold extra styling information for each line.
638 void wxStyledTextCtrl::SetLineState(int line, int state) {
639 SendMsg(2092, line, state);
640 }
641
642 // Retrieve the extra styling information for a line.
643 int wxStyledTextCtrl::GetLineState(int line) {
644 return SendMsg(2093, line, 0);
645 }
646
647 // Retrieve the last line number that has line state.
648 int wxStyledTextCtrl::GetMaxLineState() {
649 return SendMsg(2094, 0, 0);
650 }
651
652 // Is the background of the line containing the caret in a different colour?
653 bool wxStyledTextCtrl::GetCaretLineVisible() {
654 return SendMsg(2095, 0, 0) != 0;
655 }
656
657 // Dsplay the background of the line containing the caret in a different colour.
658 void wxStyledTextCtrl::SetCaretLineVisible(bool show) {
659 SendMsg(2096, show, 0);
660 }
661
662 // Get the colour of the background of the line containing the caret.
663 wxColour wxStyledTextCtrl::GetCaretLineBack() {
664 long c = SendMsg(2097, 0, 0);
665 return wxColourFromLong(c);
666 }
667
668 // Set the colour of the background of the line containing the caret.
669 void wxStyledTextCtrl::SetCaretLineBack(const wxColour& back) {
670 SendMsg(2098, wxColourAsLong(back), 0);
671 }
672
673 // Set a style to be changeable or not (read only).
674 // Experimental feature, currently buggy.
675 void wxStyledTextCtrl::StyleSetChangeable(int style, bool changeable) {
676 SendMsg(2099, style, changeable);
677 }
678
679 // Display a auto-completion list.
680 // The lenEntered parameter indicates how many characters before
681 // the caret should be used to provide context.
682 void wxStyledTextCtrl::AutoCompShow(int lenEntered, const wxString& itemList) {
683 SendMsg(2100, lenEntered, (long)itemList.c_str());
684 }
685
686 // Remove the auto-completion list from the screen.
687 void wxStyledTextCtrl::AutoCompCancel() {
688 SendMsg(2101, 0, 0);
689 }
690
691 // Is there an auto-completion list visible?
692 bool wxStyledTextCtrl::AutoCompActive() {
693 return SendMsg(2102, 0, 0) != 0;
694 }
695
696 // Retrieve the position of the caret when the auto-completion list was
697 // displayed.
698 int wxStyledTextCtrl::AutoCompPosStart() {
699 return SendMsg(2103, 0, 0);
700 }
701
702 // User has selected an item so remove the list and insert the selection.
703 void wxStyledTextCtrl::AutoCompComplete() {
704 SendMsg(2104, 0, 0);
705 }
706
707 // Define a set of character that when typed cancel the auto-completion list.
708 void wxStyledTextCtrl::AutoCompStops(const wxString& characterSet) {
709 SendMsg(2105, 0, (long)characterSet.c_str());
710 }
711
712 // Change the separator character in the string setting up an auto-completion
713 // list. Default is space but can be changed if items contain space.
714 void wxStyledTextCtrl::AutoCompSetSeparator(int separatorCharacter) {
715 SendMsg(2106, separatorCharacter, 0);
716 }
717
718 // Retrieve the auto-completion list separator character.
719 int wxStyledTextCtrl::AutoCompGetSeparator() {
720 return SendMsg(2107, 0, 0);
721 }
722
723 // Select the item in the auto-completion list that starts with a string.
724 void wxStyledTextCtrl::AutoCompSelect(const wxString& text) {
725 SendMsg(2108, 0, (long)text.c_str());
726 }
727
728 // Should the auto-completion list be cancelled if the user backspaces to a
729 // position before where the box was created.
730 void wxStyledTextCtrl::AutoCompSetCancelAtStart(bool cancel) {
731 SendMsg(2110, cancel, 0);
732 }
733
734 // Retrieve whether auto-completion cancelled by backspacing before start.
735 bool wxStyledTextCtrl::AutoCompGetCancelAtStart() {
736 return SendMsg(2111, 0, 0) != 0;
737 }
738
739 // Define a set of characters that when typed will cause the autocompletion to
740 // choose the selected item.
741 void wxStyledTextCtrl::AutoCompSetFillUps(const wxString& characterSet) {
742 SendMsg(2112, 0, (long)characterSet.c_str());
743 }
744
745 // Should a single item auto-completion list automatically choose the item.
746 void wxStyledTextCtrl::AutoCompSetChooseSingle(bool chooseSingle) {
747 SendMsg(2113, chooseSingle, 0);
748 }
749
750 // Retrieve whether a single item auto-completion list automatically choose the item.
751 bool wxStyledTextCtrl::AutoCompGetChooseSingle() {
752 return SendMsg(2114, 0, 0) != 0;
753 }
754
755 // Set whether case is significant when performing auto-completion searches.
756 void wxStyledTextCtrl::AutoCompSetIgnoreCase(bool ignoreCase) {
757 SendMsg(2115, ignoreCase, 0);
758 }
759
760 // Retrieve state of ignore case flag.
761 bool wxStyledTextCtrl::AutoCompGetIgnoreCase() {
762 return SendMsg(2116, 0, 0) != 0;
763 }
764
765 // Display a list of strings and send notification when user chooses one.
766 void wxStyledTextCtrl::UserListShow(int listType, const wxString& itemList) {
767 SendMsg(2117, listType, (long)itemList.c_str());
768 }
769
770 // Set whether or not autocompletion is hidden automatically when nothing matches
771 void wxStyledTextCtrl::AutoCompSetAutoHide(bool autoHide) {
772 SendMsg(2118, autoHide, 0);
773 }
774
775 // Retrieve whether or not autocompletion is hidden automatically when nothing matches
776 bool wxStyledTextCtrl::AutoCompGetAutoHide() {
777 return SendMsg(2119, 0, 0) != 0;
778 }
779
780 // Set whether or not autocompletion deletes any word characters after the inserted text upon completion
781 void wxStyledTextCtrl::AutoCompSetDropRestOfWord(bool dropRestOfWord) {
782 SendMsg(2270, dropRestOfWord, 0);
783 }
784
785 // Retrieve whether or not autocompletion deletes any word characters after the inserted text upon completion
786 bool wxStyledTextCtrl::AutoCompGetDropRestOfWord() {
787 return SendMsg(2271, 0, 0) != 0;
788 }
789
790 // Set the number of spaces used for one level of indentation.
791 void wxStyledTextCtrl::SetIndent(int indentSize) {
792 SendMsg(2122, indentSize, 0);
793 }
794
795 // Retrieve indentation size.
796 int wxStyledTextCtrl::GetIndent() {
797 return SendMsg(2123, 0, 0);
798 }
799
800 // Indentation will only use space characters if useTabs is false, otherwise
801 // it will use a combination of tabs and spaces.
802 void wxStyledTextCtrl::SetUseTabs(bool useTabs) {
803 SendMsg(2124, useTabs, 0);
804 }
805
806 // Retrieve whether tabs will be used in indentation.
807 bool wxStyledTextCtrl::GetUseTabs() {
808 return SendMsg(2125, 0, 0) != 0;
809 }
810
811 // Change the indentation of a line to a number of columns.
812 void wxStyledTextCtrl::SetLineIndentation(int line, int indentSize) {
813 SendMsg(2126, line, indentSize);
814 }
815
816 // Retrieve the number of columns that a line is indented.
817 int wxStyledTextCtrl::GetLineIndentation(int line) {
818 return SendMsg(2127, line, 0);
819 }
820
821 // Retrieve the position before the first non indentation character on a line.
822 int wxStyledTextCtrl::GetLineIndentPosition(int line) {
823 return SendMsg(2128, line, 0);
824 }
825
826 // Retrieve the column number of a position, taking tab width into account.
827 int wxStyledTextCtrl::GetColumn(int pos) {
828 return SendMsg(2129, pos, 0);
829 }
830
831 // Show or hide the horizontal scroll bar.
832 void wxStyledTextCtrl::SetUseHorizontalScrollBar(bool show) {
833 SendMsg(2130, show, 0);
834 }
835
836 // Is the horizontal scroll bar visible?
837 bool wxStyledTextCtrl::GetUseHorizontalScrollBar() {
838 return SendMsg(2131, 0, 0) != 0;
839 }
840
841 // Show or hide indentation guides.
842 void wxStyledTextCtrl::SetIndentationGuides(bool show) {
843 SendMsg(2132, show, 0);
844 }
845
846 // Are the indentation guides visible?
847 bool wxStyledTextCtrl::GetIndentationGuides() {
848 return SendMsg(2133, 0, 0) != 0;
849 }
850
851 // Set the highlighted indentation guide column.
852 // 0 = no highlighted guide.
853 void wxStyledTextCtrl::SetHighlightGuide(int column) {
854 SendMsg(2134, column, 0);
855 }
856
857 // Get the highlighted indentation guide column.
858 int wxStyledTextCtrl::GetHighlightGuide() {
859 return SendMsg(2135, 0, 0);
860 }
861
862 // Get the position after the last visible characters on a line.
863 int wxStyledTextCtrl::GetLineEndPosition(int line) {
864 return SendMsg(2136, line, 0);
865 }
866
867 // Get the code page used to interpret the bytes of the document as characters.
868 int wxStyledTextCtrl::GetCodePage() {
869 return SendMsg(2137, 0, 0);
870 }
871
872 // Get the foreground colour of the caret.
873 wxColour wxStyledTextCtrl::GetCaretForeground() {
874 long c = SendMsg(2138, 0, 0);
875 return wxColourFromLong(c);
876 }
877
878 // In read-only mode?
879 bool wxStyledTextCtrl::GetReadOnly() {
880 return SendMsg(2140, 0, 0) != 0;
881 }
882
883 // Sets the position of the caret.
884 void wxStyledTextCtrl::SetCurrentPos(int pos) {
885 SendMsg(2141, pos, 0);
886 }
887
888 // Sets the position that starts the selection - this becomes the anchor.
889 void wxStyledTextCtrl::SetSelectionStart(int pos) {
890 SendMsg(2142, pos, 0);
891 }
892
893 // Returns the position at the start of the selection.
894 int wxStyledTextCtrl::GetSelectionStart() {
895 return SendMsg(2143, 0, 0);
896 }
897
898 // Sets the position that ends the selection - this becomes the currentPosition.
899 void wxStyledTextCtrl::SetSelectionEnd(int pos) {
900 SendMsg(2144, pos, 0);
901 }
902
903 // Returns the position at the end of the selection.
904 int wxStyledTextCtrl::GetSelectionEnd() {
905 return SendMsg(2145, 0, 0);
906 }
907
908 // Sets the print magnification added to the point size of each style for printing.
909 void wxStyledTextCtrl::SetPrintMagnification(int magnification) {
910 SendMsg(2146, magnification, 0);
911 }
912
913 // Returns the print magnification.
914 int wxStyledTextCtrl::GetPrintMagnification() {
915 return SendMsg(2147, 0, 0);
916 }
917
918 // Modify colours when printing for clearer printed text.
919 void wxStyledTextCtrl::SetPrintColourMode(int mode) {
920 SendMsg(2148, mode, 0);
921 }
922
923 // Returns the print colour mode.
924 int wxStyledTextCtrl::GetPrintColourMode() {
925 return SendMsg(2149, 0, 0);
926 }
927
928 // Find some text in the document.
929 int wxStyledTextCtrl::FindText(int minPos, int maxPos,
930 const wxString& text,
931 bool caseSensitive, bool wholeWord) {
932 TextToFind ft;
933 int flags = 0;
934
935 flags |= caseSensitive ? SCFIND_MATCHCASE : 0;
936 flags |= wholeWord ? SCFIND_WHOLEWORD : 0;
937 ft.chrg.cpMin = minPos;
938 ft.chrg.cpMax = maxPos;
939 ft.lpstrText = (char*)text.c_str();
940
941 return SendMsg(2150, flags, (long)&ft);
942 }
943
944 // On Windows will draw the document into a display context such as a printer.
945 int wxStyledTextCtrl::FormatRange(bool doDraw,
946 int startPos,
947 int endPos,
948 wxDC* draw,
949 wxDC* target, // Why does it use two? Can they be the same?
950 wxRect renderRect,
951 wxRect pageRect) {
952 RangeToFormat fr;
953
954 if (endPos < startPos) {
955 int temp = startPos;
956 startPos = endPos;
957 endPos = temp;
958 }
959 fr.hdc = draw;
960 fr.hdcTarget = target;
961 fr.rc.top = renderRect.GetTop();
962 fr.rc.left = renderRect.GetLeft();
963 fr.rc.right = renderRect.GetRight();
964 fr.rc.bottom = renderRect.GetBottom();
965 fr.rcPage.top = pageRect.GetTop();
966 fr.rcPage.left = pageRect.GetLeft();
967 fr.rcPage.right = pageRect.GetRight();
968 fr.rcPage.bottom = pageRect.GetBottom();
969 fr.chrg.cpMin = startPos;
970 fr.chrg.cpMax = endPos;
971
972 return SendMsg(2151, doDraw, (long)&fr);
973 }
974
975 // Retrieve the line at the top of the display.
976 int wxStyledTextCtrl::GetFirstVisibleLine() {
977 return SendMsg(2152, 0, 0);
978 }
979
980 // Retrieve the contents of a line.
981 wxString wxStyledTextCtrl::GetLine(int line) {
982 wxString text;
983 int len = LineLength(line);
984 if (!len) return "";
985 char* buf = text.GetWriteBuf(len);
986
987 int pos = SendMsg(2153, line, (long)buf);
988 text.UngetWriteBuf(len);
989
990 return text;
991 }
992
993 // Returns the number of lines in the document. There is always at least one.
994 int wxStyledTextCtrl::GetLineCount() {
995 return SendMsg(2154, 0, 0);
996 }
997
998 // Sets the size in pixels of the left margin.
999 void wxStyledTextCtrl::SetMarginLeft(int pixelWidth) {
1000 SendMsg(2155, 0, pixelWidth);
1001 }
1002
1003 // Returns the size in pixels of the left margin.
1004 int wxStyledTextCtrl::GetMarginLeft() {
1005 return SendMsg(2156, 0, 0);
1006 }
1007
1008 // Sets the size in pixels of the right margin.
1009 void wxStyledTextCtrl::SetMarginRight(int pixelWidth) {
1010 SendMsg(2157, 0, pixelWidth);
1011 }
1012
1013 // Returns the size in pixels of the right margin.
1014 int wxStyledTextCtrl::GetMarginRight() {
1015 return SendMsg(2158, 0, 0);
1016 }
1017
1018 // Is the document different from when it was last saved?
1019 bool wxStyledTextCtrl::GetModify() {
1020 return SendMsg(2159, 0, 0) != 0;
1021 }
1022
1023 // Select a range of text.
1024 void wxStyledTextCtrl::SetSelection(int start, int end) {
1025 SendMsg(2160, start, end);
1026 }
1027
1028 // Retrieve the selected text.
1029 wxString wxStyledTextCtrl::GetSelectedText() {
1030 wxString text;
1031 int start;
1032 int end;
1033
1034 GetSelection(&start, &end);
1035 int len = end - start;
1036 if (!len) return "";
1037 char* buff = text.GetWriteBuf(len);
1038
1039 SendMsg(2161, 0, (long)buff);
1040 text.UngetWriteBuf(len);
1041 return text;
1042 }
1043
1044 // Retrieve a range of text.
1045 wxString wxStyledTextCtrl::GetTextRange(int startPos, int endPos) {
1046 wxString text;
1047 if (endPos < startPos) {
1048 int temp = startPos;
1049 startPos = endPos;
1050 endPos = temp;
1051 }
1052 int len = endPos - startPos;
1053 if (!len) return "";
1054 char* buff = text.GetWriteBuf(len);
1055 TextRange tr;
1056 tr.lpstrText = buff;
1057 tr.chrg.cpMin = startPos;
1058 tr.chrg.cpMax = endPos;
1059
1060 SendMsg(2162, 0, (long)&tr);
1061 text.UngetWriteBuf(len);
1062 return text;
1063 }
1064
1065 // Draw the selection in normal style or with selection highlighted.
1066 void wxStyledTextCtrl::HideSelection(bool normal) {
1067 SendMsg(2163, normal, 0);
1068 }
1069
1070 // Retrieve the line containing a position.
1071 int wxStyledTextCtrl::LineFromPosition(int pos) {
1072 return SendMsg(2166, pos, 0);
1073 }
1074
1075 // Retrieve the position at the start of a line.
1076 int wxStyledTextCtrl::PositionFromLine(int line) {
1077 return SendMsg(2167, line, 0);
1078 }
1079
1080 // Scroll horizontally and vertically.
1081 void wxStyledTextCtrl::LineScroll(int columns, int lines) {
1082 SendMsg(2168, columns, lines);
1083 }
1084
1085 // Ensure the caret is visible.
1086 void wxStyledTextCtrl::EnsureCaretVisible() {
1087 SendMsg(2169, 0, 0);
1088 }
1089
1090 // Replace the selected text with the argument text.
1091 void wxStyledTextCtrl::ReplaceSelection(const wxString& text) {
1092 SendMsg(2170, 0, (long)text.c_str());
1093 }
1094
1095 // Set to read only or read write.
1096 void wxStyledTextCtrl::SetReadOnly(bool readOnly) {
1097 SendMsg(2171, readOnly, 0);
1098 }
1099
1100 // Will a paste succeed?
1101 bool wxStyledTextCtrl::CanPaste() {
1102 return SendMsg(2173, 0, 0) != 0;
1103 }
1104
1105 // Are there any undoable actions in the undo history.
1106 bool wxStyledTextCtrl::CanUndo() {
1107 return SendMsg(2174, 0, 0) != 0;
1108 }
1109
1110 // Delete the undo history.
1111 void wxStyledTextCtrl::EmptyUndoBuffer() {
1112 SendMsg(2175, 0, 0);
1113 }
1114
1115 // Undo one action in the undo history.
1116 void wxStyledTextCtrl::Undo() {
1117 SendMsg(2176, 0, 0);
1118 }
1119
1120 // Cut the selection to the clipboard.
1121 void wxStyledTextCtrl::Cut() {
1122 SendMsg(2177, 0, 0);
1123 }
1124
1125 // Copy the selection to the clipboard.
1126 void wxStyledTextCtrl::Copy() {
1127 SendMsg(2178, 0, 0);
1128 }
1129
1130 // Paste the contents of the clipboard into the document replacing the selection.
1131 void wxStyledTextCtrl::Paste() {
1132 SendMsg(2179, 0, 0);
1133 }
1134
1135 // Clear the selection.
1136 void wxStyledTextCtrl::Clear() {
1137 SendMsg(2180, 0, 0);
1138 }
1139
1140 // Replace the contents of the document with the argument text.
1141 void wxStyledTextCtrl::SetText(const wxString& text) {
1142 SendMsg(2181, 0, (long)text.c_str());
1143 }
1144
1145 // Retrieve all the text in the document.
1146 wxString wxStyledTextCtrl::GetText() {
1147 wxString text;
1148 int len = GetTextLength();
1149 char* buff = text.GetWriteBuf(len+1); // leave room for the null...
1150
1151 SendMsg(2182, len+1, (long)buff);
1152 text.UngetWriteBuf(len);
1153 return text;
1154 }
1155
1156 // Retrieve the number of characters in the document.
1157 int wxStyledTextCtrl::GetTextLength() {
1158 return SendMsg(2183, 0, 0);
1159 }
1160
1161 // Set to overtype (true) or insert mode
1162 void wxStyledTextCtrl::SetOvertype(bool overtype) {
1163 SendMsg(2186, overtype, 0);
1164 }
1165
1166 // Returns true if overtype mode is active otherwise false is returned.
1167 bool wxStyledTextCtrl::GetOvertype() {
1168 return SendMsg(2187, 0, 0) != 0;
1169 }
1170
1171 // Set the width of the insert mode caret
1172 void wxStyledTextCtrl::SetCaretWidth(int pixelWidth) {
1173 SendMsg(2188, pixelWidth, 0);
1174 }
1175
1176 // Returns the width of the insert mode caret
1177 int wxStyledTextCtrl::GetCaretWidth() {
1178 return SendMsg(2189, 0, 0);
1179 }
1180
1181 // Sets the position that starts the target which is used for updating the
1182 // document without affecting the scroll position.
1183 void wxStyledTextCtrl::SetTargetStart(int pos) {
1184 SendMsg(2190, pos, 0);
1185 }
1186
1187 // Get the position that starts the target.
1188 int wxStyledTextCtrl::GetTargetStart() {
1189 return SendMsg(2191, 0, 0);
1190 }
1191
1192 // Sets the position that ends the target which is used for updating the
1193 // document without affecting the scroll position.
1194 void wxStyledTextCtrl::SetTargetEnd(int pos) {
1195 SendMsg(2192, pos, 0);
1196 }
1197
1198 // Get the position that ends the target.
1199 int wxStyledTextCtrl::GetTargetEnd() {
1200 return SendMsg(2193, 0, 0);
1201 }
1202
1203 // Replace the target text with the argument text.
1204 // Text is counted so it can contain nulls.
1205 // Returns the length of the replacement text.
1206
1207 int wxStyledTextCtrl::ReplaceTarget(const wxString& text) {
1208 return SendMsg(2194, text.Len(), (long)text.c_str());
1209
1210 }
1211
1212 // Replace the target text with the argument text after \d processing.
1213 // Text is counted so it can contain nulls.
1214 // Looks for \d where d is between 1 and 9 and replaces these with the strings
1215 // matched in the last search operation which were surrounded by \( and \).
1216 // Returns the length of the replacement text including any change
1217 // caused by processing the \d patterns.
1218
1219 int wxStyledTextCtrl::ReplaceTargetRE(const wxString& text) {
1220 return SendMsg(2195, text.Len(), (long)text.c_str());
1221
1222 }
1223
1224 // Search for a counted string in the target and set the target to the found
1225 // range. Text is counted so it can contain nulls.
1226 // Returns length of range or -1 for failure in which case target is not moved.
1227
1228 int wxStyledTextCtrl::SearchInTarget(const wxString& text) {
1229 return SendMsg(2197, text.Len(), (long)text.c_str());
1230
1231 }
1232
1233 // Set the search flags used by SearchInTarget
1234 void wxStyledTextCtrl::SetSearchFlags(int flags) {
1235 SendMsg(2198, flags, 0);
1236 }
1237
1238 // Get the search flags used by SearchInTarget
1239 int wxStyledTextCtrl::GetSearchFlags() {
1240 return SendMsg(2199, 0, 0);
1241 }
1242
1243 // Show a call tip containing a definition near position pos.
1244 void wxStyledTextCtrl::CallTipShow(int pos, const wxString& definition) {
1245 SendMsg(2200, pos, (long)definition.c_str());
1246 }
1247
1248 // Remove the call tip from the screen.
1249 void wxStyledTextCtrl::CallTipCancel() {
1250 SendMsg(2201, 0, 0);
1251 }
1252
1253 // Is there an active call tip?
1254 bool wxStyledTextCtrl::CallTipActive() {
1255 return SendMsg(2202, 0, 0) != 0;
1256 }
1257
1258 // Retrieve the position where the caret was before displaying the call tip.
1259 int wxStyledTextCtrl::CallTipPosAtStart() {
1260 return SendMsg(2203, 0, 0);
1261 }
1262
1263 // Highlight a segment of the definition.
1264 void wxStyledTextCtrl::CallTipSetHighlight(int start, int end) {
1265 SendMsg(2204, start, end);
1266 }
1267
1268 // Set the background colour for the call tip.
1269 void wxStyledTextCtrl::CallTipSetBackground(const wxColour& back) {
1270 SendMsg(2205, wxColourAsLong(back), 0);
1271 }
1272
1273 // Find the display line of a document line taking hidden lines into account.
1274 int wxStyledTextCtrl::VisibleFromDocLine(int line) {
1275 return SendMsg(2220, line, 0);
1276 }
1277
1278 // Find the document line of a display line taking hidden lines into account.
1279 int wxStyledTextCtrl::DocLineFromVisible(int lineDisplay) {
1280 return SendMsg(2221, lineDisplay, 0);
1281 }
1282
1283 // Set the fold level of a line.
1284 // This encodes an integer level along with flags indicating whether the
1285 // line is a header and whether it is effectively white space.
1286 void wxStyledTextCtrl::SetFoldLevel(int line, int level) {
1287 SendMsg(2222, line, level);
1288 }
1289
1290 // Retrieve the fold level of a line.
1291 int wxStyledTextCtrl::GetFoldLevel(int line) {
1292 return SendMsg(2223, line, 0);
1293 }
1294
1295 // Find the last child line of a header line.
1296 int wxStyledTextCtrl::GetLastChild(int line, int level) {
1297 return SendMsg(2224, line, level);
1298 }
1299
1300 // Find the parent line of a child line.
1301 int wxStyledTextCtrl::GetFoldParent(int line) {
1302 return SendMsg(2225, line, 0);
1303 }
1304
1305 // Make a range of lines visible.
1306 void wxStyledTextCtrl::ShowLines(int lineStart, int lineEnd) {
1307 SendMsg(2226, lineStart, lineEnd);
1308 }
1309
1310 // Make a range of lines invisible.
1311 void wxStyledTextCtrl::HideLines(int lineStart, int lineEnd) {
1312 SendMsg(2227, lineStart, lineEnd);
1313 }
1314
1315 // Is a line visible?
1316 bool wxStyledTextCtrl::GetLineVisible(int line) {
1317 return SendMsg(2228, line, 0) != 0;
1318 }
1319
1320 // Show the children of a header line.
1321 void wxStyledTextCtrl::SetFoldExpanded(int line, bool expanded) {
1322 SendMsg(2229, line, expanded);
1323 }
1324
1325 // Is a header line expanded?
1326 bool wxStyledTextCtrl::GetFoldExpanded(int line) {
1327 return SendMsg(2230, line, 0) != 0;
1328 }
1329
1330 // Switch a header line between expanded and contracted.
1331 void wxStyledTextCtrl::ToggleFold(int line) {
1332 SendMsg(2231, line, 0);
1333 }
1334
1335 // Ensure a particular line is visible by expanding any header line hiding it.
1336 void wxStyledTextCtrl::EnsureVisible(int line) {
1337 SendMsg(2232, line, 0);
1338 }
1339
1340 // Set some debugging options for folding
1341 void wxStyledTextCtrl::SetFoldFlags(int flags) {
1342 SendMsg(2233, flags, 0);
1343 }
1344
1345 // Ensure a particular line is visible by expanding any header line hiding it.
1346 // Use the currently set visibility policy to determine which range to display.
1347 void wxStyledTextCtrl::EnsureVisibleEnforcePolicy(int line) {
1348 SendMsg(2234, line, 0);
1349 }
1350
1351 // Sets whether a tab pressed when caret is within indentation indents
1352 void wxStyledTextCtrl::SetTabIndents(bool tabIndents) {
1353 SendMsg(2260, tabIndents, 0);
1354 }
1355
1356 // Does a tab pressed when caret is within indentation indent?
1357 bool wxStyledTextCtrl::GetTabIndents() {
1358 return SendMsg(2261, 0, 0) != 0;
1359 }
1360
1361 // Sets whether a backspace pressed when caret is within indentation unindents
1362 void wxStyledTextCtrl::SetBackSpaceUnIndents(bool bsUnIndents) {
1363 SendMsg(2262, bsUnIndents, 0);
1364 }
1365
1366 // Does a backspace pressed when caret is within indentation unindent?
1367 bool wxStyledTextCtrl::GetBackSpaceUnIndents() {
1368 return SendMsg(2263, 0, 0) != 0;
1369 }
1370
1371 // Sets the time the mouse must sit still to generate a mouse dwell event
1372 void wxStyledTextCtrl::SetMouseDwellTime(int periodMilliseconds) {
1373 SendMsg(2264, periodMilliseconds, 0);
1374 }
1375
1376 // Retrieve the time the mouse must sit still to generate a mouse dwell event
1377 int wxStyledTextCtrl::GetMouseDwellTime() {
1378 return SendMsg(2265, 0, 0);
1379 }
1380
1381 // Get position of start of word
1382 int wxStyledTextCtrl::WordStartPosition(int pos, bool onlyWordCharacters) {
1383 return SendMsg(2266, pos, onlyWordCharacters);
1384 }
1385
1386 // Get position of end of word
1387 int wxStyledTextCtrl::WordEndPosition(int pos, bool onlyWordCharacters) {
1388 return SendMsg(2267, pos, onlyWordCharacters);
1389 }
1390
1391 // Sets whether text is word wrapped
1392 void wxStyledTextCtrl::SetWrapMode(int mode) {
1393 SendMsg(2268, mode, 0);
1394 }
1395
1396 // Retrieve whether text is word wrapped
1397 int wxStyledTextCtrl::GetWrapMode() {
1398 return SendMsg(2269, 0, 0);
1399 }
1400
1401 // Sets the degree of caching of layout information
1402 void wxStyledTextCtrl::SetLayoutCache(int mode) {
1403 SendMsg(2272, mode, 0);
1404 }
1405
1406 // Retrieve the degree of caching of layout information
1407 int wxStyledTextCtrl::GetLayoutCache() {
1408 return SendMsg(2273, 0, 0);
1409 }
1410
1411 // Delete the selection or if no selection, the character before the caret.
1412 // Will not delete the chraacter before at the start of a line.
1413 void wxStyledTextCtrl::DeleteBackNotLine() {
1414 SendMsg(2344, 0, 0);
1415 }
1416
1417 // Move the caret inside current view if it's not there already
1418 void wxStyledTextCtrl::MoveCaretInsideView() {
1419 SendMsg(2401, 0, 0);
1420 }
1421
1422 // How many characters are on a line, not including end of line characters.
1423 int wxStyledTextCtrl::LineLength(int line) {
1424 return SendMsg(2350, line, 0);
1425 }
1426
1427 // Highlight the characters at two positions.
1428 void wxStyledTextCtrl::BraceHighlight(int pos1, int pos2) {
1429 SendMsg(2351, pos1, pos2);
1430 }
1431
1432 // Highlight the character at a position indicating there is no matching brace.
1433 void wxStyledTextCtrl::BraceBadLight(int pos) {
1434 SendMsg(2352, pos, 0);
1435 }
1436
1437 // Find the position of a matching brace or INVALID_POSITION if no match.
1438 int wxStyledTextCtrl::BraceMatch(int pos) {
1439 return SendMsg(2353, pos, 0);
1440 }
1441
1442 // Are the end of line characters visible.
1443 bool wxStyledTextCtrl::GetViewEOL() {
1444 return SendMsg(2355, 0, 0) != 0;
1445 }
1446
1447 // Make the end of line characters visible or invisible
1448 void wxStyledTextCtrl::SetViewEOL(bool visible) {
1449 SendMsg(2356, visible, 0);
1450 }
1451
1452 // Retrieve a pointer to the document object.
1453 void* wxStyledTextCtrl::GetDocPointer() {
1454 return (void*)SendMsg(2357);
1455 }
1456
1457 // Change the document object used.
1458 void wxStyledTextCtrl::SetDocPointer(void* docPointer) {
1459 SendMsg(2358, 0, (long)docPointer);
1460 }
1461
1462 // Set which document modification events are sent to the container.
1463 void wxStyledTextCtrl::SetModEventMask(int mask) {
1464 SendMsg(2359, mask, 0);
1465 }
1466
1467 // Retrieve the column number which text should be kept within.
1468 int wxStyledTextCtrl::GetEdgeColumn() {
1469 return SendMsg(2360, 0, 0);
1470 }
1471
1472 // Set the column number of the edge.
1473 // If text goes past the edge then it is highlighted.
1474 void wxStyledTextCtrl::SetEdgeColumn(int column) {
1475 SendMsg(2361, column, 0);
1476 }
1477
1478 // Retrieve the edge highlight mode.
1479 int wxStyledTextCtrl::GetEdgeMode() {
1480 return SendMsg(2362, 0, 0);
1481 }
1482
1483 // The edge may be displayed by a line (EDGE_LINE) or by highlighting text that
1484 // goes beyond it (EDGE_BACKGROUND) or not displayed at all (EDGE_NONE).
1485 void wxStyledTextCtrl::SetEdgeMode(int mode) {
1486 SendMsg(2363, mode, 0);
1487 }
1488
1489 // Retrieve the colour used in edge indication.
1490 wxColour wxStyledTextCtrl::GetEdgeColour() {
1491 long c = SendMsg(2364, 0, 0);
1492 return wxColourFromLong(c);
1493 }
1494
1495 // Change the colour used in edge indication.
1496 void wxStyledTextCtrl::SetEdgeColour(const wxColour& edgeColour) {
1497 SendMsg(2365, wxColourAsLong(edgeColour), 0);
1498 }
1499
1500 // Sets the current caret position to be the search anchor.
1501 void wxStyledTextCtrl::SearchAnchor() {
1502 SendMsg(2366, 0, 0);
1503 }
1504
1505 // Find some text starting at the search anchor.
1506 // Does not ensure the selection is visible.
1507 int wxStyledTextCtrl::SearchNext(int flags, const wxString& text) {
1508 return SendMsg(2367, flags, (long)text.c_str());
1509 }
1510
1511 // Find some text starting at the search anchor and moving backwards.
1512 // Does not ensure the selection is visible.
1513 int wxStyledTextCtrl::SearchPrev(int flags, const wxString& text) {
1514 return SendMsg(2368, flags, (long)text.c_str());
1515 }
1516
1517 // Set the way the line the caret is on is kept visible.
1518 void wxStyledTextCtrl::SetCaretPolicy(int caretPolicy, int caretSlop) {
1519 SendMsg(2369, caretPolicy, caretSlop);
1520 }
1521
1522 // Retrieves the number of lines completely visible.
1523 int wxStyledTextCtrl::LinesOnScreen() {
1524 return SendMsg(2370, 0, 0);
1525 }
1526
1527 // Set whether a pop up menu is displayed automatically when the user presses
1528 // the wrong mouse button.
1529 void wxStyledTextCtrl::UsePopUp(bool allowPopUp) {
1530 SendMsg(2371, allowPopUp, 0);
1531 }
1532
1533 // Is the selection a rectangular. The alternative is the more common stream selection.
1534 bool wxStyledTextCtrl::SelectionIsRectangle() {
1535 return SendMsg(2372, 0, 0) != 0;
1536 }
1537
1538 // Set the zoom level. This number of points is added to the size of all fonts.
1539 // It may be positive to magnify or negative to reduce.
1540 void wxStyledTextCtrl::SetZoom(int zoom) {
1541 SendMsg(2373, zoom, 0);
1542 }
1543
1544 // Retrieve the zoom level.
1545 int wxStyledTextCtrl::GetZoom() {
1546 return SendMsg(2374, 0, 0);
1547 }
1548
1549 // Create a new document object.
1550 // Starts with reference count of 1 and not selected into editor.
1551 void* wxStyledTextCtrl::CreateDocument() {
1552 return (void*)SendMsg(2375);
1553 }
1554
1555 // Extend life of document.
1556 void wxStyledTextCtrl::AddRefDocument(void* docPointer) {
1557 SendMsg(2376, (long)docPointer);
1558 }
1559
1560 // Release a reference to the document, deleting document if it fades to black.
1561 void wxStyledTextCtrl::ReleaseDocument(void* docPointer) {
1562 SendMsg(2377, (long)docPointer);
1563 }
1564
1565 // Get which document modification events are sent to the container.
1566 int wxStyledTextCtrl::GetModEventMask() {
1567 return SendMsg(2378, 0, 0);
1568 }
1569
1570 // Change internal focus flag
1571 void wxStyledTextCtrl::SetSTCFocus(bool focus) {
1572 SendMsg(2380, focus, 0);
1573 }
1574
1575 // Get internal focus flag
1576 bool wxStyledTextCtrl::GetSTCFocus() {
1577 return SendMsg(2381, 0, 0) != 0;
1578 }
1579
1580 // Change error status - 0 = OK
1581 void wxStyledTextCtrl::SetStatus(int statusCode) {
1582 SendMsg(2382, statusCode, 0);
1583 }
1584
1585 // Get error status
1586 int wxStyledTextCtrl::GetStatus() {
1587 return SendMsg(2383, 0, 0);
1588 }
1589
1590 // Set whether the mouse is captured when its button is pressed
1591 void wxStyledTextCtrl::SetMouseDownCaptures(bool captures) {
1592 SendMsg(2384, captures, 0);
1593 }
1594
1595 // Get whether mouse gets captured
1596 bool wxStyledTextCtrl::GetMouseDownCaptures() {
1597 return SendMsg(2385, 0, 0) != 0;
1598 }
1599
1600 // Sets the cursor to one of the SC_CURSOR* values
1601 void wxStyledTextCtrl::SetCursor(int cursorType) {
1602 SendMsg(2386, cursorType, 0);
1603 }
1604
1605 // Get cursor type
1606 int wxStyledTextCtrl::GetCursor() {
1607 return SendMsg(2387, 0, 0);
1608 }
1609
1610 // Change the way control characters are displayed:
1611 // If symbol is < 32, keep the drawn way, else, use the given character
1612 void wxStyledTextCtrl::SetControlCharSymbol(int symbol) {
1613 SendMsg(2388, symbol, 0);
1614 }
1615
1616 // Get the way control characters are displayed
1617 int wxStyledTextCtrl::GetControlCharSymbol() {
1618 return SendMsg(2389, 0, 0);
1619 }
1620
1621 // Move to the previous change in capitalistion
1622 void wxStyledTextCtrl::WordPartLeft() {
1623 SendMsg(2390, 0, 0);
1624 }
1625
1626 // Move to the previous change in capitalistion extending selection to new caret position.
1627 void wxStyledTextCtrl::WordPartLeftExtend() {
1628 SendMsg(2391, 0, 0);
1629 }
1630
1631 // Move to the change next in capitalistion
1632 void wxStyledTextCtrl::WordPartRight() {
1633 SendMsg(2392, 0, 0);
1634 }
1635
1636 // Move to the next change in capitalistion extending selection to new caret position.
1637 void wxStyledTextCtrl::WordPartRightExtend() {
1638 SendMsg(2393, 0, 0);
1639 }
1640
1641 // Set the way the display area is determined when a particular line is to be moved to.
1642 void wxStyledTextCtrl::SetVisiblePolicy(int visiblePolicy, int visibleSlop) {
1643 SendMsg(2394, visiblePolicy, visibleSlop);
1644 }
1645
1646 // Delete back from the current position to the start of the line
1647 void wxStyledTextCtrl::DelLineLeft() {
1648 SendMsg(2395, 0, 0);
1649 }
1650
1651 // Delete forwards from the current position to the end of the line
1652 void wxStyledTextCtrl::DelLineRight() {
1653 SendMsg(2396, 0, 0);
1654 }
1655
1656 // Get and Set the xOffset (ie, horizonal scroll position)
1657 void wxStyledTextCtrl::SetXOffset(int newOffset) {
1658 SendMsg(2397, newOffset, 0);
1659 }
1660 int wxStyledTextCtrl::GetXOffset() {
1661 return SendMsg(2398, 0, 0);
1662 }
1663
1664 // Start notifying the container of all key presses and commands.
1665 void wxStyledTextCtrl::StartRecord() {
1666 SendMsg(3001, 0, 0);
1667 }
1668
1669 // Stop notifying the container of all key presses and commands.
1670 void wxStyledTextCtrl::StopRecord() {
1671 SendMsg(3002, 0, 0);
1672 }
1673
1674 // Set the lexing language of the document.
1675 void wxStyledTextCtrl::SetLexer(int lexer) {
1676 SendMsg(4001, lexer, 0);
1677 }
1678
1679 // Retrieve the lexing language of the document.
1680 int wxStyledTextCtrl::GetLexer() {
1681 return SendMsg(4002, 0, 0);
1682 }
1683
1684 // Colourise a segment of the document using the current lexing language.
1685 void wxStyledTextCtrl::Colourise(int start, int end) {
1686 SendMsg(4003, start, end);
1687 }
1688
1689 // Set up a value that may be used by a lexer for some optional feature.
1690 void wxStyledTextCtrl::SetProperty(const wxString& key, const wxString& value) {
1691 SendMsg(4004, (long)key.c_str(), (long)value.c_str());
1692 }
1693
1694 // Set up the key words used by the lexer.
1695 void wxStyledTextCtrl::SetKeyWords(int keywordSet, const wxString& keyWords) {
1696 SendMsg(4005, keywordSet, (long)keyWords.c_str());
1697 }
1698
1699 // Set the lexing language of the document based on string name.
1700 void wxStyledTextCtrl::SetLexerLanguage(const wxString& language) {
1701 SendMsg(4006, 0, (long)language.c_str());
1702 }
1703
1704 // END of generated section
1705 //----------------------------------------------------------------------
1706
1707
1708 // Returns the line number of the line with the caret.
1709 int wxStyledTextCtrl::GetCurrentLine() {
1710 int line = LineFromPosition(GetCurrentPos());
1711 return line;
1712 }
1713
1714
1715 // Extract style settings from a spec-string which is composed of one or
1716 // more of the following comma separated elements:
1717 //
1718 // bold turns on bold
1719 // italic turns on italics
1720 // fore:#RRGGBB sets the foreground colour
1721 // back:#RRGGBB sets the background colour
1722 // face:[facename] sets the font face name to use
1723 // size:[num] sets the font size in points
1724 // eol turns on eol filling
1725 // underline turns on underlining
1726 //
1727 void wxStyledTextCtrl::StyleSetSpec(int styleNum, const wxString& spec) {
1728
1729 wxStringTokenizer tkz(spec, ",");
1730 while (tkz.HasMoreTokens()) {
1731 wxString token = tkz.GetNextToken();
1732
1733 wxString option = token.BeforeFirst(':');
1734 wxString val = token.AfterFirst(':');
1735
1736 if (option == "bold")
1737 StyleSetBold(styleNum, true);
1738
1739 else if (option == "italic")
1740 StyleSetItalic(styleNum, true);
1741
1742 else if (option == "underline")
1743 StyleSetUnderline(styleNum, true);
1744
1745 else if (option == "eol")
1746 StyleSetEOLFilled(styleNum, true);
1747
1748 else if (option == "size") {
1749 long points;
1750 if (val.ToLong(&points))
1751 StyleSetSize(styleNum, points);
1752 }
1753
1754 else if (option == "face")
1755 StyleSetFaceName(styleNum, val);
1756
1757 else if (option == "fore")
1758 StyleSetForeground(styleNum, wxColourFromSpec(val));
1759
1760 else if (option == "back")
1761 StyleSetBackground(styleNum, wxColourFromSpec(val));
1762 }
1763 }
1764
1765
1766 // Set style size, face, bold, italic, and underline attributes from
1767 // a wxFont's attributes.
1768 void wxStyledTextCtrl::StyleSetFont(int styleNum, wxFont& font) {
1769 int size = font.GetPointSize();
1770 wxString faceName = font.GetFaceName();
1771 bool bold = font.GetWeight() == wxBOLD;
1772 bool italic = font.GetStyle() != wxNORMAL;
1773 bool under = font.GetUnderlined();
1774
1775 // TODO: add encoding/charset mapping
1776 StyleSetFontAttr(styleNum, size, faceName, bold, italic, under);
1777 }
1778
1779 // Set all font style attributes at once.
1780 void wxStyledTextCtrl::StyleSetFontAttr(int styleNum, int size,
1781 const wxString& faceName,
1782 bool bold, bool italic,
1783 bool underline) {
1784 StyleSetSize(styleNum, size);
1785 StyleSetFaceName(styleNum, faceName);
1786 StyleSetBold(styleNum, bold);
1787 StyleSetItalic(styleNum, italic);
1788 StyleSetUnderline(styleNum, underline);
1789
1790 // TODO: add encoding/charset mapping
1791 }
1792
1793
1794 // Perform one of the operations defined by the wxSTC_CMD_* constants.
1795 void wxStyledTextCtrl::CmdKeyExecute(int cmd) {
1796 SendMsg(cmd);
1797 }
1798
1799
1800 // Set the left and right margin in the edit area, measured in pixels.
1801 void wxStyledTextCtrl::SetMargins(int left, int right) {
1802 SetMarginLeft(left);
1803 SetMarginRight(right);
1804 }
1805
1806
1807 // Retrieve the start and end positions of the current selection.
1808 void wxStyledTextCtrl::GetSelection(int* startPos, int* endPos) {
1809 if (startPos != NULL)
1810 *startPos = SendMsg(SCI_GETSELECTIONSTART);
1811 if (endPos != NULL)
1812 *endPos = SendMsg(SCI_GETSELECTIONEND);
1813 }
1814
1815
1816 // Retrieve the point in the window where a position is displayed.
1817 wxPoint wxStyledTextCtrl::PointFromPosition(int pos) {
1818 int x = SendMsg(SCI_POINTXFROMPOSITION, 0, pos);
1819 int y = SendMsg(SCI_POINTYFROMPOSITION, 0, pos);
1820 return wxPoint(x, y);
1821 }
1822
1823 // Scroll enough to make the given line visible
1824 void wxStyledTextCtrl::ScrollToLine(int line) {
1825 m_swx->DoScrollToLine(line);
1826 }
1827
1828
1829 // Scroll enough to make the given column visible
1830 void wxStyledTextCtrl::ScrollToColumn(int column) {
1831 m_swx->DoScrollToColumn(column);
1832 }
1833
1834
1835
1836 //----------------------------------------------------------------------
1837 // Event handlers
1838
1839 void wxStyledTextCtrl::OnPaint(wxPaintEvent& evt) {
1840 wxPaintDC dc(this);
1841 wxRegion region = GetUpdateRegion();
1842
1843 m_swx->DoPaint(&dc, region.GetBox());
1844 }
1845
1846 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent& evt) {
1847 if (evt.GetOrientation() == wxHORIZONTAL)
1848 m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition());
1849 else
1850 m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition());
1851 }
1852
1853 void wxStyledTextCtrl::OnScroll(wxScrollEvent& evt) {
1854 wxScrollBar* sb = wxDynamicCast(evt.GetEventObject(), wxScrollBar);
1855 if (sb) {
1856 if (sb->IsVertical())
1857 m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition());
1858 else
1859 m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition());
1860 }
1861 }
1862
1863 void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) {
1864 wxSize sz = GetClientSize();
1865 m_swx->DoSize(sz.x, sz.y);
1866 }
1867
1868 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) {
1869 wxPoint pt = evt.GetPosition();
1870 m_swx->DoButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(),
1871 evt.ShiftDown(), evt.ControlDown(), evt.AltDown());
1872 }
1873
1874 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) {
1875 wxPoint pt = evt.GetPosition();
1876 m_swx->DoButtonMove(Point(pt.x, pt.y));
1877 }
1878
1879 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) {
1880 wxPoint pt = evt.GetPosition();
1881 m_swx->DoButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(),
1882 evt.ControlDown());
1883 }
1884
1885
1886 void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) {
1887 wxPoint pt = evt.GetPosition();
1888 m_swx->DoContextMenu(Point(pt.x, pt.y));
1889 }
1890
1891
1892 void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) {
1893 wxPoint pt = evt.GetPosition();
1894 ScreenToClient(&pt.x, &pt.y);
1895 m_swx->DoContextMenu(Point(pt.x, pt.y));
1896 }
1897
1898
1899 void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) {
1900 m_swx->DoMouseWheel(evt.GetWheelRotation(),
1901 evt.GetWheelDelta(),
1902 evt.GetLinesPerAction(),
1903 evt.ControlDown());
1904 }
1905
1906
1907 void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) {
1908 long key = evt.KeyCode();
1909
1910 // printf("OnChar key:%d consumed:%d ctrl:%d alt:%d\n",
1911 // key, m_lastKeyDownConsumed, evt.ControlDown(), evt.AltDown());
1912
1913 // AltGr keys???
1914 // \|@#¬[]{}?£$~ ã,õ,Ã,Õ, ñ, Ñ
1915
1916 // On (some?) non-US keyboards the AltGr key is required to enter some
1917 // common characters. It comes to us as both Alt and Ctrl down so we need
1918 // to let the char through in that case, otherwise if only ctrl or only
1919 // alt let's skip it.
1920 bool ctrl = evt.ControlDown();
1921 bool alt = evt.AltDown();
1922 bool skip = ((ctrl || alt) && ! (ctrl && alt));
1923
1924 if (key <= 0xff && key >= 32 && !m_lastKeyDownConsumed && !skip) {
1925 m_swx->DoAddChar(key);
1926 return;
1927 }
1928 evt.Skip();
1929 }
1930
1931
1932 void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) {
1933 long key = evt.KeyCode();
1934 bool shift = evt.ShiftDown(),
1935 ctrl = evt.ControlDown(),
1936 alt = evt.AltDown();
1937
1938 int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, &m_lastKeyDownConsumed);
1939
1940 // printf("key: %d shift: %d ctrl: %d alt: %d processed: %d consumed: %d\n",
1941 // key, shift, ctrl, alt, processed, m_lastKeyDownConsumed);
1942
1943 if (!processed && !m_lastKeyDownConsumed)
1944 evt.Skip();
1945 }
1946
1947
1948 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent& evt) {
1949 m_swx->DoLoseFocus();
1950 }
1951
1952
1953 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) {
1954 m_swx->DoGainFocus();
1955 }
1956
1957
1958 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& evt) {
1959 m_swx->DoSysColourChange();
1960 }
1961
1962
1963 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent& evt) {
1964 // do nothing to help avoid flashing
1965 }
1966
1967
1968
1969 void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) {
1970 m_swx->DoCommand(evt.GetId());
1971 }
1972
1973
1974 void wxStyledTextCtrl::OnListBox(wxCommandEvent& evt) {
1975 m_swx->DoOnListBox();
1976 }
1977
1978
1979 //----------------------------------------------------------------------
1980 // Turn notifications from Scintilla into events
1981
1982
1983 void wxStyledTextCtrl::NotifyChange() {
1984 wxStyledTextEvent evt(wxEVT_STC_CHANGE, GetId());
1985 evt.SetEventObject(this);
1986 GetEventHandler()->ProcessEvent(evt);
1987 }
1988
1989 void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) {
1990 SCNotification& scn = *_scn;
1991 wxStyledTextEvent evt(0, GetId());
1992
1993 evt.SetEventObject(this);
1994 evt.SetPosition(scn.position);
1995 evt.SetKey(scn.ch);
1996 evt.SetModifiers(scn.modifiers);
1997
1998 switch (scn.nmhdr.code) {
1999 case SCN_STYLENEEDED:
2000 evt.SetEventType(wxEVT_STC_STYLENEEDED);
2001 break;
2002
2003 case SCN_CHARADDED:
2004 evt.SetEventType(wxEVT_STC_CHARADDED);
2005 break;
2006
2007 case SCN_SAVEPOINTREACHED:
2008 evt.SetEventType(wxEVT_STC_SAVEPOINTREACHED);
2009 break;
2010
2011 case SCN_SAVEPOINTLEFT:
2012 evt.SetEventType(wxEVT_STC_SAVEPOINTLEFT);
2013 break;
2014
2015 case SCN_MODIFYATTEMPTRO:
2016 evt.SetEventType(wxEVT_STC_ROMODIFYATTEMPT);
2017 break;
2018
2019 case SCN_KEY:
2020 evt.SetEventType(wxEVT_STC_KEY);
2021 break;
2022
2023 case SCN_DOUBLECLICK:
2024 evt.SetEventType(wxEVT_STC_DOUBLECLICK);
2025 break;
2026
2027 case SCN_UPDATEUI:
2028 evt.SetEventType(wxEVT_STC_UPDATEUI);
2029 break;
2030
2031 case SCN_MODIFIED:
2032 evt.SetEventType(wxEVT_STC_MODIFIED);
2033 evt.SetModificationType(scn.modificationType);
2034 if (scn.text)
2035 evt.SetText(wxString(scn.text, scn.length));
2036 evt.SetLength(scn.length);
2037 evt.SetLinesAdded(scn.linesAdded);
2038 evt.SetLine(scn.line);
2039 evt.SetFoldLevelNow(scn.foldLevelNow);
2040 evt.SetFoldLevelPrev(scn.foldLevelPrev);
2041 break;
2042
2043 case SCN_MACRORECORD:
2044 evt.SetEventType(wxEVT_STC_MACRORECORD);
2045 evt.SetMessage(scn.message);
2046 evt.SetWParam(scn.wParam);
2047 evt.SetLParam(scn.lParam);
2048 break;
2049
2050 case SCN_MARGINCLICK:
2051 evt.SetEventType(wxEVT_STC_MARGINCLICK);
2052 evt.SetMargin(scn.margin);
2053 break;
2054
2055 case SCN_NEEDSHOWN:
2056 evt.SetEventType(wxEVT_STC_NEEDSHOWN);
2057 evt.SetLength(scn.length);
2058 break;
2059
2060 case SCN_PAINTED:
2061 evt.SetEventType(wxEVT_STC_PAINTED);
2062 break;
2063
2064 case SCN_USERLISTSELECTION:
2065 evt.SetEventType(wxEVT_STC_USERLISTSELECTION);
2066 evt.SetListType(scn.listType);
2067 evt.SetText(scn.text);
2068 break;
2069
2070 case SCN_URIDROPPED:
2071 evt.SetEventType(wxEVT_STC_URIDROPPED);
2072 evt.SetText(scn.text);
2073 break;
2074
2075 case SCN_DWELLSTART:
2076 evt.SetEventType(wxEVT_STC_DWELLSTART);
2077 evt.SetX(scn.x);
2078 evt.SetY(scn.y);
2079 break;
2080
2081 case SCN_DWELLEND:
2082 evt.SetEventType(wxEVT_STC_DWELLEND);
2083 evt.SetX(scn.x);
2084 evt.SetY(scn.y);
2085 break;
2086
2087 default:
2088 return;
2089 }
2090
2091 GetEventHandler()->ProcessEvent(evt);
2092 }
2093
2094
2095 //----------------------------------------------------------------------
2096 //----------------------------------------------------------------------
2097 //----------------------------------------------------------------------
2098
2099 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id)
2100 : wxCommandEvent(commandType, id)
2101 {
2102 m_position = 0;
2103 m_key = 0;
2104 m_modifiers = 0;
2105 m_modificationType = 0;
2106 m_length = 0;
2107 m_linesAdded = 0;
2108 m_line = 0;
2109 m_foldLevelNow = 0;
2110 m_foldLevelPrev = 0;
2111 m_margin = 0;
2112 m_message = 0;
2113 m_wParam = 0;
2114 m_lParam = 0;
2115 m_listType = 0;
2116 m_x = 0;
2117 m_y = 0;
2118 m_dragAllowMove = FALSE;
2119 m_dragResult = wxDragNone;
2120 }
2121
2122 bool wxStyledTextEvent::GetShift() const { return (m_modifiers & SCI_SHIFT) != 0; }
2123 bool wxStyledTextEvent::GetControl() const { return (m_modifiers & SCI_CTRL) != 0; }
2124 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers & SCI_ALT) != 0; }
2125
2126
2127 wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent& event):
2128 wxCommandEvent(event)
2129 {
2130 m_position = event.m_position;
2131 m_key = event.m_key;
2132 m_modifiers = event.m_modifiers;
2133 m_modificationType = event.m_modificationType;
2134 m_text = event.m_text;
2135 m_length = event.m_length;
2136 m_linesAdded = event.m_linesAdded;
2137 m_line = event.m_line;
2138 m_foldLevelNow = event.m_foldLevelNow;
2139 m_foldLevelPrev = event.m_foldLevelPrev;
2140
2141 m_margin = event.m_margin;
2142
2143 m_message = event.m_message;
2144 m_wParam = event.m_wParam;
2145 m_lParam = event.m_lParam;
2146
2147 m_listType = event.m_listType;
2148 m_x = event.m_x;
2149 m_y = event.m_y;
2150
2151 m_dragText = event.m_dragText;
2152 m_dragAllowMove =event.m_dragAllowMove;
2153 m_dragResult = event.m_dragResult;
2154 }
2155
2156 //----------------------------------------------------------------------
2157 //----------------------------------------------------------------------
2158
2159
2160
2161
2162
2163
2164
2165
2166