]>
Commit | Line | Data |
---|---|---|
f97d84a6 RD |
1 | //////////////////////////////////////////////////////////////////////////// |
2 | // Name: stc.cpp | |
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. | |
9 | // | |
10 | // Author: Robin Dunn | |
11 | // | |
12 | // Created: 13-Jan-2000 | |
13 | // RCS-ID: $Id$ | |
14 | // Copyright: (c) 2000 by Total Control Software | |
15 | // Licence: wxWindows license | |
16 | ///////////////////////////////////////////////////////////////////////////// | |
17 | ||
18 | #include <ctype.h> | |
19 | ||
20 | #include "wx/stc/stc.h" | |
21 | #include "ScintillaWX.h" | |
22 | ||
9e730a78 | 23 | #include <wx/wx.h> |
f97d84a6 | 24 | #include <wx/tokenzr.h> |
9e730a78 RD |
25 | #include <wx/mstream.h> |
26 | #include <wx/image.h> | |
f97d84a6 | 27 | |
f97d84a6 RD |
28 | |
29 | //---------------------------------------------------------------------- | |
30 | ||
10ef30eb | 31 | const wxChar* wxSTCNameStr = wxT("stcwindow"); |
f97d84a6 | 32 | |
451c5cc7 RD |
33 | #ifdef MAKELONG |
34 | #undef MAKELONG | |
35 | #endif | |
36 | ||
37 | #define MAKELONG(a, b) ((a) | ((b) << 16)) | |
38 | ||
39 | ||
40 | static long wxColourAsLong(const wxColour& co) { | |
41 | return (((long)co.Blue() << 16) | | |
42 | ((long)co.Green() << 8) | | |
43 | ((long)co.Red())); | |
44 | } | |
45 | ||
46 | static wxColour wxColourFromLong(long c) { | |
47 | wxColour clr; | |
48 | clr.Set(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff); | |
49 | return clr; | |
50 | } | |
51 | ||
52 | ||
53 | static wxColour wxColourFromSpec(const wxString& spec) { | |
54 | // spec should be "#RRGGBB" | |
55 | long red, green, blue; | |
56 | red = green = blue = 0; | |
57 | spec.Mid(1,2).ToLong(&red, 16); | |
58 | spec.Mid(3,2).ToLong(&green, 16); | |
59 | spec.Mid(5,2).ToLong(&blue, 16); | |
60 | return wxColour(red, green, blue); | |
61 | } | |
62 | ||
63 | //---------------------------------------------------------------------- | |
64 | ||
d25f5fbb RD |
65 | DEFINE_EVENT_TYPE( wxEVT_STC_CHANGE ) |
66 | DEFINE_EVENT_TYPE( wxEVT_STC_STYLENEEDED ) | |
67 | DEFINE_EVENT_TYPE( wxEVT_STC_CHARADDED ) | |
d25f5fbb RD |
68 | DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTREACHED ) |
69 | DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTLEFT ) | |
70 | DEFINE_EVENT_TYPE( wxEVT_STC_ROMODIFYATTEMPT ) | |
65ec6247 | 71 | DEFINE_EVENT_TYPE( wxEVT_STC_KEY ) |
d25f5fbb | 72 | DEFINE_EVENT_TYPE( wxEVT_STC_DOUBLECLICK ) |
65ec6247 | 73 | DEFINE_EVENT_TYPE( wxEVT_STC_UPDATEUI ) |
d25f5fbb | 74 | DEFINE_EVENT_TYPE( wxEVT_STC_MODIFIED ) |
d25f5fbb RD |
75 | DEFINE_EVENT_TYPE( wxEVT_STC_MACRORECORD ) |
76 | DEFINE_EVENT_TYPE( wxEVT_STC_MARGINCLICK ) | |
77 | DEFINE_EVENT_TYPE( wxEVT_STC_NEEDSHOWN ) | |
78 | DEFINE_EVENT_TYPE( wxEVT_STC_POSCHANGED ) | |
65ec6247 RD |
79 | DEFINE_EVENT_TYPE( wxEVT_STC_PAINTED ) |
80 | DEFINE_EVENT_TYPE( wxEVT_STC_USERLISTSELECTION ) | |
81 | DEFINE_EVENT_TYPE( wxEVT_STC_URIDROPPED ) | |
82 | DEFINE_EVENT_TYPE( wxEVT_STC_DWELLSTART ) | |
83 | DEFINE_EVENT_TYPE( wxEVT_STC_DWELLEND ) | |
a29a241f RD |
84 | DEFINE_EVENT_TYPE( wxEVT_STC_START_DRAG ) |
85 | DEFINE_EVENT_TYPE( wxEVT_STC_DRAG_OVER ) | |
86 | DEFINE_EVENT_TYPE( wxEVT_STC_DO_DROP ) | |
a834585d | 87 | DEFINE_EVENT_TYPE( wxEVT_STC_ZOOM ) |
9e730a78 RD |
88 | DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_CLICK ) |
89 | DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_DCLICK ) | |
90 | DEFINE_EVENT_TYPE( wxEVT_STC_CALLTIP_CLICK ) | |
91 | ||
d25f5fbb RD |
92 | |
93 | ||
f97d84a6 RD |
94 | BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) |
95 | EVT_PAINT (wxStyledTextCtrl::OnPaint) | |
96 | EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin) | |
5fa4613c | 97 | EVT_SCROLL (wxStyledTextCtrl::OnScroll) |
f97d84a6 RD |
98 | EVT_SIZE (wxStyledTextCtrl::OnSize) |
99 | EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown) | |
4ceb1196 RD |
100 | // Let Scintilla see the double click as a second click |
101 | EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown) | |
f97d84a6 RD |
102 | EVT_MOTION (wxStyledTextCtrl::OnMouseMove) |
103 | EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) | |
451c5cc7 | 104 | #if defined(__WXGTK__) || defined(__WXMAC__) |
ddf2da08 RD |
105 | EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) |
106 | #else | |
65ec6247 | 107 | EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu) |
ddf2da08 | 108 | #endif |
37d62433 | 109 | EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel) |
2b5f62a0 | 110 | EVT_MIDDLE_UP (wxStyledTextCtrl::OnMouseMiddleUp) |
f97d84a6 RD |
111 | EVT_CHAR (wxStyledTextCtrl::OnChar) |
112 | EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) | |
113 | EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) | |
114 | EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus) | |
115 | EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged) | |
116 | EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground) | |
dd4aa550 | 117 | EVT_MENU_RANGE (10, 16, wxStyledTextCtrl::OnMenu) |
f97d84a6 RD |
118 | EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox) |
119 | END_EVENT_TABLE() | |
120 | ||
121 | ||
122 | IMPLEMENT_CLASS(wxStyledTextCtrl, wxControl) | |
123 | IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent, wxCommandEvent) | |
124 | ||
40716a51 | 125 | #ifdef LINK_LEXERS |
1a2fb4cd | 126 | // forces the linking of the lexer modules |
a834585d | 127 | int Scintilla_LinkLexers(); |
40716a51 | 128 | #endif |
1a2fb4cd | 129 | |
f97d84a6 RD |
130 | //---------------------------------------------------------------------- |
131 | // Constructor and Destructor | |
132 | ||
133 | wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent, | |
134 | wxWindowID id, | |
135 | const wxPoint& pos, | |
136 | const wxSize& size, | |
137 | long style, | |
138 | const wxString& name) : | |
139 | wxControl(parent, id, pos, size, | |
140 | style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS | wxCLIP_CHILDREN, | |
141 | wxDefaultValidator, name) | |
142 | { | |
40716a51 | 143 | #ifdef LINK_LEXERS |
a834585d | 144 | Scintilla_LinkLexers(); |
40716a51 | 145 | #endif |
f97d84a6 RD |
146 | m_swx = new ScintillaWX(this); |
147 | m_stopWatch.Start(); | |
d6582821 | 148 | m_lastKeyDownConsumed = FALSE; |
5fa4613c RD |
149 | m_vScrollBar = NULL; |
150 | m_hScrollBar = NULL; | |
10ef30eb RD |
151 | #if wxUSE_UNICODE |
152 | // Put Scintilla into unicode (UTF-8) mode | |
153 | SetCodePage(wxSTC_CP_UTF8); | |
154 | #endif | |
f97d84a6 RD |
155 | } |
156 | ||
157 | ||
158 | wxStyledTextCtrl::~wxStyledTextCtrl() { | |
159 | delete m_swx; | |
160 | } | |
161 | ||
162 | ||
163 | //---------------------------------------------------------------------- | |
164 | ||
165 | long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) { | |
166 | ||
167 | return m_swx->WndProc(msg, wp, lp); | |
168 | } | |
169 | ||
170 | ||
f97d84a6 RD |
171 | |
172 | //---------------------------------------------------------------------- | |
173 | // BEGIN generated section. The following code is automatically generated | |
174 | // by gen_iface.py from the contents of Scintilla.iface. Do not edit | |
175 | // this file. Edit stc.cpp.in or gen_iface.py instead and regenerate. | |
176 | ||
177 | %(METHOD_IMPS)s | |
178 | ||
179 | // END of generated section | |
180 | //---------------------------------------------------------------------- | |
181 | ||
182 | ||
183 | // Returns the line number of the line with the caret. | |
184 | int wxStyledTextCtrl::GetCurrentLine() { | |
185 | int line = LineFromPosition(GetCurrentPos()); | |
186 | return line; | |
187 | } | |
188 | ||
189 | ||
190 | // Extract style settings from a spec-string which is composed of one or | |
191 | // more of the following comma separated elements: | |
192 | // | |
193 | // bold turns on bold | |
194 | // italic turns on italics | |
195 | // fore:#RRGGBB sets the foreground colour | |
196 | // back:#RRGGBB sets the background colour | |
197 | // face:[facename] sets the font face name to use | |
198 | // size:[num] sets the font size in points | |
199 | // eol turns on eol filling | |
200 | // underline turns on underlining | |
201 | // | |
202 | void wxStyledTextCtrl::StyleSetSpec(int styleNum, const wxString& spec) { | |
203 | ||
451c5cc7 | 204 | wxStringTokenizer tkz(spec, wxT(",")); |
f97d84a6 RD |
205 | while (tkz.HasMoreTokens()) { |
206 | wxString token = tkz.GetNextToken(); | |
207 | ||
208 | wxString option = token.BeforeFirst(':'); | |
209 | wxString val = token.AfterFirst(':'); | |
210 | ||
451c5cc7 | 211 | if (option == wxT("bold")) |
f97d84a6 RD |
212 | StyleSetBold(styleNum, true); |
213 | ||
451c5cc7 | 214 | else if (option == wxT("italic")) |
f97d84a6 RD |
215 | StyleSetItalic(styleNum, true); |
216 | ||
451c5cc7 | 217 | else if (option == wxT("underline")) |
f97d84a6 RD |
218 | StyleSetUnderline(styleNum, true); |
219 | ||
451c5cc7 | 220 | else if (option == wxT("eol")) |
f97d84a6 RD |
221 | StyleSetEOLFilled(styleNum, true); |
222 | ||
451c5cc7 | 223 | else if (option == wxT("size")) { |
f97d84a6 RD |
224 | long points; |
225 | if (val.ToLong(&points)) | |
226 | StyleSetSize(styleNum, points); | |
227 | } | |
228 | ||
451c5cc7 | 229 | else if (option == wxT("face")) |
f97d84a6 RD |
230 | StyleSetFaceName(styleNum, val); |
231 | ||
451c5cc7 | 232 | else if (option == wxT("fore")) |
f97d84a6 RD |
233 | StyleSetForeground(styleNum, wxColourFromSpec(val)); |
234 | ||
451c5cc7 | 235 | else if (option == wxT("back")) |
f97d84a6 RD |
236 | StyleSetBackground(styleNum, wxColourFromSpec(val)); |
237 | } | |
238 | } | |
239 | ||
240 | ||
241 | // Set style size, face, bold, italic, and underline attributes from | |
242 | // a wxFont's attributes. | |
243 | void wxStyledTextCtrl::StyleSetFont(int styleNum, wxFont& font) { | |
244 | int size = font.GetPointSize(); | |
245 | wxString faceName = font.GetFaceName(); | |
246 | bool bold = font.GetWeight() == wxBOLD; | |
247 | bool italic = font.GetStyle() != wxNORMAL; | |
248 | bool under = font.GetUnderlined(); | |
249 | ||
250 | // TODO: add encoding/charset mapping | |
251 | StyleSetFontAttr(styleNum, size, faceName, bold, italic, under); | |
252 | } | |
253 | ||
254 | // Set all font style attributes at once. | |
255 | void wxStyledTextCtrl::StyleSetFontAttr(int styleNum, int size, | |
256 | const wxString& faceName, | |
257 | bool bold, bool italic, | |
258 | bool underline) { | |
259 | StyleSetSize(styleNum, size); | |
260 | StyleSetFaceName(styleNum, faceName); | |
261 | StyleSetBold(styleNum, bold); | |
262 | StyleSetItalic(styleNum, italic); | |
263 | StyleSetUnderline(styleNum, underline); | |
264 | ||
265 | // TODO: add encoding/charset mapping | |
266 | } | |
267 | ||
268 | ||
269 | // Perform one of the operations defined by the wxSTC_CMD_* constants. | |
270 | void wxStyledTextCtrl::CmdKeyExecute(int cmd) { | |
271 | SendMsg(cmd); | |
272 | } | |
273 | ||
274 | ||
275 | // Set the left and right margin in the edit area, measured in pixels. | |
276 | void wxStyledTextCtrl::SetMargins(int left, int right) { | |
277 | SetMarginLeft(left); | |
278 | SetMarginRight(right); | |
279 | } | |
280 | ||
281 | ||
282 | // Retrieve the start and end positions of the current selection. | |
283 | void wxStyledTextCtrl::GetSelection(int* startPos, int* endPos) { | |
284 | if (startPos != NULL) | |
285 | *startPos = SendMsg(SCI_GETSELECTIONSTART); | |
286 | if (endPos != NULL) | |
287 | *endPos = SendMsg(SCI_GETSELECTIONEND); | |
288 | } | |
289 | ||
290 | ||
291 | // Retrieve the point in the window where a position is displayed. | |
292 | wxPoint wxStyledTextCtrl::PointFromPosition(int pos) { | |
293 | int x = SendMsg(SCI_POINTXFROMPOSITION, 0, pos); | |
294 | int y = SendMsg(SCI_POINTYFROMPOSITION, 0, pos); | |
295 | return wxPoint(x, y); | |
296 | } | |
297 | ||
298 | // Scroll enough to make the given line visible | |
299 | void wxStyledTextCtrl::ScrollToLine(int line) { | |
300 | m_swx->DoScrollToLine(line); | |
301 | } | |
302 | ||
303 | ||
304 | // Scroll enough to make the given column visible | |
305 | void wxStyledTextCtrl::ScrollToColumn(int column) { | |
306 | m_swx->DoScrollToColumn(column); | |
307 | } | |
308 | ||
309 | ||
310 | ||
311 | //---------------------------------------------------------------------- | |
312 | // Event handlers | |
313 | ||
314 | void wxStyledTextCtrl::OnPaint(wxPaintEvent& evt) { | |
315 | wxPaintDC dc(this); | |
9e730a78 | 316 | m_swx->DoPaint(&dc, GetUpdateRegion().GetBox()); |
f97d84a6 RD |
317 | } |
318 | ||
319 | void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent& evt) { | |
320 | if (evt.GetOrientation() == wxHORIZONTAL) | |
321 | m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition()); | |
322 | else | |
323 | m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition()); | |
324 | } | |
325 | ||
5fa4613c RD |
326 | void wxStyledTextCtrl::OnScroll(wxScrollEvent& evt) { |
327 | wxScrollBar* sb = wxDynamicCast(evt.GetEventObject(), wxScrollBar); | |
328 | if (sb) { | |
329 | if (sb->IsVertical()) | |
330 | m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition()); | |
331 | else | |
332 | m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition()); | |
333 | } | |
334 | } | |
335 | ||
f97d84a6 RD |
336 | void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) { |
337 | wxSize sz = GetClientSize(); | |
338 | m_swx->DoSize(sz.x, sz.y); | |
339 | } | |
340 | ||
341 | void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) { | |
cb1871ca | 342 | SetFocus(); |
f97d84a6 | 343 | wxPoint pt = evt.GetPosition(); |
2b5f62a0 | 344 | m_swx->DoLeftButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(), |
f97d84a6 RD |
345 | evt.ShiftDown(), evt.ControlDown(), evt.AltDown()); |
346 | } | |
347 | ||
348 | void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) { | |
349 | wxPoint pt = evt.GetPosition(); | |
2b5f62a0 | 350 | m_swx->DoLeftButtonMove(Point(pt.x, pt.y)); |
f97d84a6 RD |
351 | } |
352 | ||
353 | void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) { | |
354 | wxPoint pt = evt.GetPosition(); | |
2b5f62a0 | 355 | m_swx->DoLeftButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(), |
f97d84a6 RD |
356 | evt.ControlDown()); |
357 | } | |
358 | ||
359 | ||
ddf2da08 RD |
360 | void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) { |
361 | wxPoint pt = evt.GetPosition(); | |
362 | m_swx->DoContextMenu(Point(pt.x, pt.y)); | |
363 | } | |
364 | ||
365 | ||
2b5f62a0 VZ |
366 | void wxStyledTextCtrl::OnMouseMiddleUp(wxMouseEvent& evt) { |
367 | wxPoint pt = evt.GetPosition(); | |
368 | m_swx->DoMiddleButtonUp(Point(pt.x, pt.y)); | |
369 | } | |
370 | ||
65ec6247 | 371 | void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) { |
f97d84a6 | 372 | wxPoint pt = evt.GetPosition(); |
65ec6247 | 373 | ScreenToClient(&pt.x, &pt.y); |
f97d84a6 RD |
374 | m_swx->DoContextMenu(Point(pt.x, pt.y)); |
375 | } | |
376 | ||
37d62433 RD |
377 | |
378 | void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { | |
379 | m_swx->DoMouseWheel(evt.GetWheelRotation(), | |
380 | evt.GetWheelDelta(), | |
65ec6247 | 381 | evt.GetLinesPerAction(), |
9b9337da RD |
382 | evt.ControlDown(), |
383 | evt.IsPageScroll()); | |
37d62433 RD |
384 | } |
385 | ||
386 | ||
f97d84a6 | 387 | void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { |
f3c2c221 RD |
388 | // On (some?) non-US keyboards the AltGr key is required to enter some |
389 | // common characters. It comes to us as both Alt and Ctrl down so we need | |
390 | // to let the char through in that case, otherwise if only ctrl or only | |
391 | // alt let's skip it. | |
392 | bool ctrl = evt.ControlDown(); | |
393 | bool alt = evt.AltDown(); | |
00c64037 | 394 | bool skip = ((ctrl || alt) && ! (ctrl && alt)); |
f3c2c221 | 395 | |
2b5f62a0 VZ |
396 | int key = evt.GetKeyCode(); |
397 | ||
451c5cc7 RD |
398 | // printf("OnChar key:%%d consumed:%%d ctrl:%%d alt:%%d skip:%%d\n", |
399 | // key, m_lastKeyDownConsumed, ctrl, alt, skip); | |
10ef30eb | 400 | |
2b5f62a0 VZ |
401 | if ( (key <= WXK_START || key > WXK_NUMPAD_DIVIDE) && |
402 | !m_lastKeyDownConsumed && !skip) { | |
f97d84a6 | 403 | m_swx->DoAddChar(key); |
f3c2c221 | 404 | return; |
f97d84a6 | 405 | } |
f3c2c221 | 406 | evt.Skip(); |
f97d84a6 RD |
407 | } |
408 | ||
d6582821 | 409 | |
f97d84a6 | 410 | void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { |
10ef30eb | 411 | int key = evt.GetKeyCode(); |
f3c2c221 | 412 | bool shift = evt.ShiftDown(), |
10ef30eb RD |
413 | ctrl = evt.ControlDown(), |
414 | alt = evt.AltDown(); | |
f3c2c221 RD |
415 | |
416 | int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, &m_lastKeyDownConsumed); | |
417 | ||
451c5cc7 RD |
418 | // printf("KeyDn key:%%d shift:%%d ctrl:%%d alt:%%d processed:%%d consumed:%%d\n", |
419 | // key, shift, ctrl, alt, processed, m_lastKeyDownConsumed); | |
f3c2c221 | 420 | |
d6582821 | 421 | if (!processed && !m_lastKeyDownConsumed) |
f97d84a6 RD |
422 | evt.Skip(); |
423 | } | |
424 | ||
d6582821 | 425 | |
f97d84a6 RD |
426 | void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent& evt) { |
427 | m_swx->DoLoseFocus(); | |
428 | } | |
429 | ||
d6582821 | 430 | |
f97d84a6 RD |
431 | void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { |
432 | m_swx->DoGainFocus(); | |
433 | } | |
434 | ||
d6582821 | 435 | |
f97d84a6 RD |
436 | void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& evt) { |
437 | m_swx->DoSysColourChange(); | |
438 | } | |
439 | ||
d6582821 | 440 | |
f97d84a6 RD |
441 | void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent& evt) { |
442 | // do nothing to help avoid flashing | |
443 | } | |
444 | ||
445 | ||
446 | ||
447 | void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) { | |
448 | m_swx->DoCommand(evt.GetId()); | |
449 | } | |
450 | ||
451 | ||
452 | void wxStyledTextCtrl::OnListBox(wxCommandEvent& evt) { | |
453 | m_swx->DoOnListBox(); | |
454 | } | |
455 | ||
456 | ||
457 | //---------------------------------------------------------------------- | |
458 | // Turn notifications from Scintilla into events | |
459 | ||
460 | ||
461 | void wxStyledTextCtrl::NotifyChange() { | |
462 | wxStyledTextEvent evt(wxEVT_STC_CHANGE, GetId()); | |
a29a241f | 463 | evt.SetEventObject(this); |
f97d84a6 RD |
464 | GetEventHandler()->ProcessEvent(evt); |
465 | } | |
466 | ||
2b5f62a0 VZ |
467 | |
468 | static void SetEventText(wxStyledTextEvent& evt, const char* text, | |
469 | size_t length) { | |
470 | if(!text) return; | |
471 | ||
472 | // The unicode conversion MUST have a null byte to terminate the | |
473 | // string so move it into a buffer first and give it one. | |
474 | wxMemoryBuffer buf(length+1); | |
475 | buf.AppendData((void*)text, length); | |
476 | buf.AppendByte(0); | |
477 | evt.SetText(stc2wx(buf)); | |
478 | } | |
479 | ||
480 | ||
f97d84a6 RD |
481 | void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { |
482 | SCNotification& scn = *_scn; | |
65ec6247 RD |
483 | wxStyledTextEvent evt(0, GetId()); |
484 | ||
a29a241f | 485 | evt.SetEventObject(this); |
65ec6247 RD |
486 | evt.SetPosition(scn.position); |
487 | evt.SetKey(scn.ch); | |
488 | evt.SetModifiers(scn.modifiers); | |
489 | ||
f97d84a6 RD |
490 | switch (scn.nmhdr.code) { |
491 | case SCN_STYLENEEDED: | |
65ec6247 | 492 | evt.SetEventType(wxEVT_STC_STYLENEEDED); |
f97d84a6 | 493 | break; |
65ec6247 | 494 | |
f97d84a6 | 495 | case SCN_CHARADDED: |
65ec6247 | 496 | evt.SetEventType(wxEVT_STC_CHARADDED); |
f97d84a6 | 497 | break; |
65ec6247 | 498 | |
f97d84a6 | 499 | case SCN_SAVEPOINTREACHED: |
65ec6247 | 500 | evt.SetEventType(wxEVT_STC_SAVEPOINTREACHED); |
f97d84a6 | 501 | break; |
65ec6247 | 502 | |
f97d84a6 | 503 | case SCN_SAVEPOINTLEFT: |
65ec6247 | 504 | evt.SetEventType(wxEVT_STC_SAVEPOINTLEFT); |
f97d84a6 | 505 | break; |
65ec6247 | 506 | |
f97d84a6 | 507 | case SCN_MODIFYATTEMPTRO: |
65ec6247 RD |
508 | evt.SetEventType(wxEVT_STC_ROMODIFYATTEMPT); |
509 | break; | |
510 | ||
511 | case SCN_KEY: | |
512 | evt.SetEventType(wxEVT_STC_KEY); | |
f97d84a6 | 513 | break; |
65ec6247 | 514 | |
f97d84a6 | 515 | case SCN_DOUBLECLICK: |
65ec6247 | 516 | evt.SetEventType(wxEVT_STC_DOUBLECLICK); |
f97d84a6 | 517 | break; |
65ec6247 RD |
518 | |
519 | case SCN_UPDATEUI: | |
520 | evt.SetEventType(wxEVT_STC_UPDATEUI); | |
f97d84a6 | 521 | break; |
65ec6247 RD |
522 | |
523 | case SCN_MODIFIED: | |
524 | evt.SetEventType(wxEVT_STC_MODIFIED); | |
525 | evt.SetModificationType(scn.modificationType); | |
2b5f62a0 | 526 | SetEventText(evt, scn.text, scn.length); |
65ec6247 RD |
527 | evt.SetLength(scn.length); |
528 | evt.SetLinesAdded(scn.linesAdded); | |
529 | evt.SetLine(scn.line); | |
530 | evt.SetFoldLevelNow(scn.foldLevelNow); | |
531 | evt.SetFoldLevelPrev(scn.foldLevelPrev); | |
f97d84a6 | 532 | break; |
65ec6247 | 533 | |
f97d84a6 | 534 | case SCN_MACRORECORD: |
65ec6247 RD |
535 | evt.SetEventType(wxEVT_STC_MACRORECORD); |
536 | evt.SetMessage(scn.message); | |
537 | evt.SetWParam(scn.wParam); | |
538 | evt.SetLParam(scn.lParam); | |
f97d84a6 | 539 | break; |
65ec6247 | 540 | |
f97d84a6 | 541 | case SCN_MARGINCLICK: |
65ec6247 RD |
542 | evt.SetEventType(wxEVT_STC_MARGINCLICK); |
543 | evt.SetMargin(scn.margin); | |
f97d84a6 | 544 | break; |
65ec6247 | 545 | |
f97d84a6 | 546 | case SCN_NEEDSHOWN: |
65ec6247 RD |
547 | evt.SetEventType(wxEVT_STC_NEEDSHOWN); |
548 | evt.SetLength(scn.length); | |
f97d84a6 | 549 | break; |
65ec6247 | 550 | |
65ec6247 RD |
551 | case SCN_PAINTED: |
552 | evt.SetEventType(wxEVT_STC_PAINTED); | |
553 | break; | |
554 | ||
555 | case SCN_USERLISTSELECTION: | |
556 | evt.SetEventType(wxEVT_STC_USERLISTSELECTION); | |
557 | evt.SetListType(scn.listType); | |
2b5f62a0 | 558 | SetEventText(evt, scn.text, strlen(scn.text)); |
f97d84a6 | 559 | break; |
f97d84a6 | 560 | |
65ec6247 RD |
561 | case SCN_URIDROPPED: |
562 | evt.SetEventType(wxEVT_STC_URIDROPPED); | |
2b5f62a0 | 563 | SetEventText(evt, scn.text, strlen(scn.text)); |
65ec6247 RD |
564 | break; |
565 | ||
566 | case SCN_DWELLSTART: | |
567 | evt.SetEventType(wxEVT_STC_DWELLSTART); | |
568 | evt.SetX(scn.x); | |
569 | evt.SetY(scn.y); | |
570 | break; | |
571 | ||
572 | case SCN_DWELLEND: | |
573 | evt.SetEventType(wxEVT_STC_DWELLEND); | |
574 | evt.SetX(scn.x); | |
575 | evt.SetY(scn.y); | |
576 | break; | |
577 | ||
a834585d RD |
578 | case SCN_ZOOM: |
579 | evt.SetEventType(wxEVT_STC_ZOOM); | |
580 | break; | |
581 | ||
9e730a78 RD |
582 | case SCN_HOTSPOTCLICK: |
583 | evt.SetEventType(wxEVT_STC_HOTSPOT_CLICK); | |
584 | break; | |
585 | ||
586 | case SCN_HOTSPOTDOUBLECLICK: | |
587 | evt.SetEventType(wxEVT_STC_HOTSPOT_DCLICK); | |
588 | break; | |
589 | ||
590 | case SCN_CALLTIPCLICK: | |
591 | evt.SetEventType(wxEVT_STC_CALLTIP_CLICK); | |
592 | break; | |
593 | ||
65ec6247 RD |
594 | default: |
595 | return; | |
f97d84a6 | 596 | } |
65ec6247 RD |
597 | |
598 | GetEventHandler()->ProcessEvent(evt); | |
f97d84a6 RD |
599 | } |
600 | ||
601 | ||
f97d84a6 RD |
602 | //---------------------------------------------------------------------- |
603 | //---------------------------------------------------------------------- | |
604 | //---------------------------------------------------------------------- | |
605 | ||
606 | wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id) | |
607 | : wxCommandEvent(commandType, id) | |
608 | { | |
609 | m_position = 0; | |
610 | m_key = 0; | |
611 | m_modifiers = 0; | |
612 | m_modificationType = 0; | |
613 | m_length = 0; | |
614 | m_linesAdded = 0; | |
615 | m_line = 0; | |
616 | m_foldLevelNow = 0; | |
617 | m_foldLevelPrev = 0; | |
618 | m_margin = 0; | |
619 | m_message = 0; | |
620 | m_wParam = 0; | |
621 | m_lParam = 0; | |
65ec6247 RD |
622 | m_listType = 0; |
623 | m_x = 0; | |
624 | m_y = 0; | |
a29a241f | 625 | m_dragAllowMove = FALSE; |
92bbd64f | 626 | #if wxUSE_DRAG_AND_DROP |
a29a241f | 627 | m_dragResult = wxDragNone; |
92bbd64f | 628 | #endif |
f97d84a6 RD |
629 | } |
630 | ||
631 | bool wxStyledTextEvent::GetShift() const { return (m_modifiers & SCI_SHIFT) != 0; } | |
632 | bool wxStyledTextEvent::GetControl() const { return (m_modifiers & SCI_CTRL) != 0; } | |
633 | bool wxStyledTextEvent::GetAlt() const { return (m_modifiers & SCI_ALT) != 0; } | |
634 | ||
f97d84a6 | 635 | |
5fa4613c RD |
636 | wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent& event): |
637 | wxCommandEvent(event) | |
638 | { | |
639 | m_position = event.m_position; | |
640 | m_key = event.m_key; | |
641 | m_modifiers = event.m_modifiers; | |
642 | m_modificationType = event.m_modificationType; | |
643 | m_text = event.m_text; | |
644 | m_length = event.m_length; | |
645 | m_linesAdded = event.m_linesAdded; | |
646 | m_line = event.m_line; | |
647 | m_foldLevelNow = event.m_foldLevelNow; | |
648 | m_foldLevelPrev = event.m_foldLevelPrev; | |
649 | ||
650 | m_margin = event.m_margin; | |
651 | ||
652 | m_message = event.m_message; | |
653 | m_wParam = event.m_wParam; | |
654 | m_lParam = event.m_lParam; | |
655 | ||
656 | m_listType = event.m_listType; | |
657 | m_x = event.m_x; | |
658 | m_y = event.m_y; | |
f97d84a6 | 659 | |
5fa4613c RD |
660 | m_dragText = event.m_dragText; |
661 | m_dragAllowMove =event.m_dragAllowMove; | |
92bbd64f | 662 | #if wxUSE_DRAG_AND_DROP |
5fa4613c | 663 | m_dragResult = event.m_dragResult; |
92bbd64f | 664 | #endif |
f97d84a6 RD |
665 | } |
666 | ||
667 | //---------------------------------------------------------------------- | |
668 | //---------------------------------------------------------------------- | |
669 | ||
a29a241f RD |
670 | |
671 | ||
672 | ||
5fa4613c RD |
673 | |
674 | ||
675 | ||
676 | ||
677 |