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