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 class wxStartDragTimer
: public wxTimer
{
54 wxStartDragTimer(ScintillaWX
* swx
) {
67 bool wxSTCDropTarget::OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) {
68 return swx
->DoDropText(x
, y
, data
);
71 wxDragResult
wxSTCDropTarget::OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
) {
72 return swx
->DoDragEnter(x
, y
, def
);
75 wxDragResult
wxSTCDropTarget::OnDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
76 return swx
->DoDragOver(x
, y
, def
);
79 void wxSTCDropTarget::OnLeave() {
85 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
86 #include <wx/popupwin.h>
87 #define wxSTCCallTipBase wxPopupWindow
88 #define param2 wxBORDER_NONE // popup's 2nd param is flags
90 #define wxSTCCallTipBase wxWindow
91 #define param2 -1 // wxWindow's 2nd param is ID
94 #include <wx/dcbuffer.h>
96 class wxSTCCallTip
: public wxSTCCallTipBase
{
98 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
)
99 : wxSTCCallTipBase(parent
, param2
),
100 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
105 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP && defined(__WXGTK__)
106 wxRect rect
= GetRect();
109 GetParent()->Refresh(false, &rect
);
113 bool AcceptsFocus() const { return false; }
115 void OnPaint(wxPaintEvent
& WXUNUSED(evt
)) {
116 wxBufferedPaintDC
dc(this);
117 Surface
* surfaceWindow
= Surface::Allocate();
118 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
119 m_ct
->PaintCT(surfaceWindow
);
120 surfaceWindow
->Release();
121 delete surfaceWindow
;
124 void OnFocus(wxFocusEvent
& event
) {
125 GetParent()->SetFocus();
129 void OnLeftDown(wxMouseEvent
& event
) {
130 wxPoint pt
= event
.GetPosition();
133 m_swx
->CallTipClick();
136 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
137 virtual void DoSetSize(int x
, int y
,
138 int width
, int height
,
139 int sizeFlags
= wxSIZE_AUTO
) {
140 if (x
!= wxDefaultCoord
) {
142 GetParent()->ClientToScreen(&x
, NULL
);
144 if (y
!= wxDefaultCoord
) {
146 GetParent()->ClientToScreen(NULL
, &y
);
148 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
152 wxPoint
GetMyPosition() {
153 return wxPoint(m_cx
, m_cy
);
160 DECLARE_EVENT_TABLE()
163 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
164 EVT_PAINT(wxSTCCallTip::OnPaint
)
165 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
166 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
170 //----------------------------------------------------------------------
173 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
177 switch (scintillaMode
) {
179 type
= wxTextFileType_Dos
;
183 type
= wxTextFileType_Mac
;
187 type
= wxTextFileType_Unix
;
191 type
= wxTextBuffer::typeDefault
;
196 #endif // wxUSE_DATAOBJ
199 //----------------------------------------------------------------------
200 // Constructor/Destructor
203 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
204 capturedMouse
= false;
215 #if wxUSE_DRAG_AND_DROP
216 startDragTimer
= new wxStartDragTimer(this);
221 ScintillaWX::~ScintillaWX() {
222 delete startDragTimer
;
226 //----------------------------------------------------------------------
227 // base class virtuals
230 void ScintillaWX::Initialise() {
231 //ScintillaBase::Initialise();
232 #if wxUSE_DRAG_AND_DROP
233 dropTarget
= new wxSTCDropTarget
;
234 dropTarget
->SetScintilla(this);
235 stc
->SetDropTarget(dropTarget
);
238 vs
.extraFontFlag
= false; // UseAntiAliasing
240 vs
.extraFontFlag
= true; // UseAntiAliasing
245 void ScintillaWX::Finalise() {
246 ScintillaBase::Finalise();
249 DestroySystemCaret();
253 void ScintillaWX::StartDrag() {
254 #if wxUSE_DRAG_AND_DROP
255 // We defer the starting of the DnD, otherwise the LeftUp of a normal
256 // click could be lost and the STC will think it is doing a DnD when the
257 // user just wanted a normal click.
258 startDragTimer
->Start(100, true);
262 void ScintillaWX::DoStartDrag() {
263 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
265 // Send an event to allow the drag text to be changed
266 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
267 evt
.SetEventObject(stc
);
268 evt
.SetDragText(dragText
);
269 evt
.SetDragAllowMove(true);
270 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
271 stc
->GetSelectionEnd()));
272 stc
->GetEventHandler()->ProcessEvent(evt
);
273 dragText
= evt
.GetDragText();
275 if (dragText
.Length()) {
276 wxDropSource
source(stc
);
277 wxTextDataObject
data(dragText
);
280 source
.SetData(data
);
281 dropWentOutside
= true;
282 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
283 if (result
== wxDragMove
&& dropWentOutside
)
286 SetDragPosition(invalidPosition
);
291 bool ScintillaWX::SetIdle(bool on
) {
292 if (idler
.state
!= on
) {
293 // connect or disconnect the EVT_IDLE handler
295 stc
->Connect(wxID_ANY
, wxEVT_IDLE
,
296 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
298 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
,
299 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
306 void ScintillaWX::SetTicking(bool on
) {
307 wxSTCTimer
* steTimer
;
308 if (timer
.ticking
!= on
) {
311 steTimer
= new wxSTCTimer(this);
312 steTimer
->Start(timer
.tickSize
);
313 timer
.tickerID
= steTimer
;
315 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
321 timer
.ticksToWait
= caret
.period
;
325 void ScintillaWX::SetMouseCapture(bool on
) {
326 if (mouseDownCaptures
) {
327 if (on
&& !capturedMouse
)
329 else if (!on
&& capturedMouse
&& stc
->HasCapture())
336 bool ScintillaWX::HaveMouseCapture() {
337 return capturedMouse
;
341 void ScintillaWX::ScrollText(int linesToMove
) {
342 int dy
= vs
.lineHeight
* (linesToMove
);
343 stc
->ScrollWindow(0, dy
);
347 void ScintillaWX::SetVerticalScrollPos() {
348 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
349 stc
->SetScrollPos(wxVERTICAL
, topLine
);
351 else { // otherwise use the one that's been given to us
352 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
356 void ScintillaWX::SetHorizontalScrollPos() {
357 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
358 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
360 else { // otherwise use the one that's been given to us
361 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
366 const int H_SCROLL_STEP
= 20;
368 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
369 bool modified
= false;
372 if (!verticalScrollBarVisible
)
375 // Check the vertical scrollbar
376 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
377 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
378 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
379 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
380 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
381 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
385 else { // otherwise use the one that's been given to us
386 int sbMax
= stc
->m_vScrollBar
->GetRange();
387 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
388 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
389 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
390 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
396 // Check the horizontal scrollbar
397 PRectangle rcText
= GetTextRectangle();
398 int horizEnd
= scrollWidth
;
401 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
403 int pageWidth
= rcText
.Width();
405 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
406 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
407 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
408 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
409 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
410 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
412 if (scrollWidth
< pageWidth
) {
413 HorizontalScrollTo(0);
417 else { // otherwise use the one that's been given to us
418 int sbMax
= stc
->m_hScrollBar
->GetRange();
419 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
420 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
421 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
422 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
424 if (scrollWidth
< pageWidth
) {
425 HorizontalScrollTo(0);
434 void ScintillaWX::NotifyChange() {
439 void ScintillaWX::NotifyParent(SCNotification scn
) {
440 stc
->NotifyParent(&scn
);
444 // This method is overloaded from ScintillaBase in order to prevent the
445 // AutoComplete window from being destroyed when it gets the focus. There is
446 // a side effect that the AutoComp will also not be destroyed when switching
447 // to another window, but I think that is okay.
448 void ScintillaWX::CancelModes() {
450 AutoCompleteCancel();
452 Editor::CancelModes();
457 void ScintillaWX::Copy() {
458 if (currentPos
!= anchor
) {
460 CopySelectionRange(&st
);
466 void ScintillaWX::Paste() {
467 pdoc
->BeginUndoAction();
471 wxTextDataObject data
;
472 bool gotData
= false;
474 if (wxTheClipboard
->Open()) {
475 wxTheClipboard
->UsePrimarySelection(false);
476 gotData
= wxTheClipboard
->GetData(data
);
477 wxTheClipboard
->Close();
480 wxString text
= wxTextBuffer::Translate(data
.GetText(),
481 wxConvertEOLMode(pdoc
->eolMode
));
482 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
483 int len
= strlen(buf
);
484 pdoc
->InsertString(currentPos
, buf
, len
);
485 SetEmptySelection(currentPos
+ len
);
487 #endif // wxUSE_DATAOBJ
489 pdoc
->EndUndoAction();
495 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
497 if (wxTheClipboard
->Open()) {
498 wxTheClipboard
->UsePrimarySelection(false);
499 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
500 wxTheClipboard
->SetData(new wxTextDataObject(text
));
501 wxTheClipboard
->Close();
505 #endif // wxUSE_CLIPBOARD
509 bool ScintillaWX::CanPaste() {
511 bool canPaste
= false;
514 if (Editor::CanPaste()) {
515 didOpen
= !wxTheClipboard
->IsOpened();
517 wxTheClipboard
->Open();
519 if (wxTheClipboard
->IsOpened()) {
520 wxTheClipboard
->UsePrimarySelection(false);
521 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
523 wxTheClipboard
->Close();
529 #endif // wxUSE_CLIPBOARD
532 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
533 if (! ct
.wCallTip
.Created() ) {
534 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
535 ct
.wDraw
= ct
.wCallTip
;
540 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
542 ((wxMenu
*)popup
.GetID())->AppendSeparator();
544 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
547 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
551 // This is called by the Editor base class whenever something is selected
552 void ScintillaWX::ClaimSelection() {
554 // Until wxGTK is able to support using both the primary selection and the
555 // clipboard at the same time I think it causes more problems than it is
556 // worth to implement this method. Selecting text should not clear the
557 // clipboard. --Robin
559 // Put the selected text in the PRIMARY selection
560 if (currentPos
!= anchor
) {
562 CopySelectionRange(&st
);
563 if (wxTheClipboard
->Open()) {
564 wxTheClipboard
->UsePrimarySelection(true);
565 wxString text
= stc2wx(st
.s
, st
.len
);
566 wxTheClipboard
->SetData(new wxTextDataObject(text
));
567 wxTheClipboard
->UsePrimarySelection(false);
568 wxTheClipboard
->Close();
576 void ScintillaWX::UpdateSystemCaret() {
579 if (HasCaretSizeChanged()) {
580 DestroySystemCaret();
583 Point pos
= LocationFromPosition(currentPos
);
584 ::SetCaretPos(pos
.x
, pos
.y
);
590 bool ScintillaWX::HasCaretSizeChanged() {
592 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
593 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
600 bool ScintillaWX::CreateSystemCaret() {
602 sysCaretWidth
= vs
.caretWidth
;
603 if (0 == sysCaretWidth
) {
606 sysCaretHeight
= vs
.lineHeight
;
607 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
608 char *bits
= new char[bitmapSize
];
609 memset(bits
, 0, bitmapSize
);
610 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
611 1, reinterpret_cast<BYTE
*>(bits
));
613 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
614 sysCaretWidth
, sysCaretHeight
);
615 ::ShowCaret(GetHwndOf(stc
));
622 bool ScintillaWX::DestroySystemCaret() {
624 ::HideCaret(GetHwndOf(stc
));
625 BOOL retval
= ::DestroyCaret();
626 if (sysCaretBitmap
) {
627 ::DeleteObject(sysCaretBitmap
);
637 //----------------------------------------------------------------------
640 long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
644 long ScintillaWX::WndProc(unsigned int iMessage
, unsigned long wParam
, long lParam
) {
646 case SCI_CALLTIPSHOW
: {
647 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
648 // because of the little tweak that needs done below for wxGTK.
649 // When updating new versions double check that this is still
650 // needed, and that any new code there is copied here too.
651 Point pt
= LocationFromPosition(wParam
);
652 char* defn
= reinterpret_cast<char *>(lParam
);
653 AutoCompleteCancel();
654 pt
.y
+= vs
.lineHeight
;
655 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
657 vs
.styles
[STYLE_DEFAULT
].fontName
,
658 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
660 vs
.styles
[STYLE_DEFAULT
].characterSet
,
662 // If the call-tip window would be out of the client
663 // space, adjust so it displays above the text.
664 PRectangle rcClient
= GetClientRectangle();
665 if (rc
.bottom
> rcClient
.bottom
) {
667 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
669 int offset
= vs
.lineHeight
+ rc
.Height();
674 // Now display the window.
675 CreateCallTipWindow(rc
);
676 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
682 case SCI_LOADLEXERLIBRARY
:
683 LexerManager::GetInstance()->Load((const char*)lParam
);
688 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
695 //----------------------------------------------------------------------
698 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
700 paintState
= painting
;
701 Surface
* surfaceWindow
= Surface::Allocate();
702 surfaceWindow
->Init(dc
, wMain
.GetID());
703 rcPaint
= PRectangleFromwxRect(rect
);
704 PRectangle rcClient
= GetClientRectangle();
705 paintingAllText
= rcPaint
.Contains(rcClient
);
707 ClipChildren(*dc
, rcPaint
);
708 Paint(surfaceWindow
, rcPaint
);
710 delete surfaceWindow
;
711 if (paintState
== paintAbandoned
) {
712 // Painting area was insufficient to cover new styling or brace
713 // highlight positions
716 paintState
= notPainting
;
720 void ScintillaWX::DoHScroll(int type
, int pos
) {
722 PRectangle rcText
= GetTextRectangle();
723 int pageWidth
= rcText
.Width() * 2 / 3;
724 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
725 xPos
-= H_SCROLL_STEP
;
726 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
727 xPos
+= H_SCROLL_STEP
;
728 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
730 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
732 if (xPos
> scrollWidth
- rcText
.Width()) {
733 xPos
= scrollWidth
- rcText
.Width();
736 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
738 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
740 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
743 HorizontalScrollTo(xPos
);
746 void ScintillaWX::DoVScroll(int type
, int pos
) {
747 int topLineNew
= topLine
;
748 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
750 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
752 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
753 topLineNew
-= LinesToScroll();
754 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
755 topLineNew
+= LinesToScroll();
756 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
758 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
759 topLineNew
= MaxScrollPos();
760 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
763 ScrollTo(topLineNew
);
766 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
767 int linesPerAction
, int ctrlDown
,
768 bool isPageScroll
) {
769 int topLineNew
= topLine
;
772 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
774 KeyCommand(SCI_ZOOMIN
);
777 KeyCommand(SCI_ZOOMOUT
);
780 else { // otherwise just scroll the window
783 wheelRotation
+= rotation
;
784 lines
= wheelRotation
/ delta
;
785 wheelRotation
-= lines
* delta
;
788 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
790 lines
*= linesPerAction
;
792 ScrollTo(topLineNew
);
798 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
802 void ScintillaWX::DoLoseFocus(){
804 SetFocusState(false);
806 DestroySystemCaret();
809 void ScintillaWX::DoGainFocus(){
813 DestroySystemCaret();
817 void ScintillaWX::DoSysColourChange() {
818 InvalidateStyleData();
821 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
822 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
825 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
826 #if wxUSE_DRAG_AND_DROP
827 if (startDragTimer
->IsRunning()) {
828 startDragTimer
->Stop();
829 SetEmptySelection(PositionFromLocation(pt
));
832 ButtonUp(pt
, curTime
, ctrl
);
835 void ScintillaWX::DoLeftButtonMove(Point pt
) {
840 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
841 // Set the current position to the mouse click point and
842 // then paste in the PRIMARY selection, if any. wxGTK only.
843 int newPos
= PositionFromLocation(pt
);
844 MovePositionTo(newPos
, noSel
, true);
846 pdoc
->BeginUndoAction();
847 wxTextDataObject data
;
848 bool gotData
= false;
849 if (wxTheClipboard
->Open()) {
850 wxTheClipboard
->UsePrimarySelection(true);
851 gotData
= wxTheClipboard
->GetData(data
);
852 wxTheClipboard
->UsePrimarySelection(false);
853 wxTheClipboard
->Close();
856 wxString text
= wxTextBuffer::Translate(data
.GetText(),
857 wxConvertEOLMode(pdoc
->eolMode
));
858 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
859 int len
= strlen(buf
);
860 pdoc
->InsertString(currentPos
, buf
, len
);
861 SetEmptySelection(currentPos
+ len
);
863 pdoc
->EndUndoAction();
867 ShowCaretAtCurrentPosition();
868 EnsureCaretVisible();
871 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
876 void ScintillaWX::DoAddChar(int key
) {
879 wszChars
[0] = (wxChar
)key
;
881 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
882 AddCharUTF((char*)buf
.data(), strlen(buf
));
889 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
891 int key
= evt
.GetKeyCode();
892 bool shift
= evt
.ShiftDown(),
893 ctrl
= evt
.ControlDown(),
896 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
900 case WXK_DOWN
: key
= SCK_DOWN
; break;
901 case WXK_UP
: key
= SCK_UP
; break;
902 case WXK_LEFT
: key
= SCK_LEFT
; break;
903 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
904 case WXK_HOME
: key
= SCK_HOME
; break;
905 case WXK_END
: key
= SCK_END
; break;
906 case WXK_PAGEUP
: // fall through
907 case WXK_PRIOR
: key
= SCK_PRIOR
; break;
908 case WXK_PAGEDOWN
: // fall through
909 case WXK_NEXT
: key
= SCK_NEXT
; break;
910 case WXK_DELETE
: key
= SCK_DELETE
; break;
911 case WXK_INSERT
: key
= SCK_INSERT
; break;
912 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
913 case WXK_BACK
: key
= SCK_BACK
; break;
914 case WXK_TAB
: key
= SCK_TAB
; break;
915 case WXK_NUMPAD_ENTER
: // fall through
916 case WXK_RETURN
: key
= SCK_RETURN
; break;
917 case WXK_ADD
: // fall through
918 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
919 case WXK_SUBTRACT
: // fall through
920 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
921 case WXK_DIVIDE
: // fall through
922 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
923 case WXK_CONTROL
: key
= 0; break;
924 case WXK_ALT
: key
= 0; break;
925 case WXK_SHIFT
: key
= 0; break;
926 case WXK_MENU
: key
= 0; break;
930 if ( evt
.MetaDown() ) {
931 // check for a few common Mac Meta-key combos and remap them to Ctrl
938 case 'A': // Select All
945 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
954 void ScintillaWX::DoCommand(int ID
) {
959 void ScintillaWX::DoContextMenu(Point pt
) {
960 if (displayPopupMenu
)
964 void ScintillaWX::DoOnListBox() {
965 AutoCompleteCompleted();
969 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
977 //----------------------------------------------------------------------
979 #if wxUSE_DRAG_AND_DROP
980 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
981 SetDragPosition(invalidPosition
);
983 wxString text
= wxTextBuffer::Translate(data
,
984 wxConvertEOLMode(pdoc
->eolMode
));
986 // Send an event to allow the drag details to be changed
987 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
988 evt
.SetEventObject(stc
);
989 evt
.SetDragResult(dragResult
);
992 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
993 evt
.SetDragText(text
);
994 stc
->GetEventHandler()->ProcessEvent(evt
);
996 dragResult
= evt
.GetDragResult();
997 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
998 DropAt(evt
.GetPosition(),
999 wx2stc(evt
.GetDragText()),
1000 dragResult
== wxDragMove
,
1001 false); // TODO: rectangular?
1008 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1014 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1015 SetDragPosition(PositionFromLocation(Point(x
, y
)));
1017 // Send an event to allow the drag result to be changed
1018 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1019 evt
.SetEventObject(stc
);
1020 evt
.SetDragResult(def
);
1023 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1024 stc
->GetEventHandler()->ProcessEvent(evt
);
1026 dragResult
= evt
.GetDragResult();
1031 void ScintillaWX::DoDragLeave() {
1032 SetDragPosition(invalidPosition
);
1035 //----------------------------------------------------------------------
1037 // Force the whole window to be repainted
1038 void ScintillaWX::FullPaint() {
1040 stc
->Refresh(false);
1046 void ScintillaWX::DoScrollToLine(int line
) {
1051 void ScintillaWX::DoScrollToColumn(int column
) {
1052 HorizontalScrollTo(column
* vs
.spaceWidth
);
1055 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1056 // will leave it here commented out for a while just in case...
1057 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1059 // wxRegion rgn(wxRectFromPRectangle(rect));
1060 // if (ac.Active()) {
1061 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1062 // rgn.Subtract(childRect);
1064 // if (ct.inCallTipMode) {
1065 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1066 // wxRect childRect = tip->GetRect();
1067 // #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
1068 // childRect.SetPosition(tip->GetMyPosition());
1070 // rgn.Subtract(childRect);
1072 // dc.SetClippingRegion(rgn);
1076 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1077 vs
.extraFontFlag
= useAA
;
1078 InvalidateStyleRedraw();
1081 bool ScintillaWX::GetUseAntiAliasing() {
1082 return vs
.extraFontFlag
;
1085 //----------------------------------------------------------------------
1086 //----------------------------------------------------------------------