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
); 
  64 wxString 
wxDllWidget::GetDllExt() 
  66     return wxDllLoader::GetDllExt(); 
  70 typedef WXDLLEXPORT 
bool (*DLL_WidgetFactory_t
)(const wxString
& className
, 
  74                                                 wxSendCommandFunc 
*cmdFunc
); 
  76 bool wxDllWidget::LoadWidget(const wxString
& dll
, const wxString
& className
, 
  81     // Load the dynamic library 
  82     m_lib 
= new wxDynamicLibrary(dll
); 
  83     if ( !m_lib
->IsLoaded() ) 
  90     DLL_WidgetFactory_t factory
; 
  91     factory 
= (DLL_WidgetFactory_t
) m_lib
->GetSymbol(wxT("DLL_WidgetFactory")); 
  99     if ( !factory(className
, this, style
, &m_widget
, &m_cmdFunc
) ) 
 111 void wxDllWidget::UnloadWidget() 
 122 int wxDllWidget::SendCommand(int cmd
, const wxString
& param
) 
 124     wxASSERT_MSG( m_widget 
&& m_cmdFunc
, wxT("Sending command to not loaded widget!")); 
 126     return m_cmdFunc(m_widget
, cmd
, param
);