1 // resource.cc for bbpager - a pager tool for Blackbox
2 //
3 //  Copyright (c) 1998-2003 John Kennis, jkennis@chello.nl
4 //
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation; either version 2 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 // (See the included file COPYING / GPL-2.0)
20 //
21 
22 extern "C" {
23 #include <strings.h>
24 }
25 #include "resource.h"
26 #include "blackboxstyle.h"
27 
Resource(ToolWindow * toolwindow,const std::string & blackbox_rc_file,const std::string & rc_file)28 Resource::Resource(ToolWindow *toolwindow, const std::string &blackbox_rc_file, const std::string &rc_file):
29         BaseResource(*toolwindow, toolwindow->getCurrentScreen(), blackbox_rc_file, rc_file), bbtool(toolwindow)
30 {
31     load();
32 }
33 
~Resource()34 Resource::~Resource()
35 {
36     clean();
37 }
38 
clean()39 void Resource::clean()
40 {
41 }
42 
43 
44 
load(void)45 void Resource::load(void)
46 {
47     unsigned int button = 0;
48     WHICH_BUTTON move_default = LEFT_BUTTON;
49 
50     button = readUInt("bbpager.desktopChangeButton", "Bbpager.Desktopchangebutton", MIDDLE_BUTTON);
51     if (button > 5 || button < 1) {
52         button = MIDDLE_BUTTON;
53     }
54     desktop_change_button = static_cast<WHICH_BUTTON>(button);
55     if (desktop_change_button == LEFT_BUTTON) {
56         move_default = MIDDLE_BUTTON;
57     }
58 
59     button = readUInt("bbpager.windowMoveButton", "Bbpager.WindowMovebutton", move_default);
60     if (button > 5 || button < 1) {
61         button = move_default;
62     }
63     window_move_button = static_cast<WHICH_BUTTON>(button);
64 
65     button = readUInt("bbpager.windowFocusButton", "Bbpager.WindowFocusbutton", INVALID_BUTTON);
66     if (button > 5 || button < 1) {
67         button = INVALID_BUTTON;
68     }
69     window_focus_button = static_cast<WHICH_BUTTON>(button);
70 
71     button = readUInt("bbpager.windowRaiseButton", "Bbpager.WindowRaisebutton", INVALID_BUTTON);
72     if (button > 5 || button < 1) {
73         button = INVALID_BUTTON;
74     }
75     window_raise_button = static_cast<WHICH_BUTTON>(button);
76 
77     Frame();
78 
79     SizeAndPosition();
80 
81     PagerWin();
82 }
83 
84 
Frame()85 void Resource::Frame()
86 {
87     frame.texture = readTexture("bbpager.frame","BbPager.Frame",BB_FRAME, BB_C_FRAME,
88                     "Raised Gradient Vertical", "slategrey","darkslategrey");
89 
90     frame.bevelWidth = readUInt("bbpager.bevelWidth","Bbpager.BevelWidth",
91                                 readUInt( "bbpager.margin","Bbpager.margin", 4));
92     if (frame.bevelWidth == 0)
93         frame.bevelWidth = 4;
94 
95     frame.desktopMargin = readUInt("bbpager.desktop.bevelWidth","Bbpager.desktop.BevelWidth",
96                                 readUInt( "bbpager.desktop.margin","Bbpager.desktop.margin", frame.bevelWidth));
97     if (frame.desktopMargin == 0)
98         frame.desktopMargin = 4;
99 }
100 
101 
SizeAndPosition()102 void Resource::SizeAndPosition()
103 {
104     unsigned int w, h;
105 
106     if (!(bbtool->configuration().isWithdrawn()))
107         bbtool->configuration().setWithdrawn(readBool("bbpager.withdrawn", "Bbpager.Withdrawn", false));
108 
109     if (!(bbtool->configuration().isShaped()))
110         bbtool->configuration().setShaped(readBool("bbpager.shape", "Bbpager.Shape", false /*bbtool->configuration().isWithdrawn() */));
111 
112     if (bbtool->configuration().geometry().empty()) {
113         std::string positionstring = readString("bbpager.position","Bbpager.Position", "-0-0");
114         position.mask = XParseGeometry(positionstring.c_str(), &position.x, &position.y, &w, &h);
115         if (!(position.mask & XValue))
116             position.x = 0;
117         if (!(position.mask & YValue))
118             position.y = 0;
119     } else {
120         position.mask = XParseGeometry(bbtool->configuration().geometry().c_str(), &position.x, &position.y, &w, &h);
121         if (!(position.mask & XValue))
122             position.x = 0;
123         if (!(position.mask & YValue))
124             position.y = 0;
125 
126     }
127 
128     position.horizontal = false;
129     position.vertical = false;
130     std::string orientation = readString( "bbpager.desktop.orientation", "Bbpager.Desktop.Orientation", "horizontal");
131 
132     if (orientation == "vertical") {
133        position.vertical = true;
134     } else {
135             position.horizontal = true;
136     }
137 
138 
139     columns = readUInt("bbpager.desktop.columns", "Bbpager.Desktop.Columns", 0xFFFF);
140     if (columns == 0)
141       columns = 0xFFFF;
142 
143     rows = readUInt("bbpager.desktop.rows","Bbpager.Desktop.Rows", 0XFFFF);
144     if (rows == 0)
145         rows = 0xFFFF;
146 
147     int default_width;
148     if (!bbtool->configuration().isWithdrawn())
149         default_width = 40;
150     else
151         default_width = 64;
152 
153     desktopSize.width = default_width;
154     desktopSize.width = readUInt("bbpager.desktop.width", "Bbpager.Desktop.Width", default_width);
155 
156     int default_height;
157     if (!bbtool->configuration().isWithdrawn())
158         default_height = 30;
159     else
160         default_height = 48;
161 
162     desktopSize.height = readUInt("bbpager.desktop.height", "Bbpager.Desktop.Height", default_height);
163 }
164 
PagerWin()165 void Resource::PagerWin()
166 {
167     std::string focus_style;
168 
169     focus_style = readString( "bbpager.desktop.focusStyle", "Bbpager.Desktop.FocusStyle", "border");
170 
171     if (strcasecmp("texture", focus_style.c_str()) == 0) {
172         desktop_focus_style = texture;
173     } else if (! strcasecmp("none", focus_style.c_str()))
174         desktop_focus_style = none;
175     else
176         desktop_focus_style = border;
177 
178           desktopwin.texture = readTexture("bbpager.desktop", "Bbpager.Desktop",
179                                            BB_LABEL,BB_C_LABEL,
180                                            "Sunken Gradient Diagonal",
181                      "slategrey","darkslategrey");
182 
183     if (desktop_focus_style == texture) {
184         desktopwin.focusedTexture = readTexture("bbpager.desktop.focus", "Bbpager.Desktop.Focus",
185                                "Sunken Gradient Diagonal",
186                                "darkslategrey","slategrey");
187         }
188 
189         // Set the borders for active (focused) and inactive (unfocused) desktops.
190         //
191         // Try to set good defaults for the active and inactive border widths.
192         // We want the inactive border width always to default to 0. For the
193         // active border width, we start by setting it to 1, but in some cases
194         // we change it to 0. We want to change the default border width to 0
195         // whenever the border would be drawn around a desktop whose texture
196         // already has a border. This can occur in the following cases:
197         //
198         //   desktop_focus_style  border    texture
199         //   -------------------  --------  -------
200         //   none                 active    desktopwin.texture
201         //   border               active    desktopwin.texture
202         //   texture              active    desktopwin.focusedTexture
203         //
204         // We can ignore the none/active case for now, though, because that
205         // border width will be set automatically to whatever the none/inactive
206         // width turns out to be.
207 
208         int default_desktop_inactive_width = 0;
209         int default_desktop_active_width = 1;
210 
211         if (desktop_focus_style == border && desktopwin.texture.borderWidth() > 0) {
212           default_desktop_active_width = 0;
213         }
214         if (desktop_focus_style == texture && desktopwin.focusedTexture.borderWidth() > 0) {
215           default_desktop_active_width = 0;
216         }
217 
218 
219         desktopwin.inactiveColor = readColor("bbpager.inactive.desktop.borderColor",
220                                              "Bbpager.Inactive.desktop.BorderColor",
221                                              "black");
222         desktopwin.inactiveWidth = readInt("bbpager.inactive.desktop.borderWidth",
223                                            "Bbpager.Inactive.desktop.BorderWidth",
224                                            default_desktop_inactive_width);
225 
226         if (desktop_focus_style == none) {
227           desktopwin.activeColor = desktopwin.inactiveColor;
228           desktopwin.activeWidth = desktopwin.inactiveWidth;
229         }
230         else {
231           desktopwin.activeColor = readColor("bbpager.active.desktop.borderColor",
232                                              "Bbpager.Active.desktop.BorderColor",
233                                              "LightGrey");
234 
235           desktopwin.activeWidth = readInt("bbpager.active.desktop.borderWidth",
236                                            "Bbpager.Active.desktop.BorderWidth",
237                                            default_desktop_active_width);
238         }
239 
240 
241 
242     std::string window_focus_style = readString("bbpager.window.focusStyle", "Bbpager.Window.FocusStyle",
243                             "texture");
244 
245     if (! strcasecmp("border", window_focus_style.c_str()))
246         pager_focus_style = border;
247     else if (! strcasecmp("none", window_focus_style.c_str()))
248         pager_focus_style = none;
249     else
250         pager_focus_style = texture;
251 
252 
253           pagerwin.texture = readTexture("bbpager.window", "Bbpager.Window",
254                                          BB_WINDOW_UNFOCUS, BB_C_WINDOW_UNFOCUS,
255                                          "Raised Gradient Diagonal",
256                        "rgb:c/9/6","rgb:8/6/4");
257 
258     if (pager_focus_style == texture) {
259         pagerwin.focusedTexture = readTexture("bbpager.window.focus","Bbpager.Window.Focus",
260                                BB_WINDOW_FOCUS,BB_C_WINDOW_FOCUS,
261                               "Raised Vertical Gradient",
262                               "rgb:c/9/6","rgb:8/6/4");
263         }
264 
265         // Set the borders for active (focused) and inactive (unfocused) windows.
266         //
267         // Try to set good defaults for the active and inactive border widths.
268         // We start by setting both to 1, but in some cases we change it to 0.
269         // We want to change the default border width to 0 whenever the border
270         // would be drawn around a window whose texture already has a border.
271         // This can occur in the following cases:
272         //
273         //   pager_focus_style  border    texture
274         //   -----------------  --------  -------
275         //   none               inactive  pagerwin.texture
276         //   none               active    pagerwin.texture
277         //   border             inactive  pagerwin.texture
278         //   border             active    pagerwin.texture
279         //   texture            inactive  pagerwin.texture
280         //   texture            active    pagerwin.focusedTexture
281         //
282         // We can ignore the none/active case for now, though, because that
283         // border width will be set automatically to whatever the none/inactive
284         // width turns out to be.
285 
286         int default_pager_inactive_width = 1;
287         int default_pager_active_width = 1;
288 
289         if (pagerwin.texture.borderWidth() > 0) {
290           default_pager_inactive_width = 0;
291         }
292         if (pager_focus_style == border && pagerwin.texture.borderWidth() > 0) {
293           default_pager_active_width = 0;
294         }
295         if (pager_focus_style == texture && pagerwin.focusedTexture.borderWidth() > 0) {
296           default_pager_active_width = 0;
297         }
298 
299 
300           pagerwin.inactiveColor = readColor("bbpager.inactive.window.borderColor",
301                                              "Bbpager.inactive.Window.BorderColor",
302                                              "black");
303 
304           pagerwin.inactiveWidth = readInt("bbpager.inactive.window.borderWidth",
305                                            "Bbpager.inactive.Window.BorderWidth",
306                                            default_pager_inactive_width);
307 
308           if (pager_focus_style == none) {
309             pagerwin.activeColor = pagerwin.inactiveColor;
310             pagerwin.activeWidth = pagerwin.inactiveWidth;
311           }
312           else {
313             pagerwin.activeColor = readColor("bbpager.active.window.borderColor",
314                                              "Bbpager.active.Window.BorderColor",
315                                              "LightGrey");
316 
317             pagerwin.activeWidth = readInt("bbpager.active.window.borderWidth",
318                                            "Bbpager.active.Window.BorderWidth",
319                                            default_pager_active_width);
320           }
321 
322 }
323 
324