1 ////////////////////////////////////////////////////////////////////////////
3 // Purpose: A wxWindows implementation of Scintilla. This class is the
4 // one meant to be used directly by wx applications. It does not
5 // derive directly from the Scintilla classes, but instead
6 // delegates most things to the real Scintilla class.
7 // This allows the use of Scintilla without polluting the
8 // namespace with all the classes and identifiers from Scintilla.
12 // Created: 13-Jan-2000
14 // Copyright: (c) 2000 by Total Control Software
15 // Licence: wxWindows license
16 /////////////////////////////////////////////////////////////////////////////
20 #include "wx/stc/stc.h"
21 #include "ScintillaWX.h"
23 #include <wx/tokenzr.h>
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)
29 int wxForceScintillaLexers(void)
31 extern LexerModule lmAda
;
32 extern LexerModule lmAVE
;
33 extern LexerModule lmConf
;
34 extern LexerModule lmCPP
;
35 extern LexerModule lmNncrontab
;
36 extern LexerModule lmEiffel
;
37 extern LexerModule lmHTML
;
38 extern LexerModule lmLISP
;
39 extern LexerModule lmLua
;
40 extern LexerModule lmBatch
; // In LexOthers.cxx
41 extern LexerModule lmPascal
;
42 extern LexerModule lmPerl
;
43 extern LexerModule lmPython
;
44 extern LexerModule lmRuby
;
45 extern LexerModule lmSQL
;
46 extern LexerModule lmVB
;
73 //----------------------------------------------------------------------
75 const wxChar
* wxSTCNameStr
= "stcwindow";
77 DEFINE_EVENT_TYPE( wxEVT_STC_CHANGE
)
78 DEFINE_EVENT_TYPE( wxEVT_STC_STYLENEEDED
)
79 DEFINE_EVENT_TYPE( wxEVT_STC_CHARADDED
)
80 DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTREACHED
)
81 DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTLEFT
)
82 DEFINE_EVENT_TYPE( wxEVT_STC_ROMODIFYATTEMPT
)
83 DEFINE_EVENT_TYPE( wxEVT_STC_KEY
)
84 DEFINE_EVENT_TYPE( wxEVT_STC_DOUBLECLICK
)
85 DEFINE_EVENT_TYPE( wxEVT_STC_UPDATEUI
)
86 DEFINE_EVENT_TYPE( wxEVT_STC_MODIFIED
)
87 DEFINE_EVENT_TYPE( wxEVT_STC_MACRORECORD
)
88 DEFINE_EVENT_TYPE( wxEVT_STC_MARGINCLICK
)
89 DEFINE_EVENT_TYPE( wxEVT_STC_NEEDSHOWN
)
90 DEFINE_EVENT_TYPE( wxEVT_STC_POSCHANGED
)
91 DEFINE_EVENT_TYPE( wxEVT_STC_PAINTED
)
92 DEFINE_EVENT_TYPE( wxEVT_STC_USERLISTSELECTION
)
93 DEFINE_EVENT_TYPE( wxEVT_STC_URIDROPPED
)
94 DEFINE_EVENT_TYPE( wxEVT_STC_DWELLSTART
)
95 DEFINE_EVENT_TYPE( wxEVT_STC_DWELLEND
)
96 #if wxUSE_DRAG_AND_DROP
97 DEFINE_EVENT_TYPE( wxEVT_STC_START_DRAG
)
98 DEFINE_EVENT_TYPE( wxEVT_STC_DRAG_OVER
)
99 DEFINE_EVENT_TYPE( wxEVT_STC_DO_DROP
)
103 BEGIN_EVENT_TABLE(wxStyledTextCtrl
, wxControl
)
104 EVT_PAINT (wxStyledTextCtrl::OnPaint
)
105 EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin
)
106 EVT_SCROLL (wxStyledTextCtrl::OnScroll
)
107 EVT_SIZE (wxStyledTextCtrl::OnSize
)
108 EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown
)
110 // Let Scintilla see the double click as a second click
111 EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown
)
113 EVT_MOTION (wxStyledTextCtrl::OnMouseMove
)
114 EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp
)
115 EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu
)
116 EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel
)
117 EVT_CHAR (wxStyledTextCtrl::OnChar
)
118 EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown
)
119 EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus
)
120 EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus
)
121 EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged
)
122 EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground
)
123 EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu
)
124 EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox
)
128 IMPLEMENT_CLASS(wxStyledTextCtrl
, wxControl
)
129 IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent
, wxCommandEvent
)
131 //----------------------------------------------------------------------
132 // Constructor and Destructor
134 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow
*parent
,
139 const wxString
& name
) :
140 wxControl(parent
, id
, pos
, size
,
141 style
| wxVSCROLL
| wxHSCROLL
| wxWANTS_CHARS
| wxCLIP_CHILDREN
,
142 wxDefaultValidator
, name
)
144 m_swx
= new ScintillaWX(this);
146 m_lastKeyDownConsumed
= FALSE
;
152 wxStyledTextCtrl::~wxStyledTextCtrl() {
157 //----------------------------------------------------------------------
159 long wxStyledTextCtrl::SendMsg(int msg
, long wp
, long lp
) {
161 return m_swx
->WndProc(msg
, wp
, lp
);
169 #define MAKELONG(a, b) ((a) | ((b) << 16))
172 static long wxColourAsLong(const wxColour
& co
) {
173 return (((long)co
.Blue() << 16) |
174 ((long)co
.Green() << 8) |
178 static wxColour
wxColourFromLong(long c
) {
180 clr
.Set(c
& 0xff, (c
>> 8) & 0xff, (c
>> 16) & 0xff);
185 static wxColour
wxColourFromSpec(const wxString
& spec
) {
186 // spec should be #RRGGBB
188 int red
= strtol(spec
.Mid(1,2), &junk
, 16);
189 int green
= strtol(spec
.Mid(3,2), &junk
, 16);
190 int blue
= strtol(spec
.Mid(5,2), &junk
, 16);
191 return wxColour(red
, green
, blue
);
195 //----------------------------------------------------------------------
196 // BEGIN generated section. The following code is automatically generated
197 // by gen_iface.py from the contents of Scintilla.iface. Do not edit
198 // this file. Edit stc.cpp.in or gen_iface.py instead and regenerate.
201 // Add text to the document
202 void wxStyledTextCtrl::AddText(const wxString
& text
) {
203 SendMsg(2001, text
.Len(), (long)text
.c_str());
206 // Add array of cells to document
207 void wxStyledTextCtrl::AddStyledText(const wxString
& text
) {
208 SendMsg(2002, text
.Len(), (long)text
.c_str());
211 // Insert string at a position
212 void wxStyledTextCtrl::InsertText(int pos
, const wxString
& text
) {
213 SendMsg(2003, pos
, (long)text
.c_str());
216 // Delete all text in the document
217 void wxStyledTextCtrl::ClearAll() {
221 // Set all style bytes to 0, remove all folding information
222 void wxStyledTextCtrl::ClearDocumentStyle() {
226 // The number of characters in the document
227 int wxStyledTextCtrl::GetLength() {
228 return SendMsg(2006, 0, 0);
231 // Returns the character byte at the position
232 int wxStyledTextCtrl::GetCharAt(int pos
) {
233 return SendMsg(2007, pos
, 0);
236 // Returns the position of the caret
237 int wxStyledTextCtrl::GetCurrentPos() {
238 return SendMsg(2008, 0, 0);
241 // Returns the position of the opposite end of the selection to the caret
242 int wxStyledTextCtrl::GetAnchor() {
243 return SendMsg(2009, 0, 0);
246 // Returns the style byte at the position
247 int wxStyledTextCtrl::GetStyleAt(int pos
) {
248 return SendMsg(2010, pos
, 0);
251 // Redoes the next action on the undo history
252 void wxStyledTextCtrl::Redo() {
256 // Choose between collecting actions into the undo
257 // history and discarding them.
258 void wxStyledTextCtrl::SetUndoCollection(bool collectUndo
) {
259 SendMsg(2012, collectUndo
, 0);
262 // Select all the text in the document.
263 void wxStyledTextCtrl::SelectAll() {
267 // Remember the current position in the undo history as the position
268 // at which the document was saved.
269 void wxStyledTextCtrl::SetSavePoint() {
273 // Retrieve a buffer of cells.
274 wxString
wxStyledTextCtrl::GetStyledText(int startPos
, int endPos
) {
276 int len
= endPos
- startPos
;
279 tr
.lpstrText
= text
.GetWriteBuf(len
*2);
280 tr
.chrg
.cpMin
= startPos
;
281 tr
.chrg
.cpMax
= endPos
;
282 SendMsg(2015, 0, (long)&tr
);
283 text
.UngetWriteBuf(len
*2);
287 // Are there any redoable actions in the undo history.
288 bool wxStyledTextCtrl::CanRedo() {
289 return SendMsg(2016, 0, 0) != 0;
292 // Retrieve the line number at which a particular marker is located
293 int wxStyledTextCtrl::MarkerLineFromHandle(int handle
) {
294 return SendMsg(2017, handle
, 0);
298 void wxStyledTextCtrl::MarkerDeleteHandle(int handle
) {
299 SendMsg(2018, handle
, 0);
302 // Is undo history being collected?
303 bool wxStyledTextCtrl::GetUndoCollection() {
304 return SendMsg(2019, 0, 0) != 0;
307 // Are white space characters currently visible?
308 // Returns one of SCWS_* constants.
309 int wxStyledTextCtrl::GetViewWhiteSpace() {
310 return SendMsg(2020, 0, 0);
313 // Make white space characters invisible, always visible or visible outside indentation.
314 void wxStyledTextCtrl::SetViewWhiteSpace(int viewWS
) {
315 SendMsg(2021, viewWS
, 0);
318 // Find the position from a point within the window.
319 int wxStyledTextCtrl::PositionFromPoint(wxPoint pt
) {
320 return SendMsg(2022, pt
.x
, pt
.y
);
323 // Find the position from a point within the window but return
324 // INVALID_POSITION if not close to text.
325 int wxStyledTextCtrl::PositionFromPointClose(int x
, int y
) {
326 return SendMsg(2023, x
, y
);
329 // Set caret to start of a line and ensure it is visible.
330 void wxStyledTextCtrl::GotoLine(int line
) {
331 SendMsg(2024, line
, 0);
334 // Set caret to a position and ensure it is visible.
335 void wxStyledTextCtrl::GotoPos(int pos
) {
336 SendMsg(2025, pos
, 0);
339 // Set the selection anchor to a position. The anchor is the opposite
340 // end of the selection from the caret.
341 void wxStyledTextCtrl::SetAnchor(int posAnchor
) {
342 SendMsg(2026, posAnchor
, 0);
345 // Retrieve the text of the line containing the caret.
346 // Returns the index of the caret on the line.
347 wxString
wxStyledTextCtrl::GetCurLine(int* linePos
) {
349 int len
= LineLength(GetCurrentLine());
351 if (linePos
) *linePos
= 0;
354 // Need an extra byte because SCI_GETCURLINE writes a null to the string
355 char* buf
= text
.GetWriteBuf(len
+1);
357 int pos
= SendMsg(2027, len
+1, (long)buf
);
358 text
.UngetWriteBuf(len
);
359 if (linePos
) *linePos
= pos
;
364 // Retrieve the position of the last correctly styled character.
365 int wxStyledTextCtrl::GetEndStyled() {
366 return SendMsg(2028, 0, 0);
369 // Convert all line endings in the document to one mode.
370 void wxStyledTextCtrl::ConvertEOLs(int eolMode
) {
371 SendMsg(2029, eolMode
, 0);
374 // Retrieve the current end of line mode - one of CRLF, CR, or LF.
375 int wxStyledTextCtrl::GetEOLMode() {
376 return SendMsg(2030, 0, 0);
379 // Set the current end of line mode.
380 void wxStyledTextCtrl::SetEOLMode(int eolMode
) {
381 SendMsg(2031, eolMode
, 0);
384 // Set the current styling position to pos and the styling mask to mask.
385 // The styling mask can be used to protect some bits in each styling byte from
387 void wxStyledTextCtrl::StartStyling(int pos
, int mask
) {
388 SendMsg(2032, pos
, mask
);
391 // Change style from current styling position for length characters to a style
392 // and move the current styling position to after this newly styled segment.
393 void wxStyledTextCtrl::SetStyling(int length
, int style
) {
394 SendMsg(2033, length
, style
);
397 // Is drawing done first into a buffer or direct to the screen.
398 bool wxStyledTextCtrl::GetBufferedDraw() {
399 return SendMsg(2034, 0, 0) != 0;
402 // If drawing is buffered then each line of text is drawn into a bitmap buffer
403 // before drawing it to the screen to avoid flicker.
404 void wxStyledTextCtrl::SetBufferedDraw(bool buffered
) {
405 SendMsg(2035, buffered
, 0);
408 // Change the visible size of a tab to be a multiple of the width of a space
410 void wxStyledTextCtrl::SetTabWidth(int tabWidth
) {
411 SendMsg(2036, tabWidth
, 0);
414 // Retrieve the visible size of a tab.
415 int wxStyledTextCtrl::GetTabWidth() {
416 return SendMsg(2121, 0, 0);
419 // Set the code page used to interpret the bytes of the document as characters.
420 // The SC_CP_UTF8 value can be used to enter Unicode mode.
421 void wxStyledTextCtrl::SetCodePage(int codePage
) {
422 SendMsg(2037, codePage
, 0);
425 // Set the symbol used for a particular marker number,
426 // and optionally the for and background colours.
427 void wxStyledTextCtrl::MarkerDefine(int markerNumber
, int markerSymbol
,
428 const wxColour
& foreground
,
429 const wxColour
& background
) {
431 SendMsg(2040, markerNumber
, markerSymbol
);
433 MarkerSetForeground(markerNumber
, foreground
);
435 MarkerSetBackground(markerNumber
, background
);
438 // Set the foreground colour used for a particular marker number.
439 void wxStyledTextCtrl::MarkerSetForeground(int markerNumber
, const wxColour
& fore
) {
440 SendMsg(2041, markerNumber
, wxColourAsLong(fore
));
443 // Set the background colour used for a particular marker number.
444 void wxStyledTextCtrl::MarkerSetBackground(int markerNumber
, const wxColour
& back
) {
445 SendMsg(2042, markerNumber
, wxColourAsLong(back
));
448 // Add a marker to a line.
449 void wxStyledTextCtrl::MarkerAdd(int line
, int markerNumber
) {
450 SendMsg(2043, line
, markerNumber
);
453 // Delete a marker from a line
454 void wxStyledTextCtrl::MarkerDelete(int line
, int markerNumber
) {
455 SendMsg(2044, line
, markerNumber
);
458 // Delete all markers with a particular number from all lines
459 void wxStyledTextCtrl::MarkerDeleteAll(int markerNumber
) {
460 SendMsg(2045, markerNumber
, 0);
463 // Get a bit mask of all the markers set on a line.
464 int wxStyledTextCtrl::MarkerGet(int line
) {
465 return SendMsg(2046, line
, 0);
468 // Find the next line after lineStart that includes a marker in mask.
469 int wxStyledTextCtrl::MarkerNext(int lineStart
, int markerMask
) {
470 return SendMsg(2047, lineStart
, markerMask
);
473 // Find the previous line before lineStart that includes a marker in mask.
474 int wxStyledTextCtrl::MarkerPrevious(int lineStart
, int markerMask
) {
475 return SendMsg(2048, lineStart
, markerMask
);
478 // Set a margin to be either numeric or symbolic.
479 void wxStyledTextCtrl::SetMarginType(int margin
, int marginType
) {
480 SendMsg(2240, margin
, marginType
);
483 // Retrieve the type of a margin.
484 int wxStyledTextCtrl::GetMarginType(int margin
) {
485 return SendMsg(2241, margin
, 0);
488 // Set the width of a margin to a width expressed in pixels.
489 void wxStyledTextCtrl::SetMarginWidth(int margin
, int pixelWidth
) {
490 SendMsg(2242, margin
, pixelWidth
);
493 // Retrieve the width of a margin in pixels.
494 int wxStyledTextCtrl::GetMarginWidth(int margin
) {
495 return SendMsg(2243, margin
, 0);
498 // Set a mask that determines which markers are displayed in a margin.
499 void wxStyledTextCtrl::SetMarginMask(int margin
, int mask
) {
500 SendMsg(2244, margin
, mask
);
503 // Retrieve the marker mask of a margin.
504 int wxStyledTextCtrl::GetMarginMask(int margin
) {
505 return SendMsg(2245, margin
, 0);
508 // Make a margin sensitive or insensitive to mouse clicks.
509 void wxStyledTextCtrl::SetMarginSensitive(int margin
, bool sensitive
) {
510 SendMsg(2246, margin
, sensitive
);
513 // Retrieve the mouse click sensitivity of a margin.
514 bool wxStyledTextCtrl::GetMarginSensitive(int margin
) {
515 return SendMsg(2247, margin
, 0) != 0;
518 // Clear all the styles and make equivalent to the global default style.
519 void wxStyledTextCtrl::StyleClearAll() {
523 // Set the foreground colour of a style.
524 void wxStyledTextCtrl::StyleSetForeground(int style
, const wxColour
& fore
) {
525 SendMsg(2051, style
, wxColourAsLong(fore
));
528 // Set the background colour of a style.
529 void wxStyledTextCtrl::StyleSetBackground(int style
, const wxColour
& back
) {
530 SendMsg(2052, style
, wxColourAsLong(back
));
533 // Set a style to be bold or not.
534 void wxStyledTextCtrl::StyleSetBold(int style
, bool bold
) {
535 SendMsg(2053, style
, bold
);
538 // Set a style to be italic or not.
539 void wxStyledTextCtrl::StyleSetItalic(int style
, bool italic
) {
540 SendMsg(2054, style
, italic
);
543 // Set the size of characters of a style.
544 void wxStyledTextCtrl::StyleSetSize(int style
, int sizePoints
) {
545 SendMsg(2055, style
, sizePoints
);
548 // Set the font of a style.
549 void wxStyledTextCtrl::StyleSetFaceName(int style
, const wxString
& fontName
) {
550 SendMsg(2056, style
, (long)fontName
.c_str());
553 // Set a style to have its end of line filled or not.
554 void wxStyledTextCtrl::StyleSetEOLFilled(int style
, bool filled
) {
555 SendMsg(2057, style
, filled
);
558 // Reset the default style to its state at startup
559 void wxStyledTextCtrl::StyleResetDefault() {
563 // Set a style to be underlined or not.
564 void wxStyledTextCtrl::StyleSetUnderline(int style
, bool underline
) {
565 SendMsg(2059, style
, underline
);
568 // Set a style to be mixed case, or to force upper or lower case.
569 void wxStyledTextCtrl::StyleSetCase(int style
, int caseForce
) {
570 SendMsg(2060, style
, caseForce
);
573 // Set the foreground colour of the selection and whether to use this setting.
574 void wxStyledTextCtrl::SetSelForeground(bool useSetting
, const wxColour
& fore
) {
575 SendMsg(2067, useSetting
, wxColourAsLong(fore
));
578 // Set the background colour of the selection and whether to use this setting.
579 void wxStyledTextCtrl::SetSelBackground(bool useSetting
, const wxColour
& back
) {
580 SendMsg(2068, useSetting
, wxColourAsLong(back
));
583 // Set the foreground colour of the caret.
584 void wxStyledTextCtrl::SetCaretForeground(const wxColour
& fore
) {
585 SendMsg(2069, wxColourAsLong(fore
), 0);
588 // When key+modifier combination km is pressed perform msg.
589 void wxStyledTextCtrl::CmdKeyAssign(int key
, int modifiers
, int cmd
) {
590 SendMsg(2070, MAKELONG(key
, modifiers
), cmd
);
593 // When key+modifier combination km do nothing.
594 void wxStyledTextCtrl::CmdKeyClear(int key
, int modifiers
) {
595 SendMsg(2071, MAKELONG(key
, modifiers
));
598 // Drop all key mappings.
599 void wxStyledTextCtrl::CmdKeyClearAll() {
603 // Set the styles for a segment of the document.
604 void wxStyledTextCtrl::SetStyleBytes(int length
, char* styleBytes
) {
605 SendMsg(2073, length
, (long)styleBytes
);
608 // Set a style to be visible or not.
609 void wxStyledTextCtrl::StyleSetVisible(int style
, bool visible
) {
610 SendMsg(2074, style
, visible
);
613 // Get the time in milliseconds that the caret is on and off.
614 int wxStyledTextCtrl::GetCaretPeriod() {
615 return SendMsg(2075, 0, 0);
618 // Get the time in milliseconds that the caret is on and off. 0 = steady on.
619 void wxStyledTextCtrl::SetCaretPeriod(int periodMilliseconds
) {
620 SendMsg(2076, periodMilliseconds
, 0);
623 // Set the set of characters making up words for when moving or selecting
625 void wxStyledTextCtrl::SetWordChars(const wxString
& characters
) {
626 SendMsg(2077, 0, (long)characters
.c_str());
629 // Start a sequence of actions that is undone and redone as a unit.
631 void wxStyledTextCtrl::BeginUndoAction() {
635 // End a sequence of actions that is undone and redone as a unit.
636 void wxStyledTextCtrl::EndUndoAction() {
640 // Set an indicator to plain, squiggle or TT.
641 void wxStyledTextCtrl::IndicatorSetStyle(int indic
, int style
) {
642 SendMsg(2080, indic
, style
);
645 // Retrieve the style of an indicator.
646 int wxStyledTextCtrl::IndicatorGetStyle(int indic
) {
647 return SendMsg(2081, indic
, 0);
650 // Set the foreground colour of an indicator.
651 void wxStyledTextCtrl::IndicatorSetForeground(int indic
, const wxColour
& fore
) {
652 SendMsg(2082, indic
, wxColourAsLong(fore
));
655 // Retrieve the foreground colour of an indicator.
656 wxColour
wxStyledTextCtrl::IndicatorGetForeground(int indic
) {
657 long c
= SendMsg(2083, indic
, 0);
658 return wxColourFromLong(c
);
661 // Divide each styling byte into lexical class bits (default:5) and indicator
662 // bits (default:3). If a lexer requires more than 32 lexical states, then this
663 // is used to expand the possible states.
664 void wxStyledTextCtrl::SetStyleBits(int bits
) {
665 SendMsg(2090, bits
, 0);
668 // Retrieve number of bits in style bytes used to hold the lexical state.
669 int wxStyledTextCtrl::GetStyleBits() {
670 return SendMsg(2091, 0, 0);
673 // Used to hold extra styling information for each line.
674 void wxStyledTextCtrl::SetLineState(int line
, int state
) {
675 SendMsg(2092, line
, state
);
678 // Retrieve the extra styling information for a line.
679 int wxStyledTextCtrl::GetLineState(int line
) {
680 return SendMsg(2093, line
, 0);
683 // Retrieve the last line number that has line state.
684 int wxStyledTextCtrl::GetMaxLineState() {
685 return SendMsg(2094, 0, 0);
688 // Is the background of the line containing the caret in a different colour?
689 bool wxStyledTextCtrl::GetCaretLineVisible() {
690 return SendMsg(2095, 0, 0) != 0;
693 // Display the background of the line containing the caret in a different colour.
694 void wxStyledTextCtrl::SetCaretLineVisible(bool show
) {
695 SendMsg(2096, show
, 0);
698 // Get the colour of the background of the line containing the caret.
699 wxColour
wxStyledTextCtrl::GetCaretLineBack() {
700 long c
= SendMsg(2097, 0, 0);
701 return wxColourFromLong(c
);
704 // Set the colour of the background of the line containing the caret.
705 void wxStyledTextCtrl::SetCaretLineBack(const wxColour
& back
) {
706 SendMsg(2098, wxColourAsLong(back
), 0);
709 // Display a auto-completion list.
710 // The lenEntered parameter indicates how many characters before
711 // the caret should be used to provide context.
712 void wxStyledTextCtrl::AutoCompShow(int lenEntered
, const wxString
& itemList
) {
713 SendMsg(2100, lenEntered
, (long)itemList
.c_str());
716 // Remove the auto-completion list from the screen.
717 void wxStyledTextCtrl::AutoCompCancel() {
721 // Is there an auto-completion list visible?
722 bool wxStyledTextCtrl::AutoCompActive() {
723 return SendMsg(2102, 0, 0) != 0;
726 // Retrieve the position of the caret when the auto-completion list was
728 int wxStyledTextCtrl::AutoCompPosStart() {
729 return SendMsg(2103, 0, 0);
732 // User has selected an item so remove the list and insert the selection.
733 void wxStyledTextCtrl::AutoCompComplete() {
737 // Define a set of character that when typed cancel the auto-completion list.
738 void wxStyledTextCtrl::AutoCompStops(const wxString
& characterSet
) {
739 SendMsg(2105, 0, (long)characterSet
.c_str());
742 // Change the separator character in the string setting up an auto-completion
743 // list. Default is space but can be changed if items contain space.
744 void wxStyledTextCtrl::AutoCompSetSeparator(int separatorCharacter
) {
745 SendMsg(2106, separatorCharacter
, 0);
748 // Retrieve the auto-completion list separator character.
749 int wxStyledTextCtrl::AutoCompGetSeparator() {
750 return SendMsg(2107, 0, 0);
753 // Select the item in the auto-completion list that starts with a string.
754 void wxStyledTextCtrl::AutoCompSelect(const wxString
& text
) {
755 SendMsg(2108, 0, (long)text
.c_str());
758 // Should the auto-completion list be cancelled if the user backspaces to a
759 // position before where the box was created.
760 void wxStyledTextCtrl::AutoCompSetCancelAtStart(bool cancel
) {
761 SendMsg(2110, cancel
, 0);
764 // Retrieve whether auto-completion cancelled by backspacing before start.
765 bool wxStyledTextCtrl::AutoCompGetCancelAtStart() {
766 return SendMsg(2111, 0, 0) != 0;
769 // Define a set of character that when typed fills up the selected word.
770 void wxStyledTextCtrl::AutoCompSetFillUps(const wxString
& characterSet
) {
771 SendMsg(2112, 0, (long)characterSet
.c_str());
774 // Should a single item auto-completion list automatically choose the item.
775 void wxStyledTextCtrl::AutoCompSetChooseSingle(bool chooseSingle
) {
776 SendMsg(2113, chooseSingle
, 0);
779 // Retrieve whether a single item auto-completion list automatically choose the item.
780 bool wxStyledTextCtrl::AutoCompGetChooseSingle() {
781 return SendMsg(2114, 0, 0) != 0;
784 // Set whether case is significant when performing auto-completion searches.
785 void wxStyledTextCtrl::AutoCompSetIgnoreCase(bool ignoreCase
) {
786 SendMsg(2115, ignoreCase
, 0);
789 // Retrieve state of ignore case flag.
790 bool wxStyledTextCtrl::AutoCompGetIgnoreCase() {
791 return SendMsg(2116, 0, 0) != 0;
794 // Display a list of strings and send notification when user chooses one.
795 void wxStyledTextCtrl::UserListShow(int listType
, const wxString
& itemList
) {
796 SendMsg(2117, listType
, (long)itemList
.c_str());
799 // Set whether or not autocompletion is hidden automatically when nothing matches
800 void wxStyledTextCtrl::AutoCompSetAutoHide(bool autoHide
) {
801 SendMsg(2118, autoHide
, 0);
804 // Retrieve whether or not autocompletion is hidden automatically when nothing matches
805 bool wxStyledTextCtrl::AutoCompGetAutoHide() {
806 return SendMsg(2119, 0, 0) != 0;
809 // Set the number of spaces used for one level of indentation.
810 void wxStyledTextCtrl::SetIndent(int indentSize
) {
811 SendMsg(2122, indentSize
, 0);
814 // Retrieve indentation size.
815 int wxStyledTextCtrl::GetIndent() {
816 return SendMsg(2123, 0, 0);
819 // Indentation will only use space characters if useTabs is false, otherwise
820 // it will use a combination of tabs and spaces.
821 void wxStyledTextCtrl::SetUseTabs(bool useTabs
) {
822 SendMsg(2124, useTabs
, 0);
825 // Retrieve whether tabs will be used in indentation.
826 bool wxStyledTextCtrl::GetUseTabs() {
827 return SendMsg(2125, 0, 0) != 0;
830 // Change the indentation of a line to a number of columns.
831 void wxStyledTextCtrl::SetLineIndentation(int line
, int indentSize
) {
832 SendMsg(2126, line
, indentSize
);
835 // Retrieve the number of columns that a line is indented.
836 int wxStyledTextCtrl::GetLineIndentation(int line
) {
837 return SendMsg(2127, line
, 0);
840 // Retrieve the position before the first non indentation character on a line.
841 int wxStyledTextCtrl::GetLineIndentPosition(int line
) {
842 return SendMsg(2128, line
, 0);
845 // Retrieve the column number of a position, taking tab width into account.
846 int wxStyledTextCtrl::GetColumn(int pos
) {
847 return SendMsg(2129, pos
, 0);
850 // Show or hide the horizontal scroll bar.
851 void wxStyledTextCtrl::SetUseHorizontalScrollBar(bool show
) {
852 SendMsg(2130, show
, 0);
855 // Is the horizontal scroll bar visible?
856 bool wxStyledTextCtrl::GetUseHorizontalScrollBar() {
857 return SendMsg(2131, 0, 0) != 0;
860 // Show or hide indentation guides.
861 void wxStyledTextCtrl::SetIndentationGuides(bool show
) {
862 SendMsg(2132, show
, 0);
865 // Are the indentation guides visible?
866 bool wxStyledTextCtrl::GetIndentationGuides() {
867 return SendMsg(2133, 0, 0) != 0;
870 // Set the highlighted indentation guide column.
871 // 0 = no highlighted guide.
872 void wxStyledTextCtrl::SetHighlightGuide(int column
) {
873 SendMsg(2134, column
, 0);
876 // Get the highlighted indentation guide column.
877 int wxStyledTextCtrl::GetHighlightGuide() {
878 return SendMsg(2135, 0, 0);
881 // Get the position after the last visible characters on a line.
882 int wxStyledTextCtrl::GetLineEndPosition(int line
) {
883 return SendMsg(2136, line
, 0);
886 // Get the code page used to interpret the bytes of the document as characters.
887 int wxStyledTextCtrl::GetCodePage() {
888 return SendMsg(2137, 0, 0);
891 // Get the foreground colour of the caret.
892 wxColour
wxStyledTextCtrl::GetCaretForeground() {
893 long c
= SendMsg(2138, 0, 0);
894 return wxColourFromLong(c
);
897 // In read-only mode?
898 bool wxStyledTextCtrl::GetReadOnly() {
899 return SendMsg(2140, 0, 0) != 0;
902 // Sets the position of the caret.
903 void wxStyledTextCtrl::SetCurrentPos(int pos
) {
904 SendMsg(2141, pos
, 0);
907 // Sets the position that starts the selection - this becomes the anchor.
908 void wxStyledTextCtrl::SetSelectionStart(int pos
) {
909 SendMsg(2142, pos
, 0);
912 // Returns the position at the start of the selection.
913 int wxStyledTextCtrl::GetSelectionStart() {
914 return SendMsg(2143, 0, 0);
917 // Sets the position that ends the selection - this becomes the currentPosition.
918 void wxStyledTextCtrl::SetSelectionEnd(int pos
) {
919 SendMsg(2144, pos
, 0);
922 // Returns the position at the end of the selection.
923 int wxStyledTextCtrl::GetSelectionEnd() {
924 return SendMsg(2145, 0, 0);
927 // Sets the print magnification added to the point size of each style for printing.
928 void wxStyledTextCtrl::SetPrintMagnification(int magnification
) {
929 SendMsg(2146, magnification
, 0);
932 // Returns the print magnification.
933 int wxStyledTextCtrl::GetPrintMagnification() {
934 return SendMsg(2147, 0, 0);
937 // Modify colours when printing for clearer printed text.
938 void wxStyledTextCtrl::SetPrintColourMode(int mode
) {
939 SendMsg(2148, mode
, 0);
942 // Returns the print colour mode.
943 int wxStyledTextCtrl::GetPrintColourMode() {
944 return SendMsg(2149, 0, 0);
947 // Find some text in the document.
948 int wxStyledTextCtrl::FindText(int minPos
, int maxPos
,
949 const wxString
& text
,
950 bool caseSensitive
, bool wholeWord
) {
954 flags
|= caseSensitive
? SCFIND_MATCHCASE
: 0;
955 flags
|= wholeWord
? SCFIND_WHOLEWORD
: 0;
956 ft
.chrg
.cpMin
= minPos
;
957 ft
.chrg
.cpMax
= maxPos
;
958 ft
.lpstrText
= (char*)text
.c_str();
960 return SendMsg(2150, flags
, (long)&ft
);
963 // On Windows will draw the document into a display context such as a printer.
964 int wxStyledTextCtrl::FormatRange(bool doDraw
,
968 wxDC
* target
, // Why does it use two? Can they be the same?
974 fr
.hdcTarget
= target
;
975 fr
.rc
.top
= renderRect
.GetTop();
976 fr
.rc
.left
= renderRect
.GetLeft();
977 fr
.rc
.right
= renderRect
.GetRight();
978 fr
.rc
.bottom
= renderRect
.GetBottom();
979 fr
.rcPage
.top
= pageRect
.GetTop();
980 fr
.rcPage
.left
= pageRect
.GetLeft();
981 fr
.rcPage
.right
= pageRect
.GetRight();
982 fr
.rcPage
.bottom
= pageRect
.GetBottom();
983 fr
.chrg
.cpMin
= startPos
;
984 fr
.chrg
.cpMax
= endPos
;
986 return SendMsg(2151, doDraw
, (long)&fr
);
989 // Retrieve the line at the top of the display.
990 int wxStyledTextCtrl::GetFirstVisibleLine() {
991 return SendMsg(2152, 0, 0);
994 // Retrieve the contents of a line.
995 wxString
wxStyledTextCtrl::GetLine(int line
) {
997 int len
= LineLength(line
);
999 char* buf
= text
.GetWriteBuf(len
);
1001 int pos
= SendMsg(2153, line
, (long)buf
);
1002 text
.UngetWriteBuf(len
);
1007 // Returns the number of lines in the document. There is always at least one.
1008 int wxStyledTextCtrl::GetLineCount() {
1009 return SendMsg(2154, 0, 0);
1012 // Sets the size in pixels of the left margin.
1013 void wxStyledTextCtrl::SetMarginLeft(int pixelWidth
) {
1014 SendMsg(2155, 0, pixelWidth
);
1017 // Returns the size in pixels of the left margin.
1018 int wxStyledTextCtrl::GetMarginLeft() {
1019 return SendMsg(2156, 0, 0);
1022 // Sets the size in pixels of the right margin.
1023 void wxStyledTextCtrl::SetMarginRight(int pixelWidth
) {
1024 SendMsg(2157, 0, pixelWidth
);
1027 // Returns the size in pixels of the right margin.
1028 int wxStyledTextCtrl::GetMarginRight() {
1029 return SendMsg(2158, 0, 0);
1032 // Is the document different from when it was last saved?
1033 bool wxStyledTextCtrl::GetModify() {
1034 return SendMsg(2159, 0, 0) != 0;
1037 // Select a range of text.
1038 void wxStyledTextCtrl::SetSelection(int start
, int end
) {
1039 SendMsg(2160, start
, end
);
1042 // Retrieve the selected text.
1043 wxString
wxStyledTextCtrl::GetSelectedText() {
1048 GetSelection(&start
, &end
);
1049 int len
= end
- start
;
1050 if (!len
) return "";
1051 char* buff
= text
.GetWriteBuf(len
);
1053 SendMsg(2161, 0, (long)buff
);
1054 text
.UngetWriteBuf(len
);
1058 // Retrieve a range of text.
1059 wxString
wxStyledTextCtrl::GetTextRange(int startPos
, int endPos
) {
1061 int len
= endPos
- startPos
;
1062 if (!len
) return "";
1063 char* buff
= text
.GetWriteBuf(len
);
1065 tr
.lpstrText
= buff
;
1066 tr
.chrg
.cpMin
= startPos
;
1067 tr
.chrg
.cpMax
= endPos
;
1069 SendMsg(2162, 0, (long)&tr
);
1070 text
.UngetWriteBuf(len
);
1074 // Draw the selection in normal style or with selection highlighted.
1075 void wxStyledTextCtrl::HideSelection(bool normal
) {
1076 SendMsg(2163, normal
, 0);
1079 // Retrieve the line containing a position.
1080 int wxStyledTextCtrl::LineFromPosition(int pos
) {
1081 return SendMsg(2166, pos
, 0);
1084 // Retrieve the position at the start of a line.
1085 int wxStyledTextCtrl::PositionFromLine(int line
) {
1086 return SendMsg(2167, line
, 0);
1089 // Scroll horizontally and vertically.
1090 void wxStyledTextCtrl::LineScroll(int columns
, int lines
) {
1091 SendMsg(2168, columns
, lines
);
1094 // Ensure the caret is visible.
1095 void wxStyledTextCtrl::EnsureCaretVisible() {
1096 SendMsg(2169, 0, 0);
1099 // Replace the selected text with the argument text.
1100 void wxStyledTextCtrl::ReplaceSelection(const wxString
& text
) {
1101 SendMsg(2170, 0, (long)text
.c_str());
1104 // Set to read only or read write.
1105 void wxStyledTextCtrl::SetReadOnly(bool readOnly
) {
1106 SendMsg(2171, readOnly
, 0);
1109 // Will a paste succeed?
1110 bool wxStyledTextCtrl::CanPaste() {
1111 return SendMsg(2173, 0, 0) != 0;
1114 // Are there any undoable actions in the undo history.
1115 bool wxStyledTextCtrl::CanUndo() {
1116 return SendMsg(2174, 0, 0) != 0;
1119 // Delete the undo history.
1120 void wxStyledTextCtrl::EmptyUndoBuffer() {
1121 SendMsg(2175, 0, 0);
1124 // Undo one action in the undo history.
1125 void wxStyledTextCtrl::Undo() {
1126 SendMsg(2176, 0, 0);
1129 // Cut the selection to the clipboard.
1130 void wxStyledTextCtrl::Cut() {
1131 SendMsg(2177, 0, 0);
1134 // Copy the selection to the clipboard.
1135 void wxStyledTextCtrl::Copy() {
1136 SendMsg(2178, 0, 0);
1139 // Paste the contents of the clipboard into the document replacing the selection.
1140 void wxStyledTextCtrl::Paste() {
1141 SendMsg(2179, 0, 0);
1144 // Clear the selection.
1145 void wxStyledTextCtrl::Clear() {
1146 SendMsg(2180, 0, 0);
1149 // Replace the contents of the document with the argument text.
1150 void wxStyledTextCtrl::SetText(const wxString
& text
) {
1151 SendMsg(2181, 0, (long)text
.c_str());
1154 // Retrieve all the text in the document.
1155 wxString
wxStyledTextCtrl::GetText() {
1157 int len
= GetTextLength();
1158 char* buff
= text
.GetWriteBuf(len
+1); // leave room for the null...
1160 SendMsg(2182, len
+1, (long)buff
);
1161 text
.UngetWriteBuf(len
);
1165 // Retrieve the number of characters in the document.
1166 int wxStyledTextCtrl::GetTextLength() {
1167 return SendMsg(2183, 0, 0);
1170 // Set to overtype (true) or insert mode
1171 void wxStyledTextCtrl::SetOvertype(bool overtype
) {
1172 SendMsg(2186, overtype
, 0);
1175 // Returns true if overtype mode is active otherwise false is returned.
1176 bool wxStyledTextCtrl::GetOvertype() {
1177 return SendMsg(2187, 0, 0) != 0;
1180 // Set the width of the insert mode caret
1181 void wxStyledTextCtrl::SetCaretWidth(int pixelWidth
) {
1182 SendMsg(2188, pixelWidth
, 0);
1185 // Returns the width of the insert mode caret
1186 int wxStyledTextCtrl::GetCaretWidth() {
1187 return SendMsg(2189, 0, 0);
1190 // Sets the position that starts the target which is used for updating the
1191 // document without affecting the scroll position.
1192 void wxStyledTextCtrl::SetTargetStart(int pos
) {
1193 SendMsg(2190, pos
, 0);
1196 // Get the position that starts the target.
1197 int wxStyledTextCtrl::GetTargetStart() {
1198 return SendMsg(2191, 0, 0);
1201 // Sets the position that ends the target which is used for updating the
1202 // document without affecting the scroll position.
1203 void wxStyledTextCtrl::SetTargetEnd(int pos
) {
1204 SendMsg(2192, pos
, 0);
1207 // Get the position that ends the target.
1208 int wxStyledTextCtrl::GetTargetEnd() {
1209 return SendMsg(2193, 0, 0);
1212 // Replace the target text with the argument text.
1213 // Text is counted so it can contain nulls.
1214 // Returns the length of the replacement text.
1216 int wxStyledTextCtrl::ReplaceTarget(const wxString
& text
) {
1217 return SendMsg(2194, text
.Len(), (long)text
.c_str());
1221 // Replace the target text with the argument text after \d processing.
1222 // Text is counted so it can contain nulls.
1223 // Looks for \d where d is between 1 and 9 and replaces these with the strings
1224 // matched in the last search operation which were surrounded by \( and \).
1225 // Returns the length of the replacement text including any change
1226 // caused by processing the \d patterns.
1228 int wxStyledTextCtrl::ReplaceTargetRE(const wxString
& text
) {
1229 return SendMsg(2195, text
.Len(), (long)text
.c_str());
1233 // Search for a counted string in the target and set the target to the found
1234 // range. Text is counted so it can contain nulls.
1235 // Returns length of range or -1 for failure in which case target is not moved.
1237 int wxStyledTextCtrl::SearchInTarget(const wxString
& text
) {
1238 return SendMsg(2197, text
.Len(), (long)text
.c_str());
1242 // Set the search flags used by SearchInTarget
1243 void wxStyledTextCtrl::SetSearchFlags(int flags
) {
1244 SendMsg(2198, flags
, 0);
1247 // Get the search flags used by SearchInTarget
1248 int wxStyledTextCtrl::GetSearchFlags() {
1249 return SendMsg(2199, 0, 0);
1252 // Show a call tip containing a definition near position pos.
1253 void wxStyledTextCtrl::CallTipShow(int pos
, const wxString
& definition
) {
1254 SendMsg(2200, pos
, (long)definition
.c_str());
1257 // Remove the call tip from the screen.
1258 void wxStyledTextCtrl::CallTipCancel() {
1259 SendMsg(2201, 0, 0);
1262 // Is there an active call tip?
1263 bool wxStyledTextCtrl::CallTipActive() {
1264 return SendMsg(2202, 0, 0) != 0;
1267 // Retrieve the position where the caret was before displaying the call tip.
1268 int wxStyledTextCtrl::CallTipPosAtStart() {
1269 return SendMsg(2203, 0, 0);
1272 // Highlight a segment of the definition.
1273 void wxStyledTextCtrl::CallTipSetHighlight(int start
, int end
) {
1274 SendMsg(2204, start
, end
);
1277 // Set the background colour for the call tip.
1278 void wxStyledTextCtrl::CallTipSetBackground(const wxColour
& back
) {
1279 SendMsg(2205, wxColourAsLong(back
), 0);
1282 // Find the display line of a document line taking hidden lines into account.
1283 int wxStyledTextCtrl::VisibleFromDocLine(int line
) {
1284 return SendMsg(2220, line
, 0);
1287 // Find the document line of a display line taking hidden lines into account.
1288 int wxStyledTextCtrl::DocLineFromVisible(int lineDisplay
) {
1289 return SendMsg(2221, lineDisplay
, 0);
1292 // Set the fold level of a line.
1293 // This encodes an integer level along with flags indicating whether the
1294 // line is a header and whether it is effectively white space.
1295 void wxStyledTextCtrl::SetFoldLevel(int line
, int level
) {
1296 SendMsg(2222, line
, level
);
1299 // Retrieve the fold level of a line.
1300 int wxStyledTextCtrl::GetFoldLevel(int line
) {
1301 return SendMsg(2223, line
, 0);
1304 // Find the last child line of a header line.
1305 int wxStyledTextCtrl::GetLastChild(int line
, int level
) {
1306 return SendMsg(2224, line
, level
);
1309 // Find the parent line of a child line.
1310 int wxStyledTextCtrl::GetFoldParent(int line
) {
1311 return SendMsg(2225, line
, 0);
1314 // Make a range of lines visible.
1315 void wxStyledTextCtrl::ShowLines(int lineStart
, int lineEnd
) {
1316 SendMsg(2226, lineStart
, lineEnd
);
1319 // Make a range of lines invisible.
1320 void wxStyledTextCtrl::HideLines(int lineStart
, int lineEnd
) {
1321 SendMsg(2227, lineStart
, lineEnd
);
1324 // Is a line visible?
1325 bool wxStyledTextCtrl::GetLineVisible(int line
) {
1326 return SendMsg(2228, line
, 0) != 0;
1329 // Show the children of a header line.
1330 void wxStyledTextCtrl::SetFoldExpanded(int line
, bool expanded
) {
1331 SendMsg(2229, line
, expanded
);
1334 // Is a header line expanded?
1335 bool wxStyledTextCtrl::GetFoldExpanded(int line
) {
1336 return SendMsg(2230, line
, 0) != 0;
1339 // Switch a header line between expanded and contracted.
1340 void wxStyledTextCtrl::ToggleFold(int line
) {
1341 SendMsg(2231, line
, 0);
1344 // Ensure a particular line is visible by expanding any header line hiding it.
1345 void wxStyledTextCtrl::EnsureVisible(int line
) {
1346 SendMsg(2232, line
, 0);
1349 // Set some debugging options for folding
1350 void wxStyledTextCtrl::SetFoldFlags(int flags
) {
1351 SendMsg(2233, flags
, 0);
1354 // Ensure a particular line is visible by expanding any header line hiding it.
1355 // Use the currently set visibility policy to determine which range to display.
1356 void wxStyledTextCtrl::EnsureVisibleEnforcePolicy(int line
) {
1357 SendMsg(2234, line
, 0);
1360 // Sets whether a tab pressed when caret is within indentation indents
1361 void wxStyledTextCtrl::SetTabIndents(bool tabIndents
) {
1362 SendMsg(2260, tabIndents
, 0);
1365 // Does a tab pressed when caret is within indentation indent?
1366 bool wxStyledTextCtrl::GetTabIndents() {
1367 return SendMsg(2261, 0, 0) != 0;
1370 // Sets whether a backspace pressed when caret is within indentation unindents
1371 void wxStyledTextCtrl::SetBackSpaceUnIndents(bool bsUnIndents
) {
1372 SendMsg(2262, bsUnIndents
, 0);
1375 // Does a backspace pressed when caret is within indentation unindent?
1376 bool wxStyledTextCtrl::GetBackSpaceUnIndents() {
1377 return SendMsg(2263, 0, 0) != 0;
1380 // Sets the time the mouse must sit still to generate a mouse dwell event
1381 void wxStyledTextCtrl::SetMouseDwellTime(int periodMilliseconds
) {
1382 SendMsg(2264, periodMilliseconds
, 0);
1385 // Retrieve the time the mouse must sit still to generate a mouse dwell event
1386 int wxStyledTextCtrl::GetMouseDwellTime() {
1387 return SendMsg(2265, 0, 0);
1390 // Move the caret inside current view if it's not there already
1391 void wxStyledTextCtrl::MoveCaretInsideView() {
1392 SendMsg(2401, 0, 0);
1395 // How many characters are on a line, not including end of line characters.
1396 int wxStyledTextCtrl::LineLength(int line
) {
1397 return SendMsg(2350, line
, 0);
1400 // Highlight the characters at two positions.
1401 void wxStyledTextCtrl::BraceHighlight(int pos1
, int pos2
) {
1402 SendMsg(2351, pos1
, pos2
);
1405 // Highlight the character at a position indicating there is no matching brace.
1406 void wxStyledTextCtrl::BraceBadLight(int pos
) {
1407 SendMsg(2352, pos
, 0);
1410 // Find the position of a matching brace or INVALID_POSITION if no match.
1411 int wxStyledTextCtrl::BraceMatch(int pos
) {
1412 return SendMsg(2353, pos
, 0);
1415 // Are the end of line characters visible.
1416 bool wxStyledTextCtrl::GetViewEOL() {
1417 return SendMsg(2355, 0, 0) != 0;
1420 // Make the end of line characters visible or invisible
1421 void wxStyledTextCtrl::SetViewEOL(bool visible
) {
1422 SendMsg(2356, visible
, 0);
1425 // Retrieve a pointer to the document object.
1426 void* wxStyledTextCtrl::GetDocPointer() {
1427 return (void*)SendMsg(2357);
1430 // Change the document object used.
1431 void wxStyledTextCtrl::SetDocPointer(void* docPointer
) {
1432 SendMsg(2358, 0, (long)docPointer
);
1435 // Set which document modification events are sent to the container.
1436 void wxStyledTextCtrl::SetModEventMask(int mask
) {
1437 SendMsg(2359, mask
, 0);
1440 // Retrieve the column number which text should be kept within.
1441 int wxStyledTextCtrl::GetEdgeColumn() {
1442 return SendMsg(2360, 0, 0);
1445 // Set the column number of the edge.
1446 // If text goes past the edge then it is highlighted.
1447 void wxStyledTextCtrl::SetEdgeColumn(int column
) {
1448 SendMsg(2361, column
, 0);
1451 // Retrieve the edge highlight mode.
1452 int wxStyledTextCtrl::GetEdgeMode() {
1453 return SendMsg(2362, 0, 0);
1456 // The edge may be displayed by a line (EDGE_LINE) or by highlighting text that
1457 // goes beyond it (EDGE_BACKGROUND) or not displayed at all (EDGE_NONE).
1458 void wxStyledTextCtrl::SetEdgeMode(int mode
) {
1459 SendMsg(2363, mode
, 0);
1462 // Retrieve the colour used in edge indication.
1463 wxColour
wxStyledTextCtrl::GetEdgeColour() {
1464 long c
= SendMsg(2364, 0, 0);
1465 return wxColourFromLong(c
);
1468 // Change the colour used in edge indication.
1469 void wxStyledTextCtrl::SetEdgeColour(const wxColour
& edgeColour
) {
1470 SendMsg(2365, wxColourAsLong(edgeColour
), 0);
1473 // Sets the current caret position to be the search anchor.
1474 void wxStyledTextCtrl::SearchAnchor() {
1475 SendMsg(2366, 0, 0);
1478 // Find some text starting at the search anchor.
1479 // Does not ensure the selection is visible.
1480 int wxStyledTextCtrl::SearchNext(int flags
, const wxString
& text
) {
1481 return SendMsg(2367, flags
, (long)text
.c_str());
1484 // Find some text starting at the search anchor and moving backwards.
1485 // Does not ensure the selection is visible.
1486 int wxStyledTextCtrl::SearchPrev(int flags
, const wxString
& text
) {
1487 return SendMsg(2368, flags
, (long)text
.c_str());
1490 // Set the way the line the caret is on is kept visible.
1491 void wxStyledTextCtrl::SetCaretPolicy(int caretPolicy
, int caretSlop
) {
1492 SendMsg(2369, caretPolicy
, caretSlop
);
1495 // Retrieves the number of lines completely visible.
1496 int wxStyledTextCtrl::LinesOnScreen() {
1497 return SendMsg(2370, 0, 0);
1500 // Set whether a pop up menu is displayed automatically when the user presses
1501 // the wrong mouse button.
1502 void wxStyledTextCtrl::UsePopUp(bool allowPopUp
) {
1503 SendMsg(2371, allowPopUp
, 0);
1506 // Is the selection a rectangular. The alternative is the more common stream selection.
1507 bool wxStyledTextCtrl::SelectionIsRectangle() {
1508 return SendMsg(2372, 0, 0) != 0;
1511 // Set the zoom level. This number of points is added to the size of all fonts.
1512 // It may be positive to magnify or negative to reduce.
1513 void wxStyledTextCtrl::SetZoom(int zoom
) {
1514 SendMsg(2373, zoom
, 0);
1517 // Retrieve the zoom level.
1518 int wxStyledTextCtrl::GetZoom() {
1519 return SendMsg(2374, 0, 0);
1522 // Create a new document object.
1523 // Starts with reference count of 1 and not selected into editor.
1524 void* wxStyledTextCtrl::CreateDocument() {
1525 return (void*)SendMsg(2375);
1528 // Extend life of document.
1529 void wxStyledTextCtrl::AddRefDocument(void* docPointer
) {
1530 SendMsg(2376, (long)docPointer
);
1533 // Release a reference to the document, deleting document if it fades to black.
1534 void wxStyledTextCtrl::ReleaseDocument(void* docPointer
) {
1535 SendMsg(2377, (long)docPointer
);
1538 // Get which document modification events are sent to the container.
1539 int wxStyledTextCtrl::GetModEventMask() {
1540 return SendMsg(2378, 0, 0);
1543 // Change internal focus flag
1544 void wxStyledTextCtrl::SetSTCFocus(bool focus
) {
1545 SendMsg(2380, focus
, 0);
1548 // Get internal focus flag
1549 bool wxStyledTextCtrl::GetSTCFocus() {
1550 return SendMsg(2381, 0, 0) != 0;
1553 // Change error status - 0 = OK
1554 void wxStyledTextCtrl::SetStatus(int statusCode
) {
1555 SendMsg(2382, statusCode
, 0);
1559 int wxStyledTextCtrl::GetStatus() {
1560 return SendMsg(2383, 0, 0);
1563 // Set whether the mouse is captured when its button is pressed
1564 void wxStyledTextCtrl::SetMouseDownCaptures(bool captures
) {
1565 SendMsg(2384, captures
, 0);
1568 // Get whether mouse gets captured
1569 bool wxStyledTextCtrl::GetMouseDownCaptures() {
1570 return SendMsg(2385, 0, 0) != 0;
1573 // Sets the cursor to one of the SC_CURSOR* values
1574 void wxStyledTextCtrl::SetCursor(int cursorType
) {
1575 SendMsg(2386, cursorType
, 0);
1579 int wxStyledTextCtrl::GetCursor() {
1580 return SendMsg(2387, 0, 0);
1583 // Move to the previous change in capitalistion
1584 void wxStyledTextCtrl::WordPartLeft() {
1585 SendMsg(2390, 0, 0);
1588 // Move to the previous change in capitalistion extending selection to new caret position.
1589 void wxStyledTextCtrl::WordPartLeftExtend() {
1590 SendMsg(2391, 0, 0);
1593 // Move to the change next in capitalistion
1594 void wxStyledTextCtrl::WordPartRight() {
1595 SendMsg(2392, 0, 0);
1598 // Move to the next change in capitalistion extending selection to new caret position.
1599 void wxStyledTextCtrl::WordPartRightExtend() {
1600 SendMsg(2393, 0, 0);
1603 // Set the way the display area is determined when a particular line is to be moved to.
1604 void wxStyledTextCtrl::SetVisiblePolicy(int visiblePolicy
, int visibleSlop
) {
1605 SendMsg(2394, visiblePolicy
, visibleSlop
);
1608 // Delete back from the current position to the start of the line
1609 void wxStyledTextCtrl::DelLineLeft() {
1610 SendMsg(2395, 0, 0);
1613 // Delete forwards from the current position to the end of the line
1614 void wxStyledTextCtrl::DelLineRight() {
1615 SendMsg(2396, 0, 0);
1618 // Start notifying the container of all key presses and commands.
1619 void wxStyledTextCtrl::StartRecord() {
1620 SendMsg(3001, 0, 0);
1623 // Stop notifying the container of all key presses and commands.
1624 void wxStyledTextCtrl::StopRecord() {
1625 SendMsg(3002, 0, 0);
1628 // Set the lexing language of the document.
1629 void wxStyledTextCtrl::SetLexer(int lexer
) {
1630 SendMsg(4001, lexer
, 0);
1633 // Retrieve the lexing language of the document.
1634 int wxStyledTextCtrl::GetLexer() {
1635 return SendMsg(4002, 0, 0);
1638 // Colourise a segment of the document using the current lexing language.
1639 void wxStyledTextCtrl::Colourise(int start
, int end
) {
1640 SendMsg(4003, start
, end
);
1643 // Set up a value that may be used by a lexer for some optional feature.
1644 void wxStyledTextCtrl::SetProperty(const wxString
& key
, const wxString
& value
) {
1645 SendMsg(4004, (long)key
.c_str(), (long)value
.c_str());
1648 // Set up the key words used by the lexer.
1649 void wxStyledTextCtrl::SetKeyWords(int keywordSet
, const wxString
& keyWords
) {
1650 SendMsg(4005, keywordSet
, (long)keyWords
.c_str());
1653 // Set the lexing language of the document based on string name.
1654 void wxStyledTextCtrl::SetLexerLanguage(const wxString
& language
) {
1655 SendMsg(4006, 0, (long)language
.c_str());
1658 // END of generated section
1659 //----------------------------------------------------------------------
1662 // Returns the line number of the line with the caret.
1663 int wxStyledTextCtrl::GetCurrentLine() {
1664 int line
= LineFromPosition(GetCurrentPos());
1669 // Extract style settings from a spec-string which is composed of one or
1670 // more of the following comma separated elements:
1672 // bold turns on bold
1673 // italic turns on italics
1674 // fore:#RRGGBB sets the foreground colour
1675 // back:#RRGGBB sets the background colour
1676 // face:[facename] sets the font face name to use
1677 // size:[num] sets the font size in points
1678 // eol turns on eol filling
1679 // underline turns on underlining
1681 void wxStyledTextCtrl::StyleSetSpec(int styleNum
, const wxString
& spec
) {
1683 wxStringTokenizer
tkz(spec
, ",");
1684 while (tkz
.HasMoreTokens()) {
1685 wxString token
= tkz
.GetNextToken();
1687 wxString option
= token
.BeforeFirst(':');
1688 wxString val
= token
.AfterFirst(':');
1690 if (option
== "bold")
1691 StyleSetBold(styleNum
, true);
1693 else if (option
== "italic")
1694 StyleSetItalic(styleNum
, true);
1696 else if (option
== "underline")
1697 StyleSetUnderline(styleNum
, true);
1699 else if (option
== "eol")
1700 StyleSetEOLFilled(styleNum
, true);
1702 else if (option
== "size") {
1704 if (val
.ToLong(&points
))
1705 StyleSetSize(styleNum
, points
);
1708 else if (option
== "face")
1709 StyleSetFaceName(styleNum
, val
);
1711 else if (option
== "fore")
1712 StyleSetForeground(styleNum
, wxColourFromSpec(val
));
1714 else if (option
== "back")
1715 StyleSetBackground(styleNum
, wxColourFromSpec(val
));
1720 // Set style size, face, bold, italic, and underline attributes from
1721 // a wxFont's attributes.
1722 void wxStyledTextCtrl::StyleSetFont(int styleNum
, wxFont
& font
) {
1723 int size
= font
.GetPointSize();
1724 wxString faceName
= font
.GetFaceName();
1725 bool bold
= font
.GetWeight() == wxBOLD
;
1726 bool italic
= font
.GetStyle() != wxNORMAL
;
1727 bool under
= font
.GetUnderlined();
1729 // TODO: add encoding/charset mapping
1730 StyleSetFontAttr(styleNum
, size
, faceName
, bold
, italic
, under
);
1733 // Set all font style attributes at once.
1734 void wxStyledTextCtrl::StyleSetFontAttr(int styleNum
, int size
,
1735 const wxString
& faceName
,
1736 bool bold
, bool italic
,
1738 StyleSetSize(styleNum
, size
);
1739 StyleSetFaceName(styleNum
, faceName
);
1740 StyleSetBold(styleNum
, bold
);
1741 StyleSetItalic(styleNum
, italic
);
1742 StyleSetUnderline(styleNum
, underline
);
1744 // TODO: add encoding/charset mapping
1748 // Perform one of the operations defined by the wxSTC_CMD_* constants.
1749 void wxStyledTextCtrl::CmdKeyExecute(int cmd
) {
1754 // Set the left and right margin in the edit area, measured in pixels.
1755 void wxStyledTextCtrl::SetMargins(int left
, int right
) {
1756 SetMarginLeft(left
);
1757 SetMarginRight(right
);
1761 // Retrieve the start and end positions of the current selection.
1762 void wxStyledTextCtrl::GetSelection(int* startPos
, int* endPos
) {
1763 if (startPos
!= NULL
)
1764 *startPos
= SendMsg(SCI_GETSELECTIONSTART
);
1766 *endPos
= SendMsg(SCI_GETSELECTIONEND
);
1770 // Retrieve the point in the window where a position is displayed.
1771 wxPoint
wxStyledTextCtrl::PointFromPosition(int pos
) {
1772 int x
= SendMsg(SCI_POINTXFROMPOSITION
, 0, pos
);
1773 int y
= SendMsg(SCI_POINTYFROMPOSITION
, 0, pos
);
1774 return wxPoint(x
, y
);
1777 // Scroll enough to make the given line visible
1778 void wxStyledTextCtrl::ScrollToLine(int line
) {
1779 m_swx
->DoScrollToLine(line
);
1783 // Scroll enough to make the given column visible
1784 void wxStyledTextCtrl::ScrollToColumn(int column
) {
1785 m_swx
->DoScrollToColumn(column
);
1790 //----------------------------------------------------------------------
1793 void wxStyledTextCtrl::OnPaint(wxPaintEvent
& evt
) {
1795 wxRegion region
= GetUpdateRegion();
1797 m_swx
->DoPaint(&dc
, region
.GetBox());
1800 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent
& evt
) {
1801 if (evt
.GetOrientation() == wxHORIZONTAL
)
1802 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
1804 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
1807 void wxStyledTextCtrl::OnScroll(wxScrollEvent
& evt
) {
1808 wxScrollBar
* sb
= wxDynamicCast(evt
.GetEventObject(), wxScrollBar
);
1810 if (sb
->IsVertical())
1811 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
1813 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
1817 void wxStyledTextCtrl::OnSize(wxSizeEvent
& evt
) {
1818 wxSize sz
= GetClientSize();
1819 m_swx
->DoSize(sz
.x
, sz
.y
);
1822 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent
& evt
) {
1823 wxPoint pt
= evt
.GetPosition();
1824 m_swx
->DoButtonDown(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1825 evt
.ShiftDown(), evt
.ControlDown(), evt
.AltDown());
1828 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent
& evt
) {
1829 wxPoint pt
= evt
.GetPosition();
1830 m_swx
->DoButtonMove(Point(pt
.x
, pt
.y
));
1833 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent
& evt
) {
1834 wxPoint pt
= evt
.GetPosition();
1835 m_swx
->DoButtonUp(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1840 void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent
& evt
) {
1841 wxPoint pt
= evt
.GetPosition();
1842 ScreenToClient(&pt
.x
, &pt
.y
);
1843 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
1847 void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent
& evt
) {
1848 m_swx
->DoMouseWheel(evt
.GetWheelRotation(),
1849 evt
.GetWheelDelta(),
1850 evt
.GetLinesPerAction(),
1855 void wxStyledTextCtrl::OnChar(wxKeyEvent
& evt
) {
1856 long key
= evt
.KeyCode();
1858 // printf("OnChar key:%d consumed:%d ctrl:%d alt:%d\n",
1859 // key, m_lastKeyDownConsumed, evt.ControlDown(), evt.AltDown());
1862 // \|@#¬[]{}?£$~ ã,õ,Ã,Õ, ñ, Ñ
1864 // On (some?) non-US keyboards the AltGr key is required to enter some
1865 // common characters. It comes to us as both Alt and Ctrl down so we need
1866 // to let the char through in that case, otherwise if only ctrl or only
1867 // alt let's skip it.
1868 bool ctrl
= evt
.ControlDown();
1869 bool alt
= evt
.AltDown();
1870 bool skip
= ((ctrl
|| alt
) && ! (ctrl
&& alt
));
1872 if (key
<= 0xff && !iscntrl(key
) && !m_lastKeyDownConsumed
&& !skip
) {
1873 m_swx
->DoAddChar(key
);
1880 void wxStyledTextCtrl::OnKeyDown(wxKeyEvent
& evt
) {
1881 long key
= evt
.KeyCode();
1882 bool shift
= evt
.ShiftDown(),
1883 ctrl
= evt
.ControlDown(),
1884 alt
= evt
.AltDown();
1886 int processed
= m_swx
->DoKeyDown(key
, shift
, ctrl
, alt
, &m_lastKeyDownConsumed
);
1888 // printf("key: %d shift: %d ctrl: %d alt: %d processed: %d consumed: %d\n",
1889 // key, shift, ctrl, alt, processed, m_lastKeyDownConsumed);
1891 if (!processed
&& !m_lastKeyDownConsumed
)
1896 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent
& evt
) {
1897 m_swx
->DoLoseFocus();
1901 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent
& evt
) {
1902 m_swx
->DoGainFocus();
1906 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& evt
) {
1907 m_swx
->DoSysColourChange();
1911 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent
& evt
) {
1912 // do nothing to help avoid flashing
1917 void wxStyledTextCtrl::OnMenu(wxCommandEvent
& evt
) {
1918 m_swx
->DoCommand(evt
.GetId());
1922 void wxStyledTextCtrl::OnListBox(wxCommandEvent
& evt
) {
1923 m_swx
->DoOnListBox();
1927 //----------------------------------------------------------------------
1928 // Turn notifications from Scintilla into events
1931 void wxStyledTextCtrl::NotifyChange() {
1932 wxStyledTextEvent
evt(wxEVT_STC_CHANGE
, GetId());
1933 evt
.SetEventObject(this);
1934 GetEventHandler()->ProcessEvent(evt
);
1937 void wxStyledTextCtrl::NotifyParent(SCNotification
* _scn
) {
1938 SCNotification
& scn
= *_scn
;
1939 wxStyledTextEvent
evt(0, GetId());
1941 evt
.SetEventObject(this);
1942 evt
.SetPosition(scn
.position
);
1944 evt
.SetModifiers(scn
.modifiers
);
1946 switch (scn
.nmhdr
.code
) {
1947 case SCN_STYLENEEDED
:
1948 evt
.SetEventType(wxEVT_STC_STYLENEEDED
);
1952 evt
.SetEventType(wxEVT_STC_CHARADDED
);
1955 case SCN_SAVEPOINTREACHED
:
1956 evt
.SetEventType(wxEVT_STC_SAVEPOINTREACHED
);
1959 case SCN_SAVEPOINTLEFT
:
1960 evt
.SetEventType(wxEVT_STC_SAVEPOINTLEFT
);
1963 case SCN_MODIFYATTEMPTRO
:
1964 evt
.SetEventType(wxEVT_STC_ROMODIFYATTEMPT
);
1968 evt
.SetEventType(wxEVT_STC_KEY
);
1971 case SCN_DOUBLECLICK
:
1972 evt
.SetEventType(wxEVT_STC_DOUBLECLICK
);
1976 evt
.SetEventType(wxEVT_STC_UPDATEUI
);
1980 evt
.SetEventType(wxEVT_STC_MODIFIED
);
1981 evt
.SetModificationType(scn
.modificationType
);
1983 evt
.SetText(wxString(scn
.text
, scn
.length
));
1984 evt
.SetLength(scn
.length
);
1985 evt
.SetLinesAdded(scn
.linesAdded
);
1986 evt
.SetLine(scn
.line
);
1987 evt
.SetFoldLevelNow(scn
.foldLevelNow
);
1988 evt
.SetFoldLevelPrev(scn
.foldLevelPrev
);
1991 case SCN_MACRORECORD
:
1992 evt
.SetEventType(wxEVT_STC_MACRORECORD
);
1993 evt
.SetMessage(scn
.message
);
1994 evt
.SetWParam(scn
.wParam
);
1995 evt
.SetLParam(scn
.lParam
);
1998 case SCN_MARGINCLICK
:
1999 evt
.SetEventType(wxEVT_STC_MARGINCLICK
);
2000 evt
.SetMargin(scn
.margin
);
2004 evt
.SetEventType(wxEVT_STC_NEEDSHOWN
);
2005 evt
.SetLength(scn
.length
);
2008 case SCN_POSCHANGED
:
2009 evt
.SetEventType(wxEVT_STC_POSCHANGED
);
2013 evt
.SetEventType(wxEVT_STC_PAINTED
);
2016 case SCN_USERLISTSELECTION
:
2017 evt
.SetEventType(wxEVT_STC_USERLISTSELECTION
);
2018 evt
.SetListType(scn
.listType
);
2019 evt
.SetText(scn
.text
);
2022 case SCN_URIDROPPED
:
2023 evt
.SetEventType(wxEVT_STC_URIDROPPED
);
2024 evt
.SetText(scn
.text
);
2027 case SCN_DWELLSTART
:
2028 evt
.SetEventType(wxEVT_STC_DWELLSTART
);
2034 evt
.SetEventType(wxEVT_STC_DWELLEND
);
2043 GetEventHandler()->ProcessEvent(evt
);
2047 //----------------------------------------------------------------------
2048 //----------------------------------------------------------------------
2049 //----------------------------------------------------------------------
2051 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType
, int id
)
2052 : wxCommandEvent(commandType
, id
)
2057 m_modificationType
= 0;
2062 m_foldLevelPrev
= 0;
2070 #if wxUSE_DRAG_AND_DROP
2071 m_dragAllowMove
= FALSE
;
2072 m_dragResult
= wxDragNone
;
2076 bool wxStyledTextEvent::GetShift() const { return (m_modifiers
& SCI_SHIFT
) != 0; }
2077 bool wxStyledTextEvent::GetControl() const { return (m_modifiers
& SCI_CTRL
) != 0; }
2078 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers
& SCI_ALT
) != 0; }
2081 wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent
& event
):
2082 wxCommandEvent(event
)
2084 m_position
= event
.m_position
;
2085 m_key
= event
.m_key
;
2086 m_modifiers
= event
.m_modifiers
;
2087 m_modificationType
= event
.m_modificationType
;
2088 m_text
= event
.m_text
;
2089 m_length
= event
.m_length
;
2090 m_linesAdded
= event
.m_linesAdded
;
2091 m_line
= event
.m_line
;
2092 m_foldLevelNow
= event
.m_foldLevelNow
;
2093 m_foldLevelPrev
= event
.m_foldLevelPrev
;
2095 m_margin
= event
.m_margin
;
2097 m_message
= event
.m_message
;
2098 m_wParam
= event
.m_wParam
;
2099 m_lParam
= event
.m_lParam
;
2101 m_listType
= event
.m_listType
;
2105 #if wxUSE_DRAG_AND_DROP
2106 m_dragText
= event
.m_dragText
;
2107 m_dragAllowMove
=event
.m_dragAllowMove
;
2108 m_dragResult
= event
.m_dragResult
;
2112 //----------------------------------------------------------------------
2113 //----------------------------------------------------------------------