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