]> git.saurik.com Git - wxWidgets.git/blame - src/os2/brush.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[wxWidgets.git] / src / os2 / brush.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: brush.cpp
3// Purpose: wxBrush
37f214d5 4// Author: David Webster
0e320a79 5// Modified by:
37f214d5 6// Created: 10/13/99
0e320a79 7// RCS-ID: $Id$
37f214d5
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
37f214d5
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
37f214d5
DW
15#ifndef WX_PRECOMP
16#include <stdio.h>
0e320a79 17#include "wx/setup.h"
37f214d5 18#include "wx/list.h"
0e320a79 19#include "wx/utils.h"
37f214d5 20#include "wx/app.h"
0e320a79 21#include "wx/brush.h"
37f214d5
DW
22#endif
23
24#include "wx/os2/private.h"
25
26#include "assert.h"
0e320a79
DW
27
28#if !USE_SHARED_LIBRARIES
29IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
30#endif
31
32wxBrushRefData::wxBrushRefData()
33{
34 m_style = wxSOLID;
37f214d5 35 m_hBrush = 0;
0e320a79
DW
36}
37
38wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
39{
37f214d5
DW
40 m_style = data.m_style;
41 m_stipple = data.m_stipple;
42 m_colour = data.m_colour;
43 m_hBrush = 0;
0e320a79
DW
44}
45
46wxBrushRefData::~wxBrushRefData()
47{
48// TODO: delete data
49}
50
51// Brushes
52wxBrush::wxBrush()
53{
54 if ( wxTheBrushList )
55 wxTheBrushList->AddBrush(this);
56}
57
58wxBrush::~wxBrush()
59{
60 if ( wxTheBrushList )
61 wxTheBrushList->RemoveBrush(this);
62}
63
64wxBrush::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;
37f214d5 70 M_BRUSHDATA->m_hBrush = 0;
0e320a79
DW
71
72 RealizeResource();
73
74 if ( wxTheBrushList )
75 wxTheBrushList->AddBrush(this);
76}
77
78wxBrush::wxBrush(const wxBitmap& stipple)
79{
80 m_refData = new wxBrushRefData;
81
82 M_BRUSHDATA->m_style = wxSTIPPLE;
83 M_BRUSHDATA->m_stipple = stipple;
37f214d5 84 M_BRUSHDATA->m_hBrush = 0;
0e320a79
DW
85
86 RealizeResource();
87
88 if ( wxTheBrushList )
89 wxTheBrushList->AddBrush(this);
90}
91
37f214d5
DW
92bool 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
168WXHANDLE wxBrush::GetResourceHandle(void)
169{
170 return (WXHANDLE) M_BRUSHDATA->m_hBrush;
171}
172
173bool 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
184bool wxBrush::IsFree() const
185{
186 return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0));
187}
188
189void 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}
0e320a79
DW
203
204void wxBrush::SetColour(const wxColour& col)
205{
206 Unshare();
207
208 M_BRUSHDATA->m_colour = col;
209
210 RealizeResource();
211}
212
213void 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
222void wxBrush::SetStyle(int Style)
223{
224 Unshare();
225
226 M_BRUSHDATA->m_style = Style;
227
228 RealizeResource();
229}
230
231void wxBrush::SetStipple(const wxBitmap& Stipple)
232{
233 Unshare();
234
235 M_BRUSHDATA->m_stipple = Stipple;
236
237 RealizeResource();
238}
239