dtcm: Resolve CID 87562
[oweals/cde.git] / cde / programs / dtcm / dtcm / rfp.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: rfp.c /main/10 1996/10/14 16:07:07 barstow $ */
24 /*
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.
29  */
30
31 #include <EUSCompat.h>
32 #include <stdlib.h>
33 #include <ctype.h>
34 #include <Xm/Xm.h>
35 #include <Xm/DialogS.h>
36 #include <Xm/Form.h>
37 #include <Xm/LabelG.h>
38 #include <Xm/RowColumn.h>
39 #include <Xm/Text.h>
40 #include <Xm/TextF.h>
41 #include <Xm/SeparatoG.h>
42 #include <Xm/PushB.h>
43 #include <Xm/MwmUtil.h>
44 #include <Xm/ComboBox.h>
45 #include "util.h"
46 #include "timeops.h"
47 #include "misc.h"
48 #include "rfp.h"
49 #include "props_pu.h"
50 #ifdef SVR4
51 #include <sys/param.h>
52 #endif /* SVR4 */
53
54 #define PRIVATE_FOREVER -9999999
55 #define GAP 5
56
57 extern Dimension ComputeMaxWidth(Widget, Widget, Widget, Widget);
58
59 static char *dow_str(time_t);
60 static void change_to_last_week(Dtcm_appointment *, int, time_t, RFP *);
61
62 /*******************************************************************************
63 **
64 **  Static functions visibile to rfp.c only
65 **
66 *******************************************************************************/
67 /*
68 **  Set the necessary for stuff grey/ungrey
69 */
70 static void
71 rfp_toggle_for_grey(RFP *rfp, Boolean status) {
72         Widget  list, text;
73
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);
79 }
80
81 static void
82 rfp_toggle_repeat_grey(RFP *rfp, Boolean status) {
83         Widget  list;
84
85         XtVaSetValues(rfp->repeat_label, XmNsensitive, status, NULL);
86         XtVaGetValues(rfp->repeat_menu, XmNlist, &list, NULL);
87         XtVaSetValues(list, XmNsensitive, status, NULL);
88 }
89
90
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. */
94
95 extern void
96 rfp_set_repeat_values(RFP *rfp)
97
98 {
99         int             i, limit;
100         XmString        xmstr;
101         Widget          list;
102
103         /* delete all the old items. */
104
105         XtVaGetValues(rfp->repeat_menu, XmNlist, &list, NULL);
106         XtVaGetValues(list, XmNitemCount, &limit, NULL);
107
108         if ((limit == 11) && (rfp->cal->general->version >= DATAVER3))
109                 return;
110
111         if ((limit == 10) && (rfp->cal->general->version == DATAVER2))
112                 return;
113
114         if ((limit == 7) && (rfp->cal->general->version == DATAVER1))
115                 return;
116
117
118         if (limit == 11) {
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);
124                 }
125                 if (rfp->repeat_popup_frame)
126                   XtUnmanageChild(rfp->repeat_form_mgr);
127                 return;
128         }
129         else if (limit == 10) {
130                 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 901, "Repeat Every ..."));
131                 XmComboBoxAddItem(rfp->repeat_menu, xmstr, 0, False);
132                 XmStringFree(xmstr);
133
134         }
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);
138                 XmStringFree(xmstr);
139          
140                 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 903, "Mon, Wed, Fri"));
141                 XmComboBoxAddItem(rfp->repeat_menu, xmstr, 0, False);
142                 XmStringFree(xmstr);
143                 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 861, "Tuesday, Thursday"));
144                 XmComboBoxAddItem(rfp->repeat_menu, xmstr, 0, False);
145                 XmStringFree(xmstr);
146
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);
150                         XmStringFree(xmstr);
151                 }
152
153         }
154 }
155
156 /*
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
159 */
160 static void
161 rfp_set_default_for(RFP *rfp, Repeat_menu_op op, Boolean status) {
162         Widget          text;
163         XmString        new_scope_str;
164         Calendar        *c = rfp->cal;
165
166         XtVaGetValues(rfp->for_menu, XmNtextField, &text, NULL);
167         XmTextFieldSetString(text, default_repeat_cnt_str(op));
168
169         new_scope_str = XmStringCreateLocalized(
170                                 default_repeat_scope_str(c->DT_catd, op));
171         XtVaSetValues(rfp->for_scope, XmNlabelString, new_scope_str,
172                 NULL);
173         XmStringFree(new_scope_str);
174
175         rfp_toggle_for_grey(rfp, status);
176 }
177
178 /*
179 **  Callbacks for the repeat every popup
180 */
181 static void
182 rfp_repeat_scope_proc(Widget w, XtPointer client_data, XtPointer cbs) {
183         RFP                     *rfp = (RFP *)client_data;
184         Repeat_scope_menu_op    op;
185
186         if (!rfp)
187                 return;
188
189         XtVaGetValues(w, XmNuserData, &op, NULL);
190         XtVaSetValues(rfp->repeat_popup_menu, XmNuserData, op, NULL);
191 }
192
193 static Boolean
194 string_is_number(char *str) {
195  
196  
197         if (blank_buf(str)) {
198                 return(False);
199         }
200  
201         while (str && *str) {
202                 if (!isdigit(*str) && *str != ' ' && *str != '\t')
203                         return(False);
204  
205                 str++;
206         }
207  
208         return(True);
209 }
210
211 static void
212 rfp_apply_proc(Widget w, XtPointer client_data, XtPointer cbs) {
213         RFP                     *rfp = (RFP *)client_data;
214         char                    *str, buf[128];
215         XmString                xmstr;
216         Calendar                *c = rfp->cal;
217         Props_pu                *pu = (Props_pu *)c->properties_pu;
218         Repeat_scope_menu_op    op = REPEAT_DAYS;
219         char                    *repeat_str;
220
221         if (!rfp)
222                 return;
223
224         str = XmTextGetString(rfp->repeat_popup_text);
225
226         if (!string_is_number(str)) {
227                 char *title = XtNewString(catgets(c->DT_catd, 1, 969, "Calendar : Error - Repeat Every"));
228                 char *text = XtNewString(catgets(c->DT_catd, 1, 970, "The Repeat Every value must be an integer with no sign."));
229                 char *ident1 = XtNewString(catgets(c->DT_catd, 1, 95, "Continue"));
230
231                 XtFree(str);
232                 dialog_popup(c->frame,
233                         DIALOG_TITLE, title,
234                         DIALOG_TEXT, text,
235                         BUTTON_IDENT, 1, ident1,
236                         DIALOG_IMAGE, pu->xm_error_pixmap,
237                         NULL);
238                 XtFree(ident1);
239                 XtFree(text);
240                 XtFree(title);
241                 return;
242         }
243
244         rfp->repeat_nth = atoi(str);
245         XtFree(str);
246         if (rfp->repeat_nth == 0) {
247           XtUnmanageChild(rfp->repeat_form_mgr);
248           return;
249         }
250
251         /*
252          * Change the string to be more informative.
253          */
254         XtVaGetValues(rfp->repeat_popup_menu, XmNuserData, &op, NULL);
255
256         switch (op) {
257
258         case REPEAT_DAYS: repeat_str = catgets(c->DT_catd, 1, 825, "Days");
259                                 break;
260
261         case REPEAT_WEEKS: repeat_str = catgets(c->DT_catd, 1, 826, "Weeks");
262                                 break;
263
264         case REPEAT_MONTHS: repeat_str = catgets(c->DT_catd, 1, 827, "Months");
265                                 break;
266         }
267
268         /*
269          * Now change the text field
270          */
271         {
272           char *nl_repeat = XtNewString(repeat_str);
273           sprintf(buf, catgets(c->DT_catd, 1, 531, "Every %d %s"),
274                   rfp->repeat_nth, nl_repeat);
275           XtFree(nl_repeat);
276         }
277
278         xmstr = XmStringCreateLocalized(buf);
279         XtVaSetValues(rfp->repeat_menu, XmNlabelString, xmstr, NULL);
280         XmStringFree(xmstr);
281
282         switch(op) {
283         case REPEAT_DAYS:
284                 rfp->repeat_type = CSA_X_DT_REPEAT_EVERY_NDAY;
285                 rfp_set_default_for(rfp, DAILY, True);
286                 break;
287         case REPEAT_WEEKS:
288                 rfp->repeat_type = CSA_X_DT_REPEAT_EVERY_NWEEK;
289                 rfp_set_default_for(rfp, WEEKLY, True);
290                 break;
291         case REPEAT_MONTHS:
292         default:
293                 rfp->repeat_type = CSA_X_DT_REPEAT_EVERY_NMONTH;
294                 rfp_set_default_for(rfp, MONTHLY_BY_DATE, True);
295                 break;
296         }
297
298         XtUnmanageChild(rfp->repeat_form_mgr);
299 }
300
301 static void
302 rfp_cancel_proc(Widget w, XtPointer client_data, XtPointer cbs) {
303         RFP     *rfp = (RFP *)client_data;
304
305         rfp->repeat_nth = 0;
306         rfp->repeat_type = CSA_X_DT_REPEAT_ONETIME;
307
308         /*
309          * If the user cancels or quits the popup, we want the
310          * combo box to say "One Time".
311          * NOTE: Changing the menu has the effect of popping
312          * down the popup.
313          */
314         XtVaSetValues(rfp->repeat_menu,
315                       XmNselectedPosition, ONE_TIME + 1, NULL);
316 }
317
318 /*
319 **  This, obviously, pops up the repeat every ...
320 */
321 static void
322 rfp_repeat_every_popup(RFP *rfp) {
323         Widget          label, apply_button, cancel_button, separator;
324         XmString        xmstr;
325         Calendar        *c = rfp->cal;
326         char            *title;
327         XmString        label_str;
328
329         title = XtNewString(catgets(c->DT_catd, 1, 532,
330                                     "Calendar : Repeat Every"));
331         rfp->repeat_popup_frame = XtVaCreatePopupShell("repeat_popup_frame",
332                 xmDialogShellWidgetClass, rfp->parent,
333                 XmNtitle, title,
334                 XmNallowShellResize, True,
335                 XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_CLOSE,
336                 XmNdeleteResponse, XmDO_NOTHING,
337                 NULL);
338         XtFree(title);
339
340         setup_quit_handler(rfp->repeat_popup_frame, rfp_cancel_proc,
341                            (XtPointer)rfp);
342
343         rfp->repeat_form_mgr = XtVaCreateWidget("form_mgr",
344                 xmFormWidgetClass, rfp->repeat_popup_frame,
345                 XmNautoUnmanage, False,
346                 XmNhorizontalSpacing, 0,
347                 XmNverticalSpacing, 5,
348                 XmNfractionBase, 2,
349                 NULL);
350
351         label_str = XmStringCreateLocalized(catgets(c->DT_catd, 1, 460, "Apply"));
352         rfp->repeat_apply_button = XtVaCreateWidget("repeat_apply_button",
353                 xmPushButtonWidgetClass, rfp->repeat_form_mgr,
354                 XmNlabelString, label_str,
355                 XmNleftOffset, 10,
356                 XmNleftAttachment, XmATTACH_POSITION,
357                 XmNleftPosition, 0,
358                 XmNrightAttachment, XmATTACH_POSITION,
359                 XmNrightPosition, 1,
360                 XmNbottomAttachment, XmATTACH_FORM,
361                 NULL);
362         XmStringFree(label_str);
363         XtAddCallback(rfp->repeat_apply_button, 
364                         XmNactivateCallback, rfp_apply_proc, rfp);
365  
366         label_str = XmStringCreateLocalized(catgets(c->DT_catd, 1, 680, "Close"));
367         rfp->repeat_cancel_button = XtVaCreateWidget("repeat_cancel_button",
368                 xmPushButtonWidgetClass, rfp->repeat_form_mgr,
369                 XmNlabelString, label_str,
370                 XmNleftAttachment, XmATTACH_POSITION,
371                 XmNleftPosition, 1,
372                 XmNrightAttachment, XmATTACH_POSITION,
373                 XmNrightPosition, 2,
374                 XmNrightOffset, 10,
375                 XmNbottomAttachment, XmATTACH_FORM,
376                 NULL);
377         XmStringFree(label_str);
378         XtAddCallback(rfp->repeat_cancel_button, 
379                         XmNactivateCallback, rfp_cancel_proc, rfp);
380
381         separator = XtVaCreateWidget("separator",
382                 xmSeparatorGadgetClass,
383                 rfp->repeat_form_mgr,
384                 XmNleftAttachment,      XmATTACH_FORM,
385                 XmNrightAttachment,     XmATTACH_FORM,
386                 XmNbottomAttachment,    XmATTACH_WIDGET,
387                 XmNbottomWidget,        rfp->repeat_apply_button,
388                 XmNbottomOffset,        5,
389                 NULL);
390
391         xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 533,
392                                                 "Repeat Every:"));
393         label = XtVaCreateWidget("every",
394                 xmLabelGadgetClass, rfp->repeat_form_mgr,
395                 XmNlabelString, xmstr,
396                 XmNtopAttachment, XmATTACH_FORM,
397                 XmNtopOffset, 10,
398                 XmNleftAttachment, XmATTACH_FORM,
399                 XmNleftOffset, 5,
400                 XmNbottomAttachment, XmATTACH_WIDGET,
401                 XmNbottomWidget, separator,
402                 NULL);
403         XmStringFree(xmstr);
404
405         rfp->repeat_popup_text = XtVaCreateWidget("text_field",
406                 xmTextWidgetClass, rfp->repeat_form_mgr,
407                 XmNeditMode, XmSINGLE_LINE_EDIT,
408                 XmNcolumns, FOR_LEN,
409                 XmNmaxLength, FOR_LEN - 1,
410                 XmNtopAttachment, XmATTACH_FORM,
411                 XmNtopOffset, 10,
412                 XmNleftAttachment, XmATTACH_WIDGET,
413                 XmNleftWidget, label,
414                 XmNleftOffset, 5,
415                 XmNbottomAttachment, XmATTACH_WIDGET,
416                 XmNbottomWidget, separator,
417                 NULL);
418  
419         rfp->repeat_popup_menu = 
420                 create_repeat_scope_menu(rfp->repeat_form_mgr, NULL,
421                                          rfp_repeat_scope_proc, (XtPointer)rfp);
422
423
424         XtVaSetValues(rfp->repeat_popup_menu,
425                 XmNuserData, REPEAT_DAYS,
426                 XmNtopAttachment, XmATTACH_FORM,
427                 XmNtopOffset, 6,
428                 XmNleftAttachment, XmATTACH_WIDGET,
429                 XmNleftWidget, rfp->repeat_popup_text,
430                 XmNleftOffset, 5,
431                 XmNbottomAttachment, XmATTACH_WIDGET,
432                 XmNbottomWidget, separator,
433                 NULL);
434
435         XtVaSetValues(rfp->repeat_form_mgr, XmNdefaultButton,
436                       rfp->repeat_apply_button, NULL);
437         XtVaSetValues(rfp->repeat_form_mgr, XmNcancelButton,
438                       rfp->repeat_cancel_button, NULL);
439
440         ManageChildren(rfp->repeat_form_mgr);
441 }
442
443 static void
444 show_repeat_every(XtPointer uData, XtIntervalId *id)
445 {
446   RFP *rfp = (RFP *)uData;
447
448   if (!rfp->repeat_form_mgr)
449     rfp_repeat_every_popup(rfp);
450
451   XtManageChild(rfp->repeat_form_mgr);
452 }
453
454 static void
455 hide_repeat_every(XtPointer uData, XtIntervalId *id)
456 {
457   RFP *rfp = (RFP *)uData;
458
459   /* Make sure repeat_every form no longer displayed. */
460   if (rfp->repeat_form_mgr)
461     XtUnmanageChild(rfp->repeat_form_mgr);
462 }
463
464 /*
465 **  This callback is attached to the repeat menu - it sets the for duration and
466 **  scope fields (actually called for_menu and for_scope)
467 */
468 static void
469 rfp_repeat_menu_proc(Widget w, XtPointer data, XtPointer cbs) {
470         RFP                     *rfp = (RFP *)data;
471         Repeat_menu_op          item_no;
472
473         if (!rfp)
474                 return;
475
476         XtVaGetValues(rfp->repeat_menu,
477                       XmNselectedPosition, &item_no,
478                       NULL);
479         --item_no;
480
481         /*
482          * We use timeouts to make sure the menu is popped
483          * down before we pop up/down the repeat_every form.
484          * Otherwise, Xt gets confused about grabs.
485          */
486         if (item_no == REPEAT_EVERY)
487         {
488           XtAppAddTimeOut(XtWidgetToApplicationContext(w),
489                           0, show_repeat_every, (XtPointer)rfp);
490         }
491         else
492         {
493           XtAppAddTimeOut(XtWidgetToApplicationContext(w),
494                           0, hide_repeat_every, (XtPointer)rfp);
495
496           rfp_set_default_for(rfp, item_no, item_no ? True : False);
497         }
498 }
499
500 /*******************************************************************************
501 **
502 **  External functions
503 **
504 *******************************************************************************/
505 extern void
506 build_rfp(
507         RFP             *rfp, 
508         Calendar        *c, 
509         Widget           parent)
510 {
511         XmString         tmp;
512         Dimension        max_left_label_width;
513         Dimension        freq_label_height;
514         XmString        label_str;
515
516         rfp->parent = parent;
517         rfp->cal = c;
518
519         rfp->rfp_form_mgr = XtVaCreateWidget("rfp_form_mgr",
520                 xmFormWidgetClass, rfp->parent,
521                 XmNautoUnmanage, False,
522                 XmNuserData, rfp,
523                 NULL);
524
525         label_str = XmStringCreateLocalized(catgets(c->DT_catd, 1, 836, "Frequency"));
526         rfp->frequency_label = XtVaCreateWidget("frequency_label",
527                 xmLabelGadgetClass,     rfp->rfp_form_mgr,
528                 XmNlabelString,         label_str,
529                 XmNtopAttachment,       XmATTACH_FORM,
530                 XmNtopOffset,           GAP,
531                 NULL);
532         XmStringFree(label_str);
533  
534         tmp = XmStringCreateLocalized(catgets(c->DT_catd, 1, 534, "Occurs:"));
535         rfp->repeat_label = XtVaCreateWidget("repeat",
536                 xmLabelGadgetClass,     rfp->rfp_form_mgr,
537                 XmNlabelString,         label_str,
538                 XmNlabelString,         tmp,
539                 NULL);
540         XmStringFree(tmp);
541
542         tmp = XmStringCreateLocalized(catgets(c->DT_catd, 1, 535, "For:"));
543         rfp->for_label = XtVaCreateWidget("for",
544                 xmLabelGadgetClass,     rfp->rfp_form_mgr,
545                 XmNlabelString,         tmp,
546                 XmNsensitive,           False,
547                 NULL);
548         XmStringFree(tmp);
549
550         tmp = XmStringCreateLocalized( catgets(c->DT_catd, 1, 536, "Privacy:"));
551         rfp->privacy_label = XtVaCreateWidget("privacy",
552                 xmLabelGadgetClass,     rfp->rfp_form_mgr,
553                 XmNlabelString,         tmp,
554                 NULL);
555         XmStringFree(tmp);
556
557         max_left_label_width = ComputeMaxWidth(rfp->frequency_label,
558                                                rfp->repeat_label,
559                                                rfp->for_label,
560                                                rfp->privacy_label)
561                                                + GAP;
562
563         XtVaGetValues(rfp->frequency_label,
564                 XmNheight,              &freq_label_height,
565                 NULL);
566
567         rfp->repeat_menu = create_repeat_menu(rfp->rfp_form_mgr,
568                 rfp_repeat_menu_proc, (XtPointer)rfp);
569
570         rfp_set_repeat_values(rfp);
571         XtVaSetValues(rfp->repeat_menu,
572                 XmNuserData,            ONE_TIME,
573                 XmNleftAttachment,      XmATTACH_FORM,
574                 XmNleftOffset,          max_left_label_width,
575                 XmNtopAttachment,       XmATTACH_FORM,
576                 XmNtopOffset,           freq_label_height + 3 * GAP,
577                 NULL);
578         tmp = XmStringCreateLocalized("\0");
579
580         rfp->for_menu = create_for_menu(rfp->rfp_form_mgr);
581         XtVaSetValues(rfp->for_menu,
582                 XmNleftAttachment,      XmATTACH_FORM,
583                 XmNleftOffset,          max_left_label_width,
584                 XmNtopAttachment,       XmATTACH_WIDGET,
585                 XmNtopWidget,           rfp->repeat_menu,
586                 XmNtopOffset,           2 * GAP,
587                 NULL);
588
589         rfp->for_scope = XtVaCreateWidget("for_scope",
590                 xmLabelGadgetClass,     rfp->rfp_form_mgr,
591                 XmNlabelString,         tmp,
592                 XmNbottomAttachment,    XmATTACH_OPPOSITE_WIDGET,
593                 XmNbottomWidget,        rfp->for_label,
594                 XmNleftAttachment,      XmATTACH_WIDGET,
595                 XmNleftWidget,          rfp->for_menu,
596                 XmNleftOffset,          GAP,
597                 NULL);
598
599         XmStringFree(tmp);
600
601         rfp->privacy_menu = create_privacy_menu(rfp->rfp_form_mgr);
602         XtVaSetValues(rfp->privacy_menu,
603                 XmNleftAttachment,      XmATTACH_FORM,
604                 XmNleftOffset,          max_left_label_width,
605                 XmNtopAttachment,       XmATTACH_WIDGET,
606                 XmNtopWidget,           rfp->for_menu,
607                 XmNtopOffset,           2 * GAP,
608                 NULL);
609
610         XtVaSetValues(rfp->frequency_label,
611                 XmNrightAttachment,     XmATTACH_WIDGET,
612                 XmNrightWidget,         rfp->repeat_menu,
613                 XmNrightOffset,         GAP,
614                 NULL);
615
616         XtVaSetValues(rfp->repeat_label,
617                 XmNbottomAttachment,    XmATTACH_OPPOSITE_WIDGET,
618                 XmNbottomWidget,        rfp->repeat_menu,
619                 XmNbottomOffset,        GAP,
620                 XmNrightAttachment,     XmATTACH_WIDGET,
621                 XmNrightWidget,         rfp->repeat_menu,
622                 XmNrightOffset,         GAP,
623                 NULL);
624
625         XtVaSetValues(rfp->for_label,
626                 XmNbottomAttachment,    XmATTACH_OPPOSITE_WIDGET,
627                 XmNbottomWidget,        rfp->for_menu,
628                 XmNbottomOffset,        GAP,
629                 XmNrightAttachment,     XmATTACH_WIDGET,
630                 XmNrightWidget,         rfp->for_menu,
631                 XmNrightOffset,         GAP,
632                 NULL);
633
634         XtVaSetValues(rfp->privacy_label,
635                 XmNbottomAttachment,    XmATTACH_OPPOSITE_WIDGET,
636                 XmNbottomWidget,        rfp->privacy_menu,
637                 XmNbottomOffset,        GAP,
638                 XmNrightAttachment,     XmATTACH_WIDGET,
639                 XmNrightWidget,         rfp->privacy_menu,
640                 XmNrightOffset,         GAP,
641                 NULL);
642 }
643
644 /*
645 **  Get and set values on the screen
646 */
647 extern void
648 get_rfp_repeat_val(
649         RFP             *rfp,
650         time_t           tick)
651 {
652         char            *str,
653                          rule_buf1[32],
654                          rule_buf2[32];
655         Widget           tf;
656         Repeat_menu_op   op;
657         Boolean          sensitive;
658
659         /* clear the buffers */
660         memset (rule_buf1, 0, 32);
661         memset (rule_buf2, 0, 32);
662
663         /* This routine has to set up the recurrence values in two spots. 
664            It has to set up the old style recurrence values for a daemon
665            in data versions 1-3, and it has to set up a recurrence rule for a 
666            data version 4 daemon. */
667
668         /*
669         **  First, get the value on the repeat menu
670         */
671         XtVaGetValues(rfp->repeat_menu, XmNselectedPosition, &op, NULL);
672         --op;
673
674         switch(op) {
675         case ONE_TIME:
676                 rfp->repeat_type = CSA_X_DT_REPEAT_ONETIME;
677                 strcpy(rule_buf1, "D1 ");
678                 break;
679         case DAILY:
680                 rfp->repeat_type = CSA_X_DT_REPEAT_DAILY;
681                 strcpy(rule_buf1, "D1 ");
682                 break;
683         case WEEKLY:
684                 rfp->repeat_type = CSA_X_DT_REPEAT_WEEKLY;
685                 strcpy(rule_buf1, "W1 ");
686                 break;
687         case EVERY_TWO_WEEKS:
688                 rfp->repeat_type = CSA_X_DT_REPEAT_BIWEEKLY;
689                 strcpy(rule_buf1, "W2 ");
690                 break;
691         case MONTHLY_BY_DATE:
692                 rfp->repeat_type = CSA_X_DT_REPEAT_MONTHLY_BY_DATE;
693                 strcpy(rule_buf1, "MD1 ");
694                 break;
695         case MONTHLY_BY_WEEKDAY: {
696                 int     wk;
697
698                 rfp->repeat_type = CSA_X_DT_REPEAT_MONTHLY_BY_WEEKDAY;
699                 /* 
700                  * The current behavior of cm/dtcm is that if an appt is
701                  * scheduled for the 5 wk of the month, it repeats on the
702                  * last week of the month.
703                  */
704                 if (weekofmonth(tick, &wk) && wk == 5)
705                         sprintf(rule_buf1, "MP1 1- %s ", dow_str(tick));
706                 else
707                         strcpy(rule_buf1, "MP1 ");
708                 break;
709         }
710         case YEARLY:
711                 rfp->repeat_type = CSA_X_DT_REPEAT_YEARLY;
712                 strcpy(rule_buf1, "YM1 ");
713                 break;
714         case MONDAY_THRU_FRIDAY:
715                 rfp->repeat_type = CSA_X_DT_REPEAT_MON_TO_FRI;
716                 strcpy(rule_buf1, "W1 MO TU WE TH FR ");
717                 break;
718         case MON_WED_FRI:
719                 rfp->repeat_type = CSA_X_DT_REPEAT_MONWEDFRI;
720                 strcpy(rule_buf1, "W1 MO WE FR ");
721                 break;
722         case TUESDAY_THURSDAY:
723                 rfp->repeat_type = CSA_X_DT_REPEAT_TUETHUR;
724                 strcpy(rule_buf1, "W1 TU TH ");
725                 break;
726         case REPEAT_EVERY:
727                 /* REPEAT_EVERY is handled in rfp_apply_proc() */
728                 switch(rfp->repeat_type) {
729                 case CSA_X_DT_REPEAT_EVERY_NDAY:
730                         sprintf(rule_buf1, "D%d ", rfp->repeat_nth);
731                         break;
732                 case CSA_X_DT_REPEAT_EVERY_NWEEK:
733                         sprintf(rule_buf1, "W%d ", rfp->repeat_nth);
734                         break;
735                 case CSA_X_DT_REPEAT_EVERY_NMONTH:
736                 default:
737                         sprintf(rule_buf1, "MD%d ", rfp->repeat_nth);
738                         break;
739                 }
740                 break;
741         default:
742                 break;
743         }
744
745         if (op != REPEAT_EVERY)
746                 rfp->repeat_nth = 0;
747
748         /*
749         **  Now get the duration - the for menu and scope.
750         */
751         XtVaGetValues(rfp->for_menu, 
752                         XmNtextField,   &tf, 
753                         NULL);
754         XtVaGetValues(tf,
755                         XmNsensitive,   &sensitive,
756                         NULL);
757
758         if (sensitive) {
759                 char    *forever_str = catgets(calendar->DT_catd, 1, 876, 
760                                                                    "forever"); 
761                 str = XmTextGetString(tf);
762                 if (strcmp(str, forever_str) == 0) {
763                         rfp->for_val = PRIVATE_FOREVER;
764                         strcat(rule_buf2, "#0");
765                 } else {
766                         rfp->for_val = atoi(str);
767                         if (rfp->for_val == 0)
768                                 strcat(rule_buf2, "#1");
769                         else {
770                                 if (op != REPEAT_EVERY) {
771                                         sprintf(rule_buf2, "#%d", rfp->for_val);
772                                 } else {
773                                         int duration;
774
775                                         if (rfp->for_val % rfp->repeat_nth)
776                                                 duration = 1 + 
777                                                    rfp->for_val/rfp->repeat_nth;
778                                         else
779                                                 duration = 
780                                                    rfp->for_val/rfp->repeat_nth;
781
782                                         sprintf(rule_buf2, "#%d", duration);
783                                 }
784                         }
785                 }
786                 XtFree(str);
787         } else {
788                 strcat(rule_buf2, "#1");
789                 rfp->for_val = 0;
790
791         }
792
793         strcat (rule_buf1, rule_buf2);
794
795         if (rfp->recurrence_rule)
796                 free(rfp->recurrence_rule);
797
798         rfp->recurrence_rule = cm_strdup(rule_buf1);
799 }
800
801 extern void
802 get_rfp_privacy_val(RFP *rfp) {
803         int     i;
804
805         XtVaGetValues(rfp->privacy_menu, XmNselectedPosition, &i, NULL);
806         --i;
807
808         switch (i) {
809         
810                 case 0: rfp->privacy_val = CSA_CLASS_PUBLIC;
811                    break;
812         
813                 case 1: rfp->privacy_val = CSA_CLASS_CONFIDENTIAL;
814                    break;
815         
816                 case 2: rfp->privacy_val = CSA_CLASS_PRIVATE;
817                    break;
818
819         }
820 }
821
822 extern void
823 get_rfp_vals(RFP *rfp, time_t tick) {
824         get_rfp_repeat_val(rfp, tick);
825         get_rfp_privacy_val(rfp);
826 }
827
828 /*
829 **  This function will consume form values and stuff them into an appointment.
830 */
831 extern Boolean
832 rfp_form_to_appt(RFP *rfp, Dtcm_appointment *a, char *name)
833 {
834   return rfp_form_flags_to_appt(rfp, a, name, (int *)NULL);
835 }
836
837 extern Boolean
838 rfp_form_flags_to_appt(RFP *rfp, Dtcm_appointment *a, char *name, int *flagsP)
839 {
840         int             wk;
841         char            buf[MAXNAMELEN];
842         time_t          tick;
843         Calendar        *c = rfp->cal;
844         Props_pu        *p = (Props_pu *)rfp->cal->properties_pu;
845         int             flags = 0;
846
847         if (flagsP == (int *)NULL)
848           flagsP = &flags;
849
850         _csa_iso8601_to_tick(a->time->value->item.date_time_value, &tick);
851
852         if (rfp->rfp_form_mgr)
853                 get_rfp_vals(rfp, tick);
854
855         a->private->value->item.sint32_value = rfp->privacy_val;
856
857         if (a->version < DATAVER4) {
858                 a->repeat_type->value->item.sint32_value = rfp->repeat_type;
859                 a->repeat_times->value->item.uint32_value = rfp->for_val == PRIVATE_FOREVER ? CSA_X_DT_DT_REPEAT_FOREVER : rfp->for_val;
860
861                 if ((a->version == DATAVER3) ||(a->version == DATAVER_ARCHIVE)) {
862                         if (a->repeat_interval)
863                                 a->repeat_interval->value->item.uint32_value =
864                                         rfp->repeat_nth;
865                         if (a->repeat_week_num)
866                                 a->repeat_week_num->value->item.sint32_value =
867                                         -1;
868                 }
869         }
870         else
871                 a->recurrence_rule->value->item.string_value = 
872                                                 cm_strdup(rfp->recurrence_rule);
873
874         if (rfp->repeat_type != CSA_X_DT_REPEAT_ONETIME) {
875                 if (rfp->for_val == 0) {
876                         editor_err_msg(rfp->parent, name, REPEAT_FOR_MISMATCH,
877                                 p->xm_error_pixmap);
878                         return False;
879                 }
880                 if (rfp->repeat_type == CSA_X_DT_REPEAT_MONTHLY_BY_WEEKDAY) {
881                         if (weekofmonth(tick, &wk) && wk == 4)
882                         {
883                             if (*flagsP == 0)
884                             {
885                                 char *title = XtNewString(catgets(c->DT_catd, 1, 537,
886                                                 "Calendar : Editor - Schedule Appointment"));
887                                 char *text = XtNewString(catgets(c->DT_catd, 1, 538,
888                                                 "Would you like to schedule this appointment as the last\nweek of the month or the 4th week of the month?"));
889                                 char *ident1 = XtNewString(catgets(c->DT_catd, 1,
890                                                 923, "Cancel"));
891                                 char *ident2 = XtNewString(catgets(c->DT_catd, 1,
892                                                 540, "Last Week"));
893                                 char *ident3 = XtNewString(catgets(c->DT_catd, 1,
894                                                 541, "4th Week"));
895                                 *flagsP = dialog_popup(rfp->parent,
896                                         DIALOG_TITLE, title,
897                                         DIALOG_TEXT, text,
898                                         BUTTON_IDENT, -1, ident1,
899                                         BUTTON_IDENT, RFP_MBW_LAST, ident2,
900                                         BUTTON_IDENT, RFP_MBW_4TH, ident3,
901                                         DIALOG_IMAGE, p->xm_question_pixmap,
902                                         NULL);
903                                 XtFree(ident3);
904                                 XtFree(ident2);
905                                 XtFree(ident1);
906                                 XtFree(text);
907                                 XtFree(title);
908                             }
909                             switch (*flagsP)
910                             {
911                             case RFP_MBW_LAST:
912                                 change_to_last_week(a, wk, tick, rfp);
913                                 break;
914
915                             case RFP_MBW_4TH:
916                                 if (a->version < DATAVER4)
917                                   a->repeat_week_num->value->item.sint32_value = wk;
918                                 break;
919
920                             default:
921                                 *flagsP = 0;
922                                 return False;
923                             }
924                         } else if (wk != 5)
925                                 if (a->version < DATAVER4)
926                                         a->repeat_week_num->value->item.sint32_value = wk;
927                 }
928                 else
929                 {
930                         if (a->repeat_type == NULL) {
931                                 if ((a->repeat_type =
932                                       (CSA_attribute *)ckalloc(sizeof(CSA_attribute)))
933                                     == NULL)
934                                   /* return (CSA_E_INSUFFICIENT_MEMORY); */
935                                   return False;
936
937                                 memset(a->repeat_type, 0, sizeof(CSA_attribute));
938
939                                 _DtCm_set_sint32_attrval(rfp->repeat_type,
940                                                          &a->repeat_type->value);
941                         }
942                         else a->repeat_type->value->item.sint32_value = rfp->repeat_type;
943                 }
944         }
945         else
946         {
947                 if (a->repeat_type == NULL) {
948                         if ((a->repeat_type =
949                              (CSA_attribute *)ckalloc(sizeof(CSA_attribute)))
950                             == NULL)
951                           /* return (CSA_E_INSUFFICIENT_MEMORY); */
952                           return False;
953
954                         memset(a->repeat_type, 0, sizeof(CSA_attribute));
955
956                         _DtCm_set_sint32_attrval(rfp->repeat_type,&a->repeat_type->value);
957                 }
958                 else a->repeat_type->value->item.sint32_value = rfp->repeat_type;
959         }
960
961         return True;
962 }
963
964 /*
965  * Given a rule, change it to always happen on the last week of the month.
966  */
967 static void
968 change_to_last_week(
969         Dtcm_appointment        *a,
970         int                      wk,
971         time_t                   tick,
972         RFP                     *rfp)
973 {
974         if (a->version < DATAVER4)
975                 return;
976         else {
977                 char    *weekday = dow_str(tick),
978                         *new_rule,
979                          duration_buf[10];
980
981                 memset(duration_buf, 0, 10);
982
983                 /* The new rule uses a little more memory than the old */
984                 new_rule = (char *)calloc(1, 
985                       strlen(a->recurrence_rule->value->item.string_value) + 8);
986
987                 /* Free the old rule */
988                 free(a->recurrence_rule->value->item.string_value);
989
990                 sprintf(new_rule, "MP1 1- %s", weekday);
991                 if (rfp->for_val == PRIVATE_FOREVER)
992                         strcat(new_rule, " #0");
993                 else if (rfp->for_val == 0)
994                         strcat(new_rule, " #1");
995                 else {
996                         sprintf(duration_buf, " #%d", rfp->for_val);
997                         strcat(new_rule, duration_buf);
998                 }
999
1000                 a->recurrence_rule->value->item.string_value = new_rule;
1001
1002                 free(weekday);
1003         }
1004 }
1005
1006 /*
1007 **  This function will take appointment values and stuff them into a form.
1008 */
1009 extern Boolean
1010 rfp_appt_to_form(RFP *rfp, CSA_entry_handle entry) {
1011         Boolean                 ret_val;
1012         CSA_return_code         stat;
1013         Dtcm_appointment        *appt;
1014
1015         appt = allocate_appt_struct(appt_read,
1016                                     rfp->cal->general->version,
1017                                     CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I,
1018                                     CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I,
1019                                     CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I,
1020                                     CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I,
1021                                     CSA_ENTRY_ATTR_CLASSIFICATION_I,
1022                                     CSA_ENTRY_ATTR_RECURRENCE_RULE_I,
1023                                     NULL);
1024         stat = query_appt_struct(rfp->cal->cal_handle, entry, appt);
1025         backend_err_msg(rfp->cal->frame, rfp->cal->view->current_calendar,
1026                 stat, ((Props_pu *)rfp->cal->properties_pu)->xm_error_pixmap);
1027         if (stat != CSA_SUCCESS) {
1028                 free_appt_struct(&appt);
1029                 return False;
1030         }
1031
1032         ret_val = rfp_attrs_to_form(rfp, appt);
1033         free_appt_struct(&appt);
1034
1035         return ret_val;
1036 }
1037
1038 extern Boolean
1039 rfp_attrs_to_form(RFP *rfp, Dtcm_appointment *appt) {
1040
1041         /* At this point, check out the returning reminder values.  If
1042            the old style reminder values are not set, we must have a client
1043            that either wrote out the appointment with no reminders, or with
1044            a recurrence rule set that will not map into what wee currently
1045            understand.  We should inactivate the rfp fields, and not set 
1046            any values.  On the other hand, if they are set, we should
1047            make sure the controls are made sensitive. */
1048
1049         if (appt->repeat_type && appt->repeat_type->value) {
1050                 rfp_toggle_repeat_grey(rfp, True);
1051                 rfp->repeat_type = appt->repeat_type->value->item.sint32_value;
1052                 if (appt->version > DATAVER2) {
1053                         rfp->repeat_nth = (appt->repeat_interval) ?
1054                                 appt->repeat_interval->value->item.uint32_value : 0;
1055                 }
1056                 if (appt->repeat_times && appt->repeat_times->value)
1057                         rfp->for_val = appt->repeat_times->value->item.uint32_value;
1058                 else
1059                         rfp->for_val = 0;
1060
1061                 rfp->privacy_val = privacy_set(appt);
1062                 set_rfp_vals(rfp);
1063         }
1064         else {
1065                 rfp_toggle_for_grey(rfp, False);
1066                 rfp_toggle_repeat_grey(rfp, False);
1067         }
1068
1069         return True;
1070 }
1071
1072 extern void
1073 set_rfp_repeat_val(RFP *rfp) {
1074         char            buf[128];
1075         Boolean         status = True;
1076         XmString        xmstr;
1077         Calendar        *c = rfp->cal;
1078         const char      *repeat_scope;
1079         Repeat_menu_op  op;
1080
1081         /*
1082         **  Set the repeat menu button based on the period value
1083         */
1084         buf[0] = '\0';
1085         if (rfp->repeat_type == CSA_X_DT_REPEAT_ONETIME) {
1086                 op = ONE_TIME;
1087                 repeat_scope = default_repeat_scope_str(c->DT_catd, ONE_TIME);
1088                 sprintf(buf, "%s", repeat_str(c->DT_catd, ONE_TIME));
1089                 status = False;
1090         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_DAILY) {
1091                 op = DAILY;
1092                 repeat_scope = default_repeat_scope_str(c->DT_catd, DAILY);
1093                 sprintf(buf, "%s", repeat_str(c->DT_catd, DAILY));
1094         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_WEEKLY) {
1095                 op = WEEKLY;
1096                 repeat_scope = default_repeat_scope_str(c->DT_catd, WEEKLY);
1097                 sprintf(buf, "%s", repeat_str(c->DT_catd, WEEKLY));
1098         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_BIWEEKLY) {
1099                 op = EVERY_TWO_WEEKS;
1100                 repeat_scope = 
1101                         default_repeat_scope_str(c->DT_catd, EVERY_TWO_WEEKS);
1102                 sprintf(buf, "%s", repeat_str(c->DT_catd, EVERY_TWO_WEEKS));
1103         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_MONTHLY_BY_DATE) {
1104                 op = MONTHLY_BY_DATE;
1105                 repeat_scope = 
1106                         default_repeat_scope_str(c->DT_catd, MONTHLY_BY_DATE);
1107                 sprintf(buf, "%s", repeat_str(c->DT_catd, MONTHLY_BY_DATE));
1108         } else if (rfp->repeat_type ==
1109                           CSA_X_DT_REPEAT_MONTHLY_BY_WEEKDAY) {
1110                 op = MONTHLY_BY_WEEKDAY;
1111                 repeat_scope = default_repeat_scope_str(c->DT_catd, 
1112                                                         MONTHLY_BY_WEEKDAY);
1113                 sprintf(buf, "%s", repeat_str(c->DT_catd, MONTHLY_BY_WEEKDAY));
1114         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_YEARLY) {
1115                 op = YEARLY;
1116                 repeat_scope = default_repeat_scope_str(c->DT_catd, YEARLY);
1117                 sprintf(buf, "%s", repeat_str(c->DT_catd, YEARLY));
1118         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_MON_TO_FRI) {
1119                 op = MONDAY_THRU_FRIDAY;
1120                 repeat_scope = default_repeat_scope_str(c->DT_catd, 
1121                                                         MONDAY_THRU_FRIDAY);
1122                 sprintf(buf, "%s", repeat_str(c->DT_catd, MONDAY_THRU_FRIDAY));
1123         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_MONWEDFRI) {
1124                 op = MON_WED_FRI;
1125                 repeat_scope = 
1126                         default_repeat_scope_str(c->DT_catd, MON_WED_FRI);
1127                 sprintf(buf, "%s", repeat_str(c->DT_catd, MON_WED_FRI));
1128         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_TUETHUR) {
1129                 op = TUESDAY_THURSDAY;
1130                 repeat_scope = 
1131                         default_repeat_scope_str(c->DT_catd, TUESDAY_THURSDAY);
1132                 sprintf(buf, "%s", repeat_str(c->DT_catd, TUESDAY_THURSDAY));
1133         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_EVERY_NDAY) {
1134                 op = REPEAT_EVERY;
1135                 repeat_scope = repeat_scope_str(c->DT_catd, REPEAT_DAYS);
1136                 sprintf(buf, catgets(c->DT_catd, 1, 542, "Every %d %s"),
1137                         rfp->repeat_nth, repeat_scope);
1138         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_EVERY_NWEEK) {
1139                 op = REPEAT_EVERY;
1140                 repeat_scope = repeat_scope_str(c->DT_catd, REPEAT_WEEKS);
1141                 sprintf(buf, catgets(c->DT_catd, 1, 543, "Every %d %s"),
1142                         rfp->repeat_nth, repeat_scope);
1143         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_EVERY_NMONTH) {
1144                 op = REPEAT_EVERY;
1145                 repeat_scope = repeat_scope_str(c->DT_catd, REPEAT_MONTHS);
1146                 sprintf(buf, catgets(c->DT_catd, 1, 544, "Every %d %s"),
1147                         rfp->repeat_nth, repeat_scope);
1148         } else
1149                 return;
1150
1151         /*
1152          * Set the Repeat combo box
1153          */
1154         xmstr = XmStringCreateLocalized(buf);
1155         XtVaSetValues(rfp->repeat_menu, XmNselectedPosition, op + 1, NULL);
1156         XtVaSetValues(rfp->repeat_menu, XmNlabelString, xmstr, NULL);
1157         XmStringFree(xmstr);
1158
1159         /*
1160         **  Set the For button, text item, and scope
1161         */
1162         if (rfp->for_val == CSA_X_DT_DT_REPEAT_FOREVER) {
1163                 if(rfp->repeat_type != CSA_X_DT_REPEAT_ONETIME)
1164                 {
1165                         sprintf(buf, "%s", catgets(c->DT_catd, 1, 876, "forever"));
1166                         xmstr = XmStringCreateLocalized(buf);
1167                         XmComboBoxSetItem(rfp->for_menu, xmstr);
1168                         XmStringFree(xmstr);
1169                 }
1170                 else
1171                 {
1172                         Widget text;
1173                         buf[0]= '\0';
1174                         XtVaGetValues(rfp->for_menu, XmNtextField,
1175                                       &text, NULL);
1176                         XmTextFieldSetString(text, buf);
1177                 }
1178                 repeat_scope = "\0";
1179         } else if (rfp->for_val >= 2 && rfp->for_val <= 14) {
1180                 sprintf(buf, "%s", for_str(rfp->for_val - 2)); 
1181                 xmstr = XmStringCreateLocalized(buf);
1182                 XmComboBoxSetItem(rfp->for_menu, xmstr);
1183                 XmStringFree(xmstr);
1184         } else {
1185                 Widget          text;
1186                 sprintf(buf, "%d", rfp->for_val);
1187                 XtVaGetValues(rfp->for_menu, XmNtextField, &text, NULL);
1188                 XmTextFieldSetString(text, buf);
1189         }
1190
1191         xmstr = XmStringCreateLocalized((char *)repeat_scope);
1192         XtVaSetValues(rfp->for_scope, XmNlabelString, xmstr,
1193                 NULL);
1194         XmStringFree(xmstr);
1195
1196         rfp_toggle_for_grey(rfp, status);
1197 }
1198
1199 extern void
1200 set_rfp_privacy_val(RFP *rfp) {
1201         int     i;
1202
1203         if (rfp->privacy_val == CSA_CLASS_PUBLIC)
1204                 i = 0;
1205         else if (rfp->privacy_val == CSA_CLASS_CONFIDENTIAL)
1206                 i = 1;
1207         else
1208                 i = 2;
1209
1210         XtVaSetValues(rfp->privacy_menu, XmNselectedPosition, i + 1, NULL);
1211 }
1212
1213 extern void
1214 set_rfp_vals(RFP *rfp) {
1215         set_rfp_repeat_val(rfp);
1216         set_rfp_privacy_val(rfp);
1217 }
1218
1219 extern void
1220 set_rfp_defaults(RFP *rfp) {
1221         Props           *p = (Props *)rfp->cal->properties;
1222
1223         rfp->for_val = 0;
1224         rfp->privacy_val = convert_privacy_str(get_char_prop(p, CP_PRIVACY));
1225         rfp->repeat_type = CSA_X_DT_REPEAT_ONETIME;
1226
1227         set_rfp_vals(rfp);
1228         rfp_set_default_for(rfp, ONE_TIME, False);
1229 }
1230
1231 static char *
1232 dow_str(
1233         time_t  tick)
1234 {
1235         switch (dow(tick)) {
1236         case 0:
1237                 return (cm_strdup("SU"));
1238         case 1:
1239                 return (cm_strdup("MO"));
1240         case 2:
1241                 return (cm_strdup("TU"));
1242         case 3:
1243                 return (cm_strdup("WE"));
1244         case 4:
1245                 return (cm_strdup("TH"));
1246         case 5:
1247                 return (cm_strdup("FR"));
1248         case 6:
1249         default:
1250                 return (cm_strdup("SA"));
1251         }
1252 }
1253
1254 extern void
1255 rfp_init(
1256         RFP             *rfp,
1257         Calendar        *c,
1258         Widget           parent)
1259 {
1260         Props           *p = (Props *)c->properties;
1261
1262         rfp->parent = parent;
1263         rfp->cal = c;
1264         rfp->for_val = 0;
1265         rfp->privacy_val = convert_privacy_str(get_char_prop(p, CP_PRIVACY));
1266         rfp->repeat_type = CSA_X_DT_REPEAT_ONETIME;
1267         rfp->recurrence_rule = strdup("D1 #1");
1268 }