]>
git.saurik.com Git - wxWidgets.git/blob - src/common/rendcmn.cpp
6cbdbb9d5a10b8132f1309e6f0834d73d4338c04
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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/scopedptr.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 typedef wxScopedPtr
<wxRendererNative
> wxRendererPtrBase
;
47 class wxRendererPtr
: public wxRendererPtrBase
50 // return true if we have a renderer, false otherwise
55 // only try to create the renderer once
64 // return the global and unique wxRendererPtr
65 static wxRendererPtr
& Get();
68 wxRendererPtr() : wxRendererPtrBase(NULL
) { m_initialized
= false; }
72 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
75 // ask the traits object to create a renderer for us
76 reset(traits
->CreateRenderer());
82 // just to suppress a gcc warning
83 friend class wxRendererPtrDummyFriend
;
85 wxDECLARE_NO_COPY_CLASS(wxRendererPtr
);
88 // return the global and unique wxRendererPtr
89 /*static*/ wxRendererPtr
& wxRendererPtr::Get()
91 static wxRendererPtr s_renderer
;
96 #if wxUSE_DYNLIB_CLASS
98 // ----------------------------------------------------------------------------
99 // wxRendererFromDynLib: represents a renderer dynamically loaded from a DLL
100 // ----------------------------------------------------------------------------
102 class wxRendererFromDynLib
: public wxDelegateRendererNative
105 // create the object wrapping the given renderer created from this DLL
107 // we take ownership of the pointer and will delete it (and also unload the
108 // DLL) when we're deleted
109 wxRendererFromDynLib(wxDynamicLibrary
& dll
, wxRendererNative
*renderer
)
110 : wxDelegateRendererNative(*renderer
),
111 m_renderer(renderer
),
112 m_dllHandle(dll
.Detach())
116 virtual ~wxRendererFromDynLib()
119 wxDynamicLibrary::Unload(m_dllHandle
);
123 wxRendererNative
*m_renderer
;
124 wxDllType m_dllHandle
;
127 #endif // wxUSE_DYNLIB_CLASS
129 // ============================================================================
130 // wxRendererNative implementation
131 // ============================================================================
133 wxRendererNative::~wxRendererNative()
135 // empty but necessary
138 // ----------------------------------------------------------------------------
139 // Managing the global renderer
140 // ----------------------------------------------------------------------------
143 wxRendererNative
& wxRendererNative::Get()
145 wxRendererPtr
& renderer
= wxRendererPtr::Get();
147 return renderer
.IsOk() ? *renderer
.get() : GetDefault();
151 wxRendererNative
*wxRendererNative::Set(wxRendererNative
*rendererNew
)
153 wxRendererPtr
& renderer
= wxRendererPtr::Get();
155 wxRendererNative
*rendererOld
= renderer
.release();
157 renderer
.reset(rendererNew
);
163 // ----------------------------------------------------------------------------
164 // Dynamic renderers loading
165 // ----------------------------------------------------------------------------
167 #if wxUSE_DYNLIB_CLASS
170 wxRendererNative
*wxRendererNative::Load(const wxString
& name
)
172 wxString fullname
= wxDynamicLibrary::CanonicalizePluginName(name
);
174 wxDynamicLibrary
dll(fullname
);
175 if ( !dll
.IsLoaded() )
178 // each theme DLL must export a wxCreateRenderer() function with this
180 typedef wxRendererNative
*(*wxCreateRenderer_t
)();
182 wxDYNLIB_FUNCTION(wxCreateRenderer_t
, wxCreateRenderer
, dll
);
183 if ( !pfnwxCreateRenderer
)
186 // create a renderer object
187 wxRendererNative
*renderer
= (*pfnwxCreateRenderer
)();
191 // check that its version is compatible with ours
192 wxRendererVersion ver
= renderer
->GetVersion();
193 if ( !wxRendererVersion::IsCompatible(ver
) )
195 wxLogError(_("Renderer \"%s\" has incompatible version %d.%d and couldn't be loaded."),
196 name
.c_str(), ver
.version
, ver
.age
);
202 // finally wrap the renderer in an object which will delete it and unload
203 // the library when it is deleted and return it to the caller
204 return new wxRendererFromDynLib(dll
, renderer
);
207 #endif // wxUSE_DYNLIB_CLASS