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 /////////////////////////////////////////////////////////////////////////////
18 #include "wx/textbuf.h"
19 #include "wx/dataobj.h"
20 #include "wx/clipbrd.h"
23 #include "ScintillaWX.h"
24 #include "ExternalLexer.h"
25 #include "wx/stc/stc.h"
30 #include "wx/msw/private.h"
33 //----------------------------------------------------------------------
36 class wxSTCTimer
: public wxTimer
{
38 wxSTCTimer(ScintillaWX
* swx
) {
51 #if wxUSE_DRAG_AND_DROP
52 class wxStartDragTimer
: public wxTimer
{
54 wxStartDragTimer(ScintillaWX
* swx
) {
67 bool wxSTCDropTarget::OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) {
68 return swx
->DoDropText(x
, y
, data
);
71 wxDragResult
wxSTCDropTarget::OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
) {
72 return swx
->DoDragEnter(x
, y
, def
);
75 wxDragResult
wxSTCDropTarget::OnDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
76 return swx
->DoDragOver(x
, y
, def
);
79 void wxSTCDropTarget::OnLeave() {
82 #endif // wxUSE_DRAG_AND_DROP
85 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
86 #include <wx/popupwin.h>
87 #define wxSTCCallTipBase wxPopupWindow
88 #define param2 wxBORDER_NONE // popup's 2nd param is flags
90 #define wxSTCCallTipBase wxFrame
91 #define param2 -1 // wxWindow's 2nd param is ID
94 #include <wx/dcbuffer.h>
96 class wxSTCCallTip
: public wxSTCCallTipBase
{
98 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
) :
99 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
100 wxSTCCallTipBase(parent
, wxBORDER_NONE
),
102 wxSTCCallTipBase(parent
, -1, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
,
104 | wxFRAME_FLOAT_ON_PARENT
111 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
116 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP && defined(__WXGTK__)
117 wxRect rect
= GetRect();
120 GetParent()->Refresh(false, &rect
);
124 bool AcceptsFocus() const { return false; }
126 void OnPaint(wxPaintEvent
& WXUNUSED(evt
))
128 wxBufferedPaintDC
dc(this);
129 Surface
* surfaceWindow
= Surface::Allocate();
130 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
131 m_ct
->PaintCT(surfaceWindow
);
132 surfaceWindow
->Release();
133 delete surfaceWindow
;
136 void OnFocus(wxFocusEvent
& event
)
138 GetParent()->SetFocus();
142 void OnLeftDown(wxMouseEvent
& event
)
144 wxPoint pt
= event
.GetPosition();
147 m_swx
->CallTipClick();
150 virtual void DoSetSize(int x
, int y
,
151 int width
, int height
,
152 int sizeFlags
= wxSIZE_AUTO
)
154 // convert coords to screen coords since we're a top-level window
155 if (x
!= wxDefaultCoord
) {
157 GetParent()->ClientToScreen(&x
, NULL
);
159 if (y
!= wxDefaultCoord
) {
161 GetParent()->ClientToScreen(NULL
, &y
);
163 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
166 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
168 virtual bool Show( bool show
= true )
170 // Although we're a frame, we always want the parent to be active, so
171 // raise it whenever we get shown.
172 bool rv
= wxSTCCallTipBase::Show(show
);
175 wxTopLevelWindow
*frame
= wxDynamicCast(
176 wxGetTopLevelParent(GetParent()), wxTopLevelWindow
);
184 wxPoint
GetMyPosition()
186 return wxPoint(m_cx
, m_cy
);
193 DECLARE_EVENT_TABLE()
196 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
197 EVT_PAINT(wxSTCCallTip::OnPaint
)
198 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
199 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
203 //----------------------------------------------------------------------
206 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
210 switch (scintillaMode
) {
212 type
= wxTextFileType_Dos
;
216 type
= wxTextFileType_Mac
;
220 type
= wxTextFileType_Unix
;
224 type
= wxTextBuffer::typeDefault
;
229 #endif // wxUSE_DATAOBJ
232 //----------------------------------------------------------------------
233 // Constructor/Destructor
236 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
237 capturedMouse
= false;
248 #if wxUSE_DRAG_AND_DROP
249 startDragTimer
= new wxStartDragTimer(this);
250 #endif // wxUSE_DRAG_AND_DROP
254 ScintillaWX::~ScintillaWX() {
255 #if wxUSE_DRAG_AND_DROP
256 delete startDragTimer
;
257 #endif // wxUSE_DRAG_AND_DROP
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
273 vs
.extraFontFlag
= false; // UseAntiAliasing
275 vs
.extraFontFlag
= true; // UseAntiAliasing
280 void ScintillaWX::Finalise() {
281 ScintillaBase::Finalise();
284 DestroySystemCaret();
288 void ScintillaWX::StartDrag() {
289 #if wxUSE_DRAG_AND_DROP
290 // We defer the starting of the DnD, otherwise the LeftUp of a normal
291 // click could be lost and the STC will think it is doing a DnD when the
292 // user just wanted a normal click.
293 startDragTimer
->Start(200, true);
294 #endif // wxUSE_DRAG_AND_DROP
297 void ScintillaWX::DoStartDrag() {
298 #if wxUSE_DRAG_AND_DROP
299 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
301 // Send an event to allow the drag text to be changed
302 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
303 evt
.SetEventObject(stc
);
304 evt
.SetDragText(dragText
);
305 evt
.SetDragAllowMove(true);
306 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
307 stc
->GetSelectionEnd()));
308 stc
->GetEventHandler()->ProcessEvent(evt
);
309 dragText
= evt
.GetDragText();
311 if (dragText
.length()) {
312 wxDropSource
source(stc
);
313 wxTextDataObject
data(dragText
);
316 source
.SetData(data
);
317 dropWentOutside
= true;
318 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
319 if (result
== wxDragMove
&& dropWentOutside
)
322 SetDragPosition(invalidPosition
);
324 #endif // wxUSE_DRAG_AND_DROP
328 bool ScintillaWX::SetIdle(bool on
) {
329 if (idler
.state
!= on
) {
330 // connect or disconnect the EVT_IDLE handler
332 stc
->Connect(wxID_ANY
, wxEVT_IDLE
,
333 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
335 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
,
336 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
343 void ScintillaWX::SetTicking(bool on
) {
344 wxSTCTimer
* steTimer
;
345 if (timer
.ticking
!= on
) {
348 steTimer
= new wxSTCTimer(this);
349 steTimer
->Start(timer
.tickSize
);
350 timer
.tickerID
= steTimer
;
352 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
358 timer
.ticksToWait
= caret
.period
;
362 void ScintillaWX::SetMouseCapture(bool on
) {
363 if (mouseDownCaptures
) {
364 if (on
&& !capturedMouse
)
366 else if (!on
&& capturedMouse
&& stc
->HasCapture())
373 bool ScintillaWX::HaveMouseCapture() {
374 return capturedMouse
;
378 void ScintillaWX::ScrollText(int linesToMove
) {
379 int dy
= vs
.lineHeight
* (linesToMove
);
380 stc
->ScrollWindow(0, dy
);
384 void ScintillaWX::SetVerticalScrollPos() {
385 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
386 stc
->SetScrollPos(wxVERTICAL
, topLine
);
388 else { // otherwise use the one that's been given to us
389 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
393 void ScintillaWX::SetHorizontalScrollPos() {
394 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
395 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
397 else { // otherwise use the one that's been given to us
398 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
403 const int H_SCROLL_STEP
= 20;
405 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
406 bool modified
= false;
409 if (!verticalScrollBarVisible
)
412 // Check the vertical scrollbar
413 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
414 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
415 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
416 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
417 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
418 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
422 else { // otherwise use the one that's been given to us
423 int sbMax
= stc
->m_vScrollBar
->GetRange();
424 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
425 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
426 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
427 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
433 // Check the horizontal scrollbar
434 PRectangle rcText
= GetTextRectangle();
435 int horizEnd
= scrollWidth
;
438 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
440 int pageWidth
= rcText
.Width();
442 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
443 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
444 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
445 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
446 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
447 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
449 if (scrollWidth
< pageWidth
) {
450 HorizontalScrollTo(0);
454 else { // otherwise use the one that's been given to us
455 int sbMax
= stc
->m_hScrollBar
->GetRange();
456 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
457 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
458 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
459 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
461 if (scrollWidth
< pageWidth
) {
462 HorizontalScrollTo(0);
471 void ScintillaWX::NotifyChange() {
476 void ScintillaWX::NotifyParent(SCNotification scn
) {
477 stc
->NotifyParent(&scn
);
481 // This method is overloaded from ScintillaBase in order to prevent the
482 // AutoComplete window from being destroyed when it gets the focus. There is
483 // a side effect that the AutoComp will also not be destroyed when switching
484 // to another window, but I think that is okay.
485 void ScintillaWX::CancelModes() {
487 AutoCompleteCancel();
489 Editor::CancelModes();
494 void ScintillaWX::Copy() {
495 if (currentPos
!= anchor
) {
497 CopySelectionRange(&st
);
503 void ScintillaWX::Paste() {
504 pdoc
->BeginUndoAction();
508 wxTextDataObject data
;
509 bool gotData
= false;
511 if (wxTheClipboard
->Open()) {
512 wxTheClipboard
->UsePrimarySelection(false);
513 gotData
= wxTheClipboard
->GetData(data
);
514 wxTheClipboard
->Close();
517 wxString text
= wxTextBuffer::Translate(data
.GetText(),
518 wxConvertEOLMode(pdoc
->eolMode
));
519 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
522 // free up the old character buffer in case the text is real big
523 data
.SetText(wxEmptyString
);
524 text
= wxEmptyString
;
526 int len
= strlen(buf
);
527 pdoc
->InsertString(currentPos
, buf
, len
);
528 SetEmptySelection(currentPos
+ len
);
530 #endif // wxUSE_DATAOBJ
532 pdoc
->EndUndoAction();
538 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
540 if (wxTheClipboard
->Open()) {
541 wxTheClipboard
->UsePrimarySelection(false);
542 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
-1));
543 wxTheClipboard
->SetData(new wxTextDataObject(text
));
544 wxTheClipboard
->Close();
548 #endif // wxUSE_CLIPBOARD
552 bool ScintillaWX::CanPaste() {
554 bool canPaste
= false;
557 if (Editor::CanPaste()) {
558 didOpen
= !wxTheClipboard
->IsOpened();
560 wxTheClipboard
->Open();
562 if (wxTheClipboard
->IsOpened()) {
563 wxTheClipboard
->UsePrimarySelection(false);
564 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
566 wxTheClipboard
->Close();
572 #endif // wxUSE_CLIPBOARD
575 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
576 if (! ct
.wCallTip
.Created() ) {
577 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
578 ct
.wDraw
= ct
.wCallTip
;
583 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
585 ((wxMenu
*)popup
.GetID())->AppendSeparator();
587 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
590 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
594 // This is called by the Editor base class whenever something is selected
595 void ScintillaWX::ClaimSelection() {
597 // Until wxGTK is able to support using both the primary selection and the
598 // clipboard at the same time I think it causes more problems than it is
599 // worth to implement this method. Selecting text should not clear the
600 // clipboard. --Robin
602 // Put the selected text in the PRIMARY selection
603 if (currentPos
!= anchor
) {
605 CopySelectionRange(&st
);
606 if (wxTheClipboard
->Open()) {
607 wxTheClipboard
->UsePrimarySelection(true);
608 wxString text
= stc2wx(st
.s
, st
.len
);
609 wxTheClipboard
->SetData(new wxTextDataObject(text
));
610 wxTheClipboard
->UsePrimarySelection(false);
611 wxTheClipboard
->Close();
619 void ScintillaWX::UpdateSystemCaret() {
622 if (HasCaretSizeChanged()) {
623 DestroySystemCaret();
626 Point pos
= LocationFromPosition(currentPos
);
627 ::SetCaretPos(pos
.x
, pos
.y
);
633 bool ScintillaWX::HasCaretSizeChanged() {
635 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
636 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
643 bool ScintillaWX::CreateSystemCaret() {
645 sysCaretWidth
= vs
.caretWidth
;
646 if (0 == sysCaretWidth
) {
649 sysCaretHeight
= vs
.lineHeight
;
650 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
651 char *bits
= new char[bitmapSize
];
652 memset(bits
, 0, bitmapSize
);
653 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
654 1, reinterpret_cast<BYTE
*>(bits
));
656 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
657 sysCaretWidth
, sysCaretHeight
);
658 ::ShowCaret(GetHwndOf(stc
));
665 bool ScintillaWX::DestroySystemCaret() {
667 ::HideCaret(GetHwndOf(stc
));
668 BOOL retval
= ::DestroyCaret();
669 if (sysCaretBitmap
) {
670 ::DeleteObject(sysCaretBitmap
);
680 //----------------------------------------------------------------------
683 long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
687 long ScintillaWX::WndProc(unsigned int iMessage
, unsigned long wParam
, long lParam
) {
689 case SCI_CALLTIPSHOW
: {
690 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
691 // because of the little tweak that needs done below for wxGTK.
692 // When updating new versions double check that this is still
693 // needed, and that any new code there is copied here too.
694 Point pt
= LocationFromPosition(wParam
);
695 char* defn
= reinterpret_cast<char *>(lParam
);
696 AutoCompleteCancel();
697 pt
.y
+= vs
.lineHeight
;
698 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
700 vs
.styles
[STYLE_DEFAULT
].fontName
,
701 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
703 vs
.styles
[STYLE_DEFAULT
].characterSet
,
705 // If the call-tip window would be out of the client
706 // space, adjust so it displays above the text.
707 PRectangle rcClient
= GetClientRectangle();
708 if (rc
.bottom
> rcClient
.bottom
) {
710 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
712 int offset
= vs
.lineHeight
+ rc
.Height();
717 // Now display the window.
718 CreateCallTipWindow(rc
);
719 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
725 case SCI_LOADLEXERLIBRARY
:
726 LexerManager::GetInstance()->Load((const char*)lParam
);
731 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
738 //----------------------------------------------------------------------
741 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
743 paintState
= painting
;
744 Surface
* surfaceWindow
= Surface::Allocate();
745 surfaceWindow
->Init(dc
, wMain
.GetID());
746 rcPaint
= PRectangleFromwxRect(rect
);
747 PRectangle rcClient
= GetClientRectangle();
748 paintingAllText
= rcPaint
.Contains(rcClient
);
750 ClipChildren(*dc
, rcPaint
);
751 Paint(surfaceWindow
, rcPaint
);
753 delete surfaceWindow
;
754 if (paintState
== paintAbandoned
) {
755 // Painting area was insufficient to cover new styling or brace
756 // highlight positions
759 paintState
= notPainting
;
763 void ScintillaWX::DoHScroll(int type
, int pos
) {
765 PRectangle rcText
= GetTextRectangle();
766 int pageWidth
= rcText
.Width() * 2 / 3;
767 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
768 xPos
-= H_SCROLL_STEP
;
769 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
770 xPos
+= H_SCROLL_STEP
;
771 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
773 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
775 if (xPos
> scrollWidth
- rcText
.Width()) {
776 xPos
= scrollWidth
- rcText
.Width();
779 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
781 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
783 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
786 HorizontalScrollTo(xPos
);
789 void ScintillaWX::DoVScroll(int type
, int pos
) {
790 int topLineNew
= topLine
;
791 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
793 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
795 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
796 topLineNew
-= LinesToScroll();
797 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
798 topLineNew
+= LinesToScroll();
799 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
801 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
802 topLineNew
= MaxScrollPos();
803 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
806 ScrollTo(topLineNew
);
809 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
810 int linesPerAction
, int ctrlDown
,
811 bool isPageScroll
) {
812 int topLineNew
= topLine
;
815 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
817 KeyCommand(SCI_ZOOMIN
);
820 KeyCommand(SCI_ZOOMOUT
);
823 else { // otherwise just scroll the window
826 wheelRotation
+= rotation
;
827 lines
= wheelRotation
/ delta
;
828 wheelRotation
-= lines
* delta
;
831 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
833 lines
*= linesPerAction
;
835 ScrollTo(topLineNew
);
841 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
845 void ScintillaWX::DoLoseFocus(){
847 SetFocusState(false);
849 DestroySystemCaret();
852 void ScintillaWX::DoGainFocus(){
856 DestroySystemCaret();
860 void ScintillaWX::DoSysColourChange() {
861 InvalidateStyleData();
864 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
865 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
868 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
869 ButtonUp(pt
, curTime
, ctrl
);
870 #if wxUSE_DRAG_AND_DROP
871 if (startDragTimer
->IsRunning()) {
872 startDragTimer
->Stop();
873 SetDragPosition(invalidPosition
);
874 SetEmptySelection(PositionFromLocation(pt
));
875 ShowCaretAtCurrentPosition();
877 #endif // wxUSE_DRAG_AND_DROP
880 void ScintillaWX::DoLeftButtonMove(Point pt
) {
885 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
886 // Set the current position to the mouse click point and
887 // then paste in the PRIMARY selection, if any. wxGTK only.
888 int newPos
= PositionFromLocation(pt
);
889 MovePositionTo(newPos
, noSel
, true);
891 pdoc
->BeginUndoAction();
892 wxTextDataObject data
;
893 bool gotData
= false;
894 if (wxTheClipboard
->Open()) {
895 wxTheClipboard
->UsePrimarySelection(true);
896 gotData
= wxTheClipboard
->GetData(data
);
897 wxTheClipboard
->UsePrimarySelection(false);
898 wxTheClipboard
->Close();
901 wxString text
= wxTextBuffer::Translate(data
.GetText(),
902 wxConvertEOLMode(pdoc
->eolMode
));
903 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
904 int len
= strlen(buf
);
905 pdoc
->InsertString(currentPos
, buf
, len
);
906 SetEmptySelection(currentPos
+ len
);
908 pdoc
->EndUndoAction();
912 ShowCaretAtCurrentPosition();
913 EnsureCaretVisible();
916 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
921 void ScintillaWX::DoAddChar(int key
) {
924 wszChars
[0] = (wxChar
)key
;
926 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
927 AddCharUTF((char*)buf
.data(), strlen(buf
));
934 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
936 int key
= evt
.GetKeyCode();
937 bool shift
= evt
.ShiftDown(),
938 ctrl
= evt
.ControlDown(),
941 if (ctrl
&& key
>= 1 && key
<= 26 && key
!= WXK_BACK
)
945 case WXK_DOWN
: key
= SCK_DOWN
; break;
946 case WXK_UP
: key
= SCK_UP
; break;
947 case WXK_LEFT
: key
= SCK_LEFT
; break;
948 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
949 case WXK_HOME
: key
= SCK_HOME
; break;
950 case WXK_END
: key
= SCK_END
; break;
951 case WXK_PAGEUP
: key
= SCK_PRIOR
; break;
952 case WXK_PAGEDOWN
: key
= SCK_NEXT
; break;
953 case WXK_NUMPAD_DOWN
: key
= SCK_DOWN
; break;
954 case WXK_NUMPAD_UP
: key
= SCK_UP
; break;
955 case WXK_NUMPAD_LEFT
: key
= SCK_LEFT
; break;
956 case WXK_NUMPAD_RIGHT
: key
= SCK_RIGHT
; break;
957 case WXK_NUMPAD_HOME
: key
= SCK_HOME
; break;
958 case WXK_NUMPAD_END
: key
= SCK_END
; break;
959 case WXK_NUMPAD_PAGEUP
: key
= SCK_PRIOR
; break;
960 case WXK_NUMPAD_PAGEDOWN
: key
= SCK_NEXT
; break;
961 case WXK_NUMPAD_DELETE
: key
= SCK_DELETE
; break;
962 case WXK_NUMPAD_INSERT
: key
= SCK_INSERT
; break;
963 case WXK_DELETE
: key
= SCK_DELETE
; break;
964 case WXK_INSERT
: key
= SCK_INSERT
; break;
965 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
966 case WXK_BACK
: key
= SCK_BACK
; break;
967 case WXK_TAB
: key
= SCK_TAB
; break;
968 case WXK_NUMPAD_ENTER
: // fall through
969 case WXK_RETURN
: key
= SCK_RETURN
; break;
970 case WXK_ADD
: // fall through
971 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
972 case WXK_SUBTRACT
: // fall through
973 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
974 case WXK_DIVIDE
: // fall through
975 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
976 case WXK_CONTROL
: key
= 0; break;
977 case WXK_ALT
: key
= 0; break;
978 case WXK_SHIFT
: key
= 0; break;
979 case WXK_MENU
: key
= 0; break;
983 if ( evt
.MetaDown() ) {
984 // check for a few common Mac Meta-key combos and remap them to Ctrl
991 case 'A': // Select All
998 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
1007 void ScintillaWX::DoCommand(int ID
) {
1012 void ScintillaWX::DoContextMenu(Point pt
) {
1013 if (displayPopupMenu
)
1017 void ScintillaWX::DoOnListBox() {
1018 AutoCompleteCompleted();
1022 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
1030 //----------------------------------------------------------------------
1032 #if wxUSE_DRAG_AND_DROP
1033 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
1034 SetDragPosition(invalidPosition
);
1036 wxString text
= wxTextBuffer::Translate(data
,
1037 wxConvertEOLMode(pdoc
->eolMode
));
1039 // Send an event to allow the drag details to be changed
1040 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
1041 evt
.SetEventObject(stc
);
1042 evt
.SetDragResult(dragResult
);
1045 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1046 evt
.SetDragText(text
);
1047 stc
->GetEventHandler()->ProcessEvent(evt
);
1049 dragResult
= evt
.GetDragResult();
1050 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
1051 DropAt(evt
.GetPosition(),
1052 wx2stc(evt
.GetDragText()),
1053 dragResult
== wxDragMove
,
1054 false); // TODO: rectangular?
1061 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
1067 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
1068 SetDragPosition(PositionFromLocation(Point(x
, y
)));
1070 // Send an event to allow the drag result to be changed
1071 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
1072 evt
.SetEventObject(stc
);
1073 evt
.SetDragResult(def
);
1076 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
1077 stc
->GetEventHandler()->ProcessEvent(evt
);
1079 dragResult
= evt
.GetDragResult();
1084 void ScintillaWX::DoDragLeave() {
1085 SetDragPosition(invalidPosition
);
1087 #endif // wxUSE_DRAG_AND_DROP
1088 //----------------------------------------------------------------------
1090 // Force the whole window to be repainted
1091 void ScintillaWX::FullPaint() {
1093 stc
->Refresh(false);
1099 void ScintillaWX::DoScrollToLine(int line
) {
1104 void ScintillaWX::DoScrollToColumn(int column
) {
1105 HorizontalScrollTo(column
* vs
.spaceWidth
);
1108 // wxGTK doesn't appear to need this explicit clipping code any longer, but I
1109 // will leave it here commented out for a while just in case...
1110 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
))
1112 // wxRegion rgn(wxRectFromPRectangle(rect));
1113 // if (ac.Active()) {
1114 // wxRect childRect = ((wxWindow*)ac.lb->GetID())->GetRect();
1115 // rgn.Subtract(childRect);
1117 // if (ct.inCallTipMode) {
1118 // wxSTCCallTip* tip = (wxSTCCallTip*)ct.wCallTip.GetID();
1119 // wxRect childRect = tip->GetRect();
1120 // #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
1121 // childRect.SetPosition(tip->GetMyPosition());
1123 // rgn.Subtract(childRect);
1125 // dc.SetClippingRegion(rgn);
1129 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1130 vs
.extraFontFlag
= useAA
;
1131 InvalidateStyleRedraw();
1134 bool ScintillaWX::GetUseAntiAliasing() {
1135 return vs
.extraFontFlag
;
1138 //----------------------------------------------------------------------
1139 //----------------------------------------------------------------------