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