1 //------------------------------------------------------------------------------
2 // emLook.h
3 //
4 // Copyright (C) 2005-2010,2014 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 #ifndef emLook_h
22 #define emLook_h
23
24 #ifndef emPanel_h
25 #include <emCore/emPanel.h>
26 #endif
27
28
29 //==============================================================================
30 //=================================== emLook ===================================
31 //==============================================================================
32
33 class emLook {
34
35 public:
36
37 // Class for the look of toolkit panels. Currently, the look consists of
38 // a set of colors only. Objects of this class have copy-on-write
39 // behavior.
40
41 emLook();
42 // Construct a default look.
43
44 emLook(const emLook & look);
45 // Construct a copied look.
46
47 ~emLook();
48 // Destructor.
49
50 emLook & operator = (const emLook & look);
51 // Copy a look.
52
53 bool operator == (const emLook & look) const;
54 bool operator != (const emLook & look) const;
55 // Compare two looks.
56
57 void Apply(emPanel * panel, bool recursively) const;
58 // Apply this look to a panel or to all panels in a sub-tree.
59 // Applying actually works for panels of class emBorder and
60 // its derivatives only, but the recursion is not stopped by
61 // other panel classes. However, the recursion can be stopped by
62 // an overloaded implementation of emBorder::SetLook.
63 // Arguments:
64 // panel - The panel.
65 // recursively - Whether to recurse ancestor panels.
66
67 emColor GetBgColor() const;
68 emColor GetFgColor() const;
69 void SetBgColor(emColor bgColor);
70 void SetFgColor(emColor fgColor);
71 // Get/set back- and foreground colors of borders, labels,
72 // groups and similar things.
73
74 emColor GetButtonBgColor() const;
75 emColor GetButtonFgColor() const;
76 void SetButtonBgColor(emColor buttonBgColor);
77 void SetButtonFgColor(emColor buttonFgColor);
78 // Get/set back- and foreground colors of button faces.
79
80 emColor GetInputBgColor() const;
81 emColor GetInputFgColor() const;
82 emColor GetInputHlColor() const;
83 void SetInputBgColor(emColor inputBgColor);
84 void SetInputFgColor(emColor inputFgColor);
85 void SetInputHlColor(emColor inputHlColor);
86 // Get/set background, foreground and highlight (=selection)
87 // colors of editable data fields.
88
89 emColor GetOutputBgColor() const;
90 emColor GetOutputFgColor() const;
91 emColor GetOutputHlColor() const;
92 void SetOutputBgColor(emColor outputBgColor);
93 void SetOutputFgColor(emColor outputFgColor);
94 void SetOutputHlColor(emColor outputHlColor);
95 // Get/set background, foreground and highlight (=selection)
96 // colors of read-only data fields.
97
98 unsigned int GetDataRefCount() const;
99 // Get number of references to the internal data of this object.
100
101 void MakeNonShared();
102 // This must be called before handing the look to another
103 // thread.
104
105 private:
106
107 void DeleteData();
108 void MakeWritable();
109
110 struct SharedData {
111 SharedData();
112 SharedData(const SharedData & sd);
113 unsigned int RefCount;
114 emColor BgColor;
115 emColor FgColor;
116 emColor ButtonBgColor;
117 emColor ButtonFgColor;
118 emColor InputBgColor;
119 emColor InputFgColor;
120 emColor InputHlColor;
121 emColor OutputBgColor;
122 emColor OutputFgColor;
123 emColor OutputHlColor;
124 };
125
126 SharedData * Data;
127
128 static SharedData DefaultData;
129 };
130
131 #ifndef EM_NO_DATA_EXPORT
emLook()132 inline emLook::emLook()
133 {
134 Data=&DefaultData;
135 }
136 #endif
137
emLook(const emLook & look)138 inline emLook::emLook(const emLook & look)
139 {
140 Data=look.Data;
141 Data->RefCount++;
142 }
143
~emLook()144 inline emLook::~emLook()
145 {
146 if (!--Data->RefCount) DeleteData();
147 }
148
149 inline emLook & emLook::operator = (const emLook & look)
150 {
151 look.Data->RefCount++;
152 if (!--Data->RefCount) DeleteData();
153 Data=look.Data;
154 return *this;
155 }
156
157 inline bool emLook::operator != (const emLook & look) const
158 {
159 return !(*this==look);
160 }
161
GetBgColor()162 inline emColor emLook::GetBgColor() const
163 {
164 return Data->BgColor;
165 }
166
GetFgColor()167 inline emColor emLook::GetFgColor() const
168 {
169 return Data->FgColor;
170 }
171
GetButtonBgColor()172 inline emColor emLook::GetButtonBgColor() const
173 {
174 return Data->ButtonBgColor;
175 }
176
GetButtonFgColor()177 inline emColor emLook::GetButtonFgColor() const
178 {
179 return Data->ButtonFgColor;
180 }
181
GetInputBgColor()182 inline emColor emLook::GetInputBgColor() const
183 {
184 return Data->InputBgColor;
185 }
186
GetInputFgColor()187 inline emColor emLook::GetInputFgColor() const
188 {
189 return Data->InputFgColor;
190 }
191
GetInputHlColor()192 inline emColor emLook::GetInputHlColor() const
193 {
194 return Data->InputHlColor;
195 }
196
GetOutputBgColor()197 inline emColor emLook::GetOutputBgColor() const
198 {
199 return Data->OutputBgColor;
200 }
201
GetOutputFgColor()202 inline emColor emLook::GetOutputFgColor() const
203 {
204 return Data->OutputFgColor;
205 }
206
GetOutputHlColor()207 inline emColor emLook::GetOutputHlColor() const
208 {
209 return Data->OutputHlColor;
210 }
211
MakeNonShared()212 inline void emLook::MakeNonShared()
213 {
214 MakeWritable();
215 }
216
217
218 #endif
219