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