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