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() {
82 #endif // wxUSE_DRAG_AND_DROP
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);
217 #endif // wxUSE_DRAG_AND_DROP
221 ScintillaWX::~ScintillaWX() {
222 #if wxUSE_DRAG_AND_DROP
223 delete startDragTimer
;
224 #endif // wxUSE_DRAG_AND_DROP
228 //----------------------------------------------------------------------
229 // base class virtuals
232 void ScintillaWX::Initialise() {
233 //ScintillaBase::Initialise();
234 #if wxUSE_DRAG_AND_DROP
235 dropTarget
= new wxSTCDropTarget
;
236 dropTarget
->SetScintilla(this);
237 stc
->SetDropTarget(dropTarget
);
238 #endif // wxUSE_DRAG_AND_DROP
240 vs
.extraFontFlag
= false; // UseAntiAliasing
242 vs
.extraFontFlag
= true; // UseAntiAliasing
247 void ScintillaWX::Finalise() {
248 ScintillaBase::Finalise();
251 DestroySystemCaret();
255 void ScintillaWX::StartDrag() {
256 #if wxUSE_DRAG_AND_DROP
257 // We defer the starting of the DnD, otherwise the LeftUp of a normal
258 // click could be lost and the STC will think it is doing a DnD when the
259 // user just wanted a normal click.
260 startDragTimer
->Start(200, true);
261 #endif // wxUSE_DRAG_AND_DROP
264 void ScintillaWX::DoStartDrag() {
265 #if wxUSE_DRAG_AND_DROP
266 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
268 // Send an event to allow the drag text to be changed
269 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
270 evt
.SetEventObject(stc
);
271 evt
.SetDragText(dragText
);
272 evt
.SetDragAllowMove(true);
273 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
274 stc
->GetSelectionEnd()));
275 stc
->GetEventHandler()->ProcessEvent(evt
);
276 dragText
= evt
.GetDragText();
278 if (dragText
.length()) {
279 wxDropSource
source(stc
);
280 wxTextDataObject
data(dragText
);
283 source
.SetData(data
);
284 dropWentOutside
= true;
285 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
286 if (result
== wxDragMove
&& dropWentOutside
)
289 SetDragPosition(invalidPosition
);
291 #endif // wxUSE_DRAG_AND_DROP
295 bool ScintillaWX::SetIdle(bool on
) {
296 if (idler
.state
!= on
) {
297 // connect or disconnect the EVT_IDLE handler
299 stc
->Connect(wxID_ANY
, wxEVT_IDLE
,
300 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
302 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
,
303 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
310 void ScintillaWX::SetTicking(bool on
) {
311 wxSTCTimer
* steTimer
;
312 if (timer
.ticking
!= on
) {
315 steTimer
= new wxSTCTimer(this);
316 steTimer
->Start(timer
.tickSize
);
317 timer
.tickerID
= steTimer
;
319 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
325 timer
.ticksToWait
= caret
.period
;
329 void ScintillaWX::SetMouseCapture(bool on
) {
330 if (mouseDownCaptures
) {
331 if (on
&& !capturedMouse
)
333 else if (!on
&& capturedMouse
&& stc
->HasCapture())
340 bool ScintillaWX::HaveMouseCapture() {
341 return capturedMouse
;
345 void ScintillaWX::ScrollText(int linesToMove
) {
346 int dy
= vs
.lineHeight
* (linesToMove
);
347 stc
->ScrollWindow(0, dy
);
351 void ScintillaWX::SetVerticalScrollPos() {
352 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
353 stc
->SetScrollPos(wxVERTICAL
, topLine
);
355 else { // otherwise use the one that's been given to us
356 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
360 void ScintillaWX::SetHorizontalScrollPos() {
361 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
362 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
364 else { // otherwise use the one that's been given to us
365 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
370 const int H_SCROLL_STEP
= 20;
372 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
373 bool modified
= false;
376 if (!verticalScrollBarVisible
)
379 // Check the vertical scrollbar
380 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
381 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
382 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
383 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
384 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
385 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
389 else { // otherwise use the one that's been given to us
390 int sbMax
= stc
->m_vScrollBar
->GetRange();
391 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
392 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
393 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
394 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
400 // Check the horizontal scrollbar
401 PRectangle rcText
= GetTextRectangle();
402 int horizEnd
= scrollWidth
;
405 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
407 int pageWidth
= rcText
.Width();
409 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
410 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
411 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
412 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
413 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
414 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
416 if (scrollWidth
< pageWidth
) {
417 HorizontalScrollTo(0);
421 else { // otherwise use the one that's been given to us
422 int sbMax
= stc
->m_hScrollBar
->GetRange();
423 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
424 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
425 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
426 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
428 if (scrollWidth
< pageWidth
) {
429 HorizontalScrollTo(0);
438 void ScintillaWX::NotifyChange() {
443 void ScintillaWX::NotifyParent(SCNotification scn
) {
444 stc
->NotifyParent(&scn
);
448 // This method is overloaded from ScintillaBase in order to prevent the
449 // AutoComplete window from being destroyed when it gets the focus. There is
450 // a side effect that the AutoComp will also not be destroyed when switching
451 // to another window, but I think that is okay.
452 void ScintillaWX::CancelModes() {
454 AutoCompleteCancel();
456 Editor::CancelModes();
461 void ScintillaWX::Copy() {
462 if (currentPos
!= anchor
) {
464 CopySelectionRange(&st
);
470 void ScintillaWX::Paste() {
471 pdoc
->BeginUndoAction();
475 wxTextDataObject data
;
476 bool gotData
= false;
478 if (wxTheClipboard
->Open()) {
479 wxTheClipboard
->UsePrimarySelection(false);
480 gotData
= wxTheClipboard
->GetData(data
);
481 wxTheClipboard
->Close();
484 wxString text
= wxTextBuffer::Translate(data
.GetText(),
485 wxConvertEOLMode(pdoc
->eolMode
));
486 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
489 // free up the old character buffer in case the text is real big
490 data
.SetText(wxEmptyString
);
491 text
= wxEmptyString
;
493 int len
= strlen(buf
);
494 pdoc
->InsertString(currentPos
, buf
, len
);
495 SetEmptySelection(currentPos
+ len
);
497 #endif // wxUSE_DATAOBJ
499 pdoc
->EndUndoAction();
505 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
507 if (wxTheClipboard
->Open()) {
508 wxTheClipboard
->UsePrimarySelection(false);
509 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
510 wxTheClipboard
->SetData(new wxTextDataObject(text
));
511 wxTheClipboard
->Close();
515 #endif // wxUSE_CLIPBOARD
519 bool ScintillaWX::CanPaste() {
521 bool canPaste
= false;
524 if (Editor::CanPaste()) {
525 didOpen
= !wxTheClipboard
->IsOpened();
527 wxTheClipboard
->Open();
529 if (wxTheClipboard
->IsOpened()) {
530 wxTheClipboard
->UsePrimarySelection(false);
531 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
533 wxTheClipboard
->Close();
539 #endif // wxUSE_CLIPBOARD
542 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
543 if (! ct
.wCallTip
.Created() ) {
544 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
545 ct
.wDraw
= ct
.wCallTip
;
550 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
552 ((wxMenu
*)popup
.GetID())->AppendSeparator();
554 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
557 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
561 // This is called by the Editor base class whenever something is selected
562 void ScintillaWX::ClaimSelection() {
564 // Until wxGTK is able to support using both the primary selection and the
565 // clipboard at the same time I think it causes more problems than it is
566 // worth to implement this method. Selecting text should not clear the
567 // clipboard. --Robin
569 // Put the selected text in the PRIMARY selection
570 if (currentPos
!= anchor
) {
572 CopySelectionRange(&st
);
573 if (wxTheClipboard
->Open()) {
574 wxTheClipboard
->UsePrimarySelection(true);
575 wxString text
= stc2wx(st
.s
, st
.len
);
576 wxTheClipboard
->SetData(new wxTextDataObject(text
));
577 wxTheClipboard
->UsePrimarySelection(false);
578 wxTheClipboard
->Close();
586 void ScintillaWX::UpdateSystemCaret() {
589 if (HasCaretSizeChanged()) {
590 DestroySystemCaret();
593 Point pos
= LocationFromPosition(currentPos
);
594 ::SetCaretPos(pos
.x
, pos
.y
);
600 bool ScintillaWX::HasCaretSizeChanged() {
602 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
603 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
610 bool ScintillaWX::CreateSystemCaret() {
612 sysCaretWidth
= vs
.caretWidth
;
613 if (0 == sysCaretWidth
) {
616 sysCaretHeight
= vs
.lineHeight
;
617 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
618 char *bits
= new char[bitmapSize
];
619 memset(bits
, 0, bitmapSize
);
620 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
621 1, reinterpret_cast<BYTE
*>(bits
));
623 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
624 sysCaretWidth
, sysCaretHeight
);
625 ::ShowCaret(GetHwndOf(stc
));
632 bool ScintillaWX::DestroySystemCaret() {
634 ::HideCaret(GetHwndOf(stc
));
635 BOOL retval
= ::DestroyCaret();
636 if (sysCaretBitmap
) {
637 ::DeleteObject(sysCaretBitmap
);
647 //----------------------------------------------------------------------
650 long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
654 long ScintillaWX::WndProc(unsigned int iMessage
, unsigned long wParam
, long lParam
) {
656 case SCI_CALLTIPSHOW
: {
657 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
658 // because of the little tweak that needs done below for wxGTK.
659 // When updating new versions double check that this is still
660 // needed, and that any new code there is copied here too.
661 Point pt
= LocationFromPosition(wParam
);
662 char* defn
= reinterpret_cast<char *>(lParam
);
663 AutoCompleteCancel();
664 pt
.y
+= vs
.lineHeight
;
665 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
667 vs
.styles
[STYLE_DEFAULT
].fontName
,
668 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
670 vs
.styles
[STYLE_DEFAULT
].characterSet
,
672 // If the call-tip window would be out of the client
673 // space, adjust so it displays above the text.
674 PRectangle rcClient
= GetClientRectangle();
675 if (rc
.bottom
> rcClient
.bottom
) {
677 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
679 int offset
= vs
.lineHeight
+ rc
.Height();
684 // Now display the window.
685 CreateCallTipWindow(rc
);
686 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
692 case SCI_LOADLEXERLIBRARY
:
693 LexerManager::GetInstance()->Load((const char*)lParam
);
698 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
705 //----------------------------------------------------------------------
708 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
710 paintState
= painting
;
711 Surface
* surfaceWindow
= Surface::Allocate();
712 surfaceWindow
->Init(dc
, wMain
.GetID());
713 rcPaint
= PRectangleFromwxRect(rect
);
714 PRectangle rcClient
= GetClientRectangle();
715 paintingAllText
= rcPaint
.Contains(rcClient
);
717 ClipChildren(*dc
, rcPaint
);
718 Paint(surfaceWindow
, rcPaint
);
720 delete surfaceWindow
;
721 if (paintState
== paintAbandoned
) {
722 // Painting area was insufficient to cover new styling or brace
723 // highlight positions
726 paintState
= notPainting
;
730 void ScintillaWX::DoHScroll(int type
, int pos
) {
732 PRectangle rcText
= GetTextRectangle();
733 int pageWidth
= rcText
.Width() * 2 / 3;
734 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
735 xPos
-= H_SCROLL_STEP
;
736 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
737 xPos
+= H_SCROLL_STEP
;
738 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
740 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
742 if (xPos
> scrollWidth
- rcText
.Width()) {
743 xPos
= scrollWidth
- rcText
.Width();
746 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
748 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
750 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
753 HorizontalScrollTo(xPos
);
756 void ScintillaWX::DoVScroll(int type
, int pos
) {
757 int topLineNew
= topLine
;
758 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
760 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
762 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
763 topLineNew
-= LinesToScroll();
764 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
765 topLineNew
+= LinesToScroll();
766 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
768 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
769 topLineNew
= MaxScrollPos();
770 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
773 ScrollTo(topLineNew
);
776 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
777 int linesPerAction
, int ctrlDown
,
778 bool isPageScroll
) {
779 int topLineNew
= topLine
;
782 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
784 KeyCommand(SCI_ZOOMIN
);
787 KeyCommand(SCI_ZOOMOUT
);
790 else { // otherwise just scroll the window
793 wheelRotation
+= rotation
;
794 lines
= wheelRotation
/ delta
;
795 wheelRotation
-= lines
* delta
;
798 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
800 lines
*= linesPerAction
;
802 ScrollTo(topLineNew
);
808 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
812 void ScintillaWX::DoLoseFocus(){
814 SetFocusState(false);
816 DestroySystemCaret();
819 void ScintillaWX::DoGainFocus(){
823 DestroySystemCaret();
827 void ScintillaWX::DoSysColourChange() {
828 InvalidateStyleData();
831 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
832 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
835 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
836 ButtonUp(pt
, curTime
, ctrl
);
837 #if wxUSE_DRAG_AND_DROP
838 if (startDragTimer
->IsRunning()) {
839 startDragTimer
->Stop();
840 SetDragPosition(invalidPosition
);
841 SetEmptySelection(PositionFromLocation(pt
));
842 ShowCaretAtCurrentPosition();
844 #endif // wxUSE_DRAG_AND_DROP
847 void ScintillaWX::DoLeftButtonMove(Point pt
) {
852 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
853 // Set the current position to the mouse click point and
854 // then paste in the PRIMARY selection, if any. wxGTK only.
855 int newPos
= PositionFromLocation(pt
);
856 MovePositionTo(newPos
, noSel
, true);
858 pdoc
->BeginUndoAction();
859 wxTextDataObject data
;
860 bool gotData
= false;
861 if (wxTheClipboard
->Open()) {
862 wxTheClipboard
->UsePrimarySelection(true);
863 gotData
= wxTheClipboard
->GetData(data
);
864 wxTheClipboard
->UsePrimarySelection(false);
865 wxTheClipboard
->Close();
868 wxString text
= wxTextBuffer::Translate(data
.GetText(),
869 wxConvertEOLMode(pdoc
->eolMode
));
870 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
871 int len
= strlen(buf
);
872 pdoc
->InsertString(currentPos
, buf
, len
);
873 SetEmptySelection(currentPos
+ len
);
875 pdoc
->EndUndoAction();
879 ShowCaretAtCurrentPosition();
880 EnsureCaretVisible();
883 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
888 void ScintillaWX::DoAddChar(int key
) {
891 wszChars
[0] = (wxChar
)key
;
893 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
894 AddCharUTF((char*)buf
.data(), strlen(buf
));
901 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
903 int key
= evt
.GetKeyCode();
904 bool shift
= evt
.ShiftDown(),
905 ctrl
= evt
.ControlDown(),
908 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
912 case WXK_DOWN
: key
= SCK_DOWN
; break;
913 case WXK_UP
: key
= SCK_UP
; break;
914 case WXK_LEFT
: key
= SCK_LEFT
; break;
915 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
916 case WXK_HOME
: key
= SCK_HOME
; break;
917 case WXK_END
: key
= SCK_END
; break;
918 case WXK_PAGEUP
: key
= SCK_PRIOR
; break;
919 case WXK_PAGEDOWN
: key
= SCK_NEXT
; break;
920 case WXK_NUMPAD_DOWN
: key
= SCK_DOWN
; break;
921 case WXK_NUMPAD_UP
: key
= SCK_UP
; break;
922 case WXK_NUMPAD_LEFT
: key
= SCK_LEFT
; break;
923 case WXK_NUMPAD_RIGHT
: key
= SCK_RIGHT
; break;
924 case WXK_NUMPAD_HOME
: key
= SCK_HOME
; break;
925 case WXK_NUMPAD_END
: key
= SCK_END
; break;
926 case WXK_NUMPAD_PAGEUP
: key
= SCK_PRIOR
; break;
927 case WXK_NUMPAD_PAGEDOWN
: key
= SCK_NEXT
; break;
928 case WXK_DELETE
: key
= SCK_DELETE
; break;
929 case WXK_INSERT
: key
= SCK_INSERT
; break;
930 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
931 case WXK_BACK
: key
= SCK_BACK
; break;
932 case WXK_TAB
: key
= SCK_TAB
; break;
933 case WXK_NUMPAD_ENTER
: // fall through
934 case WXK_RETURN
: key
= SCK_RETURN
; break;
935 case WXK_ADD
: // fall through
936 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
937 case WXK_SUBTRACT
: // fall through
938 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
939 case WXK_DIVIDE
: // fall through
940 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
941 case WXK_CONTROL
: key
= 0; break;
942 case WXK_ALT
: key
= 0; break;
943 case WXK_SHIFT
: key
= 0; break;
944 case WXK_MENU
: key
= 0; break;
948 if ( evt
.MetaDown() ) {
949 // check for a few common Mac Meta-key combos and remap them to Ctrl
956 case 'A': // Select All
963 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
972 void ScintillaWX::DoCommand(int ID
) {
977 void ScintillaWX::DoContextMenu(Point pt
) {
978 if (displayPopupMenu
)
982 void ScintillaWX::DoOnListBox() {
983 AutoCompleteCompleted();
987 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
995 //----------------------------------------------------------------------
997 #if wxUSE_DRAG_AND_DROP
998 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
999 SetDragPosition(invalidPosition
);
1001 wxString text
= wxTextBuffer::Translate(data
,
1002 wxConvertEOLMode(pdoc
->eolMode
));
1004 // Send an event to allow the drag details to be changed
1005 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
1006 evt
.SetEventObject(stc
);
1007 evt
.SetDragResult(dragResult
);
1010 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1011 evt
.SetDragText(text
);
1012 stc
->GetEventHandler()->ProcessEvent(evt
);
1014 dragResult
= evt
.GetDragResult();
1015 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
1016 DropAt(evt
.GetPosition(),
1017 wx2stc(evt
.GetDragText()),
1018 dragResult
== wxDragMove
,
1019 false); // TODO: rectangular?
1026 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1032 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1033 SetDragPosition(PositionFromLocation(Point(x
, y
)));
1035 // Send an event to allow the drag result to be changed
1036 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1037 evt
.SetEventObject(stc
);
1038 evt
.SetDragResult(def
);
1041 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1042 stc
->GetEventHandler()->ProcessEvent(evt
);
1044 dragResult
= evt
.GetDragResult();
1049 void ScintillaWX::DoDragLeave() {
1050 SetDragPosition(invalidPosition
);
1052 #endif // wxUSE_DRAG_AND_DROP
1053 //----------------------------------------------------------------------
1055 // Force the whole window to be repainted
1056 void ScintillaWX::FullPaint() {
1058 stc
->Refresh(false);
1064 void ScintillaWX::DoScrollToLine(int line
) {
1069 void ScintillaWX::DoScrollToColumn(int column
) {
1070 HorizontalScrollTo(column
* vs
.spaceWidth
);
1073 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1074 // will leave it here commented out for a while just in case...
1075 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1077 // wxRegion rgn(wxRectFromPRectangle(rect));
1078 // if (ac.Active()) {
1079 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1080 // rgn.Subtract(childRect);
1082 // if (ct.inCallTipMode) {
1083 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1084 // wxRect childRect = tip->GetRect();
1085 // #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
1086 // childRect.SetPosition(tip->GetMyPosition());
1088 // rgn.Subtract(childRect);
1090 // dc.SetClippingRegion(rgn);
1094 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1095 vs
.extraFontFlag
= useAA
;
1096 InvalidateStyleRedraw();
1099 bool ScintillaWX::GetUseAntiAliasing() {
1100 return vs
.extraFontFlag
;
1103 //----------------------------------------------------------------------
1104 //----------------------------------------------------------------------