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();
258 int GetLineFromPos(int pos
);
259 int GetLineStartPos(int line
);
260 int GetLineLengthAtPos(int pos
);
261 int GetLineLength(int line
);
263 wxString
GetCurrentLineText(int* OUTPUT
);
265 wxString
GetCurrentLineText(int* linePos
);
267 int GetCurrentLine();
268 int PositionFromPoint(wxPoint pt
);
269 int LineFromPoint(wxPoint pt
);
270 wxPoint
PointFromPosition(int pos
);
274 void SetCurrentPosition(int pos
);
275 void SetAnchor(int pos
);
276 void GotoPos(int pos
);
277 void GotoLine(int line
);
278 void ChangePosition(int delta
, bool extendSelection
);
279 void PageMove(int cmdKey
, bool extendSelection
);
281 void ScrollBy(int columnDelta
, int lineDelta
);
282 void ScrollToLine(int line
);
283 void ScrollToColumn(int column
);
284 void EnsureCaretVisible();
285 void SetCaretPolicy(int policy
, int slop
=0);
286 int GetSelectionType();
287 int GetLinesOnScreen();
288 bool IsSelectionRectangle();
289 void SetUseHorizontalScrollBar(bool use
);
290 bool GetUseHorizontalScrollBar();
294 int FindText(int minPos
, int maxPos
, const wxString
& text
,
295 bool caseSensitive
, bool wholeWord
);
297 int SearchNext(const wxString
& text
, bool caseSensitive
, bool wholeWord
);
298 int SearchPrev(const wxString
& text
, bool caseSensitive
, bool wholeWord
);
301 // Visible whitespace
302 bool GetViewWhitespace();
303 void SetViewWhitespace(bool visible
);
307 wxSTC_EOL
GetEOLMode();
308 void SetEOLMode(wxSTC_EOL mode
);
310 void SetViewEOL(bool visible
);
311 void ConvertEOL(wxSTC_EOL mode
);
316 void StartStyling(int pos
, int mask
);
317 void SetStyleFor(int length
, int style
);
318 void SetStyleBytes(int length
, char* styleBytes
);
319 void SetLineState(int line
, int value
);
320 int GetLineState(int line
);
324 void StyleClearAll();
325 void StyleResetDefault();
326 void StyleSetSpec(int styleNum
, const wxString
& spec
);
327 void StyleSetForeground(int styleNum
, const wxColour
& colour
);
328 void StyleSetBackground(int styleNum
, const wxColour
& colour
);
329 void StyleSetFont(int styleNum
, wxFont
& font
);
330 void StyleSetFontAttr(int styleNum
, int size
, const wxString
& faceName
, bool bold
=FALSE
, bool italic
=FALSE
, bool underline
=FALSE
);
331 void StyleSetBold(int styleNum
, bool bold
);
332 void StyleSetItalic(int styleNum
, bool italic
);
333 void StyleSetFaceName(int styleNum
, const wxString
& faceName
);
334 void StyleSetSize(int styleNum
, int pointSize
);
335 void StyleSetEOLFilled(int styleNum
, bool fillEOL
);
336 void StyleSetUnderline(int styleNum
, bool underline
);
339 // Margins in the edit area
341 int GetRightMargin();
342 void SetMargins(int left
, int right
);
345 // Margins for selection, markers, etc.
346 void SetMarginType(int margin
, int type
);
347 int GetMarginType(int margin
);
348 void SetMarginWidth(int margin
, int pixelWidth
);
349 int GetMarginWidth(int margin
);
350 void SetMarginMask(int margin
, int mask
);
351 int GetMarginMask(int margin
);
352 void SetMarginSensitive(int margin
, bool sensitive
);
353 bool GetMarginSensitive(int margin
);
356 // Selection and Caret styles
357 void SetSelectionForeground(const wxColour
& colour
);
358 void SetSelectionBackground(const wxColour
& colour
);
359 void SetCaretForeground(const wxColour
& colour
);
360 int GetCaretPeriod();
361 void SetCaretPeriod(int milliseconds
);
365 void SetBufferedDraw(bool isBuffered
);
366 void SetTabWidth(int numChars
);
367 void SetIndent(int numChars
);
368 void SetUseTabs(bool usetabs
);
369 void SetLineIndentation(int line
, int indentation
);
370 int GetLineIndentation(int line
);
371 int GetLineIndentationPos(int line
);
372 void SetWordChars(const wxString
& wordChars
);
374 void SetUsePop(bool usepopup
);
377 // Brace highlighting
378 void BraceHighlight(int pos1
, int pos2
);
379 void BraceBadlight(int pos
);
380 int BraceMatch(int pos
, int maxReStyle
=0);
384 void MarkerDefine(int markerNumber
, int markerSymbol
,
385 const wxColour
& foreground
,
386 const wxColour
& background
);
387 void MarkerSetType(int markerNumber
, int markerSymbol
);
388 void MarkerSetForeground(int markerNumber
, const wxColour
& colour
);
389 void MarkerSetBackground(int markerNumber
, const wxColour
& colour
);
390 int MarkerAdd(int line
, int markerNumber
);
391 void MarkerDelete(int line
, int markerNumber
);
392 void MarkerDeleteAll(int markerNumber
);
393 int MarkerGet(int line
);
394 int MarkerGetNextLine(int lineStart
, int markerMask
);
395 int MarkerGetPrevLine(int lineStart
, int markerMask
);
396 int MarkerLineFromHandle(int handle
);
397 void MarkerDeleteHandle(int handle
);
401 void IndicatorSetStyle(int indicNum
, int indicStyle
);
402 int IndicatorGetStyle(int indicNum
);
403 void IndicatorSetColour(int indicNum
, const wxColour
& colour
);
407 void AutoCompShow(const wxString
& listOfWords
);
408 void AutoCompCancel();
409 bool AutoCompActive();
410 int AutoCompPosAtStart();
411 void AutoCompComplete();
412 void AutoCompStopChars(const wxString
& stopChars
);
413 void AutoCompSetSeparator(char separator
);
414 char AutoCompGetSeparator();
415 void AutoCompSelect(const wxString
& stringtoselect
);
418 void CallTipShow(int pos
, const wxString
& text
);
419 void CallTipCancel();
420 bool CallTipActive();
421 int CallTipPosAtStart();
422 void CallTipSetHighlight(int start
, int end
);
423 void CallTipSetBackground(const wxColour
& colour
);
427 void CmdKeyAssign(int key
, int modifiers
, int cmd
);
428 void CmdKeyClear(int key
, int modifiers
);
429 void CmdKeyClearAll();
430 void CmdKeyExecute(int cmd
);
434 int FormatRange(bool doDraw
,
438 wxDC
* target
, // Why does it use two? Can they be the same?
443 // Document Sharing (multiple views)
445 void SetDocument(void* document
);
446 // TODO: create a wx wrapper for Scintilla's document class
450 int VisibleFromDocLine(int docLine
);
451 int DocLineFromVisible(int displayLine
);
452 int SetFoldLevel(int line
, int level
);
453 int GetFoldLevel(int line
);
454 int GetLastChild(int line
, int level
);
455 int GetFoldParent(int line
);
456 void ShowLines(int lineStart
, int lineEnd
);
457 void HideLines(int lineStart
, int lineEnd
);
458 bool GetLineVisible(int line
);
459 void SetFoldExpanded(int line
, bool expanded
);
460 bool GetFoldExpanded(int line
);
461 void ToggleFold(int line
);
462 void EnsureVisible(int line
);
463 void SetFoldFlags(int flags
);
469 void SetZoom(int zoom
);
475 void SetEdgeColumn(int column
);
476 wxSTC_EDGE
GetEdgeMode();
477 void SetEdgeMode(wxSTC_EDGE mode
);
478 wxColour
GetEdgeColour();
479 void SetEdgeColour(const wxColour
& colour
);
483 void SetLexer(wxSTC_LEX lexer
);
484 wxSTC_LEX
GetLexer();
485 void Colourise(int start
, int end
);
486 void SetProperty(const wxString
& key
, const wxString
& value
);
487 void SetKeywords(int keywordSet
, const wxString
& keywordList
);
490 // Event mask for Modified Event
491 void SetModEventMask(int mask
);
492 //int GetModEventMask();
497 void OnPaint(wxPaintEvent
& evt
);
498 void OnScrollWin(wxScrollWinEvent
& evt
);
499 void OnSize(wxSizeEvent
& evt
);
500 void OnMouseLeftDown(wxMouseEvent
& evt
);
501 void OnMouseMove(wxMouseEvent
& evt
);
502 void OnMouseLeftUp(wxMouseEvent
& evt
);
503 void OnMouseRightUp(wxMouseEvent
& evt
);
504 void OnChar(wxKeyEvent
& evt
);
505 void OnKeyDown(wxKeyEvent
& evt
);
506 void OnLoseFocus(wxFocusEvent
& evt
);
507 void OnGainFocus(wxFocusEvent
& evt
);
508 void OnSysColourChanged(wxSysColourChangedEvent
& evt
);
509 void OnEraseBackground(wxEraseEvent
& evt
);
510 void OnMenu(wxCommandEvent
& evt
);
511 void OnListBox(wxCommandEvent
& evt
);
514 // Turn notifications from Scintilla into events
516 void NotifyParent(SCNotification
* scn
);
518 long SendMsg(int msg
, long wp
=0, long lp
=0);
521 DECLARE_EVENT_TABLE()
522 DECLARE_CLASS(wxStyledTextCtrl
)
525 wxStopWatch m_stopWatch
;
527 wxSTC_UndoType m_undoType
;
530 friend class ScintillaWX
;
531 friend class Platform
;
535 //----------------------------------------------------------------------
537 class wxStyledTextEvent
: public wxCommandEvent
{
539 wxStyledTextEvent(wxEventType commandType
=0, int id
=0);
540 ~wxStyledTextEvent() {}
542 void SetPosition(int pos
) { m_position
= pos
; }
543 void SetKey(int k
) { m_key
= k
; }
544 void SetModifiers(int m
) { m_modifiers
= m
; }
545 void SetModificationType(int t
) { m_modificationType
= t
; }
546 void SetText(const char* t
) { m_text
= t
; }
547 void SetLength(int len
) { m_length
= len
; }
548 void SetLinesAdded(int num
) { m_linesAdded
= num
; }
549 void SetLine(int val
) { m_line
= val
; }
550 void SetFoldLevelNow(int val
) { m_foldLevelNow
= val
; }
551 void SetFoldLevelPrev(int val
) { m_foldLevelPrev
= val
; }
552 void SetMargin(int val
) { m_margin
= val
; }
553 void SetMessage(int val
) { m_message
= val
; }
554 void SetWParam(int val
) { m_wParam
= val
; }
555 void SetLParam(int val
) { m_lParam
= val
; }
557 int GetPosition() const { return m_position
; }
558 int GetKey() const { return m_key
; }
559 int GetModifiers() const { return m_modifiers
; }
560 int GetModificationType() const { return m_modificationType
; }
561 wxString
GetText() const { return m_text
; }
562 int GetLength() const { return m_length
; }
563 int GetLinesAdded() const { return m_linesAdded
; }
564 int GetLine() const { return m_line
; }
565 int GetFoldLevelNow() const { return m_foldLevelNow
; }
566 int GetFoldLevelPrev() const { return m_foldLevelPrev
; }
567 int GetMargin() const { return m_margin
; }
568 int GetMessage() const { return m_message
; }
569 int GetWParam() const { return m_wParam
; }
570 int GetLParam() const { return m_lParam
; }
572 bool GetShift() const;
573 bool GetControl() const;
576 void CopyObject(wxObject
& obj
) const;
580 DECLARE_DYNAMIC_CLASS(wxStyledTextEvent
)
586 int m_modificationType
; // wxEVT_STC_MODIFIED
594 int m_margin
; // wxEVT_STC_MARGINCLICK
596 int m_message
; // wxEVT_STC_MACRORECORD
605 wxEVT_STC_CHANGE
= 1650,
606 wxEVT_STC_STYLENEEDED
,
609 wxEVT_STC_SAVEPOINTREACHED
,
610 wxEVT_STC_SAVEPOINTLEFT
,
611 wxEVT_STC_ROMODIFYATTEMPT
,
612 wxEVT_STC_DOUBLECLICK
,
615 wxEVT_STC_MACRORECORD
,
616 wxEVT_STC_MARGINCLICK
,
620 // Modification and action types
621 const int wxSTC_MOD_INSERTTEXT
= 0x1;
622 const int wxSTC_MOD_DELETETEXT
= 0x2;
623 const int wxSTC_MOD_CHANGESTYLE
= 0x4;
624 const int wxSTC_MOD_CHANGEFOLD
= 0x8;
625 const int wxSTC_PERFORMED_USER
= 0x10;
626 const int wxSTC_PERFORMED_UNDO
= 0x20;
627 const int wxSTC_PERFORMED_REDO
= 0x40;
628 const int wxSTC_LASTSTEPINUNDOREDO
= 0x100;
629 const int wxSTC_MOD_CHANGEMARKER
= 0x200;
630 const int wxSTC_MOD_BEFOREINSERT
= 0x400;
631 const int wxSTC_MOD_BEFOREDELETE
= 0x800;
635 typedef void (wxEvtHandler::*wxStyledTextEventFunction
)(wxStyledTextEvent
&);
637 #define EVT_STC_CHANGE(id, fn) { wxEVT_STC_CHANGE, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
638 #define EVT_STC_STYLENEEDED(id, fn) { wxEVT_STC_STYLENEEDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
639 #define EVT_STC_CHARADDED(id, fn) { wxEVT_STC_CHARADDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
640 #define EVT_STC_UPDATEUI(id, fn) { wxEVT_STC_UPDATEUI, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
641 #define EVT_STC_SAVEPOINTREACHED(id, fn) { wxEVT_STC_SAVEPOINTREACHED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
642 #define EVT_STC_SAVEPOINTLEFT(id, fn) { wxEVT_STC_SAVEPOINTLEFT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
643 #define EVT_STC_ROMODIFYATTEMPT(id, fn) { wxEVT_STC_ROMODIFYATTEMPT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
644 #define EVT_STC_DOUBLECLICK(id, fn) { wxEVT_STC_DOUBLECLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
645 #define EVT_STC_MODIFIED(id, fn) { wxEVT_STC_MODIFIED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
646 #define EVT_STC_KEY(id, fn) { wxEVT_STC_KEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
647 #define EVT_STC_MACRORECORD(id, fn) { wxEVT_STC_MACRORECORD, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
648 #define EVT_STC_MARGINCLICK(id, fn) { wxEVT_STC_MARGINCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
649 #define EVT_STC_NEEDSHOWN(id, fn) { wxEVT_STC_NEEDSHOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
653 //----------------------------------------------------------------------
654 //----------------------------------------------------------------------