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