Add support for loading external lexers to wxStyledTextCtrl
Implement Scintilla DynamicLibraryImpl and generate LoadLexerLibrary() and GetLexerLanguage(). Closes #17480.
This commit is contained in:
parent
ae1a332d1f
commit
a6e249ea1a
@ -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):
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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<DynamicLibrary *>( new DynamicLibraryImpl(modulePath) );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -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),
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user