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 /////////////////////////////////////////////////////////////////////////////
28 #define STCDLLEXPORT WXDLLEXPORT
33 //----------------------------------------------------------------------
35 // Should a wxPopupWindow be used for the call tips and autocomplete windows?
36 #ifndef wxSTC_USE_POPUP
37 #define wxSTC_USE_POPUP 1
40 //----------------------------------------------------------------------
41 // BEGIN generated section. The following code is automatically generated
42 // by gen_iface.py. Do not edit this file. Edit stc.h.in instead
48 //-----------------------------------------
49 // Commands that can be bound to keystrokes
53 // END of generated section
54 //----------------------------------------------------------------------
56 class ScintillaWX
; // forward declare
58 struct SCNotification
;
61 extern STCDLLEXPORT
const wxChar
* wxSTCNameStr
;
62 class STCDLLEXPORT wxStyledTextCtrl
;
63 class STCDLLEXPORT wxStyledTextEvent
;
66 //----------------------------------------------------------------------
68 class wxStyledTextCtrl
: public wxControl
{
72 wxStyledTextCtrl(wxWindow
*parent
, wxWindowID id
,
73 const wxPoint
& pos
= wxDefaultPosition
,
74 const wxSize
& size
= wxDefaultSize
, long style
= 0,
75 const wxString
& name
= wxPySTCNameStr
);
76 %%pragma
(python
) addtomethod
= "__init__:self._setOORInfo(self)"
79 wxStyledTextCtrl(wxWindow
*parent
, wxWindowID id
,
80 const wxPoint
& pos
= wxDefaultPosition
,
81 const wxSize
& size
= wxDefaultSize
, long style
= 0,
82 const wxString
& name
= wxSTCNameStr
);
90 //----------------------------------------------------------------------
91 // BEGIN generated section. The following code is automatically generated
92 // by gen_iface.py. Do not edit this file. Edit stc.h.in instead
97 // END of generated section
98 //----------------------------------------------------------------------
102 // Returns the line number of the line with the caret.
103 int GetCurrentLine();
105 // Extract style settings from a spec-string which is composed of one or
106 // more of the following comma separated elements:
108 // bold turns on bold
109 // italic turns on italics
110 // fore:#RRGGBB sets the foreground colour
111 // back:#RRGGBB sets the background colour
112 // face:[facename] sets the font face name to use
113 // size:[num] sets the font size in points
114 // eol turns on eol filling
115 // underline turns on underlining
117 void StyleSetSpec(int styleNum
, const wxString
& spec
);
121 // Set style size, face, bold, italic, and underline attributes from
122 // a wxFont's attributes.
123 void StyleSetFont(int styleNum
, wxFont
& font
);
127 // Set all font style attributes at once.
128 void StyleSetFontAttr(int styleNum
, int size
,
129 const wxString
& faceName
,
130 bool bold
, bool italic
,
135 // Perform one of the operations defined by the wxSTC_CMD_* constants.
136 void CmdKeyExecute(int cmd
);
140 // Set the left and right margin in the edit area, measured in pixels.
141 void SetMargins(int left
, int right
);
144 // Retrieve the start and end positions of the current selection.
146 void GetSelection(int* OUTPUT
, int* OUTPUT
);
148 void GetSelection(int* startPos
, int* endPos
);
151 // Retrieve the point in the window where a position is displayed.
152 wxPoint
PointFromPosition(int pos
);
155 // Scroll enough to make the given line visible
156 void ScrollToLine(int line
);
159 // Scroll enough to make the given column visible
160 void ScrollToColumn(int column
);
163 // Send a message to Scintilla
164 long SendMsg(int msg
, long wp
=0, long lp
=0);
167 // Set the vertical scrollbar to use instead of the ont that's built-in.
168 void SetVScrollBar(wxScrollBar
* bar
) { m_vScrollBar
= bar
; }
171 // Set the horizontal scrollbar to use instead of the ont that's built-in.
172 void SetHScrollBar(wxScrollBar
* bar
) { m_hScrollBar
= bar
; }
174 // Can be used to prevent the EVT_CHAR handler from adding the char
175 bool GetLastKeydownProcessed() { return m_lastKeyDownConsumed
; }
176 void SetLastKeydownProcessed(bool val
) { m_lastKeyDownConsumed
= val
; }
179 //----------------------------------------------------------------------
185 void OnPaint(wxPaintEvent
& evt
);
186 void OnScrollWin(wxScrollWinEvent
& evt
);
187 void OnScroll(wxScrollEvent
& evt
);
188 void OnSize(wxSizeEvent
& evt
);
189 void OnMouseLeftDown(wxMouseEvent
& evt
);
190 void OnMouseMove(wxMouseEvent
& evt
);
191 void OnMouseLeftUp(wxMouseEvent
& evt
);
192 void OnMouseRightUp(wxMouseEvent
& evt
);
193 void OnMouseMiddleUp(wxMouseEvent
& evt
);
194 void OnContextMenu(wxContextMenuEvent
& evt
);
195 void OnMouseWheel(wxMouseEvent
& evt
);
196 void OnChar(wxKeyEvent
& evt
);
197 void OnKeyDown(wxKeyEvent
& evt
);
198 void OnLoseFocus(wxFocusEvent
& evt
);
199 void OnGainFocus(wxFocusEvent
& evt
);
200 void OnSysColourChanged(wxSysColourChangedEvent
& evt
);
201 void OnEraseBackground(wxEraseEvent
& evt
);
202 void OnMenu(wxCommandEvent
& evt
);
203 void OnListBox(wxCommandEvent
& evt
);
206 // Turn notifications from Scintilla into events
208 void NotifyParent(SCNotification
* scn
);
212 DECLARE_EVENT_TABLE()
213 DECLARE_CLASS(wxStyledTextCtrl
)
216 wxStopWatch m_stopWatch
;
217 wxScrollBar
* m_vScrollBar
;
218 wxScrollBar
* m_hScrollBar
;
220 bool m_lastKeyDownConsumed
;
222 friend class ScintillaWX
;
223 friend class Platform
;
227 //----------------------------------------------------------------------
229 // SWIG can't handle "#if" type of conditionals, only "#ifdef"
231 #define STC_USE_DND 1
233 #if wxUSE_DRAG_AND_DROP
234 #define STC_USE_DND 1
238 class wxStyledTextEvent
: public wxCommandEvent
{
240 wxStyledTextEvent(wxEventType commandType
=0, int id
=0);
242 wxStyledTextEvent(const wxStyledTextEvent
& event
);
244 ~wxStyledTextEvent() {}
246 void SetPosition(int pos
) { m_position
= pos
; }
247 void SetKey(int k
) { m_key
= k
; }
248 void SetModifiers(int m
) { m_modifiers
= m
; }
249 void SetModificationType(int t
) { m_modificationType
= t
; }
250 void SetText(const wxString
& t
) { m_text
= t
; }
251 void SetLength(int len
) { m_length
= len
; }
252 void SetLinesAdded(int num
) { m_linesAdded
= num
; }
253 void SetLine(int val
) { m_line
= val
; }
254 void SetFoldLevelNow(int val
) { m_foldLevelNow
= val
; }
255 void SetFoldLevelPrev(int val
) { m_foldLevelPrev
= val
; }
256 void SetMargin(int val
) { m_margin
= val
; }
257 void SetMessage(int val
) { m_message
= val
; }
258 void SetWParam(int val
) { m_wParam
= val
; }
259 void SetLParam(int val
) { m_lParam
= val
; }
260 void SetListType(int val
) { m_listType
= val
; }
261 void SetX(int val
) { m_x
= val
; }
262 void SetY(int val
) { m_y
= val
; }
263 void SetDragText(const wxString
& val
) { m_dragText
= val
; }
264 void SetDragAllowMove(bool val
) { m_dragAllowMove
= val
; }
266 void SetDragResult(wxDragResult val
) { m_dragResult
= val
; }
269 int GetPosition() const { return m_position
; }
270 int GetKey() const { return m_key
; }
271 int GetModifiers() const { return m_modifiers
; }
272 int GetModificationType() const { return m_modificationType
; }
273 wxString
GetText() const { return m_text
; }
274 int GetLength() const { return m_length
; }
275 int GetLinesAdded() const { return m_linesAdded
; }
276 int GetLine() const { return m_line
; }
277 int GetFoldLevelNow() const { return m_foldLevelNow
; }
278 int GetFoldLevelPrev() const { return m_foldLevelPrev
; }
279 int GetMargin() const { return m_margin
; }
280 int GetMessage() const { return m_message
; }
281 int GetWParam() const { return m_wParam
; }
282 int GetLParam() const { return m_lParam
; }
283 int GetListType() const { return m_listType
; }
284 int GetX() const { return m_x
; }
285 int GetY() const { return m_y
; }
286 wxString
GetDragText() { return m_dragText
; }
287 bool GetDragAllowMove() { return m_dragAllowMove
; }
289 wxDragResult
GetDragResult() { return m_dragResult
; }
292 bool GetShift() const;
293 bool GetControl() const;
296 virtual wxEvent
* Clone() const { return new wxStyledTextEvent(*this); }
300 DECLARE_DYNAMIC_CLASS(wxStyledTextEvent
)
306 int m_modificationType
; // wxEVT_STC_MODIFIED
314 int m_margin
; // wxEVT_STC_MARGINCLICK
316 int m_message
; // wxEVT_STC_MACRORECORD
324 wxString m_dragText
; // wxEVT_STC_START_DRAG, wxEVT_STC_DO_DROP
325 bool m_dragAllowMove
; // wxEVT_STC_START_DRAG
327 #if wxUSE_DRAG_AND_DROP
328 wxDragResult m_dragResult
; // wxEVT_STC_DRAG_OVER,wxEVT_STC_DO_DROP
334 BEGIN_DECLARE_EVENT_TYPES()
335 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_CHANGE
, 1650)
336 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_STYLENEEDED
, 1651)
337 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_CHARADDED
, 1652)
338 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_SAVEPOINTREACHED
, 1653)
339 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_SAVEPOINTLEFT
, 1654)
340 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_ROMODIFYATTEMPT
, 1655)
341 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_KEY
, 1656)
342 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_DOUBLECLICK
, 1657)
343 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_UPDATEUI
, 1658)
344 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_MODIFIED
, 1659)
345 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_MACRORECORD
, 1660)
346 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_MARGINCLICK
, 1661)
347 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_NEEDSHOWN
, 1662)
348 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_POSCHANGED
, 1663)
349 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_PAINTED
, 1664)
350 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_USERLISTSELECTION
, 1665)
351 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_URIDROPPED
, 1666)
352 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_DWELLSTART
, 1667)
353 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_DWELLEND
, 1668)
354 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_START_DRAG
, 1669)
355 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_DRAG_OVER
, 1670)
356 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_DO_DROP
, 1671)
357 DECLARE_LOCAL_EVENT_TYPE(wxEVT_STC_ZOOM
, 1672)
358 END_DECLARE_EVENT_TYPES()
362 wxEVT_STC_STYLENEEDED
,
364 wxEVT_STC_SAVEPOINTREACHED
,
365 wxEVT_STC_SAVEPOINTLEFT
,
366 wxEVT_STC_ROMODIFYATTEMPT
,
368 wxEVT_STC_DOUBLECLICK
,
371 wxEVT_STC_MACRORECORD
,
372 wxEVT_STC_MARGINCLICK
,
374 wxEVT_STC_POSCHANGED
,
376 wxEVT_STC_USERLISTSELECTION
,
377 wxEVT_STC_URIDROPPED
,
378 wxEVT_STC_DWELLSTART
,
380 wxEVT_STC_START_DRAG
,
390 typedef void (wxEvtHandler::*wxStyledTextEventFunction
)(wxStyledTextEvent
&);
392 #define EVT_STC_CHANGE(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_CHANGE, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
393 #define EVT_STC_STYLENEEDED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_STYLENEEDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
394 #define EVT_STC_CHARADDED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_CHARADDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
395 #define EVT_STC_SAVEPOINTREACHED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_SAVEPOINTREACHED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
396 #define EVT_STC_SAVEPOINTLEFT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_SAVEPOINTLEFT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
397 #define EVT_STC_ROMODIFYATTEMPT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_ROMODIFYATTEMPT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
398 #define EVT_STC_KEY(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_KEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
399 #define EVT_STC_DOUBLECLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_DOUBLECLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
400 #define EVT_STC_UPDATEUI(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_UPDATEUI, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
401 #define EVT_STC_MODIFIED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_MODIFIED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
402 #define EVT_STC_MACRORECORD(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_MACRORECORD, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
403 #define EVT_STC_MARGINCLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_MARGINCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
404 #define EVT_STC_NEEDSHOWN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_NEEDSHOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
405 #define EVT_STC_POSCHANGED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_POSCHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
406 #define EVT_STC_PAINTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_PAINTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
407 #define EVT_STC_USERLISTSELECTION(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_USERLISTSELECTION, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
408 #define EVT_STC_URIDROPPED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_URIDROPPED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
409 #define EVT_STC_DWELLSTART(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_DWELLSTART, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
410 #define EVT_STC_DWELLEND(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_DWELLEND, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
411 #define EVT_STC_START_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_START_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
412 #define EVT_STC_DRAG_OVER(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_DRAG_OVER, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
413 #define EVT_STC_DO_DROP(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_DO_DROP, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
414 #define EVT_STC_ZOOM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_ZOOM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL ),
417 //----------------------------------------------------------------------
418 // Utility functions used within wxSTC
422 inline wxString
stc2wx(const char* str
) {
424 return wxString(str
, wxConvUTF8
);
426 return wxString(str
);
430 inline wxString
stc2wx(const char* str
, size_t len
) {
432 return wxString(str
, wxConvUTF8
, len
);
434 return wxString(str
, len
);
439 inline const wxWX2MBbuf
wx2stc(const wxString
& str
) {
440 return str
.mb_str(wxConvUTF8
);
443 inline const wxWX2MBbuf
wx2stc(const wxString
& str
) {
444 return str
.mbc_str();
451 //----------------------------------------------------------------------