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