428
|
1 /* Tabs Widget for XEmacs.
|
|
2 Copyright (C) 1999 Edward A. Falk
|
442
|
3
|
428
|
4 This file is part of XEmacs.
|
442
|
5
|
428
|
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.
|
442
|
10
|
428
|
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.
|
442
|
15
|
428
|
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. */
|
442
|
20
|
428
|
21 /*
|
|
22 * Tabs.c - Index Tabs composite widget
|
|
23 *
|
|
24 * Author: Edward A. Falk
|
|
25 * falk@falconer.vip.best.com
|
|
26 *
|
|
27 * Date: July 29, 1997
|
|
28 *
|
|
29 *
|
|
30 * Overall layout of this widget is as follows:
|
|
31 *
|
|
32 * ________ ,---------. _________
|
|
33 * | label || Label || Label | \ tabs
|
|
34 * |________|| ||_________| /
|
|
35 * |+----------------------------+| \
|
|
36 * || || |
|
|
37 * || child widget window || > frame
|
|
38 * |+----------------------------+| |
|
|
39 * +------------------------------+ /
|
|
40 *
|
|
41 * The height of the tabs includes the shadow width, top and bottom
|
|
42 * margins, and the height of the text.
|
|
43 *
|
|
44 * The height of the frame includes the top and bottom shadow width and the
|
|
45 * size of the child widget window.
|
|
46 *
|
|
47 * The tabs overlap the frame and each other vertically by the shadow
|
|
48 * width, so that when the topmost tab is drawn, it obliterates part of
|
|
49 * the frame.
|
|
50 */
|
|
51
|
3094
|
52 /* Synched up with: Tabs.c 1.27.
|
|
53
|
|
54 This file contains essential XEmacs-related fixes to the original
|
|
55 version of the Tabs widget. Be VERY careful about syncing if you ever
|
|
56 update to a more recent version. In general this is probably now a
|
|
57 bad idea.
|
|
58
|
|
59 #### We need to check that various windows (the whole widget, or a single
|
|
60 tab) are of "reasonable" size, ie, we need to try for more sanity in the
|
|
61 geometry management routines.
|
|
62 */
|
|
63
|
434
|
64 /*
|
|
65 * TODO: min child height = tab height
|
428
|
66 */
|
|
67
|
|
68 #include <config.h>
|
|
69 #include <stdio.h>
|
|
70
|
|
71 #include <X11/Xlib.h>
|
|
72 #include <X11/IntrinsicP.h>
|
|
73 #include <X11/StringDefs.h>
|
448
|
74
|
3094
|
75 /* #### This may be risky, lwlib-internal.h redefines abort() */
|
|
76 #include "lwlib-fonts.h"
|
|
77 #include "lwlib-colors.h"
|
448
|
78 #include "lwlib-internal.h"
|
428
|
79 #include "../src/xmu.h"
|
|
80 #include "xlwtabsP.h"
|
|
81 #include "xlwgcs.h"
|
|
82
|
3094
|
83 #define XFT_USE_HEIGHT_NOT_ASCENT_DESCENT 0
|
|
84
|
|
85 /* #### These should probably be resources. */
|
428
|
86 #define MIN_WID 10
|
|
87 #define MIN_HGT 10
|
|
88 #define INDENT 3 /* tabs indented from edge by this much */
|
|
89 #define SPACING 0 /* distance between tabs */
|
|
90 #define SHADWID 1 /* default shadow width */
|
|
91 #define TABDELTA 2 /* top tab grows this many pixels */
|
|
92 #define TABLDELTA 2 /* top tab label offset this many pixels */
|
|
93
|
|
94
|
|
95 /****************************************************************
|
|
96 *
|
|
97 * IndexTabs Resources
|
|
98 *
|
|
99 ****************************************************************/
|
|
100
|
|
101 static char defaultTranslations[] = "\
|
|
102 <BtnUp>: select() \n\
|
|
103 <FocusIn>: highlight() \n\
|
|
104 <FocusOut>: unhighlight() \n\
|
|
105 <Key>Page_Up: page(up) \n\
|
|
106 <Key>KP_Page_Up: page(up) \n\
|
|
107 <Key>Prior: page(up) \n\
|
|
108 <Key>KP_Prior: page(up) \n\
|
|
109 <Key>Page_Down: page(down) \n\
|
|
110 <Key>KP_Page_Down: page(down) \n\
|
|
111 <Key>Next: page(down) \n\
|
|
112 <Key>KP_Next: page(down) \n\
|
|
113 <Key>Home: page(home) \n\
|
|
114 <Key>KP_Home: page(home) \n\
|
|
115 <Key>End: page(end) \n\
|
|
116 <Key>KP_End: page(end) \n\
|
|
117 <Key>Up: highlight(up) \n\
|
|
118 <Key>KP_Up: highlight(up) \n\
|
|
119 <Key>Down: highlight(down) \n\
|
|
120 <Key>KP_Down: highlight(down) \n\
|
|
121 <Key> : page(select) \n\
|
|
122 " ;
|
|
123
|
|
124 static char accelTable[] = " #augment\n\
|
|
125 <Key>Page_Up: page(up) \n\
|
|
126 <Key>KP_Page_Up: page(up) \n\
|
|
127 <Key>Prior: page(up) \n\
|
|
128 <Key>KP_Prior: page(up) \n\
|
|
129 <Key>Page_Down: page(down) \n\
|
|
130 <Key>KP_Page_Down: page(down) \n\
|
|
131 <Key>Next: page(down) \n\
|
|
132 <Key>KP_Next: page(down) \n\
|
|
133 <Key>Home: page(home) \n\
|
|
134 <Key>KP_Home: page(home) \n\
|
|
135 <Key>End: page(end) \n\
|
|
136 <Key>KP_End: page(end) \n\
|
|
137 <Key>Up: highlight(up) \n\
|
|
138 <Key>KP_Up: highlight(up) \n\
|
|
139 <Key>Down: highlight(down) \n\
|
|
140 <Key>KP_Down: highlight(down) \n\
|
|
141 <Key> : page(select) \n\
|
|
142 " ;
|
446
|
143 static XtAccelerators defaultAccelerators ; /* #### Never used */
|
428
|
144
|
|
145 #define offset(field) XtOffsetOf(TabsRec, tabs.field)
|
|
146 static XtResource resources[] = {
|
|
147
|
|
148 {XtNselectInsensitive, XtCSelectInsensitive, XtRBoolean, sizeof(Boolean),
|
|
149 offset(selectInsensitive), XtRImmediate, (XtPointer) True},
|
|
150 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
|
|
151 offset(font), XtRString, (XtPointer) XtDefaultFont},
|
3094
|
152 #ifdef USE_XFT_TABS
|
3397
|
153 /* #### Maybe use "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1" here?
|
|
154 or XtDefaultFont? */
|
|
155 {XtNfcFontName, XtCFcFontName, XtRString, sizeof(String),
|
3685
|
156 offset(fcFontName), XtRString, (XtPointer) NULL },
|
3397
|
157 /* #### This needs to be fixed to give a proper type and converter for
|
|
158 XftFonts. See also xlwmenu.c. */
|
3685
|
159 {XtNxftFont, XtCXftFont, XtRString, sizeof(String),
|
|
160 offset(xftFontName), XtRString, (XtPointer) "Helvetica-12" },
|
3094
|
161 #endif
|
428
|
162 {XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension),
|
|
163 offset(internalWidth), XtRImmediate, (XtPointer)4 },
|
|
164 {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension),
|
|
165 offset(internalHeight), XtRImmediate, (XtPointer)4 },
|
|
166 {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
|
|
167 XtOffsetOf(RectObjRec,rectangle.border_width), XtRImmediate, (XtPointer)0},
|
|
168 {XtNtopWidget, XtCTopWidget, XtRWidget, sizeof(Widget),
|
|
169 offset(topWidget), XtRImmediate, NULL},
|
|
170 {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
|
|
171 offset(callbacks), XtRCallback, NULL},
|
|
172 {XtNpopdownCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
|
|
173 offset(popdownCallbacks), XtRCallback, NULL},
|
|
174 {XtNbeNiceToColormap, XtCBeNiceToColormap, XtRBoolean, sizeof(Boolean),
|
|
175 offset(be_nice_to_cmap), XtRImmediate, (XtPointer) True},
|
|
176 {XtNtopShadowContrast, XtCTopShadowContrast, XtRInt, sizeof(int),
|
|
177 offset(top_shadow_contrast), XtRImmediate, (XtPointer) 20},
|
|
178 {XtNbottomShadowContrast, XtCBottomShadowContrast, XtRInt, sizeof(int),
|
|
179 offset(bot_shadow_contrast), XtRImmediate, (XtPointer) 40},
|
|
180 {XtNinsensitiveContrast, XtCInsensitiveContrast, XtRInt, sizeof(int),
|
|
181 offset(insensitive_contrast), XtRImmediate, (XtPointer) 33},
|
|
182 {XtNaccelerators, XtCAccelerators, XtRAcceleratorTable,sizeof(XtTranslations),
|
|
183 XtOffsetOf(TabsRec,core.accelerators), XtRString, accelTable},
|
|
184 };
|
|
185 #undef offset
|
|
186
|
|
187
|
|
188
|
|
189 /* constraint resources */
|
|
190
|
|
191 #define offset(field) XtOffsetOf(TabsConstraintsRec, tabs.field)
|
|
192 static XtResource tabsConstraintResources[] = {
|
|
193 {XtNtabLabel, XtCLabel, XtRString, sizeof(String),
|
|
194 offset(label), XtRString, NULL},
|
|
195 {XtNtabLeftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap),
|
|
196 offset(left_bitmap), XtRImmediate, None},
|
|
197 {XtNtabForeground, XtCForeground, XtRPixel, sizeof(Pixel),
|
|
198 offset(foreground), XtRString, (XtPointer) XtDefaultForeground},
|
|
199 {XtNresizable, XtCResizable, XtRBoolean, sizeof(Boolean),
|
|
200 offset(resizable), XtRImmediate, (XtPointer) True},
|
|
201 } ;
|
|
202 #undef offset
|
|
203
|
|
204
|
|
205
|
|
206
|
|
207 #if !NeedFunctionPrototypes
|
|
208
|
|
209 /* FORWARD REFERENCES: */
|
|
210
|
|
211 /* member functions */
|
|
212
|
|
213 static void TabsClassInit();
|
|
214 static void TabsInit();
|
|
215 static void TabsResize();
|
|
216 static void TabsExpose();
|
|
217 static void TabsDestroy();
|
|
218 static void TabsRealize();
|
|
219 static Boolean TabsSetValues();
|
434
|
220 static Boolean TabsAcceptFocus();
|
428
|
221 static XtGeometryResult TabsQueryGeometry();
|
|
222 static XtGeometryResult TabsGeometryManager();
|
|
223 static void TabsChangeManaged();
|
|
224 static void TabsConstraintInitialize() ;
|
|
225 static Boolean TabsConstraintSetValues() ;
|
|
226
|
|
227 /* action procs */
|
|
228
|
|
229 static void TabsSelect() ;
|
|
230 static void TabsPage() ;
|
|
231 static void TabsHighlight() ;
|
|
232 static void TabsUnhighlight() ;
|
|
233
|
|
234 /* internal privates */
|
|
235
|
|
236 static void TabsAllocGCs() ; /* get rendering GCs */
|
|
237 static void TabsFreeGCs() ; /* return rendering GCs */
|
|
238 static void DrawTabs() ; /* draw all tabs */
|
|
239 static void DrawTab() ; /* draw one index tab */
|
|
240 static void DrawFrame() ; /* draw frame around contents */
|
|
241 static void DrawTrim() ; /* draw trim around a tab */
|
|
242 static void DrawBorder() ; /* draw border */
|
|
243 static void DrawHighlight() ; /* draw highlight */
|
|
244 static void UndrawTab() ; /* undraw interior of a tab */
|
|
245 static void TabWidth() ; /* recompute tab size */
|
|
246 static void GetPreferredSizes() ; /* query all children for their sizes */
|
|
247 static void MaxChild() ; /* find max preferred child size */
|
|
248 static int PreferredSize() ; /* compute preferred size */
|
|
249 static int PreferredSize2() ; /* compute preferred size */
|
|
250 static int PreferredSize3() ; /* compute preferred size */
|
|
251 static void MakeSizeRequest() ; /* try to change size */
|
|
252 static void getBitmapInfo() ;
|
|
253 static int TabLayout() ; /* lay out tabs */
|
|
254 static void TabsShuffleRows() ; /* bring current tab to bottom row */
|
|
255
|
|
256 static void TabsAllocFgGC() ;
|
|
257 static void TabsAllocGreyGC() ;
|
|
258
|
|
259 #else
|
|
260
|
|
261 static void TabsClassInit(void) ;
|
3025
|
262 static void TabsInit( Widget req, Widget new_, ArgList, Cardinal *nargs) ;
|
428
|
263 static void TabsConstraintInitialize(Widget, Widget, ArgList, Cardinal *) ;
|
|
264 static void TabsRealize(Widget, Mask *, XSetWindowAttributes *) ;
|
|
265 static void TabsDestroy( Widget w) ;
|
|
266 static void TabsResize( Widget w) ;
|
|
267 static void TabsExpose( Widget w, XEvent *event, Region region) ;
|
|
268 static Boolean TabsSetValues(Widget, Widget, Widget, ArgList, Cardinal *) ;
|
434
|
269 static Boolean TabsAcceptFocus(Widget, Time *);
|
428
|
270 static Boolean TabsConstraintSetValues(Widget, Widget, Widget,
|
|
271 ArgList, Cardinal *) ;
|
|
272 static XtGeometryResult TabsQueryGeometry(Widget,
|
|
273 XtWidgetGeometry *, XtWidgetGeometry *) ;
|
|
274 static XtGeometryResult TabsGeometryManager(Widget,
|
|
275 XtWidgetGeometry *, XtWidgetGeometry *) ;
|
|
276 static void TabsChangeManaged( Widget w) ;
|
|
277
|
|
278 static void TabsSelect(Widget, XEvent *, String *, Cardinal *) ;
|
|
279 static void TabsPage(Widget, XEvent *, String *, Cardinal *) ;
|
|
280 static void TabsHighlight(Widget, XEvent *, String *, Cardinal *) ;
|
|
281 static void TabsUnhighlight(Widget, XEvent *, String *, Cardinal *) ;
|
|
282
|
|
283 static void DrawTabs( TabsWidget tw, Bool labels) ;
|
|
284 static void DrawTab( TabsWidget tw, Widget child, Bool labels) ;
|
|
285 static void DrawFrame( TabsWidget tw) ;
|
|
286 static void DrawTrim( TabsWidget, int x, int y,
|
|
287 int wid, int hgt, Bool bottom, Bool undraw) ;
|
|
288 static void DrawBorder( TabsWidget tw, Widget child, Bool undraw) ;
|
|
289 static void DrawHighlight( TabsWidget tw, Widget child, Bool undraw) ;
|
|
290 static void UndrawTab( TabsWidget tw, Widget child) ;
|
|
291
|
|
292 static void TabWidth( Widget w) ;
|
448
|
293 static int TabLayout( TabsWidget, Dimension wid, Dimension hgt, Dimension *r_hgt,
|
428
|
294 Bool query_only) ;
|
|
295 static void GetPreferredSizes(TabsWidget) ;
|
434
|
296 static void MaxChild(TabsWidget, Widget except, Dimension, Dimension) ;
|
428
|
297 static void TabsShuffleRows( TabsWidget tw) ;
|
|
298 static int PreferredSize( TabsWidget,
|
|
299 Dimension *reply_width, Dimension *reply_height,
|
|
300 Dimension *reply_cw, Dimension *reply_ch) ;
|
448
|
301 static int PreferredSize2( TabsWidget, Dimension cw, Dimension ch,
|
428
|
302 Dimension *rw, Dimension *rh) ;
|
448
|
303 static int PreferredSize3( TabsWidget, Dimension wid, Dimension hgt,
|
428
|
304 Dimension *rw, Dimension *rh) ;
|
|
305 static void MakeSizeRequest(TabsWidget) ;
|
|
306
|
|
307 static void TabsAllocGCs(TabsWidget) ;
|
|
308 static void TabsFreeGCs(TabsWidget) ;
|
|
309 static void getBitmapInfo( TabsWidget tw, TabsConstraints tab) ;
|
|
310 static void TabsAllocFgGC( TabsWidget tw) ;
|
|
311 static void TabsAllocGreyGC( TabsWidget tw) ;
|
|
312
|
|
313 #endif
|
|
314
|
|
315 #define AddRect(i,xx,yy,w,h) \
|
|
316 do{rects[(i)].x=(xx); rects[i].y=(yy); \
|
|
317 rects[i].width=(w); rects[i].height=(h);}while(0)
|
|
318
|
|
319 static XtActionsRec actionsList[] =
|
|
320 {
|
|
321 {"select", TabsSelect},
|
|
322 {"page", TabsPage},
|
|
323 {"highlight", TabsHighlight},
|
|
324 {"unhighlight", TabsUnhighlight},
|
|
325 } ;
|
|
326
|
|
327
|
|
328 /****************************************************************
|
|
329 *
|
|
330 * Full class record constant
|
|
331 *
|
|
332 ****************************************************************/
|
|
333
|
|
334 #ifndef NEED_MOTIF
|
|
335 #define SuperClass (&constraintClassRec)
|
|
336 #else
|
|
337 #define SuperClass (&xmManagerClassRec)
|
|
338 #endif
|
|
339
|
|
340 TabsClassRec tabsClassRec = {
|
|
341 {
|
|
342 /* core_class fields */
|
|
343 /* superclass */ (WidgetClass) SuperClass,
|
|
344 /* class_name */ "Tabs",
|
|
345 /* widget_size */ sizeof(TabsRec),
|
|
346 /* class_initialize */ TabsClassInit,
|
|
347 /* class_part_init */ NULL, /* TODO? */
|
|
348 /* class_inited */ FALSE,
|
|
349 /* initialize */ TabsInit,
|
|
350 /* initialize_hook */ NULL,
|
|
351 /* realize */ TabsRealize,
|
|
352 /* actions */ actionsList,
|
|
353 /* num_actions */ XtNumber(actionsList),
|
|
354 /* resources */ resources,
|
|
355 /* num_resources */ XtNumber(resources),
|
|
356 /* xrm_class */ NULLQUARK,
|
|
357 /* compress_motion */ TRUE,
|
434
|
358 #if XtSpecificationRelease < 6
|
|
359 /* compress_exposure */ XtExposeCompressMaximal,
|
|
360 #else
|
|
361 /* compress_exposure */ XtExposeCompressMaximal|XtExposeNoRegion,
|
|
362 #endif
|
428
|
363 /* compress_enterleave*/ TRUE,
|
434
|
364 /* visible_interest */ TRUE,
|
428
|
365 /* destroy */ TabsDestroy,
|
|
366 /* resize */ TabsResize,
|
|
367 /* expose */ TabsExpose,
|
|
368 /* set_values */ TabsSetValues,
|
|
369 /* set_values_hook */ NULL,
|
|
370 /* set_values_almost */ XtInheritSetValuesAlmost,
|
|
371 /* get_values_hook */ NULL,
|
434
|
372 /* accept_focus */ TabsAcceptFocus,
|
428
|
373 /* version */ XtVersion,
|
|
374 /* callback_private */ NULL,
|
|
375 /* tm_table */ defaultTranslations,
|
|
376 /* query_geometry */ TabsQueryGeometry,
|
|
377 /* display_accelerator*/ XtInheritDisplayAccelerator,
|
|
378 /* extension */ NULL
|
|
379 },
|
|
380 {
|
|
381 /* composite_class fields */
|
|
382 /* geometry_manager */ TabsGeometryManager,
|
|
383 /* change_managed */ TabsChangeManaged,
|
|
384 /* insert_child */ XtInheritInsertChild, /* TODO? */
|
|
385 /* delete_child */ XtInheritDeleteChild, /* TODO? */
|
|
386 /* extension */ NULL
|
|
387 },
|
|
388 {
|
|
389 /* constraint_class fields */
|
|
390 /* subresources */ tabsConstraintResources,
|
|
391 /* subresource_count */ XtNumber(tabsConstraintResources),
|
|
392 /* constraint_size */ sizeof(TabsConstraintsRec),
|
|
393 /* initialize */ TabsConstraintInitialize,
|
|
394 /* destroy */ NULL,
|
|
395 /* set_values */ TabsConstraintSetValues,
|
|
396 /* extension */ NULL,
|
|
397 },
|
|
398 #ifdef NEED_MOTIF
|
|
399 /* Manager Class fields */
|
|
400 {
|
|
401 /* translations */ NULL,
|
|
402 /* syn_resources */ NULL,
|
|
403 /* num_syn_resources */ 0,
|
|
404 /* syn_constraint_resources */ NULL,
|
|
405 /* num_syn_constraint_resources */ 0,
|
|
406 /* parent_process */ XmInheritParentProcess,
|
|
407 /* extension */ NULL
|
|
408 },
|
|
409 #endif
|
|
410 {
|
|
411 /* Tabs class fields */
|
|
412 /* extension */ NULL,
|
|
413 }
|
|
414 };
|
|
415
|
|
416 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec;
|
|
417
|
446
|
418 #define TabsNumChildren(tw) (((TabsWidget)tw)->composite.num_children)
|
|
419 #define TabVisible(tab) \
|
|
420 (XtIsManaged(tab) && \
|
|
421 ((TabsConstraints)((tab)->core.constraints))->tabs.visible)
|
428
|
422
|
|
423
|
3094
|
424
|
|
425 static int debug_tabs = 0; /* increase for more verbosity */
|
|
426
|
|
427 #ifdef USE_XFT_TABS
|
|
428 /* #### duplicated from xlwmenu.c -- CLEAN THIS SHIT UP!
|
|
429 Undeclared so define at top. */
|
|
430 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
|
|
431 ? ((unsigned long) (x)) : ((unsigned long) (y)))
|
|
432
|
|
433 static int
|
|
434 x_xft_text_width (Display *dpy, XftFont *xft_font, FcChar8 *run, int len)
|
|
435 {
|
|
436 static XGlyphInfo glyphinfo; /* #### static? */
|
|
437
|
|
438 XftTextExtents8 (dpy,
|
|
439 xft_font,
|
|
440 run, len, &glyphinfo);
|
|
441 return glyphinfo.xOff;
|
|
442 }
|
|
443 #endif
|
|
444
|
428
|
445 /****************************************************************
|
|
446 *
|
|
447 * Member Procedures
|
|
448 *
|
|
449 ****************************************************************/
|
|
450
|
|
451 static void
|
|
452 TabsClassInit(void)
|
|
453 {
|
|
454 defaultAccelerators = XtParseAcceleratorTable(accelTable) ;
|
|
455 /* TODO: register converter for labels? */
|
|
456 }
|
|
457
|
|
458
|
|
459
|
|
460 /* Init a newly created tabs widget. Compute height of tabs
|
|
461 * and optionally compute size of widget. */
|
|
462
|
|
463 /* ARGSUSED */
|
|
464
|
|
465 static void
|
3025
|
466 TabsInit(Widget request, Widget new_, ArgList UNUSED (args),
|
2286
|
467 Cardinal *UNUSED (num_args))
|
428
|
468 {
|
3025
|
469 TabsWidget newTw = (TabsWidget)new_;
|
428
|
470
|
|
471 newTw->tabs.numRows = 0 ;
|
446
|
472 newTw->tabs.realRows = 0;
|
428
|
473
|
|
474 GetPreferredSizes(newTw) ;
|
|
475
|
|
476 /* height is easy, it's the same for all tabs:
|
|
477 * TODO: font height + height of tallest bitmap.
|
|
478 */
|
|
479 newTw->tabs.tab_height = 2 * newTw->tabs.internalHeight + SHADWID ;
|
|
480
|
3094
|
481 #ifdef USE_XFT_TABS
|
3685
|
482 /* #### kludge for name change */
|
|
483 if (!newTw->tabs.fcFontName)
|
|
484 newTw->tabs.fcFontName = newTw->tabs.xftFontName;
|
3094
|
485 /* must get font here
|
3685
|
486 #### to do this right, we should add a new Xt Resource type +
|
|
487 conversion function */
|
3094
|
488 newTw->tabs.renderFont =
|
|
489 xft_open_font_by_name (XtDisplay ((Widget) newTw),
|
3397
|
490 newTw->tabs.fcFontName);
|
3094
|
491 if (newTw->tabs.renderFont != NULL)
|
|
492 #if XFT_USE_HEIGHT_NOT_ASCENT_DESCENT
|
|
493 newTw->tabs.tab_height += newTw->tabs.renderFont->height;
|
|
494 #else
|
|
495 newTw->tabs.tab_height += newTw->tabs.renderFont->ascent +
|
|
496 newTw->tabs.renderFont->descent;
|
|
497 #endif /* XFT_USE_HEIGHT_NOT_ASCENT_DESCENT */
|
|
498 #else /* ! USE_XFT_TABS */
|
|
499 if (newTw->tabs.font != NULL)
|
428
|
500 newTw->tabs.tab_height += newTw->tabs.font->max_bounds.ascent +
|
3094
|
501 newTw->tabs.font->max_bounds.descent;
|
|
502 #endif /* ! USE_XFT_TABS */
|
428
|
503
|
|
504 /* if size not explicitly set, set it to our preferred size now. */
|
|
505
|
|
506 if( request->core.width == 0 || request->core.height == 0 )
|
|
507 {
|
|
508 Dimension w,h ;
|
|
509 PreferredSize(newTw, &w, &h, NULL,NULL) ;
|
3025
|
510 if( request->core.width == 0 ) new_->core.width = w ;
|
|
511 if( request->core.height == 0 ) new_->core.height = h ;
|
|
512 XtClass(new_)->core_class.resize(new_) ;
|
428
|
513 }
|
|
514
|
|
515 /* defer GC allocation, etc., until Realize() time. */
|
|
516 newTw->tabs.foregroundGC =
|
|
517 newTw->tabs.backgroundGC =
|
|
518 newTw->tabs.greyGC =
|
|
519 newTw->tabs.topGC =
|
|
520 newTw->tabs.botGC = None ;
|
|
521
|
|
522 newTw->tabs.grey50 = None ;
|
|
523
|
|
524 newTw->tabs.needs_layout = False ;
|
434
|
525
|
428
|
526 newTw->tabs.hilight = NULL ;
|
|
527
|
|
528 #ifdef NEED_MOTIF
|
|
529 newTw->manager.navigation_type = XmTAB_GROUP ;
|
|
530 newTw->manager.traversal_on = True ;
|
|
531 #endif
|
|
532 }
|
|
533
|
|
534
|
|
535 /* Init the constraint part of a new tab child. Compute the
|
|
536 * size of the tab.
|
|
537 */
|
|
538 /* ARGSUSED */
|
|
539 static void
|
3025
|
540 TabsConstraintInitialize(Widget UNUSED (request), Widget new_,
|
2286
|
541 ArgList UNUSED (args), Cardinal *UNUSED (num_args))
|
428
|
542 {
|
3025
|
543 TabsConstraints tab = (TabsConstraints) new_->core.constraints ;
|
428
|
544 tab->tabs.greyAlloc = False ; /* defer allocation of pixel */
|
446
|
545 tab->tabs.visible = False ;
|
428
|
546
|
3025
|
547 getBitmapInfo((TabsWidget)XtParent(new_), tab) ;
|
|
548 TabWidth(new_) ;
|
428
|
549 }
|
|
550
|
|
551
|
|
552
|
|
553 /* Called when tabs widget first realized. Create the window
|
|
554 * and allocate the GCs
|
|
555 */
|
|
556
|
|
557 static void
|
|
558 TabsRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
|
|
559 {
|
|
560 TabsWidget tw = (TabsWidget) w;
|
|
561
|
|
562 attributes->bit_gravity = NorthWestGravity;
|
|
563 *valueMask |= CWBitGravity;
|
|
564
|
|
565 SuperClass->core_class.realize(w, valueMask, attributes);
|
|
566
|
|
567 TabsAllocGCs(tw) ;
|
|
568 }
|
|
569
|
|
570
|
|
571
|
|
572 static void
|
|
573 TabsDestroy(Widget w)
|
|
574 {
|
|
575 TabsFreeGCs((TabsWidget)w) ;
|
|
576 }
|
|
577
|
|
578
|
|
579 /* Parent has resized us. This will require that the tabs be
|
|
580 * laid out again.
|
|
581 */
|
|
582
|
|
583 static void
|
|
584 TabsResize(Widget w)
|
|
585 {
|
|
586 TabsWidget tw = (TabsWidget) w;
|
|
587 int i ;
|
|
588 int num_children = tw->composite.num_children ;
|
|
589 Widget *childP ;
|
2286
|
590 /* TabsConstraints tab ; */ /* #### unused */
|
428
|
591 Dimension cw,ch,bw ;
|
|
592
|
|
593 /* Our size has now been dictated by the parent. Lay out the
|
|
594 * tabs, lay out the frame, lay out the children. Remember
|
|
595 * that the tabs overlap each other and the frame by shadowWidth.
|
|
596 * Also, the top tab is larger than the others, so if there's only
|
|
597 * one row, the widget must be made taller to accommodate this.
|
|
598 *
|
|
599 * Once the tabs are laid out, if there is more than one
|
|
600 * row, we may need to shuffle the rows to bring the top tab
|
|
601 * to the bottom row.
|
|
602 */
|
|
603
|
434
|
604 tw->tabs.needs_layout = False ;
|
|
605
|
428
|
606 if( num_children > 0 && tw->composite.children != NULL )
|
|
607 {
|
|
608 /* Loop through the tabs and assign rows & x positions */
|
|
609 (void) TabLayout(tw, tw->core.width, tw->core.height, NULL, False) ;
|
446
|
610 num_children = TabsNumChildren (tw);
|
428
|
611
|
|
612 /* assign a top widget, bring it to bottom row. */
|
|
613 TabsShuffleRows(tw) ;
|
|
614
|
|
615 /* now assign child positions & sizes. Positions are all the
|
|
616 * same: just inside the frame. Sizes are also all the same.
|
|
617 */
|
|
618
|
|
619 tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ;
|
|
620 tw->tabs.child_height = ch =
|
448
|
621 tw->core.height < (tw->tabs.tab_total + 2 * SHADWID) ? 0 :
|
|
622 tw->core.height - tw->tabs.tab_total - 2 * SHADWID ;
|
428
|
623
|
|
624 for(i=0, childP=tw->composite.children;
|
434
|
625 i < num_children;
|
428
|
626 ++i, ++childP)
|
448
|
627 if( XtIsManaged(*childP) )
|
428
|
628 {
|
2286
|
629 /* tab = (TabsConstraints) (*childP)->core.constraints ; */
|
434
|
630 bw = (*childP)->core.border_width ;
|
448
|
631 /* Don't do anything if we can't see any of the child. */
|
|
632 if (ch >= bw*2 && ch > 0 && cw >= bw*2 && cw > 0)
|
|
633 XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID,
|
|
634 cw-bw*2,ch-bw*2, bw) ;
|
428
|
635 }
|
434
|
636 if( XtIsRealized(w) ) {
|
|
637 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
|
|
638 /* should not be necessary to explicitly repaint after a
|
|
639 * resize, but XEmacs folks tell me it is.
|
|
640 */
|
|
641 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
|
|
642 }
|
428
|
643 }
|
|
644 } /* Resize */
|
|
645
|
|
646
|
|
647
|
|
648 /* Redraw entire Tabs widget */
|
|
649
|
|
650 /* ARGSUSED */
|
|
651 static void
|
2286
|
652 TabsExpose(Widget w, XEvent *UNUSED (event), Region UNUSED (region))
|
428
|
653 {
|
|
654 TabsWidget tw = (TabsWidget) w;
|
|
655
|
|
656 if( tw->tabs.needs_layout )
|
|
657 XtClass(w)->core_class.resize(w) ;
|
|
658
|
|
659 DrawTabs(tw, True) ;
|
|
660 }
|
|
661
|
|
662
|
|
663 /* Called when any Tabs widget resources are changed. */
|
|
664
|
|
665 /* ARGSUSED */
|
|
666 static Boolean
|
3025
|
667 TabsSetValues(Widget current, Widget UNUSED (request), Widget new_,
|
2286
|
668 ArgList UNUSED (args), Cardinal *UNUSED (num_args))
|
428
|
669 {
|
430
|
670 TabsWidget curtw = (TabsWidget) current ;
|
3025
|
671 TabsWidget tw = (TabsWidget) new_ ;
|
430
|
672 Boolean needRedraw = False ;
|
|
673 Widget *childP ;
|
|
674 int i ;
|
428
|
675
|
3094
|
676 if(
|
|
677 #ifdef USE_XFT_TABS
|
|
678 tw->tabs.renderFont != curtw->tabs.renderFont ||
|
|
679 #else
|
|
680 tw->tabs.font != curtw->tabs.font ||
|
|
681 #endif
|
|
682 tw->tabs.internalWidth != curtw->tabs.internalWidth ||
|
|
683 tw->tabs.internalHeight != curtw->tabs.internalHeight)
|
430
|
684 {
|
3094
|
685 tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID;
|
428
|
686
|
3094
|
687 #ifdef USE_XFT_TABS
|
|
688 if (tw->tabs.renderFont != NULL)
|
|
689 #if XFT_USE_HEIGHT_NOT_ASCENT_DESCENT
|
|
690 tw->tabs.tab_height += tw->tabs.renderFont->height;
|
|
691 #else
|
|
692 tw->tabs.tab_height += tw->tabs.renderFont->ascent +
|
|
693 tw->tabs.renderFont->descent;
|
|
694 #endif /* XFT_USE_HEIGHT_NOT_ASCENT_DESCENT */
|
|
695 #else /* ! USE_XFT_TABS */
|
|
696 if (tw->tabs.font != NULL)
|
430
|
697 tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
|
3094
|
698 tw->tabs.font->max_bounds.descent;
|
|
699 #endif /* ! USE_XFT_TABS */
|
428
|
700
|
430
|
701 /* Tab size has changed. Resize all tabs and request a new size */
|
|
702 for(i=0, childP=tw->composite.children;
|
647
|
703 i < (int) tw->composite.num_children;
|
430
|
704 ++i, ++childP)
|
|
705 if( XtIsManaged(*childP) )
|
|
706 TabWidth(*childP) ;
|
|
707 PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
|
|
708 needRedraw = True ;
|
|
709 tw->tabs.needs_layout = True ;
|
|
710 }
|
428
|
711
|
430
|
712 /* TODO: if any color changes, need to recompute GCs and redraw */
|
428
|
713
|
430
|
714 if( tw->core.background_pixel != curtw->core.background_pixel ||
|
432
|
715 tw->core.background_pixmap != curtw->core.background_pixmap ||
|
3094
|
716 #ifdef USE_XFT_TABS
|
|
717 tw->tabs.renderFont != curtw->tabs.renderFont
|
|
718 #else
|
|
719 tw->tabs.font != curtw->tabs.font
|
|
720 #endif
|
|
721 )
|
3025
|
722 if( XtIsRealized(new_) )
|
430
|
723 {
|
|
724 TabsFreeGCs(tw) ;
|
|
725 TabsAllocGCs(tw) ;
|
|
726 needRedraw = True ;
|
|
727 }
|
428
|
728
|
430
|
729 if( tw->core.sensitive != curtw->core.sensitive )
|
|
730 needRedraw = True ;
|
428
|
731
|
430
|
732 /* If top widget changes, need to change stacking order, redraw tabs.
|
|
733 * Window system will handle the redraws.
|
|
734 */
|
428
|
735
|
442
|
736 if( tw->tabs.topWidget != curtw->tabs.topWidget )
|
432
|
737 {
|
430
|
738 if( XtIsRealized(tw->tabs.topWidget) )
|
|
739 {
|
|
740 Widget w = tw->tabs.topWidget ;
|
|
741 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
|
428
|
742
|
430
|
743 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
|
428
|
744 #ifdef NEED_MOTIF
|
430
|
745 XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
|
|
746 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
|
428
|
747 #endif
|
|
748
|
647
|
749 if( tab->tabs.row != (int) tw->tabs.numRows-1 )
|
430
|
750 TabsShuffleRows(tw) ;
|
428
|
751
|
430
|
752 needRedraw = True ;
|
|
753 }
|
|
754 else
|
|
755 tw->tabs.needs_layout = True ;
|
432
|
756 }
|
428
|
757
|
430
|
758 return needRedraw ;
|
428
|
759 }
|
|
760
|
|
761
|
|
762 /* Called when any child constraint resources change. */
|
|
763
|
|
764 /* ARGSUSED */
|
|
765 static Boolean
|
3025
|
766 TabsConstraintSetValues(Widget current, Widget UNUSED (request), Widget new_,
|
2286
|
767 ArgList UNUSED (args), Cardinal *UNUSED (num_args))
|
428
|
768 {
|
3025
|
769 TabsWidget tw = (TabsWidget) XtParent(new_) ;
|
428
|
770 TabsConstraints ctab = (TabsConstraints) current->core.constraints ;
|
3025
|
771 TabsConstraints tab = (TabsConstraints) new_->core.constraints ;
|
428
|
772
|
|
773
|
|
774 /* if label changes, need to re-layout the entire widget */
|
|
775 /* if foreground changes, need to redraw tab label */
|
|
776
|
|
777 /* TODO: only need resize of new bitmap has different dimensions
|
|
778 * from old bitmap.
|
|
779 */
|
|
780
|
|
781 if( tab->tabs.label != ctab->tabs.label || /* Tab size has changed. */
|
|
782 tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
|
|
783 {
|
3025
|
784 TabWidth(new_) ;
|
428
|
785 tw->tabs.needs_layout = True ;
|
|
786
|
|
787 if( tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
|
|
788 getBitmapInfo(tw, tab) ;
|
|
789
|
|
790 /* If there are no subclass ConstraintSetValues procedures remaining
|
|
791 * to be invoked, and if the preferred size has changed, ask
|
|
792 * for a resize.
|
|
793 */
|
|
794 if( XtClass((Widget)tw) == tabsWidgetClass )
|
|
795 MakeSizeRequest(tw) ;
|
|
796 }
|
|
797
|
|
798
|
|
799 /* The child widget itself never needs a redisplay, but the parent
|
|
800 * Tabs widget might.
|
|
801 */
|
|
802
|
3025
|
803 if( XtIsRealized(new_) )
|
428
|
804 {
|
|
805 if( tw->tabs.needs_layout ) {
|
|
806 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
|
|
807 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
|
|
808 }
|
|
809
|
|
810 else if( tab->tabs.foreground != ctab->tabs.foreground )
|
3025
|
811 DrawTab(tw, new_, True) ;
|
428
|
812 }
|
|
813
|
|
814 return False ;
|
|
815 }
|
|
816
|
|
817
|
434
|
818 static Boolean
|
2286
|
819 TabsAcceptFocus(Widget w, Time *UNUSED (t))
|
434
|
820 {
|
|
821 if( !w->core.being_destroyed && XtIsRealized(w) &&
|
|
822 XtIsSensitive(w) && XtIsManaged(w) && w->core.visible )
|
|
823 {
|
|
824 Widget p ;
|
|
825 for(p = XtParent(w); !XtIsShell(p); p = XtParent(p)) ;
|
|
826 XtSetKeyboardFocus(p,w) ;
|
|
827 return True ;
|
|
828 }
|
|
829 else
|
|
830 return False ;
|
|
831 }
|
|
832
|
|
833
|
428
|
834
|
|
835 /*
|
3094
|
836 * Return status, with preferred size in PREFERRED.
|
|
837 *
|
|
838 * According to the X Toolkit Intrinsics manual
|
|
839 * XtGeometryYes = accept INTENDED without change
|
|
840 * XtGeometryNo = request to stay _exactly_ the same
|
|
841 * XtGeometryAlmost = suggest PREFERRED as a compromise
|
|
842 * and the PREFERRED argument must be filled in completely (ie, any fields
|
|
843 * whose bits are set in the request_mode mask must correspond to the
|
|
844 * preferred geometry, which must be consistent with the return value).
|
|
845 *
|
|
846 * Assuming horizontal orientation, in XEmacs, we should always accept if
|
|
847 * the width is more than we need. There's no problem if there are only a
|
|
848 * couple of tabs packed to the left. OTOH there's probably something wrong
|
|
849 * if we're offered a height more than 1.5x or 2x the preferred height.
|
|
850 * (#### Do tab controls do vertical?)
|
428
|
851 */
|
|
852
|
3094
|
853 /* compute the height above which we complain */
|
|
854 #define TAB_HEIGHT_TOLERANCE(x) (2*x)
|
|
855
|
428
|
856 static XtGeometryResult
|
3094
|
857 TabsQueryGeometry (Widget w,
|
|
858 XtWidgetGeometry *intended,
|
|
859 XtWidgetGeometry *preferred) /* RETURN */
|
428
|
860 {
|
3094
|
861 TabsWidget tw = (TabsWidget) w;
|
|
862 XtGeometryMask mode = intended->request_mode;
|
|
863
|
|
864 preferred->request_mode = CWWidth | CWHeight;
|
|
865 PreferredSize (tw, &preferred->width, &preferred->height, NULL, NULL);
|
428
|
866
|
3094
|
867 /* If width is big enough, accept it. */
|
|
868 if ((mode & CWWidth) && intended->width >= preferred->width)
|
|
869 preferred->width = intended->width;
|
428
|
870
|
3094
|
871 /* If height is within range, accept it.
|
|
872 #### If too tall, we could offer a compromise at TAB_HEIGHT_TOLERANCE.
|
|
873 Should we? */
|
|
874 if ((mode & CWHeight) && intended->height >= preferred->height
|
|
875 && intended->height <= TAB_HEIGHT_TOLERANCE (preferred->height))
|
|
876 preferred->height = intended->height;
|
428
|
877
|
3094
|
878 /* Compute return value. */
|
|
879 if (preferred->width == ((mode & CWWidth) ? intended->width
|
|
880 : w->core.width)
|
|
881 && preferred->height == ((mode & CWHeight) ? intended->height
|
|
882 : w->core.height))
|
428
|
883 return XtGeometryYes;
|
3094
|
884 else if (preferred->width == w->core.width
|
|
885 && preferred->height == w->core.height)
|
|
886 return XtGeometryNo;
|
|
887 else
|
|
888 return XtGeometryAlmost;
|
428
|
889 }
|
|
890
|
|
891
|
|
892
|
|
893 /*
|
3094
|
894 * Geometry Manager; called when TAB (a child) wants to be resized.
|
|
895 *
|
|
896 * According to the X Toolkit Intrinsics manual
|
|
897 * XtGeometryDone = accept REQUEST and do it (#### check this)
|
|
898 * XtGeometryYes = accept REQUEST without change
|
|
899 * XtGeometryNo = refuse REQUEST (ie, stay _exactly_ the same)
|
|
900 * XtGeometryAlmost = suggest REPLY as a compromise
|
428
|
901 */
|
|
902
|
|
903 static XtGeometryResult
|
3094
|
904 TabsGeometryManager (Widget tab,
|
|
905 XtWidgetGeometry *request,
|
|
906 XtWidgetGeometry *reply) /* RETURN */
|
428
|
907 {
|
3094
|
908 TabsWidget control = (TabsWidget) XtParent(tab);
|
|
909 Dimension s = SHADWID;
|
|
910 TabsConstraints constraint = (TabsConstraints) tab->core.constraints;
|
|
911 XtGeometryResult result, best_offer = XtGeometryYes;
|
|
912 Dimension rw, rh;
|
|
913
|
|
914 static int debug_count = 0;
|
|
915 static int debug_mask = 1;
|
|
916
|
|
917 /* Position request cannot be satisfied, so if tabs are not resizable,
|
|
918 no nontrivial request can be satisfied: return XGeometryNo. */
|
|
919 if (!constraint->tabs.resizable)
|
|
920 return XtGeometryNo;
|
|
921
|
|
922 fprintf (stderr, "Urk! label is resizable!\n");
|
428
|
923
|
3094
|
924 /* Assume we will refuse these; toggle iff we accept them.
|
|
925 Reply won't specify any fields not in the request. */
|
|
926 reply->request_mode = request->request_mode;
|
|
927 reply->x = tab->core.x;
|
|
928 reply->y = tab->core.y;
|
428
|
929
|
3094
|
930 /* If a position request would result in a change, best offer is
|
|
931 XtGeometryAlmost. Otherwise toggle reply->request_mode. */
|
|
932 if ((request->request_mode & CWX) && request->x != tab->core.x)
|
|
933 best_offer = XtGeometryAlmost;
|
|
934 else
|
|
935 reply->request_mode &= ~CWX;
|
|
936 if ((request->request_mode & CWY) && request->y != tab->core.y)
|
|
937 best_offer = XtGeometryAlmost;
|
|
938 else
|
|
939 reply->request_mode &= ~CWY;
|
428
|
940
|
3094
|
941 /* Make all three fields in the reply valid */
|
|
942 reply->width = (request->request_mode & CWWidth)
|
|
943 ? request->width : tab->core.width;
|
|
944 reply->height = (request->request_mode & CWHeight)
|
|
945 ? request->height : tab->core.height;
|
|
946 reply->border_width = (request->request_mode & CWBorderWidth)
|
|
947 ? request->border_width : tab->core.border_width;
|
|
948
|
|
949 /* check if we can already offer a compromise */
|
|
950 if (best_offer == XtGeometryAlmost &&
|
|
951 reply->width == tab->core.width &&
|
|
952 reply->height == tab->core.height &&
|
|
953 reply->border_width == tab->core.border_width)
|
|
954 {
|
|
955 reply->request_mode &= ~(CWWidth | CWHeight | CWBorderWidth);
|
|
956 return best_offer;
|
|
957 }
|
428
|
958
|
3094
|
959 #ifndef DONT_DEBUG_REQUESTS
|
|
960 #define DBG_REQUEST_PRINT(name,field,size) \
|
|
961 do { \
|
|
962 if (reply->field > size) \
|
|
963 { \
|
|
964 if (++debug_count == debug_mask) \
|
|
965 { \
|
|
966 debug_mask <<= 1; \
|
|
967 fprintf (stderr, "ridiculous %s request #%d: %d > %d\n", \
|
|
968 name, debug_count, reply->field, size); \
|
|
969 } \
|
|
970 reply->field = tab->core.field; \
|
|
971 } \
|
|
972 } while (0)
|
428
|
973
|
3094
|
974 DBG_REQUEST_PRINT ("width",width,1024);
|
|
975 DBG_REQUEST_PRINT ("height",height,768);
|
|
976 DBG_REQUEST_PRINT ("border_width",border_width,30);
|
|
977 #undef DBG_REQUEST_PRINT
|
|
978 #endif
|
|
979
|
|
980 rw = reply->width + 2 * reply->border_width;
|
|
981 rh = reply->height + 2 * reply->border_width;
|
434
|
982
|
|
983 /* find out how big the children want to be now */
|
3094
|
984 MaxChild (control, tab, rw, rh);
|
428
|
985
|
|
986
|
|
987 /* Size changes must see if the new size can be accommodated.
|
3094
|
988 * The Tabs widget keeps all of its children the same height, but
|
|
989 * widths may vary.
|
|
990 * A request to shrink will be accepted only if the
|
428
|
991 * new size is still big enough for all other children. A
|
|
992 * request to shrink that is not big enough for all children
|
434
|
993 * returns an "almost" response with the new proposed size
|
|
994 * or a "no" response if unable to shrink at all.
|
|
995 *
|
3094
|
996 * A request to grow will be accepted only if the Tabs control can
|
428
|
997 * grow to accommodate.
|
|
998 *
|
|
999 * TODO:
|
|
1000 * We could get fancy here and re-arrange the tabs if it is
|
|
1001 * necessary to compromise with the parent, but we'll save that
|
|
1002 * for another day.
|
|
1003 */
|
|
1004
|
3094
|
1005 if (request->request_mode & (CWWidth | CWHeight | CWBorderWidth))
|
428
|
1006 {
|
|
1007 Dimension cw,ch ; /* children's preferred size */
|
|
1008 Dimension aw,ah ; /* available size we can give child */
|
|
1009 Dimension th ; /* space used by tabs */
|
|
1010 Dimension wid,hgt ; /* Tabs widget size */
|
3094
|
1011 int check_nrows;
|
428
|
1012
|
3094
|
1013 cw = control->tabs.max_cw ;
|
|
1014 ch = control->tabs.max_ch ;
|
428
|
1015
|
434
|
1016 /* find out what *my* resulting preferred size would be */
|
3094
|
1017 /* #### this whole API is wrong; what should happen is
|
|
1018 1. app should hint as to #rows and/or aspect ratio
|
|
1019 2. tab control should attempt to layout in current space
|
|
1020 3. if not all tabs fit, should request resize to achieve
|
|
1021 layout hints
|
|
1022 Probably can and should cache preferred size in widget, with
|
|
1023 cache cleared when labels or core size changes. */
|
|
1024 PreferredSize2(control, cw, ch, &wid, &hgt) ;
|
434
|
1025
|
|
1026 /* Would my size change? If so, ask to be resized. */
|
428
|
1027
|
3094
|
1028 if (wid != control->core.width || hgt != control->core.height)
|
428
|
1029 {
|
3094
|
1030 Dimension oldWid = control->core.width,
|
|
1031 oldHgt = control->core.height;
|
428
|
1032 XtWidgetGeometry myrequest, myreply ;
|
|
1033
|
|
1034 myrequest.width = wid ;
|
|
1035 myrequest.height = hgt ;
|
|
1036 myrequest.request_mode = CWWidth | CWHeight ;
|
448
|
1037
|
|
1038 assert (wid > 0 && hgt > 0);
|
428
|
1039 /* If child is only querying, or if we're going to have to
|
|
1040 * offer the child a compromise, then make this a query only.
|
|
1041 */
|
|
1042
|
3094
|
1043 if ((request->request_mode & XtCWQueryOnly) || rw < cw || rh < ch)
|
|
1044 myrequest.request_mode |= XtCWQueryOnly;
|
428
|
1045
|
3094
|
1046 result = XtMakeGeometryRequest ((Widget) control,
|
|
1047 &myrequest, &myreply);
|
428
|
1048
|
434
|
1049 /* !$@# Athena Box widget changes the core size even if QueryOnly
|
428
|
1050 * is set. I'm convinced this is a bug. At any rate, to work
|
|
1051 * around the bug, we need to restore the core size after every
|
|
1052 * query geometry request. This is only partly effective,
|
|
1053 * as there may be other boxes further up the tree.
|
|
1054 */
|
3094
|
1055 if (myrequest.request_mode & XtCWQueryOnly) {
|
|
1056 control->core.width = oldWid;
|
|
1057 control->core.height = oldHgt;
|
428
|
1058 }
|
|
1059
|
|
1060 /* based on the parent's response, determine what the
|
|
1061 * resulting Tabs widget size would be.
|
|
1062 */
|
|
1063
|
3094
|
1064 switch (result) {
|
428
|
1065 case XtGeometryYes:
|
|
1066 case XtGeometryDone:
|
3094
|
1067 control->tabs.needs_layout = True;
|
|
1068 break;
|
428
|
1069
|
|
1070 case XtGeometryNo:
|
3094
|
1071 wid = control->core.width;
|
|
1072 hgt = control->core.height;
|
|
1073 break;
|
428
|
1074
|
|
1075 case XtGeometryAlmost:
|
3094
|
1076 wid = myreply.width;
|
|
1077 hgt = myreply.height;
|
|
1078 control->tabs.needs_layout = True;
|
|
1079 break;
|
428
|
1080 }
|
|
1081 }
|
|
1082
|
|
1083 /* Within the constraints imposed by the parent, what is
|
|
1084 * the max size we can give the child?
|
|
1085 */
|
3094
|
1086 check_nrows = TabLayout (control, wid, hgt, &th, True);
|
|
1087 aw = wid - 2*s;
|
|
1088 if (check_nrows == 1)
|
|
1089 {
|
|
1090 ah = hgt - th - 2*s;
|
|
1091 }
|
|
1092 else
|
|
1093 {
|
|
1094 /* this rarely gets triggered, but when it does it seems to
|
|
1095 get triggered forever after */
|
|
1096 int n = control->composite.num_children;
|
|
1097 ah = control->tabs.tab_height;
|
3397
|
1098 if (debug_tabs > 1)
|
3094
|
1099 fprintf (stderr, "Kludging around %d != 1 rows,"
|
|
1100 " #children = %d, total height %d, using %d.\n",
|
|
1101 check_nrows, n, th, ah);
|
|
1102 }
|
428
|
1103
|
|
1104 /* OK, make our decision. If requested size is >= max sibling
|
|
1105 * preferred size, AND requested size <= available size, then
|
|
1106 * we accept. Otherwise, we offer a compromise.
|
|
1107 */
|
|
1108
|
3094
|
1109 if (rw == aw && rh == ah)
|
428
|
1110 {
|
|
1111 /* Acceptable. If this wasn't a query, change *all* children
|
|
1112 * to this size.
|
|
1113 */
|
3094
|
1114 if (request->request_mode & XtCWQueryOnly)
|
|
1115 {
|
|
1116 control->tabs.needs_layout = False;
|
|
1117 return XtGeometryYes ;
|
|
1118 }
|
428
|
1119 else
|
|
1120 {
|
3094
|
1121 Widget *childP = control->composite.children;
|
|
1122 int i, bw;
|
|
1123 tab->core.border_width = request->border_width;
|
|
1124 for (i = TabsNumChildren (control); --i >= 0; ++childP)
|
|
1125 if (TabVisible (*childP))
|
428
|
1126 {
|
3094
|
1127 bw = (*childP)->core.border_width;
|
|
1128 XtConfigureWidget (*childP, s, control->tabs.tab_total+s,
|
|
1129 rw-2*bw, rh-2*bw, bw);
|
428
|
1130 }
|
|
1131 #ifdef COMMENT
|
|
1132 /* TODO: under what conditions will we need to redraw? */
|
3094
|
1133 XClearWindow (XtDisplay ((Widget) control),
|
|
1134 XtWindow ((Widget) control));
|
|
1135 XtClass (control)->core_class.expose ((Widget)control,
|
|
1136 NULL, NULL);
|
428
|
1137 #endif /* COMMENT */
|
3094
|
1138 return XtGeometryDone;
|
428
|
1139 }
|
|
1140 }
|
|
1141
|
|
1142 /* Cannot grant child's request. Describe what we *can* do
|
|
1143 * and return counter-offer.
|
|
1144 */
|
3094
|
1145 control->tabs.needs_layout = False;
|
|
1146 reply->width = aw - 2 * request->border_width ;
|
|
1147 reply->height = ah - 2 * request->border_width ;
|
|
1148 reply->request_mode &=
|
|
1149 ~((reply->border_width == tab->core.border_width
|
|
1150 ? CWBorderWidth : 0)
|
|
1151 |(reply->width == tab->core.width ? CWWidth : 0)
|
|
1152 |(reply->height == tab->core.height ? CWHeight : 0));
|
428
|
1153 return XtGeometryAlmost ;
|
|
1154 }
|
|
1155
|
|
1156 return XtGeometryYes ;
|
|
1157 }
|
|
1158
|
|
1159
|
|
1160
|
|
1161
|
|
1162 /* The number of children we manage has changed; recompute
|
|
1163 * size from scratch.
|
|
1164 */
|
|
1165
|
|
1166 static void
|
|
1167 TabsChangeManaged(Widget w)
|
|
1168 {
|
|
1169 TabsWidget tw = (TabsWidget)w ;
|
|
1170 Widget *childP = tw->composite.children ;
|
|
1171 int i ;
|
|
1172
|
|
1173 if( tw->tabs.topWidget != NULL &&
|
|
1174 ( !XtIsManaged(tw->tabs.topWidget) ||
|
|
1175 tw->tabs.topWidget->core.being_destroyed ) )
|
|
1176 tw->tabs.topWidget = NULL ;
|
|
1177
|
440
|
1178 /* Check whether the highlight tab is still valid. */
|
|
1179 if( tw->tabs.hilight != NULL &&
|
|
1180 ( !XtIsManaged(tw->tabs.hilight) ||
|
|
1181 tw->tabs.hilight->core.being_destroyed ) )
|
|
1182 tw->tabs.hilight = NULL ;
|
|
1183
|
428
|
1184 GetPreferredSizes(tw) ;
|
|
1185 MakeSizeRequest(tw) ;
|
|
1186
|
|
1187 XtClass(w)->core_class.resize(w) ;
|
|
1188 if( XtIsRealized(w) )
|
|
1189 {
|
|
1190 Display *dpy = XtDisplay(w) ;
|
|
1191 XClearWindow(dpy, XtWindow(w)) ;
|
|
1192 XtClass(w)->core_class.expose(w,NULL,NULL) ;
|
|
1193
|
|
1194 /* make sure the top widget stays on top. This requires
|
|
1195 * making sure that all new children are realized first.
|
|
1196 */
|
|
1197 if( tw->tabs.topWidget != NULL && XtIsRealized(tw->tabs.topWidget) )
|
|
1198 {
|
446
|
1199 for(i=TabsNumChildren (tw); --i >= 0; ++childP)
|
428
|
1200 if( !XtIsRealized(*childP) )
|
|
1201 XtRealizeWidget(*childP) ;
|
|
1202
|
|
1203 XRaiseWindow(dpy, XtWindow(tw->tabs.topWidget)) ;
|
|
1204 }
|
|
1205 }
|
|
1206
|
|
1207 #ifdef NEED_MOTIF
|
|
1208 /* Only top widget may receive input */
|
|
1209
|
|
1210 for(childP = tw->composite.children, i=tw->composite.num_children;
|
|
1211 --i >= 0;
|
|
1212 ++childP)
|
|
1213 {
|
|
1214 XtVaSetValues(*childP, XmNtraversalOn, False, 0) ;
|
|
1215 }
|
|
1216
|
|
1217 if( tw->tabs.topWidget != NULL )
|
|
1218 XtVaSetValues(tw->tabs.topWidget, XmNtraversalOn, True, 0) ;
|
|
1219 #endif
|
|
1220 }
|
|
1221
|
|
1222
|
|
1223
|
|
1224
|
|
1225 /****************************************************************
|
|
1226 *
|
|
1227 * Action Procedures
|
|
1228 *
|
|
1229 ****************************************************************/
|
|
1230
|
|
1231
|
|
1232 /* User clicks on a tab, figure out which one it was. */
|
|
1233
|
|
1234 /* ARGSUSED */
|
|
1235 static void
|
2286
|
1236 TabsSelect(Widget w, XEvent *event, String *UNUSED (params),
|
|
1237 Cardinal *UNUSED (num_params))
|
428
|
1238 {
|
|
1239 TabsWidget tw = (TabsWidget) w ;
|
|
1240 Widget *childP ;
|
|
1241 Position x,y ;
|
|
1242 Dimension h = tw->tabs.tab_height ;
|
|
1243 int i ;
|
|
1244
|
|
1245 #ifdef NEED_MOTIF
|
|
1246 XmProcessTraversal (w, XmTRAVERSE_CURRENT) ;
|
|
1247 #endif
|
|
1248
|
|
1249 /* TODO: is there an Xmu function or something to do this instead? */
|
|
1250 switch( event->type ) {
|
|
1251 case ButtonPress:
|
|
1252 case ButtonRelease:
|
|
1253 x = event->xbutton.x ; y = event->xbutton.y ; break ;
|
|
1254 case KeyPress:
|
|
1255 case KeyRelease:
|
|
1256 x = event->xkey.x ; y = event->xkey.y ; break ;
|
|
1257 default:
|
|
1258 return ;
|
|
1259 }
|
|
1260
|
|
1261 /* TODO: determine which tab was clicked, if any. Set that
|
|
1262 * widget to be top of stacking order with XawTabsSetTop().
|
|
1263 */
|
|
1264 for(i=0, childP=tw->composite.children;
|
647
|
1265 i < (int) TabsNumChildren (tw);
|
428
|
1266 ++i, ++childP)
|
446
|
1267 if( TabVisible(*childP) )
|
428
|
1268 {
|
|
1269 TabsConstraints tab = (TabsConstraints)(*childP)->core.constraints;
|
|
1270 if( x > tab->tabs.x && x < tab->tabs.x + tab->tabs.width &&
|
|
1271 y > tab->tabs.y && y < tab->tabs.y + h )
|
|
1272 {
|
|
1273 if( *childP != tw->tabs.topWidget &&
|
|
1274 (XtIsSensitive(*childP) || tw->tabs.selectInsensitive) )
|
|
1275 XawTabsSetTop(*childP, True) ;
|
|
1276 break ;
|
|
1277 }
|
|
1278 }
|
|
1279 }
|
|
1280
|
|
1281
|
|
1282 /* User hits a key */
|
|
1283
|
|
1284 static void
|
2286
|
1285 TabsPage(Widget w, XEvent *UNUSED (event), String *params,
|
|
1286 Cardinal *num_params)
|
428
|
1287 {
|
|
1288 TabsWidget tw = (TabsWidget) w ;
|
430
|
1289 Widget newtop = NULL;
|
428
|
1290 Widget *childP ;
|
|
1291 int idx ;
|
446
|
1292 int nc = TabsNumChildren (tw) ;
|
428
|
1293
|
|
1294 if( nc <= 0 )
|
|
1295 return ;
|
|
1296
|
|
1297 if( *num_params < 1 ) {
|
|
1298 XtAppWarning(XtWidgetToApplicationContext(w),
|
|
1299 "Tabs: page() action called with no arguments") ;
|
|
1300 return ;
|
|
1301 }
|
|
1302
|
|
1303 if( tw->tabs.topWidget == NULL )
|
|
1304 tw->tabs.topWidget = tw->composite.children[0] ;
|
|
1305
|
|
1306 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
|
|
1307 if( tw->tabs.topWidget == *childP )
|
|
1308 break ;
|
|
1309
|
|
1310 switch( params[0][0] ) {
|
|
1311 case 'u': /* up */
|
|
1312 case 'U':
|
432
|
1313 if( --idx < 0 )
|
|
1314 idx = nc-1 ;
|
|
1315 newtop = tw->composite.children[idx] ;
|
428
|
1316 break ;
|
|
1317
|
|
1318 case 'd': /* down */
|
|
1319 case 'D':
|
|
1320 if( ++idx >= nc )
|
|
1321 idx = 0 ;
|
|
1322 newtop = tw->composite.children[idx] ;
|
|
1323 break ;
|
|
1324
|
|
1325 case 'h':
|
|
1326 case 'H':
|
432
|
1327 default:
|
428
|
1328 newtop = tw->composite.children[0] ;
|
|
1329 break ;
|
|
1330
|
|
1331 case 'e':
|
|
1332 case 'E':
|
|
1333 newtop = tw->composite.children[nc-1] ;
|
|
1334 break ;
|
|
1335
|
|
1336 case 's': /* selected */
|
|
1337 case 'S':
|
|
1338 if( (newtop = tw->tabs.hilight) == NULL )
|
|
1339 return ;
|
|
1340 break ;
|
|
1341 }
|
|
1342
|
|
1343 XawTabsSetTop(newtop, True) ;
|
|
1344 }
|
|
1345
|
|
1346
|
|
1347 /* User hits up/down key */
|
|
1348
|
|
1349 static void
|
2286
|
1350 TabsHighlight(Widget w, XEvent *UNUSED (event), String *params,
|
|
1351 Cardinal *num_params)
|
428
|
1352 {
|
|
1353 TabsWidget tw = (TabsWidget) w ;
|
430
|
1354 Widget newhl = NULL;
|
428
|
1355 Widget *childP ;
|
|
1356 int idx ;
|
446
|
1357 int nc = TabsNumChildren (tw) ;
|
428
|
1358
|
|
1359 if( nc <= 0 )
|
|
1360 return ;
|
|
1361
|
|
1362 if( *num_params < 1 )
|
|
1363 {
|
|
1364 if( tw->tabs.hilight != NULL )
|
|
1365 DrawHighlight(tw, tw->tabs.hilight, False) ;
|
|
1366 return ;
|
|
1367 }
|
|
1368
|
|
1369 if( tw->tabs.hilight == NULL )
|
|
1370 newhl = tw->composite.children[0] ;
|
|
1371
|
|
1372 else
|
|
1373 {
|
432
|
1374 /* find index of currently highlit child */
|
428
|
1375 for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
|
|
1376 if( tw->tabs.hilight == *childP )
|
|
1377 break ;
|
|
1378
|
|
1379 switch( params[0][0] ) {
|
|
1380 case 'u': /* up */
|
|
1381 case 'U':
|
432
|
1382 if( --idx < 0 )
|
|
1383 idx = nc-1 ;
|
|
1384 newhl = tw->composite.children[idx] ;
|
428
|
1385 break ;
|
|
1386
|
|
1387 case 'd': /* down */
|
|
1388 case 'D':
|
|
1389 if( ++idx >= nc )
|
|
1390 idx = 0 ;
|
|
1391 newhl = tw->composite.children[idx] ;
|
|
1392 break ;
|
|
1393
|
|
1394 case 'h':
|
|
1395 case 'H':
|
|
1396 newhl = tw->composite.children[0] ;
|
|
1397 break ;
|
|
1398
|
|
1399 case 'e':
|
|
1400 case 'E':
|
|
1401 newhl = tw->composite.children[nc-1] ;
|
|
1402 break ;
|
432
|
1403
|
|
1404 default:
|
|
1405 newhl = tw->tabs.hilight ;
|
|
1406 break ;
|
428
|
1407 }
|
|
1408 }
|
|
1409
|
|
1410 XawTabsSetHighlight(w, newhl) ;
|
|
1411 }
|
|
1412
|
|
1413
|
|
1414
|
|
1415 static void
|
2286
|
1416 TabsUnhighlight(Widget w, XEvent *UNUSED (event), String *UNUSED (params),
|
|
1417 Cardinal *UNUSED (num_params))
|
428
|
1418 {
|
|
1419 TabsWidget tw = (TabsWidget) w ;
|
|
1420 int nc = tw->composite.num_children ;
|
|
1421
|
|
1422 if( nc <= 0 )
|
|
1423 return ;
|
|
1424
|
|
1425 if( tw->tabs.hilight != NULL )
|
|
1426 DrawHighlight(tw, tw->tabs.hilight, True) ;
|
|
1427 }
|
|
1428
|
|
1429
|
|
1430
|
|
1431
|
|
1432
|
|
1433 /****************************************************************
|
|
1434 *
|
|
1435 * Public Procedures
|
|
1436 *
|
|
1437 ****************************************************************/
|
|
1438
|
|
1439
|
|
1440 /* Set the top tab, optionally call all callbacks. */
|
|
1441 void
|
|
1442 XawTabsSetTop(Widget w, Bool callCallbacks)
|
|
1443 {
|
|
1444 TabsWidget tw = (TabsWidget)w->core.parent ;
|
|
1445 TabsConstraints tab ;
|
|
1446 Widget oldtop = tw->tabs.topWidget ;
|
|
1447
|
|
1448 if( !XtIsSubclass(w->core.parent, tabsWidgetClass) )
|
|
1449 {
|
434
|
1450 char line[256] ;
|
|
1451 sprintf(line, "XawTabsSetTop: widget \"%.64s\" is not the child of a tabs widget.", XtName(w)) ;
|
428
|
1452 XtAppWarning(XtWidgetToApplicationContext(w), line) ;
|
|
1453 return ;
|
|
1454 }
|
|
1455
|
|
1456 if( callCallbacks )
|
|
1457 XtCallCallbackList(w, tw->tabs.popdownCallbacks,
|
434
|
1458 (XtPointer)tw->tabs.topWidget) ;
|
428
|
1459
|
|
1460 if( !XtIsRealized(w) ) {
|
|
1461 tw->tabs.topWidget = w ;
|
|
1462 tw->tabs.needs_layout = True ;
|
440
|
1463 tw->tabs.hilight = NULL; /* The highlight tab might disappear. */
|
428
|
1464 return ;
|
|
1465 }
|
|
1466
|
|
1467 XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
|
|
1468 #ifdef NEED_MOTIF
|
|
1469 XtVaSetValues(oldtop, XmNtraversalOn, False, 0) ;
|
|
1470 XtVaSetValues(w, XmNtraversalOn, True, 0) ;
|
|
1471 #endif
|
|
1472
|
|
1473 tab = (TabsConstraints) w->core.constraints ;
|
440
|
1474
|
|
1475 /* Unhighlight before we start messing with the stacking order. */
|
|
1476 if( tw->tabs.hilight != NULL )
|
|
1477 {
|
|
1478 DrawHighlight(tw, tw->tabs.hilight, True) ;
|
|
1479 tw->tabs.hilight = NULL;
|
|
1480 }
|
|
1481
|
428
|
1482 if( tab->tabs.row == 0 )
|
|
1483 {
|
|
1484 /* Easy case; undraw current top, undraw new top, assign new
|
|
1485 * top, redraw all borders.
|
|
1486 * We *could* just erase and execute a full redraw, but I like to
|
|
1487 * reduce screen flicker.
|
|
1488 */
|
|
1489 UndrawTab(tw, oldtop) ; /* undraw old */
|
|
1490 DrawBorder(tw, oldtop, True) ;
|
|
1491 UndrawTab(tw, w) ; /* undraw new */
|
|
1492 DrawBorder(tw, w, True) ;
|
|
1493 tw->tabs.topWidget = w ;
|
|
1494 DrawTab(tw, oldtop, True) ; /* redraw old */
|
|
1495 DrawTab(tw, w, True) ; /* redraw new */
|
|
1496 DrawTabs(tw, False) ;
|
|
1497 }
|
|
1498 else
|
|
1499 {
|
|
1500 tw->tabs.topWidget = w ;
|
|
1501 TabsShuffleRows(tw) ;
|
|
1502 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
|
|
1503 XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
|
|
1504 }
|
|
1505
|
|
1506 XawTabsSetHighlight((Widget)tw, w) ;
|
|
1507
|
|
1508 if( callCallbacks )
|
|
1509 XtCallCallbackList(w, tw->tabs.callbacks, (XtPointer)w) ;
|
|
1510 }
|
|
1511
|
|
1512
|
|
1513 /* Set the top tab, optionally call all callbacks. */
|
|
1514 void
|
|
1515 XawTabsSetHighlight(Widget t, Widget w)
|
|
1516 {
|
|
1517 TabsWidget tw = (TabsWidget)t ;
|
|
1518
|
|
1519 if( !XtIsSubclass(t, tabsWidgetClass) )
|
|
1520 return ;
|
|
1521
|
|
1522 if( XtIsRealized(t) && w != tw->tabs.hilight )
|
|
1523 {
|
|
1524 if( w != NULL )
|
|
1525 DrawHighlight(tw, w, False) ;
|
|
1526 }
|
|
1527
|
|
1528 tw->tabs.hilight = w ;
|
|
1529 }
|
|
1530
|
|
1531
|
|
1532
|
|
1533
|
|
1534 /****************************************************************
|
|
1535 *
|
|
1536 * Private Procedures
|
|
1537 *
|
|
1538 ****************************************************************/
|
|
1539
|
|
1540
|
|
1541 static void
|
|
1542 TabsAllocGCs(TabsWidget tw)
|
|
1543 {
|
|
1544 TabsAllocFgGC(tw) ;
|
|
1545 TabsAllocGreyGC(tw) ;
|
|
1546 tw->tabs.backgroundGC = AllocBackgroundGC((Widget)tw, None) ;
|
|
1547 tw->tabs.topGC = AllocTopShadowGC((Widget)tw,
|
|
1548 tw->tabs.top_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
|
|
1549 tw->tabs.botGC = AllocBotShadowGC((Widget)tw,
|
|
1550 tw->tabs.bot_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
|
|
1551 }
|
|
1552
|
|
1553
|
|
1554 static void
|
|
1555 TabsFreeGCs(TabsWidget tw)
|
|
1556 {
|
|
1557 Widget w = (Widget) tw;
|
|
1558
|
|
1559 XtReleaseGC(w, tw->tabs.foregroundGC) ;
|
|
1560 XtReleaseGC(w, tw->tabs.greyGC) ;
|
|
1561 XtReleaseGC(w, tw->tabs.backgroundGC) ;
|
|
1562 XtReleaseGC(w, tw->tabs.topGC) ;
|
|
1563 XtReleaseGC(w, tw->tabs.botGC) ;
|
|
1564 #ifdef HAVE_XMU
|
|
1565 XmuReleaseStippledPixmap(XtScreen(w), tw->tabs.grey50) ;
|
|
1566 #endif
|
|
1567 }
|
|
1568
|
|
1569
|
|
1570
|
|
1571
|
|
1572
|
|
1573 /* Redraw entire Tabs widget */
|
|
1574
|
|
1575 static void
|
|
1576 DrawTabs(TabsWidget tw, Bool labels)
|
|
1577 {
|
|
1578 Widget *childP ;
|
|
1579 int i,j ;
|
|
1580 Dimension s = SHADWID ;
|
|
1581 Dimension th = tw->tabs.tab_height ;
|
|
1582 Position y ;
|
|
1583 TabsConstraints tab ;
|
|
1584
|
|
1585 if( !XtIsRealized((Widget)tw))
|
|
1586 return ;
|
442
|
1587
|
428
|
1588 /* draw tabs and frames by row except for the top tab, which
|
|
1589 * is drawn last. (This is inefficiently written, but should not
|
|
1590 * be too slow as long as there are not a lot of rows.)
|
|
1591 */
|
|
1592
|
|
1593 y = tw->tabs.numRows == 1 ? TABDELTA : 0 ;
|
647
|
1594 for(i=0; i < (int) tw->tabs.numRows; ++i, y += th)
|
428
|
1595 {
|
446
|
1596 for( j=TabsNumChildren (tw), childP=tw->composite.children;
|
428
|
1597 --j >= 0; ++childP )
|
446
|
1598 if( TabVisible(*childP) )
|
428
|
1599 {
|
|
1600 tab = (TabsConstraints)(*childP)->core.constraints;
|
|
1601 if( tab->tabs.row == i && *childP != tw->tabs.topWidget )
|
|
1602 DrawTab(tw, *childP, labels) ;
|
|
1603 }
|
647
|
1604 if( i != (int) tw->tabs.numRows -1 )
|
428
|
1605 DrawTrim(tw, 0,y+th, tw->core.width, th+s, False,False) ;
|
|
1606 }
|
|
1607
|
|
1608 DrawFrame(tw) ;
|
|
1609
|
|
1610 /* and now the top tab */
|
|
1611 if( tw->tabs.topWidget != NULL )
|
|
1612 DrawTab(tw, tw->tabs.topWidget, labels) ;
|
|
1613 }
|
|
1614
|
|
1615
|
|
1616
|
|
1617 /* Draw one tab. Corners are rounded very slightly. */
|
|
1618
|
|
1619 static void
|
|
1620 DrawTab(TabsWidget tw, Widget child, Bool labels)
|
|
1621 {
|
|
1622 GC gc ;
|
|
1623 int x,y ;
|
|
1624
|
3397
|
1625 if (debug_tabs > 2) fprintf (stderr, "DrawTab called.\n");
|
3094
|
1626
|
428
|
1627 if( !XtIsRealized((Widget)tw))
|
|
1628 return ;
|
|
1629
|
|
1630 DrawBorder(tw, child, False) ;
|
|
1631
|
|
1632 if( labels )
|
|
1633 {
|
|
1634 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1635 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1636 Window win = XtWindow((Widget)tw) ;
|
|
1637 String lbl = tab->tabs.label != NULL ?
|
|
1638 tab->tabs.label : XtName(child) ;
|
3094
|
1639 #ifdef USE_XFT_TABS
|
|
1640 XftColor color;
|
|
1641 XftColor colorBG;
|
|
1642 Colormap cmap = tw->core.colormap;
|
|
1643 Visual *visual;
|
|
1644 int ignored;
|
428
|
1645
|
3094
|
1646 visual_info_from_widget ((Widget) tw, &visual, &ignored);
|
|
1647 colorBG = xft_convert_color (dpy, cmap, visual,
|
|
1648 tw->core.background_pixel, 0);
|
|
1649 #endif
|
|
1650
|
|
1651 if (debug_tabs > 2)
|
|
1652 fprintf (stderr, "(Re)drawing labels.\n");
|
|
1653
|
|
1654 if (XtIsSensitive(child))
|
428
|
1655 {
|
3094
|
1656 gc = tw->tabs.foregroundGC;
|
|
1657 #ifdef USE_XFT_TABS
|
|
1658 color = xft_convert_color (dpy, cmap, visual,
|
|
1659 tab->tabs.foreground, 0);
|
|
1660 #else
|
|
1661 XSetForeground(dpy, gc, tab->tabs.foreground);
|
|
1662 #endif
|
428
|
1663 }
|
|
1664 else
|
|
1665 {
|
|
1666 /* grey pixel allocation deferred until now */
|
3094
|
1667 if (!tab->tabs.greyAlloc)
|
428
|
1668 {
|
3094
|
1669 if (tw->tabs.be_nice_to_cmap || tw->core.depth == 1)
|
|
1670 tab->tabs.grey = tab->tabs.foreground;
|
428
|
1671 else
|
3094
|
1672 tab->tabs.grey = AllocGreyPixel ((Widget) tw,
|
428
|
1673 tab->tabs.foreground,
|
|
1674 tw->core.background_pixel,
|
3094
|
1675 tw->tabs.insensitive_contrast);
|
|
1676 tab->tabs.greyAlloc = True;
|
428
|
1677 }
|
3094
|
1678 gc = tw->tabs.greyGC;
|
|
1679 #ifdef USE_XFT_TABS
|
|
1680 color = xft_convert_color (dpy, cmap, visual, tab->tabs.grey, 0);
|
|
1681 #else
|
|
1682 XSetForeground(dpy, gc, tab->tabs.grey);
|
|
1683 #endif
|
428
|
1684 }
|
|
1685
|
3094
|
1686 x = tab->tabs.x;
|
|
1687 y = tab->tabs.y;
|
|
1688 if (child == tw->tabs.topWidget)
|
|
1689 y -= TABLDELTA;
|
428
|
1690
|
3094
|
1691 if (tab->tabs.left_bitmap != None && tab->tabs.lbm_width > 0)
|
428
|
1692 {
|
3094
|
1693 if (tab->tabs.lbm_depth == 1)
|
428
|
1694 XCopyPlane(dpy, tab->tabs.left_bitmap, win,gc,
|
434
|
1695 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
|
3094
|
1696 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y, 1L);
|
428
|
1697 else
|
|
1698 XCopyArea(dpy, tab->tabs.left_bitmap, win,gc,
|
434
|
1699 0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
|
3094
|
1700 x+tab->tabs.lbm_x, y+tab->tabs.lbm_y);
|
428
|
1701 }
|
|
1702
|
3094
|
1703 if (lbl != NULL &&
|
|
1704 #ifdef USE_XFT_TABS
|
|
1705 tw->tabs.renderFont != NULL
|
|
1706 #else
|
|
1707 tw->tabs.font != NULL
|
|
1708 #endif
|
|
1709 )
|
|
1710 {
|
|
1711 #ifdef USE_XFT_TABS
|
|
1712 XftDraw *xftDraw = XftDrawCreate (dpy, win, visual, cmap);
|
|
1713 XftFont *renderFont = tw->tabs.renderFont;
|
|
1714 XGlyphInfo glyphinfo;
|
|
1715 XftColor colorDBG;
|
|
1716 XftColorAllocName (dpy, visual, cmap, "wheat", &colorDBG);
|
3374
|
1717 XftTextExtents8 (dpy, renderFont, (FcChar8 *) lbl,
|
|
1718 (int) strlen (lbl), &glyphinfo);
|
3094
|
1719 /* #### unnecessary? for the moment, give visual extent */
|
|
1720 /* draw background rect */
|
|
1721 if (debug_tabs > 2)
|
|
1722 {
|
|
1723 fprintf (stderr, "background color: pixel=%08lx, r=%04x,"
|
|
1724 " g=%04x, b=%04x, alpha=%04x.\n",
|
|
1725 colorDBG.pixel, colorDBG.color.red,
|
|
1726 colorDBG.color.green, colorDBG.color.blue,
|
|
1727 colorDBG.color.alpha);
|
|
1728 fprintf (stderr, "label geometry: x=%d, y=%d, xOff=%d,"
|
|
1729 " yOff=%d, width=%d, height=%d\n",
|
|
1730 glyphinfo.x, glyphinfo.y, glyphinfo.xOff,
|
|
1731 glyphinfo.yOff, glyphinfo.width, glyphinfo.height);
|
|
1732 }
|
3397
|
1733 if (debug_tabs > 2)
|
|
1734 XftDrawRect (xftDraw, &colorDBG,
|
|
1735 /* left, top, width, height */
|
|
1736 x+tab->tabs.l_x-glyphinfo.x,
|
|
1737 y+tab->tabs.l_y-glyphinfo.y,
|
|
1738 glyphinfo.width, glyphinfo.height);
|
|
1739
|
3094
|
1740 /* draw text */
|
3397
|
1741 if (debug_tabs > 1)
|
3094
|
1742 {
|
|
1743 fprintf (stderr, "label: %s.\n", lbl);
|
|
1744 fprintf (stderr, "foreground color: pixel=%08lx, r=%04x,"
|
|
1745 " g=%04x, b=%04x, alpha=%04x.\n",
|
|
1746 color.pixel, color.color.red, color.color.green,
|
|
1747 color.color.blue, color.color.alpha);
|
|
1748 fprintf (stderr, "extent: x=%d, y=%d, xOffset=%d,"
|
|
1749 " yOffset=%d, height=%d, width=%d.\n",
|
|
1750 glyphinfo.x, glyphinfo.y, glyphinfo.xOff,
|
|
1751 glyphinfo.yOff, glyphinfo.height, glyphinfo.width);
|
3397
|
1752 }
|
|
1753 if (debug_tabs > 0)
|
|
1754 {
|
|
1755 FcValue name;
|
|
1756 FcValue size;
|
|
1757 FcPatternGet (renderFont->pattern, FC_FAMILY, 0, &name);
|
|
1758 FcPatternGet (renderFont->pattern, FC_SIZE, 0, &size);
|
3094
|
1759 fprintf (stderr, "font: name=%s-%.1f,"
|
|
1760 " height=%d, ascent=%d, descent=%d.\n",
|
|
1761 name.u.s, size.u.d, renderFont->height,
|
|
1762 renderFont->ascent, renderFont->descent);
|
|
1763 }
|
|
1764 XftDrawString8 (xftDraw, &color, renderFont,
|
|
1765 x+tab->tabs.l_x, y+tab->tabs.l_y,
|
3374
|
1766 (FcChar8 *) lbl, (int) strlen (lbl));
|
3094
|
1767 XftDrawDestroy (xftDraw);
|
|
1768 #else
|
|
1769 XDrawString(dpy,win,gc,
|
|
1770 x+tab->tabs.l_x, y+tab->tabs.l_y,
|
|
1771 lbl, (int)strlen(lbl));
|
|
1772 #endif
|
|
1773 }
|
428
|
1774 }
|
|
1775
|
3094
|
1776 if (child == tw->tabs.hilight)
|
|
1777 DrawHighlight(tw, child, False);
|
428
|
1778 }
|
|
1779
|
|
1780
|
|
1781 /* draw frame all the way around the child windows. */
|
|
1782
|
|
1783 static void
|
|
1784 DrawFrame(TabsWidget tw)
|
|
1785 {
|
|
1786 GC topgc = tw->tabs.topGC ;
|
|
1787 GC botgc = tw->tabs.botGC ;
|
|
1788 Dimension s = SHADWID ;
|
|
1789 Dimension ch = tw->tabs.child_height ;
|
448
|
1790 if (ch > 0)
|
|
1791 Draw3dBox((Widget)tw, 0,tw->tabs.tab_total,
|
|
1792 tw->core.width, ch+2*s, s, topgc, botgc) ;
|
|
1793 else
|
|
1794 {
|
|
1795 Widget w = tw->tabs.topWidget ;
|
|
1796 if (w != NULL)
|
|
1797 {
|
|
1798 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
|
|
1799 Draw3dBox((Widget)tw, 0,tw->core.height - 2*s,
|
|
1800 tab->tabs.x, 2*s, s, topgc, botgc);
|
|
1801 Draw3dBox((Widget)tw, tab->tabs.x + tab->tabs.width,
|
|
1802 tw->core.height - 2*s,
|
|
1803 tw->core.width - tab->tabs.x - tab->tabs.width, 2*s, s,
|
|
1804 topgc, botgc);
|
|
1805 }
|
|
1806 else
|
|
1807 Draw3dBox((Widget)tw, 0,tw->core.height - 2*s,
|
|
1808 tw->core.width, 2*s, s, topgc, botgc) ;
|
|
1809 }
|
428
|
1810 }
|
|
1811
|
|
1812
|
|
1813 /* draw trim around a tab or underneath a row of tabs */
|
|
1814
|
|
1815 static void
|
|
1816 DrawTrim(TabsWidget tw, /* widget */
|
|
1817 int x, /* upper-left corner */
|
|
1818 int y,
|
|
1819 int wid, /* total size */
|
|
1820 int hgt,
|
|
1821 Bool bottom, /* draw bottom? */
|
|
1822 Bool undraw) /* undraw all */
|
|
1823 {
|
|
1824 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1825 Window win = XtWindow((Widget)tw) ;
|
|
1826 GC bggc = tw->tabs.backgroundGC ;
|
|
1827 GC topgc = undraw ? bggc : tw->tabs.topGC ;
|
|
1828 GC botgc = undraw ? bggc : tw->tabs.botGC ;
|
|
1829 if( bottom )
|
|
1830 XDrawLine(dpy,win,bggc, x,y+hgt-1, x+wid-1,y+hgt-1) ; /* bottom */
|
|
1831 XDrawLine(dpy,win,topgc, x,y+2, x,y+hgt-2) ; /* left */
|
|
1832 XDrawPoint(dpy,win,topgc, x+1,y+1) ; /* corner */
|
|
1833 XDrawLine(dpy,win,topgc, x+2,y, x+wid-3,y) ; /* top */
|
|
1834 XDrawLine(dpy,win,botgc, x+wid-2,y+1, x+wid-2,y+hgt-2) ; /* right */
|
|
1835 XDrawLine(dpy,win,botgc, x+wid-1,y+2, x+wid-1,y+hgt-2) ; /* right */
|
|
1836 }
|
|
1837
|
|
1838
|
|
1839 /* Draw one tab border. */
|
|
1840
|
|
1841 static void
|
|
1842 DrawBorder(TabsWidget tw, Widget child, Bool undraw)
|
|
1843 {
|
|
1844 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1845 Position x = tab->tabs.x ;
|
|
1846 Position y = tab->tabs.y ;
|
|
1847 Dimension twid = tab->tabs.width ;
|
|
1848 Dimension thgt = tw->tabs.tab_height ;
|
|
1849
|
|
1850 /* top tab requires a little special attention; it overlaps
|
|
1851 * neighboring tabs slightly, so the background must be cleared
|
|
1852 * in the region of the overlap to partially erase those neighbors.
|
|
1853 * TODO: is this worth doing with regions instead?
|
|
1854 */
|
|
1855 if( child == tw->tabs.topWidget )
|
|
1856 {
|
|
1857 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1858 Window win = XtWindow((Widget)tw) ;
|
|
1859 GC bggc = tw->tabs.backgroundGC ;
|
|
1860 XRectangle rects[3] ;
|
|
1861 x -= TABDELTA ;
|
|
1862 y -= TABDELTA ;
|
|
1863 twid += TABDELTA*2 ;
|
|
1864 thgt += TABDELTA ;
|
|
1865 AddRect(0, x,y+1,twid,TABDELTA) ;
|
|
1866 AddRect(1, x+1,y,TABDELTA,thgt) ;
|
|
1867 AddRect(2, x+twid-TABDELTA-1,y,TABDELTA,thgt) ;
|
|
1868 XFillRectangles(dpy,win,bggc, rects, 3) ;
|
|
1869 }
|
|
1870
|
|
1871 DrawTrim(tw, x,y,twid,thgt+1, child == tw->tabs.topWidget, undraw) ;
|
|
1872 }
|
|
1873
|
|
1874
|
|
1875 /* Draw highlight around tab that has focus */
|
|
1876
|
|
1877 static void
|
|
1878 DrawHighlight(TabsWidget tw, Widget child, Bool undraw)
|
|
1879 {
|
|
1880 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1881 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1882 Window win = XtWindow((Widget)tw) ;
|
|
1883 GC gc ;
|
|
1884 Position x = tab->tabs.x ;
|
|
1885 Position y = tab->tabs.y ;
|
|
1886 Dimension wid = tab->tabs.width ;
|
|
1887 Dimension hgt = tw->tabs.tab_height ;
|
|
1888 XPoint points[6] ;
|
|
1889
|
|
1890 /* top tab does not have a highlight */
|
|
1891
|
|
1892 if( child == tw->tabs.topWidget )
|
|
1893 return ;
|
|
1894
|
|
1895 if( undraw )
|
|
1896 gc = tw->tabs.backgroundGC ;
|
|
1897
|
|
1898 else if( XtIsSensitive(child) )
|
|
1899 {
|
|
1900 gc = tw->tabs.foregroundGC ;
|
|
1901 XSetForeground(dpy, gc, tab->tabs.foreground) ;
|
|
1902 }
|
|
1903 else
|
|
1904 {
|
|
1905 gc = tw->tabs.greyGC ;
|
|
1906 XSetForeground(dpy, gc, tab->tabs.grey) ;
|
|
1907 }
|
|
1908
|
|
1909 points[0].x = x+1 ; points[0].y = y+hgt-1 ;
|
|
1910 points[1].x = x+1 ; points[1].y = y+2 ;
|
|
1911 points[2].x = x+2 ; points[2].y = y+1 ;
|
|
1912 points[3].x = x+wid-4 ; points[3].y = y+1 ;
|
|
1913 points[4].x = x+wid-3 ; points[4].y = y+2 ;
|
|
1914 points[5].x = x+wid-3 ; points[5].y = y+hgt-1 ;
|
|
1915
|
|
1916 XDrawLines(dpy,win,gc, points,6, CoordModeOrigin) ;
|
|
1917 }
|
|
1918
|
|
1919
|
|
1920 /* Undraw one tab interior */
|
|
1921
|
|
1922 static void
|
|
1923 UndrawTab(TabsWidget tw, Widget child)
|
|
1924 {
|
|
1925 TabsConstraints tab = (TabsConstraints)child->core.constraints;
|
|
1926 Position x = tab->tabs.x ;
|
|
1927 Position y = tab->tabs.y ;
|
|
1928 Dimension twid = tab->tabs.width ;
|
|
1929 Dimension thgt = tw->tabs.tab_height ;
|
|
1930 Display *dpy = XtDisplay((Widget)tw) ;
|
|
1931 Window win = XtWindow((Widget)tw) ;
|
|
1932 GC bggc = tw->tabs.backgroundGC ;
|
|
1933
|
|
1934 XFillRectangle(dpy,win,bggc, x,y, twid,thgt) ;
|
|
1935 }
|
|
1936
|
|
1937
|
|
1938
|
|
1939
|
|
1940
|
|
1941 /* GEOMETRY UTILITIES */
|
|
1942
|
434
|
1943 /* Overview:
|
|
1944 *
|
|
1945 * MaxChild(): ask all children (except possibly one) their
|
|
1946 * preferred sizes, set max_cw, max_ch accordingly.
|
|
1947 *
|
|
1948 * GetPreferredSizes(): ask all children their preferred sizes,
|
|
1949 * set max_cw, max_ch accordingly.
|
|
1950 *
|
|
1951 * PreferredSize(): given max_cw, max_ch, return tabs widget
|
|
1952 * preferred size. Iterate with other widths in order to get
|
|
1953 * a reasonable aspect ratio.
|
|
1954 *
|
|
1955 * PreferredSize2(): Given child dimensions, return Tabs
|
|
1956 * widget dimensions.
|
|
1957 *
|
|
1958 * PreferredSize3(): Same, except given child dimensions plus
|
|
1959 * shadow.
|
|
1960 */
|
428
|
1961
|
434
|
1962
|
|
1963 /* Compute the width of one child's tab. Positions will be computed
|
428
|
1964 * elsewhere.
|
|
1965 *
|
|
1966 * height: font height + vertical_space*2 + shadowWid*2
|
|
1967 * width: string width + horizontal_space*2 + shadowWid*2
|
|
1968 *
|
|
1969 * All tabs are the same height, so that is computed elsewhere.
|
|
1970 */
|
|
1971
|
|
1972 static void
|
|
1973 TabWidth(Widget w)
|
|
1974 {
|
|
1975 TabsConstraints tab = (TabsConstraints) w->core.constraints ;
|
|
1976 TabsWidget tw = (TabsWidget)XtParent(w) ;
|
|
1977 String lbl = tab->tabs.label != NULL ?
|
3094
|
1978 tab->tabs.label : XtName(w);
|
|
1979 #ifdef USE_XFT_TABS
|
|
1980 XftFont *font = tw->tabs.renderFont;
|
|
1981 #else
|
|
1982 XFontStruct *font = tw->tabs.font;
|
|
1983 #endif
|
|
1984 int iw = tw->tabs.internalWidth;
|
428
|
1985
|
|
1986 tab->tabs.width = iw + SHADWID*2 ;
|
|
1987 tab->tabs.l_x = tab->tabs.lbm_x = SHADWID + iw ;
|
|
1988
|
|
1989 if( tab->tabs.left_bitmap != None )
|
|
1990 {
|
|
1991 tab->tabs.width += tab->tabs.lbm_width + iw ;
|
|
1992 tab->tabs.l_x += tab->tabs.lbm_width + iw ;
|
|
1993 tab->tabs.lbm_y = (tw->tabs.tab_height - tab->tabs.lbm_height)/2 ;
|
|
1994 }
|
|
1995
|
|
1996 if( lbl != NULL && font != NULL )
|
|
1997 {
|
3094
|
1998 #ifdef USE_XFT_TABS
|
|
1999 tab->tabs.width += x_xft_text_width (XtDisplay(tw), font,
|
3374
|
2000 (FcChar8 *) lbl,
|
|
2001 (int)strlen(lbl)) + iw;
|
3094
|
2002 tab->tabs.l_y = (tw->tabs.tab_height
|
|
2003 + tw->tabs.renderFont->ascent
|
|
2004 /* #### how can this subtraction be correct? */
|
|
2005 - tw->tabs.renderFont->descent)/2;
|
|
2006 if (debug_tabs > 2)
|
|
2007 fprintf (stderr, "tab: height=%d, width=%d, baseline=%d.\n",
|
|
2008 tw->tabs.tab_height, tab->tabs.width, tab->tabs.l_y);
|
|
2009 if (debug_tabs > 1)
|
|
2010 fprintf (stderr, "font: height=%d, ascent=%d, descent=%d.\n",
|
|
2011 tw->tabs.renderFont->height,
|
|
2012 tw->tabs.renderFont->ascent,
|
|
2013 tw->tabs.renderFont->descent);
|
|
2014 #else
|
|
2015 tab->tabs.width += XTextWidth (font, lbl, (int)strlen(lbl)) + iw;
|
428
|
2016 tab->tabs.l_y = (tw->tabs.tab_height +
|
434
|
2017 tw->tabs.font->max_bounds.ascent -
|
3094
|
2018 tw->tabs.font->max_bounds.descent)/2;
|
|
2019 #endif
|
428
|
2020 }
|
|
2021 }
|
|
2022
|
|
2023
|
|
2024
|
|
2025 /* Lay out tabs to fit in given width. Compute x,y position and
|
|
2026 * row number for each tab. Return number of rows and total height
|
|
2027 * required by all tabs. If there is only one row, add TABDELTA
|
|
2028 * height to the total. Rows are assigned bottom to top.
|
|
2029 *
|
|
2030 * Tabs are indented from the edges by INDENT.
|
|
2031 *
|
|
2032 * TODO: if they require more than two rows and the total height:width
|
|
2033 * ratio is more than 2:1, then try something else.
|
3094
|
2034 * Gaak! This is actually already done in PreferredSize()!
|
|
2035 *
|
|
2036 * TODO SOONER: for reasons unclear, some applications (specifically
|
|
2037 * XEmacs) give a nominal geometry (in the core record) which doesn't
|
|
2038 * make much sense (eg, may be smaller than some of the tab children).
|
|
2039 * This results in bizarre values for DISPLAY_ROWS and REPLY_HEIGHT.
|
|
2040 * Specify a way to say "tell me what you really want" (eg, with WID
|
|
2041 * and/or HGT == 0 or == Dimension_MAX), and use it where appropriate.
|
|
2042 * LATE-BREAKING LOSE: This happens in PreferredSize(), not XEmacs!
|
|
2043 *
|
|
2044 * TODO EVEN SOONER: some applications lay out the tab control by
|
|
2045 * repeatedly querying until a fixed width and height has been filled
|
|
2046 * by the tabs (XEmacs). There should be an API to cache this?
|
428
|
2047 */
|
|
2048
|
|
2049 static int
|
448
|
2050 TabLayout(TabsWidget tw,
|
3094
|
2051 Dimension wid, /* if 0, use core.width as guess */
|
|
2052 Dimension hgt, /* if 0, use core.height as guess */
|
448
|
2053 Dimension *reply_height, Bool query_only)
|
428
|
2054 {
|
446
|
2055 int i, row, done = 0, display_rows = 0 ;
|
428
|
2056 int num_children = tw->composite.num_children ;
|
|
2057 Widget *childP ;
|
|
2058 Dimension w ;
|
3094
|
2059 Position x,y ; /* #### gaak, these are dimensions! */
|
428
|
2060 TabsConstraints tab ;
|
|
2061
|
|
2062 /* Algorithm: loop through children, assign X positions. If a tab
|
|
2063 * would extend beyond the right edge, start a new row. After all
|
|
2064 * rows are assigned, make a second pass and assign Y positions.
|
|
2065 */
|
|
2066
|
|
2067 if( num_children > 0 )
|
|
2068 {
|
|
2069 /* Loop through the tabs and see how much space they need. */
|
|
2070
|
|
2071 row = 0 ;
|
|
2072 x = INDENT ;
|
|
2073 y = 0 ;
|
3094
|
2074 /* If wid or hgt is 0, we want to guess our own dimensions.
|
|
2075 Currently the guessing functions are broken....
|
|
2076 #### When PreferredSize*() get fixed, fix this too. */
|
3397
|
2077 if (debug_tabs > 1)
|
3094
|
2078 fprintf (stderr, "arg=%d,", wid);
|
|
2079 wid = (wid ? wid : tw->core.width) - INDENT ;
|
|
2080 hgt = hgt ? hgt : tw->core.height;
|
3397
|
2081 if (debug_tabs > 1)
|
3094
|
2082 fprintf (stderr, "wid=%d: x,w,y=", wid);
|
428
|
2083 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
|
|
2084 if( XtIsManaged(*childP) )
|
|
2085 {
|
|
2086 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
2087 w = tab->tabs.width ;
|
446
|
2088
|
3397
|
2089 if (debug_tabs > 1)
|
3094
|
2090 fprintf (stderr, "%d,%d,%d;", x, w, y);
|
428
|
2091 if( x + w > wid ) { /* new row */
|
3094
|
2092 /* #### algorithm is not robust to wid < child's width */
|
|
2093 ++row;
|
|
2094 x = INDENT ;
|
|
2095 y += tw->tabs.tab_height ;
|
|
2096 if (y > hgt && !done)
|
446
|
2097 {
|
|
2098 display_rows = row;
|
|
2099 done = 1;
|
|
2100 }
|
428
|
2101 }
|
|
2102 if( !query_only ) {
|
|
2103 tab->tabs.x = x ;
|
|
2104 tab->tabs.y = y ;
|
|
2105 tab->tabs.row = row ;
|
|
2106 }
|
|
2107 x += w + SPACING ;
|
446
|
2108 if (!query_only && !done)
|
|
2109 tab->tabs.visible = 1;
|
|
2110
|
428
|
2111 }
|
3397
|
2112 if (debug_tabs > 1)
|
3094
|
2113 fprintf (stderr, "\n");
|
442
|
2114 /* If there was only one row, increase the height by TABDELTA */
|
446
|
2115 if( ++display_rows == 1 )
|
428
|
2116 {
|
|
2117 y = TABDELTA ;
|
|
2118 if( !query_only )
|
|
2119 for(i=num_children, childP=tw->composite.children;
|
|
2120 --i >= 0 ; ++childP)
|
|
2121 if( XtIsManaged(*childP) )
|
|
2122 {
|
|
2123 tab = (TabsConstraints) (*childP)->core.constraints ;
|
|
2124 tab->tabs.y = y ;
|
|
2125 }
|
|
2126 }
|
3094
|
2127 row++;
|
428
|
2128 y += tw->tabs.tab_height ;
|
|
2129 }
|
|
2130 else
|
446
|
2131 display_rows = row = y = 0 ;
|
428
|
2132
|
|
2133 if( !query_only ) {
|
|
2134 tw->tabs.tab_total = y ;
|
446
|
2135 tw->tabs.numRows = display_rows ;
|
|
2136 tw->tabs.realRows = row;
|
428
|
2137 }
|
|
2138
|
3397
|
2139 if (debug_tabs > 1 && (row > 1 || display_rows > 1))
|
3094
|
2140 fprintf (stderr, "tab: %d display rows, #children = %d,"
|
|
2141 " total height %d, total rows %d%s.\n",
|
|
2142 display_rows, num_children, y, row,
|
|
2143 query_only ? " (query)" : "");
|
|
2144
|
428
|
2145 if( reply_height != NULL )
|
|
2146 *reply_height = y ;
|
|
2147
|
446
|
2148 return display_rows ;
|
428
|
2149 }
|
|
2150
|
|
2151
|
|
2152
|
|
2153 /* Find max preferred child size. Returned sizes include child
|
434
|
2154 * border widths.
|
428
|
2155 */
|
|
2156
|
|
2157 static void
|
|
2158 GetPreferredSizes(TabsWidget tw)
|
|
2159 {
|
434
|
2160 MaxChild(tw, NULL, 0,0) ;
|
428
|
2161 }
|
|
2162
|
|
2163
|
|
2164
|
3094
|
2165 /* Find max preferred child size and store in control widget.
|
|
2166 * If except is non-null, don't ask that one.
|
434
|
2167 */
|
428
|
2168
|
|
2169 static void
|
434
|
2170 MaxChild(TabsWidget tw, Widget except, Dimension cw, Dimension ch)
|
428
|
2171 {
|
434
|
2172 int i ;
|
|
2173 Widget *childP = tw->composite.children ;
|
|
2174 XtWidgetGeometry preferred ;
|
428
|
2175
|
|
2176 for(i=tw->composite.num_children; --i >=0; ++childP)
|
448
|
2177 if( TabVisible (*childP) /*XtIsManaged(*childP)*/ && *childP != except )
|
428
|
2178 {
|
434
|
2179 (void) XtQueryGeometry(*childP, NULL, &preferred) ;
|
|
2180 cw = Max(cw, preferred.width + preferred.border_width * 2 ) ;
|
|
2181 ch = Max(ch, preferred.height + preferred.border_width * 2 ) ;
|
428
|
2182 }
|
|
2183
|
|
2184 tw->tabs.max_cw = cw ;
|
|
2185 tw->tabs.max_ch = ch ;
|
|
2186 }
|
|
2187
|
|
2188
|
|
2189
|
|
2190 /* rotate row numbers to bring current widget to bottom row,
|
|
2191 * compute y positions for all tabs
|
|
2192 */
|
|
2193
|
|
2194 static void
|
|
2195 TabsShuffleRows(TabsWidget tw)
|
|
2196 {
|
|
2197 TabsConstraints tab ;
|
|
2198 int move ;
|
446
|
2199 int real_rows, display_rows ;
|
428
|
2200 Widget *childP ;
|
|
2201 Dimension th = tw->tabs.tab_height ;
|
|
2202 Position bottom ;
|
|
2203 int i ;
|
|
2204
|
|
2205 /* There must be a top widget. If not, assign one. */
|
|
2206 if( tw->tabs.topWidget == NULL && tw->composite.children != NULL )
|
446
|
2207 for(i=TabsNumChildren (tw), childP=tw->composite.children;
|
428
|
2208 --i >= 0;
|
|
2209 ++childP)
|
|
2210 if( XtIsManaged(*childP) ) {
|
|
2211 tw->tabs.topWidget = *childP ;
|
|
2212 break ;
|
|
2213 }
|
|
2214
|
|
2215 if( tw->tabs.topWidget != NULL )
|
|
2216 {
|
446
|
2217 display_rows = tw->tabs.numRows ;
|
|
2218 real_rows = tw->tabs.realRows ;
|
448
|
2219 assert( display_rows <= real_rows ) ;
|
428
|
2220
|
446
|
2221 if( real_rows > 1 )
|
428
|
2222 {
|
|
2223 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ;
|
|
2224 assert( tab != NULL ) ;
|
|
2225
|
446
|
2226 /* How far to move top row. The selected tab must be on
|
|
2227 the bottom row of the *visible* rows. */
|
|
2228 move = (real_rows + 1 - display_rows) - tab->tabs.row ;
|
|
2229 if (move < 0)
|
|
2230 move = real_rows - move;
|
428
|
2231 bottom = tw->tabs.tab_total - th ;
|
|
2232
|
446
|
2233 for(i=tw->composite.num_children, childP=tw->composite.children;
|
428
|
2234 --i >= 0;
|
|
2235 ++childP)
|
|
2236 if( XtIsManaged(*childP) )
|
|
2237 {
|
|
2238 tab = (TabsConstraints) (*childP)->core.constraints ;
|
446
|
2239 tab->tabs.row = (tab->tabs.row + move) % real_rows ;
|
428
|
2240 tab->tabs.y = bottom - tab->tabs.row * th ;
|
446
|
2241 tab->tabs.visible = (tab->tabs.row < display_rows);
|
428
|
2242 }
|
|
2243 }
|
|
2244 }
|
|
2245 }
|
|
2246
|
|
2247
|
434
|
2248 /* Find preferred size. Ask children, find size of largest,
|
428
|
2249 * add room for tabs & return. This can get a little involved,
|
|
2250 * as we don't want to have too many rows of tabs; we may widen
|
|
2251 * the widget to reduce # of rows.
|
434
|
2252 *
|
|
2253 * This function requires that max_cw, max_ch already be set.
|
428
|
2254 */
|
|
2255 static int
|
|
2256 PreferredSize(
|
|
2257 TabsWidget tw,
|
|
2258 Dimension *reply_width, /* total widget size */
|
|
2259 Dimension *reply_height,
|
|
2260 Dimension *reply_cw, /* child widget size */
|
|
2261 Dimension *reply_ch)
|
|
2262 {
|
|
2263 Dimension cw,ch ; /* child width, height */
|
|
2264 Dimension wid,hgt ;
|
|
2265 Dimension rwid,rhgt ;
|
|
2266 int nrow ;
|
|
2267
|
|
2268 wid = cw = tw->tabs.max_cw ;
|
|
2269 hgt = ch = tw->tabs.max_ch ;
|
|
2270
|
|
2271 nrow = PreferredSize2(tw, wid,hgt, &rwid, &rhgt) ;
|
|
2272
|
|
2273 /* Check for absurd results (more than 2 rows, high aspect
|
|
2274 * ratio). Try wider size if needed.
|
|
2275 * TODO: make sure this terminates.
|
|
2276 */
|
|
2277
|
|
2278 if( nrow > 2 && rhgt > rwid )
|
|
2279 {
|
|
2280 Dimension w0, w1 ;
|
434
|
2281 int maxloop = 20 ;
|
428
|
2282
|
|
2283 /* step 1: start doubling size until it's too big */
|
|
2284 do {
|
|
2285 w0 = wid ;
|
|
2286 wid = Max(wid*2, wid+20) ;
|
|
2287 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
|
|
2288 } while( nrow > 2 && rhgt > rwid ) ;
|
|
2289 w1 = wid ;
|
|
2290
|
|
2291 /* step 2: use Newton's method to find ideal size. Stop within
|
|
2292 * 8 pixels.
|
|
2293 */
|
434
|
2294 while( --maxloop > 0 && w1 > w0 + 8 )
|
428
|
2295 {
|
|
2296 wid = (w0+w1)/2 ;
|
|
2297 nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
|
|
2298 if( nrow > 2 && rhgt > rwid )
|
|
2299 w0 = wid ;
|
|
2300 else
|
|
2301 w1 = wid ;
|
|
2302 }
|
|
2303 wid = w1 ;
|
|
2304 }
|
|
2305
|
|
2306 *reply_width = rwid ;
|
|
2307 *reply_height = rhgt ;
|
|
2308 if( reply_cw != NULL ) *reply_cw = cw ;
|
|
2309 if( reply_ch != NULL ) *reply_ch = ch ;
|
|
2310 return nrow ;
|
|
2311 }
|
|
2312
|
|
2313
|
|
2314 /* Find preferred size, given size of children. */
|
|
2315
|
|
2316 static int
|
|
2317 PreferredSize2(
|
|
2318 TabsWidget tw,
|
448
|
2319 Dimension cw, /* child width, height */
|
|
2320 Dimension ch,
|
428
|
2321 Dimension *reply_width, /* total widget size */
|
|
2322 Dimension *reply_height)
|
|
2323 {
|
|
2324 Dimension s = SHADWID ;
|
448
|
2325 int ret;
|
428
|
2326
|
|
2327 /* make room for shadow frame */
|
|
2328 cw += s*2 ;
|
|
2329 ch += s*2 ;
|
|
2330
|
448
|
2331 ret = PreferredSize3(tw, cw, ch, reply_width, reply_height) ;
|
|
2332
|
|
2333 assert (*reply_width > 0 && *reply_height > 0);
|
|
2334 return ret;
|
428
|
2335 }
|
|
2336
|
|
2337
|
|
2338 /* Find preferred size, given size of children+shadow. */
|
|
2339
|
|
2340 static int
|
|
2341 PreferredSize3(
|
|
2342 TabsWidget tw,
|
448
|
2343 Dimension wid, /* child width, height */
|
|
2344 Dimension hgt,
|
428
|
2345 Dimension *reply_width, /* total widget size */
|
|
2346 Dimension *reply_height)
|
|
2347 {
|
|
2348 Dimension th ; /* space used by tabs */
|
|
2349 int nrows ;
|
|
2350
|
|
2351 if( tw->composite.num_children > 0 )
|
3094
|
2352 /* used to be wid, hgt not 0, 0 but that's obviously wrong
|
|
2353 since TabLayout wants dimensions of control parent but
|
|
2354 wid, hgt are dimensions of some child */
|
|
2355 nrows = TabLayout(tw, 0, 0, &th, True) ;
|
428
|
2356 else {
|
|
2357 th = 0 ;
|
|
2358 nrows = 0 ;
|
|
2359 }
|
|
2360
|
|
2361 *reply_width = Max(wid, MIN_WID) ;
|
|
2362 *reply_height = Max(th+hgt, MIN_HGT) ;
|
|
2363
|
|
2364 return nrows ;
|
|
2365 }
|
|
2366
|
|
2367
|
|
2368 static void
|
|
2369 MakeSizeRequest(TabsWidget tw)
|
|
2370 {
|
|
2371 Widget w = (Widget)tw ;
|
|
2372 XtWidgetGeometry request, reply ;
|
|
2373 XtGeometryResult result ;
|
|
2374 Dimension cw,ch ;
|
|
2375
|
|
2376 request.request_mode = CWWidth | CWHeight ;
|
|
2377 PreferredSize(tw, &request.width, &request.height, &cw, &ch) ;
|
|
2378
|
|
2379 if( request.width == tw->core.width &&
|
|
2380 request.height == tw->core.height )
|
|
2381 return ;
|
|
2382
|
|
2383 result = XtMakeGeometryRequest(w, &request, &reply) ;
|
|
2384
|
|
2385 if( result == XtGeometryAlmost )
|
|
2386 {
|
|
2387 /* Bugger. Didn't get what we want, but were offered a
|
|
2388 * compromise. If the width was too small, recompute
|
|
2389 * based on the too-small width and try again.
|
|
2390 * If the height was too small, make a wild-ass guess
|
|
2391 * at a wider width and try again.
|
|
2392 */
|
|
2393
|
|
2394 if( reply.width < request.width && reply.height >= request.height )
|
|
2395 {
|
|
2396 Dimension s = SHADWID ;
|
|
2397 ch += s*2 ;
|
|
2398 PreferredSize3(tw, reply.width,ch, &request.width, &request.height);
|
|
2399 result = XtMakeGeometryRequest(w, &request, &reply) ;
|
|
2400 if( result == XtGeometryAlmost )
|
|
2401 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
|
|
2402 }
|
|
2403
|
|
2404 else
|
|
2405 (void) XtMakeGeometryRequest(w, &reply, NULL) ;
|
|
2406 }
|
|
2407 }
|
|
2408
|
|
2409
|
|
2410 static void
|
|
2411 getBitmapInfo(TabsWidget tw, TabsConstraints tab)
|
|
2412 {
|
|
2413 Window root ;
|
|
2414 int x,y ;
|
|
2415 unsigned int bw ;
|
|
2416
|
|
2417 if( tab->tabs.left_bitmap == None ||
|
|
2418 !XGetGeometry(XtDisplay(tw), tab->tabs.left_bitmap, &root, &x, &y,
|
434
|
2419 &tab->tabs.lbm_width, &tab->tabs.lbm_height,
|
428
|
2420 &bw, &tab->tabs.lbm_depth) )
|
|
2421 tab->tabs.lbm_width = tab->tabs.lbm_height = 0 ;
|
|
2422 }
|
|
2423
|
|
2424
|
|
2425
|
|
2426
|
|
2427 /* Code copied & modified from Gcs.c. This version has dynamic
|
|
2428 * foreground.
|
|
2429 */
|
|
2430
|
|
2431 static void
|
|
2432 TabsAllocFgGC(TabsWidget tw)
|
|
2433 {
|
|
2434 Widget w = (Widget) tw;
|
|
2435 XGCValues values ;
|
|
2436
|
3094
|
2437 values.background = tw->core.background_pixel;
|
|
2438 values.font =
|
|
2439 #ifdef USE_XFT_TABS
|
|
2440 None;
|
|
2441 #else
|
|
2442 tw->tabs.font->fid;
|
|
2443 #endif
|
|
2444 values.line_style = LineOnOffDash;
|
|
2445 values.line_style = LineSolid;
|
428
|
2446
|
|
2447 tw->tabs.foregroundGC =
|
|
2448 XtAllocateGC(w, w->core.depth,
|
3094
|
2449 #ifndef USE_XFT_TABS
|
|
2450 GCFont|
|
|
2451 #endif
|
|
2452 GCBackground|GCLineStyle,
|
|
2453 &values,
|
|
2454 GCForeground,
|
|
2455 #ifdef USE_XFT_TABS
|
|
2456 GCFont|
|
|
2457 #endif
|
|
2458 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
|
2459 GCDashList|GCArcMode);
|
428
|
2460 }
|
|
2461
|
|
2462 static void
|
|
2463 TabsAllocGreyGC(TabsWidget tw)
|
|
2464 {
|
|
2465 Widget w = (Widget) tw;
|
|
2466 XGCValues values ;
|
|
2467
|
3094
|
2468 values.background = tw->core.background_pixel;
|
|
2469 values.font =
|
|
2470 #ifdef USE_XFT_TABS
|
|
2471 None;
|
|
2472 #else
|
|
2473 tw->tabs.font->fid;
|
|
2474 #endif
|
428
|
2475 #ifdef HAVE_XMU
|
3094
|
2476 if (tw->tabs.be_nice_to_cmap || w->core.depth == 1)
|
428
|
2477 {
|
3094
|
2478 values.fill_style = FillStippled;
|
428
|
2479 tw->tabs.grey50 =
|
3094
|
2480 values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1);
|
428
|
2481
|
|
2482 tw->tabs.greyGC =
|
|
2483 XtAllocateGC(w, w->core.depth,
|
3094
|
2484 #ifndef USE_XFT_TABS
|
|
2485 GCFont|
|
|
2486 #endif
|
|
2487 GCBackground|GCStipple|GCFillStyle, &values,
|
428
|
2488 GCForeground,
|
3094
|
2489 #ifdef USE_XFT_TABS
|
|
2490 GCFont|
|
|
2491 #endif
|
428
|
2492 GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
3094
|
2493 GCDashList|GCArcMode);
|
428
|
2494 }
|
|
2495 else
|
|
2496 #endif
|
|
2497 {
|
|
2498 tw->tabs.greyGC =
|
|
2499 XtAllocateGC(w, w->core.depth,
|
3094
|
2500 #ifdef USE_XFT_TABS
|
|
2501 0L,
|
|
2502 #else
|
|
2503 GCFont,
|
|
2504 #endif
|
|
2505 &values,
|
428
|
2506 GCForeground,
|
3094
|
2507 #ifdef USE_XFT_TABS
|
|
2508 GCFont|
|
|
2509 #endif
|
428
|
2510 GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
|
3094
|
2511 GCDashList|GCArcMode);
|
428
|
2512 }
|
|
2513 }
|