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