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