Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtWidget / TitleBox.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: TitleBox.c /main/14 1996/10/14 10:48:11 pascale $
24  *
25  * (c) Copyright 1996 Digital Equipment Corporation.
26  * (c) Copyright 1990,1996 Hewlett-Packard Company.
27  * (c) Copyright 1996 International Business Machines Corp.
28  * (c) Copyright 1996 Sun Microsystems, Inc.
29  * (c) Copyright 1996 Novell, Inc. 
30  * (c) Copyright 1996 FUJITSU LIMITED.
31  * (c) Copyright 1996 Hitachi.
32  */
33
34 /**---------------------------------------------------------------------
35 ***     
36 ***     file:           TitleBox.c
37 ***
38 ***     project:        MotifPlus Widgets
39 ***
40 ***     description:    Source code for DtTitleBox class.
41 ***     
42 ***-------------------------------------------------------------------*/
43
44
45 /*-------------------------------------------------------------
46 **      Include Files
47 */
48
49 #include <Xm/LabelG.h>
50 #if RiversVersion == _31
51 #include <Xm/ManagerP.h>
52 #include <Xm/GadgetP.h>
53 #endif /* RiversVersion == _31 */
54 #include <Xm/DrawP.h>
55 #include <Dt/TitleBoxP.h>
56 #include <Dt/MacrosP.h>
57 #include <Dt/DtMsgsP.h>
58 #include "DtWidgetI.h"
59
60
61
62
63 /********    Public Function Declarations    ********/
64
65 extern Widget _DtCreateTitleBox( 
66                         Widget parent,
67                         char *name,
68                         ArgList arglist,
69                         Cardinal argcount) ;
70 extern Widget _DtTitleBoxGetTitleArea( 
71                         Widget w) ;
72 extern Widget _DtTitleBoxGetWorkArea( 
73                         Widget w) ;
74
75 #define Max(x, y)    (((x) > (y)) ? (x) : (y))
76 /********    End Public Function Declarations    ********/
77
78 /********    Static Function Declarations    ********/
79
80 static void ConfigureChildren( 
81                         DtTitleBoxWidget manager) ;
82 static void GetSize( 
83                         DtTitleBoxWidget manager,
84                         Dimension ta_w,
85                         Dimension ta_h,
86                         Dimension wa_w,
87                         Dimension wa_h,
88                         Dimension *w,
89                         Dimension *h) ;
90 static void GetTitleString( 
91                         DtTitleBoxWidget manager,
92                         XrmQuark resource,
93                         XtArgVal *value) ;
94 static void ClassInitialize( void ) ;
95 static void ClassPartInitialize( 
96                         WidgetClass wc) ;
97 static void Initialize( 
98                         DtTitleBoxWidget request,
99                         DtTitleBoxWidget new) ;
100 static void Destroy( 
101                         DtTitleBoxWidget manager) ;
102 static void Resize( 
103                         DtTitleBoxWidget manager) ;
104 static void Redisplay( 
105                         DtTitleBoxWidget manager,
106                         XEvent *event,
107                         Region region) ;
108 static Boolean SetValues( 
109                         DtTitleBoxWidget current,
110                         DtTitleBoxWidget request,
111                         DtTitleBoxWidget new) ;
112 static XtGeometryResult QueryGeometry( 
113                         DtTitleBoxWidget manager,
114                         XtWidgetGeometry *request,
115                         XtWidgetGeometry *reply) ;
116 static XtGeometryResult GeometryManager( 
117                         Widget kid,
118                         XtWidgetGeometry *request,
119                         XtWidgetGeometry *reply) ;
120 static void ChangeManaged( 
121                         DtTitleBoxWidget manager) ;
122 static void InsertChild( 
123                         Widget child) ;
124 static void ConstraintInitialize( 
125                         Widget request,
126                         Widget new) ;
127
128 /********    End Static Function Declarations    ********/
129
130 \f
131 /*-------------------------------------------------------------
132 **      Forward Declarations
133 */
134
135 #define UNSPECIFIED_CHAR        255
136 #define UNSPECIFIED_DIMENSION   9999
137 #define MARGIN_DEFAULT          10
138
139 #define WARN_CHILD_TYPE         _DtMsgDialogBox_0000
140 #define WARN_SHADOW_TYPE        _DtMsgIcon_0005
141 #define WARN_TITLE_POSITION     _DtMsgTitleBox_0000
142 #define WARN_TITLE_ALIGNMENT    _DtMsgTitleBox_0001
143
144 #define MESSAGE2                _DtMsgTitleBox_0002
145 #define MESSAGE3                _DtMsgTitleBox_0003
146 #define MESSAGE4                _DtMsgTitleBox_0004
147
148 extern void _DtRegisterNewConverters( void ) ;
149
150
151 /*-------------------------------------------------------------
152 **      Translations and Actions
153 */
154
155
156 \f
157 /*-------------------------------------------------------------
158 **      Resource List
159 */
160
161 /*      Define offset macros.
162 */
163 #define TB_Offset(field) \
164         XtOffset (DtTitleBoxWidget, title_box.field)
165 #define TBC_Offset(field) \
166         XtOffset (DtTitleBoxConstraintPtr, title_box_constraint.field)
167
168 static XtResource resources[] = 
169 {
170         {
171                 XmNshadowThickness,
172                 XmCShadowThickness, XmRShort, sizeof (short),
173                 XtOffset (DtTitleBoxWidget, manager.shadow_thickness),
174                 XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
175         },
176         {
177                 XmNmarginWidth,
178                 XmCMarginWidth, XmRHorizontalDimension, sizeof (Dimension),
179                 TB_Offset (margin_width),
180                 XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
181         },
182         {
183                 XmNmarginHeight,
184                 XmCMarginHeight, XmRVerticalDimension, sizeof (Dimension),
185                 TB_Offset (margin_height),
186                 XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
187         },
188         {
189                 XmNshadowType,
190                 XmCShadowType, XmRShadowType, sizeof (unsigned char),
191                 TB_Offset (shadow_type),
192                 XmRImmediate, (XtPointer) UNSPECIFIED_CHAR
193         },
194         {
195                 XmNtitleSpacing,
196                 XmCTitleSpacing, XmRHorizontalDimension, sizeof (Dimension),
197                 TB_Offset (title_spacing),
198                 XmRImmediate, (XtPointer) UNSPECIFIED_DIMENSION
199         },
200         {
201                 XmNtitlePosition,
202                 XmCTitlePosition, XmRTitlePosition, sizeof (unsigned char),
203                 TB_Offset (title_position), XmRImmediate, (XtPointer) XmTITLE_TOP
204         },
205         {
206                 XmNtitleAlignment,
207                 XmCAlignment, XmRAlignment, sizeof (unsigned char),
208                 TB_Offset (title_alignment),
209                 XmRImmediate, (XtPointer) XmALIGNMENT_BEGINNING
210         },
211         {
212                 XmNtitleString,
213                 XmCXmString, XmRXmString, sizeof (XmString),
214                 TB_Offset (title_string),
215                 XmRImmediate, (XtPointer) XmUNSPECIFIED_STRING
216         },
217         {
218                 XmNfontList,
219                 XmCFontList, XmRFontList, sizeof (XmFontList),
220                 TB_Offset (font_list), XmRImmediate, (XtPointer) NULL
221         }
222 };
223
224 /*      Synthetic Resources
225 */
226 static XmSyntheticResource syn_resources[] = 
227 {
228         {
229                 XmNtitleString, sizeof (XmString),
230                 TB_Offset (title_string),
231                 (XmExportProc) GetTitleString,
232                 (XmImportProc) NULL
233         },
234         {
235                 XmNmarginWidth, sizeof (Dimension),
236                 TB_Offset (margin_width),
237                 (XmExportProc) XmeFromHorizontalPixels,
238                 (XmImportProc) XmeToHorizontalPixels
239         },
240         {
241                 XmNmarginHeight, sizeof (Dimension),
242                 TB_Offset (margin_height),
243                 (XmExportProc) XmeFromVerticalPixels,
244                 (XmImportProc) XmeToVerticalPixels, 
245         }
246 };
247
248 /*      Constraint Resources
249 */
250 static XtResource constraints[] =
251 {
252         {
253                 XmNchildType,
254                 XmCChildType, XmRChildType, sizeof (unsigned char),
255                 TBC_Offset (child_type), XmRImmediate, (XtPointer) XmWORK_AREA
256         }
257 };
258
259 \f
260 /*-------------------------------------------------------------
261 **      Class Record
262 */
263 DtTitleBoxClassRec dtTitleBoxClassRec =
264 {
265 /*      Core Part
266 */
267         {       
268                 (WidgetClass) &xmManagerClassRec, /* superclass         */
269                 "DtTitleBox",                   /* class_name           */
270                 sizeof (DtTitleBoxRec), /* widget_size          */
271                 ClassInitialize,                /* class_initialize     */
272                 ClassPartInitialize,            /* class_part_initialize*/
273                 False,                          /* class_inited         */
274                 (XtInitProc) Initialize,        /* initialize           */
275                 NULL,                           /* initialize_hook      */
276                 XtInheritRealize,               /* realize              */
277                 NULL,                           /* actions              */
278                 0,                              /* num_actions          */
279                 resources,                      /* resources            */
280                 XtNumber (resources),           /* num_resources        */
281                 NULLQUARK,                      /* xrm_class            */
282                 True,                           /* compress_motion      */
283                 True,                           /* compress_exposure    */
284                 True,                           /* compress_enterleave  */
285                 False,                          /* visible_interest     */      
286                 (XtWidgetProc) Destroy,         /* destroy              */      
287                 (XtWidgetProc) Resize,          /* resize               */
288                 (XtExposeProc) Redisplay,       /* expose               */      
289                 (XtSetValuesFunc) SetValues,    /* set_values           */      
290                 NULL,                           /* set_values_hook      */
291                 XtInheritSetValuesAlmost,       /* set_values_almost    */
292                 NULL,                           /* get_values_hook      */
293                 NULL,                           /* accept_focus         */      
294                 XtVersion,                      /* version              */
295                 NULL,                           /* callback private     */
296                 XtInheritTranslations,          /* tm_table             */
297                 XtInheritQueryGeometry,         /* query_geometry       */
298                 NULL,                           /* display_accelerator  */
299                 NULL,                           /* extension            */
300         },
301
302 /*      Composite Part
303 */
304         {
305                 (XtGeometryHandler) GeometryManager,/* geometry_manager */
306                 (XtWidgetProc) ChangeManaged,   /* change_managed       */
307                 (XtWidgetProc) InsertChild,     /* insert_child         */
308                 XtInheritDeleteChild,           /* delete_child         */
309                 NULL,                           /* extension            */
310         },
311
312 /*      Composite Part
313 */
314         {
315                 constraints,                    /* constraint_resources */
316                 XtNumber (constraints),         /* num_constraint_resources */
317                 sizeof (DtTitleBoxConstraintRec), /* constraint_record  */
318                 (XtInitProc) ConstraintInitialize, /* constraint_initialize */
319                 NULL,                           /* constraint_destroy   */
320                 NULL,                           /* constraint_set_values */
321                 NULL,                           /* extension            */
322         },
323
324 /*      XmManager Part
325 */
326         {
327                 XtInheritTranslations,          /* default_translations */
328                 syn_resources,                  /* syn_resources        */
329                 XtNumber (syn_resources),       /* num_syn_resources    */
330                 NULL,                           /* syn_cont_resources   */
331                 0,                              /* num_syn_cont_resources */
332                 XmInheritParentProcess,         /* parent_process       */
333                 NULL,                           /* extension            */
334         },
335
336 /*      DtTitleBox Part
337 */
338         {
339                 NULL,                           /* extension            */
340         }
341 };
342
343 WidgetClass dtTitleBoxWidgetClass = (WidgetClass) &dtTitleBoxClassRec;
344
345
346 \f
347 /*-------------------------------------------------------------
348 **      Private Procs
349 **-------------------------------------------------------------
350 */
351
352 /*-------------------------------------------------------------------------
353 **      ConfigureChildren
354 **              Set positions and sizes of title and work area.
355 */
356 static void 
357 ConfigureChildren(
358         DtTitleBoxWidget manager )
359 {
360         Widget                  title_area = M_TitleArea (manager),
361                                 work_area = M_WorkArea (manager);
362         Position                ta_x = 0, ta_y = 0, wa_x = 0, wa_y = 0;
363         Dimension               ta_w = 0, ta_h = 0, ta_bw = 0,
364                                 wa_w = 0, wa_h = 0, wa_bw = 0,
365                                 w = M_Width (manager),
366                                 h = M_Height (manager),
367                                 s_t = M_ShadowThickness (manager),
368                                 m_w = M_MarginWidth (manager),
369                                 m_h = M_MarginHeight (manager),
370                                 ta_sp = M_TitleSpacing (manager);
371         Boolean                 title_top;
372         unsigned char           align = M_TitleAlignment (manager);
373         XtWidgetGeometry        ta_reply;
374
375         title_top = (M_TitlePosition (manager) == XmTITLE_TOP) ? True : False;
376
377 /*      Set position and size of title area.
378 */
379         if (title_area)
380         {
381                 XtQueryGeometry (title_area, NULL, &ta_reply);
382                 ta_w = ta_reply.width;
383                 ta_h = ta_reply.height;
384
385                 if (ta_w + 2U * ta_sp > (M_Width (manager) - 2U * ta_sp))
386                         ta_w = M_Width (manager) - 2 * ta_sp;
387                 if (ta_w == 0)
388                         ta_w = 10;
389                 if (ta_h == 0)
390                         ta_h = 10;
391
392                 if (align == XmALIGNMENT_BEGINNING)
393                         ta_x = ta_sp;
394                 else if (align == XmALIGNMENT_END)
395                         ta_x = w - ta_sp - ta_w;
396                 else
397                         ta_x = (w - ta_w) / 2U;
398
399                 ta_y = (title_top) ? 0 : h - ta_h;
400
401                 ta_bw = P_BorderWidth (title_area);
402                 XmeConfigureObject (title_area, ta_x, ta_y, ta_w, ta_h, ta_bw);
403         }
404
405 /*      Set position and size of work area.
406 */
407         if (work_area)
408         {
409                 wa_x = m_w + s_t;
410                 wa_y = (title_top) ? Max (s_t, ta_h) + m_h : s_t + m_h;
411                 wa_w = w - 2 * (m_w + s_t);
412                 if (wa_w == 0)
413                         wa_w = 10;
414                 wa_h = h - Max (s_t, ta_h) - s_t - 2 * m_h;
415                 if (wa_h == 0)
416                         wa_h = 10;
417                 wa_bw = P_BorderWidth (work_area);
418                 XmeConfigureObject (work_area,
419                                         wa_x, wa_y, wa_w, wa_h, wa_bw);
420         }
421 }
422
423
424 \f
425 /*-------------------------------------------------------------------------
426 **      GetSize
427 **              Calculate desired size based on children.
428 */
429 static void 
430 GetSize(
431         DtTitleBoxWidget manager,
432         Dimension ta_w,
433         Dimension ta_h,
434         Dimension wa_w,
435         Dimension wa_h,
436         Dimension *w,
437         Dimension *h )
438 {
439         Widget                  title_area = M_TitleArea (manager),
440                                 work_area = M_WorkArea (manager);
441         XtWidgetGeometry        ta_reply, wa_reply;
442         Dimension               s_t = M_ShadowThickness (manager),
443                                 m_w = M_MarginWidth (manager),
444                                 m_h = M_MarginHeight (manager),
445                                 ta_sp = M_TitleSpacing (manager);
446
447
448 /*      Optimize title area change if possible.
449 */
450         if (work_area && (wa_w == 0) && (wa_h == 0))
451         {
452                 if ((ta_w != 0) && (ta_h == 0))
453                 {
454                         if ((M_Width (manager) >=
455                                 M_Width (work_area) + (2U * ta_sp)) &&
456                             (M_Height (manager) >= Max (ta_h, s_t) +
457                                 M_Height (work_area) + s_t + (2U * m_h)))
458                         {
459                                 wa_w = M_Width (work_area);
460                                 wa_h = M_Height (work_area);
461                         }
462                 }
463
464                 if ((wa_w == 0) && (wa_h == 0))
465                 {       
466                         XtQueryGeometry (work_area, NULL, &wa_reply);
467                         wa_w = wa_reply.width;
468                         wa_h = wa_reply.height;
469                 }
470         }
471         if (title_area && (ta_w == 0) && (ta_h == 0))
472         {
473                 XtQueryGeometry (title_area, NULL, &ta_reply);
474                 ta_w = ta_reply.width;
475                 ta_h = ta_reply.height;
476         }
477
478         *w = Max (wa_w + (2U * (m_w + s_t)), ta_w + (2U * ta_sp));
479         if (*w == 0)
480                 *w = 10;
481         *h = Max (s_t, ta_h) + wa_h + (2 * m_h) + s_t;
482         if (*h == 0)
483                 *h = 10;
484 }
485
486
487 \f
488 /*-------------------------------------------------------------
489 **      GetTitleString
490 **              Get string from title label.
491 */
492 static void 
493 GetTitleString(
494         DtTitleBoxWidget manager,
495         XrmQuark resource,
496         XtArgVal *value )
497 {
498         Arg             al[10];         /*  arg list            */
499         register int    ac;             /*  arg count           */
500         Widget          title_area = M_TitleArea (manager);
501         XmString        string = NULL;
502
503         if (title_area)
504         {
505                 ac = 0;
506                 XtSetArg (al[ac], XmNlabelString, &string);  ac++;
507                 XtGetValues (title_area, al, ac);
508         }
509
510         *value = (XtArgVal) string;
511 }
512
513
514 \f
515 /*-------------------------------------------------------------
516 **      Action Procs
517 **-------------------------------------------------------------
518 */
519
520
521 /*-------------------------------------------------------------
522 **      Core Procs
523 **-------------------------------------------------------------
524 */
525
526 /*-------------------------------------------------------------------------
527 **      ClassInitialize
528 **              Initialize widget class.
529 */
530 static void 
531 ClassInitialize( void )
532 {
533         _DtRegisterNewConverters ();
534 }
535
536
537 /*-------------------------------------------------------------------------
538 **      ClassPartInitialize
539 **              Initialize widget class data.
540 */
541 static void 
542 ClassPartInitialize(
543         WidgetClass wc )
544 {
545 }
546
547
548 \f
549 /*-------------------------------------------------------------
550 **      Initialize
551 **              Initialize a new widget instance.
552 */
553 static void 
554 Initialize(
555         DtTitleBoxWidget request,
556         DtTitleBoxWidget new )
557 {
558         Arg             al[10];         /*  arg list            */
559         register int    ac;             /*  arg count           */
560         Widget          title = NULL;
561         XmString        title_string = NULL;
562
563 /*      Check for unspecified dimensions.
564 */
565         if (M_MarginWidth (request) == UNSPECIFIED_DIMENSION)
566                 M_MarginWidth (new) = MARGIN_DEFAULT;
567         if (M_MarginHeight (request) == UNSPECIFIED_DIMENSION)
568                 M_MarginHeight (new) = MARGIN_DEFAULT;
569         if (M_TitleSpacing (request) == UNSPECIFIED_DIMENSION)
570                 M_TitleSpacing (new) = UNSPECIFIED_DIMENSION;
571         if (M_ShadowThickness (new) == UNSPECIFIED_DIMENSION)
572         {
573                 if (XtIsShell (XtParent (new)))
574                         M_ShadowThickness (new) = 1;
575                 else
576                         M_ShadowThickness (new) = 2;
577         }
578
579 /*      Validate shadow type.
580 */
581         if (M_ShadowType (new) == UNSPECIFIED_CHAR)
582         {
583                 if (XtIsShell (XtParent (new)))
584                         M_ShadowType (new) = XmSHADOW_OUT;
585                 else
586                         M_ShadowType (new) = XmSHADOW_ETCHED_IN;
587         }
588         else if (M_ShadowType (new) != XmSHADOW_IN &&
589                  M_ShadowType (new) != XmSHADOW_OUT &&
590                  M_ShadowType (new) != XmSHADOW_ETCHED_IN &&
591                  M_ShadowType (new) != XmSHADOW_ETCHED_OUT)
592         {
593               XmeWarning ((Widget)new, WARN_SHADOW_TYPE);
594         }
595
596 /*      Validate title position.
597 */
598         if (M_TitlePosition (new) != XmTITLE_TOP &&
599             M_TitlePosition (new) != XmTITLE_BOTTOM)
600         {
601                 XmeWarning ((Widget)new, WARN_TITLE_POSITION);
602         }
603
604 /*      Validate title alignment.
605 */
606         if (M_TitleAlignment (new) != XmALIGNMENT_BEGINNING &&
607             M_TitleAlignment (new) != XmALIGNMENT_CENTER &&
608             M_TitleAlignment (new) != XmALIGNMENT_END)
609         {
610                 XmeWarning ((Widget)new, WARN_TITLE_ALIGNMENT);
611         }
612
613 /*      Check width and height.
614 */
615         if (M_Width (new) == 0)
616         {
617                 M_Width (new) = 2 * (M_ShadowThickness (new) +
618                                         M_MarginWidth (new));
619                 if (M_Width (new) == 0)
620                         M_Width (new) = 10;
621         }
622         if (M_Height (new) == 0)
623         {
624                 M_Height (new) = 2 * (M_ShadowThickness (new) +
625                                         M_MarginHeight (new));
626                 if (M_Height (new) == 0)
627                         M_Height (new) = 10;
628         }
629
630         M_OldWidth (new) = M_Width (new);
631         M_OldHeight (new) = M_Height (new);
632         M_OldShadowThickness (new) = M_ShadowThickness (new);
633
634
635         M_WorkArea (new) = NULL;
636
637 /*      Create title_area unless title explicitly set to null;
638 *       use name if unspecified.
639 */
640         if (! M_TitleString (new))
641         {
642                 M_TitleArea (new) = NULL;
643                 return;
644         }
645
646         if (M_TitleString (new) == XmUNSPECIFIED_STRING && M_Name (new))
647         {
648                 M_TitleString (new) = XmStringCreateLocalized(M_Name (new));
649                 title_string = M_TitleString (new);
650         }
651         ac = 0;
652         XtSetArg (al[ac], XmNchildType, XmTITLE_AREA);  ac++;
653         XtSetArg (al[ac], XmNmarginWidth, 2);  ac++;
654         XtSetArg (al[ac], XmNmarginHeight, 0);  ac++;
655         XtSetArg (al[ac], XmNshadowThickness, 0);  ac++;
656         XtSetArg (al[ac], XmNhighlightThickness, 0);  ac++;
657         XtSetArg (al[ac], XmNlabelString, M_TitleString (new));  ac++;
658         if (M_FontList (new))
659         {
660                 XtSetArg (al[ac], XmNfontList, M_FontList (new));
661                 ac++;
662         }
663         title = XmCreateLabelGadget ((Widget)new, "title", al, ac);
664         M_TitleArea (new) = title;
665         XtManageChild (title);
666
667         if (M_TitleSpacing (new) == UNSPECIFIED_DIMENSION)
668                 M_TitleSpacing (new) =
669                         Max (P_Height (title)/2U, M_ShadowThickness (new));
670
671         M_TitleString (new) = XmUNSPECIFIED_STRING;
672         M_FontList (new) = NULL;
673         if (title_string != NULL)
674                 XmStringFree (title_string);
675 }
676
677
678 /*-------------------------------------------------------------
679 **      Destroy
680 **              Release resources allocated for widget instance.
681 */
682 static void 
683 Destroy(
684         DtTitleBoxWidget manager )
685 {
686         /*      Superclass does all the work so far.
687         */
688 }
689
690
691 \f
692 /*-------------------------------------------------------------
693 **      Resize
694 **              Update size of children.
695 */
696 static void 
697 Resize(
698         DtTitleBoxWidget manager )
699 {
700         Widget          title_area = M_TitleArea (manager);
701         Dimension       s_t = M_OldShadowThickness (manager),
702                         w = M_OldWidth (manager),
703                         h = M_OldHeight (manager);
704         Position        y;
705
706 /*      Clear shadow and save shadow data.
707 */
708         if (XtIsRealized ((Widget)manager))
709         {
710                 _XmClearShadowType ((Widget)manager, w, h, s_t, 0);
711
712                 if ((M_TitlePosition (manager) == XmTITLE_BOTTOM) &&
713                     (M_Height (manager) > h))
714                 {
715                         y = h - P_Height (title_area);
716                         XClearArea (XtDisplay (manager), XtWindow (manager),
717                                         0, y, M_Width (manager),
718                                         M_Height (manager) - y, False);
719                 }                       
720         }
721                                 
722         M_OldWidth (manager) = M_Width (manager);
723         M_OldHeight (manager) = M_Height (manager);
724         M_OldShadowThickness (manager) = M_ShadowThickness (manager);
725
726         ConfigureChildren (manager);
727
728 /*      Draw shadow and title.
729 */
730         if (XtIsRealized ((Widget)manager))
731                 Redisplay (manager, NULL, NULL);
732 }
733
734
735 \f
736 /*-------------------------------------------------------------
737 **      Redisplay
738 **              Redisplay widget.
739 */
740 static void 
741 Redisplay(
742         DtTitleBoxWidget manager,
743         XEvent *event,
744         Region region )
745 {
746         Widget          title_area = M_TitleArea (manager),
747                         work_area = M_WorkArea (manager);
748         Position        title_x = M_X (title_area),
749                         title_y = M_Y (title_area);
750         Dimension       title_width = M_Width (title_area),
751                         title_height = M_Height (title_area);
752
753         Display *       d =             XtDisplay (manager);
754         Dimension       w =             M_Width (manager),
755                         h =             M_Height (manager),
756                         s_t =           M_ShadowThickness (manager);
757
758         GC              top_gc =        NULL,
759                         bottom_gc =     NULL,
760                         fill_gc =       NULL;
761         Boolean         s_out =         False,
762                         s_etched =      False;
763         Drawable        drawable =      XtWindow (manager);
764         Position        x = 0,
765                         y = title_height / 2 - s_t / 2;
766
767 /*      Redisplay work area.
768 */
769         if (work_area && XmIsGadget (work_area) && XtIsManaged (work_area))
770         {
771                 XtExposeProc expose;
772                 _DtProcessLock();
773                 expose = XtCoreProc(work_area, expose);
774                 _DtProcessUnlock();
775
776                 (*expose) (work_area, event, region);
777         }
778
779 /*      Draw shadow.
780 */
781         if (M_ShadowThickness (manager) > 0)
782         {
783                 h -= y;
784                 if (M_TitlePosition (manager) == XmTITLE_BOTTOM)
785                         y = 0;
786                 XmeDrawShadows(d, XtWindow(manager),
787                                M_TopShadowGC(manager),
788                                M_BottomShadowGC(manager),
789                                x, y, w, h, s_t, M_ShadowType(manager));
790         }
791
792 /*      Redisplay title area.
793 */      
794         if (title_area && XtIsManaged (title_area))
795         {               
796                 XClearArea (d, XtWindow (manager), title_x, title_y,
797                                 title_width, title_height, False);
798                 if (XmIsGadget (title_area))
799                 {
800                         XtExposeProc expose;
801                         _DtProcessLock();
802                         expose = XtCoreProc(title_area, expose);
803                         _DtProcessUnlock();
804
805                         (*expose) (title_area, event, region);
806                 }
807         }
808
809 }
810
811
812 \f
813 /*-------------------------------------------------------------
814 **      SetValues
815 **              Handle changes in resource data.
816 */
817
818
819 static Boolean 
820 SetValues(
821         DtTitleBoxWidget current,
822         DtTitleBoxWidget request,
823         DtTitleBoxWidget new )
824 {
825         Widget          title = M_TitleArea (new);
826         Boolean         redisplay_flag = False,
827                         new_title = False,
828                         new_font = False;
829         Arg             al[10];         /*  arg list            */
830         register int    ac;             /*  arg count           */
831
832 /*      Validate title position.
833 */
834         if (M_TitlePosition (new) != M_TitlePosition (current) &&
835             M_TitlePosition (new) != XmTITLE_TOP &&
836             M_TitlePosition (new) != XmTITLE_BOTTOM)
837         {
838                 XmeWarning ((Widget)new, WARN_TITLE_POSITION);
839                 M_TitlePosition (new) = M_TitlePosition (current);
840         }
841
842 /*      Validate title alignment.
843 */
844         if (M_TitleAlignment (new) != M_TitleAlignment (current) &&
845             M_TitleAlignment (new) != XmALIGNMENT_BEGINNING &&
846             M_TitleAlignment (new) != XmALIGNMENT_CENTER &&
847             M_TitleAlignment (new) != XmALIGNMENT_END)
848         {
849                 XmeWarning ((Widget)new, WARN_TITLE_ALIGNMENT);
850                 M_TitleAlignment (new) = M_TitleAlignment (current);
851         }
852
853 /*      Validate shadow type.
854 */
855         if (M_ShadowType (new) != M_ShadowThickness (current) &&
856             M_ShadowType (new) != XmSHADOW_IN &&
857             M_ShadowType (new) != XmSHADOW_OUT &&
858             M_ShadowType (new) != XmSHADOW_ETCHED_IN &&
859             M_ShadowType (new) != XmSHADOW_ETCHED_OUT)
860         {
861                 XmeWarning ((Widget)new, WARN_SHADOW_TYPE);
862                 M_ShadowType (new) = M_ShadowThickness (current);
863         }
864
865 /*      Check for redisplay; query and update kids if no resize.
866 */
867         if (M_MarginWidth (new) != M_MarginWidth (current) ||
868             M_MarginHeight (new) != M_MarginHeight (current) ||
869             M_ShadowThickness (new) != M_ShadowThickness (current))
870         {
871                 redisplay_flag = True;
872                 if (M_Width (new) == M_Width (current) &&
873                     M_Height (new) == M_Height (current))
874                 {
875                         GetSize (new, 0, 0, 0, 0,
876                                 &(M_Width (new)), &(M_Height (new)));
877                         ConfigureChildren (new);
878                 }
879         }
880
881         else if (M_TitleSpacing (new) != M_TitleSpacing (current) ||
882                  M_TitlePosition (new) != M_TitlePosition (current) ||
883                  M_TitleAlignment (new) != M_TitleAlignment (current))
884         {
885                 redisplay_flag = True;
886                 ConfigureChildren (new);
887         }
888         else if (M_ShadowType (new) != M_ShadowThickness (current))
889         {
890                 redisplay_flag = True;
891         }
892
893 /*      Update title if string or font changed.
894 */
895         ac = 0;
896         if (M_TitleString (current) != M_TitleString (new))
897         {
898                 new_title = True;
899                 XtSetArg (al[ac], XmNlabelString, M_TitleString (new));  ac++;
900         }
901         if (M_FontList (current) != M_FontList (new))
902         {
903                 new_font = True;
904                 XtSetArg (al[ac], XmNfontList, M_FontList (new));
905                 ac++;
906         }
907         if (ac && title)
908         {
909                 XtSetValues (title, al, ac);
910                 if (new_title)
911                         M_TitleString (new) = XmUNSPECIFIED_STRING;
912                 if (new_font)
913                         M_FontList (new) = NULL;
914                 redisplay_flag = True;
915         }
916
917         return (redisplay_flag);
918 }
919
920
921 \f
922 /*-------------------------------------------------------------
923 **      QueryGeometry
924 **              Handle query geometry request.
925 */
926 static XtGeometryResult 
927 QueryGeometry(
928         DtTitleBoxWidget manager,
929         XtWidgetGeometry *request,
930         XtWidgetGeometry *reply )
931 {
932         Position        x = M_X (manager),
933                         y = M_Y (manager);
934         Dimension       w = M_Width (manager),
935                         h = M_Height (manager),
936                         bw = M_BorderWidth (manager),
937                         new_w = 0,
938                         new_h = 0;
939         Boolean         x_req = request->request_mode & CWX,
940                         y_req = request->request_mode & CWY,
941                         width_req = request->request_mode & CWWidth,
942                         height_req = request->request_mode & CWHeight,
943                         bw_req = request->request_mode & CWBorderWidth;
944
945 /*      Compute preferred size if preferred width or height requested.
946 */
947         if (width_req || height_req)
948                 GetSize (manager, 0, 0, 0, 0, &new_w, &new_h);
949
950 /*      Load reply.
951 */
952         reply->request_mode = request->request_mode;
953         reply->x = request->x;
954         reply->y = request->y;
955         reply->width = (width_req) ? new_w : request->width;
956         reply->height = (height_req) ? new_h : request->height;
957         reply->border_width = request->border_width;
958
959 /*      If no change return no; otherwise yes.
960 */
961         if ((!width_req || (width_req && w == new_w)) &&
962             (!height_req || (height_req && h == new_h)))
963                 return (XtGeometryNo);
964         else
965                 return (XtGeometryYes);         
966 }
967
968
969 \f
970 /*-------------------------------------------------------------
971 **      Composite Procs
972 **-------------------------------------------------------------
973 */
974
975 /*-------------------------------------------------------------
976 **      GeometryManager
977 **              Handle geometry request from title area or work area.
978 */
979 static XtGeometryResult 
980 GeometryManager(
981         Widget kid,
982         XtWidgetGeometry *request,
983         XtWidgetGeometry *reply )
984 {
985         DtTitleBoxWidget        manager = (DtTitleBoxWidget) XtParent (kid);
986         Widget          title_area = M_TitleArea (manager),
987                         work_area = M_WorkArea (manager);
988         Dimension       ta_w = 0, ta_h = 0, ta_bw = 0,
989                         wa_w = 0, wa_h = 0,
990                         w = M_Width (manager),
991                         h = M_Height (manager),
992                         sp = M_TitleSpacing (manager);
993         Boolean         query_only = request->request_mode & XtCWQueryOnly,
994                         x_req = request->request_mode & CWX,
995                         y_req = request->request_mode & CWY,
996                         width_req = request->request_mode & CWWidth,
997                         height_req = request->request_mode & CWHeight,
998                         bw_req = request->request_mode & CWBorderWidth,
999                         almost = False;
1000         XtGeometryResult        result, parent_result;
1001         XtWidgetGeometry        parent_req, parent_reply;
1002         
1003
1004 /*      Check for width, height, and borderwidth requests.
1005 */
1006         if (!width_req && !height_req)
1007         {
1008                 if (x_req || y_req)
1009                         return (XtGeometryNo);
1010                 else
1011                         return (XtGeometryYes);
1012         }
1013         else
1014         {
1015                 if (x_req || y_req)
1016                         almost = True;
1017         }
1018
1019 /*      Compute desired size.
1020 */
1021         if (kid == title_area)
1022         {
1023                 ta_w = (width_req) ? request->width : P_Width (kid);
1024                 ta_h = (height_req) ? request->height : P_Height (kid);
1025                 ta_bw = (bw_req) ? request->border_width : P_BorderWidth (kid);
1026         }
1027         else
1028         {
1029                 wa_w = (width_req) ? request->width : P_Width (kid);
1030                 wa_h = (height_req) ? request->height : P_Height (kid);
1031         }
1032
1033         GetSize (manager, ta_w, ta_h, wa_w, wa_h, &w, &h);
1034
1035 /*      Request change from parent if necessary.
1036 */
1037         if (w != M_Width (manager) || h != M_Height (manager))
1038         {
1039                 parent_req.request_mode = CWWidth | CWHeight;
1040                 parent_req.width = w;
1041                 parent_req.height = h;
1042                 if (almost || query_only)
1043                         parent_req.request_mode |= XtCWQueryOnly;
1044                 parent_result =
1045                         XtMakeGeometryRequest ((Widget)manager, &parent_req,
1046                                         &parent_reply);
1047                 if (kid == (Widget) title_area)
1048                         parent_result = XtGeometryYes;
1049         }
1050         else
1051                 parent_result = XtGeometryYes;
1052
1053 /*      Reply to kid based on reply from parent.
1054 */
1055         switch ((int) parent_result)
1056         {
1057                 case XtGeometryYes:
1058                         if (query_only)
1059                                 result = XtGeometryYes;
1060                         else if (!almost)
1061                         {
1062                                 XtWidgetProc resize;
1063                                 if (kid == title_area)
1064                                       XmeConfigureObject (title_area,
1065                                              title_area->core.x,
1066                                              title_area->core.y,
1067                                              ta_w, ta_h, ta_bw);
1068                                 _DtProcessLock();
1069                                 resize = XtCoreProc(XtParent(kid), resize);
1070                                 _DtProcessUnlock();
1071                                 (*resize) (XtParent (kid));
1072                                 result = XtGeometryDone;
1073                         }
1074                         else
1075                         {
1076                                 result = XtGeometryNo;
1077                         }
1078                         break;
1079                 case XtGeometryAlmost:
1080                 case XtGeometryNo:
1081                         result = XtGeometryNo;
1082                         break;
1083         }
1084
1085         return (result);
1086 }
1087
1088
1089 /*-------------------------------------------------------------
1090 **      ChangeManaged
1091 **              Handle change in set of managed children.
1092 */
1093 static void 
1094 ChangeManaged(
1095         DtTitleBoxWidget manager )
1096 {
1097         Dimension       w = M_Width (manager),
1098                         h = M_Height (manager);
1099
1100 /*      Compute desired size.
1101 */
1102         GetSize (manager, 0, 0, 0, 0, &w, &h);
1103
1104 /*      Try to change size to fit children
1105 */
1106         if (w != M_Width (manager) || h != M_Height (manager))
1107         {
1108                 switch (XtMakeResizeRequest ((Widget) manager, w, h, &w, &h))
1109                 {
1110                         case XtGeometryAlmost:
1111                                 XtMakeResizeRequest ((Widget) manager, w, h,
1112                                         NULL, NULL);
1113                         case XtGeometryYes:
1114                         case XtGeometryNo:
1115                         default:
1116                                 break;
1117                 }
1118         }
1119         
1120 /*      Set positions and sizes of children.
1121 */
1122         ConfigureChildren (manager);
1123         XmeNavigChangeManaged ((Widget)manager);
1124 }
1125
1126
1127 \f
1128 /*-------------------------------------------------------------
1129 **      InsertChild
1130 **              Add a child.
1131 */
1132 static void 
1133 InsertChild(
1134         Widget child )
1135 {
1136         DtTitleBoxConstraint    constraint = (DtTitleBoxConstraint)
1137                                         M_TitleBoxConstraint (child);
1138         DtTitleBoxWidget        w;
1139         XmManagerWidgetClass    mc = (XmManagerWidgetClass)
1140                                                 xmManagerWidgetClass;
1141         unsigned char           child_type;
1142         XtWidgetProc            insert_child;
1143
1144         _DtProcessLock();
1145         insert_child = mc->composite_class.insert_child;
1146         _DtProcessUnlock();
1147         (* insert_child) (child);
1148
1149         w = (DtTitleBoxWidget) XtParent (child);
1150         
1151         if (constraint->child_type == XmWORK_AREA)
1152         {
1153                 if (! M_WorkArea (w))
1154                 {
1155                         M_WorkArea (w) = child;
1156                 }
1157         }
1158         else if (constraint->child_type == XmTITLE_AREA)
1159         {
1160                 if (! M_TitleArea (w))
1161                 {
1162                         M_TitleArea (w) = child;
1163                 }
1164         }
1165 }
1166
1167
1168 \f 
1169 /*-------------------------------------------------------------
1170 **      Constraint Procs
1171 **-------------------------------------------------------------
1172 */
1173 /*-------------------------------------------------------------
1174 **      ConstraintInitialize
1175 **              Add a child.
1176 */
1177 static void 
1178 ConstraintInitialize(
1179         Widget request,
1180         Widget new )
1181 {
1182         DtTitleBoxWidget        manager = (DtTitleBoxWidget) XtParent (new);
1183         DtTitleBoxConstraint    constraint = M_TitleBoxConstraint (new);
1184
1185 /*      Validate child type.
1186 */
1187         if (constraint->child_type != XmWORK_AREA &&
1188             constraint->child_type != XmTITLE_AREA)
1189         {
1190                 XmeWarning (new, WARN_CHILD_TYPE);
1191                 if (! M_WorkArea (manager))
1192                 {
1193                         constraint->child_type = XmWORK_AREA;
1194                 }
1195                 else if (! M_TitleArea (manager))
1196                 {
1197                         constraint->child_type = XmTITLE_AREA;
1198                 }
1199         }
1200 }
1201
1202
1203 /*-------------------------------------------------------------
1204 **      Manager Procs
1205 **-------------------------------------------------------------
1206 */
1207 /*      All inherited from superclass.
1208 */
1209
1210
1211 \f
1212 /*-------------------------------------------------------------
1213 **      Public Entry Points
1214 **-------------------------------------------------------------
1215 */
1216
1217 /*-------------------------------------------------------------
1218 **      _DtCreateTitleBox
1219 **              Create a new DtTitleBox instance.
1220 **-------------------------------------------------------------
1221 */
1222 Widget 
1223 _DtCreateTitleBox(
1224         Widget parent,
1225         char *name,
1226         ArgList arglist,
1227         Cardinal argcount )
1228 {
1229         return (XtCreateWidget (name, dtTitleBoxWidgetClass, 
1230                         parent, arglist, argcount));
1231 }
1232
1233
1234 /*-------------------------------------------------------------
1235 **      _DtTitleBoxGetTitleArea
1236 **              Return TitleBox title area;
1237 **-------------------------------------------------------------
1238 */
1239 Widget 
1240 _DtTitleBoxGetTitleArea(
1241         Widget w )
1242 {
1243         DtTitleBoxWidget        mgr =   (DtTitleBoxWidget) w;
1244         Widget                  rtn_w = M_TitleArea (mgr);
1245
1246         return (rtn_w);
1247 }
1248
1249
1250 /*-------------------------------------------------------------
1251 **      _DtTitleBoxGetWorkArea
1252 **              Return TitleBox work area;
1253 **-------------------------------------------------------------
1254 */
1255 Widget 
1256 _DtTitleBoxGetWorkArea(
1257         Widget w )
1258 {
1259         DtTitleBoxWidget        mgr =   (DtTitleBoxWidget) w;
1260         Widget                  rtn_w = M_WorkArea (mgr);
1261
1262         return (rtn_w);
1263 }