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