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