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