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 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
;
65 //----------------------------------------------------------------------
67 const wxChar
* wxSTCNameStr
= "stcwindow";
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
)
88 IMPLEMENT_CLASS(wxStyledTextCtrl
, wxControl
)
89 IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent
, wxCommandEvent
)
91 //----------------------------------------------------------------------
92 // Constructor and Destructor
94 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow
*parent
,
99 const wxString
& name
) :
100 wxControl(parent
, id
, pos
, size
,
101 style
| wxVSCROLL
| wxHSCROLL
| wxWANTS_CHARS
,
102 wxDefaultValidator
, name
)
104 m_swx
= new ScintillaWX(this);
109 wxStyledTextCtrl::~wxStyledTextCtrl() {
114 //----------------------------------------------------------------------
116 long wxStyledTextCtrl::SendMsg(int msg
, long wp
, long lp
) {
118 return m_swx
->WndProc(msg
, wp
, lp
);
122 #define MAKELONG(a, b) ((a) | ((b) << 16))
125 static long wxColourAsLong(const wxColour
& co
) {
126 return (((long)co
.Blue() << 16) |
127 ((long)co
.Green() << 8) |
131 static wxColour
wxColourFromLong(long c
) {
133 clr
.Set(c
& 0xff, (c
>> 8) & 0xff, (c
>> 16) & 0xff);
138 static wxColour
wxColourFromSpec(const wxString
& spec
) {
139 // spec should be #RRGGBB
141 int red
= strtol(spec
.Mid(1,2), &junk
, 16);
142 int green
= strtol(spec
.Mid(3,2), &junk
, 16);
143 int blue
= strtol(spec
.Mid(5,2), &junk
, 16);
144 return wxColour(red
, green
, blue
);
148 //----------------------------------------------------------------------
149 // BEGIN generated section. The following code is automatically generated
150 // by gen_iface.py from the contents of Scintilla.iface. Do not edit
151 // this file. Edit stc.cpp.in or gen_iface.py instead and regenerate.
154 // Add text to the document
155 void wxStyledTextCtrl::AddText(const wxString
& text
) {
156 SendMsg(2001, text
.Len(), (long)text
.c_str());
159 // Add array of cells to document
160 void wxStyledTextCtrl::AddStyledText(const wxString
& text
) {
161 SendMsg(2002, text
.Len(), (long)text
.c_str());
164 // Insert string at a position
165 void wxStyledTextCtrl::InsertText(int pos
, const wxString
& text
) {
166 SendMsg(2003, pos
, (long)text
.c_str());
169 // Delete all text in the document
170 void wxStyledTextCtrl::ClearAll() {
174 // Set all style bytes to 0, remove all folding information
175 void wxStyledTextCtrl::ClearDocumentStyle() {
179 // The number of characters in the document
180 int wxStyledTextCtrl::GetLength() {
181 return SendMsg(2006, 0, 0);
184 // Returns the character byte at the position
185 int wxStyledTextCtrl::GetCharAt(int pos
) {
186 return SendMsg(2007, pos
, 0);
189 // Returns the position of the caret
190 int wxStyledTextCtrl::GetCurrentPos() {
191 return SendMsg(2008, 0, 0);
194 // Returns the position of the opposite end of the selection to the caret
195 int wxStyledTextCtrl::GetAnchor() {
196 return SendMsg(2009, 0, 0);
199 // Returns the style byte at the position
200 int wxStyledTextCtrl::GetStyleAt(int pos
) {
201 return SendMsg(2010, pos
, 0);
204 // Redoes the next action on the undo history
205 void wxStyledTextCtrl::Redo() {
209 // Choose between collecting actions into the undo
210 // history and discarding them.
211 void wxStyledTextCtrl::SetUndoCollection(bool collectUndo
) {
212 SendMsg(2012, collectUndo
, 0);
215 // Select all the text in the document.
216 void wxStyledTextCtrl::SelectAll() {
220 // Remember the current position in the undo history as the position
221 // at which the document was saved.
222 void wxStyledTextCtrl::SetSavePoint() {
226 // Retrieve a buffer of cells.
227 wxString
wxStyledTextCtrl::GetStyledText(int startPos
, int endPos
) {
229 int len
= endPos
- startPos
;
231 tr
.lpstrText
= text
.GetWriteBuf(len
*2+1);
232 tr
.chrg
.cpMin
= startPos
;
233 tr
.chrg
.cpMax
= endPos
;
234 SendMsg(2015, 0, (long)&tr
);
235 text
.UngetWriteBuf(len
*2);
239 // Are there any redoable actions in the undo history.
240 bool wxStyledTextCtrl::CanRedo() {
241 return SendMsg(2016, 0, 0) != 0;
244 // Retrieve the line number at which a particular marker is located
245 int wxStyledTextCtrl::MarkerLineFromHandle(int handle
) {
246 return SendMsg(2017, handle
, 0);
250 void wxStyledTextCtrl::MarkerDeleteHandle(int handle
) {
251 SendMsg(2018, handle
, 0);
254 // Is undo history being collected?
255 bool wxStyledTextCtrl::GetUndoCollection() {
256 return SendMsg(2019, 0, 0) != 0;
259 // Are white space characters currently visible?
260 // Returns one of SCWS_* constants.
261 int wxStyledTextCtrl::GetViewWhiteSpace() {
262 return SendMsg(2020, 0, 0);
265 // Make white space characters invisible, always visible or visible outside indentation.
266 void wxStyledTextCtrl::SetViewWhiteSpace(int viewWS
) {
267 SendMsg(2021, viewWS
, 0);
270 // Find the position from a point within the window.
271 int wxStyledTextCtrl::PositionFromPoint(wxPoint pt
) {
272 return SendMsg(2022, pt
.x
, pt
.y
);
275 // Set caret to start of a line and ensure it is visible.
276 void wxStyledTextCtrl::GotoLine(int line
) {
277 SendMsg(2024, line
, 0);
280 // Set caret to a position and ensure it is visible.
281 void wxStyledTextCtrl::GotoPos(int pos
) {
282 SendMsg(2025, pos
, 0);
285 // Set the selection anchor to a position. The anchor is the opposite
286 // end of the selection from the caret.
287 void wxStyledTextCtrl::SetAnchor(int posAnchor
) {
288 SendMsg(2026, posAnchor
, 0);
291 // Retrieve the text of the line containing the caret.
292 // Returns the index of the caret on the line.
293 wxString
wxStyledTextCtrl::GetCurLine(int* linePos
) {
295 int len
= LineLength(GetCurrentLine());
296 char* buf
= text
.GetWriteBuf(len
+1);
298 int pos
= SendMsg(2027, len
, (long)buf
);
299 text
.UngetWriteBuf();
300 if (linePos
) *linePos
= pos
;
305 // Retrieve the position of the last correctly styled character.
306 int wxStyledTextCtrl::GetEndStyled() {
307 return SendMsg(2028, 0, 0);
310 // Convert all line endings in the document to use the current mode.
311 void wxStyledTextCtrl::ConvertEOLs() {
315 // Retrieve the current end of line mode - one of CRLF, CR, or LF.
316 int wxStyledTextCtrl::GetEOLMode() {
317 return SendMsg(2030, 0, 0);
320 // Set the current end of line mode.
321 void wxStyledTextCtrl::SetEOLMode(int eolMode
) {
322 SendMsg(2031, eolMode
, 0);
325 // Set the current styling position to pos and the styling mask to mask.
326 // The styling mask can be used to protect some bits in each styling byte from
328 void wxStyledTextCtrl::StartStyling(int pos
, int mask
) {
329 SendMsg(2032, pos
, mask
);
332 // Change style from current styling position for length characters to a style
333 // and move the current styling position to after this newly styled segment.
334 void wxStyledTextCtrl::SetStyling(int length
, int style
) {
335 SendMsg(2033, length
, style
);
338 // Is drawing done first into a buffer or direct to the screen.
339 bool wxStyledTextCtrl::GetBufferedDraw() {
340 return SendMsg(2034, 0, 0) != 0;
343 // If drawing is buffered then each line of text is drawn into a bitmap buffer
344 // before drawing it to the screen to avoid flicker.
345 void wxStyledTextCtrl::SetBufferedDraw(bool buffered
) {
346 SendMsg(2035, buffered
, 0);
349 // Change the visible size of a tab to be a multiple of the width of a space
351 void wxStyledTextCtrl::SetTabWidth(int tabWidth
) {
352 SendMsg(2036, tabWidth
, 0);
355 // Retrieve the visible size of a tab.
356 int wxStyledTextCtrl::GetTabWidth() {
357 return SendMsg(2121, 0, 0);
360 // Set the code page used to interpret the bytes of the document as characters.
361 // The SC_CP_UTF8 value can be used to enter Unicode mode.
362 void wxStyledTextCtrl::SetCodePage(int codePage
) {
363 SendMsg(2037, codePage
, 0);
366 // Set the symbol used for a particular marker number,
367 // and optionally the for and background colours.
368 void wxStyledTextCtrl::MarkerDefine(int markerNumber
, int markerSymbol
,
369 const wxColour
& foreground
,
370 const wxColour
& background
) {
372 SendMsg(2040, markerNumber
, markerSymbol
);
374 MarkerSetForeground(markerNumber
, foreground
);
376 MarkerSetBackground(markerNumber
, background
);
379 // Set the foreground colour used for a particular marker number.
380 void wxStyledTextCtrl::MarkerSetForeground(int markerNumber
, const wxColour
& fore
) {
381 SendMsg(2041, markerNumber
, wxColourAsLong(fore
));
384 // Set the background colour used for a particular marker number.
385 void wxStyledTextCtrl::MarkerSetBackground(int markerNumber
, const wxColour
& back
) {
386 SendMsg(2042, markerNumber
, wxColourAsLong(back
));
389 // Add a marker to a line.
390 void wxStyledTextCtrl::MarkerAdd(int line
, int markerNumber
) {
391 SendMsg(2043, line
, markerNumber
);
394 // Delete a marker from a line
395 void wxStyledTextCtrl::MarkerDelete(int line
, int markerNumber
) {
396 SendMsg(2044, line
, markerNumber
);
399 // Delete all markers with a particular number from all lines
400 void wxStyledTextCtrl::MarkerDeleteAll(int markerNumber
) {
401 SendMsg(2045, markerNumber
, 0);
404 // Get a bit mask of all the markers set on a line.
405 int wxStyledTextCtrl::MarkerGet(int line
) {
406 return SendMsg(2046, line
, 0);
409 // Find the next line after lineStart that includes a marker in mask.
410 int wxStyledTextCtrl::MarkerNext(int lineStart
, int markerMask
) {
411 return SendMsg(2047, lineStart
, markerMask
);
414 // Find the previous line before lineStart that includes a marker in mask.
415 int wxStyledTextCtrl::MarkerPrevious(int lineStart
, int markerMask
) {
416 return SendMsg(2048, lineStart
, markerMask
);
419 // Set a margin to be either numeric or symbolic.
420 void wxStyledTextCtrl::SetMarginType(int margin
, int marginType
) {
421 SendMsg(2240, margin
, marginType
);
424 // Retrieve the type of a margin.
425 int wxStyledTextCtrl::GetMarginType(int margin
) {
426 return SendMsg(2241, margin
, 0);
429 // Set the width of a margin to a width expressed in pixels.
430 void wxStyledTextCtrl::SetMarginWidth(int margin
, int pixelWidth
) {
431 SendMsg(2242, margin
, pixelWidth
);
434 // Retrieve the width of a margin in pixels.
435 int wxStyledTextCtrl::GetMarginWidth(int margin
) {
436 return SendMsg(2243, margin
, 0);
439 // Set a mask that determines which markers are displayed in a margin.
440 void wxStyledTextCtrl::SetMarginMask(int margin
, int mask
) {
441 SendMsg(2244, margin
, mask
);
444 // Retrieve the marker mask of a margin.
445 int wxStyledTextCtrl::GetMarginMask(int margin
) {
446 return SendMsg(2245, margin
, 0);
449 // Make a margin sensitive or insensitive to mouse clicks.
450 void wxStyledTextCtrl::SetMarginSensitive(int margin
, bool sensitive
) {
451 SendMsg(2246, margin
, sensitive
);
454 // Retrieve the mouse click sensitivity of a margin.
455 bool wxStyledTextCtrl::GetMarginSensitive(int margin
) {
456 return SendMsg(2247, margin
, 0) != 0;
459 // Clear all the styles and make equivalent to the global default style.
460 void wxStyledTextCtrl::StyleClearAll() {
464 // Set the foreground colour of a style.
465 void wxStyledTextCtrl::StyleSetForeground(int style
, const wxColour
& fore
) {
466 SendMsg(2051, style
, wxColourAsLong(fore
));
469 // Set the background colour of a style.
470 void wxStyledTextCtrl::StyleSetBackground(int style
, const wxColour
& back
) {
471 SendMsg(2052, style
, wxColourAsLong(back
));
474 // Set a style to be bold or not.
475 void wxStyledTextCtrl::StyleSetBold(int style
, bool bold
) {
476 SendMsg(2053, style
, bold
);
479 // Set a style to be italic or not.
480 void wxStyledTextCtrl::StyleSetItalic(int style
, bool italic
) {
481 SendMsg(2054, style
, italic
);
484 // Set the size of characters of a style.
485 void wxStyledTextCtrl::StyleSetSize(int style
, int sizePoints
) {
486 SendMsg(2055, style
, sizePoints
);
489 // Set the font of a style.
490 void wxStyledTextCtrl::StyleSetFaceName(int style
, const wxString
& fontName
) {
491 SendMsg(2056, style
, (long)fontName
.c_str());
494 // Set a style to have its end of line filled or not.
495 void wxStyledTextCtrl::StyleSetEOLFilled(int style
, bool filled
) {
496 SendMsg(2057, style
, filled
);
499 // Reset the default style to its state at startup
500 void wxStyledTextCtrl::StyleResetDefault() {
504 // Set a style to be underlined or not.
505 void wxStyledTextCtrl::StyleSetUnderline(int style
, bool underline
) {
506 SendMsg(2059, style
, underline
);
509 // Set the foreground colour of the selection and whether to use this setting.
510 void wxStyledTextCtrl::SetSelForeground(bool useSetting
, const wxColour
& fore
) {
511 SendMsg(2067, useSetting
, wxColourAsLong(fore
));
514 // Set the background colour of the selection and whether to use this setting.
515 void wxStyledTextCtrl::SetSelBackground(bool useSetting
, const wxColour
& back
) {
516 SendMsg(2068, useSetting
, wxColourAsLong(back
));
519 // Set the foreground colour of the caret.
520 void wxStyledTextCtrl::SetCaretForeground(const wxColour
& fore
) {
521 SendMsg(2069, wxColourAsLong(fore
), 0);
524 // When key+modifier combination km is pressed perform msg.
525 void wxStyledTextCtrl::CmdKeyAssign(int key
, int modifiers
, int cmd
) {
526 SendMsg(2070, MAKELONG(key
, modifiers
), cmd
);
529 // When key+modifier combination km do nothing.
530 void wxStyledTextCtrl::CmdKeyClear(int key
, int modifiers
) {
531 SendMsg(2071, MAKELONG(key
, modifiers
));
534 // Drop all key mappings.
535 void wxStyledTextCtrl::CmdKeyClearAll() {
539 // Set the styles for a segment of the document.
540 void wxStyledTextCtrl::SetStyleBytes(int length
, char* styleBytes
) {
541 SendMsg(2073, length
, (long)styleBytes
);
544 // Set a style to be visible or not.
545 void wxStyledTextCtrl::StyleSetVisible(int style
, bool visible
) {
546 SendMsg(2074, style
, visible
);
549 // Get the time in milliseconds that the caret is on and off.
550 int wxStyledTextCtrl::GetCaretPeriod() {
551 return SendMsg(2075, 0, 0);
554 // Get the time in milliseconds that the caret is on and off. 0 = steady on.
555 void wxStyledTextCtrl::SetCaretPeriod(int periodMilliseconds
) {
556 SendMsg(2076, periodMilliseconds
, 0);
559 // Set the set of characters making up words for when moving or selecting
561 void wxStyledTextCtrl::SetWordChars(const wxString
& characters
) {
562 SendMsg(2077, 0, (long)characters
.c_str());
565 // Start a sequence of actions that is undone and redone as a unit.
567 void wxStyledTextCtrl::BeginUndoAction() {
571 // End a sequence of actions that is undone and redone as a unit.
572 void wxStyledTextCtrl::EndUndoAction() {
576 // Set an indicator to plain, squiggle or TT.
577 void wxStyledTextCtrl::IndicatorSetStyle(int indic
, int style
) {
578 SendMsg(2080, indic
, style
);
581 // Retrieve the style of an indicator.
582 int wxStyledTextCtrl::IndicatorGetStyle(int indic
) {
583 return SendMsg(2081, indic
, 0);
586 // Set the foreground colour of an indicator.
587 void wxStyledTextCtrl::IndicatorSetForeground(int indic
, const wxColour
& fore
) {
588 SendMsg(2082, indic
, wxColourAsLong(fore
));
591 // Retrieve the foreground colour of an indicator.
592 wxColour
wxStyledTextCtrl::IndicatorGetForeground(int indic
) {
593 long c
= SendMsg(2083, indic
, 0);
594 return wxColourFromLong(c
);
597 // Divide each styling byte into lexical class bits (default:5) and indicator
598 // bits (default:3). If a lexer requires more than 32 lexical states, then this
599 // is used to expand the possible states.
600 void wxStyledTextCtrl::SetStyleBits(int bits
) {
601 SendMsg(2090, bits
, 0);
604 // Retrieve number of bits in style bytes used to hold the lexical state.
605 int wxStyledTextCtrl::GetStyleBits() {
606 return SendMsg(2091, 0, 0);
609 // Used to hold extra styling information for each line.
610 void wxStyledTextCtrl::SetLineState(int line
, int state
) {
611 SendMsg(2092, line
, state
);
614 // Retrieve the extra styling information for a line.
615 int wxStyledTextCtrl::GetLineState(int line
) {
616 return SendMsg(2093, line
, 0);
619 // Retrieve the last line number that has line state.
620 int wxStyledTextCtrl::GetMaxLineState() {
621 return SendMsg(2094, 0, 0);
624 // Display a auto-completion list.
625 // The lenEntered parameter indicates how many characters before
626 // the caret should be used to provide context.
627 void wxStyledTextCtrl::AutoCompShow(int lenEntered
, const wxString
& itemList
) {
628 SendMsg(2100, lenEntered
, (long)itemList
.c_str());
631 // Remove the auto-completion list from the screen.
632 void wxStyledTextCtrl::AutoCompCancel() {
636 // Is there an auto-completion list visible?
637 bool wxStyledTextCtrl::AutoCompActive() {
638 return SendMsg(2102, 0, 0) != 0;
641 // Retrieve the position of the caret when the auto-completion list was
643 int wxStyledTextCtrl::AutoCompPosStart() {
644 return SendMsg(2103, 0, 0);
647 // User has selected an item so remove the list and insert the selection.
648 void wxStyledTextCtrl::AutoCompComplete() {
652 // Define a set of character that when typed cancel the auto-completion list.
653 void wxStyledTextCtrl::AutoCompStops(const wxString
& characterSet
) {
654 SendMsg(2105, 0, (long)characterSet
.c_str());
657 // Change the separator character in the string setting up an auto-completion
658 // list. Default is space but can be changed if items contain space.
659 void wxStyledTextCtrl::AutoCompSetSeparator(int separatorCharacter
) {
660 SendMsg(2106, separatorCharacter
, 0);
663 // Retrieve the auto-completion list separator character.
664 int wxStyledTextCtrl::AutoCompGetSeparator() {
665 return SendMsg(2107, 0, 0);
668 // Select the item in the auto-completion list that starts with a string.
669 void wxStyledTextCtrl::AutoCompSelect(const wxString
& text
) {
670 SendMsg(2108, 0, (long)text
.c_str());
673 // Should the auto-completion list be cancelled if the user backspaces to a
674 // position before where the box was created.
675 void wxStyledTextCtrl::AutoCompSetCancelAtStart(bool cancel
) {
676 SendMsg(2110, cancel
, 0);
679 // Retrieve whether auto-completion cancelled by backspacing before start.
680 bool wxStyledTextCtrl::AutoCompGetCancelAtStart() {
681 return SendMsg(2111, 0, 0) != 0;
684 // Define a set of character that when typed fills up the selected word.
685 void wxStyledTextCtrl::AutoCompSetFillUps(const wxString
& characterSet
) {
686 SendMsg(2112, 0, (long)characterSet
.c_str());
689 // Should a single item auto-completion list automatically choose the item.
690 void wxStyledTextCtrl::AutoCompSetChooseSingle(bool chooseSingle
) {
691 SendMsg(2113, chooseSingle
, 0);
694 // Retrieve whether a single item auto-completion list automatically choose the item.
695 bool wxStyledTextCtrl::AutoCompGetChooseSingle() {
696 return SendMsg(2114, 0, 0) != 0;
699 // Set whether case is significant when performing auto-completion searches.
700 void wxStyledTextCtrl::AutoCompSetIgnoreCase(bool ignoreCase
) {
701 SendMsg(2115, ignoreCase
, 0);
704 // Retrieve state of ignore case flag.
705 bool wxStyledTextCtrl::AutoCompGetIgnoreCase() {
706 return SendMsg(2116, 0, 0) != 0;
709 // Set the number of spaces used for one level of indentation.
710 void wxStyledTextCtrl::SetIndent(int indentSize
) {
711 SendMsg(2122, indentSize
, 0);
714 // Retrieve indentation size.
715 int wxStyledTextCtrl::GetIndent() {
716 return SendMsg(2123, 0, 0);
719 // Indentation will only use space characters if useTabs is false, otherwise
720 // it will use a combination of tabs and spaces.
721 void wxStyledTextCtrl::SetUseTabs(bool useTabs
) {
722 SendMsg(2124, useTabs
, 0);
725 // Retrieve whether tabs will be used in indentation.
726 bool wxStyledTextCtrl::GetUseTabs() {
727 return SendMsg(2125, 0, 0) != 0;
730 // Change the indentation of a line to a number of columns.
731 void wxStyledTextCtrl::SetLineIndentation(int line
, int indentSize
) {
732 SendMsg(2126, line
, indentSize
);
735 // Retrieve the number of columns that a line is indented.
736 int wxStyledTextCtrl::GetLineIndentation(int line
) {
737 return SendMsg(2127, line
, 0);
740 // Retrieve the position before the first non indentation character on a line.
741 int wxStyledTextCtrl::GetLineIndentPosition(int line
) {
742 return SendMsg(2128, line
, 0);
745 // Retrieve the column number of a position, taking tab width into account.
746 int wxStyledTextCtrl::GetColumn(int pos
) {
747 return SendMsg(2129, pos
, 0);
750 // Show or hide the horizontal scroll bar.
751 void wxStyledTextCtrl::SetUseHorizontalScrollBar(bool show
) {
752 SendMsg(2130, show
, 0);
755 // Is the horizontal scroll bar visible?
756 bool wxStyledTextCtrl::GetUseHorizontalScrollBar() {
757 return SendMsg(2131, 0, 0) != 0;
760 // Show or hide indentation guides.
761 void wxStyledTextCtrl::SetIndentationGuides(bool show
) {
762 SendMsg(2132, show
, 0);
765 // Are the indentation guides visible?
766 bool wxStyledTextCtrl::GetIndentationGuides() {
767 return SendMsg(2133, 0, 0) != 0;
770 // Set the highlighted indentation guide column.
771 // 0 = no highlighted guide.
772 void wxStyledTextCtrl::SetHighlightGuide(int column
) {
773 SendMsg(2134, column
, 0);
776 // Get the highlighted indentation guide column.
777 int wxStyledTextCtrl::GetHighlightGuide() {
778 return SendMsg(2135, 0, 0);
781 // Get the position after the last visible characters on a line.
782 int wxStyledTextCtrl::GetLineEndPosition(int line
) {
783 return SendMsg(2136, line
, 0);
786 // Get the code page used to interpret the bytes of the document as characters.
787 int wxStyledTextCtrl::GetCodePage() {
788 return SendMsg(2137, 0, 0);
791 // Get the foreground colour of the caret.
792 wxColour
wxStyledTextCtrl::GetCaretForeground() {
793 long c
= SendMsg(2138, 0, 0);
794 return wxColourFromLong(c
);
797 // In read-only mode?
798 bool wxStyledTextCtrl::GetReadOnly() {
799 return SendMsg(2140, 0, 0) != 0;
802 // Sets the position of the caret.
803 void wxStyledTextCtrl::SetCurrentPos(int pos
) {
804 SendMsg(2141, pos
, 0);
807 // Sets the position that starts the selection - this becomes the anchor.
808 void wxStyledTextCtrl::SetSelectionStart(int pos
) {
809 SendMsg(2142, pos
, 0);
812 // Returns the position at the start of the selection.
813 int wxStyledTextCtrl::GetSelectionStart() {
814 return SendMsg(2143, 0, 0);
817 // Sets the position that ends the selection - this becomes the currentPosition.
818 void wxStyledTextCtrl::SetSelectionEnd(int pos
) {
819 SendMsg(2144, pos
, 0);
822 // Returns the position at the end of the selection.
823 int wxStyledTextCtrl::GetSelectionEnd() {
824 return SendMsg(2145, 0, 0);
827 // Sets the print magnification added to the point size of each style for printing.
828 void wxStyledTextCtrl::SetPrintMagnification(int magnification
) {
829 SendMsg(2146, magnification
, 0);
832 // Returns the print magnification.
833 int wxStyledTextCtrl::GetPrintMagnification() {
834 return SendMsg(2147, 0, 0);
837 // Modify colours when printing for clearer printed text.
838 void wxStyledTextCtrl::SetPrintColourMode(int mode
) {
839 SendMsg(2148, mode
, 0);
842 // Returns the print colour mode.
843 int wxStyledTextCtrl::GetPrintColourMode() {
844 return SendMsg(2149, 0, 0);
847 // Find some text in the document.
848 int wxStyledTextCtrl::FindText(int minPos
, int maxPos
,
849 const wxString
& text
,
850 bool caseSensitive
, bool wholeWord
) {
854 flags
|= caseSensitive
? SCFIND_MATCHCASE
: 0;
855 flags
|= wholeWord
? SCFIND_WHOLEWORD
: 0;
856 ft
.chrg
.cpMin
= minPos
;
857 ft
.chrg
.cpMax
= maxPos
;
858 ft
.lpstrText
= (char*)text
.c_str();
860 return SendMsg(2150, flags
, (long)&ft
);
863 // On Windows will draw the document into a display context such as a printer.
864 int wxStyledTextCtrl::FormatRange(bool doDraw
,
868 wxDC
* target
, // Why does it use two? Can they be the same?
874 fr
.hdcTarget
= target
;
875 fr
.rc
.top
= renderRect
.GetTop();
876 fr
.rc
.left
= renderRect
.GetLeft();
877 fr
.rc
.right
= renderRect
.GetRight();
878 fr
.rc
.bottom
= renderRect
.GetBottom();
879 fr
.rcPage
.top
= pageRect
.GetTop();
880 fr
.rcPage
.left
= pageRect
.GetLeft();
881 fr
.rcPage
.right
= pageRect
.GetRight();
882 fr
.rcPage
.bottom
= pageRect
.GetBottom();
883 fr
.chrg
.cpMin
= startPos
;
884 fr
.chrg
.cpMax
= endPos
;
886 return SendMsg(2151, doDraw
, (long)&fr
);
889 // Retrieve the line at the top of the display.
890 int wxStyledTextCtrl::GetFirstVisibleLine() {
891 return SendMsg(2152, 0, 0);
894 // Retrieve the contents of a line.
895 wxString
wxStyledTextCtrl::GetLine(int line
) {
897 int len
= LineLength(line
);
898 char* buf
= text
.GetWriteBuf(len
+1);
900 int pos
= SendMsg(2153, line
, (long)buf
);
901 text
.UngetWriteBuf();
906 // Returns the number of lines in the document. There is always at least one.
907 int wxStyledTextCtrl::GetLineCount() {
908 return SendMsg(2154, 0, 0);
911 // Sets the size in pixels of the left margin.
912 void wxStyledTextCtrl::SetMarginLeft(int width
) {
913 SendMsg(2155, 0, width
);
916 // Returns the size in pixels of the left margin.
917 int wxStyledTextCtrl::GetMarginLeft() {
918 return SendMsg(2156, 0, 0);
921 // Sets the size in pixels of the right margin.
922 void wxStyledTextCtrl::SetMarginRight(int width
) {
923 SendMsg(2157, 0, width
);
926 // Returns the size in pixels of the right margin.
927 int wxStyledTextCtrl::GetMarginRight() {
928 return SendMsg(2158, 0, 0);
931 // Is the document different from when it was last saved?
932 bool wxStyledTextCtrl::GetModify() {
933 return SendMsg(2159, 0, 0) != 0;
936 // Select a range of text.
937 void wxStyledTextCtrl::SetSelection(int start
, int end
) {
938 SendMsg(2160, start
, end
);
941 // Retrieve the selected text.
942 wxString
wxStyledTextCtrl::GetSelectedText() {
947 GetSelection(&start
, &end
);
948 int len
= end
- start
;
949 char* buff
= text
.GetWriteBuf(len
+1);
951 SendMsg(2161, 0, (long)buff
);
952 text
.UngetWriteBuf();
956 // Retrieve a range of text.
957 wxString
wxStyledTextCtrl::GetTextRange(int startPos
, int endPos
) {
959 int len
= endPos
- startPos
;
960 char* buff
= text
.GetWriteBuf(len
+1);
963 tr
.chrg
.cpMin
= startPos
;
964 tr
.chrg
.cpMax
= endPos
;
966 SendMsg(2162, 0, (long)&tr
);
967 text
.UngetWriteBuf();
971 // Draw the selection in normal style or with selection highlighted.
972 void wxStyledTextCtrl::HideSelection(bool normal
) {
973 SendMsg(2163, normal
, 0);
976 // Retrieve the line containing a position.
977 int wxStyledTextCtrl::LineFromPosition(int pos
) {
978 return SendMsg(2166, pos
, 0);
981 // Retrieve the position at the start of a line.
982 int wxStyledTextCtrl::PositionFromLine(int line
) {
983 return SendMsg(2167, line
, 0);
986 // Scroll horizontally and vertically.
987 void wxStyledTextCtrl::LineScroll(int columns
, int lines
) {
988 SendMsg(2168, columns
, lines
);
991 // Ensure the caret is visible.
992 void wxStyledTextCtrl::EnsureCaretVisible() {
996 // Replace the selected text with the argument text.
997 void wxStyledTextCtrl::ReplaceSelection(const wxString
& text
) {
998 SendMsg(2170, 0, (long)text
.c_str());
1001 // Set to read only or read write.
1002 void wxStyledTextCtrl::SetReadOnly(bool readOnly
) {
1003 SendMsg(2171, readOnly
, 0);
1006 // Will a paste succeed?
1007 bool wxStyledTextCtrl::CanPaste() {
1008 return SendMsg(2173, 0, 0) != 0;
1011 // Are there any undoable actions in the undo history.
1012 bool wxStyledTextCtrl::CanUndo() {
1013 return SendMsg(2174, 0, 0) != 0;
1016 // Delete the undo history.
1017 void wxStyledTextCtrl::EmptyUndoBuffer() {
1018 SendMsg(2175, 0, 0);
1021 // Undo one action in the undo history.
1022 void wxStyledTextCtrl::Undo() {
1023 SendMsg(2176, 0, 0);
1026 // Cut the selection to the clipboard.
1027 void wxStyledTextCtrl::Cut() {
1028 SendMsg(2177, 0, 0);
1031 // Copy the selection to the clipboard.
1032 void wxStyledTextCtrl::Copy() {
1033 SendMsg(2178, 0, 0);
1036 // Paste the contents of the clipboard into the document replacing the selection.
1037 void wxStyledTextCtrl::Paste() {
1038 SendMsg(2179, 0, 0);
1041 // Clear the selection.
1042 void wxStyledTextCtrl::Clear() {
1043 SendMsg(2180, 0, 0);
1046 // Replace the contents of the document with the argument text.
1047 void wxStyledTextCtrl::SetText(const wxString
& text
) {
1048 SendMsg(2181, 0, (long)text
.c_str());
1051 // Retrieve all the text in the document.
1052 wxString
wxStyledTextCtrl::GetText() {
1054 int len
= GetTextLength();
1055 char* buff
= text
.GetWriteBuf(len
+1);
1057 SendMsg(2182, len
, (long)buff
);
1059 text
.UngetWriteBuf();
1063 // Retrieve the number of characters in the document.
1064 int wxStyledTextCtrl::GetTextLength() {
1065 return SendMsg(2183, 0, 0);
1068 // Set to overtype (true) or insert mode
1069 void wxStyledTextCtrl::SetOvertype(bool overtype
) {
1070 SendMsg(2186, overtype
, 0);
1073 // Returns true if overtype mode is active otherwise false is returned.
1074 bool wxStyledTextCtrl::GetOvertype() {
1075 return SendMsg(2187, 0, 0) != 0;
1078 // Show a call tip containing a definition near position pos.
1079 void wxStyledTextCtrl::CallTipShow(int pos
, const wxString
& definition
) {
1080 SendMsg(2200, pos
, (long)definition
.c_str());
1083 // Remove the call tip from the screen.
1084 void wxStyledTextCtrl::CallTipCancel() {
1085 SendMsg(2201, 0, 0);
1088 // Is there an active call tip?
1089 bool wxStyledTextCtrl::CallTipActive() {
1090 return SendMsg(2202, 0, 0) != 0;
1093 // Retrieve the position where the caret was before displaying the call tip.
1094 int wxStyledTextCtrl::CallTipPosAtStart() {
1095 return SendMsg(2203, 0, 0);
1098 // Highlight a segment of the definition.
1099 void wxStyledTextCtrl::CallTipSetHighlight(int start
, int end
) {
1100 SendMsg(2204, start
, end
);
1103 // Set the background colour for the call tip.
1104 void wxStyledTextCtrl::CallTipSetBackground(const wxColour
& back
) {
1105 SendMsg(2205, wxColourAsLong(back
), 0);
1108 // Find the display line of a document line taking hidden lines into account.
1109 int wxStyledTextCtrl::VisibleFromDocLine(int line
) {
1110 return SendMsg(2220, line
, 0);
1113 // Find the document line of a display line taking hidden lines into account.
1114 int wxStyledTextCtrl::DocLineFromVisible(int lineDisplay
) {
1115 return SendMsg(2221, lineDisplay
, 0);
1118 // Set the fold level of a line.
1119 // This encodes an integer level along with flags indicating whether the
1120 // line is a header and whether it is effectively white space.
1121 void wxStyledTextCtrl::SetFoldLevel(int line
, int level
) {
1122 SendMsg(2222, line
, level
);
1125 // Retrieve the fold level of a line.
1126 int wxStyledTextCtrl::GetFoldLevel(int line
) {
1127 return SendMsg(2223, line
, 0);
1130 // Find the last child line of a header line.
1131 int wxStyledTextCtrl::GetLastChild(int line
, int level
) {
1132 return SendMsg(2224, line
, level
);
1135 // Find the parent line of a child line.
1136 int wxStyledTextCtrl::GetFoldParent(int line
) {
1137 return SendMsg(2225, line
, 0);
1140 // Make a range of lines visible.
1141 void wxStyledTextCtrl::ShowLines(int lineStart
, int lineEnd
) {
1142 SendMsg(2226, lineStart
, lineEnd
);
1145 // Make a range of lines invisible.
1146 void wxStyledTextCtrl::HideLines(int lineStart
, int lineEnd
) {
1147 SendMsg(2227, lineStart
, lineEnd
);
1150 // Is a line visible?
1151 bool wxStyledTextCtrl::GetLineVisible(int line
) {
1152 return SendMsg(2228, line
, 0) != 0;
1155 // Show the children of a header line.
1156 void wxStyledTextCtrl::SetFoldExpanded(int line
, bool expanded
) {
1157 SendMsg(2229, line
, expanded
);
1160 // Is a header line expanded?
1161 bool wxStyledTextCtrl::GetFoldExpanded(int line
) {
1162 return SendMsg(2230, line
, 0) != 0;
1165 // Switch a header line between expanded and contracted.
1166 void wxStyledTextCtrl::ToggleFold(int line
) {
1167 SendMsg(2231, line
, 0);
1170 // Ensure a particular line is visible by expanding any header line hiding it.
1171 void wxStyledTextCtrl::EnsureVisible(int line
) {
1172 SendMsg(2232, line
, 0);
1175 // Set some debugging options for folding
1176 void wxStyledTextCtrl::SetFoldFlags(int flags
) {
1177 SendMsg(2233, flags
, 0);
1180 // How many characters are on a line, not including end of line characters.
1181 int wxStyledTextCtrl::LineLength(int line
) {
1182 return SendMsg(2350, line
, 0);
1185 // Highlight the characters at two positions.
1186 void wxStyledTextCtrl::BraceHighlight(int pos1
, int pos2
) {
1187 SendMsg(2351, pos1
, pos2
);
1190 // Highlight the character at a position indicating there is no matching brace.
1191 void wxStyledTextCtrl::BraceBadLight(int pos
) {
1192 SendMsg(2352, pos
, 0);
1195 // Find the position of a matching brace or INVALID_POSITION if no match.
1196 int wxStyledTextCtrl::BraceMatch(int pos
) {
1197 return SendMsg(2353, pos
, 0);
1200 // Are the end of line characters visible.
1201 bool wxStyledTextCtrl::GetViewEOL() {
1202 return SendMsg(2355, 0, 0) != 0;
1205 // Make the end of line characters visible or invisible
1206 void wxStyledTextCtrl::SetViewEOL(bool visible
) {
1207 SendMsg(2356, visible
, 0);
1210 // Retrieve a pointer to the document object.
1211 void* wxStyledTextCtrl::GetDocPointer() {
1212 return (void*)SendMsg(2357);
1215 // Change the document object used.
1216 void wxStyledTextCtrl::SetDocPointer(void* docPointer
) {
1217 SendMsg(2358, (long)docPointer
);
1220 // Set which document modification events are sent to the container.
1221 void wxStyledTextCtrl::SetModEventMask(int mask
) {
1222 SendMsg(2359, mask
, 0);
1225 // Retrieve the column number which text should be kept within.
1226 int wxStyledTextCtrl::GetEdgeColumn() {
1227 return SendMsg(2360, 0, 0);
1230 // Set the column number of the edge.
1231 // If text goes past the edge then it is highlighted.
1232 void wxStyledTextCtrl::SetEdgeColumn(int column
) {
1233 SendMsg(2361, column
, 0);
1236 // Retrieve the edge highlight mode.
1237 int wxStyledTextCtrl::GetEdgeMode() {
1238 return SendMsg(2362, 0, 0);
1241 // The edge may be displayed by a line (EDGE_LINE) or by highlighting text that
1242 // goes beyond it (EDGE_BACKGROUND) or not displayed at all (EDGE_NONE).
1243 void wxStyledTextCtrl::SetEdgeMode(int mode
) {
1244 SendMsg(2363, mode
, 0);
1247 // Retrieve the colour used in edge indication.
1248 wxColour
wxStyledTextCtrl::GetEdgeColour() {
1249 long c
= SendMsg(2364, 0, 0);
1250 return wxColourFromLong(c
);
1253 // Change the colour used in edge indication.
1254 void wxStyledTextCtrl::SetEdgeColour(const wxColour
& edgeColour
) {
1255 SendMsg(2365, wxColourAsLong(edgeColour
), 0);
1258 // Sets the current caret position to be the search anchor.
1259 void wxStyledTextCtrl::SearchAnchor() {
1260 SendMsg(2366, 0, 0);
1263 // Find some text starting at the search anchor.
1264 int wxStyledTextCtrl::SearchNext(int flags
, const wxString
& text
) {
1265 return SendMsg(2367, flags
, (long)text
.c_str());
1268 // Find some text starting at the search anchor and moving backwards.
1269 int wxStyledTextCtrl::SearchPrev(int flags
, const wxString
& text
) {
1270 return SendMsg(2368, flags
, (long)text
.c_str());
1273 // Set the way the line the caret is on is kept visible.
1274 void wxStyledTextCtrl::SetCaretPolicy(int caretPolicy
, int caretSlop
) {
1275 SendMsg(2369, caretPolicy
, caretSlop
);
1278 // Retrieves the number of lines completely visible.
1279 int wxStyledTextCtrl::LinesOnScreen() {
1280 return SendMsg(2370, 0, 0);
1283 // Set whether a pop up menu is displayed automatically when the user presses
1284 // the wrong mouse button.
1285 void wxStyledTextCtrl::UsePopUp(bool allowPopUp
) {
1286 SendMsg(2371, allowPopUp
, 0);
1289 // Is the selection a rectangular. The alternative is the more common stream selection.
1290 bool wxStyledTextCtrl::SelectionIsRectangle() {
1291 return SendMsg(2372, 0, 0) != 0;
1294 // Set the zoom level. This number of points is added to the size of all fonts.
1295 // It may be positive to magnify or negative to reduce.
1296 void wxStyledTextCtrl::SetZoom(int zoom
) {
1297 SendMsg(2373, zoom
, 0);
1300 // Retrieve the zoom level.
1301 int wxStyledTextCtrl::GetZoom() {
1302 return SendMsg(2374, 0, 0);
1305 // Create a new document object.
1306 // Starts with reference count of 1 and not selected into editor.
1307 void* wxStyledTextCtrl::CreateDocument() {
1308 return (void*)SendMsg(2375);
1311 // Extend life of document.
1312 void wxStyledTextCtrl::AddRefDocument(void* docPointer
) {
1313 SendMsg(2376, (long)docPointer
);
1316 // Release a reference to the document, deleting document if it fades to black.
1317 void wxStyledTextCtrl::ReleaseDocument(void* docPointer
) {
1318 SendMsg(2377, (long)docPointer
);
1321 // Get which document modification events are sent to the container.
1322 int wxStyledTextCtrl::GetModEventMask() {
1323 return SendMsg(2378, 0, 0);
1326 // Start notifying the container of all key presses and commands.
1327 void wxStyledTextCtrl::StartRecord() {
1328 SendMsg(3001, 0, 0);
1331 // Stop notifying the container of all key presses and commands.
1332 void wxStyledTextCtrl::StopRecord() {
1333 SendMsg(3002, 0, 0);
1336 // Set the lexing language of the document.
1337 void wxStyledTextCtrl::SetLexer(int lexer
) {
1338 SendMsg(4001, lexer
, 0);
1341 // Retrieve the lexing language of the document.
1342 int wxStyledTextCtrl::GetLexer() {
1343 return SendMsg(4002, 0, 0);
1346 // Colourise a segment of the document using the current lexing language.
1347 void wxStyledTextCtrl::Colourise(int start
, int end
) {
1348 SendMsg(4003, start
, end
);
1351 // Set up a value that may be used by a lexer for some optional feature.
1352 void wxStyledTextCtrl::SetProperty(const wxString
& key
, const wxString
& value
) {
1353 SendMsg(4004, (long)key
.c_str(), (long)value
.c_str());
1356 // Set up the key words used by the lexer.
1357 void wxStyledTextCtrl::SetKeyWords(int keywordSet
, const wxString
& keyWords
) {
1358 SendMsg(4005, keywordSet
, (long)keyWords
.c_str());
1361 // END of generated section
1362 //----------------------------------------------------------------------
1365 // Returns the line number of the line with the caret.
1366 int wxStyledTextCtrl::GetCurrentLine() {
1367 int line
= LineFromPosition(GetCurrentPos());
1372 // Extract style settings from a spec-string which is composed of one or
1373 // more of the following comma separated elements:
1375 // bold turns on bold
1376 // italic turns on italics
1377 // fore:#RRGGBB sets the foreground colour
1378 // back:#RRGGBB sets the background colour
1379 // face:[facename] sets the font face name to use
1380 // size:[num] sets the font size in points
1381 // eol turns on eol filling
1382 // underline turns on underlining
1384 void wxStyledTextCtrl::StyleSetSpec(int styleNum
, const wxString
& spec
) {
1386 wxStringTokenizer
tkz(spec
, ",");
1387 while (tkz
.HasMoreTokens()) {
1388 wxString token
= tkz
.GetNextToken();
1390 wxString option
= token
.BeforeFirst(':');
1391 wxString val
= token
.AfterFirst(':');
1393 if (option
== "bold")
1394 StyleSetBold(styleNum
, true);
1396 else if (option
== "italic")
1397 StyleSetItalic(styleNum
, true);
1399 else if (option
== "underline")
1400 StyleSetUnderline(styleNum
, true);
1402 else if (option
== "eol")
1403 StyleSetEOLFilled(styleNum
, true);
1405 else if (option
== "size") {
1407 if (val
.ToLong(&points
))
1408 StyleSetSize(styleNum
, points
);
1411 else if (option
== "face")
1412 StyleSetFaceName(styleNum
, val
);
1414 else if (option
== "fore")
1415 StyleSetForeground(styleNum
, wxColourFromSpec(val
));
1417 else if (option
== "back")
1418 StyleSetBackground(styleNum
, wxColourFromSpec(val
));
1423 // Set style size, face, bold, italic, and underline attributes from
1424 // a wxFont's attributes.
1425 void wxStyledTextCtrl::StyleSetFont(int styleNum
, wxFont
& font
) {
1426 int size
= font
.GetPointSize();
1427 wxString faceName
= font
.GetFaceName();
1428 bool bold
= font
.GetWeight() == wxBOLD
;
1429 bool italic
= font
.GetStyle() != wxNORMAL
;
1430 bool under
= font
.GetUnderlined();
1432 // TODO: add encoding/charset mapping
1433 StyleSetFontAttr(styleNum
, size
, faceName
, bold
, italic
, under
);
1436 // Set all font style attributes at once.
1437 void wxStyledTextCtrl::StyleSetFontAttr(int styleNum
, int size
,
1438 const wxString
& faceName
,
1439 bool bold
, bool italic
,
1441 StyleSetSize(styleNum
, size
);
1442 StyleSetFaceName(styleNum
, faceName
);
1443 StyleSetBold(styleNum
, bold
);
1444 StyleSetItalic(styleNum
, italic
);
1445 StyleSetUnderline(styleNum
, underline
);
1447 // TODO: add encoding/charset mapping
1451 // Perform one of the operations defined by the wxSTC_CMD_* constants.
1452 void wxStyledTextCtrl::CmdKeyExecute(int cmd
) {
1457 // Set the left and right margin in the edit area, measured in pixels.
1458 void wxStyledTextCtrl::SetMargins(int left
, int right
) {
1459 SetMarginLeft(left
);
1460 SetMarginRight(right
);
1464 // Retrieve the start and end positions of the current selection.
1465 void wxStyledTextCtrl::GetSelection(int* startPos
, int* endPos
) {
1466 if (startPos
!= NULL
)
1467 *startPos
= SendMsg(SCI_GETSELECTIONSTART
);
1469 *endPos
= SendMsg(SCI_GETSELECTIONEND
);
1473 // Retrieve the point in the window where a position is displayed.
1474 wxPoint
wxStyledTextCtrl::PointFromPosition(int pos
) {
1475 int x
= SendMsg(SCI_POINTXFROMPOSITION
, 0, pos
);
1476 int y
= SendMsg(SCI_POINTYFROMPOSITION
, 0, pos
);
1477 return wxPoint(x
, y
);
1482 //----------------------------------------------------------------------
1485 void wxStyledTextCtrl::OnPaint(wxPaintEvent
& evt
) {
1487 wxRegion region
= GetUpdateRegion();
1489 m_swx
->DoPaint(&dc
, region
.GetBox());
1492 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent
& evt
) {
1493 if (evt
.GetOrientation() == wxHORIZONTAL
)
1494 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
1496 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
1499 void wxStyledTextCtrl::OnSize(wxSizeEvent
& evt
) {
1500 wxSize sz
= GetClientSize();
1501 m_swx
->DoSize(sz
.x
, sz
.y
);
1504 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent
& evt
) {
1505 wxPoint pt
= evt
.GetPosition();
1506 m_swx
->DoButtonDown(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1507 evt
.ShiftDown(), evt
.ControlDown(), evt
.AltDown());
1510 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent
& evt
) {
1511 wxPoint pt
= evt
.GetPosition();
1512 m_swx
->DoButtonMove(Point(pt
.x
, pt
.y
));
1515 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent
& evt
) {
1516 wxPoint pt
= evt
.GetPosition();
1517 m_swx
->DoButtonUp(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
1522 void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent
& evt
) {
1523 wxPoint pt
= evt
.GetPosition();
1524 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
1527 void wxStyledTextCtrl::OnChar(wxKeyEvent
& evt
) {
1528 long key
= evt
.KeyCode();
1529 if ((key
> WXK_ESCAPE
) &&
1530 (key
!= WXK_DELETE
) && (key
< 255) &&
1531 !evt
.ControlDown() && !evt
.AltDown()) {
1533 m_swx
->DoAddChar(key
);
1540 void wxStyledTextCtrl::OnKeyDown(wxKeyEvent
& evt
) {
1541 long key
= evt
.KeyCode();
1543 int processed
= m_swx
->DoKeyDown(key
, evt
.ShiftDown(),
1544 evt
.ControlDown(), evt
.AltDown());
1549 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent
& evt
) {
1550 m_swx
->DoLoseFocus();
1553 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent
& evt
) {
1554 m_swx
->DoGainFocus();
1557 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& evt
) {
1558 m_swx
->DoSysColourChange();
1561 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent
& evt
) {
1562 // do nothing to help avoid flashing
1567 void wxStyledTextCtrl::OnMenu(wxCommandEvent
& evt
) {
1568 m_swx
->DoCommand(evt
.GetId());
1572 void wxStyledTextCtrl::OnListBox(wxCommandEvent
& evt
) {
1573 m_swx
->DoOnListBox();
1577 //----------------------------------------------------------------------
1578 // Turn notifications from Scintilla into events
1581 void wxStyledTextCtrl::NotifyChange() {
1582 wxStyledTextEvent
evt(wxEVT_STC_CHANGE
, GetId());
1583 GetEventHandler()->ProcessEvent(evt
);
1586 void wxStyledTextCtrl::NotifyParent(SCNotification
* _scn
) {
1587 SCNotification
& scn
= *_scn
;
1589 switch (scn
.nmhdr
.code
) {
1590 case SCN_STYLENEEDED
:
1591 eventType
= wxEVT_STC_STYLENEEDED
;
1594 eventType
= wxEVT_STC_CHARADDED
;
1597 eventType
= wxEVT_STC_UPDATEUI
;
1599 case SCN_SAVEPOINTREACHED
:
1600 eventType
= wxEVT_STC_SAVEPOINTREACHED
;
1602 case SCN_SAVEPOINTLEFT
:
1603 eventType
= wxEVT_STC_SAVEPOINTLEFT
;
1605 case SCN_MODIFYATTEMPTRO
:
1606 eventType
= wxEVT_STC_ROMODIFYATTEMPT
;
1608 case SCN_DOUBLECLICK
:
1609 eventType
= wxEVT_STC_DOUBLECLICK
;
1612 eventType
= wxEVT_STC_MODIFIED
;
1615 eventType
= wxEVT_STC_KEY
;
1617 case SCN_MACRORECORD
:
1618 eventType
= wxEVT_STC_MACRORECORD
;
1620 case SCN_MARGINCLICK
:
1621 eventType
= wxEVT_STC_MARGINCLICK
;
1624 eventType
= wxEVT_STC_NEEDSHOWN
;
1626 case SCN_POSCHANGED
:
1627 eventType
= wxEVT_STC_POSCHANGED
;
1631 wxStyledTextEvent
evt(eventType
, GetId());
1632 evt
.SetPosition(scn
.position
);
1634 evt
.SetModifiers(scn
.modifiers
);
1635 if (eventType
== wxEVT_STC_MODIFIED
) {
1636 evt
.SetModificationType(scn
.modificationType
);
1638 evt
.SetText(wxString(scn
.text
, scn
.length
));
1639 evt
.SetLength(scn
.length
);
1640 evt
.SetLinesAdded(scn
.linesAdded
);
1641 evt
.SetLine(scn
.line
);
1642 evt
.SetFoldLevelNow(scn
.foldLevelNow
);
1643 evt
.SetFoldLevelPrev(scn
.foldLevelPrev
);
1645 if (eventType
== wxEVT_STC_MARGINCLICK
)
1646 evt
.SetMargin(scn
.margin
);
1647 if (eventType
== wxEVT_STC_MACRORECORD
) {
1648 evt
.SetMessage(scn
.message
);
1649 evt
.SetWParam(scn
.wParam
);
1650 evt
.SetLParam(scn
.lParam
);
1653 GetEventHandler()->ProcessEvent(evt
);
1659 //----------------------------------------------------------------------
1660 //----------------------------------------------------------------------
1661 //----------------------------------------------------------------------
1663 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType
, int id
)
1664 : wxCommandEvent(commandType
, id
)
1669 m_modificationType
= 0;
1674 m_foldLevelPrev
= 0;
1683 bool wxStyledTextEvent::GetShift() const { return (m_modifiers
& SCI_SHIFT
) != 0; }
1684 bool wxStyledTextEvent::GetControl() const { return (m_modifiers
& SCI_CTRL
) != 0; }
1685 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers
& SCI_ALT
) != 0; }
1687 void wxStyledTextEvent::CopyObject(wxObject
& obj
) const {
1688 wxCommandEvent::CopyObject(obj
);
1690 wxStyledTextEvent
* o
= (wxStyledTextEvent
*)&obj
;
1691 o
->m_position
= m_position
;
1693 o
->m_modifiers
= m_modifiers
;
1694 o
->m_modificationType
= m_modificationType
;
1696 o
->m_length
= m_length
;
1697 o
->m_linesAdded
= m_linesAdded
;
1699 o
->m_foldLevelNow
= m_foldLevelNow
;
1700 o
->m_foldLevelPrev
= m_foldLevelPrev
;
1702 o
->m_margin
= m_margin
;
1704 o
->m_message
= m_message
;
1705 o
->m_wParam
= m_wParam
;
1706 o
->m_lParam
= m_lParam
;
1712 //----------------------------------------------------------------------
1713 //----------------------------------------------------------------------