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