X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5fa4613c81c918b98da6cecfe332d0fbcee56319..7011cf1390d5ffc2b3cf132e391131d9acbe8c44:/src/stc/stc.cpp.in diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index eff7ed2936..f6c30c0896 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -22,57 +22,10 @@ #include -// The following code forces a reference to all of the Scintilla lexers. -// If we don't do something like this, then the linker tends to "optimize" -// them away. (eric@sourcegear.com) - -int wxForceScintillaLexers(void) -{ - extern LexerModule lmAda; - extern LexerModule lmAVE; - extern LexerModule lmConf; - extern LexerModule lmCPP; - extern LexerModule lmNncrontab; - extern LexerModule lmEiffel; - extern LexerModule lmHTML; - extern LexerModule lmLISP; - extern LexerModule lmLua; - extern LexerModule lmBatch; // In LexOthers.cxx - extern LexerModule lmPascal; - extern LexerModule lmPerl; - extern LexerModule lmPython; - extern LexerModule lmRuby; - extern LexerModule lmSQL; - extern LexerModule lmVB; - - if ( &lmAda - && &lmAVE - && &lmConf - && &lmCPP - && &lmNncrontab - && &lmEiffel - && &lmHTML - && &lmLISP - && &lmLua - && &lmBatch - && &lmPascal - && &lmPerl - && &lmPython - && &lmRuby - && &lmSQL - && &lmVB ) - { - return 1; - } - else - { - return 0; - } -} //---------------------------------------------------------------------- -const wxChar* wxSTCNameStr = "stcwindow"; +const wxChar* wxSTCNameStr = wxT("stcwindow"); DEFINE_EVENT_TYPE( wxEVT_STC_CHANGE ) DEFINE_EVENT_TYPE( wxEVT_STC_STYLENEEDED ) @@ -93,11 +46,9 @@ DEFINE_EVENT_TYPE( wxEVT_STC_USERLISTSELECTION ) DEFINE_EVENT_TYPE( wxEVT_STC_URIDROPPED ) DEFINE_EVENT_TYPE( wxEVT_STC_DWELLSTART ) DEFINE_EVENT_TYPE( wxEVT_STC_DWELLEND ) -#if wxUSE_DRAG_AND_DROP DEFINE_EVENT_TYPE( wxEVT_STC_START_DRAG ) DEFINE_EVENT_TYPE( wxEVT_STC_DRAG_OVER ) DEFINE_EVENT_TYPE( wxEVT_STC_DO_DROP ) -#endif BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) @@ -112,7 +63,11 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) #endif EVT_MOTION (wxStyledTextCtrl::OnMouseMove) EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) +#ifdef __WXGTK__ + EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) +#else EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu) +#endif EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel) EVT_CHAR (wxStyledTextCtrl::OnChar) EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) @@ -128,6 +83,9 @@ END_EVENT_TABLE() IMPLEMENT_CLASS(wxStyledTextCtrl, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent, wxCommandEvent) +// forces the linking of the lexer modules +int Scintilla_LinkLexers(); + //---------------------------------------------------------------------- // Constructor and Destructor @@ -141,11 +99,16 @@ wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent, style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS | wxCLIP_CHILDREN, wxDefaultValidator, name) { + Scintilla_LinkLexers(); m_swx = new ScintillaWX(this); m_stopWatch.Start(); m_lastKeyDownConsumed = FALSE; m_vScrollBar = NULL; m_hScrollBar = NULL; +#if wxUSE_UNICODE + // Put Scintilla into unicode (UTF-8) mode + SetCodePage(wxSTC_CP_UTF8); +#endif } @@ -183,11 +146,12 @@ static wxColour wxColourFromLong(long c) { static wxColour wxColourFromSpec(const wxString& spec) { - // spec should be #RRGGBB - char* junk; - int red = strtol(spec.Mid(1,2), &junk, 16); - int green = strtol(spec.Mid(3,2), &junk, 16); - int blue = strtol(spec.Mid(5,2), &junk, 16); + // spec should be "#RRGGBB" + long red, green, blue; + red = green = blue = 0; + spec.Mid(1,2).ToLong(&red, 16); + spec.Mid(3,2).ToLong(&green, 16); + spec.Mid(5,2).ToLong(&blue, 16); return wxColour(red, green, blue); } @@ -361,6 +325,7 @@ void wxStyledTextCtrl::OnScroll(wxScrollEvent& evt) { void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) { wxSize sz = GetClientSize(); m_swx->DoSize(sz.x, sz.y); + Refresh(FALSE); } void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) { @@ -381,6 +346,12 @@ void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) { } +void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) { + wxPoint pt = evt.GetPosition(); + m_swx->DoContextMenu(Point(pt.x, pt.y)); +} + + void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) { wxPoint pt = evt.GetPosition(); ScreenToClient(&pt.x, &pt.y); @@ -397,13 +368,7 @@ void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { - long key = evt.KeyCode(); - -// printf("OnChar key:%%d consumed:%%d ctrl:%%d alt:%%d\n", -// key, m_lastKeyDownConsumed, evt.ControlDown(), evt.AltDown()); - - // AltGr keys??? - // \|@#¬[]{}?£$~ ã,õ,Ã,Õ, ñ, Ñ + int key = evt.GetKeyCode(); // On (some?) non-US keyboards the AltGr key is required to enter some // common characters. It comes to us as both Alt and Ctrl down so we need @@ -413,7 +378,10 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { bool alt = evt.AltDown(); bool skip = ((ctrl || alt) && ! (ctrl && alt)); - if (key <= 0xff && !iscntrl(key) && !m_lastKeyDownConsumed && !skip) { + //printf("OnChar key:%%d consumed:%%d ctrl:%%d alt:%%d skip:%%d\n", + // key, m_lastKeyDownConsumed, ctrl, alt, skip); + + if (key <= WXK_START && /*key >= 32 &&*/ !m_lastKeyDownConsumed && !skip) { m_swx->DoAddChar(key); return; } @@ -422,10 +390,10 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { - long key = evt.KeyCode(); + int key = evt.GetKeyCode(); bool shift = evt.ShiftDown(), - ctrl = evt.ControlDown(), - alt = evt.AltDown(); + ctrl = evt.ControlDown(), + alt = evt.AltDown(); int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, &m_lastKeyDownConsumed); @@ -523,8 +491,14 @@ void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { case SCN_MODIFIED: evt.SetEventType(wxEVT_STC_MODIFIED); evt.SetModificationType(scn.modificationType); - if (scn.text) - evt.SetText(wxString(scn.text, scn.length)); + if (scn.text) { + // The unicode conversion MUST have a null byte to terminate the + // string so move it into a buffer first and give it one. + wxMemoryBuffer buf(scn.length+1); + buf.AppendData((void*)scn.text, scn.length); + buf.AppendByte(0); + evt.SetText(wxString(buf, wxConvUTF8)); + } evt.SetLength(scn.length); evt.SetLinesAdded(scn.linesAdded); evt.SetLine(scn.line); @@ -549,10 +523,6 @@ void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { evt.SetLength(scn.length); break; - case SCN_POSCHANGED: - evt.SetEventType(wxEVT_STC_POSCHANGED); - break; - case SCN_PAINTED: evt.SetEventType(wxEVT_STC_PAINTED); break; @@ -611,10 +581,8 @@ wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id) m_listType = 0; m_x = 0; m_y = 0; -#if wxUSE_DRAG_AND_DROP m_dragAllowMove = FALSE; m_dragResult = wxDragNone; -#endif } bool wxStyledTextEvent::GetShift() const { return (m_modifiers & SCI_SHIFT) != 0; } @@ -646,11 +614,9 @@ wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent& event): m_x = event.m_x; m_y = event.m_y; -#if wxUSE_DRAG_AND_DROP m_dragText = event.m_dragText; m_dragAllowMove =event.m_dragAllowMove; m_dragResult = event.m_dragResult; -#endif } //----------------------------------------------------------------------