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