Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtcm / dtcm / datefield.c
1 /*******************************************************************************
2 **
3 **  datefield.c
4 **
5 **  $XConsortium: datefield.c /main/3 1995/11/03 10:21:12 rswiston $
6 **
7 **  RESTRICTED CONFIDENTIAL INFORMATION:
8 **
9 **  The information in this document is subject to special
10 **  restrictions in a confidential disclosure agreement between
11 **  HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
12 **  document outside HP, IBM, Sun, USL, SCO, or Univel without
13 **  Sun's specific written approval.  This document and all copies
14 **  and derivative works thereof must be returned or destroyed at
15 **  Sun's request.
16 **
17 **  Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
18 **
19 *******************************************************************************/
20
21 /*                                                                      *
22  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
23  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
24  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
25  * (c) Copyright 1993, 1994 Novell, Inc.                                *
26  */
27
28 #ifndef lint
29 static  char sccsid[] = "@(#)datefield.c 1.7 94/11/07 Copyr 1993 Sun Microsystems, Inc.";
30 #endif
31
32 #include <EUSCompat.h>
33 #include <stdio.h>
34 #include <Xm/Xm.h>
35 #include <Xm/LabelG.h>
36 #include <Xm/Label.h>
37 #include <Xm/Text.h>
38 #include <Xm/TextF.h>
39 #include "util.h"
40 #include "datefield.h"
41 #include "misc.h"
42
43 /*
44 **  Returns a date string the parser can handle
45 */
46 extern char*
47 get_date_from_widget(Tick t, Widget w, OrderingType order,
48                      SeparatorType separator) {
49         char            *date = NULL;
50         WidgetClass     wc;
51         static char     buf[80];
52  
53         memset(buf, '\0', 80);
54
55         if (!w)
56                 format_tick(t, order, separator, buf);
57         else {
58                 wc = XtClass(w);
59                 if (wc == xmTextWidgetClass)
60                         date = XmTextGetString(w);
61                 else if (wc == xmTextFieldWidgetClass)
62                         date = XmTextFieldGetString(w);
63                 else
64                         return NULL;
65
66                 if (!date || *date == '\0')
67                         format_tick(t, order, separator, buf);
68                 else if (!datestr2mdy(date, order, separator, buf)) {
69                         XtFree(date);
70                         return NULL;
71                 }
72                 if (date)
73                         XtFree(date);
74         }
75
76         return buf;
77 }
78
79 extern void
80 set_date_in_widget(Tick t, Widget w, OrderingType order,
81                    SeparatorType separator) {
82         char            buf[80];
83         XmString        xmstr;
84         WidgetClass     wc = XtClass(w);
85
86         format_tick(t, order, separator, buf);
87         if (wc == xmLabelGadgetClass || wc == xmLabelWidgetClass) {
88                 xmstr = XmStringCreateLocalized(buf);
89                 XtVaSetValues(w, XmNlabelString, xmstr,
90                         NULL);
91                 XmStringFree(xmstr);
92         } else if (wc == xmTextWidgetClass)
93                 XmTextSetString(w, buf);
94         else if (wc == xmTextFieldWidgetClass)
95                 XmTextFieldSetString(w, buf);
96 }