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
100 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
101 #include "wx/popupwin.h"
102 #define wxSTCCallTipBase wxPopupWindow
103 #define param2 wxBORDER_NONE // popup's 2nd param is flags
105 #include "wx/frame.h"
106 #define wxSTCCallTipBase wxFrame
107 #define param2 -1 // wxWindow's 2nd param is ID
110 #include "wx/dcbuffer.h"
112 class wxSTCCallTip
: public wxSTCCallTipBase
{
114 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
) :
115 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
116 wxSTCCallTipBase(parent
, wxBORDER_NONE
),
118 wxSTCCallTipBase(parent
, -1, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
,
120 | wxFRAME_FLOAT_ON_PARENT
127 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
132 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP && defined(__WXGTK__)
133 wxRect rect
= GetRect();
136 GetParent()->Refresh(false, &rect
);
140 bool AcceptsFocus() const { return false; }
142 void OnPaint(wxPaintEvent
& WXUNUSED(evt
))
144 wxBufferedPaintDC
dc(this);
145 Surface
* surfaceWindow
= Surface::Allocate();
146 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
147 m_ct
->PaintCT(surfaceWindow
);
148 surfaceWindow
->Release();
149 delete surfaceWindow
;
152 void OnFocus(wxFocusEvent
& event
)
154 GetParent()->SetFocus();
158 void OnLeftDown(wxMouseEvent
& event
)
160 wxPoint pt
= event
.GetPosition();
163 m_swx
->CallTipClick();
166 virtual void DoSetSize(int x
, int y
,
167 int width
, int height
,
168 int sizeFlags
= wxSIZE_AUTO
)
170 // convert coords to screen coords since we're a top-level window
171 if (x
!= wxDefaultCoord
) {
173 GetParent()->ClientToScreen(&x
, NULL
);
175 if (y
!= wxDefaultCoord
) {
177 GetParent()->ClientToScreen(NULL
, &y
);
179 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
182 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
184 virtual bool Show( bool show
= true )
186 // Although we're a frame, we always want the parent to be active, so
187 // raise it whenever we get shown.
188 bool rv
= wxSTCCallTipBase::Show(show
);
191 wxTopLevelWindow
*frame
= wxDynamicCast(
192 wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
200 wxPoint
GetMyPosition()
202 return wxPoint(m_cx
, m_cy
);
209 DECLARE_EVENT_TABLE()
212 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
213 EVT_PAINT(wxSTCCallTip::OnPaint
)
214 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
215 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
219 //----------------------------------------------------------------------
222 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
226 switch (scintillaMode
) {
228 type
= wxTextFileType_Dos
;
232 type
= wxTextFileType_Mac
;
236 type
= wxTextFileType_Unix
;
240 type
= wxTextBuffer::typeDefault
;
245 #endif // wxUSE_DATAOBJ
248 //----------------------------------------------------------------------
249 // Constructor/Destructor
252 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
253 capturedMouse
= false;
264 #if wxUSE_DRAG_AND_DROP
265 startDragTimer
= new wxStartDragTimer(this);
266 #endif // wxUSE_DRAG_AND_DROP
270 ScintillaWX::~ScintillaWX() {
271 #if wxUSE_DRAG_AND_DROP
272 delete startDragTimer
;
273 #endif // wxUSE_DRAG_AND_DROP
277 //----------------------------------------------------------------------
278 // base class virtuals
281 void ScintillaWX::Initialise() {
282 //ScintillaBase::Initialise();
283 #if wxUSE_DRAG_AND_DROP
284 dropTarget
= new wxSTCDropTarget
;
285 dropTarget
->SetScintilla(this);
286 stc
->SetDropTarget(dropTarget
);
287 #endif // wxUSE_DRAG_AND_DROP
289 vs
.extraFontFlag
= false; // UseAntiAliasing
291 vs
.extraFontFlag
= true; // UseAntiAliasing
296 void ScintillaWX::Finalise() {
297 ScintillaBase::Finalise();
300 DestroySystemCaret();
304 void ScintillaWX::StartDrag() {
305 #if wxUSE_DRAG_AND_DROP
306 // We defer the starting of the DnD, otherwise the LeftUp of a normal
307 // click could be lost and the STC will think it is doing a DnD when the
308 // user just wanted a normal click.
309 startDragTimer
->Start(200, true);
310 #endif // wxUSE_DRAG_AND_DROP
313 void ScintillaWX::DoStartDrag() {
314 #if wxUSE_DRAG_AND_DROP
315 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
317 // Send an event to allow the drag text to be changed
318 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
319 evt
.SetEventObject(stc
);
320 evt
.SetDragText(dragText
);
321 evt
.SetDragAllowMove(true);
322 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
323 stc
->GetSelectionEnd()));
324 stc
->GetEventHandler()->ProcessEvent(evt
);
325 dragText
= evt
.GetDragText();
327 if (dragText
.length()) {
328 wxDropSource
source(stc
);
329 wxTextDataObject
data(dragText
);
332 source
.SetData(data
);
333 dropWentOutside
= true;
334 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
335 if (result
== wxDragMove
&& dropWentOutside
)
338 SetDragPosition(invalidPosition
);
340 #endif // wxUSE_DRAG_AND_DROP
344 bool ScintillaWX::SetIdle(bool on
) {
345 if (idler
.state
!= on
) {
346 // connect or disconnect the EVT_IDLE handler
348 stc
->Connect(wxID_ANY
, wxEVT_IDLE
,
349 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
351 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
,
352 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
359 void ScintillaWX::SetTicking(bool on
) {
360 wxSTCTimer
* steTimer
;
361 if (timer
.ticking
!= on
) {
364 steTimer
= new wxSTCTimer(this);
365 steTimer
->Start(timer
.tickSize
);
366 timer
.tickerID
= steTimer
;
368 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
374 timer
.ticksToWait
= caret
.period
;
378 void ScintillaWX::SetMouseCapture(bool on
) {
379 if (mouseDownCaptures
) {
380 if (on
&& !capturedMouse
)
382 else if (!on
&& capturedMouse
&& stc
->HasCapture())
389 bool ScintillaWX::HaveMouseCapture() {
390 return capturedMouse
;
394 void ScintillaWX::ScrollText(int linesToMove
) {
395 int dy
= vs
.lineHeight
* (linesToMove
);
396 stc
->ScrollWindow(0, dy
);
400 void ScintillaWX::SetVerticalScrollPos() {
401 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
402 stc
->SetScrollPos(wxVERTICAL
, topLine
);
404 else { // otherwise use the one that's been given to us
405 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
409 void ScintillaWX::SetHorizontalScrollPos() {
410 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
411 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
413 else { // otherwise use the one that's been given to us
414 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
419 const int H_SCROLL_STEP
= 20;
421 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
422 bool modified
= false;
425 if (!verticalScrollBarVisible
)
428 // Check the vertical scrollbar
429 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
430 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
431 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
432 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
433 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
434 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
438 else { // otherwise use the one that's been given to us
439 int sbMax
= stc
->m_vScrollBar
->GetRange();
440 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
441 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
442 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
443 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
449 // Check the horizontal scrollbar
450 PRectangle rcText
= GetTextRectangle();
451 int horizEnd
= scrollWidth
;
454 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
456 int pageWidth
= rcText
.Width();
458 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
459 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
460 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
461 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
462 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
463 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
465 if (scrollWidth
< pageWidth
) {
466 HorizontalScrollTo(0);
470 else { // otherwise use the one that's been given to us
471 int sbMax
= stc
->m_hScrollBar
->GetRange();
472 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
473 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
474 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
475 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
477 if (scrollWidth
< pageWidth
) {
478 HorizontalScrollTo(0);
487 void ScintillaWX::NotifyChange() {
492 void ScintillaWX::NotifyParent(SCNotification scn
) {
493 stc
->NotifyParent(&scn
);
497 // This method is overloaded from ScintillaBase in order to prevent the
498 // AutoComplete window from being destroyed when it gets the focus. There is
499 // a side effect that the AutoComp will also not be destroyed when switching
500 // to another window, but I think that is okay.
501 void ScintillaWX::CancelModes() {
503 AutoCompleteCancel();
505 Editor::CancelModes();
510 void ScintillaWX::Copy() {
511 if (currentPos
!= anchor
) {
513 CopySelectionRange(&st
);
519 void ScintillaWX::Paste() {
520 pdoc
->BeginUndoAction();
524 wxTextDataObject data
;
525 bool gotData
= false;
527 wxTheClipboard
->UsePrimarySelection(false);
528 if (wxTheClipboard
->Open()) {
529 gotData
= wxTheClipboard
->GetData(data
);
530 wxTheClipboard
->Close();
533 wxString text
= wxTextBuffer::Translate(data
.GetText(),
534 wxConvertEOLMode(pdoc
->eolMode
));
535 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
538 // free up the old character buffer in case the text is real big
539 data
.SetText(wxEmptyString
);
540 text
= wxEmptyString
;
542 int len
= strlen(buf
);
543 pdoc
->InsertString(currentPos
, buf
, len
);
544 SetEmptySelection(currentPos
+ len
);
546 #endif // wxUSE_DATAOBJ
548 pdoc
->EndUndoAction();
554 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
556 wxTheClipboard
->UsePrimarySelection(false);
557 if (wxTheClipboard
->Open()) {
558 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
559 wxTheClipboard
->SetData(new wxTextDataObject(text
));
560 wxTheClipboard
->Close();
564 #endif // wxUSE_CLIPBOARD
568 bool ScintillaWX::CanPaste() {
570 bool canPaste
= false;
573 if (Editor::CanPaste()) {
574 wxTheClipboard
->UsePrimarySelection(false);
575 didOpen
= !wxTheClipboard
->IsOpened();
577 wxTheClipboard
->Open();
579 if (wxTheClipboard
->IsOpened()) {
580 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
582 wxTheClipboard
->Close();
588 #endif // wxUSE_CLIPBOARD
591 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
592 if (! ct
.wCallTip
.Created() ) {
593 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
594 ct
.wDraw
= ct
.wCallTip
;
599 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
601 ((wxMenu
*)popup
.GetID())->AppendSeparator();
603 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
606 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
610 // This is called by the Editor base class whenever something is selected.
611 // For wxGTK we can put this text in the primary selection and then other apps
612 // can paste with the middle button.
613 void ScintillaWX::ClaimSelection() {
615 // Put the selected text in the PRIMARY selection
616 if (currentPos
!= anchor
) {
618 CopySelectionRange(&st
);
619 wxTheClipboard
->UsePrimarySelection(true);
620 if (wxTheClipboard
->Open()) {
621 wxString text
= stc2wx(st
.s
, st
.len
);
622 wxTheClipboard
->SetData(new wxTextDataObject(text
));
623 wxTheClipboard
->Close();
625 wxTheClipboard
->UsePrimarySelection(false);
631 void ScintillaWX::UpdateSystemCaret() {
634 if (HasCaretSizeChanged()) {
635 DestroySystemCaret();
638 Point pos
= LocationFromPosition(currentPos
);
639 ::SetCaretPos(pos
.x
, pos
.y
);
645 bool ScintillaWX::HasCaretSizeChanged() {
647 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
648 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
655 bool ScintillaWX::CreateSystemCaret() {
657 sysCaretWidth
= vs
.caretWidth
;
658 if (0 == sysCaretWidth
) {
661 sysCaretHeight
= vs
.lineHeight
;
662 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
663 char *bits
= new char[bitmapSize
];
664 memset(bits
, 0, bitmapSize
);
665 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
666 1, reinterpret_cast<BYTE
*>(bits
));
668 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
669 sysCaretWidth
, sysCaretHeight
);
670 ::ShowCaret(GetHwndOf(stc
));
677 bool ScintillaWX::DestroySystemCaret() {
679 ::HideCaret(GetHwndOf(stc
));
680 BOOL retval
= ::DestroyCaret();
681 if (sysCaretBitmap
) {
682 ::DeleteObject(sysCaretBitmap
);
692 //----------------------------------------------------------------------
695 sptr_t
ScintillaWX::DefWndProc(unsigned int /*iMessage*/, uptr_t
/*wParam*/, sptr_t
/*lParam*/) {
699 sptr_t
ScintillaWX::WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) {
701 case SCI_CALLTIPSHOW
: {
702 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
703 // because of the little tweak that needs done below for wxGTK.
704 // When updating new versions double check that this is still
705 // needed, and that any new code there is copied here too.
706 Point pt
= LocationFromPosition(wParam
);
707 char* defn
= reinterpret_cast<char *>(lParam
);
708 AutoCompleteCancel();
709 pt
.y
+= vs
.lineHeight
;
710 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
712 vs
.styles
[STYLE_DEFAULT
].fontName
,
713 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
715 vs
.styles
[STYLE_DEFAULT
].characterSet
,
717 // If the call-tip window would be out of the client
718 // space, adjust so it displays above the text.
719 PRectangle rcClient
= GetClientRectangle();
720 if (rc
.bottom
> rcClient
.bottom
) {
722 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
724 int offset
= vs
.lineHeight
+ rc
.Height();
729 // Now display the window.
730 CreateCallTipWindow(rc
);
731 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
737 case SCI_LOADLEXERLIBRARY
:
738 LexerManager::GetInstance()->Load((const char*)lParam
);
743 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
750 //----------------------------------------------------------------------
753 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
755 paintState
= painting
;
756 Surface
* surfaceWindow
= Surface::Allocate();
757 surfaceWindow
->Init(dc
, wMain
.GetID());
758 rcPaint
= PRectangleFromwxRect(rect
);
759 PRectangle rcClient
= GetClientRectangle();
760 paintingAllText
= rcPaint
.Contains(rcClient
);
762 ClipChildren(*dc
, rcPaint
);
763 Paint(surfaceWindow
, rcPaint
);
765 delete surfaceWindow
;
766 if (paintState
== paintAbandoned
) {
767 // Painting area was insufficient to cover new styling or brace
768 // highlight positions
771 paintState
= notPainting
;
775 void ScintillaWX::DoHScroll(int type
, int pos
) {
777 PRectangle rcText
= GetTextRectangle();
778 int pageWidth
= rcText
.Width() * 2 / 3;
779 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
780 xPos
-= H_SCROLL_STEP
;
781 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
782 xPos
+= H_SCROLL_STEP
;
783 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
785 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
787 if (xPos
> scrollWidth
- rcText
.Width()) {
788 xPos
= scrollWidth
- rcText
.Width();
791 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
793 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
795 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
798 HorizontalScrollTo(xPos
);
801 void ScintillaWX::DoVScroll(int type
, int pos
) {
802 int topLineNew
= topLine
;
803 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
805 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
807 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
808 topLineNew
-= LinesToScroll();
809 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
810 topLineNew
+= LinesToScroll();
811 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
813 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
814 topLineNew
= MaxScrollPos();
815 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
818 ScrollTo(topLineNew
);
821 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
822 int linesPerAction
, int ctrlDown
,
823 bool isPageScroll
) {
824 int topLineNew
= topLine
;
827 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
829 KeyCommand(SCI_ZOOMIN
);
832 KeyCommand(SCI_ZOOMOUT
);
835 else { // otherwise just scroll the window
838 wheelRotation
+= rotation
;
839 lines
= wheelRotation
/ delta
;
840 wheelRotation
-= lines
* delta
;
843 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
845 lines
*= linesPerAction
;
847 ScrollTo(topLineNew
);
853 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
857 void ScintillaWX::DoLoseFocus(){
859 SetFocusState(false);
861 DestroySystemCaret();
864 void ScintillaWX::DoGainFocus(){
868 DestroySystemCaret();
872 void ScintillaWX::DoSysColourChange() {
873 InvalidateStyleData();
876 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
877 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
880 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
881 ButtonUp(pt
, curTime
, ctrl
);
882 #if wxUSE_DRAG_AND_DROP
883 if (startDragTimer
->IsRunning()) {
884 startDragTimer
->Stop();
885 SetDragPosition(invalidPosition
);
886 SetEmptySelection(PositionFromLocation(pt
));
887 ShowCaretAtCurrentPosition();
889 #endif // wxUSE_DRAG_AND_DROP
892 void ScintillaWX::DoLeftButtonMove(Point pt
) {
897 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
898 // Set the current position to the mouse click point and
899 // then paste in the PRIMARY selection, if any. wxGTK only.
900 int newPos
= PositionFromLocation(pt
);
901 MovePositionTo(newPos
, noSel
, true);
903 pdoc
->BeginUndoAction();
904 wxTextDataObject data
;
905 bool gotData
= false;
906 wxTheClipboard
->UsePrimarySelection(true);
907 if (wxTheClipboard
->Open()) {
908 gotData
= wxTheClipboard
->GetData(data
);
909 wxTheClipboard
->Close();
911 wxTheClipboard
->UsePrimarySelection(false);
913 wxString text
= wxTextBuffer::Translate(data
.GetText(),
914 wxConvertEOLMode(pdoc
->eolMode
));
915 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
916 int len
= strlen(buf
);
917 pdoc
->InsertString(currentPos
, buf
, len
);
918 SetEmptySelection(currentPos
+ len
);
920 pdoc
->EndUndoAction();
924 ShowCaretAtCurrentPosition();
925 EnsureCaretVisible();
928 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
933 void ScintillaWX::DoAddChar(int key
) {
936 wszChars
[0] = (wxChar
)key
;
938 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
939 AddCharUTF((char*)buf
.data(), strlen(buf
));
946 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
948 int key
= evt
.GetKeyCode();
949 bool shift
= evt
.ShiftDown(),
950 ctrl
= evt
.ControlDown(),
953 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
957 case WXK_DOWN
: key
= SCK_DOWN
; break;
958 case WXK_UP
: key
= SCK_UP
; break;
959 case WXK_LEFT
: key
= SCK_LEFT
; break;
960 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
961 case WXK_HOME
: key
= SCK_HOME
; break;
962 case WXK_END
: key
= SCK_END
; break;
963 case WXK_PAGEUP
: key
= SCK_PRIOR
; break;
964 case WXK_PAGEDOWN
: key
= SCK_NEXT
; break;
965 case WXK_NUMPAD_DOWN
: key
= SCK_DOWN
; break;
966 case WXK_NUMPAD_UP
: key
= SCK_UP
; break;
967 case WXK_NUMPAD_LEFT
: key
= SCK_LEFT
; break;
968 case WXK_NUMPAD_RIGHT
: key
= SCK_RIGHT
; break;
969 case WXK_NUMPAD_HOME
: key
= SCK_HOME
; break;
970 case WXK_NUMPAD_END
: key
= SCK_END
; break;
971 case WXK_NUMPAD_PAGEUP
: key
= SCK_PRIOR
; break;
972 case WXK_NUMPAD_PAGEDOWN
: key
= SCK_NEXT
; break;
973 case WXK_NUMPAD_DELETE
: key
= SCK_DELETE
; break;
974 case WXK_NUMPAD_INSERT
: key
= SCK_INSERT
; break;
975 case WXK_DELETE
: key
= SCK_DELETE
; break;
976 case WXK_INSERT
: key
= SCK_INSERT
; break;
977 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
978 case WXK_BACK
: key
= SCK_BACK
; break;
979 case WXK_TAB
: key
= SCK_TAB
; break;
980 case WXK_NUMPAD_ENTER
: // fall through
981 case WXK_RETURN
: key
= SCK_RETURN
; break;
982 case WXK_ADD
: // fall through
983 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
984 case WXK_SUBTRACT
: // fall through
985 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
986 case WXK_DIVIDE
: // fall through
987 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
988 case WXK_CONTROL
: key
= 0; break;
989 case WXK_ALT
: key
= 0; break;
990 case WXK_SHIFT
: key
= 0; break;
991 case WXK_MENU
: key
= 0; break;
995 if ( evt
.MetaDown() ) {
996 // check for a few common Mac Meta-key combos and remap them to Ctrl
1003 case 'A': // Select All
1010 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
1019 void ScintillaWX::DoCommand(int ID
) {
1024 void ScintillaWX::DoContextMenu(Point pt
) {
1025 if (displayPopupMenu
)
1029 void ScintillaWX::DoOnListBox() {
1030 AutoCompleteCompleted();
1034 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
1042 //----------------------------------------------------------------------
1044 #if wxUSE_DRAG_AND_DROP
1045 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
1046 SetDragPosition(invalidPosition
);
1048 wxString text
= wxTextBuffer::Translate(data
,
1049 wxConvertEOLMode(pdoc
->eolMode
));
1051 // Send an event to allow the drag details to be changed
1052 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
1053 evt
.SetEventObject(stc
);
1054 evt
.SetDragResult(dragResult
);
1057 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1058 evt
.SetDragText(text
);
1059 stc
->GetEventHandler()->ProcessEvent(evt
);
1061 dragResult
= evt
.GetDragResult();
1062 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
1063 DropAt(evt
.GetPosition(),
1064 wx2stc(evt
.GetDragText()),
1065 dragResult
== wxDragMove
,
1066 false); // TODO: rectangular?
1073 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1079 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1080 SetDragPosition(PositionFromLocation(Point(x
, y
)));
1082 // Send an event to allow the drag result to be changed
1083 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1084 evt
.SetEventObject(stc
);
1085 evt
.SetDragResult(def
);
1088 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1089 stc
->GetEventHandler()->ProcessEvent(evt
);
1091 dragResult
= evt
.GetDragResult();
1096 void ScintillaWX::DoDragLeave() {
1097 SetDragPosition(invalidPosition
);
1099 #endif // wxUSE_DRAG_AND_DROP
1100 //----------------------------------------------------------------------
1102 // Force the whole window to be repainted
1103 void ScintillaWX::FullPaint() {
1105 stc
->Refresh(false);
1111 void ScintillaWX::DoScrollToLine(int line
) {
1116 void ScintillaWX::DoScrollToColumn(int column
) {
1117 HorizontalScrollTo(column
* vs
.spaceWidth
);
1120 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1121 // will leave it here commented out for a while just in case...
1122 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1124 // wxRegion rgn(wxRectFromPRectangle(rect));
1125 // if (ac.Active()) {
1126 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1127 // rgn.Subtract(childRect);
1129 // if (ct.inCallTipMode) {
1130 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1131 // wxRect childRect = tip->GetRect();
1132 // #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
1133 // childRect.SetPosition(tip->GetMyPosition());
1135 // rgn.Subtract(childRect);
1137 // dc.SetClippingRegion(rgn);
1141 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1142 vs
.extraFontFlag
= useAA
;
1143 InvalidateStyleRedraw();
1146 bool ScintillaWX::GetUseAntiAliasing() {
1147 return vs
.extraFontFlag
;
1150 //----------------------------------------------------------------------
1151 //----------------------------------------------------------------------