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