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