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