Updated Scintilla to 1.52 (on the trunk this time too)
[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 const int H_SCROLL_STEP = 20;
257
258 bool ScintillaWX::ModifyScrollBars(int nMax, int nPage) {
259 bool modified = false;
260
261 // Check the vertical scrollbar
262 if (stc->m_vScrollBar == NULL) { // Use built-in scrollbar
263 int sbMax = stc->GetScrollRange(wxVERTICAL);
264 int sbThumb = stc->GetScrollThumb(wxVERTICAL);
265 int sbPos = stc->GetScrollPos(wxVERTICAL);
266 if (sbMax != nMax || sbThumb != nPage) {
267 stc->SetScrollbar(wxVERTICAL, sbPos, nPage, nMax+1);
268 modified = true;
269 }
270 }
271 else { // otherwise use the one that's been given to us
272 int sbMax = stc->m_vScrollBar->GetRange();
273 int sbPage = stc->m_vScrollBar->GetPageSize();
274 int sbPos = stc->m_vScrollBar->GetThumbPosition();
275 if (sbMax != nMax || sbPage != nPage) {
276 stc->m_vScrollBar->SetScrollbar(sbPos, nPage, nMax+1, nPage);
277 modified = true;
278 }
279 }
280
281
282 // Check the horizontal scrollbar
283 PRectangle rcText = GetTextRectangle();
284 int horizEnd = scrollWidth;
285 if (horizEnd < 0)
286 horizEnd = 0;
287 if (!horizontalScrollBarVisible || (wrapState != eWrapNone))
288 horizEnd = 0;
289 int pageWidth = rcText.Width();
290
291 if (stc->m_hScrollBar == NULL) { // Use built-in scrollbar
292 int sbMax = stc->GetScrollRange(wxHORIZONTAL);
293 int sbThumb = stc->GetScrollThumb(wxHORIZONTAL);
294 int sbPos = stc->GetScrollPos(wxHORIZONTAL);
295 if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) {
296 stc->SetScrollbar(wxHORIZONTAL, 0, pageWidth, horizEnd);
297 modified = true;
298 if (scrollWidth < pageWidth) {
299 HorizontalScrollTo(0);
300 }
301 }
302 }
303 else { // otherwise use the one that's been given to us
304 int sbMax = stc->m_hScrollBar->GetRange();
305 int sbThumb = stc->m_hScrollBar->GetPageSize();
306 int sbPos = stc->m_hScrollBar->GetThumbPosition();
307 if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) {
308 stc->m_hScrollBar->SetScrollbar(0, pageWidth, horizEnd, pageWidth);
309 modified = true;
310 if (scrollWidth < pageWidth) {
311 HorizontalScrollTo(0);
312 }
313 }
314 }
315
316 return modified;
317 }
318
319
320 void ScintillaWX::NotifyChange() {
321 stc->NotifyChange();
322 }
323
324
325 void ScintillaWX::NotifyParent(SCNotification scn) {
326 stc->NotifyParent(&scn);
327 }
328
329
330
331 void ScintillaWX::Copy() {
332 if (currentPos != anchor) {
333 SelectionText st;
334 CopySelectionRange(&st);
335 if (wxTheClipboard->Open()) {
336 wxTheClipboard->UsePrimarySelection(FALSE);
337 wxString text = stc2wx(st.s, st.len);
338 wxTheClipboard->SetData(new wxTextDataObject(text));
339 wxTheClipboard->Close();
340 }
341 }
342 }
343
344
345 void ScintillaWX::Paste() {
346 pdoc->BeginUndoAction();
347 ClearSelection();
348
349 wxTextDataObject data;
350 bool gotData = FALSE;
351
352 if (wxTheClipboard->Open()) {
353 wxTheClipboard->UsePrimarySelection(FALSE);
354 gotData = wxTheClipboard->GetData(data);
355 wxTheClipboard->Close();
356 }
357 if (gotData) {
358 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(data.GetText());
359 int len = strlen(buf);
360 pdoc->InsertString(currentPos, buf, len);
361 SetEmptySelection(currentPos + len);
362 }
363
364 pdoc->EndUndoAction();
365 NotifyChange();
366 Redraw();
367 }
368
369
370 bool ScintillaWX::CanPaste() {
371 bool canPaste = FALSE;
372 bool didOpen;
373
374 if ( (didOpen = !wxTheClipboard->IsOpened()) )
375 wxTheClipboard->Open();
376
377 if (wxTheClipboard->IsOpened()) {
378 wxTheClipboard->UsePrimarySelection(FALSE);
379 canPaste = wxTheClipboard->IsSupported(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT);
380 if (didOpen)
381 wxTheClipboard->Close();
382 }
383 return canPaste;
384 }
385
386 void ScintillaWX::CreateCallTipWindow(PRectangle) {
387 if (! ct.wCallTip.Created() ) {
388 ct.wCallTip = new wxSTCCallTip(stc, &ct, this);
389 ct.wDraw = ct.wCallTip;
390 }
391 }
392
393
394 void ScintillaWX::AddToPopUp(const char *label, int cmd, bool enabled) {
395 if (!label[0])
396 ((wxMenu*)popup.GetID())->AppendSeparator();
397 else
398 ((wxMenu*)popup.GetID())->Append(cmd, stc2wx(label));
399
400 if (!enabled)
401 ((wxMenu*)popup.GetID())->Enable(cmd, enabled);
402 }
403
404
405 // This is called by the Editor base class whenever something is selected
406 void ScintillaWX::ClaimSelection() {
407 #if 0
408 // Until wxGTK is able to support using both the primary selection and the
409 // clipboard at the same time I think it causes more problems than it is
410 // worth to implement this method. Selecting text should not clear the
411 // clipboard. --Robin
412 #ifdef __WXGTK__
413 // Put the selected text in the PRIMARY selection
414 if (currentPos != anchor) {
415 SelectionText st;
416 CopySelectionRange(&st);
417 if (wxTheClipboard->Open()) {
418 wxTheClipboard->UsePrimarySelection(TRUE);
419 wxString text = stc2wx(st.s, st.len);
420 wxTheClipboard->SetData(new wxTextDataObject(text));
421 wxTheClipboard->UsePrimarySelection(FALSE);
422 wxTheClipboard->Close();
423 }
424 }
425 #endif
426 #endif
427 }
428
429
430 long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
431 return 0;
432 }
433
434 long ScintillaWX::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) {
435 switch (iMessage) {
436 case SCI_CALLTIPSHOW: {
437 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
438 // because of the little tweak that needs done below for wxGTK.
439 // When updating new versions double check that this is still
440 // needed, and that any new code there is copied here too.
441 Point pt = LocationFromPosition(wParam);
442 char* defn = reinterpret_cast<char *>(lParam);
443 AutoCompleteCancel();
444 pt.y += vs.lineHeight;
445 PRectangle rc = ct.CallTipStart(currentPos, pt,
446 defn,
447 vs.styles[STYLE_DEFAULT].fontName,
448 vs.styles[STYLE_DEFAULT].sizeZoomed,
449 IsUnicodeMode(),
450 wMain);
451 // If the call-tip window would be out of the client
452 // space, adjust so it displays above the text.
453 PRectangle rcClient = GetClientRectangle();
454 if (rc.bottom > rcClient.bottom) {
455 #ifdef __WXGTK__
456 int offset = int(vs.lineHeight * 1.25) + rc.Height();
457 #else
458 int offset = vs.lineHeight + rc.Height();
459 #endif
460 rc.top -= offset;
461 rc.bottom -= offset;
462 }
463 // Now display the window.
464 CreateCallTipWindow(rc);
465 ct.wCallTip.SetPositionRelative(rc, wMain);
466 ct.wCallTip.Show();
467 break;
468 }
469
470 default:
471 return ScintillaBase::WndProc(iMessage, wParam, lParam);
472 }
473 return 0;
474 }
475
476
477
478 //----------------------------------------------------------------------
479 // Event delegates
480
481 void ScintillaWX::DoPaint(wxDC* dc, wxRect rect) {
482
483 paintState = painting;
484 Surface* surfaceWindow = Surface::Allocate();
485 surfaceWindow->Init(dc, wMain.GetID());
486 rcPaint = PRectangleFromwxRect(rect);
487 PRectangle rcClient = GetClientRectangle();
488 paintingAllText = rcPaint.Contains(rcClient);
489
490 dc->BeginDrawing();
491 ClipChildren(*dc, rcPaint);
492 Paint(surfaceWindow, rcPaint);
493 dc->EndDrawing();
494
495 delete surfaceWindow;
496 if (paintState == paintAbandoned) {
497 // Painting area was insufficient to cover new styling or brace highlight positions
498 FullPaint();
499 }
500 paintState = notPainting;
501 }
502
503
504 void ScintillaWX::DoHScroll(int type, int pos) {
505 int xPos = xOffset;
506 PRectangle rcText = GetTextRectangle();
507 int pageWidth = rcText.Width() * 2 / 3;
508 if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)
509 xPos -= H_SCROLL_STEP;
510 else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN)
511 xPos += H_SCROLL_STEP;
512 else if (type == wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP)
513 xPos -= pageWidth;
514 else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN) {
515 xPos += pageWidth;
516 if (xPos > scrollWidth - rcText.Width()) {
517 xPos = scrollWidth - rcText.Width();
518 }
519 }
520 else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP)
521 xPos = 0;
522 else if (type == wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM)
523 xPos = scrollWidth;
524 else if (type == wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK)
525 xPos = pos;
526
527 HorizontalScrollTo(xPos);
528 }
529
530 void ScintillaWX::DoVScroll(int type, int pos) {
531 int topLineNew = topLine;
532 if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)
533 topLineNew -= 1;
534 else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN)
535 topLineNew += 1;
536 else if (type == wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP)
537 topLineNew -= LinesToScroll();
538 else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN)
539 topLineNew += LinesToScroll();
540 else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP)
541 topLineNew = 0;
542 else if (type == wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM)
543 topLineNew = MaxScrollPos();
544 else if (type == wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK)
545 topLineNew = pos;
546
547 ScrollTo(topLineNew);
548 }
549
550 void ScintillaWX::DoMouseWheel(int rotation, int delta,
551 int linesPerAction, int ctrlDown,
552 bool isPageScroll ) {
553 int topLineNew = topLine;
554 int lines;
555
556 if (ctrlDown) { // Zoom the fonts if Ctrl key down
557 if (rotation < 0) {
558 KeyCommand(SCI_ZOOMIN);
559 }
560 else {
561 KeyCommand(SCI_ZOOMOUT);
562 }
563 }
564 else { // otherwise just scroll the window
565 if ( !delta )
566 delta = 120;
567 wheelRotation += rotation;
568 lines = wheelRotation / delta;
569 wheelRotation -= lines * delta;
570 if (lines != 0) {
571 if (isPageScroll)
572 lines = lines * LinesOnScreen(); // lines is either +1 or -1
573 else
574 lines *= linesPerAction;
575 topLineNew -= lines;
576 ScrollTo(topLineNew);
577 }
578 }
579 }
580
581
582 void ScintillaWX::DoSize(int width, int height) {
583 // PRectangle rcClient(0,0,width,height);
584 // SetScrollBarsTo(rcClient);
585 // DropGraphics();
586 ChangeSize();
587 }
588
589 void ScintillaWX::DoLoseFocus(){
590 SetFocusState(false);
591 }
592
593 void ScintillaWX::DoGainFocus(){
594 SetFocusState(true);
595 }
596
597 void ScintillaWX::DoSysColourChange() {
598 InvalidateStyleData();
599 }
600
601 void ScintillaWX::DoLeftButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) {
602 ButtonDown(pt, curTime, shift, ctrl, alt);
603 }
604
605 void ScintillaWX::DoLeftButtonUp(Point pt, unsigned int curTime, bool ctrl) {
606 ButtonUp(pt, curTime, ctrl);
607 }
608
609 void ScintillaWX::DoLeftButtonMove(Point pt) {
610 ButtonMove(pt);
611 }
612
613 void ScintillaWX::DoMiddleButtonUp(Point pt) {
614 #ifdef __WXGTK__
615 // Set the current position to the mouse click point and
616 // then paste in the PRIMARY selection, if any. wxGTK only.
617 int newPos = PositionFromLocation(pt);
618 MovePositionTo(newPos, 0, 1);
619
620 pdoc->BeginUndoAction();
621 wxTextDataObject data;
622 bool gotData = FALSE;
623 if (wxTheClipboard->Open()) {
624 wxTheClipboard->UsePrimarySelection(TRUE);
625 gotData = wxTheClipboard->GetData(data);
626 wxTheClipboard->UsePrimarySelection(FALSE);
627 wxTheClipboard->Close();
628 }
629 if (gotData) {
630 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(data.GetText());
631 int len = strlen(buf);
632 pdoc->InsertString(currentPos, buf, len);
633 SetEmptySelection(currentPos + len);
634 }
635 pdoc->EndUndoAction();
636 NotifyChange();
637 Redraw();
638
639 ShowCaretAtCurrentPosition();
640 EnsureCaretVisible();
641 #endif
642 }
643
644
645 void ScintillaWX::DoAddChar(int key) {
646 #if wxUSE_UNICODE
647 wxChar wszChars[2];
648 wszChars[0] = key;
649 wszChars[1] = 0;
650 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(wszChars);
651 AddCharUTF((char*)buf.data(), strlen(buf));
652 #else
653 AddChar(key);
654 #endif
655 }
656
657
658 int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool* consumed) {
659 #if defined(__WXGTK__) || defined(__WXMAC__)
660 // Ctrl chars (A-Z) end up with the wrong keycode on wxGTK...
661 if (ctrl && key >= 1 && key <= 26)
662 key += 'A' - 1;
663 #endif
664
665 switch (key) {
666 case WXK_DOWN: key = SCK_DOWN; break;
667 case WXK_UP: key = SCK_UP; break;
668 case WXK_LEFT: key = SCK_LEFT; break;
669 case WXK_RIGHT: key = SCK_RIGHT; break;
670 case WXK_HOME: key = SCK_HOME; break;
671 case WXK_END: key = SCK_END; break;
672 case WXK_PAGEUP: // fall through
673 case WXK_PRIOR: key = SCK_PRIOR; break;
674 case WXK_PAGEDOWN: // fall through
675 case WXK_NEXT: key = SCK_NEXT; break;
676 case WXK_DELETE: key = SCK_DELETE; break;
677 case WXK_INSERT: key = SCK_INSERT; break;
678 case WXK_ESCAPE: key = SCK_ESCAPE; break;
679 case WXK_BACK: key = SCK_BACK; break;
680 case WXK_TAB: key = SCK_TAB; break;
681 case WXK_RETURN: key = SCK_RETURN; break;
682 case WXK_ADD: // fall through
683 case WXK_NUMPAD_ADD: key = SCK_ADD; break;
684 case WXK_SUBTRACT: // fall through
685 case WXK_NUMPAD_SUBTRACT: key = SCK_SUBTRACT; break;
686 case WXK_DIVIDE: // fall through
687 case WXK_NUMPAD_DIVIDE: key = SCK_DIVIDE; break;
688 case WXK_CONTROL: key = 0; break;
689 case WXK_ALT: key = 0; break;
690 case WXK_SHIFT: key = 0; break;
691 case WXK_MENU: key = 0; break;
692 }
693
694 int rv = KeyDown(key, shift, ctrl, alt, consumed);
695
696 if (key)
697 return rv;
698 else
699 return 1;
700 }
701
702
703 void ScintillaWX::DoCommand(int ID) {
704 Command(ID);
705 }
706
707
708 void ScintillaWX::DoContextMenu(Point pt) {
709 if (displayPopupMenu)
710 ContextMenu(pt);
711 }
712
713 void ScintillaWX::DoOnListBox() {
714 AutoCompleteCompleted();
715 }
716
717 //----------------------------------------------------------------------
718
719 #if wxUSE_DRAG_AND_DROP
720 bool ScintillaWX::DoDropText(long x, long y, const wxString& data) {
721 SetDragPosition(invalidPosition);
722
723 // Send an event to allow the drag details to be changed
724 wxStyledTextEvent evt(wxEVT_STC_DO_DROP, stc->GetId());
725 evt.SetEventObject(stc);
726 evt.SetDragResult(dragResult);
727 evt.SetX(x);
728 evt.SetY(y);
729 evt.SetPosition(PositionFromLocation(Point(x,y)));
730 evt.SetDragText(data);
731 stc->GetEventHandler()->ProcessEvent(evt);
732
733 dragResult = evt.GetDragResult();
734 if (dragResult == wxDragMove || dragResult == wxDragCopy) {
735 DropAt(evt.GetPosition(),
736 wx2stc(evt.GetDragText()),
737 dragResult == wxDragMove,
738 FALSE); // TODO: rectangular?
739 return TRUE;
740 }
741 return FALSE;
742 }
743
744
745 wxDragResult ScintillaWX::DoDragEnter(wxCoord x, wxCoord y, wxDragResult def) {
746 dragResult = def;
747 return dragResult;
748 }
749
750
751 wxDragResult ScintillaWX::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) {
752 SetDragPosition(PositionFromLocation(Point(x, y)));
753
754 // Send an event to allow the drag result to be changed
755 wxStyledTextEvent evt(wxEVT_STC_DRAG_OVER, stc->GetId());
756 evt.SetEventObject(stc);
757 evt.SetDragResult(def);
758 evt.SetX(x);
759 evt.SetY(y);
760 evt.SetPosition(PositionFromLocation(Point(x,y)));
761 stc->GetEventHandler()->ProcessEvent(evt);
762
763 dragResult = evt.GetDragResult();
764 return dragResult;
765 }
766
767
768 void ScintillaWX::DoDragLeave() {
769 SetDragPosition(invalidPosition);
770 }
771 #endif
772 //----------------------------------------------------------------------
773
774 // Redraw all of text area. This paint will not be abandoned.
775 void ScintillaWX::FullPaint() {
776 paintState = painting;
777 rcPaint = GetClientRectangle();
778 paintingAllText = true;
779 wxClientDC dc(stc);
780 Surface* surfaceWindow = Surface::Allocate();
781 surfaceWindow->Init(&dc, wMain.GetID());
782
783 dc.BeginDrawing();
784 ClipChildren(dc, rcPaint);
785 Paint(surfaceWindow, rcPaint);
786 dc.EndDrawing();
787
788 delete surfaceWindow;
789 paintState = notPainting;
790 }
791
792
793 void ScintillaWX::DoScrollToLine(int line) {
794 ScrollTo(line);
795 }
796
797
798 void ScintillaWX::DoScrollToColumn(int column) {
799 HorizontalScrollTo(column * vs.spaceWidth);
800 }
801
802 void ScintillaWX::ClipChildren(wxDC& dc, PRectangle rect) {
803 #ifdef __WXGTK__
804 wxRegion rgn(wxRectFromPRectangle(rect));
805 if (ac.Active()) {
806 wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
807 rgn.Subtract(childRect);
808 }
809 if (ct.inCallTipMode) {
810 wxRect childRect = ((wxWindow*)ct.wCallTip.GetID())->GetRect();
811 rgn.Subtract(childRect);
812 }
813
814 dc.SetClippingRegion(rgn);
815 #endif
816 }
817
818
819 //----------------------------------------------------------------------
820 //----------------------------------------------------------------------