]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: brush.cpp | |
3 | // Purpose: wxBrush | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "brush.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/setup.h" | |
17 | #include "wx/utils.h" | |
18 | #include "wx/brush.h" | |
19 | ||
20 | #if !USE_SHARED_LIBRARIES | |
21 | IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) | |
22 | #endif | |
23 | ||
24 | wxBrushRefData::wxBrushRefData() | |
25 | { | |
26 | m_style = wxSOLID; | |
4bb6408c JS |
27 | } |
28 | ||
29 | wxBrushRefData::wxBrushRefData(const wxBrushRefData& data) | |
30 | { | |
31 | m_style = data.m_style; | |
32 | m_stipple = data.m_stipple; | |
33 | m_colour = data.m_colour; | |
4bb6408c JS |
34 | } |
35 | ||
36 | wxBrushRefData::~wxBrushRefData() | |
37 | { | |
4bb6408c JS |
38 | } |
39 | ||
40 | // Brushes | |
41 | wxBrush::wxBrush() | |
42 | { | |
43 | if ( wxTheBrushList ) | |
44 | wxTheBrushList->AddBrush(this); | |
45 | } | |
46 | ||
47 | wxBrush::~wxBrush() | |
48 | { | |
49 | if ( wxTheBrushList ) | |
50 | wxTheBrushList->RemoveBrush(this); | |
51 | } | |
52 | ||
53 | wxBrush::wxBrush(const wxColour& col, int Style) | |
54 | { | |
55 | m_refData = new wxBrushRefData; | |
56 | ||
57 | M_BRUSHDATA->m_colour = col; | |
58 | M_BRUSHDATA->m_style = Style; | |
59 | ||
60 | RealizeResource(); | |
61 | ||
62 | if ( wxTheBrushList ) | |
63 | wxTheBrushList->AddBrush(this); | |
64 | } | |
65 | ||
66 | wxBrush::wxBrush(const wxString& col, int Style) | |
67 | { | |
68 | m_refData = new wxBrushRefData; | |
69 | ||
70 | // Implicit conversion from string to wxColour via colour database | |
71 | M_BRUSHDATA->m_colour = col; | |
72 | M_BRUSHDATA->m_style = Style; | |
73 | ||
74 | RealizeResource(); | |
75 | ||
76 | if ( wxTheBrushList ) | |
77 | wxTheBrushList->AddBrush(this); | |
78 | } | |
79 | ||
80 | wxBrush::wxBrush(const wxBitmap& stipple) | |
81 | { | |
82 | m_refData = new wxBrushRefData; | |
83 | ||
84 | M_BRUSHDATA->m_style = wxSTIPPLE; | |
85 | M_BRUSHDATA->m_stipple = stipple; | |
86 | ||
87 | RealizeResource(); | |
88 | ||
89 | if ( wxTheBrushList ) | |
90 | wxTheBrushList->AddBrush(this); | |
91 | } | |
92 | ||
93 | void wxBrush::Unshare() | |
94 | { | |
95 | // Don't change shared data | |
96 | if (!m_refData) | |
97 | { | |
98 | m_refData = new wxBrushRefData(); | |
99 | } | |
100 | else | |
101 | { | |
102 | wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData); | |
103 | UnRef(); | |
104 | m_refData = ref; | |
105 | } | |
106 | } | |
107 | ||
108 | void wxBrush::SetColour(const wxColour& col) | |
109 | { | |
110 | Unshare(); | |
111 | ||
112 | M_BRUSHDATA->m_colour = col; | |
113 | ||
114 | RealizeResource(); | |
115 | } | |
116 | ||
117 | void wxBrush::SetColour(const wxString& col) | |
118 | { | |
119 | Unshare(); | |
120 | ||
121 | M_BRUSHDATA->m_colour = col; | |
122 | ||
123 | RealizeResource(); | |
124 | } | |
125 | ||
126 | void wxBrush::SetColour(const unsigned char r, const unsigned char g, const unsigned char b) | |
127 | { | |
128 | Unshare(); | |
129 | ||
130 | M_BRUSHDATA->m_colour.Set(r, g, b); | |
131 | ||
132 | RealizeResource(); | |
133 | } | |
134 | ||
135 | void wxBrush::SetStyle(int Style) | |
136 | { | |
137 | Unshare(); | |
138 | ||
139 | M_BRUSHDATA->m_style = Style; | |
140 | ||
141 | RealizeResource(); | |
142 | } | |
143 | ||
144 | void wxBrush::SetStipple(const wxBitmap& Stipple) | |
145 | { | |
146 | Unshare(); | |
147 | ||
148 | M_BRUSHDATA->m_stipple = Stipple; | |
149 | ||
150 | RealizeResource(); | |
151 | } | |
152 | ||
dfc54541 | 153 | bool wxBrush::RealizeResource() |
4bb6408c | 154 | { |
dfc54541 JS |
155 | // Nothing more to do |
156 | return TRUE; | |
4bb6408c JS |
157 | } |
158 |