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