1 ////////////////////////////////////////////////////////////////////////////
3 // Purpose: A wxWidgets implementation of Scintilla. This class is the
4 // one meant to be used directly by wx applications. It does not
5 // derive directly from the Scintilla classes, but instead
6 // delegates most things to the real Scintilla class.
7 // This allows the use of Scintilla without polluting the
8 // namespace with all the classes and identifiers from Scintilla.
12 // Created: 13-Jan-2000
14 // Copyright: (c) 2000 by Total Control Software
15 // Licence: wxWindows license
16 /////////////////////////////////////////////////////////////////////////////
19 IMPORTANT: src/stc/stc.cpp is generated by src/stc/gen_iface.py from
20 src/stc/stc.cpp.in, don't edit stc.cpp file as your changes will be
21 lost after the next regeneration, edit stc.cpp.in and rerun the
22 gen_iface.py script instead!
24 Parts of this file generated by the script are found in between
25 the special "{{{" and "}}}" markers, the rest of it is copied
26 verbatim from src.h.in.
29 // For compilers that support precompilation, includes "wx.h".
30 #include "wx/wxprec.h"
38 #include "wx/stc/stc.h"
39 #include "wx/stc/private.h"
47 #include "wx/tokenzr.h"
48 #include "wx/mstream.h"
52 #include "ScintillaWX.h"
54 //----------------------------------------------------------------------
56 const wxChar
* wxSTCNameStr
= wxT("stcwindow");
62 #define MAKELONG(a, b) ((a) | ((b) << 16))
65 static long wxColourAsLong(const wxColour
& co
) {
66 return (((long)co
.Blue() << 16) |
67 ((long)co
.Green() << 8) |
71 static wxColour
wxColourFromLong(long c
) {
73 clr
.Set((unsigned char)(c
& 0xff),
74 (unsigned char)((c
>> 8) & 0xff),
75 (unsigned char)((c
>> 16) & 0xff));
80 static wxColour
wxColourFromSpec(const wxString
& spec
) {
81 // spec should be a colour name or "#RRGGBB"
82 if (spec
.GetChar(0) == wxT('#')) {
84 long red
, green
, blue
;
85 red
= green
= blue
= 0;
86 spec
.Mid(1,2).ToLong(&red
, 16);
87 spec
.Mid(3,2).ToLong(&green
, 16);
88 spec
.Mid(5,2).ToLong(&blue
, 16);
89 return wxColour((unsigned char)red
,
94 return wxColour(spec
);
97 //----------------------------------------------------------------------
99 DEFINE_EVENT_TYPE( wxEVT_STC_CHANGE
)
100 DEFINE_EVENT_TYPE( wxEVT_STC_STYLENEEDED
)
101 DEFINE_EVENT_TYPE( wxEVT_STC_CHARADDED
)
102 DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTREACHED
)
103 DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTLEFT
)
104 DEFINE_EVENT_TYPE( wxEVT_STC_ROMODIFYATTEMPT
)
105 DEFINE_EVENT_TYPE( wxEVT_STC_KEY
)
106 DEFINE_EVENT_TYPE( wxEVT_STC_DOUBLECLICK
)
107 DEFINE_EVENT_TYPE( wxEVT_STC_UPDATEUI
)
108 DEFINE_EVENT_TYPE( wxEVT_STC_MODIFIED
)
109 DEFINE_EVENT_TYPE( wxEVT_STC_MACRORECORD
)
110 DEFINE_EVENT_TYPE( wxEVT_STC_MARGINCLICK
)
111 DEFINE_EVENT_TYPE( wxEVT_STC_NEEDSHOWN
)
112 DEFINE_EVENT_TYPE( wxEVT_STC_PAINTED
)
113 DEFINE_EVENT_TYPE( wxEVT_STC_USERLISTSELECTION
)
114 DEFINE_EVENT_TYPE( wxEVT_STC_URIDROPPED
)
115 DEFINE_EVENT_TYPE( wxEVT_STC_DWELLSTART
)
116 DEFINE_EVENT_TYPE( wxEVT_STC_DWELLEND
)
117 DEFINE_EVENT_TYPE( wxEVT_STC_START_DRAG
)
118 DEFINE_EVENT_TYPE( wxEVT_STC_DRAG_OVER
)
119 DEFINE_EVENT_TYPE( wxEVT_STC_DO_DROP
)
120 DEFINE_EVENT_TYPE( wxEVT_STC_ZOOM
)
121 DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_CLICK
)
122 DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_DCLICK
)
123 DEFINE_EVENT_TYPE( wxEVT_STC_CALLTIP_CLICK
)
124 DEFINE_EVENT_TYPE( wxEVT_STC_AUTOCOMP_SELECTION
)
125 DEFINE_EVENT_TYPE( wxEVT_STC_INDICATOR_CLICK
)
126 DEFINE_EVENT_TYPE( wxEVT_STC_INDICATOR_RELEASE
)
130 BEGIN_EVENT_TABLE(wxStyledTextCtrl
, wxControl
)
131 EVT_PAINT (wxStyledTextCtrl::OnPaint
)
132 EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin
)
133 EVT_SCROLL (wxStyledTextCtrl::OnScroll
)
134 EVT_SIZE (wxStyledTextCtrl::OnSize
)
135 EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown
)
136 // Let Scintilla see the double click as a second click
137 EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown
)
138 EVT_MOTION (wxStyledTextCtrl::OnMouseMove
)
139 EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp
)
140 #if defined(__WXGTK__) || defined(__WXMAC__)
141 EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp
)
143 EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu
)
145 EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel
)
146 EVT_MIDDLE_UP (wxStyledTextCtrl::OnMouseMiddleUp
)
147 EVT_CHAR (wxStyledTextCtrl::OnChar
)
148 EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown
)
149 EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus
)
150 EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus
)
151 EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged
)
152 EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground
)
153 EVT_MENU_RANGE (10, 16, wxStyledTextCtrl::OnMenu
)
154 EVT_LISTBOX_DCLICK (wxID_ANY
, wxStyledTextCtrl::OnListBox
)
158 IMPLEMENT_CLASS(wxStyledTextCtrl
, wxControl
)
159 IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent
, wxCommandEvent
)
162 // forces the linking of the lexer modules
163 int Scintilla_LinkLexers();
166 //----------------------------------------------------------------------
167 // Constructor and Destructor
169 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow
*parent
,
174 const wxString
& name
)
177 Create(parent
, id
, pos
, size
, style
, name
);
181 bool wxStyledTextCtrl::Create(wxWindow
*parent
,
186 const wxString
& name
)
188 style
|= wxVSCROLL
| wxHSCROLL
;
189 if (!wxControl::Create(parent
, id
, pos
, size
,
190 style
| wxWANTS_CHARS
| wxCLIP_CHILDREN
,
191 wxDefaultValidator
, name
))
195 Scintilla_LinkLexers();
197 m_swx
= new ScintillaWX(this);
199 m_lastKeyDownConsumed
= false;
200 m_lastWheelTimestamp
= 0;
204 // Put Scintilla into unicode (UTF-8) mode
205 SetCodePage(wxSTC_CP_UTF8
);
208 SetInitialSize(size
);
210 // Reduces flicker on GTK+/X11
211 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
213 // Make sure it can take the focus
220 wxStyledTextCtrl::~wxStyledTextCtrl() {
225 //----------------------------------------------------------------------
227 wxIntPtr
wxStyledTextCtrl::SendMsg(int msg
, wxUIntPtr wp
, wxIntPtr lp
) const
229 return m_swx
->WndProc(msg
, wp
, lp
);
232 //----------------------------------------------------------------------
234 // Set the vertical scrollbar to use instead of the ont that's built-in.
235 void wxStyledTextCtrl::SetVScrollBar(wxScrollBar
* bar
) {
238 // ensure that the built-in scrollbar is not visible
239 SetScrollbar(wxVERTICAL
, 0, 0, 0);
244 // Set the horizontal scrollbar to use instead of the ont that's built-in.
245 void wxStyledTextCtrl::SetHScrollBar(wxScrollBar
* bar
) {
248 // ensure that the built-in scrollbar is not visible
249 SetScrollbar(wxHORIZONTAL
, 0, 0, 0);
253 //----------------------------------------------------------------------
254 // Generated methods implementation section {{{
259 //----------------------------------------------------------------------
262 // Returns the line number of the line with the caret.
263 int wxStyledTextCtrl::GetCurrentLine() {
264 int line
= LineFromPosition(GetCurrentPos());
269 // Extract style settings from a spec-string which is composed of one or
270 // more of the following comma separated elements:
272 // bold turns on bold
273 // italic turns on italics
274 // fore:[name or #RRGGBB] sets the foreground colour
275 // back:[name or #RRGGBB] sets the background colour
276 // face:[facename] sets the font face name to use
277 // size:[num] sets the font size in points
278 // eol turns on eol filling
279 // underline turns on underlining
281 void wxStyledTextCtrl::StyleSetSpec(int styleNum
, const wxString
& spec
) {
283 wxStringTokenizer
tkz(spec
, wxT(","));
284 while (tkz
.HasMoreTokens()) {
285 wxString token
= tkz
.GetNextToken();
287 wxString option
= token
.BeforeFirst(':');
288 wxString val
= token
.AfterFirst(':');
290 if (option
== wxT("bold"))
291 StyleSetBold(styleNum
, true);
293 else if (option
== wxT("italic"))
294 StyleSetItalic(styleNum
, true);
296 else if (option
== wxT("underline"))
297 StyleSetUnderline(styleNum
, true);
299 else if (option
== wxT("eol"))
300 StyleSetEOLFilled(styleNum
, true);
302 else if (option
== wxT("size")) {
304 if (val
.ToLong(&points
))
305 StyleSetSize(styleNum
, points
);
308 else if (option
== wxT("face"))
309 StyleSetFaceName(styleNum
, val
);
311 else if (option
== wxT("fore"))
312 StyleSetForeground(styleNum
, wxColourFromSpec(val
));
314 else if (option
== wxT("back"))
315 StyleSetBackground(styleNum
, wxColourFromSpec(val
));
320 // Get the font of a style
321 wxFont
wxStyledTextCtrl::StyleGetFont(int style
) {
323 font
.SetPointSize(StyleGetSize(style
));
324 font
.SetFaceName(StyleGetFaceName(style
));
325 if( StyleGetBold(style
) )
326 font
.SetWeight(wxFONTWEIGHT_BOLD
);
328 font
.SetWeight(wxFONTWEIGHT_NORMAL
);
330 if( StyleGetItalic(style
) )
331 font
.SetStyle(wxFONTSTYLE_ITALIC
);
333 font
.SetStyle(wxFONTSTYLE_NORMAL
);
339 // Set style size, face, bold, italic, and underline attributes from
340 // a wxFont's attributes.
341 void wxStyledTextCtrl::StyleSetFont(int styleNum
, wxFont
& font
) {
343 // Ensure that the native font is initialized
345 GetTextExtent(wxT("X"), &x
, &y
, NULL
, NULL
, &font
);
347 int size
= font
.GetPointSize();
348 wxString faceName
= font
.GetFaceName();
349 bool bold
= font
.GetWeight() == wxBOLD
;
350 bool italic
= font
.GetStyle() != wxNORMAL
;
351 bool under
= font
.GetUnderlined();
352 wxFontEncoding encoding
= font
.GetEncoding();
354 StyleSetFontAttr(styleNum
, size
, faceName
, bold
, italic
, under
, encoding
);
357 // Set all font style attributes at once.
358 void wxStyledTextCtrl::StyleSetFontAttr(int styleNum
, int size
,
359 const wxString
& faceName
,
360 bool bold
, bool italic
,
362 wxFontEncoding encoding
) {
363 StyleSetSize(styleNum
, size
);
364 StyleSetFaceName(styleNum
, faceName
);
365 StyleSetBold(styleNum
, bold
);
366 StyleSetItalic(styleNum
, italic
);
367 StyleSetUnderline(styleNum
, underline
);
368 StyleSetFontEncoding(styleNum
, encoding
);
372 // Set the character set of the font in a style. Converts the Scintilla
373 // character set values to a wxFontEncoding.
374 void wxStyledTextCtrl::StyleSetCharacterSet(int style
, int characterSet
)
376 wxFontEncoding encoding
;
378 // Translate the Scintilla characterSet to a wxFontEncoding
379 switch (characterSet
) {
381 case wxSTC_CHARSET_ANSI
:
382 case wxSTC_CHARSET_DEFAULT
:
383 encoding
= wxFONTENCODING_DEFAULT
;
386 case wxSTC_CHARSET_BALTIC
:
387 encoding
= wxFONTENCODING_ISO8859_13
;
390 case wxSTC_CHARSET_CHINESEBIG5
:
391 encoding
= wxFONTENCODING_CP950
;
394 case wxSTC_CHARSET_EASTEUROPE
:
395 encoding
= wxFONTENCODING_ISO8859_2
;
398 case wxSTC_CHARSET_GB2312
:
399 encoding
= wxFONTENCODING_CP936
;
402 case wxSTC_CHARSET_GREEK
:
403 encoding
= wxFONTENCODING_ISO8859_7
;
406 case wxSTC_CHARSET_HANGUL
:
407 encoding
= wxFONTENCODING_CP949
;
410 case wxSTC_CHARSET_MAC
:
411 encoding
= wxFONTENCODING_DEFAULT
;
414 case wxSTC_CHARSET_OEM
:
415 encoding
= wxFONTENCODING_DEFAULT
;
418 case wxSTC_CHARSET_RUSSIAN
:
419 encoding
= wxFONTENCODING_KOI8
;
422 case wxSTC_CHARSET_SHIFTJIS
:
423 encoding
= wxFONTENCODING_CP932
;
426 case wxSTC_CHARSET_SYMBOL
:
427 encoding
= wxFONTENCODING_DEFAULT
;
430 case wxSTC_CHARSET_TURKISH
:
431 encoding
= wxFONTENCODING_ISO8859_9
;
434 case wxSTC_CHARSET_JOHAB
:
435 encoding
= wxFONTENCODING_DEFAULT
;
438 case wxSTC_CHARSET_HEBREW
:
439 encoding
= wxFONTENCODING_ISO8859_8
;
442 case wxSTC_CHARSET_ARABIC
:
443 encoding
= wxFONTENCODING_ISO8859_6
;
446 case wxSTC_CHARSET_VIETNAMESE
:
447 encoding
= wxFONTENCODING_DEFAULT
;
450 case wxSTC_CHARSET_THAI
:
451 encoding
= wxFONTENCODING_ISO8859_11
;
454 case wxSTC_CHARSET_CYRILLIC
:
455 encoding
= wxFONTENCODING_ISO8859_5
;
458 case wxSTC_CHARSET_8859_15
:
459 encoding
= wxFONTENCODING_ISO8859_15
;;
463 // We just have Scintilla track the wxFontEncoding for us. It gets used
464 // in Font::Create in PlatWX.cpp. We add one to the value so that the
465 // effective wxFONENCODING_DEFAULT == SC_SHARSET_DEFAULT and so when
466 // Scintilla internally uses SC_CHARSET_DEFAULT we will translate it back
467 // to wxFONENCODING_DEFAULT in Font::Create.
468 SendMsg(SCI_STYLESETCHARACTERSET
, style
, encoding
+1);
472 // Set the font encoding to be used by a style.
473 void wxStyledTextCtrl::StyleSetFontEncoding(int style
, wxFontEncoding encoding
)
475 SendMsg(SCI_STYLESETCHARACTERSET
, style
, encoding
+1);
479 // Perform one of the operations defined by the wxSTC_CMD_* constants.
480 void wxStyledTextCtrl::CmdKeyExecute(int cmd
) {
485 // Set the left and right margin in the edit area, measured in pixels.
486 void wxStyledTextCtrl::SetMargins(int left
, int right
) {
488 SetMarginRight(right
);
492 // Retrieve the start and end positions of the current selection.
493 void wxStyledTextCtrl::GetSelection(int* startPos
, int* endPos
) {
494 if (startPos
!= NULL
)
495 *startPos
= SendMsg(SCI_GETSELECTIONSTART
);
497 *endPos
= SendMsg(SCI_GETSELECTIONEND
);
501 // Retrieve the point in the window where a position is displayed.
502 wxPoint
wxStyledTextCtrl::PointFromPosition(int pos
) {
503 int x
= SendMsg(SCI_POINTXFROMPOSITION
, 0, pos
);
504 int y
= SendMsg(SCI_POINTYFROMPOSITION
, 0, pos
);
505 return wxPoint(x
, y
);
508 // Scroll enough to make the given line visible
509 void wxStyledTextCtrl::ScrollToLine(int line
) {
510 m_swx
->DoScrollToLine(line
);
514 // Scroll enough to make the given column visible
515 void wxStyledTextCtrl::ScrollToColumn(int column
) {
516 m_swx
->DoScrollToColumn(column
);
521 bool wxStyledTextCtrl::DoSaveFile(const wxString
& filename
, int WXUNUSED(fileType
))
523 bool wxStyledTextCtrl::SaveFile(const wxString
& filename
)
526 wxFile
file(filename
, wxFile::write
);
528 if (!file
.IsOpened())
531 bool success
= file
.Write(GetText(), *wxConvCurrent
);
540 bool wxStyledTextCtrl::DoLoadFile(const wxString
& filename
, int WXUNUSED(fileType
))
542 bool wxStyledTextCtrl::LoadFile(const wxString
& filename
)
545 bool success
= false;
546 wxFile
file(filename
, wxFile::read
);
551 // get the file size (assume it is not huge file...)
552 ssize_t len
= (ssize_t
)file
.Length();
557 wxMemoryBuffer
buffer(len
+1);
558 success
= (file
.Read(buffer
.GetData(), len
) == len
);
560 ((char*)buffer
.GetData())[len
] = 0;
561 contents
= wxString(buffer
, *wxConvCurrent
, len
);
565 success
= (file
.Read(wxStringBuffer(buffer
, len
), len
) == len
);
572 success
= true; // empty file is ok
574 success
= false; // len == wxInvalidOffset
589 #if wxUSE_DRAG_AND_DROP
590 wxDragResult
wxStyledTextCtrl::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
591 return m_swx
->DoDragOver(x
, y
, def
);
595 bool wxStyledTextCtrl::DoDropText(long x
, long y
, const wxString
& data
) {
596 return m_swx
->DoDropText(x
, y
, data
);
601 void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA
) {
602 m_swx
->SetUseAntiAliasing(useAA
);
605 bool wxStyledTextCtrl::GetUseAntiAliasing() {
606 return m_swx
->GetUseAntiAliasing();
613 void wxStyledTextCtrl::AddTextRaw(const char* text
)
615 SendMsg(SCI_ADDTEXT
, strlen(text
), (sptr_t
)text
);
618 void wxStyledTextCtrl::InsertTextRaw(int pos
, const char* text
)
620 SendMsg(SCI_INSERTTEXT
, pos
, (sptr_t
)text
);
623 wxCharBuffer
wxStyledTextCtrl::GetCurLineRaw(int* linePos
)
625 int len
= LineLength(GetCurrentLine());
627 if (linePos
) *linePos
= 0;
632 wxCharBuffer
buf(len
);
633 int pos
= SendMsg(SCI_GETCURLINE
, len
, (sptr_t
)buf
.data());
634 if (linePos
) *linePos
= pos
;
638 wxCharBuffer
wxStyledTextCtrl::GetLineRaw(int line
)
640 int len
= LineLength(line
);
646 wxCharBuffer
buf(len
);
647 SendMsg(SCI_GETLINE
, line
, (sptr_t
)buf
.data());
651 wxCharBuffer
wxStyledTextCtrl::GetSelectedTextRaw()
656 GetSelection(&start
, &end
);
657 int len
= end
- start
;
663 wxCharBuffer
buf(len
);
664 SendMsg(SCI_GETSELTEXT
, 0, (sptr_t
)buf
.data());
668 wxCharBuffer
wxStyledTextCtrl::GetTextRangeRaw(int startPos
, int endPos
)
670 if (endPos
< startPos
) {
675 int len
= endPos
- startPos
;
681 wxCharBuffer
buf(len
);
683 tr
.lpstrText
= buf
.data();
684 tr
.chrg
.cpMin
= startPos
;
685 tr
.chrg
.cpMax
= endPos
;
686 SendMsg(SCI_GETTEXTRANGE
, 0, (sptr_t
)&tr
);
690 void wxStyledTextCtrl::SetTextRaw(const char* text
)
692 SendMsg(SCI_SETTEXT
, 0, (sptr_t
)text
);
695 wxCharBuffer
wxStyledTextCtrl::GetTextRaw()
697 int len
= GetTextLength();
698 wxCharBuffer
buf(len
); // adds 1 for NUL automatically
699 SendMsg(SCI_GETTEXT
, len
+ 1, (sptr_t
)buf
.data());
703 void wxStyledTextCtrl::AppendTextRaw(const char* text
)
705 SendMsg(SCI_APPENDTEXT
, strlen(text
), (sptr_t
)text
);
712 //----------------------------------------------------------------------
715 void wxStyledTextCtrl::OnPaint(wxPaintEvent
& WXUNUSED(evt
)) {
717 m_swx
->DoPaint(&dc
, GetUpdateRegion().GetBox());
720 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent
& evt
) {
721 if (evt
.GetOrientation() == wxHORIZONTAL
)
722 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
724 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
727 void wxStyledTextCtrl::OnScroll(wxScrollEvent
& evt
) {
728 wxScrollBar
* sb
= wxDynamicCast(evt
.GetEventObject(), wxScrollBar
);
730 if (sb
->IsVertical())
731 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
733 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
737 void wxStyledTextCtrl::OnSize(wxSizeEvent
& WXUNUSED(evt
)) {
739 wxSize sz
= GetClientSize();
740 m_swx
->DoSize(sz
.x
, sz
.y
);
744 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent
& evt
) {
746 wxPoint pt
= evt
.GetPosition();
747 m_swx
->DoLeftButtonDown(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
748 evt
.ShiftDown(), evt
.ControlDown(), evt
.AltDown());
751 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent
& evt
) {
752 wxPoint pt
= evt
.GetPosition();
753 m_swx
->DoLeftButtonMove(Point(pt
.x
, pt
.y
));
756 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent
& evt
) {
757 wxPoint pt
= evt
.GetPosition();
758 m_swx
->DoLeftButtonUp(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
763 void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent
& evt
) {
764 wxPoint pt
= evt
.GetPosition();
765 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
769 void wxStyledTextCtrl::OnMouseMiddleUp(wxMouseEvent
& evt
) {
770 wxPoint pt
= evt
.GetPosition();
771 m_swx
->DoMiddleButtonUp(Point(pt
.x
, pt
.y
));
774 void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent
& evt
) {
775 wxPoint pt
= evt
.GetPosition();
776 ScreenToClient(&pt
.x
, &pt
.y
);
778 Show context menu at event point if it's within the window,
779 or at caret location if not
781 wxHitTest ht
= this->HitTest(pt
);
782 if (ht
!= wxHT_WINDOW_INSIDE
) {
783 pt
= this->PointFromPosition(this->GetCurrentPos());
785 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
789 void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent
& evt
)
791 // prevent having an event queue with wheel events that cannot be processed
792 // reasonably fast (see ticket #9057)
793 if ( m_lastWheelTimestamp
<= evt
.GetTimestamp() )
795 m_lastWheelTimestamp
= m_stopWatch
.Time();
796 m_swx
->DoMouseWheel(evt
.GetWheelRotation(),
798 evt
.GetLinesPerAction(),
801 m_lastWheelTimestamp
= m_stopWatch
.Time() - m_lastWheelTimestamp
;
802 m_lastWheelTimestamp
+= evt
.GetTimestamp();
807 void wxStyledTextCtrl::OnChar(wxKeyEvent
& evt
) {
808 // On (some?) non-US PC keyboards the AltGr key is required to enter some
809 // common characters. It comes to us as both Alt and Ctrl down so we need
810 // to let the char through in that case, otherwise if only ctrl or only
811 // alt let's skip it.
812 bool ctrl
= evt
.ControlDown();
814 // On the Mac the Alt key is just a modifier key (like Shift) so we need
815 // to allow the char events to be processed when Alt is pressed.
816 // TODO: Should we check MetaDown instead in this case?
819 bool alt
= evt
.AltDown();
821 bool skip
= ((ctrl
|| alt
) && ! (ctrl
&& alt
));
824 // apparently if we don't do this, Unicode keys pressed after non-char
825 // ASCII ones (e.g. Enter, Tab) are not taken into account (patch 1615989)
826 if (m_lastKeyDownConsumed
&& evt
.GetUnicodeKey() > 255)
827 m_lastKeyDownConsumed
= false;
830 if (!m_lastKeyDownConsumed
&& !skip
) {
832 int key
= evt
.GetUnicodeKey();
835 // if the unicode key code is not really a unicode character (it may
836 // be a function key or etc., the platforms appear to always give us a
837 // small value in this case) then fallback to the ascii key code but
838 // don't do anything for function keys or etc.
840 key
= evt
.GetKeyCode();
841 keyOk
= (key
<= 127);
844 m_swx
->DoAddChar(key
);
848 int key
= evt
.GetKeyCode();
849 if (key
<= WXK_START
|| key
> WXK_COMMAND
) {
850 m_swx
->DoAddChar(key
);
860 void wxStyledTextCtrl::OnKeyDown(wxKeyEvent
& evt
) {
861 int processed
= m_swx
->DoKeyDown(evt
, &m_lastKeyDownConsumed
);
862 if (!processed
&& !m_lastKeyDownConsumed
)
867 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent
& evt
) {
868 m_swx
->DoLoseFocus();
873 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent
& evt
) {
874 m_swx
->DoGainFocus();
879 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(evt
)) {
880 m_swx
->DoSysColourChange();
884 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
)) {
885 // do nothing to help avoid flashing
890 void wxStyledTextCtrl::OnMenu(wxCommandEvent
& evt
) {
891 m_swx
->DoCommand(evt
.GetId());
895 void wxStyledTextCtrl::OnListBox(wxCommandEvent
& WXUNUSED(evt
)) {
896 m_swx
->DoOnListBox();
900 void wxStyledTextCtrl::OnIdle(wxIdleEvent
& evt
) {
901 m_swx
->DoOnIdle(evt
);
905 wxSize
wxStyledTextCtrl::DoGetBestSize() const
907 // What would be the best size for a wxSTC?
908 // Just give a reasonable minimum until something else can be figured out.
909 return wxSize(200,100);
913 //----------------------------------------------------------------------
914 // Turn notifications from Scintilla into events
917 void wxStyledTextCtrl::NotifyChange() {
918 wxStyledTextEvent
evt(wxEVT_STC_CHANGE
, GetId());
919 evt
.SetEventObject(this);
920 GetEventHandler()->ProcessEvent(evt
);
924 static void SetEventText(wxStyledTextEvent
& evt
, const char* text
,
928 evt
.SetText(stc2wx(text
, length
));
932 void wxStyledTextCtrl::NotifyParent(SCNotification
* _scn
) {
933 SCNotification
& scn
= *_scn
;
934 wxStyledTextEvent
evt(0, GetId());
936 evt
.SetEventObject(this);
937 evt
.SetPosition(scn
.position
);
939 evt
.SetModifiers(scn
.modifiers
);
941 switch (scn
.nmhdr
.code
) {
942 case SCN_STYLENEEDED
:
943 evt
.SetEventType(wxEVT_STC_STYLENEEDED
);
947 evt
.SetEventType(wxEVT_STC_CHARADDED
);
950 case SCN_SAVEPOINTREACHED
:
951 evt
.SetEventType(wxEVT_STC_SAVEPOINTREACHED
);
954 case SCN_SAVEPOINTLEFT
:
955 evt
.SetEventType(wxEVT_STC_SAVEPOINTLEFT
);
958 case SCN_MODIFYATTEMPTRO
:
959 evt
.SetEventType(wxEVT_STC_ROMODIFYATTEMPT
);
963 evt
.SetEventType(wxEVT_STC_KEY
);
966 case SCN_DOUBLECLICK
:
967 evt
.SetEventType(wxEVT_STC_DOUBLECLICK
);
971 evt
.SetEventType(wxEVT_STC_UPDATEUI
);
975 evt
.SetEventType(wxEVT_STC_MODIFIED
);
976 evt
.SetModificationType(scn
.modificationType
);
977 SetEventText(evt
, scn
.text
, scn
.length
);
978 evt
.SetLength(scn
.length
);
979 evt
.SetLinesAdded(scn
.linesAdded
);
980 evt
.SetLine(scn
.line
);
981 evt
.SetFoldLevelNow(scn
.foldLevelNow
);
982 evt
.SetFoldLevelPrev(scn
.foldLevelPrev
);
985 case SCN_MACRORECORD
:
986 evt
.SetEventType(wxEVT_STC_MACRORECORD
);
987 evt
.SetMessage(scn
.message
);
988 evt
.SetWParam(scn
.wParam
);
989 evt
.SetLParam(scn
.lParam
);
992 case SCN_MARGINCLICK
:
993 evt
.SetEventType(wxEVT_STC_MARGINCLICK
);
994 evt
.SetMargin(scn
.margin
);
998 evt
.SetEventType(wxEVT_STC_NEEDSHOWN
);
999 evt
.SetLength(scn
.length
);
1003 evt
.SetEventType(wxEVT_STC_PAINTED
);
1006 case SCN_AUTOCSELECTION
:
1007 evt
.SetEventType(wxEVT_STC_AUTOCOMP_SELECTION
);
1008 evt
.SetListType(scn
.listType
);
1009 SetEventText(evt
, scn
.text
, strlen(scn
.text
));
1010 evt
.SetPosition(scn
.lParam
);
1013 case SCN_USERLISTSELECTION
:
1014 evt
.SetEventType(wxEVT_STC_USERLISTSELECTION
);
1015 evt
.SetListType(scn
.listType
);
1016 SetEventText(evt
, scn
.text
, strlen(scn
.text
));
1017 evt
.SetPosition(scn
.lParam
);
1020 case SCN_URIDROPPED
:
1021 evt
.SetEventType(wxEVT_STC_URIDROPPED
);
1022 SetEventText(evt
, scn
.text
, strlen(scn
.text
));
1025 case SCN_DWELLSTART
:
1026 evt
.SetEventType(wxEVT_STC_DWELLSTART
);
1032 evt
.SetEventType(wxEVT_STC_DWELLEND
);
1038 evt
.SetEventType(wxEVT_STC_ZOOM
);
1041 case SCN_HOTSPOTCLICK
:
1042 evt
.SetEventType(wxEVT_STC_HOTSPOT_CLICK
);
1045 case SCN_HOTSPOTDOUBLECLICK
:
1046 evt
.SetEventType(wxEVT_STC_HOTSPOT_DCLICK
);
1049 case SCN_CALLTIPCLICK
:
1050 evt
.SetEventType(wxEVT_STC_CALLTIP_CLICK
);
1053 case SCN_INDICATORCLICK
:
1054 evt
.SetEventType(wxEVT_STC_INDICATOR_CLICK
);
1057 case SCN_INDICATORRELEASE
:
1058 evt
.SetEventType(wxEVT_STC_INDICATOR_RELEASE
);
1065 GetEventHandler()->ProcessEvent(evt
);
1069 //----------------------------------------------------------------------
1070 //----------------------------------------------------------------------
1071 //----------------------------------------------------------------------
1073 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType
, int id
)
1074 : wxCommandEvent(commandType
, id
)
1079 m_modificationType
= 0;
1084 m_foldLevelPrev
= 0;
1092 m_dragAllowMove
= false;
1093 #if wxUSE_DRAG_AND_DROP
1094 m_dragResult
= wxDragNone
;
1098 bool wxStyledTextEvent::GetShift() const { return (m_modifiers
& SCI_SHIFT
) != 0; }
1099 bool wxStyledTextEvent::GetControl() const { return (m_modifiers
& SCI_CTRL
) != 0; }
1100 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers
& SCI_ALT
) != 0; }
1103 wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent
& event
):
1104 wxCommandEvent(event
)
1106 m_position
= event
.m_position
;
1107 m_key
= event
.m_key
;
1108 m_modifiers
= event
.m_modifiers
;
1109 m_modificationType
= event
.m_modificationType
;
1110 m_text
= event
.m_text
;
1111 m_length
= event
.m_length
;
1112 m_linesAdded
= event
.m_linesAdded
;
1113 m_line
= event
.m_line
;
1114 m_foldLevelNow
= event
.m_foldLevelNow
;
1115 m_foldLevelPrev
= event
.m_foldLevelPrev
;
1117 m_margin
= event
.m_margin
;
1119 m_message
= event
.m_message
;
1120 m_wParam
= event
.m_wParam
;
1121 m_lParam
= event
.m_lParam
;
1123 m_listType
= event
.m_listType
;
1127 m_dragText
= event
.m_dragText
;
1128 m_dragAllowMove
=event
.m_dragAllowMove
;
1129 #if wxUSE_DRAG_AND_DROP
1130 m_dragResult
= event
.m_dragResult
;
1134 //----------------------------------------------------------------------
1135 //----------------------------------------------------------------------