]> git.saurik.com Git - wxWidgets.git/blob - src/qt/brush.cpp
wxString::Truncates() now doesn't change the sharied copies of the string
[wxWidgets.git] / src / qt / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: brush.cpp
3 // Purpose: wxBrush
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
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;
27 // TODO: null data
28 }
29
30 wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
31 {
32 m_style = data.m_style;
33 m_stipple = data.m_stipple;
34 m_colour = data.m_colour;
35 /* TODO: null data
36 m_hBrush = 0;
37 */
38 }
39
40 wxBrushRefData::~wxBrushRefData()
41 {
42 // TODO: delete data
43 }
44
45 // Brushes
46 wxBrush::wxBrush()
47 {
48 if ( wxTheBrushList )
49 wxTheBrushList->AddBrush(this);
50 }
51
52 wxBrush::~wxBrush()
53 {
54 if ( wxTheBrushList )
55 wxTheBrushList->RemoveBrush(this);
56 }
57
58 wxBrush::wxBrush(const wxColour& col, int Style)
59 {
60 m_refData = new wxBrushRefData;
61
62 M_BRUSHDATA->m_colour = col;
63 M_BRUSHDATA->m_style = Style;
64
65 RealizeResource();
66
67 if ( wxTheBrushList )
68 wxTheBrushList->AddBrush(this);
69 }
70
71 wxBrush::wxBrush(const wxString& col, int Style)
72 {
73 m_refData = new wxBrushRefData;
74
75 // Implicit conversion from string to wxColour via colour database
76 M_BRUSHDATA->m_colour = col;
77 M_BRUSHDATA->m_style = Style;
78
79 RealizeResource();
80
81 if ( wxTheBrushList )
82 wxTheBrushList->AddBrush(this);
83 }
84
85 wxBrush::wxBrush(const wxBitmap& stipple)
86 {
87 m_refData = new wxBrushRefData;
88
89 M_BRUSHDATA->m_style = wxSTIPPLE;
90 M_BRUSHDATA->m_stipple = stipple;
91
92 RealizeResource();
93
94 if ( wxTheBrushList )
95 wxTheBrushList->AddBrush(this);
96 }
97
98 void wxBrush::Unshare()
99 {
100 // Don't change shared data
101 if (!m_refData)
102 {
103 m_refData = new wxBrushRefData();
104 }
105 else
106 {
107 wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
108 UnRef();
109 m_refData = ref;
110 }
111 }
112
113 void wxBrush::SetColour(const wxColour& col)
114 {
115 Unshare();
116
117 M_BRUSHDATA->m_colour = col;
118
119 RealizeResource();
120 }
121
122 void wxBrush::SetColour(const wxString& col)
123 {
124 Unshare();
125
126 M_BRUSHDATA->m_colour = col;
127
128 RealizeResource();
129 }
130
131 void wxBrush::SetColour(const unsigned char r, const unsigned char g, const unsigned char b)
132 {
133 Unshare();
134
135 M_BRUSHDATA->m_colour.Set(r, g, b);
136
137 RealizeResource();
138 }
139
140 void wxBrush::SetStyle(int Style)
141 {
142 Unshare();
143
144 M_BRUSHDATA->m_style = Style;
145
146 RealizeResource();
147 }
148
149 void wxBrush::SetStipple(const wxBitmap& Stipple)
150 {
151 Unshare();
152
153 M_BRUSHDATA->m_stipple = Stipple;
154
155 RealizeResource();
156 }
157
158 void wxBrush::RealizeResource()
159 {
160 // TODO: create the brush
161 }
162