]> git.saurik.com Git - wxWidgets.git/blob - src/common/rendcmn.cpp
xti streaming extensions
[wxWidgets.git] / src / common / rendcmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/rendcmn.cpp
3 // Purpose: wxRendererNative common functions
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 28.07.03
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #ifndef WX_PRECOMP
27 #include "wx/app.h"
28 #endif //WX_PRECOMP
29
30 #include "wx/apptrait.h"
31 #include "wx/renderer.h"
32
33 #include "wx/ptr_scpd.h"
34
35 // ----------------------------------------------------------------------------
36 // wxRendererPtr: auto pointer holding the global renderer
37 // ----------------------------------------------------------------------------
38
39 wxDECLARE_SCOPED_PTR(wxRendererNative, wxRendererPtrBase);
40 wxDEFINE_SCOPED_PTR(wxRendererNative, wxRendererPtrBase);
41
42 class wxRendererPtr : public wxRendererPtrBase
43 {
44 public:
45 wxRendererPtr() : wxRendererPtrBase(NULL) { m_initialized = false; }
46
47 // return true if we have a renderer, false otherwise
48 bool IsOk()
49 {
50 if ( !m_initialized )
51 {
52 // only try to create the renderer once
53 m_initialized = true;
54
55 DoInit();
56 }
57
58 return get() != NULL;
59 }
60
61 private:
62 void DoInit()
63 {
64 wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
65 if ( traits )
66 {
67 // ask the traits object to create a renderer for us
68 reset(traits->CreateRenderer());
69 }
70 }
71
72 bool m_initialized;
73
74 DECLARE_NO_COPY_CLASS(wxRendererPtr)
75 };
76
77 // ============================================================================
78 // wxRendererNative implementation
79 // ============================================================================
80
81 /* static */
82 wxRendererNative& wxRendererNative::Get()
83 {
84 static wxRendererPtr s_renderer;
85
86 return s_renderer.IsOk() ? *s_renderer.get() : GetDefault();
87 }
88