1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dynamically loadable C++ widget for wxPython
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2001 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
19 #include "wx/dynlib.h"
22 #include "dllwidget.h"
25 IMPLEMENT_ABSTRACT_CLASS(wxDllWidget
, wxPanel
)
27 wxDllWidget::wxDllWidget(wxWindow
*parent
,
29 const wxString
& dllName
, const wxString
& className
,
30 const wxPoint
& pos
, const wxSize
& size
,
32 : wxPanel(parent
, id
, pos
, size
, wxTAB_TRAVERSAL
| wxNO_BORDER
,
33 className
+ wxT("_container")),
34 m_widget(NULL
), m_lib(NULL
), m_controlAdded(false)
36 SetBackgroundColour(wxColour(255, 0, 255));
38 LoadWidget(dllName
, className
, style
);
41 wxDllWidget::~wxDllWidget()
46 void wxDllWidget::AddChild(wxWindowBase
*child
)
48 wxASSERT_MSG( !m_controlAdded
, wxT("Couldn't load two widgets into one container!") );
50 wxPanel::AddChild(child
);
52 m_controlAdded
= true;
53 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
54 sizer
->Add((wxWindow
*)child
, 1, wxEXPAND
);
60 wxString
wxDllWidget::GetDllExt()
62 return wxDllLoader::GetDllExt();
66 typedef WXDLLEXPORT
bool (*DLL_WidgetFactory_t
)(const wxString
& className
,
70 wxSendCommandFunc
*cmdFunc
);
72 bool wxDllWidget::LoadWidget(const wxString
& dll
, const wxString
& className
,
77 // Load the dynamic library
78 m_lib
= new wxDynamicLibrary(dll
);
79 if ( !m_lib
->IsLoaded() )
86 DLL_WidgetFactory_t factory
;
87 factory
= (DLL_WidgetFactory_t
) m_lib
->GetSymbol(wxT("DLL_WidgetFactory"));
95 if ( !factory(className
, this, style
, &m_widget
, &m_cmdFunc
) )
107 void wxDllWidget::UnloadWidget()
118 int wxDllWidget::SendCommand(int cmd
, const wxString
& param
)
120 wxASSERT_MSG( m_widget
&& m_cmdFunc
, wxT("Sending command to not loaded widget!"));
122 return m_cmdFunc(m_widget
, cmd
, param
);