]> git.saurik.com Git - wxWidgets.git/blame - src/stc/stc.cpp.in
source nice-ness and remove erronous 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('#')) {
57
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)
f97d84a6
RD
123 EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox)
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();
d6582821 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())
343 return FALSE;
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
RD
360 wxString contents;
361 off_t len = 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);
9efe0302
RD
367 if (success) {
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
4a65f2c8
RD
393wxDragResult wxStyledTextCtrl::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) {
394 return m_swx->DoDragOver(x, y, def);
395}
396
397
398bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) {
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();
504 bool alt = evt.AltDown();
00c64037 505 bool skip = ((ctrl || alt) && ! (ctrl && alt));
f3c2c221 506
2b5f62a0
VZ
507 int key = evt.GetKeyCode();
508
451c5cc7
RD
509// printf("OnChar key:%%d consumed:%%d ctrl:%%d alt:%%d skip:%%d\n",
510// key, m_lastKeyDownConsumed, ctrl, alt, skip);
10ef30eb 511
25484746 512 if ( (key <= WXK_START || key > WXK_COMMAND) &&
2b5f62a0 513 !m_lastKeyDownConsumed && !skip) {
f97d84a6 514 m_swx->DoAddChar(key);
f3c2c221 515 return;
f97d84a6 516 }
f3c2c221 517 evt.Skip();
f97d84a6
RD
518}
519
d6582821 520
f97d84a6 521void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) {
10ef30eb 522 int key = evt.GetKeyCode();
f3c2c221 523 bool shift = evt.ShiftDown(),
10ef30eb 524 ctrl = evt.ControlDown(),
88a8b04e
RD
525 alt = evt.AltDown(),
526 meta = evt.MetaDown();
f3c2c221 527
88a8b04e 528 int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, meta, &m_lastKeyDownConsumed);
f3c2c221 529
451c5cc7
RD
530// printf("KeyDn key:%%d shift:%%d ctrl:%%d alt:%%d processed:%%d consumed:%%d\n",
531// key, shift, ctrl, alt, processed, m_lastKeyDownConsumed);
f3c2c221 532
d6582821 533 if (!processed && !m_lastKeyDownConsumed)
f97d84a6
RD
534 evt.Skip();
535}
536
d6582821 537
b6bfd8e8 538void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent& evt) {
ec830416 539 m_swx->DoLoseFocus();
b6bfd8e8 540 evt.Skip();
f97d84a6
RD
541}
542
d6582821 543
b6bfd8e8 544void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) {
f97d84a6 545 m_swx->DoGainFocus();
b6bfd8e8 546 evt.Skip();
f97d84a6
RD
547}
548
d6582821 549
88a8b04e 550void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(evt)) {
f97d84a6
RD
551 m_swx->DoSysColourChange();
552}
553
d6582821 554
88a8b04e 555void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent& WXUNUSED(evt)) {
f97d84a6
RD
556 // do nothing to help avoid flashing
557}
558
559
560
561void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) {
562 m_swx->DoCommand(evt.GetId());
563}
564
565
88a8b04e 566void wxStyledTextCtrl::OnListBox(wxCommandEvent& WXUNUSED(evt)) {
f97d84a6
RD
567 m_swx->DoOnListBox();
568}
569
570
8e54aaed
RD
571void wxStyledTextCtrl::OnIdle(wxIdleEvent& evt) {
572 m_swx->DoOnIdle(evt);
573}
574
575
8ae4f086
RD
576wxSize wxStyledTextCtrl::DoGetBestSize() const
577{
578 // What would be the best size for a wxSTC?
579 // Just give a reasonable minimum until something else can be figured out.
580 return wxSize(200,100);
581}
582
583
f97d84a6
RD
584//----------------------------------------------------------------------
585// Turn notifications from Scintilla into events
586
587
588void wxStyledTextCtrl::NotifyChange() {
589 wxStyledTextEvent evt(wxEVT_STC_CHANGE, GetId());
a29a241f 590 evt.SetEventObject(this);
f97d84a6
RD
591 GetEventHandler()->ProcessEvent(evt);
592}
593
2b5f62a0
VZ
594
595static void SetEventText(wxStyledTextEvent& evt, const char* text,
596 size_t length) {
597 if(!text) return;
598
599 // The unicode conversion MUST have a null byte to terminate the
600 // string so move it into a buffer first and give it one.
601 wxMemoryBuffer buf(length+1);
602 buf.AppendData((void*)text, length);
603 buf.AppendByte(0);
604 evt.SetText(stc2wx(buf));
605}
606
607
f97d84a6
RD
608void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) {
609 SCNotification& scn = *_scn;
65ec6247
RD
610 wxStyledTextEvent evt(0, GetId());
611
a29a241f 612 evt.SetEventObject(this);
65ec6247
RD
613 evt.SetPosition(scn.position);
614 evt.SetKey(scn.ch);
615 evt.SetModifiers(scn.modifiers);
616
f97d84a6
RD
617 switch (scn.nmhdr.code) {
618 case SCN_STYLENEEDED:
65ec6247 619 evt.SetEventType(wxEVT_STC_STYLENEEDED);
f97d84a6 620 break;
65ec6247 621
f97d84a6 622 case SCN_CHARADDED:
65ec6247 623 evt.SetEventType(wxEVT_STC_CHARADDED);
f97d84a6 624 break;
65ec6247 625
f97d84a6 626 case SCN_SAVEPOINTREACHED:
65ec6247 627 evt.SetEventType(wxEVT_STC_SAVEPOINTREACHED);
f97d84a6 628 break;
65ec6247 629
f97d84a6 630 case SCN_SAVEPOINTLEFT:
65ec6247 631 evt.SetEventType(wxEVT_STC_SAVEPOINTLEFT);
f97d84a6 632 break;
65ec6247 633
f97d84a6 634 case SCN_MODIFYATTEMPTRO:
65ec6247
RD
635 evt.SetEventType(wxEVT_STC_ROMODIFYATTEMPT);
636 break;
637
638 case SCN_KEY:
639 evt.SetEventType(wxEVT_STC_KEY);
f97d84a6 640 break;
65ec6247 641
f97d84a6 642 case SCN_DOUBLECLICK:
65ec6247 643 evt.SetEventType(wxEVT_STC_DOUBLECLICK);
f97d84a6 644 break;
65ec6247
RD
645
646 case SCN_UPDATEUI:
647 evt.SetEventType(wxEVT_STC_UPDATEUI);
f97d84a6 648 break;
65ec6247
RD
649
650 case SCN_MODIFIED:
651 evt.SetEventType(wxEVT_STC_MODIFIED);
652 evt.SetModificationType(scn.modificationType);
2b5f62a0 653 SetEventText(evt, scn.text, scn.length);
65ec6247
RD
654 evt.SetLength(scn.length);
655 evt.SetLinesAdded(scn.linesAdded);
656 evt.SetLine(scn.line);
657 evt.SetFoldLevelNow(scn.foldLevelNow);
658 evt.SetFoldLevelPrev(scn.foldLevelPrev);
f97d84a6 659 break;
65ec6247 660
f97d84a6 661 case SCN_MACRORECORD:
65ec6247
RD
662 evt.SetEventType(wxEVT_STC_MACRORECORD);
663 evt.SetMessage(scn.message);
664 evt.SetWParam(scn.wParam);
665 evt.SetLParam(scn.lParam);
f97d84a6 666 break;
65ec6247 667
f97d84a6 668 case SCN_MARGINCLICK:
65ec6247
RD
669 evt.SetEventType(wxEVT_STC_MARGINCLICK);
670 evt.SetMargin(scn.margin);
f97d84a6 671 break;
65ec6247 672
f97d84a6 673 case SCN_NEEDSHOWN:
65ec6247
RD
674 evt.SetEventType(wxEVT_STC_NEEDSHOWN);
675 evt.SetLength(scn.length);
f97d84a6 676 break;
65ec6247 677
65ec6247
RD
678 case SCN_PAINTED:
679 evt.SetEventType(wxEVT_STC_PAINTED);
680 break;
681
682 case SCN_USERLISTSELECTION:
683 evt.SetEventType(wxEVT_STC_USERLISTSELECTION);
684 evt.SetListType(scn.listType);
2b5f62a0 685 SetEventText(evt, scn.text, strlen(scn.text));
f97d84a6 686 break;
f97d84a6 687
65ec6247
RD
688 case SCN_URIDROPPED:
689 evt.SetEventType(wxEVT_STC_URIDROPPED);
2b5f62a0 690 SetEventText(evt, scn.text, strlen(scn.text));
65ec6247
RD
691 break;
692
693 case SCN_DWELLSTART:
694 evt.SetEventType(wxEVT_STC_DWELLSTART);
695 evt.SetX(scn.x);
696 evt.SetY(scn.y);
697 break;
698
699 case SCN_DWELLEND:
700 evt.SetEventType(wxEVT_STC_DWELLEND);
701 evt.SetX(scn.x);
702 evt.SetY(scn.y);
703 break;
704
a834585d
RD
705 case SCN_ZOOM:
706 evt.SetEventType(wxEVT_STC_ZOOM);
707 break;
708
9e730a78
RD
709 case SCN_HOTSPOTCLICK:
710 evt.SetEventType(wxEVT_STC_HOTSPOT_CLICK);
711 break;
712
713 case SCN_HOTSPOTDOUBLECLICK:
714 evt.SetEventType(wxEVT_STC_HOTSPOT_DCLICK);
715 break;
716
717 case SCN_CALLTIPCLICK:
718 evt.SetEventType(wxEVT_STC_CALLTIP_CLICK);
719 break;
720
65ec6247
RD
721 default:
722 return;
f97d84a6 723 }
65ec6247
RD
724
725 GetEventHandler()->ProcessEvent(evt);
f97d84a6
RD
726}
727
728
f97d84a6
RD
729//----------------------------------------------------------------------
730//----------------------------------------------------------------------
731//----------------------------------------------------------------------
732
733wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id)
734 : wxCommandEvent(commandType, id)
735{
736 m_position = 0;
737 m_key = 0;
738 m_modifiers = 0;
739 m_modificationType = 0;
740 m_length = 0;
741 m_linesAdded = 0;
742 m_line = 0;
743 m_foldLevelNow = 0;
744 m_foldLevelPrev = 0;
745 m_margin = 0;
746 m_message = 0;
747 m_wParam = 0;
748 m_lParam = 0;
65ec6247
RD
749 m_listType = 0;
750 m_x = 0;
751 m_y = 0;
a29a241f 752 m_dragAllowMove = FALSE;
92bbd64f 753#if wxUSE_DRAG_AND_DROP
a29a241f 754 m_dragResult = wxDragNone;
92bbd64f 755#endif
f97d84a6
RD
756}
757
758bool wxStyledTextEvent::GetShift() const { return (m_modifiers & SCI_SHIFT) != 0; }
759bool wxStyledTextEvent::GetControl() const { return (m_modifiers & SCI_CTRL) != 0; }
760bool wxStyledTextEvent::GetAlt() const { return (m_modifiers & SCI_ALT) != 0; }
761
f97d84a6 762
5fa4613c
RD
763wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent& event):
764 wxCommandEvent(event)
765{
766 m_position = event.m_position;
767 m_key = event.m_key;
768 m_modifiers = event.m_modifiers;
769 m_modificationType = event.m_modificationType;
770 m_text = event.m_text;
771 m_length = event.m_length;
772 m_linesAdded = event.m_linesAdded;
773 m_line = event.m_line;
774 m_foldLevelNow = event.m_foldLevelNow;
775 m_foldLevelPrev = event.m_foldLevelPrev;
776
777 m_margin = event.m_margin;
778
779 m_message = event.m_message;
780 m_wParam = event.m_wParam;
781 m_lParam = event.m_lParam;
782
783 m_listType = event.m_listType;
784 m_x = event.m_x;
785 m_y = event.m_y;
f97d84a6 786
5fa4613c
RD
787 m_dragText = event.m_dragText;
788 m_dragAllowMove =event.m_dragAllowMove;
92bbd64f 789#if wxUSE_DRAG_AND_DROP
5fa4613c 790 m_dragResult = event.m_dragResult;
92bbd64f 791#endif
f97d84a6
RD
792}
793
794//----------------------------------------------------------------------
795//----------------------------------------------------------------------
796
a29a241f
RD
797
798
799
5fa4613c
RD
800
801
802
803
804