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