Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[oweals/cde.git] / cde / programs / dtlogin / vgmain.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: vgmain.c /main/19 1998/09/14 18:31:11 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  **   File:        vgmain.c
34  **
35  **   Project:     HP Visual User Environment (DT)
36  **
37  **   Description: Main line code for Dtgreet application
38  **
39  **                These routines initialize the toolkit, create the widgets,
40  **                set up callbacks, and wait for events.
41  **
42  **
43  **   (c) Copyright 1987, 1988, 1989 by Hewlett-Packard Company
44  **
45  **
46  **
47  ****************************************************************************
48  ************************************<+>*************************************/
49
50
51
52 /***************************************************************************
53  *
54  *  Includes
55  *
56  ***************************************************************************/
57
58 #include        <stdio.h>
59 #include        <setjmp.h>
60 #include        <stdlib.h>
61 #include        <unistd.h>
62 #include        <sys/signal.h>
63 #include        <sys/stat.h>
64 #include        <sys/param.h>
65 #include        <locale.h>
66 #include        <netdb.h>
67
68 #include        <Xm/Xm.h>
69 #include        <X11/Xfuncs.h>
70 #include        <X11/Shell.h>
71 #include        <X11/cursorfont.h>
72 #include        <Xm/DragC.h>
73 #include        <Xm/DrawingA.h>
74 #include        <Xm/Frame.h>
75 #include        <Xm/Form.h>
76 #include        <Xm/Label.h>
77 #include        <Xm/LabelG.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 #ifdef USE_XINERAMA
94 #include <DtXinerama.h>
95 #endif
96
97 #if !defined(NL_CAT_LOCALE)
98 #define NL_CAT_LOCALE 0
99 #endif
100
101 #define LOCALHOST "%LocalHost%"
102 #define DISPLAYNAME "%DisplayName%"
103
104 /***************************************************************************
105  *
106  *  External declarations
107  *
108  ***************************************************************************/
109 extern char    password[];  /* pswd string value */
110 extern int     password_length;  /* pswd string length */
111
112
113 /***************************************************************************
114  *
115  *  Procedure declarations
116  *
117  ***************************************************************************/
118
119 static SIGVAL syncTimeout( int arg ) ;
120 static Widget InitToolKit( int argc, char **argv) ;
121 static void MakeRootCursor( void ) ;
122 static void MakeBackground( void ) ;
123 static void MakeButtons( void ) ;
124 static void MakeDtlabel( void );        
125 static void MakeGreeting( void ) ;
126 static void MakeLogin( void ) ;
127 static void MyInsert( Widget w, XEvent *event, char **params,
128                         Cardinal *num_params) ;
129 static void MyBackspace( Widget w, XEvent *event, char **params,
130                         Cardinal *num_params) ;
131 static int  ErrorHandler( Display *dpy, XErrorEvent *event) ;
132 static void xtErrorHandler( String msg ) ;
133 static void xtWarningHandler( String msg ) ;
134 static void MakeOptionsProc( XtPointer data, XtIntervalId *id) ;
135 static SIGVAL Terminate( int arg ) ;
136 static char * GetLangName( char * label );
137 static void MakeAltDtButtons( void );   
138 static void DebugWidgetResources(Widget w);
139 static char * GetDisplayName();
140
141
142
143
144
145 /***************************************************************************
146  *
147  *  Global variables
148  *
149  ***************************************************************************/
150
151
152 AppInfo         appInfo;        /* application resources                   */
153 Arg             argt[100];      /* used for resources                      */
154 DisplayInfo     dpyinfo;        /* information about the display           */
155 XmString        xmstr;          /* used for compound strings               */
156 char            *errorLogFile;  /* current value of environment var.       */
157 int             showVerifyError;/* display a Verify() error dialog         */
158
159 char            altdtname[MAXPATHLEN];
160 char            altdtclass[MAXPATHLEN];
161 char            altdtkey[MAXPATHLEN];
162 char            altdtkeyclass[MAXPATHLEN];
163 char            altdtstart[MAXPATHLEN];
164 char            altdtstartclass[MAXPATHLEN];
165 char            altdtlogo[MAXPATHLEN];
166 char            altlogoclass[MAXPATHLEN];
167 char            *langenv;
168 char            *logotype;        /* for XrmGetResource()                  */
169 XrmValue        logovalue;        /* for XrmGetResource()                    */
170 char            *rmtype;  
171 XrmValue        rmvalue;     
172 char            *keyrmtype;   
173 XrmValue        keyrmvalue;   
174
175 /******************************************************************************
176 **
177 **      WIDGET LAYOUT
178 **
179 ** toplevel                 "main"                      (toplevel)
180 **  login_shell              "login_shell"              (overrideShell)
181 **   table                    "table"                   (DrawingAreaWidget)
182 **     copyright_msg            "copyright_msg"         (MessageBox)
183 **     error_message            "error_message"         (MessageBox)
184 **     help_message             "help_message"          (MessageBox)
185 **     passwd_message           "passwd_message"        (MessageBox)
186 **     hostname_message         "hostname_msg"          (MessageBox)
187 **     matte                   "matte"                  (FormWidget)
188 **      logo                   "logo"                   (FrameWidget)
189 **       logo_pixmap            "logo_pixmap"           (LabelGadget)
190 **      matteFrame         "matteFrame"         (FrameWidget)
191 **       matte1                "matte1"                 (FormWidget)
192 **        help_button             "help_button"         (PushButtonGadget)
193 **        greeting               "greeting"             (LabelGadget)
194 **        dt_label               "dt_label"             (LabelGadget)   
195 **        login_form               "login_form"         (FormWidget)
196 **          login_label              "login_label"      (LabelGadget)
197 **          login_text               "login_text"       (TextField)
198 **          passwd_text              "passwd_text"      (TextField)
199 **        ok_button               "ok_button"           (PushButtonGadget)
200 **        clear_button            "clear_button"        (PushButtonGadget)
201 **        options_button                  "options_button"      (DtMenuButtonWidget)
202 **          options_menu                    "options_menu"      (PopupMenu)
203 **            options_item[0]         "options_languages"    (CascadeButtonGadget)
204 **            options_item[1]         "options_sep2"         (SeparatorGadget)
205 **            options_item[2]         "session_menus"        (CascadeButtonGadget)
206 **            options_item[3]         "options_sep1"         (SeparatorGadget)
207 **            options_item[4]         "options_noWindows"    (PushButtonGadget)
208 **            options_item[5]         "options_restartServer"(PushButtonGadget)
209 **            options_item[6]         "options_sep1"         (SeparatorGadget)
210 **            options_item[7]         "options_Copyright"    (PushButtonGadget)
211 **            session_menu            "session_menu"         (PulldownMenu)
212 **              options_dt            "options_dt"             (ToggleButtonGadget)
213 **              options_failsafe      "options_failsafe"       (ToggleButtonGadget)
214 **            lang_menu               "lang_menu"       (PulldownMenu)
215 **           (lang items)               (lang items)    (ToggleButtonGadget)
216 **      ...
217 **
218 */
219
220
221 Widget toplevel;                /* top level shell widget                  */
222 Widget login_shell;             /* shell for the main login widgets.       */
223 Widget table;                   /* black background for everything         */
224 Widget matte;                   /* main level form widget                  */
225 Widget matteFrame;              /* main level form widget                  */
226 Widget matte1;              /* second level form widget            */
227
228 Widget greeting;                /* Welcome message                         */
229 Widget dt_label;                /* Desktop i.e. set in options menu        */
230
231 Widget logo1;                   /* frame around the Corporate logo         */
232 Widget logo_pixmap;             /* Corporate logo                          */
233 Widget logo_shadow;             /* drop shadow under the Corporate logo    */
234
235 Widget login_matte;             /* bulletin board for login/password       */
236 Widget login_form;              /* form containing the login widgets       */
237 Widget login_label;             /* label to left of login text widget      */
238 Widget login_text;              /* login text widget                       */
239
240 Widget ok_button;               /* accept name/password text button        */
241 Widget clear_button;            /* clear name/password text button         */
242 Widget options_button;          /* login options button                    */
243 Widget help_button;             /* help button                             */
244
245 Widget copyright_msg    = NULL; /* copyright notice widget                 */
246 Widget help_message     = NULL; /* the help message box                    */
247 Widget error_message    = NULL; /* the error message box                   */
248 Widget hostname_message = NULL; /* the invalid hostname message box        */
249 Widget passwd_message   = NULL; /* the expired password message box        */
250
251 Widget options_menu = NULL;     /* pop-up menu on options button           */
252 Widget options_item[10];        /* items on options pop_up menu            */
253 Widget options_nowindows;       /* nowindows pane on options pop_up menu   */
254 Widget options_failsafe;        /* failsafe pane on options pop_up menu    */
255 Widget options_dtlite;          /* dtlite  pane on options pop_up menu     */
256 Widget *alt_dts;                /* alt_dts  widgets on options pop_up menu */
257 Widget options_dt;              /* dt regular pane on options pop_up menu */
258 Widget options_last_dt;         /* user's last dt                         */
259
260 Widget lang_menu = NULL;        /* cascading menu on "Language" option     */
261 Widget session_menu = NULL;     /* cascading menu on "Session" option     */
262
263
264 /***************************************************************************
265  *
266  *  Text widget actions and translations
267  *
268  ***************************************************************************/
269
270 static XtActionsRec textActions[] = {
271         {"my-insert", (XtActionProc)MyInsert},
272         {"my-bksp", (XtActionProc)MyBackspace},
273     };
274
275 static char textEventBindings[] = {
276 "Shift <Key>Tab:                        prev-tab-group() \n\
277   Ctrl <Key>Tab:                        next-tab-group() \n\
278  <Key>osfEndLine:                       end-of-line() \n\
279  <Key>osfBeginLine:                     beginning-of-line() \n\
280  ~Shift <Key>osfRight:                  forward-character()\n\
281  ~Shift <Key>osfLeft:                   backward-character()\n\
282   Ctrl <Key>osfDelete:                  delete-to-end-of-line()\n\
283  <Key>osfDelete:                        delete-next-character()\n\
284   <Key>osfBackSpace:                    my-bksp()\n\
285  <Key>osfActivate:                      activate()\n\
286   Ctrl <Key>Return:                     activate()\n\
287  <Key>Return:                           activate()\n\
288  <Key>:                                 my-insert()\n\
289  ~Ctrl ~Shift ~Meta ~Alt<Btn1Down>:     grab-focus() \n\
290  <EnterWindow>:                         enter()\n\
291  <LeaveWindow>:                         leave()\n\
292  <FocusIn>:                             focusIn()\n\
293  <FocusOut>:                            focusOut()\n\
294  <Unmap>:                               unmap()"
295 };
296
297
298 static
299     XtResource AppResources[] = {
300     { "workspaceCursor", "WorkspaceCursor", 
301         XtRBoolean, sizeof(Boolean), XtOffset(AppInfoPtr, workspaceCursor),
302         XtRImmediate, (caddr_t)False                                    },
303
304     { "labelFont", "LabelFont", 
305         XmRFontList, sizeof(XmFontList), XtOffset(AppInfoPtr, labelFont),
306         XmRString, "Fixed"                                              },
307
308     { "textFont", "TextFont", 
309         XmRFontList, sizeof(XmFontList), XtOffset(AppInfoPtr, textFont),
310         XmRString, "Fixed"                                              },
311
312     { "optionsDelay", "OptionsDelay", 
313         XtRInt, sizeof(int), XtOffset(AppInfoPtr, optionsDelay),
314         XtRImmediate, (XtPointer) 0                                     },
315
316     { "altDts",        "AltDts",
317         XtRInt, sizeof(int), XtOffset(AppInfoPtr, altDts),
318         XtRImmediate, (XtPointer) 0
319         },
320
321     {"languageList", "LanguageList",
322         XtRString, sizeof(char *), XtOffset(AppInfoPtr, languageList),
323         XtRString, NULL                                                 },
324
325 #if defined(USE_XINERAMA)
326     { "xineramaPreferredScreen",        "XineramaPreferredScreen",
327         XtRInt, sizeof(int), XtOffset(AppInfoPtr, xineramaPreferredScreen),
328         XtRImmediate, (XtPointer) 0
329         },
330 #endif
331
332 #if defined (ENABLE_DYNAMIC_LANGLIST)
333     {"languageListCmd", "LanguageListCmd",
334         XtRString, sizeof(char *), XtOffset(AppInfoPtr, languageListCmd),
335         XtRString, NULL                                                 },
336 #endif /* ENABLE_DYNAMIC_LANGLIST */
337
338     };
339
340
341
342
343 /***************************************************************************
344  *
345  *  Main
346  *
347  ***************************************************************************/
348
349
350 int 
351 main( int argc, char **argv )
352 {
353
354     char        *session;
355     int         i;              /* index for argt                          */
356     char        **p;            /* temp pointer to traverse argv           */
357     Boolean     nograb=FALSE;   /* debugging option to not grab server/key */
358     int         debug=0;        /* print debugging output */
359
360 #ifdef VG_TRACE
361     vg_TRACE_EXECUTION("--------------------- main ------------------------");
362 #endif /* VG_TRACE */
363
364     setlocale(LC_ALL, "");
365     XtSetLanguageProc( NULL, NULL, NULL );
366     langenv = getenv("LANG");
367     
368     /*
369      *  set TERM signal handler...
370      */
371      
372      (void) signal(SIGTERM, Terminate);
373
374     
375 #ifdef BLS
376 # ifndef NDEBUG
377     {
378         extern SIGVAL BLS_ToggleDebug( int arg );
379
380             /*
381              * Allow debug output to be turned on for dtgreet.
382              */
383
384              (void) signal(SIGHUP, BLS_ToggleDebug);
385
386     }
387 #   endif       /* NDEBUG */
388     /*
389      *  set up authorization parameters, see the identity(3) man page...
390      */
391
392     if (ISSECURE) {
393         set_auth_parameters(1, argv);
394         init_security();
395     }
396 #endif /* BLS */
397
398          
399     /*
400      *  check some environment variables...
401      */
402
403     errorLogFile = getenv(ERRORLOG);
404         
405 #ifdef sun
406     if (getenv("OPENWINHOME") == NULL) putenv(OWPATH_ENV);
407 #endif
408
409     _DtEnvControl( DT_ENV_SET );
410
411     /*
412      * set custom error handler for X protocol errors...
413      */
414
415     XSetErrorHandler(ErrorHandler);
416
417
418     /*
419      * scan argv looking for display name...
420      */
421      
422     showVerifyError = 0;
423     
424     for ( i = argc, p = argv; i > 0; i--, p++ ) {
425         if ( strcmp(*p, "-display") == 0) {
426             p++;
427             i--;
428             dpyinfo.name = malloc(strlen(*p) + 1);
429             strcpy(dpyinfo.name, *p);
430             continue;
431         }
432
433         if ( strcmp(*p, "-debug") == 0) {
434             p++;
435             i--;
436             debug = atoi(*p);
437             continue;
438         }
439
440         if ( strcmp(*p, "-nograb") == 0) {
441             nograb = TRUE;
442             continue;
443         }
444
445         if ( strcmp(*p, "-showerror") == 0) {
446             p++;
447             i--;
448             showVerifyError = atoi(*p);
449             continue;
450         }
451     }
452  
453 #ifdef VG_TRACE
454     vg_TRACE_EXECUTION("main: after options.");
455 #endif /* VG_TRACE */
456 #ifdef VG_DEBUG
457   #ifdef __hpux
458     while (1) {}
459   #else
460     LogError((unsigned char *) "main:  sleeping %d seconds.\n", debug);
461     if (debug) {
462         sleep(debug);
463     }
464   #endif /* __hpux */
465 #endif /* VG_DEBUG */
466
467     /*
468      * initialize the Intrinsics...
469      */
470      
471     toplevel = InitToolKit(argc, argv);
472 #ifdef VG_TRACE
473     vg_TRACE_EXECUTION("main:  exited InitToolKit ...");
474 #endif /* VG_TRACE */
475
476     if (debug) {
477         XtSetErrorHandler(xtErrorHandler);
478         XtSetWarningHandler(xtWarningHandler);
479     }
480
481 #ifdef __hpux
482     /*
483      * prevent the toolkit from starting the NLIO server...
484      */
485 #ifdef VG_TRACE
486     vg_TRACE_EXECUTION("main:  exited _XHPNlioctl ...");
487 #endif /* VG_TRACE */
488 #endif
489
490     /*
491      * get information about the display...
492      */
493
494     dpyinfo.dpy         = XtDisplay(toplevel);
495 /*    dpyinfo.name      = "";*/
496     dpyinfo.screen      = DefaultScreen(dpyinfo.dpy);
497     dpyinfo.root        = RootWindow   (dpyinfo.dpy, dpyinfo.screen);
498     dpyinfo.depth       = DefaultDepth (dpyinfo.dpy, dpyinfo.screen);
499     dpyinfo.width       = DisplayWidth (dpyinfo.dpy, dpyinfo.screen);
500     dpyinfo.height      = DisplayHeight(dpyinfo.dpy, dpyinfo.screen);
501     dpyinfo.black_pixel = BlackPixel   (dpyinfo.dpy, dpyinfo.screen);
502     dpyinfo.visual      = DefaultVisual(dpyinfo.dpy, dpyinfo.screen);
503
504                                 /* JET - for Xinerama, see if the extension */
505                                 /* is available and init accordingly. */
506
507 #ifdef USE_XINERAMA
508
509     dpyinfo.DtXineramaInfo = _DtXineramaInit(dpyinfo.dpy);
510
511 # ifdef DEBUG
512     if (dpyinfo.DtXineramaInfo == NULL)
513       {                         /* No xinerama, no joy. */
514         fprintf(stderr, "### JET VGMAIN: Xinerama NOT available.\n"); 
515       }
516     else
517       {
518         fprintf(stderr, "### JET VGMAIN: Xinerama available, scrns = %d\n",
519                 dpyinfo.DtXineramaInfo->numscreens);
520       }
521 # endif
522
523 #endif
524
525     /*
526      *  check if any overrides were passed in the argv string...
527      */
528
529     for ( i = 1; i < argc; i++) {
530         switch(i) {
531
532         default:
533             break;
534         }
535     }
536
537     /*
538      *  add the unit convertor for resources...
539      */
540      
541     XtAddConverter(XmRString, XmRUnitType, XmCvtStringToUnitType, NULL, 0);
542
543     /*
544      *  get user-specified resources...
545      */
546
547     SetResourceDatabase();
548  
549     XtGetApplicationResources(toplevel, &appInfo, AppResources,
550                                 XtNumber(AppResources), NULL, 0);
551
552 #ifdef VG_TRACE
553     vg_TRACE_EXECUTION("main:  got application resources ...");
554 #endif /* VG_TRACE */
555     
556     /*
557      *  build widgets...
558      */
559
560 #ifdef VG_TRACE
561     vg_TRACE_EXECUTION("main:  making UI ...");
562 #endif /* VG_TRACE */
563     MakeBackground();   /* login_shell, table, matte              */
564     MakeLogo();                 /* logo, logo_pixmap, logo_shadow         */
565     MakeGreeting();             /* greeting                               */
566     MakeLogin();                /* login_matte ...                        */
567     MakeDtlabel();              /* Show Desktop selection in options  menu*/
568
569     /*
570      *  grab the display and keyboard...
571      *  moved it from before to after creating text widgets in MakeLogin
572      *  RK 01.11.94
573      */
574     if ( ! nograb )
575         SecureDisplay();
576
577     MakeButtons();              /* ok, clear, options, help buttons       */
578     MakeDialog(copyright);      /* copyright dialog                       */
579
580     if (appInfo.optionsDelay == 0 )
581         MakeOptionsMenu();      /* make option_button pop-up menu         */
582     else
583         XtAddTimeOut((unsigned long) appInfo.optionsDelay * 1000, 
584                       MakeOptionsProc, NULL);
585
586     MakeAltDtButtons();        /* make alt desktop buttons, if any       */
587 #ifdef VG_TRACE
588     vg_TRACE_EXECUTION("main:  made UI ...");
589 #endif /* VG_TRACE */
590
591     /*
592      * Add request callback.
593      XtAddInput(0, (XtPointer)XtInputReadMask, RequestCB, NULL);
594      */
595    
596     /*
597      *  force the focus to the login_text widget...
598      */
599 /*
600      XtAddEventHandler(login_text, ExposureMask, False, 
601                         FakeFocusIn, NULL);
602 */
603
604     /*
605      *  create windows for the widgets...
606      */
607      
608 #ifdef VG_TRACE
609     vg_TRACE_EXECUTION("main:  going to realize login_shell ...");
610 #endif /* VG_TRACE */
611     XtRealizeWidget(login_shell);
612 #ifdef VG_TRACE
613     vg_TRACE_EXECUTION("main:  realized login_shell ...");
614 #endif /* VG_TRACE */
615     
616     
617     /*
618      *  miscellaneous stuff...
619      *
620      *  - turn off keyboard bell
621      *  - return root cursor to normal from hourglass
622      *  - start pinging the server
623      */
624      
625     ChangeBell("off");
626     if (appInfo.workspaceCursor)
627     {
628         MakeRootCursor();
629     }
630     else
631     {
632         XUndefineCursor(dpyinfo.dpy, dpyinfo.root);
633     }
634     PingServerCB(NULL, NULL);
635
636     
637     /*
638      *  bring up the windows and enter event loop...
639      */
640
641     XRaiseWindow(XtDisplay(greeting), XtWindow(greeting));
642         /*
643     XRaiseWindow(XtDisplay(logo_shadow), XtWindow(logo_shadow));
644     XRaiseWindow(XtDisplay(logo), XtWindow(logo));
645         */
646     /* XtPopup(login_shell, XtGrabNone); */
647     _DtEnvControl( DT_ENV_RESTORE_PRE_DT );
648
649     /*
650      * Add request callback.
651      */
652      sleep(5);
653      XtAddInput(0, (XtPointer)XtInputReadMask, RequestCB, NULL);
654    
655 #ifdef VG_TRACE
656     vg_TRACE_EXECUTION("main:  entering XtMainLoop ...");
657 #endif /* VG_TRACE */
658     XtMainLoop();
659     exit (0);
660 }
661
662
663
664
665 /***************************************************************************
666  *
667  *  InitToolKit
668  *
669  *  initialize the toolkit
670  ***************************************************************************/
671
672 #define MINTIMEOUT      20
673
674 static jmp_buf  syncJump;
675
676 static SIGVAL
677 syncTimeout( int arg )
678
679 {
680     longjmp (syncJump, 1);
681 }
682
683
684 static Widget 
685 InitToolKit( int argc, char **argv )
686 {
687     
688     int         timeout;                /* timeout to initialize toolkit   */
689     char        *t;
690     Widget      root;
691     
692 #ifdef VG_TRACE
693     vg_TRACE_EXECUTION("InitToolKit: enter ...");
694 #endif /* VG_TRACE */
695
696     /*
697      *  use server grabTimeout as initial value for timeout...
698      */
699
700     timeout = ((t = (char *)getenv(GRABTIMEOUT)) == NULL ? 0 : atoi(t));
701     timeout += MINTIMEOUT;  /* minimum MINTIMEOUT seconds */
702
703
704     /*
705      *  initialize the toolkit. Wrap a timer around it in case the server
706      *  is grabbed.
707      */
708
709     signal (SIGALRM, syncTimeout);
710     if (setjmp (syncJump)) {
711         LogError(
712                 ReadCatalog(MC_LOG_SET,MC_LOG_NO_DPYINIT,MC_DEF_LOG_NO_DPYINIT),
713                 dpyinfo.name);
714         exit(NOTIFY_RESTART);
715     }
716
717     alarm ((unsigned) timeout);
718
719     root = XtInitialize("dtlogin", "Dtlogin", NULL, 0, 
720                          &argc, argv);
721     /* Disable Drag and Drop  RK 11.02.93 */
722     XtVaSetValues(XmGetXmDisplay(XtDisplay(root)),
723                 XmNdragInitiatorProtocolStyle, XmDRAG_NONE,
724                 NULL);
725  
726
727     alarm (0);
728     signal (SIGALRM, SIG_DFL);
729
730     return(root);
731 }
732
733
734
735
736 /***************************************************************************
737  *
738  *  MakeRootCursor
739  *
740  *  Widgets: none
741  ***************************************************************************/
742
743 static void 
744 MakeRootCursor( void )
745 {
746         Cursor vg_cursor;
747
748         vg_cursor = XCreateFontCursor (dpyinfo.dpy, XC_left_ptr);
749
750         XDefineCursor (dpyinfo.dpy, dpyinfo.root, vg_cursor);
751
752         return;
753 }
754
755 /***************************************************************************
756  *
757  *  MakeBackground
758  *
759  *  Widgets: login_shell, table, matte
760  ***************************************************************************/
761
762 static void 
763 MakeBackground( void )
764 {
765     int i;
766     
767 #ifdef VG_TRACE
768     vg_TRACE_EXECUTION("MakeBackground:  entered ...");
769 #endif /* VG_TRACE */
770     /* 
771      * create the login shell widget...
772      */
773
774     i = 0;
775
776     /*          CORE resource set                                       */
777     XtSetArg(argt[i], XmNancestorSensitive,     True                    ); i++;
778     XtSetArg(argt[i], XmNbackgroundPixmap,      XmUNSPECIFIED_PIXMAP    ); i++;
779     XtSetArg(argt[i], XmNborderWidth,           0                       ); i++;
780     XtSetArg(argt[i], XmNmappedWhenManaged,     False                   ); i++;
781     XtSetArg(argt[i], XmNsensitive,             True                    ); i++;
782     XtSetArg(argt[i], XmNtranslations,          NULL                    ); i++;
783
784     /*          COMPOSITE resource set                                  */
785     XtSetArg(argt[i], XmNinsertPosition,        NULL                    ); i++;
786
787     /*          SHELL resource set (set to avoid interference by user)  */
788     XtSetArg(argt[i], XmNallowShellResize,      False                   ); i++;
789     XtSetArg(argt[i], XmNcreatePopupChildProc,  NULL                    ); i++;
790     XtSetArg(argt[i], XmNgeometry,              NULL                    ); i++;
791     XtSetArg(argt[i], XmNpopupCallback,         NULL                    ); i++;
792     XtSetArg(argt[i], XmNpopdownCallback,       NULL                    ); i++;
793     XtSetArg(argt[i], XmNoverrideRedirect,      False                   ); i++;
794     XtSetArg(argt[i], XmNsaveUnder,             False                   ); i++;
795
796     login_shell = XtCreatePopupShell("login_shell", transientShellWidgetClass,
797                                      toplevel, argt, i);
798     XtAddCallback(login_shell, XmNpopupCallback, LayoutCB, NULL);
799
800     /* Fix to display Input Method's status area. */
801     XtSetArg(argt[0], XmNheight, dpyinfo.height);
802     XtSetValues(login_shell, argt, 1);
803
804
805     /* 
806      * create the full-screen drawing area...
807      */
808
809     i = InitArg(DrawingA);
810     XtSetArg(argt[i], XmNwidth,                 dpyinfo.width           ); i++;
811     XtSetArg(argt[i], XmNheight,                dpyinfo.height          ); i++;
812     XtSetArg(argt[i], XmNunitType,              XmPIXELS                ); i++;
813
814     table = XtCreateManagedWidget("table", xmDrawingAreaWidgetClass,
815                                    login_shell, argt, i);
816
817     XtAddEventHandler(table, ButtonPressMask, False, RefreshEH, NULL);
818     XtAddCallback(table, XmNhelpCallback, ShowDialogCB, (XtPointer) help);
819
820
821     /* 
822      * create the main matte...
823      */
824
825     i = InitArg(Form);
826     /*                XmNwidth,                 (set by user)           */
827     /*                XmNheight,                (set by user)           */
828     XtSetArg(argt[i], XmNshadowThickness,       SHADOW_THICKNESS        ); i++;
829 /*
830     XtSetArg(argt[i], XmNshadowType,    XmSHADOW_OUT    ); i++;
831     XtSetArg(argt[i], XmNshadowThickness,       5       ); i++;
832 */
833
834     matte = XmCreateForm(table, "matte", argt, i);
835     XtManageChild(matte);
836
837     i = 0;
838         XtSetArg(argt[i], XmNshadowType, XmSHADOW_OUT); i++;
839         XtSetArg(argt[i], XmNshadowThickness, 2); i++;
840         XtSetArg(argt[i], XmNtopAttachment, XmATTACH_FORM); i++;
841         XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_FORM); i++;
842         XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM); i++;
843         /*
844         XtSetArg(argt[i], XmNrightAttachment, XmATTACH_FORM); i++;
845         */
846         XtSetArg(argt[i], XmNtopOffset, 15); i++;
847         XtSetArg(argt[i], XmNbottomOffset, 15); i++;
848         XtSetArg(argt[i], XmNleftOffset, 15); i++;
849         /*
850         XtSetArg(argt[i], XmNrightOffset, 15); i++;
851         */
852         matteFrame = XmCreateFrame(matte, "matteFrame", argt, i);
853     XtManageChild(matteFrame);
854
855         i = 0;
856         matte1 = XmCreateForm(matteFrame, "matte1", argt, i);
857     XtManageChild(matte1);
858         
859 }
860
861
862 static void
863 MakeAltDtButtons( void )
864 {
865 int i,j;
866 struct stat     statb;
867 char        *startup_name; 
868 XrmValue    startup_value; 
869 char        temp[MAXPATHLEN] = "\0";
870 char        *session;
871 FILE        *ls;
872 char        lastsess[MAXPATHLEN];
873 Widget      default_dt = NULL;
874 int         default_is_custom_dt = True;
875 int         found_alt_dt = False;
876 char        *temp_p;
877
878
879 #ifdef VG_TRACE
880     vg_TRACE_EXECUTION("MakeAltDtButtons:  entered ...");
881 #endif /* VG_TRACE */
882
883     if (getenv("SESSION_SET") == NULL) {
884         default_is_custom_dt = False;
885     }
886
887     if ((session = getenv ("SESSION")) == NULL)  {
888         session = "  ";
889     }
890
891     if(appInfo.altDts > 0) { 
892       if ((alt_dts =
893             (Widget *) calloc(appInfo.altDts, sizeof (Widget))) == NULL)
894         LogError(
895                 ReadCatalog(MC_ERROR_SET,MC_NO_MEMORY, MC_DEF_NO_MEMORY),
896                 dpyinfo.name);
897
898      for(i = 0; i < appInfo.altDts; ++i) {
899        int is_default;
900
901        is_default = FALSE;
902
903        /* alt desktops begin numbering with 1 */
904        sprintf(altdtname,"%s%d", "Dtlogin*altDtName",i+1);
905        sprintf(altdtclass,"%s%d", "Dtlogin*AltDtName",i+1); 
906
907        sprintf(altdtkey,"%s%d","Dtlogin*altDtKey",i+1); 
908        sprintf(altdtkeyclass,"%s%d","Dtlogin*AltDtKey",i+1); 
909
910        sprintf(altdtstart,"%s%d","Dtlogin*altDtStart",i+1); 
911        sprintf(altdtstartclass,"%s%d","Dtlogin*AltDtStart",i+1); 
912
913         if (XrmGetResource(
914                         XtDatabase(dpyinfo.dpy), 
915                         altdtkey, altdtkeyclass,
916                         &keyrmtype, &keyrmvalue) == True) {
917           /* 
918            * remove trailing spaces 
919            */
920           if(strchr(keyrmvalue.addr,' '))
921               temp_p = strtok(keyrmvalue.addr," ");
922           else 
923               temp_p =  keyrmvalue.addr;
924
925           /* 
926            * Make sure the key file exists.
927            */
928           if (stat( temp_p, &statb) == 0) { 
929
930             j = InitArg(ToggleBG);
931             if (XrmGetResource(
932                         XtDatabase(dpyinfo.dpy),
933                         altdtstart, altdtstartclass,
934                         &startup_name, &startup_value) == True) {
935
936               /* 
937                * remove trailing spaces 
938                */
939                if (strchr(startup_value.addr, ' ')) 
940                    snprintf(temp, sizeof(temp), "%s", strtok(startup_value.addr, " "));
941                else
942                    snprintf(temp, sizeof(temp), "%s", startup_value.addr);
943
944                if (default_is_custom_dt)
945                  if (strcmp(session, temp) == 0)    {
946                      is_default = TRUE;
947                  }
948             }
949             else
950               LogError((unsigned char *)"No startup script for altdt %d \n", i);
951
952             if (XrmGetResource(
953                         XtDatabase(dpyinfo.dpy), 
954                         altdtname, altdtclass,
955                         &rmtype, &rmvalue) == True) {
956               if (! strncmp(rmvalue.addr, DISPLAYNAME, strlen(DISPLAYNAME))) {
957                 char  *host;
958
959                 host = GetDisplayName();
960                 snprintf(temp, sizeof(temp), "%s - %s", host, rmvalue.addr + strlen(DISPLAYNAME));
961                 xmstr = XmStringCreateLocalized(temp);
962               }
963               else {
964                    xmstr = XmStringCreateLocalized(rmvalue.addr);
965               }
966             }
967             else {
968               LogError((unsigned char *)
969                         "Couldn't find the altdtname resource in the db\n");
970               sprintf(altdtname,"%s%d", "Alternate Desktop-",i+1);
971               xmstr = XmStringCreateLocalized(altdtname);
972             }
973
974             sprintf(altdtlogo,"%s%d","Dtlogin*altDtLogo",i+1); 
975             sprintf(altlogoclass,"%s%d","Dtlogin*AltDtLogo",i+1); 
976             if (XrmGetResource(
977                         XtDatabase(dpyinfo.dpy),
978                         altdtlogo, altlogoclass,
979                         &logotype, &logovalue) == True) {
980               XtSetArg(argt[j], XmNuserData, logovalue.addr); j++;
981             }
982             else{       
983               XtSetArg(argt[j], XmNuserData, logoInfo.bitmapFile); j++;
984             }
985
986             XtSetArg(argt[j], XmNlabelString, xmstr); j++;
987             XtSetArg(argt[j], XmNrecomputeSize, True); j++;
988  
989             alt_dts[i] = XmCreateToggleButtonGadget(
990                                                 session_menu,
991                                                 rmvalue.addr, argt, j);
992             XmStringFree(xmstr);
993             XtAddCallback(
994                         alt_dts[i],
995                         XmNvalueChangedCallback, MenuItemCB,
996                         (XtPointer) OB_ALT_DTS);
997             XtManageChild(alt_dts[i]);
998             found_alt_dt = True;
999
1000             if (is_default)
1001               default_dt = alt_dts[i];
1002           }
1003           else  
1004             LogError((unsigned char *) "Couldn't find the keyfile \n");
1005         }
1006         else
1007             LogError((unsigned char *)
1008                      "Couldn't find the altkeyfile resource in the database\n");
1009       }  
1010     }
1011
1012     if ((appInfo.altDts == 0) || !found_alt_dt)
1013       XtManageChild(options_dt);  
1014         
1015     /* 
1016      * Use the regular desktop if none of the known sessions matched the
1017      * specified custom session.
1018      */
1019     if (default_is_custom_dt && NULL == default_dt) {
1020         default_dt = options_dt;
1021         if (found_alt_dt)
1022           XtManageChild(options_dt);  
1023     }
1024
1025     /*
1026      *  [ Failsafe Session ] menu pane... 
1027      */
1028     i = InitArg(ToggleBG);
1029     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_FS_LABEL, MC_DEF_FS_LABEL);
1030     XtSetArg(argt[i], XmNuserData,       logoInfo.bitmapFile            ); i++;
1031     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1032     XtSetArg(argt[i], XmNrecomputeSize,                 True            ); i++;
1033     options_failsafe = XmCreateToggleButtonGadget(session_menu, 
1034                 "options_failsafe", argt, i);
1035     XmStringFree(xmstr);
1036     XtAddCallback(options_failsafe, XmNvalueChangedCallback, 
1037                 MenuItemCB, (XtPointer) OB_FAILSAFE);
1038
1039     XtManageChild(options_failsafe);
1040
1041     /* 
1042      * which option to set..
1043      */
1044     SetDefaultDt(default_dt);
1045     SetDtLabelAndIcon();
1046 }
1047
1048 /***************************************************************************
1049  *
1050  *  MakeButtons
1051  *
1052  *  Widgets:    ok_button, clear_button, options_button, help_button
1053  ***************************************************************************/
1054
1055
1056 static void 
1057 MakeButtons( void )
1058 {
1059     int i;
1060
1061     Dimension   max_width;      /* maximum width  of a set of widgets      */
1062     Dimension   max_height;     /* maximum height of a set of widgets      */
1063     Dimension   thick1;         /* defaultButtonShadowThickness */
1064     Dimension   thick2;         /* shadowThickness */
1065
1066     int         origin;         /* horizontal origin for button placement  */
1067     int         spacing;        /* spacing between buttons (width/32)      */
1068
1069 #ifdef VG_TRACE
1070     vg_TRACE_EXECUTION("MakeButtons:  entered ...");
1071 #endif /* VG_TRACE */
1072      
1073     /* 
1074      * create the buttons...
1075      */
1076
1077     /* ok button */
1078     
1079     i = InitArg(PushBG);
1080     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
1081     XtSetArg(argt[i], XmNbottomPosition, 95); i++;
1082     XtSetArg(argt[i], XmNtraversalOn, True); i++;
1083
1084     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_OK_LABEL, MC_DEF_OK_LABEL );
1085     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1086
1087     ok_button = XmCreatePushButtonGadget(matte1, "ok_button", argt, i);
1088
1089     XmStringFree(xmstr);
1090     XtManageChild(ok_button);
1091
1092     XtAddCallback(ok_button, XmNactivateCallback, RespondChallengeCB, NULL);    
1093
1094
1095     /* clear button */
1096
1097     i -= 1;
1098     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_CLEAR_LABEL, MC_DEF_CLEAR_LABEL);
1099     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1100
1101     clear_button = XmCreatePushButtonGadget(matte1, "clear_button", argt, i);
1102
1103     XmStringFree(xmstr);
1104     XtManageChild(clear_button);
1105     XtAddCallback(clear_button, XmNactivateCallback, RespondClearCB,
1106                   (XtPointer) 0);   
1107
1108
1109     /* help button */
1110     
1111     i -= 1;
1112     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_HELP_LABEL, MC_DEF_HELP_LABEL);
1113     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1114
1115     help_button = XmCreatePushButtonGadget(matte1, "help_button", argt, i);
1116     XtAddCallback(help_button, XmNactivateCallback, ShowDialogCB, 
1117                   (XtPointer) help);
1118     XmStringFree(xmstr);
1119     XtManageChild(help_button);
1120
1121     /* options button */
1122
1123     i = InitArg(Label);
1124     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
1125     XtSetArg(argt[i], XmNbottomPosition, 95); i++;
1126     xmstr = ReadCatalogXms(
1127                         MC_LABEL_SET,
1128                         MC_OPTIONS_LABEL,
1129                         MC_DEF_OPTIONS_LABEL );
1130
1131     XtSetArg(argt[i], XmNlabelString, xmstr); i++;
1132     XtSetArg(argt[i], XmNtraversalOn, True); i++;
1133     options_button = DtCreateMenuButton(matte1, "options_button", argt, i);
1134     XtOverrideTranslations(
1135                         options_button,
1136                         XtParseTranslationTable(" <Key> Return: Select()"));
1137
1138     XtManageChild(options_button);
1139     XmStringFree(xmstr);
1140
1141     /*
1142      *  tell form that ok_button is the default button...
1143      */
1144
1145     i = 0;
1146     XtSetArg(argt[i], XmNdefaultButton,         ok_button               ); i++;
1147     XtSetValues(matte1,  argt, i);
1148         
1149     /*
1150      * make all buttons *look* the same size...
1151      */
1152      
1153
1154     max_width = max_height = 0;
1155     GetBiggest(ok_button, &max_width, &max_height);
1156     GetBiggest(clear_button,   &max_width, &max_height);
1157     GetBiggest(options_button, &max_width, &max_height);
1158     GetBiggest(help_button,    &max_width, &max_height);
1159
1160     if ( (int) max_width < MIN_BUTTON_SIZE) max_width = MIN_BUTTON_SIZE;
1161     
1162     i = 0;
1163     XtSetArg(argt[i], XmNdefaultButtonShadowThickness, &thick1); i++;
1164     XtSetArg(argt[i], XmNshadowThickness, &thick2); i++;
1165     XtGetValues(ok_button,      argt, i);
1166     thick1 *= 4;
1167     thick1 += thick2;
1168
1169     i = 0;
1170     XtSetArg(argt[i], XmNwidth,                 max_width               ); i++;
1171     XtSetArg(argt[i], XmNheight,                max_height              ); i++;
1172     XtSetArg(argt[i], XmNrecomputeSize,         False                   ); i++;
1173     XtSetArg(argt[i], XmNbottomOffset,          thick1                  ); i++;
1174     XtSetValues(options_button, argt, i);
1175
1176     i = 0;
1177     XtSetArg(argt[i], XmNwidth,                 max_width + 2*thick1    ); i++;
1178     XtSetArg(argt[i], XmNheight,                max_height + 2*thick1   ); i++;
1179     XtSetArg(argt[i], XmNrecomputeSize,         False                   ); i++;
1180
1181     XtSetValues(ok_button,      argt, i);
1182     XtSetValues(clear_button,   argt, i);
1183     XtSetValues(help_button,    argt, i);
1184 }
1185
1186
1187
1188
1189 /***************************************************************************
1190  *
1191  *  MakeDialog
1192  *
1193  *  Widgets: error_message, help_message, copyright_msg, hostname_message,
1194  *           passwd_message
1195  ***************************************************************************/
1196
1197 void 
1198 MakeDialog( DialogType dtype )
1199 {
1200     int i, j;
1201
1202     int         width;
1203     
1204     FILE        *fp, *fopen();
1205     char        buffer[128];
1206
1207     Widget      w = NULL, text;
1208     Dimension txt_width, txt_height;
1209     XmString    ok, cancel, nw, sv;
1210
1211     Widget      tlev;           /* JET - warning, there be dragons here */
1212     unsigned int dpwidth, dpheight, xorg, yorg;
1213
1214     
1215     
1216 #ifdef VG_TRACE
1217     vg_TRACE_EXECUTION("MakeDialog:  entered ...");
1218 #endif /* VG_TRACE */
1219     /*
1220      *  do things common to all dialogs...
1221      */
1222
1223 #ifdef USE_XINERAMA
1224                                 /* get info on prefered screen */
1225     if (!_DtXineramaGetScreen(dpyinfo.DtXineramaInfo, 
1226                               appInfo.xineramaPreferredScreen,
1227                               &dpwidth, &dpheight, &xorg, &yorg))
1228       {                         /* no joy here either - setup for normal */
1229         dpwidth = dpyinfo.width;
1230         dpheight = dpyinfo.height;
1231         xorg = yorg = 0;
1232       }
1233                                 /* else, should be setup properly */
1234     XWarpPointer(dpyinfo.dpy,None,dpyinfo.root,0,0,0,0,dpwidth/2,dpheight/2);
1235 #else  /* no Xinerama */
1236     dpwidth = dpyinfo.width;
1237     dpheight = dpyinfo.height;
1238     xorg = yorg = 0;
1239 #endif    
1240
1241     ok     = ReadCatalogXms(MC_LABEL_SET, MC_OK_LABEL, MC_DEF_OK_LABEL);
1242     cancel = ReadCatalogXms(MC_LABEL_SET, MC_CANCEL_LABEL, MC_DEF_CANCEL_LABEL);
1243
1244     i = InitArg(MessageBox);
1245     XtSetArg(argt[i], XmNmarginHeight,          MBOX_MARGIN_HEIGHT      ); i++;
1246     XtSetArg(argt[i], XmNmarginWidth,           MBOX_MARGIN_WIDTH       ); i++;
1247     XtSetArg(argt[i], XmNshadowThickness,       SHADOW_THICKNESS        ); i++;
1248     XtSetArg(argt[i], XmNokLabelString,         ok                      ); i++;
1249     XtSetArg(argt[i], XmNcancelLabelString,     cancel                  ); i++;
1250     XtSetArg(argt[i], XmNnoResize,              False                   ); i++;
1251     XtSetArg(argt[i], XmNresizePolicy,          XmRESIZE_ANY            ); i++;
1252
1253     /*
1254      *  create the various dialogs...
1255      */
1256
1257     /* JET - check the matte widget, and if non-null, well use that as
1258      * the parent for dialogs.  Otherwise use table (the original
1259      * toplevel widget for this func).  This is useful for Xinerama so
1260      * that child dialogs are centered on the matte, and not the whole
1261      * SLS screen.
1262      */
1263
1264     if (matte != (Widget)NULL)
1265       tlev = matte;
1266     else
1267       tlev = table;
1268
1269    switch (dtype) {
1270
1271     case error:
1272         xmstr = ReadCatalogXms(MC_ERROR_SET, MC_LOGIN, "");
1273         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1274
1275         w = XmCreateErrorDialog(tlev, "error_message", argt, i);
1276         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
1277         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1278
1279         error_message = w;
1280         break;
1281
1282
1283     case help:
1284
1285         txt_width = (dpwidth > 850) ? 800 : dpwidth - 50;
1286         txt_height = (dpheight > 900) ? 600 : dpheight - 300;
1287
1288         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_HELP_LABEL, MC_DEF_HELP_LABEL);
1289         XtSetArg(argt[i], XmNmessageString, xmstr); i++;
1290
1291         w = XmCreateInformationDialog(tlev, "help_message", argt, i);
1292         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
1293         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1294
1295         i = InitArg(Text);
1296         XtSetArg(argt[i], XmNheight, txt_height); i++;
1297         XtSetArg(argt[i], XmNwidth, txt_width); i++;
1298         XtSetArg(argt[i], XmNeditMode, XmMULTI_LINE_EDIT); i++;
1299         XtSetArg(argt[i], XmNscrollBarDisplayPolicy, XmAS_NEEDED); i++;
1300         XtSetArg(argt[i], XmNscrollingPolicy, XmAUTOMATIC); i++;
1301         XtSetArg(argt[i], XmNeditable, False); i++;
1302         XtSetArg(
1303                 argt[i],
1304                 XmNvalue, ReadCatalog(MC_HELP_SET, MC_HELP, MC_DEF_HELP)); i++;
1305         text = XmCreateScrolledText(w, "help_message_text", argt, i);
1306
1307         XtManageChild(text);
1308         XtManageChild(w);
1309         help_message = w;
1310         break;
1311
1312
1313     case copyright:
1314         if ((fp = fopen(COPYRIGHT,"r")) == NULL)
1315             xmstr = XmStringCreate("Cannot open copyright file '/etc/copyright'.",
1316                                 XmFONTLIST_DEFAULT_TAG);
1317         else {
1318             xmstr = (XmString) NULL;
1319         
1320             while (fgets(buffer, 128, fp) != NULL) {
1321                 j = strlen(buffer);
1322                 if ( buffer[j-1] == '\n' ) buffer[j-1] = '\0';
1323             
1324                 if ( xmstr != NULL )
1325                     xmstr = XmStringConcat(xmstr, XmStringSeparatorCreate());
1326
1327                 xmstr = XmStringConcat(xmstr,
1328                                        XmStringCreate(buffer,
1329                                        XmFONTLIST_DEFAULT_TAG));
1330             }       
1331             fclose(fp);
1332         }
1333
1334         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1335
1336         w = XmCreateInformationDialog(tlev, "copyright_msg", argt, i);
1337         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
1338         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1339         
1340         XtAddCallback(w, XmNokCallback, CopyrightCB, (XtPointer) 0);    
1341
1342         copyright_msg = w;
1343         break;
1344     
1345
1346     case hostname:
1347             
1348         nw = ReadCatalogXms(MC_LABEL_SET, MC_NW_LABEL,  MC_DEF_NW_LABEL);
1349         sv = ReadCatalogXms(MC_LABEL_SET, MC_START_LABEL, MC_DEF_START_LABEL);
1350
1351         xmstr = ReadCatalogXms(MC_HELP_SET, MC_SYSTEM, MC_DEF_SYSTEM);
1352         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1353         XtSetArg(argt[i], XmNokLabelString,             nw              ); i++;
1354         XtSetArg(argt[i], XmNcancelLabelString,         sv              ); i++;
1355
1356         w = XmCreateWarningDialog(tlev, "hostname_msg", argt, i);
1357
1358         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1359
1360         XmStringFree(nw);
1361         XmStringFree(sv);
1362
1363         hostname_message = w;
1364         break;
1365
1366
1367     case expassword:
1368
1369         xmstr = ReadCatalogXms(MC_ERROR_SET, MC_PASSWD_EXPIRED, 
1370                             MC_DEF_PASSWD_EXPIRED);
1371         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1372
1373         w = XmCreateQuestionDialog(tlev, "password_msg", argt, i);
1374
1375         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1376
1377         passwd_message = w;
1378         break;
1379     }
1380
1381     /*
1382      *  finish up...
1383      */
1384
1385     switch (dtype) {
1386       case error:
1387       case hostname:
1388       case expassword:
1389         XtAddCallback(w, XmNokCallback,     RespondDialogCB, NULL);
1390         XtAddCallback(w, XmNcancelCallback, RespondDialogCB, NULL);
1391         break;
1392     }
1393
1394
1395     XtSetArg(argt[0], XmNdialogStyle,   XmDIALOG_APPLICATION_MODAL      ); i++;
1396     if(w) {
1397         XtSetValues(w, argt, 1);
1398     }
1399
1400     XmStringFree(xmstr);
1401     XmStringFree(ok);
1402     XmStringFree(cancel);
1403
1404
1405     /*
1406      *  adjust the width of the "ok" button on the dialogs...
1407      */
1408
1409     width = (dtype == hostname ? FromMM(4000) : MIN_BUTTON_SIZE);
1410     
1411     i = 0;
1412     XtSetArg(argt[i], XmNrecomputeSize,                 False           ); i++;
1413     XtSetArg(argt[i], XmNwidth,                         width           ); i++;
1414
1415     XtSetValues(XmMessageBoxGetChild(w, XmDIALOG_OK_BUTTON), argt, i);
1416
1417 }
1418
1419 /***************************************************************************
1420  *
1421  *  MakeDtlabel
1422  *
1423  *  Widgets:    dt_label
1424  ***************************************************************************/
1425
1426 static void
1427 MakeDtlabel( void )
1428 {
1429     int i;
1430
1431 #ifdef VG_TRACE
1432     vg_TRACE_EXECUTION("MakeDtlabel:  entered ...");
1433 #endif /* VG_TRACE */
1434
1435     i = InitArg(LabelG);
1436     XtSetArg(argt[i], XmNtraversalOn,           False                   ); i++;
1437     XtSetArg(argt[i], XmNtopAttachment,         XmATTACH_WIDGET         ); i++;
1438     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_FORM           ); i++;
1439     XtSetArg(argt[i], XmNrightAttachment,       XmATTACH_FORM           ); i++;
1440     XtSetArg(argt[i], XmNalignment,             XmALIGNMENT_CENTER      ); i++;
1441     XtSetArg(argt[i], XmNtopWidget,             greeting                ); i++;
1442  
1443     dt_label = XmCreateLabel(matte1, "dt_label", argt, i);
1444     XtManageChild(dt_label);
1445 }
1446
1447
1448
1449 /***************************************************************************
1450  *
1451  *  MakeGreeting
1452  *
1453  *  Widgets:    greeting
1454  ***************************************************************************/
1455
1456 typedef  struct {
1457     char        *labelString;   /* string for label                        */
1458     char        *persLabelString; /* alternate string for label */
1459     XmFontList  fontList;
1460 } GreetInfo, *GreetInfoPtr;
1461
1462 static GreetInfo greetInfo;
1463
1464 static  XtResource greetResources[] = {
1465     {XmNlabelString, XmCLabelString, 
1466         XmRString, sizeof(char *),
1467         XtOffset(GreetInfoPtr, labelString), XtRString, "default"       },
1468
1469     {"persLabelString", "PersLabelString",
1470         XmRString, sizeof(char *),
1471         XtOffset(GreetInfoPtr, persLabelString), XtRString, "default"       },
1472
1473     {XmNfontList, XmCFontList, 
1474         XmRFontList, sizeof(XmFontList),
1475         XtOffset(GreetInfoPtr, fontList), XtRString, NULL               }
1476 };     
1477
1478 static void 
1479 MakeGreeting( void )
1480 {
1481     int i;
1482
1483     char    *greetmsg;
1484     char    host[128];
1485     char    disp[128];
1486     char    *p, *q, *s, *t;
1487     int     newLine = False;
1488     int     skip;
1489
1490 #ifdef VG_TRACE
1491     vg_TRACE_EXECUTION("MakeGreeting:  entered ...");
1492 #endif /* VG_TRACE */
1493
1494     /*
1495      *  get the user's greeting preferences...
1496      */
1497      
1498     XtGetSubresources(table, &greetInfo, "greeting", "Greeting",
1499         greetResources, XtNumber(greetResources), NULL, 0);
1500
1501
1502     /*
1503      *  get the local hostname...
1504      */
1505      
1506     gethostname(host, sizeof (host));
1507     if ( (p = strchr(host,'.')) != NULL )
1508         *p = '\0';
1509
1510     /* 
1511     **  Get display name (for %DisplayName% substitutions),
1512     **  reducing "a.b.c.d:0" constructs to shorter "a:0" form.
1513     */
1514
1515     strncpy(disp,
1516         dpyinfo.name ? dpyinfo.name : (DisplayString(dpyinfo.dpy)), 127);
1517     disp[127] = '\0';
1518     p = strchr(disp, '.');
1519     t = strchr(disp, ':');
1520     if (p && t) strcpy(p,t);
1521     
1522
1523     /*
1524      *  use the default string if the user has not specified one...
1525      */
1526
1527     if ( greetInfo.persLabelString &&
1528          strcmp(greetInfo.persLabelString, "default") == 0 ) {
1529         const char *msg;
1530         msg =
1531           (const char *)
1532           ReadCatalog(MC_LABEL_SET,MC_PERS_GREET_LABEL,MC_DEF_PERS_GREET_LABEL);
1533         greetInfo.persLabelString = strdup(msg);
1534     }
1535  
1536     if ( greetInfo.labelString && 
1537          strcmp(greetInfo.labelString, "default") == 0 ) {
1538         
1539         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_GREET_LABEL,MC_DEF_GREET_LABEL);
1540         xmstr = XmStringConcat(xmstr,
1541                                XmStringCreate(" ",  XmFONTLIST_DEFAULT_TAG));
1542         xmstr = XmStringConcat(xmstr,
1543                                XmStringCreate(host, XmFONTLIST_DEFAULT_TAG));
1544     }
1545     else {
1546         /*
1547          *  scan user's message for %LocalHost% token. Replace with hostname
1548          *  if found...
1549          */
1550          
1551
1552         if ( !greetInfo.labelString                     ||
1553              strlen(greetInfo.labelString) == 0         ||
1554              strcmp(greetInfo.labelString, "None") == 0 ||
1555              strcmp(greetInfo.labelString, "none") == 0 )
1556              
1557             greetmsg = strdup(" ");
1558         else {
1559             greetmsg = strdup(greetInfo.labelString);
1560         }
1561
1562         s = greetmsg;
1563         xmstr = (XmString) NULL;
1564
1565         do {
1566             q = s;
1567         
1568             /*
1569              *  scan for a new line character in remaining label string. 
1570              *  If found, work with that substring first...
1571              */
1572              
1573             if ( (p = strchr(q, '\n')) != NULL ) {
1574                 *p = '\0';
1575                 newLine = True;
1576                 s = ++p;
1577
1578                 if ( *q == '\0' )       /* handle consecutive newlines */
1579                     q = " ";
1580                     
1581             }
1582             else {
1583                 newLine = False;
1584             }
1585             
1586             /*
1587              *  replace all occurrences of %LocalHost% and %DisplayName%
1588              *  in the current substring...
1589              */
1590              
1591             while (1) {
1592                 p = strstr(q, LOCALHOST);
1593                 t = strstr(q, DISPLAYNAME);
1594                 
1595                 if (p && t) { /* both present? do whichever comes first */
1596                     if (p > t) p = NULL;
1597                     else t = NULL;
1598                 }
1599                 if (p) { /* replace a %LocalHost% string */
1600                     t = host;
1601                     skip = sizeof(LOCALHOST);
1602                 } else if (t) { /* replace a %DisplayName% string */
1603                     p = t;
1604                     t = disp;
1605                     skip = sizeof(DISPLAYNAME);
1606                 } else /* nothing left to replace */
1607                     break;
1608                 *p = '\0';
1609                 xmstr = XmStringConcat(xmstr,
1610                                    XmStringCreate(q,
1611                                    XmFONTLIST_DEFAULT_TAG));
1612                 xmstr = XmStringConcat(xmstr,
1613                                    XmStringCreate(t,
1614                                    XmFONTLIST_DEFAULT_TAG));
1615                 q = p + skip - 1;
1616             }
1617
1618             if ( strlen(q) != 0 )
1619                 xmstr = XmStringConcat(xmstr,
1620                                    XmStringCreate(q,
1621                                    XmFONTLIST_DEFAULT_TAG));
1622
1623             /*
1624              *  add a line separator if this is a multi-line greeting...
1625              */
1626              
1627             if ( newLine == True ) {
1628                 xmstr = XmStringConcat(xmstr, XmStringSeparatorCreate());
1629             }
1630                              
1631         } while ( newLine == True ) ;
1632         
1633         free(greetmsg);
1634     }
1635
1636
1637     /* 
1638      * create the Welcome message...
1639      */
1640     
1641     i = InitArg(LabelG);
1642     XtSetArg(argt[i], XmNtraversalOn,           False                   ); i++;
1643     XtSetArg(argt[i], XmNlabelString,           xmstr                   ); i++;
1644     XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM); i++;
1645     XtSetArg(argt[i], XmNtopAttachment, XmATTACH_POSITION); i++; 
1646    /* XtSetArg(argt[i], XmNtopPosition, 15); i++; */
1647    /* Changed this to accommodate desktop label */
1648     XtSetArg(argt[i], XmNtopPosition, 9); i++; 
1649     XtSetArg(argt[i], XmNrightAttachment, XmATTACH_FORM); i++;
1650
1651
1652     /*
1653      *  use the user's font if one has been specified, otherwise use
1654      *  the application's default...
1655      */
1656
1657     if ( greetInfo.fontList != NULL ) {
1658         XtSetArg(argt[i], XmNfontList,          greetInfo.fontList      ); i++;
1659     }
1660
1661     greeting = XmCreateLabel(matte1, "greeting", argt, i);
1662     XtManageChild(greeting);
1663
1664     XmStringFree(xmstr);
1665 }
1666
1667 /***************************************************************************
1668  *
1669  *  MakeLogin
1670  *
1671  *  Widgets: login_matte, 
1672  *           login_form, login_label, login_text
1673  ***************************************************************************/
1674
1675 static void 
1676 MakeLogin( void )
1677 {
1678     int i;
1679     int j;
1680     LoginTextPtr textdata; 
1681     XtTranslations      textTable;
1682     Widget passwd_text;
1683     String greetstr;
1684
1685 #ifdef VG_TRACE
1686     vg_TRACE_EXECUTION("MakeLogin:  entered ...");
1687 #endif /* VG_TRACE */
1688
1689     /*
1690      *  create the login form
1691      */
1692
1693     i = 0;
1694     XtSetArg(argt[i], XmNshadowThickness, 0); i++; 
1695     XtSetArg(argt[i], XmNresizable,             False                   ); i++;
1696     XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM); i++;
1697     XtSetArg(argt[i], XmNleftOffset, 80); i++;
1698     XtSetArg(argt[i], XmNrightAttachment, XmATTACH_FORM); i++;
1699     XtSetArg(argt[i], XmNrightOffset, 80); i++;
1700     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
1701     XtSetArg(argt[i], XmNbottomPosition, 65); i++;
1702 /*
1703     XtSetArg(argt[i], XmNresizePolicy, XmRESIZE_ANY); i++;
1704 */
1705     XtSetArg(argt[i], XmNallowShellResize, True); i++;
1706
1707     login_form = XmCreateForm(matte1, "login_form", argt, i);
1708     XtManageChild(login_form);
1709
1710     /*
1711      *  create the login text field...
1712      */
1713
1714     i = InitArg(Text);
1715     XtSetArg(argt[i], XmNbottomAttachment,      XmATTACH_POSITION       ); i++;
1716     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_POSITION       ); i++;
1717     XtSetArg(argt[i], XmNrightAttachment,       XmATTACH_POSITION       ); i++;
1718     XtSetArg(argt[i], XmNbottomPosition,        95                      ); i++;
1719     XtSetArg(argt[i], XmNrightPosition,         80                      ); i++;
1720     XtSetArg(argt[i], XmNleftPosition,          20                      ); i++;
1721     XtSetArg(argt[i], XmNselectionArrayCount,   1                       ); i++;
1722     XtSetArg(argt[i], XmNmaxLength,             80                      ); i++;
1723     XtSetArg(argt[i], XmNmappedWhenManaged,     False                   ); i++;
1724
1725     textdata = malloc(sizeof(LoginText));
1726     XtSetArg(argt[i], XmNuserData,              textdata                ); i++;
1727
1728     login_text = XmCreateTextField(login_form, "login_text", argt, i);
1729
1730     /*
1731      *  From Human Interface model, Tab key operation should work same on
1732      *  user field as it does on password field.  Password field is setup
1733      *  to take Tab key as password data.  HIE model is for user field to
1734      *  do same.
1735      */  
1736     XtOverrideTranslations(
1737                         login_text,
1738                         XtParseTranslationTable(
1739                                 " Shift <Key>Tab: prev-tab-group() \n\
1740                                    Ctrl <Key>Tab: next-tab-group() "));
1741
1742     XtManageChild(login_text);
1743 #ifdef __hpux
1744     XtAddCallback(login_text, XmNfocusCallback, TextFocusCB, NULL);
1745 #endif
1746
1747
1748     XtAddActions(textActions, 2);
1749     textTable = XtParseTranslationTable(textEventBindings);
1750
1751 #if 0
1752     XtSetArg(argt[i], XmNtranslations,          textTable               ); i++;
1753 #endif
1754     XtSetArg(argt[i], XmNverifyBell,            False                   ); i++;
1755
1756     passwd_text = XmCreateTextField(login_form, "passwd_text", argt, i);
1757
1758     textdata->bEcho = True;
1759     textdata->noechobuf[0] = '\0';
1760     textdata->text[0] = passwd_text;
1761     textdata->text[1] = login_text;
1762
1763     XtManageChild(passwd_text);
1764 #ifdef __hpux
1765     XtAddCallback(passwd_text, XmNfocusCallback, TextFocusCB, NULL);
1766 #endif
1767     XtAddCallback(passwd_text, XmNmodifyVerifyCallback, EditPasswdCB, NULL);
1768
1769    /*
1770     * Get default greeting string
1771     */
1772     i = 0;
1773     XtSetArg(argt[i], XmNlabelString, &textdata->onGreeting); i++;
1774     XtGetValues(greeting, argt, i);
1775     textdata->offGreetingFormat = greetInfo.persLabelString;
1776     textdata->offGreetingUname = NULL;
1777
1778     /*
1779      *  create the login labels...
1780      */
1781
1782     i = InitArg(LabelG);
1783
1784    /* modified recomputeSize initial value from False to True, fails 
1785     * when setting longer strings. Manifested as bug ID:1200690.
1786     */ 
1787     XtSetArg(argt[i], XmNrecomputeSize,         True                    ); i++;
1788
1789     XtSetArg(argt[i], XmNtraversalOn,           False                   ); i++;
1790     XtSetArg(argt[i], XmNbottomAttachment,      XmATTACH_WIDGET         ); i++;
1791     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_OPPOSITE_WIDGET); i++;
1792
1793 /* XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM           ); i++; 
1794    Commented this statement to  align login_label and login_text                        
1795     XtSetArg(argt[i], XmNrightAttachment,       XmATTACH_FORM           ); i++;
1796     XtSetArg(argt[i], XmNalignment,             XmALIGNMENT_CENTER      ); i++;
1797     XtSetArg(argt[i], XmNbottomOffset,          10                      ); i++;
1798 */
1799
1800     XtSetArg(argt[i], XmNleftWidget,            login_text              ); i++;
1801     XtSetArg(argt[i], XmNbottomWidget,          login_text              ); i++;
1802
1803
1804
1805     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_LOGIN_LABEL, MC_DEF_LOGIN_LABEL);
1806     XtSetArg(argt[i], XmNlabelString,           xmstr                   ); i++;
1807     
1808     login_label = XmCreateLabel(login_form, "login_label", argt, i);
1809     XtManageChild(login_label);
1810
1811     XmStringFree(xmstr);
1812
1813 }
1814
1815
1816
1817
1818 /***************************************************************************
1819  *
1820  *  MakeOptionsMenu
1821  *
1822  *  Widgets: options_menu, options_item[]
1823  ***************************************************************************/
1824
1825 void 
1826 MakeOptionsMenu( void )
1827 {
1828     int         i, j, k;
1829
1830     struct stat statb;
1831
1832 #ifdef VG_TRACE
1833     vg_TRACE_EXECUTION("MakeOptionsMenu:  entered ...");
1834 #endif /* VG_TRACE */
1835
1836     /*
1837      * get the built-in pop_up menu from the DtMenuButton...
1838      */
1839      
1840     XtVaGetValues(options_button, DtNsubMenuId, &options_menu, NULL);
1841
1842     /*
1843      *  create language cascade menus...
1844      */
1845
1846     if ( lang_menu == NULL )
1847         MakeLangMenu();
1848
1849
1850     /*
1851      *  create first level menu items...
1852      */
1853     j = 0;
1854
1855     /*
1856      *  build [ Language ] menu pane if there are languages to choose from...
1857      */
1858     if ( lang_menu != NULL ) {
1859         /*
1860          *  [ Language ] menu pane...
1861          *  attach language cascade menu to this pane
1862          */
1863         i = InitArg(CascadeBG);
1864         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_LANG_LABEL, MC_DEF_LANG_LABEL);
1865         XtSetArg(argt[i], XmNlabelString,               xmstr           ); i++;
1866         XtSetArg(argt[i], XmNsubMenuId,                 lang_menu       ); i++;
1867         XtSetArg(argt[i], XmNrecomputeSize,             True            ); i++;
1868         options_item[j] = XmCreateCascadeButtonGadget(options_menu,
1869                                 "options_languages", argt, i);
1870         XmStringFree(xmstr);
1871         j++;
1872
1873         /*
1874          *  separator...
1875          */
1876         i = InitArg(SeparatorG);
1877         options_item[j] = XmCreateSeparatorGadget(options_menu,
1878                                                     "options_sep2",
1879                                                      argt, i);
1880         j++;
1881     }
1882
1883     if( session_menu == NULL)  {
1884         session_menu = XmCreatePulldownMenu(options_menu, "session_menu", NULL, 0);
1885
1886
1887     /*
1888      *  [ Dt "Reg" ] menu pane...
1889      */
1890     i = k = InitArg(ToggleBG);
1891     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_DT_LABEL, MC_DEF_DT_LABEL);
1892     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1893     XtSetArg(argt[i], XmNrecomputeSize,                 True            ); i++;
1894     XtSetArg(argt[i], XmNuserData,              logoInfo.bitmapFile     ); i++;
1895
1896     options_dt = XmCreateToggleButtonGadget(session_menu,
1897                                                  "options_dt",
1898                                                  argt, i);
1899     XmStringFree(xmstr);
1900     XtAddCallback(options_dt,
1901                   XmNvalueChangedCallback,
1902                   MenuItemCB,
1903                   (XtPointer) OB_DT);
1904     /*XtManageChild(options_dt);   */
1905     /*
1906      *  [ Dt Lite ] menu pane...
1907      */
1908     i = k;
1909     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_DTLITE_LABEL, MC_DEF_DTLITE_LABEL);
1910     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1911     XtSetArg(argt[i], XmNrecomputeSize,                 True            ); i++;
1912
1913     options_dtlite = XmCreateToggleButtonGadget(session_menu,
1914                                                  "options_dtlite",
1915                                                  argt, i);
1916     XmStringFree(xmstr);
1917     XtAddCallback(options_dtlite,
1918                   XmNvalueChangedCallback,
1919                   MenuItemCB,
1920                   (XtPointer) OB_DTLITE);
1921
1922
1923     }
1924
1925 if ( session_menu != NULL ) {
1926         /*
1927          *  [ Language ] menu pane...
1928          *  attach language cascade menu to this pane
1929          */
1930         i = InitArg(CascadeBG);
1931         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_SES_LABEL, MC_DEF_SES_LABEL);
1932         XtSetArg(argt[i], XmNlabelString,               xmstr           ); i++;
1933         XtSetArg(argt[i], XmNsubMenuId,                 session_menu       ); i++;
1934         XtSetArg(argt[i], XmNrecomputeSize,             True            ); i++;
1935         options_item[j] = XmCreateCascadeButtonGadget(options_menu,
1936                                 "session_menus", argt, i);
1937         XmStringFree(xmstr);
1938         j++;
1939
1940     /*
1941      *  separator...
1942      */
1943     i = InitArg(SeparatorG);
1944     options_item[j] = XmCreateSeparatorGadget(options_menu, "options_sep1",
1945                                                 argt, i);
1946     j++;
1947
1948     }
1949
1950     /*
1951      *  [ No Windows ] menu pane...
1952      */
1953     i = k = InitArg(PushBG);
1954     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_NW_LABEL, MC_DEF_NW_LABEL);
1955     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1956     options_item[j] = options_nowindows
1957                       = XmCreatePushButtonGadget(options_menu,
1958                                                  "options_noWindows",
1959                                                  argt, i);
1960     XmStringFree(xmstr);
1961     XtAddCallback(options_item[j], XmNactivateCallback,
1962                   MenuItemCB, (XtPointer) OB_NO_WINDOWS);
1963
1964     if (getenv(LOCATION) == NULL || strcmp(getenv(LOCATION), "local") != 0 )
1965         XtSetSensitive(options_item[j], False);
1966     j++;
1967
1968
1969     /* 
1970      *  [ Restart Server ] menu pane...
1971      */
1972     i = k = InitArg(PushBG);
1973     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_RS_LABEL, MC_DEF_RS_LABEL);
1974     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1975     options_item[j] = XmCreatePushButtonGadget(options_menu,
1976                                                  "options_restartServer",
1977                                                  argt, i); 
1978     XmStringFree(xmstr);
1979     XtAddCallback(options_item[j], XmNactivateCallback, 
1980                   MenuItemCB, (XtPointer) OB_RESTART_SERVER);
1981     j++;
1982
1983 #ifdef copyright_option
1984     /*
1985      *  separator...
1986      */
1987     i = InitArg(SeparatorG);
1988     options_item[j] = XmCreateSeparatorGadget(options_menu, "options_sep1",
1989                                                 argt, i);
1990     j++;
1991
1992
1993     /* 
1994      *  [ Copyright ] menu pane...
1995      */
1996     i = k = InitArg(PushBG);
1997     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_COPY_LABEL, MC_DEF_COPY_LABEL);
1998     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1999     options_item[j] = XmCreatePushButtonGadget(options_menu, 
2000                                                  "options_copyright",
2001                                                  argt, i);
2002     XmStringFree(xmstr);
2003     XtAddCallback(options_item[j], XmNactivateCallback, 
2004                   MenuItemCB, (XtPointer) OB_COPYRIGHT);
2005     j++;
2006 #endif
2007
2008     /*
2009      *  manage the [Options] menu...
2010      */
2011     XtManageChildren(options_item, j);
2012
2013
2014
2015     /*
2016      *  If the DT Lite Session Manager is not available, remove the DT Lite
2017      *  and DT menu panes. The actual widgets must still be created since
2018      *  other code (ex. MenuItemCB()) tries to obtain some of their resources.
2019      */
2020      
2021     if  ( stat(DTLITESESSION, &statb) != 0 ||
2022           ((statb.st_mode & S_IXOTH) != S_IXOTH) ) {
2023
2024         XtUnmanageChild(options_dtlite);
2025 /*
2026         XtUnmanageChild(options_dt);
2027 */
2028     }
2029
2030     if ( getenv(PINGINTERVAL) != NULL )
2031         XtUnmanageChild(options_nowindows);
2032         
2033
2034 }
2035
2036
2037
2038
2039 /***************************************************************************
2040  *
2041  *  MyInsert
2042  *
2043  *  Local self-insert action for the text widget. The default action
2044  *  discards control characters, which are allowed in password.
2045  ***************************************************************************/
2046
2047 static void 
2048 MyInsert( Widget w, XEvent *event, char **params, Cardinal *num_params )
2049 {
2050     char           str[32];
2051     XComposeStatus compstatus;
2052     int            n;
2053
2054     n = XLookupString((XKeyEvent *)event, str, sizeof(str),
2055                       (KeySym *)NULL, &compstatus);
2056
2057     if (n > 0) {
2058        str[n] = '\0';
2059        XmTextFieldInsert(w, XmTextFieldGetInsertionPosition(w), str);
2060     }
2061 }
2062
2063 /***************************************************************************
2064  *
2065  *  MyBackspace
2066  *
2067  *  Local backspace action for the text widget. 
2068  *  Deletes the last character of the password string in the 
2069  *  widget for each backspace key press, and also does not move the cursor
2070  *  position in the widget.
2071  ***************************************************************************/
2072
2073 static void
2074 MyBackspace( Widget w, XEvent *event, char **params, Cardinal *num_params )
2075 {
2076   LoginTextPtr textdata;
2077
2078   textdata = GetLoginTextPtr(w);
2079
2080   if (textdata && !textdata->bEcho && (int) strlen(textdata->noechobuf) > 0)
2081   { 
2082     textdata->noechobuf[strlen(textdata->noechobuf) - 1] = '\0';
2083   }
2084 }
2085
2086
2087 /***************************************************************************
2088  *
2089  *  ErrorHandler
2090  *
2091  *  X protocol error handler to override the default
2092  ***************************************************************************/
2093
2094 static int 
2095 ErrorHandler( Display *dpy, XErrorEvent *event )
2096 {
2097     return 0;
2098 }
2099
2100
2101
2102
2103 /***************************************************************************
2104  *
2105  *  xtErrorHandler
2106  *
2107  *  Xt protocol error handler to override the default
2108  ***************************************************************************/
2109
2110 static void 
2111 xtErrorHandler( String msg )
2112 {
2113     LogError((unsigned char *) "%s\n", msg ) ;
2114     exit(NOTIFY_RESTART);
2115 }
2116
2117
2118
2119
2120 /***************************************************************************
2121  *
2122  *  xtWarningHandler
2123  *
2124  *  Xt protocol error handler to override the default
2125  ***************************************************************************/
2126
2127 static void 
2128 xtWarningHandler( String msg )
2129 {
2130     LogError( (unsigned char *) "%s\n", msg ) ;
2131     return ;
2132 }
2133
2134
2135
2136
2137 /***************************************************************************
2138  *
2139  *  MakeOptionsProc
2140  *
2141  *  Timeout routine to build options menu
2142  ***************************************************************************/
2143
2144 static void 
2145 MakeOptionsProc( XtPointer data, XtIntervalId *id )
2146 {
2147
2148     if (options_menu == NULL)
2149         MakeOptionsMenu();
2150     
2151     return;
2152 }
2153
2154
2155
2156
2157 /***************************************************************************
2158  *
2159  *  Terminate
2160  *
2161  *  Catch a SIGTERM and unmanage display
2162  ***************************************************************************/
2163
2164 static SIGVAL
2165 Terminate( int arg )
2166
2167 {
2168     if(-1 == write(1, "terminate", 9)) {
2169         perror(strerror(errno));
2170     }
2171     CleanupAndExit(NULL, NOTIFY_ABORT);
2172 }
2173
2174
2175
2176
2177 /***************************************************************************
2178  *
2179  *  DebugWidgetResources
2180  *
2181  *  Get widget resources
2182  ***************************************************************************/
2183
2184 typedef struct resource_values {
2185     int height;
2186     int width;
2187     int x;
2188     int y;
2189     int rightAttachment;
2190     int leftAttachment;
2191     int topAttachment;
2192     int bottomAttachment;
2193 } ResourceValues;
2194
2195 static void
2196 DebugWidgetResources(Widget w)
2197
2198 {
2199     struct resource_values      values;
2200     int i;
2201
2202     i = 0;
2203     bzero((char *) &values, sizeof(values));
2204     XtSetArg(argt[i], XmNheight,        &values.height); i++;
2205     XtSetArg(argt[i], XmNwidth,         &values.width); i++;
2206     XtSetArg(argt[i], XmNx,             &values.x); i++;
2207     XtSetArg(argt[i], XmNy,             &values.y); i++;
2208     XtSetArg(argt[i], XmNrightAttachment,       &values.rightAttachment); i++;
2209     XtSetArg(argt[i], XmNleftAttachment,        &values.leftAttachment); i++;
2210     XtSetArg(argt[i], XmNtopAttachment,         &values.topAttachment); i++;
2211     XtSetArg(argt[i], XmNbottomAttachment,      &values.bottomAttachment); i++;
2212
2213     XtGetValues(w, argt, i);
2214 }
2215
2216 /***************************************************************************
2217  *
2218  * GetDisplayName (void) - transform the display name into a "short"
2219  *   host name that is used to create a display-specific session.
2220  *
2221  * The display name should match one of the following patterns:
2222  *
2223  *   1. host            (non-qualified)
2224  *   2. host.domain
2225  *   3. host:n
2226  *   4. host:n.s
2227  *   5. host.domain:n
2228  *   6. host.domain:n.s
2229  *
2230  * Note that 1 and 2 will be used if the display name is actually
2231  * something like unix:0, local:0 or 0:0
2232  *
2233  ***************************************************************************/
2234 static char * 
2235 GetDisplayName (void)
2236 {
2237     char                host[MAXHOSTNAMELEN];
2238     static char         tmp[MAXHOSTNAMELEN + 3];
2239     char                * pch;
2240     char                * col;
2241     char                * dot;
2242
2243     pch = XDisplayString(dpyinfo.dpy);
2244
2245     if (!pch ||
2246         !strncmp (pch, "local:0", 7) ||
2247         !strncmp (pch, "unix:0", 6) ||
2248         !strncmp (pch, ":0.0", 4) ||
2249         !strncmp (pch, ":0", 2)) {
2250         gethostname (host, MAXHOSTNAMELEN);
2251         pch = host;
2252     }
2253
2254     col = strchr (pch, ':');
2255     dot = strchr (pch, '.');
2256
2257     if (!col) {
2258         if (dot) {
2259             strncpy (tmp, pch, dot - pch);      /* case #2 above */
2260             tmp[dot - pch] = '\000';
2261         } else {
2262             strcpy (tmp, pch);                  /* case #1 above */
2263         }
2264     } else {
2265         if (!dot || (dot > col)) {              /* case #3 and 4 above */
2266             strncpy (tmp, pch, col - pch);
2267             tmp[col - pch] = '\000';
2268         } else {                                /* case # 5 and 6 above */
2269             strncpy (tmp, pch, dot - pch);
2270             tmp[dot - pch] = '\000';
2271         }
2272     }
2273     
2274     strcat (tmp, ":0");
2275     return (tmp);
2276 }