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