1 /* $TOG: timezone.c /main/10 1999/07/01 16:36:43 mgreess $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company
4 * (c) Copyright 1993, 1994 International Business Machines Corp.
5 * (c) Copyright 1993, 1994 Novell, Inc.
6 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
15 #include <Xm/LabelG.h>
18 #include <Xm/DialogS.h>
20 #include <Xm/RowColumn.h>
22 #include <Xm/SeparatoG.h>
24 #include <Xm/ToggleBG.h>
25 #include <Xm/MwmUtil.h>
26 #include <Xm/ComboBox.h>
27 #include <Dt/HourGlass.h>
33 #include "datefield.h"
37 #include "group_editor.h"
46 Widget text, separator, button_form;
50 char buf[BUFSIZ], tmp_buf[BUFSIZ];
52 void tz_customtime_cb(), tz_mytime_cb(),
53 tz_apply_cb(), tz_cancel_cb(), tz_ok_cb();
55 if (c->timezone == NULL) {
56 c->timezone = (caddr_t)ckalloc(sizeof(Timezone));
57 t = (Timezone*)c->timezone;
60 t = (Timezone*)c->timezone;
62 title = XtNewString(catgets(c->DT_catd, 1, 649, "Calendar : Time Zone"));
63 t->frame = XtVaCreatePopupShell("frame",
64 xmDialogShellWidgetClass, c->frame,
66 XmNallowShellResize, False,
67 XmNmwmFunctions, MWM_FUNC_CLOSE | MWM_FUNC_MOVE,
68 XmNmappedWhenManaged, False,
72 t->form = XtVaCreateWidget("timezone_form",
73 xmFormWidgetClass, t->frame,
74 XmNautoUnmanage, False,
75 XmNhorizontalSpacing, 5,
76 XmNverticalSpacing, 5,
82 t->timezone_rc_mgr = XtVaCreateWidget("search_rc_mgr",
83 xmRowColumnWidgetClass, t->form,
84 XmNpacking, XmPACK_COLUMN,
85 XmNorientation, XmVERTICAL,
86 XmNradioBehavior, True,
87 XmNisHomogeneous, True,
88 XmNentryClass, xmToggleButtonGadgetClass,
89 XmNleftAttachment, XmATTACH_FORM,
91 XmNtopAttachment, XmATTACH_FORM,
95 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 650, "My Time"));
96 t->mytime = XtVaCreateWidget("myTime",
97 xmToggleButtonGadgetClass, t->timezone_rc_mgr,
98 XmNlabelString, xmstr,
103 XtAddCallback(t->mytime, XmNvalueChangedCallback, tz_mytime_cb, NULL);
105 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 652, "Custom Time"));
106 t->customtime = XtVaCreateWidget("customTime",
107 xmToggleButtonGadgetClass, t->timezone_rc_mgr,
108 XmNlabelString, xmstr,
112 XtAddCallback(t->customtime, XmNvalueChangedCallback, tz_customtime_cb, NULL);
114 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 653, "GMT"));
115 t->gmtlabel = XtVaCreateWidget("gmtLabel", xmLabelWidgetClass, t->form,
116 XmNlabelString, xmstr,
117 XmNleftAttachment, XmATTACH_WIDGET,
118 XmNleftWidget, t->customtime,
119 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
120 XmNbottomWidget, t->timezone_rc_mgr,
124 XtSetSensitive(t->gmtlabel, False);
127 XtSetArg(args[ac], XmNcomboBoxType, XmDROP_DOWN_COMBO_BOX); ++ac;
128 XtSetArg(args[ac], XmNleftAttachment, XmATTACH_WIDGET); ++ac;
129 XtSetArg(args[ac], XmNleftWidget, t->gmtlabel); ++ac;
130 XtSetArg(args[ac], XmNleftOffset, 8); ++ac;
131 XtSetArg(args[ac], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); ++ac;
132 XtSetArg(args[ac], XmNbottomOffset, 5); ++ac;
133 XtSetArg(args[ac], XmNbottomWidget, t->timezone_rc_mgr); ++ac;
134 XtSetArg(args[ac], XmNpositionMode, XmONE_BASED); ++ac;
135 t->gmtcombo = XmCreateComboBox(t->form, "gmtcombo", args, ac);
137 XtVaSetValues(t->gmtcombo, XmNwidth, 75, NULL);
138 XtSetSensitive(t->gmtcombo, False);
140 for(ac = -12; ac <= 12; ac += 1) {
142 sprintf(buf, "+%d", ac);
144 sprintf(buf, "%d", ac);
145 xmstr = XmStringCreateLocalized(buf);
146 XmComboBoxAddItem(t->gmtcombo, xmstr, 0, False);
149 /* Remind: remove this kludge after timezone attribute is available */
150 /* Remind: don't do this because of daylight savings time */
152 XtVaGetValues(t->gmtcombo, XmNtextField, &text, NULL);
153 XmTextSetString(text, "-6");
156 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 654, "Hours"));
157 t->hourlabel = XtVaCreateWidget("gmtHours", xmLabelWidgetClass, t->form,
158 XmNlabelString, xmstr,
159 XmNleftAttachment, XmATTACH_WIDGET,
160 XmNleftWidget, t->gmtcombo,
161 XmNrightAttachment, XmATTACH_FORM,
163 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
164 XmNbottomWidget, t->timezone_rc_mgr,
168 XtSetSensitive(t->hourlabel, False);
170 separator = XtVaCreateWidget("separator",
171 xmSeparatorGadgetClass,
173 XmNleftAttachment, XmATTACH_FORM,
174 XmNrightAttachment, XmATTACH_FORM,
175 XmNtopAttachment, XmATTACH_WIDGET,
176 XmNtopWidget, t->timezone_rc_mgr,
180 button_form = XtVaCreateWidget("button_form",
181 xmFormWidgetClass, t->form,
182 XmNautoUnmanage, False,
183 XmNleftAttachment, XmATTACH_FORM,
185 XmNrightAttachment, XmATTACH_FORM,
187 XmNtopAttachment, XmATTACH_WIDGET,
188 XmNtopWidget, separator,
189 XmNhorizontalSpacing, 3,
193 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 655, "OK"));
194 t->okbutton = XtVaCreateWidget("OK",
195 xmPushButtonWidgetClass, button_form,
196 XmNlabelString, xmstr,
197 XmNtopAttachment, XmATTACH_WIDGET,
198 XmNtopWidget, separator,
200 XmNleftAttachment, XmATTACH_POSITION,
202 XmNrightAttachment, XmATTACH_POSITION,
204 XmNnavigationType, XmTAB_GROUP,
208 XtAddCallback(t->okbutton, XmNactivateCallback, tz_ok_cb, NULL);
210 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 460, "Apply"));
211 t->applybutton = XtVaCreateWidget("Apply",
212 xmPushButtonWidgetClass, button_form,
213 XmNlabelString, xmstr,
214 XmNtopAttachment, XmATTACH_WIDGET,
215 XmNtopWidget, separator,
217 XmNleftAttachment, XmATTACH_POSITION,
219 XmNrightAttachment, XmATTACH_POSITION,
221 XmNnavigationType, XmTAB_GROUP,
225 XtAddCallback(t->applybutton, XmNactivateCallback, tz_apply_cb, NULL);
227 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 923, "Cancel"));
228 t->cancelbutton = XtVaCreateWidget("Cancel",
229 xmPushButtonWidgetClass, button_form,
230 XmNlabelString, xmstr,
231 XmNtopAttachment, XmATTACH_WIDGET,
232 XmNtopWidget, separator,
234 XmNleftAttachment, XmATTACH_POSITION,
236 XmNrightAttachment, XmATTACH_POSITION,
238 XmNnavigationType, XmTAB_GROUP,
242 XtAddCallback(t->cancelbutton, XmNactivateCallback, tz_cancel_cb, NULL);
244 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 77, "Help"));
245 t->helpbutton = XtVaCreateWidget("Help",
246 xmPushButtonWidgetClass, button_form,
247 XmNlabelString, xmstr,
248 XmNtopAttachment, XmATTACH_WIDGET,
249 XmNtopWidget, separator,
251 XmNleftAttachment, XmATTACH_POSITION,
253 XmNrightAttachment, XmATTACH_POSITION,
255 XmNnavigationType, XmTAB_GROUP,
258 XtAddCallback(t->helpbutton, XmNactivateCallback,
259 (XtCallbackProc)help_cb, TIMEZONE_HELP_BUTTON);
262 t->timezone_message = XtVaCreateWidget("message",
263 xmLabelGadgetClass, t->form,
264 XmNalignment, XmALIGNMENT_BEGINNING,
265 XmNtopAttachment, XmATTACH_WIDGET,
266 XmNtopWidget, t->helpbutton,
268 XmNleftAttachment, XmATTACH_FORM,
269 XmNrightAttachment, XmATTACH_FORM,
270 XmNbottomAttachment, XmATTACH_FORM,
274 /* Remind - get this from the structure after it's available */
275 cm_strcpy(t->gmttimezone, "");
276 cm_strcpy(t->mytimezone, "US/Pacific");
277 cm_strcpy(tmp_buf, (char*)getenv("TZ"));
279 cm_strcpy(t->mytimezone, tmp_buf);
281 sprintf(buf, "%s %s", catgets(c->DT_catd, 1, 659, "Time Zone:"),
283 set_message(t->timezone_message, buf);
284 set_message(c->message_text, buf);
286 XtVaSetValues(t->form,
287 XmNdefaultButton, t->applybutton,
288 XmNcancelButton, t->cancelbutton,
290 XtVaSetValues(button_form,
291 XmNdefaultButton, t->applybutton,
292 XmNcancelButton, t->cancelbutton,
294 ManageChildren(t->timezone_rc_mgr);
295 ManageChildren(button_form);
296 ManageChildren(t->form);
297 XtManageChild(t->form);
298 XtVaSetValues(t->frame, XmNmappedWhenManaged, True, NULL);
299 XtRealizeWidget(t->frame);
301 XtPopup(t->frame, XtGrabNone);
310 XmToggleButtonSetState(t->mytime, t->timezone_type == mytime, FALSE);
311 XmToggleButtonSetState(t->customtime, t->timezone_type == customtime,FALSE);
312 XtSetSensitive(t->gmtlabel, t->timezone_type == customtime);
313 XtSetSensitive(t->gmtcombo, t->timezone_type == customtime);
314 XtSetSensitive(t->hourlabel, t->timezone_type == customtime);
316 if (t->timezone_type == mytime)
319 XtVaGetValues(t->gmtcombo, XmNtextField, &text, NULL);
320 XmTextSetString(text, "");
325 tz_mytime_cb(Widget widget, XtPointer client_data, XtPointer call_data)
328 XmToggleButtonCallbackStruct *state =
329 (XmToggleButtonCallbackStruct *) call_data;
331 XtVaGetValues(widget, XmNuserData, &t, NULL);
334 t->edit_timezone_type = mytime;
335 XtSetSensitive(t->gmtlabel, !state->set);
336 XtSetSensitive(t->gmtcombo, !state->set);
337 XtSetSensitive(t->hourlabel, !state->set);
341 tz_customtime_cb(Widget widget, XtPointer client_data, XtPointer call_data)
344 XmToggleButtonCallbackStruct *state =
345 (XmToggleButtonCallbackStruct *) call_data;
347 XtVaGetValues(widget, XmNuserData, &t, NULL);
350 t->edit_timezone_type = customtime;
351 XtSetSensitive(t->gmtlabel, state->set);
352 XtSetSensitive(t->gmtcombo, state->set);
353 XtSetSensitive(t->hourlabel, state->set);
357 tz_set_timezone(Calendar *c, Timezone *t)
359 char *tmp_buf, buf[BUFSIZ], gmt[BUFSIZ];
361 Dtcm_calendar *cal_handle;
364 t->timezone_type = t->edit_timezone_type;
365 if (t->timezone_type == mytime)
367 set_timezone(t->mytimezone);
368 sprintf(buf, "%s %s", catgets(c->DT_catd, 1, 659, "Time Zone:"),
372 /* Remind: this won't work because of daylight savings time */
373 /* Remind: add this after we can get more info from backend */
375 cal_handle = allocate_cal_struct(
378 DtCM_ATTR_UTC_OFFSET_I,
380 if (query_cal_struct(c->my_cal_handle, cal_handle) == CSA_SUCCESS)
382 seconds_to_hours(cal_handle->attrs->value->item.number_value);
383 if (time_diff >= 0) sprintf(gmt, "GMT+%d", time_diff);
384 else sprintf(gmt, "GMT%d", time_diff);
389 else if (t->timezone_type == customtime)
391 XtVaGetValues(t->gmtcombo, XmNtextField, &text, NULL);
392 tmp_buf = XmTextGetString(text);
393 cm_strcpy(t->gmttimezone, tmp_buf);
394 sprintf(gmt, "GMT%s", tmp_buf);
396 sprintf(buf, "%s %s", catgets(c->DT_catd, 1, 659, "Time Zone:"), gmt);
398 set_message(t->timezone_message, buf);
399 paint_canvas(c, NULL, RENDER_CLEAR_FIRST);
400 set_message(c->message_text, buf);
401 if (editor_showing((Editor*)c->editor))
402 add_all_appt((Editor*)c->editor);
403 if (geditor_showing((GEditor*)c->geditor))
404 add_all_gappt((GEditor*)c->geditor);
405 if (todo_showing((ToDo*)c->todo))
406 add_all_todo((ToDo*)c->todo);
410 tz_apply_cb(Widget widget, XtPointer client_data, XtPointer call_data)
415 XtVaGetValues(widget, XmNuserData, &c, NULL);
416 t = (Timezone*)c->timezone;
417 tz_set_timezone(c, t);
422 tz_ok_cb(Widget widget, XtPointer client_data, XtPointer call_data)
427 XtVaGetValues(widget, XmNuserData, &c, NULL);
428 t = (Timezone*)c->timezone;
429 tz_set_timezone(c, t);
435 tz_cancel_cb(Widget widget, XtPointer client_data, XtPointer call_data)
440 XtVaGetValues(widget, XmNuserData, &c, NULL);
441 t = (Timezone*)c->timezone;