1 ////////////////////////////////////////////////////////////////////////////
2 // Name: ScintillaWX.cxx
3 // Purpose: A wxWidgets 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.
11 // Created: 13-Jan-2000
13 // Copyright: (c) 2000 by Total Control Software
14 // Licence: wxWindows license
15 /////////////////////////////////////////////////////////////////////////////
18 #include <wx/textbuf.h>
19 #include <wx/dataobj.h>
20 #include <wx/clipbrd.h>
23 #include "ScintillaWX.h"
24 #include "ExternalLexer.h"
25 #include "wx/stc/stc.h"
30 #include <wx/msw/private.h>
33 //----------------------------------------------------------------------
36 class wxSTCTimer
: public wxTimer
{
38 wxSTCTimer(ScintillaWX
* swx
) {
51 #if wxUSE_DRAG_AND_DROP
52 bool wxSTCDropTarget::OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) {
53 return swx
->DoDropText(x
, y
, data
);
56 wxDragResult
wxSTCDropTarget::OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
) {
57 return swx
->DoDragEnter(x
, y
, def
);
60 wxDragResult
wxSTCDropTarget::OnDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
61 return swx
->DoDragOver(x
, y
, def
);
64 void wxSTCDropTarget::OnLeave() {
70 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
71 #include <wx/popupwin.h>
72 #define wxSTCCallTipBase wxPopupWindow
73 #define param2 wxBORDER_NONE // popup's 2nd param is flags
75 #define wxSTCCallTipBase wxWindow
76 #define param2 -1 // wxWindow's 2nd param is ID
79 #include <wx/dcbuffer.h>
81 class wxSTCCallTip
: public wxSTCCallTipBase
{
83 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
)
84 : wxSTCCallTipBase(parent
, param2
),
85 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
90 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP && defined(__WXGTK__)
91 wxRect rect
= GetRect();
94 GetParent()->Refresh(false, &rect
);
98 bool AcceptsFocus() const { return false; }
100 void OnPaint(wxPaintEvent
& WXUNUSED(evt
)) {
101 wxBufferedPaintDC
dc(this);
102 Surface
* surfaceWindow
= Surface::Allocate();
103 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
104 m_ct
->PaintCT(surfaceWindow
);
105 surfaceWindow
->Release();
106 delete surfaceWindow
;
109 void OnFocus(wxFocusEvent
& event
) {
110 GetParent()->SetFocus();
114 void OnLeftDown(wxMouseEvent
& event
) {
115 wxPoint pt
= event
.GetPosition();
118 m_swx
->CallTipClick();
121 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
122 virtual void DoSetSize(int x
, int y
,
123 int width
, int height
,
124 int sizeFlags
= wxSIZE_AUTO
) {
125 if (x
!= wxDefaultCoord
) {
127 GetParent()->ClientToScreen(&x
, NULL
);
129 if (y
!= wxDefaultCoord
) {
131 GetParent()->ClientToScreen(NULL
, &y
);
133 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
137 wxPoint
GetMyPosition() {
138 return wxPoint(m_cx
, m_cy
);
145 DECLARE_EVENT_TABLE()
148 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
149 EVT_PAINT(wxSTCCallTip::OnPaint
)
150 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
151 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
155 //----------------------------------------------------------------------
157 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
161 switch (scintillaMode
) {
163 type
= wxTextFileType_Dos
;
167 type
= wxTextFileType_Mac
;
171 type
= wxTextFileType_Unix
;
175 type
= wxTextBuffer::typeDefault
;
182 //----------------------------------------------------------------------
183 // Constructor/Destructor
186 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
187 capturedMouse
= false;
201 ScintillaWX::~ScintillaWX() {
205 //----------------------------------------------------------------------
206 // base class virtuals
209 void ScintillaWX::Initialise() {
210 //ScintillaBase::Initialise();
211 #if wxUSE_DRAG_AND_DROP
212 dropTarget
= new wxSTCDropTarget
;
213 dropTarget
->SetScintilla(this);
214 stc
->SetDropTarget(dropTarget
);
217 vs
.extraFontFlag
= false; // UseAntiAliasing
219 vs
.extraFontFlag
= true; // UseAntiAliasing
224 void ScintillaWX::Finalise() {
225 ScintillaBase::Finalise();
228 DestroySystemCaret();
232 void ScintillaWX::StartDrag() {
233 #if wxUSE_DRAG_AND_DROP
234 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
236 // Send an event to allow the drag text to be changed
237 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
238 evt
.SetEventObject(stc
);
239 evt
.SetDragText(dragText
);
240 evt
.SetDragAllowMove(true);
241 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
242 stc
->GetSelectionEnd()));
243 stc
->GetEventHandler()->ProcessEvent(evt
);
244 dragText
= evt
.GetDragText();
246 if (dragText
.Length()) {
247 wxDropSource
source(stc
);
248 wxTextDataObject
data(dragText
);
251 source
.SetData(data
);
252 dropWentOutside
= true;
253 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
254 if (result
== wxDragMove
&& dropWentOutside
)
257 SetDragPosition(invalidPosition
);
263 bool ScintillaWX::SetIdle(bool on
) {
264 if (idler
.state
!= on
) {
265 // connect or disconnect the EVT_IDLE handler
267 stc
->Connect(wxID_ANY
, wxEVT_IDLE
,
268 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
270 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
,
271 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
278 void ScintillaWX::SetTicking(bool on
) {
279 wxSTCTimer
* steTimer
;
280 if (timer
.ticking
!= on
) {
283 steTimer
= new wxSTCTimer(this);
284 steTimer
->Start(timer
.tickSize
);
285 timer
.tickerID
= steTimer
;
287 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
293 timer
.ticksToWait
= caret
.period
;
297 void ScintillaWX::SetMouseCapture(bool on
) {
298 if (mouseDownCaptures
) {
299 if (on
&& !capturedMouse
)
301 else if (!on
&& capturedMouse
&& stc
->HasCapture())
308 bool ScintillaWX::HaveMouseCapture() {
309 return capturedMouse
;
313 void ScintillaWX::ScrollText(int linesToMove
) {
314 int dy
= vs
.lineHeight
* (linesToMove
);
315 stc
->ScrollWindow(0, dy
);
319 void ScintillaWX::SetVerticalScrollPos() {
320 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
321 stc
->SetScrollPos(wxVERTICAL
, topLine
);
323 else { // otherwise use the one that's been given to us
324 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
328 void ScintillaWX::SetHorizontalScrollPos() {
329 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
330 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
332 else { // otherwise use the one that's been given to us
333 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
338 const int H_SCROLL_STEP
= 20;
340 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
341 bool modified
= false;
344 if (!verticalScrollBarVisible
)
347 // Check the vertical scrollbar
348 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
349 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
350 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
351 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
352 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
353 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
357 else { // otherwise use the one that's been given to us
358 int sbMax
= stc
->m_vScrollBar
->GetRange();
359 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
360 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
361 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
362 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
368 // Check the horizontal scrollbar
369 PRectangle rcText
= GetTextRectangle();
370 int horizEnd
= scrollWidth
;
373 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
375 int pageWidth
= rcText
.Width();
377 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
378 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
379 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
380 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
381 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
382 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
384 if (scrollWidth
< pageWidth
) {
385 HorizontalScrollTo(0);
389 else { // otherwise use the one that's been given to us
390 int sbMax
= stc
->m_hScrollBar
->GetRange();
391 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
392 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
393 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
394 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
396 if (scrollWidth
< pageWidth
) {
397 HorizontalScrollTo(0);
406 void ScintillaWX::NotifyChange() {
411 void ScintillaWX::NotifyParent(SCNotification scn
) {
412 stc
->NotifyParent(&scn
);
416 // This method is overloaded from ScintillaBase in order to prevent the
417 // AutoComplete window from being destroyed when it gets the focus. There is
418 // a side effect that the AutoComp will also not be destroyed when switching
419 // to another window, but I think that is okay.
420 void ScintillaWX::CancelModes() {
422 AutoCompleteCancel();
424 Editor::CancelModes();
429 void ScintillaWX::Copy() {
430 if (currentPos
!= anchor
) {
432 CopySelectionRange(&st
);
438 void ScintillaWX::Paste() {
439 pdoc
->BeginUndoAction();
442 wxTextDataObject data
;
443 bool gotData
= false;
445 if (wxTheClipboard
->Open()) {
446 wxTheClipboard
->UsePrimarySelection(false);
447 gotData
= wxTheClipboard
->GetData(data
);
448 wxTheClipboard
->Close();
451 wxString text
= wxTextBuffer::Translate(data
.GetText(),
452 wxConvertEOLMode(pdoc
->eolMode
));
453 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
454 int len
= strlen(buf
);
455 pdoc
->InsertString(currentPos
, buf
, len
);
456 SetEmptySelection(currentPos
+ len
);
459 pdoc
->EndUndoAction();
465 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
466 if (wxTheClipboard
->Open()) {
467 wxTheClipboard
->UsePrimarySelection(false);
468 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
469 wxTheClipboard
->SetData(new wxTextDataObject(text
));
470 wxTheClipboard
->Close();
475 bool ScintillaWX::CanPaste() {
476 bool canPaste
= false;
479 if (Editor::CanPaste()) {
480 didOpen
= !wxTheClipboard
->IsOpened();
482 wxTheClipboard
->Open();
484 if (wxTheClipboard
->IsOpened()) {
485 wxTheClipboard
->UsePrimarySelection(false);
486 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
488 wxTheClipboard
->Close();
494 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
495 if (! ct
.wCallTip
.Created() ) {
496 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
497 ct
.wDraw
= ct
.wCallTip
;
502 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
504 ((wxMenu
*)popup
.GetID())->AppendSeparator();
506 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
509 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
513 // This is called by the Editor base class whenever something is selected
514 void ScintillaWX::ClaimSelection() {
516 // Until wxGTK is able to support using both the primary selection and the
517 // clipboard at the same time I think it causes more problems than it is
518 // worth to implement this method. Selecting text should not clear the
519 // clipboard. --Robin
521 // Put the selected text in the PRIMARY selection
522 if (currentPos
!= anchor
) {
524 CopySelectionRange(&st
);
525 if (wxTheClipboard
->Open()) {
526 wxTheClipboard
->UsePrimarySelection(true);
527 wxString text
= stc2wx(st
.s
, st
.len
);
528 wxTheClipboard
->SetData(new wxTextDataObject(text
));
529 wxTheClipboard
->UsePrimarySelection(false);
530 wxTheClipboard
->Close();
538 void ScintillaWX::UpdateSystemCaret() {
541 if (HasCaretSizeChanged()) {
542 DestroySystemCaret();
545 Point pos
= LocationFromPosition(currentPos
);
546 ::SetCaretPos(pos
.x
, pos
.y
);
552 bool ScintillaWX::HasCaretSizeChanged() {
554 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
555 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
562 bool ScintillaWX::CreateSystemCaret() {
564 sysCaretWidth
= vs
.caretWidth
;
565 if (0 == sysCaretWidth
) {
568 sysCaretHeight
= vs
.lineHeight
;
569 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
570 char *bits
= new char[bitmapSize
];
571 memset(bits
, 0, bitmapSize
);
572 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
573 1, reinterpret_cast<BYTE
*>(bits
));
575 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
576 sysCaretWidth
, sysCaretHeight
);
577 ::ShowCaret(GetHwndOf(stc
));
584 bool ScintillaWX::DestroySystemCaret() {
586 ::HideCaret(GetHwndOf(stc
));
587 BOOL retval
= ::DestroyCaret();
588 if (sysCaretBitmap
) {
589 ::DeleteObject(sysCaretBitmap
);
599 //----------------------------------------------------------------------
602 long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
606 long ScintillaWX::WndProc(unsigned int iMessage
, unsigned long wParam
, long lParam
) {
608 case SCI_CALLTIPSHOW
: {
609 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
610 // because of the little tweak that needs done below for wxGTK.
611 // When updating new versions double check that this is still
612 // needed, and that any new code there is copied here too.
613 Point pt
= LocationFromPosition(wParam
);
614 char* defn
= reinterpret_cast<char *>(lParam
);
615 AutoCompleteCancel();
616 pt
.y
+= vs
.lineHeight
;
617 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
619 vs
.styles
[STYLE_DEFAULT
].fontName
,
620 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
622 vs
.styles
[STYLE_DEFAULT
].characterSet
,
624 // If the call-tip window would be out of the client
625 // space, adjust so it displays above the text.
626 PRectangle rcClient
= GetClientRectangle();
627 if (rc
.bottom
> rcClient
.bottom
) {
629 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
631 int offset
= vs
.lineHeight
+ rc
.Height();
636 // Now display the window.
637 CreateCallTipWindow(rc
);
638 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
644 case SCI_LOADLEXERLIBRARY
:
645 LexerManager::GetInstance()->Load((const char*)lParam
);
650 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
657 //----------------------------------------------------------------------
660 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
662 paintState
= painting
;
663 Surface
* surfaceWindow
= Surface::Allocate();
664 surfaceWindow
->Init(dc
, wMain
.GetID());
665 rcPaint
= PRectangleFromwxRect(rect
);
666 PRectangle rcClient
= GetClientRectangle();
667 paintingAllText
= rcPaint
.Contains(rcClient
);
670 ClipChildren(*dc
, rcPaint
);
671 Paint(surfaceWindow
, rcPaint
);
673 delete surfaceWindow
;
674 if (paintState
== paintAbandoned
) {
675 // Painting area was insufficient to cover new styling or brace
676 // highlight positions
679 paintState
= notPainting
;
684 void ScintillaWX::DoHScroll(int type
, int pos
) {
686 PRectangle rcText
= GetTextRectangle();
687 int pageWidth
= rcText
.Width() * 2 / 3;
688 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
689 xPos
-= H_SCROLL_STEP
;
690 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
691 xPos
+= H_SCROLL_STEP
;
692 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
694 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
696 if (xPos
> scrollWidth
- rcText
.Width()) {
697 xPos
= scrollWidth
- rcText
.Width();
700 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
702 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
704 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
707 HorizontalScrollTo(xPos
);
710 void ScintillaWX::DoVScroll(int type
, int pos
) {
711 int topLineNew
= topLine
;
712 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
714 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
716 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
717 topLineNew
-= LinesToScroll();
718 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
719 topLineNew
+= LinesToScroll();
720 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
722 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
723 topLineNew
= MaxScrollPos();
724 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
727 ScrollTo(topLineNew
);
730 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
731 int linesPerAction
, int ctrlDown
,
732 bool isPageScroll
) {
733 int topLineNew
= topLine
;
736 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
738 KeyCommand(SCI_ZOOMIN
);
741 KeyCommand(SCI_ZOOMOUT
);
744 else { // otherwise just scroll the window
747 wheelRotation
+= rotation
;
748 lines
= wheelRotation
/ delta
;
749 wheelRotation
-= lines
* delta
;
752 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
754 lines
*= linesPerAction
;
756 ScrollTo(topLineNew
);
762 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
766 void ScintillaWX::DoLoseFocus(){
768 SetFocusState(false);
770 DestroySystemCaret();
773 void ScintillaWX::DoGainFocus(){
777 DestroySystemCaret();
781 void ScintillaWX::DoSysColourChange() {
782 InvalidateStyleData();
785 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
786 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
789 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
790 ButtonUp(pt
, curTime
, ctrl
);
793 void ScintillaWX::DoLeftButtonMove(Point pt
) {
798 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
799 // Set the current position to the mouse click point and
800 // then paste in the PRIMARY selection, if any. wxGTK only.
801 int newPos
= PositionFromLocation(pt
);
802 MovePositionTo(newPos
, noSel
, true);
804 pdoc
->BeginUndoAction();
805 wxTextDataObject data
;
806 bool gotData
= false;
807 if (wxTheClipboard
->Open()) {
808 wxTheClipboard
->UsePrimarySelection(true);
809 gotData
= wxTheClipboard
->GetData(data
);
810 wxTheClipboard
->UsePrimarySelection(false);
811 wxTheClipboard
->Close();
814 wxString text
= wxTextBuffer::Translate(data
.GetText(),
815 wxConvertEOLMode(pdoc
->eolMode
));
816 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
817 int len
= strlen(buf
);
818 pdoc
->InsertString(currentPos
, buf
, len
);
819 SetEmptySelection(currentPos
+ len
);
821 pdoc
->EndUndoAction();
825 ShowCaretAtCurrentPosition();
826 EnsureCaretVisible();
829 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
834 void ScintillaWX::DoAddChar(int key
) {
837 wszChars
[0] = (wxChar
)key
;
839 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
840 AddCharUTF((char*)buf
.data(), strlen(buf
));
847 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
849 int key
= evt
.GetKeyCode();
850 bool shift
= evt
.ShiftDown(),
851 ctrl
= evt
.ControlDown(),
854 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
858 case WXK_DOWN
: key
= SCK_DOWN
; break;
859 case WXK_UP
: key
= SCK_UP
; break;
860 case WXK_LEFT
: key
= SCK_LEFT
; break;
861 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
862 case WXK_HOME
: key
= SCK_HOME
; break;
863 case WXK_END
: key
= SCK_END
; break;
864 case WXK_PAGEUP
: // fall through
865 case WXK_PRIOR
: key
= SCK_PRIOR
; break;
866 case WXK_PAGEDOWN
: // fall through
867 case WXK_NEXT
: key
= SCK_NEXT
; break;
868 case WXK_DELETE
: key
= SCK_DELETE
; break;
869 case WXK_INSERT
: key
= SCK_INSERT
; break;
870 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
871 case WXK_BACK
: key
= SCK_BACK
; break;
872 case WXK_TAB
: key
= SCK_TAB
; break;
873 case WXK_NUMPAD_ENTER
: // fall through
874 case WXK_RETURN
: key
= SCK_RETURN
; break;
875 case WXK_ADD
: // fall through
876 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
877 case WXK_SUBTRACT
: // fall through
878 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
879 case WXK_DIVIDE
: // fall through
880 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
881 case WXK_CONTROL
: key
= 0; break;
882 case WXK_ALT
: key
= 0; break;
883 case WXK_SHIFT
: key
= 0; break;
884 case WXK_MENU
: key
= 0; break;
888 if ( evt
.MetaDown() ) {
889 // check for a few common Mac Meta-key combos and remap them to Ctrl
896 case 'A': // Select All
903 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
912 void ScintillaWX::DoCommand(int ID
) {
917 void ScintillaWX::DoContextMenu(Point pt
) {
918 if (displayPopupMenu
)
922 void ScintillaWX::DoOnListBox() {
923 AutoCompleteCompleted();
927 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
935 //----------------------------------------------------------------------
937 #if wxUSE_DRAG_AND_DROP
938 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
939 SetDragPosition(invalidPosition
);
941 wxString text
= wxTextBuffer::Translate(data
,
942 wxConvertEOLMode(pdoc
->eolMode
));
944 // Send an event to allow the drag details to be changed
945 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
946 evt
.SetEventObject(stc
);
947 evt
.SetDragResult(dragResult
);
950 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
951 evt
.SetDragText(text
);
952 stc
->GetEventHandler()->ProcessEvent(evt
);
954 dragResult
= evt
.GetDragResult();
955 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
956 DropAt(evt
.GetPosition(),
957 wx2stc(evt
.GetDragText()),
958 dragResult
== wxDragMove
,
959 false); // TODO: rectangular?
966 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
972 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
973 SetDragPosition(PositionFromLocation(Point(x
, y
)));
975 // Send an event to allow the drag result to be changed
976 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
977 evt
.SetEventObject(stc
);
978 evt
.SetDragResult(def
);
981 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
982 stc
->GetEventHandler()->ProcessEvent(evt
);
984 dragResult
= evt
.GetDragResult();
989 void ScintillaWX::DoDragLeave() {
990 SetDragPosition(invalidPosition
);
993 //----------------------------------------------------------------------
995 // Force the whole window to be repainted
996 void ScintillaWX::FullPaint() {
1004 void ScintillaWX::DoScrollToLine(int line
) {
1009 void ScintillaWX::DoScrollToColumn(int column
) {
1010 HorizontalScrollTo(column
* vs
.spaceWidth
);
1013 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1014 // will leave it here commented out for a while just in case...
1015 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1017 // wxRegion rgn(wxRectFromPRectangle(rect));
1018 // if (ac.Active()) {
1019 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1020 // rgn.Subtract(childRect);
1022 // if (ct.inCallTipMode) {
1023 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1024 // wxRect childRect = tip->GetRect();
1025 // #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
1026 // childRect.SetPosition(tip->GetMyPosition());
1028 // rgn.Subtract(childRect);
1030 // dc.SetClippingRegion(rgn);
1034 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1035 vs
.extraFontFlag
= useAA
;
1036 InvalidateStyleRedraw();
1039 bool ScintillaWX::GetUseAntiAliasing() {
1040 return vs
.extraFontFlag
;
1043 //----------------------------------------------------------------------
1044 //----------------------------------------------------------------------