424
|
1 /* Tabs Widget for XEmacs.
|
|
2 Copyright (C) 1999 Edward A. Falk
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Tabs.c 1.23 */
|
|
22
|
|
23 /*
|
|
24 * Tabs.c - Index Tabs composite widget
|
|
25 *
|
|
26 * Author: Edward A. Falk
|
|
27 * falk@falconer.vip.best.com
|
|
28 *
|
|
29 * Date: July 29, 1997
|
|
30 *
|
|
31 *
|
|
32 * Overall layout of this widget is as follows:
|
|
33 *
|
|
34 * ________ ,---------. _________
|
|
35 * | label || Label || Label | \ tabs
|
|
36 * |________|| ||_________| /
|
|
37 * |+----------------------------+| \
|
|
38 * || || |
|
|
39 * || child widget window || > frame
|
|
40 * |+----------------------------+| |
|
|
41 * +------------------------------+ /
|
|
42 *
|
|
43 * The height of the tabs includes the shadow width, top and bottom
|
|
44 * margins, and the height of the text.
|
|
45 *
|
|
46 * The height of the frame includes the top and bottom shadow width and the
|
|
47 * size of the child widget window.
|
|
48 *
|
|
49 * The tabs overlap the frame and each other vertically by the shadow
|
|
50 * width, so that when the topmost tab is drawn, it obliterates part of
|
|
51 * the frame.
|
|
52 */
|
|
53
|
|
54 /* TODO: min child height = tab height
|
|
55 *
|
|
56 */
|
|
57
|
|
58 #include <config.h>
|
|
59 #include <stdio.h>
|
|
60
|
|
61 #include <X11/Xlib.h>
|
|
62 #include <X11/IntrinsicP.h>
|
|
63 #include <X11/StringDefs.h>
|
|
64 #include "../src/xmu.h"
|
|
65 #include "xlwtabsP.h"
|
|
66 #include "xlwgcs.h"
|
|
67
|
|
68 #define MIN_WID 10
|
|
69 #define MIN_HGT 10
|
|
70 #define INDENT 3 /* tabs indented from edge by this much */
|
|
71 #define SPACING 0 /* distance between tabs */
|
|
72 #define SHADWID 1 /* default shadow width */
|
|
73 #define TABDELTA 2 /* top tab grows this many pixels */
|
|
74 #define TABLDELTA 2 /* top tab label offset this many pixels */
|
|
75
|
|
76
|
|
77 /****************************************************************
|
|
78 *
|
|
79 * IndexTabs Resources
|
|
80 *
|
|
81 ****************************************************************/
|
|
82
|
|
83 static char defaultTranslations[] = "\
|
|
84 <BtnUp>: select() \n\
|
|
85 <FocusIn>: highlight() \n\
|
|
86 <FocusOut>: unhighlight() \n\
|
|
87 <Key>Page_Up: page(up) \n\
|
|
88 <Key>KP_Page_Up: page(up) \n\
|
|
89 <Key>Prior: page(up) \n\
|
|
90 <Key>KP_Prior: page(up) \n\
|
|
91 <Key>Page_Down: page(down) \n\
|
|
92 <Key>KP_Page_Down: page(down) \n\
|
|
93 <Key>Next: page(down) \n\
|
|
94 <Key>KP_Next: page(down) \n\
|
|
95 <Key>Home: page(home) \n\
|
|
96 <Key>KP_Home: page(home) \n\
|
|
97 <Key>End: page(end) \n\
|
|
98 <Key>KP_End: page(end) \n\
|
|
99 <Key>Up: highlight(up) \n\
|
|
100 <Key>KP_Up: highlight(up) \n\
|
|
101 <Key>Down: highlight(down) \n\
|
|
102 <Key>KP_Down: highlight(down) \n\
|
|
103 <Key> : page(select) \n\
|
|
104 " ;
|
|
105
|
|
106 static char accelTable[] = " #augment\n\
|
|
107 <Key>Page_Up: page(up) \n\
|
|
108 <Key>KP_Page_Up: page(up) \n\
|
|
109 <Key>Prior: page(up) \n\
|
|
110 <Key>KP_Prior: page(up) \n\
|
|
111 <Key>Page_Down: page(down) \n\
|
|
112 <Key>KP_Page_Down: page(down) \n\
|
|
113 <Key>Next: page(down) \n\
|
|
114 <Key>KP_Next: page(down) \n\
|
|
115 <Key>Home: page(home) \n\
|
|
116 <Key>KP_Home: page(home) \n\
|
|
117 <Key>End: page(end) \n\
|
|
118 <Key>KP_End: page(end) \n\
|
|
119 <Key>Up: highlight(up) \n\
|
|
120 <Key>KP_Up: highlight(up) \n\
|
|
121 <Key>Down: highlight(down) \n\
|
|
122 <Key>KP_Down: highlight(down) \n\
|
|
123 <Key> : page(select) \n\
|
|
124 " ;
|
|
125 static XtAccelerators defaultAccelerators ;
|
|
126
|
|
127 #define offset(field) XtOffsetOf(TabsRec, tabs.field)
|
|
128 static XtResource resources[] = {
|
|
129
|
|
130 {XtNselectInsensitive, XtCSelectInsensitive, XtRBoolean, sizeof(Boolean),
|
|
131 offset(selectInsensitive), XtRImmediate, (XtPointer) True},
|
|
132 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
|
|
133 offset(font), XtRString, (XtPointer) XtDefaultFont},
|
|
134 {XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension),
|
|
135 offset(internalWidth), XtRImmediate, (XtPointer)4 },
|
|
136 {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension),
|
|
137 offset(internalHeight), XtRImmediate, (XtPointer)4 },
|
|
138 {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
|
|
139 XtOffsetOf(RectObjRec,rectangle.border_width), XtRImmediate, (XtPointer)0},
|
|
140 {XtNtopWidget, XtCTopWidget, XtRWidget, sizeof(Widget),
|
|
141 offset(topWidget), XtRImmediate, NULL},
|
|
142 {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
|
|
143 offset(callbacks), XtRCallback, NULL},
|
|
144 {XtNpopdownCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
|
|
145 offset(popdownCallbacks), XtRCallback, NULL},
|
|
146 {XtNbeNiceToColormap, XtCBeNiceToColormap, XtRBoolean, sizeof(Boolean),
|
|
147 offset(be_nice_to_cmap), XtRImmediate, (XtPointer) True},
|
|
148 {XtNtopShadowContrast, XtCTopShadowContrast, XtRInt, sizeof(int),
|
|
149 offset(top_shadow_contrast), XtRImmediate, (XtPointer) 20},
|
|
150 {XtNbottomShadowContrast, XtCBottomShadowContrast, XtRInt, sizeof(int),
|
|
151 offset(bot_shadow_contrast), XtRImmediate, (XtPointer) 40},
|
|
152 {XtNinsensitiveContrast, XtCInsensitiveContrast, XtRInt, sizeof(int),
|
|
153 offset(insensitive_contrast), XtRImmediate, (XtPointer) 33},
|
|
154 {XtNaccelerators, XtCAccelerators, XtRAcceleratorTable,sizeof(XtTranslations),
|
|
155 XtOffsetOf(TabsRec,core.accelerators), XtRString, accelTable},
|
|
156 };
|
|
157 #undef offset
|
|
158
|
|
159
|
|
160
|
|
161 /* constraint resources */
|
|
162
|
|
163 #define offset(field) XtOffsetOf(TabsConstraintsRec, tabs.field)
|
|
164 static XtResource tabsConstraintResources[] = {
|
|
165 {XtNtabLabel, XtCLabel, XtRString, sizeof(String),
|
|
166 offset(label), XtRString, NULL},
|
|
167 {XtNtabLeftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap),
|
|
168 offset(left_bitmap), XtRImmediate, None},
|
|
169 {XtNtabForeground, XtCForeground, XtRPixel, sizeof(Pixel),
|
|
170 offset(foreground), XtRString, (XtPointer) XtDefaultForeground},
|
|
171 {XtNresizable, XtCResizable, XtRBoolean, sizeof(Boolean),
|
|
172 offset(resizable), XtRImmediate, (XtPointer) True},
|
|
173 } ;
|
|
174 #undef offset
|
|
175
|
|
176
|
|
177
|
|
178
|
|
179 #if !NeedFunctionPrototypes
|
|
180
|
|
181 /* FORWARD REFERENCES: */
|
|
182
|
|
183 /* member functions */
|
|
184
|
|
185 static void TabsClassInit();
|
|
186 static void TabsInit();
|
|
187 static void TabsResize();
|
|
188 static void TabsExpose();
|
|
189 static void TabsDestroy();
|
|
190 static void TabsRealize();
|
|
191 static Boolean TabsSetValues();
|
|
192 static XtGeometryResult TabsQueryGeometry();
|
|
193 static XtGeometryResult TabsGeometryManager();
|
|
194 static void TabsChangeManaged();
|
|
195 static void TabsConstraintInitialize() ;
|
|
196 static Boolean TabsConstraintSetValues() ;
|
|
197
|
|
198 /* action procs */
|
|
199
|
|
200 static void TabsSelect() ;
|
|
201 static void TabsPage() ;
|
|
202 static void TabsHighlight() ;
|
|
203 static void TabsUnhighlight() ;
|
|
204
|
|
205 /* internal privates */
|
|
206
|
|
207 static void TabsAllocGCs() ; /* get rendering GCs */
|
|
208 static void TabsFreeGCs() ; /* return rendering GCs */
|
|
209 static void DrawTabs() ; /* draw all tabs */
|
|
210 static void DrawTab() ; /* draw one index tab */
|
|
211 static void DrawFrame() ; /* draw frame around contents */
|
|
212 static void DrawTrim() ; /* draw trim around a tab */
|
|
213 static void DrawBorder() ; /* draw border */
|
|
214 static void DrawHighlight() ; /* draw highlight */
|
|
215 static void UndrawTab() ; /* undraw interior of a tab */
|
|
216 static void TabWidth() ; /* recompute tab size */
|
|
217 static void GetPreferredSizes() ; /* query all children for their sizes */
|
|
218 static void MaxChild() ; /* find max preferred child size */
|
|
219 static int PreferredSize() ; /* compute preferred size */
|
|
220 static int PreferredSize2() ; /* compute preferred size */
|
|
221 static int PreferredSize3() ; /* compute preferred size */
|
|
222 static void MakeSizeRequest() ; /* try to change size */
|
|
223 static void getBitmapInfo() ;
|
|
224 static int TabLayout() ; /* lay out tabs */
|
|
225 static void TabsShuffleRows() ; /* bring current tab to bottom row */
|
|
226
|
|
227 static void TabsAllocFgGC() ;
|
|
228 static void TabsAllocGreyGC() ;
|
|
229
|
|
230 #else
|
|
231
|
|
232 static void TabsClassInit(void) ;
|
|
233 static void TabsInit( Widget req, Widget new, ArgList, Cardinal *nargs) ;
|
|
234 static void TabsConstraintInitialize(Widget, Widget, ArgList, Cardinal *) ;
|
|
235 static void TabsRealize(Widget, Mask *, XSetWindowAttributes *) ;
|
|
236 static void TabsDestroy( Widget w) ;
|
|
237 static void TabsResize( Widget w) ;
|
|
238 static void TabsExpose( Widget w, XEvent *event, Region region) ;
|
|
239 static Boolean TabsSetValues(Widget, Widget, Widget, ArgList, Cardinal *) ;
|
|
240 static Boolean TabsConstraintSetValues(Widget, Widget, Widget,
|
|
241 ArgList, Cardinal *) ;
|
|
242 static XtGeometryResult TabsQueryGeometry(Widget,
|
|
243 XtWidgetGeometry *, XtWidgetGeometry *) ;
|
|
244 static XtGeometryResult TabsGeometryManager(Widget,
|
|
245 XtWidgetGeometry *, XtWidgetGeometry *) ;
|
|
246 static void TabsChangeManaged( Widget w) ;
|
|
247
|
|
248 static void TabsSelect(Widget, XEvent *, String *, Cardinal *) ;
|
|
249 static void TabsPage(Widget, XEvent *, String *, Cardinal *) ;
|
|
250 static void TabsHighlight(Widget, XEvent *, String *, Cardinal *) ;
|
|
251 static void TabsUnhighlight(Widget, XEvent *, String *, Cardinal *) ;
|
|
252
|
|
253 static void DrawTabs( TabsWidget tw, Bool labels) ;
|
|
254 static void DrawTab( TabsWidget tw, Widget child, Bool labels) ;
|
|
255 static void DrawFrame( TabsWidget tw) ;
|
|
256 static void DrawTrim( TabsWidget, int x, int y,
|
|
257 int wid, int hgt, Bool bottom, Bool undraw) ;
|
|
258 static void DrawBorder( TabsWidget tw, Widget child, Bool undraw) ;
|
|
259 static void DrawHighlight( TabsWidget tw, Widget child, Bool undraw) ;
|
|
260 static void UndrawTab( TabsWidget tw, Widget child) ;
|
|
261
|
|
262 static void TabWidth( Widget w) ;
|
|
263 static int TabLayout( TabsWidget, int wid, int hgt, Dimension *r_hgt,
|
|
264 Bool query_only) ;
|
|
265 static void GetPreferredSizes(TabsWidget) ;
|
|
266 static void MaxChild(TabsWidget) ;
|
|
267 static void TabsShuffleRows( TabsWidget tw) ;
|
|
268 static int PreferredSize( TabsWidget,
|
|
269 Dimension *reply_width, Dimension *reply_height,
|
|
270 Dimension *reply_cw, Dimension *reply_ch) ;
|
|
271 static int PreferredSize2( TabsWidget, int cw, int ch,
|
|
272 Dimension *rw, Dimension *rh) ;
|
|
273 static int PreferredSize3( TabsWidget, int wid, int hgt,
|
|
274 Dimension *rw, Dimension *rh) ;
|
|
275 static void MakeSizeRequest(TabsWidget) ;
|
|
276
|
|
277 static void TabsAllocGCs(TabsWidget) ;
|
|
278 static void TabsFreeGCs(TabsWidget) ;
|
|
279 static void getBitmapInfo( TabsWidget tw, TabsConstraints tab) ;
|
|
280 static void TabsAllocFgGC( TabsWidget tw) ;
|
|
281 static void TabsAllocGreyGC( TabsWidget tw) ;
|
|
282
|
|
283 #endif
|
|
284
|
|
285 #define AddRect(i,xx,yy,w,h) \
|
|
286 do{rects[(i)].x=(xx); rects[i].y=(yy); \
|
|
287 rects[i].width=(w); rects[i].height=(h);}while(0)
|
|
288
|
|
289 static XtActionsRec actionsList[] =
|
|
290 {
|
|
291 {"select", TabsSelect},
|
|
292 {"page", TabsPage},
|
|
293 {"highlight", TabsHighlight},
|
|
294 {"unhighlight", TabsUnhighlight},
|
|
295 } ;
|
|
296
|
|
297
|
|
298 /****************************************************************
|
|
299 *
|
|
300 * Full class record constant
|
|
301 *
|
|
302 ****************************************************************/
|
|
303
|
|
304 #ifndef NEED_MOTIF
|
|
305 #define SuperClass (&constraintClassRec)
|
|
306 #else
|
|
307 #define SuperClass (&xmManagerClassRec)
|
|
308 #endif
|
|
309
|
|
310 TabsClassRec tabsClassRec = {
|
|
311 {
|
|
312 /* core_class fields */
|
|
313 /* superclass */ (WidgetClass) SuperClass,
|
|
314 /* class_name */ "Tabs",
|
|
315 /* widget_size */ sizeof(TabsRec),
|
|
316 /* class_initialize */ TabsClassInit,
|
|
317 /* class_part_init */ NULL, /* TODO? */
|
|
318 /* class_inited */ FALSE,
|
|
319 /* initialize */ TabsInit,
|
|
320 /* initialize_hook */ NULL,
|
|
321 /* realize */ TabsRealize,
|
|
322 /* actions */ actionsList,
|
|
323 /* num_actions */ XtNumber(actionsList),
|
|
324 /* resources */ resources,
|
|
325 /* num_resources */ XtNumber(resources),
|
|
326 /* xrm_class */ NULLQUARK,
|
|
327 /* compress_motion */ TRUE,
|
|
328 /* compress_exposure */ TRUE,
|
|
329 /* compress_enterleave*/ TRUE,
|
|
330 /* visible_interest */ FALSE,
|
|
331 /* destroy */ TabsDestroy,
|
|
332 /* resize */ TabsResize,
|
|
333 /* expose */ TabsExpose,
|
|
334 /* set_values */ TabsSetValues,
|
|
335 /* set_values_hook */ NULL,
|
|
336 /* set_values_almost */ XtInheritSetValuesAlmost,
|
|
337 /* get_values_hook */ NULL,
|
|
338 /* accept_focus */ NULL,
|
|
339 /* version */ XtVersion,
|
|
340 /* callback_private */ NULL,
|
|
341 /* tm_table */ defaultTranslations,
|
|
342 /* query_geometry */ TabsQueryGeometry,
|
|
343 /* display_accelerator*/ XtInheritDisplayAccelerator,
|
|
344 /* extension */ NULL
|
|
345 },
|
|
346 {
|
|
347 /* composite_class fields */
|
|
348 /* geometry_manager */ TabsGeometryManager,
|
|
349 /* change_managed */ TabsChangeManaged,
|
|
350 /* insert_child */ XtInheritInsertChild, /* TODO? */
|
|
351 /* delete_child */ XtInheritDeleteChild, /* TODO? */
|
|
352 /* extension */ NULL
|
|
353 },
|
|
354 {
|
|
355 /* constraint_class fields */
|
|
356 /* subresources */ tabsConstraintResources,
|
|
357 /* subresource_count */ XtNumber(tabsConstraintResources),
|
|
358 /* constraint_size */ sizeof(TabsConstraintsRec),
|
|
359 /* initialize */ TabsConstraintInitialize,
|
|
360 /* destroy */ NULL,
|
|
361 /* set_values */ TabsConstraintSetValues,
|
|
362 /* extension */ NULL,
|
|
363 },
|
|
364 #ifdef NEED_MOTIF
|
|
365 /* Manager Class fields */
|
|
366 {
|
|
367 /* translations */ NULL,
|
|
368 /* syn_resources */ NULL,
|
|
369 /* num_syn_resources */ 0,
|
|
370 /* syn_constraint_resources */ NULL,
|
|
371 /* num_syn_constraint_resources */ 0,
|
|
372 /* parent_process */ XmInheritParentProcess,
|
|
373 /* extension */ NULL
|
|
374 },
|
|
375 #endif
|
|
376 {
|
|
377 /* Tabs class fields */
|
|
378 /* extension */ NULL,
|
|
379 }
|
|
380 };
|
|
381
|
|
382 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec;
|
|
383
|
|
384
|
|
385
|
|
386 #ifdef DEBUG
|
|
387 #ifdef __STDC__
|
|
388 #define assert(e) \
|
|
389 if(!(e)) fprintf(stderr,"yak! %s at %s:%d\n",#e,__FILE__,__LINE__)
|
|
390 #else
|
|
391 #define assert(e) \
|
|
392 if(!(e)) fprintf(stderr,"yak! e at %s:%d\n",__FILE__,__LINE__)
|
|
393 #endif
|
|
394 #else
|
|
395 #define assert(e)
|
|
396 #endif
|
|
397
|
|
398
|
|
399
|
|
400
|
|
401 /****************************************************************
|
|
402 *
|
|
403 * Member Procedures
|
|
404 *
|
|
405 ****************************************************************/
|
|
406
|
|
407 static void
|
|
408 TabsClassInit(void)
|
|
409 {
|
|
410 defaultAccelerators = XtParseAcceleratorTable(accelTable) ;
|
|
411 /* TODO: register converter for labels? */
|
|
412 }
|
|
413
|
|
414
|
|
415
|
|
416 /* Init a newly created tabs widget. Compute height of tabs
|
|
417 * and optionally compute size of widget. */
|
|
418
|
|
419 /* ARGSUSED */
|
|
420
|
|
421 static void
|
|
422 TabsInit(Widget request, Widget new, ArgList args, Cardinal *num_args)
|
|
423 {
|
|
424 TabsWidget newTw = (TabsWidget)new;
|
|
425
|
|
426 newTw->tabs.numRows = 0 ;
|
|
427 newTw->tabs.displayChildren = 0;
|
|
428
|
|
429 GetPreferredSizes(newTw) ;
|
|
430
|
|
431 /* height is easy, it's the same for all tabs:
|
|
432 * TODO: font height + height of tallest bitmap.
|
|
433 */
|
|
434 newTw->tabs.tab_height = 2 * newTw->tabs.internalHeight + SHADWID ;
|
|
435
|
|
436 if( newTw->tabs.font != NULL )
|
|
437 newTw->tabs.tab_height += newTw->tabs.font->max_bounds.ascent +
|
|
438 newTw->tabs.font->max_bounds.descent ;
|
|
439
|
|
440 /* GC allocation is deferred until XtRealize() */
|
|
441
|
|
442 /* if size not explicitly set, set it to our preferred size now. */
|
|
443
|
|
444 if( request->core.width == 0 || request->core.height == 0 )
|
|
445 {
|
|
446 Dimension w,h ;
|
|
447 PreferredSize(newTw, &w, &h, NULL,NULL) ;
|
|
448 if( request->core.width == 0 ) new->core.width = w ;
|
|
449 if( request->core.height == 0 ) new->core.height = h ;
|
|
450 XtClass(new)->core_class.resize(new) ;
|
|
451 }
|
|
452
|
|
453 /* defer GC allocation, etc., until Realize() time. */
|
|
454 newTw->tabs.foregroundGC =
|
|
455 newTw->tabs.backgroundGC =
|
|
456 newTw->tabs.greyGC =
|
|
457 newTw->tabs.topGC =
|
|
458 newTw->tabs.botGC = None ;
|
|
459
|
|
460 newTw->tabs.grey50 = None ;
|
|
461
|
|
462 newTw->tabs.needs_layout = False ;
|
|
463
|
|
464 newTw->tabs.hilight = NULL ;
|
|
465
|
|
466 #ifdef NEED_MOTIF
|
|
467 newTw->manager.navigation_type = XmTAB_GROUP ;
|
|
468 newTw->manager.traversal_on = True ;
|
|
469 #endif
|
|
470 }
|
|
471
|
|
472
|
|
473 /* Init the constraint part of a new tab child. Compute the
|
|
474 * size of the tab.
|
|
475 */
|
|
476 /* ARGSUSED */
|
|
477 static void
|
|
478 TabsConstraintInitialize(Widget request, Widget new,
|
|
479 ArgList args, Cardinal *num_args)
|
|
480 {
|
|
481 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
|
|
482 tab->tabs.greyAlloc = False ; /* defer allocation of pixel */
|
|
483 tab->tabs.queried = False ; /* defer size query */
|
|
484
|
|
485 getBitmapInfo((TabsWidget)XtParent(new), tab) ;
|
|
486 TabWidth(new) ;
|
|
487 }
|
|
488
|
|
489
|
|
490
|
|
491 /* Called when tabs widget first realized. Create the window
|
|
492 * and allocate the GCs
|
|
493 */
|
|
494
|
|
495 static void
|
|
496 TabsRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
|
|
497 {
|
|
498 TabsWidget tw = (TabsWidget) w;
|
|
499
|
|
500 attributes->bit_gravity = NorthWestGravity;
|
|
501 *valueMask |= CWBitGravity;
|
|
502
|
|
503 SuperClass->core_class.realize(w, valueMask, attributes);
|
|
504
|
|
505 TabsAllocGCs(tw) ;
|
|
506 }
|
|
507
|
|
508
|
|
509
|
|
510 static void
|
|
511 TabsDestroy(Widget w)
|
|
512 {
|
|
513 TabsFreeGCs((TabsWidget)w) ;
|
|
514 }
|
|
515
|
|
516
|
|
517 /* Parent has resized us. This will require that the tabs be
|
|
518 * laid out again.
|
|
519 */
|
|
520
|
|
521 static void
|
|
522 TabsResize(Widget w)
|
|
523 {
|
|
524 TabsWidget tw = (TabsWidget) w;
|
|
525 int i ;
|
|
526 int num_children = tw->composite.num_children ;
|
|
527 Widget *childP ;
|
|
528 TabsConstraints tab ;
|
|
529 Dimension cw,ch,bw ;
|
|
530
|
|
531 /* Our size has now been dictated by the parent. Lay out the
|
|
532 * tabs, lay out the frame, lay out the children. Remember
|
|
533 * that the tabs overlap each other and the frame by shadowWidth.
|
|
534 * Also, the top tab is larger than the others, so if there's only
|
|
535 * one row, the widget must be made taller to accommodate this.
|
|
536 *
|
|
537 * Once the tabs are laid out, if there is more than one
|
|
538 * row, we may need to shuffle the rows to bring the top tab
|
|
539 * to the bottom row.
|
|
540 */
|
|
541
|
|
542 if( num_children > 0 && tw->composite.children != NULL )
|
|
543 {
|
|
544 /* Loop through the tabs and assign rows & x positions */
|
|
545 (void) TabLayout(tw, tw->core.width, tw->core.height, NULL, False) ;
|
|
546 num_children = tw->tabs.displayChildren;
|
|
547
|
|
548 /* assign a top widget, bring it to bottom row. */
|
|
549 TabsShuffleRows(tw) ;
|
|
550
|
|
551 /* now assign child positions & sizes. Positions are all the
|
|
552 * same: just inside the frame. Sizes are also all the same.
|
|
553 */
|
|
554
|
|
555 tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ;
|
|
556 tw->tabs.child_height = ch =
|
|
557 tw->core.height - tw->tabs.tab_total - 2 * SHADWID ;
|
|
558
|
|
559
|
|
560 for(i=0, childP=tw->composite.children;
|
|
561 i < num_children;
|
|
562 ++i, ++childP)
|
|
563 if( XtIsManaged(*childP) )
|
|
564 {
|
|
565 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
566 bw = tab->tabs.bwid ;
|
|
567 XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID,
|
|
568 cw-bw*2,ch-bw*2, bw) ;
|
|
569 }
|
|
570 if( XtIsRealized(w) )
|
|
571 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
|
|
572 }
|
|
573
|
|
574 tw->tabs.needs_layout = False ;
|
|
575 } /* Resize */
|
|
576
|
|
577
|
|
578
|
|
579 /* Redraw entire Tabs widget */
|
|
580
|
|
581 /* ARGSUSED */
|
|
582 static void
|
|
583 TabsExpose(Widget w, XEvent *event, Region region)
|
|
584 {
|
|
585 TabsWidget tw = (TabsWidget) w;
|
|
586
|
|
587 if( tw->tabs.needs_layout )
|
|
588 XtClass(w)->core_class.resize(w) ;
|
|
589
|
|
590 DrawTabs(tw, True) ;
|
|
591 }
|
|
592
|
|
593
|
|
594 /* Called when any Tabs widget resources are changed. */
|
|
595
|
|
596 /* ARGSUSED */
|
|
597 static Boolean
|
|
598 TabsSetValues(Widget current, Widget request, Widget new,
|
|
599 ArgList args, Cardinal *num_args)
|
|
600 {
|
|
601 TabsWidget curtw = (TabsWidget) current ;
|
|
602 TabsWidget tw = (TabsWidget) new ;
|
|
603 Boolean needRedraw = False ;
|
|
604 Widget *childP ;
|
|
605 int i ;
|
|
606
|
|
607
|
|
608 if( tw->tabs.font != curtw->tabs.font ||
|
|
609 tw->tabs.internalWidth != curtw->tabs.internalWidth ||
|
|
610 tw->tabs.internalHeight != curtw->tabs.internalHeight )
|
|
611 {
|
|
612 tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID ;
|
|
613
|
|
614 if( tw->tabs.font != NULL )
|
|
615 tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
|
|
616 tw->tabs.font->max_bounds.descent ;
|
|
617
|
|
618 /* Tab size has changed. Resize all tabs and request a new size */
|
|
619 for(i=0, childP=tw->composite.children;
|
|
620 i < tw->composite.num_children;
|
|
621 ++i, ++childP)
|
|
622 if( XtIsManaged(*childP) )
|
|
623 TabWidth(*childP) ;
|
|
624 PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
|
|
625 needRedraw = True ;
|
|
626 tw->tabs.needs_layout = True ;
|
|
627 }
|
|
628
|
|
629 /* TODO: if any color changes, need to recompute GCs and redraw */
|
|
630
|
|
631 if( tw->core.background_pixel != curtw->core.background_pixel ||
|
|
632 tw->core.background_pixmap != curtw->core.background_pixmap )
|
|
633 if( XtIsRealized(new) )
|
|
634 {
|
|
635 TabsFreeGCs(tw) ;
|
|
636 TabsAllocGCs(tw) ;
|
|
637 needRedraw = True ;
|
|
638 }
|
|
639
|
|
640 if( tw->core.sensitive != curtw->core.sensitive )
|
|
641 needRedraw = True ;
|
|
642
|
|
643 /* If top widget changes, need to change stacking order, redraw tabs.
|
|
644 * Window system will handle the redraws.
|
|
645 */
|
|
646
|
|
647 if( tw->tabs.topWidget != curtw->tabs.topWidget )
|
|
648 if( XtIsRealized(tw->tabs.topWidget) )
|
|
649 {
|
|
650 Widget w = tw->tabs.topWidget ;
|
|
651 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
|
|
652
|
|
653 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
|
|
654 #ifdef NEED_MOTIF
|
|
655 XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
|
|
656 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
|
|
657 #endif
|
|
658
|
|
659 if( tab->tabs.row != tw->tabs.numRows-1 )
|
|
660 TabsShuffleRows(tw) ;
|
|
661
|
|
662 needRedraw = True ;
|
|
663 }
|
|
664 else
|
|
665 tw->tabs.needs_layout = True ;
|
|
666
|
|
667 return needRedraw ;
|
|
668 }
|
|
669
|
|
670
|
|
671 /* Called when any child constraint resources change. */
|
|
672
|
|
673 /* ARGSUSED */
|
|
674 static Boolean
|
|
675 TabsConstraintSetValues(Widget current, Widget request, Widget new,
|
|
676 ArgList args, Cardinal *num_args)
|
|
677 {
|
|
678 TabsWidget tw = (TabsWidget) XtParent(new) ;
|
|
679 TabsConstraints ctab = (TabsConstraints) current->core.constraints ;
|
|
680 TabsConstraints tab = (TabsConstraints) new->core.constraints ;
|
|
681
|
|
682
|
|
683 /* if label changes, need to re-layout the entire widget */
|
|
684 /* if foreground changes, need to redraw tab label */
|
|
685
|
|
686 /* TODO: only need resize of new bitmap has different dimensions
|
|
687 * from old bitmap.
|
|
688 */
|
|
689
|
|
690 if( tab->tabs.label != ctab->tabs.label || /* Tab size has changed. */
|
|
691 tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
|
|
692 {
|
|
693 TabWidth(new) ;
|
|
694 tw->tabs.needs_layout = True ;
|
|
695
|
|
696 if( tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
|
|
697 getBitmapInfo(tw, tab) ;
|
|
698
|
|
699 /* If there are no subclass ConstraintSetValues procedures remaining
|
|
700 * to be invoked, and if the preferred size has changed, ask
|
|
701 * for a resize.
|
|
702 */
|
|
703 if( XtClass((Widget)tw) == tabsWidgetClass )
|
|
704 MakeSizeRequest(tw) ;
|
|
705 }
|
|
706
|
|
707
|
|
708 /* The child widget itself never needs a redisplay, but the parent
|
|
709 * Tabs widget might.
|
|
710 */
|
|
711
|
|
712 if( XtIsRealized(new) )
|
|
713 {
|
|
714 if( tw->tabs.needs_layout ) {
|
|
715 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
|
|
716 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
|
|
717 }
|
|
718
|
|
719 else if( tab->tabs.foreground != ctab->tabs.foreground )
|
|
720 DrawTab(tw, new, True) ;
|
|
721 }
|
|
722
|
|
723 return False ;
|
|
724 }
|
|
725
|
|
726
|
|
727
|
|
728 /*
|
|
729 * Return preferred size. Happily accept anything >= our preferred size.
|
|
730 * (TODO: is that the right thing to do? Should we always return "almost"
|
|
731 * if offerred more than we need?)
|
|
732 */
|
|
733
|
|
734 static XtGeometryResult
|
|
735 TabsQueryGeometry(Widget w,
|
|
736 XtWidgetGeometry *intended, XtWidgetGeometry *preferred)
|
|
737 {
|
|
738 register TabsWidget tw = (TabsWidget)w ;
|
|
739 XtGeometryMask mode = intended->request_mode ;
|
|
740
|
|
741 preferred->request_mode = CWWidth | CWHeight ;
|
|
742 PreferredSize(tw, &preferred->width, &preferred->height, NULL,NULL) ;
|
|
743
|
|
744 if( (!(mode & CWWidth) || intended->width == w->core.width) &&
|
|
745 (!(mode & CWHeight) || intended->height == w->core.height) )
|
|
746 return XtGeometryNo ;
|
|
747
|
|
748 #ifdef COMMENT
|
|
749 if( (!(mode & CWWidth) || intended->width >= preferred->width) &&
|
|
750 (!(mode & CWHeight) || intended->height >= preferred->height) )
|
|
751 return XtGeometryYes;
|
|
752 #endif /* COMMENT */
|
|
753
|
|
754 return XtGeometryAlmost;
|
|
755 }
|
|
756
|
|
757
|
|
758
|
|
759 /*
|
|
760 * Geometry Manager; called when a child wants to be resized.
|
|
761 */
|
|
762
|
|
763 static XtGeometryResult
|
|
764 TabsGeometryManager(Widget w, XtWidgetGeometry *req, XtWidgetGeometry *reply)
|
|
765 {
|
|
766 TabsWidget tw = (TabsWidget) XtParent(w);
|
|
767 Dimension s = SHADWID ;
|
|
768 TabsConstraints tab = (TabsConstraints)w->core.constraints;
|
|
769 XtGeometryResult result ;
|
|
770
|
|
771 /* Position request always denied */
|
|
772
|
|
773 if( ((req->request_mode & CWX) && req->x != w->core.x) ||
|
|
774 ((req->request_mode & CWY) && req->y != w->core.y) ||
|
|
775 !tab->tabs.resizable )
|
|
776 return XtGeometryNo ;
|
|
777
|
|
778 /* Make all three fields in the request valid */
|
|
779 if( !(req->request_mode & CWWidth) )
|
|
780 req->width = w->core.width;
|
|
781 if( !(req->request_mode & CWHeight) )
|
|
782 req->height = w->core.height;
|
|
783 if( !(req->request_mode & CWBorderWidth) )
|
|
784 req->border_width = w->core.border_width;
|
|
785
|
|
786 if( req->width == w->core.width &&
|
|
787 req->height == w->core.height &&
|
|
788 req->border_width == w->core.border_width )
|
|
789 return XtGeometryNo ;
|
|
790
|
|
791 /* updated cached preferred size of the child */
|
|
792 tab->tabs.bwid = req->border_width ;
|
|
793 tab->tabs.wid = req->width + req->border_width * 2 ;
|
|
794 tab->tabs.hgt = req->height + req->border_width * 2 ;
|
|
795 MaxChild(tw) ;
|
|
796
|
|
797
|
|
798 /* Size changes must see if the new size can be accommodated.
|
|
799 * The Tabs widget keeps all of its children the same
|
|
800 * size. A request to shrink will be accepted only if the
|
|
801 * new size is still big enough for all other children. A
|
|
802 * request to shrink that is not big enough for all children
|
|
803 * returns an "almost" response with the new proposed size.
|
|
804 * A request to grow will be accepted only if the Tabs parent can
|
|
805 * grow to accommodate.
|
|
806 *
|
|
807 * TODO:
|
|
808 * We could get fancy here and re-arrange the tabs if it is
|
|
809 * necessary to compromise with the parent, but we'll save that
|
|
810 * for another day.
|
|
811 */
|
|
812
|
|
813 if (req->request_mode & (CWWidth | CWHeight | CWBorderWidth))
|
|
814 {
|
|
815 Dimension rw,rh ; /* child's requested width, height */
|
|
816 Dimension cw,ch ; /* children's preferred size */
|
|
817 Dimension aw,ah ; /* available size we can give child */
|
|
818 Dimension th ; /* space used by tabs */
|
|
819 Dimension wid,hgt ; /* Tabs widget size */
|
|
820
|
|
821 rw = tab->tabs.wid ;
|
|
822 rh = tab->tabs.hgt ;
|
|
823
|
|
824 /* find out what the resulting preferred size would be */
|
|
825
|
|
826 #ifdef COMMENT
|
|
827 MaxChild(tw, &cw, &ch) ;
|
|
828 #endif /* COMMENT */
|
|
829 PreferredSize2(tw, tw->tabs.max_cw,tw->tabs.max_ch, &wid, &hgt) ;
|
|
830
|
|
831 /* Ask to be resized to accommodate. */
|
|
832
|
|
833 if( wid != tw->core.width || hgt != tw->core.height )
|
|
834 {
|
|
835 Dimension oldWid = tw->core.width, oldHgt = tw->core.height ;
|
|
836 XtWidgetGeometry myrequest, myreply ;
|
|
837
|
|
838 myrequest.width = wid ;
|
|
839 myrequest.height = hgt ;
|
|
840 myrequest.request_mode = CWWidth | CWHeight ;
|
|
841
|
|
842 /* If child is only querying, or if we're going to have to
|
|
843 * offer the child a compromise, then make this a query only.
|
|
844 */
|
|
845
|
|
846 if( (req->request_mode & XtCWQueryOnly) || rw < cw || rh < ch )
|
|
847 myrequest.request_mode |= XtCWQueryOnly ;
|
|
848
|
|
849 result = XtMakeGeometryRequest((Widget)tw, &myrequest, &myreply) ;
|
|
850
|
|
851 /* !$@# Box widget changes the core size even if QueryOnly
|
|
852 * is set. I'm convinced this is a bug. At any rate, to work
|
|
853 * around the bug, we need to restore the core size after every
|
|
854 * query geometry request. This is only partly effective,
|
|
855 * as there may be other boxes further up the tree.
|
|
856 */
|
|
857 if( myrequest.request_mode & XtCWQueryOnly ) {
|
|
858 tw->core.width = oldWid ;
|
|
859 tw->core.height = oldHgt ;
|
|
860 }
|
|
861
|
|
862 /* based on the parent's response, determine what the
|
|
863 * resulting Tabs widget size would be.
|
|
864 */
|
|
865
|
|
866 switch( result ) {
|
|
867 case XtGeometryYes:
|
|
868 case XtGeometryDone:
|
|
869 break ;
|
|
870
|
|
871 case XtGeometryNo:
|
|
872 wid = tw->core.width ;
|
|
873 hgt = tw->core.height ;
|
|
874 break ;
|
|
875
|
|
876 case XtGeometryAlmost:
|
|
877 wid = myreply.width ;
|
|
878 hgt = myreply.height ;
|
|
879 }
|
|
880 }
|
|
881
|
|
882 /* Within the constraints imposed by the parent, what is
|
|
883 * the max size we can give the child?
|
|
884 */
|
|
885 (void) TabLayout(tw, wid, hgt, &th, True) ;
|
|
886 aw = wid - 2*s ;
|
|
887 ah = hgt - th - 2*s ;
|
|
888
|
|
889 /* OK, make our decision. If requested size is >= max sibling
|
|
890 * preferred size, AND requested size <= available size, then
|
|
891 * we accept. Otherwise, we offer a compromise.
|
|
892 */
|
|
893
|
|
894 if( rw == aw && rh == ah )
|
|
895 {
|
|
896 /* Acceptable. If this wasn't a query, change *all* children
|
|
897 * to this size.
|
|
898 */
|
|
899 if( req->request_mode & XtCWQueryOnly )
|
|
900 return XtGeometryYes ;
|
|
901 else
|
|
902 {
|
|
903 Widget *childP = tw->composite.children ;
|
|
904 int i,bw ;
|
|
905 w->core.border_width = req->border_width ;
|
|
906 for(i=tw->tabs.displayChildren; --i >= 0; ++childP)
|
|
907 if( XtIsManaged(*childP) )
|
|
908 {
|
|
909 bw = (*childP)->core.border_width ;
|
|
910 XtConfigureWidget(*childP, s,tw->tabs.tab_total+s,
|
|
911 rw-2*bw, rh-2*bw, bw) ;
|
|
912 }
|
|
913 #ifdef COMMENT
|
|
914 /* TODO: under what conditions will we need to redraw? */
|
|
915 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
|
|
916 XtClass(tw)->core_class.expose((Widget)tw,NULL,NULL) ;
|
|
917 #endif /* COMMENT */
|
|
918 return XtGeometryDone ;
|
|
919 }
|
|
920 }
|
|
921
|
|
922 /* Cannot grant child's request. Describe what we *can* do
|
|
923 * and return counter-offer.
|
|
924 */
|
|
925 reply->width = aw - 2 * req->border_width ;
|
|
926 reply->height = ah - 2 * req->border_width ;
|
|
927 reply->border_width = req->border_width ;
|
|
928 reply->request_mode = CWWidth | CWHeight | CWBorderWidth ;
|
|
929 return XtGeometryAlmost ;
|
|
930 }
|
|
931
|
|
932 return XtGeometryYes ;
|
|
933 }
|
|
934
|
|
935
|
|
936
|
|
937
|
|
938 /* The number of children we manage has changed; recompute
|
|
939 * size from scratch.
|
|
940 */
|
|
941
|
|
942 static void
|
|
943 TabsChangeManaged(Widget w)
|
|
944 {
|
|
945 TabsWidget tw = (TabsWidget)w ;
|
|
946 Widget *childP = tw->composite.children ;
|
|
947 int i ;
|
|
948
|
|
949 if( tw->tabs.topWidget != NULL &&
|
|
950 ( !XtIsManaged(tw->tabs.topWidget) ||
|
|
951 tw->tabs.topWidget->core.being_destroyed ) )
|
|
952 tw->tabs.topWidget = NULL ;
|
|
953
|
|
954 GetPreferredSizes(tw) ;
|
|
955 MakeSizeRequest(tw) ;
|
|
956
|
|
957 XtClass(w)->core_class.resize(w) ;
|
|
958 if( XtIsRealized(w) )
|
|
959 {
|
|
960 Display *dpy = XtDisplay(w) ;
|
|
961 XClearWindow(dpy, XtWindow(w)) ;
|
|
962 XtClass(w)->core_class.expose(w,NULL,NULL) ;
|
|
963
|
|
964 /* make sure the top widget stays on top. This requires
|
|
965 * making sure that all new children are realized first.
|
|
966 */
|
|
967 if( tw->tabs.topWidget != NULL && XtIsRealized(tw->tabs.topWidget) )
|
|
968 {
|
|
969 for(i=tw->tabs.displayChildren; --i >= 0; ++childP)
|
|
970 if( !XtIsRealized(*childP) )
|
|
971 XtRealizeWidget(*childP) ;
|
|
972
|
|
973 XRaiseWindow(dpy, XtWindow(tw->tabs.topWidget)) ;
|
|
974 }
|
|
975 }
|
|
976
|
|
977 #ifdef NEED_MOTIF
|
|
978 /* Only top widget may receive input */
|
|
979
|
|
980 for(childP = tw->composite.children, i=tw->composite.num_children;
|
|
981 --i >= 0;
|
|
982 ++childP)
|
|
983 {
|
|
984 XtVaSetValues(*childP, XmNtraversalOn, False, 0) ;
|
|
985 }
|
|
986
|
|
987 if( tw->tabs.topWidget != NULL )
|
|
988 XtVaSetValues(tw->tabs.topWidget, XmNtraversalOn, True, 0) ;
|
|
989 #endif
|
|
990
|
|
991
|
|
992
|
|
993 }
|
|
994
|
|
995
|
|
996
|
|
997
|
|
998 /****************************************************************
|
|
999 *
|
|
1000 * Action Procedures
|
|
1001 *
|
|
1002 ****************************************************************/
|
|
1003
|
|
1004
|
|
1005 /* User clicks on a tab, figure out which one it was. */
|
|
1006
|
|
1007 /* ARGSUSED */
|
|
1008 static void
|
|
1009 TabsSelect(Widget w, XEvent *event, String *params, Cardinal *num_params)
|
|
1010 {
|
|
1011 TabsWidget tw = (TabsWidget) w ;
|
|
1012 Widget *childP ;
|
|
1013 Position x,y ;
|
|
1014 Dimension h = tw->tabs.tab_height ;
|
|
1015 int i ;
|
|
1016
|
|
1017 #ifdef NEED_MOTIF
|
|
1018 XmProcessTraversal (w, XmTRAVERSE_CURRENT) ;
|
|
1019 #endif
|
|
1020
|
|
1021 /* TODO: is there an Xmu function or something to do this instead? */
|
|
1022 switch( event->type ) {
|
|
1023 case ButtonPress:
|
|
1024 case ButtonRelease:
|
|
1025 x = event->xbutton.x ; y = event->xbutton.y ; break ;
|
|
1026 case KeyPress:
|
|
1027 case KeyRelease:
|
|
1028 x = event->xkey.x ; y = event->xkey.y ; break ;
|
|
1029 default:
|
|
1030 return ;
|
|
1031 }
|
|
1032
|
|
1033 /* TODO: determine which tab was clicked, if any. Set that
|
|
1034 * widget to be top of stacking order with XawTabsSetTop().
|
|
1035 */
|
|
1036 for(i=0, childP=tw->composite.children;
|
|
1037 i < tw->tabs.displayChildren;
|
|
1038 ++i, ++childP)
|
|
1039 if( XtIsManaged(*childP) )
|
|
1040 {
|
|
1041 TabsConstraints tab = (TabsConstraints)(*childP)->core.constraints;
|
|
1042 if( x > tab->tabs.x && x < tab->tabs.x + tab->tabs.width &&
|
|
1043 y > tab->tabs.y && y < tab->tabs.y + h )
|
|
1044 {
|
|
1045 if( *childP != tw->tabs.topWidget &&
|
|
1046 (XtIsSensitive(*childP) || tw->tabs.selectInsensitive) )
|
|
1047 XawTabsSetTop(*childP, True) ;
|
|
1048 break ;
|
|
1049 }
|
|
1050 }
|
|
1051 }
|
|
1052
|
|
1053
|
|
1054 /* User hits a key */
|
|
1055
|
|
1056 static void
|
|
1057 TabsPage(Widget w, XEvent *event, String *params, Cardinal *num_params)
|
|
1058 {
|
|
1059 TabsWidget tw = (TabsWidget) w ;
|
|
1060 Widget newtop ;
|
|
1061 Widget *childP ;
|
|
1062 int idx ;
|
|
1063 int i ;
|
|
1064 int nc = tw->composite.num_children ;
|
|
1065
|
|
1066 if( nc <= 0 )
|
|
1067 return ;
|
|
1068
|
|
1069 if( *num_params < 1 ) {
|
|
1070 XtAppWarning(XtWidgetToApplicationContext(w),
|
|
1071 "Tabs: page() action called with no arguments") ;
|
|
1072 return ;
|
|
1073 }
|
|
1074
|
|
1075 if( tw->tabs.topWidget == NULL )
|
|
1076 tw->tabs.topWidget = tw->composite.children[0] ;
|
|
1077
|
|
1078 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
|
|
1079 if( tw->tabs.topWidget == *childP )
|
|
1080 break ;
|
|
1081
|
|
1082 switch( params[0][0] ) {
|
|
1083 case 'u': /* up */
|
|
1084 case 'U':
|
|
1085 if( idx == 0 )
|
|
1086 idx = nc ;
|
|
1087 newtop = tw->composite.children[idx-1] ;
|
|
1088 break ;
|
|
1089
|
|
1090 case 'd': /* down */
|
|
1091 case 'D':
|
|
1092 if( ++idx >= nc )
|
|
1093 idx = 0 ;
|
|
1094 newtop = tw->composite.children[idx] ;
|
|
1095 break ;
|
|
1096
|
|
1097 case 'h':
|
|
1098 case 'H':
|
|
1099 newtop = tw->composite.children[0] ;
|
|
1100 break ;
|
|
1101
|
|
1102 case 'e':
|
|
1103 case 'E':
|
|
1104 newtop = tw->composite.children[nc-1] ;
|
|
1105 break ;
|
|
1106
|
|
1107 case 's': /* selected */
|
|
1108 case 'S':
|
|
1109 if( (newtop = tw->tabs.hilight) == NULL )
|
|
1110 return ;
|
|
1111 break ;
|
|
1112 }
|
|
1113
|
|
1114 XawTabsSetTop(newtop, True) ;
|
|
1115 }
|
|
1116
|
|
1117
|
|
1118 /* User hits up/down key */
|
|
1119
|
|
1120 static void
|
|
1121 TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
|
|
1122 {
|
|
1123 TabsWidget tw = (TabsWidget) w ;
|
|
1124 Widget newhl ;
|
|
1125 Widget *childP ;
|
|
1126 int idx ;
|
|
1127 int i ;
|
|
1128 int nc = tw->composite.num_children ;
|
|
1129
|
|
1130 if( nc <= 0 )
|
|
1131 return ;
|
|
1132
|
|
1133 if( *num_params < 1 )
|
|
1134 {
|
|
1135 if( tw->tabs.hilight != NULL )
|
|
1136 DrawHighlight(tw, tw->tabs.hilight, False) ;
|
|
1137 return ;
|
|
1138 }
|
|
1139
|
|
1140 if( tw->tabs.hilight == NULL )
|
|
1141 newhl = tw->composite.children[0] ;
|
|
1142
|
|
1143 else
|
|
1144 {
|
|
1145 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
|
|
1146 if( tw->tabs.hilight == *childP )
|
|
1147 break ;
|
|
1148
|
|
1149 switch( params[0][0] ) {
|
|
1150 case 'u': /* up */
|
|
1151 case 'U':
|
|
1152 if( idx == 0 )
|
|
1153 idx = nc ;
|
|
1154 newhl = tw->composite.children[idx-1] ;
|
|
1155 break ;
|
|
1156
|
|
1157 case 'd': /* down */
|
|
1158 case 'D':
|
|
1159 if( ++idx >= nc )
|
|
1160 idx = 0 ;
|
|
1161 newhl = tw->composite.children[idx] ;
|
|
1162 break ;
|
|
1163
|
|
1164 case 'h':
|
|
1165 case 'H':
|
|
1166 newhl = tw->composite.children[0] ;
|
|
1167 break ;
|
|
1168
|
|
1169 case 'e':
|
|
1170 case 'E':
|
|
1171 newhl = tw->composite.children[nc-1] ;
|
|
1172 break ;
|
|
1173 }
|
|
1174 }
|
|
1175
|
|
1176 XawTabsSetHighlight(w, newhl) ;
|
|
1177 }
|
|
1178
|
|
1179
|
|
1180
|
|
1181 static void
|
|
1182 TabsUnhighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
|
|
1183 {
|
|
1184 TabsWidget tw = (TabsWidget) w ;
|
|
1185 int nc = tw->composite.num_children ;
|
|
1186
|
|
1187 if( nc <= 0 )
|
|
1188 return ;
|
|
1189
|
|
1190 if( tw->tabs.hilight != NULL )
|
|
1191 DrawHighlight(tw, tw->tabs.hilight, True) ;
|
|
1192 }
|
|
1193
|
|
1194
|
|
1195
|
|
1196
|
|
1197
|
|
1198 /****************************************************************
|
|
1199 *
|
|
1200 * Public Procedures
|
|
1201 *
|
|
1202 ****************************************************************/
|
|
1203
|
|
1204
|
|
1205 /* Set the top tab, optionally call all callbacks. */
|
|
1206 void
|
|
1207 XawTabsSetTop(Widget w, Bool callCallbacks)
|
|
1208 {
|
|
1209 TabsWidget tw = (TabsWidget)w->core.parent ;
|
|
1210 TabsConstraints tab ;
|
|
1211 Widget oldtop = tw->tabs.topWidget ;
|
|
1212
|
|
1213 if( !XtIsSubclass(w->core.parent, tabsWidgetClass) )
|
|
1214 {
|
|
1215 char line[1024] ;
|
|
1216 sprintf(line, "XawTabsSetTop: widget \"%s\" is not the child of a tabs widget.", XtName(w)) ;
|
|
1217 XtAppWarning(XtWidgetToApplicationContext(w), line) ;
|
|
1218 return ;
|
|
1219 }
|
|
1220
|
|
1221 if( callCallbacks )
|
|
1222 XtCallCallbackList(w, tw->tabs.popdownCallbacks,
|
|
1223 (XtPointer)tw->tabs.topWidget) ;
|
|
1224
|
|
1225 if( !XtIsRealized(w) ) {
|
|
1226 tw->tabs.topWidget = w ;
|
|
1227 tw->tabs.needs_layout = True ;
|
|
1228 return ;
|
|
1229 }
|
|
1230
|
|
1231 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
|
|
1232 #ifdef NEED_MOTIF
|
|
1233 XtVaSetValues(oldtop, XmNtraversalOn, False, 0) ;
|
|
1234 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
|
|
1235 #endif
|
|
1236
|
|
1237 tab = (TabsConstraints) w->core.constraints ;
|
|
1238 if( tab->tabs.row == 0 )
|
|
1239 {
|
|
1240 /* Easy case; undraw current top, undraw new top, assign new
|
|
1241 * top, redraw all borders.
|
|
1242 * We *could* just erase and execute a full redraw, but I like to
|
|
1243 * reduce screen flicker.
|
|
1244 */
|
|
1245 UndrawTab(tw, oldtop) ; /* undraw old */
|
|
1246 DrawBorder(tw, oldtop, True) ;
|
|
1247 UndrawTab(tw, w) ; /* undraw new */
|
|
1248 DrawBorder(tw, w, True) ;
|
|
1249 tw->tabs.topWidget = w ;
|
|
1250 DrawTab(tw, oldtop, True) ; /* redraw old */
|
|
1251 DrawTab(tw, w, True) ; /* redraw new */
|
|
1252 DrawTabs(tw, False) ;
|
|
1253 }
|
|
1254 else
|
|
1255 {
|
|
1256 tw->tabs.topWidget = w ;
|
|
1257 TabsShuffleRows(tw) ;
|
|
1258 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
|
|
1259 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
|
|
1260 }
|
|
1261
|
|
1262 XawTabsSetHighlight((Widget)tw, w) ;
|
|
1263
|
|
1264 if( callCallbacks )
|
|
1265 XtCallCallbackList(w, tw->tabs.callbacks, (XtPointer)w) ;
|
|
1266 }
|
|
1267
|
|
1268
|
|
1269 /* Set the top tab, optionally call all callbacks. */
|
|
1270 void
|
|
1271 XawTabsSetHighlight(Widget t, Widget w)
|
|
1272 {
|
|
1273 TabsWidget tw = (TabsWidget)t ;
|
|
1274 TabsConstraints tab ;
|
|
1275 Widget oldtop = tw->tabs.topWidget ;
|
|
1276
|
|
1277 if( !XtIsSubclass(t, tabsWidgetClass) )
|
|
1278 return ;
|
|
1279
|
|
1280 if( XtIsRealized(t) && w != tw->tabs.hilight )
|
|
1281 {
|
|
1282 if( tw->tabs.hilight != NULL )
|
|
1283 DrawHighlight(tw, tw->tabs.hilight, True) ;
|
|
1284 if( w != NULL )
|
|
1285 DrawHighlight(tw, w, False) ;
|
|
1286 }
|
|
1287
|
|
1288 tw->tabs.hilight = w ;
|
|
1289 }
|
|
1290
|
|
1291
|
|
1292
|
|
1293
|
|
1294 /****************************************************************
|
|
1295 *
|
|
1296 * Private Procedures
|
|
1297 *
|
|
1298 ****************************************************************/
|
|
1299
|
|
1300
|
|
1301 static void
|
|
1302 TabsAllocGCs(TabsWidget tw)
|
|
1303 {
|
|
1304 TabsAllocFgGC(tw) ;
|
|
1305 TabsAllocGreyGC(tw) ;
|
|
1306 tw->tabs.backgroundGC = AllocBackgroundGC((Widget)tw, None) ;
|
|
1307 tw->tabs.topGC = AllocTopShadowGC((Widget)tw,
|
|
1308 tw->tabs.top_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
|
|
1309 tw->tabs.botGC = AllocBotShadowGC((Widget)tw,
|
|
1310 tw->tabs.bot_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
|
|
1311 }
|
|
1312
|
|
1313
|
|
1314 static void
|
|
1315 TabsFreeGCs(TabsWidget tw)
|
|
1316 {
|
|
1317 Widget w = (Widget) tw;
|
|
1318
|
|
1319 XtReleaseGC(w, tw->tabs.foregroundGC) ;
|
|
1320 XtReleaseGC(w, tw->tabs.greyGC) ;
|
|
1321 XtReleaseGC(w, tw->tabs.backgroundGC) ;
|
|
1322 XtReleaseGC(w, tw->tabs.topGC) ;
|
|
1323 XtReleaseGC(w, tw->tabs.botGC) ;
|
|
1324 #ifdef HAVE_XMU
|
|
1325 XmuReleaseStippledPixmap(XtScreen(w), tw->tabs.grey50) ;
|
|
1326 #endif
|
|
1327 }
|
|
1328
|
|
1329
|
|
1330
|
|
1331
|
|
1332
|
|
1333 /* Redraw entire Tabs widget */
|
|
1334
|
|
1335 static void
|
|
1336 DrawTabs(TabsWidget tw, Bool labels)
|
|
1337 {
|
|
1338 Widget *childP ;
|
|
1339 int i,j ;
|
|
1340 Dimension s = SHADWID ;
|
|
1341 Dimension th = tw->tabs.tab_height ;
|
|
1342 Position y ;
|
|
1343 TabsConstraints tab ;
|
|
1344
|
|
1345 if( !XtIsRealized((Widget)tw))
|
|
1346 return ;
|
|
1347
|
|
1348 /* draw tabs and frames by row except for the top tab, which
|
|
1349 * is drawn last. (This is inefficiently written, but should not
|
|
1350 * be too slow as long as there are not a lot of rows.)
|
|
1351 */
|
|
1352
|
|
1353 y = tw->tabs.numRows == 1 ? TABDELTA : 0 ;
|
|
1354 for(i=0; i<tw->tabs.numRows; ++i, y += th)
|
|
1355 {
|
|
1356 for( j=tw->tabs.displayChildren, childP=tw->composite.children;
|
|
1357 --j >= 0; ++childP )
|
|
1358 if( XtIsManaged(*childP) )
|
|
1359 {
|
|
1360 tab = (TabsConstraints)(*childP)->core.constraints;
|
|
1361 if( tab->tabs.row == i && *childP != tw->tabs.topWidget )
|
|
1362 DrawTab(tw, *childP, labels) ;
|
|
1363 }
|
|
1364 if( i != tw->tabs.numRows -1 )
|
|
1365 DrawTrim(tw, 0,y+th, tw->core.width, th+s, False,False) ;
|
|
1366 }
|
|
1367
|
|
1368 DrawFrame(tw) ;
|
|
1369
|
|
1370 /* and now the top tab */
|
|
1371 if( tw->tabs.topWidget != NULL )
|
|
1372 DrawTab(tw, tw->tabs.topWidget, labels) ;
|
|
1373 }
|
|
1374
|
|
1375
|
|
1376
|
|
1377 /* Draw one tab. Corners are rounded very slightly. */
|
|
1378
|
|
1379 static void
|
|
1380 DrawTab(TabsWidget tw, Widget child, Bool labels)
|
|
1381 {
|
|
1382 GC gc ;
|
|
1383 int x,y ;
|
|
1384
|
|
1385 if( !XtIsRealized((Widget)tw))
|
|
1386 return ;
|
|
1387
|
|
1388 DrawBorder(tw, child, False) ;
|
|
1389
|
|
1390 if( labels )
|
|
1391 {
|
|
1392 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1393 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1394 Window win = XtWindow((Widget)tw) ;
|
|
1395 String lbl = tab->tabs.label != NULL ?
|
|
1396 tab->tabs.label : XtName(child) ;
|
|
1397
|
|
1398 if( XtIsSensitive(child) )
|
|
1399 {
|
|
1400 gc = tw->tabs.foregroundGC ;
|
|
1401 XSetForeground(dpy, gc, tab->tabs.foreground) ;
|
|
1402 }
|
|
1403 else
|
|
1404 {
|
|
1405 /* grey pixel allocation deferred until now */
|
|
1406 if( !tab->tabs.greyAlloc )
|
|
1407 {
|
|
1408 if( tw->tabs.be_nice_to_cmap || tw->core.depth == 1 )
|
|
1409 tab->tabs.grey = tab->tabs.foreground ;
|
|
1410 else
|
|
1411 tab->tabs.grey = AllocGreyPixel((Widget)tw,
|
|
1412 tab->tabs.foreground,
|
|
1413 tw->core.background_pixel,
|
|
1414 tw->tabs.insensitive_contrast ) ;
|
|
1415 tab->tabs.greyAlloc = True ;
|
|
1416 }
|
|
1417 gc = tw->tabs.greyGC ;
|
|
1418 XSetForeground(dpy, gc, tab->tabs.grey) ;
|
|
1419 }
|
|
1420
|
|
1421 x = tab->tabs.x ;
|
|
1422 y = tab->tabs.y ;
|
|
1423 if( child == tw->tabs.topWidget )
|
|
1424 y -= TABLDELTA ;
|
|
1425
|
|
1426 if( tab->tabs.left_bitmap != None && tab->tabs.lbm_width > 0 )
|
|
1427 {
|
|
1428 if( tab->tabs.lbm_depth == 1 )
|
|
1429 XCopyPlane(dpy, tab->tabs.left_bitmap, win,gc,
|
|
1430 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
|
|
1431 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y, 1L) ;
|
|
1432 else
|
|
1433 XCopyArea(dpy, tab->tabs.left_bitmap, win,gc,
|
|
1434 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
|
|
1435 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y) ;
|
|
1436 }
|
|
1437
|
|
1438 if( lbl != NULL && tw->tabs.font != NULL )
|
|
1439 XDrawString(dpy,win,gc,
|
|
1440 x+tab->tabs.l_x, y+tab->tabs.l_y,
|
|
1441 lbl, (int)strlen(lbl)) ;
|
|
1442 }
|
|
1443
|
|
1444 if( child == tw->tabs.hilight )
|
|
1445 DrawHighlight(tw, child, False) ;
|
|
1446 }
|
|
1447
|
|
1448
|
|
1449 /* draw frame all the way around the child windows. */
|
|
1450
|
|
1451 static void
|
|
1452 DrawFrame(TabsWidget tw)
|
|
1453 {
|
|
1454 GC topgc = tw->tabs.topGC ;
|
|
1455 GC botgc = tw->tabs.botGC ;
|
|
1456 Dimension s = SHADWID ;
|
|
1457 Dimension ch = tw->tabs.child_height ;
|
|
1458 Draw3dBox((Widget)tw, 0,tw->tabs.tab_total,
|
|
1459 tw->core.width, ch+2*s, s, topgc, botgc) ;
|
|
1460 }
|
|
1461
|
|
1462
|
|
1463 /* draw trim around a tab or underneath a row of tabs */
|
|
1464
|
|
1465 static void
|
|
1466 DrawTrim(TabsWidget tw, /* widget */
|
|
1467 int x, /* upper-left corner */
|
|
1468 int y,
|
|
1469 int wid, /* total size */
|
|
1470 int hgt,
|
|
1471 Bool bottom, /* draw bottom? */
|
|
1472 Bool undraw) /* undraw all */
|
|
1473 {
|
|
1474 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1475 Window win = XtWindow((Widget)tw) ;
|
|
1476 GC bggc = tw->tabs.backgroundGC ;
|
|
1477 GC topgc = undraw ? bggc : tw->tabs.topGC ;
|
|
1478 GC botgc = undraw ? bggc : tw->tabs.botGC ;
|
|
1479 if( bottom )
|
|
1480 XDrawLine(dpy,win,bggc, x,y+hgt-1, x+wid-1,y+hgt-1) ; /* bottom */
|
|
1481 XDrawLine(dpy,win,topgc, x,y+2, x,y+hgt-2) ; /* left */
|
|
1482 XDrawPoint(dpy,win,topgc, x+1,y+1) ; /* corner */
|
|
1483 XDrawLine(dpy,win,topgc, x+2,y, x+wid-3,y) ; /* top */
|
|
1484 XDrawLine(dpy,win,botgc, x+wid-2,y+1, x+wid-2,y+hgt-2) ; /* right */
|
|
1485 XDrawLine(dpy,win,botgc, x+wid-1,y+2, x+wid-1,y+hgt-2) ; /* right */
|
|
1486 }
|
|
1487
|
|
1488
|
|
1489 /* Draw one tab border. */
|
|
1490
|
|
1491 static void
|
|
1492 DrawBorder(TabsWidget tw, Widget child, Bool undraw)
|
|
1493 {
|
|
1494 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1495 Position x = tab->tabs.x ;
|
|
1496 Position y = tab->tabs.y ;
|
|
1497 Dimension twid = tab->tabs.width ;
|
|
1498 Dimension thgt = tw->tabs.tab_height ;
|
|
1499
|
|
1500 /* top tab requires a little special attention; it overlaps
|
|
1501 * neighboring tabs slightly, so the background must be cleared
|
|
1502 * in the region of the overlap to partially erase those neighbors.
|
|
1503 * TODO: is this worth doing with regions instead?
|
|
1504 */
|
|
1505 if( child == tw->tabs.topWidget )
|
|
1506 {
|
|
1507 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1508 Window win = XtWindow((Widget)tw) ;
|
|
1509 GC bggc = tw->tabs.backgroundGC ;
|
|
1510 XRectangle rects[3] ;
|
|
1511 x -= TABDELTA ;
|
|
1512 y -= TABDELTA ;
|
|
1513 twid += TABDELTA*2 ;
|
|
1514 thgt += TABDELTA ;
|
|
1515 AddRect(0, x,y+1,twid,TABDELTA) ;
|
|
1516 AddRect(1, x+1,y,TABDELTA,thgt) ;
|
|
1517 AddRect(2, x+twid-TABDELTA-1,y,TABDELTA,thgt) ;
|
|
1518 XFillRectangles(dpy,win,bggc, rects, 3) ;
|
|
1519 }
|
|
1520
|
|
1521 DrawTrim(tw, x,y,twid,thgt+1, child == tw->tabs.topWidget, undraw) ;
|
|
1522 }
|
|
1523
|
|
1524
|
|
1525 /* Draw highlight around tab that has focus */
|
|
1526
|
|
1527 static void
|
|
1528 DrawHighlight(TabsWidget tw, Widget child, Bool undraw)
|
|
1529 {
|
|
1530 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1531 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1532 Window win = XtWindow((Widget)tw) ;
|
|
1533 GC gc ;
|
|
1534 Position x = tab->tabs.x ;
|
|
1535 Position y = tab->tabs.y ;
|
|
1536 Dimension wid = tab->tabs.width ;
|
|
1537 Dimension hgt = tw->tabs.tab_height ;
|
|
1538 XPoint points[6] ;
|
|
1539
|
|
1540 /* top tab does not have a highlight */
|
|
1541
|
|
1542 if( child == tw->tabs.topWidget )
|
|
1543 return ;
|
|
1544
|
|
1545 if( undraw )
|
|
1546 gc = tw->tabs.backgroundGC ;
|
|
1547
|
|
1548 else if( XtIsSensitive(child) )
|
|
1549 {
|
|
1550 gc = tw->tabs.foregroundGC ;
|
|
1551 XSetForeground(dpy, gc, tab->tabs.foreground) ;
|
|
1552 }
|
|
1553 else
|
|
1554 {
|
|
1555 gc = tw->tabs.greyGC ;
|
|
1556 XSetForeground(dpy, gc, tab->tabs.grey) ;
|
|
1557 }
|
|
1558
|
|
1559 points[0].x = x+1 ; points[0].y = y+hgt-1 ;
|
|
1560 points[1].x = x+1 ; points[1].y = y+2 ;
|
|
1561 points[2].x = x+2 ; points[2].y = y+1 ;
|
|
1562 points[3].x = x+wid-4 ; points[3].y = y+1 ;
|
|
1563 points[4].x = x+wid-3 ; points[4].y = y+2 ;
|
|
1564 points[5].x = x+wid-3 ; points[5].y = y+hgt-1 ;
|
|
1565
|
|
1566 XDrawLines(dpy,win,gc, points,6, CoordModeOrigin) ;
|
|
1567 }
|
|
1568
|
|
1569
|
|
1570 /* Undraw one tab interior */
|
|
1571
|
|
1572 static void
|
|
1573 UndrawTab(TabsWidget tw, Widget child)
|
|
1574 {
|
|
1575 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1576 Position x = tab->tabs.x ;
|
|
1577 Position y = tab->tabs.y ;
|
|
1578 Dimension twid = tab->tabs.width ;
|
|
1579 Dimension thgt = tw->tabs.tab_height ;
|
|
1580 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1581 Window win = XtWindow((Widget)tw) ;
|
|
1582 GC bggc = tw->tabs.backgroundGC ;
|
|
1583
|
|
1584 XFillRectangle(dpy,win,bggc, x,y, twid,thgt) ;
|
|
1585 }
|
|
1586
|
|
1587
|
|
1588
|
|
1589
|
|
1590
|
|
1591 /* GEOMETRY UTILITIES */
|
|
1592
|
|
1593
|
|
1594 /* Compute the size of one child's tab. Positions will be computed
|
|
1595 * elsewhere.
|
|
1596 *
|
|
1597 * height: font height + vertical_space*2 + shadowWid*2
|
|
1598 * width: string width + horizontal_space*2 + shadowWid*2
|
|
1599 *
|
|
1600 * All tabs are the same height, so that is computed elsewhere.
|
|
1601 */
|
|
1602
|
|
1603 static void
|
|
1604 TabWidth(Widget w)
|
|
1605 {
|
|
1606 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
|
|
1607 TabsWidget tw = (TabsWidget)XtParent(w) ;
|
|
1608 String lbl = tab->tabs.label != NULL ?
|
|
1609 tab->tabs.label : XtName(w) ;
|
|
1610 XFontStruct *font = tw->tabs.font ;
|
|
1611 int iw = tw->tabs.internalWidth ;
|
|
1612
|
|
1613 tab->tabs.width = iw + SHADWID*2 ;
|
|
1614 tab->tabs.l_x = tab->tabs.lbm_x = SHADWID + iw ;
|
|
1615
|
|
1616 if( tab->tabs.left_bitmap != None )
|
|
1617 {
|
|
1618 tab->tabs.width += tab->tabs.lbm_width + iw ;
|
|
1619 tab->tabs.l_x += tab->tabs.lbm_width + iw ;
|
|
1620 tab->tabs.lbm_y = (tw->tabs.tab_height - tab->tabs.lbm_height)/2 ;
|
|
1621 }
|
|
1622
|
|
1623 if( lbl != NULL && font != NULL )
|
|
1624 {
|
|
1625 tab->tabs.width += XTextWidth( font, lbl, (int)strlen(lbl) ) + iw ;
|
|
1626 tab->tabs.l_y = (tw->tabs.tab_height +
|
|
1627 tw->tabs.font->max_bounds.ascent -
|
|
1628 tw->tabs.font->max_bounds.descent)/2 ;
|
|
1629 }
|
|
1630 }
|
|
1631
|
|
1632
|
|
1633
|
|
1634 /* Lay out tabs to fit in given width. Compute x,y position and
|
|
1635 * row number for each tab. Return number of rows and total height
|
|
1636 * required by all tabs. If there is only one row, add TABDELTA
|
|
1637 * height to the total. Rows are assigned bottom to top.
|
|
1638 *
|
|
1639 * Tabs are indented from the edges by INDENT.
|
|
1640 *
|
|
1641 * TODO: if they require more than two rows and the total height:width
|
|
1642 * ratio is more than 2:1, then try something else.
|
|
1643 */
|
|
1644
|
|
1645 static int
|
|
1646 TabLayout(TabsWidget tw, int wid, int hgt, Dimension *reply_height, Bool query_only)
|
|
1647 {
|
|
1648 int i, row ;
|
|
1649 int num_children = tw->composite.num_children ;
|
|
1650 Widget *childP ;
|
|
1651 Dimension w ;
|
|
1652 Position x,y ;
|
|
1653 TabsConstraints tab ;
|
|
1654
|
|
1655 if (!query_only)
|
|
1656 tw->tabs.displayChildren = 0;
|
|
1657
|
|
1658 /* Algorithm: loop through children, assign X positions. If a tab
|
|
1659 * would extend beyond the right edge, start a new row. After all
|
|
1660 * rows are assigned, make a second pass and assign Y positions.
|
|
1661 */
|
|
1662
|
|
1663 if( num_children > 0 )
|
|
1664 {
|
|
1665 /* Loop through the tabs and see how much space they need. */
|
|
1666
|
|
1667 row = 0 ;
|
|
1668 x = INDENT ;
|
|
1669 y = 0 ;
|
|
1670 wid -= INDENT ;
|
|
1671 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
|
|
1672 if( XtIsManaged(*childP) )
|
|
1673 {
|
|
1674 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
1675 w = tab->tabs.width ;
|
|
1676 if( x + w > wid ) { /* new row */
|
|
1677 if (y + tw->tabs.tab_height > hgt)
|
|
1678 break;
|
|
1679 ++row ;
|
|
1680 x = INDENT ;
|
|
1681 y += tw->tabs.tab_height ;
|
|
1682 }
|
|
1683 if( !query_only ) {
|
|
1684 tab->tabs.x = x ;
|
|
1685 tab->tabs.y = y ;
|
|
1686 tab->tabs.row = row ;
|
|
1687 }
|
|
1688 x += w + SPACING ;
|
|
1689 if (!query_only)
|
|
1690 tw->tabs.displayChildren++;
|
|
1691 }
|
|
1692 /* If there was only one row, increse the height by TABDELTA */
|
|
1693 if( ++row == 1 )
|
|
1694 {
|
|
1695 y = TABDELTA ;
|
|
1696 if( !query_only )
|
|
1697 for(i=num_children, childP=tw->composite.children;
|
|
1698 --i >= 0 ; ++childP)
|
|
1699 if( XtIsManaged(*childP) )
|
|
1700 {
|
|
1701 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
1702 tab->tabs.y = y ;
|
|
1703 }
|
|
1704 }
|
|
1705 y += tw->tabs.tab_height ;
|
|
1706 }
|
|
1707 else
|
|
1708 row = y = 0 ;
|
|
1709
|
|
1710 if( !query_only ) {
|
|
1711 tw->tabs.tab_total = y ;
|
|
1712 tw->tabs.numRows = row ;
|
|
1713 }
|
|
1714
|
|
1715 if( reply_height != NULL )
|
|
1716 *reply_height = y ;
|
|
1717
|
|
1718 return row ;
|
|
1719 }
|
|
1720
|
|
1721
|
|
1722
|
|
1723 /* Find max preferred child size. Returned sizes include child
|
|
1724 * border widths. We only ever ask a child its preferred
|
|
1725 * size once. After that, the preferred size is updated only
|
|
1726 * if the child makes a geometry request.
|
|
1727 */
|
|
1728
|
|
1729 static void
|
|
1730 GetPreferredSizes(TabsWidget tw)
|
|
1731 {
|
|
1732 int i ;
|
|
1733 Widget *childP = tw->composite.children ;
|
|
1734 XtWidgetGeometry preferred ;
|
|
1735 TabsConstraints tab ;
|
|
1736 Dimension cw = 0, ch = 0 ;
|
|
1737
|
|
1738 for(i=tw->tabs.displayChildren; --i >= 0; ++childP)
|
|
1739 if( XtIsManaged(*childP) )
|
|
1740 {
|
|
1741 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
1742 if( !tab->tabs.queried ) {
|
|
1743 (void) XtQueryGeometry(*childP, NULL, &preferred) ;
|
|
1744 tab->tabs.bwid = preferred.border_width ;
|
|
1745 tab->tabs.wid = preferred.width + preferred.border_width * 2 ;
|
|
1746 tab->tabs.hgt = preferred.height + preferred.border_width * 2 ;
|
|
1747 tab->tabs.queried = True ;
|
|
1748 }
|
|
1749 cw = Max(cw, tab->tabs.wid ) ;
|
|
1750 ch = Max(ch, tab->tabs.hgt ) ;
|
|
1751 }
|
|
1752 tw->tabs.max_cw = cw ;
|
|
1753 tw->tabs.max_ch = ch ;
|
|
1754 }
|
|
1755
|
|
1756
|
|
1757
|
|
1758 /* Find max preferred child size. Returned sizes include child
|
|
1759 * border widths. */
|
|
1760
|
|
1761 static void
|
|
1762 MaxChild(TabsWidget tw)
|
|
1763 {
|
|
1764 Dimension cw,ch ; /* child width, height */
|
|
1765 int i ;
|
|
1766 Widget *childP = tw->composite.children ;
|
|
1767 TabsConstraints tab ;
|
|
1768
|
|
1769 cw = ch = 0 ;
|
|
1770
|
|
1771 for(i=tw->composite.num_children; --i >=0; ++childP)
|
|
1772 if( XtIsManaged(*childP) )
|
|
1773 {
|
|
1774 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
1775 cw = Max(cw, tab->tabs.wid ) ;
|
|
1776 ch = Max(ch, tab->tabs.hgt ) ;
|
|
1777 }
|
|
1778
|
|
1779 tw->tabs.max_cw = cw ;
|
|
1780 tw->tabs.max_ch = ch ;
|
|
1781 }
|
|
1782
|
|
1783
|
|
1784
|
|
1785 /* rotate row numbers to bring current widget to bottom row,
|
|
1786 * compute y positions for all tabs
|
|
1787 */
|
|
1788
|
|
1789 static void
|
|
1790 TabsShuffleRows(TabsWidget tw)
|
|
1791 {
|
|
1792 TabsConstraints tab ;
|
|
1793 int move ;
|
|
1794 int nrows ;
|
|
1795 Widget *childP ;
|
|
1796 Dimension th = tw->tabs.tab_height ;
|
|
1797 Position bottom ;
|
|
1798 int i ;
|
|
1799
|
|
1800 /* There must be a top widget. If not, assign one. */
|
|
1801 if( tw->tabs.topWidget == NULL && tw->composite.children != NULL )
|
|
1802 for(i=tw->composite.num_children, childP=tw->composite.children;
|
|
1803 --i >= 0;
|
|
1804 ++childP)
|
|
1805 if( XtIsManaged(*childP) ) {
|
|
1806 tw->tabs.topWidget = *childP ;
|
|
1807 break ;
|
|
1808 }
|
|
1809
|
|
1810 if( tw->tabs.topWidget != NULL )
|
|
1811 {
|
|
1812 nrows = tw->tabs.numRows ;
|
|
1813 assert( nrows > 0 ) ;
|
|
1814
|
|
1815 if( nrows > 1 )
|
|
1816 {
|
|
1817 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ;
|
|
1818 assert( tab != NULL ) ;
|
|
1819
|
|
1820 /* how far to move top row */
|
|
1821 move = nrows - tab->tabs.row ;
|
|
1822 bottom = tw->tabs.tab_total - th ;
|
|
1823
|
|
1824 for(i=tw->tabs.displayChildren, childP=tw->composite.children;
|
|
1825 --i >= 0;
|
|
1826 ++childP)
|
|
1827 if( XtIsManaged(*childP) )
|
|
1828 {
|
|
1829 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
1830 tab->tabs.row = (tab->tabs.row + move) % nrows ;
|
|
1831 tab->tabs.y = bottom - tab->tabs.row * th ;
|
|
1832 }
|
|
1833 }
|
|
1834 }
|
|
1835 }
|
|
1836
|
|
1837
|
|
1838 /* find preferred size. Ask children, find size of largest,
|
|
1839 * add room for tabs & return. This can get a little involved,
|
|
1840 * as we don't want to have too many rows of tabs; we may widen
|
|
1841 * the widget to reduce # of rows.
|
|
1842 */
|
|
1843
|
|
1844 static int
|
|
1845 PreferredSize(
|
|
1846 TabsWidget tw,
|
|
1847 Dimension *reply_width, /* total widget size */
|
|
1848 Dimension *reply_height,
|
|
1849 Dimension *reply_cw, /* child widget size */
|
|
1850 Dimension *reply_ch)
|
|
1851 {
|
|
1852 Dimension cw,ch ; /* child width, height */
|
|
1853 Dimension wid,hgt ;
|
|
1854 Dimension rwid,rhgt ;
|
|
1855 int nrow ;
|
|
1856
|
|
1857
|
|
1858 /* find max desired child height */
|
|
1859 #ifdef COMMENT
|
|
1860 MaxChild(tw, &cw, &ch) ;
|
|
1861 #endif /* COMMENT */
|
|
1862
|
|
1863 wid = cw = tw->tabs.max_cw ;
|
|
1864 hgt = ch = tw->tabs.max_ch ;
|
|
1865
|
|
1866 nrow = PreferredSize2(tw, wid,hgt, &rwid, &rhgt) ;
|
|
1867
|
|
1868 /* Check for absurd results (more than 2 rows, high aspect
|
|
1869 * ratio). Try wider size if needed.
|
|
1870 * TODO: make sure this terminates.
|
|
1871 */
|
|
1872
|
|
1873 if( nrow > 2 && rhgt > rwid )
|
|
1874 {
|
|
1875 Dimension w0, w1 ;
|
|
1876
|
|
1877 /* step 1: start doubling size until it's too big */
|
|
1878 do {
|
|
1879 w0 = wid ;
|
|
1880 wid = Max(wid*2, wid+20) ;
|
|
1881 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
|
|
1882 } while( nrow > 2 && rhgt > rwid ) ;
|
|
1883 w1 = wid ;
|
|
1884
|
|
1885 /* step 2: use Newton's method to find ideal size. Stop within
|
|
1886 * 8 pixels.
|
|
1887 */
|
|
1888 while( w1 > w0 + 8 )
|
|
1889 {
|
|
1890 wid = (w0+w1)/2 ;
|
|
1891 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
|
|
1892 if( nrow > 2 && rhgt > rwid )
|
|
1893 w0 = wid ;
|
|
1894 else
|
|
1895 w1 = wid ;
|
|
1896 }
|
|
1897 wid = w1 ;
|
|
1898 }
|
|
1899
|
|
1900 *reply_width = rwid ;
|
|
1901 *reply_height = rhgt ;
|
|
1902 if( reply_cw != NULL ) *reply_cw = cw ;
|
|
1903 if( reply_ch != NULL ) *reply_ch = ch ;
|
|
1904 return nrow ;
|
|
1905 }
|
|
1906
|
|
1907
|
|
1908 /* Find preferred size, given size of children. */
|
|
1909
|
|
1910 static int
|
|
1911 PreferredSize2(
|
|
1912 TabsWidget tw,
|
|
1913 int cw, /* child width, height */
|
|
1914 int ch,
|
|
1915 Dimension *reply_width, /* total widget size */
|
|
1916 Dimension *reply_height)
|
|
1917 {
|
|
1918 Dimension s = SHADWID ;
|
|
1919
|
|
1920 /* make room for shadow frame */
|
|
1921 cw += s*2 ;
|
|
1922 ch += s*2 ;
|
|
1923
|
|
1924 return PreferredSize3(tw, cw, ch, reply_width, reply_height) ;
|
|
1925 }
|
|
1926
|
|
1927
|
|
1928 /* Find preferred size, given size of children+shadow. */
|
|
1929
|
|
1930 static int
|
|
1931 PreferredSize3(
|
|
1932 TabsWidget tw,
|
|
1933 int wid, /* child width, height */
|
|
1934 int hgt,
|
|
1935 Dimension *reply_width, /* total widget size */
|
|
1936 Dimension *reply_height)
|
|
1937 {
|
|
1938 Dimension th ; /* space used by tabs */
|
|
1939 int nrows ;
|
|
1940
|
|
1941 if( tw->composite.num_children > 0 )
|
|
1942 nrows = TabLayout(tw, wid, hgt, &th, True) ;
|
|
1943 else {
|
|
1944 th = 0 ;
|
|
1945 nrows = 0 ;
|
|
1946 }
|
|
1947
|
|
1948 *reply_width = Max(wid, MIN_WID) ;
|
|
1949 *reply_height = Max(th+hgt, MIN_HGT) ;
|
|
1950
|
|
1951 return nrows ;
|
|
1952 }
|
|
1953
|
|
1954
|
|
1955 static void
|
|
1956 MakeSizeRequest(TabsWidget tw)
|
|
1957 {
|
|
1958 Widget w = (Widget)tw ;
|
|
1959 XtWidgetGeometry request, reply ;
|
|
1960 XtGeometryResult result ;
|
|
1961 Dimension cw,ch ;
|
|
1962
|
|
1963 request.request_mode = CWWidth | CWHeight ;
|
|
1964 PreferredSize(tw, &request.width, &request.height, &cw, &ch) ;
|
|
1965
|
|
1966 if( request.width == tw->core.width &&
|
|
1967 request.height == tw->core.height )
|
|
1968 return ;
|
|
1969
|
|
1970 result = XtMakeGeometryRequest(w, &request, &reply) ;
|
|
1971
|
|
1972 if( result == XtGeometryAlmost )
|
|
1973 {
|
|
1974 /* Bugger. Didn't get what we want, but were offered a
|
|
1975 * compromise. If the width was too small, recompute
|
|
1976 * based on the too-small width and try again.
|
|
1977 * If the height was too small, make a wild-ass guess
|
|
1978 * at a wider width and try again.
|
|
1979 */
|
|
1980
|
|
1981 if( reply.width < request.width && reply.height >= request.height )
|
|
1982 {
|
|
1983 Dimension s = SHADWID ;
|
|
1984 ch += s*2 ;
|
|
1985 PreferredSize3(tw, reply.width,ch, &request.width, &request.height);
|
|
1986 result = XtMakeGeometryRequest(w, &request, &reply) ;
|
|
1987 if( result == XtGeometryAlmost )
|
|
1988 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
|
|
1989 }
|
|
1990
|
|
1991 else
|
|
1992 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
|
|
1993 }
|
|
1994 }
|
|
1995
|
|
1996
|
|
1997 static void
|
|
1998 getBitmapInfo(TabsWidget tw, TabsConstraints tab)
|
|
1999 {
|
|
2000 Window root ;
|
|
2001 int x,y ;
|
|
2002 unsigned int bw ;
|
|
2003
|
|
2004 if( tab->tabs.left_bitmap == None ||
|
|
2005 !XGetGeometry(XtDisplay(tw), tab->tabs.left_bitmap, &root, &x, &y,
|
|
2006 &tab->tabs.lbm_width, &tab->tabs.lbm_height,
|
|
2007 &bw, &tab->tabs.lbm_depth) )
|
|
2008 tab->tabs.lbm_width = tab->tabs.lbm_height = 0 ;
|
|
2009 }
|
|
2010
|
|
2011
|
|
2012
|
|
2013
|
|
2014 /* Code copied & modified from Gcs.c. This version has dynamic
|
|
2015 * foreground.
|
|
2016 */
|
|
2017
|
|
2018 static void
|
|
2019 TabsAllocFgGC(TabsWidget tw)
|
|
2020 {
|
|
2021 Widget w = (Widget) tw;
|
|
2022 XGCValues values ;
|
|
2023
|
|
2024 values.background = tw->core.background_pixel ;
|
|
2025 values.font = tw->tabs.font->fid ;
|
|
2026 values.line_style = LineOnOffDash ;
|
|
2027 values.line_style = LineSolid ;
|
|
2028
|
|
2029 tw->tabs.foregroundGC =
|
|
2030 XtAllocateGC(w, w->core.depth,
|
|
2031 GCBackground|GCFont|GCLineStyle, &values,
|
|
2032 GCForeground,
|
|
2033 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
|
2034 GCDashList|GCArcMode) ;
|
|
2035 }
|
|
2036
|
|
2037 static void
|
|
2038 TabsAllocGreyGC(TabsWidget tw)
|
|
2039 {
|
|
2040 Widget w = (Widget) tw;
|
|
2041 XGCValues values ;
|
|
2042
|
|
2043 values.background = tw->core.background_pixel ;
|
|
2044 values.font = tw->tabs.font->fid ;
|
|
2045 #ifdef HAVE_XMU
|
|
2046 if( tw->tabs.be_nice_to_cmap || w->core.depth == 1)
|
|
2047 {
|
|
2048 values.fill_style = FillStippled ;
|
|
2049 tw->tabs.grey50 =
|
|
2050 values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1) ;
|
|
2051
|
|
2052 tw->tabs.greyGC =
|
|
2053 XtAllocateGC(w, w->core.depth,
|
|
2054 GCBackground|GCFont|GCStipple|GCFillStyle, &values,
|
|
2055 GCForeground,
|
|
2056 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
|
2057 GCDashList|GCArcMode) ;
|
|
2058 }
|
|
2059 else
|
|
2060 #endif
|
|
2061 {
|
|
2062 tw->tabs.greyGC =
|
|
2063 XtAllocateGC(w, w->core.depth,
|
|
2064 GCFont, &values,
|
|
2065 GCForeground,
|
|
2066 GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
|
2067 GCDashList|GCArcMode) ;
|
|
2068 }
|
|
2069 }
|