1 /********************************************************************************
2 * *
3 * S e p a r a t o r W i d g e t s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2005 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: FXSeparator.cpp,v 1.25 2005/01/16 16:06:07 fox Exp $ *
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 "FXSeparator.h"
38
39
40
41 /*
42 Notes:
43 - When changing icon/font/etc, we should only recalc and update when it's different.
44 - When text changes, do we delete the hot key, or parse it from the new label?
45 - It makes sense for certain ``passive'' widgets such as labels to have onUpdate;
46 for example, to show/hide/whatever based on changing data structures.
47 - Why not just have one type of separator, orientation simply being based on the
48 widest dimension?
49 */
50
51 #define SEPARATOR_EXTRA 2
52
53 #define SEPARATOR_MASK (SEPARATOR_NONE|SEPARATOR_GROOVE|SEPARATOR_RIDGE|SEPARATOR_LINE)
54
55
56 using namespace FX;
57
58 /*******************************************************************************/
59
60
61 namespace FX {
62
63
64 // Map
65 FXDEFMAP(FXSeparator) FXSeparatorMap[]={
66 FXMAPFUNC(SEL_PAINT,0,FXSeparator::onPaint),
67 };
68
69
70 // Object implementation
FXIMPLEMENT(FXSeparator,FXFrame,FXSeparatorMap,ARRAYNUMBER (FXSeparatorMap))71 FXIMPLEMENT(FXSeparator,FXFrame,FXSeparatorMap,ARRAYNUMBER(FXSeparatorMap))
72
73
74 // Construct and init
75 FXSeparator::FXSeparator(FXComposite* p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):
76 FXFrame(p,opts,x,y,w,h,pl,pr,pt,pb){
77 }
78
79
80 // Get default size
getDefaultWidth()81 FXint FXSeparator::getDefaultWidth(){
82 FXint w=(options&(SEPARATOR_GROOVE|SEPARATOR_RIDGE)) ? 2 : 1;
83 return w+padleft+padright+(border<<1);
84 }
85
86
getDefaultHeight()87 FXint FXSeparator::getDefaultHeight(){
88 FXint h=(options&(SEPARATOR_GROOVE|SEPARATOR_RIDGE)) ? 2 : 1;
89 return h+padtop+padbottom+(border<<1);
90 }
91
92
93 // Handle repaint
onPaint(FXObject *,FXSelector,void * ptr)94 long FXSeparator::onPaint(FXObject*,FXSelector,void* ptr){
95 FXEvent *ev=(FXEvent*)ptr;
96 FXDCWindow dc(this,ev);
97 register FXint kk,ll;
98
99 // Draw background
100 dc.setForeground(backColor);
101 dc.fillRectangle(ev->rect.x,ev->rect.y,ev->rect.w,ev->rect.h);
102
103 // Draw frame
104 drawFrame(dc,0,0,width,height);
105
106 // Horizonal orientation
107 if((height-padbottom-padtop) < (width-padleft-padright)){
108 kk=(options&(SEPARATOR_GROOVE|SEPARATOR_RIDGE)) ? 2 : 1;
109 ll=border+padtop+(height-padbottom-padtop-(border<<1)-kk)/2;
110 if(options&SEPARATOR_GROOVE){
111 dc.setForeground(shadowColor);
112 dc.fillRectangle(border+padleft,ll,width-padright-padleft-(border<<1),1);
113 dc.setForeground(hiliteColor);
114 dc.fillRectangle(border+padleft,ll+1,width-padright-padleft-(border<<1),1);
115 }
116 else if(options&SEPARATOR_RIDGE){
117 dc.setForeground(hiliteColor);
118 dc.fillRectangle(border+padleft,ll,width-padright-padleft-(border<<1),1);
119 dc.setForeground(shadowColor);
120 dc.fillRectangle(border+padleft,ll+1,width-padright-padleft-(border<<1),1);
121 }
122 else if(options&SEPARATOR_LINE){
123 dc.setForeground(borderColor);
124 dc.fillRectangle(border+padleft,ll,width-padright-padleft-(border<<1),1);
125 }
126 }
127
128 // Vertical orientation
129 else{
130 kk=(options&(SEPARATOR_GROOVE|SEPARATOR_RIDGE)) ? 2 : 1;
131 ll=border+padleft+(width-padleft-padright-(border<<1)-kk)/2;
132 if(options&SEPARATOR_GROOVE){
133 dc.setForeground(shadowColor);
134 dc.fillRectangle(ll,padtop+border,1,height-padtop-padbottom-(border<<1));
135 dc.setForeground(hiliteColor);
136 dc.fillRectangle(ll+1,padtop+border,1,height-padtop-padbottom-(border<<1));
137 }
138 else if(options&SEPARATOR_RIDGE){
139 dc.setForeground(hiliteColor);
140 dc.fillRectangle(ll,padtop+border,1,height-padtop-padbottom-(border<<1));
141 dc.setForeground(shadowColor);
142 dc.fillRectangle(ll+1,padtop+border,1,height-padtop-padbottom-(border<<1));
143 }
144 else if(options&SEPARATOR_LINE){
145 dc.setForeground(borderColor);
146 dc.fillRectangle(ll,padtop+border,1,height-padtop-padbottom-(border<<1));
147 }
148 }
149 return 1;
150 }
151
152
153 // Change separator style
setSeparatorStyle(FXuint style)154 void FXSeparator::setSeparatorStyle(FXuint style){
155 FXuint opts=(options&~SEPARATOR_MASK) | (style&SEPARATOR_MASK);
156 if(options!=opts){
157 options=opts;
158 recalc();
159 update();
160 }
161 }
162
163
164 // Get separator style
getSeparatorStyle() const165 FXuint FXSeparator::getSeparatorStyle() const {
166 return (options&SEPARATOR_MASK);
167 }
168
169
170 /*******************************************************************************/
171
172
173 // Object implementation
174 FXIMPLEMENT(FXHorizontalSeparator,FXSeparator,0,0)
175
176
177 // Construct and init
FXHorizontalSeparator(FXComposite * p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb)178 FXHorizontalSeparator::FXHorizontalSeparator(FXComposite* p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):
179 FXSeparator(p,opts,x,y,w,h,pl,pr,pt,pb){
180 }
181
182
183 /*******************************************************************************/
184
185
186 // Object implementation
187 FXIMPLEMENT(FXVerticalSeparator,FXSeparator,0,0)
188
189
190 // Construct and init
FXVerticalSeparator(FXComposite * p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb)191 FXVerticalSeparator::FXVerticalSeparator(FXComposite* p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):
192 FXSeparator(p,opts,x,y,w,h,pl,pr,pt,pb){
193 }
194
195
196 }
197
198