]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/pen.cpp
Check for null return value in wxClientDC constructor
[wxWidgets.git] / src / gtk / pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: pen.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation "pen.h"
13 #endif
14
15 #include "wx/pen.h"
16
17 #include <gdk/gdk.h>
18
19 //-----------------------------------------------------------------------------
20 // wxPen
21 //-----------------------------------------------------------------------------
22
23 class wxPenRefData: public wxObjectRefData
24 {
25 public:
26 wxPenRefData()
27 {
28 m_width = 1;
29 m_style = wxSOLID;
30 m_joinStyle = wxJOIN_ROUND;
31 m_capStyle = wxCAP_ROUND;
32 m_dash = (wxGTKDash*) NULL;
33 m_countDashes = 0;
34 }
35
36 wxPenRefData( const wxPenRefData& data )
37 : wxObjectRefData()
38 {
39 m_style = data.m_style;
40 m_width = data.m_width;
41 m_joinStyle = data.m_joinStyle;
42 m_capStyle = data.m_capStyle;
43 m_colour = data.m_colour;
44 m_countDashes = data.m_countDashes;
45 /*
46 if (data.m_dash) TODO
47 m_dash = new
48 */
49 m_dash = data.m_dash;
50 }
51
52 bool operator == (const wxPenRefData& data) const
53 {
54 return (m_style == data.m_style &&
55 m_width == data.m_width &&
56 m_joinStyle == data.m_joinStyle &&
57 m_capStyle == data.m_capStyle &&
58 m_colour == data.m_colour);
59 }
60
61 int m_width;
62 int m_style;
63 int m_joinStyle;
64 int m_capStyle;
65 wxColour m_colour;
66 int m_countDashes;
67 wxGTKDash *m_dash;
68 };
69
70 //-----------------------------------------------------------------------------
71
72 #define M_PENDATA ((wxPenRefData *)m_refData)
73
74 IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
75
76 wxPen::wxPen( const wxColour &colour, int width, int style )
77 {
78 m_refData = new wxPenRefData();
79 M_PENDATA->m_width = width;
80 M_PENDATA->m_style = style;
81 M_PENDATA->m_colour = colour;
82 }
83
84 wxPen::~wxPen()
85 {
86 // m_refData unrefed in ~wxObject
87 }
88
89 wxObjectRefData *wxPen::CreateRefData() const
90 {
91 return new wxPenRefData;
92 }
93
94 wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
95 {
96 return new wxPenRefData(*(wxPenRefData *)data);
97 }
98
99 bool wxPen::operator == ( const wxPen& pen ) const
100 {
101 if (m_refData == pen.m_refData) return TRUE;
102
103 if (!m_refData || !pen.m_refData) return FALSE;
104
105 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
106 }
107
108 void wxPen::SetColour( const wxColour &colour )
109 {
110 AllocExclusive();
111
112 M_PENDATA->m_colour = colour;
113 }
114
115 void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
116 {
117 AllocExclusive();
118
119 M_PENDATA->m_countDashes = number_of_dashes;
120 M_PENDATA->m_dash = (wxGTKDash *)dash; /* TODO */
121 }
122
123 void wxPen::SetColour( int red, int green, int blue )
124 {
125 AllocExclusive();
126
127 M_PENDATA->m_colour.Set( red, green, blue );
128 }
129
130 void wxPen::SetCap( int capStyle )
131 {
132 AllocExclusive();
133
134 M_PENDATA->m_capStyle = capStyle;
135 }
136
137 void wxPen::SetJoin( int joinStyle )
138 {
139 AllocExclusive();
140
141 M_PENDATA->m_joinStyle = joinStyle;
142 }
143
144 void wxPen::SetStyle( int style )
145 {
146 AllocExclusive();
147
148 M_PENDATA->m_style = style;
149 }
150
151 void wxPen::SetWidth( int width )
152 {
153 AllocExclusive();
154
155 M_PENDATA->m_width = width;
156 }
157
158 int wxPen::GetDashes( wxDash **ptr ) const
159 {
160 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
161 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
162 }
163
164 int wxPen::GetDashCount() const
165 {
166 return (M_PENDATA->m_countDashes);
167 }
168
169 wxDash* wxPen::GetDash() const
170 {
171 return (wxDash*)M_PENDATA->m_dash;
172 }
173
174 int wxPen::GetCap() const
175 {
176 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
177
178 return M_PENDATA->m_capStyle;
179 }
180
181 int wxPen::GetJoin() const
182 {
183 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
184
185 return M_PENDATA->m_joinStyle;
186 }
187
188 int wxPen::GetStyle() const
189 {
190 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
191
192 return M_PENDATA->m_style;
193 }
194
195 int wxPen::GetWidth() const
196 {
197 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
198
199 return M_PENDATA->m_width;
200 }
201
202 wxColour &wxPen::GetColour() const
203 {
204 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
205
206 return M_PENDATA->m_colour;
207 }
208