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