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 /*******************************************************************************
27 ** $XConsortium: goto.c /main/4 1995/12/04 14:18:24 rswiston $
29 ** RESTRICTED CONFIDENTIAL INFORMATION:
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
39 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 *******************************************************************************/
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. *
51 static char sccsid[] = "@(#)goto.c 1.40 95/03/28 Copyr 1993 Sun Microsystems, Inc.";
54 #include <EUSCompat.h>
59 #include <Xm/LabelG.h>
61 #include <Xm/DialogS.h>
63 #include <Xm/RowColumn.h>
65 #include <Xm/SeparatoG.h>
67 #include <Xm/ToggleBG.h>
68 #include <Xm/MwmUtil.h>
73 #include "datefield.h"
75 #include "dayglance.h"
83 make_goto(Calendar *c)
87 Widget separator, button_form;
88 void goto_date(), g_cancel_cb();
91 if (c->goTo == NULL) {
92 c->goTo = (caddr_t)ckalloc(sizeof(Goto));
98 title = XtNewString(catgets(c->DT_catd, 1, 715, "Calendar : Go to Date"));
99 g->frame = XtVaCreatePopupShell("frame",
100 xmDialogShellWidgetClass, c->frame,
102 XmNallowShellResize, True,
103 XmNmappedWhenManaged, False,
107 g->form = XtVaCreateWidget("form",
108 xmFormWidgetClass, g->frame,
109 XmNautoUnmanage, False,
111 XmNhorizontalSpacing, 4,
112 XmNverticalSpacing, 4,
117 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 293, "Date:"));
118 g->datelabel = XtVaCreateWidget("Date:",
119 xmLabelWidgetClass, g->form,
120 XmNleftAttachment, XmATTACH_FORM,
122 XmNtopAttachment, XmATTACH_FORM,
124 XmNlabelString, xmstr,
128 g->datetext = XtVaCreateWidget("text",
129 xmTextWidgetClass, g->form,
130 XmNtopAttachment, XmATTACH_FORM,
131 XmNtopWidget, g->datelabel,
133 XmNleftAttachment, XmATTACH_WIDGET,
134 XmNleftWidget, g->datelabel,
135 XmNrightAttachment, XmATTACH_POSITION,
140 XtAddCallback(g->datetext, XmNactivateCallback, goto_date, NULL);
143 separator = XtVaCreateWidget("separator",
144 xmSeparatorGadgetClass,
146 XmNleftAttachment, XmATTACH_FORM,
147 XmNrightAttachment, XmATTACH_FORM,
148 XmNtopAttachment, XmATTACH_WIDGET,
149 XmNtopWidget, g->datetext,
153 button_form = XtVaCreateWidget("form",
154 xmFormWidgetClass, g->form,
155 XmNautoUnmanage, False,
156 XmNleftAttachment, XmATTACH_FORM,
158 XmNrightAttachment, XmATTACH_FORM,
160 XmNtopAttachment, XmATTACH_WIDGET,
161 XmNtopWidget, separator,
162 XmNhorizontalSpacing, 4,
166 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 294, "Go To"));
167 g->datebutton = XtVaCreateWidget("goTo",
168 xmPushButtonWidgetClass, button_form,
169 XmNtopAttachment, XmATTACH_WIDGET,
170 XmNtopWidget, separator,
171 XmNlabelString, xmstr,
172 XmNnavigationType, XmTAB_GROUP,
173 XmNleftAttachment, XmATTACH_POSITION,
175 XmNrightAttachment, XmATTACH_POSITION,
178 XtAddCallback(g->datebutton, XmNactivateCallback, goto_date, NULL);
181 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 680, "Close"));
182 g->cancelbutton = XtVaCreateWidget("cancel",
183 xmPushButtonWidgetClass, button_form,
184 XmNtopAttachment, XmATTACH_WIDGET,
185 XmNtopWidget, separator,
186 XmNleftAttachment, XmATTACH_POSITION,
188 XmNrightAttachment, XmATTACH_POSITION,
190 XmNlabelString, xmstr,
192 XtAddCallback(g->cancelbutton, XmNactivateCallback, g_cancel_cb, NULL);
196 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 77, "Help"));
197 g->helpbutton = XtVaCreateWidget("help",
198 xmPushButtonWidgetClass, button_form,
199 XmNtopAttachment, XmATTACH_WIDGET,
200 XmNtopWidget, separator,
201 XmNleftAttachment, XmATTACH_POSITION,
203 XmNrightAttachment, XmATTACH_POSITION,
205 XmNlabelString, xmstr,
207 XtAddCallback(g->helpbutton, XmNactivateCallback,
208 (XtCallbackProc)help_cb, GOTO_HELP_BUTTON);
209 XtAddCallback(g->form, XmNhelpCallback,
210 (XtCallbackProc)help_cb, (XtPointer) GOTO_HELP_BUTTON);
213 g->goto_message = XtVaCreateWidget("message",
214 xmLabelGadgetClass, g->form,
215 XmNalignment, XmALIGNMENT_BEGINNING,
216 XmNtopAttachment, XmATTACH_WIDGET,
217 XmNtopWidget, g->cancelbutton,
218 XmNleftAttachment, XmATTACH_FORM,
219 XmNrightAttachment, XmATTACH_FORM,
220 XmNbottomAttachment, XmATTACH_FORM,
223 /* set default button */
224 XtVaSetValues(g->form, XmNdefaultButton, g->datebutton, NULL);
225 XtVaSetValues(g->form, XmNcancelButton, g->cancelbutton, NULL);
226 XtVaSetValues(button_form, XmNdefaultButton, g->datebutton, NULL);
227 XtVaSetValues(button_form, XmNcancelButton, g->cancelbutton, NULL);
228 XmProcessTraversal(g->datetext, XmTRAVERSE_CURRENT);
229 XtVaSetValues(g->form, XmNinitialFocus, g->datetext, NULL);
231 ManageChildren(button_form);
232 ManageChildren(g->form);
233 XtManageChild(g->form);
234 XtVaSetValues(g->frame, XmNmappedWhenManaged, True, NULL);
235 XtRealizeWidget(g->frame);
237 XtPopup(g->frame, XtGrabNone);
243 goto_date(Widget widget, XtPointer client_data, XmPushButtonCallbackStruct *cbs)
245 Calendar *c = calendar;
248 Tick gotodate, start, stop;
249 char *date = NULL, today[DATESIZ];
255 p = (Props*)c->properties;
256 ot = get_int_prop(p, CP_DATEORDERING);
257 st = get_int_prop(p, CP_DATESEPARATOR);
260 date = XmTextGetString(g->datetext);
261 if ((*date == NULL) || (date == NULL)) {
262 sprintf(message, "%s", catgets(c->DT_catd, 1, 297, "Please type in a date"));
263 set_message(g->goto_message, message);
266 format_tick(c->view->date, ot, st, today);
267 set_message(g->goto_message, "");
268 date = get_date_from_widget(c->view->date, g->datetext, ot, st);
269 if ( date == NULL ) {
272 gotodate = cm_getdate(date, NULL);
274 if (!strcmp(today, date)) {
275 sprintf(message, catgets(c->DT_catd, 1, 298, "You are already viewing %s"), date);
276 set_message(g->goto_message, message);
281 if (gotodate == DATE_BBOT) {
282 sprintf(message, "%s", catgets(c->DT_catd, 1, 814, "You must enter a date after 1969 and before 2038"));
283 set_message(g->goto_message, message);
286 else if (gotodate == DATE_AEOT) {
287 sprintf(message, "%s", catgets(c->DT_catd, 1, 814, "You must enter a date after 1969 and before 2038"));
288 set_message(g->goto_message, message);
291 else if (gotodate <= 0) {
292 sprintf(message, "%s", catgets(c->DT_catd, 1, 299, "Invalid Date"));
293 set_message(g->goto_message, message);
299 get_range(c->view->glance, c->view->date, &start, &stop);
300 if (in_range(start, stop, gotodate)) {
301 /* date is in view; deselect and repaint new selection */
302 calendar_deselect(c);
303 c->view->olddate = c->view->date;
304 c->view->date = gotodate;
308 /* repaint the entire canvas */
309 c->view->olddate = c->view->date;
310 c->view->date = gotodate;
311 c->view->nwks = numwks(c->view->date);
312 XtVaGetValues(c->canvas, XmNwidth, &w, XmNheight, &h, NULL);
313 gr_clear_area(c->xcontext, 0, 0, w, h);
314 if (c->view->glance == dayGlance) {
318 paint_canvas(c, NULL, RENDER_UNMAP);
325 XtPointer client_data,
326 XmPushButtonCallbackStruct *cbs)
328 Calendar *c = calendar;
333 XmTextSetString(g->datetext, "");