]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/brush.cpp
rtti api mods added
[wxWidgets.git] / src / gtk / brush.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
7ecb8b06 2// Name: src/gtk/brush.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
f96aa4d9 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
7ecb8b06 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2 10#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
c801d85f
KB
11#pragma implementation "brush.h"
12#endif
13
14f355c2
VS
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
16
c801d85f 17#include "wx/brush.h"
ed39ff57 18#include "wx/colour.h"
c801d85f 19
20e05ffb 20#include <gdk/gdk.h>
83624f79 21
c801d85f
KB
22//-----------------------------------------------------------------------------
23// wxBrush
24//-----------------------------------------------------------------------------
25
26class wxBrushRefData: public wxObjectRefData
27{
58c837a4 28public:
c89f5c02
RR
29 wxBrushRefData()
30 {
31 m_style = 0;
32 }
33
34 wxBrushRefData( const wxBrushRefData& data )
d84afea9 35 : wxObjectRefData()
c89f5c02
RR
36 {
37 m_style = data.m_style;
38 m_stipple = data.m_stipple;
39 m_colour = data.m_colour;
40 }
41
42 bool operator == (const wxBrushRefData& data) const
43 {
44 return (m_style == data.m_style &&
45 m_stipple == data.m_stipple &&
46 m_colour == data.m_colour);
47 }
48
49 int m_style;
50 wxColour m_colour;
51 wxBitmap m_stipple;
c801d85f
KB
52};
53
c801d85f
KB
54//-----------------------------------------------------------------------------
55
56#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
57
58IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
59
debe6624 60wxBrush::wxBrush( const wxColour &colour, int style )
c801d85f 61{
58c837a4
RR
62 m_refData = new wxBrushRefData();
63 M_BRUSHDATA->m_style = style;
64 M_BRUSHDATA->m_colour = colour;
ff7b1510 65}
c801d85f 66
c801d85f
KB
67wxBrush::wxBrush( const wxBitmap &stippleBitmap )
68{
58c837a4 69 m_refData = new wxBrushRefData();
58c837a4 70 M_BRUSHDATA->m_colour = *wxBLACK;
7ecb8b06 71
58c837a4 72 M_BRUSHDATA->m_stipple = stippleBitmap;
e1208c31 73
de2d2cdc 74 if (M_BRUSHDATA->m_stipple.GetMask())
7ecb8b06
VZ
75 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
76 else
77 M_BRUSHDATA->m_style = wxSTIPPLE;
ff7b1510 78}
c801d85f 79
8bbe427f 80wxBrush::~wxBrush()
c801d85f 81{
c89f5c02 82 // m_refData unrefed in ~wxObject
ff7b1510 83}
c801d85f 84
c89f5c02 85wxObjectRefData *wxBrush::CreateRefData() const
c801d85f 86{
c89f5c02 87 return new wxBrushRefData;
ff7b1510 88}
c801d85f 89
c89f5c02 90wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
c801d85f 91{
c89f5c02 92 return new wxBrushRefData(*(wxBrushRefData *)data);
ff7b1510 93}
c801d85f 94
c89f5c02 95bool wxBrush::operator == ( const wxBrush& brush ) const
c801d85f 96{
c89f5c02
RR
97 if (m_refData == brush.m_refData) return TRUE;
98
99 if (!m_refData || !brush.m_refData) return FALSE;
100
101 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
ff7b1510 102}
c801d85f 103
8bbe427f 104int wxBrush::GetStyle() const
c801d85f 105{
58c837a4
RR
106 if (m_refData == NULL)
107 {
108 wxFAIL_MSG( wxT("invalid brush") );
109 return 0;
110 }
e55ad60e 111
58c837a4 112 return M_BRUSHDATA->m_style;
ff7b1510 113}
c801d85f 114
8bbe427f 115wxColour &wxBrush::GetColour() const
c801d85f 116{
58c837a4
RR
117 if (m_refData == NULL)
118 {
119 wxFAIL_MSG( wxT("invalid brush") );
120 return wxNullColour;
121 }
8bbe427f 122
58c837a4 123 return M_BRUSHDATA->m_colour;
ff7b1510 124}
c801d85f 125
8bbe427f 126wxBitmap *wxBrush::GetStipple() const
c801d85f 127{
58c837a4
RR
128 if (m_refData == NULL)
129 {
130 wxFAIL_MSG( wxT("invalid brush") );
131 return &wxNullBitmap;
132 }
8bbe427f 133
58c837a4 134 return &M_BRUSHDATA->m_stipple;
ff7b1510 135}
c801d85f 136
e55ad60e
RR
137void wxBrush::SetColour( const wxColour& col )
138{
c89f5c02
RR
139 AllocExclusive();
140
58c837a4 141 M_BRUSHDATA->m_colour = col;
e55ad60e
RR
142}
143
e55ad60e
RR
144void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
145{
c89f5c02
RR
146 AllocExclusive();
147
58c837a4 148 M_BRUSHDATA->m_colour.Set( r, g, b );
e55ad60e
RR
149}
150
151void wxBrush::SetStyle( int style )
152{
c89f5c02
RR
153 AllocExclusive();
154
58c837a4 155 M_BRUSHDATA->m_style = style;
e55ad60e
RR
156}
157
158void wxBrush::SetStipple( const wxBitmap& stipple )
159{
c89f5c02
RR
160 AllocExclusive();
161
58c837a4 162 M_BRUSHDATA->m_stipple = stipple;
de2d2cdc
VZ
163 if (M_BRUSHDATA->m_stipple.GetMask())
164 {
7ecb8b06
VZ
165 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
166 }
167 else
168 {
169 M_BRUSHDATA->m_style = wxSTIPPLE;
170 }
e55ad60e
RR
171}
172