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