]> git.saurik.com Git - wxWidgets.git/blob - src/stc/ScintillaWX.cpp
Beginings of wxX11 support. Much more to do but I have no more time
[wxWidgets.git] / src / stc / ScintillaWX.cpp
1 ////////////////////////////////////////////////////////////////////////////
2 // Name: ScintillaWX.cxx
3 // Purpose: A wxWindows implementation of Scintilla. A class derived
4 // from ScintillaBase that uses the "wx platform" defined in
5 // PlatformWX.cxx This class is one end of a bridge between
6 // the wx world and the Scintilla world. It needs a peer
7 // object of type wxStyledTextCtrl to function.
8 //
9 // Author: Robin Dunn
10 //
11 // Created: 13-Jan-2000
12 // RCS-ID: $Id$
13 // Copyright: (c) 2000 by Total Control Software
14 // Licence: wxWindows license
15 /////////////////////////////////////////////////////////////////////////////
16
17
18 #include "ScintillaWX.h"
19 #include "ExternalLexer.h"
20 #include "wx/stc/stc.h"
21 #include "PlatWX.h"
22 #include <wx/textbuf.h>
23
24 //----------------------------------------------------------------------
25 // Helper classes
26
27 class wxSTCTimer : public wxTimer {
28 public:
29 wxSTCTimer(ScintillaWX* swx) {
30 this->swx = swx;
31 }
32
33 void Notify() {
34 swx->DoTick();
35 }
36
37 private:
38 ScintillaWX* swx;
39 };
40
41
42 #if wxUSE_DRAG_AND_DROP
43 bool wxSTCDropTarget::OnDropText(wxCoord x, wxCoord y, const wxString& data) {
44 return swx->DoDropText(x, y, data);
45 }
46
47 wxDragResult wxSTCDropTarget::OnEnter(wxCoord x, wxCoord y, wxDragResult def) {
48 return swx->DoDragEnter(x, y, def);
49 }
50
51 wxDragResult wxSTCDropTarget::OnDragOver(wxCoord x, wxCoord y, wxDragResult def) {
52 return swx->DoDragOver(x, y, def);
53 }
54
55 void wxSTCDropTarget::OnLeave() {
56 swx->DoDragLeave();
57 }
58 #endif
59
60
61 #ifdef __WXGTK__
62 #undef wxSTC_USE_POPUP
63 #define wxSTC_USE_POPUP 0
64 #endif
65
66 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
67 #include <wx/popupwin.h>
68 #define wxSTCCallTipBase wxPopupWindow
69 #define param2 wxBORDER_NONE // popup's 2nd param is flags
70 #else
71 #define wxSTCCallTipBase wxWindow
72 #define param2 -1 // wxWindow's 2nd param is ID
73 #endif
74
75 class wxSTCCallTip : public wxSTCCallTipBase {
76 public:
77 wxSTCCallTip(wxWindow* parent, CallTip* ct, ScintillaWX* swx)
78 : wxSTCCallTipBase(parent, param2),
79 m_ct(ct), m_swx(swx)
80 {
81 }
82
83 ~wxSTCCallTip() {
84 }
85
86 bool AcceptsFocus() const { return FALSE; }
87
88 void OnPaint(wxPaintEvent& evt) {
89 wxPaintDC dc(this);
90 Surface* surfaceWindow = Surface::Allocate();
91 surfaceWindow->Init(&dc, m_ct->wDraw.GetID());
92 m_ct->PaintCT(surfaceWindow);
93 surfaceWindow->Release();
94 delete surfaceWindow;
95 }
96
97 void OnFocus(wxFocusEvent& event) {
98 GetParent()->SetFocus();
99 event.Skip();
100 }
101
102 void OnLeftDown(wxMouseEvent& event) {
103 wxPoint pt = event.GetPosition();
104 Point p(pt.x, pt.y);
105 m_ct->MouseClick(p);
106 m_swx->CallTipClick();
107 }
108
109 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
110 virtual void DoSetSize(int x, int y,
111 int width, int height,
112 int sizeFlags = wxSIZE_AUTO) {
113 if (x != -1)
114 GetParent()->ClientToScreen(&x, NULL);
115 if (y != -1)
116 GetParent()->ClientToScreen(NULL, &y);
117 wxSTCCallTipBase::DoSetSize(x, y, width, height, sizeFlags);
118 }
119 #endif
120
121 private:
122 CallTip* m_ct;
123 ScintillaWX* m_swx;
124 DECLARE_EVENT_TABLE()
125 };
126
127 BEGIN_EVENT_TABLE(wxSTCCallTip, wxSTCCallTipBase)
128 EVT_PAINT(wxSTCCallTip::OnPaint)
129 EVT_SET_FOCUS(wxSTCCallTip::OnFocus)
130 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown)
131 END_EVENT_TABLE()
132
133
134 //----------------------------------------------------------------------
135 // Constructor/Destructor
136
137
138 ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) {
139 capturedMouse = false;
140 focusEvent = false;
141 wMain = win;
142 stc = win;
143 wheelRotation = 0;
144 Initialise();
145 }
146
147
148 ScintillaWX::~ScintillaWX() {
149 SetTicking(false);
150 }
151
152 //----------------------------------------------------------------------
153 // base class virtuals
154
155
156 void ScintillaWX::Initialise() {
157 //ScintillaBase::Initialise();
158 #if wxUSE_DRAG_AND_DROP
159 dropTarget = new wxSTCDropTarget;
160 dropTarget->SetScintilla(this);
161 stc->SetDropTarget(dropTarget);
162 #endif
163 }
164
165
166 void ScintillaWX::Finalise() {
167 ScintillaBase::Finalise();
168 }
169
170
171 void ScintillaWX::StartDrag() {
172 #if wxUSE_DRAG_AND_DROP
173 wxString dragText = stc2wx(drag.s, drag.len);
174
175 // Send an event to allow the drag text to be changed
176 wxStyledTextEvent evt(wxEVT_STC_START_DRAG, stc->GetId());
177 evt.SetEventObject(stc);
178 evt.SetDragText(dragText);
179 evt.SetDragAllowMove(TRUE);
180 evt.SetPosition(wxMin(stc->GetSelectionStart(),
181 stc->GetSelectionEnd()));
182 stc->GetEventHandler()->ProcessEvent(evt);
183 dragText = evt.GetDragText();
184
185 if (dragText.Length()) {
186 wxDropSource source(stc);
187 wxTextDataObject data(dragText);
188 wxDragResult result;
189
190 source.SetData(data);
191 dropWentOutside = TRUE;
192 result = source.DoDragDrop(evt.GetDragAllowMove());
193 if (result == wxDragMove && dropWentOutside)
194 ClearSelection();
195 inDragDrop = FALSE;
196 SetDragPosition(invalidPosition);
197 }
198 #endif
199 }
200
201
202 void ScintillaWX::SetTicking(bool on) {
203 wxSTCTimer* steTimer;
204 if (timer.ticking != on) {
205 timer.ticking = on;
206 if (timer.ticking) {
207 steTimer = new wxSTCTimer(this);
208 steTimer->Start(timer.tickSize);
209 timer.tickerID = steTimer;
210 } else {
211 steTimer = (wxSTCTimer*)timer.tickerID;
212 steTimer->Stop();
213 delete steTimer;
214 timer.tickerID = 0;
215 }
216 }
217 timer.ticksToWait = caret.period;
218 }
219
220
221 void ScintillaWX::SetMouseCapture(bool on) {
222 if (on && !capturedMouse)
223 stc->CaptureMouse();
224 else if (!on && capturedMouse && stc->HasCapture())
225 stc->ReleaseMouse();
226 capturedMouse = on;
227 }
228
229
230 bool ScintillaWX::HaveMouseCapture() {
231 return capturedMouse;
232 }
233
234
235 void ScintillaWX::ScrollText(int linesToMove) {
236 int dy = vs.lineHeight * (linesToMove);
237 stc->ScrollWindow(0, dy);
238 stc->Update();
239 }
240
241 void ScintillaWX::SetVerticalScrollPos() {
242 if (stc->m_vScrollBar == NULL) { // Use built-in scrollbar
243 stc->SetScrollPos(wxVERTICAL, topLine);
244 }
245 else { // otherwise use the one that's been given to us
246 stc->m_vScrollBar->SetThumbPosition(topLine);
247 }
248 }
249
250 void ScintillaWX::SetHorizontalScrollPos() {
251 if (stc->m_hScrollBar == NULL) { // Use built-in scrollbar
252 stc->SetScrollPos(wxHORIZONTAL, xOffset);
253 }
254 else { // otherwise use the one that's been given to us
255 stc->m_hScrollBar->SetThumbPosition(xOffset);
256 }
257 }
258
259
260 const int H_SCROLL_STEP = 20;
261
262 bool ScintillaWX::ModifyScrollBars(int nMax, int nPage) {
263 bool modified = false;
264
265 int vertEnd = nMax;
266 if (!verticalScrollBarVisible)
267 vertEnd = 0;
268
269 // Check the vertical scrollbar
270 if (stc->m_vScrollBar == NULL) { // Use built-in scrollbar
271 int sbMax = stc->GetScrollRange(wxVERTICAL);
272 int sbThumb = stc->GetScrollThumb(wxVERTICAL);
273 int sbPos = stc->GetScrollPos(wxVERTICAL);
274 if (sbMax != vertEnd || sbThumb != nPage) {
275 stc->SetScrollbar(wxVERTICAL, sbPos, nPage, vertEnd+1);
276 modified = true;
277 }
278 }
279 else { // otherwise use the one that's been given to us
280 int sbMax = stc->m_vScrollBar->GetRange();
281 int sbPage = stc->m_vScrollBar->GetPageSize();
282 int sbPos = stc->m_vScrollBar->GetThumbPosition();
283 if (sbMax != vertEnd || sbPage != nPage) {
284 stc->m_vScrollBar->SetScrollbar(sbPos, nPage, vertEnd+1, nPage);
285 modified = true;
286 }
287 }
288
289
290 // Check the horizontal scrollbar
291 PRectangle rcText = GetTextRectangle();
292 int horizEnd = scrollWidth;
293 if (horizEnd < 0)
294 horizEnd = 0;
295 if (!horizontalScrollBarVisible || (wrapState != eWrapNone))
296 horizEnd = 0;
297 int pageWidth = rcText.Width();
298
299 if (stc->m_hScrollBar == NULL) { // Use built-in scrollbar
300 int sbMax = stc->GetScrollRange(wxHORIZONTAL);
301 int sbThumb = stc->GetScrollThumb(wxHORIZONTAL);
302 int sbPos = stc->GetScrollPos(wxHORIZONTAL);
303 if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) {
304 stc->SetScrollbar(wxHORIZONTAL, sbPos, pageWidth, horizEnd);
305 modified = true;
306 if (scrollWidth < pageWidth) {
307 HorizontalScrollTo(0);
308 }
309 }
310 }
311 else { // otherwise use the one that's been given to us
312 int sbMax = stc->m_hScrollBar->GetRange();
313 int sbThumb = stc->m_hScrollBar->GetPageSize();
314 int sbPos = stc->m_hScrollBar->GetThumbPosition();
315 if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) {
316 stc->m_hScrollBar->SetScrollbar(sbPos, pageWidth, horizEnd, pageWidth);
317 modified = true;
318 if (scrollWidth < pageWidth) {
319 HorizontalScrollTo(0);
320 }
321 }
322 }
323
324 return modified;
325 }
326
327
328 void ScintillaWX::NotifyChange() {
329 stc->NotifyChange();
330 }
331
332
333 void ScintillaWX::NotifyParent(SCNotification scn) {
334 stc->NotifyParent(&scn);
335 }
336
337
338 // This method is overloaded from ScintillaBase in order to prevent the
339 // AutoComplete window from being destroyed when it gets the focus. There is
340 // a side effect that the AutoComp will also not be destroyed when switching
341 // to another window, but I think that is okay.
342 void ScintillaWX::CancelModes() {
343 if (! focusEvent)
344 AutoCompleteCancel();
345 ct.CallTipCancel();
346 Editor::CancelModes();
347 }
348
349
350
351 void ScintillaWX::Copy() {
352 if (currentPos != anchor) {
353 SelectionText st;
354 CopySelectionRange(&st);
355 CopyToClipboard(st);
356 }
357 }
358
359
360 void ScintillaWX::Paste() {
361 pdoc->BeginUndoAction();
362 ClearSelection();
363
364 wxTextDataObject data;
365 bool gotData = FALSE;
366
367 if (wxTheClipboard->Open()) {
368 wxTheClipboard->UsePrimarySelection(FALSE);
369 gotData = wxTheClipboard->GetData(data);
370 wxTheClipboard->Close();
371 }
372 if (gotData) {
373 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(data.GetText());
374 int len = strlen(buf);
375 pdoc->InsertString(currentPos, buf, len);
376 SetEmptySelection(currentPos + len);
377 }
378
379 pdoc->EndUndoAction();
380 NotifyChange();
381 Redraw();
382 }
383
384
385 void ScintillaWX::CopyToClipboard(const SelectionText& st) {
386 if (wxTheClipboard->Open()) {
387 wxTheClipboard->UsePrimarySelection(FALSE);
388 wxString text = wxTextBuffer::Translate(stc2wx(st.s, st.len));
389 wxTheClipboard->SetData(new wxTextDataObject(text));
390 wxTheClipboard->Close();
391 }
392 }
393
394
395 bool ScintillaWX::CanPaste() {
396 bool canPaste = FALSE;
397 bool didOpen;
398
399 if (Editor::CanPaste()) {
400 didOpen = !wxTheClipboard->IsOpened();
401 if ( didOpen )
402 wxTheClipboard->Open();
403
404 if (wxTheClipboard->IsOpened()) {
405 wxTheClipboard->UsePrimarySelection(FALSE);
406 canPaste = wxTheClipboard->IsSupported(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT);
407 if (didOpen)
408 wxTheClipboard->Close();
409 }
410 }
411 return canPaste;
412 }
413
414 void ScintillaWX::CreateCallTipWindow(PRectangle) {
415 if (! ct.wCallTip.Created() ) {
416 ct.wCallTip = new wxSTCCallTip(stc, &ct, this);
417 ct.wDraw = ct.wCallTip;
418 }
419 }
420
421
422 void ScintillaWX::AddToPopUp(const char *label, int cmd, bool enabled) {
423 if (!label[0])
424 ((wxMenu*)popup.GetID())->AppendSeparator();
425 else
426 ((wxMenu*)popup.GetID())->Append(cmd, wxGetTranslation(stc2wx(label)));
427
428 if (!enabled)
429 ((wxMenu*)popup.GetID())->Enable(cmd, enabled);
430 }
431
432
433 // This is called by the Editor base class whenever something is selected
434 void ScintillaWX::ClaimSelection() {
435 #if 0
436 // Until wxGTK is able to support using both the primary selection and the
437 // clipboard at the same time I think it causes more problems than it is
438 // worth to implement this method. Selecting text should not clear the
439 // clipboard. --Robin
440 #ifdef __WXGTK__
441 // Put the selected text in the PRIMARY selection
442 if (currentPos != anchor) {
443 SelectionText st;
444 CopySelectionRange(&st);
445 if (wxTheClipboard->Open()) {
446 wxTheClipboard->UsePrimarySelection(TRUE);
447 wxString text = stc2wx(st.s, st.len);
448 wxTheClipboard->SetData(new wxTextDataObject(text));
449 wxTheClipboard->UsePrimarySelection(FALSE);
450 wxTheClipboard->Close();
451 }
452 }
453 #endif
454 #endif
455 }
456
457
458 long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
459 return 0;
460 }
461
462 long ScintillaWX::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) {
463 switch (iMessage) {
464 case SCI_CALLTIPSHOW: {
465 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
466 // because of the little tweak that needs done below for wxGTK.
467 // When updating new versions double check that this is still
468 // needed, and that any new code there is copied here too.
469 Point pt = LocationFromPosition(wParam);
470 char* defn = reinterpret_cast<char *>(lParam);
471 AutoCompleteCancel();
472 pt.y += vs.lineHeight;
473 PRectangle rc = ct.CallTipStart(currentPos, pt,
474 defn,
475 vs.styles[STYLE_DEFAULT].fontName,
476 vs.styles[STYLE_DEFAULT].sizeZoomed,
477 IsUnicodeMode(),
478 wMain);
479 // If the call-tip window would be out of the client
480 // space, adjust so it displays above the text.
481 PRectangle rcClient = GetClientRectangle();
482 if (rc.bottom > rcClient.bottom) {
483 #ifdef __WXGTK__
484 int offset = int(vs.lineHeight * 1.25) + rc.Height();
485 #else
486 int offset = vs.lineHeight + rc.Height();
487 #endif
488 rc.top -= offset;
489 rc.bottom -= offset;
490 }
491 // Now display the window.
492 CreateCallTipWindow(rc);
493 ct.wCallTip.SetPositionRelative(rc, wMain);
494 ct.wCallTip.Show();
495 break;
496 }
497
498 #ifdef SCI_LEXER
499 case SCI_LOADLEXERLIBRARY:
500 LexerManager::GetInstance()->Load((const char*)lParam);
501 break;
502 #endif
503 default:
504 return ScintillaBase::WndProc(iMessage, wParam, lParam);
505 }
506 return 0;
507 }
508
509
510
511 //----------------------------------------------------------------------
512 // Event delegates
513
514 void ScintillaWX::DoPaint(wxDC* dc, wxRect rect) {
515
516 paintState = painting;
517 Surface* surfaceWindow = Surface::Allocate();
518 surfaceWindow->Init(dc, wMain.GetID());
519 rcPaint = PRectangleFromwxRect(rect);
520 PRectangle rcClient = GetClientRectangle();
521 paintingAllText = rcPaint.Contains(rcClient);
522
523 dc->BeginDrawing();
524 ClipChildren(*dc, rcPaint);
525 Paint(surfaceWindow, rcPaint);
526 dc->EndDrawing();
527
528 delete surfaceWindow;
529 if (paintState == paintAbandoned) {
530 // Painting area was insufficient to cover new styling or brace highlight positions
531 FullPaint();
532 }
533 paintState = notPainting;
534 }
535
536
537 void ScintillaWX::DoHScroll(int type, int pos) {
538 int xPos = xOffset;
539 PRectangle rcText = GetTextRectangle();
540 int pageWidth = rcText.Width() * 2 / 3;
541 if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)
542 xPos -= H_SCROLL_STEP;
543 else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN)
544 xPos += H_SCROLL_STEP;
545 else if (type == wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP)
546 xPos -= pageWidth;
547 else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN) {
548 xPos += pageWidth;
549 if (xPos > scrollWidth - rcText.Width()) {
550 xPos = scrollWidth - rcText.Width();
551 }
552 }
553 else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP)
554 xPos = 0;
555 else if (type == wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM)
556 xPos = scrollWidth;
557 else if (type == wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK)
558 xPos = pos;
559
560 HorizontalScrollTo(xPos);
561 }
562
563 void ScintillaWX::DoVScroll(int type, int pos) {
564 int topLineNew = topLine;
565 if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)
566 topLineNew -= 1;
567 else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN)
568 topLineNew += 1;
569 else if (type == wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP)
570 topLineNew -= LinesToScroll();
571 else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN)
572 topLineNew += LinesToScroll();
573 else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP)
574 topLineNew = 0;
575 else if (type == wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM)
576 topLineNew = MaxScrollPos();
577 else if (type == wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK)
578 topLineNew = pos;
579
580 ScrollTo(topLineNew);
581 }
582
583 void ScintillaWX::DoMouseWheel(int rotation, int delta,
584 int linesPerAction, int ctrlDown,
585 bool isPageScroll ) {
586 int topLineNew = topLine;
587 int lines;
588
589 if (ctrlDown) { // Zoom the fonts if Ctrl key down
590 if (rotation < 0) {
591 KeyCommand(SCI_ZOOMIN);
592 }
593 else {
594 KeyCommand(SCI_ZOOMOUT);
595 }
596 }
597 else { // otherwise just scroll the window
598 if ( !delta )
599 delta = 120;
600 wheelRotation += rotation;
601 lines = wheelRotation / delta;
602 wheelRotation -= lines * delta;
603 if (lines != 0) {
604 if (isPageScroll)
605 lines = lines * LinesOnScreen(); // lines is either +1 or -1
606 else
607 lines *= linesPerAction;
608 topLineNew -= lines;
609 ScrollTo(topLineNew);
610 }
611 }
612 }
613
614
615 void ScintillaWX::DoSize(int WXUNUSED(width), int WXUNUSED(height)) {
616 // PRectangle rcClient(0,0,width,height);
617 // SetScrollBarsTo(rcClient);
618 // DropGraphics();
619 ChangeSize();
620 }
621
622 void ScintillaWX::DoLoseFocus(){
623 focusEvent = true;
624 SetFocusState(false);
625 focusEvent = false;
626 }
627
628 void ScintillaWX::DoGainFocus(){
629 focusEvent = true;
630 SetFocusState(true);
631 focusEvent = false;
632 }
633
634 void ScintillaWX::DoSysColourChange() {
635 InvalidateStyleData();
636 }
637
638 void ScintillaWX::DoLeftButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) {
639 ButtonDown(pt, curTime, shift, ctrl, alt);
640 }
641
642 void ScintillaWX::DoLeftButtonUp(Point pt, unsigned int curTime, bool ctrl) {
643 ButtonUp(pt, curTime, ctrl);
644 }
645
646 void ScintillaWX::DoLeftButtonMove(Point pt) {
647 ButtonMove(pt);
648 }
649
650 #ifdef __WXGTK__
651 void ScintillaWX::DoMiddleButtonUp(Point pt) {
652 // Set the current position to the mouse click point and
653 // then paste in the PRIMARY selection, if any. wxGTK only.
654 int newPos = PositionFromLocation(pt);
655 MovePositionTo(newPos, 0, 1);
656
657 pdoc->BeginUndoAction();
658 wxTextDataObject data;
659 bool gotData = FALSE;
660 if (wxTheClipboard->Open()) {
661 wxTheClipboard->UsePrimarySelection(TRUE);
662 gotData = wxTheClipboard->GetData(data);
663 wxTheClipboard->UsePrimarySelection(FALSE);
664 wxTheClipboard->Close();
665 }
666 if (gotData) {
667 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(data.GetText());
668 int len = strlen(buf);
669 pdoc->InsertString(currentPos, buf, len);
670 SetEmptySelection(currentPos + len);
671 }
672 pdoc->EndUndoAction();
673 NotifyChange();
674 Redraw();
675
676 ShowCaretAtCurrentPosition();
677 EnsureCaretVisible();
678 }
679 #else
680 void ScintillaWX::DoMiddleButtonUp(Point WXUNUSED(pt)) {
681 }
682 #endif
683
684
685 void ScintillaWX::DoAddChar(int key) {
686 #if wxUSE_UNICODE
687 wxChar wszChars[2];
688 wszChars[0] = key;
689 wszChars[1] = 0;
690 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(wszChars);
691 AddCharUTF((char*)buf.data(), strlen(buf));
692 #else
693 AddChar(key);
694 #endif
695 }
696
697
698 #ifdef __WXMAC__
699 int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool meta, bool* consumed) {
700 #else
701 int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool WXUNUSED(meta), bool* consumed) {
702 #endif
703 #if defined(__WXGTK__) || defined(__WXMAC__)
704 // Ctrl chars (A-Z) end up with the wrong keycode on wxGTK
705 // TODO: Check this, it shouldn't be true any longer.
706 if (ctrl && key >= 1 && key <= 26)
707 key += 'A' - 1;
708 #endif
709
710 switch (key) {
711 case WXK_DOWN: key = SCK_DOWN; break;
712 case WXK_UP: key = SCK_UP; break;
713 case WXK_LEFT: key = SCK_LEFT; break;
714 case WXK_RIGHT: key = SCK_RIGHT; break;
715 case WXK_HOME: key = SCK_HOME; break;
716 case WXK_END: key = SCK_END; break;
717 case WXK_PAGEUP: // fall through
718 case WXK_PRIOR: key = SCK_PRIOR; break;
719 case WXK_PAGEDOWN: // fall through
720 case WXK_NEXT: key = SCK_NEXT; break;
721 case WXK_DELETE: key = SCK_DELETE; break;
722 case WXK_INSERT: key = SCK_INSERT; break;
723 case WXK_ESCAPE: key = SCK_ESCAPE; break;
724 case WXK_BACK: key = SCK_BACK; break;
725 case WXK_TAB: key = SCK_TAB; break;
726 case WXK_RETURN: key = SCK_RETURN; break;
727 case WXK_ADD: // fall through
728 case WXK_NUMPAD_ADD: key = SCK_ADD; break;
729 case WXK_SUBTRACT: // fall through
730 case WXK_NUMPAD_SUBTRACT: key = SCK_SUBTRACT; break;
731 case WXK_DIVIDE: // fall through
732 case WXK_NUMPAD_DIVIDE: key = SCK_DIVIDE; break;
733 case WXK_CONTROL: key = 0; break;
734 case WXK_ALT: key = 0; break;
735 case WXK_SHIFT: key = 0; break;
736 case WXK_MENU: key = 0; break;
737 }
738
739 #ifdef __WXMAC__
740 if ( meta ) {
741 // check for a few common Mac Meta-key combos and remap them to Ctrl
742 // for Scintilla
743 switch ( key ) {
744 case 'Z': // Undo
745 case 'X': // Cut
746 case 'C': // Copy
747 case 'V': // Paste
748 case 'A': // Select All
749 ctrl = true;
750 break;
751 }
752 }
753 #endif
754
755 int rv = KeyDown(key, shift, ctrl, alt, consumed);
756
757 if (key)
758 return rv;
759 else
760 return 1;
761 }
762
763
764 void ScintillaWX::DoCommand(int ID) {
765 Command(ID);
766 }
767
768
769 void ScintillaWX::DoContextMenu(Point pt) {
770 if (displayPopupMenu)
771 ContextMenu(pt);
772 }
773
774 void ScintillaWX::DoOnListBox() {
775 AutoCompleteCompleted();
776 }
777
778 //----------------------------------------------------------------------
779
780 #if wxUSE_DRAG_AND_DROP
781 bool ScintillaWX::DoDropText(long x, long y, const wxString& data) {
782 SetDragPosition(invalidPosition);
783
784 // Send an event to allow the drag details to be changed
785 wxStyledTextEvent evt(wxEVT_STC_DO_DROP, stc->GetId());
786 evt.SetEventObject(stc);
787 evt.SetDragResult(dragResult);
788 evt.SetX(x);
789 evt.SetY(y);
790 evt.SetPosition(PositionFromLocation(Point(x,y)));
791 evt.SetDragText(data);
792 stc->GetEventHandler()->ProcessEvent(evt);
793
794 dragResult = evt.GetDragResult();
795 if (dragResult == wxDragMove || dragResult == wxDragCopy) {
796 DropAt(evt.GetPosition(),
797 wx2stc(evt.GetDragText()),
798 dragResult == wxDragMove,
799 FALSE); // TODO: rectangular?
800 return TRUE;
801 }
802 return FALSE;
803 }
804
805
806 wxDragResult ScintillaWX::DoDragEnter(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxDragResult def) {
807 dragResult = def;
808 return dragResult;
809 }
810
811
812 wxDragResult ScintillaWX::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) {
813 SetDragPosition(PositionFromLocation(Point(x, y)));
814
815 // Send an event to allow the drag result to be changed
816 wxStyledTextEvent evt(wxEVT_STC_DRAG_OVER, stc->GetId());
817 evt.SetEventObject(stc);
818 evt.SetDragResult(def);
819 evt.SetX(x);
820 evt.SetY(y);
821 evt.SetPosition(PositionFromLocation(Point(x,y)));
822 stc->GetEventHandler()->ProcessEvent(evt);
823
824 dragResult = evt.GetDragResult();
825 return dragResult;
826 }
827
828
829 void ScintillaWX::DoDragLeave() {
830 SetDragPosition(invalidPosition);
831 }
832 #endif
833 //----------------------------------------------------------------------
834
835 // Redraw all of text area. This paint will not be abandoned.
836 void ScintillaWX::FullPaint() {
837 paintState = painting;
838 rcPaint = GetClientRectangle();
839 paintingAllText = true;
840 wxClientDC dc(stc);
841 Surface* surfaceWindow = Surface::Allocate();
842 surfaceWindow->Init(&dc, wMain.GetID());
843
844 dc.BeginDrawing();
845 ClipChildren(dc, rcPaint);
846 Paint(surfaceWindow, rcPaint);
847 dc.EndDrawing();
848
849 delete surfaceWindow;
850 paintState = notPainting;
851 }
852
853
854 void ScintillaWX::DoScrollToLine(int line) {
855 ScrollTo(line);
856 }
857
858
859 void ScintillaWX::DoScrollToColumn(int column) {
860 HorizontalScrollTo(column * vs.spaceWidth);
861 }
862
863 #ifdef __WXGTK__
864 void ScintillaWX::ClipChildren(wxDC& dc, PRectangle rect) {
865 wxRegion rgn(wxRectFromPRectangle(rect));
866 if (ac.Active()) {
867 wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
868 rgn.Subtract(childRect);
869 }
870 if (ct.inCallTipMode) {
871 wxRect childRect = ((wxWindow*)ct.wCallTip.GetID())->GetRect();
872 rgn.Subtract(childRect);
873 }
874
875 dc.SetClippingRegion(rgn);
876 }
877 #else
878 void ScintillaWX::ClipChildren(wxDC& WXUNUSED(dc), PRectangle WXUNUSED(rect)) {
879 }
880 #endif
881
882 //----------------------------------------------------------------------
883 //----------------------------------------------------------------------