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