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