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