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