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
= 127;
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;
66 const int wxSTC_MARK_ARROWDOWN
= 6;
67 const int wxSTC_MARK_MINUS
= 7;
68 const int wxSTC_MARK_PLUS
= 8;
70 const int wxSTC_MARKNUM_FOLDER
= 30;
71 const int wxSTC_MARKNUM_FOLDEROPEN
= 31;
72 const int wxSTC_MASK_FOLDERS
= ((1 << wxSTC_MARKNUM_FOLDER
) | (1 << wxSTC_MARKNUM_FOLDEROPEN
));
74 const int wxSTC_INDIC_MAX
= 7;
75 const int wxSTC_INDIC_PLAIN
= 0;
76 const int wxSTC_INDIC_SQUIGGLE
= 1;
77 const int wxSTC_INDIC_TT
= 2;
78 const int wxSTC_INDIC_DIAGONAL
= 3;
79 const int wxSTC_INDIC_STRIKE
= 4;
80 const int wxSTC_INDIC0_MASK
= 32;
81 const int wxSTC_INDIC1_MASK
= 64;
82 const int wxSTC_INDIC2_MASK
= 128;
83 const int wxSTC_INDICS_MASK
= (wxSTC_INDIC0_MASK
| wxSTC_INDIC1_MASK
| wxSTC_INDIC2_MASK
);
86 const int wxSTC_FOLDLEVELBASE
= 0x0400;
87 const int wxSTC_FOLDLEVELWHITEFLAG
= 0x1000;
88 const int wxSTC_FOLDLEVELHEADERFLAG
= 0x2000;
89 const int wxSTC_FOLDLEVELNUMBERMASK
= 0x0FFF;
94 wxSTC_CMD_LINEDOWN
= 2300,
95 wxSTC_CMD_LINEDOWNEXTEND
,
97 wxSTC_CMD_LINEUPEXTEND
,
99 wxSTC_CMD_CHARLEFTEXTEND
,
101 wxSTC_CMD_CHARRIGHTEXTEND
,
103 wxSTC_CMD_WORDLEFTEXTEND
,
105 wxSTC_CMD_WORDRIGHTEXTEND
,
107 wxSTC_CMD_HOMEEXTEND
,
109 wxSTC_CMD_LINEENDEXTEND
,
110 wxSTC_CMD_DOCUMENTSTART
,
111 wxSTC_CMD_DOCUMENTSTARTEXTEND
,
112 wxSTC_CMD_DOCUMENTEND
,
113 wxSTC_CMD_DOCUMENTENDEXTEND
,
115 wxSTC_CMD_PAGEUPEXTEND
,
117 wxSTC_CMD_PAGEDOWNEXTEND
,
118 wxSTC_CMD_EDITTOGGLEOVERTYPE
,
120 wxSTC_CMD_DELETEBACK
,
126 wxSTC_CMD_VCHOMEEXTEND
,
129 wxSTC_CMD_DELWORDLEFT
,
130 wxSTC_CMD_DELWORDRIGHT
,
132 wxSTC_CMD_LINEDELETE
,
133 wxSTC_CMD_LINETRANSPOSE
,
136 wxSTC_CMD_LINESCROLLDOWN
,
137 wxSTC_CMD_LINESCROLLUP
142 wxSTC_LEX_CONTAINER
=0,
151 wxSTC_LEX_PROPERTIES
,
161 const int wxSTC_CARET_SLOP
= 0x01;
162 const int WXSTC_CARET_CENTER
= 0x02;
163 const int wxSTC_CARET_STRICT
= 0x04;
165 const int wxSTC_MARGIN_SYMBOL
= 0;
166 const int wxSTC_MARGIN_NUMBER
= 1;
169 class ScintillaWX
; // forward declare
171 struct SCNotification
;
174 extern const wxChar
* wxSTCNameStr
;
176 //----------------------------------------------------------------------
178 class wxStyledTextCtrl
: public wxControl
{
182 wxStyledTextCtrl(wxWindow
*parent
, wxWindowID id
,
183 const wxPoint
& pos
= wxDefaultPosition
,
184 const wxSize
& size
= wxDefaultSize
, long style
= 0,
185 const char* name
= "styledtext");
187 wxStyledTextCtrl(wxWindow
*parent
, wxWindowID id
,
188 const wxPoint
& pos
= wxDefaultPosition
,
189 const wxSize
& size
= wxDefaultSize
, long style
= 0,
190 const wxString
& name
= wxSTCNameStr
);
199 // Text retrieval and modification
201 bool SetText(const wxString
& text
);
202 wxString
GetLine(int line
);
203 void ReplaceSelection(const wxString
& text
);
204 void SetReadOnly(bool readOnly
);
206 wxString
GetTextRange(int startPos
, int endPos
);
207 wxString
GetStyledTextRange(int startPos
, int endPos
);
209 void GetTextRange(int startPos
, int endPos
, char* buff
);
210 void GetStyledTextRange(int startPos
, int endPos
, char* buff
);
212 void AddText(const wxString
& text
);
213 void AddStyledText(const wxString
& text
);
214 void InsertText(int pos
, const wxString
& text
);
216 char GetCharAt(int pos
);
217 char GetStyleAt(int pos
);
218 void SetStyleBits(int bits
);
227 void ClearClipbrd(); // avoiding name conflict with virtual in wxWindow
233 void EmptyUndoBuffer();
236 void SetUndoCollection(wxSTC_UndoType type
);
237 wxSTC_UndoType
GetUndoCollection();
238 void BeginUndoAction();
239 void EndUndoAction();
242 // Selection and information
244 void GetSelection(int* OUTPUT
, int* OUTPUT
);
246 void GetSelection(int* startPos
, int* endPos
);
248 void SetSelection(int startPos
, int endPos
);
249 wxString
GetSelectedText();
250 void HideSelection(bool hide
);
251 bool GetHideSelection();
254 int GetFirstVisibleLine();
257 int GetLineFromPos(int pos
);
258 int GetLineStartPos(int line
);
259 int GetLineLength(int line
);
261 wxString
GetCurrentLineText(int* OUTPUT
);
263 wxString
GetCurrentLineText(int* linePos
);
265 int GetCurrentLine();
266 int PositionFromPoint(wxPoint pt
);
267 wxPoint
PointFromPosition(int pos
);
271 void SetCurrentPosition(int pos
);
272 void SetAnchor(int pos
);
273 void GotoPos(int pos
);
274 void GotoLine(int line
);
275 void ChangePosition(int delta
, bool extendSelection
);
276 void PageMove(int cmdKey
, bool extendSelection
);
278 void ScrollBy(int columnDelta
, int lineDelta
);
279 void ScrollToLine(int line
);
280 void ScrollToColumn(int column
);
281 void EnsureCaretVisible();
282 void SetCaretPolicy(int policy
, int slop
=0);
283 int GetLinesOnScreen();
284 bool IsSelectionRectangle();
285 void SetUseHorizontalScrollBar(bool use
);
286 bool GetUseHorizontalScrollBar();
290 int FindText(int minPos
, int maxPos
, const wxString
& text
,
291 bool caseSensitive
, bool wholeWord
);
293 int SearchNext(const wxString
& text
, bool caseSensitive
, bool wholeWord
);
294 int SearchPrev(const wxString
& text
, bool caseSensitive
, bool wholeWord
);
297 // Visible whitespace
298 bool GetViewWhitespace();
299 void SetViewWhitespace(bool visible
);
303 wxSTC_EOL
GetEOLMode();
304 void SetEOLMode(wxSTC_EOL mode
);
306 void SetViewEOL(bool visible
);
307 void ConvertEOL(wxSTC_EOL mode
);
312 void StartStyling(int pos
, int mask
);
313 void SetStyleFor(int length
, int style
);
314 void SetStyleBytes(int length
, char* styleBytes
);
315 void SetLineState(int line
, int value
);
316 int GetLineState(int line
);
320 void StyleClearAll();
321 void StyleResetDefault();
322 void StyleSetSpec(int styleNum
, const wxString
& spec
);
323 void StyleSetForeground(int styleNum
, const wxColour
& colour
);
324 void StyleSetBackground(int styleNum
, const wxColour
& colour
);
325 void StyleSetFont(int styleNum
, wxFont
& font
);
326 void StyleSetFontAttr(int styleNum
, int size
, const wxString
& faceName
, bool bold
=FALSE
, bool italic
=FALSE
, bool underline
=FALSE
);
327 void StyleSetBold(int styleNum
, bool bold
);
328 void StyleSetItalic(int styleNum
, bool italic
);
329 void StyleSetFaceName(int styleNum
, const wxString
& faceName
);
330 void StyleSetSize(int styleNum
, int pointSize
);
331 void StyleSetEOLFilled(int styleNum
, bool fillEOL
);
332 void StyleSetUnderline(int styleNum
, bool underline
);
335 // Margins in the edit area
337 int GetRightMargin();
338 void SetMargins(int left
, int right
);
341 // Margins for selection, markers, etc.
342 void SetMarginType(int margin
, int type
);
343 int GetMarginType(int margin
);
344 void SetMarginWidth(int margin
, int pixelWidth
);
345 int GetMarginWidth(int margin
);
346 void SetMarginMask(int margin
, int mask
);
347 int GetMarginMask(int margin
);
348 void SetMarginSensitive(int margin
, bool sensitive
);
349 bool GetMarginSensitive(int margin
);
352 // Selection and Caret styles
353 void SetSelectionForeground(const wxColour
& colour
);
354 void SetSelectionBackground(const wxColour
& colour
);
355 void SetCaretForeground(const wxColour
& colour
);
356 int GetCaretPeriod();
357 void SetCaretPeriod(int milliseconds
);
361 void SetBufferedDraw(bool isBuffered
);
362 void SetTabWidth(int numChars
);
363 void SetIndent(int numChars
);
364 void SetUseTabs(bool usetabs
);
365 void SetLineIndentation(int line
, int indentation
);
366 int GetLineIndentation(int line
);
367 int GetLineIndentationPos(int line
);
368 void SetWordChars(const wxString
& wordChars
);
370 void SetUsePop(bool usepopup
);
373 // Brace highlighting
374 void BraceHighlight(int pos1
, int pos2
);
375 void BraceBadlight(int pos
);
376 int BraceMatch(int pos
, int maxReStyle
=0);
380 void MarkerDefine(int markerNumber
, int markerSymbol
,
381 const wxColour
& foreground
,
382 const wxColour
& background
);
383 void MarkerSetType(int markerNumber
, int markerSymbol
);
384 void MarkerSetForeground(int markerNumber
, const wxColour
& colour
);
385 void MarkerSetBackground(int markerNumber
, const wxColour
& colour
);
386 int MarkerAdd(int line
, int markerNumber
);
387 void MarkerDelete(int line
, int markerNumber
);
388 void MarkerDeleteAll(int markerNumber
);
389 int MarkerGet(int line
);
390 int MarkerGetNextLine(int lineStart
, int markerMask
);
391 int MarkerGetPrevLine(int lineStart
, int markerMask
);
392 int MarkerLineFromHandle(int handle
);
393 void MarkerDeleteHandle(int handle
);
397 void IndicatorSetStyle(int indicNum
, int indicStyle
);
398 int IndicatorGetStyle(int indicNum
);
399 void IndicatorSetColour(int indicNum
, const wxColour
& colour
);
403 void AutoCompShow(const wxString
& listOfWords
);
404 void AutoCompCancel();
405 bool AutoCompActive();
406 int AutoCompPosAtStart();
407 void AutoCompComplete();
408 void AutoCompStopChars(const wxString
& stopChars
);
409 void AutoCompSetSeparator(char separator
);
410 char AutoCompGetSeparator();
411 void AutoCompSelect(const wxString
& stringtoselect
);
414 void CallTipShow(int pos
, const wxString
& text
);
415 void CallTipCancel();
416 bool CallTipActive();
417 int CallTipPosAtStart();
418 void CallTipSetHighlight(int start
, int end
);
419 void CallTipSetBackground(const wxColour
& colour
);
423 void CmdKeyAssign(int key
, int modifiers
, int cmd
);
424 void CmdKeyClear(int key
, int modifiers
);
425 void CmdKeyClearAll();
426 void CmdKeyExecute(int cmd
);
430 int FormatRange(bool doDraw
,
434 wxDC
* target
, // Why does it use two? Can they be the same?
439 // Document Sharing (multiple views)
441 void SetDocument(void* document
);
442 // TODO: create a wx wrapper for Scintilla's document class
446 int VisibleFromDocLine(int docLine
);
447 int DocLineFromVisible(int displayLine
);
448 int SetFoldLevel(int line
, int level
);
449 int GetFoldLevel(int line
);
450 int GetLastChild(int line
, int level
);
451 int GetFoldParent(int line
);
452 void ShowLines(int lineStart
, int lineEnd
);
453 void HideLines(int lineStart
, int lineEnd
);
454 bool GetLineVisible(int line
);
455 void SetFoldExpanded(int line
, bool expanded
);
456 bool GetFoldExpanded(int line
);
457 void ToggleFold(int line
);
458 void EnsureVisible(int line
);
459 void SetFoldFlags(int flags
);
465 void SetZoom(int zoom
);
471 void SetEdgeColumn(int column
);
472 wxSTC_EDGE
GetEdgeMode();
473 void SetEdgeMode(wxSTC_EDGE mode
);
474 wxColour
GetEdgeColour();
475 void SetEdgeColour(const wxColour
& colour
);
479 void SetLexer(wxSTC_LEX lexer
);
480 wxSTC_LEX
GetLexer();
481 void Colourise(int start
, int end
);
482 void SetProperty(const wxString
& key
, const wxString
& value
);
483 void SetKeywords(int keywordSet
, const wxString
& keywordList
);
486 // Event mask for Modified Event
487 void SetModEventMask(int mask
);
488 //int GetModEventMask();
493 void OnPaint(wxPaintEvent
& evt
);
494 void OnScrollWin(wxScrollWinEvent
& evt
);
495 void OnSize(wxSizeEvent
& evt
);
496 void OnMouseLeftDown(wxMouseEvent
& evt
);
497 void OnMouseMove(wxMouseEvent
& evt
);
498 void OnMouseLeftUp(wxMouseEvent
& evt
);
499 void OnMouseRightUp(wxMouseEvent
& evt
);
500 void OnChar(wxKeyEvent
& evt
);
501 void OnKeyDown(wxKeyEvent
& evt
);
502 void OnLoseFocus(wxFocusEvent
& evt
);
503 void OnGainFocus(wxFocusEvent
& evt
);
504 void OnSysColourChanged(wxSysColourChangedEvent
& evt
);
505 void OnEraseBackground(wxEraseEvent
& evt
);
506 void OnMenu(wxCommandEvent
& evt
);
507 void OnListBox(wxCommandEvent
& evt
);
510 // Turn notifications from Scintilla into events
512 void NotifyParent(SCNotification
* scn
);
514 long SendMsg(int msg
, long wp
=0, long lp
=0);
517 DECLARE_EVENT_TABLE()
518 DECLARE_CLASS(wxStyledTextCtrl
)
521 wxStopWatch m_stopWatch
;
523 wxSTC_UndoType m_undoType
;
526 friend class ScintillaWX
;
527 friend class Platform
;
531 //----------------------------------------------------------------------
533 class wxStyledTextEvent
: public wxCommandEvent
{
535 wxStyledTextEvent(wxEventType commandType
=0, int id
=0);
536 ~wxStyledTextEvent() {}
538 void SetPosition(int pos
) { m_position
= pos
; }
539 void SetKey(int k
) { m_key
= k
; }
540 void SetModifiers(int m
) { m_modifiers
= m
; }
541 void SetModificationType(int t
) { m_modificationType
= t
; }
542 void SetText(const char* t
) { m_text
= t
; }
543 void SetLength(int len
) { m_length
= len
; }
544 void SetLinesAdded(int num
) { m_linesAdded
= num
; }
545 void SetLine(int val
) { m_line
= val
; }
546 void SetFoldLevelNow(int val
) { m_foldLevelNow
= val
; }
547 void SetFoldLevelPrev(int val
) { m_foldLevelPrev
= val
; }
548 void SetMargin(int val
) { m_margin
= val
; }
549 void SetMessage(int val
) { m_message
= val
; }
550 void SetWParam(int val
) { m_wParam
= val
; }
551 void SetLParam(int val
) { m_lParam
= val
; }
553 int GetPosition() const { return m_position
; }
554 int GetKey() const { return m_key
; }
555 int GetModifiers() const { return m_modifiers
; }
556 int GetModificationType() const { return m_modificationType
; }
557 wxString
GetText() const { return m_text
; }
558 int GetLength() const { return m_length
; }
559 int GetLinesAdded() const { return m_linesAdded
; }
560 int GetLine() const { return m_line
; }
561 int GetFoldLevelNow() const { return m_foldLevelNow
; }
562 int GetFoldLevelPrev() const { return m_foldLevelPrev
; }
563 int GetMargin() const { return m_margin
; }
564 int GetMessage() const { return m_message
; }
565 int GetWParam() const { return m_wParam
; }
566 int GetLParam() const { return m_lParam
; }
568 bool GetShift() const;
569 bool GetControl() const;
572 void CopyObject(wxObject
& obj
) const;
576 DECLARE_DYNAMIC_CLASS(wxStyledTextEvent
)
582 int m_modificationType
; // wxEVT_STC_MODIFIED
590 int m_margin
; // wxEVT_STC_MARGINCLICK
592 int m_message
; // wxEVT_STC_MACRORECORD
601 wxEVT_STC_CHANGE
= 1650,
602 wxEVT_STC_STYLENEEDED
,
605 wxEVT_STC_SAVEPOINTREACHED
,
606 wxEVT_STC_SAVEPOINTLEFT
,
607 wxEVT_STC_ROMODIFYATTEMPT
,
608 wxEVT_STC_DOUBLECLICK
,
611 wxEVT_STC_MACRORECORD
,
612 wxEVT_STC_MARGINCLICK
,
616 // Modification and action types
617 const int wxSTC_MOD_INSERTTEXT
= 0x1;
618 const int wxSTC_MOD_DELETETEXT
= 0x2;
619 const int wxSTC_MOD_CHANGESTYLE
= 0x4;
620 const int wxSTC_MOD_CHANGEFOLD
= 0x8;
621 const int wxSTC_PERFORMED_USER
= 0x10;
622 const int wxSTC_PERFORMED_UNDO
= 0x20;
623 const int wxSTC_PERFORMED_REDO
= 0x40;
624 const int wxSTC_LASTSTEPINUNDOREDO
= 0x100;
625 const int wxSTC_MOD_CHANGEMARKER
= 0x200;
626 const int wxSTC_MOD_BEFOREINSERT
= 0x400;
627 const int wxSTC_MOD_BEFOREDELETE
= 0x800;
631 typedef void (wxEvtHandler::*wxStyledTextEventFunction
)(wxStyledTextEvent
&);
633 #define EVT_STC_CHANGE(id, fn) { wxEVT_STC_CHANGE, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
634 #define EVT_STC_STYLENEEDED(id, fn) { wxEVT_STC_STYLENEEDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
635 #define EVT_STC_CHARADDED(id, fn) { wxEVT_STC_CHARADDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
636 #define EVT_STC_UPDATEUI(id, fn) { wxEVT_STC_UPDATEUI, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
637 #define EVT_STC_SAVEPOINTREACHED(id, fn) { wxEVT_STC_SAVEPOINTREACHED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
638 #define EVT_STC_SAVEPOINTLEFT(id, fn) { wxEVT_STC_SAVEPOINTLEFT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
639 #define EVT_STC_ROMODIFYATTEMPT(id, fn) { wxEVT_STC_ROMODIFYATTEMPT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
640 #define EVT_STC_DOUBLECLICK(id, fn) { wxEVT_STC_DOUBLECLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
641 #define EVT_STC_MODIFIED(id, fn) { wxEVT_STC_MODIFIED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
642 #define EVT_STC_KEY(id, fn) { wxEVT_STC_KEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
643 #define EVT_STC_MACRORECORD(id, fn) { wxEVT_STC_MACRORECORD, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
644 #define EVT_STC_MARGINCLICK(id, fn) { wxEVT_STC_MARGINCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
645 #define EVT_STC_NEEDSHOWN(id, fn) { wxEVT_STC_NEEDSHOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
649 //----------------------------------------------------------------------
650 //----------------------------------------------------------------------