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"
31 #include "wx/textbuf.h"
32 #include "wx/dataobj.h"
33 #include "wx/clipbrd.h"
36 #include "ScintillaWX.h"
37 #include "ExternalLexer.h"
38 #include "wx/stc/stc.h"
43 #include "wx/msw/private.h"
46 //----------------------------------------------------------------------
49 class wxSTCTimer
: public wxTimer
{
51 wxSTCTimer(ScintillaWX
* swx
) {
64 #if wxUSE_DRAG_AND_DROP
65 class wxStartDragTimer
: public wxTimer
{
67 wxStartDragTimer(ScintillaWX
* swx
) {
80 bool wxSTCDropTarget::OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) {
81 return swx
->DoDropText(x
, y
, data
);
84 wxDragResult
wxSTCDropTarget::OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
) {
85 return swx
->DoDragEnter(x
, y
, def
);
88 wxDragResult
wxSTCDropTarget::OnDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
89 return swx
->DoDragOver(x
, y
, def
);
92 void wxSTCDropTarget::OnLeave() {
95 #endif // wxUSE_DRAG_AND_DROP
98 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
99 #include "wx/popupwin.h"
100 #define wxSTCCallTipBase wxPopupWindow
101 #define param2 wxBORDER_NONE // popup's 2nd param is flags
103 #include "wx/frame.h"
104 #define wxSTCCallTipBase wxFrame
105 #define param2 -1 // wxWindow's 2nd param is ID
108 #include "wx/dcbuffer.h"
110 class wxSTCCallTip
: public wxSTCCallTipBase
{
112 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
) :
113 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
114 wxSTCCallTipBase(parent
, wxBORDER_NONE
),
116 wxSTCCallTipBase(parent
, -1, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
,
118 | wxFRAME_FLOAT_ON_PARENT
125 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
130 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP && defined(__WXGTK__)
131 wxRect rect
= GetRect();
134 GetParent()->Refresh(false, &rect
);
138 bool AcceptsFocus() const { return false; }
140 void OnPaint(wxPaintEvent
& WXUNUSED(evt
))
142 wxBufferedPaintDC
dc(this);
143 Surface
* surfaceWindow
= Surface::Allocate();
144 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
145 m_ct
->PaintCT(surfaceWindow
);
146 surfaceWindow
->Release();
147 delete surfaceWindow
;
150 void OnFocus(wxFocusEvent
& event
)
152 GetParent()->SetFocus();
156 void OnLeftDown(wxMouseEvent
& event
)
158 wxPoint pt
= event
.GetPosition();
161 m_swx
->CallTipClick();
164 virtual void DoSetSize(int x
, int y
,
165 int width
, int height
,
166 int sizeFlags
= wxSIZE_AUTO
)
168 // convert coords to screen coords since we're a top-level window
169 if (x
!= wxDefaultCoord
) {
171 GetParent()->ClientToScreen(&x
, NULL
);
173 if (y
!= wxDefaultCoord
) {
175 GetParent()->ClientToScreen(NULL
, &y
);
177 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
180 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
182 virtual bool Show( bool show
= true )
184 // Although we're a frame, we always want the parent to be active, so
185 // raise it whenever we get shown.
186 bool rv
= wxSTCCallTipBase::Show(show
);
189 wxTopLevelWindow
*frame
= wxDynamicCast(
190 wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
198 wxPoint
GetMyPosition()
200 return wxPoint(m_cx
, m_cy
);
207 DECLARE_EVENT_TABLE()
210 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
211 EVT_PAINT(wxSTCCallTip::OnPaint
)
212 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
213 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
217 //----------------------------------------------------------------------
220 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
224 switch (scintillaMode
) {
226 type
= wxTextFileType_Dos
;
230 type
= wxTextFileType_Mac
;
234 type
= wxTextFileType_Unix
;
238 type
= wxTextBuffer::typeDefault
;
243 #endif // wxUSE_DATAOBJ
246 //----------------------------------------------------------------------
247 // Constructor/Destructor
250 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
251 capturedMouse
= false;
262 #if wxUSE_DRAG_AND_DROP
263 startDragTimer
= new wxStartDragTimer(this);
264 #endif // wxUSE_DRAG_AND_DROP
268 ScintillaWX::~ScintillaWX() {
269 #if wxUSE_DRAG_AND_DROP
270 delete startDragTimer
;
271 #endif // wxUSE_DRAG_AND_DROP
275 //----------------------------------------------------------------------
276 // base class virtuals
279 void ScintillaWX::Initialise() {
280 //ScintillaBase::Initialise();
281 #if wxUSE_DRAG_AND_DROP
282 dropTarget
= new wxSTCDropTarget
;
283 dropTarget
->SetScintilla(this);
284 stc
->SetDropTarget(dropTarget
);
285 #endif // wxUSE_DRAG_AND_DROP
287 vs
.extraFontFlag
= false; // UseAntiAliasing
289 vs
.extraFontFlag
= true; // UseAntiAliasing
294 void ScintillaWX::Finalise() {
295 ScintillaBase::Finalise();
298 DestroySystemCaret();
302 void ScintillaWX::StartDrag() {
303 #if wxUSE_DRAG_AND_DROP
304 // We defer the starting of the DnD, otherwise the LeftUp of a normal
305 // click could be lost and the STC will think it is doing a DnD when the
306 // user just wanted a normal click.
307 startDragTimer
->Start(200, true);
308 #endif // wxUSE_DRAG_AND_DROP
311 void ScintillaWX::DoStartDrag() {
312 #if wxUSE_DRAG_AND_DROP
313 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
315 // Send an event to allow the drag text to be changed
316 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
317 evt
.SetEventObject(stc
);
318 evt
.SetDragText(dragText
);
319 evt
.SetDragAllowMove(true);
320 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
321 stc
->GetSelectionEnd()));
322 stc
->GetEventHandler()->ProcessEvent(evt
);
323 dragText
= evt
.GetDragText();
325 if (dragText
.length()) {
326 wxDropSource
source(stc
);
327 wxTextDataObject
data(dragText
);
330 source
.SetData(data
);
331 dropWentOutside
= true;
332 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
333 if (result
== wxDragMove
&& dropWentOutside
)
336 SetDragPosition(invalidPosition
);
338 #endif // wxUSE_DRAG_AND_DROP
342 bool ScintillaWX::SetIdle(bool on
) {
343 if (idler
.state
!= on
) {
344 // connect or disconnect the EVT_IDLE handler
346 stc
->Connect(wxID_ANY
, wxEVT_IDLE
,
347 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
349 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
,
350 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
357 void ScintillaWX::SetTicking(bool on
) {
358 wxSTCTimer
* steTimer
;
359 if (timer
.ticking
!= on
) {
362 steTimer
= new wxSTCTimer(this);
363 steTimer
->Start(timer
.tickSize
);
364 timer
.tickerID
= steTimer
;
366 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
372 timer
.ticksToWait
= caret
.period
;
376 void ScintillaWX::SetMouseCapture(bool on
) {
377 if (mouseDownCaptures
) {
378 if (on
&& !capturedMouse
)
380 else if (!on
&& capturedMouse
&& stc
->HasCapture())
387 bool ScintillaWX::HaveMouseCapture() {
388 return capturedMouse
;
392 void ScintillaWX::ScrollText(int linesToMove
) {
393 int dy
= vs
.lineHeight
* (linesToMove
);
394 stc
->ScrollWindow(0, dy
);
398 void ScintillaWX::SetVerticalScrollPos() {
399 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
400 stc
->SetScrollPos(wxVERTICAL
, topLine
);
402 else { // otherwise use the one that's been given to us
403 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
407 void ScintillaWX::SetHorizontalScrollPos() {
408 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
409 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
411 else { // otherwise use the one that's been given to us
412 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
417 const int H_SCROLL_STEP
= 20;
419 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
420 bool modified
= false;
423 if (!verticalScrollBarVisible
)
426 // Check the vertical scrollbar
427 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
428 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
429 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
430 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
431 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
432 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
436 else { // otherwise use the one that's been given to us
437 int sbMax
= stc
->m_vScrollBar
->GetRange();
438 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
439 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
440 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
441 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
447 // Check the horizontal scrollbar
448 PRectangle rcText
= GetTextRectangle();
449 int horizEnd
= scrollWidth
;
452 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
454 int pageWidth
= rcText
.Width();
456 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
457 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
458 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
459 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
460 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
461 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
463 if (scrollWidth
< pageWidth
) {
464 HorizontalScrollTo(0);
468 else { // otherwise use the one that's been given to us
469 int sbMax
= stc
->m_hScrollBar
->GetRange();
470 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
471 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
472 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
473 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
475 if (scrollWidth
< pageWidth
) {
476 HorizontalScrollTo(0);
485 void ScintillaWX::NotifyChange() {
490 void ScintillaWX::NotifyParent(SCNotification scn
) {
491 stc
->NotifyParent(&scn
);
495 // This method is overloaded from ScintillaBase in order to prevent the
496 // AutoComplete window from being destroyed when it gets the focus. There is
497 // a side effect that the AutoComp will also not be destroyed when switching
498 // to another window, but I think that is okay.
499 void ScintillaWX::CancelModes() {
501 AutoCompleteCancel();
503 Editor::CancelModes();
508 void ScintillaWX::Copy() {
509 if (currentPos
!= anchor
) {
511 CopySelectionRange(&st
);
517 void ScintillaWX::Paste() {
518 pdoc
->BeginUndoAction();
522 wxTextDataObject data
;
523 bool gotData
= false;
525 wxTheClipboard
->UsePrimarySelection(false);
526 if (wxTheClipboard
->Open()) {
527 gotData
= wxTheClipboard
->GetData(data
);
528 wxTheClipboard
->Close();
531 wxString text
= wxTextBuffer::Translate(data
.GetText(),
532 wxConvertEOLMode(pdoc
->eolMode
));
533 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
536 // free up the old character buffer in case the text is real big
537 data
.SetText(wxEmptyString
);
538 text
= wxEmptyString
;
540 int len
= strlen(buf
);
541 pdoc
->InsertString(currentPos
, buf
, len
);
542 SetEmptySelection(currentPos
+ len
);
544 #endif // wxUSE_DATAOBJ
546 pdoc
->EndUndoAction();
552 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
554 wxTheClipboard
->UsePrimarySelection(false);
555 if (wxTheClipboard
->Open()) {
556 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
557 wxTheClipboard
->SetData(new wxTextDataObject(text
));
558 wxTheClipboard
->Close();
562 #endif // wxUSE_CLIPBOARD
566 bool ScintillaWX::CanPaste() {
568 bool canPaste
= false;
571 if (Editor::CanPaste()) {
572 wxTheClipboard
->UsePrimarySelection(false);
573 didOpen
= !wxTheClipboard
->IsOpened();
575 wxTheClipboard
->Open();
577 if (wxTheClipboard
->IsOpened()) {
578 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
580 wxTheClipboard
->Close();
586 #endif // wxUSE_CLIPBOARD
589 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
590 if (! ct
.wCallTip
.Created() ) {
591 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
592 ct
.wDraw
= ct
.wCallTip
;
597 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
599 ((wxMenu
*)popup
.GetID())->AppendSeparator();
601 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
604 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
608 // This is called by the Editor base class whenever something is selected.
609 // For wxGTK we can put this text in the primary selection and then other apps
610 // can paste with the middle button.
611 void ScintillaWX::ClaimSelection() {
613 // Put the selected text in the PRIMARY selection
614 if (currentPos
!= anchor
) {
616 CopySelectionRange(&st
);
617 wxTheClipboard
->UsePrimarySelection(true);
618 if (wxTheClipboard
->Open()) {
619 wxString text
= stc2wx(st
.s
, st
.len
);
620 wxTheClipboard
->SetData(new wxTextDataObject(text
));
621 wxTheClipboard
->Close();
623 wxTheClipboard
->UsePrimarySelection(false);
629 void ScintillaWX::UpdateSystemCaret() {
632 if (HasCaretSizeChanged()) {
633 DestroySystemCaret();
636 Point pos
= LocationFromPosition(currentPos
);
637 ::SetCaretPos(pos
.x
, pos
.y
);
643 bool ScintillaWX::HasCaretSizeChanged() {
645 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
646 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
653 bool ScintillaWX::CreateSystemCaret() {
655 sysCaretWidth
= vs
.caretWidth
;
656 if (0 == sysCaretWidth
) {
659 sysCaretHeight
= vs
.lineHeight
;
660 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
661 char *bits
= new char[bitmapSize
];
662 memset(bits
, 0, bitmapSize
);
663 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
664 1, reinterpret_cast<BYTE
*>(bits
));
666 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
667 sysCaretWidth
, sysCaretHeight
);
668 ::ShowCaret(GetHwndOf(stc
));
675 bool ScintillaWX::DestroySystemCaret() {
677 ::HideCaret(GetHwndOf(stc
));
678 BOOL retval
= ::DestroyCaret();
679 if (sysCaretBitmap
) {
680 ::DeleteObject(sysCaretBitmap
);
690 //----------------------------------------------------------------------
693 sptr_t
ScintillaWX::DefWndProc(unsigned int /*iMessage*/, uptr_t
/*wParam*/, sptr_t
/*lParam*/) {
697 sptr_t
ScintillaWX::WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) {
699 case SCI_CALLTIPSHOW
: {
700 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
701 // because of the little tweak that needs done below for wxGTK.
702 // When updating new versions double check that this is still
703 // needed, and that any new code there is copied here too.
704 Point pt
= LocationFromPosition(wParam
);
705 char* defn
= reinterpret_cast<char *>(lParam
);
706 AutoCompleteCancel();
707 pt
.y
+= vs
.lineHeight
;
708 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
710 vs
.styles
[STYLE_DEFAULT
].fontName
,
711 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
713 vs
.styles
[STYLE_DEFAULT
].characterSet
,
715 // If the call-tip window would be out of the client
716 // space, adjust so it displays above the text.
717 PRectangle rcClient
= GetClientRectangle();
718 if (rc
.bottom
> rcClient
.bottom
) {
720 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
722 int offset
= vs
.lineHeight
+ rc
.Height();
727 // Now display the window.
728 CreateCallTipWindow(rc
);
729 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
735 case SCI_LOADLEXERLIBRARY
:
736 LexerManager::GetInstance()->Load((const char*)lParam
);
741 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
748 //----------------------------------------------------------------------
751 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
753 paintState
= painting
;
754 Surface
* surfaceWindow
= Surface::Allocate();
755 surfaceWindow
->Init(dc
, wMain
.GetID());
756 rcPaint
= PRectangleFromwxRect(rect
);
757 PRectangle rcClient
= GetClientRectangle();
758 paintingAllText
= rcPaint
.Contains(rcClient
);
760 ClipChildren(*dc
, rcPaint
);
761 Paint(surfaceWindow
, rcPaint
);
763 delete surfaceWindow
;
764 if (paintState
== paintAbandoned
) {
765 // Painting area was insufficient to cover new styling or brace
766 // highlight positions
769 paintState
= notPainting
;
773 void ScintillaWX::DoHScroll(int type
, int pos
) {
775 PRectangle rcText
= GetTextRectangle();
776 int pageWidth
= rcText
.Width() * 2 / 3;
777 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
778 xPos
-= H_SCROLL_STEP
;
779 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
780 xPos
+= H_SCROLL_STEP
;
781 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
783 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
785 if (xPos
> scrollWidth
- rcText
.Width()) {
786 xPos
= scrollWidth
- rcText
.Width();
789 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
791 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
793 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
796 HorizontalScrollTo(xPos
);
799 void ScintillaWX::DoVScroll(int type
, int pos
) {
800 int topLineNew
= topLine
;
801 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
803 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
805 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
806 topLineNew
-= LinesToScroll();
807 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
808 topLineNew
+= LinesToScroll();
809 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
811 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
812 topLineNew
= MaxScrollPos();
813 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
816 ScrollTo(topLineNew
);
819 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
820 int linesPerAction
, int ctrlDown
,
821 bool isPageScroll
) {
822 int topLineNew
= topLine
;
825 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
827 KeyCommand(SCI_ZOOMIN
);
830 KeyCommand(SCI_ZOOMOUT
);
833 else { // otherwise just scroll the window
836 wheelRotation
+= rotation
;
837 lines
= wheelRotation
/ delta
;
838 wheelRotation
-= lines
* delta
;
841 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
843 lines
*= linesPerAction
;
845 ScrollTo(topLineNew
);
851 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
855 void ScintillaWX::DoLoseFocus(){
857 SetFocusState(false);
859 DestroySystemCaret();
862 void ScintillaWX::DoGainFocus(){
866 DestroySystemCaret();
870 void ScintillaWX::DoSysColourChange() {
871 InvalidateStyleData();
874 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
875 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
878 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
879 ButtonUp(pt
, curTime
, ctrl
);
880 #if wxUSE_DRAG_AND_DROP
881 if (startDragTimer
->IsRunning()) {
882 startDragTimer
->Stop();
883 SetDragPosition(invalidPosition
);
884 SetEmptySelection(PositionFromLocation(pt
));
885 ShowCaretAtCurrentPosition();
887 #endif // wxUSE_DRAG_AND_DROP
890 void ScintillaWX::DoLeftButtonMove(Point pt
) {
895 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
896 // Set the current position to the mouse click point and
897 // then paste in the PRIMARY selection, if any. wxGTK only.
898 int newPos
= PositionFromLocation(pt
);
899 MovePositionTo(newPos
, noSel
, true);
901 pdoc
->BeginUndoAction();
902 wxTextDataObject data
;
903 bool gotData
= false;
904 wxTheClipboard
->UsePrimarySelection(true);
905 if (wxTheClipboard
->Open()) {
906 gotData
= wxTheClipboard
->GetData(data
);
907 wxTheClipboard
->Close();
909 wxTheClipboard
->UsePrimarySelection(false);
911 wxString text
= wxTextBuffer::Translate(data
.GetText(),
912 wxConvertEOLMode(pdoc
->eolMode
));
913 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
914 int len
= strlen(buf
);
915 pdoc
->InsertString(currentPos
, buf
, len
);
916 SetEmptySelection(currentPos
+ len
);
918 pdoc
->EndUndoAction();
922 ShowCaretAtCurrentPosition();
923 EnsureCaretVisible();
926 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
931 void ScintillaWX::DoAddChar(int key
) {
934 wszChars
[0] = (wxChar
)key
;
936 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
937 AddCharUTF((char*)buf
.data(), strlen(buf
));
944 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
946 int key
= evt
.GetKeyCode();
947 bool shift
= evt
.ShiftDown(),
948 ctrl
= evt
.ControlDown(),
951 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
955 case WXK_DOWN
: key
= SCK_DOWN
; break;
956 case WXK_UP
: key
= SCK_UP
; break;
957 case WXK_LEFT
: key
= SCK_LEFT
; break;
958 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
959 case WXK_HOME
: key
= SCK_HOME
; break;
960 case WXK_END
: key
= SCK_END
; break;
961 case WXK_PAGEUP
: key
= SCK_PRIOR
; break;
962 case WXK_PAGEDOWN
: key
= SCK_NEXT
; break;
963 case WXK_NUMPAD_DOWN
: key
= SCK_DOWN
; break;
964 case WXK_NUMPAD_UP
: key
= SCK_UP
; break;
965 case WXK_NUMPAD_LEFT
: key
= SCK_LEFT
; break;
966 case WXK_NUMPAD_RIGHT
: key
= SCK_RIGHT
; break;
967 case WXK_NUMPAD_HOME
: key
= SCK_HOME
; break;
968 case WXK_NUMPAD_END
: key
= SCK_END
; break;
969 case WXK_NUMPAD_PAGEUP
: key
= SCK_PRIOR
; break;
970 case WXK_NUMPAD_PAGEDOWN
: key
= SCK_NEXT
; break;
971 case WXK_NUMPAD_DELETE
: key
= SCK_DELETE
; break;
972 case WXK_NUMPAD_INSERT
: key
= SCK_INSERT
; break;
973 case WXK_DELETE
: key
= SCK_DELETE
; break;
974 case WXK_INSERT
: key
= SCK_INSERT
; break;
975 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
976 case WXK_BACK
: key
= SCK_BACK
; break;
977 case WXK_TAB
: key
= SCK_TAB
; break;
978 case WXK_NUMPAD_ENTER
: // fall through
979 case WXK_RETURN
: key
= SCK_RETURN
; break;
980 case WXK_ADD
: // fall through
981 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
982 case WXK_SUBTRACT
: // fall through
983 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
984 case WXK_DIVIDE
: // fall through
985 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
986 case WXK_CONTROL
: key
= 0; break;
987 case WXK_ALT
: key
= 0; break;
988 case WXK_SHIFT
: key
= 0; break;
989 case WXK_MENU
: key
= 0; break;
993 if ( evt
.MetaDown() ) {
994 // check for a few common Mac Meta-key combos and remap them to Ctrl
1001 case 'A': // Select All
1008 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
1017 void ScintillaWX::DoCommand(int ID
) {
1022 void ScintillaWX::DoContextMenu(Point pt
) {
1023 if (displayPopupMenu
)
1027 void ScintillaWX::DoOnListBox() {
1028 AutoCompleteCompleted();
1032 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
1040 //----------------------------------------------------------------------
1042 #if wxUSE_DRAG_AND_DROP
1043 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
1044 SetDragPosition(invalidPosition
);
1046 wxString text
= wxTextBuffer::Translate(data
,
1047 wxConvertEOLMode(pdoc
->eolMode
));
1049 // Send an event to allow the drag details to be changed
1050 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
1051 evt
.SetEventObject(stc
);
1052 evt
.SetDragResult(dragResult
);
1055 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1056 evt
.SetDragText(text
);
1057 stc
->GetEventHandler()->ProcessEvent(evt
);
1059 dragResult
= evt
.GetDragResult();
1060 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
1061 DropAt(evt
.GetPosition(),
1062 wx2stc(evt
.GetDragText()),
1063 dragResult
== wxDragMove
,
1064 false); // TODO: rectangular?
1071 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1077 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1078 SetDragPosition(PositionFromLocation(Point(x
, y
)));
1080 // Send an event to allow the drag result to be changed
1081 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1082 evt
.SetEventObject(stc
);
1083 evt
.SetDragResult(def
);
1086 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1087 stc
->GetEventHandler()->ProcessEvent(evt
);
1089 dragResult
= evt
.GetDragResult();
1094 void ScintillaWX::DoDragLeave() {
1095 SetDragPosition(invalidPosition
);
1097 #endif // wxUSE_DRAG_AND_DROP
1098 //----------------------------------------------------------------------
1100 // Force the whole window to be repainted
1101 void ScintillaWX::FullPaint() {
1103 stc
->Refresh(false);
1109 void ScintillaWX::DoScrollToLine(int line
) {
1114 void ScintillaWX::DoScrollToColumn(int column
) {
1115 HorizontalScrollTo(column
* vs
.spaceWidth
);
1118 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1119 // will leave it here commented out for a while just in case...
1120 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1122 // wxRegion rgn(wxRectFromPRectangle(rect));
1123 // if (ac.Active()) {
1124 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1125 // rgn.Subtract(childRect);
1127 // if (ct.inCallTipMode) {
1128 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1129 // wxRect childRect = tip->GetRect();
1130 // #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
1131 // childRect.SetPosition(tip->GetMyPosition());
1133 // rgn.Subtract(childRect);
1135 // dc.SetClippingRegion(rgn);
1139 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1140 vs
.extraFontFlag
= useAA
;
1141 InvalidateStyleRedraw();
1144 bool ScintillaWX::GetUseAntiAliasing() {
1145 return vs
.extraFontFlag
;
1148 //----------------------------------------------------------------------
1149 //----------------------------------------------------------------------