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