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