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