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