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