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,2020 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (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 *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #include "xincs.h"
22 #include "fxver.h"
23 #include "fxdefs.h"
24 #include "fxmath.h"
25 #include "FXArray.h"
26 #include "FXHash.h"
27 #include "FXMutex.h"
28 #include "FXStream.h"
29 #include "FXString.h"
30 #include "FXSize.h"
31 #include "FXPoint.h"
32 #include "FXRectangle.h"
33 #include "FXStringDictionary.h"
34 #include "FXSettings.h"
35 #include "FXRegistry.h"
36 #include "FXEvent.h"
37 #include "FXWindow.h"
38 #include "FXDCWindow.h"
39 #include "FXApp.h"
40 #include "FXSeparator.h"
41
42
43
44 /*
45 Notes:
46 - When changing icon/font/etc, we should only recalc and update when it's different.
47 - When text changes, do we delete the hot key, or parse it from the new label?
48 - It makes sense for certain ``passive'' widgets such as labels to have onUpdate;
49 for example, to show/hide/whatever based on changing data structures.
50 - Why not just have one type of separator, orientation simply being based on the
51 widest dimension?
52 */
53
54 #define SEPARATOR_EXTRA 2
55
56 #define SEPARATOR_MASK (SEPARATOR_NONE|SEPARATOR_GROOVE|SEPARATOR_RIDGE|SEPARATOR_LINE)
57
58
59 using namespace FX;
60
61 /*******************************************************************************/
62
63
64 namespace FX {
65
66
67 // Map
68 FXDEFMAP(FXSeparator) FXSeparatorMap[]={
69 FXMAPFUNC(SEL_PAINT,0,FXSeparator::onPaint),
70 };
71
72
73 // Object implementation
FXIMPLEMENT(FXSeparator,FXFrame,FXSeparatorMap,ARRAYNUMBER (FXSeparatorMap))74 FXIMPLEMENT(FXSeparator,FXFrame,FXSeparatorMap,ARRAYNUMBER(FXSeparatorMap))
75
76
77 // Construct and init
78 FXSeparator::FXSeparator(FXComposite* p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):FXFrame(p,opts,x,y,w,h,pl,pr,pt,pb){
79 }
80
81
82 // Get default size
getDefaultWidth()83 FXint FXSeparator::getDefaultWidth(){
84 FXint w=(options&(SEPARATOR_GROOVE|SEPARATOR_RIDGE)) ? 2 : 1;
85 return w+padleft+padright+(border<<1);
86 }
87
88
getDefaultHeight()89 FXint FXSeparator::getDefaultHeight(){
90 FXint h=(options&(SEPARATOR_GROOVE|SEPARATOR_RIDGE)) ? 2 : 1;
91 return h+padtop+padbottom+(border<<1);
92 }
93
94
95 // Handle repaint
onPaint(FXObject *,FXSelector,void * ptr)96 long FXSeparator::onPaint(FXObject*,FXSelector,void* ptr){
97 FXEvent *ev=(FXEvent*)ptr;
98 FXDCWindow dc(this,ev);
99 FXint kk,ll;
100
101 // Draw background
102 dc.setForeground(backColor);
103 dc.fillRectangle(ev->rect.x,ev->rect.y,ev->rect.w,ev->rect.h);
104
105 // Draw frame
106 drawFrame(dc,0,0,width,height);
107
108 // Horizonal orientation
109 if((height-padbottom-padtop) < (width-padleft-padright)){
110 kk=(options&(SEPARATOR_GROOVE|SEPARATOR_RIDGE)) ? 2 : 1;
111 ll=border+padtop+(height-padbottom-padtop-(border<<1)-kk)/2;
112 if(options&SEPARATOR_GROOVE){
113 dc.setForeground(shadowColor);
114 dc.fillRectangle(border+padleft,ll,width-padright-padleft-(border<<1),1);
115 dc.setForeground(hiliteColor);
116 dc.fillRectangle(border+padleft,ll+1,width-padright-padleft-(border<<1),1);
117 }
118 else if(options&SEPARATOR_RIDGE){
119 dc.setForeground(hiliteColor);
120 dc.fillRectangle(border+padleft,ll,width-padright-padleft-(border<<1),1);
121 dc.setForeground(shadowColor);
122 dc.fillRectangle(border+padleft,ll+1,width-padright-padleft-(border<<1),1);
123 }
124 else if(options&SEPARATOR_LINE){
125 dc.setForeground(borderColor);
126 dc.fillRectangle(border+padleft,ll,width-padright-padleft-(border<<1),1);
127 }
128 }
129
130 // Vertical orientation
131 else{
132 kk=(options&(SEPARATOR_GROOVE|SEPARATOR_RIDGE)) ? 2 : 1;
133 ll=border+padleft+(width-padleft-padright-(border<<1)-kk)/2;
134 if(options&SEPARATOR_GROOVE){
135 dc.setForeground(shadowColor);
136 dc.fillRectangle(ll,padtop+border,1,height-padtop-padbottom-(border<<1));
137 dc.setForeground(hiliteColor);
138 dc.fillRectangle(ll+1,padtop+border,1,height-padtop-padbottom-(border<<1));
139 }
140 else if(options&SEPARATOR_RIDGE){
141 dc.setForeground(hiliteColor);
142 dc.fillRectangle(ll,padtop+border,1,height-padtop-padbottom-(border<<1));
143 dc.setForeground(shadowColor);
144 dc.fillRectangle(ll+1,padtop+border,1,height-padtop-padbottom-(border<<1));
145 }
146 else if(options&SEPARATOR_LINE){
147 dc.setForeground(borderColor);
148 dc.fillRectangle(ll,padtop+border,1,height-padtop-padbottom-(border<<1));
149 }
150 }
151 return 1;
152 }
153
154
155 // Change separator style
setSeparatorStyle(FXuint style)156 void FXSeparator::setSeparatorStyle(FXuint style){
157 FXuint opts=(options&~SEPARATOR_MASK) | (style&SEPARATOR_MASK);
158 if(options!=opts){
159 options=opts;
160 recalc();
161 update();
162 }
163 }
164
165
166 // Get separator style
getSeparatorStyle() const167 FXuint FXSeparator::getSeparatorStyle() const {
168 return (options&SEPARATOR_MASK);
169 }
170
171
172 /*******************************************************************************/
173
174
175 // Object implementation
176 FXIMPLEMENT(FXHorizontalSeparator,FXSeparator,0,0)
177
178
179 // Construct and init
FXHorizontalSeparator(FXComposite * p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb)180 FXHorizontalSeparator::FXHorizontalSeparator(FXComposite* p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):
181 FXSeparator(p,opts,x,y,w,h,pl,pr,pt,pb){
182 }
183
184
185 /*******************************************************************************/
186
187
188 // Object implementation
189 FXIMPLEMENT(FXVerticalSeparator,FXSeparator,0,0)
190
191
192 // Construct and init
FXVerticalSeparator(FXComposite * p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb)193 FXVerticalSeparator::FXVerticalSeparator(FXComposite* p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):
194 FXSeparator(p,opts,x,y,w,h,pl,pr,pt,pb){
195 }
196
197
198 }
199
200