9fc02da1344c524a5f2a95844935195a1c263af4
[oweals/cde.git] / cde / programs / dtlogin / dtchooser.c
1 /* $TOG: dtchooser.c /main/8 1998/04/20 12:56:18 mgreess $ */
2 /*                                                                      *
3  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
4  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
5  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
6  * (c) Copyright 1993, 1994 Novell, Inc.                                *
7  */
8 /*
9  */
10
11  /****************************************************************************
12  **
13  **   File:        dtchooser.c
14  **
15  **   Project:     HP Visual User Environment (DT)
16  **
17  **   Description: Main line code for Dtgreet application
18  **
19  **                These routines initialize the toolkit, create the widgets,
20  **                set up callbacks, and wait for events.
21  **
22  **
23  **   (c) Copyright 1987, 1988, 1989 by Hewlett-Packard Company
24  **
25  **
26  **
27  ****************************************************************************
28  ************************************<+>*************************************/
29
30
31
32 /***************************************************************************
33  *
34  *  Includes
35  *
36  ***************************************************************************/
37
38 #include        <stdio.h>
39 #include        <setjmp.h>
40 #include        <stdlib.h>
41 #include        <unistd.h>
42 #include        <sys/signal.h>
43 #include        <sys/stat.h>
44 #include        <locale.h>
45
46 #include        <Xm/Xm.h>
47 #include        <X11/Shell.h>
48 #include        <X11/cursorfont.h>
49 #include        <Xm/DragC.h>
50 #include        <Xm/DrawingA.h>
51 #include        <Xm/Frame.h>
52 #include        <Xm/Form.h>
53 #include        <Xm/Label.h>
54 #include        <Xm/LabelG.h>
55 #include        <Xm/List.h>
56 #include        <Xm/Text.h>
57 #include        <Xm/TextF.h>
58 #include        <Xm/PushB.h>
59 #include        <Xm/PushBG.h>
60 #include        <Xm/MessageB.h>
61 #include        <Xm/RowColumn.h>
62 #include        <Xm/SeparatoG.h>
63 #include        <Xm/ToggleBG.h>
64 #include        <Xm/CascadeBG.h>
65 #include        <Dt/EnvControlP.h>
66 #include        "vg.h"
67 #include        "vgmsg.h"
68 #include        <Dt/MenuButton.h>
69
70
71
72
73
74 /***************************************************************************
75  *
76  *  External declarations
77  *
78  ***************************************************************************/
79 extern char    password[];  /* pswd string value */
80 extern int     password_length;  /* pswd string length */
81
82 extern void DoAccept (Widget w, XtPointer client_data, XtPointer call_data);
83 extern void DoPing (Widget w, XtPointer client_data, XtPointer call_data);
84
85 /***************************************************************************
86  *
87  *  Procedure declarations
88  *
89  ***************************************************************************/
90
91 static SIGVAL syncTimeout( int arg ) ;
92 static Widget InitToolKit( int argc, char **argv) ;
93 void MakeRootCursor( void ) ;
94 void MakeBackground( void ) ;
95 void MakeButtons( void ) ;
96 void MakeLogin( void ) ;
97 void MakeOptionsProc( XtPointer data, XtIntervalId *id) ;
98 static int  ErrorHandler( Display *dpy, XErrorEvent *event) ;
99 static SIGVAL Terminate( int arg ) ;
100 extern void DoCancel (Widget w, XtPointer client_data, XtPointer call_data);
101
102
103
104
105
106 /***************************************************************************
107  *
108  *  Global variables
109  *
110  ***************************************************************************/
111
112
113 AppInfo         appInfo;        /* application resources                   */
114 Arg             argt[100];      /* used for resources                      */
115 DisplayInfo     dpyinfo;        /* information about the display           */
116 XmString        xmstr;          /* used for compound strings               */
117 char            *langenv;       /* current value of LANG environment var.  */
118 char            *errorLogFile;  /* current value of environment var.       */
119 int             showVerifyError;/* display a Verify() error dialog         */
120 int             fullScreen = 0; /* Obscure the entire screen.              */
121
122
123 /******************************************************************************
124 **
125 **      WIDGET LAYOUT
126 **
127 ** toplevel                 "main"                      (toplevel)
128 **  login_shell              "login_shell"              (overrideShell)
129 **   table                    "table"                   (DrawingAreaWidget)
130 **     copyright_msg            "copyright_msg"         (MessageBox)
131 **     error_message            "error_message"         (MessageBox)
132 **     help_message             "help_message"          (MessageBox)
133 **     passwd_message           "passwd_message"        (MessageBox)
134 **     hostname_message         "hostname_msg"          (MessageBox)
135 **     matte                   "matte"                  (FormWidget)
136 **      logo                   "logo"                   (FrameWidget)
137 **       logo_pixmap            "logo_pixmap"           (LabelGadget)
138 **      matteFrame         "matteFrame"         (FrameWidget)
139 **       matte1                "matte1"                 (FormWidget)
140 **        dt_label                "dt_label"            (LabelGadget)
141 **        help_button             "help_button"         (PushButtonGadget)
142 **        greeting               "greeting"             (LabelGadget)
143 **        login_form               "login_form"         (FormWidget)
144 **          login_label              "login_label"      (LabelGadget)
145 **          login_text               "login_text"       (TextField)
146 **        ok_button               "ok_button"           (PushButtonGadget)
147 **        clear_button            "clear_button"        (PushButtonGadget)
148 **        options_button                  "options_button"      (PushButton)
149 **          options_menu                    "options_menu"      (PopupMenu)
150 **            options_item[0]         "options_languages"    (CascadeButtonGadget)
151 **            options_item[1]         "options_sep2"         (SeparatorGadget)
152 **            options_item[2]         "session_menus"        (CascadeButtonGadget)
153 **            options_item[3]         "options_sep1"         (SeparatorGadget)
154 **            options_item[4]         "options_noWindows"    (PushButtonGadget)
155 **            options_item[5]         "options_restartServer"(PushButtonGadget)
156 **            options_item[6]         "options_sep1"         (SeparatorGadget)
157 **            options_item[7]         "options_Copyright"    (PushButtonGadget)
158 **            session_menu            "session_menu"         (PulldownMenu)
159 **              options_dt            "options_dt"             (ToggleButtonGadget)
160 **              options_failsafe      "options_failsafe"       (ToggleButtonGadget)
161 **            lang_menu               "lang_menu"       (PulldownMenu)
162 **           (lang items)               (lang items)    (ToggleButtonGadget)
163 **      ...
164 **
165 */
166
167
168 extern Widget toplevel;         /* top level shell widget                  */
169 Widget login_shell;             /* shell for the main login widgets.       */
170 Widget table;                   /* black background for everything         */
171 Widget matte;                   /* main level form widget                  */
172 Widget matteFrame;              /* main level form widget                  */
173 Widget matte1;                  /* second level form widget                */
174
175 Widget greeting;                /* Welcome message                         */
176
177 Widget logo1;                   /* frame around the Corporate logo         */
178 Widget logo_pixmap;             /* Corporate logo                          */
179 Widget logo_shadow;             /* drop shadow under the Corporate logo    */
180
181 Widget login_matte;             /* bulletin board for login/password       */
182 Widget dt_label;                /* desktop label showing the current session */
183 Widget login_form = NULL;       /* form containing the login widgets       */
184 Widget login_label;             /* label to left of login text widget      */
185 Widget login_text;              /* login text widget                       */
186
187 Widget ok_button;               /* accept name/password text button        */
188 Widget clear_button;            /* clear name/password text button         */
189 Widget options_button;          /* login options button                    */
190 Widget help_button;             /* help button                             */
191
192 Widget copyright_msg    = NULL; /* copyright notice widget                 */
193 Widget help_message     = NULL; /* the help message box                    */
194 Widget error_message    = NULL; /* the error message box                   */
195 Widget hostname_message = NULL; /* the invalid hostname message box        */
196 Widget passwd_message   = NULL; /* the expired password message box        */
197
198 Widget options_menu = NULL;     /* pop-up menu on options button           */
199 Widget options_item[10];        /* items on options pop_up menu            */
200 Widget options_nowindows;       /* nowindows pane on options pop_up menu   */
201 Widget options_failsafe;        /* failsafe pane on options pop_up menu    */
202 Widget options_dtlite;          /* dtlite  pane on options pop_up menu     */
203 Widget options_dt;              /* dt regular pane on options pop_up menu  */
204
205 Widget *alt_dts;
206 Widget options_sp_dt;           /* dt button for special desktop          */
207 Widget options_last_dt;         /* user's last dt                         */
208
209
210
211 Widget lang_menu = NULL;        /* cascading menu on "Language" option     */
212 Widget session_menu = NULL;     /* cascading menu on "Session" option      */
213
214 Widget chooser_list;            /* list of hosts displayed by chooser      */
215 Widget list_head;               /* the heading for the chooser list        */
216
217
218
219 static
220     XtResource AppResources[] = {
221     { "workspaceCursor", "WorkspaceCursor", 
222         XtRBoolean, sizeof(Boolean), XtOffset(AppInfoPtr, workspaceCursor),
223         XtRImmediate, (caddr_t)False                                    },
224
225     { "labelFont", "LabelFont", 
226         XmRFontList, sizeof(XmFontList), XtOffset(AppInfoPtr, labelFont),
227         XmRString, "Fixed"                                              },
228
229     { "textFont", "TextFont", 
230         XmRFontList, sizeof(XmFontList), XtOffset(AppInfoPtr, textFont),
231         XmRString, "Fixed"                                              },
232
233     { "chlistFont", "ChlistFont",
234         XmRFontList, sizeof(XmFontList), XtOffset(AppInfoPtr, chlistFont),
235         XmRString, "Fixed"                                              },
236
237     { "optionsDelay", "OptionsDelay", 
238         XtRInt, sizeof(int), XtOffset(AppInfoPtr, optionsDelay),
239         XtRImmediate, (XtPointer) 0                                     },
240
241     {"languageList", "LanguageList",
242         XtRString, sizeof(char *), XtOffset(AppInfoPtr, languageList),
243         XtRString, NULL                                                 },
244
245 #if defined (ENABLE_DYNAMIC_LANGLIST)
246     {"languageListCmd", "LanguageListCmd",
247         XtRString, sizeof(char *), XtOffset(AppInfoPtr, languageListCmd),
248         XtRString, NULL                                                 },
249 #endif /* ENABLE_DYNAMIC_LANGLIST */
250
251     };
252
253
254
255
256
257
258
259
260 /***************************************************************************
261  *
262  *  MakeRootCursor
263  *
264  *  Widgets: none
265  ***************************************************************************/
266
267 void 
268 MakeRootCursor( void )
269 {
270         Cursor vg_cursor;
271
272         vg_cursor = XCreateFontCursor (dpyinfo.dpy, XC_left_ptr);
273
274         XDefineCursor (dpyinfo.dpy, dpyinfo.root, vg_cursor);
275
276         return;
277 }
278
279 /***************************************************************************
280  *
281  *  MakeBackground
282  *
283  *  Widgets: login_shell, table, matte
284  ***************************************************************************/
285
286 void 
287 MakeBackground( void )
288 {
289     register int i;
290
291     /*
292      * Get resources first
293      */
294     SetResourceDatabase();
295     XtGetApplicationResources(toplevel, &appInfo, AppResources,
296                                 XtNumber(AppResources), NULL, 0);
297     
298     
299     /* 
300      * create the login shell widget...
301      */
302
303     i = 0;
304
305     /*          CORE resource set                                       */
306     XtSetArg(argt[i], XmNancestorSensitive,     True                    ); i++;
307     XtSetArg(argt[i], XmNbackgroundPixmap,      XmUNSPECIFIED_PIXMAP    ); i++;
308     XtSetArg(argt[i], XmNborderWidth,           0                       ); i++;
309     XtSetArg(argt[i], XmNmappedWhenManaged,     False                   ); i++;
310     XtSetArg(argt[i], XmNsensitive,             True                    ); i++;
311     XtSetArg(argt[i], XmNtranslations,          NULL                    ); i++;
312
313     /*          COMPOSITE resource set                                  */
314     XtSetArg(argt[i], XmNinsertPosition,        NULL                    ); i++;
315
316     /*          SHELL resource set (set to avoid interference by user)  */
317     XtSetArg(argt[i], XmNallowShellResize,      False                   ); i++;
318     XtSetArg(argt[i], XmNcreatePopupChildProc,  NULL                    ); i++;
319     XtSetArg(argt[i], XmNgeometry,              NULL                    ); i++;
320     XtSetArg(argt[i], XmNpopupCallback,         NULL                    ); i++;
321     XtSetArg(argt[i], XmNpopdownCallback,       NULL                    ); i++;
322     XtSetArg(argt[i], XmNoverrideRedirect,      False                   ); i++;
323     XtSetArg(argt[i], XmNsaveUnder,             False                   ); i++;
324
325     login_shell = XtCreatePopupShell("login_shell", transientShellWidgetClass,
326                                      toplevel, argt, i);
327     XtAddCallback(login_shell, XmNpopupCallback, LayoutCB, NULL);
328
329     /* Fix to display Input Method's status area. */
330     XtSetArg(argt[0], XmNheight, dpyinfo.height);
331     XtSetValues(login_shell, argt, 1);
332
333
334     /* 
335      * create the full-screen drawing area...
336      */
337
338     i = InitArg(DrawingA);
339     XtSetArg(argt[i], XmNwidth,                 dpyinfo.width           ); i++;
340     XtSetArg(argt[i], XmNheight,                dpyinfo.height          ); i++;
341     XtSetArg(argt[i], XmNunitType,              XmPIXELS                ); i++;
342
343     table = XtCreateManagedWidget("table", xmDrawingAreaWidgetClass,
344                                    login_shell, argt, i);
345
346     XtAddEventHandler(table, ButtonPressMask, False, RefreshEH, NULL);
347
348
349
350     /* 
351      * create the main matte...
352      */
353
354     i = InitArg(Form);
355     /*                XmNwidth,                 (set by user)           */
356     /*                XmNheight,                (set by user)           */
357     XtSetArg(argt[i], XmNshadowThickness,       SHADOW_THICKNESS        ); i++;
358 /*
359     XtSetArg(argt[i], XmNshadowType,    XmSHADOW_OUT    ); i++;
360     XtSetArg(argt[i], XmNshadowThickness,       5       ); i++;
361 */
362
363     matte = XmCreateForm(table, "matte", argt, i);
364     XtManageChild(matte);
365
366     i = 0;
367         XtSetArg(argt[i], XmNshadowType, XmSHADOW_OUT); i++;
368         XtSetArg(argt[i], XmNshadowThickness, 2); i++;
369         XtSetArg(argt[i], XmNtopAttachment, XmATTACH_FORM); i++;
370         XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_FORM); i++;
371         XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM); i++;
372         /*
373         XtSetArg(argt[i], XmNrightAttachment, XmATTACH_FORM); i++;
374         */
375         XtSetArg(argt[i], XmNtopOffset, 15); i++;
376         XtSetArg(argt[i], XmNbottomOffset, 15); i++;
377         XtSetArg(argt[i], XmNleftOffset, 15); i++;
378         /*
379         XtSetArg(argt[i], XmNrightOffset, 15); i++;
380         */
381         matteFrame = XmCreateFrame(matte, "matteFrame", argt, i);
382     XtManageChild(matteFrame);
383
384         i = 0;
385         matte1 = XmCreateForm(matteFrame, "matte1", argt, i);
386     XtManageChild(matte1);
387         
388 }
389
390
391
392
393 /***************************************************************************
394  *
395  *  MakeButtons
396  *
397  *  Widgets:    ok_button, clear_button, options_button, help_button
398  ***************************************************************************/
399
400 void 
401 MakeButtons( void )
402 {
403     register int i;
404
405     Dimension   width;
406
407     Dimension   max_width;      /* maximum width  of a set of widgets      */
408     Dimension   max_height;     /* maximum height of a set of widgets      */
409
410     int         origin;         /* horizontal origin for button placement  */
411     int         spacing;        /* spacing between buttons (width/32)      */
412
413      
414     /* 
415      * create the buttons...
416      */
417
418     /* ok button */
419     
420     i = InitArg(PushBG);
421     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
422     XtSetArg(argt[i], XmNbottomPosition, 95); i++;
423     XtSetArg(argt[i], XmNtraversalOn, True); i++;
424     XtSetArg(argt[i], XmNleftAttachment,   XmATTACH_FORM);      i++;
425
426     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_OK_LABEL, MC_DEF_OK_LABEL );
427     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
428
429     ok_button = XmCreatePushButtonGadget(matte1, "ok_button", argt, i);
430
431     XmStringFree(xmstr);
432     XtManageChild(ok_button);
433
434     XtAddCallback(ok_button, XmNactivateCallback, DoAccept, NULL);    
435
436
437     /* clear button */
438
439     i -= 2;
440     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_WIDGET);       i++;
441     XtSetArg(argt[i], XmNleftWidget,            ok_button);             i++;
442     xmstr = ReadCatalogXms(MC_CHOOSER_SET, MC_UPDATE_LABEL, MC_DEF_UPDATE_LABEL);
443     XtSetArg(argt[i], XmNlabelString,           xmstr);                 i++;
444
445     clear_button = XmCreatePushButtonGadget(matte1, "clear_button", argt, i);
446
447     XmStringFree(xmstr);
448     XtManageChild(clear_button);
449     XtAddCallback(clear_button, XmNactivateCallback, DoPing,
450                   (XtPointer) 0);   
451
452
453
454     /* help button */
455     
456     i -= 3;
457     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_HELP_LABEL, MC_DEF_HELP_LABEL);
458     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
459
460     help_button = XmCreatePushButtonGadget(matte1, "help_button", argt, i);
461     XtAddCallback(help_button, XmNactivateCallback, ShowDialogCB, 
462                   (XtPointer) help_chooser);
463     XmStringFree(xmstr);
464     XtManageChild(help_button);
465
466
467     i = InitArg(Label);
468     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
469     XtSetArg(argt[i], XmNbottomPosition, 95); i++;
470     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_WIDGET);       i++;
471     XtSetArg(argt[i], XmNleftWidget,            clear_button);          i++;
472     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_OPTIONS_LABEL, MC_DEF_OPTIONS_LABEL );
473     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
474
475     options_button = DtCreateMenuButton(matte1, "options_button", argt, i);
476
477     XmStringFree(xmstr);
478     XtManageChild(options_button);
479
480     /** set attachment for help button **/
481     i = 0;
482     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_WIDGET);       i++;
483     XtSetArg(argt[i], XmNleftWidget,            options_button);        i++;
484     XtSetArg(argt[i], XmNrightAttachment,       XmATTACH_FORM);         i++;
485     XtSetValues(help_button, argt, i);
486
487
488     /*
489      *  tell form that ok_button is the default button...
490      */
491
492     i = 0;
493     XtSetArg(argt[i], XmNdefaultButton,         ok_button               ); i++;
494     XtSetValues(matte1,  argt, i);
495
496     
497
498     /*
499      * make all buttons the same size...
500      */
501      
502
503     max_width = max_height = 0;
504     GetBiggest(ok_button, &max_width, &max_height);
505     GetBiggest(clear_button,   &max_width, &max_height);
506     GetBiggest(options_button, &max_width, &max_height);
507     GetBiggest(help_button,    &max_width, &max_height);
508
509     if ( max_width < MIN_BUTTON_SIZE) max_width = MIN_BUTTON_SIZE;
510     
511     i = 0;
512     XtSetArg(argt[i], XmNwidth,                 max_width               ); i++;
513     XtSetArg(argt[i], XmNheight,                max_height              ); i++;
514     XtSetArg(argt[i], XmNrecomputeSize,         False                   ); i++;
515
516     XtSetValues(ok_button,      argt, i);
517     XtSetValues(clear_button,   argt, i);
518     XtSetValues(options_button, argt, i);
519     XtSetValues(help_button,    argt, i);
520 }
521
522
523 /***************************************************************************
524  *
525  *  MakeChooser
526  *
527  *  Widgets: greeting, list_head, chooser_list
528  ***************************************************************************/
529 typedef  struct {
530     XmFontList  fontList;
531 } GreetInfo, *GreetInfoPtr;
532
533 static GreetInfo greetInfo;
534
535 static  XtResource greetResources[] = {
536     {XmNfontList, XmCFontList,
537         XmRFontList, sizeof(XmFontList),
538         XtOffset(GreetInfoPtr, fontList), XtRString, NULL               }
539 };
540
541 void
542 MakeChooser( void )
543 {
544     int i;
545
546     /** greeting **/
547     XtGetSubresources(table, &greetInfo, "greeting", "Greeting",
548                       greetResources, XtNumber(greetResources), NULL, 0);
549     i = InitArg(LabelG);
550     xmstr = ReadCatalogXms(MC_CHOOSER_SET, MC_CHOOSER_TITLE, MC_DEF_CHOOSER_TITLE);
551     XtSetArg(argt[i], XmNtraversalOn,      False); i++;
552     XtSetArg(argt[i], XmNlabelString,      xmstr); i++;
553     XtSetArg(argt[i], XmNtopAttachment,    XmATTACH_FORM); i++;
554     XtSetArg(argt[i], XmNtopOffset,        10); i++;
555     XtSetArg(argt[i], XmNleftAttachment,   XmATTACH_FORM); i++;
556     XtSetArg(argt[i], XmNrightAttachment,  XmATTACH_FORM); i++;
557     XtSetArg(argt[i], XmNalignment,        XmALIGNMENT_CENTER); i++;
558     if ( greetInfo.fontList != NULL ) {
559         XtSetArg(argt[i], XmNfontList,     greetInfo.fontList); i++;
560     }
561     greeting = XmCreateLabel(matte1, "greeting", argt, i);
562     XtManageChild(greeting);
563     XmStringFree(xmstr);
564
565     /** list head **/
566     i = InitArg(LabelG);
567     xmstr = ReadCatalogXms(MC_CHOOSER_SET, MC_CHOOSER_HEADING,
568                         MC_DEF_CHOOSER_HEADING);
569     XtSetArg(argt[i], XmNtraversalOn,      False); i++;
570     XtSetArg(argt[i], XmNlabelString,      xmstr); i++;
571     XtSetArg(argt[i], XmNtopAttachment,    XmATTACH_WIDGET); i++;
572     XtSetArg(argt[i], XmNtopWidget,        greeting); i++;
573     XtSetArg(argt[i], XmNtopOffset,        10); i++;
574     XtSetArg(argt[i], XmNleftAttachment,   XmATTACH_FORM); i++;
575     XtSetArg(argt[i], XmNleftOffset,       13); i++;
576     if (appInfo.chlistFont != NULL) {
577         XtSetArg(argt[i], XmNfontList,     appInfo.chlistFont); i++;
578     }
579     list_head = XmCreateLabelGadget(matte1, "list_head", argt, i);
580     XtManageChild(list_head);
581     XmStringFree(xmstr);
582
583     i = 0;
584     XtSetArg(argt[i], XmNresizable, True);
585     XtSetValues(matte, argt, i);
586     XtSetValues(matte1, argt, i);
587
588     /** chooser_list **/
589     i = 0;
590     XtSetArg(argt[i], XmNleftAttachment,   XmATTACH_FORM); i++;
591     XtSetArg(argt[i], XmNleftOffset,       10); i++;
592     XtSetArg(argt[i], XmNrightAttachment,  XmATTACH_FORM); i++;
593     XtSetArg(argt[i], XmNrightOffset,      10); i++;
594     XtSetArg(argt[i], XmNtopAttachment,    XmATTACH_WIDGET); i++;
595     XtSetArg(argt[i], XmNtopWidget,        list_head); i++;
596     XtSetArg(argt[i], XmNtopOffset,        1); i++;
597     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
598     XtSetArg(argt[i], XmNbottomWidget,     ok_button); i++;
599     XtSetArg(argt[i], XmNbottomOffset,     10); i++;
600     XtSetArg(argt[i], XmNallowShellResize, True); i++;
601     XtSetArg(argt[i], XmNlistSizePolicy,   XmCONSTANT); i++;
602     XtSetArg(argt[i], XmNscrollBarDisplayPolicy, XmSTATIC); i++;
603     if (appInfo.chlistFont != NULL) {
604         XtSetArg(argt[i], XmNfontList,     appInfo.chlistFont); i++;
605     }
606     chooser_list = XmCreateScrolledList(matte1, "chooser_list", argt, i);
607     XtAddCallback(chooser_list, XmNdefaultActionCallback, DoAccept, NULL);
608     XtManageChild(chooser_list);
609
610     if (appInfo.workspaceCursor)
611     {
612         MakeRootCursor();
613     }
614     else
615     {
616         XUndefineCursor(dpyinfo.dpy, dpyinfo.root);
617     }
618 }
619
620
621 /***************************************************************************
622  *
623  *  MakeDialog
624  *
625  *  Widgets: error_message, help_message, copyright_msg, hostname_message,
626  *           passwd_message
627  ***************************************************************************/
628
629 void 
630 MakeDialog( DialogType dtype )
631 {
632     register int i, j;
633
634     int         width;
635     
636     FILE        *fp, *fopen();
637     char        buffer[128];
638     char        *str;
639
640     Widget      w, text;
641     Dimension   txt_width, txt_height;
642     XmString    ok, cancel, nw, sv;
643     
644     
645     /*
646      *  do things common to all dialogs...
647      */
648
649     ok     = ReadCatalogXms(MC_LABEL_SET, MC_OK_LABEL, MC_DEF_OK_LABEL);
650     cancel = ReadCatalogXms(MC_LABEL_SET, MC_CANCEL_LABEL, MC_DEF_CANCEL_LABEL);
651
652     i = InitArg(MessageBox);
653     XtSetArg(argt[i], XmNmarginHeight,          MBOX_MARGIN_HEIGHT      ); i++;
654     XtSetArg(argt[i], XmNmarginWidth,           MBOX_MARGIN_WIDTH       ); i++;
655     XtSetArg(argt[i], XmNshadowThickness,       SHADOW_THICKNESS        ); i++;
656     XtSetArg(argt[i], XmNokLabelString,         ok                      ); i++;
657     XtSetArg(argt[i], XmNcancelLabelString,     cancel                  ); i++;
658     XtSetArg(argt[i], XmNnoResize,              False                   ); i++;
659     XtSetArg(argt[i], XmNresizePolicy,          XmRESIZE_ANY            ); i++;
660
661     /*
662      *  create the various dialogs...
663      */
664
665     switch (dtype) {
666
667     case error:
668         xmstr = ReadCatalogXms(MC_ERROR_SET, MC_LOGIN, "");
669         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
670
671         w = XmCreateErrorDialog(table, "error_message", argt, i);
672         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
673         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
674
675         error_message = w;
676         break;
677
678
679     case help:
680         xmstr = ReadCatalogXms(MC_HELP_SET, MC_HELP, MC_DEF_HELP);
681         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
682         w = XmCreateInformationDialog(table, "help_message", argt, i);
683         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
684         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
685
686         txt_width = DisplayWidth (XtDisplay(w), DefaultScreen(XtDisplay(w)));
687         txt_height = DisplayHeight (XtDisplay(w), DefaultScreen(XtDisplay(w)));
688         txt_width = (txt_width > 850) ? 800 : txt_width - 50;
689         txt_height = (txt_height > 900) ? 750 : txt_height - 150;
690         i = InitArg(Text);
691         XtSetArg(argt[i], XmNheight, txt_height); i++;
692         XtSetArg(argt[i], XmNwidth, txt_width); i++;
693         XtSetArg(argt[i], XmNeditMode, XmMULTI_LINE_EDIT); i++;
694         XtSetArg(argt[i], XmNscrollBarDisplayPolicy, XmAS_NEEDED); i++;
695         XtSetArg(argt[i], XmNscrollingPolicy, XmAUTOMATIC); i++;
696         XtSetArg(argt[i], XmNeditable, False); i++;
697         str = (char*) ReadCatalog(MC_HELP_SET, MC_HELP, MC_DEF_HELP);
698         XtSetArg(argt[i], XmNvalue, strdup(str)); i++;
699         text = XmCreateScrolledText(w, "help_message_text", argt, i);
700
701         XtManageChild(text);
702         XtManageChild(w);
703         help_message = w;
704         break;
705
706
707     case copyright:
708         if ((fp = fopen(COPYRIGHT,"r")) == NULL)
709 #if defined( __hp_osf )
710             xmstr = XmStringCreate("Cannot open copyright file '/usr/X11/copyright'.",
711                                 XmFONTLIST_DEFAULT_TAG);
712 #else
713             xmstr = XmStringCreate("Cannot open copyright file '/etc/copyright'.",
714                                 XmFONTLIST_DEFAULT_TAG);
715 #endif
716         else {
717             xmstr = (XmString) NULL;
718         
719             while (fgets(buffer, 128, fp) != NULL) {
720                 j = strlen(buffer);
721                 if ( buffer[j-1] == '\n' ) buffer[j-1] = '\0';
722             
723                 if ( xmstr != NULL )
724                     xmstr = XmStringConcat(xmstr, XmStringSeparatorCreate());
725
726                 xmstr = XmStringConcat(xmstr,
727                                        XmStringCreate(buffer,
728                                        XmFONTLIST_DEFAULT_TAG));
729             }       
730         }
731
732         fclose(fp);
733         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
734
735         w = XmCreateInformationDialog(table, "copyright_msg", argt, i);
736         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
737         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
738         
739         XtAddCallback(w, XmNokCallback, CopyrightCB, (XtPointer) 0);    
740
741         copyright_msg = w;
742         break;
743     
744
745     case hostname:
746             
747         nw = ReadCatalogXms(MC_LABEL_SET, MC_NW_LABEL,  MC_DEF_NW_LABEL);
748         sv = ReadCatalogXms(MC_LABEL_SET, MC_START_LABEL, MC_DEF_START_LABEL);
749
750         xmstr = ReadCatalogXms(MC_HELP_SET, MC_SYSTEM, MC_DEF_SYSTEM);
751         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
752         XtSetArg(argt[i], XmNokLabelString,             nw              ); i++;
753         XtSetArg(argt[i], XmNcancelLabelString,         sv              ); i++;
754
755         w = XmCreateWarningDialog(table, "hostname_msg", argt, i);
756
757         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
758
759         XmStringFree(nw);
760         XmStringFree(sv);
761
762         hostname_message = w;
763         break;
764
765
766     case expassword:
767
768         xmstr = ReadCatalogXms(MC_ERROR_SET, MC_PASSWD_EXPIRED, 
769                             MC_DEF_PASSWD_EXPIRED);
770         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
771
772         w = XmCreateQuestionDialog(table, "password_msg", argt, i);
773
774         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
775
776         passwd_message = w;
777         break;
778
779
780     case help_chooser:
781         xmstr = ReadCatalogXms(MC_HELP_SET, MC_HELP_CHOOSER, MC_DEF_HELP_CHOOSER);
782
783         w = XmCreateInformationDialog(table, "help_message", argt, i);
784         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
785         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
786
787         txt_width = DisplayWidth (XtDisplay(w), DefaultScreen(XtDisplay(w)));
788         txt_height = DisplayHeight (XtDisplay(w), DefaultScreen(XtDisplay(w)));
789         txt_width = (txt_width > 850) ? 800 : txt_width - 50;
790         txt_height = (txt_height > 900) ? 750 : txt_height - 150;
791         i = InitArg(Text);
792         XtSetArg(argt[i], XmNheight, txt_height); i++;
793         XtSetArg(argt[i], XmNwidth, txt_width); i++;
794         XtSetArg(argt[i], XmNeditMode, XmMULTI_LINE_EDIT); i++;
795         XtSetArg(argt[i], XmNscrollBarDisplayPolicy, XmAS_NEEDED); i++;
796         XtSetArg(argt[i], XmNscrollingPolicy, XmAUTOMATIC); i++;
797         XtSetArg(argt[i], XmNeditable, False); i++;
798         str = (char*)
799               ReadCatalog(MC_HELP_SET, MC_HELP_CHOOSER, MC_DEF_HELP_CHOOSER);
800         XtSetArg(argt[i], XmNvalue, strdup(str)); i++;
801         text = XmCreateScrolledText(w, "help_message_text", argt, i);
802
803         XtManageChild(text);
804         XtManageChild(w);
805         help_message = w;
806         break;
807     }
808
809     /*
810      *  finish up...
811      */
812
813     switch (dtype) {
814       case error:
815       case hostname:
816       case expassword:
817         XtAddCallback(w, XmNokCallback,     RespondDialogCB, NULL);
818         XtAddCallback(w, XmNcancelCallback, RespondDialogCB, NULL);
819         break;
820     }
821
822
823     XtSetArg(argt[0], XmNdialogStyle,   XmDIALOG_APPLICATION_MODAL      ); i++;
824     XtSetValues(w, argt, 1);
825
826     XmStringFree(xmstr);
827     XmStringFree(ok);
828     XmStringFree(cancel);
829
830
831     /*
832      *  adjust the width of the "ok" button on the dialogs...
833      */
834
835     width = (dtype == hostname ? FromMM(4000) : MIN_BUTTON_SIZE);
836     
837     i = 0;
838     XtSetArg(argt[i], XmNrecomputeSize,                 False           ); i++;
839     XtSetArg(argt[i], XmNwidth,                         width           ); i++;
840
841     XtSetValues(XmMessageBoxGetChild(w, XmDIALOG_OK_BUTTON), argt, i);
842
843 }
844
845
846
847 /***************************************************************************
848  *
849  *  MakeOptionsMenu
850  *
851  *  Widgets: options_menu, options_item[]
852  ***************************************************************************/
853
854 void 
855 MakeOptionsMenu( void )
856 {
857     int         i, j, k;
858
859     struct stat statb;
860
861
862     /*
863      * get the built-in pop_up menu from the DtMenuButton...
864      */
865      
866     XtVaGetValues(options_button, DtNsubMenuId, &options_menu, NULL);
867
868     /*
869      *  create language cascade menus...
870      */
871
872     if ( lang_menu == NULL )
873         MakeLangMenu();
874
875
876     /*
877      *  create first level menu items...
878      */
879     j = 0;
880
881     /*
882      *  build [ Language ] menu pane if there are languages to choose from...
883      */
884     if ( lang_menu != NULL ) {
885         /*
886          *  [ Language ] menu pane...
887          *  attach language cascade menu to this pane
888          */
889         i = InitArg(CascadeBG);
890         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_LANG_LABEL, MC_DEF_LANG_LABEL);
891         XtSetArg(argt[i], XmNlabelString,               xmstr           ); i++;
892         XtSetArg(argt[i], XmNsubMenuId,                 lang_menu       ); i++;
893         XtSetArg(argt[i], XmNrecomputeSize,             True            ); i++;
894         options_item[j] = XmCreateCascadeButtonGadget(options_menu,
895                                 "options_languages", argt, i);
896         XmStringFree(xmstr);
897         j++;
898
899         /*
900          *  separator...
901          */
902         i = InitArg(SeparatorG);
903         options_item[j] = XmCreateSeparatorGadget(options_menu,
904                                                     "options_sep2",
905                                                      argt, i);
906         j++;
907     }
908
909
910     /* 
911      *  [ Restart Server ] menu pane...
912      */
913     i = k = InitArg(PushBG);
914     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_RS_LABEL, MC_DEF_RS_LABEL);
915     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
916     options_item[j] = XmCreatePushButtonGadget(options_menu,
917                                                  "options_restartServer",
918                                                  argt, i); 
919     XmStringFree(xmstr);
920     XtAddCallback(options_item[j], XmNactivateCallback, 
921                   DoCancel, (XtPointer) OB_RESTART_SERVER);
922     j++;
923
924 #ifdef copyright_option
925     /*
926      *  separator...
927      */
928     i = InitArg(SeparatorG);
929     options_item[j] = XmCreateSeparatorGadget(options_menu, "options_sep1",
930                                                 argt, i);
931     j++;
932
933
934     /* 
935      *  [ Copyright ] menu pane...
936      */
937     i = k = InitArg(PushBG);
938     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_COPY_LABEL, MC_DEF_COPY_LABEL);
939     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
940     options_item[j] = XmCreatePushButtonGadget(options_menu, 
941                                                  "options_copyright",
942                                                  argt, i);
943     XmStringFree(xmstr);
944     XtAddCallback(options_item[j], XmNactivateCallback, 
945                   MenuItemCB, (XtPointer) OB_COPYRIGHT);
946     j++;
947 #endif
948
949     /*
950      *  manage the [Options] menu...
951      */
952     XtManageChildren(options_item, j);
953
954
955
956     /*
957      *  If the DT Lite Session Manager is not available, remove the DT Lite
958      *  and DT menu panes. The actual widgets must still be created since
959      *  other code (ex. MenuItemCB()) tries to obtain some of their resources.
960      */
961      
962     if  ( stat(DTLITESESSION, &statb) != 0 ||
963           ((statb.st_mode & S_IXOTH) != S_IXOTH) ) {
964
965 /*
966         XtUnmanageChild(options_dt);
967 */
968     }
969
970     if ( getenv(PINGINTERVAL) != NULL )
971         XtUnmanageChild(options_nowindows);
972         
973
974 }
975
976
977
978
979
980 /***************************************************************************
981  *
982  *  ErrorHandler
983  *
984  *  X protocol error handler to override the default
985  ***************************************************************************/
986
987 static int 
988 ErrorHandler( Display *dpy, XErrorEvent *event )
989 {
990     return;
991 }
992
993
994
995
996 /***************************************************************************
997  *
998  *  MakeOptionsProc
999  *
1000  *  Timeout routine to build options menu
1001  ***************************************************************************/
1002
1003 void 
1004 MakeOptionsProc( XtPointer data, XtIntervalId *id )
1005 {
1006
1007     if (options_menu == NULL)
1008         MakeOptionsMenu();
1009     
1010     return;
1011 }
1012
1013
1014
1015
1016 /***************************************************************************
1017  *
1018  *  Terminate
1019  *
1020  *  Catch a SIGTERM and unmanage display
1021  ***************************************************************************/
1022
1023 static SIGVAL
1024 Terminate( int arg )
1025
1026 {
1027     write(1, "terminate", 9);
1028     CleanupAndExit(NULL, NOTIFY_ABORT);
1029 }
1030
1031 #ifdef SIA
1032 /*
1033  * Chooser doesn't use SIA but it does link with vgcallback.o.  We just need
1034  * this symbol to keep the linker happy.
1035  */
1036
1037 void SiaForm()
1038 {
1039 return;
1040 }
1041
1042 #endif