Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtcm / dtcm / props.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: props.c /main/9 1996/03/25 10:22:39 rswiston $ */
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 <stdlib.h>
32 #include <malloc.h>
33 #include <Xm/Xm.h>
34 #include <Xm/Form.h>
35 #include <Xm/LabelG.h>
36 #include <Xm/List.h>
37 #include <Xm/DialogS.h>
38 #include <Xm/PushB.h>
39 #include <Xm/SeparatoG.h>
40 #include <Xm/Text.h>
41 #include <Xm/ToggleBG.h>
42 #include <csa.h>
43 #include "props_pu.h"
44 #include "help.h"
45 #include "calendar.h"
46 #include "deskset.h"
47
48 #define GAP             10
49 #define TOG_GAP         10
50 #define RIGHT_GAP       85  /* Space between text field and right edge */
51 #define MAX_LABEL_SPACE 55
52 #define INDICATOR_SIZE  20
53
54 extern unsigned int p_gap_convert_permissions(Props_pu *);
55 extern void gap_list_select_proc(Widget, XtPointer, XtPointer);
56 extern void p_gap_remove_proc(Widget, XtPointer, XtPointer);
57 extern void p_set_change(Props_pu *);
58 extern Dimension ComputeMaxWidth(Widget, Widget, Widget, Widget);
59
60 static void GAPAddProc(Widget, XtPointer, XtPointer);
61 static void GAPChangeProc(Widget, XtPointer, XtPointer);
62 static Widget CreatePermissions(Props_pu *, Widget, Widget, Dimension,
63                                 Dimension);
64 static int ChangeExistingGAPEntry(Props_pu *);
65
66 extern void
67 v5_gap_pending_change(Widget w, XtPointer data, XtPointer cbs) {
68         Props_pu *p = (Props_pu *) data;
69
70         if (p->v5_gap_pending_message_up == False) {
71                 p->v5_gap_pending_message_up = True;
72                 XtSetSensitive(p->gap2_add_button, True);
73         }
74 }
75
76 extern void
77 v5_gap_clear_pending_change(Props_pu *p) {
78  
79         p->v5_gap_pending_message_up = False;
80         XtSetSensitive(p->gap2_add_button, False);
81 }
82
83
84
85 extern void
86 p_create_v5_group_access_pane(
87         Props_pu *p)
88 {
89         Calendar *c =    calendar;
90         XmString         xstr = NULL;
91         int              i = 0;
92         Widget           gap2_form_mgr;
93         Dimension        max_left_label_width,
94                          max_button_label_width,
95                          tmp;
96         Arg              args[20]; 
97         XtWidgetGeometry geo;
98
99         gap2_form_mgr =
100             XtVaCreateWidget("gap2_form_mgr",
101                 xmFormWidgetClass,
102                 p->base_form_mgr,
103                 XmNtopAttachment,               XmATTACH_WIDGET,
104                 XmNtopWidget,                   p->separator1,
105                 XmNleftAttachment,              XmATTACH_FORM,
106                 XmNrightAttachment,             XmATTACH_FORM,
107                 XmNrightOffset,                 0,
108                 XmNbottomAttachment,            XmATTACH_WIDGET,
109                 XmNbottomOffset,                GAP,
110                 XmNbottomWidget,                p->separator2,
111                 NULL);
112
113         p->pane_list[GROUP_ACCESS_PANE] = gap2_form_mgr;
114
115         /* 
116          * Create our three left hand side labels first in order to figure
117          * out the offset required between the middle widgets and the left
118          * side.
119          */
120         xstr = XmStringCreateLocalized(
121                                 catgets(c->DT_catd, 1, 410, "User Name:"));
122         p->gap2_user_label =
123             XtVaCreateWidget("gap2_label_user_name",
124                 xmLabelGadgetClass,
125                 gap2_form_mgr,
126                 XmNlabelType,                   XmSTRING,
127                 XmNlabelString,                 xstr,
128                 NULL);
129
130         XmStringFree(xstr);
131
132         xstr = XmStringCreateLocalized(
133                                 catgets(c->DT_catd, 1, 738, "Access List:"));
134         p->gap2_access_label =
135             XtVaCreateWidget("gap2_label_access",
136                 xmLabelGadgetClass,
137                 gap2_form_mgr,
138                 XmNlabelType,                   XmSTRING,
139                 XmNlabelString,                 xstr,
140                 NULL);
141
142         XmStringFree(xstr);
143
144         xstr = XmStringCreateLocalized(
145                                 catgets(c->DT_catd, 1, 739, "Access Rights:"));
146         p->gap2_permissions_label =
147             XtVaCreateWidget("gap2_label_permissions",
148                 xmLabelGadgetClass,
149                 gap2_form_mgr,
150                 XmNlabelType,                   XmSTRING,
151                 XmNlabelString,                 xstr,
152                 NULL);
153
154         XmStringFree(xstr);
155
156         max_left_label_width = ComputeMaxWidth(p->gap2_user_label,
157                                                p->gap2_access_label,
158                                                p->gap2_permissions_label,
159                                                NULL)
160                                                + 2 * GAP;
161
162         p->gap2_user_text =
163             XtVaCreateWidget("gap2_text_user_name",
164                 xmTextWidgetClass,
165                 gap2_form_mgr,
166                 XmNmaxLength,                   80,
167                 XmNbottomAttachment,            XmATTACH_NONE,
168                 XmNleftAttachment,              XmATTACH_FORM,
169                 XmNleftOffset,                  max_left_label_width,
170                 XmNtopAttachment,               XmATTACH_FORM,
171                 XmNtopOffset,                   GAP,
172                 NULL);
173         p->gap_user_text = p->gap2_user_text;
174
175         XtAddCallback(p->gap_user_text, XmNvalueChangedCallback, 
176                                         v5_gap_pending_change, (XtPointer)p);
177
178         p->gap2_perm_form = CreatePermissions(p, gap2_form_mgr,
179                                               p->gap2_user_text,
180                                               max_left_label_width, RIGHT_GAP);
181
182         p->gap2_button_form =
183             XtVaCreateWidget("gap2_button_form_mgr",
184                 xmFormWidgetClass,
185                 gap2_form_mgr,
186                 XmNtopAttachment,               XmATTACH_WIDGET,
187                 XmNtopWidget,                   p->gap2_perm_form,
188                 XmNtopOffset,                   GAP,
189                 XmNrightAttachment,             XmATTACH_FORM,
190                 XmNrightOffset,                 GAP,
191                 NULL);
192
193         xstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 740, "Add"));
194         p->gap2_add_button =
195             XtVaCreateWidget("gap2_button_add",
196                 xmPushButtonWidgetClass,
197                 p->gap2_button_form,
198                 XmNleftAttachment,              XmATTACH_FORM,
199                 XmNleftOffset,                  0,
200                 XmNtopAttachment,               XmATTACH_FORM,
201                 XmNtopOffset,                   5,
202                 XmNalignment,                   XmALIGNMENT_CENTER,
203                 XmNlabelType,                   XmSTRING,
204                 XmNlabelString,                 xstr,
205                 NULL);
206
207         XmStringFree(xstr);
208         XtAddCallback(p->gap2_add_button, XmNactivateCallback, GAPAddProc, p);
209
210         xstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 419, "Delete"));
211         p->gap2_delete_button =
212             XtVaCreateWidget("gap2_button_delete",
213                 xmPushButtonWidgetClass,
214                 p->gap2_button_form,
215                 XmNleftAttachment,              XmATTACH_FORM,
216                 XmNleftOffset,                  0,
217                 XmNtopAttachment,               XmATTACH_WIDGET,
218                 XmNtopWidget,                   p->gap2_add_button,
219                 XmNtopOffset,                   GAP,
220                 XmNalignment,                   XmALIGNMENT_CENTER,
221                 XmNlabelType,                   XmSTRING,
222                 XmNlabelString,                 xstr,
223                 NULL);
224         p->gap_remove_button = p->gap2_delete_button; 
225
226         XmStringFree(xstr);
227         XtAddCallback(p->gap2_delete_button, XmNactivateCallback,
228                       p_gap_remove_proc, p);
229
230         xstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 343, "Change"));
231         p->gap2_change_button =
232             XtVaCreateWidget("gap2_button_change",
233                 xmPushButtonWidgetClass,
234                 p->gap2_button_form,
235                 XmNleftAttachment,              XmATTACH_FORM,
236                 XmNleftOffset,                  0,
237                 XmNtopAttachment,               XmATTACH_WIDGET,
238                 XmNtopWidget,                   p->gap2_delete_button,
239                 XmNtopOffset,                   GAP,
240                 XmNalignment,                   XmALIGNMENT_CENTER,
241                 XmNlabelType,                   XmSTRING,
242                 XmNlabelString,                 xstr,
243                 NULL);
244
245         XmStringFree(xstr);
246         XtAddCallback(p->gap2_change_button, XmNactivateCallback, GAPChangeProc,
247                       p);
248
249         max_button_label_width = ComputeMaxWidth(p->gap2_add_button,
250                                                  p->gap2_delete_button,
251                                                  p->gap2_change_button,
252                                                  NULL);
253
254         XtVaSetValues(p->gap2_add_button,
255                 XmNrightAttachment,             XmATTACH_OPPOSITE_FORM,
256                 XmNrightOffset,                 -max_button_label_width,
257                 NULL);
258         XtVaSetValues(p->gap2_delete_button,
259                 XmNrightAttachment,             XmATTACH_OPPOSITE_FORM,
260                 XmNrightOffset,                 -max_button_label_width,
261                 NULL);
262         XtVaSetValues(p->gap2_change_button,
263                 XmNrightAttachment,             XmATTACH_OPPOSITE_FORM,
264                 XmNrightOffset,                 -max_button_label_width,
265                 NULL);
266
267         p->gap_list = NULL;
268         XtSetArg(args[i], XmNscrollBarDisplayPolicy,    XmAUTOMATIC);       ++i;
269         XtSetArg(args[i], XmNlistSizePolicy,            XmVARIABLE);        ++i;
270         XtSetArg(args[i], XmNvisibleItemCount,          10);                ++i;
271         XtSetArg(args[i], XmNrightAttachment,           XmATTACH_WIDGET);   ++i;
272         XtSetArg(args[i], XmNrightWidget,               p->gap2_button_form); ++i;
273         XtSetArg(args[i], XmNrightOffset,               GAP * 2);         ++i;
274         XtSetArg(args[i], XmNleftAttachment,            XmATTACH_FORM);     ++i;
275         XtSetArg(args[i], XmNleftOffset,                max_left_label_width);
276                                                                             ++i;
277         XtSetArg(args[i], XmNtopAttachment,             XmATTACH_WIDGET);   ++i;
278         XtSetArg(args[i], XmNtopOffset,                 GAP);               ++i;
279         XtSetArg(args[i], XmNtopWidget,                 p->gap2_perm_form); ++i;
280         XtSetArg(args[i], XmNbottomAttachment,          XmATTACH_WIDGET);   ++i;
281         XtSetArg(args[i], XmNbottomOffset,              0);                 ++i;
282         XtSetArg(args[i], XmNbottomWidget,              p->separator2);     ++i;
283         XtSetArg(args[i], XmNdoubleClickInterval,       5);                 ++i;
284
285         p->gap2_access_list =
286             XmCreateScrolledList(gap2_form_mgr, "gap2_access_list", args, i);
287         p->gap_access_list = p->gap2_access_list;
288
289         XtAddCallback(p->gap2_access_list, XmNbrowseSelectionCallback,
290                                            gap_list_select_proc, p);
291
292         XtManageChild(p->gap2_access_list);
293
294         XtQueryGeometry( p->gap2_button_form, NULL, &geo );
295
296         XtVaSetValues( p->gap2_user_text,
297                         XmNrightAttachment, XmATTACH_FORM,
298                         XmNrightOffset, geo.width + GAP + GAP,
299                         NULL );
300         XtVaSetValues( p->gap2_perm_form,
301                         XmNrightAttachment, XmATTACH_FORM,
302                         XmNrightOffset, geo.width + GAP + GAP,
303                         NULL );
304
305
306         ManageChildren(p->gap2_button_form);
307
308         XtVaSetValues(p->gap2_user_label,
309                 XmNtopAttachment,               XmATTACH_FORM,
310                 XmNtopOffset,                   GAP,
311                 XmNrightAttachment,             XmATTACH_WIDGET,
312                 XmNrightWidget,                 p->gap2_user_text,
313                 XmNrightOffset,                 5,
314                 NULL);
315
316         XtVaSetValues(p->gap2_permissions_label,
317                 XmNtopAttachment,               XmATTACH_WIDGET,
318                 XmNtopWidget,                   p->gap2_user_text,
319                 XmNtopOffset,                   GAP,
320                 XmNrightAttachment,             XmATTACH_WIDGET,
321                 XmNrightWidget,                 p->gap2_perm_form,
322                 XmNrightOffset,                 5,
323                 NULL);
324
325         XtVaSetValues(p->gap2_access_label,
326                 XmNtopAttachment,               XmATTACH_WIDGET,
327                 XmNtopWidget,                   p->gap2_perm_form,
328                 XmNtopOffset,                   GAP,
329                 XmNrightAttachment,             XmATTACH_WIDGET,
330                 XmNrightWidget,                 p->gap2_access_list,
331                 XmNrightOffset,                 5,
332                 NULL);
333
334         ManageChildren(gap2_form_mgr);
335 }
336
337 static Widget
338 CreatePermissions(
339         Props_pu        *p,
340         Widget           parent,
341         Widget           widget_above,
342         Dimension        left_gap,
343         Dimension        right_gap) 
344 {
345         Calendar *c =    calendar;
346         Widget           perm_form;
347         int              n,
348                          max_label_width,
349                          label_offset;
350         Dimension        tog_width,
351                          view_label_width,
352                          insert_label_width,
353                          change_label_width;
354         XmString         xstr = NULL,
355                          xstr_empty = NULL;
356
357         /* Create the box containing the permission settings */
358
359         perm_form =
360             XtVaCreateWidget("gap2_perm_form_mgr",
361                 xmFormWidgetClass,
362                 parent,
363                 XmNleftAttachment,              XmATTACH_FORM,
364                 XmNleftOffset,                  left_gap,
365                 XmNtopAttachment,               XmATTACH_WIDGET,
366                 XmNtopWidget,                   widget_above,
367                 XmNtopOffset,                   GAP,
368                 XmNshadowThickness,             1,
369                 XmNshadowType,                  XmSHADOW_IN,
370                 NULL);
371
372         xstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 743, "Public:"));
373         p->gap2_public_label =
374             XtVaCreateWidget("gap2_public_label",
375                 xmLabelGadgetClass,
376                 perm_form,
377                 XmNlabelString,                 xstr,
378                 NULL);
379
380         XmStringFree (xstr);
381
382         xstr = XmStringCreateLocalized(
383                                 catgets(c->DT_catd, 1, 744, "Semiprivate:"));
384         p->gap2_semi_label =
385             XtVaCreateWidget("gap2_semi_label",
386                 xmLabelGadgetClass,
387                 perm_form,
388                 XmNlabelString,                 xstr,
389                 XmNleftAttachment,              XmATTACH_FORM,
390                 XmNleftOffset,                  10,
391                 NULL);
392
393         XmStringFree (xstr);
394
395         xstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 745, "Private:"));
396         p->gap2_private_label =
397             XtVaCreateWidget("gap2_private_label",
398                 xmLabelGadgetClass,
399                 perm_form,
400                 XmNlabelString,                 xstr,
401                 NULL);
402
403         XmStringFree (xstr);
404
405         /* Margin to the left of the View label */
406         max_label_width = ComputeMaxWidth(p->gap2_public_label,
407                                           p->gap2_semi_label,
408                                           p->gap2_private_label,
409                                           NULL) + 2 * GAP;
410
411         /* Create the labels and toggles for the permissions */
412
413         xstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 40, "View"));
414         p->gap2_view_label =
415             XtVaCreateWidget("gap2_view_label",
416                 xmLabelGadgetClass,
417                 perm_form,
418                 XmNlabelString,                 xstr,
419                 XmNleftAttachment,              XmATTACH_FORM,
420                 XmNleftOffset,                  max_label_width,
421                 XmNtopAttachment,               XmATTACH_FORM,
422                 XmNtopOffset,                   GAP,
423                 NULL);
424
425         XmStringFree (xstr);
426
427         XtVaGetValues(p->gap2_view_label,
428                 XmNwidth,       &view_label_width,
429                 NULL);
430
431         /* 
432          * If label is greater than the allocated space for the
433          * label, then we use a 0 offset.
434          */
435 #ifdef __ppc
436         label_offset = MAX_LABEL_SPACE;
437         label_offset -= view_label_width;
438 #else
439         label_offset = MAX_LABEL_SPACE - view_label_width;
440 #endif /* __ppc */
441         if (label_offset < 0) label_offset = 0;
442
443         xstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 342, "Insert"));
444
445         p->gap2_insert_label =
446             XtVaCreateWidget("gap2_insert_label",
447                 xmLabelGadgetClass,
448                 perm_form,
449                 XmNlabelString,                 xstr,
450                 XmNleftAttachment,              XmATTACH_WIDGET,
451                 XmNleftWidget,                  p->gap2_view_label,
452                 XmNleftOffset,                  label_offset,
453                 XmNtopAttachment,               XmATTACH_FORM,
454                 XmNtopOffset,                   GAP,
455                 NULL);
456
457         XmStringFree (xstr);
458
459         XtVaGetValues(p->gap2_insert_label,
460                 XmNwidth,       &insert_label_width,
461                 NULL);
462
463         xstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 343, "Change"));
464
465         /* 
466          * If label is greater than the allocated space for the
467          * label, then we use a 0 offset.
468          */
469 #ifdef __ppc
470         label_offset = MAX_LABEL_SPACE;
471         label_offset -= insert_label_width;
472 #else
473         label_offset = MAX_LABEL_SPACE - insert_label_width;
474 #endif /* __ppc */
475         if (label_offset < 0) label_offset = 0;
476
477         p->gap2_change_label =
478             XtVaCreateWidget("gap2_change_label",
479                 xmLabelGadgetClass,
480                 perm_form,
481                 XmNlabelString,                 xstr,
482                 XmNleftAttachment,              XmATTACH_WIDGET,
483                 XmNleftWidget,                  p->gap2_insert_label,
484                 XmNleftOffset,                  label_offset,
485                 XmNtopAttachment,               XmATTACH_FORM,
486                 XmNtopOffset,                   GAP,
487                 NULL);
488
489         XmStringFree (xstr);
490
491         XtVaGetValues(p->gap2_change_label,
492                 XmNwidth,       &change_label_width,
493                 NULL);
494
495         xstr_empty = XmStringCreateLocalized("");
496         p->gap2_public_tog[GAP_VIEW] =
497             XtVaCreateWidget("gap2_public_view_tog",
498                 xmToggleButtonGadgetClass,
499                 perm_form,
500                 XmNlabelString,                 xstr_empty,
501                 XmNleftAttachment,              XmATTACH_OPPOSITE_WIDGET,
502                 XmNleftWidget,                  p->gap2_view_label,
503                 XmNtopAttachment,               XmATTACH_WIDGET,
504                 XmNtopWidget,                   p->gap2_view_label,
505                 XmNtopOffset,                   TOG_GAP,
506                 XmNindicatorSize,               INDICATOR_SIZE,
507                 NULL);
508
509         XtVaGetValues(p->gap2_public_tog[GAP_VIEW],
510                 XmNwidth,                       &tog_width,
511                 NULL);
512
513         /*
514          * Center the toggle item under the label above it.
515          */
516         XtVaSetValues(p->gap2_public_tog[GAP_VIEW],
517                 XmNleftOffset,                  view_label_width/2 -
518                                                         (int)(tog_width * 3)/8,
519                 NULL);
520
521         p->gap2_public_tog[GAP_INSERT] =
522             XtVaCreateWidget("gap2_public_insert_tog",
523                 xmToggleButtonGadgetClass,
524                 perm_form,
525                 XmNlabelString,                 xstr_empty,
526                 XmNleftAttachment,              XmATTACH_OPPOSITE_WIDGET,
527                 XmNleftWidget,                  p->gap2_insert_label,
528                 XmNleftOffset,                  insert_label_width/2 -
529                                                         (int)(tog_width * 3)/8,
530                 XmNtopAttachment,               XmATTACH_WIDGET,
531                 XmNtopWidget,                   p->gap2_insert_label,
532                 XmNtopOffset,                   TOG_GAP,
533                 XmNindicatorSize,               INDICATOR_SIZE,
534                 NULL);
535
536         p->gap2_public_tog[GAP_CHANGE] =
537             XtVaCreateWidget("gap2_public_change_tog",
538                 xmToggleButtonGadgetClass,
539                 perm_form,
540                 XmNlabelString,                 xstr_empty,
541                 XmNleftAttachment,              XmATTACH_OPPOSITE_WIDGET,
542                 XmNleftWidget,                  p->gap2_change_label,
543                 XmNleftOffset,                  change_label_width/2 - 
544                                                         (int)(tog_width * 3)/8,
545                 XmNtopAttachment,               XmATTACH_WIDGET,
546                 XmNtopWidget,                   p->gap2_change_label,
547                 XmNtopOffset,                   TOG_GAP,
548                 XmNindicatorSize,               INDICATOR_SIZE,
549                 NULL);
550
551         p->gap2_semi_tog[GAP_VIEW] =
552             XtVaCreateWidget("gap2_semi_view_tog",
553                 xmToggleButtonGadgetClass,
554                 perm_form,
555                 XmNlabelString,                 xstr_empty,
556                 XmNleftAttachment,              XmATTACH_OPPOSITE_WIDGET,
557                 XmNleftWidget,                  p->gap2_public_tog[GAP_VIEW],
558                 XmNtopAttachment,               XmATTACH_WIDGET,
559                 XmNtopWidget,                   p->gap2_public_tog[GAP_VIEW],
560                 XmNtopOffset,                   TOG_GAP,
561                 XmNindicatorSize,               INDICATOR_SIZE,
562                 NULL);
563
564         p->gap2_semi_tog[GAP_INSERT] =
565             XtVaCreateWidget("gap2_semi_insert_tog",
566                 xmToggleButtonGadgetClass,
567                 perm_form,
568                 XmNlabelString,                 xstr_empty,
569                 XmNleftAttachment,              XmATTACH_OPPOSITE_WIDGET,
570                 XmNleftWidget,                  p->gap2_public_tog[GAP_INSERT],
571                 XmNtopAttachment,               XmATTACH_WIDGET,
572                 XmNtopWidget,                   p->gap2_public_tog[GAP_INSERT],
573                 XmNtopOffset,                   TOG_GAP,
574                 XmNindicatorSize,               INDICATOR_SIZE,
575                 NULL);
576                 
577         p->gap2_semi_tog[GAP_CHANGE] =
578             XtVaCreateWidget("gap2_semi_change_tog",
579                 xmToggleButtonGadgetClass,
580                 perm_form,
581                 XmNlabelString,                 xstr_empty,
582                 XmNleftAttachment,              XmATTACH_OPPOSITE_WIDGET,
583                 XmNleftWidget,                  p->gap2_public_tog[GAP_CHANGE],
584                 XmNtopAttachment,               XmATTACH_WIDGET,
585                 XmNtopWidget,                   p->gap2_public_tog[GAP_CHANGE],
586                 XmNtopOffset,                   TOG_GAP,
587                 XmNindicatorSize,               INDICATOR_SIZE,
588                 NULL);
589
590         p->gap2_private_tog[GAP_VIEW] =
591             XtVaCreateWidget("gap2_private_view_tog",
592                 xmToggleButtonGadgetClass,
593                 perm_form,
594                 XmNlabelString,                 xstr_empty,
595                 XmNleftAttachment,              XmATTACH_OPPOSITE_WIDGET,
596                 XmNleftWidget,                  p->gap2_semi_tog[GAP_VIEW],
597                 XmNtopAttachment,               XmATTACH_WIDGET,
598                 XmNtopWidget,                   p->gap2_semi_tog[GAP_VIEW],
599                 XmNtopOffset,                   TOG_GAP,
600                 XmNindicatorSize,               INDICATOR_SIZE,
601                 NULL);
602
603         p->gap2_private_tog[GAP_INSERT] =
604             XtVaCreateWidget("gap2_private_insert_tog",
605                 xmToggleButtonGadgetClass,
606                 perm_form,
607                 XmNlabelString,                 xstr_empty,
608                 XmNleftAttachment,              XmATTACH_OPPOSITE_WIDGET,
609                 XmNleftWidget,                  p->gap2_semi_tog[GAP_INSERT],
610                 XmNtopAttachment,               XmATTACH_WIDGET,
611                 XmNtopWidget,                   p->gap2_semi_tog[GAP_INSERT],
612                 XmNtopOffset,                   TOG_GAP,
613                 XmNindicatorSize,               INDICATOR_SIZE,
614                 NULL);
615                 
616         p->gap2_private_tog[GAP_CHANGE] =
617             XtVaCreateWidget("gap2_private_change_tog",
618                 xmToggleButtonGadgetClass,
619                 perm_form,
620                 XmNlabelString,                 xstr_empty,
621                 XmNleftAttachment,              XmATTACH_OPPOSITE_WIDGET,
622                 XmNleftWidget,                  p->gap2_semi_tog[GAP_CHANGE],
623                 XmNtopAttachment,               XmATTACH_WIDGET,
624                 XmNtopWidget,                   p->gap2_semi_tog[GAP_CHANGE],
625                 XmNtopOffset,                   TOG_GAP,
626                 XmNindicatorSize,               INDICATOR_SIZE,
627                 NULL);
628
629         XmStringFree (xstr_empty);
630
631         XtVaSetValues(p->gap2_public_label,
632                 XmNtopAttachment,               XmATTACH_OPPOSITE_WIDGET,
633                 XmNtopWidget,                   p->gap2_public_tog[GAP_VIEW],
634                 XmNrightAttachment,             XmATTACH_WIDGET,
635                 XmNrightWidget,                 p->gap2_public_tog[GAP_VIEW],
636                 XmNrightOffset,                 2 * GAP,
637                 NULL);
638
639         XtVaSetValues(p->gap2_semi_label,
640                 XmNtopAttachment,               XmATTACH_OPPOSITE_WIDGET,
641                 XmNtopWidget,                   p->gap2_semi_tog[GAP_VIEW],
642                 XmNrightAttachment,             XmATTACH_WIDGET,
643                 XmNrightWidget,                 p->gap2_public_tog[GAP_VIEW],
644                 XmNrightOffset,                 2 * GAP,
645                 NULL);
646
647         XtVaSetValues(p->gap2_private_label,
648                 XmNtopAttachment,               XmATTACH_OPPOSITE_WIDGET,
649                 XmNtopWidget,                   p->gap2_private_tog[GAP_VIEW],
650                 XmNrightAttachment,             XmATTACH_WIDGET,
651                 XmNrightWidget,                 p->gap2_public_tog[GAP_VIEW],
652                 XmNrightOffset,                 2 * GAP,
653                 XmNbottomAttachment,            XmATTACH_FORM,
654                 XmNbottomOffset,                GAP,
655                 NULL);
656
657         /* Margin to the right of the Change label */
658         XtVaSetValues(p->gap2_change_label,
659                 XmNmarginRight,                 GAP,
660                 NULL);
661
662         ManageChildren(perm_form);
663         return (perm_form);
664 }
665
666 static void
667 GAPAddProc(
668         Widget                   w,
669         XtPointer                client_data,
670         XtPointer                callback_struct)
671 {
672         Calendar                *c = calendar;
673         Props_pu                *p = (Props_pu *)client_data;
674         CSA_flags                access_rights;
675         CSA_access_rights       *access_entry,
676                                 *access_list_ptr;
677         char                    *user_name;
678         XmString                 xmstr;
679
680         /*
681          * Get the necessary strings from the UI.
682          */
683         if (!(access_rights = p_gap_convert_permissions(p)))
684                  return;
685
686         /* Get the user's name and host */
687         if (!(user_name = (char *)XmTextGetString(p->gap2_user_text)) ||
688             !*user_name) {
689                 char *title = XtNewString(catgets(c->DT_catd, 1, 750, 
690                               "Calendar : Error - Access List and Permissions"));
691                 char *text = XtNewString(catgets(c->DT_catd, 1, 749,
692                       "Name and Access Rights must be set to add an item to the Access List."));
693                 char *ident1 = XtNewString(catgets(c->DT_catd, 1, 95,
694                                                    "Continue"));
695
696                 XtFree(user_name);
697                 dialog_popup(p->frame,
698                         DIALOG_TITLE, title,
699                         DIALOG_TEXT, text,
700                         BUTTON_IDENT, 1, ident1,
701                         BUTTON_HELP, ACCESS_RIGHTS_ERROR_HELP,
702                         DIALOG_IMAGE, p->xm_error_pixmap,
703                         NULL);
704                 XtFree(ident1);
705                 XtFree(text);
706                 XtFree(title);
707                 return;
708         }
709
710         xmstr = XmStringCreateLocalized(user_name);
711
712         /* See if the item is already in the list */
713         if (p->gap_list) {
714                 int     list_pos = XmListItemPos(p->gap_access_list, xmstr);
715
716                 if (list_pos) {
717                         XmListSelectPos(p->gap_access_list, list_pos, False);
718                         XmListSetBottomPos(p->gap_access_list, list_pos);
719                         XtSetSensitive(p->gap2_change_button, True);
720                         XtSetSensitive(p->gap2_delete_button, True);
721
722                         /* Does the user want us to change an existing item? */
723                         if (!ChangeExistingGAPEntry(p)) {
724                                 /* No */
725                                 XtFree(user_name);
726                                 XmStringFree(xmstr);
727                                 return;
728                         }
729
730                         /* Find the entry and change the rights. */
731                         access_list_ptr = p->gap_list;
732                         do {
733                                 if (!strcmp(access_list_ptr->user->user_name,
734                                                                    user_name)) {
735                                         access_list_ptr->rights = access_rights;
736                                         p->changed_flag = True;
737                                         p_set_change(p);
738                                         XtFree(user_name);
739                                         XmStringFree(xmstr);
740                                         return;
741                                 }
742                         } while (access_list_ptr = access_list_ptr->next);
743                 }
744         }
745
746         /* Create a new access entry and add it to the end of the list */
747         access_entry = 
748                 (CSA_access_rights *)ckalloc(sizeof(CSA_access_rights));
749         access_entry->user = 
750                 (CSA_calendar_user *)ckalloc(sizeof(CSA_calendar_user));
751         access_entry->user->user_name = cm_strdup(user_name);
752         access_entry->rights = access_rights;
753         access_entry->next = NULL;
754
755         if (!p->gap_list) { 
756                 p->gap_list = access_entry;
757         } else {
758                 access_list_ptr = p->gap_list;
759                 while (access_list_ptr->next)
760                         access_list_ptr = access_list_ptr->next;
761                 access_list_ptr->next = access_entry;
762         }
763
764         XmListAddItem(p->gap_access_list, xmstr, 0);
765         p->changed_flag = True;
766         p_set_change(p);
767         XtFree(user_name);
768         XmStringFree(xmstr);
769 }
770
771 static int
772 ChangeExistingGAPEntry(
773         Props_pu        *p)
774 {
775         Calendar        *c = calendar;
776         int              answer;
777
778         char *title = XtNewString(catgets(c->DT_catd, 1, 1078, 
779                         "Calendar : Access List and Permissions - Add"));
780         char *text = XtNewString(catgets(c->DT_catd, 1, 751,
781                 "This entry already exists in the Access List.  Do you wish to change it?"));
782         char *ident1 = XtNewString(catgets(c->DT_catd, 1, 343,
783                         "Change"));
784         char *ident2 = XtNewString(catgets(c->DT_catd, 1, 923,
785                         "Cancel"));
786
787         answer = dialog_popup(p->frame,
788                 DIALOG_TITLE, title,
789                 DIALOG_TEXT, text,
790                 BUTTON_IDENT, 2, ident2,
791                 BUTTON_IDENT, 1, ident1,
792                 NULL);
793         XtFree(ident2);
794         XtFree(ident1);
795         XtFree(text);
796         XtFree(title);
797
798         if (answer == 1)
799                 return False;
800         return True;
801 }
802
803 static void
804 GAPChangeProc(
805         Widget                   w,
806         XtPointer                client_data,
807         XtPointer                callback_struct)
808 {
809         Calendar                *c = calendar;
810         Props_pu                *p = (Props_pu *)client_data;
811         CSA_access_list          step = p->gap_list, 
812                                  last = NULL;
813         int                     *item_list = NULL,
814                                  item_cnt = 0;
815         CSA_flags                access_rights;
816         CSA_access_rights       *access_entry;
817         char                    *user_name;
818         XmString                 xmstr;
819
820
821         /* An item to change must be selected in the access list */
822         if (!XmListGetSelectedPos(p->gap2_access_list, &item_list, &item_cnt)) {
823                 char *title = XtNewString(catgets(c->DT_catd, 1, 750,
824                               "Calendar : Error - Access List and Permissions"));
825                 char *text = XtNewString(catgets(c->DT_catd, 1, 408,
826                               "Please select a name first.                   "));
827                 char *ident1 = XtNewString(catgets(c->DT_catd, 1, 95, "Continue"));
828                 dialog_popup(p->frame,
829                         DIALOG_TITLE, title,
830                         DIALOG_TEXT, text,
831                         BUTTON_IDENT, 1, ident1,
832                         DIALOG_IMAGE, p->xm_error_pixmap,
833                         NULL);
834                 XtFree(ident1);
835                 XtFree(text);
836                 XtFree(title);
837                 return;
838         }
839
840         /*
841          * Get the necessary strings from the UI.
842          */
843         if (!(access_rights = p_gap_convert_permissions(p)))
844                  return;
845
846         /* Get the user's name and host */
847         if (!(user_name = (char *)XmTextGetString(p->gap2_user_text)) ||
848             !*user_name) {
849                 char *title = XtNewString(catgets(c->DT_catd, 1, 750, 
850                               "Calendar : Error - Access List and Permissions"));
851                 char *text = XtNewString(catgets(c->DT_catd, 1, 756,
852                       "Name and Access rights must be set to change an item in the Access List"));
853                 char *ident1 = XtNewString(catgets(c->DT_catd, 1, 95, "Continue"));
854
855                 XtFree(user_name);
856                 dialog_popup(p->frame,
857                         DIALOG_TITLE, title,
858                         DIALOG_TEXT, text,
859                         BUTTON_IDENT, 1, ident1,
860                         DIALOG_IMAGE, p->xm_error_pixmap,
861                         NULL);
862                 XtFree(ident1);
863                 XtFree(text);
864                 XtFree(title);
865                 return;
866         }
867
868         xmstr = XmStringCreateLocalized(user_name);
869
870         /* Create a new access entry and add it to the end of the list */
871         access_entry = 
872                 (CSA_access_rights *)ckalloc(sizeof(CSA_access_rights));
873         access_entry->user = 
874                 (CSA_calendar_user *)ckalloc(sizeof(CSA_calendar_user));
875         access_entry->user->user_name = cm_strdup(user_name);
876         access_entry->rights = access_rights;
877         access_entry->next = NULL;
878
879         /*
880          * Find and change the Access_Entry/name from the list.
881          */
882         item_cnt = 1;
883         while(item_cnt < *item_list) {
884                 last = step;
885                 step = step->next;
886                 ++item_cnt;
887         }
888
889         if (last)
890                 last->next = access_entry;
891         else     
892                 p->gap_list = access_entry;
893  
894         access_entry->next = step->next;
895
896         free(step->user);
897         free(step);
898  
899         XmListReplaceItemsPos(p->gap2_access_list, &xmstr, 1, *item_list);
900
901         p->changed_flag = True;
902         p_set_change(p);
903
904         XmStringFree(xmstr);
905         XtFree((XtPointer)item_list);
906 }