Spelling fixes
[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 HP_EXTENSIONS
486     _XHPNlioctl(0,0,-1,0);
487 #endif
488 #ifdef VG_TRACE
489     vg_TRACE_EXECUTION("main:  exited _XHPNlioctl ...");
490 #endif /* VG_TRACE */
491 #endif
492
493     /*
494      * get information about the display...
495      */
496
497     dpyinfo.dpy         = XtDisplay(toplevel);
498 /*    dpyinfo.name      = "";*/
499     dpyinfo.screen      = DefaultScreen(dpyinfo.dpy);
500     dpyinfo.root        = RootWindow   (dpyinfo.dpy, dpyinfo.screen);
501     dpyinfo.depth       = DefaultDepth (dpyinfo.dpy, dpyinfo.screen);
502     dpyinfo.width       = DisplayWidth (dpyinfo.dpy, dpyinfo.screen);
503     dpyinfo.height      = DisplayHeight(dpyinfo.dpy, dpyinfo.screen);
504     dpyinfo.black_pixel = BlackPixel   (dpyinfo.dpy, dpyinfo.screen);
505     dpyinfo.visual      = DefaultVisual(dpyinfo.dpy, dpyinfo.screen);
506
507                                 /* JET - for Xinerama, see if the extension */
508                                 /* is available and init accordingly. */
509
510 #ifdef USE_XINERAMA
511
512     dpyinfo.DtXineramaInfo = _DtXineramaInit(dpyinfo.dpy);
513
514 # ifdef DEBUG
515     if (dpyinfo.DtXineramaInfo == NULL)
516       {                         /* No xinerama, no joy. */
517         fprintf(stderr, "### JET VGMAIN: Xinerama NOT available.\n"); 
518       }
519     else
520       {
521         fprintf(stderr, "### JET VGMAIN: Xinerama available, scrns = %d\n",
522                 dpyinfo.DtXineramaInfo->numscreens);
523       }
524 # endif
525
526 #endif
527
528     /*
529      *  check if any overrides were passed in the argv string...
530      */
531
532     for ( i = 1; i < argc; i++) {
533         switch(i) {
534
535         default:
536             break;
537         }
538     }
539
540     /*
541      *  add the unit convertor for resources...
542      */
543      
544     XtAddConverter(XmRString, XmRUnitType, XmCvtStringToUnitType, NULL, 0);
545
546     /*
547      *  get user-specified resources...
548      */
549
550     SetResourceDatabase();
551  
552     XtGetApplicationResources(toplevel, &appInfo, AppResources,
553                                 XtNumber(AppResources), NULL, 0);
554
555 #ifdef VG_TRACE
556     vg_TRACE_EXECUTION("main:  got application resources ...");
557 #endif /* VG_TRACE */
558     
559     /*
560      *  build widgets...
561      */
562
563 #ifdef VG_TRACE
564     vg_TRACE_EXECUTION("main:  making UI ...");
565 #endif /* VG_TRACE */
566     MakeBackground();   /* login_shell, table, matte              */
567     MakeLogo();                 /* logo, logo_pixmap, logo_shadow         */
568     MakeGreeting();             /* greeting                               */
569     MakeLogin();                /* login_matte ...                        */
570     MakeDtlabel();              /* Show Desktop selection in options  menu*/
571
572     /*
573      *  grab the display and keyboard...
574      *  moved it from before to after creating text widgets in MakeLogin
575      *  RK 01.11.94
576      */
577     if ( ! nograb )
578         SecureDisplay();
579
580     MakeButtons();              /* ok, clear, options, help buttons       */
581     MakeDialog(copyright);      /* copyright dialog                       */
582
583     if (appInfo.optionsDelay == 0 )
584         MakeOptionsMenu();      /* make option_button pop-up menu         */
585     else
586         XtAddTimeOut((unsigned long) appInfo.optionsDelay * 1000, 
587                       MakeOptionsProc, NULL);
588
589     MakeAltDtButtons();        /* make alt desktop buttons, if any       */
590 #ifdef VG_TRACE
591     vg_TRACE_EXECUTION("main:  made UI ...");
592 #endif /* VG_TRACE */
593
594     /*
595      * Add request callback.
596      XtAddInput(0, (XtPointer)XtInputReadMask, RequestCB, NULL);
597      */
598    
599     /*
600      *  force the focus to the login_text widget...
601      */
602 /*
603      XtAddEventHandler(login_text, ExposureMask, False, 
604                         FakeFocusIn, NULL);
605 */
606
607     /*
608      *  create windows for the widgets...
609      */
610      
611 #ifdef VG_TRACE
612     vg_TRACE_EXECUTION("main:  going to realize login_shell ...");
613 #endif /* VG_TRACE */
614     XtRealizeWidget(login_shell);
615 #ifdef VG_TRACE
616     vg_TRACE_EXECUTION("main:  realized login_shell ...");
617 #endif /* VG_TRACE */
618     
619     
620     /*
621      *  miscellaneous stuff...
622      *
623      *  - turn off keyboard bell
624      *  - return root cursor to normal from hourglass
625      *  - start pinging the server
626      */
627      
628     ChangeBell("off");
629     if (appInfo.workspaceCursor)
630     {
631         MakeRootCursor();
632     }
633     else
634     {
635         XUndefineCursor(dpyinfo.dpy, dpyinfo.root);
636     }
637     PingServerCB(NULL, NULL);
638
639     
640     /*
641      *  bring up the windows and enter event loop...
642      */
643
644     XRaiseWindow(XtDisplay(greeting), XtWindow(greeting));
645         /*
646     XRaiseWindow(XtDisplay(logo_shadow), XtWindow(logo_shadow));
647     XRaiseWindow(XtDisplay(logo), XtWindow(logo));
648         */
649     /* XtPopup(login_shell, XtGrabNone); */
650     _DtEnvControl( DT_ENV_RESTORE_PRE_DT );
651
652     /*
653      * Add request callback.
654      */
655      sleep(5);
656      XtAddInput(0, (XtPointer)XtInputReadMask, RequestCB, NULL);
657    
658 #ifdef VG_TRACE
659     vg_TRACE_EXECUTION("main:  entering XtMainLoop ...");
660 #endif /* VG_TRACE */
661     XtMainLoop();
662     exit (0);
663 }
664
665
666
667
668 /***************************************************************************
669  *
670  *  InitToolKit
671  *
672  *  initialize the toolkit
673  ***************************************************************************/
674
675 #define MINTIMEOUT      20
676
677 static jmp_buf  syncJump;
678
679 static SIGVAL
680 syncTimeout( int arg )
681
682 {
683     longjmp (syncJump, 1);
684 }
685
686
687 static Widget 
688 InitToolKit( int argc, char **argv )
689 {
690     
691     int         timeout;                /* timeout to initialize toolkit   */
692     char        *t;
693     Widget      root;
694     
695 #ifdef VG_TRACE
696     vg_TRACE_EXECUTION("InitToolKit: enter ...");
697 #endif /* VG_TRACE */
698
699     /*
700      *  use server grabTimeout as initial value for timeout...
701      */
702
703     timeout = ((t = (char *)getenv(GRABTIMEOUT)) == NULL ? 0 : atoi(t));
704     timeout += MINTIMEOUT;  /* minimum MINTIMEOUT seconds */
705
706
707     /*
708      *  initialize the toolkit. Wrap a timer around it in case the server
709      *  is grabbed.
710      */
711
712     signal (SIGALRM, syncTimeout);
713     if (setjmp (syncJump)) {
714         LogError(
715                 ReadCatalog(MC_LOG_SET,MC_LOG_NO_DPYINIT,MC_DEF_LOG_NO_DPYINIT),
716                 dpyinfo.name);
717         exit(NOTIFY_RESTART);
718     }
719
720     alarm ((unsigned) timeout);
721
722     root = XtInitialize("dtlogin", "Dtlogin", NULL, 0, 
723                          &argc, argv);
724     /* Disable Drag and Drop  RK 11.02.93 */
725     XtVaSetValues(XmGetXmDisplay(XtDisplay(root)),
726                 XmNdragInitiatorProtocolStyle, XmDRAG_NONE,
727                 NULL);
728  
729
730     alarm (0);
731     signal (SIGALRM, SIG_DFL);
732
733     return(root);
734 }
735
736
737
738
739 /***************************************************************************
740  *
741  *  MakeRootCursor
742  *
743  *  Widgets: none
744  ***************************************************************************/
745
746 static void 
747 MakeRootCursor( void )
748 {
749         Cursor vg_cursor;
750
751         vg_cursor = XCreateFontCursor (dpyinfo.dpy, XC_left_ptr);
752
753         XDefineCursor (dpyinfo.dpy, dpyinfo.root, vg_cursor);
754
755         return;
756 }
757
758 /***************************************************************************
759  *
760  *  MakeBackground
761  *
762  *  Widgets: login_shell, table, matte
763  ***************************************************************************/
764
765 static void 
766 MakeBackground( void )
767 {
768     register int i;
769     
770 #ifdef VG_TRACE
771     vg_TRACE_EXECUTION("MakeBackground:  entered ...");
772 #endif /* VG_TRACE */
773     /* 
774      * create the login shell widget...
775      */
776
777     i = 0;
778
779     /*          CORE resource set                                       */
780     XtSetArg(argt[i], XmNancestorSensitive,     True                    ); i++;
781     XtSetArg(argt[i], XmNbackgroundPixmap,      XmUNSPECIFIED_PIXMAP    ); i++;
782     XtSetArg(argt[i], XmNborderWidth,           0                       ); i++;
783     XtSetArg(argt[i], XmNmappedWhenManaged,     False                   ); i++;
784     XtSetArg(argt[i], XmNsensitive,             True                    ); i++;
785     XtSetArg(argt[i], XmNtranslations,          NULL                    ); i++;
786
787     /*          COMPOSITE resource set                                  */
788     XtSetArg(argt[i], XmNinsertPosition,        NULL                    ); i++;
789
790     /*          SHELL resource set (set to avoid interference by user)  */
791     XtSetArg(argt[i], XmNallowShellResize,      False                   ); i++;
792     XtSetArg(argt[i], XmNcreatePopupChildProc,  NULL                    ); i++;
793     XtSetArg(argt[i], XmNgeometry,              NULL                    ); i++;
794     XtSetArg(argt[i], XmNpopupCallback,         NULL                    ); i++;
795     XtSetArg(argt[i], XmNpopdownCallback,       NULL                    ); i++;
796     XtSetArg(argt[i], XmNoverrideRedirect,      False                   ); i++;
797     XtSetArg(argt[i], XmNsaveUnder,             False                   ); i++;
798
799     login_shell = XtCreatePopupShell("login_shell", transientShellWidgetClass,
800                                      toplevel, argt, i);
801     XtAddCallback(login_shell, XmNpopupCallback, LayoutCB, NULL);
802
803     /* Fix to display Input Method's status area. */
804     XtSetArg(argt[0], XmNheight, dpyinfo.height);
805     XtSetValues(login_shell, argt, 1);
806
807
808     /* 
809      * create the full-screen drawing area...
810      */
811
812     i = InitArg(DrawingA);
813     XtSetArg(argt[i], XmNwidth,                 dpyinfo.width           ); i++;
814     XtSetArg(argt[i], XmNheight,                dpyinfo.height          ); i++;
815     XtSetArg(argt[i], XmNunitType,              XmPIXELS                ); i++;
816
817     table = XtCreateManagedWidget("table", xmDrawingAreaWidgetClass,
818                                    login_shell, argt, i);
819
820     XtAddEventHandler(table, ButtonPressMask, False, RefreshEH, NULL);
821     XtAddCallback(table, XmNhelpCallback, ShowDialogCB, (XtPointer) help);
822
823
824     /* 
825      * create the main matte...
826      */
827
828     i = InitArg(Form);
829     /*                XmNwidth,                 (set by user)           */
830     /*                XmNheight,                (set by user)           */
831     XtSetArg(argt[i], XmNshadowThickness,       SHADOW_THICKNESS        ); i++;
832 /*
833     XtSetArg(argt[i], XmNshadowType,    XmSHADOW_OUT    ); i++;
834     XtSetArg(argt[i], XmNshadowThickness,       5       ); i++;
835 */
836
837     matte = XmCreateForm(table, "matte", argt, i);
838     XtManageChild(matte);
839
840     i = 0;
841         XtSetArg(argt[i], XmNshadowType, XmSHADOW_OUT); i++;
842         XtSetArg(argt[i], XmNshadowThickness, 2); i++;
843         XtSetArg(argt[i], XmNtopAttachment, XmATTACH_FORM); i++;
844         XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_FORM); i++;
845         XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM); i++;
846         /*
847         XtSetArg(argt[i], XmNrightAttachment, XmATTACH_FORM); i++;
848         */
849         XtSetArg(argt[i], XmNtopOffset, 15); i++;
850         XtSetArg(argt[i], XmNbottomOffset, 15); i++;
851         XtSetArg(argt[i], XmNleftOffset, 15); i++;
852         /*
853         XtSetArg(argt[i], XmNrightOffset, 15); i++;
854         */
855         matteFrame = XmCreateFrame(matte, "matteFrame", argt, i);
856     XtManageChild(matteFrame);
857
858         i = 0;
859         matte1 = XmCreateForm(matteFrame, "matte1", argt, i);
860     XtManageChild(matte1);
861         
862 }
863
864
865 static void
866 MakeAltDtButtons( void )
867 {
868 int i,j;
869 struct stat     statb;
870 char        *startup_name; 
871 XrmValue    startup_value; 
872 char        temp[MAXPATHLEN] = "\0";
873 char        *session;
874 FILE        *ls;
875 char        lastsess[MAXPATHLEN];
876 Widget      default_dt = NULL;
877 int         default_is_custom_dt = True;
878 int         found_alt_dt = False;
879 char        *temp_p;
880
881
882 #ifdef VG_TRACE
883     vg_TRACE_EXECUTION("MakeAltDtButtons:  entered ...");
884 #endif /* VG_TRACE */
885
886     if (getenv("SESSION_SET") == NULL) {
887         default_is_custom_dt = False;
888     }
889
890     if ((session = getenv ("SESSION")) == NULL)  {
891         session = "  ";
892     }
893
894     if(appInfo.altDts > 0) { 
895       if ((alt_dts =
896             (Widget *) calloc(appInfo.altDts, sizeof (Widget))) == NULL)
897         LogError(
898                 ReadCatalog(MC_ERROR_SET,MC_NO_MEMORY, MC_DEF_NO_MEMORY),
899                 dpyinfo.name);
900
901      for(i = 0; i < appInfo.altDts; ++i) {
902        int is_default;
903
904        is_default = FALSE;
905
906        /* alt desktops begin numbering with 1 */
907        sprintf(altdtname,"%s%d", "Dtlogin*altDtName",i+1);
908        sprintf(altdtclass,"%s%d", "Dtlogin*AltDtName",i+1); 
909
910        sprintf(altdtkey,"%s%d","Dtlogin*altDtKey",i+1); 
911        sprintf(altdtkeyclass,"%s%d","Dtlogin*AltDtKey",i+1); 
912
913        sprintf(altdtstart,"%s%d","Dtlogin*altDtStart",i+1); 
914        sprintf(altdtstartclass,"%s%d","Dtlogin*AltDtStart",i+1); 
915
916         if (XrmGetResource(
917                         XtDatabase(dpyinfo.dpy), 
918                         altdtkey, altdtkeyclass,
919                         &keyrmtype, &keyrmvalue) == True) {
920           /* 
921            * remove trailing spaces 
922            */
923           if(strchr(keyrmvalue.addr,' '))
924               temp_p = strtok(keyrmvalue.addr," ");
925           else 
926               temp_p =  keyrmvalue.addr;
927
928           /* 
929            * Make sure the key file exists.
930            */
931           if (stat( temp_p, &statb) == 0) { 
932
933             j = InitArg(ToggleBG);
934             if (XrmGetResource(
935                         XtDatabase(dpyinfo.dpy),
936                         altdtstart, altdtstartclass,
937                         &startup_name, &startup_value) == True) {
938
939               /* 
940                * remove trailing spaces 
941                */
942                if (strchr(startup_value.addr, ' ')) 
943                    snprintf(temp, sizeof(temp), "%s", strtok(startup_value.addr, " "));
944                else
945                    snprintf(temp, sizeof(temp), "%s", startup_value.addr);
946
947                if (default_is_custom_dt)
948                  if (strcmp(session, temp) == 0)    {
949                      is_default = TRUE;
950                  }
951             }
952             else
953               LogError((unsigned char *)"No startup script for altdt %d \n", i);
954
955             if (XrmGetResource(
956                         XtDatabase(dpyinfo.dpy), 
957                         altdtname, altdtclass,
958                         &rmtype, &rmvalue) == True) {
959               if (! strncmp(rmvalue.addr, DISPLAYNAME, strlen(DISPLAYNAME))) {
960                 char  *host;
961
962                 host = GetDisplayName();
963                 snprintf(temp, sizeof(temp), "%s - %s", host, rmvalue.addr + strlen(DISPLAYNAME));
964                 xmstr = XmStringCreateLocalized(temp);
965               }
966               else {
967                    xmstr = XmStringCreateLocalized(rmvalue.addr);
968               }
969             }
970             else {
971               LogError((unsigned char *)
972                         "Couldn't find the altdtname resource in the db\n");
973               sprintf(altdtname,"%s%d", "Alternate Desktop-",i+1);
974               xmstr = XmStringCreateLocalized(altdtname);
975             }
976
977             sprintf(altdtlogo,"%s%d","Dtlogin*altDtLogo",i+1); 
978             sprintf(altlogoclass,"%s%d","Dtlogin*AltDtLogo",i+1); 
979             if (XrmGetResource(
980                         XtDatabase(dpyinfo.dpy),
981                         altdtlogo, altlogoclass,
982                         &logotype, &logovalue) == True) {
983               XtSetArg(argt[j], XmNuserData, logovalue.addr); j++;
984             }
985             else{       
986               XtSetArg(argt[j], XmNuserData, logoInfo.bitmapFile); j++;
987             }
988
989             XtSetArg(argt[j], XmNlabelString, xmstr); j++;
990             XtSetArg(argt[j], XmNrecomputeSize, True); j++;
991  
992             alt_dts[i] = XmCreateToggleButtonGadget(
993                                                 session_menu,
994                                                 rmvalue.addr, argt, j);
995             XmStringFree(xmstr);
996             XtAddCallback(
997                         alt_dts[i],
998                         XmNvalueChangedCallback, MenuItemCB,
999                         (XtPointer) OB_ALT_DTS);
1000             XtManageChild(alt_dts[i]);
1001             found_alt_dt = True;
1002
1003             if (is_default)
1004               default_dt = alt_dts[i];
1005           }
1006           else  
1007             LogError((unsigned char *) "Couldn't find the keyfile \n");
1008         }
1009         else
1010             LogError((unsigned char *)
1011                      "Couldn't find the altkeyfile resource in the database\n");
1012       }  
1013     }
1014
1015     if ((appInfo.altDts == 0) || !found_alt_dt)
1016       XtManageChild(options_dt);  
1017         
1018     /* 
1019      * Use the regular desktop if none of the known sessions matched the
1020      * specified custom session.
1021      */
1022     if (default_is_custom_dt && NULL == default_dt) {
1023         default_dt = options_dt;
1024         if (found_alt_dt)
1025           XtManageChild(options_dt);  
1026     }
1027
1028     /*
1029      *  [ Failsafe Session ] menu pane... 
1030      */
1031     i = InitArg(ToggleBG);
1032     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_FS_LABEL, MC_DEF_FS_LABEL);
1033     XtSetArg(argt[i], XmNuserData,       logoInfo.bitmapFile            ); i++;
1034     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1035     XtSetArg(argt[i], XmNrecomputeSize,                 True            ); i++;
1036     options_failsafe = XmCreateToggleButtonGadget(session_menu, 
1037                 "options_failsafe", argt, i);
1038     XmStringFree(xmstr);
1039     XtAddCallback(options_failsafe, XmNvalueChangedCallback, 
1040                 MenuItemCB, (XtPointer) OB_FAILSAFE);
1041
1042     XtManageChild(options_failsafe);
1043
1044     /* 
1045      * which option to set..
1046      */
1047     SetDefaultDt(default_dt);
1048     SetDtLabelAndIcon();
1049 }
1050
1051 /***************************************************************************
1052  *
1053  *  MakeButtons
1054  *
1055  *  Widgets:    ok_button, clear_button, options_button, help_button
1056  ***************************************************************************/
1057
1058
1059 static void 
1060 MakeButtons( void )
1061 {
1062     register int i;
1063
1064     Dimension   max_width;      /* maximum width  of a set of widgets      */
1065     Dimension   max_height;     /* maximum height of a set of widgets      */
1066     Dimension   thick1;         /* defaultButtonShadowThickness */
1067     Dimension   thick2;         /* shadowThickness */
1068
1069     int         origin;         /* horizontal origin for button placement  */
1070     int         spacing;        /* spacing between buttons (width/32)      */
1071
1072 #ifdef VG_TRACE
1073     vg_TRACE_EXECUTION("MakeButtons:  entered ...");
1074 #endif /* VG_TRACE */
1075      
1076     /* 
1077      * create the buttons...
1078      */
1079
1080     /* ok button */
1081     
1082     i = InitArg(PushBG);
1083     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
1084     XtSetArg(argt[i], XmNbottomPosition, 95); i++;
1085     XtSetArg(argt[i], XmNtraversalOn, True); i++;
1086
1087     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_OK_LABEL, MC_DEF_OK_LABEL );
1088     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1089
1090     ok_button = XmCreatePushButtonGadget(matte1, "ok_button", argt, i);
1091
1092     XmStringFree(xmstr);
1093     XtManageChild(ok_button);
1094
1095     XtAddCallback(ok_button, XmNactivateCallback, RespondChallengeCB, NULL);    
1096
1097
1098     /* clear button */
1099
1100     i -= 1;
1101     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_CLEAR_LABEL, MC_DEF_CLEAR_LABEL);
1102     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1103
1104     clear_button = XmCreatePushButtonGadget(matte1, "clear_button", argt, i);
1105
1106     XmStringFree(xmstr);
1107     XtManageChild(clear_button);
1108     XtAddCallback(clear_button, XmNactivateCallback, RespondClearCB,
1109                   (XtPointer) 0);   
1110
1111
1112     /* help button */
1113     
1114     i -= 1;
1115     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_HELP_LABEL, MC_DEF_HELP_LABEL);
1116     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1117
1118     help_button = XmCreatePushButtonGadget(matte1, "help_button", argt, i);
1119     XtAddCallback(help_button, XmNactivateCallback, ShowDialogCB, 
1120                   (XtPointer) help);
1121     XmStringFree(xmstr);
1122     XtManageChild(help_button);
1123
1124     /* options button */
1125
1126     i = InitArg(Label);
1127     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
1128     XtSetArg(argt[i], XmNbottomPosition, 95); i++;
1129     xmstr = ReadCatalogXms(
1130                         MC_LABEL_SET,
1131                         MC_OPTIONS_LABEL,
1132                         MC_DEF_OPTIONS_LABEL );
1133
1134     XtSetArg(argt[i], XmNlabelString, xmstr); i++;
1135     XtSetArg(argt[i], XmNtraversalOn, True); i++;
1136     options_button = DtCreateMenuButton(matte1, "options_button", argt, i);
1137     XtOverrideTranslations(
1138                         options_button,
1139                         XtParseTranslationTable(" <Key> Return: Select()"));
1140
1141     XtManageChild(options_button);
1142     XmStringFree(xmstr);
1143
1144     /*
1145      *  tell form that ok_button is the default button...
1146      */
1147
1148     i = 0;
1149     XtSetArg(argt[i], XmNdefaultButton,         ok_button               ); i++;
1150     XtSetValues(matte1,  argt, i);
1151         
1152     /*
1153      * make all buttons *look* the same size...
1154      */
1155      
1156
1157     max_width = max_height = 0;
1158     GetBiggest(ok_button, &max_width, &max_height);
1159     GetBiggest(clear_button,   &max_width, &max_height);
1160     GetBiggest(options_button, &max_width, &max_height);
1161     GetBiggest(help_button,    &max_width, &max_height);
1162
1163     if ( (int) max_width < MIN_BUTTON_SIZE) max_width = MIN_BUTTON_SIZE;
1164     
1165     i = 0;
1166     XtSetArg(argt[i], XmNdefaultButtonShadowThickness, &thick1); i++;
1167     XtSetArg(argt[i], XmNshadowThickness, &thick2); i++;
1168     XtGetValues(ok_button,      argt, i);
1169     thick1 *= 4;
1170     thick1 += thick2;
1171
1172     i = 0;
1173     XtSetArg(argt[i], XmNwidth,                 max_width               ); i++;
1174     XtSetArg(argt[i], XmNheight,                max_height              ); i++;
1175     XtSetArg(argt[i], XmNrecomputeSize,         False                   ); i++;
1176     XtSetArg(argt[i], XmNbottomOffset,          thick1                  ); i++;
1177     XtSetValues(options_button, argt, i);
1178
1179     i = 0;
1180     XtSetArg(argt[i], XmNwidth,                 max_width + 2*thick1    ); i++;
1181     XtSetArg(argt[i], XmNheight,                max_height + 2*thick1   ); i++;
1182     XtSetArg(argt[i], XmNrecomputeSize,         False                   ); i++;
1183
1184     XtSetValues(ok_button,      argt, i);
1185     XtSetValues(clear_button,   argt, i);
1186     XtSetValues(help_button,    argt, i);
1187 }
1188
1189
1190
1191
1192 /***************************************************************************
1193  *
1194  *  MakeDialog
1195  *
1196  *  Widgets: error_message, help_message, copyright_msg, hostname_message,
1197  *           passwd_message
1198  ***************************************************************************/
1199
1200 void 
1201 MakeDialog( DialogType dtype )
1202 {
1203     register int i, j;
1204
1205     int         width;
1206     
1207     FILE        *fp, *fopen();
1208     char        buffer[128];
1209
1210     Widget      w = NULL, text;
1211     Dimension txt_width, txt_height;
1212     XmString    ok, cancel, nw, sv;
1213
1214     Widget      tlev;           /* JET - warning, there be dragons here */
1215     unsigned int dpwidth, dpheight, xorg, yorg;
1216
1217     
1218     
1219 #ifdef VG_TRACE
1220     vg_TRACE_EXECUTION("MakeDialog:  entered ...");
1221 #endif /* VG_TRACE */
1222     /*
1223      *  do things common to all dialogs...
1224      */
1225
1226 #ifdef USE_XINERAMA
1227                                 /* get info on prefered screen */
1228     if (!_DtXineramaGetScreen(dpyinfo.DtXineramaInfo, 
1229                               appInfo.xineramaPreferredScreen,
1230                               &dpwidth, &dpheight, &xorg, &yorg))
1231       {                         /* no joy here either - setup for normal */
1232         dpwidth = dpyinfo.width;
1233         dpheight = dpyinfo.height;
1234         xorg = yorg = 0;
1235       }
1236                                 /* else, should be setup properly */
1237     XWarpPointer(dpyinfo.dpy,None,dpyinfo.root,0,0,0,0,dpwidth/2,dpheight/2);
1238 #else  /* no Xinerama */
1239     dpwidth = dpyinfo.width;
1240     dpheight = dpyinfo.height;
1241     xorg = yorg = 0;
1242 #endif    
1243
1244     ok     = ReadCatalogXms(MC_LABEL_SET, MC_OK_LABEL, MC_DEF_OK_LABEL);
1245     cancel = ReadCatalogXms(MC_LABEL_SET, MC_CANCEL_LABEL, MC_DEF_CANCEL_LABEL);
1246
1247     i = InitArg(MessageBox);
1248     XtSetArg(argt[i], XmNmarginHeight,          MBOX_MARGIN_HEIGHT      ); i++;
1249     XtSetArg(argt[i], XmNmarginWidth,           MBOX_MARGIN_WIDTH       ); i++;
1250     XtSetArg(argt[i], XmNshadowThickness,       SHADOW_THICKNESS        ); i++;
1251     XtSetArg(argt[i], XmNokLabelString,         ok                      ); i++;
1252     XtSetArg(argt[i], XmNcancelLabelString,     cancel                  ); i++;
1253     XtSetArg(argt[i], XmNnoResize,              False                   ); i++;
1254     XtSetArg(argt[i], XmNresizePolicy,          XmRESIZE_ANY            ); i++;
1255
1256     /*
1257      *  create the various dialogs...
1258      */
1259
1260     /* JET - check the matte widget, and if non-null, well use that as
1261      * the parent for dialogs.  Otherwise use table (the original
1262      * toplevel widget for this func).  This is useful for Xinerama so
1263      * that child dialogs are centered on the matte, and not the whole
1264      * SLS screen.
1265      */
1266
1267     if (matte != (Widget)NULL)
1268       tlev = matte;
1269     else
1270       tlev = table;
1271
1272    switch (dtype) {
1273
1274     case error:
1275         xmstr = ReadCatalogXms(MC_ERROR_SET, MC_LOGIN, "");
1276         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1277
1278         w = XmCreateErrorDialog(tlev, "error_message", argt, i);
1279         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
1280         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1281
1282         error_message = w;
1283         break;
1284
1285
1286     case help:
1287
1288         txt_width = (dpwidth > 850) ? 800 : dpwidth - 50;
1289         txt_height = (dpheight > 900) ? 600 : dpheight - 300;
1290
1291         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_HELP_LABEL, MC_DEF_HELP_LABEL);
1292         XtSetArg(argt[i], XmNmessageString, xmstr); i++;
1293
1294         w = XmCreateInformationDialog(tlev, "help_message", argt, i);
1295         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
1296         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1297
1298         i = InitArg(Text);
1299         XtSetArg(argt[i], XmNheight, txt_height); i++;
1300         XtSetArg(argt[i], XmNwidth, txt_width); i++;
1301         XtSetArg(argt[i], XmNeditMode, XmMULTI_LINE_EDIT); i++;
1302         XtSetArg(argt[i], XmNscrollBarDisplayPolicy, XmAS_NEEDED); i++;
1303         XtSetArg(argt[i], XmNscrollingPolicy, XmAUTOMATIC); i++;
1304         XtSetArg(argt[i], XmNeditable, False); i++;
1305         XtSetArg(
1306                 argt[i],
1307                 XmNvalue, ReadCatalog(MC_HELP_SET, MC_HELP, MC_DEF_HELP)); i++;
1308         text = XmCreateScrolledText(w, "help_message_text", argt, i);
1309
1310         XtManageChild(text);
1311         XtManageChild(w);
1312         help_message = w;
1313         break;
1314
1315
1316     case copyright:
1317         if ((fp = fopen(COPYRIGHT,"r")) == NULL)
1318             xmstr = XmStringCreate("Cannot open copyright file '/etc/copyright'.",
1319                                 XmFONTLIST_DEFAULT_TAG);
1320         else {
1321             xmstr = (XmString) NULL;
1322         
1323             while (fgets(buffer, 128, fp) != NULL) {
1324                 j = strlen(buffer);
1325                 if ( buffer[j-1] == '\n' ) buffer[j-1] = '\0';
1326             
1327                 if ( xmstr != NULL )
1328                     xmstr = XmStringConcat(xmstr, XmStringSeparatorCreate());
1329
1330                 xmstr = XmStringConcat(xmstr,
1331                                        XmStringCreate(buffer,
1332                                        XmFONTLIST_DEFAULT_TAG));
1333             }       
1334             fclose(fp);
1335         }
1336
1337         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1338
1339         w = XmCreateInformationDialog(tlev, "copyright_msg", argt, i);
1340         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
1341         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1342         
1343         XtAddCallback(w, XmNokCallback, CopyrightCB, (XtPointer) 0);    
1344
1345         copyright_msg = w;
1346         break;
1347     
1348
1349     case hostname:
1350             
1351         nw = ReadCatalogXms(MC_LABEL_SET, MC_NW_LABEL,  MC_DEF_NW_LABEL);
1352         sv = ReadCatalogXms(MC_LABEL_SET, MC_START_LABEL, MC_DEF_START_LABEL);
1353
1354         xmstr = ReadCatalogXms(MC_HELP_SET, MC_SYSTEM, MC_DEF_SYSTEM);
1355         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1356         XtSetArg(argt[i], XmNokLabelString,             nw              ); i++;
1357         XtSetArg(argt[i], XmNcancelLabelString,         sv              ); i++;
1358
1359         w = XmCreateWarningDialog(tlev, "hostname_msg", argt, i);
1360
1361         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1362
1363         XmStringFree(nw);
1364         XmStringFree(sv);
1365
1366         hostname_message = w;
1367         break;
1368
1369
1370     case expassword:
1371
1372         xmstr = ReadCatalogXms(MC_ERROR_SET, MC_PASSWD_EXPIRED, 
1373                             MC_DEF_PASSWD_EXPIRED);
1374         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1375
1376         w = XmCreateQuestionDialog(tlev, "password_msg", argt, i);
1377
1378         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1379
1380         passwd_message = w;
1381         break;
1382     }
1383
1384     /*
1385      *  finish up...
1386      */
1387
1388     switch (dtype) {
1389       case error:
1390       case hostname:
1391       case expassword:
1392         XtAddCallback(w, XmNokCallback,     RespondDialogCB, NULL);
1393         XtAddCallback(w, XmNcancelCallback, RespondDialogCB, NULL);
1394         break;
1395     }
1396
1397
1398     XtSetArg(argt[0], XmNdialogStyle,   XmDIALOG_APPLICATION_MODAL      ); i++;
1399     if(w) {
1400         XtSetValues(w, argt, 1);
1401     }
1402
1403     XmStringFree(xmstr);
1404     XmStringFree(ok);
1405     XmStringFree(cancel);
1406
1407
1408     /*
1409      *  adjust the width of the "ok" button on the dialogs...
1410      */
1411
1412     width = (dtype == hostname ? FromMM(4000) : MIN_BUTTON_SIZE);
1413     
1414     i = 0;
1415     XtSetArg(argt[i], XmNrecomputeSize,                 False           ); i++;
1416     XtSetArg(argt[i], XmNwidth,                         width           ); i++;
1417
1418     XtSetValues(XmMessageBoxGetChild(w, XmDIALOG_OK_BUTTON), argt, i);
1419
1420 }
1421
1422 /***************************************************************************
1423  *
1424  *  MakeDtlabel
1425  *
1426  *  Widgets:    dt_label
1427  ***************************************************************************/
1428
1429 static void
1430 MakeDtlabel( void )
1431 {
1432     int i;
1433
1434 #ifdef VG_TRACE
1435     vg_TRACE_EXECUTION("MakeDtlabel:  entered ...");
1436 #endif /* VG_TRACE */
1437
1438     i = InitArg(LabelG);
1439     XtSetArg(argt[i], XmNtraversalOn,           False                   ); i++;
1440     XtSetArg(argt[i], XmNtopAttachment,         XmATTACH_WIDGET         ); i++;
1441     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_FORM           ); i++;
1442     XtSetArg(argt[i], XmNrightAttachment,       XmATTACH_FORM           ); i++;
1443     XtSetArg(argt[i], XmNalignment,             XmALIGNMENT_CENTER      ); i++;
1444     XtSetArg(argt[i], XmNtopWidget,             greeting                ); i++;
1445  
1446     dt_label = XmCreateLabel(matte1, "dt_label", argt, i);
1447     XtManageChild(dt_label);
1448 }
1449
1450
1451
1452 /***************************************************************************
1453  *
1454  *  MakeGreeting
1455  *
1456  *  Widgets:    greeting
1457  ***************************************************************************/
1458
1459 typedef  struct {
1460     char        *labelString;   /* string for label                        */
1461     char        *persLabelString; /* alternate string for label */
1462     XmFontList  fontList;
1463 } GreetInfo, *GreetInfoPtr;
1464
1465 static GreetInfo greetInfo;
1466
1467 static  XtResource greetResources[] = {
1468     {XmNlabelString, XmCLabelString, 
1469         XmRString, sizeof(char *),
1470         XtOffset(GreetInfoPtr, labelString), XtRString, "default"       },
1471
1472     {"persLabelString", "PersLabelString",
1473         XmRString, sizeof(char *),
1474         XtOffset(GreetInfoPtr, persLabelString), XtRString, "default"       },
1475
1476     {XmNfontList, XmCFontList, 
1477         XmRFontList, sizeof(XmFontList),
1478         XtOffset(GreetInfoPtr, fontList), XtRString, NULL               }
1479 };     
1480
1481 static void 
1482 MakeGreeting( void )
1483 {
1484     register int i;
1485
1486     char    *greetmsg;
1487     char    host[128];
1488     char    disp[128];
1489     char    *p, *q, *s, *t;
1490     int     newLine = False;
1491     int     skip;
1492
1493 #ifdef VG_TRACE
1494     vg_TRACE_EXECUTION("MakeGreeting:  entered ...");
1495 #endif /* VG_TRACE */
1496
1497     /*
1498      *  get the user's greeting preferences...
1499      */
1500      
1501     XtGetSubresources(table, &greetInfo, "greeting", "Greeting",
1502         greetResources, XtNumber(greetResources), NULL, 0);
1503
1504
1505     /*
1506      *  get the local hostname...
1507      */
1508      
1509     gethostname(host, sizeof (host));
1510     if ( (p = strchr(host,'.')) != NULL )
1511         *p = '\0';
1512
1513     /* 
1514     **  Get display name (for %DisplayName% substitutions),
1515     **  reducing "a.b.c.d:0" constructs to shorter "a:0" form.
1516     */
1517
1518     strncpy(disp,
1519         dpyinfo.name ? dpyinfo.name : (DisplayString(dpyinfo.dpy)), 127);
1520     disp[127] = '\0';
1521     p = strchr(disp, '.');
1522     t = strchr(disp, ':');
1523     if (p && t) strcpy(p,t);
1524     
1525
1526     /*
1527      *  use the default string if the user has not specified one...
1528      */
1529
1530     if ( greetInfo.persLabelString &&
1531          strcmp(greetInfo.persLabelString, "default") == 0 ) {
1532         const char *msg;
1533         msg =
1534           (const char *)
1535           ReadCatalog(MC_LABEL_SET,MC_PERS_GREET_LABEL,MC_DEF_PERS_GREET_LABEL);
1536         greetInfo.persLabelString = strdup(msg);
1537     }
1538  
1539     if ( greetInfo.labelString && 
1540          strcmp(greetInfo.labelString, "default") == 0 ) {
1541         
1542         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_GREET_LABEL,MC_DEF_GREET_LABEL);
1543         xmstr = XmStringConcat(xmstr,
1544                                XmStringCreate(" ",  XmFONTLIST_DEFAULT_TAG));
1545         xmstr = XmStringConcat(xmstr,
1546                                XmStringCreate(host, XmFONTLIST_DEFAULT_TAG));
1547     }
1548     else {
1549         /*
1550          *  scan user's message for %LocalHost% token. Replace with hostname
1551          *  if found...
1552          */
1553          
1554
1555         if ( !greetInfo.labelString                     ||
1556              strlen(greetInfo.labelString) == 0         ||
1557              strcmp(greetInfo.labelString, "None") == 0 ||
1558              strcmp(greetInfo.labelString, "none") == 0 )
1559              
1560             greetmsg = strdup(" ");
1561         else {
1562             greetmsg = strdup(greetInfo.labelString);
1563         }
1564
1565         s = greetmsg;
1566         xmstr = (XmString) NULL;
1567
1568         do {
1569             q = s;
1570         
1571             /*
1572              *  scan for a new line character in remaining label string. 
1573              *  If found, work with that substring first...
1574              */
1575              
1576             if ( (p = strchr(q, '\n')) != NULL ) {
1577                 *p = '\0';
1578                 newLine = True;
1579                 s = ++p;
1580
1581                 if ( *q == '\0' )       /* handle consecutive newlines */
1582                     q = " ";
1583                     
1584             }
1585             else {
1586                 newLine = False;
1587             }
1588             
1589             /*
1590              *  replace all occurrences of %LocalHost% and %DisplayName%
1591              *  in the current substring...
1592              */
1593              
1594             while (1) {
1595                 p = strstr(q, LOCALHOST);
1596                 t = strstr(q, DISPLAYNAME);
1597                 
1598                 if (p && t) { /* both present? do whichever comes first */
1599                     if (p > t) p = NULL;
1600                     else t = NULL;
1601                 }
1602                 if (p) { /* replace a %LocalHost% string */
1603                     t = host;
1604                     skip = sizeof(LOCALHOST);
1605                 } else if (t) { /* replace a %DisplayName% string */
1606                     p = t;
1607                     t = disp;
1608                     skip = sizeof(DISPLAYNAME);
1609                 } else /* nothing left to replace */
1610                     break;
1611                 *p = '\0';
1612                 xmstr = XmStringConcat(xmstr,
1613                                    XmStringCreate(q,
1614                                    XmFONTLIST_DEFAULT_TAG));
1615                 xmstr = XmStringConcat(xmstr,
1616                                    XmStringCreate(t,
1617                                    XmFONTLIST_DEFAULT_TAG));
1618                 q = p + skip - 1;
1619             }
1620
1621             if ( strlen(q) != 0 )
1622                 xmstr = XmStringConcat(xmstr,
1623                                    XmStringCreate(q,
1624                                    XmFONTLIST_DEFAULT_TAG));
1625
1626             /*
1627              *  add a line separator if this is a multi-line greeting...
1628              */
1629              
1630             if ( newLine == True ) {
1631                 xmstr = XmStringConcat(xmstr, XmStringSeparatorCreate());
1632             }
1633                              
1634         } while ( newLine == True ) ;
1635         
1636         free(greetmsg);
1637     }
1638
1639
1640     /* 
1641      * create the Welcome message...
1642      */
1643     
1644     i = InitArg(LabelG);
1645     XtSetArg(argt[i], XmNtraversalOn,           False                   ); i++;
1646     XtSetArg(argt[i], XmNlabelString,           xmstr                   ); i++;
1647     XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM); i++;
1648     XtSetArg(argt[i], XmNtopAttachment, XmATTACH_POSITION); i++; 
1649    /* XtSetArg(argt[i], XmNtopPosition, 15); i++; */
1650    /* Changed this to accommodate desktop label */
1651     XtSetArg(argt[i], XmNtopPosition, 9); i++; 
1652     XtSetArg(argt[i], XmNrightAttachment, XmATTACH_FORM); i++;
1653
1654
1655     /*
1656      *  use the user's font if one has been specified, otherwise use
1657      *  the application's default...
1658      */
1659
1660     if ( greetInfo.fontList != NULL ) {
1661         XtSetArg(argt[i], XmNfontList,          greetInfo.fontList      ); i++;
1662     }
1663
1664     greeting = XmCreateLabel(matte1, "greeting", argt, i);
1665     XtManageChild(greeting);
1666
1667     XmStringFree(xmstr);
1668 }
1669
1670 /***************************************************************************
1671  *
1672  *  MakeLogin
1673  *
1674  *  Widgets: login_matte, 
1675  *           login_form, login_label, login_text
1676  ***************************************************************************/
1677
1678 static void 
1679 MakeLogin( void )
1680 {
1681     register int i;
1682     int j;
1683     LoginTextPtr textdata; 
1684     XtTranslations      textTable;
1685     Widget passwd_text;
1686     String greetstr;
1687
1688 #ifdef VG_TRACE
1689     vg_TRACE_EXECUTION("MakeLogin:  entered ...");
1690 #endif /* VG_TRACE */
1691
1692     /*
1693      *  create the login form
1694      */
1695
1696     i = 0;
1697     XtSetArg(argt[i], XmNshadowThickness, 0); i++; 
1698     XtSetArg(argt[i], XmNresizable,             False                   ); i++;
1699     XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM); i++;
1700     XtSetArg(argt[i], XmNleftOffset, 80); i++;
1701     XtSetArg(argt[i], XmNrightAttachment, XmATTACH_FORM); i++;
1702     XtSetArg(argt[i], XmNrightOffset, 80); i++;
1703     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
1704     XtSetArg(argt[i], XmNbottomPosition, 65); i++;
1705 /*
1706     XtSetArg(argt[i], XmNresizePolicy, XmRESIZE_ANY); i++;
1707 */
1708     XtSetArg(argt[i], XmNallowShellResize, True); i++;
1709
1710     login_form = XmCreateForm(matte1, "login_form", argt, i);
1711     XtManageChild(login_form);
1712
1713     /*
1714      *  create the login text field...
1715      */
1716
1717     i = InitArg(Text);
1718     XtSetArg(argt[i], XmNbottomAttachment,      XmATTACH_POSITION       ); i++;
1719     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_POSITION       ); i++;
1720     XtSetArg(argt[i], XmNrightAttachment,       XmATTACH_POSITION       ); i++;
1721     XtSetArg(argt[i], XmNbottomPosition,        95                      ); i++;
1722     XtSetArg(argt[i], XmNrightPosition,         80                      ); i++;
1723     XtSetArg(argt[i], XmNleftPosition,          20                      ); i++;
1724     XtSetArg(argt[i], XmNselectionArrayCount,   1                       ); i++;
1725     XtSetArg(argt[i], XmNmaxLength,             80                      ); i++;
1726     XtSetArg(argt[i], XmNmappedWhenManaged,     False                   ); i++;
1727
1728     textdata = malloc(sizeof(LoginText));
1729     XtSetArg(argt[i], XmNuserData,              textdata                ); i++;
1730
1731     login_text = XmCreateTextField(login_form, "login_text", argt, i);
1732
1733     /*
1734      *  From Human Interface model, Tab key operation should work same on
1735      *  user field as it does on password field.  Password field is setup
1736      *  to take Tab key as password data.  HIE model is for user field to
1737      *  do same.
1738      */  
1739     XtOverrideTranslations(
1740                         login_text,
1741                         XtParseTranslationTable(
1742                                 " Shift <Key>Tab: prev-tab-group() \n\
1743                                    Ctrl <Key>Tab: next-tab-group() "));
1744
1745     XtManageChild(login_text);
1746 #ifdef __hpux
1747     XtAddCallback(login_text, XmNfocusCallback, TextFocusCB, NULL);
1748 #endif
1749
1750
1751     XtAddActions(textActions, 2);
1752     textTable = XtParseTranslationTable(textEventBindings);
1753
1754 #if 0
1755     XtSetArg(argt[i], XmNtranslations,          textTable               ); i++;
1756 #endif
1757     XtSetArg(argt[i], XmNverifyBell,            False                   ); i++;
1758
1759     passwd_text = XmCreateTextField(login_form, "passwd_text", argt, i);
1760
1761     textdata->bEcho = True;
1762     textdata->noechobuf[0] = '\0';
1763     textdata->text[0] = passwd_text;
1764     textdata->text[1] = login_text;
1765
1766     XtManageChild(passwd_text);
1767 #ifdef __hpux
1768     XtAddCallback(passwd_text, XmNfocusCallback, TextFocusCB, NULL);
1769 #endif
1770     XtAddCallback(passwd_text, XmNmodifyVerifyCallback, EditPasswdCB, NULL);
1771
1772    /*
1773     * Get default greeting string
1774     */
1775     i = 0;
1776     XtSetArg(argt[i], XmNlabelString, &textdata->onGreeting); i++;
1777     XtGetValues(greeting, argt, i);
1778     textdata->offGreetingFormat = greetInfo.persLabelString;
1779     textdata->offGreetingUname = NULL;
1780
1781     /*
1782      *  create the login labels...
1783      */
1784
1785     i = InitArg(LabelG);
1786
1787    /* modified recomputeSize initial value from False to True, fails 
1788     * when setting longer strings. Manifested as bug ID:1200690.
1789     */ 
1790     XtSetArg(argt[i], XmNrecomputeSize,         True                    ); i++;
1791
1792     XtSetArg(argt[i], XmNtraversalOn,           False                   ); i++;
1793     XtSetArg(argt[i], XmNbottomAttachment,      XmATTACH_WIDGET         ); i++;
1794     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_OPPOSITE_WIDGET); i++;
1795
1796 /* XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM           ); i++; 
1797    Commented this statement to  align login_label and login_text                        
1798     XtSetArg(argt[i], XmNrightAttachment,       XmATTACH_FORM           ); i++;
1799     XtSetArg(argt[i], XmNalignment,             XmALIGNMENT_CENTER      ); i++;
1800     XtSetArg(argt[i], XmNbottomOffset,          10                      ); i++;
1801 */
1802
1803     XtSetArg(argt[i], XmNleftWidget,            login_text              ); i++;
1804     XtSetArg(argt[i], XmNbottomWidget,          login_text              ); i++;
1805
1806
1807
1808     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_LOGIN_LABEL, MC_DEF_LOGIN_LABEL);
1809     XtSetArg(argt[i], XmNlabelString,           xmstr                   ); i++;
1810     
1811     login_label = XmCreateLabel(login_form, "login_label", argt, i);
1812     XtManageChild(login_label);
1813
1814     XmStringFree(xmstr);
1815
1816 }
1817
1818
1819
1820
1821 /***************************************************************************
1822  *
1823  *  MakeOptionsMenu
1824  *
1825  *  Widgets: options_menu, options_item[]
1826  ***************************************************************************/
1827
1828 void 
1829 MakeOptionsMenu( void )
1830 {
1831     int         i, j, k;
1832
1833     struct stat statb;
1834
1835 #ifdef VG_TRACE
1836     vg_TRACE_EXECUTION("MakeOptionsMenu:  entered ...");
1837 #endif /* VG_TRACE */
1838
1839     /*
1840      * get the built-in pop_up menu from the DtMenuButton...
1841      */
1842      
1843     XtVaGetValues(options_button, DtNsubMenuId, &options_menu, NULL);
1844
1845     /*
1846      *  create language cascade menus...
1847      */
1848
1849     if ( lang_menu == NULL )
1850         MakeLangMenu();
1851
1852
1853     /*
1854      *  create first level menu items...
1855      */
1856     j = 0;
1857
1858     /*
1859      *  build [ Language ] menu pane if there are languages to choose from...
1860      */
1861     if ( lang_menu != NULL ) {
1862         /*
1863          *  [ Language ] menu pane...
1864          *  attach language cascade menu to this pane
1865          */
1866         i = InitArg(CascadeBG);
1867         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_LANG_LABEL, MC_DEF_LANG_LABEL);
1868         XtSetArg(argt[i], XmNlabelString,               xmstr           ); i++;
1869         XtSetArg(argt[i], XmNsubMenuId,                 lang_menu       ); i++;
1870         XtSetArg(argt[i], XmNrecomputeSize,             True            ); i++;
1871         options_item[j] = XmCreateCascadeButtonGadget(options_menu,
1872                                 "options_languages", argt, i);
1873         XmStringFree(xmstr);
1874         j++;
1875
1876         /*
1877          *  separator...
1878          */
1879         i = InitArg(SeparatorG);
1880         options_item[j] = XmCreateSeparatorGadget(options_menu,
1881                                                     "options_sep2",
1882                                                      argt, i);
1883         j++;
1884     }
1885
1886     if( session_menu == NULL)  {
1887         session_menu = XmCreatePulldownMenu(options_menu, "session_menu", NULL, 0);
1888
1889
1890     /*
1891      *  [ Dt "Reg" ] menu pane...
1892      */
1893     i = k = InitArg(ToggleBG);
1894     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_DT_LABEL, MC_DEF_DT_LABEL);
1895     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1896     XtSetArg(argt[i], XmNrecomputeSize,                 True            ); i++;
1897     XtSetArg(argt[i], XmNuserData,              logoInfo.bitmapFile     ); i++;
1898
1899     options_dt = XmCreateToggleButtonGadget(session_menu,
1900                                                  "options_dt",
1901                                                  argt, i);
1902     XmStringFree(xmstr);
1903     XtAddCallback(options_dt,
1904                   XmNvalueChangedCallback,
1905                   MenuItemCB,
1906                   (XtPointer) OB_DT);
1907     /*XtManageChild(options_dt);   */
1908     /*
1909      *  [ Dt Lite ] menu pane...
1910      */
1911     i = k;
1912     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_DTLITE_LABEL, MC_DEF_DTLITE_LABEL);
1913     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1914     XtSetArg(argt[i], XmNrecomputeSize,                 True            ); i++;
1915
1916     options_dtlite = XmCreateToggleButtonGadget(session_menu,
1917                                                  "options_dtlite",
1918                                                  argt, i);
1919     XmStringFree(xmstr);
1920     XtAddCallback(options_dtlite,
1921                   XmNvalueChangedCallback,
1922                   MenuItemCB,
1923                   (XtPointer) OB_DTLITE);
1924
1925
1926     }
1927
1928 if ( session_menu != NULL ) {
1929         /*
1930          *  [ Language ] menu pane...
1931          *  attach language cascade menu to this pane
1932          */
1933         i = InitArg(CascadeBG);
1934         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_SES_LABEL, MC_DEF_SES_LABEL);
1935         XtSetArg(argt[i], XmNlabelString,               xmstr           ); i++;
1936         XtSetArg(argt[i], XmNsubMenuId,                 session_menu       ); i++;
1937         XtSetArg(argt[i], XmNrecomputeSize,             True            ); i++;
1938         options_item[j] = XmCreateCascadeButtonGadget(options_menu,
1939                                 "session_menus", argt, i);
1940         XmStringFree(xmstr);
1941         j++;
1942
1943     /*
1944      *  separator...
1945      */
1946     i = InitArg(SeparatorG);
1947     options_item[j] = XmCreateSeparatorGadget(options_menu, "options_sep1",
1948                                                 argt, i);
1949     j++;
1950
1951     }
1952
1953
1954      
1955
1956
1957 #ifndef __apollo
1958     /*
1959      *  [ No Windows ] menu pane...
1960      */
1961     i = k = InitArg(PushBG);
1962     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_NW_LABEL, MC_DEF_NW_LABEL);
1963     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1964     options_item[j] = options_nowindows
1965                       = XmCreatePushButtonGadget(options_menu,
1966                                                  "options_noWindows",
1967                                                  argt, i);
1968     XmStringFree(xmstr);
1969     XtAddCallback(options_item[j], XmNactivateCallback,
1970                   MenuItemCB, (XtPointer) OB_NO_WINDOWS);
1971
1972     if (getenv(LOCATION) == NULL || strcmp(getenv(LOCATION), "local") != 0 )
1973         XtSetSensitive(options_item[j], False);
1974     j++;
1975 #endif
1976
1977
1978     /* 
1979      *  [ Restart Server ] menu pane...
1980      */
1981     i = k = InitArg(PushBG);
1982     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_RS_LABEL, MC_DEF_RS_LABEL);
1983     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1984     options_item[j] = XmCreatePushButtonGadget(options_menu,
1985                                                  "options_restartServer",
1986                                                  argt, i); 
1987     XmStringFree(xmstr);
1988     XtAddCallback(options_item[j], XmNactivateCallback, 
1989                   MenuItemCB, (XtPointer) OB_RESTART_SERVER);
1990     j++;
1991
1992 #ifdef copyright_option
1993     /*
1994      *  separator...
1995      */
1996     i = InitArg(SeparatorG);
1997     options_item[j] = XmCreateSeparatorGadget(options_menu, "options_sep1",
1998                                                 argt, i);
1999     j++;
2000
2001
2002     /* 
2003      *  [ Copyright ] menu pane...
2004      */
2005     i = k = InitArg(PushBG);
2006     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_COPY_LABEL, MC_DEF_COPY_LABEL);
2007     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
2008     options_item[j] = XmCreatePushButtonGadget(options_menu, 
2009                                                  "options_copyright",
2010                                                  argt, i);
2011     XmStringFree(xmstr);
2012     XtAddCallback(options_item[j], XmNactivateCallback, 
2013                   MenuItemCB, (XtPointer) OB_COPYRIGHT);
2014     j++;
2015 #endif
2016
2017     /*
2018      *  manage the [Options] menu...
2019      */
2020     XtManageChildren(options_item, j);
2021
2022
2023
2024     /*
2025      *  If the DT Lite Session Manager is not available, remove the DT Lite
2026      *  and DT menu panes. The actual widgets must still be created since
2027      *  other code (ex. MenuItemCB()) tries to obtain some of their resources.
2028      */
2029      
2030     if  ( stat(DTLITESESSION, &statb) != 0 ||
2031           ((statb.st_mode & S_IXOTH) != S_IXOTH) ) {
2032
2033         XtUnmanageChild(options_dtlite);
2034 /*
2035         XtUnmanageChild(options_dt);
2036 */
2037     }
2038
2039     if ( getenv(PINGINTERVAL) != NULL )
2040         XtUnmanageChild(options_nowindows);
2041         
2042
2043 }
2044
2045
2046
2047
2048 /***************************************************************************
2049  *
2050  *  MyInsert
2051  *
2052  *  Local self-insert action for the text widget. The default action
2053  *  discards control characters, which are allowed in password.
2054  ***************************************************************************/
2055
2056 static void 
2057 MyInsert( Widget w, XEvent *event, char **params, Cardinal *num_params )
2058 {
2059     char           str[32];
2060     XComposeStatus compstatus;
2061     int            n;
2062
2063     n = XLookupString((XKeyEvent *)event, str, sizeof(str),
2064                       (KeySym *)NULL, &compstatus);
2065
2066     if (n > 0) {
2067        str[n] = '\0';
2068        XmTextFieldInsert(w, XmTextFieldGetInsertionPosition(w), str);
2069     }
2070 }
2071
2072 /***************************************************************************
2073  *
2074  *  MyBackspace
2075  *
2076  *  Local backspace action for the text widget. 
2077  *  Deletes the last character of the password string in the 
2078  *  widget for each backspace key press, and also does not move the cursor
2079  *  position in the widget.
2080  ***************************************************************************/
2081
2082 static void
2083 MyBackspace( Widget w, XEvent *event, char **params, Cardinal *num_params )
2084 {
2085   LoginTextPtr textdata;
2086
2087   textdata = GetLoginTextPtr(w);
2088
2089   if (textdata && !textdata->bEcho && (int) strlen(textdata->noechobuf) > 0)
2090   { 
2091     textdata->noechobuf[strlen(textdata->noechobuf) - 1] = '\0';
2092   }
2093 }
2094
2095
2096 /***************************************************************************
2097  *
2098  *  ErrorHandler
2099  *
2100  *  X protocol error handler to override the default
2101  ***************************************************************************/
2102
2103 static int 
2104 ErrorHandler( Display *dpy, XErrorEvent *event )
2105 {
2106     return 0;
2107 }
2108
2109
2110
2111
2112 /***************************************************************************
2113  *
2114  *  xtErrorHandler
2115  *
2116  *  Xt protocol error handler to override the default
2117  ***************************************************************************/
2118
2119 static void 
2120 xtErrorHandler( String msg )
2121 {
2122     LogError((unsigned char *) "%s\n", msg ) ;
2123     exit(NOTIFY_RESTART);
2124 }
2125
2126
2127
2128
2129 /***************************************************************************
2130  *
2131  *  xtWarningHandler
2132  *
2133  *  Xt protocol error handler to override the default
2134  ***************************************************************************/
2135
2136 static void 
2137 xtWarningHandler( String msg )
2138 {
2139     LogError( (unsigned char *) "%s\n", msg ) ;
2140     return ;
2141 }
2142
2143
2144
2145
2146 /***************************************************************************
2147  *
2148  *  MakeOptionsProc
2149  *
2150  *  Timeout routine to build options menu
2151  ***************************************************************************/
2152
2153 static void 
2154 MakeOptionsProc( XtPointer data, XtIntervalId *id )
2155 {
2156
2157     if (options_menu == NULL)
2158         MakeOptionsMenu();
2159     
2160     return;
2161 }
2162
2163
2164
2165
2166 /***************************************************************************
2167  *
2168  *  Terminate
2169  *
2170  *  Catch a SIGTERM and unmanage display
2171  ***************************************************************************/
2172
2173 static SIGVAL
2174 Terminate( int arg )
2175
2176 {
2177     if(-1 == write(1, "terminate", 9)) {
2178         perror(strerror(errno));
2179     }
2180     CleanupAndExit(NULL, NOTIFY_ABORT);
2181 }
2182
2183
2184
2185
2186 /***************************************************************************
2187  *
2188  *  DebugWidgetResources
2189  *
2190  *  Get widget resources
2191  ***************************************************************************/
2192
2193 typedef struct resource_values {
2194     int height;
2195     int width;
2196     int x;
2197     int y;
2198     int rightAttachment;
2199     int leftAttachment;
2200     int topAttachment;
2201     int bottomAttachment;
2202 } ResourceValues;
2203
2204 static void
2205 DebugWidgetResources(Widget w)
2206
2207 {
2208     struct resource_values      values;
2209     int i;
2210
2211     i = 0;
2212     bzero((char *) &values, sizeof(values));
2213     XtSetArg(argt[i], XmNheight,        &values.height); i++;
2214     XtSetArg(argt[i], XmNwidth,         &values.width); i++;
2215     XtSetArg(argt[i], XmNx,             &values.x); i++;
2216     XtSetArg(argt[i], XmNy,             &values.y); i++;
2217     XtSetArg(argt[i], XmNrightAttachment,       &values.rightAttachment); i++;
2218     XtSetArg(argt[i], XmNleftAttachment,        &values.leftAttachment); i++;
2219     XtSetArg(argt[i], XmNtopAttachment,         &values.topAttachment); i++;
2220     XtSetArg(argt[i], XmNbottomAttachment,      &values.bottomAttachment); i++;
2221
2222     XtGetValues(w, argt, i);
2223 }
2224
2225 /***************************************************************************
2226  *
2227  * GetDisplayName (void) - transform the display name into a "short"
2228  *   host name that is used to create a display-specific session.
2229  *
2230  * The display name should match one of the following patterns:
2231  *
2232  *   1. host            (non-qualified)
2233  *   2. host.domain
2234  *   3. host:n
2235  *   4. host:n.s
2236  *   5. host.domain:n
2237  *   6. host.domain:n.s
2238  *
2239  * Note that 1 and 2 will be used if the display name is actually
2240  * something like unix:0, local:0 or 0:0
2241  *
2242  ***************************************************************************/
2243 static char * 
2244 GetDisplayName (void)
2245 {
2246     char                host[MAXHOSTNAMELEN];
2247     static char         tmp[MAXHOSTNAMELEN + 3];
2248     char                * pch;
2249     char                * col;
2250     char                * dot;
2251
2252     pch = XDisplayString(dpyinfo.dpy);
2253
2254     if (!pch ||
2255         !strncmp (pch, "local:0", 7) ||
2256         !strncmp (pch, "unix:0", 6) ||
2257         !strncmp (pch, ":0.0", 4) ||
2258         !strncmp (pch, ":0", 2)) {
2259         gethostname (host, MAXHOSTNAMELEN);
2260         pch = host;
2261     }
2262
2263     col = strchr (pch, ':');
2264     dot = strchr (pch, '.');
2265
2266     if (!col) {
2267         if (dot) {
2268             strncpy (tmp, pch, dot - pch);      /* case #2 above */
2269             tmp[dot - pch] = '\000';
2270         } else {
2271             strcpy (tmp, pch);                  /* case #1 above */
2272         }
2273     } else {
2274         if (!dot || (dot > col)) {              /* case #3 and 4 above */
2275             strncpy (tmp, pch, col - pch);
2276             tmp[col - pch] = '\000';
2277         } else {                                /* case # 5 and 6 above */
2278             strncpy (tmp, pch, dot - pch);
2279             tmp[dot - pch] = '\000';
2280         }
2281     }
2282     
2283     strcat (tmp, ":0");
2284     return (tmp);
2285 }