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 /* $TOG: timezone.c /main/10 1999/07/01 16:36:43 mgreess $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Novell, Inc.
28 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
31 #include <EUSCompat.h>
37 #include <Xm/LabelG.h>
40 #include <Xm/DialogS.h>
42 #include <Xm/RowColumn.h>
44 #include <Xm/SeparatoG.h>
46 #include <Xm/ToggleBG.h>
47 #include <Xm/MwmUtil.h>
48 #include <Xm/ComboBox.h>
49 #include <Dt/HourGlass.h>
55 #include "datefield.h"
59 #include "group_editor.h"
68 Widget text, separator, button_form;
72 char buf[BUFSIZ], tmp_buf[BUFSIZ];
74 void tz_customtime_cb(), tz_mytime_cb(),
75 tz_apply_cb(), tz_cancel_cb(), tz_ok_cb();
77 if (c->timezone == NULL) {
78 c->timezone = (caddr_t)ckalloc(sizeof(Timezone));
79 t = (Timezone*)c->timezone;
82 t = (Timezone*)c->timezone;
84 title = XtNewString(catgets(c->DT_catd, 1, 649, "Calendar : Time Zone"));
85 t->frame = XtVaCreatePopupShell("frame",
86 xmDialogShellWidgetClass, c->frame,
88 XmNallowShellResize, False,
89 XmNmwmFunctions, MWM_FUNC_CLOSE | MWM_FUNC_MOVE,
90 XmNmappedWhenManaged, False,
94 t->form = XtVaCreateWidget("timezone_form",
95 xmFormWidgetClass, t->frame,
96 XmNautoUnmanage, False,
97 XmNhorizontalSpacing, 5,
98 XmNverticalSpacing, 5,
104 t->timezone_rc_mgr = XtVaCreateWidget("search_rc_mgr",
105 xmRowColumnWidgetClass, t->form,
106 XmNpacking, XmPACK_COLUMN,
107 XmNorientation, XmVERTICAL,
108 XmNradioBehavior, True,
109 XmNisHomogeneous, True,
110 XmNentryClass, xmToggleButtonGadgetClass,
111 XmNleftAttachment, XmATTACH_FORM,
113 XmNtopAttachment, XmATTACH_FORM,
117 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 650, "My Time"));
118 t->mytime = XtVaCreateWidget("myTime",
119 xmToggleButtonGadgetClass, t->timezone_rc_mgr,
120 XmNlabelString, xmstr,
125 XtAddCallback(t->mytime, XmNvalueChangedCallback, tz_mytime_cb, NULL);
127 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 652, "Custom Time"));
128 t->customtime = XtVaCreateWidget("customTime",
129 xmToggleButtonGadgetClass, t->timezone_rc_mgr,
130 XmNlabelString, xmstr,
134 XtAddCallback(t->customtime, XmNvalueChangedCallback, tz_customtime_cb, NULL);
136 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 653, "GMT"));
137 t->gmtlabel = XtVaCreateWidget("gmtLabel", xmLabelWidgetClass, t->form,
138 XmNlabelString, xmstr,
139 XmNleftAttachment, XmATTACH_WIDGET,
140 XmNleftWidget, t->customtime,
141 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
142 XmNbottomWidget, t->timezone_rc_mgr,
146 XtSetSensitive(t->gmtlabel, False);
149 XtSetArg(args[ac], XmNcomboBoxType, XmDROP_DOWN_COMBO_BOX); ++ac;
150 XtSetArg(args[ac], XmNleftAttachment, XmATTACH_WIDGET); ++ac;
151 XtSetArg(args[ac], XmNleftWidget, t->gmtlabel); ++ac;
152 XtSetArg(args[ac], XmNleftOffset, 8); ++ac;
153 XtSetArg(args[ac], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); ++ac;
154 XtSetArg(args[ac], XmNbottomOffset, 5); ++ac;
155 XtSetArg(args[ac], XmNbottomWidget, t->timezone_rc_mgr); ++ac;
156 XtSetArg(args[ac], XmNpositionMode, XmONE_BASED); ++ac;
157 t->gmtcombo = XmCreateComboBox(t->form, "gmtcombo", args, ac);
159 XtVaSetValues(t->gmtcombo, XmNwidth, 75, NULL);
160 XtSetSensitive(t->gmtcombo, False);
162 for(ac = -12; ac <= 12; ac += 1) {
164 sprintf(buf, "+%d", ac);
166 sprintf(buf, "%d", ac);
167 xmstr = XmStringCreateLocalized(buf);
168 XmComboBoxAddItem(t->gmtcombo, xmstr, 0, False);
171 /* Remind: remove this kludge after timezone attribute is available */
172 /* Remind: don't do this because of daylight savings time */
174 XtVaGetValues(t->gmtcombo, XmNtextField, &text, NULL);
175 XmTextSetString(text, "-6");
178 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 654, "Hours"));
179 t->hourlabel = XtVaCreateWidget("gmtHours", xmLabelWidgetClass, t->form,
180 XmNlabelString, xmstr,
181 XmNleftAttachment, XmATTACH_WIDGET,
182 XmNleftWidget, t->gmtcombo,
183 XmNrightAttachment, XmATTACH_FORM,
185 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
186 XmNbottomWidget, t->timezone_rc_mgr,
190 XtSetSensitive(t->hourlabel, False);
192 separator = XtVaCreateWidget("separator",
193 xmSeparatorGadgetClass,
195 XmNleftAttachment, XmATTACH_FORM,
196 XmNrightAttachment, XmATTACH_FORM,
197 XmNtopAttachment, XmATTACH_WIDGET,
198 XmNtopWidget, t->timezone_rc_mgr,
202 button_form = XtVaCreateWidget("button_form",
203 xmFormWidgetClass, t->form,
204 XmNautoUnmanage, False,
205 XmNleftAttachment, XmATTACH_FORM,
207 XmNrightAttachment, XmATTACH_FORM,
209 XmNtopAttachment, XmATTACH_WIDGET,
210 XmNtopWidget, separator,
211 XmNhorizontalSpacing, 3,
215 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 655, "OK"));
216 t->okbutton = XtVaCreateWidget("OK",
217 xmPushButtonWidgetClass, button_form,
218 XmNlabelString, xmstr,
219 XmNtopAttachment, XmATTACH_WIDGET,
220 XmNtopWidget, separator,
222 XmNleftAttachment, XmATTACH_POSITION,
224 XmNrightAttachment, XmATTACH_POSITION,
226 XmNnavigationType, XmTAB_GROUP,
230 XtAddCallback(t->okbutton, XmNactivateCallback, tz_ok_cb, NULL);
232 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 460, "Apply"));
233 t->applybutton = XtVaCreateWidget("Apply",
234 xmPushButtonWidgetClass, button_form,
235 XmNlabelString, xmstr,
236 XmNtopAttachment, XmATTACH_WIDGET,
237 XmNtopWidget, separator,
239 XmNleftAttachment, XmATTACH_POSITION,
241 XmNrightAttachment, XmATTACH_POSITION,
243 XmNnavigationType, XmTAB_GROUP,
247 XtAddCallback(t->applybutton, XmNactivateCallback, tz_apply_cb, NULL);
249 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 923, "Cancel"));
250 t->cancelbutton = XtVaCreateWidget("Cancel",
251 xmPushButtonWidgetClass, button_form,
252 XmNlabelString, xmstr,
253 XmNtopAttachment, XmATTACH_WIDGET,
254 XmNtopWidget, separator,
256 XmNleftAttachment, XmATTACH_POSITION,
258 XmNrightAttachment, XmATTACH_POSITION,
260 XmNnavigationType, XmTAB_GROUP,
264 XtAddCallback(t->cancelbutton, XmNactivateCallback, tz_cancel_cb, NULL);
266 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 77, "Help"));
267 t->helpbutton = XtVaCreateWidget("Help",
268 xmPushButtonWidgetClass, button_form,
269 XmNlabelString, xmstr,
270 XmNtopAttachment, XmATTACH_WIDGET,
271 XmNtopWidget, separator,
273 XmNleftAttachment, XmATTACH_POSITION,
275 XmNrightAttachment, XmATTACH_POSITION,
277 XmNnavigationType, XmTAB_GROUP,
280 XtAddCallback(t->helpbutton, XmNactivateCallback,
281 (XtCallbackProc)help_cb, TIMEZONE_HELP_BUTTON);
284 t->timezone_message = XtVaCreateWidget("message",
285 xmLabelGadgetClass, t->form,
286 XmNalignment, XmALIGNMENT_BEGINNING,
287 XmNtopAttachment, XmATTACH_WIDGET,
288 XmNtopWidget, t->helpbutton,
290 XmNleftAttachment, XmATTACH_FORM,
291 XmNrightAttachment, XmATTACH_FORM,
292 XmNbottomAttachment, XmATTACH_FORM,
296 /* Remind - get this from the structure after it's available */
297 cm_strcpy(t->gmttimezone, "");
298 cm_strcpy(t->mytimezone, "US/Pacific");
299 cm_strcpy(tmp_buf, (char*)getenv("TZ"));
301 cm_strcpy(t->mytimezone, tmp_buf);
303 sprintf(buf, "%s %s", catgets(c->DT_catd, 1, 659, "Time Zone:"),
305 set_message(t->timezone_message, buf);
306 set_message(c->message_text, buf);
308 XtVaSetValues(t->form,
309 XmNdefaultButton, t->applybutton,
310 XmNcancelButton, t->cancelbutton,
312 XtVaSetValues(button_form,
313 XmNdefaultButton, t->applybutton,
314 XmNcancelButton, t->cancelbutton,
316 ManageChildren(t->timezone_rc_mgr);
317 ManageChildren(button_form);
318 ManageChildren(t->form);
319 XtManageChild(t->form);
320 XtVaSetValues(t->frame, XmNmappedWhenManaged, True, NULL);
321 XtRealizeWidget(t->frame);
323 XtPopup(t->frame, XtGrabNone);
332 XmToggleButtonSetState(t->mytime, t->timezone_type == mytime, FALSE);
333 XmToggleButtonSetState(t->customtime, t->timezone_type == customtime,FALSE);
334 XtSetSensitive(t->gmtlabel, t->timezone_type == customtime);
335 XtSetSensitive(t->gmtcombo, t->timezone_type == customtime);
336 XtSetSensitive(t->hourlabel, t->timezone_type == customtime);
338 if (t->timezone_type == mytime)
341 XtVaGetValues(t->gmtcombo, XmNtextField, &text, NULL);
342 XmTextSetString(text, "");
347 tz_mytime_cb(Widget widget, XtPointer client_data, XtPointer call_data)
350 XmToggleButtonCallbackStruct *state =
351 (XmToggleButtonCallbackStruct *) call_data;
353 XtVaGetValues(widget, XmNuserData, &t, NULL);
356 t->edit_timezone_type = mytime;
357 XtSetSensitive(t->gmtlabel, !state->set);
358 XtSetSensitive(t->gmtcombo, !state->set);
359 XtSetSensitive(t->hourlabel, !state->set);
363 tz_customtime_cb(Widget widget, XtPointer client_data, XtPointer call_data)
366 XmToggleButtonCallbackStruct *state =
367 (XmToggleButtonCallbackStruct *) call_data;
369 XtVaGetValues(widget, XmNuserData, &t, NULL);
372 t->edit_timezone_type = customtime;
373 XtSetSensitive(t->gmtlabel, state->set);
374 XtSetSensitive(t->gmtcombo, state->set);
375 XtSetSensitive(t->hourlabel, state->set);
379 tz_set_timezone(Calendar *c, Timezone *t)
381 char *tmp_buf, buf[BUFSIZ], gmt[BUFSIZ];
383 Dtcm_calendar *cal_handle;
386 t->timezone_type = t->edit_timezone_type;
387 if (t->timezone_type == mytime)
389 set_timezone(t->mytimezone);
390 sprintf(buf, "%s %s", catgets(c->DT_catd, 1, 659, "Time Zone:"),
394 /* Remind: this won't work because of daylight savings time */
395 /* Remind: add this after we can get more info from backend */
397 cal_handle = allocate_cal_struct(
400 DtCM_ATTR_UTC_OFFSET_I,
402 if (query_cal_struct(c->my_cal_handle, cal_handle) == CSA_SUCCESS)
404 seconds_to_hours(cal_handle->attrs->value->item.number_value);
405 if (time_diff >= 0) sprintf(gmt, "GMT+%d", time_diff);
406 else sprintf(gmt, "GMT%d", time_diff);
411 else if (t->timezone_type == customtime)
413 XtVaGetValues(t->gmtcombo, XmNtextField, &text, NULL);
414 tmp_buf = XmTextGetString(text);
415 cm_strcpy(t->gmttimezone, tmp_buf);
416 sprintf(gmt, "GMT%s", tmp_buf);
418 sprintf(buf, "%s %s", catgets(c->DT_catd, 1, 659, "Time Zone:"), gmt);
420 set_message(t->timezone_message, buf);
421 paint_canvas(c, NULL, RENDER_CLEAR_FIRST);
422 set_message(c->message_text, buf);
423 if (editor_showing((Editor*)c->editor))
424 add_all_appt((Editor*)c->editor);
425 if (geditor_showing((GEditor*)c->geditor))
426 add_all_gappt((GEditor*)c->geditor);
427 if (todo_showing((ToDo*)c->todo))
428 add_all_todo((ToDo*)c->todo);
432 tz_apply_cb(Widget widget, XtPointer client_data, XtPointer call_data)
437 XtVaGetValues(widget, XmNuserData, &c, NULL);
438 t = (Timezone*)c->timezone;
439 tz_set_timezone(c, t);
444 tz_ok_cb(Widget widget, XtPointer client_data, XtPointer call_data)
449 XtVaGetValues(widget, XmNuserData, &c, NULL);
450 t = (Timezone*)c->timezone;
451 tz_set_timezone(c, t);
457 tz_cancel_cb(Widget widget, XtPointer client_data, XtPointer call_data)
462 XtVaGetValues(widget, XmNuserData, &c, NULL);
463 t = (Timezone*)c->timezone;