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