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