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 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
27 #include "wx/scrolbar.h"
32 #include "wx/textbuf.h"
33 #include "wx/dataobj.h"
34 #include "wx/clipbrd.h"
37 #include "ScintillaWX.h"
38 #include "ExternalLexer.h"
39 #include "wx/stc/stc.h"
40 #include "wx/stc/private.h"
45 #include "wx/msw/private.h"
48 //----------------------------------------------------------------------
51 class wxSTCTimer
: public wxTimer
{
53 wxSTCTimer(ScintillaWX
* swx
) {
66 #if wxUSE_DRAG_AND_DROP
67 bool wxSTCDropTarget::OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) {
68 return m_swx
->DoDropText(x
, y
, data
);
71 wxDragResult
wxSTCDropTarget::OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
) {
72 return m_swx
->DoDragEnter(x
, y
, def
);
75 wxDragResult
wxSTCDropTarget::OnDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
76 return m_swx
->DoDragOver(x
, y
, def
);
79 void wxSTCDropTarget::OnLeave() {
82 #endif // wxUSE_DRAG_AND_DROP
86 #include "wx/popupwin.h"
87 #define wxSTCCallTipBase wxPopupWindow
90 #define wxSTCCallTipBase wxFrame
93 #include "wx/dcbuffer.h"
95 class wxSTCCallTip
: public wxSTCCallTipBase
{
97 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
) :
99 wxSTCCallTipBase(parent
, wxBORDER_NONE
),
101 wxSTCCallTipBase(parent
, -1, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
,
103 | wxFRAME_FLOAT_ON_PARENT
110 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
112 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
116 #if wxUSE_POPUPWIN && defined(__WXGTK__)
117 wxRect rect
= GetRect();
120 GetParent()->Refresh(false, &rect
);
124 bool AcceptsFocus() const { return false; }
126 void OnPaint(wxPaintEvent
& WXUNUSED(evt
))
128 wxAutoBufferedPaintDC
dc(this);
129 Surface
* surfaceWindow
= Surface::Allocate();
130 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
131 m_ct
->PaintCT(surfaceWindow
);
132 surfaceWindow
->Release();
133 delete surfaceWindow
;
136 void OnFocus(wxFocusEvent
& event
)
138 GetParent()->SetFocus();
142 void OnLeftDown(wxMouseEvent
& event
)
144 wxPoint pt
= event
.GetPosition();
147 m_swx
->CallTipClick();
150 virtual void DoSetSize(int x
, int y
,
151 int width
, int height
,
152 int sizeFlags
= wxSIZE_AUTO
)
154 // convert coords to screen coords since we're a top-level window
155 if (x
!= wxDefaultCoord
) {
157 GetParent()->ClientToScreen(&x
, NULL
);
159 if (y
!= wxDefaultCoord
) {
161 GetParent()->ClientToScreen(NULL
, &y
);
163 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
168 virtual bool Show( bool show
= true )
170 // Although we're a frame, we always want the parent to be active, so
171 // raise it whenever we get shown.
172 bool rv
= wxSTCCallTipBase::Show(show
);
175 wxTopLevelWindow
*frame
= wxDynamicCast(
176 wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
184 wxPoint
GetMyPosition()
186 return wxPoint(m_cx
, m_cy
);
193 DECLARE_EVENT_TABLE()
196 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
197 EVT_PAINT(wxSTCCallTip::OnPaint
)
198 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
199 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
203 //----------------------------------------------------------------------
206 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
210 switch (scintillaMode
) {
212 type
= wxTextFileType_Dos
;
216 type
= wxTextFileType_Mac
;
220 type
= wxTextFileType_Unix
;
224 type
= wxTextBuffer::typeDefault
;
229 #endif // wxUSE_DATAOBJ
232 //----------------------------------------------------------------------
233 // Constructor/Destructor
236 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
237 capturedMouse
= false;
251 ScintillaWX::~ScintillaWX() {
255 //----------------------------------------------------------------------
256 // base class virtuals
259 void ScintillaWX::Initialise() {
260 //ScintillaBase::Initialise();
261 #if wxUSE_DRAG_AND_DROP
262 dropTarget
= new wxSTCDropTarget
;
263 dropTarget
->SetScintilla(this);
264 stc
->SetDropTarget(dropTarget
);
265 #endif // wxUSE_DRAG_AND_DROP
266 vs
.extraFontFlag
= true; // UseAntiAliasing
270 void ScintillaWX::Finalise() {
271 ScintillaBase::Finalise();
274 DestroySystemCaret();
278 void ScintillaWX::StartDrag() {
279 #if wxUSE_DRAG_AND_DROP
280 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
282 // Send an event to allow the drag text to be changed
283 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
284 evt
.SetEventObject(stc
);
285 evt
.SetDragText(dragText
);
286 evt
.SetDragAllowMove(true);
287 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
288 stc
->GetSelectionEnd()));
289 stc
->GetEventHandler()->ProcessEvent(evt
);
290 dragText
= evt
.GetDragText();
292 if (dragText
.length()) {
293 wxDropSource
source(stc
);
294 wxTextDataObject
data(dragText
);
297 source
.SetData(data
);
298 dropWentOutside
= true;
299 inDragDrop
= ddDragging
;
300 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
301 if (result
== wxDragMove
&& dropWentOutside
)
304 SetDragPosition(invalidPosition
);
306 #endif // wxUSE_DRAG_AND_DROP
310 bool ScintillaWX::SetIdle(bool on
) {
311 if (idler
.state
!= on
) {
312 // connect or disconnect the EVT_IDLE handler
314 stc
->Connect(wxID_ANY
, wxEVT_IDLE
, wxIdleEventHandler(wxStyledTextCtrl::OnIdle
));
316 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
, wxIdleEventHandler(wxStyledTextCtrl::OnIdle
));
323 void ScintillaWX::SetTicking(bool on
) {
324 wxSTCTimer
* steTimer
;
325 if (timer
.ticking
!= on
) {
328 steTimer
= new wxSTCTimer(this);
329 steTimer
->Start(timer
.tickSize
);
330 timer
.tickerID
= steTimer
;
332 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
338 timer
.ticksToWait
= caret
.period
;
342 void ScintillaWX::SetMouseCapture(bool on
) {
343 if (mouseDownCaptures
) {
344 if (on
&& !capturedMouse
)
346 else if (!on
&& capturedMouse
&& stc
->HasCapture())
353 bool ScintillaWX::HaveMouseCapture() {
354 return capturedMouse
;
358 void ScintillaWX::ScrollText(int linesToMove
) {
359 int dy
= vs
.lineHeight
* (linesToMove
);
360 stc
->ScrollWindow(0, dy
);
364 void ScintillaWX::SetVerticalScrollPos() {
365 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
366 stc
->SetScrollPos(wxVERTICAL
, topLine
);
368 else { // otherwise use the one that's been given to us
369 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
373 void ScintillaWX::SetHorizontalScrollPos() {
374 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
375 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
377 else { // otherwise use the one that's been given to us
378 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
383 const int H_SCROLL_STEP
= 20;
385 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
386 bool modified
= false;
389 if (!verticalScrollBarVisible
)
392 // Check the vertical scrollbar
393 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
394 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
395 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
396 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
397 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
398 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
402 else { // otherwise use the one that's been given to us
403 int sbMax
= stc
->m_vScrollBar
->GetRange();
404 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
405 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
406 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
407 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
413 // Check the horizontal scrollbar
414 PRectangle rcText
= GetTextRectangle();
415 int horizEnd
= scrollWidth
;
418 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
420 int pageWidth
= rcText
.Width();
422 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
423 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
424 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
425 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
426 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
427 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
429 if (scrollWidth
< pageWidth
) {
430 HorizontalScrollTo(0);
434 else { // otherwise use the one that's been given to us
435 int sbMax
= stc
->m_hScrollBar
->GetRange();
436 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
437 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
438 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
439 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
441 if (scrollWidth
< pageWidth
) {
442 HorizontalScrollTo(0);
451 void ScintillaWX::NotifyChange() {
456 void ScintillaWX::NotifyParent(SCNotification scn
) {
457 stc
->NotifyParent(&scn
);
461 // This method is overloaded from ScintillaBase in order to prevent the
462 // AutoComplete window from being destroyed when it gets the focus. There is
463 // a side effect that the AutoComp will also not be destroyed when switching
464 // to another window, but I think that is okay.
465 void ScintillaWX::CancelModes() {
467 AutoCompleteCancel();
469 Editor::CancelModes();
474 void ScintillaWX::Copy() {
475 if (currentPos
!= anchor
) {
477 CopySelectionRange(&st
);
483 void ScintillaWX::Paste() {
484 pdoc
->BeginUndoAction();
488 wxTextDataObject data
;
489 bool gotData
= false;
491 wxTheClipboard
->UsePrimarySelection(false);
492 if (wxTheClipboard
->Open()) {
493 gotData
= wxTheClipboard
->GetData(data
);
494 wxTheClipboard
->Close();
497 wxString text
= wxTextBuffer::Translate(data
.GetText(),
498 wxConvertEOLMode(pdoc
->eolMode
));
499 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
502 // free up the old character buffer in case the text is real big
503 data
.SetText(wxEmptyString
);
504 text
= wxEmptyString
;
506 int len
= strlen(buf
);
507 pdoc
->InsertString(currentPos
, buf
, len
);
508 SetEmptySelection(currentPos
+ len
);
510 #endif // wxUSE_DATAOBJ
512 pdoc
->EndUndoAction();
518 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
523 wxTheClipboard
->UsePrimarySelection(false);
524 if (wxTheClipboard
->Open()) {
525 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
526 wxTheClipboard
->SetData(new wxTextDataObject(text
));
527 wxTheClipboard
->Close();
531 #endif // wxUSE_CLIPBOARD
535 bool ScintillaWX::CanPaste() {
537 bool canPaste
= false;
540 if (Editor::CanPaste()) {
541 wxTheClipboard
->UsePrimarySelection(false);
542 didOpen
= !wxTheClipboard
->IsOpened();
544 wxTheClipboard
->Open();
546 if (wxTheClipboard
->IsOpened()) {
547 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
549 wxTheClipboard
->Close();
555 #endif // wxUSE_CLIPBOARD
558 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
559 if (! ct
.wCallTip
.Created() ) {
560 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
561 ct
.wDraw
= ct
.wCallTip
;
566 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
568 ((wxMenu
*)popup
.GetID())->AppendSeparator();
570 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
573 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
577 // This is called by the Editor base class whenever something is selected.
578 // For wxGTK we can put this text in the primary selection and then other apps
579 // can paste with the middle button.
580 void ScintillaWX::ClaimSelection() {
582 // Put the selected text in the PRIMARY selection
583 if (currentPos
!= anchor
) {
585 CopySelectionRange(&st
);
586 wxTheClipboard
->UsePrimarySelection(true);
587 if (wxTheClipboard
->Open()) {
588 wxString text
= stc2wx(st
.s
, st
.len
);
589 wxTheClipboard
->SetData(new wxTextDataObject(text
));
590 wxTheClipboard
->Close();
592 wxTheClipboard
->UsePrimarySelection(false);
598 void ScintillaWX::UpdateSystemCaret() {
601 if (HasCaretSizeChanged()) {
602 DestroySystemCaret();
605 Point pos
= LocationFromPosition(currentPos
);
606 ::SetCaretPos(pos
.x
, pos
.y
);
612 bool ScintillaWX::HasCaretSizeChanged() {
614 if ( (vs
.caretWidth
&& (sysCaretWidth
!= vs
.caretWidth
))
615 || (vs
.lineHeight
&& (sysCaretHeight
!= vs
.lineHeight
)) ) {
622 bool ScintillaWX::CreateSystemCaret() {
624 sysCaretWidth
= vs
.caretWidth
;
625 if (0 == sysCaretWidth
) {
628 sysCaretHeight
= vs
.lineHeight
;
629 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
630 char *bits
= new char[bitmapSize
];
631 memset(bits
, 0, bitmapSize
);
632 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
633 1, reinterpret_cast<BYTE
*>(bits
));
635 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
636 sysCaretWidth
, sysCaretHeight
);
637 ::ShowCaret(GetHwndOf(stc
));
644 bool ScintillaWX::DestroySystemCaret() {
646 ::HideCaret(GetHwndOf(stc
));
647 BOOL retval
= ::DestroyCaret();
648 if (sysCaretBitmap
) {
649 ::DeleteObject(sysCaretBitmap
);
659 //----------------------------------------------------------------------
662 sptr_t
ScintillaWX::DefWndProc(unsigned int /*iMessage*/, uptr_t
/*wParam*/, sptr_t
/*lParam*/) {
666 sptr_t
ScintillaWX::WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) {
668 case SCI_CALLTIPSHOW
: {
669 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
670 // because of the little tweak that needs done below for wxGTK.
671 // When updating new versions double check that this is still
672 // needed, and that any new code there is copied here too.
673 Point pt
= LocationFromPosition(wParam
);
674 char* defn
= reinterpret_cast<char *>(lParam
);
675 AutoCompleteCancel();
676 pt
.y
+= vs
.lineHeight
;
677 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
679 vs
.styles
[STYLE_DEFAULT
].fontName
,
680 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
682 vs
.styles
[STYLE_DEFAULT
].characterSet
,
684 // If the call-tip window would be out of the client
685 // space, adjust so it displays above the text.
686 PRectangle rcClient
= GetClientRectangle();
687 if (rc
.bottom
> rcClient
.bottom
) {
689 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
691 int offset
= vs
.lineHeight
+ rc
.Height();
696 // Now display the window.
697 CreateCallTipWindow(rc
);
698 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
704 case SCI_LOADLEXERLIBRARY
:
705 LexerManager::GetInstance()->Load((const char*)lParam
);
710 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
717 //----------------------------------------------------------------------
720 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
722 paintState
= painting
;
723 Surface
* surfaceWindow
= Surface::Allocate();
724 surfaceWindow
->Init(dc
, wMain
.GetID());
725 rcPaint
= PRectangleFromwxRect(rect
);
726 PRectangle rcClient
= GetClientRectangle();
727 paintingAllText
= rcPaint
.Contains(rcClient
);
729 ClipChildren(*dc
, rcPaint
);
730 Paint(surfaceWindow
, rcPaint
);
732 delete surfaceWindow
;
733 if (paintState
== paintAbandoned
) {
734 // Painting area was insufficient to cover new styling or brace
735 // highlight positions
738 paintState
= notPainting
;
742 void ScintillaWX::DoHScroll(int type
, int pos
) {
744 PRectangle rcText
= GetTextRectangle();
745 int pageWidth
= rcText
.Width() * 2 / 3;
746 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
747 xPos
-= H_SCROLL_STEP
;
748 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
749 xPos
+= H_SCROLL_STEP
;
750 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
752 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
754 if (xPos
> scrollWidth
- rcText
.Width()) {
755 xPos
= scrollWidth
- rcText
.Width();
758 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
760 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
762 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
765 HorizontalScrollTo(xPos
);
768 void ScintillaWX::DoVScroll(int type
, int pos
) {
769 int topLineNew
= topLine
;
770 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
772 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
774 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
775 topLineNew
-= LinesToScroll();
776 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
777 topLineNew
+= LinesToScroll();
778 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
780 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
781 topLineNew
= MaxScrollPos();
782 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
785 ScrollTo(topLineNew
);
788 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
789 int linesPerAction
, int ctrlDown
,
790 bool isPageScroll
) {
791 int topLineNew
= topLine
;
794 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
796 KeyCommand(SCI_ZOOMIN
);
799 KeyCommand(SCI_ZOOMOUT
);
802 else { // otherwise just scroll the window
805 wheelRotation
+= rotation
;
806 lines
= wheelRotation
/ delta
;
807 wheelRotation
-= lines
* delta
;
810 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
812 lines
*= linesPerAction
;
814 ScrollTo(topLineNew
);
820 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
824 void ScintillaWX::DoLoseFocus(){
826 SetFocusState(false);
828 DestroySystemCaret();
831 void ScintillaWX::DoGainFocus(){
835 DestroySystemCaret();
839 void ScintillaWX::DoSysColourChange() {
840 InvalidateStyleData();
843 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
844 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
847 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
848 ButtonUp(pt
, curTime
, ctrl
);
851 void ScintillaWX::DoLeftButtonMove(Point pt
) {
856 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
857 // Set the current position to the mouse click point and
858 // then paste in the PRIMARY selection, if any. wxGTK only.
859 int newPos
= PositionFromLocation(pt
);
860 MovePositionTo(newPos
, noSel
, true);
862 pdoc
->BeginUndoAction();
863 wxTextDataObject data
;
864 bool gotData
= false;
865 wxTheClipboard
->UsePrimarySelection(true);
866 if (wxTheClipboard
->Open()) {
867 gotData
= wxTheClipboard
->GetData(data
);
868 wxTheClipboard
->Close();
870 wxTheClipboard
->UsePrimarySelection(false);
872 wxString text
= wxTextBuffer::Translate(data
.GetText(),
873 wxConvertEOLMode(pdoc
->eolMode
));
874 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
875 int len
= strlen(buf
);
876 pdoc
->InsertString(currentPos
, buf
, len
);
877 SetEmptySelection(currentPos
+ len
);
879 pdoc
->EndUndoAction();
883 ShowCaretAtCurrentPosition();
884 EnsureCaretVisible();
887 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
892 void ScintillaWX::DoAddChar(int key
) {
895 wszChars
[0] = (wxChar
)key
;
897 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
898 AddCharUTF((char*)buf
.data(), strlen(buf
));
905 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
907 int key
= evt
.GetKeyCode();
908 bool shift
= evt
.ShiftDown(),
909 ctrl
= evt
.ControlDown(),
912 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
916 case WXK_DOWN
: key
= SCK_DOWN
; break;
917 case WXK_UP
: key
= SCK_UP
; break;
918 case WXK_LEFT
: key
= SCK_LEFT
; break;
919 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
920 case WXK_HOME
: key
= SCK_HOME
; break;
921 case WXK_END
: key
= SCK_END
; break;
922 case WXK_PAGEUP
: key
= SCK_PRIOR
; break;
923 case WXK_PAGEDOWN
: key
= SCK_NEXT
; break;
924 case WXK_NUMPAD_DOWN
: key
= SCK_DOWN
; break;
925 case WXK_NUMPAD_UP
: key
= SCK_UP
; break;
926 case WXK_NUMPAD_LEFT
: key
= SCK_LEFT
; break;
927 case WXK_NUMPAD_RIGHT
: key
= SCK_RIGHT
; break;
928 case WXK_NUMPAD_HOME
: key
= SCK_HOME
; break;
929 case WXK_NUMPAD_END
: key
= SCK_END
; break;
930 case WXK_NUMPAD_PAGEUP
: key
= SCK_PRIOR
; break;
931 case WXK_NUMPAD_PAGEDOWN
: key
= SCK_NEXT
; break;
932 case WXK_NUMPAD_DELETE
: key
= SCK_DELETE
; break;
933 case WXK_NUMPAD_INSERT
: key
= SCK_INSERT
; break;
934 case WXK_DELETE
: key
= SCK_DELETE
; break;
935 case WXK_INSERT
: key
= SCK_INSERT
; break;
936 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
937 case WXK_BACK
: key
= SCK_BACK
; break;
938 case WXK_TAB
: key
= SCK_TAB
; break;
939 case WXK_NUMPAD_ENTER
: // fall through
940 case WXK_RETURN
: key
= SCK_RETURN
; break;
941 case WXK_ADD
: // fall through
942 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
943 case WXK_SUBTRACT
: // fall through
944 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
945 case WXK_DIVIDE
: // fall through
946 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
947 case WXK_CONTROL
: key
= 0; break;
948 case WXK_ALT
: key
= 0; break;
949 case WXK_SHIFT
: key
= 0; break;
950 case WXK_MENU
: key
= 0; break;
954 if ( evt
.MetaDown() ) {
955 // check for a few common Mac Meta-key combos and remap them to Ctrl
962 case 'A': // Select All
969 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
978 void ScintillaWX::DoCommand(int ID
) {
983 void ScintillaWX::DoContextMenu(Point pt
) {
984 if (displayPopupMenu
)
988 void ScintillaWX::DoOnListBox() {
989 AutoCompleteCompleted();
993 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
1001 //----------------------------------------------------------------------
1003 #if wxUSE_DRAG_AND_DROP
1004 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
1005 SetDragPosition(invalidPosition
);
1007 wxString text
= wxTextBuffer::Translate(data
,
1008 wxConvertEOLMode(pdoc
->eolMode
));
1010 // Send an event to allow the drag details to be changed
1011 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
1012 evt
.SetEventObject(stc
);
1013 evt
.SetDragResult(dragResult
);
1016 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1017 evt
.SetDragText(text
);
1018 stc
->GetEventHandler()->ProcessEvent(evt
);
1020 dragResult
= evt
.GetDragResult();
1021 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
1022 DropAt(evt
.GetPosition(),
1023 wx2stc(evt
.GetDragText()),
1024 dragResult
== wxDragMove
,
1025 false); // TODO: rectangular?
1032 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1038 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1039 SetDragPosition(PositionFromLocation(Point(x
, y
)));
1041 // Send an event to allow the drag result to be changed
1042 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1043 evt
.SetEventObject(stc
);
1044 evt
.SetDragResult(def
);
1047 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1048 stc
->GetEventHandler()->ProcessEvent(evt
);
1050 dragResult
= evt
.GetDragResult();
1055 void ScintillaWX::DoDragLeave() {
1056 SetDragPosition(invalidPosition
);
1058 #endif // wxUSE_DRAG_AND_DROP
1059 //----------------------------------------------------------------------
1061 // Force the whole window to be repainted
1062 void ScintillaWX::FullPaint() {
1064 stc
->Refresh(false);
1070 void ScintillaWX::DoScrollToLine(int line
) {
1075 void ScintillaWX::DoScrollToColumn(int column
) {
1076 HorizontalScrollTo(column
* vs
.spaceWidth
);
1079 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1080 // will leave it here commented out for a while just in case...
1081 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1083 // wxRegion rgn(wxRectFromPRectangle(rect));
1084 // if (ac.Active()) {
1085 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1086 // rgn.Subtract(childRect);
1088 // if (ct.inCallTipMode) {
1089 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1090 // wxRect childRect = tip->GetRect();
1091 // #if wxUSE_POPUPWIN
1092 // childRect.SetPosition(tip->GetMyPosition());
1094 // rgn.Subtract(childRect);
1096 // dc.SetClippingRegion(rgn);
1100 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1101 vs
.extraFontFlag
= useAA
;
1102 InvalidateStyleRedraw();
1105 bool ScintillaWX::GetUseAntiAliasing() {
1106 return vs
.extraFontFlag
;
1109 //----------------------------------------------------------------------
1110 //----------------------------------------------------------------------