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