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