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