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