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