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