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