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