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 /* $TOG: Control.c /main/18 1997/04/22 11:40:14 mgreess $
25 * (c) Copyright 1996 Digital Equipment Corporation.
26 * (c) Copyright 1992,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.
34 /**---------------------------------------------------------------------
38 *** project: MotifPlus Widgets
40 *** description: Source code for DtControl class.
42 ***-------------------------------------------------------------------*/
45 /*-------------------------------------------------------------
51 #include <sys/types.h> /* needed for sys/stat.h on bsd4.3 */
56 #define X_INCLUDE_STRING_H
57 #define X_INCLUDE_TIME_H
58 #define XOS_USE_XT_LOCKING
59 #include <X11/Xos_r.h>
60 #include <Xm/GadgetP.h>
63 #include <Dt/Control.h>
64 #include <Dt/ControlP.h>
65 #include <Xm/ManagerP.h>
66 #include <Dt/MacrosP.h>
68 #include "DtWidgetI.h"
69 #include "DtSvcInternal.h"
72 /******** Public Function Declarations ********/
74 extern Widget _DtCreateControl(
80 /******** End Public Function Declarations ********/
82 /******** Static Function Declarations ********/
84 static void ClickTimeout(
85 XtPointer client_data,
87 static void BusyTimeout(
88 XtPointer client_data,
90 static void DateTimeout(
91 XtPointer client_data,
93 static void PushAnimationTimeout(
94 XtPointer client_data,
96 static void DropAnimationTimeout(
97 XtPointer client_data,
99 static void FileCheckTimeout(
100 XtPointer client_data,
102 static void CheckFile(
104 static void ClassInitialize( void ) ;
105 static void ClassPartInitialize(
108 static void Destroy (Widget);
110 static void Initialize(
113 static Boolean SetValues(
121 static void GetPositions(
140 unsigned char s_type,
141 unsigned char fill_mode) ;
142 static void CallCallback(
147 static void UpdateGCs(
149 static void ReplaceJPDate(
154 /******** End Static Function Declarations ********/
157 /*-------------------------------------------------------------
159 **-------------------------------------------------------------
162 WidgetClass dtControlGadgetClass;
165 #define UNSPECIFIED_DIMENSION 9999
166 #define UNSPECIFIED_CHAR 255
169 static const char _DtMsgIndicator_0000[] = "/var/mail/";
170 #elif defined(__osf__)
171 static const char _DtMsgIndicator_0000[] = "/usr/spool/mail/";
173 static const char _DtMsgIndicator_0000[] = "/usr/mail/";
176 #define MAIL_DIR _DtMsgIndicator_0000
177 #define Min(x, y) (((x) < (y)) ? (x) : (y))
178 #define Max(x, y) (((x) > (y)) ? (x) : (y))
180 #define G_Width(r) (r -> rectangle.width)
181 #define G_Height(r) (r -> rectangle.height)
183 /*-------------------------------------------------------------
186 #define R_Offset(field) \
187 XtOffset (DtControlGadget, control.field)
188 static XtResource resources[] =
192 XmCBoolean, XmRBoolean, sizeof (Boolean),
193 R_Offset (_do_update), XmRImmediate, (XtPointer) FALSE
197 XmCBoolean, XmRBoolean, sizeof (Boolean),
198 R_Offset (use_embossed_text), XmRImmediate, (XtPointer) TRUE
202 XmCPushFunction, XmRFunction, sizeof (XtPointer),
203 R_Offset (push_function),
204 XmRImmediate, (XtPointer) NULL
208 XmCPushArgument, XmRPointer, sizeof (XtPointer),
209 R_Offset (push_argument),
210 XmRImmediate, (XtPointer) NULL
214 XmCDropAction, XmRString, sizeof (String),
215 R_Offset (drop_action),
216 XmRImmediate, (XtPointer) NULL
220 "PushAction", XmRString, sizeof (String),
221 R_Offset (push_action),
222 XmRImmediate, (XtPointer) NULL
226 XmCFormat, XmRString, sizeof (String),
228 XmRImmediate, (XtPointer) "%b%n%e"
232 XmCFormatJP, XmRString, sizeof (String),
233 R_Offset (format_jp),
234 XmRImmediate, (XtPointer) NULL
238 XmCSubpanel, XmRWidget, sizeof (Widget),
240 XmRImmediate, (XtPointer) NULL
244 XmCControlType, XmRControlType, sizeof (unsigned char),
245 R_Offset (control_type),
246 XmRImmediate, (XtPointer) XmCONTROL_NONE
250 XmCString, XmRString, sizeof (XmString),
251 R_Offset (file_name), XmRImmediate, (XtPointer) NULL
255 XmCAlternateImage, XmRString, sizeof (String),
256 R_Offset (alt_image), XmRImmediate, (XtPointer) NULL
260 XmCBoolean, XmRBoolean, sizeof (Boolean),
261 R_Offset (chime), XmRImmediate, (XtPointer) FALSE
264 XmNclientTimeoutInterval,
265 XmCInterval, XmRInt, sizeof (int),
266 R_Offset (max_blink_time), XmRImmediate, (XtPointer) 10000
270 XmCInterval, XmRInt, sizeof (int),
271 R_Offset (blink_time), XmRImmediate, (XtPointer) 500
275 XmCInterval, XmRInt, sizeof (int),
276 R_Offset (monitor_time), XmRImmediate, (XtPointer) 30000
279 XmNpushButtonClickTime,
280 XmCInterval, XmRInt, sizeof (int),
281 R_Offset (click_time),
282 XmRImmediate, (XtPointer) 1000
285 XmNuseLabelAdjustment,
286 XmCBoolean, XmRBoolean, sizeof (Boolean),
287 R_Offset (use_label_adj), XmRImmediate, (XtPointer) TRUE
293 static XmBaseClassExtRec controlBaseClassExtRec = {
294 NULL, /* Next extension */
295 NULLQUARK, /* record type XmQmotif */
296 XmBaseClassExtVersion, /* version */
297 sizeof(XmBaseClassExtRec), /* size */
298 XmInheritInitializePrehook, /* initialize prehook */
299 XmInheritSetValuesPrehook, /* set_values prehook */
300 XmInheritInitializePosthook, /* initialize posthook */
301 XmInheritSetValuesPosthook, /* set_values posthook */
302 (WidgetClass)&dtControlCacheObjClassRec, /* secondary class */
303 XmInheritSecObjectCreate, /* creation proc */
304 XmInheritGetSecResData, /* getSecResData */
305 {0}, /* fast subclass */
306 XmInheritGetValuesPrehook, /* get_values prehook */
307 XmInheritGetValuesPosthook, /* get_values posthook */
308 NULL, /* classPartInitPrehook */
309 NULL, /* classPartInitPosthook*/
310 NULL, /* ext_resources */
311 NULL, /* compiled_ext_resources*/
312 0, /* num_ext_resources */
313 FALSE, /* use_sub_resources */
314 XmInheritWidgetNavigable, /* widgetNavigable */
315 XmInheritFocusChange, /* focusChange */
318 /* ext rec static initialization */
319 externaldef (xmcontrolcacheobjclassrec)
320 DtControlCacheObjClassRec dtControlCacheObjClassRec =
323 /* superclass */ (WidgetClass) &xmExtClassRec,
324 /* class_name */ "DtControl",
325 /* widget_size */ sizeof(DtControlCacheObjRec),
326 /* class_initialize */ NULL,
327 /* chained class init */ NULL,
328 /* class_inited */ False,
329 /* initialize */ NULL,
330 /* initialize hook */ NULL,
334 /* resources */ NULL,
335 /* num_resources */ 0,
336 /* xrm_class */ NULLQUARK,
337 /* compress_motion */ False,
338 /* compress_exposure */ False,
339 /* compress enter/exit*/ False,
340 /* visible_interest */ False,
344 /* set_values */ NULL,
345 /* set values hook */ NULL,
346 /* set values almost */ NULL,
347 /* get values hook */ NULL,
348 /* accept_focus */ NULL,
349 /* version */ XtVersion,
350 /* callback offsetlst */ NULL,
351 /* default trans */ NULL,
352 /* query geo proc */ NULL,
353 /* display accelerator*/ NULL,
354 /* extension record */ (XtPointer)NULL,
358 /* synthetic resources */ NULL,
359 /* num_syn_resources */ 0,
360 /* extension */ NULL,
365 /*-------------------------------------------------------------
368 DtControlClassRec dtControlClassRec =
373 (WidgetClass) &dtIconClassRec, /* superclass */
374 "Control", /* class_name */
375 sizeof (DtControlRec), /* widget_size */
376 ClassInitialize, /* class_initialize */
377 ClassPartInitialize, /* class_part_initialize*/
378 False, /* class_inited */
379 (XtInitProc) Initialize, /* initialize */
380 NULL, /* initialize_hook */
384 resources, /* resources */
385 XtNumber (resources), /* num_resources */
387 NULLQUARK, /* xrm_class */
388 True, /* compress_motion */
389 True, /* compress_exposure */
390 True, /* compress_enterleave */
391 False, /* visible_interest */
392 Destroy, /* destroy */
393 XtInheritResize, /* resize */
394 XtInheritExpose, /* expose */
395 (XtSetValuesFunc)SetValues, /* set_values */
396 NULL, /* set_values_hook */
397 XtInheritSetValuesAlmost, /* set_values_almost */
398 NULL, /* get_values_hook */
399 NULL, /* accept_focus */
400 XtVersion, /* version */
401 NULL, /* callback private */
403 NULL, /* query_geometry */
404 NULL, /* display_accelerator */
405 (XtPointer)&controlBaseClassExtRec, /* extension */
412 (XtWidgetProc) XmInheritBorderHighlight, /* border_highlight */
413 (XtWidgetProc) XmInheritBorderUnhighlight, /* border_unhighlight */
414 (XtActionProc) XmInheritArmAndActivate, /* arm_and_activate */
415 (XmWidgetDispatchProc) XmInheritInputDispatch, /* input_dispatch */
416 (XmVisualChangeProc) XmInheritVisualChange, /* visual_change */
417 NULL, /* get_resources */
418 0, /* num_get_resources */
419 XmInheritCachePart, /* class_cache_part */
420 NULL, /* extension */
426 (GetSizeProc) GetSize, /* get_size */
427 (GetPositionProc) GetPositions, /* get_positions */
428 (DrawProc) Draw, /* draw */
429 (CallCallbackProc) CallCallback, /* call_callback */
430 (UpdateGCsProc) UpdateGCs, /* update_gcs */
431 True, /* optimize_redraw */
432 NULL, /* class_cache_part */
433 NULL, /* extension */
439 NULL, /* class_cache_part */
440 NULL, /* extension */
445 WidgetClass dtControlGadgetClass = (WidgetClass) &dtControlClassRec;
449 /*-------------------------------------------------------------
451 **-------------------------------------------------------------
454 /*-------------------------------------------------------------
456 ** Check for change in file, reset timeout.
457 ** An XtTimerCallbackProc.
461 XtPointer client_data,
464 DtControlGadget g = (DtControlGadget) client_data;
465 XtAppContext app_context =
466 XtWidgetToApplicationContext ((Widget) g);
471 XtAppAddTimeOut (app_context, G_MonitorTime (g),
472 FileCheckTimeout, (XtPointer) g);
476 /*-------------------------------------------------------------
478 ** Check for change in file size
484 Boolean file_changed;
486 struct stat stat_buf;
488 if (stat (G_FileName (g), &stat_buf) == 0)
490 file_size = stat_buf.st_size;
493 switch (G_ControlType (g))
495 case XmCONTROL_MONITOR:
496 file_changed = (file_size == 0) ? False : True;
501 file_changed = False;
502 else if (stat_buf.st_atime > stat_buf.st_mtime)
503 file_changed = False;
504 else if (file_size == G_FileSize (g))
505 file_changed = G_FileChanged (g);
506 else if (file_size > G_FileSize (g))
509 file_changed = False;
513 /* unsupported control type */
517 G_FileSize (g) = file_size;
518 if (file_changed != G_FileChanged (g))
521 CallCallbackProc call_callback;
524 expose = XtCoreProc((Widget)g, expose);
525 call_callback = C_CallCallback(XtClass(g));
528 G_FileChanged (g) = file_changed;
529 (*call_callback) ((DtIconGadget) g, G_Callback (g), XmCR_MONITOR, NULL);
530 (*expose)((Widget)g, NULL, NULL);
531 XmUpdateDisplay ((Widget) g);
537 /*-------------------------------------------------------------
539 ** An XtTimerCallbackProc.
544 XtPointer client_data,
547 DtControlGadget g = (DtControlGadget) client_data;
549 G_ClickTimer (g) = 0;
554 /*-------------------------------------------------------------
557 ** An XtTimerCallbackProc.
561 XtPointer client_data,
564 DtControlGadget g = (DtControlGadget) client_data;
565 XtAppContext app_context = XtWidgetToApplicationContext((Widget) g);
567 CallCallbackProc call_callback;
570 expose = XtCoreProc((Widget)g, expose);
571 call_callback = C_CallCallback(XtClass((Widget)g));
574 if ((G_Busy (g) > 0) && (G_BlinkElapsed (g) < G_MaxBlinkTime (g)))
576 G_Set (g) = ! G_Set (g);
578 XtAppAddTimeOut (app_context, G_BlinkTime (g),
579 BusyTimeout, (XtPointer) g);
580 G_BlinkElapsed (g) += G_BlinkTime (g);
585 G_BlinkTimer (g) = 0;
586 G_BlinkElapsed (g) = 0;
588 (*call_callback) ((DtIconGadget) g, G_Callback (g), XmCR_BUSY_STOP, NULL);
591 (*expose) ((Widget) g, NULL, False);
596 /*-------------------------------------------------------------
598 ** Update date strings.
599 ** An XtTimerCallbackProc.
603 XtPointer client_data,
606 DtControlGadget g = (DtControlGadget) client_data;
607 XtAppContext app_context =
608 XtWidgetToApplicationContext ((Widget) g);
613 unsigned long tilMidnight;
619 timeptr = _XLocaltime(&tse, localtime_buf);
620 strftime ((char*) sTime, 128, G_Format (g), timeptr);
621 if (g->control.format_jp != NULL && strlen(g->control.format_jp) != 0)
622 ReplaceJPDate(sTime, g->control.format_jp, timeptr->tm_wday);
624 /* Break time string between date and day of week.
627 s2 = strchr (sTime, '\n');
633 s3 = strchr (s2+1, '\n');
645 /* Create date string.
651 XmStringFree(G_String(g));
652 G_String (g) = XmStringCreate (s1, XmFONTLIST_DEFAULT_TAG);
653 XmStringExtent (G_FontList (g), G_String (g),
654 &(G_StringWidth (g)), &(G_StringHeight (g)));
656 if (G_AltString (g) != NULL)
658 XmStringFree (G_AltString (g));
659 G_AltString (g) = NULL;
660 G_AltStringHeight (g) = 0;
661 G_AltStringWidth (g) = 0;
666 if (!G_UseLabelAdjustment (g))
673 if (G_AltString (g) != NULL)
674 XmStringFree (G_AltString (g));
675 G_AltString (g) = XmStringCreate (s1, XmFONTLIST_DEFAULT_TAG);
676 XmStringExtent (G_FontList (g), G_AltString (g),
677 &(G_AltStringWidth (g)), &(G_AltStringHeight (g)));
678 XmStringFree(G_String(g));
679 G_String (g) = XmStringCreate (s2, XmFONTLIST_DEFAULT_TAG);
680 XmStringExtent (G_FontList (g), G_String (g),
681 &(G_StringWidth (g)), &(G_StringHeight (g)));
688 expose = XtCoreProc((Widget)g, expose);
690 (*expose) ((Widget) g, NULL, False);
691 XmUpdateDisplay ((Widget) g);
693 /* Compute milliseconds until midnight:
694 * a. compute current time in seconds
695 * b. subtract that from number of seconds in a day.
696 * c. multiply by 1000 to get milliseconds.
699 tilMidnight = 1000 * (86400 - ((3600 * timeptr->tm_hour) +
700 (60 * timeptr->tm_min) +
703 if (G_Format (g) != NULL)
706 XtAppAddTimeOut (app_context, tilMidnight,
707 DateTimeout, (XtPointer) g);
717 /*-------------------------------------------------------------
719 **-------------------------------------------------------------
724 /*-------------------------------------------------------------
726 **-------------------------------------------------------------
730 /*-------------------------------------------------------------
735 ClassInitialize( void )
737 controlBaseClassExtRec.record_type = XmQmotif;
741 /*-------------------------------------------------------------
742 ** ClassPartInitialize
749 dtControlCacheObjClassRec.object_class.resources =
750 dtIconCacheObjClassRec.object_class.resources;
752 dtControlCacheObjClassRec.object_class.num_resources =
753 dtIconCacheObjClassRec.object_class.num_resources;
758 /*-------------------------------------------------------------
760 ** Initialize a new gadget instance.
767 DtControlGadget request = (DtControlGadget) request_w,
768 new = (DtControlGadget) new_w;
769 XtAppContext app_context =
770 XtWidgetToApplicationContext (new_w);
772 UpdateGCsProc update_gcs;
774 G_MonitorTimer (new) = 0;
775 G_ClickTimer (new) = 0;
776 G_DateTimer (new) = 0;
777 G_BlinkTimer (new) = 0;
778 G_PushAnimationTimer (new) = 0;
779 G_DropAnimationTimer (new) = 0;
781 G_FileSize (new) = 0;
782 G_FileChanged (new) = False;
785 G_AltString (new) = NULL;
786 G_AltStringWidth (new) = 0;
787 G_AltStringHeight (new) = 0;
789 /* Initialize animation data.
791 G_NumPushImages (new) = 0;
792 G_MaxPushImages (new) = 0;
793 G_PushImagePosition (new) = 0;
794 G_PushDelays (new) = NULL;
795 G_PushPixmaps (new) = NULL;
796 G_PushMasks (new) = NULL;
798 G_NumDropImages (new) = 0;
799 G_MaxDropImages (new) = 0;
800 G_DropImagePosition (new) = 0;
801 G_DropDelays (new) = NULL;
802 G_DropPixmaps (new) = NULL;
803 G_DropMasks (new) = NULL;
805 /* Copy drop argument.
807 if (G_DropAction (new) != NULL)
809 String str = G_DropAction (new);
810 G_DropAction (new) = XtMalloc (strlen (str) + 1);
811 strcpy (G_DropAction (new), str);
814 if (G_PushAction (new) != NULL)
816 String str = G_PushAction (new);
817 G_PushAction (new) = XtMalloc (strlen (str) + 1);
818 strcpy (G_PushAction (new), str);
821 /* Validate control type.
823 if (G_ControlType (new) != XmCONTROL_NONE &&
824 G_ControlType (new) != XmCONTROL_SWITCH &&
825 G_ControlType (new) != XmCONTROL_BUTTON &&
826 G_ControlType (new) != XmCONTROL_BLANK &&
827 G_ControlType (new) != XmCONTROL_DATE &&
828 G_ControlType (new) != XmCONTROL_BUSY &&
829 G_ControlType (new) != XmCONTROL_CLIENT &&
830 G_ControlType (new) != XmCONTROL_MAIL &&
831 G_ControlType (new) != XmCONTROL_MONITOR)
833 G_ControlType (new) = XmCONTROL_NONE;
836 if (G_ControlType (new) == XmCONTROL_SWITCH)
837 G_ShadowType (new) = (G_Set (new)) ? XmSHADOW_IN : XmSHADOW_OUT;
839 if ( ((G_ControlType (new) == XmCONTROL_MONITOR) ||
840 (G_ControlType (new) == XmCONTROL_MAIL) ||
841 (G_ControlType (new) == XmCONTROL_BUSY)) &&
842 (G_AltImage (new) != NULL))
845 /* Copy string or default to user mail directory.
847 if ((G_ControlType (new) == XmCONTROL_MONITOR) ||
848 (G_ControlType (new) == XmCONTROL_MAIL))
850 if (G_FileName (new) == NULL)
852 if (G_ControlType (new) == XmCONTROL_MAIL)
854 if ((str = getenv ("MAIL")) == NULL)
856 str = getenv ("LOGNAME");
858 XtMalloc (strlen (MAIL_DIR) + strlen (str) + 1);
859 strcpy (G_FileName (new), MAIL_DIR);
860 strcat (G_FileName (new), str);
864 G_FileName (new) = XtMalloc (strlen (str) + 1);
865 strcpy (G_FileName (new), str);
871 str = G_FileName (new);
872 G_FileName (new) = XtMalloc (strlen (str) + 1);
873 strcpy (G_FileName (new), str);
876 G_FileChanged (new) = False;
879 /* Get alternate pixmap and mask.
882 XmGetPixmap (XtScreen (new), G_AltImage (new),
883 G_PixmapForeground (new),
884 G_PixmapBackground (new));
886 _DtGetMask (XtScreen (new), G_AltImage (new));
887 G_AltImage (new) = NULL;
889 if ((G_AltPix (new) != XmUNSPECIFIED_PIXMAP) &&
890 ((G_ControlType (new) == XmCONTROL_MONITOR) ||
891 (G_ControlType (new) == XmCONTROL_MAIL)))
894 G_MonitorTimer (new) =
895 XtAppAddTimeOut (app_context, G_MonitorTime (new),
896 FileCheckTimeout, (XtPointer) new);
899 /* Check for Control state change.
904 G_AltPix (new) = XmUNSPECIFIED_PIXMAP;
905 G_AltMask (new) = XmUNSPECIFIED_PIXMAP;
906 G_MonitorTimer (new) = 0;
907 G_FileName (new) = NULL;
910 if (G_ControlType (new) == XmCONTROL_DATE)
914 DateTimeout ((XtPointer) new_w, NULL);
916 if (G_Width (request) == 0 || G_Height (request) == 0)
918 GetSizeProc get_size;
921 get_size = C_GetSize(XtClass(new));
923 (*get_size) ((DtIconGadget) new, &w, &h);
924 if (G_Width (request) == 0)
926 if (G_Height (request) == 0)
931 G_ArmedGC (new) = NULL;
933 G_TopShadowGC (new) = NULL;
934 G_BottomShadowGC (new) = NULL;
935 G__DoUpdate (new) = True;
937 update_gcs = C_UpdateGCs(XtClass(new));
939 (*update_gcs) ((DtIconGadget) new);
940 G__DoUpdate (new) = False;
945 /*-------------------------------------------------------------
947 ** Release resources allocated for gadget.
954 DtControlGadget g = (DtControlGadget) w;
956 if (G_FileName (g) != NULL)
957 XtFree (G_FileName (g));
959 if (G_NumPushImages (g) > 0)
961 XtFree ((char*) G_PushDelays (g));
962 XtFree ((char*) G_PushPixmaps (g));
963 XtFree ((char*) G_PushMasks (g));
965 if (G_NumDropImages (g) > 0)
967 XtFree ((char*) G_DropDelays (g));
968 XtFree ((char*) G_DropPixmaps (g));
969 XtFree ((char*) G_DropMasks (g));
971 if (G_DropAction (g) != NULL)
972 XtFree (G_DropAction (g));
973 if (G_PushAction (g) != NULL)
974 XtFree (G_PushAction (g));
976 if (G_AltString (g) != NULL)
977 XmStringFree (G_AltString (g));
979 if (G_ClickTimer (g))
980 XtRemoveTimeOut (G_ClickTimer (g));
981 if (G_BlinkTimer (g))
982 XtRemoveTimeOut (G_BlinkTimer (g));
983 if (G_MonitorTimer (g))
984 XtRemoveTimeOut (G_MonitorTimer (g));
986 XtRemoveTimeOut (G_DateTimer (g));
987 if (G_PushAnimationTimer (g))
988 XtRemoveTimeOut (G_PushAnimationTimer (g));
989 if (G_DropAnimationTimer (g))
990 XtRemoveTimeOut (G_DropAnimationTimer (g));
995 /*-------------------------------------------------------------
1007 DtControlGadget current_c = (DtControlGadget) current_w,
1008 new_c = (DtControlGadget) new_w;
1010 String file_name = G_FileName (new);
1012 Boolean redraw_flag = False;
1015 if (strcmp(G_Format(new_c),G_Format(current_c)) &&
1016 G_ControlType (new_c) == XmCONTROL_DATE)
1018 if (G_DateTimer (new_c))
1019 XtRemoveTimeOut (G_DateTimer (new_c));
1021 if (G_Format(new_c) != NULL)
1022 DateTimeout ((XtPointer) new_w, NULL);
1025 if (G_ImageName (new_c) && (G_ImageName (current_c) != G_ImageName (new_c)))
1032 /* Copy drop argument.
1034 if (G_DropAction (new) != G_DropAction (current))
1036 String str = G_DropAction (new);
1037 if (G_DropAction (current) != NULL)
1038 XtFree (G_DropAction (current));
1039 G_DropAction (new) = XtMalloc (strlen (str) + 1);
1040 strcpy (G_DropAction (new), str);
1043 if (G_PushAction (new) != G_PushAction (current))
1045 String str = G_PushAction (new);
1046 if (G_PushAction (current) != NULL)
1047 XtFree (G_PushAction (current));
1048 G_PushAction (new) = XtMalloc (strlen (str) + 1);
1049 strcpy (G_PushAction (new), str);
1052 /* Copy string or default to user mail directory.
1054 if ((G_ControlType (new) == XmCONTROL_MONITOR) ||
1055 (G_ControlType (new) == XmCONTROL_MAIL))
1057 if (G_FileName (new) != G_FileName (current))
1059 if (G_FileName (current) != NULL)
1060 XtFree (G_FileName (current));
1061 if (G_FileName (new) != NULL)
1063 file_name_size = strlen (G_FileName (new));
1064 G_FileName (new) = XtMalloc (file_name_size);
1065 strcpy (G_FileName (new), file_name);
1070 return (redraw_flag);
1075 /*-------------------------------------------------------------
1077 **-------------------------------------------------------------
1081 /*-------------------------------------------------------------
1083 **-------------------------------------------------------------
1086 /*-------------------------------------------------------------
1096 Dimension s_t = G_ShadowThickness (g);
1097 Dimension h_t = G_HighlightThickness (g);
1098 Dimension p_w = G_PixmapWidth (g);
1099 Dimension p_h = G_PixmapHeight (g);
1100 Dimension m_w = G_MarginWidth (g);
1101 Dimension m_h = G_MarginHeight (g);
1102 Dimension s_w = G_StringWidth (g);
1103 Dimension s_h = G_StringHeight (g);
1104 Dimension v_pad = 2 * (s_t + h_t + m_h);
1105 Dimension h_pad = 2 * (s_t + h_t + m_w);
1106 Dimension spacing = G_Spacing (g);
1108 if (((p_w == 0) && (p_h == 0)) || ((s_w == 0) && (s_h == 0)))
1111 if (G_ControlType (g) == XmCONTROL_DATE)
1113 /* Adjust size based on second date string.
1115 if ( (G_StringWidth (g) > 0) &&
1116 (G_AltStringWidth (g) > G_StringWidth (g)) )
1117 s_w = G_AltStringWidth (g);
1118 if ( (G_StringWidth (g) > 0) && (G_AltStringWidth (g) > 0) )
1119 s_h += spacing + G_AltStringHeight (g);
1123 /* Add left and right spacing for string.
1129 /* Get width and height.
1131 switch ((int) G_PixmapPosition (g))
1134 case XmPIXMAP_BOTTOM:
1135 *w = Max (p_w, s_w) + h_pad;
1136 *h = p_h + s_h + v_pad + spacing;
1139 case XmPIXMAP_RIGHT:
1140 *w = p_w + s_w + h_pad + spacing;
1141 *h = Max (p_h, s_h) + v_pad;
1143 case XmPIXMAP_MIDDLE:
1144 *w = Max (p_w, s_w) + h_pad;
1145 *h = Max (p_h, s_h) + v_pad;
1152 /*-------------------------------------------------------------
1154 ** Get positions of string and pixmap.
1168 Dimension p_w = G_PixmapWidth (g),
1169 p_h = G_PixmapHeight (g),
1170 s_w = G_StringWidth (g),
1171 s_h = G_StringHeight (g),
1172 m_w = G_MarginWidth (g),
1173 m_h = G_MarginHeight (g),
1174 spacing = G_Spacing (g),
1175 h_pad = s_t + h_t + m_w,
1176 v_pad = s_t + h_t + m_h,
1177 width = w - 2 * h_pad,
1178 height = h - 2 * v_pad;
1179 Position p_x = h_pad,
1183 unsigned char align = G_Alignment (g);
1185 if (((p_w == 0) && (p_h == 0)) || ((s_w == 0) && (s_h == 0)))
1190 switch ((int) G_PixmapPosition (g))
1193 if (align == XmALIGNMENT_CENTER)
1195 if (p_w && width > p_w)
1196 p_x += (width - p_w)/2U;
1197 if (s_w && width > s_w)
1198 s_x += (width - s_w)/2U;
1200 else if (align == XmALIGNMENT_END)
1202 if (p_w && width > p_w)
1204 if (s_w && width > s_w)
1207 if (p_h && ((unsigned)height > (p_h + s_h + spacing)))
1208 p_y += (height - p_h - s_h - spacing)/2U;
1210 s_y = p_y + p_h + spacing;
1212 s_y += (height - s_h)/2U;
1214 case XmPIXMAP_BOTTOM:
1215 if (align == XmALIGNMENT_CENTER)
1217 if (p_w && width > p_w)
1218 p_x += (width - p_w)/2U;
1219 if (s_w && width > s_w)
1220 s_x += (width - s_w)/2U;
1222 else if (align == XmALIGNMENT_END)
1224 if (p_w && width > p_w)
1226 if (s_w && width > s_w)
1229 if (s_h && ((unsigned)height > (p_h + s_h + spacing)))
1230 s_y += (height - p_h - s_h - spacing)/2U;
1232 p_y = s_y + s_h + spacing;
1234 p_y += (height - p_h)/2U;
1237 if (p_h && height > p_h)
1238 p_y += (height - p_h)/2U;
1239 s_x += p_w + spacing;
1240 if (s_h && height > s_h)
1241 s_y += (height - s_h)/2U;
1243 if (p_w && width > p_w + spacing + s_w)
1244 p_x += (width - p_w - spacing - s_w)/2;
1245 if (s_w && width > p_w + spacing + s_w)
1246 s_x += (width - p_w - spacing - s_w)/2;
1249 case XmPIXMAP_RIGHT:
1250 if (s_h && height > s_h)
1251 s_y += (height - s_h)/2U;
1252 p_x += s_w + spacing;
1253 if (p_w && ((unsigned)width > (p_w + spacing + s_w)))
1254 p_x += (width - p_w - spacing - s_w)/2U;
1255 if (s_w && ((unsigned)width > (p_w + spacing + s_w)))
1256 s_x += (width - p_w - spacing - s_w)/2U;
1257 if (p_h && height > p_h)
1258 p_y += (height - p_h)/2U;
1260 case XmPIXMAP_MIDDLE:
1261 if (p_w && width > p_w)
1262 p_x += (width - p_w)/2U;
1263 if (s_w && width > s_w)
1264 s_x += (width - s_w)/2U;
1265 if (s_h && height > s_h)
1266 s_y += (height - s_h)/2U;
1267 if (p_h && height > p_h)
1268 p_y += (height - p_h)/2U;
1280 /*-------------------------------------------------------------
1282 ** Draw gadget to drawable.
1294 unsigned char s_type,
1295 unsigned char fill_mode )
1297 XmManagerWidget mgr = (XmManagerWidget) XtParent (g);
1298 Display * d = XtDisplay (g);
1301 Position p_x, p_y, s_x, s_y;
1302 Dimension width = 0, height = 0;
1306 Dimension left = 0, right = 0, top = 0, bottom = 0;
1308 Boolean bClearArea = False;
1309 Boolean bClearShadow = False;
1311 GetPositionProc get_positions;
1313 bMono = (((G_Foreground (g) == BlackPixelOfScreen (XtScreen (g))) ||
1314 (G_Foreground (g) == WhitePixelOfScreen (XtScreen (g)))) &&
1315 ((G_Background (g) == BlackPixelOfScreen (XtScreen (g))) ||
1316 (G_Background (g) == WhitePixelOfScreen (XtScreen (g)))) );
1318 /* Select gc to fill background.
1320 if (G_ControlType (g) == XmCONTROL_SWITCH)
1321 gc = bMono ? M_BackgroundGC (mgr) : G_BackgroundGC (g);
1322 else if ((G_Armed (g)) && (fill_mode != XmFILL_PARENT))
1323 gc = G_ArmedBackgroundGC (g);
1325 gc = M_BackgroundGC (mgr);
1327 if ((fill_mode != XmFILL_NONE) && (fill_mode != XmFILL_TRANSPARENT))
1330 /* Select pixmap and mask.
1334 /* Terminate animation sequence.
1336 if (G_PushImagePosition (g) > G_NumPushImages (g))
1337 G_PushImagePosition (g) = 0;
1338 if (G_DropImagePosition (g) > G_NumDropImages (g))
1339 G_DropImagePosition (g) = 0;
1341 /* Use animation image.
1343 if (G_PushImagePosition (g) > 0)
1345 index = (G_PushImagePosition (g)) - 1;
1346 if ((index == 0) || (bMono))
1350 pix = G_PushPixmaps (g)[index];
1351 mask = G_PushMasks (g)[index];
1352 ++G_PushImagePosition (g);
1354 else if (G_DropImagePosition (g) > 0)
1356 index = G_DropImagePosition (g) - 1;
1361 pix = G_DropPixmaps (g)[index];
1362 mask = G_DropMasks (g)[index];
1363 ++G_DropImagePosition (g);
1366 /* Use alternate image.
1368 else if ( ( ((G_ControlType (g) == XmCONTROL_MONITOR) ||
1369 (G_ControlType (g) == XmCONTROL_MAIL)) &&
1370 (G_AltPix (g) != XmUNSPECIFIED_PIXMAP) &&
1371 G_FileChanged (g) ) ||
1372 ( (G_ControlType (g) == XmCONTROL_BUSY) &&
1373 (G_AltPix (g) != XmUNSPECIFIED_PIXMAP) &&
1374 G_Busy (g) && G_Set (g)) )
1377 mask = G_AltMask (g);
1380 /* Use normal image.
1391 /* Erase shadow - top, left, right, bottom.
1393 XFillRectangle (d, drawable, gc, x + h_t, y + h_t,
1395 XFillRectangle (d, drawable, gc, x + h_t, y + h_t + s_t,
1396 s_t, h - 2 * (h_t + s_t));
1397 XFillRectangle (d, drawable, gc, x + w - h_t - s_t, y + h_t + s_t,
1398 s_t, h - 2 * (h_t + s_t));
1399 XFillRectangle (d, drawable, gc, x + h_t, y + h - h_t - s_t,
1402 else if (bClearArea)
1405 XFillRectangle (d, drawable, gc, x + h_t, y + h_t,
1406 w - 2 * h_t, h - 2 * h_t);
1409 /* Get pixmap and string positions.
1412 get_positions = C_GetPositions(XtClass(g));
1414 (*get_positions) ((DtIconGadget) g, w, h, h_t, s_t, &p_x, &p_y, &s_x, &s_y);
1416 /* Select and display pixmap.
1421 /* Compute display region.
1423 if ((width == 0) && (height == 0))
1425 width = ((unsigned)(p_x + s_t + h_t) >= G_Width (g))
1426 ? 0 : Min ((unsigned)G_PixmapWidth (g),
1427 G_Width (g) - p_x - s_t - h_t);
1428 height = ((unsigned)(p_y + s_t + h_t) >= G_Height (g))
1429 ? 0 : Min ((unsigned)G_PixmapHeight (g),
1430 G_Height (g) - p_y - s_t - h_t);
1434 if (mask != XmUNSPECIFIED_PIXMAP)
1437 XSetClipMask (XtDisplay(g), gc, mask);
1438 XSetClipOrigin (XtDisplay(g), gc, x + p_x, y + p_y);
1441 gc = G_NormalGC (g);
1445 if ((width > 0 && height > 0) &&
1446 (gc != NULL) && (pix != XmUNSPECIFIED_PIXMAP))
1447 XCopyArea (d, pix, drawable, gc, 0, 0,
1448 width, height, x + p_x, y + p_y);
1453 clip.x = x + h_t + s_t;
1454 clip.y = y + h_t + s_t;
1455 clip.width = G_Width (g) - (2 * (h_t + s_t));
1456 clip.height = G_Height (g) - (2 * (h_t + s_t));
1458 if ((G_String (g)) && (clip.width > 0 && clip.height > 0))
1460 if (G_ControlType (g) == XmCONTROL_DATE)
1462 if ( (G_StringHeight (g) > 0) && (G_AltStringHeight (g) > 0) )
1464 unsigned pad_factor;
1466 if (G_UseLabelAdjustment (g))
1471 v_pad = ((unsigned)G_Height(g) >
1472 (G_StringHeight(g) + G_AltStringHeight(g))) ?
1473 (G_Height (g) - G_StringHeight (g) -
1474 G_AltStringHeight (g)) / pad_factor : 0;
1480 XmStringDrawImage (d, drawable, G_FontList (g), G_String (g),
1481 G_NormalGC (g), x + s_x, y + s_y,
1482 clip.width, XmALIGNMENT_BEGINNING,
1483 XmSTRING_DIRECTION_L_TO_R, &clip);
1487 if (G_UseEmbossedText (g))
1488 XmStringDraw (d, drawable, G_FontList (g), G_String (g),
1489 G_BottomShadowGC (g), x + s_x + 1, y + s_y + 1,
1490 clip.width, XmALIGNMENT_BEGINNING,
1491 XmSTRING_DIRECTION_L_TO_R, &clip);
1492 XmStringDraw (d, drawable, G_FontList (g), G_String (g),
1493 G_NormalGC (g), x + s_x, y + s_y,
1494 clip.width, XmALIGNMENT_BEGINNING,
1495 XmSTRING_DIRECTION_L_TO_R, &clip);
1498 if (G_Width (g) > G_AltStringWidth (g))
1499 s_x = (G_Width (g) - G_AltStringWidth (g)) / 2U;
1501 if (G_UseLabelAdjustment (g))
1502 s_y = ((G_Height (g) - G_AltStringWidth (g)) + 5);
1504 s_y += G_StringHeight (g);
1508 XmStringDrawImage (d, drawable, G_FontList (g),
1510 G_NormalGC (g), x + s_x, y + s_y,
1511 clip.width, XmALIGNMENT_BEGINNING,
1512 XmSTRING_DIRECTION_L_TO_R, &clip);
1516 if (G_UseEmbossedText (g))
1517 XmStringDraw (d, drawable, G_FontList (g),
1519 G_BottomShadowGC (g), x + s_x + 1, y + s_y + 1,
1520 clip.width, XmALIGNMENT_BEGINNING,
1521 XmSTRING_DIRECTION_L_TO_R, &clip);
1522 XmStringDraw (d, drawable, G_FontList (g),
1524 G_NormalGC (g), x + s_x, y + s_y,
1525 clip.width, XmALIGNMENT_BEGINNING,
1526 XmSTRING_DIRECTION_L_TO_R, &clip);
1533 if ((s_x - 2U) >= (h_t + s_t))
1534 XFillRectangle (d, drawable, G_ArmedBackgroundGC (g),
1535 x + s_x - 2, y + s_y,
1536 2, G_StringHeight (g));
1537 XmStringDrawImage (d, drawable, G_FontList (g), G_String (g),
1538 G_NormalGC (g), x + s_x, y + s_y,
1539 clip.width, XmALIGNMENT_BEGINNING,
1540 XmSTRING_DIRECTION_L_TO_R, &clip);
1541 if ((s_x + G_StringWidth (g) + 2U) <= (G_Width (g) - h_t - s_t))
1542 XFillRectangle (d, drawable, G_ArmedBackgroundGC (g),
1543 x + s_x + G_StringWidth (g), y + s_y,
1544 2, G_StringHeight (g));
1548 if (G_UseEmbossedText (g))
1549 XmStringDraw (d, drawable, G_FontList (g), G_String (g),
1550 G_BottomShadowGC (g), x + s_x + 1, y + s_y + 1,
1551 clip.width, XmALIGNMENT_BEGINNING,
1552 XmSTRING_DIRECTION_L_TO_R, &clip);
1553 XmStringDraw (d, drawable, G_FontList (g), G_String (g),
1554 G_NormalGC (g), x + s_x, y + s_y,
1555 clip.width, XmALIGNMENT_BEGINNING,
1556 XmSTRING_DIRECTION_L_TO_R, &clip);
1563 switch (G_ControlType (g))
1565 case XmCONTROL_BLANK:
1566 case XmCONTROL_DATE:
1569 case XmCONTROL_CLIENT:
1573 /* Use black and white.
1576 if (G_Foreground (g) == WhitePixelOfScreen (XtScreen (g)))
1578 gcTS = G_BackgroundGC (g);
1579 gcBS = G_NormalGC (g);
1583 gcBS = G_BackgroundGC (g);
1584 gcTS = G_NormalGC (g);
1589 gcTS = M_BottomShadowGC (mgr);
1590 gcBS = M_TopShadowGC (mgr);
1592 /* Drop inner shadow if secondary since no fill.
1594 XmeDrawShadows (d, drawable, gcTS, gcBS,
1595 x + left - s_t, y + top - s_t,
1596 w - left - right + (2 * s_t),
1597 h - top - bottom + (2 * s_t),
1598 s_t, XmSHADOW_ETCHED_OUT);
1602 case XmCONTROL_BUTTON:
1603 case XmCONTROL_MONITOR:
1604 case XmCONTROL_MAIL:
1605 switch (G_Behavior (g))
1609 XmeDrawShadows(d, drawable,
1610 M_TopShadowGC(mgr), M_BottomShadowGC(mgr),
1612 w - 2*h_t, h - 2*h_t, s_t, XmSHADOW_IN);
1615 if ( (G_Armed (g) && !G_Set (g)) ||
1616 (!G_Armed (g) && G_Set (g)) )
1617 XmeDrawShadows(d, drawable,
1618 M_TopShadowGC(mgr), M_BottomShadowGC(mgr),
1620 w - 2*h_t, h - 2*h_t, s_t, XmSHADOW_IN);
1624 case XmCONTROL_SWITCH:
1625 if (!G_FillOnArm (g))
1627 gcTS = G_BottomShadowGC (g);
1628 gcBS = G_TopShadowGC (g);
1632 if (G_Foreground (g) == WhitePixelOfScreen (XtScreen (g)))
1634 gcTS = G_BackgroundGC (g);
1635 gcBS = G_NormalGC (g);
1639 gcTS = G_NormalGC (g);
1640 gcBS = G_BackgroundGC (g);
1643 XmeDrawShadows (d, drawable, gcTS, gcBS,
1644 x + h_t, y + h_t, w - 2*h_t, h - 2*h_t, 1,
1647 ++x; ++y; w -= 2; h -= 2; --s_t;
1650 if ( (G_Armed (g) && !G_Set (g)) ||
1651 (!G_Armed (g) && G_Set (g)) )
1653 gcTS = G_BottomShadowGC (g);
1654 gcBS = G_TopShadowGC (g);
1658 gcTS = G_TopShadowGC (g);
1659 gcBS = G_BottomShadowGC (g);
1661 XmeDrawShadows (d, drawable, gcTS, gcBS,
1662 x + h_t, y + h_t, w - 2*h_t, h - 2*h_t, s_t,
1670 /*-------------------------------------------------------------
1672 ** Call callback, if any, with reason and event.
1681 DtControlCallbackStruct cb_data;
1682 XtAppContext app_context = XtWidgetToApplicationContext ((Widget) g);
1684 if ((reason == XmCR_ACTIVATE) && (G_Behavior (g) == XmICON_BUTTON))
1686 if (G_ClickTimer (g) != 0)
1690 XtAppAddTimeOut (app_context, G_ClickTime (g),
1691 ClickTimeout, (XtPointer) g);
1696 cb_data.reason = reason;
1697 cb_data.event = event;
1698 cb_data.control_type = G_ControlType (g);
1699 cb_data.set = G_Set (g);
1700 cb_data.push_function = G_PushFunction (g);
1701 cb_data.push_argument = G_PushArgument (g);
1702 cb_data.subpanel = G_Subpanel (g);
1703 cb_data.file_size = G_FileSize (g);
1704 XtCallCallbackList ((Widget) g, cb, &cb_data);
1711 /*-------------------------------------------------------------
1713 ** Get normal and background graphics contexts.
1714 ** Use standard mask to maximize caching opportunities.
1721 XtGCMask value_mask;
1722 XmManagerWidget mw = (XmManagerWidget) XtParent(g);
1725 if (!G__DoUpdate (g))
1729 XtReleaseGC ((Widget)mw, G_NormalGC (g));
1731 XtReleaseGC ((Widget)mw, G_ClipGC (g));
1732 if (G_BackgroundGC (g))
1733 XtReleaseGC ((Widget)mw, G_BackgroundGC (g));
1734 if (G_ArmedBackgroundGC (g))
1735 XtReleaseGC ((Widget)mw, G_ArmedBackgroundGC (g));
1736 if (G_TopShadowGC (g))
1737 XtReleaseGC ((Widget)mw, G_TopShadowGC (g));
1738 if (G_BottomShadowGC (g))
1739 XtReleaseGC ((Widget)mw, G_BottomShadowGC (g));
1743 value_mask = GCForeground | GCBackground | GCFillStyle;
1744 if (XmeRenderTableGetDefaultFont (G_FontList (g), &font)) {
1745 value_mask |= GCFont;
1746 values.font = font->fid;
1749 if (G_UseEmbossedText (g))
1750 values.foreground = WhitePixelOfScreen (XtScreen (g));
1752 values.foreground = G_Foreground (g);
1753 values.background = G_Background (g);
1754 values.fill_style = FillSolid;
1756 G_NormalGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
1758 /* Get top shadow GC.
1760 if (G_ControlType (g) == XmCONTROL_SWITCH)
1761 values.foreground = G_PixmapBackground (g);
1763 values.foreground = mw -> manager.top_shadow_color;
1764 values.background = G_Background (g);
1765 G_TopShadowGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
1767 /* Get bottom shadow GC.
1769 if (G_ControlType (g) == XmCONTROL_SWITCH)
1770 values.foreground = G_PixmapForeground (g);
1772 values.foreground = mw -> manager.bottom_shadow_color;
1773 values.background = G_Background (g);
1774 G_BottomShadowGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
1776 /* Get background GC.
1778 values.foreground = G_Background (g);
1779 values.background = G_Foreground (g);
1780 G_BackgroundGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
1782 /* Get armed background GC.
1784 values.foreground = G_ArmColor (g);
1785 values.background = G_Background (g);
1786 G_ArmedBackgroundGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
1790 if (G_Mask(g) != XmUNSPECIFIED_PIXMAP)
1792 value_mask |= GCClipMask;
1793 values.clip_mask = G_Mask(g);
1795 values.foreground = G_Foreground (g);
1796 values.background = G_Background (g);
1797 G_ClipGC (g) = XtGetGC ((Widget)mw, value_mask, &values);
1801 /*-------------------------------------------------------------
1802 ** Public Entry Points
1803 **-------------------------------------------------------------
1807 /*-------------------------------------------------------------
1808 ** Push Animation Timeout
1809 ** An XtTimerCallbackProc.
1812 PushAnimationTimeout(
1813 XtPointer client_data,
1816 DtControlGadget g = (DtControlGadget) client_data;
1817 XtAppContext app_context = XtWidgetToApplicationContext ((Widget) g);
1818 XtExposeProc expose;
1820 if ((G_PushImagePosition (g) > 0) &&
1821 (G_PushImagePosition (g) <= G_NumPushImages (g)))
1823 G_PushAnimationTimer (g) =
1824 XtAppAddTimeOut (app_context,
1825 G_PushDelays (g)[G_PushImagePosition (g) - 1],
1826 PushAnimationTimeout, (XtPointer) g);
1828 if (G_PushImagePosition (g) > 1)
1831 expose = XtCoreProc((Widget)g, expose);
1833 (*expose) ((Widget) g, NULL, NULL);
1838 /*-------------------------------------------------------------
1839 ** _DtControlDoPushAnimation
1840 ** Do Push animation.
1841 **-------------------------------------------------------------
1844 _DtControlDoPushAnimation(
1847 DtControlGadget g = (DtControlGadget) w;
1849 if ((G_NumPushImages (g) > 0) && (G_PushImagePosition (g) == 0))
1851 G_PushImagePosition (g) = 1;
1852 PushAnimationTimeout ((XtPointer) g, NULL);
1857 /*-------------------------------------------------------------
1858 ** _DtControlAddPushAnimationImage
1859 ** Add Push animation image.
1860 **-------------------------------------------------------------
1863 _DtControlAddPushAnimationImage(
1868 DtControlGadget g = (DtControlGadget) w;
1871 /* Allocate blocks of animation data.
1873 if (G_NumPushImages (g) == G_MaxPushImages (g))
1875 G_MaxPushImages (g) += NUM_LIST_ITEMS;
1876 G_PushDelays (g) = (int*)
1877 XtRealloc ((char*) G_PushDelays (g),
1878 G_MaxPushImages (g) *sizeof (int));
1879 G_PushPixmaps (g) = (Pixmap*)
1880 XtRealloc ((char*) G_PushPixmaps (g),
1881 G_MaxPushImages (g) *sizeof (Pixmap));
1882 G_PushMasks (g) = (Pixmap*)
1883 XtRealloc ((char*) G_PushMasks (g),
1884 G_MaxPushImages (g) *sizeof (Pixmap));
1887 /* Allocate animation image.
1889 i = G_NumPushImages (g)++;
1890 G_PushDelays (g)[i] = delay;
1891 G_PushPixmaps (g)[i] = XmGetPixmap (XtScreen (g), image,
1892 G_PixmapForeground (g),
1893 G_PixmapBackground (g));
1894 G_PushMasks (g)[i] = _DtGetMask (XtScreen (g), image);
1898 /*-------------------------------------------------------------
1899 ** Drop Animation Timeout
1900 ** An XtTimerCallbackProc.
1903 DropAnimationTimeout(
1904 XtPointer client_data,
1907 DtControlGadget g = (DtControlGadget) client_data;
1908 XtAppContext app_context = XtWidgetToApplicationContext ((Widget) g);
1909 XtExposeProc expose;
1911 if ((G_DropImagePosition (g) > 0) &&
1912 (G_DropImagePosition (g) <= G_NumDropImages (g)))
1914 G_DropAnimationTimer (g) =
1915 XtAppAddTimeOut (app_context,
1916 G_DropDelays (g)[G_DropImagePosition (g) - 1],
1917 DropAnimationTimeout, (XtPointer) g);
1921 expose = XtCoreProc((Widget)g, expose);
1923 (*expose) ((Widget) g, NULL, NULL);
1927 /*-------------------------------------------------------------
1928 ** _DtControlDoDropAnimation
1929 ** Do drop animation.
1930 **-------------------------------------------------------------
1933 _DtControlDoDropAnimation(
1936 DtControlGadget g = (DtControlGadget) w;
1938 if ((G_NumDropImages (g) > 0) && (G_DropImagePosition (g) == 0))
1940 G_DropImagePosition (g) = 1;
1941 DropAnimationTimeout ((XtPointer) g, NULL);
1946 /*-------------------------------------------------------------
1947 ** _DtControlAddDropAnimationImage
1948 ** Add drop animation image.
1949 **-------------------------------------------------------------
1952 _DtControlAddDropAnimationImage(
1957 DtControlGadget g = (DtControlGadget) w;
1960 /* Allocate blocks of animation data.
1962 if (G_NumDropImages (g) == G_MaxDropImages (g))
1964 G_MaxDropImages (g) += NUM_LIST_ITEMS;
1965 G_DropDelays (g) = (int*)
1966 XtRealloc ((char*) G_DropDelays (g),
1967 G_MaxDropImages (g) *sizeof (int));
1968 G_DropPixmaps (g) = (Pixmap*)
1969 XtRealloc ((char*) G_DropPixmaps (g),
1970 G_MaxDropImages (g) *sizeof (Pixmap));
1971 G_DropMasks (g) = (Pixmap*)
1972 XtRealloc ((char*) G_DropMasks (g),
1973 G_MaxDropImages (g) *sizeof (Pixmap));
1976 /* Allocate animation image.
1978 i = G_NumDropImages (g)++;
1979 G_DropDelays (g)[i] = delay;
1980 G_DropPixmaps (g)[i] = XmGetPixmap (XtScreen (g), image,
1981 G_PixmapForeground (g),
1982 G_PixmapBackground (g));
1983 G_DropMasks (g)[i] = _DtGetMask (XtScreen (g), image);
1987 /*-------------------------------------------------------------
1988 ** _DtControlSetFileChanged
1989 ** Set file changed.
1990 **-------------------------------------------------------------
1993 _DtControlSetFileChanged(
1997 DtControlGadget g = (DtControlGadget) w;
1998 XtExposeProc expose;
2000 if ((G_ControlType (g) == XmCONTROL_MONITOR) ||
2001 (G_ControlType (g) == XmCONTROL_MAIL))
2003 G_FileChanged (g) = b;
2005 expose = XtCoreProc((Widget)g, expose);
2007 (*expose) ((Widget) g, NULL, False);
2012 /*-------------------------------------------------------------
2013 ** _DtControlSetBusy
2015 **-------------------------------------------------------------
2022 DtControlGadget g = (DtControlGadget) w;
2024 if (G_ControlType (g) != XmCONTROL_BUSY)
2029 G_BlinkElapsed (g) = 0;
2031 if (G_Busy (g) == 1)
2033 CallCallbackProc call_callback;
2036 call_callback = C_CallCallback(XtClass(g));
2038 (*call_callback) ((DtIconGadget) g, G_Callback (g), XmCR_BUSY_START,
2040 BusyTimeout ((XtPointer) w, NULL);
2051 /*-------------------------------------------------------------
2053 ** Create a new gadget instance.
2054 **-------------------------------------------------------------
2063 return (XtCreateWidget (name, dtControlGadgetClass,
2064 parent, arglist, argcount));
2068 ReplaceJPDate(char *date, char *jpstr, int wday)
2076 _Xstrtokparams strtok_buf;
2078 s = (char *)malloc((strlen(jpstr) + 1) * sizeof(char));
2080 for(p = _XStrtok(s, ",", strtok_buf), i = 0;
2081 p != NULL && i < wday ;
2082 p = _XStrtok(NULL, ",", strtok_buf), i++)
2088 strcpy(abday, nl_langinfo(ABDAY_1 + wday));
2089 if((rp = strstr(date, abday)) != NULL) {
2090 for(i = 0, j = 0, sp = date; date[j] != '\0'; sp++) {
2092 for(k = 0; k < strlen(p); k++)
2093 newdate[i++] = p[k];
2097 newdate[i++] = date[j++];
2100 strcpy(date, newdate);
2107 _DtControlGetMonitorState(Widget w)
2109 DtControlGadget g = (DtControlGadget) w;
2111 if (G_FileChanged (g))
2112 return(DtMONITOR_ON);
2114 return(DtMONITOR_OFF);