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