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 "ScintillaWX.h"
19 #include "ExternalLexer.h"
20 #include "wx/stc/stc.h"
22 #include <wx/textbuf.h>
26 #include <wx/msw/private.h>
29 //----------------------------------------------------------------------
32 class wxSTCTimer
: public wxTimer
{
34 wxSTCTimer(ScintillaWX
* swx
) {
47 #if wxUSE_DRAG_AND_DROP
48 bool wxSTCDropTarget::OnDropText(wxCoord x
, wxCoord y
, const wxString
& data
) {
49 return swx
->DoDropText(x
, y
, data
);
52 wxDragResult
wxSTCDropTarget::OnEnter(wxCoord x
, wxCoord y
, wxDragResult def
) {
53 return swx
->DoDragEnter(x
, y
, def
);
56 wxDragResult
wxSTCDropTarget::OnDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
57 return swx
->DoDragOver(x
, y
, def
);
60 void wxSTCDropTarget::OnLeave() {
66 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
67 #include <wx/popupwin.h>
68 #define wxSTCCallTipBase wxPopupWindow
69 #define param2 wxBORDER_NONE // popup's 2nd param is flags
71 #define wxSTCCallTipBase wxWindow
72 #define param2 -1 // wxWindow's 2nd param is ID
75 #include <wx/dcbuffer.h>
77 class wxSTCCallTip
: public wxSTCCallTipBase
{
79 wxSTCCallTip(wxWindow
* parent
, CallTip
* ct
, ScintillaWX
* swx
)
80 : wxSTCCallTipBase(parent
, param2
),
81 m_ct(ct
), m_swx(swx
), m_cx(wxDefaultCoord
), m_cy(wxDefaultCoord
)
86 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP && defined(__WXGTK__)
87 wxRect rect
= GetRect();
90 GetParent()->Refresh(false, &rect
);
94 bool AcceptsFocus() const { return false; }
96 void OnPaint(wxPaintEvent
& WXUNUSED(evt
)) {
97 wxBufferedPaintDC
dc(this);
98 Surface
* surfaceWindow
= Surface::Allocate();
99 surfaceWindow
->Init(&dc
, m_ct
->wDraw
.GetID());
100 m_ct
->PaintCT(surfaceWindow
);
101 surfaceWindow
->Release();
102 delete surfaceWindow
;
105 void OnFocus(wxFocusEvent
& event
) {
106 GetParent()->SetFocus();
110 void OnLeftDown(wxMouseEvent
& event
) {
111 wxPoint pt
= event
.GetPosition();
114 m_swx
->CallTipClick();
117 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
118 virtual void DoSetSize(int x
, int y
,
119 int width
, int height
,
120 int sizeFlags
= wxSIZE_AUTO
) {
121 if (x
!= wxDefaultCoord
) {
123 GetParent()->ClientToScreen(&x
, NULL
);
125 if (y
!= wxDefaultCoord
) {
127 GetParent()->ClientToScreen(NULL
, &y
);
129 wxSTCCallTipBase::DoSetSize(x
, y
, width
, height
, sizeFlags
);
133 wxPoint
GetMyPosition() {
134 return wxPoint(m_cx
, m_cy
);
141 DECLARE_EVENT_TABLE()
144 BEGIN_EVENT_TABLE(wxSTCCallTip
, wxSTCCallTipBase
)
145 EVT_PAINT(wxSTCCallTip::OnPaint
)
146 EVT_SET_FOCUS(wxSTCCallTip::OnFocus
)
147 EVT_LEFT_DOWN(wxSTCCallTip::OnLeftDown
)
151 //----------------------------------------------------------------------
153 static wxTextFileType
wxConvertEOLMode(int scintillaMode
)
157 switch (scintillaMode
) {
159 type
= wxTextFileType_Dos
;
163 type
= wxTextFileType_Mac
;
167 type
= wxTextFileType_Unix
;
171 type
= wxTextBuffer::typeDefault
;
178 //----------------------------------------------------------------------
179 // Constructor/Destructor
182 ScintillaWX::ScintillaWX(wxStyledTextCtrl
* win
) {
183 capturedMouse
= false;
197 ScintillaWX::~ScintillaWX() {
201 //----------------------------------------------------------------------
202 // base class virtuals
205 void ScintillaWX::Initialise() {
206 //ScintillaBase::Initialise();
207 #if wxUSE_DRAG_AND_DROP
208 dropTarget
= new wxSTCDropTarget
;
209 dropTarget
->SetScintilla(this);
210 stc
->SetDropTarget(dropTarget
);
213 vs
.extraFontFlag
= false; // UseAntiAliasing
215 vs
.extraFontFlag
= true; // UseAntiAliasing
220 void ScintillaWX::Finalise() {
221 ScintillaBase::Finalise();
224 DestroySystemCaret();
228 void ScintillaWX::StartDrag() {
229 #if wxUSE_DRAG_AND_DROP
230 wxString dragText
= stc2wx(drag
.s
, drag
.len
);
232 // Send an event to allow the drag text to be changed
233 wxStyledTextEvent
evt(wxEVT_STC_START_DRAG
, stc
->GetId());
234 evt
.SetEventObject(stc
);
235 evt
.SetDragText(dragText
);
236 evt
.SetDragAllowMove(true);
237 evt
.SetPosition(wxMin(stc
->GetSelectionStart(),
238 stc
->GetSelectionEnd()));
239 stc
->GetEventHandler()->ProcessEvent(evt
);
240 dragText
= evt
.GetDragText();
242 if (dragText
.Length()) {
243 wxDropSource
source(stc
);
244 wxTextDataObject
data(dragText
);
247 source
.SetData(data
);
248 dropWentOutside
= true;
249 result
= source
.DoDragDrop(evt
.GetDragAllowMove());
250 if (result
== wxDragMove
&& dropWentOutside
)
253 SetDragPosition(invalidPosition
);
259 bool ScintillaWX::SetIdle(bool on
) {
260 if (idler
.state
!= on
) {
261 // connect or disconnect the EVT_IDLE handler
263 stc
->Connect(wxID_ANY
, wxEVT_IDLE
,
264 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
266 stc
->Disconnect(wxID_ANY
, wxEVT_IDLE
,
267 (wxObjectEventFunction
) (wxEventFunction
) (wxIdleEventFunction
) &wxStyledTextCtrl::OnIdle
);
274 void ScintillaWX::SetTicking(bool on
) {
275 wxSTCTimer
* steTimer
;
276 if (timer
.ticking
!= on
) {
279 steTimer
= new wxSTCTimer(this);
280 steTimer
->Start(timer
.tickSize
);
281 timer
.tickerID
= steTimer
;
283 steTimer
= (wxSTCTimer
*)timer
.tickerID
;
289 timer
.ticksToWait
= caret
.period
;
293 void ScintillaWX::SetMouseCapture(bool on
) {
294 if (mouseDownCaptures
) {
295 if (on
&& !capturedMouse
)
297 else if (!on
&& capturedMouse
&& stc
->HasCapture())
304 bool ScintillaWX::HaveMouseCapture() {
305 return capturedMouse
;
309 void ScintillaWX::ScrollText(int linesToMove
) {
310 int dy
= vs
.lineHeight
* (linesToMove
);
311 stc
->ScrollWindow(0, dy
);
315 void ScintillaWX::SetVerticalScrollPos() {
316 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
317 stc
->SetScrollPos(wxVERTICAL
, topLine
);
319 else { // otherwise use the one that's been given to us
320 stc
->m_vScrollBar
->SetThumbPosition(topLine
);
324 void ScintillaWX::SetHorizontalScrollPos() {
325 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
326 stc
->SetScrollPos(wxHORIZONTAL
, xOffset
);
328 else { // otherwise use the one that's been given to us
329 stc
->m_hScrollBar
->SetThumbPosition(xOffset
);
334 const int H_SCROLL_STEP
= 20;
336 bool ScintillaWX::ModifyScrollBars(int nMax
, int nPage
) {
337 bool modified
= false;
340 if (!verticalScrollBarVisible
)
343 // Check the vertical scrollbar
344 if (stc
->m_vScrollBar
== NULL
) { // Use built-in scrollbar
345 int sbMax
= stc
->GetScrollRange(wxVERTICAL
);
346 int sbThumb
= stc
->GetScrollThumb(wxVERTICAL
);
347 int sbPos
= stc
->GetScrollPos(wxVERTICAL
);
348 if (sbMax
!= vertEnd
|| sbThumb
!= nPage
) {
349 stc
->SetScrollbar(wxVERTICAL
, sbPos
, nPage
, vertEnd
+1);
353 else { // otherwise use the one that's been given to us
354 int sbMax
= stc
->m_vScrollBar
->GetRange();
355 int sbPage
= stc
->m_vScrollBar
->GetPageSize();
356 int sbPos
= stc
->m_vScrollBar
->GetThumbPosition();
357 if (sbMax
!= vertEnd
|| sbPage
!= nPage
) {
358 stc
->m_vScrollBar
->SetScrollbar(sbPos
, nPage
, vertEnd
+1, nPage
);
364 // Check the horizontal scrollbar
365 PRectangle rcText
= GetTextRectangle();
366 int horizEnd
= scrollWidth
;
369 if (!horizontalScrollBarVisible
|| (wrapState
!= eWrapNone
))
371 int pageWidth
= rcText
.Width();
373 if (stc
->m_hScrollBar
== NULL
) { // Use built-in scrollbar
374 int sbMax
= stc
->GetScrollRange(wxHORIZONTAL
);
375 int sbThumb
= stc
->GetScrollThumb(wxHORIZONTAL
);
376 int sbPos
= stc
->GetScrollPos(wxHORIZONTAL
);
377 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
378 stc
->SetScrollbar(wxHORIZONTAL
, sbPos
, pageWidth
, horizEnd
);
380 if (scrollWidth
< pageWidth
) {
381 HorizontalScrollTo(0);
385 else { // otherwise use the one that's been given to us
386 int sbMax
= stc
->m_hScrollBar
->GetRange();
387 int sbThumb
= stc
->m_hScrollBar
->GetPageSize();
388 int sbPos
= stc
->m_hScrollBar
->GetThumbPosition();
389 if ((sbMax
!= horizEnd
) || (sbThumb
!= pageWidth
) || (sbPos
!= 0)) {
390 stc
->m_hScrollBar
->SetScrollbar(sbPos
, pageWidth
, horizEnd
, pageWidth
);
392 if (scrollWidth
< pageWidth
) {
393 HorizontalScrollTo(0);
402 void ScintillaWX::NotifyChange() {
407 void ScintillaWX::NotifyParent(SCNotification scn
) {
408 stc
->NotifyParent(&scn
);
412 // This method is overloaded from ScintillaBase in order to prevent the
413 // AutoComplete window from being destroyed when it gets the focus. There is
414 // a side effect that the AutoComp will also not be destroyed when switching
415 // to another window, but I think that is okay.
416 void ScintillaWX::CancelModes() {
418 AutoCompleteCancel();
420 Editor::CancelModes();
425 void ScintillaWX::Copy() {
426 if (currentPos
!= anchor
) {
428 CopySelectionRange(&st
);
434 void ScintillaWX::Paste() {
435 pdoc
->BeginUndoAction();
438 wxTextDataObject data
;
439 bool gotData
= false;
441 if (wxTheClipboard
->Open()) {
442 wxTheClipboard
->UsePrimarySelection(false);
443 gotData
= wxTheClipboard
->GetData(data
);
444 wxTheClipboard
->Close();
447 wxString text
= wxTextBuffer::Translate(data
.GetText(),
448 wxConvertEOLMode(pdoc
->eolMode
));
449 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
450 int len
= strlen(buf
);
451 pdoc
->InsertString(currentPos
, buf
, len
);
452 SetEmptySelection(currentPos
+ len
);
455 pdoc
->EndUndoAction();
461 void ScintillaWX::CopyToClipboard(const SelectionText
& st
) {
462 if (wxTheClipboard
->Open()) {
463 wxTheClipboard
->UsePrimarySelection(false);
464 wxString text
= wxTextBuffer::Translate(stc2wx(st
.s
, st
.len
));
465 wxTheClipboard
->SetData(new wxTextDataObject(text
));
466 wxTheClipboard
->Close();
471 bool ScintillaWX::CanPaste() {
472 bool canPaste
= false;
475 if (Editor::CanPaste()) {
476 didOpen
= !wxTheClipboard
->IsOpened();
478 wxTheClipboard
->Open();
480 if (wxTheClipboard
->IsOpened()) {
481 wxTheClipboard
->UsePrimarySelection(false);
482 canPaste
= wxTheClipboard
->IsSupported(wxUSE_UNICODE
? wxDF_UNICODETEXT
: wxDF_TEXT
);
484 wxTheClipboard
->Close();
490 void ScintillaWX::CreateCallTipWindow(PRectangle
) {
491 if (! ct
.wCallTip
.Created() ) {
492 ct
.wCallTip
= new wxSTCCallTip(stc
, &ct
, this);
493 ct
.wDraw
= ct
.wCallTip
;
498 void ScintillaWX::AddToPopUp(const char *label
, int cmd
, bool enabled
) {
500 ((wxMenu
*)popup
.GetID())->AppendSeparator();
502 ((wxMenu
*)popup
.GetID())->Append(cmd
, wxGetTranslation(stc2wx(label
)));
505 ((wxMenu
*)popup
.GetID())->Enable(cmd
, enabled
);
509 // This is called by the Editor base class whenever something is selected
510 void ScintillaWX::ClaimSelection() {
512 // Until wxGTK is able to support using both the primary selection and the
513 // clipboard at the same time I think it causes more problems than it is
514 // worth to implement this method. Selecting text should not clear the
515 // clipboard. --Robin
517 // Put the selected text in the PRIMARY selection
518 if (currentPos
!= anchor
) {
520 CopySelectionRange(&st
);
521 if (wxTheClipboard
->Open()) {
522 wxTheClipboard
->UsePrimarySelection(true);
523 wxString text
= stc2wx(st
.s
, st
.len
);
524 wxTheClipboard
->SetData(new wxTextDataObject(text
));
525 wxTheClipboard
->UsePrimarySelection(false);
526 wxTheClipboard
->Close();
534 void ScintillaWX::UpdateSystemCaret() {
537 if (HasCaretSizeChanged()) {
538 DestroySystemCaret();
541 Point pos
= LocationFromPosition(currentPos
);
542 ::SetCaretPos(pos
.x
, pos
.y
);
548 bool ScintillaWX::HasCaretSizeChanged() {
550 if (( (0 != vs
.caretWidth
) && (sysCaretWidth
!= vs
.caretWidth
) )
551 || (0 != vs
.lineHeight
) && (sysCaretHeight
!= vs
.lineHeight
)) {
558 bool ScintillaWX::CreateSystemCaret() {
560 sysCaretWidth
= vs
.caretWidth
;
561 if (0 == sysCaretWidth
) {
564 sysCaretHeight
= vs
.lineHeight
;
565 int bitmapSize
= (((sysCaretWidth
+ 15) & ~15) >> 3) * sysCaretHeight
;
566 char *bits
= new char[bitmapSize
];
567 memset(bits
, 0, bitmapSize
);
568 sysCaretBitmap
= ::CreateBitmap(sysCaretWidth
, sysCaretHeight
, 1,
569 1, reinterpret_cast<BYTE
*>(bits
));
571 BOOL retval
= ::CreateCaret(GetHwndOf(stc
), sysCaretBitmap
,
572 sysCaretWidth
, sysCaretHeight
);
573 ::ShowCaret(GetHwndOf(stc
));
580 bool ScintillaWX::DestroySystemCaret() {
582 ::HideCaret(GetHwndOf(stc
));
583 BOOL retval
= ::DestroyCaret();
584 if (sysCaretBitmap
) {
585 ::DeleteObject(sysCaretBitmap
);
595 //----------------------------------------------------------------------
598 long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {
602 long ScintillaWX::WndProc(unsigned int iMessage
, unsigned long wParam
, long lParam
) {
604 case SCI_CALLTIPSHOW
: {
605 // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
606 // because of the little tweak that needs done below for wxGTK.
607 // When updating new versions double check that this is still
608 // needed, and that any new code there is copied here too.
609 Point pt
= LocationFromPosition(wParam
);
610 char* defn
= reinterpret_cast<char *>(lParam
);
611 AutoCompleteCancel();
612 pt
.y
+= vs
.lineHeight
;
613 PRectangle rc
= ct
.CallTipStart(currentPos
, pt
,
615 vs
.styles
[STYLE_DEFAULT
].fontName
,
616 vs
.styles
[STYLE_DEFAULT
].sizeZoomed
,
618 vs
.styles
[STYLE_DEFAULT
].characterSet
,
620 // If the call-tip window would be out of the client
621 // space, adjust so it displays above the text.
622 PRectangle rcClient
= GetClientRectangle();
623 if (rc
.bottom
> rcClient
.bottom
) {
625 int offset
= int(vs
.lineHeight
* 1.25) + rc
.Height();
627 int offset
= vs
.lineHeight
+ rc
.Height();
632 // Now display the window.
633 CreateCallTipWindow(rc
);
634 ct
.wCallTip
.SetPositionRelative(rc
, wMain
);
640 case SCI_LOADLEXERLIBRARY
:
641 LexerManager::GetInstance()->Load((const char*)lParam
);
646 return ScintillaBase::WndProc(iMessage
, wParam
, lParam
);
653 //----------------------------------------------------------------------
656 void ScintillaWX::DoPaint(wxDC
* dc
, wxRect rect
) {
658 paintState
= painting
;
659 Surface
* surfaceWindow
= Surface::Allocate();
660 surfaceWindow
->Init(dc
, wMain
.GetID());
661 rcPaint
= PRectangleFromwxRect(rect
);
662 PRectangle rcClient
= GetClientRectangle();
663 paintingAllText
= rcPaint
.Contains(rcClient
);
666 ClipChildren(*dc
, rcPaint
);
667 Paint(surfaceWindow
, rcPaint
);
669 delete surfaceWindow
;
670 if (paintState
== paintAbandoned
) {
671 // Painting area was insufficient to cover new styling or brace
672 // highlight positions
675 paintState
= notPainting
;
680 void ScintillaWX::DoHScroll(int type
, int pos
) {
682 PRectangle rcText
= GetTextRectangle();
683 int pageWidth
= rcText
.Width() * 2 / 3;
684 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
685 xPos
-= H_SCROLL_STEP
;
686 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
687 xPos
+= H_SCROLL_STEP
;
688 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
690 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
) {
692 if (xPos
> scrollWidth
- rcText
.Width()) {
693 xPos
= scrollWidth
- rcText
.Width();
696 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
698 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
700 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
703 HorizontalScrollTo(xPos
);
706 void ScintillaWX::DoVScroll(int type
, int pos
) {
707 int topLineNew
= topLine
;
708 if (type
== wxEVT_SCROLLWIN_LINEUP
|| type
== wxEVT_SCROLL_LINEUP
)
710 else if (type
== wxEVT_SCROLLWIN_LINEDOWN
|| type
== wxEVT_SCROLL_LINEDOWN
)
712 else if (type
== wxEVT_SCROLLWIN_PAGEUP
|| type
== wxEVT_SCROLL_PAGEUP
)
713 topLineNew
-= LinesToScroll();
714 else if (type
== wxEVT_SCROLLWIN_PAGEDOWN
|| type
== wxEVT_SCROLL_PAGEDOWN
)
715 topLineNew
+= LinesToScroll();
716 else if (type
== wxEVT_SCROLLWIN_TOP
|| type
== wxEVT_SCROLL_TOP
)
718 else if (type
== wxEVT_SCROLLWIN_BOTTOM
|| type
== wxEVT_SCROLL_BOTTOM
)
719 topLineNew
= MaxScrollPos();
720 else if (type
== wxEVT_SCROLLWIN_THUMBTRACK
|| type
== wxEVT_SCROLL_THUMBTRACK
)
723 ScrollTo(topLineNew
);
726 void ScintillaWX::DoMouseWheel(int rotation
, int delta
,
727 int linesPerAction
, int ctrlDown
,
728 bool isPageScroll
) {
729 int topLineNew
= topLine
;
732 if (ctrlDown
) { // Zoom the fonts if Ctrl key down
734 KeyCommand(SCI_ZOOMIN
);
737 KeyCommand(SCI_ZOOMOUT
);
740 else { // otherwise just scroll the window
743 wheelRotation
+= rotation
;
744 lines
= wheelRotation
/ delta
;
745 wheelRotation
-= lines
* delta
;
748 lines
= lines
* LinesOnScreen(); // lines is either +1 or -1
750 lines
*= linesPerAction
;
752 ScrollTo(topLineNew
);
758 void ScintillaWX::DoSize(int WXUNUSED(width
), int WXUNUSED(height
)) {
762 void ScintillaWX::DoLoseFocus(){
764 SetFocusState(false);
766 DestroySystemCaret();
769 void ScintillaWX::DoGainFocus(){
773 DestroySystemCaret();
777 void ScintillaWX::DoSysColourChange() {
778 InvalidateStyleData();
781 void ScintillaWX::DoLeftButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
) {
782 ButtonDown(pt
, curTime
, shift
, ctrl
, alt
);
785 void ScintillaWX::DoLeftButtonUp(Point pt
, unsigned int curTime
, bool ctrl
) {
786 ButtonUp(pt
, curTime
, ctrl
);
789 void ScintillaWX::DoLeftButtonMove(Point pt
) {
794 void ScintillaWX::DoMiddleButtonUp(Point pt
) {
795 // Set the current position to the mouse click point and
796 // then paste in the PRIMARY selection, if any. wxGTK only.
797 int newPos
= PositionFromLocation(pt
);
798 MovePositionTo(newPos
, noSel
, true);
800 pdoc
->BeginUndoAction();
801 wxTextDataObject data
;
802 bool gotData
= false;
803 if (wxTheClipboard
->Open()) {
804 wxTheClipboard
->UsePrimarySelection(true);
805 gotData
= wxTheClipboard
->GetData(data
);
806 wxTheClipboard
->UsePrimarySelection(false);
807 wxTheClipboard
->Close();
810 wxString text
= wxTextBuffer::Translate(data
.GetText(),
811 wxConvertEOLMode(pdoc
->eolMode
));
812 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(text
);
813 int len
= strlen(buf
);
814 pdoc
->InsertString(currentPos
, buf
, len
);
815 SetEmptySelection(currentPos
+ len
);
817 pdoc
->EndUndoAction();
821 ShowCaretAtCurrentPosition();
822 EnsureCaretVisible();
825 void ScintillaWX::DoMiddleButtonUp(Point
WXUNUSED(pt
)) {
830 void ScintillaWX::DoAddChar(int key
) {
833 wszChars
[0] = (wxChar
)key
;
835 wxWX2MBbuf buf
= (wxWX2MBbuf
)wx2stc(wszChars
);
836 AddCharUTF((char*)buf
.data(), strlen(buf
));
843 int ScintillaWX::DoKeyDown(const wxKeyEvent
& evt
, bool* consumed
)
845 int key
= evt
.GetKeyCode();
846 bool shift
= evt
.ShiftDown(),
847 ctrl
= evt
.ControlDown(),
850 if (ctrl
&& key
>= 1 && key
<= 26)
854 case WXK_DOWN
: key
= SCK_DOWN
; break;
855 case WXK_UP
: key
= SCK_UP
; break;
856 case WXK_LEFT
: key
= SCK_LEFT
; break;
857 case WXK_RIGHT
: key
= SCK_RIGHT
; break;
858 case WXK_HOME
: key
= SCK_HOME
; break;
859 case WXK_END
: key
= SCK_END
; break;
860 case WXK_PAGEUP
: // fall through
861 case WXK_PRIOR
: key
= SCK_PRIOR
; break;
862 case WXK_PAGEDOWN
: // fall through
863 case WXK_NEXT
: key
= SCK_NEXT
; break;
864 case WXK_DELETE
: key
= SCK_DELETE
; break;
865 case WXK_INSERT
: key
= SCK_INSERT
; break;
866 case WXK_ESCAPE
: key
= SCK_ESCAPE
; break;
867 case WXK_BACK
: key
= SCK_BACK
; break;
868 case WXK_TAB
: key
= SCK_TAB
; break;
869 case WXK_NUMPAD_ENTER
: // fall through
870 case WXK_RETURN
: key
= SCK_RETURN
; break;
871 case WXK_ADD
: // fall through
872 case WXK_NUMPAD_ADD
: key
= SCK_ADD
; break;
873 case WXK_SUBTRACT
: // fall through
874 case WXK_NUMPAD_SUBTRACT
: key
= SCK_SUBTRACT
; break;
875 case WXK_DIVIDE
: // fall through
876 case WXK_NUMPAD_DIVIDE
: key
= SCK_DIVIDE
; break;
877 case WXK_CONTROL
: key
= 0; break;
878 case WXK_ALT
: key
= 0; break;
879 case WXK_SHIFT
: key
= 0; break;
880 case WXK_MENU
: key
= 0; break;
884 if ( evt
.MetaDown() ) {
885 // check for a few common Mac Meta-key combos and remap them to Ctrl
892 case 'A': // Select All
899 int rv
= KeyDown(key
, shift
, ctrl
, alt
, consumed
);
908 void ScintillaWX::DoCommand(int ID
) {
913 void ScintillaWX::DoContextMenu(Point pt
) {
914 if (displayPopupMenu
)
918 void ScintillaWX::DoOnListBox() {
919 AutoCompleteCompleted();
923 void ScintillaWX::DoOnIdle(wxIdleEvent
& evt
) {
931 //----------------------------------------------------------------------
933 #if wxUSE_DRAG_AND_DROP
934 bool ScintillaWX::DoDropText(long x
, long y
, const wxString
& data
) {
935 SetDragPosition(invalidPosition
);
937 wxString text
= wxTextBuffer::Translate(data
,
938 wxConvertEOLMode(pdoc
->eolMode
));
940 // Send an event to allow the drag details to be changed
941 wxStyledTextEvent
evt(wxEVT_STC_DO_DROP
, stc
->GetId());
942 evt
.SetEventObject(stc
);
943 evt
.SetDragResult(dragResult
);
946 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
947 evt
.SetDragText(text
);
948 stc
->GetEventHandler()->ProcessEvent(evt
);
950 dragResult
= evt
.GetDragResult();
951 if (dragResult
== wxDragMove
|| dragResult
== wxDragCopy
) {
952 DropAt(evt
.GetPosition(),
953 wx2stc(evt
.GetDragText()),
954 dragResult
== wxDragMove
,
955 false); // TODO: rectangular?
962 wxDragResult
ScintillaWX::DoDragEnter(wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
), wxDragResult def
) {
968 wxDragResult
ScintillaWX::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
969 SetDragPosition(PositionFromLocation(Point(x
, y
)));
971 // Send an event to allow the drag result to be changed
972 wxStyledTextEvent
evt(wxEVT_STC_DRAG_OVER
, stc
->GetId());
973 evt
.SetEventObject(stc
);
974 evt
.SetDragResult(def
);
977 evt
.SetPosition(PositionFromLocation(Point(x
,y
)));
978 stc
->GetEventHandler()->ProcessEvent(evt
);
980 dragResult
= evt
.GetDragResult();
985 void ScintillaWX::DoDragLeave() {
986 SetDragPosition(invalidPosition
);
989 //----------------------------------------------------------------------
991 // Force the whole window to be repainted
992 void ScintillaWX::FullPaint() {
1000 void ScintillaWX::DoScrollToLine(int line
) {
1005 void ScintillaWX::DoScrollToColumn(int column
) {
1006 HorizontalScrollTo(column
* vs
.spaceWidth
);
1010 void ScintillaWX::ClipChildren(wxDC
& dc
, PRectangle rect
) {
1011 wxRegion
rgn(wxRectFromPRectangle(rect
));
1013 wxRect childRect
= ((wxWindow
*)ac
.lb
->GetID())->GetRect();
1014 rgn
.Subtract(childRect
);
1016 if (ct
.inCallTipMode
) {
1017 wxSTCCallTip
* tip
= (wxSTCCallTip
*)ct
.wCallTip
.GetID();
1018 wxRect childRect
= tip
->GetRect();
1019 #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
1020 childRect
.SetPosition(tip
->GetMyPosition());
1022 rgn
.Subtract(childRect
);
1025 dc
.SetClippingRegion(rgn
);
1028 void ScintillaWX::ClipChildren(wxDC
& WXUNUSED(dc
), PRectangle
WXUNUSED(rect
)) {
1033 void ScintillaWX::SetUseAntiAliasing(bool useAA
) {
1034 vs
.extraFontFlag
= useAA
;
1035 InvalidateStyleRedraw();
1038 bool ScintillaWX::GetUseAntiAliasing() {
1039 return vs
.extraFontFlag
;
1042 //----------------------------------------------------------------------
1043 //----------------------------------------------------------------------