]>
Commit | Line | Data |
---|---|---|
9ce192d4 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 | |
f6bcfd97 | 8 | // namespace with all the classes and identifiers from Scintilla. |
9ce192d4 RD |
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 | ||
f6bcfd97 BP |
18 | #include <ctype.h> |
19 | ||
9ce192d4 RD |
20 | #include "wx/stc/stc.h" |
21 | #include "ScintillaWX.h" | |
22 | ||
23 | #include <wx/tokenzr.h> | |
24 | ||
f6bcfd97 BP |
25 | // The following code forces a reference to all of the Scintilla lexers. |
26 | // If we don't do something like this, then the linker tends to "optimize" | |
27 | // them away. (eric@sourcegear.com) | |
28 | ||
d134f170 | 29 | static int wxForceScintillaLexers(void) |
f6bcfd97 BP |
30 | { |
31 | extern LexerModule lmCPP; | |
32 | extern LexerModule lmHTML; | |
33 | extern LexerModule lmXML; | |
34 | extern LexerModule lmProps; | |
35 | extern LexerModule lmErrorList; | |
36 | extern LexerModule lmMake; | |
37 | extern LexerModule lmBatch; | |
38 | extern LexerModule lmPerl; | |
39 | extern LexerModule lmPython; | |
40 | extern LexerModule lmSQL; | |
41 | extern LexerModule lmVB; | |
d134f170 | 42 | extern LexerModule lmLua; |
f6bcfd97 BP |
43 | |
44 | if ( | |
45 | &lmCPP | |
46 | && &lmHTML | |
47 | && &lmXML | |
48 | && &lmProps | |
49 | && &lmErrorList | |
50 | && &lmMake | |
51 | && &lmBatch | |
52 | && &lmPerl | |
53 | && &lmPython | |
54 | && &lmSQL | |
55 | && &lmVB | |
d134f170 | 56 | && &lmLua |
f6bcfd97 BP |
57 | ) |
58 | { | |
59 | return 1; | |
60 | } | |
f6bcfd97 BP |
61 | } |
62 | ||
9ce192d4 RD |
63 | //---------------------------------------------------------------------- |
64 | ||
65 | const wxChar* wxSTCNameStr = "stcwindow"; | |
66 | ||
67 | BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) | |
68 | EVT_PAINT (wxStyledTextCtrl::OnPaint) | |
69 | EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin) | |
70 | EVT_SIZE (wxStyledTextCtrl::OnSize) | |
71 | EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown) | |
72 | EVT_MOTION (wxStyledTextCtrl::OnMouseMove) | |
73 | EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) | |
74 | EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) | |
75 | EVT_CHAR (wxStyledTextCtrl::OnChar) | |
f6bcfd97 | 76 | EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) |
9ce192d4 RD |
77 | EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) |
78 | EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus) | |
79 | EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged) | |
80 | EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground) | |
81 | EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu) | |
f6bcfd97 | 82 | EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox) |
9ce192d4 RD |
83 | END_EVENT_TABLE() |
84 | ||
f6bcfd97 BP |
85 | |
86 | IMPLEMENT_CLASS(wxStyledTextCtrl, wxControl) | |
87 | IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent, wxCommandEvent) | |
88 | ||
9ce192d4 RD |
89 | //---------------------------------------------------------------------- |
90 | // Constructor and Destructor | |
91 | ||
92 | wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent, | |
93 | wxWindowID id, | |
94 | const wxPoint& pos, | |
95 | const wxSize& size, | |
96 | long style, | |
97 | const wxString& name) : | |
98 | wxControl(parent, id, pos, size, | |
99 | style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS, | |
100 | wxDefaultValidator, name) | |
101 | { | |
102 | m_swx = new ScintillaWX(this); | |
103 | // m_keywords = new WordList; | |
104 | m_stopWatch.Start(); | |
105 | m_readOnly = false; | |
106 | m_undoType = wxSTC_UndoCollectAutoStart; | |
107 | } | |
108 | ||
109 | ||
110 | wxStyledTextCtrl::~wxStyledTextCtrl() { | |
111 | delete m_swx; | |
112 | // delete m_keywords; | |
113 | } | |
114 | ||
115 | ||
116 | //---------------------------------------------------------------------- | |
117 | ||
f6bcfd97 | 118 | long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) { |
9ce192d4 RD |
119 | |
120 | return m_swx->WndProc(msg, wp, lp); | |
121 | } | |
122 | ||
123 | ||
124 | //---------------------------------------------------------------------- | |
125 | // Text retrieval and modification | |
126 | ||
127 | wxString wxStyledTextCtrl::GetText() { | |
128 | wxString text; | |
129 | int len = GetTextLength(); | |
f6bcfd97 | 130 | char* buff = text.GetWriteBuf(len+1); |
9ce192d4 | 131 | |
d134f170 | 132 | SendMsg(SCI_GETTEXT, len, (long)buff); |
f6bcfd97 | 133 | buff[len] = 0; |
9ce192d4 RD |
134 | text.UngetWriteBuf(); |
135 | return text; | |
136 | } | |
137 | ||
138 | ||
139 | bool wxStyledTextCtrl::SetText(const wxString& text) { | |
d134f170 | 140 | return SendMsg(SCI_SETTEXT, 0, (long)text.c_str()) != 0; |
9ce192d4 RD |
141 | } |
142 | ||
143 | ||
144 | wxString wxStyledTextCtrl::GetLine(int line) { | |
145 | wxString text; | |
146 | int len = GetLineLength(line); | |
147 | char* buff = text.GetWriteBuf(len+1); | |
148 | ||
d134f170 | 149 | SendMsg(SCI_GETLINE, line, (long)buff); |
f6bcfd97 | 150 | buff[len] = 0; |
9ce192d4 RD |
151 | text.UngetWriteBuf(); |
152 | return text; | |
153 | } | |
154 | ||
155 | ||
156 | void wxStyledTextCtrl::ReplaceSelection(const wxString& text) { | |
d134f170 | 157 | SendMsg(SCI_REPLACESEL, 0, (long)text.c_str()); |
9ce192d4 RD |
158 | } |
159 | ||
160 | ||
161 | void wxStyledTextCtrl::SetReadOnly(bool readOnly) { | |
d134f170 | 162 | SendMsg(SCI_SETREADONLY, (long)readOnly); |
9ce192d4 RD |
163 | m_readOnly = readOnly; |
164 | } | |
165 | ||
166 | ||
167 | bool wxStyledTextCtrl::GetReadOnly() { | |
168 | // TODO: need support in Scintilla to do this right, | |
169 | // until then we'll track it ourselves | |
170 | return m_readOnly; | |
171 | } | |
172 | ||
173 | ||
174 | void wxStyledTextCtrl::GetTextRange(int startPos, int endPos, char* buff) { | |
d134f170 | 175 | TextRange tr; |
9ce192d4 RD |
176 | tr.lpstrText = buff; |
177 | tr.chrg.cpMin = startPos; | |
178 | tr.chrg.cpMax = endPos; | |
d134f170 | 179 | SendMsg(SCI_GETTEXTRANGE, 0, (long)&tr); |
9ce192d4 RD |
180 | } |
181 | ||
182 | ||
183 | wxString wxStyledTextCtrl::GetTextRange(int startPos, int endPos) { | |
184 | wxString text; | |
185 | int len = endPos - startPos; | |
d134f170 | 186 | char* buff = text.GetWriteBuf(len+1); |
9ce192d4 RD |
187 | GetTextRange(startPos, endPos, buff); |
188 | text.UngetWriteBuf(); | |
189 | return text; | |
190 | } | |
191 | ||
192 | ||
193 | void wxStyledTextCtrl::GetStyledTextRange(int startPos, int endPos, char* buff) { | |
d134f170 | 194 | TextRange tr; |
9ce192d4 RD |
195 | tr.lpstrText = buff; |
196 | tr.chrg.cpMin = startPos; | |
197 | tr.chrg.cpMax = endPos; | |
198 | SendMsg(SCI_GETSTYLEDTEXT, 0, (long)&tr); | |
199 | } | |
200 | ||
201 | ||
202 | wxString wxStyledTextCtrl::GetStyledTextRange(int startPos, int endPos) { | |
203 | wxString text; | |
204 | int len = endPos - startPos; | |
d134f170 | 205 | char* buff = text.GetWriteBuf(len*2+1); |
9ce192d4 RD |
206 | GetStyledTextRange(startPos, endPos, buff); |
207 | text.UngetWriteBuf(len*2); | |
208 | return text; | |
209 | } | |
210 | ||
211 | ||
212 | void wxStyledTextCtrl::AddText(const wxString& text) { | |
213 | SendMsg(SCI_ADDTEXT, text.Len(), (long)text.c_str()); | |
214 | } | |
215 | ||
216 | ||
217 | void wxStyledTextCtrl::AddStyledText(const wxString& text) { | |
218 | SendMsg(SCI_ADDSTYLEDTEXT, text.Len(), (long)text.c_str()); | |
219 | } | |
220 | ||
221 | ||
222 | void wxStyledTextCtrl::InsertText(int pos, const wxString& text) { | |
223 | SendMsg(SCI_INSERTTEXT, pos, (long)text.c_str()); | |
224 | } | |
225 | ||
226 | ||
227 | void wxStyledTextCtrl::ClearAll() { | |
228 | SendMsg(SCI_CLEARALL); | |
229 | } | |
230 | ||
231 | ||
232 | char wxStyledTextCtrl::GetCharAt(int pos) { | |
233 | return SendMsg(SCI_GETCHARAT, pos); | |
234 | } | |
235 | ||
236 | ||
237 | char wxStyledTextCtrl::GetStyleAt(int pos) { | |
238 | return SendMsg(SCI_GETSTYLEAT, pos); | |
239 | } | |
240 | ||
241 | ||
242 | void wxStyledTextCtrl::SetStyleBits(int bits) { | |
243 | SendMsg(SCI_SETSTYLEBITS, bits); | |
244 | } | |
245 | ||
246 | ||
247 | int wxStyledTextCtrl::GetStyleBits() { | |
248 | return SendMsg(SCI_GETSTYLEBITS); | |
249 | } | |
250 | ||
251 | ||
252 | //---------------------------------------------------------------------- | |
253 | // Clipboard | |
254 | ||
255 | ||
256 | void wxStyledTextCtrl::Cut() { | |
d134f170 | 257 | SendMsg(SCI_CUT); |
9ce192d4 RD |
258 | } |
259 | ||
260 | ||
261 | void wxStyledTextCtrl::Copy() { | |
d134f170 | 262 | SendMsg(SCI_COPY); |
9ce192d4 RD |
263 | } |
264 | ||
265 | ||
266 | void wxStyledTextCtrl::Paste() { | |
d134f170 | 267 | SendMsg(SCI_PASTE); |
9ce192d4 RD |
268 | } |
269 | ||
270 | ||
271 | bool wxStyledTextCtrl::CanPaste() { | |
d134f170 | 272 | return SendMsg(SCI_CANPASTE) != 0; |
9ce192d4 RD |
273 | } |
274 | ||
275 | ||
276 | void wxStyledTextCtrl::ClearClipbrd() { | |
d134f170 | 277 | SendMsg(SCI_CLEAR); |
9ce192d4 RD |
278 | } |
279 | ||
280 | ||
281 | ||
282 | //---------------------------------------------------------------------- | |
283 | // Undo and Redo | |
284 | ||
285 | void wxStyledTextCtrl::Undo() { | |
d134f170 | 286 | SendMsg(SCI_UNDO); |
9ce192d4 RD |
287 | } |
288 | ||
289 | ||
290 | bool wxStyledTextCtrl::CanUndo() { | |
d134f170 | 291 | return SendMsg(SCI_CANUNDO) != 0; |
9ce192d4 RD |
292 | } |
293 | ||
294 | ||
295 | void wxStyledTextCtrl::EmptyUndoBuffer() { | |
d134f170 | 296 | SendMsg(SCI_EMPTYUNDOBUFFER); |
9ce192d4 RD |
297 | } |
298 | ||
299 | ||
300 | void wxStyledTextCtrl::Redo() { | |
301 | SendMsg(SCI_REDO); | |
302 | } | |
303 | ||
304 | ||
305 | bool wxStyledTextCtrl::CanRedo() { | |
306 | return SendMsg(SCI_CANREDO) != 0; | |
307 | } | |
308 | ||
309 | ||
310 | void wxStyledTextCtrl::SetUndoCollection(wxSTC_UndoType type) { | |
311 | SendMsg(SCI_SETUNDOCOLLECTION, type); | |
312 | m_undoType = type; | |
313 | } | |
314 | ||
315 | ||
316 | wxSTC_UndoType wxStyledTextCtrl::GetUndoCollection() { | |
317 | // TODO: need support in Scintilla to do this right, | |
318 | // until then we'll track it ourselves | |
319 | return m_undoType; | |
320 | } | |
321 | ||
322 | ||
323 | void wxStyledTextCtrl::BeginUndoAction() { | |
324 | SendMsg(SCI_BEGINUNDOACTION); | |
325 | } | |
326 | ||
327 | ||
328 | void wxStyledTextCtrl::EndUndoAction() { | |
329 | SendMsg(SCI_ENDUNDOACTION); | |
330 | } | |
331 | ||
332 | ||
333 | ||
334 | ||
335 | //---------------------------------------------------------------------- | |
336 | // Selection and information | |
337 | ||
338 | ||
339 | void wxStyledTextCtrl::GetSelection(int* startPos, int* endPos) { | |
d134f170 RD |
340 | // SendMsg(EM_GETSEL, (long)startPos, (long)endPos); |
341 | *startPos = SendMsg(SCI_GETSELECTIONSTART); | |
342 | *endPos = SendMsg(SCI_GETSELECTIONEND); | |
9ce192d4 RD |
343 | } |
344 | ||
345 | ||
346 | void wxStyledTextCtrl::SetSelection(int startPos, int endPos) { | |
d134f170 | 347 | SendMsg(SCI_SETSEL, startPos, endPos); |
9ce192d4 RD |
348 | } |
349 | ||
350 | ||
351 | wxString wxStyledTextCtrl::GetSelectedText() { | |
352 | wxString text; | |
353 | int start; | |
354 | int end; | |
355 | ||
356 | GetSelection(&start, &end); | |
357 | int len = end - start; | |
d134f170 | 358 | char* buff = text.GetWriteBuf(len+1); |
9ce192d4 | 359 | |
d134f170 | 360 | SendMsg(SCI_GETSELTEXT, 0, (long)buff); |
9ce192d4 RD |
361 | text.UngetWriteBuf(); |
362 | return text; | |
363 | } | |
364 | ||
365 | ||
366 | void wxStyledTextCtrl::HideSelection(bool hide) { | |
d134f170 | 367 | SendMsg(SCI_HIDESELECTION, hide); |
9ce192d4 RD |
368 | } |
369 | ||
370 | ||
371 | bool wxStyledTextCtrl::GetHideSelection() { | |
372 | return m_swx->GetHideSelection(); | |
373 | } | |
374 | ||
375 | ||
376 | int wxStyledTextCtrl::GetTextLength() { | |
d134f170 | 377 | return SendMsg(SCI_GETTEXTLENGTH); |
9ce192d4 RD |
378 | } |
379 | ||
380 | ||
381 | int wxStyledTextCtrl::GetFirstVisibleLine() { | |
d134f170 | 382 | return SendMsg(SCI_GETFIRSTVISIBLELINE); |
9ce192d4 RD |
383 | } |
384 | ||
385 | ||
386 | int wxStyledTextCtrl::GetLineCount() { | |
d134f170 | 387 | return SendMsg(SCI_GETLINECOUNT); |
9ce192d4 RD |
388 | } |
389 | ||
390 | ||
391 | bool wxStyledTextCtrl::GetModified() { | |
d134f170 | 392 | return SendMsg(SCI_GETMODIFY) != 0; |
9ce192d4 RD |
393 | } |
394 | ||
395 | ||
396 | int wxStyledTextCtrl::GetLineFromPos(int pos) { | |
d134f170 | 397 | return SendMsg(SCI_LINEFROMPOSITION, pos); |
9ce192d4 RD |
398 | } |
399 | ||
400 | ||
401 | int wxStyledTextCtrl::GetLineStartPos(int line) { | |
d134f170 | 402 | return SendMsg(SCI_POSITIONFROMLINE, line); |
9ce192d4 RD |
403 | } |
404 | ||
405 | ||
406 | int wxStyledTextCtrl::GetLineLength(int line) { | |
407 | return SendMsg(SCI_LINELENGTH, line); | |
408 | } | |
409 | ||
410 | ||
411 | int wxStyledTextCtrl::GetCurrentLine() { | |
412 | int line = GetLineFromPos(GetCurrentPos()); | |
413 | return line; | |
414 | } | |
415 | ||
416 | ||
417 | wxString wxStyledTextCtrl::GetCurrentLineText(int* linePos) { | |
418 | wxString text; | |
419 | int len = GetLineLength(GetCurrentLine()); | |
420 | char* buff = text.GetWriteBuf(len+1); | |
421 | ||
f6bcfd97 | 422 | int pos = SendMsg(SCI_GETCURLINE, len, (long)buff); |
9ce192d4 RD |
423 | text.UngetWriteBuf(); |
424 | ||
425 | if (linePos) | |
426 | *linePos = pos; | |
427 | ||
428 | return text; | |
429 | } | |
430 | ||
431 | ||
432 | int wxStyledTextCtrl::PositionFromPoint(wxPoint pt) { | |
d134f170 | 433 | return SendMsg(SCI_POSITIONFROMPOINT, pt.x, pt.y); |
9ce192d4 RD |
434 | } |
435 | ||
436 | ||
437 | wxPoint wxStyledTextCtrl::PointFromPosition(int pos) { | |
d134f170 RD |
438 | int x = SendMsg(SCI_POINTXFROMPOSITION, 0, pos); |
439 | int y = SendMsg(SCI_POINTYFROMPOSITION, 0, pos); | |
440 | return wxPoint(x, y); | |
9ce192d4 RD |
441 | } |
442 | ||
443 | ||
444 | int wxStyledTextCtrl::GetCurrentPos() { | |
445 | return SendMsg(SCI_GETCURRENTPOS); | |
446 | } | |
447 | ||
448 | ||
449 | int wxStyledTextCtrl::GetAnchor() { | |
450 | return SendMsg(SCI_GETANCHOR); | |
451 | } | |
452 | ||
453 | ||
454 | void wxStyledTextCtrl::SelectAll() { | |
455 | SendMsg(SCI_SELECTALL); | |
456 | } | |
457 | ||
458 | ||
459 | void wxStyledTextCtrl::SetCurrentPosition(int pos) { | |
460 | SendMsg(SCI_GOTOPOS, pos); | |
461 | } | |
462 | ||
463 | ||
464 | void wxStyledTextCtrl::SetAnchor(int pos) { | |
465 | SendMsg(SCI_SETANCHOR, pos); | |
466 | } | |
467 | ||
468 | ||
469 | void wxStyledTextCtrl::GotoPos(int pos) { | |
470 | SendMsg(SCI_GOTOPOS, pos); | |
471 | } | |
472 | ||
473 | ||
474 | void wxStyledTextCtrl::GotoLine(int line) { | |
475 | SendMsg(SCI_GOTOLINE, line); | |
476 | } | |
477 | ||
478 | ||
479 | void wxStyledTextCtrl::ChangePosition(int delta, bool extendSelection) { | |
480 | // TODO: Is documented but doesn't seem to be implemented | |
481 | //SendMsg(SCI_CHANGEPOSITION, delta, extendSelection); | |
482 | } | |
483 | ||
484 | ||
485 | void wxStyledTextCtrl::PageMove(int cmdKey, bool extendSelection) { | |
486 | // TODO: Is documented but doesn't seem to be implemented | |
487 | //SendMsg(SCI_PAGEMOVE, cmdKey, extendSelection); | |
488 | } | |
489 | ||
490 | ||
491 | void wxStyledTextCtrl::ScrollBy(int columnDelta, int lineDelta) { | |
d134f170 | 492 | SendMsg(SCI_LINESCROLL, columnDelta, lineDelta); |
9ce192d4 RD |
493 | } |
494 | ||
495 | void wxStyledTextCtrl::ScrollToLine(int line) { | |
496 | m_swx->DoScrollToLine(line); | |
497 | } | |
498 | ||
499 | ||
500 | void wxStyledTextCtrl::ScrollToColumn(int column) { | |
501 | m_swx->DoScrollToColumn(column); | |
502 | } | |
503 | ||
504 | ||
505 | void wxStyledTextCtrl::EnsureCaretVisible() { | |
d134f170 | 506 | SendMsg(SCI_SCROLLCARET); |
9ce192d4 RD |
507 | } |
508 | ||
509 | ||
510 | void wxStyledTextCtrl::SetCaretPolicy(int policy, int slop) { | |
511 | SendMsg(SCI_SETCARETPOLICY, policy, slop); | |
512 | } | |
513 | ||
514 | ||
f6bcfd97 BP |
515 | int wxStyledTextCtrl::GetLinesOnScreen() { |
516 | return SendMsg(SCI_LINESONSCREEN); | |
517 | } | |
518 | ||
519 | ||
520 | bool wxStyledTextCtrl::IsSelectionRectangle() { | |
521 | return SendMsg(SCI_SELECTIONISRECTANGLE) != 0; | |
522 | } | |
523 | ||
524 | ||
525 | void wxStyledTextCtrl::SetUseHorizontalScrollBar(bool use) { | |
526 | SendMsg(SCI_SETHSCROLLBAR, use); | |
527 | } | |
528 | ||
529 | ||
530 | bool wxStyledTextCtrl::GetUseHorizontalScrollBar() { | |
531 | return SendMsg(SCI_GETHSCROLLBAR) != 0; | |
532 | } | |
533 | ||
534 | ||
535 | ||
9ce192d4 RD |
536 | |
537 | ||
538 | //---------------------------------------------------------------------- | |
539 | // Searching | |
540 | ||
541 | int wxStyledTextCtrl::FindText(int minPos, int maxPos, | |
d134f170 RD |
542 | const wxString& text, |
543 | bool caseSensitive, bool wholeWord) { | |
544 | TextToFind ft; | |
9ce192d4 RD |
545 | int flags = 0; |
546 | ||
d134f170 RD |
547 | flags |= caseSensitive ? SCFIND_MATCHCASE : 0; |
548 | flags |= wholeWord ? SCFIND_WHOLEWORD : 0; | |
9ce192d4 RD |
549 | ft.chrg.cpMin = minPos; |
550 | ft.chrg.cpMax = maxPos; | |
551 | ft.lpstrText = (char*)text.c_str(); | |
552 | ||
d134f170 | 553 | return SendMsg(SCI_FINDTEXT, flags, (long)&ft); |
9ce192d4 RD |
554 | } |
555 | ||
556 | ||
557 | void wxStyledTextCtrl::SearchAnchor() { | |
558 | SendMsg(SCI_SEARCHANCHOR); | |
559 | } | |
560 | ||
561 | ||
562 | int wxStyledTextCtrl::SearchNext(const wxString& text, bool caseSensitive, bool wholeWord) { | |
563 | int flags = 0; | |
d134f170 RD |
564 | flags |= caseSensitive ? SCFIND_MATCHCASE : 0; |
565 | flags |= wholeWord ? SCFIND_WHOLEWORD : 0; | |
9ce192d4 RD |
566 | |
567 | return SendMsg(SCI_SEARCHNEXT, flags, (long)text.c_str()); | |
568 | } | |
569 | ||
570 | ||
571 | int wxStyledTextCtrl::SearchPrev(const wxString& text, bool caseSensitive, bool wholeWord) { | |
572 | int flags = 0; | |
d134f170 RD |
573 | flags |= caseSensitive ? SCFIND_MATCHCASE : 0; |
574 | flags |= wholeWord ? SCFIND_WHOLEWORD : 0; | |
9ce192d4 RD |
575 | |
576 | return SendMsg(SCI_SEARCHPREV, flags, (long)text.c_str()); | |
577 | } | |
578 | ||
579 | //---------------------------------------------------------------------- | |
580 | // Visible whitespace | |
581 | ||
582 | ||
583 | bool wxStyledTextCtrl::GetViewWhitespace() { | |
584 | return SendMsg(SCI_GETVIEWWS) != 0; | |
585 | } | |
586 | ||
587 | ||
588 | void wxStyledTextCtrl::SetViewWhitespace(bool visible) { | |
589 | SendMsg(SCI_SETVIEWWS, visible); | |
590 | } | |
591 | ||
592 | ||
593 | ||
594 | //---------------------------------------------------------------------- | |
595 | // Line endings | |
596 | ||
597 | wxSTC_EOL wxStyledTextCtrl::GetEOLMode() { | |
598 | return (wxSTC_EOL)SendMsg(SCI_GETEOLMODE); | |
599 | } | |
600 | ||
601 | ||
602 | void wxStyledTextCtrl::SetEOLMode(wxSTC_EOL mode) { | |
603 | SendMsg(SCI_SETEOLMODE, mode); | |
604 | } | |
605 | ||
606 | ||
607 | bool wxStyledTextCtrl::GetViewEOL() { | |
608 | return SendMsg(SCI_GETVIEWEOL) != 0; | |
609 | } | |
610 | ||
611 | ||
612 | void wxStyledTextCtrl::SetViewEOL(bool visible) { | |
613 | SendMsg(SCI_SETVIEWEOL, visible); | |
614 | } | |
615 | ||
616 | void wxStyledTextCtrl::ConvertEOL(wxSTC_EOL mode) { | |
617 | SendMsg(SCI_CONVERTEOLS, mode); | |
618 | } | |
619 | ||
620 | //---------------------------------------------------------------------- | |
621 | // Styling | |
622 | ||
623 | int wxStyledTextCtrl::GetEndStyled() { | |
624 | return SendMsg(SCI_GETENDSTYLED); | |
625 | } | |
626 | ||
627 | ||
628 | void wxStyledTextCtrl::StartStyling(int pos, int mask) { | |
629 | SendMsg(SCI_STARTSTYLING, pos, mask); | |
630 | } | |
631 | ||
632 | ||
633 | void wxStyledTextCtrl::SetStyleFor(int length, int style) { | |
634 | SendMsg(SCI_SETSTYLING, length, style); | |
635 | } | |
636 | ||
637 | ||
638 | void wxStyledTextCtrl::SetStyleBytes(int length, char* styleBytes) { | |
639 | SendMsg(SCI_SETSTYLINGEX, length, (long)styleBytes); | |
640 | } | |
641 | ||
642 | ||
f6bcfd97 BP |
643 | void wxStyledTextCtrl::SetLineState(int line, int value) { |
644 | SendMsg(SCI_SETLINESTATE, line, value); | |
645 | } | |
646 | ||
647 | ||
648 | int wxStyledTextCtrl::GetLineState(int line) { | |
649 | return SendMsg(SCI_GETLINESTATE, line); | |
650 | } | |
651 | ||
652 | ||
9ce192d4 RD |
653 | //---------------------------------------------------------------------- |
654 | // Style Definition | |
655 | ||
656 | ||
657 | static long wxColourAsLong(const wxColour& co) { | |
658 | return (((long)co.Blue() << 16) | | |
659 | ((long)co.Green() << 8) | | |
660 | ((long)co.Red())); | |
661 | } | |
662 | ||
663 | static wxColour wxColourFromLong(long c) { | |
664 | wxColour clr; | |
665 | clr.Set(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff); | |
666 | return clr; | |
667 | } | |
668 | ||
669 | ||
670 | static wxColour wxColourFromSpec(const wxString& spec) { | |
671 | // spec should be #RRGGBB | |
672 | char* junk; | |
673 | int red = strtol(spec.Mid(1,2), &junk, 16); | |
674 | int green = strtol(spec.Mid(3,2), &junk, 16); | |
675 | int blue = strtol(spec.Mid(5,2), &junk, 16); | |
676 | return wxColour(red, green, blue); | |
677 | } | |
678 | ||
679 | ||
680 | void wxStyledTextCtrl::StyleClearAll() { | |
681 | SendMsg(SCI_STYLECLEARALL); | |
682 | } | |
683 | ||
684 | ||
685 | void wxStyledTextCtrl::StyleResetDefault() { | |
686 | SendMsg(SCI_STYLERESETDEFAULT); | |
687 | } | |
688 | ||
689 | ||
690 | ||
691 | // Extract style settings from a spec-string which is composed of one or | |
692 | // more of the following comma separated elements: | |
693 | // | |
694 | // bold turns on bold | |
695 | // italic turns on italics | |
696 | // fore:#RRGGBB sets the foreground colour | |
697 | // back:#RRGGBB sets the background colour | |
698 | // face:[facename] sets the font face name to use | |
699 | // size:[num] sets the font size in points | |
700 | // eol turns on eol filling | |
f6bcfd97 | 701 | // underline turns on underlining |
9ce192d4 RD |
702 | // |
703 | ||
704 | void wxStyledTextCtrl::StyleSetSpec(int styleNum, const wxString& spec) { | |
705 | ||
706 | wxStringTokenizer tkz(spec, ","); | |
707 | while (tkz.HasMoreTokens()) { | |
708 | wxString token = tkz.GetNextToken(); | |
709 | ||
710 | wxString option = token.BeforeFirst(':'); | |
711 | wxString val = token.AfterFirst(':'); | |
712 | ||
713 | if (option == "bold") | |
714 | StyleSetBold(styleNum, true); | |
715 | ||
716 | else if (option == "italic") | |
717 | StyleSetItalic(styleNum, true); | |
718 | ||
f6bcfd97 BP |
719 | else if (option == "underline") |
720 | StyleSetUnderline(styleNum, true); | |
721 | ||
9ce192d4 RD |
722 | else if (option == "eol") |
723 | StyleSetEOLFilled(styleNum, true); | |
724 | ||
725 | else if (option == "size") { | |
726 | long points; | |
727 | if (val.ToLong(&points)) | |
728 | StyleSetSize(styleNum, points); | |
729 | } | |
730 | ||
731 | else if (option == "face") | |
732 | StyleSetFaceName(styleNum, val); | |
733 | ||
734 | else if (option == "fore") | |
735 | StyleSetForeground(styleNum, wxColourFromSpec(val)); | |
736 | ||
737 | else if (option == "back") | |
738 | StyleSetBackground(styleNum, wxColourFromSpec(val)); | |
739 | } | |
740 | } | |
741 | ||
742 | ||
743 | void wxStyledTextCtrl::StyleSetForeground(int styleNum, const wxColour& colour) { | |
744 | SendMsg(SCI_STYLESETFORE, styleNum, wxColourAsLong(colour)); | |
745 | } | |
746 | ||
747 | ||
748 | void wxStyledTextCtrl::StyleSetBackground(int styleNum, const wxColour& colour) { | |
749 | SendMsg(SCI_STYLESETBACK, styleNum, wxColourAsLong(colour)); | |
750 | } | |
751 | ||
752 | ||
753 | void wxStyledTextCtrl::StyleSetFont(int styleNum, wxFont& font) { | |
754 | int size = font.GetPointSize(); | |
755 | wxString faceName = font.GetFaceName(); | |
756 | bool bold = font.GetWeight() == wxBOLD; | |
757 | bool italic = font.GetStyle() != wxNORMAL; | |
f6bcfd97 | 758 | bool under = font.GetUnderlined(); |
9ce192d4 | 759 | |
f6bcfd97 | 760 | StyleSetFontAttr(styleNum, size, faceName, bold, italic, under); |
9ce192d4 RD |
761 | } |
762 | ||
763 | ||
764 | void wxStyledTextCtrl::StyleSetFontAttr(int styleNum, int size, | |
765 | const wxString& faceName, | |
f6bcfd97 BP |
766 | bool bold, bool italic, |
767 | bool underline) { | |
9ce192d4 RD |
768 | StyleSetSize(styleNum, size); |
769 | StyleSetFaceName(styleNum, faceName); | |
770 | StyleSetBold(styleNum, bold); | |
771 | StyleSetItalic(styleNum, italic); | |
f6bcfd97 | 772 | StyleSetUnderline(styleNum, underline); |
9ce192d4 RD |
773 | } |
774 | ||
775 | ||
776 | void wxStyledTextCtrl::StyleSetBold(int styleNum, bool bold) { | |
777 | SendMsg(SCI_STYLESETBOLD, styleNum, bold); | |
778 | } | |
779 | ||
780 | ||
781 | void wxStyledTextCtrl::StyleSetItalic(int styleNum, bool italic) { | |
782 | SendMsg(SCI_STYLESETITALIC, styleNum, italic); | |
783 | } | |
784 | ||
785 | ||
786 | void wxStyledTextCtrl::StyleSetFaceName(int styleNum, const wxString& faceName) { | |
787 | SendMsg(SCI_STYLESETFONT, styleNum, (long)faceName.c_str()); | |
788 | } | |
789 | ||
790 | ||
791 | void wxStyledTextCtrl::StyleSetSize(int styleNum, int pointSize) { | |
792 | SendMsg(SCI_STYLESETSIZE, styleNum, pointSize); | |
793 | } | |
794 | ||
795 | ||
796 | void wxStyledTextCtrl::StyleSetEOLFilled(int styleNum, bool fillEOL) { | |
797 | SendMsg(SCI_STYLESETEOLFILLED, styleNum, fillEOL); | |
798 | } | |
799 | ||
800 | ||
f6bcfd97 BP |
801 | void wxStyledTextCtrl::StyleSetUnderline(int styleNum, bool underline) { |
802 | SendMsg(SCI_STYLESETUNDERLINE, styleNum, underline); | |
803 | } | |
804 | ||
805 | ||
9ce192d4 RD |
806 | //---------------------------------------------------------------------- |
807 | // Margins in the edit area | |
808 | ||
809 | int wxStyledTextCtrl::GetLeftMargin() { | |
d134f170 | 810 | return SendMsg(SCI_GETMARGINLEFT); |
9ce192d4 RD |
811 | } |
812 | ||
813 | ||
814 | int wxStyledTextCtrl::GetRightMargin() { | |
d134f170 | 815 | return SendMsg(SCI_GETMARGINRIGHT); |
9ce192d4 RD |
816 | } |
817 | ||
818 | ||
819 | void wxStyledTextCtrl::SetMargins(int left, int right) { | |
820 | int flag = 0; | |
9ce192d4 RD |
821 | |
822 | if (right != -1) { | |
d134f170 | 823 | SendMsg(SCI_SETMARGINRIGHT, 0, right); |
9ce192d4 RD |
824 | } |
825 | if (left != -1) { | |
d134f170 | 826 | SendMsg(SCI_SETMARGINLEFT, 0, left); |
9ce192d4 | 827 | } |
9ce192d4 RD |
828 | } |
829 | ||
830 | ||
831 | //---------------------------------------------------------------------- | |
832 | // Margins for selection, markers, etc. | |
833 | ||
834 | void wxStyledTextCtrl::SetMarginType(int margin, int type) { | |
835 | SendMsg(SCI_SETMARGINTYPEN, margin, type); | |
836 | } | |
837 | ||
838 | ||
839 | int wxStyledTextCtrl::GetMarginType(int margin) { | |
840 | return SendMsg(SCI_GETMARGINTYPEN, margin); | |
841 | } | |
842 | ||
843 | ||
844 | void wxStyledTextCtrl::SetMarginWidth(int margin, int pixelWidth) { | |
845 | SendMsg(SCI_SETMARGINWIDTHN, margin, pixelWidth); | |
846 | } | |
847 | ||
848 | ||
849 | int wxStyledTextCtrl::GetMarginWidth(int margin) { | |
850 | return SendMsg(SCI_GETMARGINWIDTHN, margin); | |
851 | } | |
852 | ||
853 | ||
854 | void wxStyledTextCtrl::SetMarginMask(int margin, int mask) { | |
855 | SendMsg(SCI_SETMARGINMASKN, margin, mask); | |
856 | } | |
857 | ||
858 | ||
859 | int wxStyledTextCtrl::GetMarginMask(int margin) { | |
860 | return SendMsg(SCI_GETMARGINMASKN, margin); | |
861 | } | |
862 | ||
863 | ||
864 | void wxStyledTextCtrl::SetMarginSensitive(int margin, bool sensitive) { | |
865 | SendMsg(SCI_SETMARGINSENSITIVEN, margin, sensitive); | |
866 | } | |
867 | ||
868 | ||
869 | bool wxStyledTextCtrl::GetMarginSensitive(int margin) { | |
67003d1a | 870 | return SendMsg(SCI_GETMARGINSENSITIVEN, margin) != 0; |
9ce192d4 RD |
871 | } |
872 | ||
873 | ||
874 | ||
875 | ||
876 | //---------------------------------------------------------------------- | |
877 | // Selection and Caret styles | |
878 | ||
879 | ||
880 | void wxStyledTextCtrl::SetSelectionForeground(const wxColour& colour) { | |
881 | SendMsg(SCI_SETSELFORE, 0, wxColourAsLong(colour)); | |
882 | } | |
883 | ||
884 | ||
885 | void wxStyledTextCtrl::SetSelectionBackground(const wxColour& colour) { | |
886 | SendMsg(SCI_SETSELBACK, 0, wxColourAsLong(colour)); | |
887 | } | |
888 | ||
889 | ||
890 | void wxStyledTextCtrl::SetCaretForeground(const wxColour& colour) { | |
f6bcfd97 | 891 | SendMsg(SCI_SETCARETFORE, wxColourAsLong(colour)); |
9ce192d4 RD |
892 | } |
893 | ||
894 | ||
895 | int wxStyledTextCtrl::GetCaretPeriod() { | |
896 | return SendMsg(SCI_GETCARETPERIOD); | |
897 | } | |
898 | ||
899 | ||
900 | void wxStyledTextCtrl::SetCaretPeriod(int milliseconds) { | |
901 | SendMsg(SCI_SETCARETPERIOD, milliseconds); | |
902 | } | |
903 | ||
904 | ||
905 | ||
906 | //---------------------------------------------------------------------- | |
907 | // Other settings | |
908 | ||
909 | ||
910 | void wxStyledTextCtrl::SetBufferedDraw(bool isBuffered) { | |
911 | SendMsg(SCI_SETBUFFEREDDRAW, isBuffered); | |
912 | } | |
913 | ||
914 | ||
915 | void wxStyledTextCtrl::SetTabWidth(int numChars) { | |
916 | SendMsg(SCI_SETTABWIDTH, numChars); | |
917 | } | |
918 | ||
919 | ||
f6bcfd97 BP |
920 | void wxStyledTextCtrl::SetIndent(int numChars) { |
921 | SendMsg(SCI_SETINDENT, numChars); | |
922 | } | |
923 | ||
924 | ||
925 | void wxStyledTextCtrl::SetUseTabs(bool usetabs) { | |
926 | SendMsg(SCI_SETUSETABS, usetabs); | |
927 | } | |
928 | ||
929 | ||
930 | void wxStyledTextCtrl::SetLineIndentation(int line, int indentation) { | |
931 | SendMsg(SCI_SETLINEINDENTATION, line, indentation); | |
932 | } | |
933 | ||
934 | ||
935 | int wxStyledTextCtrl:: GetLineIndentation(int line) { | |
936 | return SendMsg(SCI_GETLINEINDENTATION, line); | |
937 | } | |
938 | ||
939 | ||
940 | int wxStyledTextCtrl::GetLineIndentationPos(int line) { | |
941 | return SendMsg(SCI_GETLINEINDENTPOSITION, line); | |
942 | } | |
943 | ||
944 | ||
9ce192d4 RD |
945 | void wxStyledTextCtrl::SetWordChars(const wxString& wordChars) { |
946 | SendMsg(SCI_SETTABWIDTH, 0, (long)wordChars.c_str()); | |
947 | } | |
948 | ||
949 | ||
f6bcfd97 BP |
950 | void wxStyledTextCtrl::SetUsePop(bool usepopup) { |
951 | SendMsg(SCI_USEPOPUP, usepopup); | |
952 | } | |
953 | ||
954 | ||
9ce192d4 RD |
955 | //---------------------------------------------------------------------- |
956 | // Brace highlighting | |
957 | ||
958 | ||
959 | void wxStyledTextCtrl::BraceHighlight(int pos1, int pos2) { | |
960 | SendMsg(SCI_BRACEHIGHLIGHT, pos1, pos2); | |
961 | } | |
962 | ||
963 | ||
964 | void wxStyledTextCtrl::BraceBadlight(int pos) { | |
965 | SendMsg(SCI_BRACEBADLIGHT, pos); | |
966 | } | |
967 | ||
968 | ||
969 | int wxStyledTextCtrl::BraceMatch(int pos, int maxReStyle) { | |
970 | return SendMsg(SCI_BRACEMATCH, pos, maxReStyle); | |
971 | } | |
972 | ||
973 | ||
974 | ||
975 | //---------------------------------------------------------------------- | |
976 | // Markers | |
977 | ||
978 | void wxStyledTextCtrl::MarkerDefine(int markerNumber, int markerSymbol, | |
979 | const wxColour& foreground, | |
980 | const wxColour& background) { | |
981 | MarkerSetType(markerNumber, markerSymbol); | |
982 | MarkerSetForeground(markerNumber, foreground); | |
983 | MarkerSetBackground(markerNumber, background); | |
984 | } | |
985 | ||
986 | ||
987 | void wxStyledTextCtrl::MarkerSetType(int markerNumber, int markerSymbol) { | |
988 | SendMsg(SCI_MARKERDEFINE, markerNumber, markerSymbol); | |
989 | } | |
990 | ||
991 | ||
992 | void wxStyledTextCtrl::MarkerSetForeground(int markerNumber, const wxColour& colour) { | |
993 | SendMsg(SCI_MARKERSETFORE, markerNumber, wxColourAsLong(colour)); | |
994 | } | |
995 | ||
996 | ||
997 | void wxStyledTextCtrl::MarkerSetBackground(int markerNumber, const wxColour& colour) { | |
998 | SendMsg(SCI_MARKERSETBACK, markerNumber, wxColourAsLong(colour)); | |
999 | } | |
1000 | ||
1001 | ||
1002 | int wxStyledTextCtrl::MarkerAdd(int line, int markerNumber) { | |
1003 | return SendMsg(SCI_MARKERADD, line, markerNumber); | |
1004 | } | |
1005 | ||
1006 | ||
1007 | void wxStyledTextCtrl::MarkerDelete(int line, int markerNumber) { | |
1008 | SendMsg(SCI_MARKERDELETE, line, markerNumber); | |
1009 | } | |
1010 | ||
1011 | ||
1012 | void wxStyledTextCtrl::MarkerDeleteAll(int markerNumber) { | |
1013 | SendMsg(SCI_MARKERDELETEALL, markerNumber); | |
1014 | } | |
1015 | ||
1016 | ||
1017 | int wxStyledTextCtrl::MarkerGet(int line) { | |
1018 | return SendMsg(SCI_MARKERGET); | |
1019 | } | |
1020 | ||
1021 | ||
1022 | int wxStyledTextCtrl::MarkerGetNextLine(int lineStart, int markerMask) { | |
1023 | return SendMsg(SCI_MARKERNEXT, lineStart, markerMask); | |
1024 | } | |
1025 | ||
1026 | ||
1027 | int wxStyledTextCtrl::MarkerGetPrevLine(int lineStart, int markerMask) { | |
1028 | // return SendMsg(SCI_MARKERPREV, lineStart, markerMask); | |
1029 | return 0; | |
1030 | } | |
1031 | ||
1032 | ||
1033 | int wxStyledTextCtrl::MarkerLineFromHandle(int handle) { | |
1034 | return SendMsg(SCI_MARKERLINEFROMHANDLE, handle); | |
1035 | } | |
1036 | ||
1037 | ||
1038 | void wxStyledTextCtrl::MarkerDeleteHandle(int handle) { | |
1039 | SendMsg(SCI_MARKERDELETEHANDLE, handle); | |
1040 | } | |
1041 | ||
1042 | ||
1043 | ||
1044 | //---------------------------------------------------------------------- | |
1045 | // Indicators | |
1046 | ||
1047 | ||
1048 | void wxStyledTextCtrl::IndicatorSetStyle(int indicNum, int indicStyle) { | |
1049 | SendMsg(SCI_INDICSETSTYLE, indicNum, indicStyle); | |
1050 | } | |
1051 | ||
1052 | ||
1053 | int wxStyledTextCtrl::IndicatorGetStyle(int indicNum) { | |
1054 | return SendMsg(SCI_INDICGETSTYLE, indicNum); | |
1055 | } | |
1056 | ||
1057 | ||
1058 | void wxStyledTextCtrl::IndicatorSetColour(int indicNum, const wxColour& colour) { | |
f6bcfd97 | 1059 | SendMsg(SCI_INDICSETFORE, indicNum, wxColourAsLong(colour)); |
9ce192d4 RD |
1060 | } |
1061 | ||
1062 | ||
1063 | ||
1064 | //---------------------------------------------------------------------- | |
1065 | // Auto completion | |
1066 | ||
1067 | ||
1068 | void wxStyledTextCtrl::AutoCompShow(const wxString& listOfWords) { | |
1069 | SendMsg(SCI_AUTOCSHOW, 0, (long)listOfWords.c_str()); | |
1070 | } | |
1071 | ||
1072 | ||
1073 | void wxStyledTextCtrl::AutoCompCancel() { | |
1074 | SendMsg(SCI_AUTOCCANCEL); | |
1075 | } | |
1076 | ||
1077 | ||
1078 | bool wxStyledTextCtrl::AutoCompActive() { | |
1079 | return SendMsg(SCI_AUTOCACTIVE) != 0; | |
1080 | } | |
1081 | ||
1082 | ||
1083 | int wxStyledTextCtrl::AutoCompPosAtStart() { | |
1084 | return SendMsg(SCI_AUTOCPOSSTART); | |
1085 | } | |
1086 | ||
1087 | ||
1088 | void wxStyledTextCtrl::AutoCompComplete() { | |
1089 | SendMsg(SCI_AUTOCCOMPLETE); | |
1090 | } | |
1091 | ||
1092 | ||
1093 | void wxStyledTextCtrl::AutoCompStopChars(const wxString& stopChars) { | |
1094 | SendMsg(SCI_AUTOCSHOW, 0, (long)stopChars.c_str()); | |
1095 | } | |
1096 | ||
1097 | ||
f6bcfd97 BP |
1098 | void wxStyledTextCtrl::AutoCompSetSeparator(char separator) { |
1099 | SendMsg(SCI_AUTOCSETSEPARATOR, separator); | |
1100 | } | |
1101 | ||
1102 | ||
1103 | char wxStyledTextCtrl::AutoCompGetSeparator() { | |
1104 | return SendMsg(SCI_AUTOCGETSEPARATOR); | |
1105 | } | |
1106 | ||
1107 | ||
1108 | void wxStyledTextCtrl::AutoCompSelect(const wxString& stringtoselect) { | |
1109 | SendMsg(SCI_AUTOCSELECT, (long)stringtoselect.c_str()); | |
1110 | } | |
1111 | ||
1112 | ||
9ce192d4 RD |
1113 | //---------------------------------------------------------------------- |
1114 | // Call tips | |
1115 | ||
1116 | void wxStyledTextCtrl::CallTipShow(int pos, const wxString& text) { | |
1117 | SendMsg(SCI_CALLTIPSHOW, pos, (long)text.c_str()); | |
1118 | } | |
1119 | ||
1120 | ||
1121 | void wxStyledTextCtrl::CallTipCancel() { | |
1122 | SendMsg(SCI_CALLTIPCANCEL); | |
1123 | } | |
1124 | ||
1125 | ||
1126 | bool wxStyledTextCtrl::CallTipActive() { | |
1127 | return SendMsg(SCI_CALLTIPACTIVE) != 0; | |
1128 | } | |
1129 | ||
1130 | ||
1131 | int wxStyledTextCtrl::CallTipPosAtStart() { | |
1132 | return SendMsg(SCI_CALLTIPPOSSTART); | |
1133 | } | |
1134 | ||
1135 | ||
1136 | void wxStyledTextCtrl::CallTipSetHighlight(int start, int end) { | |
1137 | SendMsg(SCI_CALLTIPSETHLT, start, end); | |
1138 | } | |
1139 | ||
1140 | ||
1141 | void wxStyledTextCtrl::CallTipSetBackground(const wxColour& colour) { | |
1142 | SendMsg(SCI_CALLTIPSETBACK, wxColourAsLong(colour)); | |
1143 | } | |
1144 | ||
1145 | ||
1146 | //---------------------------------------------------------------------- | |
1147 | // Key bindings | |
1148 | ||
d134f170 RD |
1149 | #define MAKELONG(a, b) ((a) | ((b) << 16)) |
1150 | ||
9ce192d4 RD |
1151 | void wxStyledTextCtrl::CmdKeyAssign(int key, int modifiers, int cmd) { |
1152 | SendMsg(SCI_ASSIGNCMDKEY, MAKELONG(key, modifiers), cmd); | |
1153 | } | |
1154 | ||
1155 | ||
1156 | void wxStyledTextCtrl::CmdKeyClear(int key, int modifiers) { | |
1157 | SendMsg(SCI_CLEARCMDKEY, MAKELONG(key, modifiers)); | |
1158 | } | |
1159 | ||
1160 | ||
1161 | void wxStyledTextCtrl::CmdKeyClearAll() { | |
1162 | SendMsg(SCI_CLEARALLCMDKEYS); | |
1163 | } | |
1164 | ||
1165 | ||
1166 | void wxStyledTextCtrl::CmdKeyExecute(int cmd) { | |
1167 | SendMsg(cmd); | |
1168 | } | |
1169 | ||
1170 | ||
1171 | ||
1172 | //---------------------------------------------------------------------- | |
1173 | // Print formatting | |
1174 | ||
1175 | int | |
1176 | wxStyledTextCtrl::FormatRange(bool doDraw, | |
1177 | int startPos, | |
1178 | int endPos, | |
1179 | wxDC* draw, | |
1180 | wxDC* target, // Why does it use two? Can they be the same? | |
1181 | wxRect renderRect, | |
1182 | wxRect pageRect) { | |
d134f170 | 1183 | RangeToFormat fr; |
9ce192d4 RD |
1184 | |
1185 | fr.hdc = draw; | |
1186 | fr.hdcTarget = target; | |
1187 | fr.rc.top = renderRect.GetTop(); | |
1188 | fr.rc.left = renderRect.GetLeft(); | |
1189 | fr.rc.right = renderRect.GetRight(); | |
1190 | fr.rc.bottom = renderRect.GetBottom(); | |
1191 | fr.rcPage.top = pageRect.GetTop(); | |
1192 | fr.rcPage.left = pageRect.GetLeft(); | |
1193 | fr.rcPage.right = pageRect.GetRight(); | |
1194 | fr.rcPage.bottom = pageRect.GetBottom(); | |
1195 | fr.chrg.cpMin = startPos; | |
1196 | fr.chrg.cpMax = endPos; | |
1197 | ||
d134f170 | 1198 | return SendMsg(SCI_FORMATRANGE, doDraw, (long)&fr); |
9ce192d4 RD |
1199 | } |
1200 | ||
1201 | ||
1202 | //---------------------------------------------------------------------- | |
1203 | // Document Sharing | |
1204 | ||
1205 | void* wxStyledTextCtrl::GetDocument() { | |
1206 | return (void*)SendMsg(SCI_GETDOCPOINTER); | |
1207 | } | |
1208 | ||
1209 | ||
1210 | void wxStyledTextCtrl::SetDocument(void* document) { | |
1211 | SendMsg(SCI_SETDOCPOINTER, 0, (long)document); | |
1212 | } | |
1213 | ||
1214 | ||
67003d1a RD |
1215 | //---------------------------------------------------------------------- |
1216 | // Folding | |
1217 | ||
1218 | int wxStyledTextCtrl::VisibleFromDocLine(int docLine) { | |
1219 | return SendMsg(SCI_VISIBLEFROMDOCLINE, docLine); | |
1220 | } | |
1221 | ||
1222 | ||
1223 | int wxStyledTextCtrl::DocLineFromVisible(int displayLine) { | |
1224 | return SendMsg(SCI_DOCLINEFROMVISIBLE, displayLine); | |
1225 | } | |
1226 | ||
1227 | ||
1228 | int wxStyledTextCtrl::SetFoldLevel(int line, int level) { | |
1229 | return SendMsg(SCI_SETFOLDLEVEL, line, level); | |
1230 | } | |
1231 | ||
1232 | ||
1233 | int wxStyledTextCtrl::GetFoldLevel(int line) { | |
1234 | return SendMsg(SCI_GETFOLDLEVEL, line); | |
1235 | } | |
1236 | ||
1237 | ||
f6bcfd97 BP |
1238 | int wxStyledTextCtrl::GetLastChild(int line, int level) { |
1239 | return SendMsg(SCI_GETLASTCHILD, line, level); | |
67003d1a RD |
1240 | } |
1241 | ||
1242 | ||
1243 | int wxStyledTextCtrl::GetFoldParent(int line) { | |
1244 | return SendMsg(SCI_GETFOLDPARENT, line); | |
1245 | } | |
1246 | ||
1247 | ||
1248 | void wxStyledTextCtrl::ShowLines(int lineStart, int lineEnd) { | |
1249 | SendMsg(SCI_SHOWLINES, lineStart, lineEnd); | |
1250 | } | |
1251 | ||
1252 | ||
1253 | void wxStyledTextCtrl::HideLines(int lineStart, int lineEnd) { | |
1254 | SendMsg(SCI_HIDELINES, lineStart, lineEnd); | |
1255 | } | |
1256 | ||
1257 | ||
1258 | bool wxStyledTextCtrl::GetLineVisible(int line) { | |
1259 | return SendMsg(SCI_GETLINEVISIBLE, line) != 0; | |
1260 | } | |
1261 | ||
1262 | ||
f6bcfd97 BP |
1263 | void wxStyledTextCtrl::SetFoldExpanded(int line, bool expanded) { |
1264 | SendMsg(SCI_SETFOLDEXPANDED, line, expanded); | |
67003d1a RD |
1265 | } |
1266 | ||
1267 | ||
1268 | bool wxStyledTextCtrl::GetFoldExpanded(int line) { | |
1269 | return SendMsg(SCI_GETFOLDEXPANDED, line) != 0; | |
1270 | } | |
1271 | ||
1272 | ||
1273 | void wxStyledTextCtrl::ToggleFold(int line) { | |
1274 | SendMsg(SCI_TOGGLEFOLD, line); | |
1275 | } | |
1276 | ||
1277 | ||
1278 | void wxStyledTextCtrl::EnsureVisible(int line) { | |
1279 | SendMsg(SCI_ENSUREVISIBLE, line); | |
1280 | } | |
1281 | ||
1282 | ||
f6bcfd97 BP |
1283 | void wxStyledTextCtrl::SetFoldFlags(int flags) { |
1284 | SendMsg(SCI_SETFOLDFLAGS, flags); | |
1285 | } | |
1286 | ||
1287 | ||
1288 | //---------------------------------------------------------------------- | |
1289 | // Zooming | |
1290 | ||
1291 | void wxStyledTextCtrl::ZoomIn() { | |
1292 | SendMsg(SCI_ZOOMIN); | |
1293 | } | |
1294 | ||
1295 | ||
1296 | void wxStyledTextCtrl::ZoomOut() { | |
1297 | SendMsg(SCI_ZOOMOUT); | |
1298 | } | |
1299 | ||
1300 | ||
1301 | void wxStyledTextCtrl::SetZoom(int zoom) { | |
1302 | SendMsg(SCI_SETZOOM, zoom); | |
1303 | } | |
1304 | ||
1305 | ||
1306 | int wxStyledTextCtrl::GetZoom() { | |
1307 | return SendMsg(SCI_GETZOOM); | |
1308 | } | |
1309 | ||
9ce192d4 RD |
1310 | //---------------------------------------------------------------------- |
1311 | // Long Lines | |
1312 | ||
1313 | int wxStyledTextCtrl::GetEdgeColumn() { | |
1314 | return SendMsg(SCI_GETEDGECOLUMN); | |
1315 | } | |
1316 | ||
1317 | void wxStyledTextCtrl::SetEdgeColumn(int column) { | |
1318 | SendMsg(SCI_SETEDGECOLUMN, column); | |
1319 | } | |
1320 | ||
1321 | wxSTC_EDGE wxStyledTextCtrl::GetEdgeMode() { | |
1322 | return (wxSTC_EDGE) SendMsg(SCI_GETEDGEMODE); | |
1323 | } | |
1324 | ||
1325 | void wxStyledTextCtrl::SetEdgeMode(wxSTC_EDGE mode){ | |
1326 | SendMsg(SCI_SETEDGEMODE, mode); | |
1327 | } | |
1328 | ||
1329 | wxColour wxStyledTextCtrl::GetEdgeColour() { | |
1330 | long c = SendMsg(SCI_GETEDGECOLOUR); | |
1331 | return wxColourFromLong(c); | |
1332 | } | |
1333 | ||
1334 | void wxStyledTextCtrl::SetEdgeColour(const wxColour& colour) { | |
1335 | SendMsg(SCI_SETEDGECOLOUR, wxColourAsLong(colour)); | |
1336 | } | |
1337 | ||
1338 | ||
1339 | //---------------------------------------------------------------------- | |
1340 | // Lexer | |
1341 | ||
1342 | void wxStyledTextCtrl::SetLexer(wxSTC_LEX lexer) { | |
1343 | SendMsg(SCI_SETLEXER, lexer); | |
1344 | } | |
1345 | ||
1346 | ||
1347 | wxSTC_LEX wxStyledTextCtrl::GetLexer() { | |
1348 | return (wxSTC_LEX)SendMsg(SCI_GETLEXER); | |
1349 | } | |
1350 | ||
1351 | ||
1352 | void wxStyledTextCtrl::Colourise(int start, int end) { | |
1353 | SendMsg(SCI_COLOURISE, start, end); | |
1354 | } | |
1355 | ||
1356 | ||
1357 | void wxStyledTextCtrl::SetProperty(const wxString& key, const wxString& value) { | |
1358 | SendMsg(SCI_SETPROPERTY, (long)key.c_str(), (long)value.c_str()); | |
1359 | } | |
1360 | ||
1361 | ||
1362 | void wxStyledTextCtrl::SetKeywords(int keywordSet, const wxString& keywordList) { | |
1363 | SendMsg(SCI_SETKEYWORDS, keywordSet, (long)keywordList.c_str()); | |
1364 | } | |
1365 | ||
1366 | ||
1367 | ||
f6bcfd97 BP |
1368 | //---------------------------------------------------------------------- |
1369 | // Event mask for Modified Event | |
1370 | ||
1371 | void wxStyledTextCtrl::SetModEventMask(int mask) { | |
1372 | SendMsg(SCI_SETMODEVENTMASK, mask); | |
1373 | } | |
1374 | ||
1375 | ||
1376 | //int wxStyledTextCtrl::GetModEventMask() { | |
1377 | // return SendMsg(SCI_GETMODEVENTMASK); | |
1378 | //} | |
1379 | ||
9ce192d4 RD |
1380 | //---------------------------------------------------------------------- |
1381 | // Event handlers | |
1382 | ||
1383 | void wxStyledTextCtrl::OnPaint(wxPaintEvent& evt) { | |
1384 | wxPaintDC dc(this); | |
1385 | wxRegion region = GetUpdateRegion(); | |
1386 | ||
1387 | m_swx->DoPaint(&dc, region.GetBox()); | |
1388 | } | |
1389 | ||
1390 | void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent& evt) { | |
1391 | if (evt.GetOrientation() == wxHORIZONTAL) | |
1392 | m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition()); | |
1393 | else | |
1394 | m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition()); | |
1395 | } | |
1396 | ||
1397 | void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) { | |
1398 | wxSize sz = GetClientSize(); | |
1399 | m_swx->DoSize(sz.x, sz.y); | |
1400 | } | |
1401 | ||
1402 | void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) { | |
1403 | wxPoint pt = evt.GetPosition(); | |
1404 | m_swx->DoButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(), | |
1405 | evt.ShiftDown(), evt.ControlDown(), evt.AltDown()); | |
1406 | } | |
1407 | ||
1408 | void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) { | |
1409 | wxPoint pt = evt.GetPosition(); | |
1410 | m_swx->DoButtonMove(Point(pt.x, pt.y)); | |
1411 | } | |
1412 | ||
1413 | void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) { | |
1414 | wxPoint pt = evt.GetPosition(); | |
1415 | m_swx->DoButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(), | |
1416 | evt.ControlDown()); | |
1417 | } | |
1418 | ||
1419 | ||
1420 | void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) { | |
1421 | wxPoint pt = evt.GetPosition(); | |
1422 | m_swx->DoContextMenu(Point(pt.x, pt.y)); | |
1423 | } | |
1424 | ||
1425 | void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { | |
9ce192d4 RD |
1426 | long key = evt.KeyCode(); |
1427 | if ((key > WXK_ESCAPE) && | |
1428 | (key != WXK_DELETE) && (key < 255) && | |
1429 | !evt.ControlDown() && !evt.AltDown()) { | |
1430 | ||
1431 | m_swx->DoAddChar(key); | |
9ce192d4 RD |
1432 | } |
1433 | else { | |
f6bcfd97 | 1434 | evt.Skip(); |
9ce192d4 | 1435 | } |
f6bcfd97 BP |
1436 | } |
1437 | ||
1438 | void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { | |
1439 | long key = evt.KeyCode(); | |
1440 | key = toupper(key); | |
1441 | int processed = m_swx->DoKeyDown(key, evt.ShiftDown(), | |
1442 | evt.ControlDown(), evt.AltDown()); | |
9ce192d4 RD |
1443 | if (! processed) |
1444 | evt.Skip(); | |
1445 | } | |
1446 | ||
1447 | void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent& evt) { | |
1448 | m_swx->DoLoseFocus(); | |
1449 | } | |
1450 | ||
1451 | void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { | |
1452 | m_swx->DoGainFocus(); | |
1453 | } | |
1454 | ||
1455 | void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& evt) { | |
1456 | m_swx->DoSysColourChange(); | |
1457 | } | |
1458 | ||
1459 | void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent& evt) { | |
1460 | // do nothing to help avoid flashing | |
1461 | } | |
1462 | ||
1463 | ||
1464 | ||
1465 | void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) { | |
1466 | m_swx->DoCommand(evt.GetId()); | |
1467 | } | |
1468 | ||
1469 | ||
f6bcfd97 BP |
1470 | void wxStyledTextCtrl::OnListBox(wxCommandEvent& evt) { |
1471 | m_swx->DoOnListBox(); | |
1472 | } | |
1473 | ||
1474 | ||
9ce192d4 RD |
1475 | //---------------------------------------------------------------------- |
1476 | // Turn notifications from Scintilla into events | |
1477 | ||
f6bcfd97 | 1478 | |
9ce192d4 RD |
1479 | void wxStyledTextCtrl::NotifyChange() { |
1480 | wxStyledTextEvent evt(wxEVT_STC_CHANGE, GetId()); | |
1481 | GetEventHandler()->ProcessEvent(evt); | |
1482 | } | |
1483 | ||
1484 | void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { | |
1485 | SCNotification& scn = *_scn; | |
1486 | int eventType = 0; | |
1487 | switch (scn.nmhdr.code) { | |
1488 | case SCN_STYLENEEDED: | |
1489 | eventType = wxEVT_STC_STYLENEEDED; | |
1490 | break; | |
1491 | case SCN_CHARADDED: | |
1492 | eventType = wxEVT_STC_CHARADDED; | |
1493 | break; | |
1494 | case SCN_UPDATEUI: | |
1495 | eventType = wxEVT_STC_UPDATEUI; | |
1496 | break; | |
1497 | case SCN_SAVEPOINTREACHED: | |
1498 | eventType = wxEVT_STC_SAVEPOINTREACHED; | |
1499 | break; | |
1500 | case SCN_SAVEPOINTLEFT: | |
1501 | eventType = wxEVT_STC_SAVEPOINTLEFT; | |
1502 | break; | |
1503 | case SCN_MODIFYATTEMPTRO: | |
1504 | eventType = wxEVT_STC_ROMODIFYATTEMPT; | |
1505 | break; | |
1506 | case SCN_DOUBLECLICK: | |
1507 | eventType = wxEVT_STC_DOUBLECLICK; | |
1508 | break; | |
1509 | case SCN_MODIFIED: | |
1510 | eventType = wxEVT_STC_MODIFIED; | |
1511 | break; | |
1512 | case SCN_KEY: | |
1513 | eventType = wxEVT_STC_KEY; | |
1514 | break; | |
1515 | case SCN_MACRORECORD: | |
1516 | eventType = wxEVT_STC_MACRORECORD; | |
1517 | break; | |
1518 | case SCN_MARGINCLICK: | |
1519 | eventType = wxEVT_STC_MARGINCLICK; | |
1520 | break; | |
1521 | case SCN_NEEDSHOWN: | |
1522 | eventType = wxEVT_STC_NEEDSHOWN; | |
1523 | break; | |
1524 | } | |
1525 | if (eventType) { | |
1526 | wxStyledTextEvent evt(eventType, GetId()); | |
1527 | evt.SetPosition(scn.position); | |
1528 | evt.SetKey(scn.ch); | |
1529 | evt.SetModifiers(scn.modifiers); | |
1530 | if (eventType == wxEVT_STC_MODIFIED) { | |
1531 | evt.SetModificationType(scn.modificationType); | |
f6bcfd97 BP |
1532 | if (scn.text) |
1533 | evt.SetText(wxString(scn.text, scn.length)); | |
9ce192d4 RD |
1534 | evt.SetLength(scn.length); |
1535 | evt.SetLinesAdded(scn.linesAdded); | |
1536 | evt.SetLine(scn.line); | |
1537 | evt.SetFoldLevelNow(scn.foldLevelNow); | |
1538 | evt.SetFoldLevelPrev(scn.foldLevelPrev); | |
1539 | } | |
1540 | if (eventType == wxEVT_STC_MARGINCLICK) | |
1541 | evt.SetMargin(scn.margin); | |
1542 | if (eventType == wxEVT_STC_MACRORECORD) { | |
1543 | evt.SetMessage(scn.message); | |
1544 | evt.SetWParam(scn.wParam); | |
1545 | evt.SetLParam(scn.lParam); | |
1546 | } | |
1547 | ||
1548 | GetEventHandler()->ProcessEvent(evt); | |
1549 | } | |
1550 | } | |
1551 | ||
1552 | ||
1553 | ||
1554 | //---------------------------------------------------------------------- | |
1555 | //---------------------------------------------------------------------- | |
1556 | //---------------------------------------------------------------------- | |
1557 | ||
1558 | wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id) | |
1559 | : wxCommandEvent(commandType, id) | |
1560 | { | |
1561 | m_position = 0; | |
1562 | m_key = 0; | |
1563 | m_modifiers = 0; | |
1564 | m_modificationType = 0; | |
1565 | m_length = 0; | |
1566 | m_linesAdded = 0; | |
1567 | m_line = 0; | |
1568 | m_foldLevelNow = 0; | |
1569 | m_foldLevelPrev = 0; | |
1570 | m_margin = 0; | |
1571 | m_message = 0; | |
1572 | m_wParam = 0; | |
1573 | m_lParam = 0; | |
1574 | ||
1575 | ||
1576 | } | |
1577 | ||
1578 | bool wxStyledTextEvent::GetShift() const { return (m_modifiers & SCI_SHIFT) != 0; } | |
1579 | bool wxStyledTextEvent::GetControl() const { return (m_modifiers & SCI_CTRL) != 0; } | |
1580 | bool wxStyledTextEvent::GetAlt() const { return (m_modifiers & SCI_ALT) != 0; } | |
1581 | ||
1582 | void wxStyledTextEvent::CopyObject(wxObject& obj) const { | |
1583 | wxCommandEvent::CopyObject(obj); | |
1584 | ||
1585 | wxStyledTextEvent* o = (wxStyledTextEvent*)&obj; | |
1586 | o->m_position = m_position; | |
1587 | o->m_key = m_key; | |
1588 | o->m_modifiers = m_modifiers; | |
1589 | o->m_modificationType = m_modificationType; | |
1590 | o->m_text = m_text; | |
1591 | o->m_length = m_length; | |
1592 | o->m_linesAdded = m_linesAdded; | |
1593 | o->m_line = m_line; | |
1594 | o->m_foldLevelNow = m_foldLevelNow; | |
1595 | o->m_foldLevelPrev = m_foldLevelPrev; | |
1596 | ||
1597 | o->m_margin = m_margin; | |
1598 | ||
1599 | o->m_message = m_message; | |
1600 | o->m_wParam = m_wParam; | |
1601 | o->m_lParam = m_lParam; | |
1602 | ||
1603 | ||
1604 | ||
1605 | } | |
1606 | ||
1607 | //---------------------------------------------------------------------- | |
1608 | //---------------------------------------------------------------------- | |
1609 |