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