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