1 /********************************************************************************
2 *                                                                               *
3 *                        F r a m e   W i n d o w   O b j e c t                  *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1997,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: FXFrame.cpp 3297 2015-12-14 20:30:04Z 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 "FXSettings.h"
35 #include "FXRegistry.h"
36 #include "FXApp.h"
37 #include "FXDCWindow.h"
38 #include "FXFrame.h"
39 
40 /*
41   Notes:
42   - This really should become the base class for everything that has
43     a border.
44 */
45 
46 
47 // Frame styles
48 #define FRAME_MASK        (FRAME_SUNKEN|FRAME_RAISED|FRAME_THICK)
49 
50 using namespace FX;
51 
52 /*******************************************************************************/
53 
54 namespace FX {
55 
56 // Map
57 FXDEFMAP(FXFrame) FXFrameMap[]={
58   FXMAPFUNC(SEL_PAINT,0,FXFrame::onPaint),
59   };
60 
61 
62 // Object implementation
FXIMPLEMENT(FXFrame,FXWindow,FXFrameMap,ARRAYNUMBER (FXFrameMap))63 FXIMPLEMENT(FXFrame,FXWindow,FXFrameMap,ARRAYNUMBER(FXFrameMap))
64 
65 
66 // Deserialization
67 FXFrame::FXFrame(){
68   flags|=FLAG_SHOWN;
69   baseColor=0;
70   hiliteColor=0;
71   shadowColor=0;
72   borderColor=0;
73   border=0;
74   }
75 
76 
77 // Create child frame window
FXFrame(FXComposite * p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb)78 FXFrame::FXFrame(FXComposite* p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):
79   FXWindow(p,opts,x,y,w,h){
80   flags|=FLAG_SHOWN;
81   backColor=getApp()->getBaseColor();
82   baseColor=getApp()->getBaseColor();
83   hiliteColor=getApp()->getHiliteColor();
84   shadowColor=getApp()->getShadowColor();
85   borderColor=getApp()->getBorderColor();
86   padtop=pt;
87   padbottom=pb;
88   padleft=pl;
89   padright=pr;
90   border=(options&FRAME_THICK)?2:(options&(FRAME_SUNKEN|FRAME_RAISED))?1:0;
91   }
92 
93 
94 // Get default width
getDefaultWidth()95 FXint FXFrame::getDefaultWidth(){
96   return padleft+padright+(border<<1);
97   }
98 
99 
100 // Get default height
getDefaultHeight()101 FXint FXFrame::getDefaultHeight(){
102   return padtop+padbottom+(border<<1);
103   }
104 
105 
drawBorderRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)106 void FXFrame::drawBorderRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
107   dc.setForeground(borderColor);
108   dc.drawRectangle(x,y,w-1,h-1);
109   }
110 
111 
drawRaisedRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)112 void FXFrame::drawRaisedRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
113   if(0<w && 0<h){
114     dc.setForeground(shadowColor);
115     dc.fillRectangle(x,y+h-1,w,1);
116     dc.fillRectangle(x+w-1,y,1,h);
117     dc.setForeground(hiliteColor);
118     dc.fillRectangle(x,y,w,1);
119     dc.fillRectangle(x,y,1,h);
120     }
121   }
122 
123 
drawSunkenRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)124 void FXFrame::drawSunkenRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
125   if(0<w && 0<h){
126     dc.setForeground(shadowColor);
127     dc.fillRectangle(x,y,w,1);
128     dc.fillRectangle(x,y,1,h);
129     dc.setForeground(hiliteColor);
130     dc.fillRectangle(x,y+h-1,w,1);
131     dc.fillRectangle(x+w-1,y,1,h);
132     }
133   }
134 
135 
drawRidgeRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)136 void FXFrame::drawRidgeRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
137   if(0<w && 0<h){
138     dc.setForeground(hiliteColor);
139     dc.fillRectangle(x,y,w,1);
140     dc.fillRectangle(x,y,1,h);
141     dc.setForeground(shadowColor);
142     dc.fillRectangle(x,y+h-1,w,1);
143     dc.fillRectangle(x+w-1,y,1,h);
144     if(1<w && 1<h){
145       dc.setForeground(hiliteColor);
146       dc.fillRectangle(x+1,y+h-2,w-2,1);
147       dc.fillRectangle(x+w-2,y+1,1,h-2);
148       dc.setForeground(shadowColor);
149       dc.fillRectangle(x+1,y+1,w-3,1);
150       dc.fillRectangle(x+1,y+1,1,h-3);
151       }
152     }
153   }
154 
155 
drawGrooveRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)156 void FXFrame::drawGrooveRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
157   if(0<w && 0<h){
158     dc.setForeground(shadowColor);
159     dc.fillRectangle(x,y,w,1);
160     dc.fillRectangle(x,y,1,h);
161     dc.setForeground(hiliteColor);
162     dc.fillRectangle(x,y+h-1,w,1);
163     dc.fillRectangle(x+w-1,y,1,h);
164     if(1<w && 1<h){
165       dc.setForeground(shadowColor);
166       dc.fillRectangle(x+1,y+h-2,w-2,1);
167       dc.fillRectangle(x+w-2,y+1,1,h-2);
168       dc.setForeground(hiliteColor);
169       dc.fillRectangle(x+1,y+1,w-3,1);
170       dc.fillRectangle(x+1,y+1,1,h-3);
171       }
172     }
173   }
174 
175 
drawDoubleRaisedRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)176 void FXFrame::drawDoubleRaisedRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
177   if(0<w && 0<h){
178     dc.setForeground(borderColor);
179     dc.fillRectangle(x,y+h-1,w,1);
180     dc.fillRectangle(x+w-1,y,1,h);
181     dc.setForeground(hiliteColor);
182     dc.fillRectangle(x,y,w-1,1);
183     dc.fillRectangle(x,y,1,h-1);
184     if(1<w && 1<h){
185       dc.setForeground(baseColor);
186       dc.fillRectangle(x+1,y+1,w-2,1);
187       dc.fillRectangle(x+1,y+1,1,h-2);
188       dc.setForeground(shadowColor);
189       dc.fillRectangle(x+1,y+h-2,w-2,1);
190       dc.fillRectangle(x+w-2,y+1,1,h-2);
191       }
192     }
193   }
194 
drawDoubleSunkenRectangle(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)195 void FXFrame::drawDoubleSunkenRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
196   if(0<w && 0<h){
197     dc.setForeground(hiliteColor);
198     dc.fillRectangle(x,y+h-1,w,1);
199     dc.fillRectangle(x+w-1,y,1,h);
200     dc.setForeground(shadowColor);
201     dc.fillRectangle(x,y,w-1,1);
202     dc.fillRectangle(x,y,1,h-1);
203     if(1<w && 1<h){
204       dc.setForeground(borderColor);
205       dc.fillRectangle(x+1,y+1,w-3,1);
206       dc.fillRectangle(x+1,y+1,1,h-3);
207       dc.setForeground(baseColor);
208       dc.fillRectangle(x+1,y+h-2,w-2,1);
209       dc.fillRectangle(x+w-2,y+1,1,h-2);
210       }
211     }
212   }
213 
214 
215 // Draw border
drawFrame(FXDCWindow & dc,FXint x,FXint y,FXint w,FXint h)216 void FXFrame::drawFrame(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
217   switch(options&FRAME_MASK){
218     case FRAME_LINE: drawBorderRectangle(dc,x,y,w,h); break;
219     case FRAME_SUNKEN: drawSunkenRectangle(dc,x,y,w,h); break;
220     case FRAME_RAISED: drawRaisedRectangle(dc,x,y,w,h); break;
221     case FRAME_GROOVE: drawGrooveRectangle(dc,x,y,w,h); break;
222     case FRAME_RIDGE: drawRidgeRectangle(dc,x,y,w,h); break;
223     case FRAME_SUNKEN|FRAME_THICK: drawDoubleSunkenRectangle(dc,x,y,w,h); break;
224     case FRAME_RAISED|FRAME_THICK: drawDoubleRaisedRectangle(dc,x,y,w,h); break;
225     }
226   }
227 
228 
229 // Handle repaint
onPaint(FXObject *,FXSelector,void * ptr)230 long FXFrame::onPaint(FXObject*,FXSelector,void* ptr){
231   FXEvent* event=static_cast<FXEvent*>(ptr);
232   FXDCWindow dc(this,event);
233   dc.setForeground(backColor);
234   dc.fillRectangle(border,border,width-(border<<1),height-(border<<1));
235   drawFrame(dc,0,0,width,height);
236   return 1;
237   }
238 
239 
240 // Change frame border style
setFrameStyle(FXuint style)241 void FXFrame::setFrameStyle(FXuint style){
242   FXuint opts=(options&~FRAME_MASK) | (style&FRAME_MASK);
243   if(options!=opts){
244     FXint b=(opts&FRAME_THICK) ? 2 : (opts&(FRAME_SUNKEN|FRAME_RAISED)) ? 1 : 0;
245     options=opts;
246     if(border!=b){
247       border=b;
248       recalc();
249       }
250     update();
251     }
252   }
253 
254 
255 // Get frame style
getFrameStyle() const256 FXuint FXFrame::getFrameStyle() const {
257   return (options&FRAME_MASK);
258   }
259 
260 
261 // Set base color
setBaseColor(FXColor clr)262 void FXFrame::setBaseColor(FXColor clr){
263   if(clr!=baseColor){
264     baseColor=clr;
265     update();
266     }
267   }
268 
269 
270 // Set highlight color
setHiliteColor(FXColor clr)271 void FXFrame::setHiliteColor(FXColor clr){
272   if(clr!=hiliteColor){
273     hiliteColor=clr;
274     update();
275     }
276   }
277 
278 
279 // Set shadow color
setShadowColor(FXColor clr)280 void FXFrame::setShadowColor(FXColor clr){
281   if(clr!=shadowColor){
282     shadowColor=clr;
283     update();
284     }
285   }
286 
287 
288 // Set border color
setBorderColor(FXColor clr)289 void FXFrame::setBorderColor(FXColor clr){
290   if(clr!=borderColor){
291     borderColor=clr;
292     update();
293     }
294   }
295 
296 
297 // Change top padding
setPadTop(FXint pt)298 void FXFrame::setPadTop(FXint pt){
299   if(padtop!=pt){
300     padtop=pt;
301     recalc();
302     update();
303     }
304   }
305 
306 
307 // Change bottom padding
setPadBottom(FXint pb)308 void FXFrame::setPadBottom(FXint pb){
309   if(padbottom!=pb){
310     padbottom=pb;
311     recalc();
312     update();
313     }
314   }
315 
316 
317 // Change left padding
setPadLeft(FXint pl)318 void FXFrame::setPadLeft(FXint pl){
319   if(padleft!=pl){
320     padleft=pl;
321     recalc();
322     update();
323     }
324   }
325 
326 
327 // Change right padding
setPadRight(FXint pr)328 void FXFrame::setPadRight(FXint pr){
329   if(padright!=pr){
330     padright=pr;
331     recalc();
332     update();
333     }
334   }
335 
336 
337 // Save data
save(FXStream & store) const338 void FXFrame::save(FXStream& store) const {
339   FXWindow::save(store);
340   store << baseColor;
341   store << hiliteColor;
342   store << shadowColor;
343   store << borderColor;
344   store << padtop;
345   store << padbottom;
346   store << padleft;
347   store << padright;
348   store << border;
349   }
350 
351 
352 // Load data
load(FXStream & store)353 void FXFrame::load(FXStream& store){
354   FXWindow::load(store);
355   store >> baseColor;
356   store >> hiliteColor;
357   store >> shadowColor;
358   store >> borderColor;
359   store >> padtop;
360   store >> padbottom;
361   store >> padleft;
362   store >> padright;
363   store >> border;
364   }
365 
366 
367 }
368 
369