diff --git a/docs/changes.txt b/docs/changes.txt index 855fecb574..3b04f6a60c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -63,6 +63,7 @@ All: wxLog::SetVerbose() which now only affects wxLogVerbose(). - Add wxFileType::GetExpandedCommand() (troelsk). - Make it easier to convert to/from UTF-8-encoded std::string (ARATA Mizuki). +- Add support for loading dynamic lexer in wxStyledTextCtrl (New Pagodi). All (GUI): diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index 0f69df1c67..c0569b8f9b 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -4773,6 +4773,9 @@ public: // Set the lexing language of the document based on string name. void SetLexerLanguage(const wxString& language); + // Load a lexer library (dll / so). + void LoadLexerLibrary(const wxString& path); + // Retrieve a 'property' value previously set with SetProperty. wxString GetProperty(const wxString& key); @@ -4787,6 +4790,9 @@ public: // Retrieve the number of bits the current lexer needs for styling. int GetStyleBitsNeeded() const; + // Retrieve the lexing language of the document. + wxString GetLexerLanguage() const; + // For private communication between an application and a known lexer. void* PrivateLexerCall(int operation, void* pointer); diff --git a/interface/wx/stc/stc.h b/interface/wx/stc/stc.h index f3bad2c642..a649508fb0 100644 --- a/interface/wx/stc/stc.h +++ b/interface/wx/stc/stc.h @@ -6031,6 +6031,11 @@ public: */ void SetLexerLanguage(const wxString& language); + /** + Load a lexer library (dll / so). + */ + void LoadLexerLibrary(const wxString& path); + /** Retrieve a 'property' value previously set with SetProperty. */ @@ -6053,6 +6058,11 @@ public: */ int GetStyleBitsNeeded() const; + /** + Retrieve the lexing language of the document. + */ + wxString GetLexerLanguage() const; + /** For private communication between an application and a known lexer. */ diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 79e6e16af8..cbbdc9e9ab 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -32,6 +32,7 @@ #include "wx/image.h" #include "wx/imaglist.h" #include "wx/tokenzr.h" +#include "wx/dynlib.h" #ifdef wxHAS_RAW_BITMAP #include "wx/rawbmp.h" @@ -1440,9 +1441,37 @@ void Menu::Show(Point pt, Window &w) { //---------------------------------------------------------------------- -DynamicLibrary *DynamicLibrary::Load(const char *WXUNUSED(modulePath)) { - wxFAIL_MSG(wxT("Dynamic lexer loading not implemented yet")); - return NULL; +class DynamicLibraryImpl : public DynamicLibrary { +public: + explicit DynamicLibraryImpl(const char *modulePath) + : m_dynlib(wxString::FromUTF8(modulePath), wxDL_LAZY) { + } + + // Use GetSymbol to get a pointer to the relevant function. + virtual Function FindFunction(const char *name) wxOVERRIDE { + if (m_dynlib.IsLoaded()) { + bool status; + void* fn_address = m_dynlib.GetSymbol(wxString::FromUTF8(name), + &status); + if(status) + return fn_address; + else + return NULL; + } + else + return NULL; + } + + virtual bool IsValid() wxOVERRIDE { + return m_dynlib.IsLoaded(); + } + +private: + wxDynamicLibrary m_dynlib; +}; + +DynamicLibrary *DynamicLibrary::Load(const char *modulePath) { + return static_cast( new DynamicLibraryImpl(modulePath) ); } //---------------------------------------------------------------------- diff --git a/src/stc/gen_iface.py b/src/stc/gen_iface.py index 79fb4384f5..89130de3d7 100755 --- a/src/stc/gen_iface.py +++ b/src/stc/gen_iface.py @@ -762,12 +762,26 @@ methodOverrideMap = { 'SetCursor' : ('SetSTCCursor', 0, 0, 0), 'GetCursor' : ('GetSTCCursor', 0, 0, 0), - 'LoadLexerLibrary' : (None, 0,0,0), - 'SetPositionCache' : ('SetPositionCacheSize', 0, 0, 0), 'GetPositionCache' : ('GetPositionCacheSize', 0, 0, 0), - 'GetLexerLanguage' : (None, 0, 0, 0), + 'GetLexerLanguage' :(0, + 'wxString %s() const;', + + '''wxString %s() const { + const int msg = %s; + int len = SendMsg(msg, 0, (sptr_t)NULL); + if (!len) return wxEmptyString; + + wxMemoryBuffer mbuf(len+1); + char* buf = (char*)mbuf.GetWriteBuf(len+1); + SendMsg(msg, 0, (sptr_t)buf); + mbuf.UngetWriteBuf(len); + mbuf.AppendByte(0); + return stc2wx(buf);''', + + ('Retrieve the lexing language of the document.',)), + 'SetFontQuality' : (None, 0, 0, 0), 'GetFontQuality' : (None, 0, 0, 0), 'SetSelection' : (None, 0, 0, 0), diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index bcf8b06c2d..6d9c56b711 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -4365,6 +4365,12 @@ void wxStyledTextCtrl::SetLexerLanguage(const wxString& language) SendMsg(SCI_SETLEXERLANGUAGE, 0, (sptr_t)(const char*)wx2stc(language)); } +// Load a lexer library (dll / so). +void wxStyledTextCtrl::LoadLexerLibrary(const wxString& path) +{ + SendMsg(SCI_LOADLEXERLIBRARY, 0, (sptr_t)(const char*)wx2stc(path)); +} + // Retrieve a 'property' value previously set with SetProperty. wxString wxStyledTextCtrl::GetProperty(const wxString& key) { int len = SendMsg(SCI_GETPROPERTY, (sptr_t)(const char*)wx2stc(key), 0); @@ -4405,6 +4411,20 @@ int wxStyledTextCtrl::GetStyleBitsNeeded() const return SendMsg(SCI_GETSTYLEBITSNEEDED, 0, 0); } +// Retrieve the lexing language of the document. +wxString wxStyledTextCtrl::GetLexerLanguage() const { + const int msg = SCI_GETLEXERLANGUAGE; + int len = SendMsg(msg, 0, (sptr_t)NULL); + if (!len) return wxEmptyString; + + wxMemoryBuffer mbuf(len+1); + char* buf = (char*)mbuf.GetWriteBuf(len+1); + SendMsg(msg, 0, (sptr_t)buf); + mbuf.UngetWriteBuf(len); + mbuf.AppendByte(0); + return stc2wx(buf); +} + // For private communication between an application and a known lexer. void* wxStyledTextCtrl::PrivateLexerCall(int operation, void* pointer) { return (void*)(sptr_t)SendMsg(SCI_PRIVATELEXERCALL, operation, (sptr_t)pointer);