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