]> git.saurik.com Git - wxWidgets.git/blame - src/os2/pen.cpp
Changed order of #ifdefs to get native version on OS/2, even if
[wxWidgets.git] / src / os2 / pen.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: pen.cpp
3// Purpose: wxPen
cdf1e714 4// Author: David Webster
0e320a79 5// Modified by:
cdf1e714 6// Created: 10/10/99
0e320a79 7// RCS-ID: $Id$
cdf1e714
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
cdf1e714
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
cdf1e714
DW
15#ifndef WX_PRECOMP
16#include <stdio.h>
0e320a79 17#include "wx/setup.h"
cdf1e714 18#include "wx/list.h"
0e320a79 19#include "wx/utils.h"
cdf1e714 20#include "wx/app.h"
0e320a79 21#include "wx/pen.h"
0e320a79
DW
22#endif
23
cdf1e714
DW
24#include "wx/os2/private.h"
25#include "assert.h"
26
004fd0c8 27IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
004fd0c8 28
0e320a79
DW
29wxPenRefData::wxPenRefData()
30{
31 m_style = wxSOLID;
32 m_width = 1;
33 m_join = wxJOIN_ROUND ;
34 m_cap = wxCAP_ROUND ;
35 m_nbDash = 0 ;
36 m_dash = 0 ;
0e320a79 37 m_hPen = 0;
0e320a79
DW
38}
39
40wxPenRefData::wxPenRefData(const wxPenRefData& data)
41{
42 m_style = data.m_style;
43 m_width = data.m_width;
44 m_join = data.m_join;
45 m_cap = data.m_cap;
46 m_nbDash = data.m_nbDash;
47 m_dash = data.m_dash;
48 m_colour = data.m_colour;
49/* TODO: null data
50 m_hPen = 0;
51*/
52}
53
54wxPenRefData::~wxPenRefData()
55{
56 // TODO: delete data
57}
58
59// Pens
60
61wxPen::wxPen()
62{
63 if ( wxThePenList )
64 wxThePenList->AddPen(this);
65}
66
67wxPen::~wxPen()
68{
69 if (wxThePenList)
70 wxThePenList->RemovePen(this);
71}
72
73// Should implement Create
74wxPen::wxPen(const wxColour& col, int Width, int Style)
75{
76 m_refData = new wxPenRefData;
77
78 M_PENDATA->m_colour = col;
cdf1e714 79// M_PENDATA->m_stipple = NULL;
0e320a79
DW
80 M_PENDATA->m_width = Width;
81 M_PENDATA->m_style = Style;
82 M_PENDATA->m_join = wxJOIN_ROUND ;
83 M_PENDATA->m_cap = wxCAP_ROUND ;
84 M_PENDATA->m_nbDash = 0 ;
85 M_PENDATA->m_dash = 0 ;
cdf1e714
DW
86 M_PENDATA->m_hPen = 0 ;
87
88// TODO:
89/*
90 if ((Style == wxDOT) || (Style == wxLONG_DASH) ||
91 (Style == wxSHORT_DASH) || (Style == wxDOT_DASH) ||
92 (Style == wxUSER_DASH))
93 M_PENDATA->m_width = 1;
94*/
0e320a79
DW
95 RealizeResource();
96
97 if ( wxThePenList )
98 wxThePenList->AddPen(this);
99}
100
101wxPen::wxPen(const wxBitmap& stipple, int Width)
102{
103 m_refData = new wxPenRefData;
104
105 M_PENDATA->m_stipple = stipple;
106 M_PENDATA->m_width = Width;
107 M_PENDATA->m_style = wxSTIPPLE;
108 M_PENDATA->m_join = wxJOIN_ROUND ;
109 M_PENDATA->m_cap = wxCAP_ROUND ;
110 M_PENDATA->m_nbDash = 0 ;
111 M_PENDATA->m_dash = 0 ;
cdf1e714 112 M_PENDATA->m_hPen = 0 ;
0e320a79
DW
113
114 RealizeResource();
115
116 if ( wxThePenList )
117 wxThePenList->AddPen(this);
118}
119
cdf1e714
DW
120bool wxPen::RealizeResource()
121{
122 // TODO: create actual pen
123 return FALSE;
124}
125
126WXHANDLE wxPen::GetResourceHandle()
127{
128 if ( !M_PENDATA )
129 return 0;
130 else
131 return (WXHANDLE)M_PENDATA->m_hPen;
132}
133
134bool wxPen::FreeResource(bool force)
135{
136 if (M_PENDATA && (M_PENDATA->m_hPen != 0))
137 {
fb46a9a6 138// TODO: DeleteObject((HPEN) M_PENDATA->m_hPen);
cdf1e714
DW
139 M_PENDATA->m_hPen = 0;
140 return TRUE;
141 }
142 else return FALSE;
143}
144
e6ebb514
DW
145bool wxPen::IsFree() const
146{
147 return (M_PENDATA && M_PENDATA->m_hPen == 0);
148}
149
0e320a79
DW
150void wxPen::Unshare()
151{
cdf1e714
DW
152 // Don't change shared data
153 if (!m_refData)
0e320a79 154 {
cdf1e714
DW
155 m_refData = new wxPenRefData();
156 }
0e320a79
DW
157 else
158 {
cdf1e714
DW
159 wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
160 UnRef();
161 m_refData = ref;
162 }
0e320a79
DW
163}
164
165void wxPen::SetColour(const wxColour& col)
166{
167 Unshare();
168
169 M_PENDATA->m_colour = col;
fb46a9a6 170
0e320a79
DW
171 RealizeResource();
172}
173
174void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
175{
176 Unshare();
177
178 M_PENDATA->m_colour.Set(r, g, b);
fb46a9a6 179
0e320a79
DW
180 RealizeResource();
181}
182
183void wxPen::SetWidth(int Width)
184{
185 Unshare();
186
187 M_PENDATA->m_width = Width;
188
189 RealizeResource();
190}
191
192void wxPen::SetStyle(int Style)
193{
194 Unshare();
195
196 M_PENDATA->m_style = Style;
197
198 RealizeResource();
199}
200
201void wxPen::SetStipple(const wxBitmap& Stipple)
202{
203 Unshare();
204
205 M_PENDATA->m_stipple = Stipple;
206 M_PENDATA->m_style = wxSTIPPLE;
fb46a9a6 207
0e320a79
DW
208 RealizeResource();
209}
210
211void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
212{
213 Unshare();
214
215 M_PENDATA->m_nbDash = nb_dashes;
216 M_PENDATA->m_dash = (wxDash *)Dash;
fb46a9a6 217
0e320a79
DW
218 RealizeResource();
219}
220
221void wxPen::SetJoin(int Join)
222{
223 Unshare();
224
225 M_PENDATA->m_join = Join;
226
227 RealizeResource();
228}
229
230void wxPen::SetCap(int Cap)
231{
232 Unshare();
233
234 M_PENDATA->m_cap = Cap;
235
236 RealizeResource();
237}
238
cdf1e714
DW
239int wx2os2PenStyle(int wx_style)
240{
9dea36ef 241 int cstyle = 0;
cdf1e714
DW
242// TODO:
243/*
244 switch (wx_style)
fb46a9a6 245 {
cdf1e714
DW
246 case wxDOT:
247 cstyle = PS_DOT;
248 break;
249
250 case wxDOT_DASH:
251 cstyle = PS_DASHDOT;
252 break;
253
254 case wxSHORT_DASH:
255 case wxLONG_DASH:
256 cstyle = PS_DASH;
257 break;
258
259 case wxTRANSPARENT:
260 cstyle = PS_NULL;
261 break;
262
263 case wxUSER_DASH:
264#ifdef __WIN32__
265 // Win32s doesn't have PS_USERSTYLE
266 if (wxGetOsVersion()==wxWINDOWS_NT || wxGetOsVersion()==wxWIN95)
267 cstyle = PS_USERSTYLE;
268 else
269 cstyle = PS_DOT; // We must make a choice... This is mine!
270#else
271 cstyle = PS_DASH;
272#endif
273 break;
274 case wxSOLID:
275 default:
276 cstyle = PS_SOLID;
277 break;
278 }
279*/
280 return cstyle;
0e320a79
DW
281}
282
283