Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[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 libraries 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;
217         Props_pu                *pu;
218         Repeat_scope_menu_op    op = REPEAT_DAYS;
219         char                    *repeat_str;
220
221         if (!rfp)
222                 return;
223
224         c = rfp->cal;
225         pu = (Props_pu *)c->properties_pu;
226
227         str = XmTextGetString(rfp->repeat_popup_text);
228
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"));
233
234                 XtFree(str);
235                 dialog_popup(c->frame,
236                         DIALOG_TITLE, title,
237                         DIALOG_TEXT, text,
238                         BUTTON_IDENT, 1, ident1,
239                         DIALOG_IMAGE, pu->xm_error_pixmap,
240                         NULL);
241                 XtFree(ident1);
242                 XtFree(text);
243                 XtFree(title);
244                 return;
245         }
246
247         rfp->repeat_nth = atoi(str);
248         XtFree(str);
249         if (rfp->repeat_nth == 0) {
250           XtUnmanageChild(rfp->repeat_form_mgr);
251           return;
252         }
253
254         /*
255          * Change the string to be more informative.
256          */
257         XtVaGetValues(rfp->repeat_popup_menu, XmNuserData, &op, NULL);
258
259         switch (op) {
260
261         case REPEAT_DAYS: repeat_str = catgets(c->DT_catd, 1, 825, "Days");
262                                 break;
263
264         case REPEAT_WEEKS: repeat_str = catgets(c->DT_catd, 1, 826, "Weeks");
265                                 break;
266
267         case REPEAT_MONTHS: repeat_str = catgets(c->DT_catd, 1, 827, "Months");
268                                 break;
269         }
270
271         /*
272          * Now change the text field
273          */
274         {
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);
278           XtFree(nl_repeat);
279         }
280
281         xmstr = XmStringCreateLocalized(buf);
282         XtVaSetValues(rfp->repeat_menu, XmNlabelString, xmstr, NULL);
283         XmStringFree(xmstr);
284
285         switch(op) {
286         case REPEAT_DAYS:
287                 rfp->repeat_type = CSA_X_DT_REPEAT_EVERY_NDAY;
288                 rfp_set_default_for(rfp, DAILY, True);
289                 break;
290         case REPEAT_WEEKS:
291                 rfp->repeat_type = CSA_X_DT_REPEAT_EVERY_NWEEK;
292                 rfp_set_default_for(rfp, WEEKLY, True);
293                 break;
294         case REPEAT_MONTHS:
295         default:
296                 rfp->repeat_type = CSA_X_DT_REPEAT_EVERY_NMONTH;
297                 rfp_set_default_for(rfp, MONTHLY_BY_DATE, True);
298                 break;
299         }
300
301         XtUnmanageChild(rfp->repeat_form_mgr);
302 }
303
304 static void
305 rfp_cancel_proc(Widget w, XtPointer client_data, XtPointer cbs) {
306         RFP     *rfp = (RFP *)client_data;
307
308         rfp->repeat_nth = 0;
309         rfp->repeat_type = CSA_X_DT_REPEAT_ONETIME;
310
311         /*
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
315          * down the popup.
316          */
317         XtVaSetValues(rfp->repeat_menu,
318                       XmNselectedPosition, ONE_TIME + 1, NULL);
319 }
320
321 /*
322 **  This, obviously, pops up the repeat every ...
323 */
324 static void
325 rfp_repeat_every_popup(RFP *rfp) {
326         Widget          label, apply_button, cancel_button, separator;
327         XmString        xmstr;
328         Calendar        *c = rfp->cal;
329         char            *title;
330         XmString        label_str;
331
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,
336                 XmNtitle, title,
337                 XmNallowShellResize, True,
338                 XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_CLOSE,
339                 XmNdeleteResponse, XmDO_NOTHING,
340                 NULL);
341         XtFree(title);
342
343         setup_quit_handler(rfp->repeat_popup_frame, rfp_cancel_proc,
344                            (XtPointer)rfp);
345
346         rfp->repeat_form_mgr = XtVaCreateWidget("form_mgr",
347                 xmFormWidgetClass, rfp->repeat_popup_frame,
348                 XmNautoUnmanage, False,
349                 XmNhorizontalSpacing, 0,
350                 XmNverticalSpacing, 5,
351                 XmNfractionBase, 2,
352                 NULL);
353
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,
358                 XmNleftOffset, 10,
359                 XmNleftAttachment, XmATTACH_POSITION,
360                 XmNleftPosition, 0,
361                 XmNrightAttachment, XmATTACH_POSITION,
362                 XmNrightPosition, 1,
363                 XmNbottomAttachment, XmATTACH_FORM,
364                 NULL);
365         XmStringFree(label_str);
366         XtAddCallback(rfp->repeat_apply_button, 
367                         XmNactivateCallback, rfp_apply_proc, rfp);
368  
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,
374                 XmNleftPosition, 1,
375                 XmNrightAttachment, XmATTACH_POSITION,
376                 XmNrightPosition, 2,
377                 XmNrightOffset, 10,
378                 XmNbottomAttachment, XmATTACH_FORM,
379                 NULL);
380         XmStringFree(label_str);
381         XtAddCallback(rfp->repeat_cancel_button, 
382                         XmNactivateCallback, rfp_cancel_proc, rfp);
383
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,
391                 XmNbottomOffset,        5,
392                 NULL);
393
394         xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 533,
395                                                 "Repeat Every:"));
396         label = XtVaCreateWidget("every",
397                 xmLabelGadgetClass, rfp->repeat_form_mgr,
398                 XmNlabelString, xmstr,
399                 XmNtopAttachment, XmATTACH_FORM,
400                 XmNtopOffset, 10,
401                 XmNleftAttachment, XmATTACH_FORM,
402                 XmNleftOffset, 5,
403                 XmNbottomAttachment, XmATTACH_WIDGET,
404                 XmNbottomWidget, separator,
405                 NULL);
406         XmStringFree(xmstr);
407
408         rfp->repeat_popup_text = XtVaCreateWidget("text_field",
409                 xmTextWidgetClass, rfp->repeat_form_mgr,
410                 XmNeditMode, XmSINGLE_LINE_EDIT,
411                 XmNcolumns, FOR_LEN,
412                 XmNmaxLength, FOR_LEN - 1,
413                 XmNtopAttachment, XmATTACH_FORM,
414                 XmNtopOffset, 10,
415                 XmNleftAttachment, XmATTACH_WIDGET,
416                 XmNleftWidget, label,
417                 XmNleftOffset, 5,
418                 XmNbottomAttachment, XmATTACH_WIDGET,
419                 XmNbottomWidget, separator,
420                 NULL);
421  
422         rfp->repeat_popup_menu = 
423                 create_repeat_scope_menu(rfp->repeat_form_mgr, NULL,
424                                          rfp_repeat_scope_proc, (XtPointer)rfp);
425
426
427         XtVaSetValues(rfp->repeat_popup_menu,
428                 XmNuserData, REPEAT_DAYS,
429                 XmNtopAttachment, XmATTACH_FORM,
430                 XmNtopOffset, 6,
431                 XmNleftAttachment, XmATTACH_WIDGET,
432                 XmNleftWidget, rfp->repeat_popup_text,
433                 XmNleftOffset, 5,
434                 XmNbottomAttachment, XmATTACH_WIDGET,
435                 XmNbottomWidget, separator,
436                 NULL);
437
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);
442
443         ManageChildren(rfp->repeat_form_mgr);
444 }
445
446 static void
447 show_repeat_every(XtPointer uData, XtIntervalId *id)
448 {
449   RFP *rfp = (RFP *)uData;
450
451   if (!rfp->repeat_form_mgr)
452     rfp_repeat_every_popup(rfp);
453
454   XtManageChild(rfp->repeat_form_mgr);
455 }
456
457 static void
458 hide_repeat_every(XtPointer uData, XtIntervalId *id)
459 {
460   RFP *rfp = (RFP *)uData;
461
462   /* Make sure repeat_every form no longer displayed. */
463   if (rfp->repeat_form_mgr)
464     XtUnmanageChild(rfp->repeat_form_mgr);
465 }
466
467 /*
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)
470 */
471 static void
472 rfp_repeat_menu_proc(Widget w, XtPointer data, XtPointer cbs) {
473         RFP                     *rfp = (RFP *)data;
474         Repeat_menu_op          item_no;
475
476         if (!rfp)
477                 return;
478
479         XtVaGetValues(rfp->repeat_menu,
480                       XmNselectedPosition, &item_no,
481                       NULL);
482         --item_no;
483
484         /*
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.
488          */
489         if (item_no == REPEAT_EVERY)
490         {
491           XtAppAddTimeOut(XtWidgetToApplicationContext(w),
492                           0, show_repeat_every, (XtPointer)rfp);
493         }
494         else
495         {
496           XtAppAddTimeOut(XtWidgetToApplicationContext(w),
497                           0, hide_repeat_every, (XtPointer)rfp);
498
499           rfp_set_default_for(rfp, item_no, item_no ? True : False);
500         }
501 }
502
503 /*******************************************************************************
504 **
505 **  External functions
506 **
507 *******************************************************************************/
508 extern void
509 build_rfp(
510         RFP             *rfp, 
511         Calendar        *c, 
512         Widget           parent)
513 {
514         XmString         tmp;
515         Dimension        max_left_label_width;
516         Dimension        freq_label_height;
517         XmString        label_str;
518
519         rfp->parent = parent;
520         rfp->cal = c;
521
522         rfp->rfp_form_mgr = XtVaCreateWidget("rfp_form_mgr",
523                 xmFormWidgetClass, rfp->parent,
524                 XmNautoUnmanage, False,
525                 XmNuserData, rfp,
526                 NULL);
527
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,
533                 XmNtopOffset,           GAP,
534                 NULL);
535         XmStringFree(label_str);
536  
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,
541                 XmNlabelString,         tmp,
542                 NULL);
543         XmStringFree(tmp);
544
545         tmp = XmStringCreateLocalized(catgets(c->DT_catd, 1, 535, "For:"));
546         rfp->for_label = XtVaCreateWidget("for",
547                 xmLabelGadgetClass,     rfp->rfp_form_mgr,
548                 XmNlabelString,         tmp,
549                 XmNsensitive,           False,
550                 NULL);
551         XmStringFree(tmp);
552
553         tmp = XmStringCreateLocalized( catgets(c->DT_catd, 1, 536, "Privacy:"));
554         rfp->privacy_label = XtVaCreateWidget("privacy",
555                 xmLabelGadgetClass,     rfp->rfp_form_mgr,
556                 XmNlabelString,         tmp,
557                 NULL);
558         XmStringFree(tmp);
559
560         max_left_label_width = ComputeMaxWidth(rfp->frequency_label,
561                                                rfp->repeat_label,
562                                                rfp->for_label,
563                                                rfp->privacy_label)
564                                                + GAP;
565
566         XtVaGetValues(rfp->frequency_label,
567                 XmNheight,              &freq_label_height,
568                 NULL);
569
570         rfp->repeat_menu = create_repeat_menu(rfp->rfp_form_mgr,
571                 rfp_repeat_menu_proc, (XtPointer)rfp);
572
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,
580                 NULL);
581         tmp = XmStringCreateLocalized("\0");
582
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,
590                 NULL);
591
592         rfp->for_scope = XtVaCreateWidget("for_scope",
593                 xmLabelGadgetClass,     rfp->rfp_form_mgr,
594                 XmNlabelString,         tmp,
595                 XmNbottomAttachment,    XmATTACH_OPPOSITE_WIDGET,
596                 XmNbottomWidget,        rfp->for_label,
597                 XmNleftAttachment,      XmATTACH_WIDGET,
598                 XmNleftWidget,          rfp->for_menu,
599                 XmNleftOffset,          GAP,
600                 NULL);
601
602         XmStringFree(tmp);
603
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,
611                 NULL);
612
613         XtVaSetValues(rfp->frequency_label,
614                 XmNrightAttachment,     XmATTACH_WIDGET,
615                 XmNrightWidget,         rfp->repeat_menu,
616                 XmNrightOffset,         GAP,
617                 NULL);
618
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,
625                 XmNrightOffset,         GAP,
626                 NULL);
627
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,
634                 XmNrightOffset,         GAP,
635                 NULL);
636
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,
643                 XmNrightOffset,         GAP,
644                 NULL);
645 }
646
647 /*
648 **  Get and set values on the screen
649 */
650 extern void
651 get_rfp_repeat_val(
652         RFP             *rfp,
653         time_t           tick)
654 {
655         char            *str,
656                          rule_buf1[32],
657                          rule_buf2[32];
658         Widget           tf;
659         Repeat_menu_op   op;
660         Boolean          sensitive;
661
662         /* clear the buffers */
663         memset (rule_buf1, 0, 32);
664         memset (rule_buf2, 0, 32);
665
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. */
670
671         /*
672         **  First, get the value on the repeat menu
673         */
674         XtVaGetValues(rfp->repeat_menu, XmNselectedPosition, &op, NULL);
675         --op;
676
677         switch(op) {
678         case ONE_TIME:
679                 rfp->repeat_type = CSA_X_DT_REPEAT_ONETIME;
680                 strcpy(rule_buf1, "D1 ");
681                 break;
682         case DAILY:
683                 rfp->repeat_type = CSA_X_DT_REPEAT_DAILY;
684                 strcpy(rule_buf1, "D1 ");
685                 break;
686         case WEEKLY:
687                 rfp->repeat_type = CSA_X_DT_REPEAT_WEEKLY;
688                 strcpy(rule_buf1, "W1 ");
689                 break;
690         case EVERY_TWO_WEEKS:
691                 rfp->repeat_type = CSA_X_DT_REPEAT_BIWEEKLY;
692                 strcpy(rule_buf1, "W2 ");
693                 break;
694         case MONTHLY_BY_DATE:
695                 rfp->repeat_type = CSA_X_DT_REPEAT_MONTHLY_BY_DATE;
696                 strcpy(rule_buf1, "MD1 ");
697                 break;
698         case MONTHLY_BY_WEEKDAY: {
699                 int     wk;
700
701                 rfp->repeat_type = CSA_X_DT_REPEAT_MONTHLY_BY_WEEKDAY;
702                 /* 
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.
706                  */
707                 if (weekofmonth(tick, &wk) && wk == 5)
708                         sprintf(rule_buf1, "MP1 1- %s ", dow_str(tick));
709                 else
710                         strcpy(rule_buf1, "MP1 ");
711                 break;
712         }
713         case YEARLY:
714                 rfp->repeat_type = CSA_X_DT_REPEAT_YEARLY;
715                 strcpy(rule_buf1, "YM1 ");
716                 break;
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 ");
720                 break;
721         case MON_WED_FRI:
722                 rfp->repeat_type = CSA_X_DT_REPEAT_MONWEDFRI;
723                 strcpy(rule_buf1, "W1 MO WE FR ");
724                 break;
725         case TUESDAY_THURSDAY:
726                 rfp->repeat_type = CSA_X_DT_REPEAT_TUETHUR;
727                 strcpy(rule_buf1, "W1 TU TH ");
728                 break;
729         case REPEAT_EVERY:
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);
734                         break;
735                 case CSA_X_DT_REPEAT_EVERY_NWEEK:
736                         sprintf(rule_buf1, "W%d ", rfp->repeat_nth);
737                         break;
738                 case CSA_X_DT_REPEAT_EVERY_NMONTH:
739                 default:
740                         sprintf(rule_buf1, "MD%d ", rfp->repeat_nth);
741                         break;
742                 }
743                 break;
744         default:
745                 break;
746         }
747
748         if (op != REPEAT_EVERY)
749                 rfp->repeat_nth = 0;
750
751         /*
752         **  Now get the duration - the for menu and scope.
753         */
754         XtVaGetValues(rfp->for_menu, 
755                         XmNtextField,   &tf, 
756                         NULL);
757         XtVaGetValues(tf,
758                         XmNsensitive,   &sensitive,
759                         NULL);
760
761         if (sensitive) {
762                 char    *forever_str = catgets(calendar->DT_catd, 1, 876, 
763                                                                    "forever"); 
764                 str = XmTextGetString(tf);
765                 if (strcmp(str, forever_str) == 0) {
766                         rfp->for_val = PRIVATE_FOREVER;
767                         strcat(rule_buf2, "#0");
768                 } else {
769                         rfp->for_val = atoi(str);
770                         if (rfp->for_val == 0)
771                                 strcat(rule_buf2, "#1");
772                         else {
773                                 if (op != REPEAT_EVERY) {
774                                         sprintf(rule_buf2, "#%d", rfp->for_val);
775                                 } else {
776                                         int duration;
777
778                                         if (rfp->for_val % rfp->repeat_nth)
779                                                 duration = 1 + 
780                                                    rfp->for_val/rfp->repeat_nth;
781                                         else
782                                                 duration = 
783                                                    rfp->for_val/rfp->repeat_nth;
784
785                                         sprintf(rule_buf2, "#%d", duration);
786                                 }
787                         }
788                 }
789                 XtFree(str);
790         } else {
791                 strcat(rule_buf2, "#1");
792                 rfp->for_val = 0;
793
794         }
795
796         strcat (rule_buf1, rule_buf2);
797
798         if (rfp->recurrence_rule)
799                 free(rfp->recurrence_rule);
800
801         rfp->recurrence_rule = cm_strdup(rule_buf1);
802 }
803
804 extern void
805 get_rfp_privacy_val(RFP *rfp) {
806         int     i;
807
808         XtVaGetValues(rfp->privacy_menu, XmNselectedPosition, &i, NULL);
809         --i;
810
811         switch (i) {
812         
813                 case 0: rfp->privacy_val = CSA_CLASS_PUBLIC;
814                    break;
815         
816                 case 1: rfp->privacy_val = CSA_CLASS_CONFIDENTIAL;
817                    break;
818         
819                 case 2: rfp->privacy_val = CSA_CLASS_PRIVATE;
820                    break;
821
822         }
823 }
824
825 extern void
826 get_rfp_vals(RFP *rfp, time_t tick) {
827         get_rfp_repeat_val(rfp, tick);
828         get_rfp_privacy_val(rfp);
829 }
830
831 /*
832 **  This function will consume form values and stuff them into an appointment.
833 */
834 extern Boolean
835 rfp_form_to_appt(RFP *rfp, Dtcm_appointment *a, char *name)
836 {
837   return rfp_form_flags_to_appt(rfp, a, name, (int *)NULL);
838 }
839
840 extern Boolean
841 rfp_form_flags_to_appt(RFP *rfp, Dtcm_appointment *a, char *name, int *flagsP)
842 {
843         int             wk;
844         char            buf[MAXNAMELEN];
845         time_t          tick;
846         Calendar        *c = rfp->cal;
847         Props_pu        *p = (Props_pu *)rfp->cal->properties_pu;
848         int             flags = 0;
849
850         if (flagsP == (int *)NULL)
851           flagsP = &flags;
852
853         _csa_iso8601_to_tick(a->time->value->item.date_time_value, &tick);
854
855         if (rfp->rfp_form_mgr)
856                 get_rfp_vals(rfp, tick);
857
858         a->private->value->item.sint32_value = rfp->privacy_val;
859
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;
863
864                 if ((a->version == DATAVER3) ||(a->version == DATAVER_ARCHIVE)) {
865                         if (a->repeat_interval)
866                                 a->repeat_interval->value->item.uint32_value =
867                                         rfp->repeat_nth;
868                         if (a->repeat_week_num)
869                                 a->repeat_week_num->value->item.sint32_value =
870                                         -1;
871                 }
872         }
873         else
874                 a->recurrence_rule->value->item.string_value = 
875                                                 cm_strdup(rfp->recurrence_rule);
876
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,
880                                 p->xm_error_pixmap);
881                         return False;
882                 }
883                 if (rfp->repeat_type == CSA_X_DT_REPEAT_MONTHLY_BY_WEEKDAY) {
884                         if (weekofmonth(tick, &wk) && wk == 4)
885                         {
886                             if (*flagsP == 0)
887                             {
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,
893                                                 923, "Cancel"));
894                                 char *ident2 = XtNewString(catgets(c->DT_catd, 1,
895                                                 540, "Last Week"));
896                                 char *ident3 = XtNewString(catgets(c->DT_catd, 1,
897                                                 541, "4th Week"));
898                                 *flagsP = dialog_popup(rfp->parent,
899                                         DIALOG_TITLE, title,
900                                         DIALOG_TEXT, text,
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,
905                                         NULL);
906                                 XtFree(ident3);
907                                 XtFree(ident2);
908                                 XtFree(ident1);
909                                 XtFree(text);
910                                 XtFree(title);
911                             }
912                             switch (*flagsP)
913                             {
914                             case RFP_MBW_LAST:
915                                 change_to_last_week(a, wk, tick, rfp);
916                                 break;
917
918                             case RFP_MBW_4TH:
919                                 if (a->version < DATAVER4)
920                                   a->repeat_week_num->value->item.sint32_value = wk;
921                                 break;
922
923                             default:
924                                 *flagsP = 0;
925                                 return False;
926                             }
927                         } else if (wk != 5)
928                                 if (a->version < DATAVER4)
929                                         a->repeat_week_num->value->item.sint32_value = wk;
930                 }
931                 else
932                 {
933                         if (a->repeat_type == NULL) {
934                                 if ((a->repeat_type =
935                                       (CSA_attribute *)ckalloc(sizeof(CSA_attribute)))
936                                     == NULL)
937                                   /* return (CSA_E_INSUFFICIENT_MEMORY); */
938                                   return False;
939
940                                 memset(a->repeat_type, 0, sizeof(CSA_attribute));
941
942                                 _DtCm_set_sint32_attrval(rfp->repeat_type,
943                                                          &a->repeat_type->value);
944                         }
945                         else a->repeat_type->value->item.sint32_value = rfp->repeat_type;
946                 }
947         }
948         else
949         {
950                 if (a->repeat_type == NULL) {
951                         if ((a->repeat_type =
952                              (CSA_attribute *)ckalloc(sizeof(CSA_attribute)))
953                             == NULL)
954                           /* return (CSA_E_INSUFFICIENT_MEMORY); */
955                           return False;
956
957                         memset(a->repeat_type, 0, sizeof(CSA_attribute));
958
959                         _DtCm_set_sint32_attrval(rfp->repeat_type,&a->repeat_type->value);
960                 }
961                 else a->repeat_type->value->item.sint32_value = rfp->repeat_type;
962         }
963
964         return True;
965 }
966
967 /*
968  * Given a rule, change it to always happen on the last week of the month.
969  */
970 static void
971 change_to_last_week(
972         Dtcm_appointment        *a,
973         int                      wk,
974         time_t                   tick,
975         RFP                     *rfp)
976 {
977         if (a->version < DATAVER4)
978                 return;
979         else {
980                 char    *weekday = dow_str(tick),
981                         *new_rule,
982                          duration_buf[10];
983
984                 memset(duration_buf, 0, 10);
985
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);
989
990                 /* Free the old rule */
991                 free(a->recurrence_rule->value->item.string_value);
992
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");
998                 else {
999                         sprintf(duration_buf, " #%d", rfp->for_val);
1000                         strcat(new_rule, duration_buf);
1001                 }
1002
1003                 a->recurrence_rule->value->item.string_value = new_rule;
1004
1005                 free(weekday);
1006         }
1007 }
1008
1009 /*
1010 **  This function will take appointment values and stuff them into a form.
1011 */
1012 extern Boolean
1013 rfp_appt_to_form(RFP *rfp, CSA_entry_handle entry) {
1014         Boolean                 ret_val;
1015         CSA_return_code         stat;
1016         Dtcm_appointment        *appt;
1017
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,
1026                                     NULL);
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);
1032                 return False;
1033         }
1034
1035         ret_val = rfp_attrs_to_form(rfp, appt);
1036         free_appt_struct(&appt);
1037
1038         return ret_val;
1039 }
1040
1041 extern Boolean
1042 rfp_attrs_to_form(RFP *rfp, Dtcm_appointment *appt) {
1043
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. */
1051
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;
1058                 }
1059                 if (appt->repeat_times && appt->repeat_times->value)
1060                         rfp->for_val = appt->repeat_times->value->item.uint32_value;
1061                 else
1062                         rfp->for_val = 0;
1063
1064                 rfp->privacy_val = privacy_set(appt);
1065                 set_rfp_vals(rfp);
1066         }
1067         else {
1068                 rfp_toggle_for_grey(rfp, False);
1069                 rfp_toggle_repeat_grey(rfp, False);
1070         }
1071
1072         return True;
1073 }
1074
1075 extern void
1076 set_rfp_repeat_val(RFP *rfp) {
1077         char            buf[128];
1078         Boolean         status = True;
1079         XmString        xmstr;
1080         Calendar        *c = rfp->cal;
1081         const char      *repeat_scope;
1082         Repeat_menu_op  op;
1083
1084         /*
1085         **  Set the repeat menu button based on the period value
1086         */
1087         buf[0] = '\0';
1088         if (rfp->repeat_type == CSA_X_DT_REPEAT_ONETIME) {
1089                 op = ONE_TIME;
1090                 repeat_scope = default_repeat_scope_str(c->DT_catd, ONE_TIME);
1091                 sprintf(buf, "%s", repeat_str(c->DT_catd, ONE_TIME));
1092                 status = False;
1093         } else if (rfp->repeat_type == CSA_X_DT_REPEAT_DAILY) {
1094                 op = 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) {
1098                 op = 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;
1103                 repeat_scope = 
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;
1108                 repeat_scope = 
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) {
1118                 op = 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) {
1127                 op = MON_WED_FRI;
1128                 repeat_scope = 
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;
1133                 repeat_scope = 
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) {
1137                 op = REPEAT_EVERY;
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) {
1142                 op = REPEAT_EVERY;
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) {
1147                 op = REPEAT_EVERY;
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);
1151         } else
1152                 return;
1153
1154         /*
1155          * Set the Repeat combo box
1156          */
1157         xmstr = XmStringCreateLocalized(buf);
1158         XtVaSetValues(rfp->repeat_menu, XmNselectedPosition, op + 1, NULL);
1159         XtVaSetValues(rfp->repeat_menu, XmNlabelString, xmstr, NULL);
1160         XmStringFree(xmstr);
1161
1162         /*
1163         **  Set the For button, text item, and scope
1164         */
1165         if (rfp->for_val == CSA_X_DT_DT_REPEAT_FOREVER) {
1166                 if(rfp->repeat_type != CSA_X_DT_REPEAT_ONETIME)
1167                 {
1168                         sprintf(buf, "%s", catgets(c->DT_catd, 1, 876, "forever"));
1169                         xmstr = XmStringCreateLocalized(buf);
1170                         XmComboBoxSetItem(rfp->for_menu, xmstr);
1171                         XmStringFree(xmstr);
1172                 }
1173                 else
1174                 {
1175                         Widget text;
1176                         buf[0]= '\0';
1177                         XtVaGetValues(rfp->for_menu, XmNtextField,
1178                                       &text, NULL);
1179                         XmTextFieldSetString(text, buf);
1180                 }
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);
1187         } else {
1188                 Widget          text;
1189                 sprintf(buf, "%d", rfp->for_val);
1190                 XtVaGetValues(rfp->for_menu, XmNtextField, &text, NULL);
1191                 XmTextFieldSetString(text, buf);
1192         }
1193
1194         xmstr = XmStringCreateLocalized((char *)repeat_scope);
1195         XtVaSetValues(rfp->for_scope, XmNlabelString, xmstr,
1196                 NULL);
1197         XmStringFree(xmstr);
1198
1199         rfp_toggle_for_grey(rfp, status);
1200 }
1201
1202 extern void
1203 set_rfp_privacy_val(RFP *rfp) {
1204         int     i;
1205
1206         if (rfp->privacy_val == CSA_CLASS_PUBLIC)
1207                 i = 0;
1208         else if (rfp->privacy_val == CSA_CLASS_CONFIDENTIAL)
1209                 i = 1;
1210         else
1211                 i = 2;
1212
1213         XtVaSetValues(rfp->privacy_menu, XmNselectedPosition, i + 1, NULL);
1214 }
1215
1216 extern void
1217 set_rfp_vals(RFP *rfp) {
1218         set_rfp_repeat_val(rfp);
1219         set_rfp_privacy_val(rfp);
1220 }
1221
1222 extern void
1223 set_rfp_defaults(RFP *rfp) {
1224         Props           *p = (Props *)rfp->cal->properties;
1225
1226         rfp->for_val = 0;
1227         rfp->privacy_val = convert_privacy_str(get_char_prop(p, CP_PRIVACY));
1228         rfp->repeat_type = CSA_X_DT_REPEAT_ONETIME;
1229
1230         set_rfp_vals(rfp);
1231         rfp_set_default_for(rfp, ONE_TIME, False);
1232 }
1233
1234 static char *
1235 dow_str(
1236         time_t  tick)
1237 {
1238         switch (dow(tick)) {
1239         case 0:
1240                 return (cm_strdup("SU"));
1241         case 1:
1242                 return (cm_strdup("MO"));
1243         case 2:
1244                 return (cm_strdup("TU"));
1245         case 3:
1246                 return (cm_strdup("WE"));
1247         case 4:
1248                 return (cm_strdup("TH"));
1249         case 5:
1250                 return (cm_strdup("FR"));
1251         case 6:
1252         default:
1253                 return (cm_strdup("SA"));
1254         }
1255 }
1256
1257 extern void
1258 rfp_init(
1259         RFP             *rfp,
1260         Calendar        *c,
1261         Widget           parent)
1262 {
1263         Props           *p = (Props *)c->properties;
1264
1265         rfp->parent = parent;
1266         rfp->cal = c;
1267         rfp->for_val = 0;
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");
1271 }