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
12 // Copyright: (c) 2000 by Total Control Software
13 // Licence: wxWindows licence
14 /////////////////////////////////////////////////////////////////////////////
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/scrolbar.h"
31 #include "wx/textbuf.h"
32 #include "wx/dataobj.h"
33 #include "wx/clipbrd.h"
36 #if !wxUSE_STD_CONTAINERS && !wxUSE_STD_IOSTREAM && !wxUSE_STD_STRING
37 #include "wx/beforestd.h"
39 #include "wx/afterstd.h"
42 #include "ScintillaWX.h"
43 #include "ExternalLexer.h"
44 #include "wx/stc/stc.h"
45 #include "wx/stc/private.h"
50 #include "wx/msw/private.h"
53 //----------------------------------------------------------------------
56 class wxSTCTimer
: public wxTimer
{
58 wxSTCTimer(ScintillaWX
* swx
) {
71 #if wxUSE_DRAG_AND_DROP
72 bool wxSTCDropTarget::OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) {
73 return m_swx
->DoDropText(x
, y
, data
);
76 wxDragResult
wxSTCDropTarget::OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
) {
77 return m_swx
->DoDragEnter(x
, y
, def
);
80 wxDragResult
wxSTCDropTarget::OnDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
81 return m_swx
->DoDragOver(x
, y
, def
);
84 void wxSTCDropTarget::OnLeave() {
87 #endif // wxUSE_DRAG_AND_DROP
91 #include "wx/popupwin.h"
92 #define wxSTCCallTipBase wxPopupWindow
95 #define wxSTCCallTipBase wxFrame
98 #include "wx/dcbuffer.h"
100 class wxSTCCallTip
: public wxSTCCallTipBase
{
102 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
) :
104 wxSTCCallTipBase(parent
, wxBORDER_NONE
),
106 wxSTCCallTipBase(parent
, -1, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
,
108 | wxFRAME_FLOAT_ON_PARENT
115 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
117 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
121 #if wxUSE_POPUPWIN && defined(__WXGTK__)
122 wxRect rect
= GetRect();
125 GetParent()->Refresh(false, &rect
);
129 bool AcceptsFocus() const { return false; }
131 void OnPaint(wxPaintEvent
& WXUNUSED(evt
))
133 wxAutoBufferedPaintDC
dc(this);
134 Surface
* surfaceWindow
= Surface::Allocate(0);
135 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
136 m_ct
->PaintCT(surfaceWindow
);
137 surfaceWindow
->Release();
138 delete surfaceWindow
;
141 void OnFocus(wxFocusEvent
& event
)
143 GetParent()->SetFocus();
147 void OnLeftDown(wxMouseEvent
& event
)
149 wxPoint pt
= event
.GetPosition();
152 m_swx
->CallTipClick();
155 virtual void DoSetSize(int x
, int y
,
156 int width
, int height
,
157 int sizeFlags
= wxSIZE_AUTO
)
159 // convert coords to screen coords since we're a top-level window
160 if (x
!= wxDefaultCoord
) {
162 GetParent()->ClientToScreen(&x
, NULL
);
164 if (y
!= wxDefaultCoord
) {
166 GetParent()->ClientToScreen(NULL
, &y
);
168 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
173 virtual bool Show( bool show
= true )
175 // Although we're a frame, we always want the parent to be active, so
176 // raise it whenever we get shown.
177 bool rv
= wxSTCCallTipBase::Show(show
);
180 wxTopLevelWindow
*frame
= wxDynamicCast(
181 wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
189 wxPoint
GetMyPosition()
191 return wxPoint(m_cx
, m_cy
);
198 DECLARE_EVENT_TABLE()
201 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
202 EVT_PAINT(wxSTCCallTip::OnPaint
)
203 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
204 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
208 //----------------------------------------------------------------------
211 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
215 switch (scintillaMode
) {
217 type
= wxTextFileType_Dos
;
221 type
= wxTextFileType_Mac
;
225 type
= wxTextFileType_Unix
;
229 type
= wxTextBuffer::typeDefault
;
234 #endif // wxUSE_DATAOBJ
237 //----------------------------------------------------------------------
238 // Constructor/Destructor
241 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
242 capturedMouse
= false;
257 ScintillaWX::~ScintillaWX() {
261 //----------------------------------------------------------------------
262 // base class virtuals
265 void ScintillaWX::Initialise() {
266 //ScintillaBase::Initialise();
267 #if wxUSE_DRAG_AND_DROP
268 dropTarget
= new wxSTCDropTarget
;
269 dropTarget
->SetScintilla(this);
270 stc
->SetDropTarget(dropTarget
);
271 #endif // wxUSE_DRAG_AND_DROP
272 vs
.extraFontFlag
= true; // UseAntiAliasing
276 void ScintillaWX::Finalise() {
277 ScintillaBase::Finalise();
280 DestroySystemCaret();
284 void ScintillaWX::StartDrag() {
285 #if wxUSE_DRAG_AND_DROP
286 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
288 // Send an event to allow the drag text to be changed
289 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
290 evt
.SetEventObject(stc
);
291 evt
.SetDragText(dragText
);
292 evt
.SetDragFlags(wxDrag_DefaultMove
);
293 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
294 stc
->GetSelectionEnd()));
295 stc
->GetEventHandler()->ProcessEvent(evt
);
296 dragText
= evt
.GetDragText();
298 if ( !dragText
.empty() ) {
299 wxDropSource
source(stc
);
300 wxTextDataObject
data(dragText
);
303 source
.SetData(data
);
304 dropWentOutside
= true;
305 inDragDrop
= ddDragging
;
306 result
= source
.DoDragDrop(evt
.GetDragFlags());
307 if (result
== wxDragMove
&& dropWentOutside
)
310 SetDragPosition(SelectionPosition(invalidPosition
));
312 #endif // wxUSE_DRAG_AND_DROP
316 bool ScintillaWX::SetIdle(bool on
) {
317 if (idler
.state
!= on
) {
318 // connect or disconnect the EVT_IDLE handler
320 stc
->Connect(wxID_ANY
, wxEVT_IDLE
, wxIdleEventHandler(wxStyledTextCtrl::OnIdle
));
322 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
, wxIdleEventHandler(wxStyledTextCtrl::OnIdle
));
329 void ScintillaWX::SetTicking(bool on
) {
330 wxSTCTimer
* steTimer
;
331 if (timer
.ticking
!= on
) {
334 steTimer
= new wxSTCTimer(this);
335 steTimer
->Start(timer
.tickSize
);
336 timer
.tickerID
= steTimer
;
338 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
344 timer
.ticksToWait
= caret
.period
;
348 void ScintillaWX::SetMouseCapture(bool on
) {
349 if (mouseDownCaptures
) {
350 if (on
&& !capturedMouse
)
352 else if (!on
&& capturedMouse
&& stc
->HasCapture())
359 bool ScintillaWX::HaveMouseCapture() {
360 return capturedMouse
;
364 void ScintillaWX::ScrollText(int linesToMove
) {
365 int dy
= vs
.lineHeight
* (linesToMove
);
366 stc
->ScrollWindow(0, dy
);
369 void ScintillaWX::SetVerticalScrollPos() {
370 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
371 stc
->SetScrollPos(wxVERTICAL
, topLine
);
373 else { // otherwise use the one that's been given to us
374 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
378 void ScintillaWX::SetHorizontalScrollPos() {
379 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
380 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
382 else { // otherwise use the one that's been given to us
383 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
388 const int H_SCROLL_STEP
= 20;
390 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
391 bool modified
= false;
394 if (!verticalScrollBarVisible
)
397 // Check the vertical scrollbar
398 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
399 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
400 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
401 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
402 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
403 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
407 else { // otherwise use the one that's been given to us
408 int sbMax
= stc
->m_vScrollBar
->GetRange();
409 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
410 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
411 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
412 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
418 // Check the horizontal scrollbar
419 PRectangle rcText
= GetTextRectangle();
420 int horizEnd
= scrollWidth
;
423 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
425 int pageWidth
= rcText
.Width();
427 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
428 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
429 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
430 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
431 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
432 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
434 if (scrollWidth
< pageWidth
) {
435 HorizontalScrollTo(0);
439 else { // otherwise use the one that's been given to us
440 int sbMax
= stc
->m_hScrollBar
->GetRange();
441 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
442 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
443 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
444 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
446 if (scrollWidth
< pageWidth
) {
447 HorizontalScrollTo(0);
456 void ScintillaWX::NotifyChange() {
461 void ScintillaWX::NotifyParent(SCNotification scn
) {
462 stc
->NotifyParent(&scn
);
466 // This method is overloaded from ScintillaBase in order to prevent the
467 // AutoComplete window from being destroyed when it gets the focus. There is
468 // a side effect that the AutoComp will also not be destroyed when switching
469 // to another window, but I think that is okay.
470 void ScintillaWX::CancelModes() {
472 AutoCompleteCancel();
474 Editor::CancelModes();
479 void ScintillaWX::Copy() {
482 CopySelectionRange(&st
);
488 void ScintillaWX::Paste() {
489 pdoc
->BeginUndoAction();
493 wxTextDataObject data
;
494 bool gotData
= false;
496 wxTheClipboard
->UsePrimarySelection(false);
497 if (wxTheClipboard
->Open()) {
498 gotData
= wxTheClipboard
->GetData(data
);
499 wxTheClipboard
->Close();
502 wxString text
= wxTextBuffer::Translate(data
.GetText(),
503 wxConvertEOLMode(pdoc
->eolMode
));
504 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
507 // free up the old character buffer in case the text is real big
508 data
.SetText(wxEmptyString
);
509 text
= wxEmptyString
;
511 int len
= strlen(buf
);
512 int caretMain
= sel
.MainCaret();
513 pdoc
->InsertString(caretMain
, buf
, len
);
514 SetEmptySelection(caretMain
+ len
);
516 #endif // wxUSE_DATAOBJ
518 pdoc
->EndUndoAction();
524 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
529 wxTheClipboard
->UsePrimarySelection(false);
530 if (wxTheClipboard
->Open()) {
531 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
532 wxTheClipboard
->SetData(new wxTextDataObject(text
));
533 wxTheClipboard
->Close();
537 #endif // wxUSE_CLIPBOARD
541 bool ScintillaWX::CanPaste() {
543 bool canPaste
= false;
546 if (Editor::CanPaste()) {
547 wxTheClipboard
->UsePrimarySelection(false);
548 didOpen
= !wxTheClipboard
->IsOpened();
550 wxTheClipboard
->Open();
552 if (wxTheClipboard
->IsOpened()) {
553 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
555 wxTheClipboard
->Close();
561 #endif // wxUSE_CLIPBOARD
564 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
565 if (! ct
.wCallTip
.Created() ) {
566 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
567 ct
.wDraw
= ct
.wCallTip
;
572 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
574 ((wxMenu
*)popup
.GetID())->AppendSeparator();
576 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
579 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
583 // This is called by the Editor base class whenever something is selected.
584 // For wxGTK we can put this text in the primary selection and then other apps
585 // can paste with the middle button.
586 void ScintillaWX::ClaimSelection() {
588 // Put the selected text in the PRIMARY selection
591 CopySelectionRange(&st
);
592 wxTheClipboard
->UsePrimarySelection(true);
593 if (wxTheClipboard
->Open()) {
594 wxString text
= stc2wx(st
.s
, st
.len
);
595 wxTheClipboard
->SetData(new wxTextDataObject(text
));
596 wxTheClipboard
->Close();
598 wxTheClipboard
->UsePrimarySelection(false);
604 void ScintillaWX::UpdateSystemCaret() {
607 if (HasCaretSizeChanged()) {
608 DestroySystemCaret();
611 Point pos
= PointMainCaret();
612 ::SetCaretPos(pos
.x
, pos
.y
);
618 bool ScintillaWX::HasCaretSizeChanged() {
620 if ( (vs
.caretWidth
&& (sysCaretWidth
!= vs
.caretWidth
))
621 || (vs
.lineHeight
&& (sysCaretHeight
!= vs
.lineHeight
)) ) {
628 bool ScintillaWX::CreateSystemCaret() {
630 sysCaretWidth
= vs
.caretWidth
;
631 if (0 == sysCaretWidth
) {
634 sysCaretHeight
= vs
.lineHeight
;
635 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
636 char *bits
= new char[bitmapSize
];
637 memset(bits
, 0, bitmapSize
);
638 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
639 1, reinterpret_cast<BYTE
*>(bits
));
641 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
642 sysCaretWidth
, sysCaretHeight
);
643 ::ShowCaret(GetHwndOf(stc
));
650 bool ScintillaWX::DestroySystemCaret() {
652 ::HideCaret(GetHwndOf(stc
));
653 BOOL retval
= ::DestroyCaret();
654 if (sysCaretBitmap
) {
655 ::DeleteObject(sysCaretBitmap
);
665 //----------------------------------------------------------------------
668 sptr_t
ScintillaWX::DefWndProc(unsigned int /*iMessage*/, uptr_t
/*wParam*/, sptr_t
/*lParam*/) {
672 sptr_t
ScintillaWX::WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) {
674 #if 0 // TODO: check this
676 case SCI_CALLTIPSHOW
: {
677 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
678 // because of the little tweak that needs done below for wxGTK.
679 // When updating new versions double check that this is still
680 // needed, and that any new code there is copied here too.
681 Point pt
= LocationFromPosition(wParam
);
682 char* defn
= reinterpret_cast<char *>(lParam
);
683 AutoCompleteCancel();
684 pt
.y
+= vs
.lineHeight
;
685 int ctStyle
= ct
.UseStyleCallTip() ? STYLE_CALLTIP
: STYLE_DEFAULT
;
686 if (ct
.UseStyleCallTip())
688 ct
.SetForeBack(vs
.styles
[STYLE_CALLTIP
].fore
, vs
.styles
[STYLE_CALLTIP
].back
);
690 int caretMain
= sel
.MainCaret();
691 PRectangle rc
= ct
.CallTipStart(caretMain
, pt
,
693 vs
.styles
[ctStyle
].fontName
,
694 vs
.styles
[ctStyle
].sizeZoomed
,
696 vs
.styles
[ctStyle
].characterSet
,
698 // If the call-tip window would be out of the client
699 // space, adjust so it displays above the text.
700 PRectangle rcClient
= GetClientRectangle();
701 if (rc
.bottom
> rcClient
.bottom
) {
703 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
705 int offset
= vs
.lineHeight
+ rc
.Height();
710 // Now display the window.
711 CreateCallTipWindow(rc
);
712 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
719 case SCI_LOADLEXERLIBRARY
:
720 LexerManager::GetInstance()->Load((const char*)lParam
);
725 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
732 //----------------------------------------------------------------------
735 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
737 paintState
= painting
;
738 AutoSurface
surfaceWindow(dc
, this);
740 rcPaint
= PRectangleFromwxRect(rect
);
741 PRectangle rcClient
= GetClientRectangle();
742 paintingAllText
= rcPaint
.Contains(rcClient
);
744 ClipChildren(*dc
, rcPaint
);
745 Paint(surfaceWindow
, rcPaint
);
746 surfaceWindow
->Release();
749 if (paintState
== paintAbandoned
) {
750 // Painting area was insufficient to cover new styling or brace
751 // highlight positions. So trigger a new paint event that will
752 // repaint the whole window.
755 #if defined(__WXOSX__)
756 // On Mac we also need to finish the current paint to make sure that
757 // everything is on the screen that needs to be there between now and
758 // when the next paint event arrives.
762 paintState
= notPainting
;
766 // Force the whole window to be repainted
767 void ScintillaWX::FullPaint() {
773 void ScintillaWX::FullPaintDC(wxDC
* dc
) {
774 paintState
= painting
;
775 rcPaint
= GetClientRectangle();
776 paintingAllText
= true;
777 AutoSurface
surfaceWindow(dc
, this);
779 Paint(surfaceWindow
, rcPaint
);
780 surfaceWindow
->Release();
782 paintState
= notPainting
;
787 void ScintillaWX::DoHScroll(int type
, int pos
) {
789 PRectangle rcText
= GetTextRectangle();
790 int pageWidth
= rcText
.Width() * 2 / 3;
791 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
792 xPos
-= H_SCROLL_STEP
;
793 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
794 xPos
+= H_SCROLL_STEP
;
795 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
797 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
799 if (xPos
> scrollWidth
- rcText
.Width()) {
800 xPos
= scrollWidth
- rcText
.Width();
803 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
805 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
807 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
810 HorizontalScrollTo(xPos
);
813 void ScintillaWX::DoVScroll(int type
, int pos
) {
814 int topLineNew
= topLine
;
815 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
817 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
819 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
820 topLineNew
-= LinesToScroll();
821 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
822 topLineNew
+= LinesToScroll();
823 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
825 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
826 topLineNew
= MaxScrollPos();
827 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
830 ScrollTo(topLineNew
);
833 void ScintillaWX::DoMouseWheel(wxMouseWheelAxis axis
, int rotation
, int delta
,
834 int linesPerAction
, int columnsPerAction
,
835 bool ctrlDown
, bool isPageScroll
) {
836 int topLineNew
= topLine
;
841 if (axis
== wxMOUSE_WHEEL_HORIZONTAL
) {
842 wheelHRotation
+= rotation
* (columnsPerAction
* vs
.spaceWidth
);
843 pixels
= wheelHRotation
/ delta
;
844 wheelHRotation
-= pixels
* delta
;
847 PRectangle rcText
= GetTextRectangle();
848 if (xPos
> scrollWidth
- rcText
.Width()) {
849 xPos
= scrollWidth
- rcText
.Width();
851 HorizontalScrollTo(xPos
);
854 else if (ctrlDown
) { // Zoom the fonts if Ctrl key down
856 KeyCommand(SCI_ZOOMIN
);
859 KeyCommand(SCI_ZOOMOUT
);
862 else { // otherwise just scroll the window
865 wheelVRotation
+= rotation
;
866 lines
= wheelVRotation
/ delta
;
867 wheelVRotation
-= lines
* delta
;
870 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
872 lines
*= linesPerAction
;
874 ScrollTo(topLineNew
);
880 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
884 void ScintillaWX::DoLoseFocus(){
886 SetFocusState(false);
888 DestroySystemCaret();
891 void ScintillaWX::DoGainFocus(){
895 DestroySystemCaret();
899 void ScintillaWX::DoSysColourChange() {
900 InvalidateStyleData();
903 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
904 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
907 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
908 ButtonUp(pt
, curTime
, ctrl
);
911 void ScintillaWX::DoLeftButtonMove(Point pt
) {
916 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
917 // Set the current position to the mouse click point and
918 // then paste in the PRIMARY selection, if any. wxGTK only.
919 int newPos
= PositionFromLocation(pt
);
920 MovePositionTo(newPos
, Selection::noSel
, true);
922 pdoc
->BeginUndoAction();
923 wxTextDataObject data
;
924 bool gotData
= false;
925 wxTheClipboard
->UsePrimarySelection(true);
926 if (wxTheClipboard
->Open()) {
927 gotData
= wxTheClipboard
->GetData(data
);
928 wxTheClipboard
->Close();
930 wxTheClipboard
->UsePrimarySelection(false);
932 wxString text
= wxTextBuffer::Translate(data
.GetText(),
933 wxConvertEOLMode(pdoc
->eolMode
));
934 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
935 int len
= strlen(buf
);
936 int caretMain
= sel
.MainCaret();
937 pdoc
->InsertString(caretMain
, buf
, len
);
938 SetEmptySelection(caretMain
+ len
);
940 pdoc
->EndUndoAction();
944 ShowCaretAtCurrentPosition();
945 EnsureCaretVisible();
948 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
953 void ScintillaWX::DoAddChar(int key
) {
956 wszChars
[0] = (wxChar
)key
;
958 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
959 AddCharUTF((char*)buf
.data(), strlen(buf
));
966 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
968 int key
= evt
.GetKeyCode();
969 if (key
== WXK_NONE
) {
970 // This is a Unicode character not representable in Latin-1 or some key
971 // without key code at all (e.g. dead key or VK_PROCESSKEY under MSW).
977 bool shift
= evt
.ShiftDown(),
978 ctrl
= evt
.ControlDown(),
981 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
985 case WXK_DOWN
: key
= SCK_DOWN
; break;
986 case WXK_UP
: key
= SCK_UP
; break;
987 case WXK_LEFT
: key
= SCK_LEFT
; break;
988 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
989 case WXK_HOME
: key
= SCK_HOME
; break;
990 case WXK_END
: key
= SCK_END
; break;
991 case WXK_PAGEUP
: key
= SCK_PRIOR
; break;
992 case WXK_PAGEDOWN
: key
= SCK_NEXT
; break;
993 case WXK_NUMPAD_DOWN
: key
= SCK_DOWN
; break;
994 case WXK_NUMPAD_UP
: key
= SCK_UP
; break;
995 case WXK_NUMPAD_LEFT
: key
= SCK_LEFT
; break;
996 case WXK_NUMPAD_RIGHT
: key
= SCK_RIGHT
; break;
997 case WXK_NUMPAD_HOME
: key
= SCK_HOME
; break;
998 case WXK_NUMPAD_END
: key
= SCK_END
; break;
999 case WXK_NUMPAD_PAGEUP
: key
= SCK_PRIOR
; break;
1000 case WXK_NUMPAD_PAGEDOWN
: key
= SCK_NEXT
; break;
1001 case WXK_NUMPAD_DELETE
: key
= SCK_DELETE
; break;
1002 case WXK_NUMPAD_INSERT
: key
= SCK_INSERT
; break;
1003 case WXK_DELETE
: key
= SCK_DELETE
; break;
1004 case WXK_INSERT
: key
= SCK_INSERT
; break;
1005 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
1006 case WXK_BACK
: key
= SCK_BACK
; break;
1007 case WXK_TAB
: key
= SCK_TAB
; break;
1008 case WXK_NUMPAD_ENTER
: // fall through
1009 case WXK_RETURN
: key
= SCK_RETURN
; break;
1010 case WXK_ADD
: // fall through
1011 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
1012 case WXK_SUBTRACT
: // fall through
1013 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
1014 case WXK_DIVIDE
: // fall through
1015 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
1016 case WXK_CONTROL
: key
= 0; break;
1017 case WXK_ALT
: key
= 0; break;
1018 case WXK_SHIFT
: key
= 0; break;
1019 case WXK_MENU
: key
= SCK_MENU
; break;
1023 if ( evt
.MetaDown() ) {
1024 // check for a few common Mac Meta-key combos and remap them to Ctrl
1031 case 'A': // Select All
1038 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
1047 void ScintillaWX::DoCommand(int ID
) {
1052 void ScintillaWX::DoContextMenu(Point pt
) {
1053 if (displayPopupMenu
)
1057 void ScintillaWX::DoOnListBox() {
1058 AutoCompleteCompleted();
1062 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
1070 //----------------------------------------------------------------------
1072 #if wxUSE_DRAG_AND_DROP
1073 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
1074 SetDragPosition(SelectionPosition(invalidPosition
));
1076 wxString text
= wxTextBuffer::Translate(data
,
1077 wxConvertEOLMode(pdoc
->eolMode
));
1079 // Send an event to allow the drag details to be changed
1080 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
1081 evt
.SetEventObject(stc
);
1082 evt
.SetDragResult(dragResult
);
1085 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1086 evt
.SetDragText(text
);
1087 stc
->GetEventHandler()->ProcessEvent(evt
);
1089 dragResult
= evt
.GetDragResult();
1090 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
1091 DropAt(SelectionPosition(evt
.GetPosition()),
1092 wx2stc(evt
.GetDragText()),
1093 dragResult
== wxDragMove
,
1094 false); // TODO: rectangular?
1101 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1107 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1108 SetDragPosition(SelectionPosition(PositionFromLocation(Point(x
, y
))));
1110 // Send an event to allow the drag result to be changed
1111 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1112 evt
.SetEventObject(stc
);
1113 evt
.SetDragResult(def
);
1116 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1117 stc
->GetEventHandler()->ProcessEvent(evt
);
1119 dragResult
= evt
.GetDragResult();
1124 void ScintillaWX::DoDragLeave() {
1125 SetDragPosition(SelectionPosition(invalidPosition
));
1127 #endif // wxUSE_DRAG_AND_DROP
1128 //----------------------------------------------------------------------
1130 void ScintillaWX::DoScrollToLine(int line
) {
1135 void ScintillaWX::DoScrollToColumn(int column
) {
1136 HorizontalScrollTo(column
* vs
.spaceWidth
);
1139 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1140 // will leave it here commented out for a while just in case...
1141 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1143 // wxRegion rgn(wxRectFromPRectangle(rect));
1144 // if (ac.Active()) {
1145 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1146 // rgn.Subtract(childRect);
1148 // if (ct.inCallTipMode) {
1149 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1150 // wxRect childRect = tip->GetRect();
1151 // #if wxUSE_POPUPWIN
1152 // childRect.SetPosition(tip->GetMyPosition());
1154 // rgn.Subtract(childRect);
1156 // dc.SetClippingRegion(rgn);
1160 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1161 vs
.extraFontFlag
= useAA
;
1162 InvalidateStyleRedraw();
1165 bool ScintillaWX::GetUseAntiAliasing() {
1166 return vs
.extraFontFlag
!= 0;
1169 //----------------------------------------------------------------------
1170 //----------------------------------------------------------------------