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