]> git.saurik.com Git - wxWidgets.git/blob - src/os2/brush.cpp
OnEnter/OnDragOver API update (compiles, links, somewhat runs under wxGTK)
[wxWidgets.git] / src / os2 / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: brush.cpp
3 // Purpose: wxBrush
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/13/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include <stdio.h>
17 #include "wx/setup.h"
18 #include "wx/list.h"
19 #include "wx/utils.h"
20 #include "wx/app.h"
21 #include "wx/brush.h"
22 #endif
23
24 #include "wx/os2/private.h"
25
26 #include "assert.h"
27
28 #if !USE_SHARED_LIBRARIES
29 IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
30 #endif
31
32 wxBrushRefData::wxBrushRefData()
33 {
34 m_style = wxSOLID;
35 m_hBrush = 0;
36 }
37
38 wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
39 {
40 m_style = data.m_style;
41 m_stipple = data.m_stipple;
42 m_colour = data.m_colour;
43 m_hBrush = 0;
44 }
45
46 wxBrushRefData::~wxBrushRefData()
47 {
48 // TODO: delete data
49 }
50
51 // Brushes
52 wxBrush::wxBrush()
53 {
54 if ( wxTheBrushList )
55 wxTheBrushList->AddBrush(this);
56 }
57
58 wxBrush::~wxBrush()
59 {
60 if ( wxTheBrushList )
61 wxTheBrushList->RemoveBrush(this);
62 }
63
64 wxBrush::wxBrush(const wxColour& col, int Style)
65 {
66 m_refData = new wxBrushRefData;
67
68 M_BRUSHDATA->m_colour = col;
69 M_BRUSHDATA->m_style = Style;
70 M_BRUSHDATA->m_hBrush = 0;
71
72 RealizeResource();
73
74 if ( wxTheBrushList )
75 wxTheBrushList->AddBrush(this);
76 }
77
78 wxBrush::wxBrush(const wxBitmap& stipple)
79 {
80 m_refData = new wxBrushRefData;
81
82 M_BRUSHDATA->m_style = wxSTIPPLE;
83 M_BRUSHDATA->m_stipple = stipple;
84 M_BRUSHDATA->m_hBrush = 0;
85
86 RealizeResource();
87
88 if ( wxTheBrushList )
89 wxTheBrushList->AddBrush(this);
90 }
91
92 bool wxBrush::RealizeResource(void)
93 {
94 // TODO:
95 /*
96 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0))
97 {
98 if (M_BRUSHDATA->m_style==wxTRANSPARENT)
99 {
100 M_BRUSHDATA->m_hBrush = (WXHBRUSH) ::GetStockObject(NULL_BRUSH);
101 return TRUE;
102 }
103 COLORREF ms_colour = 0 ;
104
105 ms_colour = M_BRUSHDATA->m_colour.GetPixel() ;
106
107 switch (M_BRUSHDATA->m_style)
108 {
109 //
110 // Don't reset cbrush, wxTRANSPARENT is handled by wxBrush::SelectBrush()
111 // this could save (many) time if frequently switching from
112 // wxSOLID to wxTRANSPARENT, because Create... is not always called!!
113 //
114 // NB August 95: now create and select a Null brush instead.
115 // This could be optimized as above.
116 case wxTRANSPARENT:
117 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
118 // - could choose white always for a quick solution
119 break;
120 //
121 case wxBDIAGONAL_HATCH:
122 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_BDIAGONAL,ms_colour) ;
123 break ;
124
125 case wxCROSSDIAG_HATCH:
126 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_DIAGCROSS,ms_colour) ;
127 break ;
128
129 case wxFDIAGONAL_HATCH:
130 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_FDIAGONAL,ms_colour) ;
131 break ;
132
133 case wxCROSS_HATCH:
134 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_CROSS,ms_colour) ;
135 break ;
136
137 case wxHORIZONTAL_HATCH:
138 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_HORIZONTAL,ms_colour) ;
139 break ;
140
141 case wxVERTICAL_HATCH:
142 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_VERTICAL,ms_colour) ;
143 break ;
144
145 case wxSTIPPLE:
146 if (M_BRUSHDATA->m_stipple.Ok())
147 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreatePatternBrush((HBITMAP) M_BRUSHDATA->m_stipple.GetHBITMAP()) ;
148 else
149 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
150 break ;
151
152 case wxSOLID:
153 default:
154 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
155 break;
156 }
157 #ifdef WXDEBUG_CREATE
158 if (M_BRUSHDATA->m_hBrush==NULL) wxError("Cannot create brush","Internal error") ;
159 #endif
160 return TRUE;
161 }
162 else
163 return FALSE;
164 */
165 return FALSE;
166 }
167
168 WXHANDLE wxBrush::GetResourceHandle(void)
169 {
170 return (WXHANDLE) M_BRUSHDATA->m_hBrush;
171 }
172
173 bool wxBrush::FreeResource(bool WXUNUSED(force))
174 {
175 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush != 0))
176 {
177 // TODO DeleteObject((HBRUSH) M_BRUSHDATA->m_hBrush);
178 M_BRUSHDATA->m_hBrush = 0;
179 return TRUE;
180 }
181 else return FALSE;
182 }
183
184 bool wxBrush::IsFree() const
185 {
186 return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0));
187 }
188
189 void wxBrush::Unshare()
190 {
191 // Don't change shared data
192 if (!m_refData)
193 {
194 m_refData = new wxBrushRefData();
195 }
196 else
197 {
198 wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
199 UnRef();
200 m_refData = ref;
201 }
202 }
203
204 void wxBrush::SetColour(const wxColour& col)
205 {
206 Unshare();
207
208 M_BRUSHDATA->m_colour = col;
209
210 RealizeResource();
211 }
212
213 void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
214 {
215 Unshare();
216
217 M_BRUSHDATA->m_colour.Set(r, g, b);
218
219 RealizeResource();
220 }
221
222 void wxBrush::SetStyle(int Style)
223 {
224 Unshare();
225
226 M_BRUSHDATA->m_style = Style;
227
228 RealizeResource();
229 }
230
231 void wxBrush::SetStipple(const wxBitmap& Stipple)
232 {
233 Unshare();
234
235 M_BRUSHDATA->m_stipple = Stipple;
236
237 RealizeResource();
238 }
239