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