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 licence
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 char wxSTCNameStr
[] = "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 wxDEFINE_EVENT( wxEVT_STC_CHANGE
, wxStyledTextEvent
);
100 wxDEFINE_EVENT( wxEVT_STC_STYLENEEDED
, wxStyledTextEvent
);
101 wxDEFINE_EVENT( wxEVT_STC_CHARADDED
, wxStyledTextEvent
);
102 wxDEFINE_EVENT( wxEVT_STC_SAVEPOINTREACHED
, wxStyledTextEvent
);
103 wxDEFINE_EVENT( wxEVT_STC_SAVEPOINTLEFT
, wxStyledTextEvent
);
104 wxDEFINE_EVENT( wxEVT_STC_ROMODIFYATTEMPT
, wxStyledTextEvent
);
105 wxDEFINE_EVENT( wxEVT_STC_KEY
, wxStyledTextEvent
);
106 wxDEFINE_EVENT( wxEVT_STC_DOUBLECLICK
, wxStyledTextEvent
);
107 wxDEFINE_EVENT( wxEVT_STC_UPDATEUI
, wxStyledTextEvent
);
108 wxDEFINE_EVENT( wxEVT_STC_MODIFIED
, wxStyledTextEvent
);
109 wxDEFINE_EVENT( wxEVT_STC_MACRORECORD
, wxStyledTextEvent
);
110 wxDEFINE_EVENT( wxEVT_STC_MARGINCLICK
, wxStyledTextEvent
);
111 wxDEFINE_EVENT( wxEVT_STC_NEEDSHOWN
, wxStyledTextEvent
);
112 wxDEFINE_EVENT( wxEVT_STC_PAINTED
, wxStyledTextEvent
);
113 wxDEFINE_EVENT( wxEVT_STC_USERLISTSELECTION
, wxStyledTextEvent
);
114 wxDEFINE_EVENT( wxEVT_STC_URIDROPPED
, wxStyledTextEvent
);
115 wxDEFINE_EVENT( wxEVT_STC_DWELLSTART
, wxStyledTextEvent
);
116 wxDEFINE_EVENT( wxEVT_STC_DWELLEND
, wxStyledTextEvent
);
117 wxDEFINE_EVENT( wxEVT_STC_START_DRAG
, wxStyledTextEvent
);
118 wxDEFINE_EVENT( wxEVT_STC_DRAG_OVER
, wxStyledTextEvent
);
119 wxDEFINE_EVENT( wxEVT_STC_DO_DROP
, wxStyledTextEvent
);
120 wxDEFINE_EVENT( wxEVT_STC_ZOOM
, wxStyledTextEvent
);
121 wxDEFINE_EVENT( wxEVT_STC_HOTSPOT_CLICK
, wxStyledTextEvent
);
122 wxDEFINE_EVENT( wxEVT_STC_HOTSPOT_DCLICK
, wxStyledTextEvent
);
123 wxDEFINE_EVENT( wxEVT_STC_CALLTIP_CLICK
, wxStyledTextEvent
);
124 wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_SELECTION
, wxStyledTextEvent
);
125 wxDEFINE_EVENT( wxEVT_STC_INDICATOR_CLICK
, wxStyledTextEvent
);
126 wxDEFINE_EVENT( wxEVT_STC_INDICATOR_RELEASE
, wxStyledTextEvent
);
127 wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_CANCELLED
, wxStyledTextEvent
);
128 wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_CHAR_DELETED
, wxStyledTextEvent
);
129 wxDEFINE_EVENT( wxEVT_STC_HOTSPOT_RELEASE_CLICK
, wxStyledTextEvent
);
133 BEGIN_EVENT_TABLE(wxStyledTextCtrl
, wxControl
)
134 EVT_PAINT (wxStyledTextCtrl::OnPaint
)
135 EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin
)
136 EVT_SCROLL (wxStyledTextCtrl::OnScroll
)
137 EVT_SIZE (wxStyledTextCtrl::OnSize
)
138 EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown
)
139 // Let Scintilla see the double click as a second click
140 EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown
)
141 EVT_MOTION (wxStyledTextCtrl::OnMouseMove
)
142 EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp
)
143 #if defined(__WXGTK__) || defined(__WXMAC__)
144 EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp
)
146 EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu
)
148 EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel
)
149 EVT_MIDDLE_UP (wxStyledTextCtrl::OnMouseMiddleUp
)
150 EVT_CHAR (wxStyledTextCtrl::OnChar
)
151 EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown
)
152 EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus
)
153 EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus
)
154 EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged
)
155 EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground
)
156 EVT_MENU_RANGE (10, 16, wxStyledTextCtrl::OnMenu
)
157 EVT_LISTBOX_DCLICK (wxID_ANY
, wxStyledTextCtrl::OnListBox
)
161 IMPLEMENT_CLASS(wxStyledTextCtrl
, wxControl
)
162 IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent
, wxCommandEvent
)
165 // forces the linking of the lexer modules
166 int Scintilla_LinkLexers();
169 //----------------------------------------------------------------------
170 // Constructor and Destructor
172 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow
*parent
,
177 const wxString
& name
)
180 Create(parent
, id
, pos
, size
, style
, name
);
184 bool wxStyledTextCtrl::Create(wxWindow
*parent
,
189 const wxString
& name
)
191 style
|= wxVSCROLL
| wxHSCROLL
;
192 if (!wxControl::Create(parent
, id
, pos
, size
,
193 style
| wxWANTS_CHARS
| wxCLIP_CHILDREN
,
194 wxDefaultValidator
, name
))
198 Scintilla_LinkLexers();
200 m_swx
= new ScintillaWX(this);
202 m_lastKeyDownConsumed
= false;
206 // Put Scintilla into unicode (UTF-8) mode
207 SetCodePage(wxSTC_CP_UTF8
);
210 SetInitialSize(size
);
212 // Reduces flicker on GTK+/X11
213 SetBackgroundStyle(wxBG_STYLE_PAINT
);
215 // Make sure it can take the focus
222 wxStyledTextCtrl::~wxStyledTextCtrl() {
227 //----------------------------------------------------------------------
229 wxIntPtr
wxStyledTextCtrl::SendMsg(int msg
, wxUIntPtr wp
, wxIntPtr lp
) const
231 return m_swx
->WndProc(msg
, wp
, lp
);
234 //----------------------------------------------------------------------
236 // Set the vertical scrollbar to use instead of the ont that's built-in.
237 void wxStyledTextCtrl::SetVScrollBar(wxScrollBar
* bar
) {
240 // ensure that the built-in scrollbar is not visible
241 SetScrollbar(wxVERTICAL
, 0, 0, 0);
246 // Set the horizontal scrollbar to use instead of the ont that's built-in.
247 void wxStyledTextCtrl::SetHScrollBar(wxScrollBar
* bar
) {
250 // ensure that the built-in scrollbar is not visible
251 SetScrollbar(wxHORIZONTAL
, 0, 0, 0);
255 //----------------------------------------------------------------------
256 // Generated methods implementation section {{{
261 //----------------------------------------------------------------------
264 // Returns the line number of the line with the caret.
265 int wxStyledTextCtrl::GetCurrentLine() {
266 int line
= LineFromPosition(GetCurrentPos());
271 // Extract style settings from a spec-string which is composed of one or
272 // more of the following comma separated elements:
274 // bold turns on bold
275 // italic turns on italics
276 // fore:[name or #RRGGBB] sets the foreground colour
277 // back:[name or #RRGGBB] sets the background colour
278 // face:[facename] sets the font face name to use
279 // size:[num] sets the font size in points
280 // eol turns on eol filling
281 // underline turns on underlining
283 void wxStyledTextCtrl::StyleSetSpec(int styleNum
, const wxString
& spec
) {
285 wxStringTokenizer
tkz(spec
, wxT(","));
286 while (tkz
.HasMoreTokens()) {
287 wxString token
= tkz
.GetNextToken();
289 wxString option
= token
.BeforeFirst(':');
290 wxString val
= token
.AfterFirst(':');
292 if (option
== wxT("bold"))
293 StyleSetBold(styleNum
, true);
295 else if (option
== wxT("italic"))
296 StyleSetItalic(styleNum
, true);
298 else if (option
== wxT("underline"))
299 StyleSetUnderline(styleNum
, true);
301 else if (option
== wxT("eol"))
302 StyleSetEOLFilled(styleNum
, true);
304 else if (option
== wxT("size")) {
306 if (val
.ToLong(&points
))
307 StyleSetSize(styleNum
, points
);
310 else if (option
== wxT("face"))
311 StyleSetFaceName(styleNum
, val
);
313 else if (option
== wxT("fore"))
314 StyleSetForeground(styleNum
, wxColourFromSpec(val
));
316 else if (option
== wxT("back"))
317 StyleSetBackground(styleNum
, wxColourFromSpec(val
));
322 // Get the font of a style
323 wxFont
wxStyledTextCtrl::StyleGetFont(int style
) {
325 font
.SetPointSize(StyleGetSize(style
));
326 font
.SetFaceName(StyleGetFaceName(style
));
327 if( StyleGetBold(style
) )
328 font
.SetWeight(wxFONTWEIGHT_BOLD
);
330 font
.SetWeight(wxFONTWEIGHT_NORMAL
);
332 if( StyleGetItalic(style
) )
333 font
.SetStyle(wxFONTSTYLE_ITALIC
);
335 font
.SetStyle(wxFONTSTYLE_NORMAL
);
341 // Set style size, face, bold, italic, and underline attributes from
342 // a wxFont's attributes.
343 void wxStyledTextCtrl::StyleSetFont(int styleNum
, wxFont
& font
) {
345 // Ensure that the native font is initialized
347 GetTextExtent(wxT("X"), &x
, &y
, NULL
, NULL
, &font
);
349 int size
= font
.GetPointSize();
350 wxString faceName
= font
.GetFaceName();
351 bool bold
= font
.GetWeight() == wxBOLD
;
352 bool italic
= font
.GetStyle() != wxNORMAL
;
353 bool under
= font
.GetUnderlined();
354 wxFontEncoding encoding
= font
.GetEncoding();
356 StyleSetFontAttr(styleNum
, size
, faceName
, bold
, italic
, under
, encoding
);
359 // Set all font style attributes at once.
360 void wxStyledTextCtrl::StyleSetFontAttr(int styleNum
, int size
,
361 const wxString
& faceName
,
362 bool bold
, bool italic
,
364 wxFontEncoding encoding
) {
365 StyleSetSize(styleNum
, size
);
366 StyleSetFaceName(styleNum
, faceName
);
367 StyleSetBold(styleNum
, bold
);
368 StyleSetItalic(styleNum
, italic
);
369 StyleSetUnderline(styleNum
, underline
);
370 StyleSetFontEncoding(styleNum
, encoding
);
374 // Set the character set of the font in a style. Converts the Scintilla
375 // character set values to a wxFontEncoding.
376 void wxStyledTextCtrl::StyleSetCharacterSet(int style
, int characterSet
)
378 wxFontEncoding encoding
;
380 // Translate the Scintilla characterSet to a wxFontEncoding
381 switch (characterSet
) {
383 case wxSTC_CHARSET_ANSI
:
384 case wxSTC_CHARSET_DEFAULT
:
385 encoding
= wxFONTENCODING_DEFAULT
;
388 case wxSTC_CHARSET_BALTIC
:
389 encoding
= wxFONTENCODING_ISO8859_13
;
392 case wxSTC_CHARSET_CHINESEBIG5
:
393 encoding
= wxFONTENCODING_CP950
;
396 case wxSTC_CHARSET_EASTEUROPE
:
397 encoding
= wxFONTENCODING_ISO8859_2
;
400 case wxSTC_CHARSET_GB2312
:
401 encoding
= wxFONTENCODING_CP936
;
404 case wxSTC_CHARSET_GREEK
:
405 encoding
= wxFONTENCODING_ISO8859_7
;
408 case wxSTC_CHARSET_HANGUL
:
409 encoding
= wxFONTENCODING_CP949
;
412 case wxSTC_CHARSET_MAC
:
413 encoding
= wxFONTENCODING_DEFAULT
;
416 case wxSTC_CHARSET_OEM
:
417 encoding
= wxFONTENCODING_DEFAULT
;
420 case wxSTC_CHARSET_RUSSIAN
:
421 encoding
= wxFONTENCODING_KOI8
;
424 case wxSTC_CHARSET_SHIFTJIS
:
425 encoding
= wxFONTENCODING_CP932
;
428 case wxSTC_CHARSET_SYMBOL
:
429 encoding
= wxFONTENCODING_DEFAULT
;
432 case wxSTC_CHARSET_TURKISH
:
433 encoding
= wxFONTENCODING_ISO8859_9
;
436 case wxSTC_CHARSET_JOHAB
:
437 encoding
= wxFONTENCODING_DEFAULT
;
440 case wxSTC_CHARSET_HEBREW
:
441 encoding
= wxFONTENCODING_ISO8859_8
;
444 case wxSTC_CHARSET_ARABIC
:
445 encoding
= wxFONTENCODING_ISO8859_6
;
448 case wxSTC_CHARSET_VIETNAMESE
:
449 encoding
= wxFONTENCODING_DEFAULT
;
452 case wxSTC_CHARSET_THAI
:
453 encoding
= wxFONTENCODING_ISO8859_11
;
456 case wxSTC_CHARSET_CYRILLIC
:
457 encoding
= wxFONTENCODING_ISO8859_5
;
460 case wxSTC_CHARSET_8859_15
:
461 encoding
= wxFONTENCODING_ISO8859_15
;;
465 // We just have Scintilla track the wxFontEncoding for us. It gets used
466 // in Font::Create in PlatWX.cpp. We add one to the value so that the
467 // effective wxFONENCODING_DEFAULT == SC_SHARSET_DEFAULT and so when
468 // Scintilla internally uses SC_CHARSET_DEFAULT we will translate it back
469 // to wxFONENCODING_DEFAULT in Font::Create.
470 SendMsg(SCI_STYLESETCHARACTERSET
, style
, encoding
+1);
474 // Set the font encoding to be used by a style.
475 void wxStyledTextCtrl::StyleSetFontEncoding(int style
, wxFontEncoding encoding
)
477 SendMsg(SCI_STYLESETCHARACTERSET
, style
, encoding
+1);
481 // Perform one of the operations defined by the wxSTC_CMD_* constants.
482 void wxStyledTextCtrl::CmdKeyExecute(int cmd
) {
487 // Set the left and right margin in the edit area, measured in pixels.
488 void wxStyledTextCtrl::SetMargins(int left
, int right
) {
490 SetMarginRight(right
);
494 // Retrieve the point in the window where a position is displayed.
495 wxPoint
wxStyledTextCtrl::PointFromPosition(int pos
) {
496 int x
= SendMsg(SCI_POINTXFROMPOSITION
, 0, pos
);
497 int y
= SendMsg(SCI_POINTYFROMPOSITION
, 0, pos
);
498 return wxPoint(x
, y
);
501 // Scroll enough to make the given line visible
502 void wxStyledTextCtrl::ScrollToLine(int line
) {
503 m_swx
->DoScrollToLine(line
);
507 // Scroll enough to make the given column visible
508 void wxStyledTextCtrl::ScrollToColumn(int column
) {
509 m_swx
->DoScrollToColumn(column
);
514 bool wxStyledTextCtrl::DoSaveFile(const wxString
& filename
, int fileType
)
516 bool ok
= wxTextAreaBase::DoSaveFile(filename
, fileType
);
518 bool wxStyledTextCtrl::SaveFile(const wxString
& filename
)
521 wxFFile
file(filename
, wxT("w"));
522 bool ok
= file
.IsOpened() && file
.Write(GetValue(), *wxConvCurrent
);
525 #endif // wxUSE_FFILE
535 bool wxStyledTextCtrl::DoLoadFile(const wxString
& filename
, int fileType
)
537 bool ok
= wxTextAreaBase::DoLoadFile(filename
, fileType
);
539 bool wxStyledTextCtrl::LoadFile(const wxString
& filename
)
542 wxFFile
file(filename
);
543 bool ok
= file
.IsOpened();
547 ok
= file
.ReadAll(&text
, *wxConvCurrent
);
555 #endif // wxUSE_FFILE
565 #if wxUSE_DRAG_AND_DROP
566 wxDragResult
wxStyledTextCtrl::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
567 return m_swx
->DoDragOver(x
, y
, def
);
571 bool wxStyledTextCtrl::DoDropText(long x
, long y
, const wxString
& data
) {
572 return m_swx
->DoDropText(x
, y
, data
);
577 void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA
) {
578 m_swx
->SetUseAntiAliasing(useAA
);
581 bool wxStyledTextCtrl::GetUseAntiAliasing() {
582 return m_swx
->GetUseAntiAliasing();
589 void wxStyledTextCtrl::AddTextRaw(const char* text
, int length
)
592 length
= strlen(text
);
593 SendMsg(SCI_ADDTEXT
, length
, (sptr_t
)text
);
596 void wxStyledTextCtrl::InsertTextRaw(int pos
, const char* text
)
598 SendMsg(SCI_INSERTTEXT
, pos
, (sptr_t
)text
);
601 wxCharBuffer
wxStyledTextCtrl::GetCurLineRaw(int* linePos
)
603 int len
= LineLength(GetCurrentLine());
605 if (linePos
) *linePos
= 0;
610 wxCharBuffer
buf(len
);
611 int pos
= SendMsg(SCI_GETCURLINE
, len
, (sptr_t
)buf
.data());
612 if (linePos
) *linePos
= pos
;
616 wxCharBuffer
wxStyledTextCtrl::GetLineRaw(int line
)
618 int len
= LineLength(line
);
624 wxCharBuffer
buf(len
);
625 SendMsg(SCI_GETLINE
, line
, (sptr_t
)buf
.data());
629 wxCharBuffer
wxStyledTextCtrl::GetSelectedTextRaw()
631 // Calculate the length needed first.
632 const int len
= SendMsg(SCI_GETSELTEXT
, 0, (sptr_t
)0);
634 // And then really get the data.
635 wxCharBuffer
buf(len
);
636 SendMsg(SCI_GETSELTEXT
, 0, (sptr_t
)buf
.data());
640 wxCharBuffer
wxStyledTextCtrl::GetTextRangeRaw(int startPos
, int endPos
)
642 if (endPos
< startPos
) {
647 int len
= endPos
- startPos
;
653 wxCharBuffer
buf(len
);
655 tr
.lpstrText
= buf
.data();
656 tr
.chrg
.cpMin
= startPos
;
657 tr
.chrg
.cpMax
= endPos
;
658 SendMsg(SCI_GETTEXTRANGE
, 0, (sptr_t
)&tr
);
662 void wxStyledTextCtrl::SetTextRaw(const char* text
)
664 SendMsg(SCI_SETTEXT
, 0, (sptr_t
)text
);
667 wxCharBuffer
wxStyledTextCtrl::GetTextRaw()
669 int len
= GetTextLength();
670 wxCharBuffer
buf(len
); // adds 1 for NUL automatically
671 SendMsg(SCI_GETTEXT
, len
+ 1, (sptr_t
)buf
.data());
675 void wxStyledTextCtrl::AppendTextRaw(const char* text
, int length
)
678 length
= strlen(text
);
679 SendMsg(SCI_APPENDTEXT
, length
, (sptr_t
)text
);
686 //----------------------------------------------------------------------
689 void wxStyledTextCtrl::OnPaint(wxPaintEvent
& WXUNUSED(evt
)) {
691 m_swx
->DoPaint(&dc
, GetUpdateRegion().GetBox());
694 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent
& evt
) {
695 if (evt
.GetOrientation() == wxHORIZONTAL
)
696 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
698 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
701 void wxStyledTextCtrl::OnScroll(wxScrollEvent
& evt
) {
702 wxScrollBar
* sb
= wxDynamicCast(evt
.GetEventObject(), wxScrollBar
);
704 if (sb
->IsVertical())
705 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
707 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
711 void wxStyledTextCtrl::OnSize(wxSizeEvent
& WXUNUSED(evt
)) {
713 wxSize sz
= GetClientSize();
714 m_swx
->DoSize(sz
.x
, sz
.y
);
718 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent
& evt
) {
720 wxPoint pt
= evt
.GetPosition();
721 m_swx
->DoLeftButtonDown(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
722 evt
.ShiftDown(), evt
.ControlDown(), evt
.AltDown());
725 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent
& evt
) {
726 wxPoint pt
= evt
.GetPosition();
727 m_swx
->DoLeftButtonMove(Point(pt
.x
, pt
.y
));
730 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent
& evt
) {
731 wxPoint pt
= evt
.GetPosition();
732 m_swx
->DoLeftButtonUp(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
737 void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent
& evt
) {
738 wxPoint pt
= evt
.GetPosition();
739 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
743 void wxStyledTextCtrl::OnMouseMiddleUp(wxMouseEvent
& evt
) {
744 wxPoint pt
= evt
.GetPosition();
745 m_swx
->DoMiddleButtonUp(Point(pt
.x
, pt
.y
));
748 void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent
& evt
) {
749 wxPoint pt
= evt
.GetPosition();
750 ScreenToClient(&pt
.x
, &pt
.y
);
752 Show context menu at event point if it's within the window,
753 or at caret location if not
755 wxHitTest ht
= this->HitTest(pt
);
756 if (ht
!= wxHT_WINDOW_INSIDE
) {
757 pt
= this->PointFromPosition(this->GetCurrentPos());
759 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
763 void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent
& evt
)
765 m_swx
->DoMouseWheel(evt
.GetWheelRotation(),
767 evt
.GetLinesPerAction(),
773 void wxStyledTextCtrl::OnChar(wxKeyEvent
& evt
) {
774 // On (some?) non-US PC keyboards the AltGr key is required to enter some
775 // common characters. It comes to us as both Alt and Ctrl down so we need
776 // to let the char through in that case, otherwise if only ctrl or only
777 // alt let's skip it.
778 bool ctrl
= evt
.ControlDown();
780 // On the Mac the Alt key is just a modifier key (like Shift) so we need
781 // to allow the char events to be processed when Alt is pressed.
782 // TODO: Should we check MetaDown instead in this case?
785 bool alt
= evt
.AltDown();
787 bool skip
= ((ctrl
|| alt
) && ! (ctrl
&& alt
));
790 // apparently if we don't do this, Unicode keys pressed after non-char
791 // ASCII ones (e.g. Enter, Tab) are not taken into account (patch 1615989)
792 if (m_lastKeyDownConsumed
&& evt
.GetUnicodeKey() > 255)
793 m_lastKeyDownConsumed
= false;
796 if (!m_lastKeyDownConsumed
&& !skip
) {
798 int key
= evt
.GetUnicodeKey();
801 // if the unicode key code is not really a unicode character (it may
802 // be a function key or etc., the platforms appear to always give us a
803 // small value in this case) then fallback to the ascii key code but
804 // don't do anything for function keys or etc.
806 key
= evt
.GetKeyCode();
807 keyOk
= (key
<= 127);
810 m_swx
->DoAddChar(key
);
814 int key
= evt
.GetKeyCode();
815 if (key
<= WXK_START
|| key
> WXK_COMMAND
) {
816 m_swx
->DoAddChar(key
);
826 void wxStyledTextCtrl::OnKeyDown(wxKeyEvent
& evt
) {
827 int processed
= m_swx
->DoKeyDown(evt
, &m_lastKeyDownConsumed
);
828 if (!processed
&& !m_lastKeyDownConsumed
)
833 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent
& evt
) {
834 m_swx
->DoLoseFocus();
839 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent
& evt
) {
840 m_swx
->DoGainFocus();
845 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(evt
)) {
846 m_swx
->DoSysColourChange();
850 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
)) {
851 // do nothing to help avoid flashing
856 void wxStyledTextCtrl::OnMenu(wxCommandEvent
& evt
) {
857 m_swx
->DoCommand(evt
.GetId());
861 void wxStyledTextCtrl::OnListBox(wxCommandEvent
& WXUNUSED(evt
)) {
862 m_swx
->DoOnListBox();
866 void wxStyledTextCtrl::OnIdle(wxIdleEvent
& evt
) {
867 m_swx
->DoOnIdle(evt
);
871 wxSize
wxStyledTextCtrl::DoGetBestSize() const
873 // What would be the best size for a wxSTC?
874 // Just give a reasonable minimum until something else can be figured out.
875 return wxSize(200,100);
879 //----------------------------------------------------------------------
880 // Turn notifications from Scintilla into events
883 void wxStyledTextCtrl::NotifyChange() {
884 wxStyledTextEvent
evt(wxEVT_STC_CHANGE
, GetId());
885 evt
.SetEventObject(this);
886 GetEventHandler()->ProcessEvent(evt
);
890 static void SetEventText(wxStyledTextEvent
& evt
, const char* text
,
894 evt
.SetText(stc2wx(text
, length
));
898 void wxStyledTextCtrl::NotifyParent(SCNotification
* _scn
) {
899 SCNotification
& scn
= *_scn
;
900 wxStyledTextEvent
evt(0, GetId());
902 evt
.SetEventObject(this);
903 evt
.SetPosition(scn
.position
);
905 evt
.SetModifiers(scn
.modifiers
);
907 switch (scn
.nmhdr
.code
) {
908 case SCN_STYLENEEDED
:
909 evt
.SetEventType(wxEVT_STC_STYLENEEDED
);
913 evt
.SetEventType(wxEVT_STC_CHARADDED
);
916 case SCN_SAVEPOINTREACHED
:
917 evt
.SetEventType(wxEVT_STC_SAVEPOINTREACHED
);
920 case SCN_SAVEPOINTLEFT
:
921 evt
.SetEventType(wxEVT_STC_SAVEPOINTLEFT
);
924 case SCN_MODIFYATTEMPTRO
:
925 evt
.SetEventType(wxEVT_STC_ROMODIFYATTEMPT
);
929 evt
.SetEventType(wxEVT_STC_KEY
);
932 case SCN_DOUBLECLICK
:
933 evt
.SetEventType(wxEVT_STC_DOUBLECLICK
);
934 evt
.SetLine(scn
.line
);
938 evt
.SetEventType(wxEVT_STC_UPDATEUI
);
939 evt
.SetUpdated(scn
.updated
);
943 evt
.SetEventType(wxEVT_STC_MODIFIED
);
944 evt
.SetModificationType(scn
.modificationType
);
945 SetEventText(evt
, scn
.text
, scn
.length
);
946 evt
.SetLength(scn
.length
);
947 evt
.SetLinesAdded(scn
.linesAdded
);
948 evt
.SetLine(scn
.line
);
949 evt
.SetFoldLevelNow(scn
.foldLevelNow
);
950 evt
.SetFoldLevelPrev(scn
.foldLevelPrev
);
951 evt
.SetToken(scn
.token
);
952 evt
.SetAnnotationLinesAdded(scn
.annotationLinesAdded
);
955 case SCN_MACRORECORD
:
956 evt
.SetEventType(wxEVT_STC_MACRORECORD
);
957 evt
.SetMessage(scn
.message
);
958 evt
.SetWParam(scn
.wParam
);
959 evt
.SetLParam(scn
.lParam
);
962 case SCN_MARGINCLICK
:
963 evt
.SetEventType(wxEVT_STC_MARGINCLICK
);
964 evt
.SetMargin(scn
.margin
);
968 evt
.SetEventType(wxEVT_STC_NEEDSHOWN
);
969 evt
.SetLength(scn
.length
);
973 evt
.SetEventType(wxEVT_STC_PAINTED
);
976 case SCN_AUTOCSELECTION
:
977 evt
.SetEventType(wxEVT_STC_AUTOCOMP_SELECTION
);
978 evt
.SetListType(scn
.listType
);
979 SetEventText(evt
, scn
.text
, strlen(scn
.text
));
980 evt
.SetPosition(scn
.lParam
);
983 case SCN_USERLISTSELECTION
:
984 evt
.SetEventType(wxEVT_STC_USERLISTSELECTION
);
985 evt
.SetListType(scn
.listType
);
986 SetEventText(evt
, scn
.text
, strlen(scn
.text
));
987 evt
.SetPosition(scn
.lParam
);
991 evt
.SetEventType(wxEVT_STC_URIDROPPED
);
992 SetEventText(evt
, scn
.text
, strlen(scn
.text
));
996 evt
.SetEventType(wxEVT_STC_DWELLSTART
);
1002 evt
.SetEventType(wxEVT_STC_DWELLEND
);
1008 evt
.SetEventType(wxEVT_STC_ZOOM
);
1011 case SCN_HOTSPOTCLICK
:
1012 evt
.SetEventType(wxEVT_STC_HOTSPOT_CLICK
);
1015 case SCN_HOTSPOTDOUBLECLICK
:
1016 evt
.SetEventType(wxEVT_STC_HOTSPOT_DCLICK
);
1019 case SCN_CALLTIPCLICK
:
1020 evt
.SetEventType(wxEVT_STC_CALLTIP_CLICK
);
1023 case SCN_INDICATORCLICK
:
1024 evt
.SetEventType(wxEVT_STC_INDICATOR_CLICK
);
1027 case SCN_INDICATORRELEASE
:
1028 evt
.SetEventType(wxEVT_STC_INDICATOR_RELEASE
);
1031 case SCN_AUTOCCANCELLED
:
1032 evt
.SetEventType(wxEVT_STC_AUTOCOMP_CANCELLED
);
1035 case SCN_AUTOCCHARDELETED
:
1036 evt
.SetEventType(wxEVT_STC_AUTOCOMP_CHAR_DELETED
);
1039 case SCN_HOTSPOTRELEASECLICK
:
1040 evt
.SetEventType(wxEVT_STC_HOTSPOT_RELEASE_CLICK
);
1047 GetEventHandler()->ProcessEvent(evt
);
1051 //----------------------------------------------------------------------
1052 //----------------------------------------------------------------------
1053 //----------------------------------------------------------------------
1055 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType
, int id
)
1056 : wxCommandEvent(commandType
, id
)
1061 m_modificationType
= 0;
1066 m_foldLevelPrev
= 0;
1075 m_annotationLinesAdded
= 0;
1078 #if wxUSE_DRAG_AND_DROP
1079 m_dragFlags
= wxDrag_CopyOnly
;
1080 m_dragResult
= wxDragNone
;
1084 bool wxStyledTextEvent::GetShift() const { return (m_modifiers
& SCI_SHIFT
) != 0; }
1085 bool wxStyledTextEvent::GetControl() const { return (m_modifiers
& SCI_CTRL
) != 0; }
1086 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers
& SCI_ALT
) != 0; }
1089 wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent
& event
):
1090 wxCommandEvent(event
)
1092 m_position
= event
.m_position
;
1093 m_key
= event
.m_key
;
1094 m_modifiers
= event
.m_modifiers
;
1095 m_modificationType
= event
.m_modificationType
;
1096 m_text
= event
.m_text
;
1097 m_length
= event
.m_length
;
1098 m_linesAdded
= event
.m_linesAdded
;
1099 m_line
= event
.m_line
;
1100 m_foldLevelNow
= event
.m_foldLevelNow
;
1101 m_foldLevelPrev
= event
.m_foldLevelPrev
;
1103 m_margin
= event
.m_margin
;
1105 m_message
= event
.m_message
;
1106 m_wParam
= event
.m_wParam
;
1107 m_lParam
= event
.m_lParam
;
1109 m_listType
= event
.m_listType
;
1113 m_token
= event
.m_token
;
1114 m_annotationLinesAdded
= event
.m_annotationLinesAdded
;
1115 m_updated
= event
.m_updated
;
1117 #if wxUSE_DRAG_AND_DROP
1118 m_dragText
= event
.m_dragText
;
1119 m_dragFlags
= event
.m_dragFlags
;
1120 m_dragResult
= event
.m_dragResult
;
1124 //----------------------------------------------------------------------
1125 //----------------------------------------------------------------------
1127 /*static*/ wxVersionInfo
wxStyledTextCtrl::GetLibraryVersionInfo()
1129 return wxVersionInfo("Scintilla", 3, 21, 0, "Scintilla 3.21");