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"
24 #include <wx/tokenzr.h>
25 #include <wx/mstream.h>
30 //----------------------------------------------------------------------
32 const wxChar
* wxSTCNameStr
= wxT("stcwindow");
38 #define MAKELONG(a, b) ((a) | ((b) << 16))
41 static long wxColourAsLong(const wxColour
& co
) {
42 return (((long)co
.Blue() << 16) |
43 ((long)co
.Green() << 8) |
47 static wxColour
wxColourFromLong(long c
) {
49 clr
.Set(c
& 0xff, (c
>> 8) & 0xff, (c
>> 16) & 0xff);
54 static wxColour
wxColourFromSpec(const wxString
& spec
) {
55 // spec should be "#RRGGBB"
56 long red
, green
, blue
;
57 red
= green
= blue
= 0;
58 spec
.Mid(1,2).ToLong(&red
, 16);
59 spec
.Mid(3,2).ToLong(&green
, 16);
60 spec
.Mid(5,2).ToLong(&blue
, 16);
61 return wxColour(red
, green
, blue
);
64 //----------------------------------------------------------------------
66 DEFINE_EVENT_TYPE( wxEVT_STC_CHANGE
)
67 DEFINE_EVENT_TYPE( wxEVT_STC_STYLENEEDED
)
68 DEFINE_EVENT_TYPE( wxEVT_STC_CHARADDED
)
69 DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTREACHED
)
70 DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTLEFT
)
71 DEFINE_EVENT_TYPE( wxEVT_STC_ROMODIFYATTEMPT
)
72 DEFINE_EVENT_TYPE( wxEVT_STC_KEY
)
73 DEFINE_EVENT_TYPE( wxEVT_STC_DOUBLECLICK
)
74 DEFINE_EVENT_TYPE( wxEVT_STC_UPDATEUI
)
75 DEFINE_EVENT_TYPE( wxEVT_STC_MODIFIED
)
76 DEFINE_EVENT_TYPE( wxEVT_STC_MACRORECORD
)
77 DEFINE_EVENT_TYPE( wxEVT_STC_MARGINCLICK
)
78 DEFINE_EVENT_TYPE( wxEVT_STC_NEEDSHOWN
)
79 DEFINE_EVENT_TYPE( wxEVT_STC_POSCHANGED
)
80 DEFINE_EVENT_TYPE( wxEVT_STC_PAINTED
)
81 DEFINE_EVENT_TYPE( wxEVT_STC_USERLISTSELECTION
)
82 DEFINE_EVENT_TYPE( wxEVT_STC_URIDROPPED
)
83 DEFINE_EVENT_TYPE( wxEVT_STC_DWELLSTART
)
84 DEFINE_EVENT_TYPE( wxEVT_STC_DWELLEND
)
85 DEFINE_EVENT_TYPE( wxEVT_STC_START_DRAG
)
86 DEFINE_EVENT_TYPE( wxEVT_STC_DRAG_OVER
)
87 DEFINE_EVENT_TYPE( wxEVT_STC_DO_DROP
)
88 DEFINE_EVENT_TYPE( wxEVT_STC_ZOOM
)
89 DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_CLICK
)
90 DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_DCLICK
)
91 DEFINE_EVENT_TYPE( wxEVT_STC_CALLTIP_CLICK
)
95 BEGIN_EVENT_TABLE(wxStyledTextCtrl
, wxControl
)
96 EVT_PAINT (wxStyledTextCtrl::OnPaint
)
97 EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin
)
98 EVT_SCROLL (wxStyledTextCtrl::OnScroll
)
99 EVT_SIZE (wxStyledTextCtrl::OnSize
)
100 EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown
)
101 // Let Scintilla see the double click as a second click
102 EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown
)
103 EVT_MOTION (wxStyledTextCtrl::OnMouseMove
)
104 EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp
)
105 #if defined(__WXGTK__) || defined(__WXMAC__)
106 EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp
)
108 EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu
)
110 EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel
)
111 EVT_MIDDLE_UP (wxStyledTextCtrl::OnMouseMiddleUp
)
112 EVT_CHAR (wxStyledTextCtrl::OnChar
)
113 EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown
)
114 EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus
)
115 EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus
)
116 EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged
)
117 EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground
)
118 EVT_MENU_RANGE (10, 16, wxStyledTextCtrl::OnMenu
)
119 EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox
)
123 IMPLEMENT_CLASS(wxStyledTextCtrl
, wxControl
)
124 IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent
, wxCommandEvent
)
127 // forces the linking of the lexer modules
128 int Scintilla_LinkLexers();
131 //----------------------------------------------------------------------
132 // Constructor and Destructor
134 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow
*parent
,
139 const wxString
& name
)
142 Create(parent
, id
, pos
, size
, style
, name
);
146 void wxStyledTextCtrl::Create(wxWindow
*parent
,
151 const wxString
& name
)
154 style
|= wxVSCROLL
| wxHSCROLL
;
156 wxControl::Create(parent
, id
, pos
, size
,
157 style
| wxWANTS_CHARS
| wxCLIP_CHILDREN
,
158 wxDefaultValidator
, name
);
161 Scintilla_LinkLexers();
163 m_swx
= new ScintillaWX(this);
165 m_lastKeyDownConsumed
= FALSE
;
169 // Put Scintilla into unicode (UTF-8) mode
170 SetCodePage(wxSTC_CP_UTF8
);
175 wxStyledTextCtrl::~wxStyledTextCtrl() {
180 //----------------------------------------------------------------------
182 long wxStyledTextCtrl::SendMsg(int msg
, long wp
, long lp
) {
184 return m_swx
->WndProc(msg
, wp
, lp
);
189 //----------------------------------------------------------------------
190 // BEGIN generated section. The following code is automatically generated
191 // by gen_iface.py from the contents of Scintilla.iface. Do not edit
192 // this file. Edit stc.cpp.in or gen_iface.py instead and regenerate.
195 // Add text to the document.
196 void wxStyledTextCtrl::AddText(const wxString
& text
) {
197 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
198 SendMsg(2001, strlen(buf
), (long)(const char*)buf
);
201 // Add array of cells to document.
202 void wxStyledTextCtrl::AddStyledText(const wxMemoryBuffer
& data
) {
203 SendMsg(2002, data
.GetDataLen(), (long)data
.GetData());
206 // Insert string at a position.
207 void wxStyledTextCtrl::InsertText(int pos
, const wxString
& text
) {
208 SendMsg(2003, pos
, (long)(const char*)wx2stc(text
));
211 // Delete all text in the document.
212 void wxStyledTextCtrl::ClearAll() {
216 // Set all style bytes to 0, remove all folding information.
217 void wxStyledTextCtrl::ClearDocumentStyle() {
221 // The number of characters in the document.
222 int wxStyledTextCtrl::GetLength() {
223 return SendMsg(2006, 0, 0);
226 // Returns the character byte at the position.
227 int wxStyledTextCtrl::GetCharAt(int pos
) {
228 return (unsigned char)SendMsg(2007, pos
, 0);
231 // Returns the position of the caret.
232 int wxStyledTextCtrl::GetCurrentPos() {
233 return SendMsg(2008, 0, 0);
236 // Returns the position of the opposite end of the selection to the caret.
237 int wxStyledTextCtrl::GetAnchor() {
238 return SendMsg(2009, 0, 0);
241 // Returns the style byte at the position.
242 int wxStyledTextCtrl::GetStyleAt(int pos
) {
243 return (unsigned char)SendMsg(2010, pos
, 0);
246 // Redoes the next action on the undo history.
247 void wxStyledTextCtrl::Redo() {
251 // Choose between collecting actions into the undo
252 // history and discarding them.
253 void wxStyledTextCtrl::SetUndoCollection(bool collectUndo
) {
254 SendMsg(2012, collectUndo
, 0);
257 // Select all the text in the document.
258 void wxStyledTextCtrl::SelectAll() {
262 // Remember the current position in the undo history as the position
263 // at which the document was saved.
264 void wxStyledTextCtrl::SetSavePoint() {
268 // Retrieve a buffer of cells.
269 wxMemoryBuffer
wxStyledTextCtrl::GetStyledText(int startPos
, int endPos
) {
271 if (endPos
< startPos
) {
276 int len
= endPos
- startPos
;
277 if (!len
) return buf
;
279 tr
.lpstrText
= (char*)buf
.GetWriteBuf(len
*2+1);
280 tr
.chrg
.cpMin
= startPos
;
281 tr
.chrg
.cpMax
= endPos
;
282 len
= SendMsg(2015, 0, (long)&tr
);
283 buf
.UngetWriteBuf(len
);
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
) {
348 int len
= LineLength(GetCurrentLine());
350 if (linePos
) *linePos
= 0;
351 return wxEmptyString
;
354 wxMemoryBuffer
mbuf(len
+1);
355 char* buf
= (char*)mbuf
.GetWriteBuf(len
+1);
357 int pos
= SendMsg(2027, len
+1, (long)buf
);
358 mbuf
.UngetWriteBuf(len
);
360 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 modification.
386 void wxStyledTextCtrl::StartStyling(int pos
, int mask
) {
387 SendMsg(2032, pos
, mask
);
390 // Change style from current styling position for length characters to a style
391 // and move the current styling position to after this newly styled segment.
392 void wxStyledTextCtrl::SetStyling(int length
, int style
) {
393 SendMsg(2033, length
, style
);
396 // Is drawing done first into a buffer or direct to the screen?
397 bool wxStyledTextCtrl::GetBufferedDraw() {
398 return SendMsg(2034, 0, 0) != 0;
401 // If drawing is buffered then each line of text is drawn into a bitmap buffer
402 // before drawing it to the screen to avoid flicker.
403 void wxStyledTextCtrl::SetBufferedDraw(bool buffered
) {
404 SendMsg(2035, buffered
, 0);
407 // Change the visible size of a tab to be a multiple of the width of a space character.
408 void wxStyledTextCtrl::SetTabWidth(int tabWidth
) {
409 SendMsg(2036, tabWidth
, 0);
412 // Retrieve the visible size of a tab.
413 int wxStyledTextCtrl::GetTabWidth() {
414 return SendMsg(2121, 0, 0);
417 // Set the code page used to interpret the bytes of the document as characters.
418 void wxStyledTextCtrl::SetCodePage(int codePage
) {
420 wxASSERT_MSG(codePage
== wxSTC_CP_UTF8
,
421 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
423 wxASSERT_MSG(codePage
!= wxSTC_CP_UTF8
,
424 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
426 SendMsg(2037, codePage
);
429 // Set the symbol used for a particular marker number,
430 // and optionally the fore and background colours.
431 void wxStyledTextCtrl::MarkerDefine(int markerNumber
, int markerSymbol
,
432 const wxColour
& foreground
,
433 const wxColour
& background
) {
435 SendMsg(2040, markerNumber
, markerSymbol
);
437 MarkerSetForeground(markerNumber
, foreground
);
439 MarkerSetBackground(markerNumber
, background
);
442 // Set the foreground colour used for a particular marker number.
443 void wxStyledTextCtrl::MarkerSetForeground(int markerNumber
, const wxColour
& fore
) {
444 SendMsg(2041, markerNumber
, wxColourAsLong(fore
));
447 // Set the background colour used for a particular marker number.
448 void wxStyledTextCtrl::MarkerSetBackground(int markerNumber
, const wxColour
& back
) {
449 SendMsg(2042, markerNumber
, wxColourAsLong(back
));
452 // Add a marker to a line, returning an ID which can be used to find or delete the marker.
453 int wxStyledTextCtrl::MarkerAdd(int line
, int markerNumber
) {
454 return SendMsg(2043, line
, markerNumber
);
457 // Delete a marker from a line.
458 void wxStyledTextCtrl::MarkerDelete(int line
, int markerNumber
) {
459 SendMsg(2044, line
, markerNumber
);
462 // Delete all markers with a particular number from all lines.
463 void wxStyledTextCtrl::MarkerDeleteAll(int markerNumber
) {
464 SendMsg(2045, markerNumber
, 0);
467 // Get a bit mask of all the markers set on a line.
468 int wxStyledTextCtrl::MarkerGet(int line
) {
469 return SendMsg(2046, line
, 0);
472 // Find the next line after lineStart that includes a marker in mask.
473 int wxStyledTextCtrl::MarkerNext(int lineStart
, int markerMask
) {
474 return SendMsg(2047, lineStart
, markerMask
);
477 // Find the previous line before lineStart that includes a marker in mask.
478 int wxStyledTextCtrl::MarkerPrevious(int lineStart
, int markerMask
) {
479 return SendMsg(2048, lineStart
, markerMask
);
482 // Define a marker from a bitmap
483 void wxStyledTextCtrl::MarkerDefineBitmap(int markerNumber
, const wxBitmap
& bmp
) {
484 // convert bmp to a xpm in a string
485 wxMemoryOutputStream strm
;
486 wxImage img
= bmp
.ConvertToImage();
487 img
.SaveFile(strm
, wxBITMAP_TYPE_XPM
);
488 size_t len
= strm
.GetSize();
489 char* buff
= new char[len
+1];
490 strm
.CopyTo(buff
, len
);
492 SendMsg(2049, markerNumber
, (long)buff
);
497 // Set a margin to be either numeric or symbolic.
498 void wxStyledTextCtrl::SetMarginType(int margin
, int marginType
) {
499 SendMsg(2240, margin
, marginType
);
502 // Retrieve the type of a margin.
503 int wxStyledTextCtrl::GetMarginType(int margin
) {
504 return SendMsg(2241, margin
, 0);
507 // Set the width of a margin to a width expressed in pixels.
508 void wxStyledTextCtrl::SetMarginWidth(int margin
, int pixelWidth
) {
509 SendMsg(2242, margin
, pixelWidth
);
512 // Retrieve the width of a margin in pixels.
513 int wxStyledTextCtrl::GetMarginWidth(int margin
) {
514 return SendMsg(2243, margin
, 0);
517 // Set a mask that determines which markers are displayed in a margin.
518 void wxStyledTextCtrl::SetMarginMask(int margin
, int mask
) {
519 SendMsg(2244, margin
, mask
);
522 // Retrieve the marker mask of a margin.
523 int wxStyledTextCtrl::GetMarginMask(int margin
) {
524 return SendMsg(2245, margin
, 0);
527 // Make a margin sensitive or insensitive to mouse clicks.
528 void wxStyledTextCtrl::SetMarginSensitive(int margin
, bool sensitive
) {
529 SendMsg(2246, margin
, sensitive
);
532 // Retrieve the mouse click sensitivity of a margin.
533 bool wxStyledTextCtrl::GetMarginSensitive(int margin
) {
534 return SendMsg(2247, margin
, 0) != 0;
537 // Clear all the styles and make equivalent to the global default style.
538 void wxStyledTextCtrl::StyleClearAll() {
542 // Set the foreground colour of a style.
543 void wxStyledTextCtrl::StyleSetForeground(int style
, const wxColour
& fore
) {
544 SendMsg(2051, style
, wxColourAsLong(fore
));
547 // Set the background colour of a style.
548 void wxStyledTextCtrl::StyleSetBackground(int style
, const wxColour
& back
) {
549 SendMsg(2052, style
, wxColourAsLong(back
));
552 // Set a style to be bold or not.
553 void wxStyledTextCtrl::StyleSetBold(int style
, bool bold
) {
554 SendMsg(2053, style
, bold
);
557 // Set a style to be italic or not.
558 void wxStyledTextCtrl::StyleSetItalic(int style
, bool italic
) {
559 SendMsg(2054, style
, italic
);
562 // Set the size of characters of a style.
563 void wxStyledTextCtrl::StyleSetSize(int style
, int sizePoints
) {
564 SendMsg(2055, style
, sizePoints
);
567 // Set the font of a style.
568 void wxStyledTextCtrl::StyleSetFaceName(int style
, const wxString
& fontName
) {
569 SendMsg(2056, style
, (long)(const char*)wx2stc(fontName
));
572 // Set a style to have its end of line filled or not.
573 void wxStyledTextCtrl::StyleSetEOLFilled(int style
, bool filled
) {
574 SendMsg(2057, style
, filled
);
577 // Reset the default style to its state at startup
578 void wxStyledTextCtrl::StyleResetDefault() {
582 // Set a style to be underlined or not.
583 void wxStyledTextCtrl::StyleSetUnderline(int style
, bool underline
) {
584 SendMsg(2059, style
, underline
);
587 // Set a style to be mixed case, or to force upper or lower case.
588 void wxStyledTextCtrl::StyleSetCase(int style
, int caseForce
) {
589 SendMsg(2060, style
, caseForce
);
592 // Set the character set of the font in a style.
593 void wxStyledTextCtrl::StyleSetCharacterSet(int style
, int characterSet
) {
594 SendMsg(2066, style
, characterSet
);
597 // Set a style to be a hotspot or not.
598 void wxStyledTextCtrl::StyleSetHotSpot(int style
, bool hotspot
) {
599 SendMsg(2409, style
, hotspot
);
602 // Set the foreground colour of the selection and whether to use this setting.
603 void wxStyledTextCtrl::SetSelForeground(bool useSetting
, const wxColour
& fore
) {
604 SendMsg(2067, useSetting
, wxColourAsLong(fore
));
607 // Set the background colour of the selection and whether to use this setting.
608 void wxStyledTextCtrl::SetSelBackground(bool useSetting
, const wxColour
& back
) {
609 SendMsg(2068, useSetting
, wxColourAsLong(back
));
612 // Set the foreground colour of the caret.
613 void wxStyledTextCtrl::SetCaretForeground(const wxColour
& fore
) {
614 SendMsg(2069, wxColourAsLong(fore
), 0);
617 // When key+modifier combination km is pressed perform msg.
618 void wxStyledTextCtrl::CmdKeyAssign(int key
, int modifiers
, int cmd
) {
619 SendMsg(2070, MAKELONG(key
, modifiers
), cmd
);
622 // When key+modifier combination km do nothing.
623 void wxStyledTextCtrl::CmdKeyClear(int key
, int modifiers
) {
624 SendMsg(2071, MAKELONG(key
, modifiers
));
627 // Drop all key mappings.
628 void wxStyledTextCtrl::CmdKeyClearAll() {
632 // Set the styles for a segment of the document.
633 void wxStyledTextCtrl::SetStyleBytes(int length
, char* styleBytes
) {
634 SendMsg(2073, length
, (long)styleBytes
);
637 // Set a style to be visible or not.
638 void wxStyledTextCtrl::StyleSetVisible(int style
, bool visible
) {
639 SendMsg(2074, style
, visible
);
642 // Get the time in milliseconds that the caret is on and off.
643 int wxStyledTextCtrl::GetCaretPeriod() {
644 return SendMsg(2075, 0, 0);
647 // Get the time in milliseconds that the caret is on and off. 0 = steady on.
648 void wxStyledTextCtrl::SetCaretPeriod(int periodMilliseconds
) {
649 SendMsg(2076, periodMilliseconds
, 0);
652 // Set the set of characters making up words for when moving or selecting by word.
653 void wxStyledTextCtrl::SetWordChars(const wxString
& characters
) {
654 SendMsg(2077, 0, (long)(const char*)wx2stc(characters
));
657 // Start a sequence of actions that is undone and redone as a unit.
659 void wxStyledTextCtrl::BeginUndoAction() {
663 // End a sequence of actions that is undone and redone as a unit.
664 void wxStyledTextCtrl::EndUndoAction() {
668 // Set an indicator to plain, squiggle or TT.
669 void wxStyledTextCtrl::IndicatorSetStyle(int indic
, int style
) {
670 SendMsg(2080, indic
, style
);
673 // Retrieve the style of an indicator.
674 int wxStyledTextCtrl::IndicatorGetStyle(int indic
) {
675 return SendMsg(2081, indic
, 0);
678 // Set the foreground colour of an indicator.
679 void wxStyledTextCtrl::IndicatorSetForeground(int indic
, const wxColour
& fore
) {
680 SendMsg(2082, indic
, wxColourAsLong(fore
));
683 // Retrieve the foreground colour of an indicator.
684 wxColour
wxStyledTextCtrl::IndicatorGetForeground(int indic
) {
685 long c
= SendMsg(2083, indic
, 0);
686 return wxColourFromLong(c
);
689 // Set the foreground colour of all whitespace and whether to use this setting.
690 void wxStyledTextCtrl::SetWhitespaceForeground(bool useSetting
, const wxColour
& fore
) {
691 SendMsg(2084, useSetting
, wxColourAsLong(fore
));
694 // Set the background colour of all whitespace and whether to use this setting.
695 void wxStyledTextCtrl::SetWhitespaceBackground(bool useSetting
, const wxColour
& back
) {
696 SendMsg(2085, useSetting
, wxColourAsLong(back
));
699 // Divide each styling byte into lexical class bits (default: 5) and indicator
700 // bits (default: 3). If a lexer requires more than 32 lexical states, then this
701 // is used to expand the possible states.
702 void wxStyledTextCtrl::SetStyleBits(int bits
) {
703 SendMsg(2090, bits
, 0);
706 // Retrieve number of bits in style bytes used to hold the lexical state.
707 int wxStyledTextCtrl::GetStyleBits() {
708 return SendMsg(2091, 0, 0);
711 // Used to hold extra styling information for each line.
712 void wxStyledTextCtrl::SetLineState(int line
, int state
) {
713 SendMsg(2092, line
, state
);
716 // Retrieve the extra styling information for a line.
717 int wxStyledTextCtrl::GetLineState(int line
) {
718 return SendMsg(2093, line
, 0);
721 // Retrieve the last line number that has line state.
722 int wxStyledTextCtrl::GetMaxLineState() {
723 return SendMsg(2094, 0, 0);
726 // Is the background of the line containing the caret in a different colour?
727 bool wxStyledTextCtrl::GetCaretLineVisible() {
728 return SendMsg(2095, 0, 0) != 0;
731 // Display the background of the line containing the caret in a different colour.
732 void wxStyledTextCtrl::SetCaretLineVisible(bool show
) {
733 SendMsg(2096, show
, 0);
736 // Get the colour of the background of the line containing the caret.
737 wxColour
wxStyledTextCtrl::GetCaretLineBack() {
738 long c
= SendMsg(2097, 0, 0);
739 return wxColourFromLong(c
);
742 // Set the colour of the background of the line containing the caret.
743 void wxStyledTextCtrl::SetCaretLineBack(const wxColour
& back
) {
744 SendMsg(2098, wxColourAsLong(back
), 0);
747 // Set a style to be changeable or not (read only).
748 // Experimental feature, currently buggy.
749 void wxStyledTextCtrl::StyleSetChangeable(int style
, bool changeable
) {
750 SendMsg(2099, style
, changeable
);
753 // Display a auto-completion list.
754 // The lenEntered parameter indicates how many characters before
755 // the caret should be used to provide context.
756 void wxStyledTextCtrl::AutoCompShow(int lenEntered
, const wxString
& itemList
) {
757 SendMsg(2100, lenEntered
, (long)(const char*)wx2stc(itemList
));
760 // Remove the auto-completion list from the screen.
761 void wxStyledTextCtrl::AutoCompCancel() {
765 // Is there an auto-completion list visible?
766 bool wxStyledTextCtrl::AutoCompActive() {
767 return SendMsg(2102, 0, 0) != 0;
770 // Retrieve the position of the caret when the auto-completion list was displayed.
771 int wxStyledTextCtrl::AutoCompPosStart() {
772 return SendMsg(2103, 0, 0);
775 // User has selected an item so remove the list and insert the selection.
776 void wxStyledTextCtrl::AutoCompComplete() {
780 // Define a set of character that when typed cancel the auto-completion list.
781 void wxStyledTextCtrl::AutoCompStops(const wxString
& characterSet
) {
782 SendMsg(2105, 0, (long)(const char*)wx2stc(characterSet
));
785 // Change the separator character in the string setting up an auto-completion list.
786 // Default is space but can be changed if items contain space.
787 void wxStyledTextCtrl::AutoCompSetSeparator(int separatorCharacter
) {
788 SendMsg(2106, separatorCharacter
, 0);
791 // Retrieve the auto-completion list separator character.
792 int wxStyledTextCtrl::AutoCompGetSeparator() {
793 return SendMsg(2107, 0, 0);
796 // Select the item in the auto-completion list that starts with a string.
797 void wxStyledTextCtrl::AutoCompSelect(const wxString
& text
) {
798 SendMsg(2108, 0, (long)(const char*)wx2stc(text
));
801 // Should the auto-completion list be cancelled if the user backspaces to a
802 // position before where the box was created.
803 void wxStyledTextCtrl::AutoCompSetCancelAtStart(bool cancel
) {
804 SendMsg(2110, cancel
, 0);
807 // Retrieve whether auto-completion cancelled by backspacing before start.
808 bool wxStyledTextCtrl::AutoCompGetCancelAtStart() {
809 return SendMsg(2111, 0, 0) != 0;
812 // Define a set of characters that when typed will cause the autocompletion to
813 // choose the selected item.
814 void wxStyledTextCtrl::AutoCompSetFillUps(const wxString
& characterSet
) {
815 SendMsg(2112, 0, (long)(const char*)wx2stc(characterSet
));
818 // Should a single item auto-completion list automatically choose the item.
819 void wxStyledTextCtrl::AutoCompSetChooseSingle(bool chooseSingle
) {
820 SendMsg(2113, chooseSingle
, 0);
823 // Retrieve whether a single item auto-completion list automatically choose the item.
824 bool wxStyledTextCtrl::AutoCompGetChooseSingle() {
825 return SendMsg(2114, 0, 0) != 0;
828 // Set whether case is significant when performing auto-completion searches.
829 void wxStyledTextCtrl::AutoCompSetIgnoreCase(bool ignoreCase
) {
830 SendMsg(2115, ignoreCase
, 0);
833 // Retrieve state of ignore case flag.
834 bool wxStyledTextCtrl::AutoCompGetIgnoreCase() {
835 return SendMsg(2116, 0, 0) != 0;
838 // Display a list of strings and send notification when user chooses one.
839 void wxStyledTextCtrl::UserListShow(int listType
, const wxString
& itemList
) {
840 SendMsg(2117, listType
, (long)(const char*)wx2stc(itemList
));
843 // Set whether or not autocompletion is hidden automatically when nothing matches.
844 void wxStyledTextCtrl::AutoCompSetAutoHide(bool autoHide
) {
845 SendMsg(2118, autoHide
, 0);
848 // Retrieve whether or not autocompletion is hidden automatically when nothing matches.
849 bool wxStyledTextCtrl::AutoCompGetAutoHide() {
850 return SendMsg(2119, 0, 0) != 0;
853 // Set whether or not autocompletion deletes any word characters
854 // after the inserted text upon completion.
855 void wxStyledTextCtrl::AutoCompSetDropRestOfWord(bool dropRestOfWord
) {
856 SendMsg(2270, dropRestOfWord
, 0);
859 // Retrieve whether or not autocompletion deletes any word characters
860 // after the inserted text upon completion.
861 bool wxStyledTextCtrl::AutoCompGetDropRestOfWord() {
862 return SendMsg(2271, 0, 0) != 0;
865 // Register an image for use in autocompletion lists.
866 void wxStyledTextCtrl::RegisterImage(int type
, const wxBitmap
& bmp
) {
867 // convert bmp to a xpm in a string
868 wxMemoryOutputStream strm
;
869 wxImage img
= bmp
.ConvertToImage();
870 img
.SaveFile(strm
, wxBITMAP_TYPE_XPM
);
871 size_t len
= strm
.GetSize();
872 char* buff
= new char[len
+1];
873 strm
.CopyTo(buff
, len
);
875 SendMsg(2405, type
, (long)buff
);
880 // Clear all the registered images.
881 void wxStyledTextCtrl::ClearRegisteredImages() {
885 // Retrieve the auto-completion list type-separator character.
886 int wxStyledTextCtrl::AutoCompGetTypeSeparator() {
887 return SendMsg(2285, 0, 0);
890 // Change the type-separator character in the string setting up an auto-completion list.
891 // Default is '?' but can be changed if items contain '?'.
892 void wxStyledTextCtrl::AutoCompSetTypeSeparator(int separatorCharacter
) {
893 SendMsg(2286, separatorCharacter
, 0);
896 // Set the number of spaces used for one level of indentation.
897 void wxStyledTextCtrl::SetIndent(int indentSize
) {
898 SendMsg(2122, indentSize
, 0);
901 // Retrieve indentation size.
902 int wxStyledTextCtrl::GetIndent() {
903 return SendMsg(2123, 0, 0);
906 // Indentation will only use space characters if useTabs is false, otherwise
907 // it will use a combination of tabs and spaces.
908 void wxStyledTextCtrl::SetUseTabs(bool useTabs
) {
909 SendMsg(2124, useTabs
, 0);
912 // Retrieve whether tabs will be used in indentation.
913 bool wxStyledTextCtrl::GetUseTabs() {
914 return SendMsg(2125, 0, 0) != 0;
917 // Change the indentation of a line to a number of columns.
918 void wxStyledTextCtrl::SetLineIndentation(int line
, int indentSize
) {
919 SendMsg(2126, line
, indentSize
);
922 // Retrieve the number of columns that a line is indented.
923 int wxStyledTextCtrl::GetLineIndentation(int line
) {
924 return SendMsg(2127, line
, 0);
927 // Retrieve the position before the first non indentation character on a line.
928 int wxStyledTextCtrl::GetLineIndentPosition(int line
) {
929 return SendMsg(2128, line
, 0);
932 // Retrieve the column number of a position, taking tab width into account.
933 int wxStyledTextCtrl::GetColumn(int pos
) {
934 return SendMsg(2129, pos
, 0);
937 // Show or hide the horizontal scroll bar.
938 void wxStyledTextCtrl::SetUseHorizontalScrollBar(bool show
) {
939 SendMsg(2130, show
, 0);
942 // Is the horizontal scroll bar visible?
943 bool wxStyledTextCtrl::GetUseHorizontalScrollBar() {
944 return SendMsg(2131, 0, 0) != 0;
947 // Show or hide indentation guides.
948 void wxStyledTextCtrl::SetIndentationGuides(bool show
) {
949 SendMsg(2132, show
, 0);
952 // Are the indentation guides visible?
953 bool wxStyledTextCtrl::GetIndentationGuides() {
954 return SendMsg(2133, 0, 0) != 0;
957 // Set the highlighted indentation guide column.
958 // 0 = no highlighted guide.
959 void wxStyledTextCtrl::SetHighlightGuide(int column
) {
960 SendMsg(2134, column
, 0);
963 // Get the highlighted indentation guide column.
964 int wxStyledTextCtrl::GetHighlightGuide() {
965 return SendMsg(2135, 0, 0);
968 // Get the position after the last visible characters on a line.
969 int wxStyledTextCtrl::GetLineEndPosition(int line
) {
970 return SendMsg(2136, line
, 0);
973 // Get the code page used to interpret the bytes of the document as characters.
974 int wxStyledTextCtrl::GetCodePage() {
975 return SendMsg(2137, 0, 0);
978 // Get the foreground colour of the caret.
979 wxColour
wxStyledTextCtrl::GetCaretForeground() {
980 long c
= SendMsg(2138, 0, 0);
981 return wxColourFromLong(c
);
984 // In read-only mode?
985 bool wxStyledTextCtrl::GetReadOnly() {
986 return SendMsg(2140, 0, 0) != 0;
989 // Sets the position of the caret.
990 void wxStyledTextCtrl::SetCurrentPos(int pos
) {
991 SendMsg(2141, pos
, 0);
994 // Sets the position that starts the selection - this becomes the anchor.
995 void wxStyledTextCtrl::SetSelectionStart(int pos
) {
996 SendMsg(2142, pos
, 0);
999 // Returns the position at the start of the selection.
1000 int wxStyledTextCtrl::GetSelectionStart() {
1001 return SendMsg(2143, 0, 0);
1004 // Sets the position that ends the selection - this becomes the currentPosition.
1005 void wxStyledTextCtrl::SetSelectionEnd(int pos
) {
1006 SendMsg(2144, pos
, 0);
1009 // Returns the position at the end of the selection.
1010 int wxStyledTextCtrl::GetSelectionEnd() {
1011 return SendMsg(2145, 0, 0);
1014 // Sets the print magnification added to the point size of each style for printing.
1015 void wxStyledTextCtrl::SetPrintMagnification(int magnification
) {
1016 SendMsg(2146, magnification
, 0);
1019 // Returns the print magnification.
1020 int wxStyledTextCtrl::GetPrintMagnification() {
1021 return SendMsg(2147, 0, 0);
1024 // Modify colours when printing for clearer printed text.
1025 void wxStyledTextCtrl::SetPrintColourMode(int mode
) {
1026 SendMsg(2148, mode
, 0);
1029 // Returns the print colour mode.
1030 int wxStyledTextCtrl::GetPrintColourMode() {
1031 return SendMsg(2149, 0, 0);
1034 // Find some text in the document.
1035 int wxStyledTextCtrl::FindText(int minPos
, int maxPos
,
1036 const wxString
& text
,
1039 ft
.chrg
.cpMin
= minPos
;
1040 ft
.chrg
.cpMax
= maxPos
;
1041 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
1042 ft
.lpstrText
= (char*)(const char*)buf
;
1044 return SendMsg(2150, flags
, (long)&ft
);
1047 // On Windows, will draw the document into a display context such as a printer.
1048 int wxStyledTextCtrl::FormatRange(bool doDraw
,
1052 wxDC
* target
, // Why does it use two? Can they be the same?
1057 if (endPos
< startPos
) {
1058 int temp
= startPos
;
1063 fr
.hdcTarget
= target
;
1064 fr
.rc
.top
= renderRect
.GetTop();
1065 fr
.rc
.left
= renderRect
.GetLeft();
1066 fr
.rc
.right
= renderRect
.GetRight();
1067 fr
.rc
.bottom
= renderRect
.GetBottom();
1068 fr
.rcPage
.top
= pageRect
.GetTop();
1069 fr
.rcPage
.left
= pageRect
.GetLeft();
1070 fr
.rcPage
.right
= pageRect
.GetRight();
1071 fr
.rcPage
.bottom
= pageRect
.GetBottom();
1072 fr
.chrg
.cpMin
= startPos
;
1073 fr
.chrg
.cpMax
= endPos
;
1075 return SendMsg(2151, doDraw
, (long)&fr
);
1078 // Retrieve the display line at the top of the display.
1079 int wxStyledTextCtrl::GetFirstVisibleLine() {
1080 return SendMsg(2152, 0, 0);
1083 // Retrieve the contents of a line.
1084 wxString
wxStyledTextCtrl::GetLine(int line
) {
1085 int len
= LineLength(line
);
1086 if (!len
) return wxEmptyString
;
1088 wxMemoryBuffer
mbuf(len
+1);
1089 char* buf
= (char*)mbuf
.GetWriteBuf(len
+1);
1090 SendMsg(2153, line
, (long)buf
);
1091 mbuf
.UngetWriteBuf(len
);
1096 // Returns the number of lines in the document. There is always at least one.
1097 int wxStyledTextCtrl::GetLineCount() {
1098 return SendMsg(2154, 0, 0);
1101 // Sets the size in pixels of the left margin.
1102 void wxStyledTextCtrl::SetMarginLeft(int pixelWidth
) {
1103 SendMsg(2155, 0, pixelWidth
);
1106 // Returns the size in pixels of the left margin.
1107 int wxStyledTextCtrl::GetMarginLeft() {
1108 return SendMsg(2156, 0, 0);
1111 // Sets the size in pixels of the right margin.
1112 void wxStyledTextCtrl::SetMarginRight(int pixelWidth
) {
1113 SendMsg(2157, 0, pixelWidth
);
1116 // Returns the size in pixels of the right margin.
1117 int wxStyledTextCtrl::GetMarginRight() {
1118 return SendMsg(2158, 0, 0);
1121 // Is the document different from when it was last saved?
1122 bool wxStyledTextCtrl::GetModify() {
1123 return SendMsg(2159, 0, 0) != 0;
1126 // Select a range of text.
1127 void wxStyledTextCtrl::SetSelection(int start
, int end
) {
1128 SendMsg(2160, start
, end
);
1131 // Retrieve the selected text.
1132 wxString
wxStyledTextCtrl::GetSelectedText() {
1136 GetSelection(&start
, &end
);
1137 int len
= end
- start
;
1138 if (!len
) return wxEmptyString
;
1140 wxMemoryBuffer
mbuf(len
+2);
1141 char* buf
= (char*)mbuf
.GetWriteBuf(len
+1);
1142 SendMsg(2161, 0, (long)buf
);
1143 mbuf
.UngetWriteBuf(len
);
1148 // Retrieve a range of text.
1149 wxString
wxStyledTextCtrl::GetTextRange(int startPos
, int endPos
) {
1150 if (endPos
< startPos
) {
1151 int temp
= startPos
;
1155 int len
= endPos
- startPos
;
1156 if (!len
) return wxEmptyString
;
1157 wxMemoryBuffer
mbuf(len
+1);
1158 char* buf
= (char*)mbuf
.GetWriteBuf(len
);
1161 tr
.chrg
.cpMin
= startPos
;
1162 tr
.chrg
.cpMax
= endPos
;
1163 SendMsg(2162, 0, (long)&tr
);
1164 mbuf
.UngetWriteBuf(len
);
1169 // Draw the selection in normal style or with selection highlighted.
1170 void wxStyledTextCtrl::HideSelection(bool normal
) {
1171 SendMsg(2163, normal
, 0);
1174 // Retrieve the line containing a position.
1175 int wxStyledTextCtrl::LineFromPosition(int pos
) {
1176 return SendMsg(2166, pos
, 0);
1179 // Retrieve the position at the start of a line.
1180 int wxStyledTextCtrl::PositionFromLine(int line
) {
1181 return SendMsg(2167, line
, 0);
1184 // Scroll horizontally and vertically.
1185 void wxStyledTextCtrl::LineScroll(int columns
, int lines
) {
1186 SendMsg(2168, columns
, lines
);
1189 // Ensure the caret is visible.
1190 void wxStyledTextCtrl::EnsureCaretVisible() {
1191 SendMsg(2169, 0, 0);
1194 // Replace the selected text with the argument text.
1195 void wxStyledTextCtrl::ReplaceSelection(const wxString
& text
) {
1196 SendMsg(2170, 0, (long)(const char*)wx2stc(text
));
1199 // Set to read only or read write.
1200 void wxStyledTextCtrl::SetReadOnly(bool readOnly
) {
1201 SendMsg(2171, readOnly
, 0);
1204 // Will a paste succeed?
1205 bool wxStyledTextCtrl::CanPaste() {
1206 return SendMsg(2173, 0, 0) != 0;
1209 // Are there any undoable actions in the undo history?
1210 bool wxStyledTextCtrl::CanUndo() {
1211 return SendMsg(2174, 0, 0) != 0;
1214 // Delete the undo history.
1215 void wxStyledTextCtrl::EmptyUndoBuffer() {
1216 SendMsg(2175, 0, 0);
1219 // Undo one action in the undo history.
1220 void wxStyledTextCtrl::Undo() {
1221 SendMsg(2176, 0, 0);
1224 // Cut the selection to the clipboard.
1225 void wxStyledTextCtrl::Cut() {
1226 SendMsg(2177, 0, 0);
1229 // Copy the selection to the clipboard.
1230 void wxStyledTextCtrl::Copy() {
1231 SendMsg(2178, 0, 0);
1234 // Paste the contents of the clipboard into the document replacing the selection.
1235 void wxStyledTextCtrl::Paste() {
1236 SendMsg(2179, 0, 0);
1239 // Clear the selection.
1240 void wxStyledTextCtrl::Clear() {
1241 SendMsg(2180, 0, 0);
1244 // Replace the contents of the document with the argument text.
1245 void wxStyledTextCtrl::SetText(const wxString
& text
) {
1246 SendMsg(2181, 0, (long)(const char*)wx2stc(text
));
1249 // Retrieve all the text in the document.
1250 wxString
wxStyledTextCtrl::GetText() {
1251 int len
= GetTextLength();
1252 wxMemoryBuffer
mbuf(len
+1); // leave room for the null...
1253 char* buf
= (char*)mbuf
.GetWriteBuf(len
+1);
1254 SendMsg(2182, len
+1, (long)buf
);
1255 mbuf
.UngetWriteBuf(len
);
1260 // Retrieve the number of characters in the document.
1261 int wxStyledTextCtrl::GetTextLength() {
1262 return SendMsg(2183, 0, 0);
1265 // Set to overtype (true) or insert mode.
1266 void wxStyledTextCtrl::SetOvertype(bool overtype
) {
1267 SendMsg(2186, overtype
, 0);
1270 // Returns true if overtype mode is active otherwise false is returned.
1271 bool wxStyledTextCtrl::GetOvertype() {
1272 return SendMsg(2187, 0, 0) != 0;
1275 // Set the width of the insert mode caret.
1276 void wxStyledTextCtrl::SetCaretWidth(int pixelWidth
) {
1277 SendMsg(2188, pixelWidth
, 0);
1280 // Returns the width of the insert mode caret.
1281 int wxStyledTextCtrl::GetCaretWidth() {
1282 return SendMsg(2189, 0, 0);
1285 // Sets the position that starts the target which is used for updating the
1286 // document without affecting the scroll position.
1287 void wxStyledTextCtrl::SetTargetStart(int pos
) {
1288 SendMsg(2190, pos
, 0);
1291 // Get the position that starts the target.
1292 int wxStyledTextCtrl::GetTargetStart() {
1293 return SendMsg(2191, 0, 0);
1296 // Sets the position that ends the target which is used for updating the
1297 // document without affecting the scroll position.
1298 void wxStyledTextCtrl::SetTargetEnd(int pos
) {
1299 SendMsg(2192, pos
, 0);
1302 // Get the position that ends the target.
1303 int wxStyledTextCtrl::GetTargetEnd() {
1304 return SendMsg(2193, 0, 0);
1307 // Replace the target text with the argument text.
1308 // Text is counted so it can contain nulls.
1309 // Returns the length of the replacement text.
1311 int wxStyledTextCtrl::ReplaceTarget(const wxString
& text
) {
1312 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
1313 return SendMsg(2194, strlen(buf
), (long)(const char*)buf
);
1316 // Replace the target text with the argument text after \d processing.
1317 // Text is counted so it can contain nulls.
1318 // Looks for \d where d is between 1 and 9 and replaces these with the strings
1319 // matched in the last search operation which were surrounded by \( and \).
1320 // Returns the length of the replacement text including any change
1321 // caused by processing the \d patterns.
1323 int wxStyledTextCtrl::ReplaceTargetRE(const wxString
& text
) {
1324 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
1325 return SendMsg(2195, strlen(buf
), (long)(const char*)buf
);
1328 // Search for a counted string in the target and set the target to the found
1329 // range. Text is counted so it can contain nulls.
1330 // Returns length of range or -1 for failure in which case target is not moved.
1332 int wxStyledTextCtrl::SearchInTarget(const wxString
& text
) {
1333 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
1334 return SendMsg(2197, strlen(buf
), (long)(const char*)buf
);
1337 // Set the search flags used by SearchInTarget.
1338 void wxStyledTextCtrl::SetSearchFlags(int flags
) {
1339 SendMsg(2198, flags
, 0);
1342 // Get the search flags used by SearchInTarget.
1343 int wxStyledTextCtrl::GetSearchFlags() {
1344 return SendMsg(2199, 0, 0);
1347 // Show a call tip containing a definition near position pos.
1348 void wxStyledTextCtrl::CallTipShow(int pos
, const wxString
& definition
) {
1349 SendMsg(2200, pos
, (long)(const char*)wx2stc(definition
));
1352 // Remove the call tip from the screen.
1353 void wxStyledTextCtrl::CallTipCancel() {
1354 SendMsg(2201, 0, 0);
1357 // Is there an active call tip?
1358 bool wxStyledTextCtrl::CallTipActive() {
1359 return SendMsg(2202, 0, 0) != 0;
1362 // Retrieve the position where the caret was before displaying the call tip.
1363 int wxStyledTextCtrl::CallTipPosAtStart() {
1364 return SendMsg(2203, 0, 0);
1367 // Highlight a segment of the definition.
1368 void wxStyledTextCtrl::CallTipSetHighlight(int start
, int end
) {
1369 SendMsg(2204, start
, end
);
1372 // Set the background colour for the call tip.
1373 void wxStyledTextCtrl::CallTipSetBackground(const wxColour
& back
) {
1374 SendMsg(2205, wxColourAsLong(back
), 0);
1377 // Set the foreground colour for the call tip.
1378 void wxStyledTextCtrl::CallTipSetForeground(const wxColour
& fore
) {
1379 SendMsg(2206, wxColourAsLong(fore
), 0);
1382 // Set the foreground colour for the highlighted part of the call tip.
1383 void wxStyledTextCtrl::CallTipSetForegroundHighlight(const wxColour
& fore
) {
1384 SendMsg(2207, wxColourAsLong(fore
), 0);
1387 // Find the display line of a document line taking hidden lines into account.
1388 int wxStyledTextCtrl::VisibleFromDocLine(int line
) {
1389 return SendMsg(2220, line
, 0);
1392 // Find the document line of a display line taking hidden lines into account.
1393 int wxStyledTextCtrl::DocLineFromVisible(int lineDisplay
) {
1394 return SendMsg(2221, lineDisplay
, 0);
1397 // Set the fold level of a line.
1398 // This encodes an integer level along with flags indicating whether the
1399 // line is a header and whether it is effectively white space.
1400 void wxStyledTextCtrl::SetFoldLevel(int line
, int level
) {
1401 SendMsg(2222, line
, level
);
1404 // Retrieve the fold level of a line.
1405 int wxStyledTextCtrl::GetFoldLevel(int line
) {
1406 return SendMsg(2223, line
, 0);
1409 // Find the last child line of a header line.
1410 int wxStyledTextCtrl::GetLastChild(int line
, int level
) {
1411 return SendMsg(2224, line
, level
);
1414 // Find the parent line of a child line.
1415 int wxStyledTextCtrl::GetFoldParent(int line
) {
1416 return SendMsg(2225, line
, 0);
1419 // Make a range of lines visible.
1420 void wxStyledTextCtrl::ShowLines(int lineStart
, int lineEnd
) {
1421 SendMsg(2226, lineStart
, lineEnd
);
1424 // Make a range of lines invisible.
1425 void wxStyledTextCtrl::HideLines(int lineStart
, int lineEnd
) {
1426 SendMsg(2227, lineStart
, lineEnd
);
1429 // Is a line visible?
1430 bool wxStyledTextCtrl::GetLineVisible(int line
) {
1431 return SendMsg(2228, line
, 0) != 0;
1434 // Show the children of a header line.
1435 void wxStyledTextCtrl::SetFoldExpanded(int line
, bool expanded
) {
1436 SendMsg(2229, line
, expanded
);
1439 // Is a header line expanded?
1440 bool wxStyledTextCtrl::GetFoldExpanded(int line
) {
1441 return SendMsg(2230, line
, 0) != 0;
1444 // Switch a header line between expanded and contracted.
1445 void wxStyledTextCtrl::ToggleFold(int line
) {
1446 SendMsg(2231, line
, 0);
1449 // Ensure a particular line is visible by expanding any header line hiding it.
1450 void wxStyledTextCtrl::EnsureVisible(int line
) {
1451 SendMsg(2232, line
, 0);
1454 // Set some style options for folding.
1455 void wxStyledTextCtrl::SetFoldFlags(int flags
) {
1456 SendMsg(2233, flags
, 0);
1459 // Ensure a particular line is visible by expanding any header line hiding it.
1460 // Use the currently set visibility policy to determine which range to display.
1461 void wxStyledTextCtrl::EnsureVisibleEnforcePolicy(int line
) {
1462 SendMsg(2234, line
, 0);
1465 // Sets whether a tab pressed when caret is within indentation indents.
1466 void wxStyledTextCtrl::SetTabIndents(bool tabIndents
) {
1467 SendMsg(2260, tabIndents
, 0);
1470 // Does a tab pressed when caret is within indentation indent?
1471 bool wxStyledTextCtrl::GetTabIndents() {
1472 return SendMsg(2261, 0, 0) != 0;
1475 // Sets whether a backspace pressed when caret is within indentation unindents.
1476 void wxStyledTextCtrl::SetBackSpaceUnIndents(bool bsUnIndents
) {
1477 SendMsg(2262, bsUnIndents
, 0);
1480 // Does a backspace pressed when caret is within indentation unindent?
1481 bool wxStyledTextCtrl::GetBackSpaceUnIndents() {
1482 return SendMsg(2263, 0, 0) != 0;
1485 // Sets the time the mouse must sit still to generate a mouse dwell event.
1486 void wxStyledTextCtrl::SetMouseDwellTime(int periodMilliseconds
) {
1487 SendMsg(2264, periodMilliseconds
, 0);
1490 // Retrieve the time the mouse must sit still to generate a mouse dwell event.
1491 int wxStyledTextCtrl::GetMouseDwellTime() {
1492 return SendMsg(2265, 0, 0);
1495 // Get position of start of word.
1496 int wxStyledTextCtrl::WordStartPosition(int pos
, bool onlyWordCharacters
) {
1497 return SendMsg(2266, pos
, onlyWordCharacters
);
1500 // Get position of end of word.
1501 int wxStyledTextCtrl::WordEndPosition(int pos
, bool onlyWordCharacters
) {
1502 return SendMsg(2267, pos
, onlyWordCharacters
);
1505 // Sets whether text is word wrapped.
1506 void wxStyledTextCtrl::SetWrapMode(int mode
) {
1507 SendMsg(2268, mode
, 0);
1510 // Retrieve whether text is word wrapped.
1511 int wxStyledTextCtrl::GetWrapMode() {
1512 return SendMsg(2269, 0, 0);
1515 // Sets the degree of caching of layout information.
1516 void wxStyledTextCtrl::SetLayoutCache(int mode
) {
1517 SendMsg(2272, mode
, 0);
1520 // Retrieve the degree of caching of layout information.
1521 int wxStyledTextCtrl::GetLayoutCache() {
1522 return SendMsg(2273, 0, 0);
1525 // Sets the document width assumed for scrolling.
1526 void wxStyledTextCtrl::SetScrollWidth(int pixelWidth
) {
1527 SendMsg(2274, pixelWidth
, 0);
1530 // Retrieve the document width assumed for scrolling.
1531 int wxStyledTextCtrl::GetScrollWidth() {
1532 return SendMsg(2275, 0, 0);
1535 // Measure the pixel width of some text in a particular style.
1536 // Nul terminated text argument.
1537 // Does not handle tab or control characters.
1538 int wxStyledTextCtrl::TextWidth(int style
, const wxString
& text
) {
1539 return SendMsg(2276, style
, (long)(const char*)wx2stc(text
));
1542 // Sets the scroll range so that maximum scroll position has
1543 // the last line at the bottom of the view (default).
1544 // Setting this to false allows scrolling one page below the last line.
1545 void wxStyledTextCtrl::SetEndAtLastLine(bool endAtLastLine
) {
1546 SendMsg(2277, endAtLastLine
, 0);
1549 // Retrieve whether the maximum scroll position has the last
1550 // line at the bottom of the view.
1551 int wxStyledTextCtrl::GetEndAtLastLine() {
1552 return SendMsg(2278, 0, 0);
1555 // Retrieve the height of a particular line of text in pixels.
1556 int wxStyledTextCtrl::TextHeight(int line
) {
1557 return SendMsg(2279, line
, 0);
1560 // Show or hide the vertical scroll bar.
1561 void wxStyledTextCtrl::SetUseVerticalScrollBar(bool show
) {
1562 SendMsg(2280, show
, 0);
1565 // Is the vertical scroll bar visible?
1566 bool wxStyledTextCtrl::GetUseVerticalScrollBar() {
1567 return SendMsg(2281, 0, 0) != 0;
1570 // Append a string to the end of the document without changing the selection.
1571 void wxStyledTextCtrl::AppendText(int length
, const wxString
& text
) {
1572 SendMsg(2282, length
, (long)(const char*)wx2stc(text
));
1575 // Is drawing done in two phases with backgrounds drawn before foregrounds?
1576 bool wxStyledTextCtrl::GetTwoPhaseDraw() {
1577 return SendMsg(2283, 0, 0) != 0;
1580 // In twoPhaseDraw mode, drawing is performed in two phases, first the background
1581 // and then the foreground. This avoids chopping off characters that overlap the next run.
1582 void wxStyledTextCtrl::SetTwoPhaseDraw(bool twoPhase
) {
1583 SendMsg(2284, twoPhase
, 0);
1586 // Make the target range start and end be the same as the selection range start and end.
1587 void wxStyledTextCtrl::TargetFromSelection() {
1588 SendMsg(2287, 0, 0);
1591 // Join the lines in the target.
1592 void wxStyledTextCtrl::LinesJoin() {
1593 SendMsg(2288, 0, 0);
1596 // Split the lines in the target into lines that are less wide than pixelWidth
1598 void wxStyledTextCtrl::LinesSplit(int pixelWidth
) {
1599 SendMsg(2289, pixelWidth
, 0);
1602 // Set the colours used as a chequerboard pattern in the fold margin
1603 void wxStyledTextCtrl::SetFoldMarginColour(bool useSetting
, const wxColour
& back
) {
1604 SendMsg(2290, useSetting
, wxColourAsLong(back
));
1606 void wxStyledTextCtrl::SetFoldMarginHiColour(bool useSetting
, const wxColour
& fore
) {
1607 SendMsg(2291, useSetting
, wxColourAsLong(fore
));
1610 // Duplicate the current line.
1611 void wxStyledTextCtrl::LineDuplicate() {
1612 SendMsg(2404, 0, 0);
1615 // Move caret to first position on display line.
1616 void wxStyledTextCtrl::HomeDisplay() {
1617 SendMsg(2345, 0, 0);
1620 // Move caret to first position on display line extending selection to
1621 // new caret position.
1622 void wxStyledTextCtrl::HomeDisplayExtend() {
1623 SendMsg(2346, 0, 0);
1626 // Move caret to last position on display line.
1627 void wxStyledTextCtrl::LineEndDisplay() {
1628 SendMsg(2347, 0, 0);
1631 // Move caret to last position on display line extending selection to new
1633 void wxStyledTextCtrl::LineEndDisplayExtend() {
1634 SendMsg(2348, 0, 0);
1637 // Copy the line containing the caret.
1638 void wxStyledTextCtrl::LineCopy() {
1639 SendMsg(2455, 0, 0);
1642 // Move the caret inside current view if it's not there already.
1643 void wxStyledTextCtrl::MoveCaretInsideView() {
1644 SendMsg(2401, 0, 0);
1647 // How many characters are on a line, not including end of line characters?
1648 int wxStyledTextCtrl::LineLength(int line
) {
1649 return SendMsg(2350, line
, 0);
1652 // Highlight the characters at two positions.
1653 void wxStyledTextCtrl::BraceHighlight(int pos1
, int pos2
) {
1654 SendMsg(2351, pos1
, pos2
);
1657 // Highlight the character at a position indicating there is no matching brace.
1658 void wxStyledTextCtrl::BraceBadLight(int pos
) {
1659 SendMsg(2352, pos
, 0);
1662 // Find the position of a matching brace or INVALID_POSITION if no match.
1663 int wxStyledTextCtrl::BraceMatch(int pos
) {
1664 return SendMsg(2353, pos
, 0);
1667 // Are the end of line characters visible?
1668 bool wxStyledTextCtrl::GetViewEOL() {
1669 return SendMsg(2355, 0, 0) != 0;
1672 // Make the end of line characters visible or invisible.
1673 void wxStyledTextCtrl::SetViewEOL(bool visible
) {
1674 SendMsg(2356, visible
, 0);
1677 // Retrieve a pointer to the document object.
1678 void* wxStyledTextCtrl::GetDocPointer() {
1679 return (void*)SendMsg(2357);
1682 // Change the document object used.
1683 void wxStyledTextCtrl::SetDocPointer(void* docPointer
) {
1684 SendMsg(2358, 0, (long)docPointer
);
1687 // Set which document modification events are sent to the container.
1688 void wxStyledTextCtrl::SetModEventMask(int mask
) {
1689 SendMsg(2359, mask
, 0);
1692 // Retrieve the column number which text should be kept within.
1693 int wxStyledTextCtrl::GetEdgeColumn() {
1694 return SendMsg(2360, 0, 0);
1697 // Set the column number of the edge.
1698 // If text goes past the edge then it is highlighted.
1699 void wxStyledTextCtrl::SetEdgeColumn(int column
) {
1700 SendMsg(2361, column
, 0);
1703 // Retrieve the edge highlight mode.
1704 int wxStyledTextCtrl::GetEdgeMode() {
1705 return SendMsg(2362, 0, 0);
1708 // The edge may be displayed by a line (EDGE_LINE) or by highlighting text that
1709 // goes beyond it (EDGE_BACKGROUND) or not displayed at all (EDGE_NONE).
1710 void wxStyledTextCtrl::SetEdgeMode(int mode
) {
1711 SendMsg(2363, mode
, 0);
1714 // Retrieve the colour used in edge indication.
1715 wxColour
wxStyledTextCtrl::GetEdgeColour() {
1716 long c
= SendMsg(2364, 0, 0);
1717 return wxColourFromLong(c
);
1720 // Change the colour used in edge indication.
1721 void wxStyledTextCtrl::SetEdgeColour(const wxColour
& edgeColour
) {
1722 SendMsg(2365, wxColourAsLong(edgeColour
), 0);
1725 // Sets the current caret position to be the search anchor.
1726 void wxStyledTextCtrl::SearchAnchor() {
1727 SendMsg(2366, 0, 0);
1730 // Find some text starting at the search anchor.
1731 // Does not ensure the selection is visible.
1732 int wxStyledTextCtrl::SearchNext(int flags
, const wxString
& text
) {
1733 return SendMsg(2367, flags
, (long)(const char*)wx2stc(text
));
1736 // Find some text starting at the search anchor and moving backwards.
1737 // Does not ensure the selection is visible.
1738 int wxStyledTextCtrl::SearchPrev(int flags
, const wxString
& text
) {
1739 return SendMsg(2368, flags
, (long)(const char*)wx2stc(text
));
1742 // Retrieves the number of lines completely visible.
1743 int wxStyledTextCtrl::LinesOnScreen() {
1744 return SendMsg(2370, 0, 0);
1747 // Set whether a pop up menu is displayed automatically when the user presses
1748 // the wrong mouse button.
1749 void wxStyledTextCtrl::UsePopUp(bool allowPopUp
) {
1750 SendMsg(2371, allowPopUp
, 0);
1753 // Is the selection rectangular? The alternative is the more common stream selection.
1754 bool wxStyledTextCtrl::SelectionIsRectangle() {
1755 return SendMsg(2372, 0, 0) != 0;
1758 // Set the zoom level. This number of points is added to the size of all fonts.
1759 // It may be positive to magnify or negative to reduce.
1760 void wxStyledTextCtrl::SetZoom(int zoom
) {
1761 SendMsg(2373, zoom
, 0);
1764 // Retrieve the zoom level.
1765 int wxStyledTextCtrl::GetZoom() {
1766 return SendMsg(2374, 0, 0);
1769 // Create a new document object.
1770 // Starts with reference count of 1 and not selected into editor.
1771 void* wxStyledTextCtrl::CreateDocument() {
1772 return (void*)SendMsg(2375);
1775 // Extend life of document.
1776 void wxStyledTextCtrl::AddRefDocument(void* docPointer
) {
1777 SendMsg(2376, 0, (long)docPointer
);
1780 // Release a reference to the document, deleting document if it fades to black.
1781 void wxStyledTextCtrl::ReleaseDocument(void* docPointer
) {
1782 SendMsg(2377, 0, (long)docPointer
);
1785 // Get which document modification events are sent to the container.
1786 int wxStyledTextCtrl::GetModEventMask() {
1787 return SendMsg(2378, 0, 0);
1790 // Change internal focus flag.
1791 void wxStyledTextCtrl::SetSTCFocus(bool focus
) {
1792 SendMsg(2380, focus
, 0);
1795 // Get internal focus flag.
1796 bool wxStyledTextCtrl::GetSTCFocus() {
1797 return SendMsg(2381, 0, 0) != 0;
1800 // Change error status - 0 = OK.
1801 void wxStyledTextCtrl::SetStatus(int statusCode
) {
1802 SendMsg(2382, statusCode
, 0);
1805 // Get error status.
1806 int wxStyledTextCtrl::GetStatus() {
1807 return SendMsg(2383, 0, 0);
1810 // Set whether the mouse is captured when its button is pressed.
1811 void wxStyledTextCtrl::SetMouseDownCaptures(bool captures
) {
1812 SendMsg(2384, captures
, 0);
1815 // Get whether mouse gets captured.
1816 bool wxStyledTextCtrl::GetMouseDownCaptures() {
1817 return SendMsg(2385, 0, 0) != 0;
1820 // Sets the cursor to one of the SC_CURSOR* values.
1821 void wxStyledTextCtrl::SetSTCCursor(int cursorType
) {
1822 SendMsg(2386, cursorType
, 0);
1826 int wxStyledTextCtrl::GetSTCCursor() {
1827 return SendMsg(2387, 0, 0);
1830 // Change the way control characters are displayed:
1831 // If symbol is < 32, keep the drawn way, else, use the given character.
1832 void wxStyledTextCtrl::SetControlCharSymbol(int symbol
) {
1833 SendMsg(2388, symbol
, 0);
1836 // Get the way control characters are displayed.
1837 int wxStyledTextCtrl::GetControlCharSymbol() {
1838 return SendMsg(2389, 0, 0);
1841 // Move to the previous change in capitalisation.
1842 void wxStyledTextCtrl::WordPartLeft() {
1843 SendMsg(2390, 0, 0);
1846 // Move to the previous change in capitalisation extending selection
1847 // to new caret position.
1848 void wxStyledTextCtrl::WordPartLeftExtend() {
1849 SendMsg(2391, 0, 0);
1852 // Move to the change next in capitalisation.
1853 void wxStyledTextCtrl::WordPartRight() {
1854 SendMsg(2392, 0, 0);
1857 // Move to the next change in capitalisation extending selection
1858 // to new caret position.
1859 void wxStyledTextCtrl::WordPartRightExtend() {
1860 SendMsg(2393, 0, 0);
1863 // Set the way the display area is determined when a particular line
1864 // is to be moved to by Find, FindNext, GotoLine, etc.
1865 void wxStyledTextCtrl::SetVisiblePolicy(int visiblePolicy
, int visibleSlop
) {
1866 SendMsg(2394, visiblePolicy
, visibleSlop
);
1869 // Delete back from the current position to the start of the line.
1870 void wxStyledTextCtrl::DelLineLeft() {
1871 SendMsg(2395, 0, 0);
1874 // Delete forwards from the current position to the end of the line.
1875 void wxStyledTextCtrl::DelLineRight() {
1876 SendMsg(2396, 0, 0);
1879 // Get and Set the xOffset (ie, horizonal scroll position).
1880 void wxStyledTextCtrl::SetXOffset(int newOffset
) {
1881 SendMsg(2397, newOffset
, 0);
1883 int wxStyledTextCtrl::GetXOffset() {
1884 return SendMsg(2398, 0, 0);
1887 // Set the last x chosen value to be the caret x position
1888 void wxStyledTextCtrl::ChooseCaretX() {
1889 SendMsg(2399, 0, 0);
1892 // Set the way the caret is kept visible when going sideway.
1893 // The exclusion zone is given in pixels.
1894 void wxStyledTextCtrl::SetXCaretPolicy(int caretPolicy
, int caretSlop
) {
1895 SendMsg(2402, caretPolicy
, caretSlop
);
1898 // Set the way the line the caret is on is kept visible.
1899 // The exclusion zone is given in lines.
1900 void wxStyledTextCtrl::SetYCaretPolicy(int caretPolicy
, int caretSlop
) {
1901 SendMsg(2403, caretPolicy
, caretSlop
);
1904 // Set printing to line wrapped (SC_WRAP_WORD) or not line wrapped (SC_WRAP_NONE).
1905 void wxStyledTextCtrl::SetPrintWrapMode(int mode
) {
1906 SendMsg(2406, mode
, 0);
1909 // Is printing line wrapped.
1910 int wxStyledTextCtrl::GetPrintWrapMode() {
1911 return SendMsg(2407, 0, 0);
1914 // Set a fore colour for active hotspots.
1915 void wxStyledTextCtrl::SetHotspotActiveForeground(bool useSetting
, const wxColour
& fore
) {
1916 SendMsg(2410, useSetting
, wxColourAsLong(fore
));
1919 // Set a back colour for active hotspots.
1920 void wxStyledTextCtrl::SetHotspotActiveBackground(bool useSetting
, const wxColour
& back
) {
1921 SendMsg(2411, useSetting
, wxColourAsLong(back
));
1924 // Enable / Disable underlining active hotspots.
1925 void wxStyledTextCtrl::SetHotspotActiveUnderline(bool underline
) {
1926 SendMsg(2412, underline
, 0);
1929 // Given a valid document position, return the previous position taking code
1930 // page into account. Returns 0 if passed 0.
1931 int wxStyledTextCtrl::PositionBefore(int pos
) {
1932 return SendMsg(2417, pos
, 0);
1935 // Given a valid document position, return the next position taking code
1936 // page into account. Maximum value returned is the last position in the document.
1937 int wxStyledTextCtrl::PositionAfter(int pos
) {
1938 return SendMsg(2418, pos
, 0);
1941 // Copy a range of text to the clipboard. Positions are clipped into the document.
1942 void wxStyledTextCtrl::CopyRange(int start
, int end
) {
1943 SendMsg(2419, start
, end
);
1946 // Copy argument text to the clipboard.
1947 void wxStyledTextCtrl::CopyText(int length
, const wxString
& text
) {
1948 SendMsg(2420, length
, (long)(const char*)wx2stc(text
));
1951 // Start notifying the container of all key presses and commands.
1952 void wxStyledTextCtrl::StartRecord() {
1953 SendMsg(3001, 0, 0);
1956 // Stop notifying the container of all key presses and commands.
1957 void wxStyledTextCtrl::StopRecord() {
1958 SendMsg(3002, 0, 0);
1961 // Set the lexing language of the document.
1962 void wxStyledTextCtrl::SetLexer(int lexer
) {
1963 SendMsg(4001, lexer
, 0);
1966 // Retrieve the lexing language of the document.
1967 int wxStyledTextCtrl::GetLexer() {
1968 return SendMsg(4002, 0, 0);
1971 // Colourise a segment of the document using the current lexing language.
1972 void wxStyledTextCtrl::Colourise(int start
, int end
) {
1973 SendMsg(4003, start
, end
);
1976 // Set up a value that may be used by a lexer for some optional feature.
1977 void wxStyledTextCtrl::SetProperty(const wxString
& key
, const wxString
& value
) {
1978 SendMsg(4004, (long)(const char*)wx2stc(key
), (long)(const char*)wx2stc(value
));
1981 // Set up the key words used by the lexer.
1982 void wxStyledTextCtrl::SetKeyWords(int keywordSet
, const wxString
& keyWords
) {
1983 SendMsg(4005, keywordSet
, (long)(const char*)wx2stc(keyWords
));
1986 // Set the lexing language of the document based on string name.
1987 void wxStyledTextCtrl::SetLexerLanguage(const wxString
& language
) {
1988 SendMsg(4006, 0, (long)(const char*)wx2stc(language
));
1991 // END of generated section
1992 //----------------------------------------------------------------------
1995 // Returns the line number of the line with the caret.
1996 int wxStyledTextCtrl::GetCurrentLine() {
1997 int line
= LineFromPosition(GetCurrentPos());
2002 // Extract style settings from a spec-string which is composed of one or
2003 // more of the following comma separated elements:
2005 // bold turns on bold
2006 // italic turns on italics
2007 // fore:#RRGGBB sets the foreground colour
2008 // back:#RRGGBB sets the background colour
2009 // face:[facename] sets the font face name to use
2010 // size:[num] sets the font size in points
2011 // eol turns on eol filling
2012 // underline turns on underlining
2014 void wxStyledTextCtrl::StyleSetSpec(int styleNum
, const wxString
& spec
) {
2016 wxStringTokenizer
tkz(spec
, wxT(","));
2017 while (tkz
.HasMoreTokens()) {
2018 wxString token
= tkz
.GetNextToken();
2020 wxString option
= token
.BeforeFirst(':');
2021 wxString val
= token
.AfterFirst(':');
2023 if (option
== wxT("bold"))
2024 StyleSetBold(styleNum
, true);
2026 else if (option
== wxT("italic"))
2027 StyleSetItalic(styleNum
, true);
2029 else if (option
== wxT("underline"))
2030 StyleSetUnderline(styleNum
, true);
2032 else if (option
== wxT("eol"))
2033 StyleSetEOLFilled(styleNum
, true);
2035 else if (option
== wxT("size")) {
2037 if (val
.ToLong(&points
))
2038 StyleSetSize(styleNum
, points
);
2041 else if (option
== wxT("face"))
2042 StyleSetFaceName(styleNum
, val
);
2044 else if (option
== wxT("fore"))
2045 StyleSetForeground(styleNum
, wxColourFromSpec(val
));
2047 else if (option
== wxT("back"))
2048 StyleSetBackground(styleNum
, wxColourFromSpec(val
));
2053 // Set style size, face, bold, italic, and underline attributes from
2054 // a wxFont's attributes.
2055 void wxStyledTextCtrl::StyleSetFont(int styleNum
, wxFont
& font
) {
2057 // Ensure that the native font is initialized
2059 GetTextExtent(wxT("X"), &x
, &y
, NULL
, NULL
, &font
);
2061 int size
= font
.GetPointSize();
2062 wxString faceName
= font
.GetFaceName();
2063 bool bold
= font
.GetWeight() == wxBOLD
;
2064 bool italic
= font
.GetStyle() != wxNORMAL
;
2065 bool under
= font
.GetUnderlined();
2067 // TODO: add encoding/charset mapping
2068 StyleSetFontAttr(styleNum
, size
, faceName
, bold
, italic
, under
);
2071 // Set all font style attributes at once.
2072 void wxStyledTextCtrl::StyleSetFontAttr(int styleNum
, int size
,
2073 const wxString
& faceName
,
2074 bool bold
, bool italic
,
2076 StyleSetSize(styleNum
, size
);
2077 StyleSetFaceName(styleNum
, faceName
);
2078 StyleSetBold(styleNum
, bold
);
2079 StyleSetItalic(styleNum
, italic
);
2080 StyleSetUnderline(styleNum
, underline
);
2082 // TODO: add encoding/charset mapping
2086 // Perform one of the operations defined by the wxSTC_CMD_* constants.
2087 void wxStyledTextCtrl::CmdKeyExecute(int cmd
) {
2092 // Set the left and right margin in the edit area, measured in pixels.
2093 void wxStyledTextCtrl::SetMargins(int left
, int right
) {
2094 SetMarginLeft(left
);
2095 SetMarginRight(right
);
2099 // Retrieve the start and end positions of the current selection.
2100 void wxStyledTextCtrl::GetSelection(int* startPos
, int* endPos
) {
2101 if (startPos
!= NULL
)
2102 *startPos
= SendMsg(SCI_GETSELECTIONSTART
);
2104 *endPos
= SendMsg(SCI_GETSELECTIONEND
);
2108 // Retrieve the point in the window where a position is displayed.
2109 wxPoint
wxStyledTextCtrl::PointFromPosition(int pos
) {
2110 int x
= SendMsg(SCI_POINTXFROMPOSITION
, 0, pos
);
2111 int y
= SendMsg(SCI_POINTYFROMPOSITION
, 0, pos
);
2112 return wxPoint(x
, y
);
2115 // Scroll enough to make the given line visible
2116 void wxStyledTextCtrl::ScrollToLine(int line
) {
2117 m_swx
->DoScrollToLine(line
);
2121 // Scroll enough to make the given column visible
2122 void wxStyledTextCtrl::ScrollToColumn(int column
) {
2123 m_swx
->DoScrollToColumn(column
);
2127 bool wxStyledTextCtrl::SaveFile(const wxString
& filename
)
2129 wxFile
file(filename
, wxFile::write
);
2131 if (!file
.IsOpened())
2134 bool success
= file
.Write(GetText(), *wxConvCurrent
);
2142 bool wxStyledTextCtrl::LoadFile(const wxString
& filename
)
2144 bool success
= false;
2145 wxFile
file(filename
, wxFile::read
);
2147 if (file
.IsOpened())
2150 off_t len
= file
.Length();
2154 wxMemoryBuffer
buffer(len
);
2155 success
= (file
.Read(buffer
.GetData(), len
) == len
);
2156 contents
= wxString(buffer
, *wxConvCurrent
);
2159 success
= (file
.Read(wxStringBuffer(buffer
, len
), len
) == len
);
2164 success
= true; // empty file is ok
2178 #if wxUSE_DRAG_AND_DROP
2179 wxDragResult
wxStyledTextCtrl::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
2180 return m_swx
->DoDragOver(x
, y
, def
);
2184 bool wxStyledTextCtrl::DoDropText(long x
, long y
, const wxString
& data
) {
2185 return m_swx
->DoDropText(x
, y
, data
);
2190 //----------------------------------------------------------------------
2193 void wxStyledTextCtrl::OnPaint(wxPaintEvent
& WXUNUSED(evt
)) {
2195 m_swx
->DoPaint(&dc
, GetUpdateRegion().GetBox());
2198 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent
& evt
) {
2199 if (evt
.GetOrientation() == wxHORIZONTAL
)
2200 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
2202 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
2205 void wxStyledTextCtrl::OnScroll(wxScrollEvent
& evt
) {
2206 wxScrollBar
* sb
= wxDynamicCast(evt
.GetEventObject(), wxScrollBar
);
2208 if (sb
->IsVertical())
2209 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
2211 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
2215 void wxStyledTextCtrl::OnSize(wxSizeEvent
& WXUNUSED(evt
)) {
2217 wxSize sz
= GetClientSize();
2218 m_swx
->DoSize(sz
.x
, sz
.y
);
2222 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent
& evt
) {
2224 wxPoint pt
= evt
.GetPosition();
2225 m_swx
->DoLeftButtonDown(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
2226 evt
.ShiftDown(), evt
.ControlDown(), evt
.AltDown());
2229 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent
& evt
) {
2230 wxPoint pt
= evt
.GetPosition();
2231 m_swx
->DoLeftButtonMove(Point(pt
.x
, pt
.y
));
2234 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent
& evt
) {
2235 wxPoint pt
= evt
.GetPosition();
2236 m_swx
->DoLeftButtonUp(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
2241 void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent
& evt
) {
2242 wxPoint pt
= evt
.GetPosition();
2243 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
2247 void wxStyledTextCtrl::OnMouseMiddleUp(wxMouseEvent
& evt
) {
2248 wxPoint pt
= evt
.GetPosition();
2249 m_swx
->DoMiddleButtonUp(Point(pt
.x
, pt
.y
));
2252 void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent
& evt
) {
2253 wxPoint pt
= evt
.GetPosition();
2254 ScreenToClient(&pt
.x
, &pt
.y
);
2255 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
2259 void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent
& evt
) {
2260 m_swx
->DoMouseWheel(evt
.GetWheelRotation(),
2261 evt
.GetWheelDelta(),
2262 evt
.GetLinesPerAction(),
2264 evt
.IsPageScroll());
2268 void wxStyledTextCtrl::OnChar(wxKeyEvent
& evt
) {
2269 // On (some?) non-US keyboards the AltGr key is required to enter some
2270 // common characters. It comes to us as both Alt and Ctrl down so we need
2271 // to let the char through in that case, otherwise if only ctrl or only
2272 // alt let's skip it.
2273 bool ctrl
= evt
.ControlDown();
2274 bool alt
= evt
.AltDown();
2275 bool skip
= ((ctrl
|| alt
) && ! (ctrl
&& alt
));
2277 int key
= evt
.GetKeyCode();
2279 // printf("OnChar key:%d consumed:%d ctrl:%d alt:%d skip:%d\n",
2280 // key, m_lastKeyDownConsumed, ctrl, alt, skip);
2282 if ( (key
<= WXK_START
|| key
> WXK_NUMPAD_DIVIDE
) &&
2283 !m_lastKeyDownConsumed
&& !skip
) {
2284 m_swx
->DoAddChar(key
);
2291 void wxStyledTextCtrl::OnKeyDown(wxKeyEvent
& evt
) {
2292 int key
= evt
.GetKeyCode();
2293 bool shift
= evt
.ShiftDown(),
2294 ctrl
= evt
.ControlDown(),
2295 alt
= evt
.AltDown(),
2296 meta
= evt
.MetaDown();
2298 int processed
= m_swx
->DoKeyDown(key
, shift
, ctrl
, alt
, meta
, &m_lastKeyDownConsumed
);
2300 // printf("KeyDn key:%d shift:%d ctrl:%d alt:%d processed:%d consumed:%d\n",
2301 // key, shift, ctrl, alt, processed, m_lastKeyDownConsumed);
2303 if (!processed
&& !m_lastKeyDownConsumed
)
2308 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent
& WXUNUSED(evt
)) {
2309 m_swx
->DoLoseFocus();
2313 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent
& WXUNUSED(evt
)) {
2314 m_swx
->DoGainFocus();
2318 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(evt
)) {
2319 m_swx
->DoSysColourChange();
2323 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
)) {
2324 // do nothing to help avoid flashing
2329 void wxStyledTextCtrl::OnMenu(wxCommandEvent
& evt
) {
2330 m_swx
->DoCommand(evt
.GetId());
2334 void wxStyledTextCtrl::OnListBox(wxCommandEvent
& WXUNUSED(evt
)) {
2335 m_swx
->DoOnListBox();
2339 //----------------------------------------------------------------------
2340 // Turn notifications from Scintilla into events
2343 void wxStyledTextCtrl::NotifyChange() {
2344 wxStyledTextEvent
evt(wxEVT_STC_CHANGE
, GetId());
2345 evt
.SetEventObject(this);
2346 GetEventHandler()->ProcessEvent(evt
);
2350 static void SetEventText(wxStyledTextEvent
& evt
, const char* text
,
2354 // The unicode conversion MUST have a null byte to terminate the
2355 // string so move it into a buffer first and give it one.
2356 wxMemoryBuffer
buf(length
+1);
2357 buf
.AppendData((void*)text
, length
);
2359 evt
.SetText(stc2wx(buf
));
2363 void wxStyledTextCtrl::NotifyParent(SCNotification
* _scn
) {
2364 SCNotification
& scn
= *_scn
;
2365 wxStyledTextEvent
evt(0, GetId());
2367 evt
.SetEventObject(this);
2368 evt
.SetPosition(scn
.position
);
2370 evt
.SetModifiers(scn
.modifiers
);
2372 switch (scn
.nmhdr
.code
) {
2373 case SCN_STYLENEEDED
:
2374 evt
.SetEventType(wxEVT_STC_STYLENEEDED
);
2378 evt
.SetEventType(wxEVT_STC_CHARADDED
);
2381 case SCN_SAVEPOINTREACHED
:
2382 evt
.SetEventType(wxEVT_STC_SAVEPOINTREACHED
);
2385 case SCN_SAVEPOINTLEFT
:
2386 evt
.SetEventType(wxEVT_STC_SAVEPOINTLEFT
);
2389 case SCN_MODIFYATTEMPTRO
:
2390 evt
.SetEventType(wxEVT_STC_ROMODIFYATTEMPT
);
2394 evt
.SetEventType(wxEVT_STC_KEY
);
2397 case SCN_DOUBLECLICK
:
2398 evt
.SetEventType(wxEVT_STC_DOUBLECLICK
);
2402 evt
.SetEventType(wxEVT_STC_UPDATEUI
);
2406 evt
.SetEventType(wxEVT_STC_MODIFIED
);
2407 evt
.SetModificationType(scn
.modificationType
);
2408 SetEventText(evt
, scn
.text
, scn
.length
);
2409 evt
.SetLength(scn
.length
);
2410 evt
.SetLinesAdded(scn
.linesAdded
);
2411 evt
.SetLine(scn
.line
);
2412 evt
.SetFoldLevelNow(scn
.foldLevelNow
);
2413 evt
.SetFoldLevelPrev(scn
.foldLevelPrev
);
2416 case SCN_MACRORECORD
:
2417 evt
.SetEventType(wxEVT_STC_MACRORECORD
);
2418 evt
.SetMessage(scn
.message
);
2419 evt
.SetWParam(scn
.wParam
);
2420 evt
.SetLParam(scn
.lParam
);
2423 case SCN_MARGINCLICK
:
2424 evt
.SetEventType(wxEVT_STC_MARGINCLICK
);
2425 evt
.SetMargin(scn
.margin
);
2429 evt
.SetEventType(wxEVT_STC_NEEDSHOWN
);
2430 evt
.SetLength(scn
.length
);
2434 evt
.SetEventType(wxEVT_STC_PAINTED
);
2437 case SCN_USERLISTSELECTION
:
2438 evt
.SetEventType(wxEVT_STC_USERLISTSELECTION
);
2439 evt
.SetListType(scn
.listType
);
2440 SetEventText(evt
, scn
.text
, strlen(scn
.text
));
2443 case SCN_URIDROPPED
:
2444 evt
.SetEventType(wxEVT_STC_URIDROPPED
);
2445 SetEventText(evt
, scn
.text
, strlen(scn
.text
));
2448 case SCN_DWELLSTART
:
2449 evt
.SetEventType(wxEVT_STC_DWELLSTART
);
2455 evt
.SetEventType(wxEVT_STC_DWELLEND
);
2461 evt
.SetEventType(wxEVT_STC_ZOOM
);
2464 case SCN_HOTSPOTCLICK
:
2465 evt
.SetEventType(wxEVT_STC_HOTSPOT_CLICK
);
2468 case SCN_HOTSPOTDOUBLECLICK
:
2469 evt
.SetEventType(wxEVT_STC_HOTSPOT_DCLICK
);
2472 case SCN_CALLTIPCLICK
:
2473 evt
.SetEventType(wxEVT_STC_CALLTIP_CLICK
);
2480 GetEventHandler()->ProcessEvent(evt
);
2484 //----------------------------------------------------------------------
2485 //----------------------------------------------------------------------
2486 //----------------------------------------------------------------------
2488 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType
, int id
)
2489 : wxCommandEvent(commandType
, id
)
2494 m_modificationType
= 0;
2499 m_foldLevelPrev
= 0;
2507 m_dragAllowMove
= FALSE
;
2508 #if wxUSE_DRAG_AND_DROP
2509 m_dragResult
= wxDragNone
;
2513 bool wxStyledTextEvent::GetShift() const { return (m_modifiers
& SCI_SHIFT
) != 0; }
2514 bool wxStyledTextEvent::GetControl() const { return (m_modifiers
& SCI_CTRL
) != 0; }
2515 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers
& SCI_ALT
) != 0; }
2518 wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent
& event
):
2519 wxCommandEvent(event
)
2521 m_position
= event
.m_position
;
2522 m_key
= event
.m_key
;
2523 m_modifiers
= event
.m_modifiers
;
2524 m_modificationType
= event
.m_modificationType
;
2525 m_text
= event
.m_text
;
2526 m_length
= event
.m_length
;
2527 m_linesAdded
= event
.m_linesAdded
;
2528 m_line
= event
.m_line
;
2529 m_foldLevelNow
= event
.m_foldLevelNow
;
2530 m_foldLevelPrev
= event
.m_foldLevelPrev
;
2532 m_margin
= event
.m_margin
;
2534 m_message
= event
.m_message
;
2535 m_wParam
= event
.m_wParam
;
2536 m_lParam
= event
.m_lParam
;
2538 m_listType
= event
.m_listType
;
2542 m_dragText
= event
.m_dragText
;
2543 m_dragAllowMove
=event
.m_dragAllowMove
;
2544 #if wxUSE_DRAG_AND_DROP
2545 m_dragResult
= event
.m_dragResult
;
2549 //----------------------------------------------------------------------
2550 //----------------------------------------------------------------------