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