]> git.saurik.com Git - wxWidgets.git/blame - src/x11/brush.cpp
avoid trying to link QA if not required
[wxWidgets.git] / src / x11 / brush.cpp
CommitLineData
83df96d6 1/////////////////////////////////////////////////////////////////////////////
7266b672 2// Name: src/x11/brush.cpp
83df96d6
JS
3// Purpose: wxBrush
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
83df96d6
JS
10/////////////////////////////////////////////////////////////////////////////
11
83df96d6
JS
12#include "wx/setup.h"
13#include "wx/utils.h"
14#include "wx/brush.h"
69c44812 15#include "wx/bitmap.h"
ed39ff57 16#include "wx/colour.h"
83df96d6 17
74dc5eb6
RR
18//-----------------------------------------------------------------------------
19// wxBrush
20//-----------------------------------------------------------------------------
83df96d6 21
74dc5eb6 22class wxBrushRefData: public wxObjectRefData
83df96d6 23{
74dc5eb6
RR
24public:
25 wxBrushRefData()
26 {
27 m_style = 0;
28 }
29
30 wxBrushRefData( const wxBrushRefData& data )
31 {
32 m_style = data.m_style;
33 m_stipple = data.m_stipple;
34 m_colour = data.m_colour;
35 }
36
37 bool operator == (const wxBrushRefData& data) const
38 {
39 return (m_style == data.m_style &&
40 m_stipple == data.m_stipple &&
41 m_colour == data.m_colour);
42 }
43
44 int m_style;
45 wxColour m_colour;
46 wxBitmap m_stipple;
47};
83df96d6 48
74dc5eb6 49//-----------------------------------------------------------------------------
83df96d6 50
74dc5eb6
RR
51#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
52
53IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
54
55wxBrush::wxBrush( const wxColour &colour, int style )
83df96d6 56{
74dc5eb6
RR
57 m_refData = new wxBrushRefData();
58 M_BRUSHDATA->m_style = style;
59 M_BRUSHDATA->m_colour = colour;
83df96d6
JS
60}
61
74dc5eb6 62wxBrush::wxBrush( const wxBitmap &stippleBitmap )
83df96d6 63{
74dc5eb6
RR
64 m_refData = new wxBrushRefData();
65 M_BRUSHDATA->m_colour = *wxBLACK;
66
67 M_BRUSHDATA->m_stipple = stippleBitmap;
68
69 if (M_BRUSHDATA->m_stipple.GetMask())
70 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
71 else
72 M_BRUSHDATA->m_style = wxSTIPPLE;
83df96d6
JS
73}
74
75wxBrush::~wxBrush()
76{
74dc5eb6 77 // m_refData unrefed in ~wxObject
83df96d6
JS
78}
79
74dc5eb6 80wxObjectRefData *wxBrush::CreateRefData() const
83df96d6 81{
74dc5eb6 82 return new wxBrushRefData;
83df96d6
JS
83}
84
74dc5eb6 85wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
83df96d6 86{
74dc5eb6
RR
87 return new wxBrushRefData(*(wxBrushRefData *)data);
88}
83df96d6 89
74dc5eb6
RR
90bool wxBrush::operator == ( const wxBrush& brush ) const
91{
92 if (m_refData == brush.m_refData) return TRUE;
93
94 if (!m_refData || !brush.m_refData) return FALSE;
95
96 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
83df96d6
JS
97}
98
74dc5eb6 99int wxBrush::GetStyle() const
83df96d6 100{
74dc5eb6 101 if (m_refData == NULL)
83df96d6 102 {
74dc5eb6
RR
103 wxFAIL_MSG( wxT("invalid brush") );
104 return 0;
83df96d6 105 }
74dc5eb6
RR
106
107 return M_BRUSHDATA->m_style;
83df96d6
JS
108}
109
74dc5eb6 110wxColour &wxBrush::GetColour() const
83df96d6 111{
74dc5eb6
RR
112 if (m_refData == NULL)
113 {
114 wxFAIL_MSG( wxT("invalid brush") );
115 return wxNullColour;
116 }
83df96d6 117
74dc5eb6 118 return M_BRUSHDATA->m_colour;
83df96d6
JS
119}
120
74dc5eb6 121wxBitmap *wxBrush::GetStipple() const
83df96d6 122{
74dc5eb6
RR
123 if (m_refData == NULL)
124 {
125 wxFAIL_MSG( wxT("invalid brush") );
126 return &wxNullBitmap;
127 }
83df96d6 128
74dc5eb6 129 return &M_BRUSHDATA->m_stipple;
83df96d6
JS
130}
131
74dc5eb6 132void wxBrush::SetColour( const wxColour& col )
83df96d6 133{
74dc5eb6
RR
134 AllocExclusive();
135
136 M_BRUSHDATA->m_colour = col;
83df96d6
JS
137}
138
74dc5eb6 139void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
83df96d6 140{
74dc5eb6
RR
141 AllocExclusive();
142
143 M_BRUSHDATA->m_colour.Set( r, g, b );
83df96d6
JS
144}
145
74dc5eb6 146void wxBrush::SetStyle( int style )
83df96d6 147{
74dc5eb6
RR
148 AllocExclusive();
149
150 M_BRUSHDATA->m_style = style;
83df96d6
JS
151}
152
74dc5eb6
RR
153void wxBrush::SetStipple( const wxBitmap& stipple )
154{
155 AllocExclusive();
156
157 M_BRUSHDATA->m_stipple = stipple;
158 if (M_BRUSHDATA->m_stipple.GetMask())
159 {
160 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
161 }
162 else
163 {
164 M_BRUSHDATA->m_style = wxSTIPPLE;
165 }
166}