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