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