1 /**
2  *
3  * $Id: Sash.c,v 1.1 2004/08/28 19:22:45 dannybackx Exp $
4  *
5  * Copyright (C) 1995 Free Software Foundation, Inc.
6  * Copyright (C) 1995-2001 LessTif Development Team
7  *
8  * This file is part of the GNU LessTif Library.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the Free
22  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  **/
25 
26 static const char rcsid[] = "$Id: Sash.c,v 1.1 2004/08/28 19:22:45 dannybackx Exp $";
27 
28 #include <LTconfig.h>
29 
30 #include <XmI/XmI.h>
31 #include <Xm/XmP.h>
32 #include <Xm/SashP.h>
33 #include <Xm/DisplayP.h>
34 #include <Xm/TransltnsP.h>
35 
36 #include <XmI/DebugUtil.h>
37 
38 /* Forward Declarations */
39 
40 static void class_initialize(void);
41 
42 static void class_part_initialize(WidgetClass w_class);
43 
44 static void initialize(Widget request, Widget new_w,
45 		       ArgList args, Cardinal *num_args);
46 
47 static void realize(Widget w, XtValueMask *value_mask,
48 		    XSetWindowAttributes *attributes);
49 
50 static void expose(Widget w, XEvent *event, Region region);
51 
52 #if 0
53 static XtGeometryResult query_geometry(Widget w,
54 				       XtWidgetGeometry *proposed,
55 				       XtWidgetGeometry *answer);
56 #endif
57 
58 /*
59  * Resources for the sash class
60  */
61 #define Offset(field) XtOffsetOf(XmSashRec, sash.field)
62 #define POffset(field) XtOffsetOf(XmSashRec, primitive.field)
63 static XtResource resources[] =
64 {
65     {
66 	XmNborderWidth, XmCBorderWidth, XmRHorizontalDimension,
67 	sizeof(Dimension), XtOffsetOf(XmPrimitiveRec, core.border_width),
68 	XmRImmediate, (XtPointer)0
69     },
70     {
71 	XmNcallback, XmCCallback, XmRCallback,
72 	sizeof(XtCallbackList), Offset(sash_action),
73 	XmRPointer, (XtPointer)NULL
74     },
75     {
76 	XmNnavigationType, XmCNavigationType, XmRNavigationType,
77 	sizeof(XmNavigationType), POffset(navigation_type),
78 	XmRImmediate, (XtPointer)XmSTICKY_TAB_GROUP
79     },
80 };
81 
82 static void SashAction(Widget, XEvent *, String *, Cardinal *);
83 
84 static void SashFocusIn(Widget, XEvent *, String *, Cardinal *);
85 
86 static void SashFocusOut(Widget, XEvent *, String *, Cardinal *);
87 
88 static XtActionsRec actions[] =
89 {
90     {"SashAction", SashAction},
91     {"SashFocusIn", SashFocusIn},
92     {"SashFocusOut", SashFocusOut},
93 };
94 
95 
96 static XmBaseClassExtRec _XmSashCoreClassExtRec = {
97     /* next_extension            */ NULL,
98     /* record_type               */ NULLQUARK,
99     /* version                   */ XmBaseClassExtVersion,
100     /* size                      */ sizeof(XmBaseClassExtRec),
101     /* initialize_prehook        */ NULL,
102     /* set_values_prehook        */ NULL,
103     /* initialize_posthook       */ NULL,
104     /* set_values_posthook       */ NULL,
105     /* secondary_object_class    */ NULL,
106     /* secondary_object_create   */ NULL,
107     /* get_secondary_resources   */ NULL,
108     /* fast_subclass             */ { 0 },
109     /* get_values_prehook        */ NULL,
110     /* get_values_posthook       */ NULL,
111     /* class_part_init_prehook   */ NULL,
112     /* class_part_init_posthook  */ NULL,
113     /* ext_resources             */ NULL,
114     /* compiled_ext_resources    */ NULL,
115     /* num_ext_resources         */ 0,
116     /* use_sub_resources         */ False,
117     /* widget_navigable          */ XmInheritWidgetNavigable,
118     /* focus_change              */ XmInheritFocusChange,
119     /* wrapper_data              */ NULL
120 };
121 
122 #if 0
123 XmPrimitiveClassExtRec _XmSashPrimClassExtRec = {
124     /* next_extension      */ NULL,
125     /* record_type         */ NULLQUARK,
126     /* version             */ XmPrimitiveClassExtVersion,
127     /* record_size         */ sizeof(XmPrimitiveClassExtRec),
128     /* widget_baseline     */ NULL,
129     /* widget_display_rect */ NULL,
130     /* widget_margins      */ NULL
131 };
132 #endif
133 
134 XmSashClassRec xmSashClassRec = {
135     /* Core class part */
136     {
137 	/* superclass            */ (WidgetClass) &xmPrimitiveClassRec,
138         /* class_name            */ "XmSash",
139 	/* widget_size           */ sizeof(XmSashRec),
140 	/* class_initialize      */ class_initialize,
141 	/* class_part_initialize */ class_part_initialize,
142 	/* class_inited          */ False,
143 	/* initialize            */ initialize,
144 	/* initialize_hook       */ NULL,
145 	/* realize               */ realize,
146 	/* actions               */ actions,
147 	/* num_actions           */ XtNumber(actions),
148 	/* resources             */ resources,
149 	/* num_resources         */ XtNumber(resources),
150 	/* xrm_class             */ NULLQUARK,
151 	/* compress_motion       */ True,
152 	/* compress_exposure     */ XtExposeCompressMaximal,
153 	/* compress_enterleave   */ True,
154 	/* visible_interest      */ False,
155 	/* destroy               */ NULL,
156 	/* resize                */ NULL,
157 	/* expose                */ expose,
158 	/* set_values            */ NULL,
159 	/* set_values_hook       */ NULL,
160 	/* set_values_almost     */ XtInheritSetValuesAlmost,
161 	/* get_values_hook       */ NULL,
162 	/* accept_focus          */ NULL,
163 	/* version               */ XtVersion,
164 	/* callback offsets      */ NULL,
165 	/* tm_table              */ _XmSash_defTranslations,
166 	/* query_geometry        */ NULL /* query_geometry */,
167 	/* display_accelerator   */ NULL,
168 	/* extension             */ (XtPointer)&_XmSashCoreClassExtRec
169     },
170     /* Primitive Class part */
171     {
172 	/* border_highlight      */ XmInheritBorderHighlight,
173         /* border_unhighlight    */ XmInheritBorderUnhighlight,
174         /* translations          */ NULL,
175         /* arm_and_activate_proc */ NULL,
176         /* synthetic resources   */ NULL,
177 	/* num syn res           */ 0,
178         /* extension             */ (XtPointer)NULL /*&_XmSashPrimClassExtRec*/,
179     },
180     /* Sash Class part */
181     {
182 	/* extension */ NULL
183     }
184 };
185 
186 
187 WidgetClass xmSashWidgetClass = (WidgetClass)&xmSashClassRec;
188 
189 static void
class_initialize(void)190 class_initialize(void)
191 {
192     _XmSashCoreClassExtRec.record_type = XmQmotif;
193 }
194 
195 static void
class_part_initialize(WidgetClass widget_class)196 class_part_initialize(WidgetClass widget_class)
197 {
198     _XmFastSubclassInit(widget_class, XmSASH_BIT);
199 }
200 
201 static void
initialize(Widget request,Widget new_w,ArgList args,Cardinal * num_args)202 initialize(Widget request, Widget new_w,
203 	   ArgList args, Cardinal *num_args)
204 {
205     DEBUGOUT(_LtDebug(__FILE__, new_w, "sash initialize\n"));
206 }
207 
208 static void
realize(Widget w,XtValueMask * value_mask,XSetWindowAttributes * attributes)209 realize(Widget w, XtValueMask *value_mask, XSetWindowAttributes *attributes)
210 {
211     Widget disp = XmGetXmDisplay(XtDisplay(w));
212 
213     *value_mask |= CWCursor;
214     attributes->cursor =
215 	((XmDisplayInfo *) Display_DisplayInfo(disp))->SashCursor;
216 
217 #define superclass (&xmPrimitiveClassRec)
218     (*superclass->core_class.realize) (w, value_mask, attributes);
219 #undef superclass
220 }
221 
222 static void
expose(Widget w,XEvent * event,Region region)223 expose(Widget w,
224        XEvent *event,
225        Region region)
226 {
227     DEBUGOUT(_LtDebug(__FILE__, w, "Sash expose\n"));
228 
229     _XmDrawShadows(XtDisplay(w),
230 		   XtWindow(w),
231 		   Prim_TopShadowGC(w),
232 		   Prim_BottomShadowGC(w),
233 		   0, 0,
234 		   XtWidth(w),
235 		   XtHeight(w),
236 		   Prim_ShadowThickness(w),
237 		   XmSHADOW_OUT);
238 
239     if (!Prim_Highlighted(w))
240     {
241 	XFillRectangle(XtDisplay(w), XtWindow(w),
242 		       XmParentBackgroundGC(w),
243 		       Prim_ShadowThickness(w), Prim_ShadowThickness(w),
244 		       XtWidth(w) - 2 * Prim_ShadowThickness(w),
245 		       XtHeight(w) - 2 * Prim_ShadowThickness(w));
246     }
247 }
248 
249 #if 0
250 static XtGeometryResult
251 query_geometry(Widget w,
252 	       XtWidgetGeometry *proposed,
253 	       XtWidgetGeometry *answer)
254 {
255     /* Motif does not have this method */
256     XmSashWidget sw = (XmSashWidget)w;
257     answer->request_mode = CWWidth | CWHeight;
258 
259     answer->width = XtWidth(w) + 2 * Prim_ShadowThickness(sw);
260 
261     answer->height = XtHeight(w) + 2 * Prim_ShadowThickness(sw);
262 
263     if (((proposed->request_mode & (CWWidth | CWHeight))
264 	 == (CWWidth | CWHeight)) &&
265 	proposed->width == answer->width &&
266 	proposed->height == answer->height)
267     {
268 	return XtGeometryYes;
269     }
270     else if (answer->width == XtWidth(sw) &&
271 	     answer->height == XtHeight(sw))
272     {
273 	return XtGeometryNo;
274     }
275     else
276     {
277 	return XtGeometryAlmost;
278     }
279 }
280 #endif
281 
282 static void
SashAction(Widget w,XEvent * event,String * params,Cardinal * num_params)283 SashAction(Widget w,
284 	   XEvent *event,
285 	   String *params,
286 	   Cardinal *num_params)
287 {
288     XmSashWidget sw = (XmSashWidget)w;
289     SashCallDataRec cd;
290 
291     cd.event = event;
292     cd.params = params;
293     cd.num_params = *num_params;
294 
295     XtCallCallbackList((Widget)sw, Sash_SashAction(sw), &cd);
296 
297     expose(w, NULL, NULL);
298 }
299 
300 static void
SashFocusIn(Widget w,XEvent * event,String * params,Cardinal * num_params)301 SashFocusIn(Widget w, XEvent *event, String *params, Cardinal *num_params)
302 {
303     DEBUGOUT(_LtDebug(__FILE__, w, "Sash FocusIn\n"));
304 }
305 
306 static void
SashFocusOut(Widget w,XEvent * event,String * params,Cardinal * num_params)307 SashFocusOut(Widget w, XEvent *event, String *params, Cardinal *num_params)
308 {
309     DEBUGOUT(_LtDebug(__FILE__, w, "SASH FOCUS OUT\n"));
310 }
311