]> git.saurik.com Git - wxWidgets.git/blob - src/common/cairo.cpp
Add some version checks to help compiling on OSX.
[wxWidgets.git] / src / common / cairo.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/cairo.cpp
3 // Purpose: Cairo library
4 // Author: Anthony Betaudeau
5 // Created: 2007-08-25
6 // RCS-ID: $Id$
7 // Copyright: (c) Anthony Bretaudeau
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #include "wx/cairo.h"
20
21 #if wxUSE_CAIRO
22
23 #ifndef WX_PRECOMP
24 #include "wx/module.h"
25 #include "wx/log.h"
26 #endif
27
28
29 wxCairoLibrary *wxCairoLibrary::ms_lib = NULL;
30
31 //----------------------------------------------------------------------------
32 // wxCairoLibrary
33 //----------------------------------------------------------------------------
34
35 wxCairoLibrary::wxCairoLibrary()
36 {
37 wxLogNull log;
38
39 m_libCairo.Load("libcairo.so.2");
40 m_ok = m_libCairo.IsLoaded();
41 if ( !m_ok )
42 return;
43
44 #if wxUSE_PANGO
45 m_libPangoCairo.Load("libpangocairo-1.0.so.0");
46 m_ok = m_libPangoCairo.IsLoaded();
47 if ( !m_ok )
48 {
49 m_libCairo.Unload();
50 return;
51 }
52 #endif
53
54 m_ok = InitializeMethods();
55 }
56
57 wxCairoLibrary::~wxCairoLibrary()
58 {
59 }
60
61 /* static */ wxCairoLibrary* wxCairoLibrary::Get()
62 {
63 if ( !ms_lib )
64 {
65 ms_lib = new wxCairoLibrary();
66 if ( !ms_lib->IsOk() )
67 {
68 delete ms_lib;
69 ms_lib = NULL;
70 }
71 }
72
73 return ms_lib;
74 }
75
76 /* static */ void wxCairoLibrary::CleanUp()
77 {
78 if (ms_lib)
79 {
80 delete ms_lib;
81 ms_lib = NULL;
82 }
83 }
84
85 bool wxCairoLibrary::IsOk()
86 {
87 return m_ok;
88 }
89
90 bool wxCairoLibrary::InitializeMethods()
91 {
92 wxDL_METHOD_LOAD(m_libCairo, cairo_arc);
93 wxDL_METHOD_LOAD(m_libCairo, cairo_arc_negative);
94 wxDL_METHOD_LOAD(m_libCairo, cairo_clip);
95 wxDL_METHOD_LOAD(m_libCairo, cairo_close_path);
96 wxDL_METHOD_LOAD(m_libCairo, cairo_create);
97 wxDL_METHOD_LOAD(m_libCairo, cairo_curve_to);
98 wxDL_METHOD_LOAD(m_libCairo, cairo_destroy);
99 wxDL_METHOD_LOAD(m_libCairo, cairo_fill);
100 wxDL_METHOD_LOAD(m_libCairo, cairo_fill_preserve);
101 wxDL_METHOD_LOAD(m_libCairo, cairo_get_target);
102 wxDL_METHOD_LOAD(m_libCairo, cairo_image_surface_create_for_data);
103 wxDL_METHOD_LOAD(m_libCairo, cairo_line_to);
104 wxDL_METHOD_LOAD(m_libCairo, cairo_move_to);
105 wxDL_METHOD_LOAD(m_libCairo, cairo_new_path);
106 wxDL_METHOD_LOAD(m_libCairo, cairo_paint);
107 wxDL_METHOD_LOAD(m_libCairo, cairo_pattern_add_color_stop_rgba);
108 wxDL_METHOD_LOAD(m_libCairo, cairo_pattern_create_for_surface);
109 wxDL_METHOD_LOAD(m_libCairo, cairo_pattern_create_linear);
110 wxDL_METHOD_LOAD(m_libCairo, cairo_pattern_create_radial);
111 wxDL_METHOD_LOAD(m_libCairo, cairo_pattern_destroy);
112 wxDL_METHOD_LOAD(m_libCairo, cairo_pattern_set_extend);
113 wxDL_METHOD_LOAD(m_libCairo, cairo_pattern_set_filter);
114 wxDL_METHOD_LOAD(m_libCairo, cairo_rectangle);
115 wxDL_METHOD_LOAD(m_libCairo, cairo_reset_clip);
116 wxDL_METHOD_LOAD(m_libCairo, cairo_restore);
117 wxDL_METHOD_LOAD(m_libCairo, cairo_rotate);
118 wxDL_METHOD_LOAD(m_libCairo, cairo_save);
119 wxDL_METHOD_LOAD(m_libCairo, cairo_scale);
120 wxDL_METHOD_LOAD(m_libCairo, cairo_set_dash);
121 wxDL_METHOD_LOAD(m_libCairo, cairo_set_fill_rule);
122 wxDL_METHOD_LOAD(m_libCairo, cairo_set_line_cap);
123 wxDL_METHOD_LOAD(m_libCairo, cairo_set_line_join);
124 wxDL_METHOD_LOAD(m_libCairo, cairo_set_line_width);
125 wxDL_METHOD_LOAD(m_libCairo, cairo_set_operator);
126 wxDL_METHOD_LOAD(m_libCairo, cairo_set_source);
127 wxDL_METHOD_LOAD(m_libCairo, cairo_set_source_rgba);
128 wxDL_METHOD_LOAD(m_libCairo, cairo_stroke);
129 wxDL_METHOD_LOAD(m_libCairo, cairo_stroke_preserve);
130 wxDL_METHOD_LOAD(m_libCairo, cairo_surface_create_similar);
131 wxDL_METHOD_LOAD(m_libCairo, cairo_surface_destroy);
132 wxDL_METHOD_LOAD(m_libCairo, cairo_translate);
133
134 #if wxUSE_PANGO
135 wxDL_METHOD_LOAD(m_libPangoCairo, pango_cairo_update_layout);
136 wxDL_METHOD_LOAD(m_libPangoCairo, pango_cairo_show_layout);
137 #endif
138
139 return true;
140 }
141
142 //----------------------------------------------------------------------------
143 // wxCairoModule
144 //----------------------------------------------------------------------------
145
146 class wxCairoModule : public wxModule
147 {
148 public:
149 wxCairoModule() { }
150 virtual bool OnInit();
151 virtual void OnExit();
152
153 private:
154 DECLARE_DYNAMIC_CLASS(wxCairotModule)
155 };
156
157 bool wxCairoModule::OnInit()
158 {
159 return true;
160 }
161
162 void wxCairoModule::OnExit()
163 {
164 wxCairoLibrary::CleanUp();
165 }
166
167 IMPLEMENT_DYNAMIC_CLASS(wxCairoModule, wxModule)
168
169 #endif // wxUSE_CAIRO