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