]>
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 | //---------------------------------------------------------------------- | |
24 | ||
25 | const int H_SCROLL_MAX = 4000; | |
26 | const int H_SCROLL_STEP = 20; | |
27 | const int H_SCROLL_PAGE = 200; | |
28 | ||
29 | //---------------------------------------------------------------------- | |
30 | // Helper classes | |
31 | ||
32 | class wxSTCTimer : public wxTimer { | |
33 | public: | |
34 | wxSTCTimer(ScintillaWX* swx) { | |
35 | this->swx = swx; | |
36 | } | |
37 | ||
38 | void Notify() { | |
39 | swx->DoTick(); | |
40 | } | |
41 | ||
42 | private: | |
43 | ScintillaWX* swx; | |
44 | }; | |
45 | ||
46 | ||
47 | #if wxUSE_DRAG_AND_DROP | |
48 | bool wxSTCDropTarget::OnDropText(wxCoord x, wxCoord y, const wxString& data) { | |
49 | return swx->DoDropText(x, y, data); | |
50 | } | |
51 | ||
52 | wxDragResult wxSTCDropTarget::OnEnter(wxCoord x, wxCoord y, wxDragResult def) { | |
53 | return swx->DoDragEnter(x, y, def); | |
54 | } | |
55 | ||
56 | wxDragResult wxSTCDropTarget::OnDragOver(wxCoord x, wxCoord y, wxDragResult def) { | |
57 | return swx->DoDragOver(x, y, def); | |
58 | } | |
59 | ||
60 | void wxSTCDropTarget::OnLeave() { | |
61 | swx->DoDragLeave(); | |
62 | } | |
63 | #endif | |
64 | ||
65 | ||
66 | #if wxUSE_POPUPWIN && wxSTC_USE_POPUP | |
67 | #include <wx/popupwin.h> | |
68 | #define wxSTCCallTipBase wxPopupWindow | |
69 | #define param2 wxBORDER_NONE // popup's 2nd param is flags | |
70 | #else | |
71 | #define wxSTCCallTipBase wxWindow | |
72 | #define param2 -1 // wxWindows 2nd param is ID | |
73 | #endif | |
74 | ||
75 | class wxSTCCallTip : public wxSTCCallTipBase { | |
76 | public: | |
77 | wxSTCCallTip(wxWindow* parent, CallTip* ct) | |
78 | : wxSTCCallTipBase(parent, param2) | |
79 | { | |
80 | m_ct = ct; | |
81 | } | |
82 | ||
83 | ~wxSTCCallTip() { | |
84 | if (HasCapture()) ReleaseMouse(); | |
85 | } | |
86 | ||
87 | void OnPaint(wxPaintEvent& evt) { | |
88 | wxPaintDC dc(this); | |
89 | Surface* surfaceWindow = Surface::Allocate(); | |
90 | surfaceWindow->Init(&dc); | |
91 | m_ct->PaintCT(surfaceWindow); | |
92 | delete surfaceWindow; | |
93 | } | |
94 | ||
95 | void OnFocus(wxFocusEvent& event) { | |
96 | GetParent()->SetFocus(); | |
97 | event.Skip(); | |
98 | } | |
99 | ||
100 | #if wxUSE_POPUPWIN && wxSTC_USE_POPUP | |
101 | virtual void DoSetSize(int x, int y, | |
102 | int width, int height, | |
103 | int sizeFlags = wxSIZE_AUTO) { | |
104 | if (x != -1) | |
105 | GetParent()->ClientToScreen(&x, NULL); | |
106 | if (y != -1) | |
107 | GetParent()->ClientToScreen(NULL, &y); | |
108 | wxSTCCallTipBase::DoSetSize(x, y, width, height, sizeFlags); | |
109 | } | |
110 | ||
111 | virtual bool Show( bool show = TRUE ) { | |
112 | bool retval = wxSTCCallTipBase::Show(show); | |
113 | if (show) | |
114 | CaptureMouse(); | |
115 | else | |
116 | if (HasCapture()) ReleaseMouse(); | |
117 | return retval; | |
118 | } | |
119 | ||
120 | void OnLeftDown(wxMouseEvent& ) { | |
121 | Show(FALSE); | |
122 | } | |
123 | #endif | |
124 | ||
125 | private: | |
126 | CallTip* m_ct; | |
127 | DECLARE_EVENT_TABLE() | |
128 | }; | |
129 | ||
130 | BEGIN_EVENT_TABLE(wxSTCCallTip, wxSTCCallTipBase) | |
131 | EVT_PAINT(wxSTCCallTip::OnPaint) | |
132 | EVT_SET_FOCUS(wxSTCCallTip::OnFocus) | |
133 | #if wxUSE_POPUPWIN && wxSTC_USE_POPUP | |
134 | EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown) | |
135 | #endif | |
136 | END_EVENT_TABLE() | |
137 | ||
138 | ||
139 | //---------------------------------------------------------------------- | |
140 | // Constructor/Destructor | |
141 | ||
142 | ||
143 | ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) { | |
144 | capturedMouse = false; | |
145 | wMain = win; | |
146 | stc = win; | |
147 | wheelRotation = 0; | |
148 | Initialise(); | |
149 | } | |
150 | ||
151 | ||
152 | ScintillaWX::~ScintillaWX() { | |
153 | SetTicking(false); | |
154 | } | |
155 | ||
156 | //---------------------------------------------------------------------- | |
157 | // base class virtuals | |
158 | ||
159 | ||
160 | void ScintillaWX::Initialise() { | |
161 | //ScintillaBase::Initialise(); | |
162 | #if wxUSE_DRAG_AND_DROP | |
163 | dropTarget = new wxSTCDropTarget; | |
164 | dropTarget->SetScintilla(this); | |
165 | stc->SetDropTarget(dropTarget); | |
166 | #endif | |
167 | } | |
168 | ||
169 | ||
170 | void ScintillaWX::Finalise() { | |
171 | ScintillaBase::Finalise(); | |
172 | } | |
173 | ||
174 | ||
175 | void ScintillaWX::StartDrag() { | |
176 | #if wxUSE_DRAG_AND_DROP | |
177 | wxString dragText = stc2wx(drag.s, drag.len); | |
178 | ||
179 | // Send an event to allow the drag text to be changed | |
180 | wxStyledTextEvent evt(wxEVT_STC_START_DRAG, stc->GetId()); | |
181 | evt.SetEventObject(stc); | |
182 | evt.SetDragText(dragText); | |
183 | evt.SetDragAllowMove(TRUE); | |
184 | evt.SetPosition(wxMin(stc->GetSelectionStart(), | |
185 | stc->GetSelectionEnd())); | |
186 | stc->GetEventHandler()->ProcessEvent(evt); | |
187 | dragText = evt.GetDragText(); | |
188 | ||
189 | if (dragText.Length()) { | |
190 | wxDropSource source(stc); | |
191 | wxTextDataObject data(dragText); | |
192 | wxDragResult result; | |
193 | ||
194 | source.SetData(data); | |
195 | dropWentOutside = TRUE; | |
196 | result = source.DoDragDrop(evt.GetDragAllowMove()); | |
197 | if (result == wxDragMove && dropWentOutside) | |
198 | ClearSelection(); | |
199 | inDragDrop = FALSE; | |
200 | SetDragPosition(invalidPosition); | |
201 | } | |
202 | #endif | |
203 | } | |
204 | ||
205 | ||
206 | void ScintillaWX::SetTicking(bool on) { | |
207 | wxSTCTimer* steTimer; | |
208 | if (timer.ticking != on) { | |
209 | timer.ticking = on; | |
210 | if (timer.ticking) { | |
211 | steTimer = new wxSTCTimer(this); | |
212 | steTimer->Start(timer.tickSize); | |
213 | timer.tickerID = steTimer; | |
214 | } else { | |
215 | steTimer = (wxSTCTimer*)timer.tickerID; | |
216 | steTimer->Stop(); | |
217 | delete steTimer; | |
218 | timer.tickerID = 0; | |
219 | } | |
220 | } | |
221 | timer.ticksToWait = caret.period; | |
222 | } | |
223 | ||
224 | ||
225 | void ScintillaWX::SetMouseCapture(bool on) { | |
226 | if (on && !capturedMouse) | |
227 | stc->CaptureMouse(); | |
228 | else if (!on && capturedMouse) | |
229 | stc->ReleaseMouse(); | |
230 | capturedMouse = on; | |
231 | } | |
232 | ||
233 | ||
234 | bool ScintillaWX::HaveMouseCapture() { | |
235 | return capturedMouse; | |
236 | } | |
237 | ||
238 | ||
239 | void ScintillaWX::ScrollText(int linesToMove) { | |
240 | int dy = vs.lineHeight * (linesToMove); | |
241 | stc->ScrollWindow(0, dy); | |
242 | stc->Update(); | |
243 | } | |
244 | ||
245 | void ScintillaWX::SetVerticalScrollPos() { | |
246 | if (stc->m_vScrollBar == NULL) { // Use built-in scrollbar | |
247 | stc->SetScrollPos(wxVERTICAL, topLine); | |
248 | } | |
249 | else { // otherwise use the one that's been given to us | |
250 | stc->m_vScrollBar->SetThumbPosition(topLine); | |
251 | } | |
252 | } | |
253 | ||
254 | void ScintillaWX::SetHorizontalScrollPos() { | |
255 | if (stc->m_hScrollBar == NULL) { // Use built-in scrollbar | |
256 | stc->SetScrollPos(wxHORIZONTAL, xOffset); | |
257 | } | |
258 | else { // otherwise use the one that's been given to us | |
259 | stc->m_hScrollBar->SetThumbPosition(xOffset); | |
260 | } | |
261 | } | |
262 | ||
263 | ||
264 | bool ScintillaWX::ModifyScrollBars(int nMax, int nPage) { | |
265 | bool modified = false; | |
266 | ||
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 != nMax || sbThumb != nPage) { | |
272 | stc->SetScrollbar(wxVERTICAL, sbPos, nPage, nMax); | |
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 != nMax || sbPage != nPage) { | |
281 | stc->m_vScrollBar->SetScrollbar(sbPos, nPage, nMax, nPage); | |
282 | modified = true; | |
283 | } | |
284 | } | |
285 | ||
286 | ||
287 | if (horizontalScrollBarVisible) { | |
288 | if (stc->m_hScrollBar == NULL) { // Use built-in scrollbar | |
289 | int sbMax = stc->GetScrollRange(wxHORIZONTAL); | |
290 | int sbThumb = stc->GetScrollThumb(wxHORIZONTAL); | |
291 | if ((sbMax != H_SCROLL_MAX) || (sbThumb != H_SCROLL_STEP)) { | |
292 | stc->SetScrollbar(wxHORIZONTAL, 0, H_SCROLL_STEP, H_SCROLL_MAX); | |
293 | modified = true; | |
294 | } | |
295 | } | |
296 | else { // otherwise use the one that's been given to us | |
297 | int sbMax = stc->m_hScrollBar->GetRange(); | |
298 | int sbPage = stc->m_hScrollBar->GetPageSize(); | |
299 | if ((sbMax != H_SCROLL_MAX) || (sbPage != H_SCROLL_STEP)) { | |
300 | stc->m_hScrollBar->SetScrollbar(0, H_SCROLL_STEP, H_SCROLL_MAX, H_SCROLL_STEP); | |
301 | modified = true; | |
302 | } | |
303 | } | |
304 | } | |
305 | return modified; | |
306 | } | |
307 | ||
308 | ||
309 | void ScintillaWX::NotifyChange() { | |
310 | stc->NotifyChange(); | |
311 | } | |
312 | ||
313 | ||
314 | void ScintillaWX::NotifyParent(SCNotification scn) { | |
315 | stc->NotifyParent(&scn); | |
316 | } | |
317 | ||
318 | ||
319 | ||
320 | void ScintillaWX::Copy() { | |
321 | if (currentPos != anchor) { | |
322 | SelectionText st; | |
323 | CopySelectionRange(&st); | |
324 | wxTheClipboard->Open(); | |
325 | wxTheClipboard->UsePrimarySelection(); | |
326 | wxString text = stc2wx(st.s, st.len); | |
327 | wxTheClipboard->SetData(new wxTextDataObject(text)); | |
328 | wxTheClipboard->Close(); | |
329 | } | |
330 | } | |
331 | ||
332 | ||
333 | void ScintillaWX::Paste() { | |
334 | pdoc->BeginUndoAction(); | |
335 | ClearSelection(); | |
336 | ||
337 | wxTextDataObject data; | |
338 | bool gotData; | |
339 | ||
340 | wxTheClipboard->Open(); | |
341 | wxTheClipboard->UsePrimarySelection(); | |
342 | gotData = wxTheClipboard->GetData(data); | |
343 | wxTheClipboard->Close(); | |
344 | if (gotData) { | |
345 | wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(data.GetText()); | |
346 | int len = strlen(buf); | |
347 | pdoc->InsertString(currentPos, buf, len); | |
348 | SetEmptySelection(currentPos + len); | |
349 | } | |
350 | ||
351 | pdoc->EndUndoAction(); | |
352 | NotifyChange(); | |
353 | Redraw(); | |
354 | } | |
355 | ||
356 | ||
357 | bool ScintillaWX::CanPaste() { | |
358 | bool canPaste; | |
359 | ||
360 | wxTheClipboard->Open(); | |
361 | wxTheClipboard->UsePrimarySelection(); | |
362 | canPaste = wxTheClipboard->IsSupported(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT); | |
363 | wxTheClipboard->Close(); | |
364 | ||
365 | return canPaste; | |
366 | } | |
367 | ||
368 | void ScintillaWX::CreateCallTipWindow(PRectangle) { | |
369 | ct.wCallTip = new wxSTCCallTip(stc, &ct); | |
370 | ct.wDraw = ct.wCallTip; | |
371 | } | |
372 | ||
373 | ||
374 | void ScintillaWX::AddToPopUp(const char *label, int cmd, bool enabled) { | |
375 | if (!label[0]) | |
376 | ((wxMenu*)popup.GetID())->AppendSeparator(); | |
377 | else | |
378 | ((wxMenu*)popup.GetID())->Append(cmd, stc2wx(label)); | |
379 | ||
380 | if (!enabled) | |
381 | ((wxMenu*)popup.GetID())->Enable(cmd, enabled); | |
382 | } | |
383 | ||
384 | ||
385 | void ScintillaWX::ClaimSelection() { | |
386 | ||
387 | } | |
388 | ||
389 | ||
390 | long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) { | |
391 | return 0; | |
392 | } | |
393 | ||
394 | long ScintillaWX::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { | |
395 | // switch (iMessage) { | |
396 | // case EM_CANPASTE: | |
397 | // return CanPaste(); | |
398 | // default: | |
399 | return ScintillaBase::WndProc(iMessage, wParam, lParam); | |
400 | // } | |
401 | // return 0; | |
402 | } | |
403 | ||
404 | ||
405 | ||
406 | //---------------------------------------------------------------------- | |
407 | // Event delegates | |
408 | ||
409 | void ScintillaWX::DoPaint(wxDC* dc, wxRect rect) { | |
410 | ||
411 | paintState = painting; | |
412 | Surface* surfaceWindow = Surface::Allocate(); | |
413 | surfaceWindow->Init(dc); | |
414 | PRectangle rcPaint = PRectangleFromwxRect(rect); | |
415 | dc->BeginDrawing(); | |
416 | Paint(surfaceWindow, rcPaint); | |
417 | dc->EndDrawing(); | |
418 | delete surfaceWindow; | |
419 | if (paintState == paintAbandoned) { | |
420 | // Painting area was insufficient to cover new styling or brace highlight positions | |
421 | FullPaint(); | |
422 | } | |
423 | paintState = notPainting; | |
424 | #ifdef __WXGTK__ | |
425 | // On wxGTK the editor window paints can overwrite the listbox... | |
426 | if (ac.Active()) | |
427 | ((wxWindow*)ac.lb.GetID())->Refresh(TRUE); | |
428 | #endif | |
429 | } | |
430 | ||
431 | ||
432 | void ScintillaWX::DoHScroll(int type, int pos) { | |
433 | int xPos = xOffset; | |
434 | if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP) | |
435 | xPos -= H_SCROLL_STEP; | |
436 | else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN) | |
437 | xPos += H_SCROLL_STEP; | |
438 | else if (type == wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP) | |
439 | xPos -= H_SCROLL_PAGE; | |
440 | else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN) | |
441 | xPos += H_SCROLL_PAGE; | |
442 | else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP) | |
443 | xPos = 0; | |
444 | else if (type == wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM) | |
445 | xPos = H_SCROLL_MAX; | |
446 | else if (type == wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK) | |
447 | xPos = pos; | |
448 | ||
449 | HorizontalScrollTo(xPos); | |
450 | } | |
451 | ||
452 | void ScintillaWX::DoVScroll(int type, int pos) { | |
453 | int topLineNew = topLine; | |
454 | if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP) | |
455 | topLineNew -= 1; | |
456 | else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN) | |
457 | topLineNew += 1; | |
458 | else if (type == wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP) | |
459 | topLineNew -= LinesToScroll(); | |
460 | else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN) | |
461 | topLineNew += LinesToScroll(); | |
462 | else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP) | |
463 | topLineNew = 0; | |
464 | else if (type == wxEVT_SCROLLWIN_BOTTOM || type == wxEVT_SCROLL_BOTTOM) | |
465 | topLineNew = MaxScrollPos(); | |
466 | else if (type == wxEVT_SCROLLWIN_THUMBTRACK || type == wxEVT_SCROLL_THUMBTRACK) | |
467 | topLineNew = pos; | |
468 | ||
469 | ScrollTo(topLineNew); | |
470 | } | |
471 | ||
472 | void ScintillaWX::DoMouseWheel(int rotation, int delta, | |
473 | int linesPerAction, int ctrlDown, | |
474 | bool isPageScroll ) { | |
475 | int topLineNew = topLine; | |
476 | int lines; | |
477 | ||
478 | if (ctrlDown) { // Zoom the fonts if Ctrl key down | |
479 | if (rotation < 0) { | |
480 | KeyCommand(SCI_ZOOMIN); | |
481 | } | |
482 | else { | |
483 | KeyCommand(SCI_ZOOMOUT); | |
484 | } | |
485 | } | |
486 | else { // otherwise just scroll the window | |
487 | wheelRotation += rotation; | |
488 | lines = wheelRotation / delta; | |
489 | wheelRotation -= lines * delta; | |
490 | if (lines != 0) { | |
491 | if (isPageScroll) | |
492 | lines = lines * LinesOnScreen(); // lines is either +1 or -1 | |
493 | else | |
494 | lines *= linesPerAction; | |
495 | topLineNew -= lines; | |
496 | ScrollTo(topLineNew); | |
497 | } | |
498 | } | |
499 | } | |
500 | ||
501 | ||
502 | void ScintillaWX::DoSize(int width, int height) { | |
503 | // PRectangle rcClient(0,0,width,height); | |
504 | // SetScrollBarsTo(rcClient); | |
505 | // DropGraphics(); | |
506 | ChangeSize(); | |
507 | } | |
508 | ||
509 | void ScintillaWX::DoLoseFocus(){ | |
510 | SetFocusState(false); | |
511 | } | |
512 | ||
513 | void ScintillaWX::DoGainFocus(){ | |
514 | SetFocusState(true); | |
515 | } | |
516 | ||
517 | void ScintillaWX::DoSysColourChange() { | |
518 | InvalidateStyleData(); | |
519 | } | |
520 | ||
521 | void ScintillaWX::DoButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) { | |
522 | ButtonDown(pt, curTime, shift, ctrl, alt); | |
523 | } | |
524 | ||
525 | void ScintillaWX::DoButtonUp(Point pt, unsigned int curTime, bool ctrl) { | |
526 | ButtonUp(pt, curTime, ctrl); | |
527 | } | |
528 | ||
529 | void ScintillaWX::DoButtonMove(Point pt) { | |
530 | ButtonMove(pt); | |
531 | } | |
532 | ||
533 | ||
534 | void ScintillaWX::DoAddChar(int key) { | |
535 | AddChar(key); | |
536 | } | |
537 | ||
538 | int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool* consumed) { | |
539 | #if defined(__WXGTK__) || defined(__WXMAC__) | |
540 | // Ctrl chars (A-Z) end up with the wrong keycode on wxGTK... | |
541 | if (ctrl && key >= 1 && key <= 26) | |
542 | key += 'A' - 1; | |
543 | #endif | |
544 | ||
545 | switch (key) { | |
546 | case WXK_DOWN: key = SCK_DOWN; break; | |
547 | case WXK_UP: key = SCK_UP; break; | |
548 | case WXK_LEFT: key = SCK_LEFT; break; | |
549 | case WXK_RIGHT: key = SCK_RIGHT; break; | |
550 | case WXK_HOME: key = SCK_HOME; break; | |
551 | case WXK_END: key = SCK_END; break; | |
552 | case WXK_PRIOR: key = SCK_PRIOR; break; | |
553 | case WXK_NEXT: key = SCK_NEXT; break; | |
554 | case WXK_DELETE: key = SCK_DELETE; break; | |
555 | case WXK_INSERT: key = SCK_INSERT; break; | |
556 | case WXK_ESCAPE: key = SCK_ESCAPE; break; | |
557 | case WXK_BACK: key = SCK_BACK; break; | |
558 | case WXK_TAB: key = SCK_TAB; break; | |
559 | case WXK_RETURN: key = SCK_RETURN; break; | |
560 | case WXK_ADD: // fall through | |
561 | case WXK_NUMPAD_ADD: key = SCK_ADD; break; | |
562 | case WXK_SUBTRACT: // fall through | |
563 | case WXK_NUMPAD_SUBTRACT: key = SCK_SUBTRACT; break; | |
564 | case WXK_DIVIDE: // fall through | |
565 | case WXK_NUMPAD_DIVIDE: key = SCK_DIVIDE; break; | |
566 | case WXK_CONTROL: key = 0; break; | |
567 | case WXK_ALT: key = 0; break; | |
568 | case WXK_SHIFT: key = 0; break; | |
569 | case WXK_MENU: key = 0; break; | |
570 | } | |
571 | ||
572 | int rv = KeyDown(key, shift, ctrl, alt, consumed); | |
573 | ||
574 | if (key) | |
575 | return rv; | |
576 | else | |
577 | return 1; | |
578 | } | |
579 | ||
580 | ||
581 | void ScintillaWX::DoCommand(int ID) { | |
582 | Command(ID); | |
583 | } | |
584 | ||
585 | ||
586 | void ScintillaWX::DoContextMenu(Point pt) { | |
587 | if (displayPopupMenu) | |
588 | ContextMenu(pt); | |
589 | } | |
590 | ||
591 | void ScintillaWX::DoOnListBox() { | |
592 | AutoCompleteCompleted(); | |
593 | } | |
594 | ||
595 | //---------------------------------------------------------------------- | |
596 | ||
597 | #if wxUSE_DRAG_AND_DROP | |
598 | bool ScintillaWX::DoDropText(long x, long y, const wxString& data) { | |
599 | SetDragPosition(invalidPosition); | |
600 | ||
601 | // Send an event to allow the drag details to be changed | |
602 | wxStyledTextEvent evt(wxEVT_STC_DO_DROP, stc->GetId()); | |
603 | evt.SetEventObject(stc); | |
604 | evt.SetDragResult(dragResult); | |
605 | evt.SetX(x); | |
606 | evt.SetY(y); | |
607 | evt.SetPosition(PositionFromLocation(Point(x,y))); | |
608 | evt.SetDragText(data); | |
609 | stc->GetEventHandler()->ProcessEvent(evt); | |
610 | ||
611 | dragResult = evt.GetDragResult(); | |
612 | if (dragResult == wxDragMove || dragResult == wxDragCopy) { | |
613 | DropAt(evt.GetPosition(), | |
614 | wx2stc(evt.GetDragText()), | |
615 | dragResult == wxDragMove, | |
616 | FALSE); // TODO: rectangular? | |
617 | return TRUE; | |
618 | } | |
619 | return FALSE; | |
620 | } | |
621 | ||
622 | ||
623 | wxDragResult ScintillaWX::DoDragEnter(wxCoord x, wxCoord y, wxDragResult def) { | |
624 | dragResult = def; | |
625 | return dragResult; | |
626 | } | |
627 | ||
628 | ||
629 | wxDragResult ScintillaWX::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) { | |
630 | SetDragPosition(PositionFromLocation(Point(x, y))); | |
631 | ||
632 | // Send an event to allow the drag result to be changed | |
633 | wxStyledTextEvent evt(wxEVT_STC_DRAG_OVER, stc->GetId()); | |
634 | evt.SetEventObject(stc); | |
635 | evt.SetDragResult(def); | |
636 | evt.SetX(x); | |
637 | evt.SetY(y); | |
638 | evt.SetPosition(PositionFromLocation(Point(x,y))); | |
639 | stc->GetEventHandler()->ProcessEvent(evt); | |
640 | ||
641 | dragResult = evt.GetDragResult(); | |
642 | return dragResult; | |
643 | } | |
644 | ||
645 | ||
646 | void ScintillaWX::DoDragLeave() { | |
647 | SetDragPosition(invalidPosition); | |
648 | } | |
649 | #endif | |
650 | //---------------------------------------------------------------------- | |
651 | ||
652 | // Redraw all of text area. This paint will not be abandoned. | |
653 | void ScintillaWX::FullPaint() { | |
654 | paintState = painting; | |
655 | rcPaint = GetTextRectangle(); | |
656 | paintingAllText = true; | |
657 | wxClientDC dc(stc); | |
658 | Surface* surfaceWindow = Surface::Allocate(); | |
659 | surfaceWindow->Init(&dc); | |
660 | Paint(surfaceWindow, rcPaint); | |
661 | delete surfaceWindow; | |
662 | ||
663 | // stc->Refresh(FALSE); | |
664 | ||
665 | paintState = notPainting; | |
666 | } | |
667 | ||
668 | ||
669 | void ScintillaWX::DoScrollToLine(int line) { | |
670 | ScrollTo(line); | |
671 | } | |
672 | ||
673 | ||
674 | void ScintillaWX::DoScrollToColumn(int column) { | |
675 | HorizontalScrollTo(column * vs.spaceWidth); | |
676 | } | |
677 | ||
678 | ||
679 | ||
680 | //---------------------------------------------------------------------- | |
681 | //---------------------------------------------------------------------- |