1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dynamically loadable C++ widget for wxPython
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2001 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "dllwidget.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
23 #include "wx/dynlib.h"
26 #include "dllwidget.h"
29 IMPLEMENT_ABSTRACT_CLASS(wxDllWidget
, wxPanel
)
31 wxDllWidget::wxDllWidget(wxWindow
*parent
,
33 const wxString
& dllName
, const wxString
& className
,
34 const wxPoint
& pos
, const wxSize
& size
,
36 : wxPanel(parent
, id
, pos
, size
, wxTAB_TRAVERSAL
| wxNO_BORDER
,
37 className
+ wxT("_container")),
38 m_widget(NULL
), m_lib(NULL
), m_controlAdded(FALSE
)
40 SetBackgroundColour(wxColour(255, 0, 255));
42 LoadWidget(dllName
, className
, style
);
45 wxDllWidget::~wxDllWidget()
50 void wxDllWidget::AddChild(wxWindowBase
*child
)
52 wxASSERT_MSG( !m_controlAdded
, wxT("Couldn't load two widgets into one container!") )
54 wxPanel::AddChild(child
);
56 m_controlAdded
= TRUE
;
57 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
58 sizer
->Add((wxWindow
*)child
, 1, wxEXPAND
);
65 wxString
wxDllWidget::GetDllExt()
67 return wxDllLoader::GetDllExt();
71 typedef WXDLLEXPORT
bool (*DLL_WidgetFactory_t
)(const wxString
& className
,
75 wxSendCommandFunc
*cmdFunc
);
77 bool wxDllWidget::LoadWidget(const wxString
& dll
, const wxString
& className
,
82 // Load the dynamic library
83 m_lib
= new wxDynamicLibrary(dll
);
84 if ( !m_lib
->IsLoaded() )
91 DLL_WidgetFactory_t factory
;
92 factory
= (DLL_WidgetFactory_t
) m_lib
->GetSymbol(wxT("DLL_WidgetFactory"));
100 if ( !factory(className
, this, style
, &m_widget
, &m_cmdFunc
) )
112 void wxDllWidget::UnloadWidget()
123 int wxDllWidget::SendCommand(int cmd
, const wxString
& param
)
125 wxASSERT_MSG( m_widget
&& m_cmdFunc
, wxT("Sending command to not loaded widget!"));
127 return m_cmdFunc(m_widget
, cmd
, param
);