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