summaryrefslogtreecommitdiff
path: root/Xw/Toggle.c
blob: fa3cdf6ac2da1367583e70e4afc8c058134f6927 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
/*************************************<+>*************************************
 *****************************************************************************
 **
 **   File:        Toggle.c
 **
 **   Project:     X Widgets
 **
 **   Description: Contains code for primitive widget class: Toggle
 **
 *****************************************************************************
 **   
 **   Copyright (c) 1988 by Hewlett-Packard Company
 **   Copyright (c) 1988 by the Massachusetts Institute of Technology
 **   
 **   Permission to use, copy, modify, and distribute this software 
 **   and its documentation for any purpose and without fee is hereby 
 **   granted, provided that the above copyright notice appear in all 
 **   copies and that both that copyright notice and this permission 
 **   notice appear in supporting documentation, and that the names of 
 **   Hewlett-Packard or  M.I.T.  not be used in advertising or publicity 
 **   pertaining to distribution of the software without specific, written 
 **   prior permission.
 **   
 *****************************************************************************
 *************************************<+>*************************************/

/*
 * Include files & Static Routine Definitions
 */


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <X11/Intrinsic.h>
#include <X11/IntrinsicP.h>
#include <Xw/Xw.h>
#include <Xw/XwP.h>
#include <Xw/ToggleP.h>
#include <Xw/Toggle.h>
#include <X11/StringDefs.h>
#include <X11/keysymdef.h>   
   
#define SPACE_FACTOR 3
#define T_BW 2

static void Redisplay();
static Boolean SetValues();
static void ClassInitialize();
static void Initialize();
static void Destroy();
static void Toggle();
static void Select();
static void Unselect();
static void DrawToggle();
static void Resize();
static void DrawDiamondButton();
static void GetSelectGC();



/*************************************<->*************************************
 *
 *
 *   Description:  default translation table for class: Toggle
 *   -----------
 *
 *   Matches events with string descriptors for internal routines.
 *
 *************************************<->***********************************/


static char defaultTranslations[] =
   "<EnterWindow>:          enter() \n\
    <LeaveWindow>:          leave() \n\
    <Btn1Down>:             toggle() \n\
    <Key>Select:            toggle()";



/*************************************<->*************************************
 *
 *
 *   Description:  action list for class: Toggle
 *   -----------
 *
 *   Matches string descriptors with internal routines.
 *
 *************************************<->***********************************/

static XtActionsRec actionsList[] =
{
  {"toggle", (XtActionProc) Toggle},
  {"select", (XtActionProc) Select},
  {"unselect", (XtActionProc) Unselect},
  {"enter", (XtActionProc) _XwPrimitiveEnter},
  {"leave", (XtActionProc) _XwPrimitiveLeave},
};




/*************************************<->*************************************
 *
 *
 *   Description:  resource list for class: Toggle
 *   -----------
 *
 *   Provides default resource settings for instances of this class.
 *   To get full set of default settings, examine resouce list of super
 *   classes of this class.
 *
 *************************************<->***********************************/

static XtResource resources[] = 
{
   {
      XtNsquare, XtCSquare, XtRBoolean, sizeof (Boolean),
      XtOffset (XwToggleWidget, toggle.square),
      XtRString, "True"
   },

   {
      XtNselectColor, XtCForeground, XtRPixel, sizeof (Pixel),
      XtOffset (XwToggleWidget, toggle.select_color),
      XtRString, "Black"
   }
};



/*************************************<->*************************************
 *
 *
 *   Description:  global class record for instances of class: Toggle
 *   -----------
 *
 *   Defines default field settings for this class record.
 *
 *************************************<->***********************************/

XwToggleClassRec XwtoggleClassRec = {
  {
/* core_class fields */	
    /* superclass	  */	(WidgetClass) &XwbuttonClassRec,
    /* class_name	  */	"Toggle",
    /* widget_size	  */	sizeof(XwToggleRec),
    /* class_initialize   */    ClassInitialize,
    /* class_part_init    */    NULL,				
    /* class_inited       */	FALSE,
    /* initialize	  */	Initialize,
    /* initialize_hook    */    NULL,
    /* realize		  */	_XwRealize,
    /* actions		  */	actionsList,
    /* num_actions	  */	XtNumber(actionsList),
    /* resources	  */	resources,
    /* num_resources	  */	XtNumber(resources),
    /* xrm_class	  */	NULLQUARK,
    /* compress_motion	  */	TRUE,
    /* compress_exposure  */	TRUE,
    /* compress_enterlv   */    TRUE,
    /* visible_interest	  */	FALSE,
    /* destroy		  */	Destroy,
    /* resize		  */	Resize,
    /* expose		  */	Redisplay,
    /* set_values	  */	SetValues,
    /* set_values_hook    */    NULL,
    /* set_values_almost  */    XtInheritSetValuesAlmost,
    /* get_values_hook  */	NULL,
    /* accept_focus     */      NULL,
    /* version          */	XtVersion,
    /* callback_private */      NULL,
    /* tm_table         */      defaultTranslations,
    /* query_geometry   */	NULL, 
    /* display_accelerator	*/	XtInheritDisplayAccelerator,
    /* extension		*/	NULL
   }
};
WidgetClass XwtoggleWidgetClass = (WidgetClass)&XwtoggleClassRec;

/*************************************<->*************************************
 *
 *  ComputeSpace (w, redisplay)
 *
 *   Description:
 *   -----------
 *     Compute allowable space to display label and/or toggle.
 *     If this function is used in redisplay (i.e. redisplay
 *     flag is true), compute space for label as well as toggle.
 *     Compute for toggle only if redisplay flag is FALSE.
 *
 *   Inputs:
 *   ------
 *     w           =   widget instance that was selected.
 *     redisplay   =   flag indicating routine is called from Redisplay()
 * 
 *   Outputs:
 *   -------
 *
 *   Procedures Called
 *   -----------------
 *   XClearArea()
 *   _XwHighlightBorder()
 *   _XwUnhighlightBorder()
 *************************************<->***********************************/
static void ComputeSpace(w, redisplay)
     Widget w;
     Boolean redisplay;
{
   XwToggleWidget cbox = (XwToggleWidget)w;
   Boolean clipHeight, clipWidth;
   int x, available_width, available_height;
     
  /* COMPUTE SPACE FOR DRAWING TOGGLE */

   if (redisplay)
      {
         available_width = Max(0, (int)cbox->core.width - 2*
                                 ((int)cbox->button.internal_width +
	  		               cbox->primitive.highlight_thickness));

        /* SEE IF WE NEED TO CLIP THIS LABEL ON RIGHT */

         if (((int)cbox->button.label_width + 
              (int)cbox->button.label_height +
              (int)cbox->button.label_height/SPACE_FACTOR)  > available_width)
                clipWidth = True;
         else 
                clipWidth = False;

      }
   else 
      {
         available_width = Max(0,((int)cbox->core.width - 2*
                                 ((int)cbox->button.internal_width +
	           		       cbox->primitive.highlight_thickness) -
                                  (int)cbox->button.label_width -
                                  (int)cbox->button.label_height/SPACE_FACTOR));

        /* SEE IF WE NEED TO CLIP THIS LABEL ON RIGHT */

         if ((int)cbox->button.label_height > available_width)
             clipWidth = True;
         else
             clipWidth = False;
      }
 
   available_height = Max(0, (int)cbox->core.height - 2*
                            ((int)cbox->button.internal_height +
				  cbox->primitive.highlight_thickness));

  
  /* SEE IF WE NEED TO CLIP THIS LABEL ON TOP AND/OR BOTTOM */

    if ((int)cbox->button.label_height > available_height)
        clipHeight = True;
    else 
        clipHeight = False;

    if (clipWidth)
       {
          x = (int)cbox->core.width - cbox->primitive.highlight_thickness -
              (int)cbox->button.internal_width;
  
          if ((cbox->button.label_location != XwRIGHT) && redisplay)
             x -= Min((int)cbox->button.label_height, 
                      Max(0, (int)cbox->core.height - 
		      2*(cbox->primitive.highlight_thickness + 
                      (int)cbox->button.internal_height)));


          XClearArea (XtDisplay(w), XtWindow(w), x, 0,
 		      ((int)cbox->core.width - x), cbox->core.height, FALSE);
       }
   
    if (clipHeight)
       {
           XClearArea (XtDisplay(w), XtWindow(w), 0,0, cbox->core.width, 
		       (cbox->primitive.highlight_thickness +
		         cbox->button.internal_height), FALSE);
           XClearArea (XtDisplay(w), XtWindow(w), 0,
		       ((int)cbox->core.height - 
                        cbox->primitive.highlight_thickness -
		         (int)cbox->button.internal_height), cbox->core.width,
		       (cbox->primitive.highlight_thickness +
		         cbox->button.internal_height), FALSE);
       }

    if (cbox->primitive.highlighted)
         _XwHighlightBorder(w);
    else if (cbox->primitive.display_highlighted)
         _XwUnhighlightBorder(w);

    /* REDRAW THE TOGGLE ON LABEL LOCATION LEFT CONDITIONS AND RECURSIVELY
       CALL THIS FUNCTION.  THIS ENSURES VISIBILITY OF THE TOGGLE */
    if ((cbox->button.label_location != XwRIGHT) && redisplay)
      {
  	DrawToggle(w, FALSE);
  	ComputeSpace(w, FALSE);
      }

} /* ComputeSpace */


/*************************************<->*************************************
 *
 *  Toggle (w, event)                  PRIVATE
 *
 *   Description:
 *   -----------
 *     When this Toggle is selected, toggle the activation state
 *     (i.e., draw it as active if it was not active and draw it as
 *     inactive if it was active).  Generate the correct callbacks
 *     in response.
 *
 *     NOTE: this code assumes that instances do not receive selection
 *           events when insensitive.
 *
 *   Inputs:
 *   ------
 *     w           =   widget instance that was selected.
 *     event       =   event record
 * 
 *   Outputs:
 *   -------
 *
 *   Procedures Called
 *   -----------------
 *   DrawToggle()    [Toggle.c]
 *   ComputeSpace()    [Toggle.c]
 *   XtCallCallbacks()
 *************************************<->***********************************/

static void Toggle(w,event)
     Widget w;
     XEvent *event;
{
  XwToggleWidget cbox = (XwToggleWidget)w;

  cbox->button.set = (cbox->button.set == TRUE) ? FALSE : TRUE;
  DrawToggle(w, FALSE);
  ComputeSpace(w, FALSE);
  XFlush(XtDisplay(w));
  if (cbox->button.set == TRUE)
     XtCallCallbacks (w, XtNselect, NULL);
  else
     XtCallCallbacks (w, XtNrelease, NULL);
}


/*************************************<->*************************************
 *
 *  Select (w, event)                  PRIVATE
 *
 *   Description:
 *   -----------
 *     Mark Toggle as selected, (i.e., draw it as active)
 *     Generate the correct callbacks.
 *
 *     NOTE: this code assumes that instances do not receive selection
 *           events when insensitive.
 *
 *   Inputs:
 *   ------
 *     w           =   widget instance that was selected.
 *     event       =   event record
 * 
 *   Outputs:
 *   -------
 *
 *   Procedures Called
 *   -----------------
 *   DrawToggle()    [Toggle.c]
 *   ComputeSpace()    [Toggle.c]
 *   XtCallCallbacks()
 *************************************<->***********************************/

static void Select(w,event)
     Widget w;
     XEvent *event;
{
  XwToggleWidget cbox = (XwToggleWidget)w;

  cbox->button.set = TRUE;
  DrawToggle(w, FALSE);
  ComputeSpace(w,FALSE);
  XFlush(XtDisplay(w));
  XtCallCallbacks (w, XtNselect, NULL);
}


/*************************************<->*************************************
 *
 *  Unselect (w, event)                  PRIVATE
 *
 *   Description:
 *   -----------
 *     When this Toggle is unselected draw it as inactive.
 *     Generate the correct callbacks.
 *
 *     NOTE: this code assumes that instances do not receive selection
 *           events when insensitive.
 *
 *   Inputs:
 *   ------
 *     w           =   widget instance that was selected.
 *     event       =   event record
 * 
 *   Outputs:
 *   -------
 *
 *   Procedures Called
 *   -----------------
 *   DrawToggle()    [Toggle.c]
 *   ComputeSpace()    [Toggle.c]
 *   XtCallCallbacks()
 *************************************<->***********************************/

static void Unselect(w,event)
     Widget w;
     XEvent *event;
{
  XwToggleWidget cbox = (XwToggleWidget)w;

  cbox->button.set = FALSE;
  DrawToggle(w, FALSE);
  ComputeSpace(w,FALSE);
  XFlush(XtDisplay(w));
  XtCallCallbacks (w, XtNrelease, NULL);
}




/************************************************************************
 *
 *  GetSelectGC
 *	Get the graphics context to be used to fill the interior of
 *	a square or diamond when selected.
 *
 ************************************************************************/

static void GetSelectGC (tw)
XwToggleWidget tw;

{
   XGCValues values;

   values.foreground = tw -> toggle.select_color;
   values.background = tw -> core.background_pixel;
   values.fill_style = FillSolid;

   tw -> toggle.select_GC = 
      XtGetGC ((Widget)tw, GCForeground | GCBackground | GCFillStyle, &values);
               
}




/*************************************<->*************************************
 *
 *  Resize
 *
 *   Description:
 *   -----------
 *     A resize event has been generated. Recompute location of button
 *     elements.
 *
 *   Inputs:
 *   ------
 *     w  = widget to be resized.
 * 
 *************************************<->***********************************/

static void Resize(w)
    Widget w;
{
    register XwButtonWidget aButton = (XwButtonWidget) w;
    int direction = aButton->button.label_location;

       switch (direction)
	 {
            case XwRIGHT:
             aButton->button.label_x =  aButton->button.internal_width +
                                  aButton->primitive.highlight_thickness +
				  aButton->button.label_height +
				    aButton->button.label_height/SPACE_FACTOR;
             break;

           default:
            aButton->button.label_x = aButton->button.internal_width +
                                 aButton->primitive.highlight_thickness;
          }

    aButton->button.label_y =
       (((int)aButton->core.height - (int)aButton->button.label_height) >> 1)
 	 + aButton->button.font->max_bounds.ascent;
}

/*************************************<->*************************************
 *
 *  Initialize
 *
 *   Description:
 *   -----------
 *    If the core height and width fields are set to 0, treat that as a flag
 *    and compute the optimum size for this button.  Then using what ever
 *    the core fields are set to, compute the text placement fields.
 *    Make sure that the label location field is properly set for the
 *    Resize call.
 *************************************<->***********************************/
static void Initialize (request, new)
 Widget request, new;
{
     XwToggleWidget cbox = (XwToggleWidget) new;

    if ((cbox->button.label_location != XwLEFT) &&
          (cbox->button.label_location != XwRIGHT))
      {
        cbox->button.label_location = XwLEFT;
	XtWarning ("XwToggle Initialize: invalid label location setting.");
      }

    if (request->core.width == 0)  cbox->core.width +=
           cbox->button.label_width +
	      2 * cbox->button.internal_width +    /* white space */
		   cbox->button.label_height +    /* size of box */
		       cbox->button.label_height/SPACE_FACTOR  +    /* space */
		    2 * cbox->primitive.highlight_thickness;
    
    if (request->core.height == 0) cbox->core.height +=
           cbox->button.label_height + 2 * cbox->button.internal_height
	      + 2 * cbox->primitive.highlight_thickness;  

/* dana change */
    if (!cbox->toggle.square) cbox->core.height += 2;

    GetSelectGC (new);
    Resize (new);
}   





/************************************************************************
 *
 *  Destroy
 *	Free toggle's graphic context.
 *
 ************************************************************************/

static void Destroy (tw)
XwToggleWidget tw;

{
   XtDestroyGC (tw -> toggle.select_GC);
}





/*************************************<->*************************************
 *
 *  DrawToggle(w)
 *
 *   Description:
 *   -----------
 *     Depending on the state of this widget, draw the Toggle.
 *
 *
 *   Inputs:
 *   ------
 *     w = widget to be (re)displayed.
 * 
 *************************************<->***********************************/

static void DrawToggle(w, all)
   XwToggleWidget w;
   Boolean all;         /* redo all, or just center? */
{
   int x, y, edge;
   
   /***************************************************************
    * Determine whether label should appear to the left or
    * the right of the box and set label X coordinate accordingly.
    ****************************************************************/

   edge = Min((int)w->button.label_height, 
	      Max(0, (int)w->core.height - 2*(w->primitive.highlight_thickness
		   + (int)w->button.internal_height)));

   if (w->button.label_location == XwRIGHT)
        x= w->button.internal_width + w->primitive.highlight_thickness;
   else
	x= Max(0, (int)w->core.width - (int)w->button.internal_width
	   - w->primitive.highlight_thickness - edge);      /* size of box */
   
   y= Max(0, ((int)w->core.height - edge) / 2); 

   if (w->toggle.square)
   {
      _XwDrawBox (XtDisplay (w), XtWindow (w), 
                     w -> button.normal_GC, T_BW,
                     x, y, edge, edge);
      if (edge > 6) XFillRectangle (XtDisplay ((Widget) w), 
                                    XtWindow ((Widget) w),
                                    ((w->button.set) ? w -> toggle.select_GC :
                                                       w -> button.inverse_GC),
                                    x+3, y+3, edge-6, edge-6);
   }
   else
      DrawDiamondButton ((XwButtonWidget) w, x-1, y-1, edge+2,
                         w -> button.normal_GC,
                         ((w->button.set) ? 
                           w -> toggle.select_GC :
                           w -> button.inverse_GC));
}




/*************************************<->*************************************
 *
 *  ClassInitialize
 *
 *   Description:
 *   -----------
 *    Set fields in primitive class part of our class record so that
 *    the traversal code can invoke our button select procedures.
 *
 *************************************<->***********************************/
static void ClassInitialize()
{
   XwtoggleClassRec.primitive_class.select_proc = (XwEventProc) Select;
   XwtoggleClassRec.primitive_class.release_proc = (XwEventProc) Unselect;
   XwtoggleClassRec.primitive_class.toggle_proc = (XwEventProc) Toggle;
}


/*************************************<->*************************************
 *
 *  Redisplay (w, event)
 *
 *   Description:
 *   -----------
 *     Cause the widget, identified by w, to be redisplayed.
 *
 *
 *   Inputs:
 *   ------
 *     w = widget to be redisplayed;
 *     event = event structure identifying need for redisplay on this
 *             widget.
 * 
 *   Outputs:
 *   -------
 *
 *   Procedures Called
 *   -----------------
 *   XDrawString()
 *   DrawToggle()     [Toggle.c]
 *   ComputeSpace()   [Toggle.c]
 *************************************<->***********************************/

static void Redisplay(w, event)
    Widget w;
    XEvent *event;
{
   register XwToggleWidget cbox = (XwToggleWidget) w;

   if (cbox->button.label_len > 0)
          XDrawString( XtDisplay(w), XtWindow(w),  cbox->button.normal_GC,
	               cbox->button.label_x, cbox->button.label_y,
    	               cbox->button.label, cbox->button.label_len);
   DrawToggle(cbox, TRUE);
   ComputeSpace(w, TRUE);
}



/*************************************<->*************************************
 *
 *  SetValues(current, request, new)
 *
 *   Description:
 *   -----------
 *     This is the set values procedure for the Toggle class.  It is
 *     called last (the set values rtnes for its superclasses are called
 *     first).
 *
 *
 *   Inputs:
 *   ------
 *    current = original widget;
 *    request = copy of current (?);
 *    new = copy of request which reflects changes made to it by
 *          set values procedures of its superclasses;
 * 
 *
 *************************************<->***********************************/

static Boolean SetValues(current, request, new)
    Widget current, request, new;
{
    XwToggleWidget curcbox = (XwToggleWidget) current;
    XwToggleWidget newcbox = (XwToggleWidget) new;
    Boolean  flag = FALSE;    /* our return value */
    
    
    /**********************************************************************
     * Calculate the window size:  The assumption here is that if
     * the width and height are the same in the new and current instance
     * record that those fields were not changed with set values.  Therefore
     * its okay to recompute the necessary width and height.  However, if
     * the new and current do have different width/heights then leave them
     * alone because that's what the user wants.
     *********************************************************************/

    if ((curcbox->core.width == newcbox->core.width) &&
        (_XwRecomputeSize(current, new)))
     {
	newcbox->core.width =
	    newcbox->button.label_width +2*newcbox->button.internal_width
	       + newcbox->button.label_height +
		  newcbox->button.label_height/SPACE_FACTOR +
     		    2 * newcbox->primitive.highlight_thickness;
	flag = TRUE;
     }

    if ((curcbox->core.height == newcbox->core.height) &&
        (_XwRecomputeSize(current, new)))
     {
	newcbox->core.height =
	    newcbox->button.label_height + 2*newcbox->button.internal_height +
     		    2 * newcbox->primitive.highlight_thickness;
	flag = TRUE;
     }


    if (curcbox -> toggle.select_color != newcbox -> toggle.select_color)
    {
       XtDestroyGC (newcbox -> toggle.select_GC);
       GetSelectGC (newcbox);
       flag = True;
    }


    if (curcbox -> toggle.square != newcbox -> toggle.square)
    {
       flag = True;
    }


    Resize(new);  /* fix label x and label y positioning */
    return(flag);
}





/************************************************************************
 *
 *  DrawDiamondButton()
 *	The dimond drawing routine.  Used in place of primitives
 *	draw routine when toggle's square flag is False.
 *
 ************************************************************************/


static void DrawDiamondButton (bw, x, y, size, borderGC, centerGC)
XwButtonWidget bw;
int x, y, size;
GC borderGC, centerGC;


{
   XSegment seg[8];
   XPoint   pt[5];
   int midX, midY;

   if (size % 2 == 0)
      size--;

   midX = x + (size + 1) / 2;
   midY = y + (size + 1) / 2;


   /*  The top segments  */

   seg[0].x1 = x;			/*  1  */
   seg[0].y1 = midY - 1;
   seg[0].x2 = midX - 1;		/*  2  */
   seg[0].y2 = y;

   seg[1].x1 = x + 1;			/*  3  */
   seg[1].y1 = midY - 1;
   seg[1].x2 = midX - 1;		/*  4  */
   seg[1].y2 = y + 1;

   seg[2].x1 = midX - 1;		/*  5  */
   seg[2].y1 = y;
   seg[2].x2 = x + size - 1;		/*  6  */
   seg[2].y2 = midY - 1;

   seg[3].x1 = midX - 1;		/*  7  */
   seg[3].y1 = y + 1;
   seg[3].x2 = x + size - 2;		/*  8  */
   seg[3].y2 = midY - 1;


   /*  The bottom segments  */

   seg[4].x1 = x;			/*  9  */
   seg[4].y1 = midY - 1;
   seg[4].x2 = midX - 1;		/*  10  */
   seg[4].y2 = y + size - 1;

   seg[5].x1 = x + 1;			/*  11  */
   seg[5].y1 = midY - 1;
   seg[5].x2 = midX - 1;		/*  12  */
   seg[5].y2 = y + size - 2;

   seg[6].x1 = midX - 1;		/*  13  */
   seg[6].y1 = y + size - 1;
   seg[6].x2 = x + size - 1;		/*  14  */
   seg[6].y2 = midY - 1;

   seg[7].x1 = midX - 1;		/*  15  */
   seg[7].y1 = y + size - 2;
   seg[7].x2 = x + size - 2;		/*  16  */
   seg[7].y2 = midY - 1;

   XDrawSegments (XtDisplay ((Widget) bw), XtWindow ((Widget) bw),
                  borderGC, &seg[2], 2);

   XDrawSegments (XtDisplay ((Widget) bw), XtWindow ((Widget) bw),
                  borderGC, &seg[4], 4);

   XDrawSegments (XtDisplay ((Widget) bw), XtWindow ((Widget) bw),
                  borderGC, &seg[0], 2);


   pt[0].x = x + 3;
   pt[0].y = midY - 1;
   pt[1].x = midX - 1;
   pt[1].y = y + 3;
   pt[2].x = x + size - 4;
   pt[2].y = midY - 1;
   pt[3].x = midX - 2;
   pt[3].y = y + size - 4;

   XFillPolygon (XtDisplay ((Widget) bw), XtWindow ((Widget) bw),
                 centerGC, pt, 4, Convex, CoordModeOrigin);
}