1 /********************************************************************************
2 * *
3 * T o o l B a r S h e l l W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2000,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXToolBarShell.cpp 4937 2019-03-10 19:59:30Z arthurcnorman $ *
23 ********************************************************************************/
24 #include "xincs.h"
25 #include "fxver.h"
26 #include "fxdefs.h"
27 #include "FXHash.h"
28 #include "FXThread.h"
29 #include "FXStream.h"
30 #include "FXString.h"
31 #include "FXSize.h"
32 #include "FXPoint.h"
33 #include "FXRectangle.h"
34 #include "FXRegistry.h"
35 #include "FXApp.h"
36 #include "FXDCWindow.h"
37 #include "FXCursor.h"
38 #include "FXToolBarShell.h"
39
40 /*
41 Notes:
42 - Managed by Window Manager because it needs to stay on top of window.
43 - Window manager may hide it when application does not have focus.
44 - If it has a child and the child is shown, it will show, otherwise it'll hide.
45 - Need some code to allow grabbing of edges to resize [w/o intervention of WM].
46 - Allow reshaping FXToolbarShell by pulling on edges.
47 */
48
49
50 #define FRAME_MASK (FRAME_SUNKEN|FRAME_RAISED|FRAME_THICK)
51
52 using namespace FX;
53
54 /*******************************************************************************/
55
56 namespace FX {
57
58 // Map
59 FXDEFMAP(FXToolBarShell) FXToolBarShellMap[]={
60 FXMAPFUNC(SEL_PAINT,0,FXToolBarShell::onPaint),
61 };
62
63
64
65 // Object implementation
FXIMPLEMENT(FXToolBarShell,FXTopWindow,FXToolBarShellMap,ARRAYNUMBER (FXToolBarShellMap))66 FXIMPLEMENT(FXToolBarShell,FXTopWindow,FXToolBarShellMap,ARRAYNUMBER(FXToolBarShellMap))
67
68
69 // Make toolbar shell
70 FXToolBarShell::FXToolBarShell(FXWindow* owner,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint hs,FXint vs):
71 FXTopWindow(owner,FXString::null,NULL,NULL,(opts|DECOR_SHRINKABLE|DECOR_STRETCHABLE)&~(DECOR_TITLE|DECOR_MINIMIZE|DECOR_MAXIMIZE|DECOR_CLOSE|DECOR_BORDER|DECOR_MENU),x,y,w,h,0,0,0,0,hs,vs){
72 baseColor=getApp()->getBaseColor();
73 hiliteColor=getApp()->getHiliteColor();
74 shadowColor=getApp()->getShadowColor();
75 borderColor=getApp()->getBorderColor();
76 border=(options&FRAME_THICK)?2:(options&(FRAME_SUNKEN|FRAME_RAISED))?1:0;
77 }
78
79
80 // Create window
create()81 void FXToolBarShell::create(){
82 FXTopWindow::create();
83 if(getFirst() && getFirst()->shown()) show();
84 }
85
86
87
drawBorderRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)88 void FXToolBarShell::drawBorderRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
89 dc.setForeground(borderColor);
90 dc.drawRectangle(x,y,w-1,h-1);
91 }
92
93
drawRaisedRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)94 void FXToolBarShell::drawRaisedRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
95 dc.setForeground(shadowColor);
96 dc.fillRectangle(x,y+h-1,w,1);
97 dc.fillRectangle(x+w-1,y,1,h);
98 dc.setForeground(hiliteColor);
99 dc.fillRectangle(x,y,w,1);
100 dc.fillRectangle(x,y,1,h);
101 }
102
103
drawSunkenRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)104 void FXToolBarShell::drawSunkenRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
105 dc.setForeground(shadowColor);
106 dc.fillRectangle(x,y,w,1);
107 dc.fillRectangle(x,y,1,h);
108 dc.setForeground(hiliteColor);
109 dc.fillRectangle(x,y+h-1,w,1);
110 dc.fillRectangle(x+w-1,y,1,h);
111 }
112
113
drawRidgeRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)114 void FXToolBarShell::drawRidgeRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
115 dc.setForeground(hiliteColor);
116 dc.fillRectangle(x,y,w,1);
117 dc.fillRectangle(x,y,1,h);
118 dc.fillRectangle(x+1,y+h-2,w-2,1);
119 dc.fillRectangle(x+w-2,y+1,1,h-2);
120 dc.setForeground(shadowColor);
121 dc.fillRectangle(x+1,y+1,w-3,1);
122 dc.fillRectangle(x+1,y+1,1,h-3);
123 dc.fillRectangle(x,y+h-1,w,1);
124 dc.fillRectangle(x+w-1,y,1,h);
125 }
126
127
drawGrooveRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)128 void FXToolBarShell::drawGrooveRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
129 dc.setForeground(shadowColor);
130 dc.fillRectangle(x,y,w,1);
131 dc.fillRectangle(x,y,1,h);
132 dc.fillRectangle(x+1,y+h-2,w-2,1);
133 dc.fillRectangle(x+w-2,y+1,1,h-2);
134 dc.setForeground(hiliteColor);
135 dc.fillRectangle(x+1,y+1,w-3,1);
136 dc.fillRectangle(x+1,y+1,1,h-3);
137 dc.fillRectangle(x,y+h-1,w,1);
138 dc.fillRectangle(x+w-1,y,1,h);
139 }
140
141
drawDoubleRaisedRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)142 void FXToolBarShell::drawDoubleRaisedRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
143 dc.setForeground(baseColor);
144 dc.fillRectangle(x,y,w-1,1);
145 dc.fillRectangle(x,y,1,h-1);
146 dc.setForeground(hiliteColor);
147 dc.fillRectangle(x+1,y+1,w-2,1);
148 dc.fillRectangle(x+1,y+1,1,h-2);
149 dc.setForeground(shadowColor);
150 dc.fillRectangle(x+1,y+h-2,w-2,1);
151 dc.fillRectangle(x+w-2,y+1,1,h-1);
152 dc.setForeground(borderColor);
153 dc.fillRectangle(x,y+h-1,w,1);
154 dc.fillRectangle(x+w-1,y,1,h);
155 }
156
157
drawDoubleSunkenRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)158 void FXToolBarShell::drawDoubleSunkenRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
159 dc.setForeground(shadowColor);
160 dc.fillRectangle(x,y,w-1,1);
161 dc.fillRectangle(x,y,1,h-1);
162 dc.setForeground(borderColor);
163 dc.fillRectangle(x+1,y+1,w-3,1);
164 dc.fillRectangle(x+1,y+1,1,h-3);
165 dc.setForeground(hiliteColor);
166 dc.fillRectangle(x,y+h-1,w,1);
167 dc.fillRectangle(x+w-1,y,1,h);
168 dc.setForeground(baseColor);
169 dc.fillRectangle(x+1,y+h-2,w-2,1);
170 dc.fillRectangle(x+w-2,y+1,1,h-2);
171 }
172
173
174 // Draw border
drawFrame(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)175 void FXToolBarShell::drawFrame(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
176 switch(options&FRAME_MASK){
177 case FRAME_LINE: drawBorderRectangle(dc,x,y,w,h); break;
178 case FRAME_SUNKEN: drawSunkenRectangle(dc,x,y,w,h); break;
179 case FRAME_RAISED: drawRaisedRectangle(dc,x,y,w,h); break;
180 case FRAME_GROOVE: drawGrooveRectangle(dc,x,y,w,h); break;
181 case FRAME_RIDGE: drawRidgeRectangle(dc,x,y,w,h); break;
182 case FRAME_SUNKEN|FRAME_THICK: drawDoubleSunkenRectangle(dc,x,y,w,h); break;
183 case FRAME_RAISED|FRAME_THICK: drawDoubleRaisedRectangle(dc,x,y,w,h); break;
184 }
185 }
186
187
188 // Handle repaint
onPaint(FXObject *,FXSelector,void * ptr)189 long FXToolBarShell::onPaint(FXObject*,FXSelector,void* ptr){
190 FXEvent *ev=(FXEvent*)ptr;
191 FXDCWindow dc(this,ev);
192 drawFrame(dc,0,0,width,height);
193 return 1;
194 }
195
196
197 // Get width
getDefaultWidth()198 FXint FXToolBarShell::getDefaultWidth(){
199 FXWindow* child=getFirst();
200 FXuint hints;
201 FXint w=0;
202 if(child && child->shown()){
203 hints=child->getLayoutHints();
204 if(hints&LAYOUT_FIX_WIDTH){ // Fixed width
205 w=child->getWidth();
206 }
207 else if(hints&LAYOUT_SIDE_LEFT){ // Vertical
208 w=child->getWidthForHeight((hints&LAYOUT_FIX_HEIGHT) ? child->getHeight() : child->getDefaultHeight());
209 }
210 else{ // Horizontal
211 w=child->getDefaultWidth();
212 }
213 }
214 return w+(border<<1);
215 }
216
217
218 // Get height
getDefaultHeight()219 FXint FXToolBarShell::getDefaultHeight(){
220 FXWindow* child=getFirst();
221 FXuint hints;
222 FXint h=0;
223 if(child && child->shown()){
224 hints=child->getLayoutHints();
225 if(hints&LAYOUT_FIX_HEIGHT){ // Fixed height
226 h=child->getHeight();
227 }
228 else if(hints&LAYOUT_SIDE_LEFT){ // Vertical
229 h=child->getDefaultHeight();
230 }
231 else{ // Horizontal
232 h=child->getHeightForWidth((hints&LAYOUT_FIX_WIDTH) ? child->getWidth() : child->getDefaultWidth());
233 }
234 }
235 return h+(border<<1);
236 }
237
238
239 // Recalculate layout
layout()240 void FXToolBarShell::layout(){
241 if(getFirst()){
242 if(getFirst()->shown()){
243 getFirst()->position(border,border,width-(border<<1),height-(border<<1));
244 show();
245 }
246 else{
247 hide();
248 }
249 }
250 flags&=~FLAG_DIRTY;
251 }
252
253
254 // Change frame border style
setFrameStyle(FXuint style)255 void FXToolBarShell::setFrameStyle(FXuint style){
256 FXuint opts=(options&~FRAME_MASK) | (style&FRAME_MASK);
257 if(options!=opts){
258 FXint b=(opts&FRAME_THICK) ? 2 : (opts&(FRAME_SUNKEN|FRAME_RAISED)) ? 1 : 0;
259 options=opts;
260 if(border!=b){
261 border=b;
262 recalc();
263 }
264 update();
265 }
266 }
267
268
269 // Get frame style
getFrameStyle() const270 FXuint FXToolBarShell::getFrameStyle() const {
271 return (options&FRAME_MASK);
272 }
273
274
275 // Set base color
setBaseColor(FXColor clr)276 void FXToolBarShell::setBaseColor(FXColor clr){
277 if(clr!=baseColor){
278 baseColor=clr;
279 update();
280 }
281 }
282
283
284 // Set highlight color
setHiliteColor(FXColor clr)285 void FXToolBarShell::setHiliteColor(FXColor clr){
286 if(clr!=hiliteColor){
287 hiliteColor=clr;
288 update();
289 }
290 }
291
292
293 // Set shadow color
setShadowColor(FXColor clr)294 void FXToolBarShell::setShadowColor(FXColor clr){
295 if(clr!=shadowColor){
296 shadowColor=clr;
297 update();
298 }
299 }
300
301
302 // Set border color
setBorderColor(FXColor clr)303 void FXToolBarShell::setBorderColor(FXColor clr){
304 if(clr!=borderColor){
305 borderColor=clr;
306 update();
307 }
308 }
309
310
311 // Save data
save(FXStream & store) const312 void FXToolBarShell::save(FXStream& store) const {
313 FXTopWindow::save(store);
314 store << baseColor;
315 store << hiliteColor;
316 store << shadowColor;
317 store << borderColor;
318 store << border;
319 }
320
321
322 // Load data
load(FXStream & store)323 void FXToolBarShell::load(FXStream& store){
324 FXTopWindow::load(store);
325 store >> baseColor;
326 store >> hiliteColor;
327 store >> shadowColor;
328 store >> borderColor;
329 store >> border;
330 }
331
332 }
333