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