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