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