]>
Commit | Line | Data |
---|---|---|
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 | ||
54429bb3 RD |
18 | // For compilers that support precompilation, includes "wx.h". |
19 | #include "wx/wxprec.h" | |
20 | ||
21 | #ifdef __BORLANDC__ | |
22 | #pragma hdrstop | |
23 | #endif | |
24 | ||
29825f5f PC |
25 | #if wxUSE_STC |
26 | ||
27 | #include "wx/stc/stc.h" | |
4c784823 | 28 | #include "wx/stc/private.h" |
54429bb3 RD |
29 | |
30 | #ifndef WX_PRECOMP | |
29825f5f | 31 | #include "wx/wx.h" |
54429bb3 RD |
32 | #endif // WX_PRECOMP |
33 | ||
f97d84a6 RD |
34 | #include <ctype.h> |
35 | ||
d6655166 WS |
36 | #include "wx/tokenzr.h" |
37 | #include "wx/mstream.h" | |
38 | #include "wx/image.h" | |
39 | #include "wx/file.h" | |
f97d84a6 | 40 | |
f9ee2e27 | 41 | #include "ScintillaWX.h" |
f97d84a6 RD |
42 | |
43 | //---------------------------------------------------------------------- | |
44 | ||
10ef30eb | 45 | const wxChar* wxSTCNameStr = wxT("stcwindow"); |
f97d84a6 | 46 | |
451c5cc7 RD |
47 | #ifdef MAKELONG |
48 | #undef MAKELONG | |
49 | #endif | |
50 | ||
51 | #define MAKELONG(a, b) ((a) | ((b) << 16)) | |
52 | ||
53 | ||
54 | static long wxColourAsLong(const wxColour& co) { | |
55 | return (((long)co.Blue() << 16) | | |
56 | ((long)co.Green() << 8) | | |
57 | ((long)co.Red())); | |
58 | } | |
59 | ||
60 | static wxColour wxColourFromLong(long c) { | |
61 | wxColour clr; | |
a5b274d7 WS |
62 | clr.Set((unsigned char)(c & 0xff), |
63 | (unsigned char)((c >> 8) & 0xff), | |
64 | (unsigned char)((c >> 16) & 0xff)); | |
451c5cc7 RD |
65 | return clr; |
66 | } | |
67 | ||
68 | ||
69 | static wxColour wxColourFromSpec(const wxString& spec) { | |
5ee1d760 RD |
70 | // spec should be a colour name or "#RRGGBB" |
71 | if (spec.GetChar(0) == wxT('#')) { | |
dc8005e2 | 72 | |
5ee1d760 RD |
73 | long red, green, blue; |
74 | red = green = blue = 0; | |
75 | spec.Mid(1,2).ToLong(&red, 16); | |
76 | spec.Mid(3,2).ToLong(&green, 16); | |
77 | spec.Mid(5,2).ToLong(&blue, 16); | |
a5b274d7 WS |
78 | return wxColour((unsigned char)red, |
79 | (unsigned char)green, | |
80 | (unsigned char)blue); | |
5ee1d760 RD |
81 | } |
82 | else | |
83 | return wxColour(spec); | |
451c5cc7 RD |
84 | } |
85 | ||
86 | //---------------------------------------------------------------------- | |
87 | ||
d25f5fbb RD |
88 | DEFINE_EVENT_TYPE( wxEVT_STC_CHANGE ) |
89 | DEFINE_EVENT_TYPE( wxEVT_STC_STYLENEEDED ) | |
90 | DEFINE_EVENT_TYPE( wxEVT_STC_CHARADDED ) | |
d25f5fbb RD |
91 | DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTREACHED ) |
92 | DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTLEFT ) | |
93 | DEFINE_EVENT_TYPE( wxEVT_STC_ROMODIFYATTEMPT ) | |
65ec6247 | 94 | DEFINE_EVENT_TYPE( wxEVT_STC_KEY ) |
d25f5fbb | 95 | DEFINE_EVENT_TYPE( wxEVT_STC_DOUBLECLICK ) |
65ec6247 | 96 | DEFINE_EVENT_TYPE( wxEVT_STC_UPDATEUI ) |
d25f5fbb | 97 | DEFINE_EVENT_TYPE( wxEVT_STC_MODIFIED ) |
d25f5fbb RD |
98 | DEFINE_EVENT_TYPE( wxEVT_STC_MACRORECORD ) |
99 | DEFINE_EVENT_TYPE( wxEVT_STC_MARGINCLICK ) | |
100 | DEFINE_EVENT_TYPE( wxEVT_STC_NEEDSHOWN ) | |
65ec6247 RD |
101 | DEFINE_EVENT_TYPE( wxEVT_STC_PAINTED ) |
102 | DEFINE_EVENT_TYPE( wxEVT_STC_USERLISTSELECTION ) | |
103 | DEFINE_EVENT_TYPE( wxEVT_STC_URIDROPPED ) | |
104 | DEFINE_EVENT_TYPE( wxEVT_STC_DWELLSTART ) | |
105 | DEFINE_EVENT_TYPE( wxEVT_STC_DWELLEND ) | |
a29a241f RD |
106 | DEFINE_EVENT_TYPE( wxEVT_STC_START_DRAG ) |
107 | DEFINE_EVENT_TYPE( wxEVT_STC_DRAG_OVER ) | |
108 | DEFINE_EVENT_TYPE( wxEVT_STC_DO_DROP ) | |
a834585d | 109 | DEFINE_EVENT_TYPE( wxEVT_STC_ZOOM ) |
9e730a78 RD |
110 | DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_CLICK ) |
111 | DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_DCLICK ) | |
112 | DEFINE_EVENT_TYPE( wxEVT_STC_CALLTIP_CLICK ) | |
7e0c58e9 RD |
113 | DEFINE_EVENT_TYPE( wxEVT_STC_AUTOCOMP_SELECTION ) |
114 | DEFINE_EVENT_TYPE( wxEVT_STC_INDICATOR_CLICK ) | |
115 | DEFINE_EVENT_TYPE( wxEVT_STC_INDICATOR_RELEASE ) | |
9e730a78 | 116 | |
d25f5fbb RD |
117 | |
118 | ||
f97d84a6 RD |
119 | BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) |
120 | EVT_PAINT (wxStyledTextCtrl::OnPaint) | |
121 | EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin) | |
5fa4613c | 122 | EVT_SCROLL (wxStyledTextCtrl::OnScroll) |
f97d84a6 RD |
123 | EVT_SIZE (wxStyledTextCtrl::OnSize) |
124 | EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown) | |
4ceb1196 RD |
125 | // Let Scintilla see the double click as a second click |
126 | EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown) | |
f97d84a6 RD |
127 | EVT_MOTION (wxStyledTextCtrl::OnMouseMove) |
128 | EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) | |
451c5cc7 | 129 | #if defined(__WXGTK__) || defined(__WXMAC__) |
ddf2da08 RD |
130 | EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) |
131 | #else | |
65ec6247 | 132 | EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu) |
ddf2da08 | 133 | #endif |
37d62433 | 134 | EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel) |
2b5f62a0 | 135 | EVT_MIDDLE_UP (wxStyledTextCtrl::OnMouseMiddleUp) |
f97d84a6 RD |
136 | EVT_CHAR (wxStyledTextCtrl::OnChar) |
137 | EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) | |
138 | EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) | |
139 | EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus) | |
140 | EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged) | |
141 | EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground) | |
dd4aa550 | 142 | EVT_MENU_RANGE (10, 16, wxStyledTextCtrl::OnMenu) |
dc8005e2 | 143 | EVT_LISTBOX_DCLICK (wxID_ANY, wxStyledTextCtrl::OnListBox) |
f97d84a6 RD |
144 | END_EVENT_TABLE() |
145 | ||
146 | ||
147 | IMPLEMENT_CLASS(wxStyledTextCtrl, wxControl) | |
148 | IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent, wxCommandEvent) | |
149 | ||
40716a51 | 150 | #ifdef LINK_LEXERS |
1a2fb4cd | 151 | // forces the linking of the lexer modules |
a834585d | 152 | int Scintilla_LinkLexers(); |
40716a51 | 153 | #endif |
1a2fb4cd | 154 | |
f97d84a6 RD |
155 | //---------------------------------------------------------------------- |
156 | // Constructor and Destructor | |
157 | ||
158 | wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent, | |
159 | wxWindowID id, | |
160 | const wxPoint& pos, | |
161 | const wxSize& size, | |
162 | long style, | |
39c0acb6 RD |
163 | const wxString& name) |
164 | { | |
165 | m_swx = NULL; | |
166 | Create(parent, id, pos, size, style, name); | |
167 | } | |
168 | ||
169 | ||
a48cb415 RD |
170 | bool wxStyledTextCtrl::Create(wxWindow *parent, |
171 | wxWindowID id, | |
172 | const wxPoint& pos, | |
173 | const wxSize& size, | |
174 | long style, | |
175 | const wxString& name) | |
f97d84a6 | 176 | { |
2659dad3 | 177 | style |= wxVSCROLL | wxHSCROLL; |
a48cb415 RD |
178 | if (!wxControl::Create(parent, id, pos, size, |
179 | style | wxWANTS_CHARS | wxCLIP_CHILDREN, | |
180 | wxDefaultValidator, name)) | |
181 | return false; | |
39c0acb6 | 182 | |
40716a51 | 183 | #ifdef LINK_LEXERS |
a834585d | 184 | Scintilla_LinkLexers(); |
40716a51 | 185 | #endif |
f97d84a6 RD |
186 | m_swx = new ScintillaWX(this); |
187 | m_stopWatch.Start(); | |
dc8005e2 | 188 | m_lastKeyDownConsumed = false; |
5fa4613c RD |
189 | m_vScrollBar = NULL; |
190 | m_hScrollBar = NULL; | |
10ef30eb RD |
191 | #if wxUSE_UNICODE |
192 | // Put Scintilla into unicode (UTF-8) mode | |
193 | SetCodePage(wxSTC_CP_UTF8); | |
194 | #endif | |
8ae4f086 | 195 | |
170acdc9 | 196 | SetInitialSize(size); |
f9ee2e27 RD |
197 | |
198 | // Reduces flicker on GTK+/X11 | |
199 | SetBackgroundStyle(wxBG_STYLE_CUSTOM); | |
a48cb415 | 200 | return true; |
f97d84a6 RD |
201 | } |
202 | ||
203 | ||
204 | wxStyledTextCtrl::~wxStyledTextCtrl() { | |
205 | delete m_swx; | |
206 | } | |
207 | ||
208 | ||
209 | //---------------------------------------------------------------------- | |
210 | ||
211 | long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) { | |
212 | ||
213 | return m_swx->WndProc(msg, wp, lp); | |
214 | } | |
215 | ||
ccfc3219 RD |
216 | //---------------------------------------------------------------------- |
217 | ||
218 | // Set the vertical scrollbar to use instead of the ont that's built-in. | |
219 | void wxStyledTextCtrl::SetVScrollBar(wxScrollBar* bar) { | |
220 | m_vScrollBar = bar; | |
221 | if (bar != NULL) { | |
222 | // ensure that the built-in scrollbar is not visible | |
223 | SetScrollbar(wxVERTICAL, 0, 0, 0); | |
224 | } | |
225 | } | |
f97d84a6 | 226 | |
f97d84a6 | 227 | |
ccfc3219 RD |
228 | // Set the horizontal scrollbar to use instead of the ont that's built-in. |
229 | void wxStyledTextCtrl::SetHScrollBar(wxScrollBar* bar) { | |
230 | m_hScrollBar = bar; | |
231 | if (bar != NULL) { | |
232 | // ensure that the built-in scrollbar is not visible | |
233 | SetScrollbar(wxHORIZONTAL, 0, 0, 0); | |
234 | } | |
235 | } | |
236 | ||
f97d84a6 RD |
237 | //---------------------------------------------------------------------- |
238 | // BEGIN generated section. The following code is automatically generated | |
239 | // by gen_iface.py from the contents of Scintilla.iface. Do not edit | |
240 | // this file. Edit stc.cpp.in or gen_iface.py instead and regenerate. | |
241 | ||
242 | %(METHOD_IMPS)s | |
243 | ||
244 | // END of generated section | |
245 | //---------------------------------------------------------------------- | |
246 | ||
247 | ||
248 | // Returns the line number of the line with the caret. | |
249 | int wxStyledTextCtrl::GetCurrentLine() { | |
250 | int line = LineFromPosition(GetCurrentPos()); | |
251 | return line; | |
252 | } | |
253 | ||
254 | ||
255 | // Extract style settings from a spec-string which is composed of one or | |
256 | // more of the following comma separated elements: | |
257 | // | |
258 | // bold turns on bold | |
259 | // italic turns on italics | |
5ee1d760 RD |
260 | // fore:[name or #RRGGBB] sets the foreground colour |
261 | // back:[name or #RRGGBB] sets the background colour | |
f97d84a6 RD |
262 | // face:[facename] sets the font face name to use |
263 | // size:[num] sets the font size in points | |
264 | // eol turns on eol filling | |
265 | // underline turns on underlining | |
266 | // | |
267 | void wxStyledTextCtrl::StyleSetSpec(int styleNum, const wxString& spec) { | |
268 | ||
451c5cc7 | 269 | wxStringTokenizer tkz(spec, wxT(",")); |
f97d84a6 RD |
270 | while (tkz.HasMoreTokens()) { |
271 | wxString token = tkz.GetNextToken(); | |
272 | ||
273 | wxString option = token.BeforeFirst(':'); | |
274 | wxString val = token.AfterFirst(':'); | |
275 | ||
451c5cc7 | 276 | if (option == wxT("bold")) |
f97d84a6 RD |
277 | StyleSetBold(styleNum, true); |
278 | ||
451c5cc7 | 279 | else if (option == wxT("italic")) |
f97d84a6 RD |
280 | StyleSetItalic(styleNum, true); |
281 | ||
451c5cc7 | 282 | else if (option == wxT("underline")) |
f97d84a6 RD |
283 | StyleSetUnderline(styleNum, true); |
284 | ||
451c5cc7 | 285 | else if (option == wxT("eol")) |
f97d84a6 RD |
286 | StyleSetEOLFilled(styleNum, true); |
287 | ||
451c5cc7 | 288 | else if (option == wxT("size")) { |
f97d84a6 RD |
289 | long points; |
290 | if (val.ToLong(&points)) | |
291 | StyleSetSize(styleNum, points); | |
292 | } | |
293 | ||
451c5cc7 | 294 | else if (option == wxT("face")) |
f97d84a6 RD |
295 | StyleSetFaceName(styleNum, val); |
296 | ||
451c5cc7 | 297 | else if (option == wxT("fore")) |
f97d84a6 RD |
298 | StyleSetForeground(styleNum, wxColourFromSpec(val)); |
299 | ||
451c5cc7 | 300 | else if (option == wxT("back")) |
f97d84a6 RD |
301 | StyleSetBackground(styleNum, wxColourFromSpec(val)); |
302 | } | |
303 | } | |
304 | ||
305 | ||
7e0c58e9 RD |
306 | // Get the font of a style |
307 | wxFont wxStyledTextCtrl::StyleGetFont(int style) { | |
308 | wxFont font; | |
309 | font.SetPointSize(StyleGetSize(style)); | |
310 | font.SetFaceName(StyleGetFaceName(style)); | |
311 | if( StyleGetBold(style) ) | |
312 | font.SetWeight(wxFONTWEIGHT_BOLD); | |
313 | else | |
314 | font.SetWeight(wxFONTWEIGHT_NORMAL); | |
315 | ||
316 | if( StyleGetItalic(style) ) | |
317 | font.SetStyle(wxFONTSTYLE_ITALIC); | |
318 | else | |
319 | font.SetStyle(wxFONTSTYLE_NORMAL); | |
320 | ||
321 | return font; | |
322 | } | |
323 | ||
324 | ||
f97d84a6 RD |
325 | // Set style size, face, bold, italic, and underline attributes from |
326 | // a wxFont's attributes. | |
327 | void wxStyledTextCtrl::StyleSetFont(int styleNum, wxFont& font) { | |
7475e814 RD |
328 | #ifdef __WXGTK__ |
329 | // Ensure that the native font is initialized | |
330 | int x, y; | |
331 | GetTextExtent(wxT("X"), &x, &y, NULL, NULL, &font); | |
332 | #endif | |
af0531a5 RD |
333 | int size = font.GetPointSize(); |
334 | wxString faceName = font.GetFaceName(); | |
335 | bool bold = font.GetWeight() == wxBOLD; | |
336 | bool italic = font.GetStyle() != wxNORMAL; | |
337 | bool under = font.GetUnderlined(); | |
c5bd09bf | 338 | wxFontEncoding encoding = font.GetEncoding(); |
7e0c58e9 | 339 | |
af0531a5 | 340 | StyleSetFontAttr(styleNum, size, faceName, bold, italic, under, encoding); |
f97d84a6 RD |
341 | } |
342 | ||
343 | // Set all font style attributes at once. | |
344 | void wxStyledTextCtrl::StyleSetFontAttr(int styleNum, int size, | |
345 | const wxString& faceName, | |
346 | bool bold, bool italic, | |
3727c043 RD |
347 | bool underline, |
348 | wxFontEncoding encoding) { | |
f97d84a6 RD |
349 | StyleSetSize(styleNum, size); |
350 | StyleSetFaceName(styleNum, faceName); | |
351 | StyleSetBold(styleNum, bold); | |
352 | StyleSetItalic(styleNum, italic); | |
353 | StyleSetUnderline(styleNum, underline); | |
3727c043 RD |
354 | StyleSetFontEncoding(styleNum, encoding); |
355 | } | |
f97d84a6 | 356 | |
3727c043 RD |
357 | |
358 | // Set the character set of the font in a style. Converts the Scintilla | |
359 | // character set values to a wxFontEncoding. | |
360 | void wxStyledTextCtrl::StyleSetCharacterSet(int style, int characterSet) | |
361 | { | |
362 | wxFontEncoding encoding; | |
363 | ||
364 | // Translate the Scintilla characterSet to a wxFontEncoding | |
365 | switch (characterSet) { | |
366 | default: | |
367 | case wxSTC_CHARSET_ANSI: | |
368 | case wxSTC_CHARSET_DEFAULT: | |
369 | encoding = wxFONTENCODING_DEFAULT; | |
370 | break; | |
371 | ||
372 | case wxSTC_CHARSET_BALTIC: | |
373 | encoding = wxFONTENCODING_ISO8859_13; | |
374 | break; | |
375 | ||
376 | case wxSTC_CHARSET_CHINESEBIG5: | |
377 | encoding = wxFONTENCODING_CP950; | |
378 | break; | |
379 | ||
380 | case wxSTC_CHARSET_EASTEUROPE: | |
381 | encoding = wxFONTENCODING_ISO8859_2; | |
382 | break; | |
383 | ||
384 | case wxSTC_CHARSET_GB2312: | |
385 | encoding = wxFONTENCODING_CP936; | |
386 | break; | |
387 | ||
388 | case wxSTC_CHARSET_GREEK: | |
389 | encoding = wxFONTENCODING_ISO8859_7; | |
390 | break; | |
391 | ||
392 | case wxSTC_CHARSET_HANGUL: | |
393 | encoding = wxFONTENCODING_CP949; | |
394 | break; | |
395 | ||
396 | case wxSTC_CHARSET_MAC: | |
397 | encoding = wxFONTENCODING_DEFAULT; | |
398 | break; | |
399 | ||
400 | case wxSTC_CHARSET_OEM: | |
401 | encoding = wxFONTENCODING_DEFAULT; | |
402 | break; | |
403 | ||
404 | case wxSTC_CHARSET_RUSSIAN: | |
405 | encoding = wxFONTENCODING_KOI8; | |
406 | break; | |
407 | ||
408 | case wxSTC_CHARSET_SHIFTJIS: | |
409 | encoding = wxFONTENCODING_CP932; | |
410 | break; | |
411 | ||
412 | case wxSTC_CHARSET_SYMBOL: | |
413 | encoding = wxFONTENCODING_DEFAULT; | |
414 | break; | |
415 | ||
416 | case wxSTC_CHARSET_TURKISH: | |
417 | encoding = wxFONTENCODING_ISO8859_9; | |
418 | break; | |
419 | ||
420 | case wxSTC_CHARSET_JOHAB: | |
421 | encoding = wxFONTENCODING_DEFAULT; | |
422 | break; | |
423 | ||
424 | case wxSTC_CHARSET_HEBREW: | |
425 | encoding = wxFONTENCODING_ISO8859_8; | |
426 | break; | |
427 | ||
428 | case wxSTC_CHARSET_ARABIC: | |
429 | encoding = wxFONTENCODING_ISO8859_6; | |
430 | break; | |
431 | ||
432 | case wxSTC_CHARSET_VIETNAMESE: | |
433 | encoding = wxFONTENCODING_DEFAULT; | |
434 | break; | |
435 | ||
436 | case wxSTC_CHARSET_THAI: | |
437 | encoding = wxFONTENCODING_ISO8859_11; | |
438 | break; | |
1e9bafca RD |
439 | |
440 | case wxSTC_CHARSET_CYRILLIC: | |
441 | encoding = wxFONTENCODING_ISO8859_5; | |
442 | break; | |
7e0c58e9 | 443 | |
1e9bafca RD |
444 | case wxSTC_CHARSET_8859_15: |
445 | encoding = wxFONTENCODING_ISO8859_15;; | |
446 | break; | |
3727c043 RD |
447 | } |
448 | ||
449 | // We just have Scintilla track the wxFontEncoding for us. It gets used | |
450 | // in Font::Create in PlatWX.cpp. We add one to the value so that the | |
451 | // effective wxFONENCODING_DEFAULT == SC_SHARSET_DEFAULT and so when | |
452 | // Scintilla internally uses SC_CHARSET_DEFAULT we will translate it back | |
453 | // to wxFONENCODING_DEFAULT in Font::Create. | |
454 | SendMsg(SCI_STYLESETCHARACTERSET, style, encoding+1); | |
455 | } | |
456 | ||
457 | ||
458 | // Set the font encoding to be used by a style. | |
459 | void wxStyledTextCtrl::StyleSetFontEncoding(int style, wxFontEncoding encoding) | |
460 | { | |
461 | SendMsg(SCI_STYLESETCHARACTERSET, style, encoding+1); | |
f97d84a6 RD |
462 | } |
463 | ||
464 | ||
465 | // Perform one of the operations defined by the wxSTC_CMD_* constants. | |
466 | void wxStyledTextCtrl::CmdKeyExecute(int cmd) { | |
467 | SendMsg(cmd); | |
468 | } | |
469 | ||
470 | ||
471 | // Set the left and right margin in the edit area, measured in pixels. | |
472 | void wxStyledTextCtrl::SetMargins(int left, int right) { | |
473 | SetMarginLeft(left); | |
474 | SetMarginRight(right); | |
475 | } | |
476 | ||
477 | ||
478 | // Retrieve the start and end positions of the current selection. | |
479 | void wxStyledTextCtrl::GetSelection(int* startPos, int* endPos) { | |
480 | if (startPos != NULL) | |
481 | *startPos = SendMsg(SCI_GETSELECTIONSTART); | |
482 | if (endPos != NULL) | |
483 | *endPos = SendMsg(SCI_GETSELECTIONEND); | |
484 | } | |
485 | ||
486 | ||
487 | // Retrieve the point in the window where a position is displayed. | |
488 | wxPoint wxStyledTextCtrl::PointFromPosition(int pos) { | |
489 | int x = SendMsg(SCI_POINTXFROMPOSITION, 0, pos); | |
490 | int y = SendMsg(SCI_POINTYFROMPOSITION, 0, pos); | |
491 | return wxPoint(x, y); | |
492 | } | |
493 | ||
494 | // Scroll enough to make the given line visible | |
495 | void wxStyledTextCtrl::ScrollToLine(int line) { | |
496 | m_swx->DoScrollToLine(line); | |
497 | } | |
498 | ||
499 | ||
500 | // Scroll enough to make the given column visible | |
501 | void wxStyledTextCtrl::ScrollToColumn(int column) { | |
502 | m_swx->DoScrollToColumn(column); | |
503 | } | |
504 | ||
505 | ||
51566b0b RD |
506 | bool wxStyledTextCtrl::SaveFile(const wxString& filename) |
507 | { | |
508 | wxFile file(filename, wxFile::write); | |
509 | ||
510 | if (!file.IsOpened()) | |
dc8005e2 | 511 | return false; |
51566b0b | 512 | |
4a65f2c8 | 513 | bool success = file.Write(GetText(), *wxConvCurrent); |
51566b0b RD |
514 | |
515 | if (success) | |
516 | SetSavePoint(); | |
517 | ||
518 | return success; | |
519 | } | |
520 | ||
521 | bool wxStyledTextCtrl::LoadFile(const wxString& filename) | |
522 | { | |
041973c5 | 523 | bool success = false; |
51566b0b RD |
524 | wxFile file(filename, wxFile::read); |
525 | ||
041973c5 | 526 | if (file.IsOpened()) |
51566b0b | 527 | { |
041973c5 | 528 | wxString contents; |
a5b274d7 WS |
529 | // get the file size (assume it is not huge file...) |
530 | ssize_t len = (ssize_t)file.Length(); | |
531 | ||
041973c5 RD |
532 | if (len > 0) |
533 | { | |
1e545382 | 534 | #if wxUSE_UNICODE |
1c26fbe0 | 535 | wxMemoryBuffer buffer(len+1); |
8e5ec9cc | 536 | success = (file.Read(buffer.GetData(), len) == len); |
dc8005e2 | 537 | if (success) { |
9efe0302 RD |
538 | ((char*)buffer.GetData())[len] = 0; |
539 | contents = wxString(buffer, *wxConvCurrent, len); | |
540 | } | |
4a65f2c8 | 541 | #else |
8e5ec9cc MB |
542 | wxString buffer; |
543 | success = (file.Read(wxStringBuffer(buffer, len), len) == len); | |
4a65f2c8 RD |
544 | contents = buffer; |
545 | #endif | |
041973c5 RD |
546 | } |
547 | else | |
a5b274d7 WS |
548 | { |
549 | if (len == 0) | |
550 | success = true; // empty file is ok | |
551 | else | |
552 | success = false; // len == wxInvalidOffset | |
553 | } | |
041973c5 RD |
554 | |
555 | if (success) | |
556 | { | |
557 | SetText(contents); | |
558 | EmptyUndoBuffer(); | |
559 | SetSavePoint(); | |
560 | } | |
51566b0b RD |
561 | } |
562 | ||
563 | return success; | |
564 | } | |
565 | ||
f97d84a6 | 566 | |
2fcce896 | 567 | #if wxUSE_DRAG_AND_DROP |
dc8005e2 RD |
568 | wxDragResult wxStyledTextCtrl::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) { |
569 | return m_swx->DoDragOver(x, y, def); | |
570 | } | |
4a65f2c8 RD |
571 | |
572 | ||
dc8005e2 | 573 | bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) { |
4a65f2c8 RD |
574 | return m_swx->DoDropText(x, y, data); |
575 | } | |
2fcce896 | 576 | #endif |
4a65f2c8 RD |
577 | |
578 | ||
d1558f3d RD |
579 | void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA) { |
580 | m_swx->SetUseAntiAliasing(useAA); | |
581 | } | |
582 | ||
583 | bool wxStyledTextCtrl::GetUseAntiAliasing() { | |
584 | return m_swx->GetUseAntiAliasing(); | |
585 | } | |
586 | ||
41a499cd RD |
587 | |
588 | ||
589 | ||
590 | ||
591 | void wxStyledTextCtrl::AddTextRaw(const char* text) | |
592 | { | |
593 | SendMsg(SCI_ADDTEXT, strlen(text), (long)text); | |
594 | } | |
595 | ||
596 | void wxStyledTextCtrl::InsertTextRaw(int pos, const char* text) | |
597 | { | |
598 | SendMsg(SCI_INSERTTEXT, pos, (long)text); | |
599 | } | |
600 | ||
601 | wxCharBuffer wxStyledTextCtrl::GetCurLineRaw(int* linePos) | |
602 | { | |
603 | int len = LineLength(GetCurrentLine()); | |
604 | if (!len) { | |
605 | if (linePos) *linePos = 0; | |
606 | wxCharBuffer empty; | |
607 | return empty; | |
608 | } | |
609 | ||
610 | wxCharBuffer buf(len); | |
611 | int pos = SendMsg(SCI_GETCURLINE, len, (long)buf.data()); | |
612 | if (linePos) *linePos = pos; | |
613 | return buf; | |
614 | } | |
615 | ||
616 | wxCharBuffer wxStyledTextCtrl::GetLineRaw(int line) | |
617 | { | |
618 | int len = LineLength(line); | |
619 | if (!len) { | |
620 | wxCharBuffer empty; | |
621 | return empty; | |
622 | } | |
623 | ||
624 | wxCharBuffer buf(len); | |
625 | SendMsg(SCI_GETLINE, line, (long)buf.data()); | |
626 | return buf; | |
627 | } | |
628 | ||
629 | wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw() | |
630 | { | |
631 | int start; | |
632 | int end; | |
633 | ||
634 | GetSelection(&start, &end); | |
635 | int len = end - start; | |
636 | if (!len) { | |
637 | wxCharBuffer empty; | |
638 | return empty; | |
7e0c58e9 | 639 | } |
41a499cd RD |
640 | |
641 | wxCharBuffer buf(len); | |
642 | SendMsg(SCI_GETSELTEXT, 0, (long)buf.data()); | |
643 | return buf; | |
644 | } | |
645 | ||
646 | wxCharBuffer wxStyledTextCtrl::GetTextRangeRaw(int startPos, int endPos) | |
647 | { | |
648 | if (endPos < startPos) { | |
649 | int temp = startPos; | |
650 | startPos = endPos; | |
651 | endPos = temp; | |
652 | } | |
653 | int len = endPos - startPos; | |
654 | if (!len) { | |
655 | wxCharBuffer empty; | |
656 | return empty; | |
7e0c58e9 | 657 | } |
41a499cd RD |
658 | |
659 | wxCharBuffer buf(len); | |
660 | TextRange tr; | |
661 | tr.lpstrText = buf.data(); | |
662 | tr.chrg.cpMin = startPos; | |
663 | tr.chrg.cpMax = endPos; | |
664 | SendMsg(SCI_GETTEXTRANGE, 0, (long)&tr); | |
665 | return buf; | |
666 | } | |
667 | ||
668 | void wxStyledTextCtrl::SetTextRaw(const char* text) | |
669 | { | |
670 | SendMsg(SCI_SETTEXT, 0, (long)text); | |
671 | } | |
672 | ||
673 | wxCharBuffer wxStyledTextCtrl::GetTextRaw() | |
674 | { | |
675 | int len = GetTextLength(); | |
676 | wxCharBuffer buf(len); | |
677 | SendMsg(SCI_GETTEXT, len, (long)buf.data()); | |
678 | return buf; | |
679 | } | |
680 | ||
681 | void wxStyledTextCtrl::AppendTextRaw(const char* text) | |
682 | { | |
683 | SendMsg(SCI_APPENDTEXT, strlen(text), (long)text); | |
684 | } | |
685 | ||
686 | ||
687 | ||
688 | ||
689 | ||
f97d84a6 RD |
690 | //---------------------------------------------------------------------- |
691 | // Event handlers | |
692 | ||
88a8b04e | 693 | void wxStyledTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(evt)) { |
f97d84a6 | 694 | wxPaintDC dc(this); |
9e730a78 | 695 | m_swx->DoPaint(&dc, GetUpdateRegion().GetBox()); |
f97d84a6 RD |
696 | } |
697 | ||
698 | void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent& evt) { | |
699 | if (evt.GetOrientation() == wxHORIZONTAL) | |
700 | m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition()); | |
701 | else | |
702 | m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition()); | |
703 | } | |
704 | ||
5fa4613c RD |
705 | void wxStyledTextCtrl::OnScroll(wxScrollEvent& evt) { |
706 | wxScrollBar* sb = wxDynamicCast(evt.GetEventObject(), wxScrollBar); | |
707 | if (sb) { | |
708 | if (sb->IsVertical()) | |
709 | m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition()); | |
710 | else | |
711 | m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition()); | |
712 | } | |
713 | } | |
714 | ||
88a8b04e | 715 | void wxStyledTextCtrl::OnSize(wxSizeEvent& WXUNUSED(evt)) { |
39c0acb6 RD |
716 | if (m_swx) { |
717 | wxSize sz = GetClientSize(); | |
718 | m_swx->DoSize(sz.x, sz.y); | |
719 | } | |
f97d84a6 RD |
720 | } |
721 | ||
722 | void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) { | |
cb1871ca | 723 | SetFocus(); |
f97d84a6 | 724 | wxPoint pt = evt.GetPosition(); |
2b5f62a0 | 725 | m_swx->DoLeftButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(), |
f97d84a6 RD |
726 | evt.ShiftDown(), evt.ControlDown(), evt.AltDown()); |
727 | } | |
728 | ||
729 | void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) { | |
730 | wxPoint pt = evt.GetPosition(); | |
2b5f62a0 | 731 | m_swx->DoLeftButtonMove(Point(pt.x, pt.y)); |
f97d84a6 RD |
732 | } |
733 | ||
734 | void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) { | |
735 | wxPoint pt = evt.GetPosition(); | |
2b5f62a0 | 736 | m_swx->DoLeftButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(), |
f97d84a6 RD |
737 | evt.ControlDown()); |
738 | } | |
739 | ||
740 | ||
ddf2da08 RD |
741 | void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) { |
742 | wxPoint pt = evt.GetPosition(); | |
743 | m_swx->DoContextMenu(Point(pt.x, pt.y)); | |
744 | } | |
745 | ||
746 | ||
2b5f62a0 VZ |
747 | void wxStyledTextCtrl::OnMouseMiddleUp(wxMouseEvent& evt) { |
748 | wxPoint pt = evt.GetPosition(); | |
749 | m_swx->DoMiddleButtonUp(Point(pt.x, pt.y)); | |
750 | } | |
751 | ||
65ec6247 | 752 | void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) { |
f97d84a6 | 753 | wxPoint pt = evt.GetPosition(); |
65ec6247 | 754 | ScreenToClient(&pt.x, &pt.y); |
25484746 RD |
755 | /* |
756 | Show context menu at event point if it's within the window, | |
757 | or at caret location if not | |
758 | */ | |
759 | wxHitTest ht = this->HitTest(pt); | |
760 | if (ht != wxHT_WINDOW_INSIDE) { | |
761 | pt = this->PointFromPosition(this->GetCurrentPos()); | |
762 | } | |
f97d84a6 RD |
763 | m_swx->DoContextMenu(Point(pt.x, pt.y)); |
764 | } | |
765 | ||
37d62433 RD |
766 | |
767 | void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { | |
768 | m_swx->DoMouseWheel(evt.GetWheelRotation(), | |
769 | evt.GetWheelDelta(), | |
65ec6247 | 770 | evt.GetLinesPerAction(), |
9b9337da RD |
771 | evt.ControlDown(), |
772 | evt.IsPageScroll()); | |
37d62433 RD |
773 | } |
774 | ||
775 | ||
f97d84a6 | 776 | void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { |
5fd656d5 | 777 | // On (some?) non-US PC keyboards the AltGr key is required to enter some |
f3c2c221 RD |
778 | // common characters. It comes to us as both Alt and Ctrl down so we need |
779 | // to let the char through in that case, otherwise if only ctrl or only | |
780 | // alt let's skip it. | |
781 | bool ctrl = evt.ControlDown(); | |
28e0c28e RD |
782 | #ifdef __WXMAC__ |
783 | // On the Mac the Alt key is just a modifier key (like Shift) so we need | |
784 | // to allow the char events to be processed when Alt is pressed. | |
785 | // TODO: Should we check MetaDown instead in this case? | |
786 | bool alt = false; | |
787 | #else | |
f3c2c221 | 788 | bool alt = evt.AltDown(); |
28e0c28e | 789 | #endif |
00c64037 | 790 | bool skip = ((ctrl || alt) && ! (ctrl && alt)); |
f3c2c221 | 791 | |
4358b585 VZ |
792 | #if wxUSE_UNICODE |
793 | // apparently if we don't do this, Unicode keys pressed after non-char | |
794 | // ASCII ones (e.g. Enter, Tab) are not taken into account (patch 1615989) | |
795 | if (m_lastKeyDownConsumed && evt.GetUnicodeKey() > 255) | |
796 | m_lastKeyDownConsumed = false; | |
797 | #endif | |
798 | ||
5fd656d5 RD |
799 | if (!m_lastKeyDownConsumed && !skip) { |
800 | #if wxUSE_UNICODE | |
801 | int key = evt.GetUnicodeKey(); | |
802 | bool keyOk = true; | |
803 | ||
804 | // if the unicode key code is not really a unicode character (it may | |
805 | // be a function key or etc., the platforms appear to always give us a | |
806 | // small value in this case) then fallback to the ascii key code but | |
807 | // don't do anything for function keys or etc. | |
1b14227e | 808 | if (key <= 127) { |
5fd656d5 | 809 | key = evt.GetKeyCode(); |
1b14227e | 810 | keyOk = (key <= 127); |
5fd656d5 RD |
811 | } |
812 | if (keyOk) { | |
813 | m_swx->DoAddChar(key); | |
814 | return; | |
815 | } | |
816 | #else | |
817 | int key = evt.GetKeyCode(); | |
818 | if (key <= WXK_START || key > WXK_COMMAND) { | |
819 | m_swx->DoAddChar(key); | |
820 | return; | |
821 | } | |
822 | #endif | |
f97d84a6 | 823 | } |
7e0c58e9 | 824 | |
f3c2c221 | 825 | evt.Skip(); |
f97d84a6 RD |
826 | } |
827 | ||
d6582821 | 828 | |
f97d84a6 | 829 | void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { |
5fd656d5 | 830 | int processed = m_swx->DoKeyDown(evt, &m_lastKeyDownConsumed); |
d6582821 | 831 | if (!processed && !m_lastKeyDownConsumed) |
f97d84a6 RD |
832 | evt.Skip(); |
833 | } | |
834 | ||
d6582821 | 835 | |
b6bfd8e8 | 836 | void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent& evt) { |
ec830416 | 837 | m_swx->DoLoseFocus(); |
b6bfd8e8 | 838 | evt.Skip(); |
f97d84a6 RD |
839 | } |
840 | ||
d6582821 | 841 | |
b6bfd8e8 | 842 | void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { |
f97d84a6 | 843 | m_swx->DoGainFocus(); |
b6bfd8e8 | 844 | evt.Skip(); |
f97d84a6 RD |
845 | } |
846 | ||
d6582821 | 847 | |
88a8b04e | 848 | void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(evt)) { |
f97d84a6 RD |
849 | m_swx->DoSysColourChange(); |
850 | } | |
851 | ||
d6582821 | 852 | |
88a8b04e | 853 | void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent& WXUNUSED(evt)) { |
f97d84a6 RD |
854 | // do nothing to help avoid flashing |
855 | } | |
856 | ||
857 | ||
858 | ||
859 | void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) { | |
860 | m_swx->DoCommand(evt.GetId()); | |
861 | } | |
862 | ||
863 | ||
88a8b04e | 864 | void wxStyledTextCtrl::OnListBox(wxCommandEvent& WXUNUSED(evt)) { |
f97d84a6 RD |
865 | m_swx->DoOnListBox(); |
866 | } | |
867 | ||
868 | ||
8e54aaed RD |
869 | void wxStyledTextCtrl::OnIdle(wxIdleEvent& evt) { |
870 | m_swx->DoOnIdle(evt); | |
871 | } | |
872 | ||
873 | ||
8ae4f086 RD |
874 | wxSize wxStyledTextCtrl::DoGetBestSize() const |
875 | { | |
876 | // What would be the best size for a wxSTC? | |
877 | // Just give a reasonable minimum until something else can be figured out. | |
878 | return wxSize(200,100); | |
879 | } | |
880 | ||
881 | ||
f97d84a6 RD |
882 | //---------------------------------------------------------------------- |
883 | // Turn notifications from Scintilla into events | |
884 | ||
885 | ||
886 | void wxStyledTextCtrl::NotifyChange() { | |
887 | wxStyledTextEvent evt(wxEVT_STC_CHANGE, GetId()); | |
a29a241f | 888 | evt.SetEventObject(this); |
f97d84a6 RD |
889 | GetEventHandler()->ProcessEvent(evt); |
890 | } | |
891 | ||
2b5f62a0 VZ |
892 | |
893 | static void SetEventText(wxStyledTextEvent& evt, const char* text, | |
894 | size_t length) { | |
895 | if(!text) return; | |
896 | ||
1c930beb | 897 | evt.SetText(stc2wx(text, length)); |
2b5f62a0 VZ |
898 | } |
899 | ||
900 | ||
f97d84a6 RD |
901 | void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { |
902 | SCNotification& scn = *_scn; | |
65ec6247 RD |
903 | wxStyledTextEvent evt(0, GetId()); |
904 | ||
a29a241f | 905 | evt.SetEventObject(this); |
65ec6247 RD |
906 | evt.SetPosition(scn.position); |
907 | evt.SetKey(scn.ch); | |
908 | evt.SetModifiers(scn.modifiers); | |
909 | ||
f97d84a6 RD |
910 | switch (scn.nmhdr.code) { |
911 | case SCN_STYLENEEDED: | |
65ec6247 | 912 | evt.SetEventType(wxEVT_STC_STYLENEEDED); |
f97d84a6 | 913 | break; |
65ec6247 | 914 | |
f97d84a6 | 915 | case SCN_CHARADDED: |
65ec6247 | 916 | evt.SetEventType(wxEVT_STC_CHARADDED); |
f97d84a6 | 917 | break; |
65ec6247 | 918 | |
f97d84a6 | 919 | case SCN_SAVEPOINTREACHED: |
65ec6247 | 920 | evt.SetEventType(wxEVT_STC_SAVEPOINTREACHED); |
f97d84a6 | 921 | break; |
65ec6247 | 922 | |
f97d84a6 | 923 | case SCN_SAVEPOINTLEFT: |
65ec6247 | 924 | evt.SetEventType(wxEVT_STC_SAVEPOINTLEFT); |
f97d84a6 | 925 | break; |
65ec6247 | 926 | |
f97d84a6 | 927 | case SCN_MODIFYATTEMPTRO: |
65ec6247 RD |
928 | evt.SetEventType(wxEVT_STC_ROMODIFYATTEMPT); |
929 | break; | |
930 | ||
931 | case SCN_KEY: | |
932 | evt.SetEventType(wxEVT_STC_KEY); | |
f97d84a6 | 933 | break; |
65ec6247 | 934 | |
f97d84a6 | 935 | case SCN_DOUBLECLICK: |
65ec6247 | 936 | evt.SetEventType(wxEVT_STC_DOUBLECLICK); |
f97d84a6 | 937 | break; |
65ec6247 RD |
938 | |
939 | case SCN_UPDATEUI: | |
940 | evt.SetEventType(wxEVT_STC_UPDATEUI); | |
f97d84a6 | 941 | break; |
65ec6247 RD |
942 | |
943 | case SCN_MODIFIED: | |
944 | evt.SetEventType(wxEVT_STC_MODIFIED); | |
945 | evt.SetModificationType(scn.modificationType); | |
2b5f62a0 | 946 | SetEventText(evt, scn.text, scn.length); |
65ec6247 RD |
947 | evt.SetLength(scn.length); |
948 | evt.SetLinesAdded(scn.linesAdded); | |
949 | evt.SetLine(scn.line); | |
950 | evt.SetFoldLevelNow(scn.foldLevelNow); | |
951 | evt.SetFoldLevelPrev(scn.foldLevelPrev); | |
f97d84a6 | 952 | break; |
65ec6247 | 953 | |
f97d84a6 | 954 | case SCN_MACRORECORD: |
65ec6247 RD |
955 | evt.SetEventType(wxEVT_STC_MACRORECORD); |
956 | evt.SetMessage(scn.message); | |
957 | evt.SetWParam(scn.wParam); | |
958 | evt.SetLParam(scn.lParam); | |
f97d84a6 | 959 | break; |
65ec6247 | 960 | |
f97d84a6 | 961 | case SCN_MARGINCLICK: |
65ec6247 RD |
962 | evt.SetEventType(wxEVT_STC_MARGINCLICK); |
963 | evt.SetMargin(scn.margin); | |
f97d84a6 | 964 | break; |
65ec6247 | 965 | |
f97d84a6 | 966 | case SCN_NEEDSHOWN: |
65ec6247 RD |
967 | evt.SetEventType(wxEVT_STC_NEEDSHOWN); |
968 | evt.SetLength(scn.length); | |
f97d84a6 | 969 | break; |
65ec6247 | 970 | |
65ec6247 RD |
971 | case SCN_PAINTED: |
972 | evt.SetEventType(wxEVT_STC_PAINTED); | |
973 | break; | |
974 | ||
0daf5e6b RD |
975 | case SCN_AUTOCSELECTION: |
976 | evt.SetEventType(wxEVT_STC_AUTOCOMP_SELECTION); | |
977 | evt.SetListType(scn.listType); | |
978 | SetEventText(evt, scn.text, strlen(scn.text)); | |
979 | evt.SetPosition(scn.lParam); | |
980 | break; | |
7e0c58e9 | 981 | |
65ec6247 RD |
982 | case SCN_USERLISTSELECTION: |
983 | evt.SetEventType(wxEVT_STC_USERLISTSELECTION); | |
984 | evt.SetListType(scn.listType); | |
2b5f62a0 | 985 | SetEventText(evt, scn.text, strlen(scn.text)); |
0daf5e6b | 986 | evt.SetPosition(scn.lParam); |
f97d84a6 | 987 | break; |
f97d84a6 | 988 | |
65ec6247 RD |
989 | case SCN_URIDROPPED: |
990 | evt.SetEventType(wxEVT_STC_URIDROPPED); | |
2b5f62a0 | 991 | SetEventText(evt, scn.text, strlen(scn.text)); |
65ec6247 RD |
992 | break; |
993 | ||
994 | case SCN_DWELLSTART: | |
995 | evt.SetEventType(wxEVT_STC_DWELLSTART); | |
996 | evt.SetX(scn.x); | |
997 | evt.SetY(scn.y); | |
998 | break; | |
999 | ||
1000 | case SCN_DWELLEND: | |
1001 | evt.SetEventType(wxEVT_STC_DWELLEND); | |
1002 | evt.SetX(scn.x); | |
1003 | evt.SetY(scn.y); | |
1004 | break; | |
1005 | ||
a834585d RD |
1006 | case SCN_ZOOM: |
1007 | evt.SetEventType(wxEVT_STC_ZOOM); | |
1008 | break; | |
1009 | ||
9e730a78 RD |
1010 | case SCN_HOTSPOTCLICK: |
1011 | evt.SetEventType(wxEVT_STC_HOTSPOT_CLICK); | |
1012 | break; | |
1013 | ||
1014 | case SCN_HOTSPOTDOUBLECLICK: | |
1015 | evt.SetEventType(wxEVT_STC_HOTSPOT_DCLICK); | |
1016 | break; | |
1017 | ||
1018 | case SCN_CALLTIPCLICK: | |
1019 | evt.SetEventType(wxEVT_STC_CALLTIP_CLICK); | |
1020 | break; | |
7e0c58e9 RD |
1021 | |
1022 | case SCN_INDICATORCLICK: | |
1023 | evt.SetEventType(wxEVT_STC_INDICATOR_CLICK); | |
1024 | break; | |
1025 | ||
1026 | case SCN_INDICATORRELEASE: | |
1027 | evt.SetEventType(wxEVT_STC_INDICATOR_RELEASE); | |
1028 | break; | |
1029 | ||
65ec6247 RD |
1030 | default: |
1031 | return; | |
f97d84a6 | 1032 | } |
65ec6247 RD |
1033 | |
1034 | GetEventHandler()->ProcessEvent(evt); | |
f97d84a6 RD |
1035 | } |
1036 | ||
1037 | ||
f97d84a6 RD |
1038 | //---------------------------------------------------------------------- |
1039 | //---------------------------------------------------------------------- | |
1040 | //---------------------------------------------------------------------- | |
1041 | ||
1042 | wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id) | |
1043 | : wxCommandEvent(commandType, id) | |
1044 | { | |
1045 | m_position = 0; | |
1046 | m_key = 0; | |
1047 | m_modifiers = 0; | |
1048 | m_modificationType = 0; | |
1049 | m_length = 0; | |
1050 | m_linesAdded = 0; | |
1051 | m_line = 0; | |
1052 | m_foldLevelNow = 0; | |
1053 | m_foldLevelPrev = 0; | |
1054 | m_margin = 0; | |
1055 | m_message = 0; | |
1056 | m_wParam = 0; | |
1057 | m_lParam = 0; | |
65ec6247 RD |
1058 | m_listType = 0; |
1059 | m_x = 0; | |
1060 | m_y = 0; | |
dc8005e2 | 1061 | m_dragAllowMove = false; |
92bbd64f | 1062 | #if wxUSE_DRAG_AND_DROP |
a29a241f | 1063 | m_dragResult = wxDragNone; |
92bbd64f | 1064 | #endif |
f97d84a6 RD |
1065 | } |
1066 | ||
1067 | bool wxStyledTextEvent::GetShift() const { return (m_modifiers & SCI_SHIFT) != 0; } | |
1068 | bool wxStyledTextEvent::GetControl() const { return (m_modifiers & SCI_CTRL) != 0; } | |
1069 | bool wxStyledTextEvent::GetAlt() const { return (m_modifiers & SCI_ALT) != 0; } | |
1070 | ||
f97d84a6 | 1071 | |
5fa4613c RD |
1072 | wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent& event): |
1073 | wxCommandEvent(event) | |
1074 | { | |
1075 | m_position = event.m_position; | |
1076 | m_key = event.m_key; | |
1077 | m_modifiers = event.m_modifiers; | |
1078 | m_modificationType = event.m_modificationType; | |
1079 | m_text = event.m_text; | |
1080 | m_length = event.m_length; | |
1081 | m_linesAdded = event.m_linesAdded; | |
1082 | m_line = event.m_line; | |
1083 | m_foldLevelNow = event.m_foldLevelNow; | |
1084 | m_foldLevelPrev = event.m_foldLevelPrev; | |
1085 | ||
1086 | m_margin = event.m_margin; | |
1087 | ||
1088 | m_message = event.m_message; | |
1089 | m_wParam = event.m_wParam; | |
1090 | m_lParam = event.m_lParam; | |
1091 | ||
1092 | m_listType = event.m_listType; | |
1093 | m_x = event.m_x; | |
1094 | m_y = event.m_y; | |
f97d84a6 | 1095 | |
5fa4613c RD |
1096 | m_dragText = event.m_dragText; |
1097 | m_dragAllowMove =event.m_dragAllowMove; | |
92bbd64f | 1098 | #if wxUSE_DRAG_AND_DROP |
5fa4613c | 1099 | m_dragResult = event.m_dragResult; |
92bbd64f | 1100 | #endif |
f97d84a6 RD |
1101 | } |
1102 | ||
1103 | //---------------------------------------------------------------------- | |
1104 | //---------------------------------------------------------------------- | |
1105 | ||
29825f5f | 1106 | #endif // wxUSE_STC |