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 /////////////////////////////////////////////////////////////////////////////
21 #include "wx/tokenzr.h"
22 #include "wx/mstream.h"
26 #include "wx/stc/stc.h"
27 #include "ScintillaWX.h"
29 //----------------------------------------------------------------------
31 const wxChar
* wxSTCNameStr
= wxT("stcwindow");
37 #define MAKELONG(a, b) ((a) | ((b) << 16))
40 static long wxColourAsLong(const wxColour
& co
) {
41 return (((long)co
.Blue() << 16) |
42 ((long)co
.Green() << 8) |
46 static wxColour
wxColourFromLong(long c
) {
48 clr
.Set((unsigned char)(c
& 0xff),
49 (unsigned char)((c
>> 8) & 0xff),
50 (unsigned char)((c
>> 16) & 0xff));
55 static wxColour
wxColourFromSpec(const wxString
& spec
) {
56 // spec should be a colour name or "#RRGGBB"
57 if (spec
.GetChar(0) == wxT('#')) {
59 long red
, green
, blue
;
60 red
= green
= blue
= 0;
61 spec
.Mid(1,2).ToLong(&red
, 16);
62 spec
.Mid(3,2).ToLong(&green
, 16);
63 spec
.Mid(5,2).ToLong(&blue
, 16);
64 return wxColour((unsigned char)red
,
69 return wxColour(spec
);
72 //----------------------------------------------------------------------
74 DEFINE_EVENT_TYPE( wxEVT_STC_CHANGE
)
75 DEFINE_EVENT_TYPE( wxEVT_STC_STYLENEEDED
)
76 DEFINE_EVENT_TYPE( wxEVT_STC_CHARADDED
)
77 DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTREACHED
)
78 DEFINE_EVENT_TYPE( wxEVT_STC_SAVEPOINTLEFT
)
79 DEFINE_EVENT_TYPE( wxEVT_STC_ROMODIFYATTEMPT
)
80 DEFINE_EVENT_TYPE( wxEVT_STC_KEY
)
81 DEFINE_EVENT_TYPE( wxEVT_STC_DOUBLECLICK
)
82 DEFINE_EVENT_TYPE( wxEVT_STC_UPDATEUI
)
83 DEFINE_EVENT_TYPE( wxEVT_STC_MODIFIED
)
84 DEFINE_EVENT_TYPE( wxEVT_STC_MACRORECORD
)
85 DEFINE_EVENT_TYPE( wxEVT_STC_MARGINCLICK
)
86 DEFINE_EVENT_TYPE( wxEVT_STC_NEEDSHOWN
)
87 DEFINE_EVENT_TYPE( wxEVT_STC_PAINTED
)
88 DEFINE_EVENT_TYPE( wxEVT_STC_USERLISTSELECTION
)
89 DEFINE_EVENT_TYPE( wxEVT_STC_URIDROPPED
)
90 DEFINE_EVENT_TYPE( wxEVT_STC_DWELLSTART
)
91 DEFINE_EVENT_TYPE( wxEVT_STC_DWELLEND
)
92 DEFINE_EVENT_TYPE( wxEVT_STC_START_DRAG
)
93 DEFINE_EVENT_TYPE( wxEVT_STC_DRAG_OVER
)
94 DEFINE_EVENT_TYPE( wxEVT_STC_DO_DROP
)
95 DEFINE_EVENT_TYPE( wxEVT_STC_ZOOM
)
96 DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_CLICK
)
97 DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_DCLICK
)
98 DEFINE_EVENT_TYPE( wxEVT_STC_CALLTIP_CLICK
)
99 DEFINE_EVENT_TYPE( wxEVT_STC_AUTOCOMP_SELECTION
)
103 BEGIN_EVENT_TABLE(wxStyledTextCtrl
, wxControl
)
104 EVT_PAINT (wxStyledTextCtrl::OnPaint
)
105 EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin
)
106 EVT_SCROLL (wxStyledTextCtrl::OnScroll
)
107 EVT_SIZE (wxStyledTextCtrl::OnSize
)
108 EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown
)
109 // Let Scintilla see the double click as a second click
110 EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown
)
111 EVT_MOTION (wxStyledTextCtrl::OnMouseMove
)
112 EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp
)
113 #if defined(__WXGTK__) || defined(__WXMAC__)
114 EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp
)
116 EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu
)
118 EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel
)
119 EVT_MIDDLE_UP (wxStyledTextCtrl::OnMouseMiddleUp
)
120 EVT_CHAR (wxStyledTextCtrl::OnChar
)
121 EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown
)
122 EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus
)
123 EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus
)
124 EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged
)
125 EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground
)
126 EVT_MENU_RANGE (10, 16, wxStyledTextCtrl::OnMenu
)
127 EVT_LISTBOX_DCLICK (wxID_ANY
, wxStyledTextCtrl::OnListBox
)
131 IMPLEMENT_CLASS(wxStyledTextCtrl
, wxControl
)
132 IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent
, wxCommandEvent
)
135 // forces the linking of the lexer modules
136 int Scintilla_LinkLexers();
139 //----------------------------------------------------------------------
140 // Constructor and Destructor
142 wxStyledTextCtrl::wxStyledTextCtrl(wxWindow
*parent
,
147 const wxString
& name
)
150 Create(parent
, id
, pos
, size
, style
, name
);
154 bool wxStyledTextCtrl::Create(wxWindow
*parent
,
159 const wxString
& name
)
162 style
|= wxVSCROLL
| wxHSCROLL
;
164 if (!wxControl::Create(parent
, id
, pos
, size
,
165 style
| wxWANTS_CHARS
| wxCLIP_CHILDREN
,
166 wxDefaultValidator
, name
))
170 Scintilla_LinkLexers();
172 m_swx
= new ScintillaWX(this);
174 m_lastKeyDownConsumed
= false;
178 // Put Scintilla into unicode (UTF-8) mode
179 SetCodePage(wxSTC_CP_UTF8
);
182 SetBestFittingSize(size
);
184 // Reduces flicker on GTK+/X11
185 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
190 wxStyledTextCtrl::~wxStyledTextCtrl() {
195 //----------------------------------------------------------------------
197 long wxStyledTextCtrl::SendMsg(int msg
, long wp
, long lp
) {
199 return m_swx
->WndProc(msg
, wp
, lp
);
202 //----------------------------------------------------------------------
204 // Set the vertical scrollbar to use instead of the ont that's built-in.
205 void wxStyledTextCtrl::SetVScrollBar(wxScrollBar
* bar
) {
208 // ensure that the built-in scrollbar is not visible
209 SetScrollbar(wxVERTICAL
, 0, 0, 0);
214 // Set the horizontal scrollbar to use instead of the ont that's built-in.
215 void wxStyledTextCtrl::SetHScrollBar(wxScrollBar
* bar
) {
218 // ensure that the built-in scrollbar is not visible
219 SetScrollbar(wxHORIZONTAL
, 0, 0, 0);
223 //----------------------------------------------------------------------
224 // BEGIN generated section. The following code is automatically generated
225 // by gen_iface.py from the contents of Scintilla.iface. Do not edit
226 // this file. Edit stc.cpp.in or gen_iface.py instead and regenerate.
230 // END of generated section
231 //----------------------------------------------------------------------
234 // Returns the line number of the line with the caret.
235 int wxStyledTextCtrl::GetCurrentLine() {
236 int line
= LineFromPosition(GetCurrentPos());
241 // Extract style settings from a spec-string which is composed of one or
242 // more of the following comma separated elements:
244 // bold turns on bold
245 // italic turns on italics
246 // fore:[name or #RRGGBB] sets the foreground colour
247 // back:[name or #RRGGBB] sets the background colour
248 // face:[facename] sets the font face name to use
249 // size:[num] sets the font size in points
250 // eol turns on eol filling
251 // underline turns on underlining
253 void wxStyledTextCtrl::StyleSetSpec(int styleNum
, const wxString
& spec
) {
255 wxStringTokenizer
tkz(spec
, wxT(","));
256 while (tkz
.HasMoreTokens()) {
257 wxString token
= tkz
.GetNextToken();
259 wxString option
= token
.BeforeFirst(':');
260 wxString val
= token
.AfterFirst(':');
262 if (option
== wxT("bold"))
263 StyleSetBold(styleNum
, true);
265 else if (option
== wxT("italic"))
266 StyleSetItalic(styleNum
, true);
268 else if (option
== wxT("underline"))
269 StyleSetUnderline(styleNum
, true);
271 else if (option
== wxT("eol"))
272 StyleSetEOLFilled(styleNum
, true);
274 else if (option
== wxT("size")) {
276 if (val
.ToLong(&points
))
277 StyleSetSize(styleNum
, points
);
280 else if (option
== wxT("face"))
281 StyleSetFaceName(styleNum
, val
);
283 else if (option
== wxT("fore"))
284 StyleSetForeground(styleNum
, wxColourFromSpec(val
));
286 else if (option
== wxT("back"))
287 StyleSetBackground(styleNum
, wxColourFromSpec(val
));
292 // Set style size, face, bold, italic, and underline attributes from
293 // a wxFont's attributes.
294 void wxStyledTextCtrl::StyleSetFont(int styleNum
, wxFont
& font
) {
296 // Ensure that the native font is initialized
298 GetTextExtent(wxT("X"), &x
, &y
, NULL
, NULL
, &font
);
300 int size
= font
.GetPointSize();
301 wxString faceName
= font
.GetFaceName();
302 bool bold
= font
.GetWeight() == wxBOLD
;
303 bool italic
= font
.GetStyle() != wxNORMAL
;
304 bool under
= font
.GetUnderlined();
305 wxFontEncoding encoding
= font
.GetEncoding();
307 StyleSetFontAttr(styleNum
, size
, faceName
, bold
, italic
, under
, encoding
);
310 // Set all font style attributes at once.
311 void wxStyledTextCtrl::StyleSetFontAttr(int styleNum
, int size
,
312 const wxString
& faceName
,
313 bool bold
, bool italic
,
315 wxFontEncoding encoding
) {
316 StyleSetSize(styleNum
, size
);
317 StyleSetFaceName(styleNum
, faceName
);
318 StyleSetBold(styleNum
, bold
);
319 StyleSetItalic(styleNum
, italic
);
320 StyleSetUnderline(styleNum
, underline
);
321 StyleSetFontEncoding(styleNum
, encoding
);
325 // Set the character set of the font in a style. Converts the Scintilla
326 // character set values to a wxFontEncoding.
327 void wxStyledTextCtrl::StyleSetCharacterSet(int style
, int characterSet
)
329 wxFontEncoding encoding
;
331 // Translate the Scintilla characterSet to a wxFontEncoding
332 switch (characterSet
) {
334 case wxSTC_CHARSET_ANSI
:
335 case wxSTC_CHARSET_DEFAULT
:
336 encoding
= wxFONTENCODING_DEFAULT
;
339 case wxSTC_CHARSET_BALTIC
:
340 encoding
= wxFONTENCODING_ISO8859_13
;
343 case wxSTC_CHARSET_CHINESEBIG5
:
344 encoding
= wxFONTENCODING_CP950
;
347 case wxSTC_CHARSET_EASTEUROPE
:
348 encoding
= wxFONTENCODING_ISO8859_2
;
351 case wxSTC_CHARSET_GB2312
:
352 encoding
= wxFONTENCODING_CP936
;
355 case wxSTC_CHARSET_GREEK
:
356 encoding
= wxFONTENCODING_ISO8859_7
;
359 case wxSTC_CHARSET_HANGUL
:
360 encoding
= wxFONTENCODING_CP949
;
363 case wxSTC_CHARSET_MAC
:
364 encoding
= wxFONTENCODING_DEFAULT
;
367 case wxSTC_CHARSET_OEM
:
368 encoding
= wxFONTENCODING_DEFAULT
;
371 case wxSTC_CHARSET_RUSSIAN
:
372 encoding
= wxFONTENCODING_KOI8
;
375 case wxSTC_CHARSET_SHIFTJIS
:
376 encoding
= wxFONTENCODING_CP932
;
379 case wxSTC_CHARSET_SYMBOL
:
380 encoding
= wxFONTENCODING_DEFAULT
;
383 case wxSTC_CHARSET_TURKISH
:
384 encoding
= wxFONTENCODING_ISO8859_9
;
387 case wxSTC_CHARSET_JOHAB
:
388 encoding
= wxFONTENCODING_DEFAULT
;
391 case wxSTC_CHARSET_HEBREW
:
392 encoding
= wxFONTENCODING_ISO8859_8
;
395 case wxSTC_CHARSET_ARABIC
:
396 encoding
= wxFONTENCODING_ISO8859_6
;
399 case wxSTC_CHARSET_VIETNAMESE
:
400 encoding
= wxFONTENCODING_DEFAULT
;
403 case wxSTC_CHARSET_THAI
:
404 encoding
= wxFONTENCODING_ISO8859_11
;
407 case wxSTC_CHARSET_CYRILLIC
:
408 encoding
= wxFONTENCODING_ISO8859_5
;
411 case wxSTC_CHARSET_8859_15
:
412 encoding
= wxFONTENCODING_ISO8859_15
;;
416 // We just have Scintilla track the wxFontEncoding for us. It gets used
417 // in Font::Create in PlatWX.cpp. We add one to the value so that the
418 // effective wxFONENCODING_DEFAULT == SC_SHARSET_DEFAULT and so when
419 // Scintilla internally uses SC_CHARSET_DEFAULT we will translate it back
420 // to wxFONENCODING_DEFAULT in Font::Create.
421 SendMsg(SCI_STYLESETCHARACTERSET
, style
, encoding
+1);
425 // Set the font encoding to be used by a style.
426 void wxStyledTextCtrl::StyleSetFontEncoding(int style
, wxFontEncoding encoding
)
428 SendMsg(SCI_STYLESETCHARACTERSET
, style
, encoding
+1);
432 // Perform one of the operations defined by the wxSTC_CMD_* constants.
433 void wxStyledTextCtrl::CmdKeyExecute(int cmd
) {
438 // Set the left and right margin in the edit area, measured in pixels.
439 void wxStyledTextCtrl::SetMargins(int left
, int right
) {
441 SetMarginRight(right
);
445 // Retrieve the start and end positions of the current selection.
446 void wxStyledTextCtrl::GetSelection(int* startPos
, int* endPos
) {
447 if (startPos
!= NULL
)
448 *startPos
= SendMsg(SCI_GETSELECTIONSTART
);
450 *endPos
= SendMsg(SCI_GETSELECTIONEND
);
454 // Retrieve the point in the window where a position is displayed.
455 wxPoint
wxStyledTextCtrl::PointFromPosition(int pos
) {
456 int x
= SendMsg(SCI_POINTXFROMPOSITION
, 0, pos
);
457 int y
= SendMsg(SCI_POINTYFROMPOSITION
, 0, pos
);
458 return wxPoint(x
, y
);
461 // Scroll enough to make the given line visible
462 void wxStyledTextCtrl::ScrollToLine(int line
) {
463 m_swx
->DoScrollToLine(line
);
467 // Scroll enough to make the given column visible
468 void wxStyledTextCtrl::ScrollToColumn(int column
) {
469 m_swx
->DoScrollToColumn(column
);
473 bool wxStyledTextCtrl::SaveFile(const wxString
& filename
)
475 wxFile
file(filename
, wxFile::write
);
477 if (!file
.IsOpened())
480 bool success
= file
.Write(GetText(), *wxConvCurrent
);
488 bool wxStyledTextCtrl::LoadFile(const wxString
& filename
)
490 bool success
= false;
491 wxFile
file(filename
, wxFile::read
);
496 // get the file size (assume it is not huge file...)
497 ssize_t len
= (ssize_t
)file
.Length();
502 wxMemoryBuffer
buffer(len
+1);
503 success
= (file
.Read(buffer
.GetData(), len
) == len
);
505 ((char*)buffer
.GetData())[len
] = 0;
506 contents
= wxString(buffer
, *wxConvCurrent
, len
);
510 success
= (file
.Read(wxStringBuffer(buffer
, len
), len
) == len
);
517 success
= true; // empty file is ok
519 success
= false; // len == wxInvalidOffset
534 #if wxUSE_DRAG_AND_DROP
535 wxDragResult
wxStyledTextCtrl::DoDragOver(wxCoord x
, wxCoord y
, wxDragResult def
) {
536 return m_swx
->DoDragOver(x
, y
, def
);
540 bool wxStyledTextCtrl::DoDropText(long x
, long y
, const wxString
& data
) {
541 return m_swx
->DoDropText(x
, y
, data
);
546 void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA
) {
547 m_swx
->SetUseAntiAliasing(useAA
);
550 bool wxStyledTextCtrl::GetUseAntiAliasing() {
551 return m_swx
->GetUseAntiAliasing();
558 void wxStyledTextCtrl::AddTextRaw(const char* text
)
560 SendMsg(SCI_ADDTEXT
, strlen(text
), (long)text
);
563 void wxStyledTextCtrl::InsertTextRaw(int pos
, const char* text
)
565 SendMsg(SCI_INSERTTEXT
, pos
, (long)text
);
568 wxCharBuffer
wxStyledTextCtrl::GetCurLineRaw(int* linePos
)
570 int len
= LineLength(GetCurrentLine());
572 if (linePos
) *linePos
= 0;
577 wxCharBuffer
buf(len
);
578 int pos
= SendMsg(SCI_GETCURLINE
, len
, (long)buf
.data());
579 if (linePos
) *linePos
= pos
;
583 wxCharBuffer
wxStyledTextCtrl::GetLineRaw(int line
)
585 int len
= LineLength(line
);
591 wxCharBuffer
buf(len
);
592 SendMsg(SCI_GETLINE
, line
, (long)buf
.data());
596 wxCharBuffer
wxStyledTextCtrl::GetSelectedTextRaw()
601 GetSelection(&start
, &end
);
602 int len
= end
- start
;
608 wxCharBuffer
buf(len
);
609 SendMsg(SCI_GETSELTEXT
, 0, (long)buf
.data());
613 wxCharBuffer
wxStyledTextCtrl::GetTextRangeRaw(int startPos
, int endPos
)
615 if (endPos
< startPos
) {
620 int len
= endPos
- startPos
;
626 wxCharBuffer
buf(len
);
628 tr
.lpstrText
= buf
.data();
629 tr
.chrg
.cpMin
= startPos
;
630 tr
.chrg
.cpMax
= endPos
;
631 SendMsg(SCI_GETTEXTRANGE
, 0, (long)&tr
);
635 void wxStyledTextCtrl::SetTextRaw(const char* text
)
637 SendMsg(SCI_SETTEXT
, 0, (long)text
);
640 wxCharBuffer
wxStyledTextCtrl::GetTextRaw()
642 int len
= GetTextLength();
643 wxCharBuffer
buf(len
);
644 SendMsg(SCI_GETTEXT
, len
, (long)buf
.data());
648 void wxStyledTextCtrl::AppendTextRaw(const char* text
)
650 SendMsg(SCI_APPENDTEXT
, strlen(text
), (long)text
);
657 //----------------------------------------------------------------------
660 void wxStyledTextCtrl::OnPaint(wxPaintEvent
& WXUNUSED(evt
)) {
662 m_swx
->DoPaint(&dc
, GetUpdateRegion().GetBox());
665 void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent
& evt
) {
666 if (evt
.GetOrientation() == wxHORIZONTAL
)
667 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
669 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
672 void wxStyledTextCtrl::OnScroll(wxScrollEvent
& evt
) {
673 wxScrollBar
* sb
= wxDynamicCast(evt
.GetEventObject(), wxScrollBar
);
675 if (sb
->IsVertical())
676 m_swx
->DoVScroll(evt
.GetEventType(), evt
.GetPosition());
678 m_swx
->DoHScroll(evt
.GetEventType(), evt
.GetPosition());
682 void wxStyledTextCtrl::OnSize(wxSizeEvent
& WXUNUSED(evt
)) {
684 wxSize sz
= GetClientSize();
685 m_swx
->DoSize(sz
.x
, sz
.y
);
689 void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent
& evt
) {
691 wxPoint pt
= evt
.GetPosition();
692 m_swx
->DoLeftButtonDown(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
693 evt
.ShiftDown(), evt
.ControlDown(), evt
.AltDown());
696 void wxStyledTextCtrl::OnMouseMove(wxMouseEvent
& evt
) {
697 wxPoint pt
= evt
.GetPosition();
698 m_swx
->DoLeftButtonMove(Point(pt
.x
, pt
.y
));
701 void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent
& evt
) {
702 wxPoint pt
= evt
.GetPosition();
703 m_swx
->DoLeftButtonUp(Point(pt
.x
, pt
.y
), m_stopWatch
.Time(),
708 void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent
& evt
) {
709 wxPoint pt
= evt
.GetPosition();
710 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
714 void wxStyledTextCtrl::OnMouseMiddleUp(wxMouseEvent
& evt
) {
715 wxPoint pt
= evt
.GetPosition();
716 m_swx
->DoMiddleButtonUp(Point(pt
.x
, pt
.y
));
719 void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent
& evt
) {
720 wxPoint pt
= evt
.GetPosition();
721 ScreenToClient(&pt
.x
, &pt
.y
);
723 Show context menu at event point if it's within the window,
724 or at caret location if not
726 wxHitTest ht
= this->HitTest(pt
);
727 if (ht
!= wxHT_WINDOW_INSIDE
) {
728 pt
= this->PointFromPosition(this->GetCurrentPos());
730 m_swx
->DoContextMenu(Point(pt
.x
, pt
.y
));
734 void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent
& evt
) {
735 m_swx
->DoMouseWheel(evt
.GetWheelRotation(),
737 evt
.GetLinesPerAction(),
743 void wxStyledTextCtrl::OnChar(wxKeyEvent
& evt
) {
744 // On (some?) non-US PC keyboards the AltGr key is required to enter some
745 // common characters. It comes to us as both Alt and Ctrl down so we need
746 // to let the char through in that case, otherwise if only ctrl or only
747 // alt let's skip it.
748 bool ctrl
= evt
.ControlDown();
750 // On the Mac the Alt key is just a modifier key (like Shift) so we need
751 // to allow the char events to be processed when Alt is pressed.
752 // TODO: Should we check MetaDown instead in this case?
755 bool alt
= evt
.AltDown();
757 bool skip
= ((ctrl
|| alt
) && ! (ctrl
&& alt
));
759 if (!m_lastKeyDownConsumed
&& !skip
) {
761 int key
= evt
.GetUnicodeKey();
764 // if the unicode key code is not really a unicode character (it may
765 // be a function key or etc., the platforms appear to always give us a
766 // small value in this case) then fallback to the ascii key code but
767 // don't do anything for function keys or etc.
769 key
= evt
.GetKeyCode();
770 keyOk
= (key
<= 127);
773 m_swx
->DoAddChar(key
);
777 int key
= evt
.GetKeyCode();
778 if (key
<= WXK_START
|| key
> WXK_COMMAND
) {
779 m_swx
->DoAddChar(key
);
789 void wxStyledTextCtrl::OnKeyDown(wxKeyEvent
& evt
) {
790 int processed
= m_swx
->DoKeyDown(evt
, &m_lastKeyDownConsumed
);
791 if (!processed
&& !m_lastKeyDownConsumed
)
796 void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent
& evt
) {
797 m_swx
->DoLoseFocus();
802 void wxStyledTextCtrl::OnGainFocus(wxFocusEvent
& evt
) {
803 m_swx
->DoGainFocus();
808 void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(evt
)) {
809 m_swx
->DoSysColourChange();
813 void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent
& WXUNUSED(evt
)) {
814 // do nothing to help avoid flashing
819 void wxStyledTextCtrl::OnMenu(wxCommandEvent
& evt
) {
820 m_swx
->DoCommand(evt
.GetId());
824 void wxStyledTextCtrl::OnListBox(wxCommandEvent
& WXUNUSED(evt
)) {
825 m_swx
->DoOnListBox();
829 void wxStyledTextCtrl::OnIdle(wxIdleEvent
& evt
) {
830 m_swx
->DoOnIdle(evt
);
834 wxSize
wxStyledTextCtrl::DoGetBestSize() const
836 // What would be the best size for a wxSTC?
837 // Just give a reasonable minimum until something else can be figured out.
838 return wxSize(200,100);
842 //----------------------------------------------------------------------
843 // Turn notifications from Scintilla into events
846 void wxStyledTextCtrl::NotifyChange() {
847 wxStyledTextEvent
evt(wxEVT_STC_CHANGE
, GetId());
848 evt
.SetEventObject(this);
849 GetEventHandler()->ProcessEvent(evt
);
853 static void SetEventText(wxStyledTextEvent
& evt
, const char* text
,
857 evt
.SetText(stc2wx(text
, length
));
861 void wxStyledTextCtrl::NotifyParent(SCNotification
* _scn
) {
862 SCNotification
& scn
= *_scn
;
863 wxStyledTextEvent
evt(0, GetId());
865 evt
.SetEventObject(this);
866 evt
.SetPosition(scn
.position
);
868 evt
.SetModifiers(scn
.modifiers
);
870 switch (scn
.nmhdr
.code
) {
871 case SCN_STYLENEEDED
:
872 evt
.SetEventType(wxEVT_STC_STYLENEEDED
);
876 evt
.SetEventType(wxEVT_STC_CHARADDED
);
879 case SCN_SAVEPOINTREACHED
:
880 evt
.SetEventType(wxEVT_STC_SAVEPOINTREACHED
);
883 case SCN_SAVEPOINTLEFT
:
884 evt
.SetEventType(wxEVT_STC_SAVEPOINTLEFT
);
887 case SCN_MODIFYATTEMPTRO
:
888 evt
.SetEventType(wxEVT_STC_ROMODIFYATTEMPT
);
892 evt
.SetEventType(wxEVT_STC_KEY
);
895 case SCN_DOUBLECLICK
:
896 evt
.SetEventType(wxEVT_STC_DOUBLECLICK
);
900 evt
.SetEventType(wxEVT_STC_UPDATEUI
);
904 evt
.SetEventType(wxEVT_STC_MODIFIED
);
905 evt
.SetModificationType(scn
.modificationType
);
906 SetEventText(evt
, scn
.text
, scn
.length
);
907 evt
.SetLength(scn
.length
);
908 evt
.SetLinesAdded(scn
.linesAdded
);
909 evt
.SetLine(scn
.line
);
910 evt
.SetFoldLevelNow(scn
.foldLevelNow
);
911 evt
.SetFoldLevelPrev(scn
.foldLevelPrev
);
914 case SCN_MACRORECORD
:
915 evt
.SetEventType(wxEVT_STC_MACRORECORD
);
916 evt
.SetMessage(scn
.message
);
917 evt
.SetWParam(scn
.wParam
);
918 evt
.SetLParam(scn
.lParam
);
921 case SCN_MARGINCLICK
:
922 evt
.SetEventType(wxEVT_STC_MARGINCLICK
);
923 evt
.SetMargin(scn
.margin
);
927 evt
.SetEventType(wxEVT_STC_NEEDSHOWN
);
928 evt
.SetLength(scn
.length
);
932 evt
.SetEventType(wxEVT_STC_PAINTED
);
935 case SCN_USERLISTSELECTION
:
936 evt
.SetEventType(wxEVT_STC_USERLISTSELECTION
);
937 evt
.SetListType(scn
.listType
);
938 SetEventText(evt
, scn
.text
, strlen(scn
.text
));
942 evt
.SetEventType(wxEVT_STC_URIDROPPED
);
943 SetEventText(evt
, scn
.text
, strlen(scn
.text
));
947 evt
.SetEventType(wxEVT_STC_DWELLSTART
);
953 evt
.SetEventType(wxEVT_STC_DWELLEND
);
959 evt
.SetEventType(wxEVT_STC_ZOOM
);
962 case SCN_HOTSPOTCLICK
:
963 evt
.SetEventType(wxEVT_STC_HOTSPOT_CLICK
);
966 case SCN_HOTSPOTDOUBLECLICK
:
967 evt
.SetEventType(wxEVT_STC_HOTSPOT_DCLICK
);
970 case SCN_CALLTIPCLICK
:
971 evt
.SetEventType(wxEVT_STC_CALLTIP_CLICK
);
974 case SCN_AUTOCSELECTION
:
975 evt
.SetEventType(wxEVT_STC_AUTOCOMP_SELECTION
);
982 GetEventHandler()->ProcessEvent(evt
);
986 //----------------------------------------------------------------------
987 //----------------------------------------------------------------------
988 //----------------------------------------------------------------------
990 wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType
, int id
)
991 : wxCommandEvent(commandType
, id
)
996 m_modificationType
= 0;
1001 m_foldLevelPrev
= 0;
1009 m_dragAllowMove
= false;
1010 #if wxUSE_DRAG_AND_DROP
1011 m_dragResult
= wxDragNone
;
1015 bool wxStyledTextEvent::GetShift() const { return (m_modifiers
& SCI_SHIFT
) != 0; }
1016 bool wxStyledTextEvent::GetControl() const { return (m_modifiers
& SCI_CTRL
) != 0; }
1017 bool wxStyledTextEvent::GetAlt() const { return (m_modifiers
& SCI_ALT
) != 0; }
1020 wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent
& event
):
1021 wxCommandEvent(event
)
1023 m_position
= event
.m_position
;
1024 m_key
= event
.m_key
;
1025 m_modifiers
= event
.m_modifiers
;
1026 m_modificationType
= event
.m_modificationType
;
1027 m_text
= event
.m_text
;
1028 m_length
= event
.m_length
;
1029 m_linesAdded
= event
.m_linesAdded
;
1030 m_line
= event
.m_line
;
1031 m_foldLevelNow
= event
.m_foldLevelNow
;
1032 m_foldLevelPrev
= event
.m_foldLevelPrev
;
1034 m_margin
= event
.m_margin
;
1036 m_message
= event
.m_message
;
1037 m_wParam
= event
.m_wParam
;
1038 m_lParam
= event
.m_lParam
;
1040 m_listType
= event
.m_listType
;
1044 m_dragText
= event
.m_dragText
;
1045 m_dragAllowMove
=event
.m_dragAllowMove
;
1046 #if wxUSE_DRAG_AND_DROP
1047 m_dragResult
= event
.m_dragResult
;
1051 //----------------------------------------------------------------------
1052 //----------------------------------------------------------------------