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