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 /* $XConsortium: rfp.c /main/10 1996/10/14 16:07:07 barstow $ */
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>
35 #include <Xm/DialogS.h>
37 #include <Xm/LabelG.h>
38 #include <Xm/RowColumn.h>
41 #include <Xm/SeparatoG.h>
43 #include <Xm/MwmUtil.h>
44 #include <Xm/ComboBox.h>
51 #include <sys/param.h>
54 #define PRIVATE_FOREVER -9999999
57 extern Dimension ComputeMaxWidth(Widget, Widget, Widget, Widget);
59 static char *dow_str(time_t);
60 static void change_to_last_week(Dtcm_appointment *, int, time_t, RFP *);
62 /*******************************************************************************
64 ** Static functions visibile to rfp.c only
66 *******************************************************************************/
68 ** Set the necessary for stuff grey/ungrey
71 rfp_toggle_for_grey(RFP *rfp, Boolean status) {
74 XtVaSetValues(rfp->for_label, XmNsensitive, status, NULL);
75 XtVaGetValues(rfp->for_menu, XmNlist, &list, XmNtextField, &text, NULL);
76 XtVaSetValues(list, XmNsensitive, status, NULL);
77 XtVaSetValues(text, XmNsensitive, status, NULL);
78 XtVaSetValues(rfp->for_scope, XmNsensitive, status, NULL);
82 rfp_toggle_repeat_grey(RFP *rfp, Boolean status) {
85 XtVaSetValues(rfp->repeat_label, XmNsensitive, status, NULL);
86 XtVaGetValues(rfp->repeat_menu, XmNlist, &list, NULL);
87 XtVaSetValues(list, XmNsensitive, status, NULL);
91 /* This routine makes sure that the repeat menu has the right set
92 of values in it for the connection version. The REPEAT_EVERY
93 item should not appear for vcalendars of version 3 and lower. */
96 rfp_set_repeat_values(RFP *rfp)
103 /* delete all the old items. */
105 XtVaGetValues(rfp->repeat_menu, XmNlist, &list, NULL);
106 XtVaGetValues(list, XmNitemCount, &limit, NULL);
108 if ((limit == 11) && (rfp->cal->general->version >= DATAVER3))
111 if ((limit == 10) && (rfp->cal->general->version == DATAVER2))
114 if ((limit == 7) && (rfp->cal->general->version == DATAVER1))
119 XmComboBoxDeletePos(rfp->repeat_menu, 11);
120 if (rfp->cal->general->version == DATAVER1) {
121 XmComboBoxDeletePos(rfp->repeat_menu, 10);
122 XmComboBoxDeletePos(rfp->repeat_menu, 9);
123 XmComboBoxDeletePos(rfp->repeat_menu, 8);
125 if (rfp->repeat_popup_frame)
126 XtUnmanageChild(rfp->repeat_form_mgr);
129 else if (limit == 10) {
130 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 901, "Repeat Every ..."));
131 XmComboBoxAddItem(rfp->repeat_menu, xmstr, 0, False);
135 else if (limit == 7) {
136 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 902, "Monday Thru Friday"));
137 XmComboBoxAddItem(rfp->repeat_menu, xmstr, 0, False);
140 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 903, "Mon, Wed, Fri"));
141 XmComboBoxAddItem(rfp->repeat_menu, xmstr, 0, False);
143 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 861, "Tuesday, Thursday"));
144 XmComboBoxAddItem(rfp->repeat_menu, xmstr, 0, False);
147 if (rfp->cal->general->version == DATAVER3) {
148 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 862, "Repeat Every..."));
149 XmComboBoxAddItem(rfp->repeat_menu, xmstr, 0, False);
157 ** This is used for the rfp_repeat_menu_proc and the rfp_apply_proc functions.
158 ** It simply sets default for values given a Repeat_op
161 rfp_set_default_for(RFP *rfp, Repeat_menu_op op, Boolean status) {
163 XmString new_scope_str;
164 Calendar *c = rfp->cal;
166 XtVaGetValues(rfp->for_menu, XmNtextField, &text, NULL);
167 XmTextFieldSetString(text, default_repeat_cnt_str(op));
169 new_scope_str = XmStringCreateLocalized(
170 default_repeat_scope_str(c->DT_catd, op));
171 XtVaSetValues(rfp->for_scope, XmNlabelString, new_scope_str,
173 XmStringFree(new_scope_str);
175 rfp_toggle_for_grey(rfp, status);
179 ** Callbacks for the repeat every popup
182 rfp_repeat_scope_proc(Widget w, XtPointer client_data, XtPointer cbs) {
183 RFP *rfp = (RFP *)client_data;
184 Repeat_scope_menu_op op;
189 XtVaGetValues(w, XmNuserData, &op, NULL);
190 XtVaSetValues(rfp->repeat_popup_menu, XmNuserData, op, NULL);
194 string_is_number(char *str) {
197 if (blank_buf(str)) {
201 while (str && *str) {
202 if (!isdigit(*str) && *str != ' ' && *str != '\t')
212 rfp_apply_proc(Widget w, XtPointer client_data, XtPointer cbs) {
213 RFP *rfp = (RFP *)client_data;
218 Repeat_scope_menu_op op = REPEAT_DAYS;
225 pu = (Props_pu *)c->properties_pu;
227 str = XmTextGetString(rfp->repeat_popup_text);
229 if (!string_is_number(str)) {
230 char *title = XtNewString(catgets(c->DT_catd, 1, 969, "Calendar : Error - Repeat Every"));
231 char *text = XtNewString(catgets(c->DT_catd, 1, 970, "The Repeat Every value must be an integer with no sign."));
232 char *ident1 = XtNewString(catgets(c->DT_catd, 1, 95, "Continue"));
235 dialog_popup(c->frame,
238 BUTTON_IDENT, 1, ident1,
239 DIALOG_IMAGE, pu->xm_error_pixmap,
247 rfp->repeat_nth = atoi(str);
249 if (rfp->repeat_nth == 0) {
250 XtUnmanageChild(rfp->repeat_form_mgr);
255 * Change the string to be more informative.
257 XtVaGetValues(rfp->repeat_popup_menu, XmNuserData, &op, NULL);
261 case REPEAT_DAYS: repeat_str = catgets(c->DT_catd, 1, 825, "Days");
264 case REPEAT_WEEKS: repeat_str = catgets(c->DT_catd, 1, 826, "Weeks");
267 case REPEAT_MONTHS: repeat_str = catgets(c->DT_catd, 1, 827, "Months");
272 * Now change the text field
275 char *nl_repeat = XtNewString(repeat_str);
276 sprintf(buf, catgets(c->DT_catd, 1, 531, "Every %d %s"),
277 rfp->repeat_nth, nl_repeat);
281 xmstr = XmStringCreateLocalized(buf);
282 XtVaSetValues(rfp->repeat_menu, XmNlabelString, xmstr, NULL);
287 rfp->repeat_type = CSA_X_DT_REPEAT_EVERY_NDAY;
288 rfp_set_default_for(rfp, DAILY, True);
291 rfp->repeat_type = CSA_X_DT_REPEAT_EVERY_NWEEK;
292 rfp_set_default_for(rfp, WEEKLY, True);
296 rfp->repeat_type = CSA_X_DT_REPEAT_EVERY_NMONTH;
297 rfp_set_default_for(rfp, MONTHLY_BY_DATE, True);
301 XtUnmanageChild(rfp->repeat_form_mgr);
305 rfp_cancel_proc(Widget w, XtPointer client_data, XtPointer cbs) {
306 RFP *rfp = (RFP *)client_data;
309 rfp->repeat_type = CSA_X_DT_REPEAT_ONETIME;
312 * If the user cancels or quits the popup, we want the
313 * combo box to say "One Time".
314 * NOTE: Changing the menu has the effect of popping
317 XtVaSetValues(rfp->repeat_menu,
318 XmNselectedPosition, ONE_TIME + 1, NULL);
322 ** This, obviously, pops up the repeat every ...
325 rfp_repeat_every_popup(RFP *rfp) {
326 Widget label, apply_button, cancel_button, separator;
328 Calendar *c = rfp->cal;
332 title = XtNewString(catgets(c->DT_catd, 1, 532,
333 "Calendar : Repeat Every"));
334 rfp->repeat_popup_frame = XtVaCreatePopupShell("repeat_popup_frame",
335 xmDialogShellWidgetClass, rfp->parent,
337 XmNallowShellResize, True,
338 XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_CLOSE,
339 XmNdeleteResponse, XmDO_NOTHING,
343 setup_quit_handler(rfp->repeat_popup_frame, rfp_cancel_proc,
346 rfp->repeat_form_mgr = XtVaCreateWidget("form_mgr",
347 xmFormWidgetClass, rfp->repeat_popup_frame,
348 XmNautoUnmanage, False,
349 XmNhorizontalSpacing, 0,
350 XmNverticalSpacing, 5,
354 label_str = XmStringCreateLocalized(catgets(c->DT_catd, 1, 460, "Apply"));
355 rfp->repeat_apply_button = XtVaCreateWidget("repeat_apply_button",
356 xmPushButtonWidgetClass, rfp->repeat_form_mgr,
357 XmNlabelString, label_str,
359 XmNleftAttachment, XmATTACH_POSITION,
361 XmNrightAttachment, XmATTACH_POSITION,
363 XmNbottomAttachment, XmATTACH_FORM,
365 XmStringFree(label_str);
366 XtAddCallback(rfp->repeat_apply_button,
367 XmNactivateCallback, rfp_apply_proc, rfp);
369 label_str = XmStringCreateLocalized(catgets(c->DT_catd, 1, 680, "Close"));
370 rfp->repeat_cancel_button = XtVaCreateWidget("repeat_cancel_button",
371 xmPushButtonWidgetClass, rfp->repeat_form_mgr,
372 XmNlabelString, label_str,
373 XmNleftAttachment, XmATTACH_POSITION,
375 XmNrightAttachment, XmATTACH_POSITION,
378 XmNbottomAttachment, XmATTACH_FORM,
380 XmStringFree(label_str);
381 XtAddCallback(rfp->repeat_cancel_button,
382 XmNactivateCallback, rfp_cancel_proc, rfp);
384 separator = XtVaCreateWidget("separator",
385 xmSeparatorGadgetClass,
386 rfp->repeat_form_mgr,
387 XmNleftAttachment, XmATTACH_FORM,
388 XmNrightAttachment, XmATTACH_FORM,
389 XmNbottomAttachment, XmATTACH_WIDGET,
390 XmNbottomWidget, rfp->repeat_apply_button,
394 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 533,
396 label = XtVaCreateWidget("every",
397 xmLabelGadgetClass, rfp->repeat_form_mgr,
398 XmNlabelString, xmstr,
399 XmNtopAttachment, XmATTACH_FORM,
401 XmNleftAttachment, XmATTACH_FORM,
403 XmNbottomAttachment, XmATTACH_WIDGET,
404 XmNbottomWidget, separator,
408 rfp->repeat_popup_text = XtVaCreateWidget("text_field",
409 xmTextWidgetClass, rfp->repeat_form_mgr,
410 XmNeditMode, XmSINGLE_LINE_EDIT,
412 XmNmaxLength, FOR_LEN - 1,
413 XmNtopAttachment, XmATTACH_FORM,
415 XmNleftAttachment, XmATTACH_WIDGET,
416 XmNleftWidget, label,
418 XmNbottomAttachment, XmATTACH_WIDGET,
419 XmNbottomWidget, separator,
422 rfp->repeat_popup_menu =
423 create_repeat_scope_menu(rfp->repeat_form_mgr, NULL,
424 rfp_repeat_scope_proc, (XtPointer)rfp);
427 XtVaSetValues(rfp->repeat_popup_menu,
428 XmNuserData, REPEAT_DAYS,
429 XmNtopAttachment, XmATTACH_FORM,
431 XmNleftAttachment, XmATTACH_WIDGET,
432 XmNleftWidget, rfp->repeat_popup_text,
434 XmNbottomAttachment, XmATTACH_WIDGET,
435 XmNbottomWidget, separator,
438 XtVaSetValues(rfp->repeat_form_mgr, XmNdefaultButton,
439 rfp->repeat_apply_button, NULL);
440 XtVaSetValues(rfp->repeat_form_mgr, XmNcancelButton,
441 rfp->repeat_cancel_button, NULL);
443 ManageChildren(rfp->repeat_form_mgr);
447 show_repeat_every(XtPointer uData, XtIntervalId *id)
449 RFP *rfp = (RFP *)uData;
451 if (!rfp->repeat_form_mgr)
452 rfp_repeat_every_popup(rfp);
454 XtManageChild(rfp->repeat_form_mgr);
458 hide_repeat_every(XtPointer uData, XtIntervalId *id)
460 RFP *rfp = (RFP *)uData;
462 /* Make sure repeat_every form no longer displayed. */
463 if (rfp->repeat_form_mgr)
464 XtUnmanageChild(rfp->repeat_form_mgr);
468 ** This callback is attached to the repeat menu - it sets the for duration and
469 ** scope fields (actually called for_menu and for_scope)
472 rfp_repeat_menu_proc(Widget w, XtPointer data, XtPointer cbs) {
473 RFP *rfp = (RFP *)data;
474 Repeat_menu_op item_no;
479 XtVaGetValues(rfp->repeat_menu,
480 XmNselectedPosition, &item_no,
485 * We use timeouts to make sure the menu is popped
486 * down before we pop up/down the repeat_every form.
487 * Otherwise, Xt gets confused about grabs.
489 if (item_no == REPEAT_EVERY)
491 XtAppAddTimeOut(XtWidgetToApplicationContext(w),
492 0, show_repeat_every, (XtPointer)rfp);
496 XtAppAddTimeOut(XtWidgetToApplicationContext(w),
497 0, hide_repeat_every, (XtPointer)rfp);
499 rfp_set_default_for(rfp, item_no, item_no ? True : False);
503 /*******************************************************************************
505 ** External functions
507 *******************************************************************************/
515 Dimension max_left_label_width;
516 Dimension freq_label_height;
519 rfp->parent = parent;
522 rfp->rfp_form_mgr = XtVaCreateWidget("rfp_form_mgr",
523 xmFormWidgetClass, rfp->parent,
524 XmNautoUnmanage, False,
528 label_str = XmStringCreateLocalized(catgets(c->DT_catd, 1, 836, "Frequency"));
529 rfp->frequency_label = XtVaCreateWidget("frequency_label",
530 xmLabelGadgetClass, rfp->rfp_form_mgr,
531 XmNlabelString, label_str,
532 XmNtopAttachment, XmATTACH_FORM,
535 XmStringFree(label_str);
537 tmp = XmStringCreateLocalized(catgets(c->DT_catd, 1, 534, "Occurs:"));
538 rfp->repeat_label = XtVaCreateWidget("repeat",
539 xmLabelGadgetClass, rfp->rfp_form_mgr,
540 XmNlabelString, label_str,
545 tmp = XmStringCreateLocalized(catgets(c->DT_catd, 1, 535, "For:"));
546 rfp->for_label = XtVaCreateWidget("for",
547 xmLabelGadgetClass, rfp->rfp_form_mgr,
553 tmp = XmStringCreateLocalized( catgets(c->DT_catd, 1, 536, "Privacy:"));
554 rfp->privacy_label = XtVaCreateWidget("privacy",
555 xmLabelGadgetClass, rfp->rfp_form_mgr,
560 max_left_label_width = ComputeMaxWidth(rfp->frequency_label,
566 XtVaGetValues(rfp->frequency_label,
567 XmNheight, &freq_label_height,
570 rfp->repeat_menu = create_repeat_menu(rfp->rfp_form_mgr,
571 rfp_repeat_menu_proc, (XtPointer)rfp);
573 rfp_set_repeat_values(rfp);
574 XtVaSetValues(rfp->repeat_menu,
575 XmNuserData, ONE_TIME,
576 XmNleftAttachment, XmATTACH_FORM,
577 XmNleftOffset, max_left_label_width,
578 XmNtopAttachment, XmATTACH_FORM,
579 XmNtopOffset, freq_label_height + 3 * GAP,
581 tmp = XmStringCreateLocalized("\0");
583 rfp->for_menu = create_for_menu(rfp->rfp_form_mgr);
584 XtVaSetValues(rfp->for_menu,
585 XmNleftAttachment, XmATTACH_FORM,
586 XmNleftOffset, max_left_label_width,
587 XmNtopAttachment, XmATTACH_WIDGET,
588 XmNtopWidget, rfp->repeat_menu,
589 XmNtopOffset, 2 * GAP,
592 rfp->for_scope = XtVaCreateWidget("for_scope",
593 xmLabelGadgetClass, rfp->rfp_form_mgr,
595 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
596 XmNbottomWidget, rfp->for_label,
597 XmNleftAttachment, XmATTACH_WIDGET,
598 XmNleftWidget, rfp->for_menu,
604 rfp->privacy_menu = create_privacy_menu(rfp->rfp_form_mgr);
605 XtVaSetValues(rfp->privacy_menu,
606 XmNleftAttachment, XmATTACH_FORM,
607 XmNleftOffset, max_left_label_width,
608 XmNtopAttachment, XmATTACH_WIDGET,
609 XmNtopWidget, rfp->for_menu,
610 XmNtopOffset, 2 * GAP,
613 XtVaSetValues(rfp->frequency_label,
614 XmNrightAttachment, XmATTACH_WIDGET,
615 XmNrightWidget, rfp->repeat_menu,
619 XtVaSetValues(rfp->repeat_label,
620 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
621 XmNbottomWidget, rfp->repeat_menu,
622 XmNbottomOffset, GAP,
623 XmNrightAttachment, XmATTACH_WIDGET,
624 XmNrightWidget, rfp->repeat_menu,
628 XtVaSetValues(rfp->for_label,
629 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
630 XmNbottomWidget, rfp->for_menu,
631 XmNbottomOffset, GAP,
632 XmNrightAttachment, XmATTACH_WIDGET,
633 XmNrightWidget, rfp->for_menu,
637 XtVaSetValues(rfp->privacy_label,
638 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
639 XmNbottomWidget, rfp->privacy_menu,
640 XmNbottomOffset, GAP,
641 XmNrightAttachment, XmATTACH_WIDGET,
642 XmNrightWidget, rfp->privacy_menu,
648 ** Get and set values on the screen
662 /* clear the buffers */
663 memset (rule_buf1, 0, 32);
664 memset (rule_buf2, 0, 32);
666 /* This routine has to set up the recurrence values in two spots.
667 It has to set up the old style recurrence values for a daemon
668 in data versions 1-3, and it has to set up a recurrence rule for a
669 data version 4 daemon. */
672 ** First, get the value on the repeat menu
674 XtVaGetValues(rfp->repeat_menu, XmNselectedPosition, &op, NULL);
679 rfp->repeat_type = CSA_X_DT_REPEAT_ONETIME;
680 strcpy(rule_buf1, "D1 ");
683 rfp->repeat_type = CSA_X_DT_REPEAT_DAILY;
684 strcpy(rule_buf1, "D1 ");
687 rfp->repeat_type = CSA_X_DT_REPEAT_WEEKLY;
688 strcpy(rule_buf1, "W1 ");
690 case EVERY_TWO_WEEKS:
691 rfp->repeat_type = CSA_X_DT_REPEAT_BIWEEKLY;
692 strcpy(rule_buf1, "W2 ");
694 case MONTHLY_BY_DATE:
695 rfp->repeat_type = CSA_X_DT_REPEAT_MONTHLY_BY_DATE;
696 strcpy(rule_buf1, "MD1 ");
698 case MONTHLY_BY_WEEKDAY: {
701 rfp->repeat_type = CSA_X_DT_REPEAT_MONTHLY_BY_WEEKDAY;
703 * The current behavior of cm/dtcm is that if an appt is
704 * scheduled for the 5 wk of the month, it repeats on the
705 * last week of the month.
707 if (weekofmonth(tick, &wk) && wk == 5)
708 sprintf(rule_buf1, "MP1 1- %s ", dow_str(tick));
710 strcpy(rule_buf1, "MP1 ");
714 rfp->repeat_type = CSA_X_DT_REPEAT_YEARLY;
715 strcpy(rule_buf1, "YM1 ");
717 case MONDAY_THRU_FRIDAY:
718 rfp->repeat_type = CSA_X_DT_REPEAT_MON_TO_FRI;
719 strcpy(rule_buf1, "W1 MO TU WE TH FR ");
722 rfp->repeat_type = CSA_X_DT_REPEAT_MONWEDFRI;
723 strcpy(rule_buf1, "W1 MO WE FR ");
725 case TUESDAY_THURSDAY:
726 rfp->repeat_type = CSA_X_DT_REPEAT_TUETHUR;
727 strcpy(rule_buf1, "W1 TU TH ");
730 /* REPEAT_EVERY is handled in rfp_apply_proc() */
731 switch(rfp->repeat_type) {
732 case CSA_X_DT_REPEAT_EVERY_NDAY:
733 sprintf(rule_buf1, "D%d ", rfp->repeat_nth);
735 case CSA_X_DT_REPEAT_EVERY_NWEEK:
736 sprintf(rule_buf1, "W%d ", rfp->repeat_nth);
738 case CSA_X_DT_REPEAT_EVERY_NMONTH:
740 sprintf(rule_buf1, "MD%d ", rfp->repeat_nth);
748 if (op != REPEAT_EVERY)
752 ** Now get the duration - the for menu and scope.
754 XtVaGetValues(rfp->for_menu,
758 XmNsensitive, &sensitive,
762 char *forever_str = catgets(calendar->DT_catd, 1, 876,
764 str = XmTextGetString(tf);
765 if (strcmp(str, forever_str) == 0) {
766 rfp->for_val = PRIVATE_FOREVER;
767 strcat(rule_buf2, "#0");
769 rfp->for_val = atoi(str);
770 if (rfp->for_val == 0)
771 strcat(rule_buf2, "#1");
773 if (op != REPEAT_EVERY) {
774 sprintf(rule_buf2, "#%d", rfp->for_val);
778 if (rfp->for_val % rfp->repeat_nth)
780 rfp->for_val/rfp->repeat_nth;
783 rfp->for_val/rfp->repeat_nth;
785 sprintf(rule_buf2, "#%d", duration);
791 strcat(rule_buf2, "#1");
796 strcat (rule_buf1, rule_buf2);
798 if (rfp->recurrence_rule)
799 free(rfp->recurrence_rule);
801 rfp->recurrence_rule = cm_strdup(rule_buf1);
805 get_rfp_privacy_val(RFP *rfp) {
808 XtVaGetValues(rfp->privacy_menu, XmNselectedPosition, &i, NULL);
813 case 0: rfp->privacy_val = CSA_CLASS_PUBLIC;
816 case 1: rfp->privacy_val = CSA_CLASS_CONFIDENTIAL;
819 case 2: rfp->privacy_val = CSA_CLASS_PRIVATE;
826 get_rfp_vals(RFP *rfp, time_t tick) {
827 get_rfp_repeat_val(rfp, tick);
828 get_rfp_privacy_val(rfp);
832 ** This function will consume form values and stuff them into an appointment.
835 rfp_form_to_appt(RFP *rfp, Dtcm_appointment *a, char *name)
837 return rfp_form_flags_to_appt(rfp, a, name, (int *)NULL);
841 rfp_form_flags_to_appt(RFP *rfp, Dtcm_appointment *a, char *name, int *flagsP)
844 char buf[MAXNAMELEN];
846 Calendar *c = rfp->cal;
847 Props_pu *p = (Props_pu *)rfp->cal->properties_pu;
850 if (flagsP == (int *)NULL)
853 _csa_iso8601_to_tick(a->time->value->item.date_time_value, &tick);
855 if (rfp->rfp_form_mgr)
856 get_rfp_vals(rfp, tick);
858 a->private->value->item.sint32_value = rfp->privacy_val;
860 if (a->version < DATAVER4) {
861 a->repeat_type->value->item.sint32_value = rfp->repeat_type;
862 a->repeat_times->value->item.uint32_value = rfp->for_val == PRIVATE_FOREVER ? CSA_X_DT_DT_REPEAT_FOREVER : rfp->for_val;
864 if ((a->version == DATAVER3) ||(a->version == DATAVER_ARCHIVE)) {
865 if (a->repeat_interval)
866 a->repeat_interval->value->item.uint32_value =
868 if (a->repeat_week_num)
869 a->repeat_week_num->value->item.sint32_value =
874 a->recurrence_rule->value->item.string_value =
875 cm_strdup(rfp->recurrence_rule);
877 if (rfp->repeat_type != CSA_X_DT_REPEAT_ONETIME) {
878 if (rfp->for_val == 0) {
879 editor_err_msg(rfp->parent, name, REPEAT_FOR_MISMATCH,
883 if (rfp->repeat_type == CSA_X_DT_REPEAT_MONTHLY_BY_WEEKDAY) {
884 if (weekofmonth(tick, &wk) && wk == 4)
888 char *title = XtNewString(catgets(c->DT_catd, 1, 537,
889 "Calendar : Editor - Schedule Appointment"));
890 char *text = XtNewString(catgets(c->DT_catd, 1, 538,
891 "Would you like to schedule this appointment as the last\nweek of the month or the 4th week of the month?"));
892 char *ident1 = XtNewString(catgets(c->DT_catd, 1,
894 char *ident2 = XtNewString(catgets(c->DT_catd, 1,
896 char *ident3 = XtNewString(catgets(c->DT_catd, 1,
898 *flagsP = dialog_popup(rfp->parent,
901 BUTTON_IDENT, -1, ident1,
902 BUTTON_IDENT, RFP_MBW_LAST, ident2,
903 BUTTON_IDENT, RFP_MBW_4TH, ident3,
904 DIALOG_IMAGE, p->xm_question_pixmap,
915 change_to_last_week(a, wk, tick, rfp);
919 if (a->version < DATAVER4)
920 a->repeat_week_num->value->item.sint32_value = wk;
928 if (a->version < DATAVER4)
929 a->repeat_week_num->value->item.sint32_value = wk;
933 if (a->repeat_type == NULL) {
934 if ((a->repeat_type =
935 (CSA_attribute *)ckalloc(sizeof(CSA_attribute)))
937 /* return (CSA_E_INSUFFICIENT_MEMORY); */
940 memset(a->repeat_type, 0, sizeof(CSA_attribute));
942 _DtCm_set_sint32_attrval(rfp->repeat_type,
943 &a->repeat_type->value);
945 else a->repeat_type->value->item.sint32_value = rfp->repeat_type;
950 if (a->repeat_type == NULL) {
951 if ((a->repeat_type =
952 (CSA_attribute *)ckalloc(sizeof(CSA_attribute)))
954 /* return (CSA_E_INSUFFICIENT_MEMORY); */
957 memset(a->repeat_type, 0, sizeof(CSA_attribute));
959 _DtCm_set_sint32_attrval(rfp->repeat_type,&a->repeat_type->value);
961 else a->repeat_type->value->item.sint32_value = rfp->repeat_type;
968 * Given a rule, change it to always happen on the last week of the month.
977 if (a->version < DATAVER4)
980 char *weekday = dow_str(tick),
984 memset(duration_buf, 0, 10);
986 /* The new rule uses a little more memory than the old */
987 new_rule = (char *)calloc(1,
988 strlen(a->recurrence_rule->value->item.string_value) + 8);
990 /* Free the old rule */
991 free(a->recurrence_rule->value->item.string_value);
993 sprintf(new_rule, "MP1 1- %s", weekday);
994 if (rfp->for_val == PRIVATE_FOREVER)
995 strcat(new_rule, " #0");
996 else if (rfp->for_val == 0)
997 strcat(new_rule, " #1");
999 sprintf(duration_buf, " #%d", rfp->for_val);
1000 strcat(new_rule, duration_buf);
1003 a->recurrence_rule->value->item.string_value = new_rule;
1010 ** This function will take appointment values and stuff them into a form.
1013 rfp_appt_to_form(RFP *rfp, CSA_entry_handle entry) {
1015 CSA_return_code stat;
1016 Dtcm_appointment *appt;
1018 appt = allocate_appt_struct(appt_read,
1019 rfp->cal->general->version,
1020 CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I,
1021 CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I,
1022 CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I,
1023 CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I,
1024 CSA_ENTRY_ATTR_CLASSIFICATION_I,
1025 CSA_ENTRY_ATTR_RECURRENCE_RULE_I,
1027 stat = query_appt_struct(rfp->cal->cal_handle, entry, appt);
1028 backend_err_msg(rfp->cal->frame, rfp->cal->view->current_calendar,
1029 stat, ((Props_pu *)rfp->cal->properties_pu)->xm_error_pixmap);
1030 if (stat != CSA_SUCCESS) {
1031 free_appt_struct(&appt);
1035 ret_val = rfp_attrs_to_form(rfp, appt);
1036 free_appt_struct(&appt);
1042 rfp_attrs_to_form(RFP *rfp, Dtcm_appointment *appt) {
1044 /* At this point, check out the returning reminder values. If
1045 the old style reminder values are not set, we must have a client
1046 that either wrote out the appointment with no reminders, or with
1047 a recurrence rule set that will not map into what wee currently
1048 understand. We should inactivate the rfp fields, and not set
1049 any values. On the other hand, if they are set, we should
1050 make sure the controls are made sensitive. */
1052 if (appt->repeat_type && appt->repeat_type->value) {
1053 rfp_toggle_repeat_grey(rfp, True);
1054 rfp->repeat_type = appt->repeat_type->value->item.sint32_value;
1055 if (appt->version > DATAVER2) {
1056 rfp->repeat_nth = (appt->repeat_interval) ?
1057 appt->repeat_interval->value->item.uint32_value : 0;
1059 if (appt->repeat_times && appt->repeat_times->value)
1060 rfp->for_val = appt->repeat_times->value->item.uint32_value;
1064 rfp->privacy_val = privacy_set(appt);
1068 rfp_toggle_for_grey(rfp, False);
1069 rfp_toggle_repeat_grey(rfp, False);
1076 set_rfp_repeat_val(RFP *rfp) {
1078 Boolean status = True;
1080 Calendar *c = rfp->cal;
1081 const char *repeat_scope;
1085 ** Set the repeat menu button based on the period value
1088 if (rfp->repeat_type == CSA_X_DT_REPEAT_ONETIME) {
1090 repeat_scope = default_repeat_scope_str(c->DT_catd, ONE_TIME);
1091 sprintf(buf, "%s", repeat_str(c->DT_catd, ONE_TIME));
1093 } else if (rfp->repeat_type == CSA_X_DT_REPEAT_DAILY) {
1095 repeat_scope = default_repeat_scope_str(c->DT_catd, DAILY);
1096 sprintf(buf, "%s", repeat_str(c->DT_catd, DAILY));
1097 } else if (rfp->repeat_type == CSA_X_DT_REPEAT_WEEKLY) {
1099 repeat_scope = default_repeat_scope_str(c->DT_catd, WEEKLY);
1100 sprintf(buf, "%s", repeat_str(c->DT_catd, WEEKLY));
1101 } else if (rfp->repeat_type == CSA_X_DT_REPEAT_BIWEEKLY) {
1102 op = EVERY_TWO_WEEKS;
1104 default_repeat_scope_str(c->DT_catd, EVERY_TWO_WEEKS);
1105 sprintf(buf, "%s", repeat_str(c->DT_catd, EVERY_TWO_WEEKS));
1106 } else if (rfp->repeat_type == CSA_X_DT_REPEAT_MONTHLY_BY_DATE) {
1107 op = MONTHLY_BY_DATE;
1109 default_repeat_scope_str(c->DT_catd, MONTHLY_BY_DATE);
1110 sprintf(buf, "%s", repeat_str(c->DT_catd, MONTHLY_BY_DATE));
1111 } else if (rfp->repeat_type ==
1112 CSA_X_DT_REPEAT_MONTHLY_BY_WEEKDAY) {
1113 op = MONTHLY_BY_WEEKDAY;
1114 repeat_scope = default_repeat_scope_str(c->DT_catd,
1115 MONTHLY_BY_WEEKDAY);
1116 sprintf(buf, "%s", repeat_str(c->DT_catd, MONTHLY_BY_WEEKDAY));
1117 } else if (rfp->repeat_type == CSA_X_DT_REPEAT_YEARLY) {
1119 repeat_scope = default_repeat_scope_str(c->DT_catd, YEARLY);
1120 sprintf(buf, "%s", repeat_str(c->DT_catd, YEARLY));
1121 } else if (rfp->repeat_type == CSA_X_DT_REPEAT_MON_TO_FRI) {
1122 op = MONDAY_THRU_FRIDAY;
1123 repeat_scope = default_repeat_scope_str(c->DT_catd,
1124 MONDAY_THRU_FRIDAY);
1125 sprintf(buf, "%s", repeat_str(c->DT_catd, MONDAY_THRU_FRIDAY));
1126 } else if (rfp->repeat_type == CSA_X_DT_REPEAT_MONWEDFRI) {
1129 default_repeat_scope_str(c->DT_catd, MON_WED_FRI);
1130 sprintf(buf, "%s", repeat_str(c->DT_catd, MON_WED_FRI));
1131 } else if (rfp->repeat_type == CSA_X_DT_REPEAT_TUETHUR) {
1132 op = TUESDAY_THURSDAY;
1134 default_repeat_scope_str(c->DT_catd, TUESDAY_THURSDAY);
1135 sprintf(buf, "%s", repeat_str(c->DT_catd, TUESDAY_THURSDAY));
1136 } else if (rfp->repeat_type == CSA_X_DT_REPEAT_EVERY_NDAY) {
1138 repeat_scope = repeat_scope_str(c->DT_catd, REPEAT_DAYS);
1139 sprintf(buf, catgets(c->DT_catd, 1, 542, "Every %d %s"),
1140 rfp->repeat_nth, repeat_scope);
1141 } else if (rfp->repeat_type == CSA_X_DT_REPEAT_EVERY_NWEEK) {
1143 repeat_scope = repeat_scope_str(c->DT_catd, REPEAT_WEEKS);
1144 sprintf(buf, catgets(c->DT_catd, 1, 543, "Every %d %s"),
1145 rfp->repeat_nth, repeat_scope);
1146 } else if (rfp->repeat_type == CSA_X_DT_REPEAT_EVERY_NMONTH) {
1148 repeat_scope = repeat_scope_str(c->DT_catd, REPEAT_MONTHS);
1149 sprintf(buf, catgets(c->DT_catd, 1, 544, "Every %d %s"),
1150 rfp->repeat_nth, repeat_scope);
1155 * Set the Repeat combo box
1157 xmstr = XmStringCreateLocalized(buf);
1158 XtVaSetValues(rfp->repeat_menu, XmNselectedPosition, op + 1, NULL);
1159 XtVaSetValues(rfp->repeat_menu, XmNlabelString, xmstr, NULL);
1160 XmStringFree(xmstr);
1163 ** Set the For button, text item, and scope
1165 if (rfp->for_val == CSA_X_DT_DT_REPEAT_FOREVER) {
1166 if(rfp->repeat_type != CSA_X_DT_REPEAT_ONETIME)
1168 sprintf(buf, "%s", catgets(c->DT_catd, 1, 876, "forever"));
1169 xmstr = XmStringCreateLocalized(buf);
1170 XmComboBoxSetItem(rfp->for_menu, xmstr);
1171 XmStringFree(xmstr);
1177 XtVaGetValues(rfp->for_menu, XmNtextField,
1179 XmTextFieldSetString(text, buf);
1181 repeat_scope = "\0";
1182 } else if (rfp->for_val >= 2 && rfp->for_val <= 14) {
1183 sprintf(buf, "%s", for_str(rfp->for_val - 2));
1184 xmstr = XmStringCreateLocalized(buf);
1185 XmComboBoxSetItem(rfp->for_menu, xmstr);
1186 XmStringFree(xmstr);
1189 sprintf(buf, "%d", rfp->for_val);
1190 XtVaGetValues(rfp->for_menu, XmNtextField, &text, NULL);
1191 XmTextFieldSetString(text, buf);
1194 xmstr = XmStringCreateLocalized((char *)repeat_scope);
1195 XtVaSetValues(rfp->for_scope, XmNlabelString, xmstr,
1197 XmStringFree(xmstr);
1199 rfp_toggle_for_grey(rfp, status);
1203 set_rfp_privacy_val(RFP *rfp) {
1206 if (rfp->privacy_val == CSA_CLASS_PUBLIC)
1208 else if (rfp->privacy_val == CSA_CLASS_CONFIDENTIAL)
1213 XtVaSetValues(rfp->privacy_menu, XmNselectedPosition, i + 1, NULL);
1217 set_rfp_vals(RFP *rfp) {
1218 set_rfp_repeat_val(rfp);
1219 set_rfp_privacy_val(rfp);
1223 set_rfp_defaults(RFP *rfp) {
1224 Props *p = (Props *)rfp->cal->properties;
1227 rfp->privacy_val = convert_privacy_str(get_char_prop(p, CP_PRIVACY));
1228 rfp->repeat_type = CSA_X_DT_REPEAT_ONETIME;
1231 rfp_set_default_for(rfp, ONE_TIME, False);
1238 switch (dow(tick)) {
1240 return (cm_strdup("SU"));
1242 return (cm_strdup("MO"));
1244 return (cm_strdup("TU"));
1246 return (cm_strdup("WE"));
1248 return (cm_strdup("TH"));
1250 return (cm_strdup("FR"));
1253 return (cm_strdup("SA"));
1263 Props *p = (Props *)c->properties;
1265 rfp->parent = parent;
1268 rfp->privacy_val = convert_privacy_str(get_char_prop(p, CP_PRIVACY));
1269 rfp->repeat_type = CSA_X_DT_REPEAT_ONETIME;
1270 rfp->recurrence_rule = strdup("D1 #1");