1 /*******************************************************************************
5 ** $XConsortium: goto.c /main/4 1995/12/04 14:18:24 rswiston $
7 ** RESTRICTED CONFIDENTIAL INFORMATION:
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
17 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
19 *******************************************************************************/
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. *
29 static char sccsid[] = "@(#)goto.c 1.40 95/03/28 Copyr 1993 Sun Microsystems, Inc.";
32 #include <EUSCompat.h>
37 #include <Xm/LabelG.h>
39 #include <Xm/DialogS.h>
41 #include <Xm/RowColumn.h>
43 #include <Xm/SeparatoG.h>
45 #include <Xm/ToggleBG.h>
46 #include <Xm/MwmUtil.h>
51 #include "datefield.h"
53 #include "dayglance.h"
61 make_goto(Calendar *c)
65 Widget separator, button_form;
66 void goto_date(), g_cancel_cb();
69 if (c->goTo == NULL) {
70 c->goTo = (caddr_t)ckalloc(sizeof(Goto));
76 title = XtNewString(catgets(c->DT_catd, 1, 715, "Calendar : Go to Date"));
77 g->frame = XtVaCreatePopupShell("frame",
78 xmDialogShellWidgetClass, c->frame,
80 XmNallowShellResize, True,
81 XmNmappedWhenManaged, False,
85 g->form = XtVaCreateWidget("form",
86 xmFormWidgetClass, g->frame,
87 XmNautoUnmanage, False,
89 XmNhorizontalSpacing, 4,
90 XmNverticalSpacing, 4,
95 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 293, "Date:"));
96 g->datelabel = XtVaCreateWidget("Date:",
97 xmLabelWidgetClass, g->form,
98 XmNleftAttachment, XmATTACH_FORM,
100 XmNtopAttachment, XmATTACH_FORM,
102 XmNlabelString, xmstr,
106 g->datetext = XtVaCreateWidget("text",
107 xmTextWidgetClass, g->form,
108 XmNtopAttachment, XmATTACH_FORM,
109 XmNtopWidget, g->datelabel,
111 XmNleftAttachment, XmATTACH_WIDGET,
112 XmNleftWidget, g->datelabel,
113 XmNrightAttachment, XmATTACH_POSITION,
118 XtAddCallback(g->datetext, XmNactivateCallback, goto_date, NULL);
121 separator = XtVaCreateWidget("separator",
122 xmSeparatorGadgetClass,
124 XmNleftAttachment, XmATTACH_FORM,
125 XmNrightAttachment, XmATTACH_FORM,
126 XmNtopAttachment, XmATTACH_WIDGET,
127 XmNtopWidget, g->datetext,
131 button_form = XtVaCreateWidget("form",
132 xmFormWidgetClass, g->form,
133 XmNautoUnmanage, False,
134 XmNleftAttachment, XmATTACH_FORM,
136 XmNrightAttachment, XmATTACH_FORM,
138 XmNtopAttachment, XmATTACH_WIDGET,
139 XmNtopWidget, separator,
140 XmNhorizontalSpacing, 4,
144 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 294, "Go To"));
145 g->datebutton = XtVaCreateWidget("goTo",
146 xmPushButtonWidgetClass, button_form,
147 XmNtopAttachment, XmATTACH_WIDGET,
148 XmNtopWidget, separator,
149 XmNlabelString, xmstr,
150 XmNnavigationType, XmTAB_GROUP,
151 XmNleftAttachment, XmATTACH_POSITION,
153 XmNrightAttachment, XmATTACH_POSITION,
156 XtAddCallback(g->datebutton, XmNactivateCallback, goto_date, NULL);
159 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 680, "Close"));
160 g->cancelbutton = XtVaCreateWidget("cancel",
161 xmPushButtonWidgetClass, button_form,
162 XmNtopAttachment, XmATTACH_WIDGET,
163 XmNtopWidget, separator,
164 XmNleftAttachment, XmATTACH_POSITION,
166 XmNrightAttachment, XmATTACH_POSITION,
168 XmNlabelString, xmstr,
170 XtAddCallback(g->cancelbutton, XmNactivateCallback, g_cancel_cb, NULL);
174 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 77, "Help"));
175 g->helpbutton = XtVaCreateWidget("help",
176 xmPushButtonWidgetClass, button_form,
177 XmNtopAttachment, XmATTACH_WIDGET,
178 XmNtopWidget, separator,
179 XmNleftAttachment, XmATTACH_POSITION,
181 XmNrightAttachment, XmATTACH_POSITION,
183 XmNlabelString, xmstr,
185 XtAddCallback(g->helpbutton, XmNactivateCallback,
186 (XtCallbackProc)help_cb, GOTO_HELP_BUTTON);
187 XtAddCallback(g->form, XmNhelpCallback,
188 (XtCallbackProc)help_cb, (XtPointer) GOTO_HELP_BUTTON);
191 g->goto_message = XtVaCreateWidget("message",
192 xmLabelGadgetClass, g->form,
193 XmNalignment, XmALIGNMENT_BEGINNING,
194 XmNtopAttachment, XmATTACH_WIDGET,
195 XmNtopWidget, g->cancelbutton,
196 XmNleftAttachment, XmATTACH_FORM,
197 XmNrightAttachment, XmATTACH_FORM,
198 XmNbottomAttachment, XmATTACH_FORM,
201 /* set default button */
202 XtVaSetValues(g->form, XmNdefaultButton, g->datebutton, NULL);
203 XtVaSetValues(g->form, XmNcancelButton, g->cancelbutton, NULL);
204 XtVaSetValues(button_form, XmNdefaultButton, g->datebutton, NULL);
205 XtVaSetValues(button_form, XmNcancelButton, g->cancelbutton, NULL);
206 XmProcessTraversal(g->datetext, XmTRAVERSE_CURRENT);
207 XtVaSetValues(g->form, XmNinitialFocus, g->datetext, NULL);
209 ManageChildren(button_form);
210 ManageChildren(g->form);
211 XtManageChild(g->form);
212 XtVaSetValues(g->frame, XmNmappedWhenManaged, True, NULL);
213 XtRealizeWidget(g->frame);
215 XtPopup(g->frame, XtGrabNone);
221 goto_date(Widget widget, XtPointer client_data, XmPushButtonCallbackStruct *cbs)
223 Calendar *c = calendar;
226 Tick gotodate, start, stop;
227 char *date = NULL, today[DATESIZ];
233 p = (Props*)c->properties;
234 ot = get_int_prop(p, CP_DATEORDERING);
235 st = get_int_prop(p, CP_DATESEPARATOR);
238 date = XmTextGetString(g->datetext);
239 if ((*date == NULL) || (date == NULL)) {
240 sprintf(message, catgets(c->DT_catd, 1, 297, "Please type in a date"));
241 set_message(g->goto_message, message);
244 format_tick(c->view->date, ot, st, today);
245 set_message(g->goto_message, "");
246 date = get_date_from_widget(c->view->date, g->datetext, ot, st);
247 if ( date == NULL ) {
250 gotodate = cm_getdate(date, NULL);
252 if (!strcmp(today, date)) {
253 sprintf(message, catgets(c->DT_catd, 1, 298, "You are already viewing %s"), date);
254 set_message(g->goto_message, message);
259 if (gotodate == DATE_BBOT) {
260 sprintf(message, catgets(c->DT_catd, 1, 814, "You must enter a date after 1969 and before 2038"));
261 set_message(g->goto_message, message);
264 else if (gotodate == DATE_AEOT) {
265 sprintf(message, catgets(c->DT_catd, 1, 814, "You must enter a date after 1969 and before 2038"));
266 set_message(g->goto_message, message);
269 else if (gotodate <= 0) {
270 sprintf(message, catgets(c->DT_catd, 1, 299, "Invalid Date"));
271 set_message(g->goto_message, message);
277 get_range(c->view->glance, c->view->date, &start, &stop);
278 if (in_range(start, stop, gotodate)) {
279 /* date is in view; deselect and repaint new selection */
280 calendar_deselect(c);
281 c->view->olddate = c->view->date;
282 c->view->date = gotodate;
286 /* repaint the entire canvas */
287 c->view->olddate = c->view->date;
288 c->view->date = gotodate;
289 c->view->nwks = numwks(c->view->date);
290 XtVaGetValues(c->canvas, XmNwidth, &w, XmNheight, &h, NULL);
291 gr_clear_area(c->xcontext, 0, 0, w, h);
292 if (c->view->glance == dayGlance) {
296 paint_canvas(c, NULL, RENDER_UNMAP);
303 XtPointer client_data,
304 XmPushButtonCallbackStruct *cbs)
306 Calendar *c = calendar;
311 XmTextSetString(g->datetext, "");