]>
git.saurik.com Git - wxWidgets.git/blob - src/common/rendcmn.cpp
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"
30 #include "wx/apptrait.h"
31 #include "wx/renderer.h"
33 #include "wx/ptr_scpd.h"
35 #if wxUSE_DYNLIB_CLASS
36 #include "wx/dynlib.h"
37 #endif // wxUSE_DYNLIB_CLASS
39 // ----------------------------------------------------------------------------
40 // wxRendererPtr: auto pointer holding the global renderer
41 // ----------------------------------------------------------------------------
43 wxDECLARE_SCOPED_PTR(wxRendererNative
, wxRendererPtrBase
);
44 wxDEFINE_SCOPED_PTR(wxRendererNative
, wxRendererPtrBase
);
46 class wxRendererPtr
: public wxRendererPtrBase
49 // return true if we have a renderer, false otherwise
54 // only try to create the renderer once
63 // return the global and unique wxRendererPtr
64 static wxRendererPtr
& Get()
66 static wxRendererPtr s_renderer
;
72 wxRendererPtr() : wxRendererPtrBase(NULL
) { m_initialized
= false; }
76 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
79 // ask the traits object to create a renderer for us
80 reset(traits
->CreateRenderer());
86 DECLARE_NO_COPY_CLASS(wxRendererPtr
)
89 #if wxUSE_DYNLIB_CLASS
91 // ----------------------------------------------------------------------------
92 // wxRendererFromDynLib: represents a renderer dynamically loaded from a DLL
93 // ----------------------------------------------------------------------------
95 class wxRendererFromDynLib
: public wxDelegateRendererNative
98 // create the object wrapping the given renderer created from this DLL
100 // we take ownership of the pointer and will delete it (and also unload the
101 // DLL) when we're deleted
102 wxRendererFromDynLib(wxDynamicLibrary
& dll
, wxRendererNative
*renderer
)
103 : wxDelegateRendererNative(*renderer
),
104 m_renderer(renderer
),
105 m_dllHandle(dll
.Detach())
109 virtual ~wxRendererFromDynLib()
112 wxDynamicLibrary::Unload(m_dllHandle
);
116 wxRendererNative
*m_renderer
;
117 wxDllType m_dllHandle
;
120 #endif // wxUSE_DYNLIB_CLASS
122 // ============================================================================
123 // wxRendererNative implementation
124 // ============================================================================
126 // ----------------------------------------------------------------------------
127 // Managing the global renderer
128 // ----------------------------------------------------------------------------
131 wxRendererNative
& wxRendererNative::Get()
133 wxRendererPtr
& renderer
= wxRendererPtr::Get();
135 return renderer
.IsOk() ? *renderer
.get() : GetDefault();
139 wxRendererNative
*wxRendererNative::Set(wxRendererNative
*rendererNew
)
141 wxRendererPtr
& renderer
= wxRendererPtr::Get();
143 wxRendererNative
*rendererOld
= renderer
.release();
145 renderer
.reset(rendererNew
);
151 // ----------------------------------------------------------------------------
152 // Dynamic renderers loading
153 // ----------------------------------------------------------------------------
155 #if wxUSE_DYNLIB_CLASS
158 wxRendererNative
*wxRendererNative::Load(const wxString
& name
)
160 wxString fullname
= wxDynamicLibrary::CanonicalizePluginName(name
);
162 wxDynamicLibrary
dll(fullname
);
163 if ( !dll
.IsLoaded() )
166 // each theme DLL must export a wxCreateRenderer() function with this
168 typedef wxRendererNative
*(*wxCreateRenderer_t
)();
170 wxDYNLIB_FUNCTION(wxCreateRenderer_t
, wxCreateRenderer
, dll
);
171 if ( !pfnwxCreateRenderer
)
174 wxRendererNative
*renderer
= (*pfnwxCreateRenderer
)();
178 return new wxRendererFromDynLib(dll
, renderer
);
181 #endif // wxUSE_DYNLIB_CLASS