]> git.saurik.com Git - wxWidgets.git/blame - wxPython/contrib/dllwidget/dllwidget.cpp
No animate contrib anymore
[wxWidgets.git] / wxPython / contrib / dllwidget / dllwidget.cpp
CommitLineData
4a61305d
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: dllwidget.cpp
3// Purpose: Dynamically loadable C++ widget for wxPython
4// Author: Vaclav Slavik
5// Created: 2001/12/03
6// RCS-ID: $Id$
7// Copyright: (c) 2001 Vaclav Slavik
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
4a61305d
RD
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18#include "wx/defs.h"
19#include "wx/dynlib.h"
20#include "wx/sizer.h"
21
22#include "dllwidget.h"
23
24
25IMPLEMENT_ABSTRACT_CLASS(wxDllWidget, wxPanel)
26
27wxDllWidget::wxDllWidget(wxWindow *parent,
28 wxWindowID id,
29 const wxString& dllName, const wxString& className,
30 const wxPoint& pos, const wxSize& size,
31 long style)
32 : wxPanel(parent, id, pos, size, wxTAB_TRAVERSAL | wxNO_BORDER,
33 className + wxT("_container")),
dabbc6a5 34 m_widget(NULL), m_lib(NULL), m_controlAdded(false)
4a61305d
RD
35{
36 SetBackgroundColour(wxColour(255, 0, 255));
37 if ( !!className )
38 LoadWidget(dllName, className, style);
39}
40
41wxDllWidget::~wxDllWidget()
42{
43 UnloadWidget();
44}
45
46void wxDllWidget::AddChild(wxWindowBase *child)
47{
63fd5f0b 48 wxASSERT_MSG( !m_controlAdded, wxT("Couldn't load two widgets into one container!") );
4a61305d
RD
49
50 wxPanel::AddChild(child);
51
dabbc6a5 52 m_controlAdded = true;
4a61305d
RD
53 wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
54 sizer->Add((wxWindow*)child, 1, wxEXPAND);
55 SetSizer(sizer);
4a61305d
RD
56 Layout();
57}
58
59
60wxString wxDllWidget::GetDllExt()
61{
62 return wxDllLoader::GetDllExt();
63}
64
65
66typedef WXDLLEXPORT bool (*DLL_WidgetFactory_t)(const wxString& className,
67 wxWindow *parent,
68 long style,
69 wxWindow **classInst,
70 wxSendCommandFunc *cmdFunc);
71
72bool wxDllWidget::LoadWidget(const wxString& dll, const wxString& className,
73 long style)
74{
75 UnloadWidget();
76
77 // Load the dynamic library
78 m_lib = new wxDynamicLibrary(dll);
79 if ( !m_lib->IsLoaded() )
80 {
81 delete m_lib;
82 m_lib = NULL;
dabbc6a5 83 return false;
4a61305d
RD
84 }
85
86 DLL_WidgetFactory_t factory;
87 factory = (DLL_WidgetFactory_t) m_lib->GetSymbol(wxT("DLL_WidgetFactory"));
88 if ( factory == NULL)
89 {
90 delete m_lib;
91 m_lib = NULL;
dabbc6a5 92 return false;
4a61305d
RD
93 }
94
95 if ( !factory(className, this, style, &m_widget, &m_cmdFunc) )
96 {
97 delete m_widget;
98 delete m_lib;
99 m_lib = NULL;
100 m_widget = NULL;
dabbc6a5 101 return false;
4a61305d
RD
102 }
103
dabbc6a5 104 return true;
4a61305d
RD
105}
106
107void wxDllWidget::UnloadWidget()
108{
109 if ( m_widget )
110 {
111 DestroyChildren();
112 m_widget = NULL;
113 delete m_lib;
114 m_lib = NULL;
115 }
116}
117
118int wxDllWidget::SendCommand(int cmd, const wxString& param)
119{
120 wxASSERT_MSG( m_widget && m_cmdFunc, wxT("Sending command to not loaded widget!"));
121
122 return m_cmdFunc(m_widget, cmd, param);
123}