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 libraries 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"
64 make_timezone(Calendar *c)
67 Widget text, separator, button_form;
71 char buf[BUFSIZ], tmp_buf[BUFSIZ] = "";
73 void tz_customtime_cb(), tz_mytime_cb(),
74 tz_apply_cb(), tz_cancel_cb(), tz_ok_cb();
76 if (c->timezone == NULL) {
77 c->timezone = (caddr_t)ckalloc(sizeof(Timezone));
78 t = (Timezone*)c->timezone;
81 t = (Timezone*)c->timezone;
83 title = XtNewString(catgets(c->DT_catd, 1, 649, "Calendar : Time Zone"));
84 t->frame = XtVaCreatePopupShell("frame",
85 xmDialogShellWidgetClass, c->frame,
87 XmNallowShellResize, False,
88 XmNmwmFunctions, MWM_FUNC_CLOSE | MWM_FUNC_MOVE,
89 XmNmappedWhenManaged, False,
93 t->form = XtVaCreateWidget("timezone_form",
94 xmFormWidgetClass, t->frame,
95 XmNautoUnmanage, False,
96 XmNhorizontalSpacing, 5,
97 XmNverticalSpacing, 5,
103 t->timezone_rc_mgr = XtVaCreateWidget("search_rc_mgr",
104 xmRowColumnWidgetClass, t->form,
105 XmNpacking, XmPACK_COLUMN,
106 XmNorientation, XmVERTICAL,
107 XmNradioBehavior, True,
108 XmNisHomogeneous, True,
109 XmNentryClass, xmToggleButtonGadgetClass,
110 XmNleftAttachment, XmATTACH_FORM,
112 XmNtopAttachment, XmATTACH_FORM,
116 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 650, "My Time"));
117 t->mytime = XtVaCreateWidget("myTime",
118 xmToggleButtonGadgetClass, t->timezone_rc_mgr,
119 XmNlabelString, xmstr,
124 XtAddCallback(t->mytime, XmNvalueChangedCallback, tz_mytime_cb, NULL);
126 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 652, "Custom Time"));
127 t->customtime = XtVaCreateWidget("customTime",
128 xmToggleButtonGadgetClass, t->timezone_rc_mgr,
129 XmNlabelString, xmstr,
133 XtAddCallback(t->customtime, XmNvalueChangedCallback, tz_customtime_cb, NULL);
135 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 653, "GMT"));
136 t->gmtlabel = XtVaCreateWidget("gmtLabel", xmLabelWidgetClass, t->form,
137 XmNlabelString, xmstr,
138 XmNleftAttachment, XmATTACH_WIDGET,
139 XmNleftWidget, t->customtime,
140 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
141 XmNbottomWidget, t->timezone_rc_mgr,
145 XtSetSensitive(t->gmtlabel, False);
148 XtSetArg(args[ac], XmNcomboBoxType, XmDROP_DOWN_COMBO_BOX); ++ac;
149 XtSetArg(args[ac], XmNleftAttachment, XmATTACH_WIDGET); ++ac;
150 XtSetArg(args[ac], XmNleftWidget, t->gmtlabel); ++ac;
151 XtSetArg(args[ac], XmNleftOffset, 8); ++ac;
152 XtSetArg(args[ac], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); ++ac;
153 XtSetArg(args[ac], XmNbottomOffset, 5); ++ac;
154 XtSetArg(args[ac], XmNbottomWidget, t->timezone_rc_mgr); ++ac;
155 XtSetArg(args[ac], XmNpositionMode, XmONE_BASED); ++ac;
156 t->gmtcombo = XmCreateComboBox(t->form, "gmtcombo", args, ac);
158 XtVaSetValues(t->gmtcombo, XmNwidth, 75, NULL);
159 XtSetSensitive(t->gmtcombo, False);
161 for(ac = -12; ac <= 12; ac += 1) {
163 sprintf(buf, "+%d", ac);
165 sprintf(buf, "%d", ac);
166 xmstr = XmStringCreateLocalized(buf);
167 XmComboBoxAddItem(t->gmtcombo, xmstr, 0, False);
170 /* Remind: remove this kludge after timezone attribute is available */
171 /* Remind: don't do this because of daylight savings time */
173 XtVaGetValues(t->gmtcombo, XmNtextField, &text, NULL);
174 XmTextSetString(text, "-6");
177 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 654, "Hours"));
178 t->hourlabel = XtVaCreateWidget("gmtHours", xmLabelWidgetClass, t->form,
179 XmNlabelString, xmstr,
180 XmNleftAttachment, XmATTACH_WIDGET,
181 XmNleftWidget, t->gmtcombo,
182 XmNrightAttachment, XmATTACH_FORM,
184 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
185 XmNbottomWidget, t->timezone_rc_mgr,
189 XtSetSensitive(t->hourlabel, False);
191 separator = XtVaCreateWidget("separator",
192 xmSeparatorGadgetClass,
194 XmNleftAttachment, XmATTACH_FORM,
195 XmNrightAttachment, XmATTACH_FORM,
196 XmNtopAttachment, XmATTACH_WIDGET,
197 XmNtopWidget, t->timezone_rc_mgr,
201 button_form = XtVaCreateWidget("button_form",
202 xmFormWidgetClass, t->form,
203 XmNautoUnmanage, False,
204 XmNleftAttachment, XmATTACH_FORM,
206 XmNrightAttachment, XmATTACH_FORM,
208 XmNtopAttachment, XmATTACH_WIDGET,
209 XmNtopWidget, separator,
210 XmNhorizontalSpacing, 3,
214 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 655, "OK"));
215 t->okbutton = XtVaCreateWidget("OK",
216 xmPushButtonWidgetClass, button_form,
217 XmNlabelString, xmstr,
218 XmNtopAttachment, XmATTACH_WIDGET,
219 XmNtopWidget, separator,
221 XmNleftAttachment, XmATTACH_POSITION,
223 XmNrightAttachment, XmATTACH_POSITION,
225 XmNnavigationType, XmTAB_GROUP,
229 XtAddCallback(t->okbutton, XmNactivateCallback, tz_ok_cb, NULL);
231 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 460, "Apply"));
232 t->applybutton = XtVaCreateWidget("Apply",
233 xmPushButtonWidgetClass, button_form,
234 XmNlabelString, xmstr,
235 XmNtopAttachment, XmATTACH_WIDGET,
236 XmNtopWidget, separator,
238 XmNleftAttachment, XmATTACH_POSITION,
240 XmNrightAttachment, XmATTACH_POSITION,
242 XmNnavigationType, XmTAB_GROUP,
246 XtAddCallback(t->applybutton, XmNactivateCallback, tz_apply_cb, NULL);
248 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 923, "Cancel"));
249 t->cancelbutton = XtVaCreateWidget("Cancel",
250 xmPushButtonWidgetClass, button_form,
251 XmNlabelString, xmstr,
252 XmNtopAttachment, XmATTACH_WIDGET,
253 XmNtopWidget, separator,
255 XmNleftAttachment, XmATTACH_POSITION,
257 XmNrightAttachment, XmATTACH_POSITION,
259 XmNnavigationType, XmTAB_GROUP,
263 XtAddCallback(t->cancelbutton, XmNactivateCallback, tz_cancel_cb, NULL);
265 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 77, "Help"));
266 t->helpbutton = XtVaCreateWidget("Help",
267 xmPushButtonWidgetClass, button_form,
268 XmNlabelString, xmstr,
269 XmNtopAttachment, XmATTACH_WIDGET,
270 XmNtopWidget, separator,
272 XmNleftAttachment, XmATTACH_POSITION,
274 XmNrightAttachment, XmATTACH_POSITION,
276 XmNnavigationType, XmTAB_GROUP,
279 XtAddCallback(t->helpbutton, XmNactivateCallback,
280 (XtCallbackProc)help_cb, TIMEZONE_HELP_BUTTON);
283 t->timezone_message = XtVaCreateWidget("message",
284 xmLabelGadgetClass, t->form,
285 XmNalignment, XmALIGNMENT_BEGINNING,
286 XmNtopAttachment, XmATTACH_WIDGET,
287 XmNtopWidget, t->helpbutton,
289 XmNleftAttachment, XmATTACH_FORM,
290 XmNrightAttachment, XmATTACH_FORM,
291 XmNbottomAttachment, XmATTACH_FORM,
295 /* Remind - get this from the structure after it's available */
296 cm_strcpy(t->gmttimezone, "");
297 cm_strcpy(t->mytimezone, "US/Pacific");
298 cm_strcpy(tmp_buf, (char*)getenv("TZ"));
299 cm_strcpy(t->mytimezone, tmp_buf);
301 sprintf(buf, "%s %s", catgets(c->DT_catd, 1, 659, "Time Zone:"),
303 set_message(t->timezone_message, buf);
304 set_message(c->message_text, buf);
306 XtVaSetValues(t->form,
307 XmNdefaultButton, t->applybutton,
308 XmNcancelButton, t->cancelbutton,
310 XtVaSetValues(button_form,
311 XmNdefaultButton, t->applybutton,
312 XmNcancelButton, t->cancelbutton,
314 ManageChildren(t->timezone_rc_mgr);
315 ManageChildren(button_form);
316 ManageChildren(t->form);
317 XtManageChild(t->form);
318 XtVaSetValues(t->frame, XmNmappedWhenManaged, True, NULL);
319 XtRealizeWidget(t->frame);
321 XtPopup(t->frame, XtGrabNone);
327 refresh_timezone(Timezone *t)
329 XmToggleButtonSetState(t->mytime, t->timezone_type == mytime, FALSE);
330 XmToggleButtonSetState(t->customtime, t->timezone_type == customtime,FALSE);
331 XtSetSensitive(t->gmtlabel, t->timezone_type == customtime);
332 XtSetSensitive(t->gmtcombo, t->timezone_type == customtime);
333 XtSetSensitive(t->hourlabel, t->timezone_type == customtime);
335 if (t->timezone_type == mytime)
338 XtVaGetValues(t->gmtcombo, XmNtextField, &text, NULL);
339 XmTextSetString(text, "");
344 tz_mytime_cb(Widget widget, XtPointer client_data, XtPointer call_data)
347 XmToggleButtonCallbackStruct *state =
348 (XmToggleButtonCallbackStruct *) call_data;
350 XtVaGetValues(widget, XmNuserData, &t, NULL);
353 t->edit_timezone_type = mytime;
354 XtSetSensitive(t->gmtlabel, !state->set);
355 XtSetSensitive(t->gmtcombo, !state->set);
356 XtSetSensitive(t->hourlabel, !state->set);
360 tz_customtime_cb(Widget widget, XtPointer client_data, XtPointer call_data)
363 XmToggleButtonCallbackStruct *state =
364 (XmToggleButtonCallbackStruct *) call_data;
366 XtVaGetValues(widget, XmNuserData, &t, NULL);
369 t->edit_timezone_type = customtime;
370 XtSetSensitive(t->gmtlabel, state->set);
371 XtSetSensitive(t->gmtcombo, state->set);
372 XtSetSensitive(t->hourlabel, state->set);
376 tz_set_timezone(Calendar *c, Timezone *t)
378 char *tmp_buf, buf[BUFSIZ], gmt[BUFSIZ];
380 Dtcm_calendar *cal_handle;
383 t->timezone_type = t->edit_timezone_type;
384 if (t->timezone_type == mytime)
386 set_timezone(t->mytimezone);
387 sprintf(buf, "%s %s", catgets(c->DT_catd, 1, 659, "Time Zone:"),
391 /* Remind: this won't work because of daylight savings time */
392 /* Remind: add this after we can get more info from backend */
394 cal_handle = allocate_cal_struct(
397 DtCM_ATTR_UTC_OFFSET_I,
399 if (query_cal_struct(c->my_cal_handle, cal_handle) == CSA_SUCCESS)
401 seconds_to_hours(cal_handle->attrs->value->item.number_value);
402 if (time_diff >= 0) sprintf(gmt, "GMT+%d", time_diff);
403 else sprintf(gmt, "GMT%d", time_diff);
408 else if (t->timezone_type == customtime)
410 XtVaGetValues(t->gmtcombo, XmNtextField, &text, NULL);
411 tmp_buf = XmTextGetString(text);
412 cm_strcpy(t->gmttimezone, tmp_buf);
413 sprintf(gmt, "GMT%s", tmp_buf);
415 sprintf(buf, "%s %s", catgets(c->DT_catd, 1, 659, "Time Zone:"), gmt);
417 set_message(t->timezone_message, buf);
418 paint_canvas(c, NULL, RENDER_CLEAR_FIRST);
419 set_message(c->message_text, buf);
420 if (editor_showing((Editor*)c->editor))
421 add_all_appt((Editor*)c->editor);
422 if (geditor_showing((GEditor*)c->geditor))
423 add_all_gappt((GEditor*)c->geditor);
424 if (todo_showing((ToDo*)c->todo))
425 add_all_todo((ToDo*)c->todo);
429 tz_apply_cb(Widget widget, XtPointer client_data, XtPointer call_data)
434 XtVaGetValues(widget, XmNuserData, &c, NULL);
435 t = (Timezone*)c->timezone;
436 tz_set_timezone(c, t);
441 tz_ok_cb(Widget widget, XtPointer client_data, XtPointer call_data)
446 XtVaGetValues(widget, XmNuserData, &c, NULL);
447 t = (Timezone*)c->timezone;
448 tz_set_timezone(c, t);
454 tz_cancel_cb(Widget widget, XtPointer client_data, XtPointer call_data)
459 XtVaGetValues(widget, XmNuserData, &c, NULL);
460 t = (Timezone*)c->timezone;