1 //------------------------------------------------------------------------------
2 // emLook.cpp
3 //
4 // Copyright (C) 2005-2011,2014,2016 Oliver Hamann.
5 //
6 // Homepage: http://eaglemode.sourceforge.net/
7 //
8 // This program is free software: you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License version 3 as published by the
10 // Free Software Foundation.
11 //
12 // This program is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
15 // more details.
16 //
17 // You should have received a copy of the GNU General Public License version 3
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //------------------------------------------------------------------------------
20
21 #include <emCore/emLook.h>
22 #include <emCore/emBorder.h>
23
24
25 #ifdef EM_NO_DATA_EXPORT
emLook()26 emLook::emLook()
27 {
28 Data=&DefaultData;
29 }
30 #endif
31
32
operator ==(const emLook & look) const33 bool emLook::operator == (const emLook & look) const
34 {
35 return
36 Data==look.Data || (
37 Data->BgColor==look.Data->BgColor &&
38 Data->FgColor==look.Data->FgColor &&
39 Data->ButtonBgColor==look.Data->ButtonBgColor &&
40 Data->ButtonFgColor==look.Data->ButtonFgColor &&
41 Data->InputBgColor==look.Data->InputBgColor &&
42 Data->InputFgColor==look.Data->InputFgColor &&
43 Data->InputHlColor==look.Data->InputHlColor &&
44 Data->OutputBgColor==look.Data->OutputBgColor &&
45 Data->OutputFgColor==look.Data->OutputFgColor &&
46 Data->OutputHlColor==look.Data->OutputHlColor
47 )
48 ;
49 }
50
51
Apply(emPanel * panel,bool recursively) const52 void emLook::Apply(emPanel * panel, bool recursively) const
53 {
54 emBorder * border;
55
56 border=dynamic_cast<emBorder*>(panel);
57 if (border) {
58 // Remember: border->SetLook could be overloaded to stop the
59 // recursion.
60 border->SetLook(*this,recursively);
61 }
62 else if (recursively) {
63 for (panel=panel->GetFirstChild(); panel; panel=panel->GetNext()) {
64 Apply(panel,true);
65 }
66 }
67 }
68
69
SetBgColor(emColor bgColor)70 void emLook::SetBgColor(emColor bgColor)
71 {
72 if (Data->BgColor!=bgColor) {
73 MakeWritable();
74 Data->BgColor=bgColor;
75 }
76 }
77
78
SetFgColor(emColor fgColor)79 void emLook::SetFgColor(emColor fgColor)
80 {
81 if (Data->FgColor!=fgColor) {
82 MakeWritable();
83 Data->FgColor=fgColor;
84 }
85 }
86
87
SetButtonBgColor(emColor buttonBgColor)88 void emLook::SetButtonBgColor(emColor buttonBgColor)
89 {
90 if (Data->ButtonBgColor!=buttonBgColor) {
91 MakeWritable();
92 Data->ButtonBgColor=buttonBgColor;
93 }
94 }
95
96
SetButtonFgColor(emColor buttonFgColor)97 void emLook::SetButtonFgColor(emColor buttonFgColor)
98 {
99 if (Data->ButtonFgColor!=buttonFgColor) {
100 MakeWritable();
101 Data->ButtonFgColor=buttonFgColor;
102 }
103 }
104
105
SetInputBgColor(emColor inputBgColor)106 void emLook::SetInputBgColor(emColor inputBgColor)
107 {
108 if (Data->InputBgColor!=inputBgColor) {
109 MakeWritable();
110 Data->InputBgColor=inputBgColor;
111 }
112 }
113
114
SetInputFgColor(emColor inputFgColor)115 void emLook::SetInputFgColor(emColor inputFgColor)
116 {
117 if (Data->InputFgColor!=inputFgColor) {
118 MakeWritable();
119 Data->InputFgColor=inputFgColor;
120 }
121 }
122
123
SetInputHlColor(emColor inputHlColor)124 void emLook::SetInputHlColor(emColor inputHlColor)
125 {
126 if (Data->InputHlColor!=inputHlColor) {
127 MakeWritable();
128 Data->InputHlColor=inputHlColor;
129 }
130 }
131
132
SetOutputBgColor(emColor outputBgColor)133 void emLook::SetOutputBgColor(emColor outputBgColor)
134 {
135 if (Data->OutputBgColor!=outputBgColor) {
136 MakeWritable();
137 Data->OutputBgColor=outputBgColor;
138 }
139 }
140
141
SetOutputFgColor(emColor outputFgColor)142 void emLook::SetOutputFgColor(emColor outputFgColor)
143 {
144 if (Data->OutputFgColor!=outputFgColor) {
145 MakeWritable();
146 Data->OutputFgColor=outputFgColor;
147 }
148 }
149
150
SetOutputHlColor(emColor outputHlColor)151 void emLook::SetOutputHlColor(emColor outputHlColor)
152 {
153 if (Data->OutputHlColor!=outputHlColor) {
154 MakeWritable();
155 Data->OutputHlColor=outputHlColor;
156 }
157 }
158
159
GetDataRefCount() const160 unsigned int emLook::GetDataRefCount() const
161 {
162 return Data==&DefaultData ? UINT_MAX/2 : Data->RefCount;
163 }
164
165
DeleteData()166 void emLook::DeleteData()
167 {
168 DefaultData.RefCount=UINT_MAX/2;
169 if (Data!=&DefaultData) delete Data;
170 }
171
172
MakeWritable()173 void emLook::MakeWritable()
174 {
175 SharedData * d;
176
177 if (Data->RefCount>1 || Data==&DefaultData) {
178 d=new SharedData(*Data);
179 d->RefCount=1;
180 Data->RefCount--;
181 Data=d;
182 }
183 }
184
185
SharedData()186 emLook::SharedData::SharedData()
187 : RefCount(UINT_MAX/2),
188 BgColor (0x515E84FF),
189 FgColor (0xEFF0F4FF),
190 ButtonBgColor(0x596790FF),
191 ButtonFgColor(0xF2F2F7FF),
192 InputBgColor (0xEFF0F4FF),
193 InputFgColor (0x020E1DFF),
194 InputHlColor (0x0038C0FF),
195 OutputBgColor(0xA7A9B0FF),
196 OutputFgColor(0x070B18FF),
197 OutputHlColor(0x002B9AFF)
198 {
199 }
200
201
SharedData(const SharedData & sd)202 emLook::SharedData::SharedData(const SharedData & sd)
203 : RefCount(sd.RefCount),
204 BgColor(sd.BgColor),
205 FgColor(sd.FgColor),
206 ButtonBgColor(sd.ButtonBgColor),
207 ButtonFgColor(sd.ButtonFgColor),
208 InputBgColor(sd.InputBgColor),
209 InputFgColor(sd.InputFgColor),
210 InputHlColor(sd.InputHlColor),
211 OutputBgColor(sd.OutputBgColor),
212 OutputFgColor(sd.OutputFgColor),
213 OutputHlColor(sd.OutputHlColor)
214 {
215 }
216
217
218 emLook::SharedData emLook::DefaultData;
219