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