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, and in fact there
6 // is no mention of Scintilla classes at all in this header.
7 // This class delegates all method calls and events to the
8 // Scintilla objects and so forth. This allows the use of
9 // Scintilla without polluting the namespace with all the
10 // classes and itentifiers from Scintilla.
14 // Created: 13-Jan-2000
16 // Copyright: (c) 2000 by Total Control Software
17 // Licence: wxWindows license
18 /////////////////////////////////////////////////////////////////////////////
27 //----------------------------------------------------------------------
28 // constants and stuff
31 wxSTC_UndoCollectNone
,
32 wxSTC_UndoCollectAutoStart
50 const int wxSTC_LEX_STYLE_MAX
= 31;
51 const int wxSTC_STYLE_DEFAULT
= 32;
52 const int wxSTC_STYLE_LINENUMBER
= 33;
53 const int wxSTC_STYLE_BRACELIGHT
= 34;
54 const int wxSTC_STYLE_BRACEBAD
= 35;
55 const int wxSTC_STYLE_CONTROLCHAR
= 36;
56 const int wxSTC_STYLE_MAX
= 63;
57 const int wxSTC_STYLE_MASK
= 31;
59 const int wxSTC_MARKER_MAX
= 31;
60 const int wxSTC_MARK_CIRCLE
= 0;
61 const int wxSTC_MARK_ROUNDRECT
= 1;
62 const int wxSTC_MARK_ARROW
= 2;
63 const int wxSTC_MARK_SMALLRECT
= 3;
64 const int wxSTC_MARK_SHORTARROW
= 4;
65 const int wxSTC_MARK_EMPTY
= 5;
67 const int wxSTC_INDIC_PLAIN
= 0;
68 const int wxSTC_INDIC_SQUIGGLE
= 1;
69 const int wxSTC_INDIC_TT
= 2;
70 const int wxSTC_INDIC0_MASK
= 32;
71 const int wxSTC_INDIC1_MASK
= 64;
72 const int wxSTC_INDIC2_MASK
= 128;
73 const int wxSTC_INDICS_MASK
= (wxSTC_INDIC0_MASK
| wxSTC_INDIC1_MASK
| wxSTC_INDIC2_MASK
);
78 wxSTC_CMD_LINEDOWN
= 2300,
79 wxSTC_CMD_LINEDOWNEXTEND
,
81 wxSTC_CMD_LINEUPEXTEND
,
83 wxSTC_CMD_CHARLEFTEXTEND
,
85 wxSTC_CMD_CHARRIGHTEXTEND
,
87 wxSTC_CMD_WORDLEFTEXTEND
,
89 wxSTC_CMD_WORDRIGHTEXTEND
,
93 wxSTC_CMD_LINEENDEXTEND
,
94 wxSTC_CMD_DOCUMENTSTART
,
95 wxSTC_CMD_DOCUMENTSTARTEXTEND
,
96 wxSTC_CMD_DOCUMENTEND
,
97 wxSTC_CMD_DOCUMENTENDEXTEND
,
99 wxSTC_CMD_PAGEUPEXTEND
,
101 wxSTC_CMD_PAGEDOWNEXTEND
,
102 wxSTC_CMD_EDITTOGGLEOVERTYPE
,
104 wxSTC_CMD_DELETEBACK
,
110 wxSTC_CMD_VCHOMEEXTEND
,
113 wxSTC_CMD_DELWORDLEFT
,
114 wxSTC_CMD_DELWORDRIGHT
119 wxSTC_LEX_CONTAINER
=0,
128 wxSTC_LEX_PROPERTIES
,
136 const int wxSTC_CARET_SLOP
= 0x01;
137 const int WXSTC_CARET_CENTER
= 0x02;
138 const int wxSTC_CARET_STRICT
= 0x04;
140 const int wxSTC_MARGIN_SYMBOL
= 0;
141 const int wxSTC_MARGIN_NUMBER
= 1;
144 class ScintillaWX
; // forward declare
146 struct SCNotification
;
149 extern const wxChar
* wxSTCNameStr
;
151 //----------------------------------------------------------------------
153 class wxStyledTextCtrl
: public wxControl
{
156 wxStyledTextCtrl(wxWindow
*parent
, wxWindowID id
,
157 const wxPoint
& pos
= wxDefaultPosition
,
158 const wxSize
& size
= wxDefaultSize
, long style
= 0,
159 const wxString
& name
= wxSTCNameStr
);
164 // Text retrieval and modification
166 bool SetText(const wxString
& text
);
167 wxString
GetLine(int line
);
168 void ReplaceSelection(const wxString
& text
);
169 void SetReadOnly(bool readOnly
);
171 wxString
GetTextRange(int startPos
, int endPos
);
172 wxString
GetStyledTextRange(int startPos
, int endPos
);
173 void GetTextRange(int startPos
, int endPos
, char* buff
);
174 void GetStyledTextRange(int startPos
, int endPos
, char* buff
);
175 void AddText(const wxString
& text
);
176 void AddStyledText(const wxString
& text
);
177 void InsertText(int pos
, const wxString
& text
);
179 char GetCharAt(int pos
);
180 char GetStyleAt(int pos
);
181 void SetStyleBits(int bits
);
190 void ClearClipbrd(); // avoiding name conflict with virtual in wxWindow
196 void EmptyUndoBuffer();
199 void SetUndoCollection(wxSTC_UndoType type
);
200 wxSTC_UndoType
GetUndoCollection();
201 void BeginUndoAction();
202 void EndUndoAction();
205 // Selection and information
206 void GetSelection(int* startPos
, int* endPos
);
207 void SetSelection(int startPos
, int endPos
);
208 wxString
GetSelectedText();
209 void HideSelection(bool hide
);
210 bool GetHideSelection();
213 int GetFirstVisibleLine();
217 int GetLineFromPos(int pos
);
218 int GetLineStartPos(int line
);
219 int GetLineLengthAtPos(int pos
);
220 int GetLineLength(int line
);
221 wxString
GetCurrentLineText(int* linePos
=NULL
);
222 int GetCurrentLine();
223 int PositionFromPoint(wxPoint pt
);
224 int LineFromPoint(wxPoint pt
);
225 wxPoint
PointFromPosition(int pos
);
229 void SetCurrentPosition(int pos
);
230 void SetAnchor(int pos
);
231 void GotoPos(int pos
);
232 void GotoLine(int line
);
233 void ChangePosition(int delta
, bool extendSelection
);
234 void PageMove(int cmdKey
, bool extendSelection
);
236 void ScrollBy(int columnDelta
, int lineDelta
);
237 void ScrollToLine(int line
);
238 void ScrollToColumn(int column
);
239 void EnsureCaretVisible();
240 void SetCaretPolicy(int policy
, int slop
=0);
241 int GetSelectionType();
246 int FindText(int minPos
, int maxPos
, const wxString
& text
,
247 bool caseSensitive
, bool wholeWord
);
249 int SearchNext(const wxString
& text
, bool caseSensitive
, bool wholeWord
);
250 int SearchPrev(const wxString
& text
, bool caseSensitive
, bool wholeWord
);
253 // Visible whitespace
254 bool GetViewWhitespace();
255 void SetViewWhitespace(bool visible
);
259 wxSTC_EOL
GetEOLMode();
260 void SetEOLMode(wxSTC_EOL mode
);
262 void SetViewEOL(bool visible
);
263 void ConvertEOL(wxSTC_EOL mode
);
268 void StartStyling(int pos
, int mask
);
269 void SetStyleFor(int length
, int style
);
270 void SetStyleBytes(int length
, char* styleBytes
);
274 void StyleClearAll();
275 void StyleResetDefault();
276 void StyleSetSpec(int styleNum
, const wxString
& spec
);
277 void StyleSetForeground(int styleNum
, const wxColour
& colour
);
278 void StyleSetBackground(int styleNum
, const wxColour
& colour
);
279 void StyleSetFont(int styleNum
, wxFont
& font
);
280 void StyleSetFontAttr(int styleNum
, int size
, const wxString
& faceName
, bool bold
, bool italic
);
281 void StyleSetBold(int styleNum
, bool bold
);
282 void StyleSetItalic(int styleNum
, bool italic
);
283 void StyleSetFaceName(int styleNum
, const wxString
& faceName
);
284 void StyleSetSize(int styleNum
, int pointSize
);
285 void StyleSetEOLFilled(int styleNum
, bool fillEOL
);
288 // Margins in the edit area
290 int GetRightMargin();
291 void SetMargins(int left
, int right
);
294 // Margins for selection, markers, etc.
295 void SetMarginType(int margin
, int type
);
296 int GetMarginType(int margin
);
297 void SetMarginWidth(int margin
, int pixelWidth
);
298 int GetMarginWidth(int margin
);
299 void SetMarginMask(int margin
, int mask
);
300 int GetMarginMask(int margin
);
301 void SetMarginSensitive(int margin
, bool sensitive
);
302 bool GetMarginSensitive(int margin
);
305 // Selection and Caret styles
306 void SetSelectionForeground(const wxColour
& colour
);
307 void SetSelectionBackground(const wxColour
& colour
);
308 void SetCaretForeground(const wxColour
& colour
);
309 int GetCaretPeriod();
310 void SetCaretPeriod(int milliseconds
);
314 void SetBufferedDraw(bool isBuffered
);
315 void SetTabWidth(int numChars
);
316 void SetWordChars(const wxString
& wordChars
);
319 // Brace highlighting
320 void BraceHighlight(int pos1
, int pos2
);
321 void BraceBadlight(int pos
);
322 int BraceMatch(int pos
, int maxReStyle
=0);
326 void MarkerDefine(int markerNumber
, int markerSymbol
,
327 const wxColour
& foreground
,
328 const wxColour
& background
);
329 void MarkerSetType(int markerNumber
, int markerSymbol
);
330 void MarkerSetForeground(int markerNumber
, const wxColour
& colour
);
331 void MarkerSetBackground(int markerNumber
, const wxColour
& colour
);
332 int MarkerAdd(int line
, int markerNumber
);
333 void MarkerDelete(int line
, int markerNumber
);
334 void MarkerDeleteAll(int markerNumber
);
335 int MarkerGet(int line
);
336 int MarkerGetNextLine(int lineStart
, int markerMask
);
337 int MarkerGetPrevLine(int lineStart
, int markerMask
);
338 int MarkerLineFromHandle(int handle
);
339 void MarkerDeleteHandle(int handle
);
343 void IndicatorSetStyle(int indicNum
, int indicStyle
);
344 int IndicatorGetStyle(int indicNum
);
345 void IndicatorSetColour(int indicNum
, const wxColour
& colour
);
349 void AutoCompShow(const wxString
& listOfWords
);
350 void AutoCompCancel();
351 bool AutoCompActive();
352 int AutoCompPosAtStart();
353 void AutoCompComplete();
354 void AutoCompStopChars(const wxString
& stopChars
);
358 void CallTipShow(int pos
, const wxString
& text
);
359 void CallTipCancel();
360 bool CallTipActive();
361 int CallTipPosAtStart();
362 void CallTipSetHighlight(int start
, int end
);
363 void CallTipSetBackground(const wxColour
& colour
);
367 void CmdKeyAssign(int key
, int modifiers
, int cmd
);
368 void CmdKeyClear(int key
, int modifiers
);
369 void CmdKeyClearAll();
370 void CmdKeyExecute(int cmd
);
374 int FormatRange(bool doDraw
,
378 wxDC
* target
, // Why does it use two? Can they be the same?
383 // Document Sharing (multiple views)
385 void SetDocument(void* document
);
386 // TODO: create a wx wrapper for Scintilla's document class
390 int VisibleFromDocLine(int docLine
);
391 int DocLineFromVisible(int displayLine
);
392 int SetFoldLevel(int line
, int level
);
393 int GetFoldLevel(int line
);
394 int GetLastChild(int line
);
395 int GetFoldParent(int line
);
396 void ShowLines(int lineStart
, int lineEnd
);
397 void HideLines(int lineStart
, int lineEnd
);
398 bool GetLineVisible(int line
);
399 void SetFoldExpanded(int line
);
400 bool GetFoldExpanded(int line
);
401 void ToggleFold(int line
);
402 void EnsureVisible(int line
);
407 void SetEdgeColumn(int column
);
408 wxSTC_EDGE
GetEdgeMode();
409 void SetEdgeMode(wxSTC_EDGE mode
);
410 wxColour
GetEdgeColour();
411 void SetEdgeColour(const wxColour
& colour
);
415 void SetLexer(wxSTC_LEX lexer
);
416 wxSTC_LEX
GetLexer();
417 void Colourise(int start
, int end
);
418 void SetProperty(const wxString
& key
, const wxString
& value
);
419 void SetKeywords(int keywordSet
, const wxString
& keywordList
);
425 void OnPaint(wxPaintEvent
& evt
);
426 void OnScrollWin(wxScrollWinEvent
& evt
);
427 void OnSize(wxSizeEvent
& evt
);
428 void OnMouseLeftDown(wxMouseEvent
& evt
);
429 void OnMouseMove(wxMouseEvent
& evt
);
430 void OnMouseLeftUp(wxMouseEvent
& evt
);
431 void OnMouseRightUp(wxMouseEvent
& evt
);
432 void OnChar(wxKeyEvent
& evt
);
433 void OnLoseFocus(wxFocusEvent
& evt
);
434 void OnGainFocus(wxFocusEvent
& evt
);
435 void OnSysColourChanged(wxSysColourChangedEvent
& evt
);
436 void OnEraseBackground(wxEraseEvent
& evt
);
437 void OnMenu(wxCommandEvent
& evt
);
440 // Turn notifications from Scintilla into events
442 void NotifyParent(SCNotification
* scn
);
444 long SendMsg(int msg
, long wp
=0, long lp
=0);
447 DECLARE_EVENT_TABLE()
450 wxStopWatch m_stopWatch
;
452 wxSTC_UndoType m_undoType
;
455 friend class ScintillaWX
;
456 friend class Platform
;
459 //----------------------------------------------------------------------
461 class wxStyledTextEvent
: public wxCommandEvent
{
463 wxStyledTextEvent(wxEventType commandType
, int id
);
464 ~wxStyledTextEvent() {}
466 void SetPosition(int pos
) { m_position
= pos
; }
467 void SetKey(int k
) { m_key
= k
; }
468 void SetModifiers(int m
) { m_modifiers
= m
; }
469 void SetModificationType(int t
) { m_modificationType
= t
; }
470 void SetText(const char* t
) { m_text
= t
; }
471 void SetLength(int len
) { m_length
= len
; }
472 void SetLinesAdded(int num
) { m_linesAdded
= num
; }
473 void SetLine(int val
) { m_line
= val
; }
474 void SetFoldLevelNow(int val
) { m_foldLevelNow
= val
; }
475 void SetFoldLevelPrev(int val
) { m_foldLevelPrev
= val
; }
476 void SetMargin(int val
) { m_margin
= val
; }
477 void SetMessage(int val
) { m_message
= val
; }
478 void SetWParam(int val
) { m_wParam
= val
; }
479 void SetLParam(int val
) { m_lParam
= val
; }
481 int GetPosition() const { return m_position
; }
482 int GetKey() const { return m_key
; }
483 int GetModifiers() const { return m_modifiers
; }
484 int GetModificationType() const { return m_modificationType
; }
485 wxString
GetText() const { return m_text
; }
486 int GetLength() const { return m_length
; }
487 int GetLinesAdded() const { return m_linesAdded
; }
488 int GetLine() const { return m_line
; }
489 int GetFoldLevelNow() const { return m_foldLevelNow
; }
490 int GetFoldLevelPrev() const { return m_foldLevelPrev
; }
491 int GetMargin() const { return m_margin
; }
492 int GetMessage() const { return m_message
; }
493 int GetWParam() const { return m_wParam
; }
494 int GetLParam() const { return m_lParam
; }
496 bool GetShift() const;
497 bool GetControl() const;
500 void CopyObject(wxObject
& obj
) const;
507 int m_modificationType
; // wxEVT_STC_MODIFIED
515 int m_margin
; // wxEVT_STC_MARGINCLICK
517 int m_message
; // wxEVT_STC_MACRORECORD
526 wxEVT_STC_CHANGE
= 1650,
527 wxEVT_STC_STYLENEEDED
,
530 wxEVT_STC_SAVEPOINTREACHED
,
531 wxEVT_STC_SAVEPOINTLEFT
,
532 wxEVT_STC_ROMODIFYATTEMPT
,
533 wxEVT_STC_DOUBLECLICK
,
536 wxEVT_STC_MACRORECORD
,
537 wxEVT_STC_MARGINCLICK
,
541 typedef void (wxEvtHandler::*wxStyledTextEventFunction
)(wxStyledTextEvent
&);
543 #define EVT_STC_CHANGE(id, fn) { wxEVT_STC_CHANGE, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
544 #define EVT_STC_STYLENEEDED(id, fn) { wxEVT_STC_STYLENEEDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
545 #define EVT_STC_CHARADDED(id, fn) { wxEVT_STC_CHARADDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
546 #define EVT_STC_UPDATEUI(id, fn) { wxEVT_STC_UPDATEUI, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
547 #define EVT_STC_SAVEPOINTREACHED(id, fn) { wxEVT_STC_SAVEPOINTREACHED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
548 #define EVT_STC_SAVEPOINTLEFT(id, fn) { wxEVT_STC_SAVEPOINTLEFT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
549 #define EVT_STC_ROMODIFYATTEMPT(id, fn) { wxEVT_STC_ROMODIFYATTEMPT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
550 #define EVT_STC_DOUBLECLICK(id, fn) { wxEVT_STC_DOUBLECLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
551 #define EVT_STC_MODIFIED(id, fn) { wxEVT_STC_MODIFIED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
552 #define EVT_STC_CMDKEY(id, fn) { wxEVT_STC_CMDKEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
553 #define EVT_STC_UNKNOWNCMDKEY(id, fn) { wxEVT_STC_UNKNOWNCMDKEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
556 //----------------------------------------------------------------------
557 //----------------------------------------------------------------------