1 ////////////////////////////////////////////////////////////////////////////
2 // Name: src/stc/ScintillaWX.cpp
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 licence
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 #if !wxUSE_STD_CONTAINERS && !wxUSE_STD_IOSTREAM && !wxUSE_STD_STRING
38 #include "wx/beforestd.h"
40 #include "wx/afterstd.h"
43 #include "ScintillaWX.h"
44 #include "ExternalLexer.h"
45 #include "wx/stc/stc.h"
46 #include "wx/stc/private.h"
51 #include "wx/msw/private.h"
54 //----------------------------------------------------------------------
57 class wxSTCTimer
: public wxTimer
{
59 wxSTCTimer(ScintillaWX
* swx
) {
72 #if wxUSE_DRAG_AND_DROP
73 bool wxSTCDropTarget::OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) {
74 return m_swx
->DoDropText(x
, y
, data
);
77 wxDragResult
wxSTCDropTarget::OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
) {
78 return m_swx
->DoDragEnter(x
, y
, def
);
81 wxDragResult
wxSTCDropTarget::OnDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
82 return m_swx
->DoDragOver(x
, y
, def
);
85 void wxSTCDropTarget::OnLeave() {
88 #endif // wxUSE_DRAG_AND_DROP
92 #include "wx/popupwin.h"
93 #define wxSTCCallTipBase wxPopupWindow
96 #define wxSTCCallTipBase wxFrame
99 #include "wx/dcbuffer.h"
101 class wxSTCCallTip
: public wxSTCCallTipBase
{
103 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
) :
105 wxSTCCallTipBase(parent
, wxBORDER_NONE
),
107 wxSTCCallTipBase(parent
, -1, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
,
109 | wxFRAME_FLOAT_ON_PARENT
116 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
118 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
122 #if wxUSE_POPUPWIN && defined(__WXGTK__)
123 wxRect rect
= GetRect();
126 GetParent()->Refresh(false, &rect
);
130 bool AcceptsFocus() const { return false; }
132 void OnPaint(wxPaintEvent
& WXUNUSED(evt
))
134 wxAutoBufferedPaintDC
dc(this);
135 Surface
* surfaceWindow
= Surface::Allocate(0);
136 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
137 m_ct
->PaintCT(surfaceWindow
);
138 surfaceWindow
->Release();
139 delete surfaceWindow
;
142 void OnFocus(wxFocusEvent
& event
)
144 GetParent()->SetFocus();
148 void OnLeftDown(wxMouseEvent
& event
)
150 wxPoint pt
= event
.GetPosition();
153 m_swx
->CallTipClick();
156 virtual void DoSetSize(int x
, int y
,
157 int width
, int height
,
158 int sizeFlags
= wxSIZE_AUTO
)
160 // convert coords to screen coords since we're a top-level window
161 if (x
!= wxDefaultCoord
) {
163 GetParent()->ClientToScreen(&x
, NULL
);
165 if (y
!= wxDefaultCoord
) {
167 GetParent()->ClientToScreen(NULL
, &y
);
169 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
174 virtual bool Show( bool show
= true )
176 // Although we're a frame, we always want the parent to be active, so
177 // raise it whenever we get shown.
178 bool rv
= wxSTCCallTipBase::Show(show
);
181 wxTopLevelWindow
*frame
= wxDynamicCast(
182 wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
190 wxPoint
GetMyPosition()
192 return wxPoint(m_cx
, m_cy
);
199 DECLARE_EVENT_TABLE()
202 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
203 EVT_PAINT(wxSTCCallTip::OnPaint
)
204 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
205 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
209 //----------------------------------------------------------------------
212 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
216 switch (scintillaMode
) {
218 type
= wxTextFileType_Dos
;
222 type
= wxTextFileType_Mac
;
226 type
= wxTextFileType_Unix
;
230 type
= wxTextBuffer::typeDefault
;
235 #endif // wxUSE_DATAOBJ
238 //----------------------------------------------------------------------
239 // Constructor/Destructor
242 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
243 capturedMouse
= false;
258 ScintillaWX::~ScintillaWX() {
262 //----------------------------------------------------------------------
263 // base class virtuals
266 void ScintillaWX::Initialise() {
267 //ScintillaBase::Initialise();
268 #if wxUSE_DRAG_AND_DROP
269 dropTarget
= new wxSTCDropTarget
;
270 dropTarget
->SetScintilla(this);
271 stc
->SetDropTarget(dropTarget
);
272 #endif // wxUSE_DRAG_AND_DROP
273 vs
.extraFontFlag
= true; // UseAntiAliasing
277 void ScintillaWX::Finalise() {
278 ScintillaBase::Finalise();
281 DestroySystemCaret();
285 void ScintillaWX::StartDrag() {
286 #if wxUSE_DRAG_AND_DROP
287 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
289 // Send an event to allow the drag text to be changed
290 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
291 evt
.SetEventObject(stc
);
292 evt
.SetDragText(dragText
);
293 evt
.SetDragFlags(wxDrag_DefaultMove
);
294 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
295 stc
->GetSelectionEnd()));
296 stc
->GetEventHandler()->ProcessEvent(evt
);
297 dragText
= evt
.GetDragText();
299 if ( !dragText
.empty() ) {
300 wxDropSource
source(stc
);
301 wxTextDataObject
data(dragText
);
304 source
.SetData(data
);
305 dropWentOutside
= true;
306 inDragDrop
= ddDragging
;
307 result
= source
.DoDragDrop(evt
.GetDragFlags());
308 if (result
== wxDragMove
&& dropWentOutside
)
311 SetDragPosition(SelectionPosition(invalidPosition
));
313 #endif // wxUSE_DRAG_AND_DROP
317 bool ScintillaWX::SetIdle(bool on
) {
318 if (idler
.state
!= on
) {
319 // connect or disconnect the EVT_IDLE handler
321 stc
->Connect(wxID_ANY
, wxEVT_IDLE
, wxIdleEventHandler(wxStyledTextCtrl::OnIdle
));
323 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
, wxIdleEventHandler(wxStyledTextCtrl::OnIdle
));
330 void ScintillaWX::SetTicking(bool on
) {
331 wxSTCTimer
* steTimer
;
332 if (timer
.ticking
!= on
) {
335 steTimer
= new wxSTCTimer(this);
336 steTimer
->Start(timer
.tickSize
);
337 timer
.tickerID
= steTimer
;
339 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
345 timer
.ticksToWait
= caret
.period
;
349 void ScintillaWX::SetMouseCapture(bool on
) {
350 if (mouseDownCaptures
) {
351 if (on
&& !capturedMouse
)
353 else if (!on
&& capturedMouse
&& stc
->HasCapture())
360 bool ScintillaWX::HaveMouseCapture() {
361 return capturedMouse
;
365 void ScintillaWX::ScrollText(int linesToMove
) {
366 int dy
= vs
.lineHeight
* (linesToMove
);
367 stc
->ScrollWindow(0, dy
);
370 void ScintillaWX::SetVerticalScrollPos() {
371 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
372 stc
->SetScrollPos(wxVERTICAL
, topLine
);
374 else { // otherwise use the one that's been given to us
375 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
379 void ScintillaWX::SetHorizontalScrollPos() {
380 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
381 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
383 else { // otherwise use the one that's been given to us
384 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
389 const int H_SCROLL_STEP
= 20;
391 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
392 bool modified
= false;
395 if (!verticalScrollBarVisible
)
398 // Check the vertical scrollbar
399 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
400 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
401 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
402 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
403 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
404 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
408 else { // otherwise use the one that's been given to us
409 int sbMax
= stc
->m_vScrollBar
->GetRange();
410 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
411 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
412 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
413 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
419 // Check the horizontal scrollbar
420 PRectangle rcText
= GetTextRectangle();
421 int horizEnd
= scrollWidth
;
424 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
426 int pageWidth
= rcText
.Width();
428 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
429 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
430 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
431 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
432 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
433 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
435 if (scrollWidth
< pageWidth
) {
436 HorizontalScrollTo(0);
440 else { // otherwise use the one that's been given to us
441 int sbMax
= stc
->m_hScrollBar
->GetRange();
442 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
443 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
444 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
445 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
447 if (scrollWidth
< pageWidth
) {
448 HorizontalScrollTo(0);
457 void ScintillaWX::NotifyChange() {
462 void ScintillaWX::NotifyParent(SCNotification scn
) {
463 stc
->NotifyParent(&scn
);
467 // This method is overloaded from ScintillaBase in order to prevent the
468 // AutoComplete window from being destroyed when it gets the focus. There is
469 // a side effect that the AutoComp will also not be destroyed when switching
470 // to another window, but I think that is okay.
471 void ScintillaWX::CancelModes() {
473 AutoCompleteCancel();
475 Editor::CancelModes();
480 void ScintillaWX::Copy() {
483 CopySelectionRange(&st
);
489 void ScintillaWX::Paste() {
490 pdoc
->BeginUndoAction();
494 wxTextDataObject data
;
495 bool gotData
= false;
497 wxTheClipboard
->UsePrimarySelection(false);
498 if (wxTheClipboard
->Open()) {
499 gotData
= wxTheClipboard
->GetData(data
);
500 wxTheClipboard
->Close();
503 wxString text
= wxTextBuffer::Translate(data
.GetText(),
504 wxConvertEOLMode(pdoc
->eolMode
));
505 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
508 // free up the old character buffer in case the text is real big
509 data
.SetText(wxEmptyString
);
510 text
= wxEmptyString
;
512 int len
= strlen(buf
);
513 int caretMain
= sel
.MainCaret();
514 pdoc
->InsertString(caretMain
, buf
, len
);
515 SetEmptySelection(caretMain
+ len
);
517 #endif // wxUSE_DATAOBJ
519 pdoc
->EndUndoAction();
525 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
530 wxTheClipboard
->UsePrimarySelection(false);
531 if (wxTheClipboard
->Open()) {
532 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
533 wxTheClipboard
->SetData(new wxTextDataObject(text
));
534 wxTheClipboard
->Close();
538 #endif // wxUSE_CLIPBOARD
542 bool ScintillaWX::CanPaste() {
544 bool canPaste
= false;
547 if (Editor::CanPaste()) {
548 wxTheClipboard
->UsePrimarySelection(false);
549 didOpen
= !wxTheClipboard
->IsOpened();
551 wxTheClipboard
->Open();
553 if (wxTheClipboard
->IsOpened()) {
554 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
556 wxTheClipboard
->Close();
562 #endif // wxUSE_CLIPBOARD
565 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
566 if (! ct
.wCallTip
.Created() ) {
567 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
568 ct
.wDraw
= ct
.wCallTip
;
573 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
575 ((wxMenu
*)popup
.GetID())->AppendSeparator();
577 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
580 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
584 // This is called by the Editor base class whenever something is selected.
585 // For wxGTK we can put this text in the primary selection and then other apps
586 // can paste with the middle button.
587 void ScintillaWX::ClaimSelection() {
589 // Put the selected text in the PRIMARY selection
592 CopySelectionRange(&st
);
593 wxTheClipboard
->UsePrimarySelection(true);
594 if (wxTheClipboard
->Open()) {
595 wxString text
= stc2wx(st
.s
, st
.len
);
596 wxTheClipboard
->SetData(new wxTextDataObject(text
));
597 wxTheClipboard
->Close();
599 wxTheClipboard
->UsePrimarySelection(false);
605 void ScintillaWX::UpdateSystemCaret() {
608 if (HasCaretSizeChanged()) {
609 DestroySystemCaret();
612 Point pos
= PointMainCaret();
613 ::SetCaretPos(pos
.x
, pos
.y
);
619 bool ScintillaWX::HasCaretSizeChanged() {
621 if ( (vs
.caretWidth
&& (sysCaretWidth
!= vs
.caretWidth
))
622 || (vs
.lineHeight
&& (sysCaretHeight
!= vs
.lineHeight
)) ) {
629 bool ScintillaWX::CreateSystemCaret() {
631 sysCaretWidth
= vs
.caretWidth
;
632 if (0 == sysCaretWidth
) {
635 sysCaretHeight
= vs
.lineHeight
;
636 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
637 char *bits
= new char[bitmapSize
];
638 memset(bits
, 0, bitmapSize
);
639 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
640 1, reinterpret_cast<BYTE
*>(bits
));
642 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
643 sysCaretWidth
, sysCaretHeight
);
644 ::ShowCaret(GetHwndOf(stc
));
651 bool ScintillaWX::DestroySystemCaret() {
653 ::HideCaret(GetHwndOf(stc
));
654 BOOL retval
= ::DestroyCaret();
655 if (sysCaretBitmap
) {
656 ::DeleteObject(sysCaretBitmap
);
666 //----------------------------------------------------------------------
669 sptr_t
ScintillaWX::DefWndProc(unsigned int /*iMessage*/, uptr_t
/*wParam*/, sptr_t
/*lParam*/) {
673 sptr_t
ScintillaWX::WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) {
675 #if 0 // TODO: check this
677 case SCI_CALLTIPSHOW
: {
678 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
679 // because of the little tweak that needs done below for wxGTK.
680 // When updating new versions double check that this is still
681 // needed, and that any new code there is copied here too.
682 Point pt
= LocationFromPosition(wParam
);
683 char* defn
= reinterpret_cast<char *>(lParam
);
684 AutoCompleteCancel();
685 pt
.y
+= vs
.lineHeight
;
686 int ctStyle
= ct
.UseStyleCallTip() ? STYLE_CALLTIP
: STYLE_DEFAULT
;
687 if (ct
.UseStyleCallTip())
689 ct
.SetForeBack(vs
.styles
[STYLE_CALLTIP
].fore
, vs
.styles
[STYLE_CALLTIP
].back
);
691 int caretMain
= sel
.MainCaret();
692 PRectangle rc
= ct
.CallTipStart(caretMain
, pt
,
694 vs
.styles
[ctStyle
].fontName
,
695 vs
.styles
[ctStyle
].sizeZoomed
,
697 vs
.styles
[ctStyle
].characterSet
,
699 // If the call-tip window would be out of the client
700 // space, adjust so it displays above the text.
701 PRectangle rcClient
= GetClientRectangle();
702 if (rc
.bottom
> rcClient
.bottom
) {
704 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
706 int offset
= vs
.lineHeight
+ rc
.Height();
711 // Now display the window.
712 CreateCallTipWindow(rc
);
713 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
720 case SCI_LOADLEXERLIBRARY
:
721 LexerManager::GetInstance()->Load((const char*)lParam
);
726 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
733 //----------------------------------------------------------------------
736 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
738 paintState
= painting
;
739 AutoSurface
surfaceWindow(dc
, this);
741 rcPaint
= PRectangleFromwxRect(rect
);
742 PRectangle rcClient
= GetClientRectangle();
743 paintingAllText
= rcPaint
.Contains(rcClient
);
745 ClipChildren(*dc
, rcPaint
);
746 Paint(surfaceWindow
, rcPaint
);
747 surfaceWindow
->Release();
750 if (paintState
== paintAbandoned
) {
751 // Painting area was insufficient to cover new styling or brace
752 // highlight positions. So trigger a new paint event that will
753 // repaint the whole window.
756 #if defined(__WXOSX__)
757 // On Mac we also need to finish the current paint to make sure that
758 // everything is on the screen that needs to be there between now and
759 // when the next paint event arrives.
763 paintState
= notPainting
;
767 // Force the whole window to be repainted
768 void ScintillaWX::FullPaint() {
774 void ScintillaWX::FullPaintDC(wxDC
* dc
) {
775 paintState
= painting
;
776 rcPaint
= GetClientRectangle();
777 paintingAllText
= true;
778 AutoSurface
surfaceWindow(dc
, this);
780 Paint(surfaceWindow
, rcPaint
);
781 surfaceWindow
->Release();
783 paintState
= notPainting
;
788 void ScintillaWX::DoHScroll(int type
, int pos
) {
790 PRectangle rcText
= GetTextRectangle();
791 int pageWidth
= rcText
.Width() * 2 / 3;
792 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
793 xPos
-= H_SCROLL_STEP
;
794 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
795 xPos
+= H_SCROLL_STEP
;
796 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
798 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
800 if (xPos
> scrollWidth
- rcText
.Width()) {
801 xPos
= scrollWidth
- rcText
.Width();
804 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
806 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
808 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
811 HorizontalScrollTo(xPos
);
814 void ScintillaWX::DoVScroll(int type
, int pos
) {
815 int topLineNew
= topLine
;
816 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
818 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
820 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
821 topLineNew
-= LinesToScroll();
822 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
823 topLineNew
+= LinesToScroll();
824 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
826 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
827 topLineNew
= MaxScrollPos();
828 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
831 ScrollTo(topLineNew
);
834 void ScintillaWX::DoMouseWheel(wxMouseWheelAxis axis
, int rotation
, int delta
,
835 int linesPerAction
, int columnsPerAction
,
836 bool ctrlDown
, bool isPageScroll
) {
837 int topLineNew
= topLine
;
842 if (axis
== wxMOUSE_WHEEL_HORIZONTAL
) {
843 wheelHRotation
+= rotation
* (columnsPerAction
* vs
.spaceWidth
);
844 pixels
= wheelHRotation
/ delta
;
845 wheelHRotation
-= pixels
* delta
;
848 PRectangle rcText
= GetTextRectangle();
849 if (xPos
> scrollWidth
- rcText
.Width()) {
850 xPos
= scrollWidth
- rcText
.Width();
852 HorizontalScrollTo(xPos
);
855 else if (ctrlDown
) { // Zoom the fonts if Ctrl key down
857 KeyCommand(SCI_ZOOMIN
);
860 KeyCommand(SCI_ZOOMOUT
);
863 else { // otherwise just scroll the window
866 wheelVRotation
+= rotation
;
867 lines
= wheelVRotation
/ delta
;
868 wheelVRotation
-= lines
* delta
;
871 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
873 lines
*= linesPerAction
;
875 ScrollTo(topLineNew
);
881 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
885 void ScintillaWX::DoLoseFocus(){
887 SetFocusState(false);
889 DestroySystemCaret();
892 void ScintillaWX::DoGainFocus(){
896 DestroySystemCaret();
900 void ScintillaWX::DoSysColourChange() {
901 InvalidateStyleData();
904 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
905 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
908 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
909 ButtonUp(pt
, curTime
, ctrl
);
912 void ScintillaWX::DoLeftButtonMove(Point pt
) {
917 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
918 // Set the current position to the mouse click point and
919 // then paste in the PRIMARY selection, if any. wxGTK only.
920 int newPos
= PositionFromLocation(pt
);
921 MovePositionTo(newPos
, Selection::noSel
, true);
923 pdoc
->BeginUndoAction();
924 wxTextDataObject data
;
925 bool gotData
= false;
926 wxTheClipboard
->UsePrimarySelection(true);
927 if (wxTheClipboard
->Open()) {
928 gotData
= wxTheClipboard
->GetData(data
);
929 wxTheClipboard
->Close();
931 wxTheClipboard
->UsePrimarySelection(false);
933 wxString text
= wxTextBuffer::Translate(data
.GetText(),
934 wxConvertEOLMode(pdoc
->eolMode
));
935 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
936 int len
= strlen(buf
);
937 int caretMain
= sel
.MainCaret();
938 pdoc
->InsertString(caretMain
, buf
, len
);
939 SetEmptySelection(caretMain
+ len
);
941 pdoc
->EndUndoAction();
945 ShowCaretAtCurrentPosition();
946 EnsureCaretVisible();
949 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
954 void ScintillaWX::DoAddChar(int key
) {
957 wszChars
[0] = (wxChar
)key
;
959 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
960 AddCharUTF((char*)buf
.data(), strlen(buf
));
967 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
969 int key
= evt
.GetKeyCode();
970 if (key
== WXK_NONE
) {
971 // This is a Unicode character not representable in Latin-1 or some key
972 // without key code at all (e.g. dead key or VK_PROCESSKEY under MSW).
978 bool shift
= evt
.ShiftDown(),
979 ctrl
= evt
.ControlDown(),
982 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
986 case WXK_DOWN
: key
= SCK_DOWN
; break;
987 case WXK_UP
: key
= SCK_UP
; break;
988 case WXK_LEFT
: key
= SCK_LEFT
; break;
989 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
990 case WXK_HOME
: key
= SCK_HOME
; break;
991 case WXK_END
: key
= SCK_END
; break;
992 case WXK_PAGEUP
: key
= SCK_PRIOR
; break;
993 case WXK_PAGEDOWN
: key
= SCK_NEXT
; break;
994 case WXK_NUMPAD_DOWN
: key
= SCK_DOWN
; break;
995 case WXK_NUMPAD_UP
: key
= SCK_UP
; break;
996 case WXK_NUMPAD_LEFT
: key
= SCK_LEFT
; break;
997 case WXK_NUMPAD_RIGHT
: key
= SCK_RIGHT
; break;
998 case WXK_NUMPAD_HOME
: key
= SCK_HOME
; break;
999 case WXK_NUMPAD_END
: key
= SCK_END
; break;
1000 case WXK_NUMPAD_PAGEUP
: key
= SCK_PRIOR
; break;
1001 case WXK_NUMPAD_PAGEDOWN
: key
= SCK_NEXT
; break;
1002 case WXK_NUMPAD_DELETE
: key
= SCK_DELETE
; break;
1003 case WXK_NUMPAD_INSERT
: key
= SCK_INSERT
; break;
1004 case WXK_DELETE
: key
= SCK_DELETE
; break;
1005 case WXK_INSERT
: key
= SCK_INSERT
; break;
1006 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
1007 case WXK_BACK
: key
= SCK_BACK
; break;
1008 case WXK_TAB
: key
= SCK_TAB
; break;
1009 case WXK_NUMPAD_ENTER
: // fall through
1010 case WXK_RETURN
: key
= SCK_RETURN
; break;
1011 case WXK_ADD
: // fall through
1012 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
1013 case WXK_SUBTRACT
: // fall through
1014 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
1015 case WXK_DIVIDE
: // fall through
1016 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
1017 case WXK_CONTROL
: key
= 0; break;
1018 case WXK_ALT
: key
= 0; break;
1019 case WXK_SHIFT
: key
= 0; break;
1020 case WXK_MENU
: key
= SCK_MENU
; break;
1024 if ( evt
.MetaDown() ) {
1025 // check for a few common Mac Meta-key combos and remap them to Ctrl
1032 case 'A': // Select All
1039 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
1048 void ScintillaWX::DoCommand(int ID
) {
1053 void ScintillaWX::DoContextMenu(Point pt
) {
1054 if (displayPopupMenu
)
1058 void ScintillaWX::DoOnListBox() {
1059 AutoCompleteCompleted();
1063 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
1071 //----------------------------------------------------------------------
1073 #if wxUSE_DRAG_AND_DROP
1074 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
1075 SetDragPosition(SelectionPosition(invalidPosition
));
1077 wxString text
= wxTextBuffer::Translate(data
,
1078 wxConvertEOLMode(pdoc
->eolMode
));
1080 // Send an event to allow the drag details to be changed
1081 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
1082 evt
.SetEventObject(stc
);
1083 evt
.SetDragResult(dragResult
);
1086 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1087 evt
.SetDragText(text
);
1088 stc
->GetEventHandler()->ProcessEvent(evt
);
1090 dragResult
= evt
.GetDragResult();
1091 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
1092 DropAt(SelectionPosition(evt
.GetPosition()),
1093 wx2stc(evt
.GetDragText()),
1094 dragResult
== wxDragMove
,
1095 false); // TODO: rectangular?
1102 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1108 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1109 SetDragPosition(SelectionPosition(PositionFromLocation(Point(x
, y
))));
1111 // Send an event to allow the drag result to be changed
1112 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1113 evt
.SetEventObject(stc
);
1114 evt
.SetDragResult(def
);
1117 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1118 stc
->GetEventHandler()->ProcessEvent(evt
);
1120 dragResult
= evt
.GetDragResult();
1125 void ScintillaWX::DoDragLeave() {
1126 SetDragPosition(SelectionPosition(invalidPosition
));
1128 #endif // wxUSE_DRAG_AND_DROP
1129 //----------------------------------------------------------------------
1131 void ScintillaWX::DoScrollToLine(int line
) {
1136 void ScintillaWX::DoScrollToColumn(int column
) {
1137 HorizontalScrollTo(column
* vs
.spaceWidth
);
1140 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1141 // will leave it here commented out for a while just in case...
1142 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1144 // wxRegion rgn(wxRectFromPRectangle(rect));
1145 // if (ac.Active()) {
1146 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1147 // rgn.Subtract(childRect);
1149 // if (ct.inCallTipMode) {
1150 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1151 // wxRect childRect = tip->GetRect();
1152 // #if wxUSE_POPUPWIN
1153 // childRect.SetPosition(tip->GetMyPosition());
1155 // rgn.Subtract(childRect);
1157 // dc.SetClippingRegion(rgn);
1161 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1162 vs
.extraFontFlag
= useAA
;
1163 InvalidateStyleRedraw();
1166 bool ScintillaWX::GetUseAntiAliasing() {
1167 return vs
.extraFontFlag
!= 0;
1170 //----------------------------------------------------------------------
1171 //----------------------------------------------------------------------