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