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"
28 #include "wx/textbuf.h"
29 #include "wx/dataobj.h"
30 #include "wx/clipbrd.h"
33 #include "ScintillaWX.h"
34 #include "ExternalLexer.h"
35 #include "wx/stc/stc.h"
40 #include "wx/msw/private.h"
43 //----------------------------------------------------------------------
46 class wxSTCTimer
: public wxTimer
{
48 wxSTCTimer(ScintillaWX
* swx
) {
61 #if wxUSE_DRAG_AND_DROP
62 class wxStartDragTimer
: public wxTimer
{
64 wxStartDragTimer(ScintillaWX
* swx
) {
77 bool wxSTCDropTarget::OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) {
78 return swx
->DoDropText(x
, y
, data
);
81 wxDragResult
wxSTCDropTarget::OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
) {
82 return swx
->DoDragEnter(x
, y
, def
);
85 wxDragResult
wxSTCDropTarget::OnDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
86 return swx
->DoDragOver(x
, y
, def
);
89 void wxSTCDropTarget::OnLeave() {
92 #endif // wxUSE_DRAG_AND_DROP
95 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
96 #include <wx/popupwin.h>
97 #define wxSTCCallTipBase wxPopupWindow
98 #define param2 wxBORDER_NONE // popup's 2nd param is flags
100 #define wxSTCCallTipBase wxFrame
101 #define param2 -1 // wxWindow's 2nd param is ID
104 #include <wx/dcbuffer.h>
106 class wxSTCCallTip
: public wxSTCCallTipBase
{
108 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
) :
109 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
110 wxSTCCallTipBase(parent
, wxBORDER_NONE
),
112 wxSTCCallTipBase(parent
, -1, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
,
114 | wxFRAME_FLOAT_ON_PARENT
121 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
126 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP && defined(__WXGTK__)
127 wxRect rect
= GetRect();
130 GetParent()->Refresh(false, &rect
);
134 bool AcceptsFocus() const { return false; }
136 void OnPaint(wxPaintEvent
& WXUNUSED(evt
))
138 wxBufferedPaintDC
dc(this);
139 Surface
* surfaceWindow
= Surface::Allocate();
140 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
141 m_ct
->PaintCT(surfaceWindow
);
142 surfaceWindow
->Release();
143 delete surfaceWindow
;
146 void OnFocus(wxFocusEvent
& event
)
148 GetParent()->SetFocus();
152 void OnLeftDown(wxMouseEvent
& event
)
154 wxPoint pt
= event
.GetPosition();
157 m_swx
->CallTipClick();
160 virtual void DoSetSize(int x
, int y
,
161 int width
, int height
,
162 int sizeFlags
= wxSIZE_AUTO
)
164 // convert coords to screen coords since we're a top-level window
165 if (x
!= wxDefaultCoord
) {
167 GetParent()->ClientToScreen(&x
, NULL
);
169 if (y
!= wxDefaultCoord
) {
171 GetParent()->ClientToScreen(NULL
, &y
);
173 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
176 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
178 virtual bool Show( bool show
= true )
180 // Although we're a frame, we always want the parent to be active, so
181 // raise it whenever we get shown.
182 bool rv
= wxSTCCallTipBase::Show(show
);
185 wxTopLevelWindow
*frame
= wxDynamicCast(
186 wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
194 wxPoint
GetMyPosition()
196 return wxPoint(m_cx
, m_cy
);
203 DECLARE_EVENT_TABLE()
206 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
207 EVT_PAINT(wxSTCCallTip::OnPaint
)
208 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
209 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
213 //----------------------------------------------------------------------
216 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
220 switch (scintillaMode
) {
222 type
= wxTextFileType_Dos
;
226 type
= wxTextFileType_Mac
;
230 type
= wxTextFileType_Unix
;
234 type
= wxTextBuffer::typeDefault
;
239 #endif // wxUSE_DATAOBJ
242 //----------------------------------------------------------------------
243 // Constructor/Destructor
246 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
247 capturedMouse
= false;
258 #if wxUSE_DRAG_AND_DROP
259 startDragTimer
= new wxStartDragTimer(this);
260 #endif // wxUSE_DRAG_AND_DROP
264 ScintillaWX::~ScintillaWX() {
265 #if wxUSE_DRAG_AND_DROP
266 delete startDragTimer
;
267 #endif // wxUSE_DRAG_AND_DROP
271 //----------------------------------------------------------------------
272 // base class virtuals
275 void ScintillaWX::Initialise() {
276 //ScintillaBase::Initialise();
277 #if wxUSE_DRAG_AND_DROP
278 dropTarget
= new wxSTCDropTarget
;
279 dropTarget
->SetScintilla(this);
280 stc
->SetDropTarget(dropTarget
);
281 #endif // wxUSE_DRAG_AND_DROP
283 vs
.extraFontFlag
= false; // UseAntiAliasing
285 vs
.extraFontFlag
= true; // UseAntiAliasing
290 void ScintillaWX::Finalise() {
291 ScintillaBase::Finalise();
294 DestroySystemCaret();
298 void ScintillaWX::StartDrag() {
299 #if wxUSE_DRAG_AND_DROP
300 // We defer the starting of the DnD, otherwise the LeftUp of a normal
301 // click could be lost and the STC will think it is doing a DnD when the
302 // user just wanted a normal click.
303 startDragTimer
->Start(200, true);
304 #endif // wxUSE_DRAG_AND_DROP
307 void ScintillaWX::DoStartDrag() {
308 #if wxUSE_DRAG_AND_DROP
309 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
311 // Send an event to allow the drag text to be changed
312 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
313 evt
.SetEventObject(stc
);
314 evt
.SetDragText(dragText
);
315 evt
.SetDragAllowMove(true);
316 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
317 stc
->GetSelectionEnd()));
318 stc
->GetEventHandler()->ProcessEvent(evt
);
319 dragText
= evt
.GetDragText();
321 if (dragText
.length()) {
322 wxDropSource
source(stc
);
323 wxTextDataObject
data(dragText
);
326 source
.SetData(data
);
327 dropWentOutside
= true;
328 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
329 if (result
== wxDragMove
&& dropWentOutside
)
332 SetDragPosition(invalidPosition
);
334 #endif // wxUSE_DRAG_AND_DROP
338 bool ScintillaWX::SetIdle(bool on
) {
339 if (idler
.state
!= on
) {
340 // connect or disconnect the EVT_IDLE handler
342 stc
->Connect(wxID_ANY
, wxEVT_IDLE
,
343 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
345 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
,
346 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
353 void ScintillaWX::SetTicking(bool on
) {
354 wxSTCTimer
* steTimer
;
355 if (timer
.ticking
!= on
) {
358 steTimer
= new wxSTCTimer(this);
359 steTimer
->Start(timer
.tickSize
);
360 timer
.tickerID
= steTimer
;
362 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
368 timer
.ticksToWait
= caret
.period
;
372 void ScintillaWX::SetMouseCapture(bool on
) {
373 if (mouseDownCaptures
) {
374 if (on
&& !capturedMouse
)
376 else if (!on
&& capturedMouse
&& stc
->HasCapture())
383 bool ScintillaWX::HaveMouseCapture() {
384 return capturedMouse
;
388 void ScintillaWX::ScrollText(int linesToMove
) {
389 int dy
= vs
.lineHeight
* (linesToMove
);
390 stc
->ScrollWindow(0, dy
);
394 void ScintillaWX::SetVerticalScrollPos() {
395 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
396 stc
->SetScrollPos(wxVERTICAL
, topLine
);
398 else { // otherwise use the one that's been given to us
399 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
403 void ScintillaWX::SetHorizontalScrollPos() {
404 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
405 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
407 else { // otherwise use the one that's been given to us
408 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
413 const int H_SCROLL_STEP
= 20;
415 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
416 bool modified
= false;
419 if (!verticalScrollBarVisible
)
422 // Check the vertical scrollbar
423 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
424 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
425 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
426 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
427 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
428 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
432 else { // otherwise use the one that's been given to us
433 int sbMax
= stc
->m_vScrollBar
->GetRange();
434 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
435 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
436 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
437 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
443 // Check the horizontal scrollbar
444 PRectangle rcText
= GetTextRectangle();
445 int horizEnd
= scrollWidth
;
448 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
450 int pageWidth
= rcText
.Width();
452 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
453 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
454 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
455 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
456 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
457 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
459 if (scrollWidth
< pageWidth
) {
460 HorizontalScrollTo(0);
464 else { // otherwise use the one that's been given to us
465 int sbMax
= stc
->m_hScrollBar
->GetRange();
466 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
467 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
468 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
469 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
471 if (scrollWidth
< pageWidth
) {
472 HorizontalScrollTo(0);
481 void ScintillaWX::NotifyChange() {
486 void ScintillaWX::NotifyParent(SCNotification scn
) {
487 stc
->NotifyParent(&scn
);
491 // This method is overloaded from ScintillaBase in order to prevent the
492 // AutoComplete window from being destroyed when it gets the focus. There is
493 // a side effect that the AutoComp will also not be destroyed when switching
494 // to another window, but I think that is okay.
495 void ScintillaWX::CancelModes() {
497 AutoCompleteCancel();
499 Editor::CancelModes();
504 void ScintillaWX::Copy() {
505 if (currentPos
!= anchor
) {
507 CopySelectionRange(&st
);
513 void ScintillaWX::Paste() {
514 pdoc
->BeginUndoAction();
518 wxTextDataObject data
;
519 bool gotData
= false;
521 wxTheClipboard
->UsePrimarySelection(false);
522 if (wxTheClipboard
->Open()) {
523 gotData
= wxTheClipboard
->GetData(data
);
524 wxTheClipboard
->Close();
527 wxString text
= wxTextBuffer::Translate(data
.GetText(),
528 wxConvertEOLMode(pdoc
->eolMode
));
529 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
532 // free up the old character buffer in case the text is real big
533 data
.SetText(wxEmptyString
);
534 text
= wxEmptyString
;
536 int len
= strlen(buf
);
537 pdoc
->InsertString(currentPos
, buf
, len
);
538 SetEmptySelection(currentPos
+ len
);
540 #endif // wxUSE_DATAOBJ
542 pdoc
->EndUndoAction();
548 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
550 wxTheClipboard
->UsePrimarySelection(false);
551 if (wxTheClipboard
->Open()) {
552 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
553 wxTheClipboard
->SetData(new wxTextDataObject(text
));
554 wxTheClipboard
->Close();
558 #endif // wxUSE_CLIPBOARD
562 bool ScintillaWX::CanPaste() {
564 bool canPaste
= false;
567 if (Editor::CanPaste()) {
568 wxTheClipboard
->UsePrimarySelection(false);
569 didOpen
= !wxTheClipboard
->IsOpened();
571 wxTheClipboard
->Open();
573 if (wxTheClipboard
->IsOpened()) {
574 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
576 wxTheClipboard
->Close();
582 #endif // wxUSE_CLIPBOARD
585 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
586 if (! ct
.wCallTip
.Created() ) {
587 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
588 ct
.wDraw
= ct
.wCallTip
;
593 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
595 ((wxMenu
*)popup
.GetID())->AppendSeparator();
597 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
600 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
604 // This is called by the Editor base class whenever something is selected.
605 // For wxGTK we can put this text in the primary selection and then other apps
606 // can paste with the middle button.
607 void ScintillaWX::ClaimSelection() {
609 // Put the selected text in the PRIMARY selection
610 if (currentPos
!= anchor
) {
612 CopySelectionRange(&st
);
613 wxTheClipboard
->UsePrimarySelection(true);
614 if (wxTheClipboard
->Open()) {
615 wxString text
= stc2wx(st
.s
, st
.len
);
616 wxTheClipboard
->SetData(new wxTextDataObject(text
));
617 wxTheClipboard
->Close();
619 wxTheClipboard
->UsePrimarySelection(false);
625 void ScintillaWX::UpdateSystemCaret() {
628 if (HasCaretSizeChanged()) {
629 DestroySystemCaret();
632 Point pos
= LocationFromPosition(currentPos
);
633 ::SetCaretPos(pos
.x
, pos
.y
);
639 bool ScintillaWX::HasCaretSizeChanged() {
641 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
642 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
649 bool ScintillaWX::CreateSystemCaret() {
651 sysCaretWidth
= vs
.caretWidth
;
652 if (0 == sysCaretWidth
) {
655 sysCaretHeight
= vs
.lineHeight
;
656 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
657 char *bits
= new char[bitmapSize
];
658 memset(bits
, 0, bitmapSize
);
659 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
660 1, reinterpret_cast<BYTE
*>(bits
));
662 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
663 sysCaretWidth
, sysCaretHeight
);
664 ::ShowCaret(GetHwndOf(stc
));
671 bool ScintillaWX::DestroySystemCaret() {
673 ::HideCaret(GetHwndOf(stc
));
674 BOOL retval
= ::DestroyCaret();
675 if (sysCaretBitmap
) {
676 ::DeleteObject(sysCaretBitmap
);
686 //----------------------------------------------------------------------
689 sptr_t
ScintillaWX::DefWndProc(unsigned int /*iMessage*/, uptr_t
/*wParam*/, sptr_t
/*lParam*/) {
693 sptr_t
ScintillaWX::WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) {
695 case SCI_CALLTIPSHOW
: {
696 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
697 // because of the little tweak that needs done below for wxGTK.
698 // When updating new versions double check that this is still
699 // needed, and that any new code there is copied here too.
700 Point pt
= LocationFromPosition(wParam
);
701 char* defn
= reinterpret_cast<char *>(lParam
);
702 AutoCompleteCancel();
703 pt
.y
+= vs
.lineHeight
;
704 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
706 vs
.styles
[STYLE_DEFAULT
].fontName
,
707 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
709 vs
.styles
[STYLE_DEFAULT
].characterSet
,
711 // If the call-tip window would be out of the client
712 // space, adjust so it displays above the text.
713 PRectangle rcClient
= GetClientRectangle();
714 if (rc
.bottom
> rcClient
.bottom
) {
716 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
718 int offset
= vs
.lineHeight
+ rc
.Height();
723 // Now display the window.
724 CreateCallTipWindow(rc
);
725 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
731 case SCI_LOADLEXERLIBRARY
:
732 LexerManager::GetInstance()->Load((const char*)lParam
);
737 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
744 //----------------------------------------------------------------------
747 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
749 paintState
= painting
;
750 Surface
* surfaceWindow
= Surface::Allocate();
751 surfaceWindow
->Init(dc
, wMain
.GetID());
752 rcPaint
= PRectangleFromwxRect(rect
);
753 PRectangle rcClient
= GetClientRectangle();
754 paintingAllText
= rcPaint
.Contains(rcClient
);
756 ClipChildren(*dc
, rcPaint
);
757 Paint(surfaceWindow
, rcPaint
);
759 delete surfaceWindow
;
760 if (paintState
== paintAbandoned
) {
761 // Painting area was insufficient to cover new styling or brace
762 // highlight positions
765 paintState
= notPainting
;
769 void ScintillaWX::DoHScroll(int type
, int pos
) {
771 PRectangle rcText
= GetTextRectangle();
772 int pageWidth
= rcText
.Width() * 2 / 3;
773 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
774 xPos
-= H_SCROLL_STEP
;
775 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
776 xPos
+= H_SCROLL_STEP
;
777 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
779 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
781 if (xPos
> scrollWidth
- rcText
.Width()) {
782 xPos
= scrollWidth
- rcText
.Width();
785 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
787 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
789 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
792 HorizontalScrollTo(xPos
);
795 void ScintillaWX::DoVScroll(int type
, int pos
) {
796 int topLineNew
= topLine
;
797 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
799 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
801 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
802 topLineNew
-= LinesToScroll();
803 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
804 topLineNew
+= LinesToScroll();
805 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
807 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
808 topLineNew
= MaxScrollPos();
809 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
812 ScrollTo(topLineNew
);
815 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
816 int linesPerAction
, int ctrlDown
,
817 bool isPageScroll
) {
818 int topLineNew
= topLine
;
821 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
823 KeyCommand(SCI_ZOOMIN
);
826 KeyCommand(SCI_ZOOMOUT
);
829 else { // otherwise just scroll the window
832 wheelRotation
+= rotation
;
833 lines
= wheelRotation
/ delta
;
834 wheelRotation
-= lines
* delta
;
837 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
839 lines
*= linesPerAction
;
841 ScrollTo(topLineNew
);
847 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
851 void ScintillaWX::DoLoseFocus(){
853 SetFocusState(false);
855 DestroySystemCaret();
858 void ScintillaWX::DoGainFocus(){
862 DestroySystemCaret();
866 void ScintillaWX::DoSysColourChange() {
867 InvalidateStyleData();
870 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
871 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
874 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
875 ButtonUp(pt
, curTime
, ctrl
);
876 #if wxUSE_DRAG_AND_DROP
877 if (startDragTimer
->IsRunning()) {
878 startDragTimer
->Stop();
879 SetDragPosition(invalidPosition
);
880 SetEmptySelection(PositionFromLocation(pt
));
881 ShowCaretAtCurrentPosition();
883 #endif // wxUSE_DRAG_AND_DROP
886 void ScintillaWX::DoLeftButtonMove(Point pt
) {
891 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
892 // Set the current position to the mouse click point and
893 // then paste in the PRIMARY selection, if any. wxGTK only.
894 int newPos
= PositionFromLocation(pt
);
895 MovePositionTo(newPos
, noSel
, true);
897 pdoc
->BeginUndoAction();
898 wxTextDataObject data
;
899 bool gotData
= false;
900 wxTheClipboard
->UsePrimarySelection(true);
901 if (wxTheClipboard
->Open()) {
902 gotData
= wxTheClipboard
->GetData(data
);
903 wxTheClipboard
->Close();
905 wxTheClipboard
->UsePrimarySelection(false);
907 wxString text
= wxTextBuffer::Translate(data
.GetText(),
908 wxConvertEOLMode(pdoc
->eolMode
));
909 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
910 int len
= strlen(buf
);
911 pdoc
->InsertString(currentPos
, buf
, len
);
912 SetEmptySelection(currentPos
+ len
);
914 pdoc
->EndUndoAction();
918 ShowCaretAtCurrentPosition();
919 EnsureCaretVisible();
922 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
927 void ScintillaWX::DoAddChar(int key
) {
930 wszChars
[0] = (wxChar
)key
;
932 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
933 AddCharUTF((char*)buf
.data(), strlen(buf
));
940 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
942 int key
= evt
.GetKeyCode();
943 bool shift
= evt
.ShiftDown(),
944 ctrl
= evt
.ControlDown(),
947 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
951 case WXK_DOWN
: key
= SCK_DOWN
; break;
952 case WXK_UP
: key
= SCK_UP
; break;
953 case WXK_LEFT
: key
= SCK_LEFT
; break;
954 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
955 case WXK_HOME
: key
= SCK_HOME
; break;
956 case WXK_END
: key
= SCK_END
; break;
957 case WXK_PAGEUP
: key
= SCK_PRIOR
; break;
958 case WXK_PAGEDOWN
: key
= SCK_NEXT
; break;
959 case WXK_NUMPAD_DOWN
: key
= SCK_DOWN
; break;
960 case WXK_NUMPAD_UP
: key
= SCK_UP
; break;
961 case WXK_NUMPAD_LEFT
: key
= SCK_LEFT
; break;
962 case WXK_NUMPAD_RIGHT
: key
= SCK_RIGHT
; break;
963 case WXK_NUMPAD_HOME
: key
= SCK_HOME
; break;
964 case WXK_NUMPAD_END
: key
= SCK_END
; break;
965 case WXK_NUMPAD_PAGEUP
: key
= SCK_PRIOR
; break;
966 case WXK_NUMPAD_PAGEDOWN
: key
= SCK_NEXT
; break;
967 case WXK_NUMPAD_DELETE
: key
= SCK_DELETE
; break;
968 case WXK_NUMPAD_INSERT
: key
= SCK_INSERT
; break;
969 case WXK_DELETE
: key
= SCK_DELETE
; break;
970 case WXK_INSERT
: key
= SCK_INSERT
; break;
971 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
972 case WXK_BACK
: key
= SCK_BACK
; break;
973 case WXK_TAB
: key
= SCK_TAB
; break;
974 case WXK_NUMPAD_ENTER
: // fall through
975 case WXK_RETURN
: key
= SCK_RETURN
; break;
976 case WXK_ADD
: // fall through
977 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
978 case WXK_SUBTRACT
: // fall through
979 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
980 case WXK_DIVIDE
: // fall through
981 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
982 case WXK_CONTROL
: key
= 0; break;
983 case WXK_ALT
: key
= 0; break;
984 case WXK_SHIFT
: key
= 0; break;
985 case WXK_MENU
: key
= 0; break;
989 if ( evt
.MetaDown() ) {
990 // check for a few common Mac Meta-key combos and remap them to Ctrl
997 case 'A': // Select All
1004 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
1013 void ScintillaWX::DoCommand(int ID
) {
1018 void ScintillaWX::DoContextMenu(Point pt
) {
1019 if (displayPopupMenu
)
1023 void ScintillaWX::DoOnListBox() {
1024 AutoCompleteCompleted();
1028 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
1036 //----------------------------------------------------------------------
1038 #if wxUSE_DRAG_AND_DROP
1039 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
1040 SetDragPosition(invalidPosition
);
1042 wxString text
= wxTextBuffer::Translate(data
,
1043 wxConvertEOLMode(pdoc
->eolMode
));
1045 // Send an event to allow the drag details to be changed
1046 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
1047 evt
.SetEventObject(stc
);
1048 evt
.SetDragResult(dragResult
);
1051 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1052 evt
.SetDragText(text
);
1053 stc
->GetEventHandler()->ProcessEvent(evt
);
1055 dragResult
= evt
.GetDragResult();
1056 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
1057 DropAt(evt
.GetPosition(),
1058 wx2stc(evt
.GetDragText()),
1059 dragResult
== wxDragMove
,
1060 false); // TODO: rectangular?
1067 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1073 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1074 SetDragPosition(PositionFromLocation(Point(x
, y
)));
1076 // Send an event to allow the drag result to be changed
1077 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1078 evt
.SetEventObject(stc
);
1079 evt
.SetDragResult(def
);
1082 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1083 stc
->GetEventHandler()->ProcessEvent(evt
);
1085 dragResult
= evt
.GetDragResult();
1090 void ScintillaWX::DoDragLeave() {
1091 SetDragPosition(invalidPosition
);
1093 #endif // wxUSE_DRAG_AND_DROP
1094 //----------------------------------------------------------------------
1096 // Force the whole window to be repainted
1097 void ScintillaWX::FullPaint() {
1099 stc
->Refresh(false);
1105 void ScintillaWX::DoScrollToLine(int line
) {
1110 void ScintillaWX::DoScrollToColumn(int column
) {
1111 HorizontalScrollTo(column
* vs
.spaceWidth
);
1114 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1115 // will leave it here commented out for a while just in case...
1116 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1118 // wxRegion rgn(wxRectFromPRectangle(rect));
1119 // if (ac.Active()) {
1120 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1121 // rgn.Subtract(childRect);
1123 // if (ct.inCallTipMode) {
1124 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1125 // wxRect childRect = tip->GetRect();
1126 // #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
1127 // childRect.SetPosition(tip->GetMyPosition());
1129 // rgn.Subtract(childRect);
1131 // dc.SetClippingRegion(rgn);
1135 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1136 vs
.extraFontFlag
= useAA
;
1137 InvalidateStyleRedraw();
1140 bool ScintillaWX::GetUseAntiAliasing() {
1141 return vs
.extraFontFlag
;
1144 //----------------------------------------------------------------------
1145 //----------------------------------------------------------------------