2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* static char rcsid[] =
24 "$XConsortium: Clock.c /main/8 1996/10/14 10:58:15 pascale $";
26 /**---------------------------------------------------------------------
30 *** project: MotifPlus Widgets
32 *** description: Source code for DtClock class.
33 *** Portions adapted from the Xaw Clock widget.
36 *** (c) Copyright 1990 by Hewlett-Packard Company.
39 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
40 and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
44 Permission to use, copy, modify, and distribute this software and its
45 documentation for any purpose and without fee is hereby granted,
46 provided that the above copyright notice appear in all copies and that
47 both that copyright notice and this permission notice appear in
48 supporting documentation, and that the names of Digital or MIT not be
49 used in advertising or publicity pertaining to distribution of the
50 software without specific, written prior permission.
52 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
53 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
54 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
55 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
56 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
57 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
61 ***-------------------------------------------------------------------*/
65 /*-------------------------------------------------------------
71 #include <sys/types.h>
75 #include <Xm/GadgetP.h>
76 #include <Xm/ManagerP.h>
78 #include <Dt/Control.h>
81 /*-------------------------------------------------------------
83 **-------------------------------------------------------------
86 WidgetClass dtClockGadgetClass;
89 /*-------------------------------------------------------------
92 #define SIZE_DEFAULT 32
93 #define DELAY_DEFAULT 250
94 #define VERTICES_IN_HANDS 6 /* to draw triangle */
95 #define PI 3.14159265358979
96 #define TWOPI (2. * PI)
98 #define SMALL_TICK_FRACT 100
99 #define SMALL_MINUTE_HAND_FRACT 95
100 #define SMALL_HOUR_HAND_FRACT 68
101 #define SMALL_HAND_WIDTH_FRACT 12
103 #define TICK_FRACT 90
104 #define MINUTE_HAND_FRACT 70
105 #define HOUR_HAND_FRACT 40
106 #define HAND_WIDTH_FRACT 7
108 #define max(a,b) ((a) > (b) ? (a) : (b))
109 #define min(a,b) ((a) < (b) ? (a) : (b))
110 #define abs(a) ((a) < 0 ? - (a) : (a))
112 #define G_Width(r) (r -> rectangle.width)
113 #define G_Height(r) (r -> rectangle.height)
114 #define M_BackgroundGC(m) (m -> manager.background_GC)
115 #define G_X(r) (r -> rectangle.x)
116 #define G_Y(r) (r -> rectangle.y)
119 /* Is this still needed, or does <time.h> always declare time()? */
120 extern time_t time ( time_t * );
123 /******** Public Function Declarations ********/
125 extern Widget DtCreateClock(
131 /******** End Public Function Declarations ********/
133 /******** Static Function Declarations ********/
135 static void ClockTick(
136 XtPointer client_data,
138 static void DrawLine(
140 Dimension blank_length,
142 double fraction_of_a_circle) ;
143 static void DrawHand(
147 double fraction_of_a_circle) ;
148 static void SetSegment(
156 static void DrawClockFace(
158 static void Initialize(
174 unsigned char s_type,
175 unsigned char fill_mode) ;
176 static void UpdateGCs(
178 static void EraseHands ( DtClockGadget w, struct tm * tm );
180 /******** End Static Function Declarations ********/
183 /*-------------------------------------------------------------
186 #define R_Offset(field) \
187 XtOffset (DtClockGadget, clock.field)
189 static XtResource resources[] =
193 XmCInterval, XmRInt, sizeof (int),
194 R_Offset (clock_interval), XmRImmediate, (XtPointer) 60
198 XmCBoolean, XmRBoolean, sizeof (Boolean),
199 R_Offset (chime), XmRImmediate, (XtPointer) FALSE
203 XmCSpacing, XmRHorizontalDimension, sizeof (Dimension),
204 R_Offset (left_inset), XmRImmediate, (caddr_t) 2
208 XmCSpacing, XmRHorizontalDimension, sizeof (Dimension),
209 R_Offset (right_inset), XmRImmediate, (caddr_t) 2
213 XmCSpacing, XmRVerticalDimension, sizeof (Dimension),
214 R_Offset (top_inset), XmRImmediate, (caddr_t) 2
218 XmCSpacing, XmRVerticalDimension, sizeof (Dimension),
219 R_Offset (bottom_inset), XmRImmediate, (caddr_t) 2
226 /*-------------------------------------------------------------
229 DtClockClassRec dtClockClassRec =
234 (WidgetClass) &dtControlClassRec, /* superclass */
235 "Clock", /* class_name */
236 sizeof (DtClockRec), /* widget_size */
237 NULL, /* class_initialize */
238 NULL, /* class_part_initialize*/
239 False, /* class_inited */
240 (XtInitProc) Initialize, /* initialize */
241 NULL, /* initialize_hook */
245 resources, /* resources */
246 XtNumber (resources), /* num_resources */
247 NULLQUARK, /* xrm_class */
248 True, /* compress_motion */
249 True, /* compress_exposure */
250 True, /* compress_enterleave */
251 False, /* visible_interest */
252 Destroy, /* destroy */
254 XtInheritExpose, /* expose */
255 NULL, /* set_values */
256 NULL, /* set_values_hook */
257 XtInheritSetValuesAlmost, /* set_values_almost */
258 NULL, /* get_values_hook */
259 NULL, /* accept_focus */
260 XtVersion, /* version */
261 NULL, /* callback private */
263 NULL, /* query_geometry */
264 NULL, /* display_accelerator */
265 NULL, /* extension */
271 XmInheritBorderHighlight, /* border_highlight */
272 XmInheritBorderUnhighlight, /* border_unhighlight */
273 (XtActionProc) XmInheritArmAndActivate, /* arm_and_activate */
274 (XmWidgetDispatchProc) XmInheritInputDispatch, /* input_dispatch */
275 XmInheritVisualChange, /* visual_change */
276 NULL, /* get_resources */
277 0, /* num_get_resources */
278 XmInheritCachePart, /* class_cache_part */
279 NULL, /* extension */
285 DtInheritGetSize, /* get_size */
286 DtInheritGetPositions, /* get_positions */
287 (DrawProc) Draw, /* draw */
288 DtInheritCallCallback, /* call_callback */
289 (UpdateGCsProc) UpdateGCs, /* update_gcs */
290 False, /* optimize_redraw */
291 NULL, /* class_cache_part */
292 NULL, /* extension */
298 NULL, /* class_cache_part */
299 NULL, /* extension */
305 NULL, /* class_cache_part */
306 NULL, /* extension */
311 WidgetClass dtClockGadgetClass = (WidgetClass) &dtClockClassRec;
315 /*-------------------------------------------------------------
317 **-------------------------------------------------------------
320 /*-------------------------------------------------------------
326 XtPointer client_data,
329 DtClockGadget w = (DtClockGadget)client_data;
330 struct tm * localtime ();
334 register Display * dpy = XtDisplay (w);
335 register Window win = XtWindow (w);
337 if (id || !w->clock.interval_id)
338 w->clock.interval_id =
340 XtWidgetToApplicationContext ((Widget) w),
341 G_ClockInterval (w)*1000, ClockTick,
343 (void) time (&time_value);
344 tm = *localtime (&time_value);
346 if (! XtIsManaged ((Widget)w))
352 /* Beep on the half hour; double-beep on the hour.
354 if (w->clock.chime == TRUE)
356 if (w->clock.beeped && (tm.tm_min != 30) &&
358 w->clock.beeped = FALSE;
359 if (((tm.tm_min == 30) || (tm.tm_min == 0))
360 && (!w->clock.beeped))
362 w->clock.beeped = TRUE;
369 /* remove this when clipping added to gcs */
371 (Dimension)((G_ClockWidth (w) / 2) + w->clock.centerX)) ||
373 (Dimension)((G_ClockHeight (w) / 2) + w->clock.centerY)))
376 /* The second (or minute) hand is sec (or min) sixtieths around the
377 * clock face. The hour hand is (hour + min/60) twelfths of the way
378 * around the clock-face.
385 w->clock.segbuffptr = w->clock.segbuff;
388 /* Calculate the hour hand, fill it in with its color.
390 DrawHand (w, w->clock.minute_hand_length, w->clock.hand_width,
391 ((double) tm.tm_min)/60.0);
392 XDrawLines (dpy, win, G_ClockHandGC (w), w->clock.segbuff,
393 VERTICES_IN_HANDS, CoordModeOrigin);
394 XFillPolygon (dpy, win, G_ClockHandGC (w), w->clock.segbuff,
395 VERTICES_IN_HANDS, Convex, CoordModeOrigin);
397 w->clock.hour = w->clock.segbuffptr;
399 DrawHand (w, w->clock.hour_hand_length, w->clock.hand_width,
400 ((((double)tm.tm_hour) +
401 (((double)tm.tm_min)/60.0)) / 12.0));
402 XFillPolygon (dpy, win, G_ClockHandGC (w), w->clock.hour,
403 VERTICES_IN_HANDS, Convex, CoordModeOrigin);
404 XDrawLines (dpy, win, G_ClockHandGC (w), w->clock.hour,
405 VERTICES_IN_HANDS, CoordModeOrigin);
407 w->clock.sec = w->clock.segbuffptr;
413 /*-------------------------------------------------------------
415 ** Erase clock hands.
422 XmManagerWidget mgr = (XmManagerWidget) XtParent (w);
423 Display * dpy = XtDisplay (w);
424 Window win = XtWindow (w);
425 unsigned char behavior = G_Behavior (w);
428 if (! XtIsManaged ((Widget)w) || w->clock.numseg <= 0)
431 gc = G_ClockBackgroundGC (w);
435 if (!tm || tm->tm_min != w->clock.otm.tm_min ||
436 tm->tm_hour != w->clock.otm.tm_hour)
438 XDrawLines (dpy, win, gc, w->clock.segbuff,
439 VERTICES_IN_HANDS, CoordModeOrigin);
440 XDrawLines (dpy, win, gc, w->clock.hour,
441 VERTICES_IN_HANDS, CoordModeOrigin);
442 XFillPolygon (dpy, win, gc, w->clock.segbuff,
443 VERTICES_IN_HANDS, Convex, CoordModeOrigin);
444 XFillPolygon (dpy, win, gc, w->clock.hour,
445 VERTICES_IN_HANDS, Convex, CoordModeOrigin);
451 /*-------------------------------------------------------------
454 * blank_length is the distance from the center which the line begins.
455 * length is the maximum length of the hand.
456 * Fraction_of_a_circle is a fraction between 0 and 1 (inclusive) indicating
457 * how far around the circle (clockwise) from high noon.
459 * The blank_length feature is because I wanted to draw tick-marks around the
460 * circle (for seconds). The obvious means of drawing lines from the center
461 * to the perimeter, then erasing all but the outside most pixels doesn't
462 * work because of round-off error (sigh).
467 Dimension blank_length,
469 double fraction_of_a_circle )
471 double dblank_length = (double)blank_length, dlength = (double)length;
472 double angle, cosangle, sinangle;
475 int cx = w->clock.centerX, cy = w->clock.centerY, x1, y1, x2, y2;
478 * A full circle is 2 PI radians.
479 * Angles are measured from 12 o'clock, clockwise increasing.
480 * Since in X, +x is to the right and +y is downward:
482 * x = x0 + r * sin (theta)
483 * y = y0 - r * cos (theta)
486 angle = TWOPI * fraction_of_a_circle;
487 cosangle = cos (angle);
488 sinangle = sin (angle);
490 /* break this out so that stupid compilers can cope */
491 x1 = cx + (int) (dblank_length * sinangle);
492 y1 = cy - (int) (dblank_length * cosangle);
493 x2 = cx + (int) (dlength * sinangle);
494 y2 = cy - (int) (dlength * cosangle);
495 SetSegment (w, x1, y1, x2, y2);
500 /*-------------------------------------------------------------
504 * length is the maximum length of the hand.
505 * width is the half-width of the hand.
506 * Fraction_of_a_circle is a fraction between 0 and 1 (inclusive) indicating
507 * how far around the circle (clockwise) from high noon.
515 double fraction_of_a_circle )
517 register double angle, cosangle, sinangle;
518 register double ws, wc;
519 Position x, y, x1, y1, x2, y2;
523 /* A full circle is 2 PI radians.
524 * Angles are measured from 12 o'clock, clockwise increasing.
525 * Since in X, +x is to the right and +y is downward:
527 * x = x0 + r * sin (theta)
528 * y = y0 - r * cos (theta)
530 angle = TWOPI * fraction_of_a_circle;
531 cosangle = cos (angle);
532 sinangle = sin (angle);
534 /* Order of points when drawing the hand.
541 wc = width * cosangle;
542 ws = width * sinangle;
544 x = w->clock.centerX + round (length * sinangle),
545 y = w->clock.centerY - round (length * cosangle),
546 x1 = w->clock.centerX - round (ws + wc),
547 y1 = w->clock.centerY + round (wc - ws)); /* 1 ---- 2 */
548 SetSegment (w, x1, y1,
549 x2 = w->clock.centerX - round (ws - wc),
550 y2 = w->clock.centerY + round (wc + ws)); /* 2 ----- 3 */
551 SetSegment (w, x2, y2, x, y); /* 3 ----- 1 (4) */
556 /*-------------------------------------------------------------
558 ** Set segment values.
568 w->clock.segbuffptr->x = x1 + G_X (w);
569 w->clock.segbuffptr++->y = y1 + G_Y (w);
570 w->clock.segbuffptr->x = x2 + G_X (w);
571 w->clock.segbuffptr++->y = y2 + G_Y (w);
572 w->clock.numseg += 2;
576 /*-------------------------------------------------------------
584 return (x >= 0.0 ? (int) (x + .5) : (int) (x - .5));
589 /*-------------------------------------------------------------
592 * Draw the clock face (every fifth tick-mark is longer
599 Boolean draw_minute_ticks =
600 ((G_ClockWidth (g) > (Dimension) (2 * SIZE_DEFAULT)) &&
601 (G_ClockHeight (g) > (Dimension) (2 * SIZE_DEFAULT)));
604 (int)(g->clock.radius - g->clock.tick_spacing) / 3;
606 if (! XtIsManaged ((Widget)g))
609 g->clock.segbuffptr = g->clock.segbuff;
614 for (i = 0; i < 60; i++)
616 if (draw_minute_ticks)
619 DrawLine (g, g->clock.tick_spacing,
620 g->clock.radius, ((double) i)/60.);
622 DrawLine (g, g->clock.radius - delta,
623 g->clock.radius, ((double) i)/60.);
627 DrawLine (g, g->clock.radius - 1,
628 g->clock.radius, ((double) i)/60.);
633 XDrawSegments (XtDisplay (g), XtWindow (g), G_ClockHandGC (g),
634 (XSegment *) & (g->clock.segbuff[0]),
637 g->clock.segbuffptr = g->clock.segbuff;
643 /*-------------------------------------------------------------
645 **-------------------------------------------------------------
648 /*-------------------------------------------------------------
650 **-------------------------------------------------------------
654 /*-------------------------------------------------------------
656 ** Initialize a new gadget instance.
664 DtClockGadget request = (DtClockGadget) request_w,
665 new = (DtClockGadget) new_w;
667 h_t = G_HighlightThickness (new),
668 s_t = G_ShadowThickness (new);
669 XmManagerWidget mw = (XmManagerWidget) XtParent (new);
673 /* Set width and height.
675 if ((G_Width (request) == 0) ||
676 (G_Height (request) == 0))
678 G_ClockWidth (new) = SIZE_DEFAULT;
679 G_ClockHeight (new) = SIZE_DEFAULT;
680 G_GetSize ((DtIconGadget)new, &w, &h);
681 if (G_Width (request) == 0)
683 if (G_Height (request) == 0)
687 Resize ((Widget)new);
689 if (G_ClockInterval (new) <= 0)
690 G_ClockInterval (new) = 60; /* make invalid update's use a default */
691 new->clock.interval_id = 0;
692 new->clock.numseg = 0;
697 /*-------------------------------------------------------------
699 ** Release resources allocated for gadget.
705 DtClockGadget g = (DtClockGadget) w;
706 XmManagerWidget mw = (XmManagerWidget) XtParent (g);
708 if (g->clock.interval_id) XtRemoveTimeOut (g->clock.interval_id);
710 XtReleaseGC ((Widget) mw, G_ClockHandGC (g));
715 /*-------------------------------------------------------------
717 ** Set positions of string and pixmap.
723 DtClockGadget g = (DtClockGadget) widget;
724 Position pix_x, pix_y, str_x, str_y;
725 Dimension s_t = G_ShadowThickness (g),
726 h_t = G_HighlightThickness (g),
727 p_w = G_PixmapWidth (g),
728 p_h = G_PixmapHeight (g),
729 m_w = G_MarginWidth (g),
730 m_h = G_MarginHeight (g),
731 s_w = G_StringWidth (g),
732 s_h = G_StringHeight (g),
733 v_pad = 2 * (s_t + h_t + m_h),
734 h_pad = 2 * (s_t + h_t + m_w),
735 spacing = G_Spacing (g),
740 G_ClockWidth (g) = p_w - G_LeftInset (g) - G_RightInset (g);
741 G_ClockHeight (g) = p_h - G_TopInset (g) - G_BottomInset (g);
743 G_ClockWidth (g) = min (G_ClockWidth (g), G_ClockHeight (g));
744 G_ClockHeight (g) = G_ClockWidth (g);
746 G_GetPositions ((DtIconGadget)g, w, h, h_t, s_t,
747 &pix_x, &pix_y, &str_x, &str_y);
749 /* Compute clock size factors.
750 * (need signed radius value since Dimension is unsigned)
752 radius = ((int) min (G_ClockWidth (g), G_ClockHeight (g))/2);
753 g->clock.radius = (Dimension) max (radius, 1);
755 if (G_ClockWidth (g) < (Dimension)(SIZE_DEFAULT / 2))
757 g->clock.tick_spacing =
758 ((Dimension)(TICK_FRACT * g->clock.radius)/100);
759 g->clock.minute_hand_length =
760 ((Dimension)(MINUTE_HAND_FRACT * g->clock.radius)/100);
761 g->clock.hour_hand_length =
762 ((Dimension)(HOUR_HAND_FRACT * g->clock.radius)/100);
763 g->clock.hand_width =
764 ((Dimension)(HAND_WIDTH_FRACT * g->clock.radius)/100);
768 g->clock.tick_spacing =
769 ((Dimension)(SMALL_TICK_FRACT * g->clock.radius)/100);
770 g->clock.minute_hand_length =
771 ((Dimension)(SMALL_MINUTE_HAND_FRACT * g->clock.radius)/100);
772 g->clock.hour_hand_length =
773 ((Dimension)(SMALL_HOUR_HAND_FRACT * g->clock.radius)/100);
774 g->clock.hand_width =
775 ((Dimension)(SMALL_HAND_WIDTH_FRACT * g->clock.radius)/100);
778 /* Compute clock position factors.
780 g->clock.centerX = pix_x + (p_w / 2);
781 g->clock.centerY = pix_y + (p_h / 2);
786 /*-------------------------------------------------------------
798 DtClockGadget request = (DtClockGadget) request_w,
799 current = (DtClockGadget) current_w,
800 new = (DtClockGadget) new_w;
801 Boolean redraw_flag = False;
803 if (G_ClockInterval (new) != current->clock.update)
805 if (current->clock.interval_id)
806 XtRemoveTimeOut (current->clock.interval_id);
807 if (XtIsRealized (new))
808 new->clock.interval_id =
810 XtWidgetToApplicationContext (new_w),
811 G_ClockInterval (new)*1000,
812 (XtTimerCallbackProc) ClockTick,
816 /* Update clock face and hand color.
818 if ((G_ClockBackground (new) != G_ClockBackground (current)) ||
819 (G_ClockHandPixel (new) != G_ClockHandPixel (current)))
821 G_UpdateGCs ((DtIconGadget)new);
825 /* Update size factors if no resize.
827 if ((G_Width (new) == G_Width (current) &&
828 G_Height (new) == G_Height (current)) &&
829 (G_MarginWidth (new) != G_MarginWidth (current) ||
830 G_MarginHeight (new) != G_MarginHeight (current) ||
831 G_Spacing (new) != G_Spacing (current) ||
832 G_ShadowThickness (new) != G_ShadowThickness (current) ||
833 G_HighlightThickness (new) != G_HighlightThickness (current)))
836 return (redraw_flag);
841 /*-------------------------------------------------------------
843 **-------------------------------------------------------------
847 /*-------------------------------------------------------------
849 **-------------------------------------------------------------
852 /*-------------------------------------------------------------
854 ** Draw gadget to drawable.
866 unsigned char s_type,
867 unsigned char fill_mode )
869 XmManagerWidget mgr = (XmManagerWidget) XtParent (g);
870 Display * d = XtDisplay (g);
873 Position p_x, p_y, s_x, s_y;
874 unsigned char behavior = G_Behavior (g);
875 Dimension m_w = G_MarginWidth (g);
876 Dimension m_h = G_MarginHeight (g);
877 Dimension h_pad = h_t + s_t + m_w;
878 Dimension v_pad = h_t + s_t + m_h;
879 Dimension width, height;
884 bMono = ( ((G_Foreground (g) == BlackPixelOfScreen (XtScreen (g))) ||
885 (G_Foreground (g) == WhitePixelOfScreen (XtScreen (g)))) &&
886 ((G_Background (g) == BlackPixelOfScreen (XtScreen (g))) ||
887 (G_Background (g) == WhitePixelOfScreen (XtScreen (g)))) );
889 if ((G_Armed (g)) && (fill_mode != XmFILL_PARENT))
890 gc = G_ArmedBackgroundGC (g);
892 gc = M_BackgroundGC (mgr);
894 if ((fill_mode != XmFILL_NONE) && (fill_mode != XmFILL_TRANSPARENT))
895 XFillRectangle (d, drawable, gc, x + h_t, y + h_t,
896 w - 2 * h_t, h - 2 * h_t);
898 G_GetPositions ((DtIconGadget)g, w, h, h_t, s_t, &p_x, &p_y, &s_x, &s_y);
902 width = ((Dimension)(p_x + s_t + h_t) >= G_Width (g))
903 ? 0 : min (G_PixmapWidth (g),
904 (Dimension)(G_Width (g) - p_x - s_t - h_t));
905 height = ((Dimension)(p_y + s_t + h_t) >= G_Height (g))
906 ? 0 : min (G_PixmapHeight (g),
907 (Dimension)(G_Height (g) - p_y - s_t - h_t));
915 if (mask != XmUNSPECIFIED_PIXMAP)
918 XSetClipMask (XtDisplay(g), gc, mask);
919 XSetClipOrigin (XtDisplay(g), gc, x + p_x, y + p_y);
926 if ((gc != NULL) && (pix != XmUNSPECIFIED_PIXMAP))
927 XCopyArea (d, pix, drawable, gc, 0, 0,
928 width, height, x + p_x, y + p_y);
931 /* Fill clock face region and draw clock.
933 if (g->clock.numseg != 0)
934 EraseHands (g, (struct tm *) 0);
936 ClockTick ((XtPointer)g, (XtIntervalId)0);
940 if ((behavior == XmICON_BUTTON || behavior == XmICON_DRAG) &&
941 G_FillOnArm (g) && G_Armed (g))
943 else if (behavior == XmICON_TOGGLE && G_FillOnArm (g) &&
944 ((G_Armed (g) && !G_Set (g)) ||
945 (!G_Armed (g) && G_Set (g))))
954 clip.x = x + h_t + s_x;
955 clip.y = y + h_t + s_y;
956 clip.width = G_Width (g) - (2 * (h_t + s_t));
957 clip.height = G_Height (g) - (2 * (h_t + s_t));
958 if (clip.width > 0 && clip.height > 0)
962 if ((s_x - 2) >= (Position)(h_t + s_t))
963 XFillRectangle (d, drawable,
964 G_ArmedBackgroundGC (g),
965 x + s_x - 2, y + s_y,
966 2, G_StringHeight (g));
967 XmStringDrawImage (d, drawable, G_FontList (g),
968 G_String (g), G_NormalGC (g),
970 clip.width, XmALIGNMENT_BEGINNING,
971 XmSTRING_DIRECTION_L_TO_R, &clip);
972 if ((s_x + (Position)(G_StringWidth (g) + 2))
973 <= (Position)(G_Width (g) - h_t - s_t))
974 XFillRectangle (d, drawable,
975 G_ArmedBackgroundGC (g),
976 x + s_x + G_StringWidth (g),
977 y + s_y, 2, G_StringHeight (g));
981 if (G_UseEmbossedText (g))
982 XmStringDraw (d, drawable, G_FontList (g),
983 G_String (g), G_BottomShadowGC (g),
984 x + s_x + 1, y + s_y + 1,
985 clip.width, XmALIGNMENT_BEGINNING,
986 XmSTRING_DIRECTION_L_TO_R, &clip);
987 XmStringDraw (d, drawable, G_FontList (g),
988 G_String (g), G_NormalGC (g),
990 clip.width, XmALIGNMENT_BEGINNING,
991 XmSTRING_DIRECTION_L_TO_R, &clip);
1001 /*-------------------------------------------------------------
1003 ** Get normal and background graphics contexts.
1004 ** Use standard mask to maximize caching opportunities.
1011 XtGCMask value_mask;
1012 XmManagerWidget mw = (XmManagerWidget) XtParent(g);
1016 super = (DtIconGadgetClass) XtSuperclass (g);
1017 static Boolean first = True;
1019 /* Let superclass do most of the work.
1021 (* C_UpdateGCs (super)) ((DtIconGadget)g);
1025 else if (G_ClockHandGC (g))
1026 XtReleaseGC ((Widget)mw, G_ClockHandGC (g));
1028 /* Get clock hand GC.
1030 font_rtn = XmeRenderTableGetDefaultFont (G_FontList (g), &font);
1031 value_mask = GCForeground | GCFont | GCFillStyle;
1033 if (((G_PixmapForeground (g) == WhitePixelOfScreen (XtScreen (g))) &&
1034 (G_PixmapBackground (g) == BlackPixelOfScreen (XtScreen (g)))) ||
1035 ((G_PixmapForeground (g) == BlackPixelOfScreen (XtScreen (g))) &&
1036 (G_PixmapBackground (g) == WhitePixelOfScreen (XtScreen (g)))))
1037 values.foreground = G_PixmapBackground (g);
1039 values.foreground = mw->manager.top_shadow_color;
1040 values.fill_style = FillSolid;
1041 values.font = font->fid;
1043 G_ClockHandGC (g) = XtGetGC ((Widget) mw, value_mask, &values);
1045 /* Get clock background GC
1048 value_mask |= GCBackground;
1050 if (((G_PixmapForeground (g) == WhitePixelOfScreen (XtScreen (g))) &&
1051 (G_PixmapBackground (g) == BlackPixelOfScreen (XtScreen (g)))) ||
1052 ((G_PixmapForeground (g) == BlackPixelOfScreen (XtScreen (g))) &&
1053 (G_PixmapBackground (g) == WhitePixelOfScreen (XtScreen (g)))))
1054 values.foreground = G_PixmapForeground (g);
1056 values.foreground = G_ArmColor (g);
1057 values.background = G_PixmapBackground (g);
1059 G_ClockBackgroundGC (g) = XtGetGC ((Widget) mw, value_mask, &values);
1064 /*-------------------------------------------------------------
1065 ** Public Entry Points
1066 **-------------------------------------------------------------
1069 /*-------------------------------------------------------------
1071 ** Create a new gadget instance.
1072 **-------------------------------------------------------------
1081 return (XtCreateWidget (name, dtClockGadgetClass,
1082 parent, arglist, argcount));