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