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
267 vs
.extraFontFlag
= false; // UseAntiAliasing
269 vs
.extraFontFlag
= true; // UseAntiAliasing
274 void ScintillaWX::Finalise() {
275 ScintillaBase::Finalise();
278 DestroySystemCaret();
282 void ScintillaWX::StartDrag() {
283 #if wxUSE_DRAG_AND_DROP
284 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
286 // Send an event to allow the drag text to be changed
287 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
288 evt
.SetEventObject(stc
);
289 evt
.SetDragText(dragText
);
290 evt
.SetDragAllowMove(true);
291 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
292 stc
->GetSelectionEnd()));
293 stc
->GetEventHandler()->ProcessEvent(evt
);
294 dragText
= evt
.GetDragText();
296 if (dragText
.length()) {
297 wxDropSource
source(stc
);
298 wxTextDataObject
data(dragText
);
301 source
.SetData(data
);
302 dropWentOutside
= true;
303 inDragDrop
= ddDragging
;
304 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
305 if (result
== wxDragMove
&& dropWentOutside
)
308 SetDragPosition(invalidPosition
);
310 #endif // wxUSE_DRAG_AND_DROP
314 bool ScintillaWX::SetIdle(bool on
) {
315 if (idler
.state
!= on
) {
316 // connect or disconnect the EVT_IDLE handler
318 stc
->Connect(wxID_ANY
, wxEVT_IDLE
,
319 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
321 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
,
322 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
329 void ScintillaWX::SetTicking(bool on
) {
330 wxSTCTimer
* steTimer
;
331 if (timer
.ticking
!= on
) {
334 steTimer
= new wxSTCTimer(this);
335 steTimer
->Start(timer
.tickSize
);
336 timer
.tickerID
= steTimer
;
338 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
344 timer
.ticksToWait
= caret
.period
;
348 void ScintillaWX::SetMouseCapture(bool on
) {
349 if (mouseDownCaptures
) {
350 if (on
&& !capturedMouse
)
352 else if (!on
&& capturedMouse
&& stc
->HasCapture())
359 bool ScintillaWX::HaveMouseCapture() {
360 return capturedMouse
;
364 void ScintillaWX::ScrollText(int linesToMove
) {
365 int dy
= vs
.lineHeight
* (linesToMove
);
366 stc
->ScrollWindow(0, dy
);
370 void ScintillaWX::SetVerticalScrollPos() {
371 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
372 stc
->SetScrollPos(wxVERTICAL
, topLine
);
374 else { // otherwise use the one that's been given to us
375 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
379 void ScintillaWX::SetHorizontalScrollPos() {
380 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
381 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
383 else { // otherwise use the one that's been given to us
384 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
389 const int H_SCROLL_STEP
= 20;
391 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
392 bool modified
= false;
395 if (!verticalScrollBarVisible
)
398 // Check the vertical scrollbar
399 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
400 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
401 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
402 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
403 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
404 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
408 else { // otherwise use the one that's been given to us
409 int sbMax
= stc
->m_vScrollBar
->GetRange();
410 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
411 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
412 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
413 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
419 // Check the horizontal scrollbar
420 PRectangle rcText
= GetTextRectangle();
421 int horizEnd
= scrollWidth
;
424 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
426 int pageWidth
= rcText
.Width();
428 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
429 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
430 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
431 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
432 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
433 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
435 if (scrollWidth
< pageWidth
) {
436 HorizontalScrollTo(0);
440 else { // otherwise use the one that's been given to us
441 int sbMax
= stc
->m_hScrollBar
->GetRange();
442 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
443 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
444 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
445 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
447 if (scrollWidth
< pageWidth
) {
448 HorizontalScrollTo(0);
457 void ScintillaWX::NotifyChange() {
462 void ScintillaWX::NotifyParent(SCNotification scn
) {
463 stc
->NotifyParent(&scn
);
467 // This method is overloaded from ScintillaBase in order to prevent the
468 // AutoComplete window from being destroyed when it gets the focus. There is
469 // a side effect that the AutoComp will also not be destroyed when switching
470 // to another window, but I think that is okay.
471 void ScintillaWX::CancelModes() {
473 AutoCompleteCancel();
475 Editor::CancelModes();
480 void ScintillaWX::Copy() {
481 if (currentPos
!= anchor
) {
483 CopySelectionRange(&st
);
489 void ScintillaWX::Paste() {
490 pdoc
->BeginUndoAction();
494 wxTextDataObject data
;
495 bool gotData
= false;
497 wxTheClipboard
->UsePrimarySelection(false);
498 if (wxTheClipboard
->Open()) {
499 gotData
= wxTheClipboard
->GetData(data
);
500 wxTheClipboard
->Close();
503 wxString text
= wxTextBuffer::Translate(data
.GetText(),
504 wxConvertEOLMode(pdoc
->eolMode
));
505 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
508 // free up the old character buffer in case the text is real big
509 data
.SetText(wxEmptyString
);
510 text
= wxEmptyString
;
512 int len
= strlen(buf
);
513 pdoc
->InsertString(currentPos
, buf
, len
);
514 SetEmptySelection(currentPos
+ len
);
516 #endif // wxUSE_DATAOBJ
518 pdoc
->EndUndoAction();
524 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
529 wxTheClipboard
->UsePrimarySelection(false);
530 if (wxTheClipboard
->Open()) {
531 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
532 wxTheClipboard
->SetData(new wxTextDataObject(text
));
533 wxTheClipboard
->Close();
537 #endif // wxUSE_CLIPBOARD
541 bool ScintillaWX::CanPaste() {
543 bool canPaste
= false;
546 if (Editor::CanPaste()) {
547 wxTheClipboard
->UsePrimarySelection(false);
548 didOpen
= !wxTheClipboard
->IsOpened();
550 wxTheClipboard
->Open();
552 if (wxTheClipboard
->IsOpened()) {
553 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
555 wxTheClipboard
->Close();
561 #endif // wxUSE_CLIPBOARD
564 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
565 if (! ct
.wCallTip
.Created() ) {
566 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
567 ct
.wDraw
= ct
.wCallTip
;
572 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
574 ((wxMenu
*)popup
.GetID())->AppendSeparator();
576 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
579 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
583 // This is called by the Editor base class whenever something is selected.
584 // For wxGTK we can put this text in the primary selection and then other apps
585 // can paste with the middle button.
586 void ScintillaWX::ClaimSelection() {
588 // Put the selected text in the PRIMARY selection
589 if (currentPos
!= anchor
) {
591 CopySelectionRange(&st
);
592 wxTheClipboard
->UsePrimarySelection(true);
593 if (wxTheClipboard
->Open()) {
594 wxString text
= stc2wx(st
.s
, st
.len
);
595 wxTheClipboard
->SetData(new wxTextDataObject(text
));
596 wxTheClipboard
->Close();
598 wxTheClipboard
->UsePrimarySelection(false);
604 void ScintillaWX::UpdateSystemCaret() {
607 if (HasCaretSizeChanged()) {
608 DestroySystemCaret();
611 Point pos
= LocationFromPosition(currentPos
);
612 ::SetCaretPos(pos
.x
, pos
.y
);
618 bool ScintillaWX::HasCaretSizeChanged() {
620 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
621 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
628 bool ScintillaWX::CreateSystemCaret() {
630 sysCaretWidth
= vs
.caretWidth
;
631 if (0 == sysCaretWidth
) {
634 sysCaretHeight
= vs
.lineHeight
;
635 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
636 char *bits
= new char[bitmapSize
];
637 memset(bits
, 0, bitmapSize
);
638 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
639 1, reinterpret_cast<BYTE
*>(bits
));
641 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
642 sysCaretWidth
, sysCaretHeight
);
643 ::ShowCaret(GetHwndOf(stc
));
650 bool ScintillaWX::DestroySystemCaret() {
652 ::HideCaret(GetHwndOf(stc
));
653 BOOL retval
= ::DestroyCaret();
654 if (sysCaretBitmap
) {
655 ::DeleteObject(sysCaretBitmap
);
665 //----------------------------------------------------------------------
668 sptr_t
ScintillaWX::DefWndProc(unsigned int /*iMessage*/, uptr_t
/*wParam*/, sptr_t
/*lParam*/) {
672 sptr_t
ScintillaWX::WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) {
674 case SCI_CALLTIPSHOW
: {
675 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
676 // because of the little tweak that needs done below for wxGTK.
677 // When updating new versions double check that this is still
678 // needed, and that any new code there is copied here too.
679 Point pt
= LocationFromPosition(wParam
);
680 char* defn
= reinterpret_cast<char *>(lParam
);
681 AutoCompleteCancel();
682 pt
.y
+= vs
.lineHeight
;
683 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
685 vs
.styles
[STYLE_DEFAULT
].fontName
,
686 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
688 vs
.styles
[STYLE_DEFAULT
].characterSet
,
690 // If the call-tip window would be out of the client
691 // space, adjust so it displays above the text.
692 PRectangle rcClient
= GetClientRectangle();
693 if (rc
.bottom
> rcClient
.bottom
) {
695 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
697 int offset
= vs
.lineHeight
+ rc
.Height();
702 // Now display the window.
703 CreateCallTipWindow(rc
);
704 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
710 case SCI_LOADLEXERLIBRARY
:
711 LexerManager::GetInstance()->Load((const char*)lParam
);
716 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
723 //----------------------------------------------------------------------
726 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
728 paintState
= painting
;
729 Surface
* surfaceWindow
= Surface::Allocate();
730 surfaceWindow
->Init(dc
, wMain
.GetID());
731 rcPaint
= PRectangleFromwxRect(rect
);
732 PRectangle rcClient
= GetClientRectangle();
733 paintingAllText
= rcPaint
.Contains(rcClient
);
735 ClipChildren(*dc
, rcPaint
);
736 Paint(surfaceWindow
, rcPaint
);
738 delete surfaceWindow
;
739 if (paintState
== paintAbandoned
) {
740 // Painting area was insufficient to cover new styling or brace
741 // highlight positions
744 paintState
= notPainting
;
748 void ScintillaWX::DoHScroll(int type
, int pos
) {
750 PRectangle rcText
= GetTextRectangle();
751 int pageWidth
= rcText
.Width() * 2 / 3;
752 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
753 xPos
-= H_SCROLL_STEP
;
754 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
755 xPos
+= H_SCROLL_STEP
;
756 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
758 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
760 if (xPos
> scrollWidth
- rcText
.Width()) {
761 xPos
= scrollWidth
- rcText
.Width();
764 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
766 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
768 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
771 HorizontalScrollTo(xPos
);
774 void ScintillaWX::DoVScroll(int type
, int pos
) {
775 int topLineNew
= topLine
;
776 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
778 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
780 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
781 topLineNew
-= LinesToScroll();
782 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
783 topLineNew
+= LinesToScroll();
784 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
786 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
787 topLineNew
= MaxScrollPos();
788 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
791 ScrollTo(topLineNew
);
794 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
795 int linesPerAction
, int ctrlDown
,
796 bool isPageScroll
) {
797 int topLineNew
= topLine
;
800 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
802 KeyCommand(SCI_ZOOMIN
);
805 KeyCommand(SCI_ZOOMOUT
);
808 else { // otherwise just scroll the window
811 wheelRotation
+= rotation
;
812 lines
= wheelRotation
/ delta
;
813 wheelRotation
-= lines
* delta
;
816 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
818 lines
*= linesPerAction
;
820 ScrollTo(topLineNew
);
826 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
830 void ScintillaWX::DoLoseFocus(){
832 SetFocusState(false);
834 DestroySystemCaret();
837 void ScintillaWX::DoGainFocus(){
841 DestroySystemCaret();
845 void ScintillaWX::DoSysColourChange() {
846 InvalidateStyleData();
849 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
850 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
853 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
854 ButtonUp(pt
, curTime
, ctrl
);
857 void ScintillaWX::DoLeftButtonMove(Point pt
) {
862 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
863 // Set the current position to the mouse click point and
864 // then paste in the PRIMARY selection, if any. wxGTK only.
865 int newPos
= PositionFromLocation(pt
);
866 MovePositionTo(newPos
, noSel
, true);
868 pdoc
->BeginUndoAction();
869 wxTextDataObject data
;
870 bool gotData
= false;
871 wxTheClipboard
->UsePrimarySelection(true);
872 if (wxTheClipboard
->Open()) {
873 gotData
= wxTheClipboard
->GetData(data
);
874 wxTheClipboard
->Close();
876 wxTheClipboard
->UsePrimarySelection(false);
878 wxString text
= wxTextBuffer::Translate(data
.GetText(),
879 wxConvertEOLMode(pdoc
->eolMode
));
880 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
881 int len
= strlen(buf
);
882 pdoc
->InsertString(currentPos
, buf
, len
);
883 SetEmptySelection(currentPos
+ len
);
885 pdoc
->EndUndoAction();
889 ShowCaretAtCurrentPosition();
890 EnsureCaretVisible();
893 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
898 void ScintillaWX::DoAddChar(int key
) {
901 wszChars
[0] = (wxChar
)key
;
903 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
904 AddCharUTF((char*)buf
.data(), strlen(buf
));
911 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
913 int key
= evt
.GetKeyCode();
914 bool shift
= evt
.ShiftDown(),
915 ctrl
= evt
.ControlDown(),
918 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
922 case WXK_DOWN
: key
= SCK_DOWN
; break;
923 case WXK_UP
: key
= SCK_UP
; break;
924 case WXK_LEFT
: key
= SCK_LEFT
; break;
925 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
926 case WXK_HOME
: key
= SCK_HOME
; break;
927 case WXK_END
: key
= SCK_END
; break;
928 case WXK_PAGEUP
: key
= SCK_PRIOR
; break;
929 case WXK_PAGEDOWN
: key
= SCK_NEXT
; break;
930 case WXK_NUMPAD_DOWN
: key
= SCK_DOWN
; break;
931 case WXK_NUMPAD_UP
: key
= SCK_UP
; break;
932 case WXK_NUMPAD_LEFT
: key
= SCK_LEFT
; break;
933 case WXK_NUMPAD_RIGHT
: key
= SCK_RIGHT
; break;
934 case WXK_NUMPAD_HOME
: key
= SCK_HOME
; break;
935 case WXK_NUMPAD_END
: key
= SCK_END
; break;
936 case WXK_NUMPAD_PAGEUP
: key
= SCK_PRIOR
; break;
937 case WXK_NUMPAD_PAGEDOWN
: key
= SCK_NEXT
; break;
938 case WXK_NUMPAD_DELETE
: key
= SCK_DELETE
; break;
939 case WXK_NUMPAD_INSERT
: key
= SCK_INSERT
; break;
940 case WXK_DELETE
: key
= SCK_DELETE
; break;
941 case WXK_INSERT
: key
= SCK_INSERT
; break;
942 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
943 case WXK_BACK
: key
= SCK_BACK
; break;
944 case WXK_TAB
: key
= SCK_TAB
; break;
945 case WXK_NUMPAD_ENTER
: // fall through
946 case WXK_RETURN
: key
= SCK_RETURN
; break;
947 case WXK_ADD
: // fall through
948 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
949 case WXK_SUBTRACT
: // fall through
950 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
951 case WXK_DIVIDE
: // fall through
952 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
953 case WXK_CONTROL
: key
= 0; break;
954 case WXK_ALT
: key
= 0; break;
955 case WXK_SHIFT
: key
= 0; break;
956 case WXK_MENU
: key
= 0; break;
960 if ( evt
.MetaDown() ) {
961 // check for a few common Mac Meta-key combos and remap them to Ctrl
968 case 'A': // Select All
975 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
984 void ScintillaWX::DoCommand(int ID
) {
989 void ScintillaWX::DoContextMenu(Point pt
) {
990 if (displayPopupMenu
)
994 void ScintillaWX::DoOnListBox() {
995 AutoCompleteCompleted();
999 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
1007 //----------------------------------------------------------------------
1009 #if wxUSE_DRAG_AND_DROP
1010 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
1011 SetDragPosition(invalidPosition
);
1013 wxString text
= wxTextBuffer::Translate(data
,
1014 wxConvertEOLMode(pdoc
->eolMode
));
1016 // Send an event to allow the drag details to be changed
1017 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
1018 evt
.SetEventObject(stc
);
1019 evt
.SetDragResult(dragResult
);
1022 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1023 evt
.SetDragText(text
);
1024 stc
->GetEventHandler()->ProcessEvent(evt
);
1026 dragResult
= evt
.GetDragResult();
1027 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
1028 DropAt(evt
.GetPosition(),
1029 wx2stc(evt
.GetDragText()),
1030 dragResult
== wxDragMove
,
1031 false); // TODO: rectangular?
1038 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1044 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1045 SetDragPosition(PositionFromLocation(Point(x
, y
)));
1047 // Send an event to allow the drag result to be changed
1048 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1049 evt
.SetEventObject(stc
);
1050 evt
.SetDragResult(def
);
1053 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1054 stc
->GetEventHandler()->ProcessEvent(evt
);
1056 dragResult
= evt
.GetDragResult();
1061 void ScintillaWX::DoDragLeave() {
1062 SetDragPosition(invalidPosition
);
1064 #endif // wxUSE_DRAG_AND_DROP
1065 //----------------------------------------------------------------------
1067 // Force the whole window to be repainted
1068 void ScintillaWX::FullPaint() {
1070 stc
->Refresh(false);
1076 void ScintillaWX::DoScrollToLine(int line
) {
1081 void ScintillaWX::DoScrollToColumn(int column
) {
1082 HorizontalScrollTo(column
* vs
.spaceWidth
);
1085 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1086 // will leave it here commented out for a while just in case...
1087 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1089 // wxRegion rgn(wxRectFromPRectangle(rect));
1090 // if (ac.Active()) {
1091 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1092 // rgn.Subtract(childRect);
1094 // if (ct.inCallTipMode) {
1095 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1096 // wxRect childRect = tip->GetRect();
1097 // #if wxUSE_POPUPWIN
1098 // childRect.SetPosition(tip->GetMyPosition());
1100 // rgn.Subtract(childRect);
1102 // dc.SetClippingRegion(rgn);
1106 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1107 vs
.extraFontFlag
= useAA
;
1108 InvalidateStyleRedraw();
1111 bool ScintillaWX::GetUseAntiAliasing() {
1112 return vs
.extraFontFlag
;
1115 //----------------------------------------------------------------------
1116 //----------------------------------------------------------------------