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