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 /////////////////////////////////////////////////////////////////////////////
17 #define Point macPoint // These names are also defined by some mac headers so
18 #define Style macStyle // change their names, and then undef before we need them
21 #include <wx/textbuf.h>
22 #include <wx/dataobj.h>
23 #include <wx/clipbrd.h>
29 #include "ScintillaWX.h"
30 #include "ExternalLexer.h"
31 #include "wx/stc/stc.h"
36 #include <wx/msw/private.h>
39 //----------------------------------------------------------------------
42 class wxSTCTimer
: public wxTimer
{
44 wxSTCTimer(ScintillaWX
* swx
) {
57 #if wxUSE_DRAG_AND_DROP
58 bool wxSTCDropTarget::OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) {
59 return swx
->DoDropText(x
, y
, data
);
62 wxDragResult
wxSTCDropTarget::OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
) {
63 return swx
->DoDragEnter(x
, y
, def
);
66 wxDragResult
wxSTCDropTarget::OnDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
67 return swx
->DoDragOver(x
, y
, def
);
70 void wxSTCDropTarget::OnLeave() {
76 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
77 #include <wx/popupwin.h>
78 #define wxSTCCallTipBase wxPopupWindow
79 #define param2 wxBORDER_NONE // popup's 2nd param is flags
81 #define wxSTCCallTipBase wxWindow
82 #define param2 -1 // wxWindow's 2nd param is ID
85 #include <wx/dcbuffer.h>
87 class wxSTCCallTip
: public wxSTCCallTipBase
{
89 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
)
90 : wxSTCCallTipBase(parent
, param2
),
91 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
96 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP && defined(__WXGTK__)
97 wxRect rect
= GetRect();
100 GetParent()->Refresh(false, &rect
);
104 bool AcceptsFocus() const { return false; }
106 void OnPaint(wxPaintEvent
& WXUNUSED(evt
)) {
107 wxBufferedPaintDC
dc(this);
108 Surface
* surfaceWindow
= Surface::Allocate();
109 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
110 m_ct
->PaintCT(surfaceWindow
);
111 surfaceWindow
->Release();
112 delete surfaceWindow
;
115 void OnFocus(wxFocusEvent
& event
) {
116 GetParent()->SetFocus();
120 void OnLeftDown(wxMouseEvent
& event
) {
121 wxPoint pt
= event
.GetPosition();
124 m_swx
->CallTipClick();
127 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
128 virtual void DoSetSize(int x
, int y
,
129 int width
, int height
,
130 int sizeFlags
= wxSIZE_AUTO
) {
131 if (x
!= wxDefaultCoord
) {
133 GetParent()->ClientToScreen(&x
, NULL
);
135 if (y
!= wxDefaultCoord
) {
137 GetParent()->ClientToScreen(NULL
, &y
);
139 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
143 wxPoint
GetMyPosition() {
144 return wxPoint(m_cx
, m_cy
);
151 DECLARE_EVENT_TABLE()
154 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
155 EVT_PAINT(wxSTCCallTip::OnPaint
)
156 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
157 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
161 //----------------------------------------------------------------------
163 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
167 switch (scintillaMode
) {
169 type
= wxTextFileType_Dos
;
173 type
= wxTextFileType_Mac
;
177 type
= wxTextFileType_Unix
;
181 type
= wxTextBuffer::typeDefault
;
188 //----------------------------------------------------------------------
189 // Constructor/Destructor
192 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
193 capturedMouse
= false;
207 ScintillaWX::~ScintillaWX() {
211 //----------------------------------------------------------------------
212 // base class virtuals
215 void ScintillaWX::Initialise() {
216 //ScintillaBase::Initialise();
217 #if wxUSE_DRAG_AND_DROP
218 dropTarget
= new wxSTCDropTarget
;
219 dropTarget
->SetScintilla(this);
220 stc
->SetDropTarget(dropTarget
);
223 vs
.extraFontFlag
= false; // UseAntiAliasing
225 vs
.extraFontFlag
= true; // UseAntiAliasing
230 void ScintillaWX::Finalise() {
231 ScintillaBase::Finalise();
234 DestroySystemCaret();
238 void ScintillaWX::StartDrag() {
239 #if wxUSE_DRAG_AND_DROP
240 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
242 // Send an event to allow the drag text to be changed
243 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
244 evt
.SetEventObject(stc
);
245 evt
.SetDragText(dragText
);
246 evt
.SetDragAllowMove(true);
247 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
248 stc
->GetSelectionEnd()));
249 stc
->GetEventHandler()->ProcessEvent(evt
);
250 dragText
= evt
.GetDragText();
252 if (dragText
.Length()) {
253 wxDropSource
source(stc
);
254 wxTextDataObject
data(dragText
);
257 source
.SetData(data
);
258 dropWentOutside
= true;
259 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
260 if (result
== wxDragMove
&& dropWentOutside
)
263 SetDragPosition(invalidPosition
);
269 bool ScintillaWX::SetIdle(bool on
) {
270 if (idler
.state
!= on
) {
271 // connect or disconnect the EVT_IDLE handler
273 stc
->Connect(wxID_ANY
, wxEVT_IDLE
,
274 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
276 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
,
277 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
284 void ScintillaWX::SetTicking(bool on
) {
285 wxSTCTimer
* steTimer
;
286 if (timer
.ticking
!= on
) {
289 steTimer
= new wxSTCTimer(this);
290 steTimer
->Start(timer
.tickSize
);
291 timer
.tickerID
= steTimer
;
293 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
299 timer
.ticksToWait
= caret
.period
;
303 void ScintillaWX::SetMouseCapture(bool on
) {
304 if (mouseDownCaptures
) {
305 if (on
&& !capturedMouse
)
307 else if (!on
&& capturedMouse
&& stc
->HasCapture())
314 bool ScintillaWX::HaveMouseCapture() {
315 return capturedMouse
;
319 void ScintillaWX::ScrollText(int linesToMove
) {
320 int dy
= vs
.lineHeight
* (linesToMove
);
321 stc
->ScrollWindow(0, dy
);
325 void ScintillaWX::SetVerticalScrollPos() {
326 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
327 stc
->SetScrollPos(wxVERTICAL
, topLine
);
329 else { // otherwise use the one that's been given to us
330 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
334 void ScintillaWX::SetHorizontalScrollPos() {
335 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
336 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
338 else { // otherwise use the one that's been given to us
339 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
344 const int H_SCROLL_STEP
= 20;
346 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
347 bool modified
= false;
350 if (!verticalScrollBarVisible
)
353 // Check the vertical scrollbar
354 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
355 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
356 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
357 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
358 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
359 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
363 else { // otherwise use the one that's been given to us
364 int sbMax
= stc
->m_vScrollBar
->GetRange();
365 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
366 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
367 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
368 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
374 // Check the horizontal scrollbar
375 PRectangle rcText
= GetTextRectangle();
376 int horizEnd
= scrollWidth
;
379 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
381 int pageWidth
= rcText
.Width();
383 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
384 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
385 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
386 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
387 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
388 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
390 if (scrollWidth
< pageWidth
) {
391 HorizontalScrollTo(0);
395 else { // otherwise use the one that's been given to us
396 int sbMax
= stc
->m_hScrollBar
->GetRange();
397 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
398 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
399 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
400 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
402 if (scrollWidth
< pageWidth
) {
403 HorizontalScrollTo(0);
412 void ScintillaWX::NotifyChange() {
417 void ScintillaWX::NotifyParent(SCNotification scn
) {
418 stc
->NotifyParent(&scn
);
422 // This method is overloaded from ScintillaBase in order to prevent the
423 // AutoComplete window from being destroyed when it gets the focus. There is
424 // a side effect that the AutoComp will also not be destroyed when switching
425 // to another window, but I think that is okay.
426 void ScintillaWX::CancelModes() {
428 AutoCompleteCancel();
430 Editor::CancelModes();
435 void ScintillaWX::Copy() {
436 if (currentPos
!= anchor
) {
438 CopySelectionRange(&st
);
444 void ScintillaWX::Paste() {
445 pdoc
->BeginUndoAction();
448 wxTextDataObject data
;
449 bool gotData
= false;
451 if (wxTheClipboard
->Open()) {
452 wxTheClipboard
->UsePrimarySelection(false);
453 gotData
= wxTheClipboard
->GetData(data
);
454 wxTheClipboard
->Close();
457 wxString text
= wxTextBuffer::Translate(data
.GetText(),
458 wxConvertEOLMode(pdoc
->eolMode
));
459 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
460 int len
= strlen(buf
);
461 pdoc
->InsertString(currentPos
, buf
, len
);
462 SetEmptySelection(currentPos
+ len
);
465 pdoc
->EndUndoAction();
471 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
472 if (wxTheClipboard
->Open()) {
473 wxTheClipboard
->UsePrimarySelection(false);
474 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
475 wxTheClipboard
->SetData(new wxTextDataObject(text
));
476 wxTheClipboard
->Close();
481 bool ScintillaWX::CanPaste() {
482 bool canPaste
= false;
485 if (Editor::CanPaste()) {
486 didOpen
= !wxTheClipboard
->IsOpened();
488 wxTheClipboard
->Open();
490 if (wxTheClipboard
->IsOpened()) {
491 wxTheClipboard
->UsePrimarySelection(false);
492 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
494 wxTheClipboard
->Close();
500 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
501 if (! ct
.wCallTip
.Created() ) {
502 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
503 ct
.wDraw
= ct
.wCallTip
;
508 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
510 ((wxMenu
*)popup
.GetID())->AppendSeparator();
512 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
515 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
519 // This is called by the Editor base class whenever something is selected
520 void ScintillaWX::ClaimSelection() {
522 // Until wxGTK is able to support using both the primary selection and the
523 // clipboard at the same time I think it causes more problems than it is
524 // worth to implement this method. Selecting text should not clear the
525 // clipboard. --Robin
527 // Put the selected text in the PRIMARY selection
528 if (currentPos
!= anchor
) {
530 CopySelectionRange(&st
);
531 if (wxTheClipboard
->Open()) {
532 wxTheClipboard
->UsePrimarySelection(true);
533 wxString text
= stc2wx(st
.s
, st
.len
);
534 wxTheClipboard
->SetData(new wxTextDataObject(text
));
535 wxTheClipboard
->UsePrimarySelection(false);
536 wxTheClipboard
->Close();
544 void ScintillaWX::UpdateSystemCaret() {
547 if (HasCaretSizeChanged()) {
548 DestroySystemCaret();
551 Point pos
= LocationFromPosition(currentPos
);
552 ::SetCaretPos(pos
.x
, pos
.y
);
558 bool ScintillaWX::HasCaretSizeChanged() {
560 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
561 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
568 bool ScintillaWX::CreateSystemCaret() {
570 sysCaretWidth
= vs
.caretWidth
;
571 if (0 == sysCaretWidth
) {
574 sysCaretHeight
= vs
.lineHeight
;
575 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
576 char *bits
= new char[bitmapSize
];
577 memset(bits
, 0, bitmapSize
);
578 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
579 1, reinterpret_cast<BYTE
*>(bits
));
581 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
582 sysCaretWidth
, sysCaretHeight
);
583 ::ShowCaret(GetHwndOf(stc
));
590 bool ScintillaWX::DestroySystemCaret() {
592 ::HideCaret(GetHwndOf(stc
));
593 BOOL retval
= ::DestroyCaret();
594 if (sysCaretBitmap
) {
595 ::DeleteObject(sysCaretBitmap
);
605 //----------------------------------------------------------------------
608 long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
612 long ScintillaWX::WndProc(unsigned int iMessage
, unsigned long wParam
, long lParam
) {
614 case SCI_CALLTIPSHOW
: {
615 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
616 // because of the little tweak that needs done below for wxGTK.
617 // When updating new versions double check that this is still
618 // needed, and that any new code there is copied here too.
619 Point pt
= LocationFromPosition(wParam
);
620 char* defn
= reinterpret_cast<char *>(lParam
);
621 AutoCompleteCancel();
622 pt
.y
+= vs
.lineHeight
;
623 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
625 vs
.styles
[STYLE_DEFAULT
].fontName
,
626 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
628 vs
.styles
[STYLE_DEFAULT
].characterSet
,
630 // If the call-tip window would be out of the client
631 // space, adjust so it displays above the text.
632 PRectangle rcClient
= GetClientRectangle();
633 if (rc
.bottom
> rcClient
.bottom
) {
635 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
637 int offset
= vs
.lineHeight
+ rc
.Height();
642 // Now display the window.
643 CreateCallTipWindow(rc
);
644 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
650 case SCI_LOADLEXERLIBRARY
:
651 LexerManager::GetInstance()->Load((const char*)lParam
);
656 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
663 //----------------------------------------------------------------------
666 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
668 paintState
= painting
;
669 Surface
* surfaceWindow
= Surface::Allocate();
670 surfaceWindow
->Init(dc
, wMain
.GetID());
671 rcPaint
= PRectangleFromwxRect(rect
);
672 PRectangle rcClient
= GetClientRectangle();
673 paintingAllText
= rcPaint
.Contains(rcClient
);
676 ClipChildren(*dc
, rcPaint
);
677 Paint(surfaceWindow
, rcPaint
);
679 delete surfaceWindow
;
680 if (paintState
== paintAbandoned
) {
681 // Painting area was insufficient to cover new styling or brace
682 // highlight positions
685 paintState
= notPainting
;
690 void ScintillaWX::DoHScroll(int type
, int pos
) {
692 PRectangle rcText
= GetTextRectangle();
693 int pageWidth
= rcText
.Width() * 2 / 3;
694 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
695 xPos
-= H_SCROLL_STEP
;
696 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
697 xPos
+= H_SCROLL_STEP
;
698 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
700 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
702 if (xPos
> scrollWidth
- rcText
.Width()) {
703 xPos
= scrollWidth
- rcText
.Width();
706 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
708 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
710 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
713 HorizontalScrollTo(xPos
);
716 void ScintillaWX::DoVScroll(int type
, int pos
) {
717 int topLineNew
= topLine
;
718 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
720 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
722 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
723 topLineNew
-= LinesToScroll();
724 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
725 topLineNew
+= LinesToScroll();
726 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
728 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
729 topLineNew
= MaxScrollPos();
730 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
733 ScrollTo(topLineNew
);
736 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
737 int linesPerAction
, int ctrlDown
,
738 bool isPageScroll
) {
739 int topLineNew
= topLine
;
742 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
744 KeyCommand(SCI_ZOOMIN
);
747 KeyCommand(SCI_ZOOMOUT
);
750 else { // otherwise just scroll the window
753 wheelRotation
+= rotation
;
754 lines
= wheelRotation
/ delta
;
755 wheelRotation
-= lines
* delta
;
758 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
760 lines
*= linesPerAction
;
762 ScrollTo(topLineNew
);
768 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
772 void ScintillaWX::DoLoseFocus(){
774 SetFocusState(false);
776 DestroySystemCaret();
779 void ScintillaWX::DoGainFocus(){
783 DestroySystemCaret();
787 void ScintillaWX::DoSysColourChange() {
788 InvalidateStyleData();
791 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
792 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
795 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
796 ButtonUp(pt
, curTime
, ctrl
);
799 void ScintillaWX::DoLeftButtonMove(Point pt
) {
804 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
805 // Set the current position to the mouse click point and
806 // then paste in the PRIMARY selection, if any. wxGTK only.
807 int newPos
= PositionFromLocation(pt
);
808 MovePositionTo(newPos
, noSel
, true);
810 pdoc
->BeginUndoAction();
811 wxTextDataObject data
;
812 bool gotData
= false;
813 if (wxTheClipboard
->Open()) {
814 wxTheClipboard
->UsePrimarySelection(true);
815 gotData
= wxTheClipboard
->GetData(data
);
816 wxTheClipboard
->UsePrimarySelection(false);
817 wxTheClipboard
->Close();
820 wxString text
= wxTextBuffer::Translate(data
.GetText(),
821 wxConvertEOLMode(pdoc
->eolMode
));
822 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
823 int len
= strlen(buf
);
824 pdoc
->InsertString(currentPos
, buf
, len
);
825 SetEmptySelection(currentPos
+ len
);
827 pdoc
->EndUndoAction();
831 ShowCaretAtCurrentPosition();
832 EnsureCaretVisible();
835 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
840 void ScintillaWX::DoAddChar(int key
) {
843 wszChars
[0] = (wxChar
)key
;
845 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
846 AddCharUTF((char*)buf
.data(), strlen(buf
));
853 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
855 int key
= evt
.GetKeyCode();
856 bool shift
= evt
.ShiftDown(),
857 ctrl
= evt
.ControlDown(),
860 if (ctrl
&& key
>= 1 && key
<= 26)
864 case WXK_DOWN
: key
= SCK_DOWN
; break;
865 case WXK_UP
: key
= SCK_UP
; break;
866 case WXK_LEFT
: key
= SCK_LEFT
; break;
867 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
868 case WXK_HOME
: key
= SCK_HOME
; break;
869 case WXK_END
: key
= SCK_END
; break;
870 case WXK_PAGEUP
: // fall through
871 case WXK_PRIOR
: key
= SCK_PRIOR
; break;
872 case WXK_PAGEDOWN
: // fall through
873 case WXK_NEXT
: key
= SCK_NEXT
; break;
874 case WXK_DELETE
: key
= SCK_DELETE
; break;
875 case WXK_INSERT
: key
= SCK_INSERT
; break;
876 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
877 case WXK_BACK
: key
= SCK_BACK
; break;
878 case WXK_TAB
: key
= SCK_TAB
; break;
879 case WXK_NUMPAD_ENTER
: // fall through
880 case WXK_RETURN
: key
= SCK_RETURN
; break;
881 case WXK_ADD
: // fall through
882 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
883 case WXK_SUBTRACT
: // fall through
884 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
885 case WXK_DIVIDE
: // fall through
886 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
887 case WXK_CONTROL
: key
= 0; break;
888 case WXK_ALT
: key
= 0; break;
889 case WXK_SHIFT
: key
= 0; break;
890 case WXK_MENU
: key
= 0; break;
894 if ( evt
.MetaDown() ) {
895 // check for a few common Mac Meta-key combos and remap them to Ctrl
902 case 'A': // Select All
909 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
918 void ScintillaWX::DoCommand(int ID
) {
923 void ScintillaWX::DoContextMenu(Point pt
) {
924 if (displayPopupMenu
)
928 void ScintillaWX::DoOnListBox() {
929 AutoCompleteCompleted();
933 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
941 //----------------------------------------------------------------------
943 #if wxUSE_DRAG_AND_DROP
944 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
945 SetDragPosition(invalidPosition
);
947 wxString text
= wxTextBuffer::Translate(data
,
948 wxConvertEOLMode(pdoc
->eolMode
));
950 // Send an event to allow the drag details to be changed
951 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
952 evt
.SetEventObject(stc
);
953 evt
.SetDragResult(dragResult
);
956 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
957 evt
.SetDragText(text
);
958 stc
->GetEventHandler()->ProcessEvent(evt
);
960 dragResult
= evt
.GetDragResult();
961 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
962 DropAt(evt
.GetPosition(),
963 wx2stc(evt
.GetDragText()),
964 dragResult
== wxDragMove
,
965 false); // TODO: rectangular?
972 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
978 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
979 SetDragPosition(PositionFromLocation(Point(x
, y
)));
981 // Send an event to allow the drag result to be changed
982 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
983 evt
.SetEventObject(stc
);
984 evt
.SetDragResult(def
);
987 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
988 stc
->GetEventHandler()->ProcessEvent(evt
);
990 dragResult
= evt
.GetDragResult();
995 void ScintillaWX::DoDragLeave() {
996 SetDragPosition(invalidPosition
);
999 //----------------------------------------------------------------------
1001 // Force the whole window to be repainted
1002 void ScintillaWX::FullPaint() {
1004 stc
->Refresh(false);
1010 void ScintillaWX::DoScrollToLine(int line
) {
1015 void ScintillaWX::DoScrollToColumn(int column
) {
1016 HorizontalScrollTo(column
* vs
.spaceWidth
);
1020 void ScintillaWX::ClipChildren(wxDC
& dc
, PRectangle rect
) {
1021 wxRegion
rgn(wxRectFromPRectangle(rect
));
1023 wxRect childRect
= ((wxWindow
*)ac
.lb
->GetID())->GetRect();
1024 rgn
.Subtract(childRect
);
1026 if (ct
.inCallTipMode
) {
1027 wxSTCCallTip
* tip
= (wxSTCCallTip
*)ct
.wCallTip
.GetID();
1028 wxRect childRect
= tip
->GetRect();
1029 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
1030 childRect
.SetPosition(tip
->GetMyPosition());
1032 rgn
.Subtract(childRect
);
1035 dc
.SetClippingRegion(rgn
);
1038 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
)) {
1043 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1044 vs
.extraFontFlag
= useAA
;
1045 InvalidateStyleRedraw();
1048 bool ScintillaWX::GetUseAntiAliasing() {
1049 return vs
.extraFontFlag
;
1052 //----------------------------------------------------------------------
1053 //----------------------------------------------------------------------