]> git.saurik.com Git - wxWidgets.git/blame - src/stc/ScintillaWX.cpp
attempts to fix separate compilation (didn't work)
[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
0b887a21
RD
379 if (Editor::CanPaste()) {
380 if ( (didOpen = !wxTheClipboard->IsOpened()) )
381 wxTheClipboard->Open();
45c6a927 382
0b887a21
RD
383 if (wxTheClipboard->IsOpened()) {
384 wxTheClipboard->UsePrimarySelection(FALSE);
385 canPaste = wxTheClipboard->IsSupported(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT);
386 if (didOpen)
387 wxTheClipboard->Close();
388 }
6ba338ec 389 }
9ce192d4
RD
390 return canPaste;
391}
392
393void ScintillaWX::CreateCallTipWindow(PRectangle) {
9e730a78
RD
394 if (! ct.wCallTip.Created() ) {
395 ct.wCallTip = new wxSTCCallTip(stc, &ct, this);
396 ct.wDraw = ct.wCallTip;
397 }
9ce192d4
RD
398}
399
400
401void ScintillaWX::AddToPopUp(const char *label, int cmd, bool enabled) {
402 if (!label[0])
1a2fb4cd 403 ((wxMenu*)popup.GetID())->AppendSeparator();
9ce192d4 404 else
0c5b83b0 405 ((wxMenu*)popup.GetID())->Append(cmd, stc2wx(label));
9ce192d4
RD
406
407 if (!enabled)
1a2fb4cd 408 ((wxMenu*)popup.GetID())->Enable(cmd, enabled);
9ce192d4
RD
409}
410
411
2b5f62a0 412// This is called by the Editor base class whenever something is selected
9ce192d4 413void ScintillaWX::ClaimSelection() {
f3030ba7
RD
414#if 0
415 // Until wxGTK is able to support using both the primary selection and the
416 // clipboard at the same time I think it causes more problems than it is
417 // worth to implement this method. Selecting text should not clear the
418 // clipboard. --Robin
2b5f62a0
VZ
419#ifdef __WXGTK__
420 // Put the selected text in the PRIMARY selection
421 if (currentPos != anchor) {
422 SelectionText st;
423 CopySelectionRange(&st);
424 if (wxTheClipboard->Open()) {
425 wxTheClipboard->UsePrimarySelection(TRUE);
426 wxString text = stc2wx(st.s, st.len);
427 wxTheClipboard->SetData(new wxTextDataObject(text));
428 wxTheClipboard->UsePrimarySelection(FALSE);
429 wxTheClipboard->Close();
430 }
431 }
432#endif
f3030ba7 433#endif
9ce192d4
RD
434}
435
436
d134f170 437long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
9ce192d4
RD
438 return 0;
439}
440
d134f170 441long ScintillaWX::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) {
fdec65df
RD
442 switch (iMessage) {
443 case SCI_CALLTIPSHOW: {
444 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
9e730a78
RD
445 // because of the little tweak that needs done below for wxGTK.
446 // When updating new versions double check that this is still
447 // needed, and that any new code there is copied here too.
448 Point pt = LocationFromPosition(wParam);
449 char* defn = reinterpret_cast<char *>(lParam);
fdec65df 450 AutoCompleteCancel();
9e730a78
RD
451 pt.y += vs.lineHeight;
452 PRectangle rc = ct.CallTipStart(currentPos, pt,
453 defn,
454 vs.styles[STYLE_DEFAULT].fontName,
455 vs.styles[STYLE_DEFAULT].sizeZoomed,
456 IsUnicodeMode(),
457 wMain);
458 // If the call-tip window would be out of the client
459 // space, adjust so it displays above the text.
460 PRectangle rcClient = GetClientRectangle();
461 if (rc.bottom > rcClient.bottom) {
fdec65df 462#ifdef __WXGTK__
9e730a78 463 int offset = int(vs.lineHeight * 1.25) + rc.Height();
fdec65df 464#else
9e730a78 465 int offset = vs.lineHeight + rc.Height();
fdec65df 466#endif
9e730a78
RD
467 rc.top -= offset;
468 rc.bottom -= offset;
fdec65df 469 }
9e730a78
RD
470 // Now display the window.
471 CreateCallTipWindow(rc);
472 ct.wCallTip.SetPositionRelative(rc, wMain);
473 ct.wCallTip.Show();
fdec65df 474 break;
9e730a78 475 }
fdec65df
RD
476
477 default:
478 return ScintillaBase::WndProc(iMessage, wParam, lParam);
479 }
480 return 0;
9ce192d4
RD
481}
482
483
484
485//----------------------------------------------------------------------
486// Event delegates
487
488void ScintillaWX::DoPaint(wxDC* dc, wxRect rect) {
489
490 paintState = painting;
1a2fb4cd 491 Surface* surfaceWindow = Surface::Allocate();
9e730a78
RD
492 surfaceWindow->Init(dc, wMain.GetID());
493 rcPaint = PRectangleFromwxRect(rect);
494 PRectangle rcClient = GetClientRectangle();
495 paintingAllText = rcPaint.Contains(rcClient);
496
9ce192d4 497 dc->BeginDrawing();
9e730a78 498 ClipChildren(*dc, rcPaint);
1a2fb4cd 499 Paint(surfaceWindow, rcPaint);
9ce192d4 500 dc->EndDrawing();
9e730a78 501
1a2fb4cd 502 delete surfaceWindow;
9ce192d4
RD
503 if (paintState == paintAbandoned) {
504 // Painting area was insufficient to cover new styling or brace highlight positions
505 FullPaint();
506 }
507 paintState = notPainting;
508}
509
510
511void ScintillaWX::DoHScroll(int type, int pos) {
512 int xPos = xOffset;
a834585d
RD
513 PRectangle rcText = GetTextRectangle();
514 int pageWidth = rcText.Width() * 2 / 3;
5fa4613c 515 if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)
9ce192d4 516 xPos -= H_SCROLL_STEP;
5fa4613c 517 else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN)
9ce192d4 518 xPos += H_SCROLL_STEP;
5fa4613c 519 else if (type == wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP)
a834585d
RD
520 xPos -= pageWidth;
521 else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN) {
522 xPos += pageWidth;
523 if (xPos > scrollWidth - rcText.Width()) {
524 xPos = scrollWidth - rcText.Width();
525 }
526 }
5fa4613c 527 else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP)
9ce192d4 528 xPos = 0;
5fa4613c 529 else if (type == wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM)
a834585d 530 xPos = scrollWidth;
5fa4613c 531 else if (type == wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK)
9ce192d4 532 xPos = pos;
ce1ecc6d 533
9ce192d4
RD
534 HorizontalScrollTo(xPos);
535}
536
537void ScintillaWX::DoVScroll(int type, int pos) {
538 int topLineNew = topLine;
5fa4613c 539 if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)
9ce192d4 540 topLineNew -= 1;
5fa4613c 541 else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN)
9ce192d4 542 topLineNew += 1;
5fa4613c 543 else if (type == wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP)
9ce192d4 544 topLineNew -= LinesToScroll();
5fa4613c 545 else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN)
9ce192d4 546 topLineNew += LinesToScroll();
5fa4613c 547 else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP)
9ce192d4 548 topLineNew = 0;
5fa4613c 549 else if (type == wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM)
9ce192d4 550 topLineNew = MaxScrollPos();
5fa4613c 551 else if (type == wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK)
9ce192d4 552 topLineNew = pos;
ce1ecc6d 553
9ce192d4
RD
554 ScrollTo(topLineNew);
555}
556
9b9337da
RD
557void ScintillaWX::DoMouseWheel(int rotation, int delta,
558 int linesPerAction, int ctrlDown,
559 bool isPageScroll ) {
37d62433
RD
560 int topLineNew = topLine;
561 int lines;
562
65ec6247
RD
563 if (ctrlDown) { // Zoom the fonts if Ctrl key down
564 if (rotation < 0) {
565 KeyCommand(SCI_ZOOMIN);
566 }
567 else {
568 KeyCommand(SCI_ZOOMOUT);
569 }
570 }
571 else { // otherwise just scroll the window
91f580b2
RD
572 if ( !delta )
573 delta = 120;
65ec6247
RD
574 wheelRotation += rotation;
575 lines = wheelRotation / delta;
576 wheelRotation -= lines * delta;
577 if (lines != 0) {
9b9337da
RD
578 if (isPageScroll)
579 lines = lines * LinesOnScreen(); // lines is either +1 or -1
580 else
581 lines *= linesPerAction;
65ec6247
RD
582 topLineNew -= lines;
583 ScrollTo(topLineNew);
584 }
37d62433
RD
585 }
586}
587
588
9ce192d4 589void ScintillaWX::DoSize(int width, int height) {
1a2fb4cd
RD
590// PRectangle rcClient(0,0,width,height);
591// SetScrollBarsTo(rcClient);
592// DropGraphics();
593 ChangeSize();
9ce192d4
RD
594}
595
596void ScintillaWX::DoLoseFocus(){
65ec6247 597 SetFocusState(false);
9ce192d4
RD
598}
599
600void ScintillaWX::DoGainFocus(){
65ec6247 601 SetFocusState(true);
9ce192d4
RD
602}
603
604void ScintillaWX::DoSysColourChange() {
605 InvalidateStyleData();
606}
607
2b5f62a0 608void ScintillaWX::DoLeftButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) {
9ce192d4
RD
609 ButtonDown(pt, curTime, shift, ctrl, alt);
610}
611
2b5f62a0 612void ScintillaWX::DoLeftButtonUp(Point pt, unsigned int curTime, bool ctrl) {
9ce192d4
RD
613 ButtonUp(pt, curTime, ctrl);
614}
615
2b5f62a0 616void ScintillaWX::DoLeftButtonMove(Point pt) {
9ce192d4
RD
617 ButtonMove(pt);
618}
619
2b5f62a0
VZ
620void ScintillaWX::DoMiddleButtonUp(Point pt) {
621#ifdef __WXGTK__
622 // Set the current position to the mouse click point and
623 // then paste in the PRIMARY selection, if any. wxGTK only.
624 int newPos = PositionFromLocation(pt);
625 MovePositionTo(newPos, 0, 1);
626
627 pdoc->BeginUndoAction();
628 wxTextDataObject data;
629 bool gotData = FALSE;
630 if (wxTheClipboard->Open()) {
631 wxTheClipboard->UsePrimarySelection(TRUE);
632 gotData = wxTheClipboard->GetData(data);
633 wxTheClipboard->UsePrimarySelection(FALSE);
634 wxTheClipboard->Close();
635 }
636 if (gotData) {
637 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(data.GetText());
638 int len = strlen(buf);
639 pdoc->InsertString(currentPos, buf, len);
640 SetEmptySelection(currentPos + len);
641 }
642 pdoc->EndUndoAction();
643 NotifyChange();
644 Redraw();
645
646 ShowCaretAtCurrentPosition();
647 EnsureCaretVisible();
648#endif
649}
650
9ce192d4 651
10ef30eb 652void ScintillaWX::DoAddChar(int key) {
2b5f62a0 653#if wxUSE_UNICODE
fdec65df
RD
654 wxChar wszChars[2];
655 wszChars[0] = key;
656 wszChars[1] = 0;
657 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(wszChars);
2b5f62a0
VZ
658 AddCharUTF((char*)buf.data(), strlen(buf));
659#else
10ef30eb 660 AddChar(key);
2b5f62a0 661#endif
9ce192d4
RD
662}
663
2b5f62a0 664
65ec6247 665int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool* consumed) {
451c5cc7 666#if defined(__WXGTK__) || defined(__WXMAC__)
39178e3b
RD
667 // Ctrl chars (A-Z) end up with the wrong keycode on wxGTK...
668 if (ctrl && key >= 1 && key <= 26)
669 key += 'A' - 1;
670#endif
671
d134f170 672 switch (key) {
0b9dfbc0
RD
673 case WXK_DOWN: key = SCK_DOWN; break;
674 case WXK_UP: key = SCK_UP; break;
675 case WXK_LEFT: key = SCK_LEFT; break;
676 case WXK_RIGHT: key = SCK_RIGHT; break;
677 case WXK_HOME: key = SCK_HOME; break;
678 case WXK_END: key = SCK_END; break;
c9c50e23 679 case WXK_PAGEUP: // fall through
0b9dfbc0 680 case WXK_PRIOR: key = SCK_PRIOR; break;
c9c50e23 681 case WXK_PAGEDOWN: // fall through
0b9dfbc0
RD
682 case WXK_NEXT: key = SCK_NEXT; break;
683 case WXK_DELETE: key = SCK_DELETE; break;
684 case WXK_INSERT: key = SCK_INSERT; break;
685 case WXK_ESCAPE: key = SCK_ESCAPE; break;
686 case WXK_BACK: key = SCK_BACK; break;
687 case WXK_TAB: key = SCK_TAB; break;
688 case WXK_RETURN: key = SCK_RETURN; break;
689 case WXK_ADD: // fall through
690 case WXK_NUMPAD_ADD: key = SCK_ADD; break;
691 case WXK_SUBTRACT: // fall through
692 case WXK_NUMPAD_SUBTRACT: key = SCK_SUBTRACT; break;
693 case WXK_DIVIDE: // fall through
694 case WXK_NUMPAD_DIVIDE: key = SCK_DIVIDE; break;
695 case WXK_CONTROL: key = 0; break;
696 case WXK_ALT: key = 0; break;
697 case WXK_SHIFT: key = 0; break;
698 case WXK_MENU: key = 0; break;
d134f170
RD
699 }
700
d6582821 701 int rv = KeyDown(key, shift, ctrl, alt, consumed);
0122b7e3 702
d6582821
RD
703 if (key)
704 return rv;
705 else
706 return 1;
9ce192d4
RD
707}
708
709
710void ScintillaWX::DoCommand(int ID) {
711 Command(ID);
712}
713
714
715void ScintillaWX::DoContextMenu(Point pt) {
752cd08c
RD
716 if (displayPopupMenu)
717 ContextMenu(pt);
9ce192d4
RD
718}
719
f6bcfd97
BP
720void ScintillaWX::DoOnListBox() {
721 AutoCompleteCompleted();
722}
9ce192d4
RD
723
724//----------------------------------------------------------------------
725
1bc32508 726#if wxUSE_DRAG_AND_DROP
9ce192d4
RD
727bool ScintillaWX::DoDropText(long x, long y, const wxString& data) {
728 SetDragPosition(invalidPosition);
a29a241f
RD
729
730 // Send an event to allow the drag details to be changed
731 wxStyledTextEvent evt(wxEVT_STC_DO_DROP, stc->GetId());
732 evt.SetEventObject(stc);
733 evt.SetDragResult(dragResult);
734 evt.SetX(x);
735 evt.SetY(y);
736 evt.SetPosition(PositionFromLocation(Point(x,y)));
737 evt.SetDragText(data);
738 stc->GetEventHandler()->ProcessEvent(evt);
739
740 dragResult = evt.GetDragResult();
741 if (dragResult == wxDragMove || dragResult == wxDragCopy) {
742 DropAt(evt.GetPosition(),
0c5b83b0 743 wx2stc(evt.GetDragText()),
a29a241f
RD
744 dragResult == wxDragMove,
745 FALSE); // TODO: rectangular?
746 return TRUE;
747 }
748 return FALSE;
9ce192d4
RD
749}
750
751
752wxDragResult ScintillaWX::DoDragEnter(wxCoord x, wxCoord y, wxDragResult def) {
b8b0e402
RD
753 dragResult = def;
754 return dragResult;
9ce192d4
RD
755}
756
757
758wxDragResult ScintillaWX::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) {
759 SetDragPosition(PositionFromLocation(Point(x, y)));
a29a241f
RD
760
761 // Send an event to allow the drag result to be changed
762 wxStyledTextEvent evt(wxEVT_STC_DRAG_OVER, stc->GetId());
763 evt.SetEventObject(stc);
764 evt.SetDragResult(def);
765 evt.SetX(x);
766 evt.SetY(y);
767 evt.SetPosition(PositionFromLocation(Point(x,y)));
768 stc->GetEventHandler()->ProcessEvent(evt);
769
770 dragResult = evt.GetDragResult();
b8b0e402 771 return dragResult;
9ce192d4
RD
772}
773
774
775void ScintillaWX::DoDragLeave() {
776 SetDragPosition(invalidPosition);
777}
1bc32508 778#endif
9ce192d4
RD
779//----------------------------------------------------------------------
780
781// Redraw all of text area. This paint will not be abandoned.
782void ScintillaWX::FullPaint() {
783 paintState = painting;
9e730a78 784 rcPaint = GetClientRectangle();
a7642be1 785 paintingAllText = true;
5fa4613c 786 wxClientDC dc(stc);
1a2fb4cd 787 Surface* surfaceWindow = Surface::Allocate();
9e730a78 788 surfaceWindow->Init(&dc, wMain.GetID());
a7642be1 789
9e730a78
RD
790 dc.BeginDrawing();
791 ClipChildren(dc, rcPaint);
792 Paint(surfaceWindow, rcPaint);
793 dc.EndDrawing();
a7642be1 794
9e730a78 795 delete surfaceWindow;
9ce192d4
RD
796 paintState = notPainting;
797}
798
799
800void ScintillaWX::DoScrollToLine(int line) {
801 ScrollTo(line);
802}
803
804
805void ScintillaWX::DoScrollToColumn(int column) {
806 HorizontalScrollTo(column * vs.spaceWidth);
807}
808
9e730a78
RD
809void ScintillaWX::ClipChildren(wxDC& dc, PRectangle rect) {
810#ifdef __WXGTK__
811 wxRegion rgn(wxRectFromPRectangle(rect));
812 if (ac.Active()) {
813 wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
814 rgn.Subtract(childRect);
815 }
816 if (ct.inCallTipMode) {
817 wxRect childRect = ((wxWindow*)ct.wCallTip.GetID())->GetRect();
818 rgn.Subtract(childRect);
819 }
820
821 dc.SetClippingRegion(rgn);
822#endif
823}
9ce192d4
RD
824
825
826//----------------------------------------------------------------------
827//----------------------------------------------------------------------