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 class wxStartDragTimer
: public wxTimer
{
69 wxStartDragTimer(ScintillaWX
* swx
) {
82 bool wxSTCDropTarget::OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) {
83 return m_swx
->DoDropText(x
, y
, data
);
86 wxDragResult
wxSTCDropTarget::OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
) {
87 return m_swx
->DoDragEnter(x
, y
, def
);
90 wxDragResult
wxSTCDropTarget::OnDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
91 return m_swx
->DoDragOver(x
, y
, def
);
94 void wxSTCDropTarget::OnLeave() {
97 #endif // wxUSE_DRAG_AND_DROP
101 #include "wx/popupwin.h"
102 #define wxSTCCallTipBase wxPopupWindow
104 #include "wx/frame.h"
105 #define wxSTCCallTipBase wxFrame
108 #include "wx/dcbuffer.h"
110 class wxSTCCallTip
: public wxSTCCallTipBase
{
112 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
) :
114 wxSTCCallTipBase(parent
, wxBORDER_NONE
),
116 wxSTCCallTipBase(parent
, -1, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
,
118 | wxFRAME_FLOAT_ON_PARENT
125 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
127 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
131 #if wxUSE_POPUPWIN && defined(__WXGTK__)
132 wxRect rect
= GetRect();
135 GetParent()->Refresh(false, &rect
);
139 bool AcceptsFocus() const { return false; }
141 void OnPaint(wxPaintEvent
& WXUNUSED(evt
))
143 wxAutoBufferedPaintDC
dc(this);
144 Surface
* surfaceWindow
= Surface::Allocate();
145 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
146 m_ct
->PaintCT(surfaceWindow
);
147 surfaceWindow
->Release();
148 delete surfaceWindow
;
151 void OnFocus(wxFocusEvent
& event
)
153 GetParent()->SetFocus();
157 void OnLeftDown(wxMouseEvent
& event
)
159 wxPoint pt
= event
.GetPosition();
162 m_swx
->CallTipClick();
165 virtual void DoSetSize(int x
, int y
,
166 int width
, int height
,
167 int sizeFlags
= wxSIZE_AUTO
)
169 // convert coords to screen coords since we're a top-level window
170 if (x
!= wxDefaultCoord
) {
172 GetParent()->ClientToScreen(&x
, NULL
);
174 if (y
!= wxDefaultCoord
) {
176 GetParent()->ClientToScreen(NULL
, &y
);
178 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
183 virtual bool Show( bool show
= true )
185 // Although we're a frame, we always want the parent to be active, so
186 // raise it whenever we get shown.
187 bool rv
= wxSTCCallTipBase::Show(show
);
190 wxTopLevelWindow
*frame
= wxDynamicCast(
191 wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
199 wxPoint
GetMyPosition()
201 return wxPoint(m_cx
, m_cy
);
208 DECLARE_EVENT_TABLE()
211 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
212 EVT_PAINT(wxSTCCallTip::OnPaint
)
213 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
214 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
218 //----------------------------------------------------------------------
221 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
225 switch (scintillaMode
) {
227 type
= wxTextFileType_Dos
;
231 type
= wxTextFileType_Mac
;
235 type
= wxTextFileType_Unix
;
239 type
= wxTextBuffer::typeDefault
;
244 #endif // wxUSE_DATAOBJ
247 //----------------------------------------------------------------------
248 // Constructor/Destructor
251 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
252 capturedMouse
= false;
263 #if wxUSE_DRAG_AND_DROP
264 startDragTimer
= new wxStartDragTimer(this);
265 #endif // wxUSE_DRAG_AND_DROP
269 ScintillaWX::~ScintillaWX() {
270 #if wxUSE_DRAG_AND_DROP
271 delete startDragTimer
;
272 #endif // wxUSE_DRAG_AND_DROP
276 //----------------------------------------------------------------------
277 // base class virtuals
280 void ScintillaWX::Initialise() {
281 //ScintillaBase::Initialise();
282 #if wxUSE_DRAG_AND_DROP
283 dropTarget
= new wxSTCDropTarget
;
284 dropTarget
->SetScintilla(this);
285 stc
->SetDropTarget(dropTarget
);
286 #endif // wxUSE_DRAG_AND_DROP
288 vs
.extraFontFlag
= false; // UseAntiAliasing
290 vs
.extraFontFlag
= true; // UseAntiAliasing
295 void ScintillaWX::Finalise() {
296 ScintillaBase::Finalise();
299 DestroySystemCaret();
303 void ScintillaWX::StartDrag() {
304 #if wxUSE_DRAG_AND_DROP
305 // We defer the starting of the DnD, otherwise the LeftUp of a normal
306 // click could be lost and the STC will think it is doing a DnD when the
307 // user just wanted a normal click.
308 startDragTimer
->Start(200, true);
309 #endif // wxUSE_DRAG_AND_DROP
312 void ScintillaWX::DoStartDrag() {
313 #if wxUSE_DRAG_AND_DROP
314 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
316 // Send an event to allow the drag text to be changed
317 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
318 evt
.SetEventObject(stc
);
319 evt
.SetDragText(dragText
);
320 evt
.SetDragAllowMove(true);
321 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
322 stc
->GetSelectionEnd()));
323 stc
->GetEventHandler()->ProcessEvent(evt
);
324 dragText
= evt
.GetDragText();
326 if (dragText
.length()) {
327 wxDropSource
source(stc
);
328 wxTextDataObject
data(dragText
);
331 source
.SetData(data
);
332 dropWentOutside
= true;
333 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
334 if (result
== wxDragMove
&& dropWentOutside
)
337 SetDragPosition(invalidPosition
);
339 #endif // wxUSE_DRAG_AND_DROP
343 bool ScintillaWX::SetIdle(bool on
) {
344 if (idler
.state
!= on
) {
345 // connect or disconnect the EVT_IDLE handler
347 stc
->Connect(wxID_ANY
, wxEVT_IDLE
,
348 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
350 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
,
351 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
358 void ScintillaWX::SetTicking(bool on
) {
359 wxSTCTimer
* steTimer
;
360 if (timer
.ticking
!= on
) {
363 steTimer
= new wxSTCTimer(this);
364 steTimer
->Start(timer
.tickSize
);
365 timer
.tickerID
= steTimer
;
367 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
373 timer
.ticksToWait
= caret
.period
;
377 void ScintillaWX::SetMouseCapture(bool on
) {
378 if (mouseDownCaptures
) {
379 if (on
&& !capturedMouse
)
381 else if (!on
&& capturedMouse
&& stc
->HasCapture())
388 bool ScintillaWX::HaveMouseCapture() {
389 return capturedMouse
;
393 void ScintillaWX::ScrollText(int linesToMove
) {
394 int dy
= vs
.lineHeight
* (linesToMove
);
395 stc
->ScrollWindow(0, dy
);
399 void ScintillaWX::SetVerticalScrollPos() {
400 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
401 stc
->SetScrollPos(wxVERTICAL
, topLine
);
403 else { // otherwise use the one that's been given to us
404 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
408 void ScintillaWX::SetHorizontalScrollPos() {
409 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
410 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
412 else { // otherwise use the one that's been given to us
413 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
418 const int H_SCROLL_STEP
= 20;
420 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
421 bool modified
= false;
424 if (!verticalScrollBarVisible
)
427 // Check the vertical scrollbar
428 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
429 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
430 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
431 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
432 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
433 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
437 else { // otherwise use the one that's been given to us
438 int sbMax
= stc
->m_vScrollBar
->GetRange();
439 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
440 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
441 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
442 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
448 // Check the horizontal scrollbar
449 PRectangle rcText
= GetTextRectangle();
450 int horizEnd
= scrollWidth
;
453 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
455 int pageWidth
= rcText
.Width();
457 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
458 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
459 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
460 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
461 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
462 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
464 if (scrollWidth
< pageWidth
) {
465 HorizontalScrollTo(0);
469 else { // otherwise use the one that's been given to us
470 int sbMax
= stc
->m_hScrollBar
->GetRange();
471 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
472 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
473 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
474 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
476 if (scrollWidth
< pageWidth
) {
477 HorizontalScrollTo(0);
486 void ScintillaWX::NotifyChange() {
491 void ScintillaWX::NotifyParent(SCNotification scn
) {
492 stc
->NotifyParent(&scn
);
496 // This method is overloaded from ScintillaBase in order to prevent the
497 // AutoComplete window from being destroyed when it gets the focus. There is
498 // a side effect that the AutoComp will also not be destroyed when switching
499 // to another window, but I think that is okay.
500 void ScintillaWX::CancelModes() {
502 AutoCompleteCancel();
504 Editor::CancelModes();
509 void ScintillaWX::Copy() {
510 if (currentPos
!= anchor
) {
512 CopySelectionRange(&st
);
518 void ScintillaWX::Paste() {
519 pdoc
->BeginUndoAction();
523 wxTextDataObject data
;
524 bool gotData
= false;
526 wxTheClipboard
->UsePrimarySelection(false);
527 if (wxTheClipboard
->Open()) {
528 gotData
= wxTheClipboard
->GetData(data
);
529 wxTheClipboard
->Close();
532 wxString text
= wxTextBuffer::Translate(data
.GetText(),
533 wxConvertEOLMode(pdoc
->eolMode
));
534 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
537 // free up the old character buffer in case the text is real big
538 data
.SetText(wxEmptyString
);
539 text
= wxEmptyString
;
541 int len
= strlen(buf
);
542 pdoc
->InsertString(currentPos
, buf
, len
);
543 SetEmptySelection(currentPos
+ len
);
545 #endif // wxUSE_DATAOBJ
547 pdoc
->EndUndoAction();
553 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
555 wxTheClipboard
->UsePrimarySelection(false);
556 if (wxTheClipboard
->Open()) {
557 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
558 wxTheClipboard
->SetData(new wxTextDataObject(text
));
559 wxTheClipboard
->Close();
563 #endif // wxUSE_CLIPBOARD
567 bool ScintillaWX::CanPaste() {
569 bool canPaste
= false;
572 if (Editor::CanPaste()) {
573 wxTheClipboard
->UsePrimarySelection(false);
574 didOpen
= !wxTheClipboard
->IsOpened();
576 wxTheClipboard
->Open();
578 if (wxTheClipboard
->IsOpened()) {
579 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
581 wxTheClipboard
->Close();
587 #endif // wxUSE_CLIPBOARD
590 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
591 if (! ct
.wCallTip
.Created() ) {
592 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
593 ct
.wDraw
= ct
.wCallTip
;
598 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
600 ((wxMenu
*)popup
.GetID())->AppendSeparator();
602 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
605 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
609 // This is called by the Editor base class whenever something is selected.
610 // For wxGTK we can put this text in the primary selection and then other apps
611 // can paste with the middle button.
612 void ScintillaWX::ClaimSelection() {
614 // Put the selected text in the PRIMARY selection
615 if (currentPos
!= anchor
) {
617 CopySelectionRange(&st
);
618 wxTheClipboard
->UsePrimarySelection(true);
619 if (wxTheClipboard
->Open()) {
620 wxString text
= stc2wx(st
.s
, st
.len
);
621 wxTheClipboard
->SetData(new wxTextDataObject(text
));
622 wxTheClipboard
->Close();
624 wxTheClipboard
->UsePrimarySelection(false);
630 void ScintillaWX::UpdateSystemCaret() {
633 if (HasCaretSizeChanged()) {
634 DestroySystemCaret();
637 Point pos
= LocationFromPosition(currentPos
);
638 ::SetCaretPos(pos
.x
, pos
.y
);
644 bool ScintillaWX::HasCaretSizeChanged() {
646 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
647 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
654 bool ScintillaWX::CreateSystemCaret() {
656 sysCaretWidth
= vs
.caretWidth
;
657 if (0 == sysCaretWidth
) {
660 sysCaretHeight
= vs
.lineHeight
;
661 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
662 char *bits
= new char[bitmapSize
];
663 memset(bits
, 0, bitmapSize
);
664 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
665 1, reinterpret_cast<BYTE
*>(bits
));
667 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
668 sysCaretWidth
, sysCaretHeight
);
669 ::ShowCaret(GetHwndOf(stc
));
676 bool ScintillaWX::DestroySystemCaret() {
678 ::HideCaret(GetHwndOf(stc
));
679 BOOL retval
= ::DestroyCaret();
680 if (sysCaretBitmap
) {
681 ::DeleteObject(sysCaretBitmap
);
691 //----------------------------------------------------------------------
694 sptr_t
ScintillaWX::DefWndProc(unsigned int /*iMessage*/, uptr_t
/*wParam*/, sptr_t
/*lParam*/) {
698 sptr_t
ScintillaWX::WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) {
700 case SCI_CALLTIPSHOW
: {
701 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
702 // because of the little tweak that needs done below for wxGTK.
703 // When updating new versions double check that this is still
704 // needed, and that any new code there is copied here too.
705 Point pt
= LocationFromPosition(wParam
);
706 char* defn
= reinterpret_cast<char *>(lParam
);
707 AutoCompleteCancel();
708 pt
.y
+= vs
.lineHeight
;
709 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
711 vs
.styles
[STYLE_DEFAULT
].fontName
,
712 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
714 vs
.styles
[STYLE_DEFAULT
].characterSet
,
716 // If the call-tip window would be out of the client
717 // space, adjust so it displays above the text.
718 PRectangle rcClient
= GetClientRectangle();
719 if (rc
.bottom
> rcClient
.bottom
) {
721 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
723 int offset
= vs
.lineHeight
+ rc
.Height();
728 // Now display the window.
729 CreateCallTipWindow(rc
);
730 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
736 case SCI_LOADLEXERLIBRARY
:
737 LexerManager::GetInstance()->Load((const char*)lParam
);
742 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
749 //----------------------------------------------------------------------
752 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
754 paintState
= painting
;
755 Surface
* surfaceWindow
= Surface::Allocate();
756 surfaceWindow
->Init(dc
, wMain
.GetID());
757 rcPaint
= PRectangleFromwxRect(rect
);
758 PRectangle rcClient
= GetClientRectangle();
759 paintingAllText
= rcPaint
.Contains(rcClient
);
761 ClipChildren(*dc
, rcPaint
);
762 Paint(surfaceWindow
, rcPaint
);
764 delete surfaceWindow
;
765 if (paintState
== paintAbandoned
) {
766 // Painting area was insufficient to cover new styling or brace
767 // highlight positions
770 paintState
= notPainting
;
774 void ScintillaWX::DoHScroll(int type
, int pos
) {
776 PRectangle rcText
= GetTextRectangle();
777 int pageWidth
= rcText
.Width() * 2 / 3;
778 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
779 xPos
-= H_SCROLL_STEP
;
780 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
781 xPos
+= H_SCROLL_STEP
;
782 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
784 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
786 if (xPos
> scrollWidth
- rcText
.Width()) {
787 xPos
= scrollWidth
- rcText
.Width();
790 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
792 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
794 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
797 HorizontalScrollTo(xPos
);
800 void ScintillaWX::DoVScroll(int type
, int pos
) {
801 int topLineNew
= topLine
;
802 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
804 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
806 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
807 topLineNew
-= LinesToScroll();
808 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
809 topLineNew
+= LinesToScroll();
810 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
812 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
813 topLineNew
= MaxScrollPos();
814 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
817 ScrollTo(topLineNew
);
820 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
821 int linesPerAction
, int ctrlDown
,
822 bool isPageScroll
) {
823 int topLineNew
= topLine
;
826 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
828 KeyCommand(SCI_ZOOMIN
);
831 KeyCommand(SCI_ZOOMOUT
);
834 else { // otherwise just scroll the window
837 wheelRotation
+= rotation
;
838 lines
= wheelRotation
/ delta
;
839 wheelRotation
-= lines
* delta
;
842 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
844 lines
*= linesPerAction
;
846 ScrollTo(topLineNew
);
852 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
856 void ScintillaWX::DoLoseFocus(){
858 SetFocusState(false);
860 DestroySystemCaret();
863 void ScintillaWX::DoGainFocus(){
867 DestroySystemCaret();
871 void ScintillaWX::DoSysColourChange() {
872 InvalidateStyleData();
875 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
876 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
879 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
880 ButtonUp(pt
, curTime
, ctrl
);
881 #if wxUSE_DRAG_AND_DROP
882 if (startDragTimer
->IsRunning()) {
883 startDragTimer
->Stop();
884 SetDragPosition(invalidPosition
);
885 SetEmptySelection(PositionFromLocation(pt
));
886 ShowCaretAtCurrentPosition();
888 #endif // wxUSE_DRAG_AND_DROP
891 void ScintillaWX::DoLeftButtonMove(Point pt
) {
896 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
897 // Set the current position to the mouse click point and
898 // then paste in the PRIMARY selection, if any. wxGTK only.
899 int newPos
= PositionFromLocation(pt
);
900 MovePositionTo(newPos
, noSel
, true);
902 pdoc
->BeginUndoAction();
903 wxTextDataObject data
;
904 bool gotData
= false;
905 wxTheClipboard
->UsePrimarySelection(true);
906 if (wxTheClipboard
->Open()) {
907 gotData
= wxTheClipboard
->GetData(data
);
908 wxTheClipboard
->Close();
910 wxTheClipboard
->UsePrimarySelection(false);
912 wxString text
= wxTextBuffer::Translate(data
.GetText(),
913 wxConvertEOLMode(pdoc
->eolMode
));
914 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
915 int len
= strlen(buf
);
916 pdoc
->InsertString(currentPos
, buf
, len
);
917 SetEmptySelection(currentPos
+ len
);
919 pdoc
->EndUndoAction();
923 ShowCaretAtCurrentPosition();
924 EnsureCaretVisible();
927 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
932 void ScintillaWX::DoAddChar(int key
) {
935 wszChars
[0] = (wxChar
)key
;
937 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
938 AddCharUTF((char*)buf
.data(), strlen(buf
));
945 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
947 int key
= evt
.GetKeyCode();
948 bool shift
= evt
.ShiftDown(),
949 ctrl
= evt
.ControlDown(),
952 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
956 case WXK_DOWN
: key
= SCK_DOWN
; break;
957 case WXK_UP
: key
= SCK_UP
; break;
958 case WXK_LEFT
: key
= SCK_LEFT
; break;
959 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
960 case WXK_HOME
: key
= SCK_HOME
; break;
961 case WXK_END
: key
= SCK_END
; break;
962 case WXK_PAGEUP
: key
= SCK_PRIOR
; break;
963 case WXK_PAGEDOWN
: key
= SCK_NEXT
; break;
964 case WXK_NUMPAD_DOWN
: key
= SCK_DOWN
; break;
965 case WXK_NUMPAD_UP
: key
= SCK_UP
; break;
966 case WXK_NUMPAD_LEFT
: key
= SCK_LEFT
; break;
967 case WXK_NUMPAD_RIGHT
: key
= SCK_RIGHT
; break;
968 case WXK_NUMPAD_HOME
: key
= SCK_HOME
; break;
969 case WXK_NUMPAD_END
: key
= SCK_END
; break;
970 case WXK_NUMPAD_PAGEUP
: key
= SCK_PRIOR
; break;
971 case WXK_NUMPAD_PAGEDOWN
: key
= SCK_NEXT
; break;
972 case WXK_NUMPAD_DELETE
: key
= SCK_DELETE
; break;
973 case WXK_NUMPAD_INSERT
: key
= SCK_INSERT
; break;
974 case WXK_DELETE
: key
= SCK_DELETE
; break;
975 case WXK_INSERT
: key
= SCK_INSERT
; break;
976 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
977 case WXK_BACK
: key
= SCK_BACK
; break;
978 case WXK_TAB
: key
= SCK_TAB
; break;
979 case WXK_NUMPAD_ENTER
: // fall through
980 case WXK_RETURN
: key
= SCK_RETURN
; break;
981 case WXK_ADD
: // fall through
982 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
983 case WXK_SUBTRACT
: // fall through
984 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
985 case WXK_DIVIDE
: // fall through
986 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
987 case WXK_CONTROL
: key
= 0; break;
988 case WXK_ALT
: key
= 0; break;
989 case WXK_SHIFT
: key
= 0; break;
990 case WXK_MENU
: key
= 0; break;
994 if ( evt
.MetaDown() ) {
995 // check for a few common Mac Meta-key combos and remap them to Ctrl
1002 case 'A': // Select All
1009 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
1018 void ScintillaWX::DoCommand(int ID
) {
1023 void ScintillaWX::DoContextMenu(Point pt
) {
1024 if (displayPopupMenu
)
1028 void ScintillaWX::DoOnListBox() {
1029 AutoCompleteCompleted();
1033 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
1041 //----------------------------------------------------------------------
1043 #if wxUSE_DRAG_AND_DROP
1044 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
1045 SetDragPosition(invalidPosition
);
1047 wxString text
= wxTextBuffer::Translate(data
,
1048 wxConvertEOLMode(pdoc
->eolMode
));
1050 // Send an event to allow the drag details to be changed
1051 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
1052 evt
.SetEventObject(stc
);
1053 evt
.SetDragResult(dragResult
);
1056 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1057 evt
.SetDragText(text
);
1058 stc
->GetEventHandler()->ProcessEvent(evt
);
1060 dragResult
= evt
.GetDragResult();
1061 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
1062 DropAt(evt
.GetPosition(),
1063 wx2stc(evt
.GetDragText()),
1064 dragResult
== wxDragMove
,
1065 false); // TODO: rectangular?
1072 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1078 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1079 SetDragPosition(PositionFromLocation(Point(x
, y
)));
1081 // Send an event to allow the drag result to be changed
1082 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1083 evt
.SetEventObject(stc
);
1084 evt
.SetDragResult(def
);
1087 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1088 stc
->GetEventHandler()->ProcessEvent(evt
);
1090 dragResult
= evt
.GetDragResult();
1095 void ScintillaWX::DoDragLeave() {
1096 SetDragPosition(invalidPosition
);
1098 #endif // wxUSE_DRAG_AND_DROP
1099 //----------------------------------------------------------------------
1101 // Force the whole window to be repainted
1102 void ScintillaWX::FullPaint() {
1104 stc
->Refresh(false);
1110 void ScintillaWX::DoScrollToLine(int line
) {
1115 void ScintillaWX::DoScrollToColumn(int column
) {
1116 HorizontalScrollTo(column
* vs
.spaceWidth
);
1119 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1120 // will leave it here commented out for a while just in case...
1121 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1123 // wxRegion rgn(wxRectFromPRectangle(rect));
1124 // if (ac.Active()) {
1125 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1126 // rgn.Subtract(childRect);
1128 // if (ct.inCallTipMode) {
1129 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1130 // wxRect childRect = tip->GetRect();
1131 // #if wxUSE_POPUPWIN
1132 // childRect.SetPosition(tip->GetMyPosition());
1134 // rgn.Subtract(childRect);
1136 // dc.SetClippingRegion(rgn);
1140 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1141 vs
.extraFontFlag
= useAA
;
1142 InvalidateStyleRedraw();
1145 bool ScintillaWX::GetUseAntiAliasing() {
1146 return vs
.extraFontFlag
;
1149 //----------------------------------------------------------------------
1150 //----------------------------------------------------------------------