1 /*----------------------------------------------------------------------------
2 --
3 --  Module:           xitColorSelect
4 --
5 --  Project:          xit   - X Internal Toolkit
6 --  System:           <>
7 --    Subsystem:      <>
8 --    Function block: <>
9 --
10 --  Description:
11 --    The field select widget contains a single line Text widget. To the
12 --    right of the field there is a button. By clicking on the button,
13 --    a menu with colors is presented. If a color is selected from the menu,
14 --    the background of the text field is changed to the selected color.
15 --
16 --  Filename:         xitColorSel.c
17 --
18 --  Authors:          Roger Larsson, Ulrika Bornetun
19 --  Creation date:    1992-05-28
20 --
21 --
22 --  (C) Copyright Ulrika Bornetun, Roger Larsson (1995)
23 --      All rights reserved
24 --
25 --  Permission to use, copy, modify, and distribute this software and its
26 --  documentation for any purpose and without fee is hereby granted,
27 --  provided that the above copyright notice appear in all copies. Ulrika
28 --  Bornetun and Roger Larsson make no representations about the usability
29 --  of this software for any purpose. It is provided "as is" without express
30 --  or implied warranty.
31 ----------------------------------------------------------------------------*/
32 
33 /* SCCS module identifier. */
34 static char SCCSID[] = "@(#) Module: xitColorSel.c, Version: 1.1, Date: 95/02/18 15:10:21";
35 
36 
37 /*----------------------------------------------------------------------------
38 --  Include files
39 ----------------------------------------------------------------------------*/
40 
41 #include <stdio.h>
42 
43 #include <X11/Intrinsic.h>
44 
45 #include <Xm/Xm.h>
46 #include <Xm/ArrowB.h>
47 #include <Xm/CascadeB.h>
48 #include <Xm/DrawnB.h>
49 #include <Xm/DrawingA.h>
50 #include <Xm/PushB.h>
51 #include <Xm/PushBG.h>
52 #include <Xm/RowColumn.h>
53 #include <Xm/Text.h>
54 
55 #include "System.h"
56 
57 #include "xitTools.h"
58 #include "xitColorSel.h"
59 
60 
61 /*----------------------------------------------------------------------------
62 --  Macro definitions
63 ----------------------------------------------------------------------------*/
64 
65 
66 /*----------------------------------------------------------------------------
67 --  Type declarations
68 ----------------------------------------------------------------------------*/
69 
70 /* Record associated with the widget. */
71 typedef struct {
72   XtPointer       client_data;
73   int             columns;
74   int             elements;
75   int             item_selected;
76   int             max_length;
77   Dimension       button_width;
78   Dimension       text_width;
79   Widget          field;
80   Widget          menu;
81   Widget          menuBr;
82   Widget          select_button;
83   XmString        select_string;
84   String          *list;
85   XtCallbackProc  call_proc;
86 } SelectRec, *SelectRecPtr;
87 
88 
89 
90 /*----------------------------------------------------------------------------
91 --  Global definitions
92 ----------------------------------------------------------------------------*/
93 
94 /* Resource list for items. */
95 static XtResource  item_resources[] = {
96 
97   { XmNlabelString, XmCLabelString, XmRXmString, sizeof( XmString ),
98     XtOffset( SelectRecPtr, select_string ),
99     XmRString, "-" },
100 
101   { XmNcolumns, XmCColumns, XmRInt, sizeof( int ),
102     XtOffset( SelectRecPtr, columns ),
103     XmRString, "10" },
104 
105   { XmNitems, XmCItems, XmRStringTable, sizeof( String * ),
106     XtOffset( SelectRecPtr, list ),
107     XmRImmediate, NULL },
108 
109   { XmNitemCount, XmCItemCount, XmRInt, sizeof( int ),
110     XtOffset( SelectRecPtr, elements ),
111     XmRString, "0" },
112 
113 };
114 
115 
116 /*----------------------------------------------------------------------------
117 --  Function prototypes
118 ----------------------------------------------------------------------------*/
119 
120 static void
121   callCallback( SelectRecPtr  rec,
122                 XEvent        *event );
123 
124 static void
125   destroyCB( Widget        widget,
126              SelectRecPtr  rec,
127              XtPointer     call_data );
128 
129 static void
130   getColorInfo( SelectRecPtr  rec,
131                 Pixel         *pixel,
132                 XColor        *color,
133                 char          *rgb_string );
134 
135 static void
136   menuSelectCB( Widget                     widget,
137                 SelectRecPtr               rec,
138                 XmRowColumnCallbackStruct  *call_data );
139 
140 static void
141   resizeCB( Widget               widget,
142             SelectRecPtr         rec,
143             XmAnyCallbackStruct  *call_data );
144 
145 
146 
147 /*----------------------------------------------------------------------------
148 --  Functions
149 ----------------------------------------------------------------------------*/
150 
151 Widget
xitCreateColorSelect(Widget parent,String name,ArgList add_args,Cardinal num_args,XtCallbackProc proc,XtPointer client_data)152   xitCreateColorSelect( Widget          parent,
153                         String          name,
154                         ArgList         add_args,
155                         Cardinal        num_args,
156                         XtCallbackProc  proc,
157                         XtPointer       client_data )
158 {
159 
160   /* Variables. */
161   Boolean        ok;
162   int            index;
163   char           buffer[ 50 ];
164   Arg            args[ 6 ];
165   ArgList        merge_args;
166   Cardinal       n;
167   Dimension      select_height;
168   Dimension      text_height;
169   Dimension      text_width;
170   Pixel          bottom_color;
171   Pixel          color;
172   Pixel          top_color;
173   SelectRecPtr   rec;
174   Widget         manager;
175   Widget         menuPb;
176   XmString       xstr;
177 
178   static XIT_TEXT_STRUCT text_buffer[] = {
179     { "",  NULL, 1, True },
180   };
181 
182 
183   /* Code. */
184 
185   /* Initialize widget record, used in callbacks. */
186   rec = SysNew( SelectRec );
187 
188   rec -> call_proc   = proc;
189   rec -> client_data = client_data;
190 
191   /* Drawing area as manager. */
192   n = 0;
193   XtSetArg( args[ n ], XmNmarginHeight, 0 ); n++;
194   XtSetArg( args[ n ], XmNmarginWidth,  0 ); n++;
195   XtSetArg( args[ n ], XmNuserData,     rec ); n++;
196   manager = XmCreateDrawingArea( parent, name, args, n );
197 
198   XtAddCallback( manager, XmNresizeCallback,
199                  (XtCallbackProc) resizeCB, (XtPointer) rec );
200   XtAddCallback( manager, XmNdestroyCallback,
201                  (XtCallbackProc) destroyCB, (XtPointer) rec );
202 
203 
204   /* Initialize the rest of the callback record. */
205   XtGetSubresources( manager, (XtPointer) rec, name, COLOR_SELECT_CLASS,
206                      item_resources, XtNumber( item_resources ),
207                      add_args, num_args );
208 
209 
210   /* Text display. */
211   sprintf( buffer, "%sTx", name );
212 
213   text_buffer[ 0 ].name = buffer;
214   rec -> field = xitCreateText( manager, &text_buffer[ 0 ] );
215 
216   n = 0;
217   XtSetArg( args[ n ], XmNeditMode, XmSINGLE_LINE_EDIT ); n++;
218   XtSetArg( args[ n ], XmNrecomputeSize, False ); n++;
219   XtSetArg( args[ n ], XmNeditable, False ); n++;
220   XtSetArg( args[ n ], XmNcursorPositionVisible, False ); n++;
221   XtSetArg( args[ n ], XmNmaxLength, rec -> columns ); n++;
222   XtSetArg( args[ n ], XmNcolumns, (short ) rec -> columns ); n++;
223 
224   merge_args = XtMergeArgLists( add_args, num_args, args, n );
225 
226   XtSetValues( rec -> field, merge_args, num_args + n );
227 
228   XtManageChild( rec -> field );
229 
230   SysFree( merge_args );
231 
232 
233   /* Swap bottom and top shadow colors. */
234   n = 0;
235   XtSetArg( args[ n ], XmNtopShadowColor,    &top_color ); n++;
236   XtSetArg( args[ n ], XmNbottomShadowColor, &bottom_color ); n++;
237   XtGetValues( rec -> field, args, n );
238 
239   n = 0;
240   XtSetArg( args[ n ], XmNtopShadowColor,    bottom_color ); n++;
241   XtSetArg( args[ n ], XmNbottomShadowColor, top_color ); n++;
242   XtSetValues( rec -> field, args, n );
243 
244 
245   /* Create the menubar and menu cascades. */
246   sprintf( buffer, "%sBr", name );
247 
248   n = 0;
249   XtSetArg( args[ n ], XmNmarginWidth,     0 ); n++;
250   XtSetArg( args[ n ], XmNmarginHeight,    0 ); n++;
251   rec -> menuBr = XmCreateMenuBar( manager, buffer, args, n );
252 
253   XtManageChild( rec -> menuBr );
254 
255 
256   /* Create the pull-down menu to use. */
257   sprintf( buffer, "%sPd", name );
258 
259   n = 0;
260   rec -> menu = XmCreatePulldownMenu( rec -> menuBr, buffer, args, n );
261 
262   XtAddCallback( rec -> menu, XmNentryCallback,
263                  (XtCallbackProc) menuSelectCB, (XtPointer) rec );
264 
265 
266   /* The cascade button. */
267   sprintf( buffer, "%sCa", name );
268 
269   if( rec -> select_string == NULL )
270     xstr = XmStringCreate( "-", CS );
271   else
272     xstr = rec -> select_string;
273 
274   n = 0;
275   XtSetArg( args[ n ], XmNshadowThickness, 0 ); n++;
276   XtSetArg( args[ n ], XmNmarginHeight,    0 ); n++;
277   XtSetArg( args[ n ], XmNsubMenuId,       rec -> menu ); n++;
278   XtSetArg( args[ n ], XmNlabelString,     xstr ); n++;
279   rec -> select_button = XmCreateCascadeButton( rec -> menuBr, buffer,
280                                                 args, n );
281   if( rec -> select_string == NULL )
282     XmStringFree( xstr );
283 
284   XtManageChild( rec -> select_button );
285 
286 
287   /* Assign all the labels in the menu. */
288   xstr = XmStringCreate( "     ", CS );
289 
290   for( index = 0; index < rec -> elements; index++ ) {
291     sprintf( buffer, "%dPb", index + 1 );
292 
293     ok = xitAllocNamedColor( rec -> menu, rec -> list[ index ], &color );
294     if( ! ok )
295       color = WhitePixelOfScreen( XtScreen( rec -> menu ) );
296 
297     n = 0;
298     XtSetArg( args[ n ], XmNlabelString, xstr ); n++;
299     XtSetArg( args[ n ], XmNbackground,  color ); n++;
300     menuPb = XmCreatePushButton( rec -> menu, buffer, args, n );
301 
302     XtManageChild( menuPb );
303 
304     XtAddCallback( menuPb, XmNactivateCallback,
305                    (XtCallbackProc) menuSelectCB, (XtPointer)(intptr_t)index );
306 
307     /* The default color is the first color. */
308     if( index == 0 ) {
309       n = 0;
310       XtSetArg( args[ n ], XmNbackground,  color ); n++;
311       XtSetValues( rec -> field, args, n );
312     }
313 
314   } /* loop */
315 
316   XmStringFree( xstr );
317 
318 
319   /* Align text and select button. */
320   n = 0;
321   XtSetArg( args[ n ], XmNheight, &text_height ); n++;
322   XtGetValues( rec -> field, args, n );
323 
324   n = 0;
325   XtSetArg( args[ n ], XmNwidth, &text_width ); n++;
326   XtGetValues( rec -> field, args, n );
327 
328   n = 0;
329   XtSetArg( args[ n ], XmNheight, &select_height ); n++;
330   XtGetValues( rec -> select_button, args, n );
331 
332   n = 0;
333   XtSetArg( args[ n ], XmNheight, &rec -> button_width ); n++;
334   XtGetValues( rec -> menuBr, args, n );
335 
336   n = 0;
337   XtSetArg( args[ n ], XmNx, text_width + 2 ); n++;
338   XtSetArg( args[ n ], XmNy, (text_height - select_height) / 2 - 2 ); n++;
339   XtSetValues( rec -> menuBr, args, n );
340 
341 
342   return( manager );
343 
344 } /* xitCreateFieldSelect */
345 
346 
347 /*----------------------------------------------------------------------*/
348 
349 Widget
xitColorSelectGetChild(Widget widget,xitColorSelectChildren child)350   xitColorSelectGetChild( Widget                  widget,
351                           xitColorSelectChildren  child )
352 {
353 
354   /* Variables. */
355   Arg           args[ 2 ];
356   Cardinal      n;
357   SelectRecPtr  rec;
358 
359 
360   /* Code. */
361 
362   n = 0;
363   XtSetArg( args[ n ], XmNuserData, &rec ); n++;
364   XtGetValues( widget, args, n );
365 
366   if( rec == NULL )
367     return( NULL );
368 
369   switch( child ) {
370     case xitCOLOR_SELECT_TEXT_FIELD:
371       return( rec -> field );
372 
373     case xitCOLOR_SELECT_BUTTON:
374       return( rec -> select_button );
375 
376     default:
377       break;
378   } /* switch */
379 
380 
381   return( NULL );
382 
383 } /* xitColorSelectGetChild */
384 
385 
386 /*----------------------------------------------------------------------*/
387 
388 Boolean
xitColorSelectGetColor(Widget widget,Pixel * pixel,XColor * color,char * rgb_string)389   xitColorSelectGetColor( Widget  widget,
390                           Pixel   *pixel,
391                           XColor  *color,
392                           char    *rgb_string )
393 {
394 
395   /* Variables. */
396   Arg           args[ 2 ];
397   Cardinal      n;
398   SelectRecPtr  rec;
399 
400 
401   /* Code. */
402 
403   n = 0;
404   XtSetArg( args[ n ], XmNuserData, &rec ); n++;
405   XtGetValues( widget, args, n );
406 
407   if( rec == NULL )
408     return( False );
409 
410   getColorInfo( rec,
411                 pixel, color, rgb_string );
412 
413 
414   return( True );
415 
416 } /* xitColorSelectGetColor */
417 
418 
419 /*----------------------------------------------------------------------*/
420 
421 Boolean
xitColorSelectGetIndex(Widget widget,int * selected_index)422   xitColorSelectGetIndex( Widget  widget,
423                           int     *selected_index )
424 {
425 
426   /* Variables. */
427   int           index;
428   char          buffer[ 50 ];
429   Arg           args[ 5 ];
430   Cardinal      n;
431   Pixel         bg_color;
432   Pixel         sel_color;
433   SelectRecPtr  rec;
434   Widget        tempW;
435   XColor        dummy_color;
436 
437 
438   /* Code. */
439 
440   n = 0;
441   XtSetArg( args[ n ], XmNuserData, &rec ); n++;
442   XtGetValues( widget, args, n );
443 
444   if( rec == NULL )
445     return( False );
446 
447 
448   /* The color we have selected. */
449   getColorInfo( rec, &sel_color, &dummy_color, buffer );
450 
451   /* Search the color in the range of colors. */
452   for( index = 0; index < rec -> elements; index++ ) {
453 
454     sprintf( buffer, "%dPb", index + 1 );
455 
456     tempW = XtNameToWidget( rec -> menu, buffer );
457 
458     n = 0;
459     XtSetArg( args[ n ], XmNbackground, &bg_color ); n++;
460     XtGetValues( tempW, args, n );
461 
462     if( bg_color == sel_color ) {
463       *selected_index = index;
464       return( True );
465     }
466 
467   } /* loop */
468 
469 
470   return( False );
471 
472 } /* xitColorSelectGetIndex */
473 
474 
475 /*----------------------------------------------------------------------*/
476 
477 Boolean
xitColorSelectGetPixel(Widget widget,Pixel * pixel)478   xitColorSelectGetPixel( Widget  widget,
479                           Pixel   *pixel )
480 {
481 
482   /* Variables. */
483   Boolean  ok;
484   char     rgb_string[ 50 ];
485   XColor   color;
486 
487 
488   /* Code. */
489 
490   ok = xitColorSelectGetColor( widget, pixel, &color, rgb_string );
491 
492 
493   return( ok );
494 
495 } /* xitColorSelectGetPixel */
496 
497 
498 /*----------------------------------------------------------------------*/
499 
500 void
xitColorSelectSetColor(Widget widget,char * new_color,Boolean call)501   xitColorSelectSetColor( Widget   widget,
502                           char     *new_color,
503                           Boolean  call )
504 {
505 
506   /* Variables. */
507   Boolean       ok;
508   Arg           args[ 5 ];
509   Cardinal      n;
510   Pixel         color;
511   SelectRecPtr  rec;
512 
513 
514   /* Code. */
515 
516   if( new_color == NULL || strlen( new_color ) == 0 )
517     return;
518 
519   n = 0;
520   XtSetArg( args[ n ], XmNuserData, &rec ); n++;
521   XtGetValues( widget, args, n );
522 
523   if( rec == NULL )
524     return;
525 
526   /* Allocate the new color. */
527   ok = xitAllocNamedColor( widget, new_color, &color );
528 
529   if( ! ok )
530     color = WhitePixelOfScreen( XtScreen( widget ) );
531 
532   n = 0;
533   XtSetArg( args[ n ], XmNbackground, color ); n++;
534   XtSetValues( rec -> field, args, n );
535 
536   if( call )
537     callCallback( rec, NULL );
538 
539 
540   return;
541 
542 } /* xitColorSelectSetColor */
543 
544 
545 /*----------------------------------------------------------------------*/
546 
547 void
xitColorSelectSetIndex(Widget widget,int set_index,Boolean call)548   xitColorSelectSetIndex( Widget   widget,
549                           int      set_index,
550                           Boolean  call )
551 {
552 
553   /* Variables. */
554   char          buffer[ 50 ];
555   Arg           args[ 5 ];
556   Cardinal      n;
557   Pixel         bg_color;
558   SelectRecPtr  rec;
559   Widget        tempW;
560 
561 
562   /* Code. */
563 
564   n = 0;
565   XtSetArg( args[ n ], XmNuserData, &rec ); n++;
566   XtGetValues( widget, args, n );
567 
568   if( rec == NULL )
569     return;
570 
571 
572   if( set_index < 0 || set_index > rec -> elements - 1 )
573     return;
574 
575 
576   /* Fetch color for the index we selected. */
577   sprintf( buffer, "%dPb", set_index + 1 );
578 
579   tempW = XtNameToWidget( rec -> menu, buffer );
580 
581   n = 0;
582   XtSetArg( args[ n ], XmNbackground, &bg_color ); n++;
583   XtGetValues( tempW, args, n );
584 
585 
586   /* Set the color. */
587   n = 0;
588   XtSetArg( args[ n ], XmNbackground, bg_color ); n++;
589   XtSetValues( rec -> field, args, n );
590 
591 
592   /* Call callback? */
593   if( call )
594     callCallback( rec, NULL );
595 
596 
597   return;
598 
599 } /* xitColorSelectSetIndex */
600 
601 
602 /*----------------------------------------------------------------------*/
603 
604 void
xitColorSelectSetMenu(Widget widget,char * new_menu[],int elements)605   xitColorSelectSetMenu( Widget  widget,
606                          char    *new_menu[],
607                          int     elements )
608 {
609 
610   /* Variables. */
611   Boolean       ok;
612   int           index;
613   char          buffer[ 50 ];
614   Arg           args[ 5 ];
615   Cardinal      n;
616   Widget        menuPb;
617   Widget        tempW;
618   Pixel         color;
619   SelectRecPtr  rec;
620   XmString      xstr;
621 
622 
623   /* Code. */
624 
625   n = 0;
626   XtSetArg( args[ n ], XmNuserData, &rec ); n++;
627   XtGetValues( widget, args, n );
628 
629   if( rec == NULL )
630     return;
631 
632 
633   /* New menu buttons. */
634   for( index = 0; index < elements; index++ ) {
635     sprintf( buffer, "%dPb", index + 1 );
636 
637     xstr = XmStringCreate( "     ", CS );
638 
639     menuPb = XtNameToWidget( rec -> menu, buffer );
640     if( menuPb == NULL )
641       menuPb = XmCreatePushButton( rec -> menu, buffer, args, 0 );
642 
643     ok = xitAllocNamedColor( rec -> menu, new_menu[ index ], &color );
644     if( ! ok )
645       color = WhitePixelOfScreen( XtScreen( rec -> menu ) );
646 
647     n = 0;
648     XtSetArg( args[ n ], XmNlabelString, xstr ); n++;
649     XtSetArg( args[ n ], XmNbackground,  color ); n++;
650     XtSetValues( menuPb, args, n );
651 
652     XtManageChild( menuPb );
653 
654     XmStringFree( xstr );
655   } /* loop */
656 
657   for( index = elements; index < rec -> elements; index++ ) {
658     sprintf( buffer, "%dPb", index + 1 );
659 
660     tempW = XtNameToWidget( rec -> menu, buffer );
661     if( tempW != NULL )
662       XtUnmanageChild( tempW );
663   }
664 
665   rec -> elements = elements;
666 
667 
668   return;
669 
670 } /* xitColorSelectSetMenu */
671 
672 
673 /*----------------------------------------------------------------------*/
674 
675 void
xitColorSelectSetPixel(Widget widget,Pixel pixel,Boolean call)676   xitColorSelectSetPixel( Widget   widget,
677                           Pixel    pixel,
678                           Boolean  call )
679 {
680 
681   /* Variables. */
682   Arg           args[ 5 ];
683   Cardinal      n;
684   SelectRecPtr  rec;
685 
686 
687   /* Code. */
688 
689   n = 0;
690   XtSetArg( args[ n ], XmNuserData, &rec ); n++;
691   XtGetValues( widget, args, n );
692 
693   if( rec == NULL )
694     return;
695 
696   /* Set new color. */
697   n = 0;
698   XtSetArg( args[ n ], XmNbackground, pixel ); n++;
699   XtSetValues( rec -> field, args, n );
700 
701   if( call )
702     callCallback( rec, NULL );
703 
704 
705   return;
706 
707 } /* xitColorSelectSetPixel */
708 
709 
710 /*----------------------------------------------------------------------*/
711 
712 static void
callCallback(SelectRecPtr rec,XEvent * event)713   callCallback( SelectRecPtr  rec,
714                 XEvent        *event )
715 {
716 
717   /* Variables. */
718   xitColorSelectCallbackStruct  cb;
719 
720 
721   /* Code. */
722 
723   if( rec -> call_proc != NULL ) {
724 
725     getColorInfo( rec,
726                   &cb.pixel, &cb.color, cb.rgb_string );
727 
728     cb.reason   = XmCR_VALUE_CHANGED;
729     cb.event    = event;
730 
731     (* rec -> call_proc) ( rec -> field,
732                            (XtPointer) rec -> client_data, (XtPointer) &cb );
733 
734   } /* if */
735 
736 
737   return;
738 
739 } /* callCallback */
740 
741 
742 /*----------------------------------------------------------------------*/
743 
744 static void
getColorInfo(SelectRecPtr rec,Pixel * pixel,XColor * color,char * rgb_string)745   getColorInfo( SelectRecPtr  rec,
746                 Pixel         *pixel,
747                 XColor        *color,
748                 char          *rgb_string )
749 {
750 
751   /* Variables. */
752   Arg       args[ 5 ];
753   Cardinal  n;
754 
755 
756   /* Code. */
757 
758   /* Selected pixel. */
759   n = 0;
760   XtSetArg( args[ n ], XmNbackground, pixel ); n++;
761   XtGetValues( rec -> field, args, n );
762 
763   /* Selected color strcture. */
764   color -> pixel = (unsigned long) *pixel;
765   XQueryColor( XtDisplay( rec -> field ),
766                DefaultColormapOfScreen( XtScreen( rec -> field ) ),
767                color );
768 
769   /* Selected RGB string. */
770   sprintf( rgb_string, "#%4.4hx%4.4hx%4.4hx",
771            color -> red, color -> green, color -> blue );
772 
773 
774   return;
775 
776 } /* getColorInfo */
777 
778 
779 /*----------------------------------------------------------------------*/
780 
781 static void
destroyCB(Widget widget,SelectRecPtr rec,XtPointer call_data)782   destroyCB( Widget        widget,
783              SelectRecPtr  rec,
784              XtPointer     call_data )
785 {
786 
787   /* Code. */
788 
789   /* Free the allocated record. */
790   SysFree( rec );
791 
792 
793   return;
794 
795 } /* destroyCB */
796 
797 
798 /*----------------------------------------------------------------------*/
799 
800 static void
menuSelectCB(Widget widget,SelectRecPtr rec,XmRowColumnCallbackStruct * call_data)801   menuSelectCB( Widget                     widget,
802                 SelectRecPtr               rec,
803                 XmRowColumnCallbackStruct  *call_data )
804 {
805 
806   /* Variables. */
807   Arg       args[ 5 ];
808   Cardinal  n;
809   Pixel     color;
810 
811 
812   /* Code. */
813 
814   if( call_data -> reason != XmCR_ACTIVATE )
815     return;
816 
817 
818   /* Fetch the selected color. */
819   n = 0;
820   XtSetArg( args[ n ], XmNbackground, &color ); n++;
821   XtGetValues( call_data -> widget, args, n );
822 
823 
824   /* Set the new selected color. */
825   n = 0;
826   XtSetArg( args[ n ], XmNbackground, color ); n++;
827   XtSetValues( rec -> field, args, n );
828 
829 
830   callCallback( rec, call_data -> event );
831 
832 
833   return;
834 
835 } /* menuSelectCB */
836 
837 
838 /*----------------------------------------------------------------------*/
839 
840 static void
resizeCB(Widget widget,SelectRecPtr rec,XmAnyCallbackStruct * call_data)841   resizeCB( Widget               widget,
842             SelectRecPtr         rec,
843             XmAnyCallbackStruct  *call_data )
844 {
845 
846   /* Variables. */
847   Arg        args[ 5 ];
848   Cardinal   n;
849   Dimension  height;
850   Dimension  select_height;
851   Dimension  text_height;
852   Dimension  text_width;
853   Dimension  width;
854   Position   new_y;
855 
856 
857   /* Code. */
858 
859   n = 0;
860   XtSetArg( args[ n ], XmNwidth, &width ); n++;
861   XtSetArg( args[ n ], XmNheight, &height ); n++;
862   XtGetValues( widget, args, n );
863 
864   text_width = width - rec -> button_width - 2;
865 
866   n = 0;
867   XtSetArg( args[ n ], XmNheight, &text_height ); n++;
868   XtSetArg( args[ n ], XmNwidth,  &text_width ); n++;
869   XtGetValues( rec -> field, args, n );
870 
871   if( height > text_height )
872     new_y = (height - text_height) / 2;
873   else
874     new_y = 0;
875 
876   /* Stop resizing the drawing area now. */
877   n = 0;
878   XtSetArg( args[ n ], XmNresizePolicy, XmRESIZE_NONE ); n++;
879   XtSetValues( widget, args, n );
880 
881   n = 0;
882   XtSetArg( args[ n ], XmNheight, &select_height ); n++;
883   XtGetValues( rec -> select_button, args, n );
884 
885   /* Resize the children. */
886   n = 0;
887   XtSetArg( args[ n ], XmNy,     new_y ); n++;
888   XtSetArg( args[ n ], XmNwidth, text_width ); n++;
889   XtSetValues( rec -> field, args, n );
890 
891   new_y = new_y + (text_height - select_height) / 2 - 2;
892 
893   n = 0;
894   XtSetArg( args[ n ], XmNx, text_width + 2 ); n++;
895   XtSetArg( args[ n ], XmNy, new_y ); n++;
896   XtSetValues( rec -> menuBr, args, n );
897 
898 
899   return;
900 
901 } /* resizeCB */
902