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
&& !stc
->HasCapture())
333 else if (!on
&& stc
->HasCapture())
335 capturedMouse
= stc
->HasCapture();
340 bool ScintillaWX::HaveMouseCapture() {
341 capturedMouse
= stc
->HasCapture();
342 return capturedMouse
;
346 void ScintillaWX::ScrollText(int linesToMove
) {
347 int dy
= vs
.lineHeight
* (linesToMove
);
348 stc
->ScrollWindow(0, dy
);
352 void ScintillaWX::SetVerticalScrollPos() {
353 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
354 stc
->SetScrollPos(wxVERTICAL
, topLine
);
356 else { // otherwise use the one that's been given to us
357 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
361 void ScintillaWX::SetHorizontalScrollPos() {
362 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
363 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
365 else { // otherwise use the one that's been given to us
366 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
371 const int H_SCROLL_STEP
= 20;
373 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
374 bool modified
= false;
377 if (!verticalScrollBarVisible
)
380 // Check the vertical scrollbar
381 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
382 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
383 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
384 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
385 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
386 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
390 else { // otherwise use the one that's been given to us
391 int sbMax
= stc
->m_vScrollBar
->GetRange();
392 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
393 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
394 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
395 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
401 // Check the horizontal scrollbar
402 PRectangle rcText
= GetTextRectangle();
403 int horizEnd
= scrollWidth
;
406 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
408 int pageWidth
= rcText
.Width();
410 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
411 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
412 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
413 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
414 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
415 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
417 if (scrollWidth
< pageWidth
) {
418 HorizontalScrollTo(0);
422 else { // otherwise use the one that's been given to us
423 int sbMax
= stc
->m_hScrollBar
->GetRange();
424 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
425 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
426 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
427 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
429 if (scrollWidth
< pageWidth
) {
430 HorizontalScrollTo(0);
439 void ScintillaWX::NotifyChange() {
444 void ScintillaWX::NotifyParent(SCNotification scn
) {
445 stc
->NotifyParent(&scn
);
449 // This method is overloaded from ScintillaBase in order to prevent the
450 // AutoComplete window from being destroyed when it gets the focus. There is
451 // a side effect that the AutoComp will also not be destroyed when switching
452 // to another window, but I think that is okay.
453 void ScintillaWX::CancelModes() {
455 AutoCompleteCancel();
457 Editor::CancelModes();
462 void ScintillaWX::Copy() {
463 if (currentPos
!= anchor
) {
465 CopySelectionRange(&st
);
471 void ScintillaWX::Paste() {
472 pdoc
->BeginUndoAction();
476 wxTextDataObject data
;
477 bool gotData
= false;
479 if (wxTheClipboard
->Open()) {
480 wxTheClipboard
->UsePrimarySelection(false);
481 gotData
= wxTheClipboard
->GetData(data
);
482 wxTheClipboard
->Close();
485 wxString text
= wxTextBuffer::Translate(data
.GetText(),
486 wxConvertEOLMode(pdoc
->eolMode
));
487 data
.SetText(wxEmptyString
); // free the data object content
488 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
489 text
= wxEmptyString
; // free text
491 int len
= strlen(buf
);
492 pdoc
->InsertString(currentPos
, buf
, len
);
493 SetEmptySelection(currentPos
+ len
);
495 #endif // wxUSE_DATAOBJ
497 pdoc
->EndUndoAction();
503 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
505 if (wxTheClipboard
->Open()) {
506 wxTheClipboard
->UsePrimarySelection(false);
507 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
508 wxTheClipboard
->SetData(new wxTextDataObject(text
));
509 wxTheClipboard
->Close();
513 #endif // wxUSE_CLIPBOARD
517 bool ScintillaWX::CanPaste() {
519 bool canPaste
= false;
522 if (Editor::CanPaste()) {
523 didOpen
= !wxTheClipboard
->IsOpened();
525 wxTheClipboard
->Open();
527 if (wxTheClipboard
->IsOpened()) {
528 wxTheClipboard
->UsePrimarySelection(false);
529 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
531 wxTheClipboard
->Close();
537 #endif // wxUSE_CLIPBOARD
540 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
541 if (! ct
.wCallTip
.Created() ) {
542 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
543 ct
.wDraw
= ct
.wCallTip
;
548 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
550 ((wxMenu
*)popup
.GetID())->AppendSeparator();
552 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
555 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
559 // This is called by the Editor base class whenever something is selected
560 void ScintillaWX::ClaimSelection() {
562 // Until wxGTK is able to support using both the primary selection and the
563 // clipboard at the same time I think it causes more problems than it is
564 // worth to implement this method. Selecting text should not clear the
565 // clipboard. --Robin
567 // Put the selected text in the PRIMARY selection
568 if (currentPos
!= anchor
) {
570 CopySelectionRange(&st
);
571 if (wxTheClipboard
->Open()) {
572 wxTheClipboard
->UsePrimarySelection(true);
573 wxString text
= stc2wx(st
.s
, st
.len
);
574 wxTheClipboard
->SetData(new wxTextDataObject(text
));
575 wxTheClipboard
->UsePrimarySelection(false);
576 wxTheClipboard
->Close();
584 void ScintillaWX::UpdateSystemCaret() {
587 if (HasCaretSizeChanged()) {
588 DestroySystemCaret();
591 Point pos
= LocationFromPosition(currentPos
);
592 ::SetCaretPos(pos
.x
, pos
.y
);
598 bool ScintillaWX::HasCaretSizeChanged() {
600 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
601 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
608 bool ScintillaWX::CreateSystemCaret() {
610 sysCaretWidth
= vs
.caretWidth
;
611 if (0 == sysCaretWidth
) {
614 sysCaretHeight
= vs
.lineHeight
;
615 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
616 char *bits
= new char[bitmapSize
];
617 memset(bits
, 0, bitmapSize
);
618 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
619 1, reinterpret_cast<BYTE
*>(bits
));
621 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
622 sysCaretWidth
, sysCaretHeight
);
623 ::ShowCaret(GetHwndOf(stc
));
630 bool ScintillaWX::DestroySystemCaret() {
632 ::HideCaret(GetHwndOf(stc
));
633 BOOL retval
= ::DestroyCaret();
634 if (sysCaretBitmap
) {
635 ::DeleteObject(sysCaretBitmap
);
645 //----------------------------------------------------------------------
648 long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
652 long ScintillaWX::WndProc(unsigned int iMessage
, unsigned long wParam
, long lParam
) {
654 case SCI_CALLTIPSHOW
: {
655 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
656 // because of the little tweak that needs done below for wxGTK.
657 // When updating new versions double check that this is still
658 // needed, and that any new code there is copied here too.
659 Point pt
= LocationFromPosition(wParam
);
660 char* defn
= reinterpret_cast<char *>(lParam
);
661 AutoCompleteCancel();
662 pt
.y
+= vs
.lineHeight
;
663 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
665 vs
.styles
[STYLE_DEFAULT
].fontName
,
666 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
668 vs
.styles
[STYLE_DEFAULT
].characterSet
,
670 // If the call-tip window would be out of the client
671 // space, adjust so it displays above the text.
672 PRectangle rcClient
= GetClientRectangle();
673 if (rc
.bottom
> rcClient
.bottom
) {
675 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
677 int offset
= vs
.lineHeight
+ rc
.Height();
682 // Now display the window.
683 CreateCallTipWindow(rc
);
684 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
690 case SCI_LOADLEXERLIBRARY
:
691 LexerManager::GetInstance()->Load((const char*)lParam
);
696 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
703 //----------------------------------------------------------------------
706 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
708 paintState
= painting
;
709 Surface
* surfaceWindow
= Surface::Allocate();
710 surfaceWindow
->Init(dc
, wMain
.GetID());
711 rcPaint
= PRectangleFromwxRect(rect
);
712 PRectangle rcClient
= GetClientRectangle();
713 paintingAllText
= rcPaint
.Contains(rcClient
);
715 ClipChildren(*dc
, rcPaint
);
716 Paint(surfaceWindow
, rcPaint
);
718 delete surfaceWindow
;
719 if (paintState
== paintAbandoned
) {
720 // Painting area was insufficient to cover new styling or brace
721 // highlight positions
724 paintState
= notPainting
;
728 void ScintillaWX::DoHScroll(int type
, int pos
) {
730 PRectangle rcText
= GetTextRectangle();
731 int pageWidth
= rcText
.Width() * 2 / 3;
732 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
733 xPos
-= H_SCROLL_STEP
;
734 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
735 xPos
+= H_SCROLL_STEP
;
736 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
738 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
740 if (xPos
> scrollWidth
- rcText
.Width()) {
741 xPos
= scrollWidth
- rcText
.Width();
744 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
746 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
748 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
751 HorizontalScrollTo(xPos
);
754 void ScintillaWX::DoVScroll(int type
, int pos
) {
755 int topLineNew
= topLine
;
756 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
758 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
760 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
761 topLineNew
-= LinesToScroll();
762 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
763 topLineNew
+= LinesToScroll();
764 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
766 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
767 topLineNew
= MaxScrollPos();
768 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
771 ScrollTo(topLineNew
);
774 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
775 int linesPerAction
, int ctrlDown
,
776 bool isPageScroll
) {
777 int topLineNew
= topLine
;
780 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
782 KeyCommand(SCI_ZOOMIN
);
785 KeyCommand(SCI_ZOOMOUT
);
788 else { // otherwise just scroll the window
791 wheelRotation
+= rotation
;
792 lines
= wheelRotation
/ delta
;
793 wheelRotation
-= lines
* delta
;
796 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
798 lines
*= linesPerAction
;
800 ScrollTo(topLineNew
);
806 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
810 void ScintillaWX::DoLoseFocus(){
812 SetFocusState(false);
814 DestroySystemCaret();
817 void ScintillaWX::DoGainFocus(){
821 DestroySystemCaret();
825 void ScintillaWX::DoSysColourChange() {
826 InvalidateStyleData();
829 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
830 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
833 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
834 ButtonUp(pt
, curTime
, ctrl
);
835 #if wxUSE_DRAG_AND_DROP
836 if (startDragTimer
->IsRunning()) {
837 startDragTimer
->Stop();
838 SetDragPosition(invalidPosition
);
839 SetEmptySelection(PositionFromLocation(pt
));
840 ShowCaretAtCurrentPosition();
842 #endif // wxUSE_DRAG_AND_DROP
845 void ScintillaWX::DoLeftButtonMove(Point pt
) {
850 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
851 // Set the current position to the mouse click point and
852 // then paste in the PRIMARY selection, if any. wxGTK only.
853 int newPos
= PositionFromLocation(pt
);
854 MovePositionTo(newPos
, noSel
, true);
856 pdoc
->BeginUndoAction();
857 wxTextDataObject data
;
858 bool gotData
= false;
859 if (wxTheClipboard
->Open()) {
860 wxTheClipboard
->UsePrimarySelection(true);
861 gotData
= wxTheClipboard
->GetData(data
);
862 wxTheClipboard
->UsePrimarySelection(false);
863 wxTheClipboard
->Close();
866 wxString text
= wxTextBuffer::Translate(data
.GetText(),
867 wxConvertEOLMode(pdoc
->eolMode
));
868 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
869 int len
= strlen(buf
);
870 pdoc
->InsertString(currentPos
, buf
, len
);
871 SetEmptySelection(currentPos
+ len
);
873 pdoc
->EndUndoAction();
877 ShowCaretAtCurrentPosition();
878 EnsureCaretVisible();
881 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
886 void ScintillaWX::DoAddChar(int key
) {
889 wszChars
[0] = (wxChar
)key
;
891 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
892 AddCharUTF((char*)buf
.data(), strlen(buf
));
899 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
901 int key
= evt
.GetKeyCode();
902 bool shift
= evt
.ShiftDown(),
903 ctrl
= evt
.ControlDown(),
906 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
910 case WXK_DOWN
: key
= SCK_DOWN
; break;
911 case WXK_UP
: key
= SCK_UP
; break;
912 case WXK_LEFT
: key
= SCK_LEFT
; break;
913 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
914 case WXK_HOME
: key
= SCK_HOME
; break;
915 case WXK_END
: key
= SCK_END
; break;
916 case WXK_PAGEUP
: key
= SCK_PRIOR
; break;
917 case WXK_PAGEDOWN
: key
= SCK_NEXT
; break;
918 case WXK_NUMPAD_PAGEUP
: key
= SCK_PRIOR
; break;
919 case WXK_NUMPAD_PAGEDOWN
: key
= SCK_NEXT
; break;
920 case WXK_DELETE
: key
= SCK_DELETE
; break;
921 case WXK_INSERT
: key
= SCK_INSERT
; break;
922 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
923 case WXK_BACK
: key
= SCK_BACK
; break;
924 case WXK_TAB
: key
= SCK_TAB
; break;
925 case WXK_NUMPAD_ENTER
: // fall through
926 case WXK_RETURN
: key
= SCK_RETURN
; break;
927 case WXK_ADD
: // fall through
928 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
929 case WXK_SUBTRACT
: // fall through
930 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
931 case WXK_DIVIDE
: // fall through
932 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
933 case WXK_CONTROL
: key
= 0; break;
934 case WXK_ALT
: key
= 0; break;
935 case WXK_SHIFT
: key
= 0; break;
936 case WXK_MENU
: key
= 0; break;
940 if ( evt
.MetaDown() ) {
941 // check for a few common Mac Meta-key combos and remap them to Ctrl
948 case 'A': // Select All
955 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
964 void ScintillaWX::DoCommand(int ID
) {
969 void ScintillaWX::DoContextMenu(Point pt
) {
970 if (displayPopupMenu
)
974 void ScintillaWX::DoOnListBox() {
975 AutoCompleteCompleted();
979 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
987 //----------------------------------------------------------------------
989 #if wxUSE_DRAG_AND_DROP
990 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
991 SetDragPosition(invalidPosition
);
993 wxString text
= wxTextBuffer::Translate(data
,
994 wxConvertEOLMode(pdoc
->eolMode
));
996 // Send an event to allow the drag details to be changed
997 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
998 evt
.SetEventObject(stc
);
999 evt
.SetDragResult(dragResult
);
1002 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1003 evt
.SetDragText(text
);
1004 stc
->GetEventHandler()->ProcessEvent(evt
);
1006 dragResult
= evt
.GetDragResult();
1007 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
1008 DropAt(evt
.GetPosition(),
1009 wx2stc(evt
.GetDragText()),
1010 dragResult
== wxDragMove
,
1011 false); // TODO: rectangular?
1018 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1024 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1025 SetDragPosition(PositionFromLocation(Point(x
, y
)));
1027 // Send an event to allow the drag result to be changed
1028 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1029 evt
.SetEventObject(stc
);
1030 evt
.SetDragResult(def
);
1033 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1034 stc
->GetEventHandler()->ProcessEvent(evt
);
1036 dragResult
= evt
.GetDragResult();
1041 void ScintillaWX::DoDragLeave() {
1042 SetDragPosition(invalidPosition
);
1044 #endif // wxUSE_DRAG_AND_DROP
1045 //----------------------------------------------------------------------
1047 // Force the whole window to be repainted
1048 void ScintillaWX::FullPaint() {
1050 stc
->Refresh(false);
1056 void ScintillaWX::DoScrollToLine(int line
) {
1061 void ScintillaWX::DoScrollToColumn(int column
) {
1062 HorizontalScrollTo(column
* vs
.spaceWidth
);
1065 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1066 // will leave it here commented out for a while just in case...
1067 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1069 // wxRegion rgn(wxRectFromPRectangle(rect));
1070 // if (ac.Active()) {
1071 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1072 // rgn.Subtract(childRect);
1074 // if (ct.inCallTipMode) {
1075 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1076 // wxRect childRect = tip->GetRect();
1077 // #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
1078 // childRect.SetPosition(tip->GetMyPosition());
1080 // rgn.Subtract(childRect);
1082 // dc.SetClippingRegion(rgn);
1086 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1087 vs
.extraFontFlag
= useAA
;
1088 InvalidateStyleRedraw();
1091 bool ScintillaWX::GetUseAntiAliasing() {
1092 return vs
.extraFontFlag
;
1095 //----------------------------------------------------------------------
1096 //----------------------------------------------------------------------