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