]>
git.saurik.com Git - wxWidgets.git/blob - src/common/rendcmn.cpp
2cedd7f4de8d788831a5e6a63b3692ff5b299d37
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/rendcmn.cpp
3 // Purpose: wxRendererNative common functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
32 #include "wx/apptrait.h"
33 #include "wx/renderer.h"
35 #include "wx/ptr_scpd.h"
37 #if wxUSE_DYNLIB_CLASS
38 #include "wx/dynlib.h"
39 #endif // wxUSE_DYNLIB_CLASS
41 // ----------------------------------------------------------------------------
42 // wxRendererPtr: auto pointer holding the global renderer
43 // ----------------------------------------------------------------------------
45 wxDECLARE_SCOPED_PTR(wxRendererNative
, wxRendererPtrBase
);
46 wxDEFINE_SCOPED_PTR(wxRendererNative
, wxRendererPtrBase
);
48 class wxRendererPtr
: public wxRendererPtrBase
51 // return true if we have a renderer, false otherwise
56 // only try to create the renderer once
65 // return the global and unique wxRendererPtr
66 static wxRendererPtr
& Get()
68 static wxRendererPtr s_renderer
;
74 wxRendererPtr() : wxRendererPtrBase(NULL
) { m_initialized
= false; }
78 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
81 // ask the traits object to create a renderer for us
82 reset(traits
->CreateRenderer());
88 // just to suppress a gcc warning
89 friend class wxRendererPtrDummyFriend
;
91 DECLARE_NO_COPY_CLASS(wxRendererPtr
)
94 #if wxUSE_DYNLIB_CLASS
96 // ----------------------------------------------------------------------------
97 // wxRendererFromDynLib: represents a renderer dynamically loaded from a DLL
98 // ----------------------------------------------------------------------------
100 class wxRendererFromDynLib
: public wxDelegateRendererNative
103 // create the object wrapping the given renderer created from this DLL
105 // we take ownership of the pointer and will delete it (and also unload the
106 // DLL) when we're deleted
107 wxRendererFromDynLib(wxDynamicLibrary
& dll
, wxRendererNative
*renderer
)
108 : wxDelegateRendererNative(*renderer
),
109 m_renderer(renderer
),
110 m_dllHandle(dll
.Detach())
114 virtual ~wxRendererFromDynLib()
117 wxDynamicLibrary::Unload(m_dllHandle
);
121 wxRendererNative
*m_renderer
;
122 wxDllType m_dllHandle
;
125 #endif // wxUSE_DYNLIB_CLASS
127 // ============================================================================
128 // wxRendererNative implementation
129 // ============================================================================
131 wxRendererNative::~wxRendererNative()
133 // empty but necessary
136 // ----------------------------------------------------------------------------
137 // Managing the global renderer
138 // ----------------------------------------------------------------------------
141 wxRendererNative
& wxRendererNative::Get()
143 wxRendererPtr
& renderer
= wxRendererPtr::Get();
145 return renderer
.IsOk() ? *renderer
.get() : GetDefault();
149 wxRendererNative
*wxRendererNative::Set(wxRendererNative
*rendererNew
)
151 wxRendererPtr
& renderer
= wxRendererPtr::Get();
153 wxRendererNative
*rendererOld
= renderer
.release();
155 renderer
.reset(rendererNew
);
161 // ----------------------------------------------------------------------------
162 // Dynamic renderers loading
163 // ----------------------------------------------------------------------------
165 #if wxUSE_DYNLIB_CLASS
168 wxRendererNative
*wxRendererNative::Load(const wxString
& name
)
170 wxString fullname
= wxDynamicLibrary::CanonicalizePluginName(name
);
172 wxDynamicLibrary
dll(fullname
);
173 if ( !dll
.IsLoaded() )
176 // each theme DLL must export a wxCreateRenderer() function with this
178 typedef wxRendererNative
*(*wxCreateRenderer_t
)();
180 wxDYNLIB_FUNCTION(wxCreateRenderer_t
, wxCreateRenderer
, dll
);
181 if ( !pfnwxCreateRenderer
)
184 // create a renderer object
185 wxRendererNative
*renderer
= (*pfnwxCreateRenderer
)();
189 // check that its version is compatible with ours
190 wxRendererVersion ver
= renderer
->GetVersion();
191 if ( !wxRendererVersion::IsCompatible(ver
) )
193 wxLogError(_("Renderer \"%s\" has incompatible version %d.%d and couldn't be loaded."),
194 name
.c_str(), ver
.version
, ver
.age
);
200 // finally wrap the renderer in an object which will delete it and unload
201 // the library when it is deleted and return it to the caller
202 return new wxRendererFromDynLib(dll
, renderer
);
205 #endif // wxUSE_DYNLIB_CLASS