Patches from pkgsrc-WIP
[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 librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: 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                    strcpy(temp, strtok(startup_value.addr," "));
944                else
945                    strcpy(temp, 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                 strcpy(temp, host);
964                 strcat(temp, " - ");
965                 strcat(temp, rmvalue.addr + strlen(DISPLAYNAME));
966                 xmstr = XmStringCreateLocalized(temp);
967               }
968               else {
969                    xmstr = XmStringCreateLocalized(rmvalue.addr);
970               }
971             }
972             else {
973               LogError((unsigned char *)
974                         "Couldn't find the altdtname resource in the db\n");
975               sprintf(altdtname,"%s%d", "Alternate Desktop-",i+1);
976               xmstr = XmStringCreateLocalized(altdtname);
977             }
978
979             sprintf(altdtlogo,"%s%d","Dtlogin*altDtLogo",i+1); 
980             sprintf(altlogoclass,"%s%d","Dtlogin*AltDtLogo",i+1); 
981             if (XrmGetResource(
982                         XtDatabase(dpyinfo.dpy),
983                         altdtlogo, altlogoclass,
984                         &logotype, &logovalue) == True) {
985               XtSetArg(argt[j], XmNuserData, logovalue.addr); j++;
986             }
987             else{       
988               XtSetArg(argt[j], XmNuserData, logoInfo.bitmapFile); j++;
989             }
990
991             XtSetArg(argt[j], XmNlabelString, xmstr); j++;
992             XtSetArg(argt[j], XmNrecomputeSize, True); j++;
993  
994             alt_dts[i] = XmCreateToggleButtonGadget(
995                                                 session_menu,
996                                                 rmvalue.addr, argt, j);
997             XmStringFree(xmstr);
998             XtAddCallback(
999                         alt_dts[i],
1000                         XmNvalueChangedCallback, MenuItemCB,
1001                         (XtPointer) OB_ALT_DTS);
1002             XtManageChild(alt_dts[i]);
1003             found_alt_dt = True;
1004
1005             if (is_default)
1006               default_dt = alt_dts[i];
1007           }
1008           else  
1009             LogError((unsigned char *) "Couldn't find the keyfile \n");
1010         }
1011         else
1012             LogError((unsigned char *)
1013                      "Couldn't find the altkeyfile resource in the database\n");
1014       }  
1015     }
1016
1017     if ((appInfo.altDts == 0) || !found_alt_dt)
1018       XtManageChild(options_dt);  
1019         
1020     /* 
1021      * Use the regular desktop if none of the known sessions matched the
1022      * specified custom session.
1023      */
1024     if (default_is_custom_dt && NULL == default_dt) {
1025         default_dt = options_dt;
1026         if (found_alt_dt)
1027           XtManageChild(options_dt);  
1028     }
1029
1030     /*
1031      *  [ Failsafe Session ] menu pane... 
1032      */
1033     i = InitArg(ToggleBG);
1034     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_FS_LABEL, MC_DEF_FS_LABEL);
1035     XtSetArg(argt[i], XmNuserData,       logoInfo.bitmapFile            ); i++;
1036     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1037     XtSetArg(argt[i], XmNrecomputeSize,                 True            ); i++;
1038     options_failsafe = XmCreateToggleButtonGadget(session_menu, 
1039                 "options_failsafe", argt, i);
1040     XmStringFree(xmstr);
1041     XtAddCallback(options_failsafe, XmNvalueChangedCallback, 
1042                 MenuItemCB, (XtPointer) OB_FAILSAFE);
1043
1044     XtManageChild(options_failsafe);
1045
1046     /* 
1047      * which option to set..
1048      */
1049     SetDefaultDt(default_dt);
1050     SetDtLabelAndIcon();
1051 }
1052
1053 /***************************************************************************
1054  *
1055  *  MakeButtons
1056  *
1057  *  Widgets:    ok_button, clear_button, options_button, help_button
1058  ***************************************************************************/
1059
1060
1061 static void 
1062 MakeButtons( void )
1063 {
1064     register int i;
1065
1066     Dimension   max_width;      /* maximum width  of a set of widgets      */
1067     Dimension   max_height;     /* maximum height of a set of widgets      */
1068     Dimension   thick1;         /* defaultButtonShadowThickness */
1069     Dimension   thick2;         /* shadowThickness */
1070
1071     int         origin;         /* horizontal origin for button placement  */
1072     int         spacing;        /* spacing between buttons (width/32)      */
1073
1074 #ifdef VG_TRACE
1075     vg_TRACE_EXECUTION("MakeButtons:  entered ...");
1076 #endif /* VG_TRACE */
1077      
1078     /* 
1079      * create the buttons...
1080      */
1081
1082     /* ok button */
1083     
1084     i = InitArg(PushBG);
1085     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
1086     XtSetArg(argt[i], XmNbottomPosition, 95); i++;
1087     XtSetArg(argt[i], XmNtraversalOn, True); i++;
1088
1089     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_OK_LABEL, MC_DEF_OK_LABEL );
1090     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1091
1092     ok_button = XmCreatePushButtonGadget(matte1, "ok_button", argt, i);
1093
1094     XmStringFree(xmstr);
1095     XtManageChild(ok_button);
1096
1097     XtAddCallback(ok_button, XmNactivateCallback, RespondChallengeCB, NULL);    
1098
1099
1100     /* clear button */
1101
1102     i -= 1;
1103     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_CLEAR_LABEL, MC_DEF_CLEAR_LABEL);
1104     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1105
1106     clear_button = XmCreatePushButtonGadget(matte1, "clear_button", argt, i);
1107
1108     XmStringFree(xmstr);
1109     XtManageChild(clear_button);
1110     XtAddCallback(clear_button, XmNactivateCallback, RespondClearCB,
1111                   (XtPointer) 0);   
1112
1113
1114     /* help button */
1115     
1116     i -= 1;
1117     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_HELP_LABEL, MC_DEF_HELP_LABEL);
1118     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1119
1120     help_button = XmCreatePushButtonGadget(matte1, "help_button", argt, i);
1121     XtAddCallback(help_button, XmNactivateCallback, ShowDialogCB, 
1122                   (XtPointer) help);
1123     XmStringFree(xmstr);
1124     XtManageChild(help_button);
1125
1126     /* options button */
1127
1128     i = InitArg(Label);
1129     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
1130     XtSetArg(argt[i], XmNbottomPosition, 95); i++;
1131     xmstr = ReadCatalogXms(
1132                         MC_LABEL_SET,
1133                         MC_OPTIONS_LABEL,
1134                         MC_DEF_OPTIONS_LABEL );
1135
1136     XtSetArg(argt[i], XmNlabelString, xmstr); i++;
1137     XtSetArg(argt[i], XmNtraversalOn, True); i++;
1138     options_button = DtCreateMenuButton(matte1, "options_button", argt, i);
1139     XtOverrideTranslations(
1140                         options_button,
1141                         XtParseTranslationTable(" <Key> Return: Select()"));
1142
1143     XtManageChild(options_button);
1144     XmStringFree(xmstr);
1145
1146     /*
1147      *  tell form that ok_button is the default button...
1148      */
1149
1150     i = 0;
1151     XtSetArg(argt[i], XmNdefaultButton,         ok_button               ); i++;
1152     XtSetValues(matte1,  argt, i);
1153         
1154     /*
1155      * make all buttons *look* the same size...
1156      */
1157      
1158
1159     max_width = max_height = 0;
1160     GetBiggest(ok_button, &max_width, &max_height);
1161     GetBiggest(clear_button,   &max_width, &max_height);
1162     GetBiggest(options_button, &max_width, &max_height);
1163     GetBiggest(help_button,    &max_width, &max_height);
1164
1165     if ( (int) max_width < MIN_BUTTON_SIZE) max_width = MIN_BUTTON_SIZE;
1166     
1167     i = 0;
1168     XtSetArg(argt[i], XmNdefaultButtonShadowThickness, &thick1); i++;
1169     XtSetArg(argt[i], XmNshadowThickness, &thick2); i++;
1170     XtGetValues(ok_button,      argt, i);
1171     thick1 *= 4;
1172     thick1 += thick2;
1173
1174     i = 0;
1175     XtSetArg(argt[i], XmNwidth,                 max_width               ); i++;
1176     XtSetArg(argt[i], XmNheight,                max_height              ); i++;
1177     XtSetArg(argt[i], XmNrecomputeSize,         False                   ); i++;
1178     XtSetArg(argt[i], XmNbottomOffset,          thick1                  ); i++;
1179     XtSetValues(options_button, argt, i);
1180
1181     i = 0;
1182     XtSetArg(argt[i], XmNwidth,                 max_width + 2*thick1    ); i++;
1183     XtSetArg(argt[i], XmNheight,                max_height + 2*thick1   ); i++;
1184     XtSetArg(argt[i], XmNrecomputeSize,         False                   ); i++;
1185
1186     XtSetValues(ok_button,      argt, i);
1187     XtSetValues(clear_button,   argt, i);
1188     XtSetValues(help_button,    argt, i);
1189 }
1190
1191
1192
1193
1194 /***************************************************************************
1195  *
1196  *  MakeDialog
1197  *
1198  *  Widgets: error_message, help_message, copyright_msg, hostname_message,
1199  *           passwd_message
1200  ***************************************************************************/
1201
1202 void 
1203 MakeDialog( DialogType dtype )
1204 {
1205     register int i, j;
1206
1207     int         width;
1208     
1209     FILE        *fp, *fopen();
1210     char        buffer[128];
1211
1212     Widget      w, text;
1213     Dimension txt_width, txt_height;
1214     XmString    ok, cancel, nw, sv;
1215
1216     Widget      tlev;           /* JET - warning, there be dragons here */
1217     unsigned int dpwidth, dpheight, xorg, yorg;
1218
1219     
1220     
1221 #ifdef VG_TRACE
1222     vg_TRACE_EXECUTION("MakeDialog:  entered ...");
1223 #endif /* VG_TRACE */
1224     /*
1225      *  do things common to all dialogs...
1226      */
1227
1228 #ifdef USE_XINERAMA
1229                                 /* get info on prefered screen */
1230     if (!_DtXineramaGetScreen(dpyinfo.DtXineramaInfo, 
1231                               appInfo.xineramaPreferredScreen,
1232                               &dpwidth, &dpheight, &xorg, &yorg))
1233       {                         /* no joy here either - setup for normal */
1234         dpwidth = dpyinfo.width;
1235         dpheight = dpyinfo.height;
1236         xorg = yorg = 0;
1237       }
1238                                 /* else, should be setup properly */
1239 #else  /* no Xinerama */
1240     dpwidth = dpyinfo.width;
1241     dpheight = dpyinfo.height;
1242     xorg = yorg = 0;
1243 #endif    
1244
1245     ok     = ReadCatalogXms(MC_LABEL_SET, MC_OK_LABEL, MC_DEF_OK_LABEL);
1246     cancel = ReadCatalogXms(MC_LABEL_SET, MC_CANCEL_LABEL, MC_DEF_CANCEL_LABEL);
1247
1248     i = InitArg(MessageBox);
1249     XtSetArg(argt[i], XmNmarginHeight,          MBOX_MARGIN_HEIGHT      ); i++;
1250     XtSetArg(argt[i], XmNmarginWidth,           MBOX_MARGIN_WIDTH       ); i++;
1251     XtSetArg(argt[i], XmNshadowThickness,       SHADOW_THICKNESS        ); i++;
1252     XtSetArg(argt[i], XmNokLabelString,         ok                      ); i++;
1253     XtSetArg(argt[i], XmNcancelLabelString,     cancel                  ); i++;
1254     XtSetArg(argt[i], XmNnoResize,              False                   ); i++;
1255     XtSetArg(argt[i], XmNresizePolicy,          XmRESIZE_ANY            ); i++;
1256
1257     /*
1258      *  create the various dialogs...
1259      */
1260
1261     /* JET - check the matte widget, and if non-null, well use that as
1262      * the parent for dialogs.  Otherwise use table (the original
1263      * toplevel widget for this func).  This is useful for Xinerama so
1264      * that child dialogs are centered on the matte, and not the whole
1265      * SLS screen.
1266      */
1267
1268     if (matte != (Widget)NULL)
1269       tlev = matte;
1270     else
1271       tlev = table;
1272
1273    switch (dtype) {
1274
1275     case error:
1276         xmstr = ReadCatalogXms(MC_ERROR_SET, MC_LOGIN, "");
1277         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1278
1279         w = XmCreateErrorDialog(tlev, "error_message", argt, i);
1280         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
1281         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1282
1283         error_message = w;
1284         break;
1285
1286
1287     case help:
1288
1289         txt_width = (dpwidth > 850) ? 800 : dpwidth - 50;
1290         txt_height = (dpheight > 900) ? 600 : dpheight - 300;
1291
1292         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_HELP_LABEL, MC_DEF_HELP_LABEL);
1293         XtSetArg(argt[i], XmNmessageString, xmstr); i++;
1294
1295         w = XmCreateInformationDialog(tlev, "help_message", argt, i);
1296         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
1297         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1298
1299         i = InitArg(Text);
1300         XtSetArg(argt[i], XmNheight, txt_height); i++;
1301         XtSetArg(argt[i], XmNwidth, txt_width); i++;
1302         XtSetArg(argt[i], XmNeditMode, XmMULTI_LINE_EDIT); i++;
1303         XtSetArg(argt[i], XmNscrollBarDisplayPolicy, XmAS_NEEDED); i++;
1304         XtSetArg(argt[i], XmNscrollingPolicy, XmAUTOMATIC); i++;
1305         XtSetArg(argt[i], XmNeditable, False); i++;
1306         XtSetArg(
1307                 argt[i],
1308                 XmNvalue, ReadCatalog(MC_HELP_SET, MC_HELP, MC_DEF_HELP)); i++;
1309         text = XmCreateScrolledText(w, "help_message_text", argt, i);
1310
1311         XtManageChild(text);
1312         XtManageChild(w);
1313         help_message = w;
1314         break;
1315
1316
1317     case copyright:
1318         if ((fp = fopen(COPYRIGHT,"r")) == NULL)
1319 #if defined( __hp_osf )
1320             xmstr = XmStringCreate("Cannot open copyright file '/usr/X11/copyright'.",
1321                                 XmFONTLIST_DEFAULT_TAG);
1322 #else
1323             xmstr = XmStringCreate("Cannot open copyright file '/etc/copyright'.",
1324                                 XmFONTLIST_DEFAULT_TAG);
1325 #endif
1326         else {
1327             xmstr = (XmString) NULL;
1328         
1329             while (fgets(buffer, 128, fp) != NULL) {
1330                 j = strlen(buffer);
1331                 if ( buffer[j-1] == '\n' ) buffer[j-1] = '\0';
1332             
1333                 if ( xmstr != NULL )
1334                     xmstr = XmStringConcat(xmstr, XmStringSeparatorCreate());
1335
1336                 xmstr = XmStringConcat(xmstr,
1337                                        XmStringCreate(buffer,
1338                                        XmFONTLIST_DEFAULT_TAG));
1339             }       
1340             fclose(fp);
1341         }
1342
1343         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1344
1345         w = XmCreateInformationDialog(tlev, "copyright_msg", argt, i);
1346         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_CANCEL_BUTTON));
1347         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1348         
1349         XtAddCallback(w, XmNokCallback, CopyrightCB, (XtPointer) 0);    
1350
1351         copyright_msg = w;
1352         break;
1353     
1354
1355     case hostname:
1356             
1357         nw = ReadCatalogXms(MC_LABEL_SET, MC_NW_LABEL,  MC_DEF_NW_LABEL);
1358         sv = ReadCatalogXms(MC_LABEL_SET, MC_START_LABEL, MC_DEF_START_LABEL);
1359
1360         xmstr = ReadCatalogXms(MC_HELP_SET, MC_SYSTEM, MC_DEF_SYSTEM);
1361         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1362         XtSetArg(argt[i], XmNokLabelString,             nw              ); i++;
1363         XtSetArg(argt[i], XmNcancelLabelString,         sv              ); i++;
1364
1365         w = XmCreateWarningDialog(tlev, "hostname_msg", argt, i);
1366
1367         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1368
1369         XmStringFree(nw);
1370         XmStringFree(sv);
1371
1372         hostname_message = w;
1373         break;
1374
1375
1376     case expassword:
1377
1378         xmstr = ReadCatalogXms(MC_ERROR_SET, MC_PASSWD_EXPIRED, 
1379                             MC_DEF_PASSWD_EXPIRED);
1380         XtSetArg(argt[i], XmNmessageString,             xmstr           ); i++;
1381
1382         w = XmCreateQuestionDialog(tlev, "password_msg", argt, i);
1383
1384         XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));
1385
1386         passwd_message = w;
1387         break;
1388     }
1389
1390     /*
1391      *  finish up...
1392      */
1393
1394     switch (dtype) {
1395       case error:
1396       case hostname:
1397       case expassword:
1398         XtAddCallback(w, XmNokCallback,     RespondDialogCB, NULL);
1399         XtAddCallback(w, XmNcancelCallback, RespondDialogCB, NULL);
1400         break;
1401     }
1402
1403
1404     XtSetArg(argt[0], XmNdialogStyle,   XmDIALOG_APPLICATION_MODAL      ); i++;
1405     XtSetValues(w, argt, 1);
1406
1407     XmStringFree(xmstr);
1408     XmStringFree(ok);
1409     XmStringFree(cancel);
1410
1411
1412     /*
1413      *  adjust the width of the "ok" button on the dialogs...
1414      */
1415
1416     width = (dtype == hostname ? FromMM(4000) : MIN_BUTTON_SIZE);
1417     
1418     i = 0;
1419     XtSetArg(argt[i], XmNrecomputeSize,                 False           ); i++;
1420     XtSetArg(argt[i], XmNwidth,                         width           ); i++;
1421
1422     XtSetValues(XmMessageBoxGetChild(w, XmDIALOG_OK_BUTTON), argt, i);
1423
1424 }
1425
1426 /***************************************************************************
1427  *
1428  *  MakeDtlabel
1429  *
1430  *  Widgets:    dt_label
1431  ***************************************************************************/
1432
1433 static void
1434 MakeDtlabel( void )
1435 {
1436     int i;
1437
1438 #ifdef VG_TRACE
1439     vg_TRACE_EXECUTION("MakeDtlabel:  entered ...");
1440 #endif /* VG_TRACE */
1441
1442     i = InitArg(LabelG);
1443     XtSetArg(argt[i], XmNtraversalOn,           False                   ); i++;
1444     XtSetArg(argt[i], XmNtopAttachment,         XmATTACH_WIDGET         ); i++;
1445     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_FORM           ); i++;
1446     XtSetArg(argt[i], XmNrightAttachment,       XmATTACH_FORM           ); i++;
1447     XtSetArg(argt[i], XmNalignment,             XmALIGNMENT_CENTER      ); i++;
1448     XtSetArg(argt[i], XmNtopWidget,             greeting                ); i++;
1449  
1450     dt_label = XmCreateLabel(matte1, "dt_label", argt, i);
1451     XtManageChild(dt_label);
1452 }
1453
1454
1455
1456 /***************************************************************************
1457  *
1458  *  MakeGreeting
1459  *
1460  *  Widgets:    greeting
1461  ***************************************************************************/
1462
1463 typedef  struct {
1464     char        *labelString;   /* string for label                        */
1465     char        *persLabelString; /* alternate string for label */
1466     XmFontList  fontList;
1467 } GreetInfo, *GreetInfoPtr;
1468
1469 static GreetInfo greetInfo;
1470
1471 static  XtResource greetResources[] = {
1472     {XmNlabelString, XmCLabelString, 
1473         XmRString, sizeof(char *),
1474         XtOffset(GreetInfoPtr, labelString), XtRString, "default"       },
1475
1476     {"persLabelString", "PersLabelString",
1477         XmRString, sizeof(char *),
1478         XtOffset(GreetInfoPtr, persLabelString), XtRString, "default"       },
1479
1480     {XmNfontList, XmCFontList, 
1481         XmRFontList, sizeof(XmFontList),
1482         XtOffset(GreetInfoPtr, fontList), XtRString, NULL               }
1483 };     
1484
1485 static void 
1486 MakeGreeting( void )
1487 {
1488     register int i;
1489
1490     char    *greetmsg;
1491     char    host[128];
1492     char    disp[128];
1493     char    *p, *q, *s, *t;
1494     int     newLine = False;
1495     int     skip;
1496
1497 #ifdef VG_TRACE
1498     vg_TRACE_EXECUTION("MakeGreeting:  entered ...");
1499 #endif /* VG_TRACE */
1500
1501     /*
1502      *  get the user's greeting preferences...
1503      */
1504      
1505     XtGetSubresources(table, &greetInfo, "greeting", "Greeting",
1506         greetResources, XtNumber(greetResources), NULL, 0);
1507
1508
1509     /*
1510      *  get the local hostname...
1511      */
1512      
1513     gethostname(host, sizeof (host));
1514     if ( (p = strchr(host,'.')) != NULL )
1515         *p = '\0';
1516
1517     /* 
1518     **  Get display name (for %DisplayName% substitutions),
1519     **  reducing "a.b.c.d:0" constructs to shorter "a:0" form.
1520     */
1521
1522     strncpy(disp,
1523         dpyinfo.name ? dpyinfo.name : (DisplayString(dpyinfo.dpy)), 127);
1524     disp[127] = '\0';
1525     p = strchr(disp, '.');
1526     t = strchr(disp, ':');
1527     if (p && t) strcpy(p,t);
1528     
1529
1530     /*
1531      *  use the default string if the user has not specified one...
1532      */
1533
1534     if ( greetInfo.persLabelString &&
1535          strcmp(greetInfo.persLabelString, "default") == 0 ) {
1536         const char *msg;
1537         msg =
1538           (const char *)
1539           ReadCatalog(MC_LABEL_SET,MC_PERS_GREET_LABEL,MC_DEF_PERS_GREET_LABEL);
1540         greetInfo.persLabelString = strdup(msg);
1541     }
1542  
1543     if ( greetInfo.labelString && 
1544          strcmp(greetInfo.labelString, "default") == 0 ) {
1545         
1546         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_GREET_LABEL,MC_DEF_GREET_LABEL);
1547         xmstr = XmStringConcat(xmstr,
1548                                XmStringCreate(" ",  XmFONTLIST_DEFAULT_TAG));
1549         xmstr = XmStringConcat(xmstr,
1550                                XmStringCreate(host, XmFONTLIST_DEFAULT_TAG));
1551     }
1552     else {
1553         /*
1554          *  scan user's message for %LocalHost% token. Replace with hostname
1555          *  if found...
1556          */
1557          
1558
1559         if ( strlen(greetInfo.labelString) == 0         ||
1560              strcmp(greetInfo.labelString, "None") == 0 ||
1561              strcmp(greetInfo.labelString, "none") == 0 )
1562              
1563             greetmsg = strdup(" ");
1564         else {
1565             greetmsg = strdup(greetInfo.labelString);
1566         }
1567
1568         s = greetmsg;
1569         xmstr = (XmString) NULL;
1570
1571         do {
1572             q = s;
1573         
1574             /*
1575              *  scan for a new line character in remaining label string. 
1576              *  If found, work with that substring first...
1577              */
1578              
1579             if ( (p = strchr(q, '\n')) != NULL ) {
1580                 *p = '\0';
1581                 newLine = True;
1582                 s = ++p;
1583
1584                 if ( *q == '\0' )       /* handle consecutive newlines */
1585                     q = " ";
1586                     
1587             }
1588             else {
1589                 newLine = False;
1590             }
1591             
1592             /*
1593              *  replace all occurrances of %LocalHost% and %DisplayName%
1594              *  in the current substring...
1595              */
1596              
1597             while (1) {
1598                 p = strstr(q, LOCALHOST);
1599                 t = strstr(q, DISPLAYNAME);
1600                 
1601                 if (p && t) { /* both present? do whichever comes first */
1602                     if (p > t) p = NULL;
1603                     else t = NULL;
1604                 }
1605                 if (p) { /* replace a %LocalHost% string */
1606                     t = host;
1607                     skip = sizeof(LOCALHOST);
1608                 } else if (t) { /* replace a %DisplayName% string */
1609                     p = t;
1610                     t = disp;
1611                     skip = sizeof(DISPLAYNAME);
1612                 } else /* nothing left to replace */
1613                     break;
1614                 *p = '\0';
1615                 xmstr = XmStringConcat(xmstr,
1616                                    XmStringCreate(q,
1617                                    XmFONTLIST_DEFAULT_TAG));
1618                 xmstr = XmStringConcat(xmstr,
1619                                    XmStringCreate(t,
1620                                    XmFONTLIST_DEFAULT_TAG));
1621                 q = p + skip - 1;
1622             }
1623
1624             if ( strlen(q) != 0 )
1625                 xmstr = XmStringConcat(xmstr,
1626                                    XmStringCreate(q,
1627                                    XmFONTLIST_DEFAULT_TAG));
1628
1629             /*
1630              *  add a line seperator if this is a multi-line greeting...
1631              */
1632              
1633             if ( newLine == True ) {
1634                 xmstr = XmStringConcat(xmstr, XmStringSeparatorCreate());
1635             }
1636                              
1637         } while ( newLine == True ) ;
1638         
1639         free(greetmsg);
1640     }
1641
1642
1643     /* 
1644      * create the Welcome message...
1645      */
1646     
1647     i = InitArg(LabelG);
1648     XtSetArg(argt[i], XmNtraversalOn,           False                   ); i++;
1649     XtSetArg(argt[i], XmNlabelString,           xmstr                   ); i++;
1650     XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM); i++;
1651     XtSetArg(argt[i], XmNtopAttachment, XmATTACH_POSITION); i++; 
1652    /* XtSetArg(argt[i], XmNtopPosition, 15); i++; */
1653    /* Changed this to accomodate desktop label */
1654     XtSetArg(argt[i], XmNtopPosition, 9); i++; 
1655     XtSetArg(argt[i], XmNrightAttachment, XmATTACH_FORM); i++;
1656
1657
1658     /*
1659      *  use the user's font if one has been specified, otherwise use
1660      *  the application's default...
1661      */
1662
1663     if ( greetInfo.fontList != NULL ) {
1664         XtSetArg(argt[i], XmNfontList,          greetInfo.fontList      ); i++;
1665     }
1666
1667     greeting = XmCreateLabel(matte1, "greeting", argt, i);
1668     XtManageChild(greeting);
1669
1670     XmStringFree(xmstr);
1671 }
1672
1673 /***************************************************************************
1674  *
1675  *  MakeLogin
1676  *
1677  *  Widgets: login_matte, 
1678  *           login_form, login_label, login_text
1679  ***************************************************************************/
1680
1681 static void 
1682 MakeLogin( void )
1683 {
1684     register int i;
1685     int j;
1686     LoginTextPtr textdata; 
1687     XtTranslations      textTable;
1688     Widget passwd_text;
1689     String greetstr;
1690
1691 #ifdef VG_TRACE
1692     vg_TRACE_EXECUTION("MakeLogin:  entered ...");
1693 #endif /* VG_TRACE */
1694
1695     /*
1696      *  create the login form
1697      */
1698
1699     i = 0;
1700     XtSetArg(argt[i], XmNshadowThickness, 0); i++; 
1701     XtSetArg(argt[i], XmNresizable,             False                   ); i++;
1702     XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM); i++;
1703     XtSetArg(argt[i], XmNleftOffset, 80); i++;
1704     XtSetArg(argt[i], XmNrightAttachment, XmATTACH_FORM); i++;
1705     XtSetArg(argt[i], XmNrightOffset, 80); i++;
1706     XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_POSITION); i++;
1707     XtSetArg(argt[i], XmNbottomPosition, 65); i++;
1708 /*
1709     XtSetArg(argt[i], XmNresizePolicy, XmRESIZE_ANY); i++;
1710 */
1711     XtSetArg(argt[i], XmNallowShellResize, True); i++;
1712
1713     login_form = XmCreateForm(matte1, "login_form", argt, i);
1714     XtManageChild(login_form);
1715
1716     /*
1717      *  create the login text field...
1718      */
1719
1720     i = InitArg(Text);
1721     XtSetArg(argt[i], XmNbottomAttachment,      XmATTACH_POSITION       ); i++;
1722     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_POSITION       ); i++;
1723     XtSetArg(argt[i], XmNrightAttachment,       XmATTACH_POSITION       ); i++;
1724     XtSetArg(argt[i], XmNbottomPosition,        95                      ); i++;
1725     XtSetArg(argt[i], XmNrightPosition,         80                      ); i++;
1726     XtSetArg(argt[i], XmNleftPosition,          20                      ); i++;
1727     XtSetArg(argt[i], XmNselectionArrayCount,   1                       ); i++;
1728     XtSetArg(argt[i], XmNmaxLength,             80                      ); i++;
1729     XtSetArg(argt[i], XmNmappedWhenManaged,     False                   ); i++;
1730
1731     textdata = malloc(sizeof(LoginText));
1732     XtSetArg(argt[i], XmNuserData,              textdata                ); i++;
1733
1734     login_text = XmCreateTextField(login_form, "login_text", argt, i);
1735
1736     /*
1737      *  From Human Interface model, Tab key operation should work same on
1738      *  user field as it does on password field.  Password field is setup
1739      *  to take Tab key as password data.  HIE model is for user field to
1740      *  do same.
1741      */  
1742     XtOverrideTranslations(
1743                         login_text,
1744                         XtParseTranslationTable(
1745                                 " Shift <Key>Tab: prev-tab-group() \n\
1746                                    Ctrl <Key>Tab: next-tab-group() "));
1747
1748     XtManageChild(login_text);
1749 #ifdef __hpux
1750     XtAddCallback(login_text, XmNfocusCallback, TextFocusCB, NULL);
1751 #endif
1752
1753
1754     XtAddActions(textActions, 2);
1755     textTable = XtParseTranslationTable(textEventBindings);
1756
1757 #if 0
1758     XtSetArg(argt[i], XmNtranslations,          textTable               ); i++;
1759 #endif
1760     XtSetArg(argt[i], XmNverifyBell,            False                   ); i++;
1761
1762     passwd_text = XmCreateTextField(login_form, "passwd_text", argt, i);
1763
1764     textdata->bEcho = True;
1765     textdata->noechobuf[0] = '\0';
1766     textdata->text[0] = passwd_text;
1767     textdata->text[1] = login_text;
1768
1769     XtManageChild(passwd_text);
1770 #ifdef __hpux
1771     XtAddCallback(passwd_text, XmNfocusCallback, TextFocusCB, NULL);
1772 #endif
1773     XtAddCallback(passwd_text, XmNmodifyVerifyCallback, EditPasswdCB, NULL);
1774
1775    /*
1776     * Get default greeting string
1777     */
1778     i = 0;
1779     XtSetArg(argt[i], XmNlabelString, &textdata->onGreeting); i++;
1780     XtGetValues(greeting, argt, i);
1781     textdata->offGreetingFormat = greetInfo.persLabelString;
1782     textdata->offGreetingUname = NULL;
1783
1784     /*
1785      *  create the login labels...
1786      */
1787
1788     i = InitArg(LabelG);
1789
1790    /* modified recomputeSize initial value from False to True, fails 
1791     * when setting longer strings. Manifested as bug ID:1200690.
1792     */ 
1793     XtSetArg(argt[i], XmNrecomputeSize,         True                    ); i++;
1794
1795     XtSetArg(argt[i], XmNtraversalOn,           False                   ); i++;
1796     XtSetArg(argt[i], XmNbottomAttachment,      XmATTACH_WIDGET         ); i++;
1797     XtSetArg(argt[i], XmNleftAttachment,        XmATTACH_OPPOSITE_WIDGET); i++;
1798
1799 /* XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM           ); i++; 
1800    Commented this statement to  align login_label and login_text                        
1801     XtSetArg(argt[i], XmNrightAttachment,       XmATTACH_FORM           ); i++;
1802     XtSetArg(argt[i], XmNalignment,             XmALIGNMENT_CENTER      ); i++;
1803     XtSetArg(argt[i], XmNbottomOffset,          10                      ); i++;
1804 */
1805
1806     XtSetArg(argt[i], XmNleftWidget,            login_text              ); i++;
1807     XtSetArg(argt[i], XmNbottomWidget,          login_text              ); i++;
1808
1809
1810
1811     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_LOGIN_LABEL, MC_DEF_LOGIN_LABEL);
1812     XtSetArg(argt[i], XmNlabelString,           xmstr                   ); i++;
1813     
1814     login_label = XmCreateLabel(login_form, "login_label", argt, i);
1815     XtManageChild(login_label);
1816
1817     XmStringFree(xmstr);
1818
1819 }
1820
1821
1822
1823
1824 /***************************************************************************
1825  *
1826  *  MakeOptionsMenu
1827  *
1828  *  Widgets: options_menu, options_item[]
1829  ***************************************************************************/
1830
1831 void 
1832 MakeOptionsMenu( void )
1833 {
1834     int         i, j, k;
1835
1836     struct stat statb;
1837
1838 #ifdef VG_TRACE
1839     vg_TRACE_EXECUTION("MakeOptionsMenu:  entered ...");
1840 #endif /* VG_TRACE */
1841
1842     /*
1843      * get the built-in pop_up menu from the DtMenuButton...
1844      */
1845      
1846     XtVaGetValues(options_button, DtNsubMenuId, &options_menu, NULL);
1847
1848     /*
1849      *  create language cascade menus...
1850      */
1851
1852     if ( lang_menu == NULL )
1853         MakeLangMenu();
1854
1855
1856     /*
1857      *  create first level menu items...
1858      */
1859     j = 0;
1860
1861     /*
1862      *  build [ Language ] menu pane if there are languages to choose from...
1863      */
1864     if ( lang_menu != NULL ) {
1865         /*
1866          *  [ Language ] menu pane...
1867          *  attach language cascade menu to this pane
1868          */
1869         i = InitArg(CascadeBG);
1870         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_LANG_LABEL, MC_DEF_LANG_LABEL);
1871         XtSetArg(argt[i], XmNlabelString,               xmstr           ); i++;
1872         XtSetArg(argt[i], XmNsubMenuId,                 lang_menu       ); i++;
1873         XtSetArg(argt[i], XmNrecomputeSize,             True            ); i++;
1874         options_item[j] = XmCreateCascadeButtonGadget(options_menu,
1875                                 "options_languages", argt, i);
1876         XmStringFree(xmstr);
1877         j++;
1878
1879         /*
1880          *  separator...
1881          */
1882         i = InitArg(SeparatorG);
1883         options_item[j] = XmCreateSeparatorGadget(options_menu,
1884                                                     "options_sep2",
1885                                                      argt, i);
1886         j++;
1887     }
1888
1889     if( session_menu == NULL)  {
1890         session_menu = XmCreatePulldownMenu(options_menu, "session_menu", NULL, 0);
1891
1892
1893     /*
1894      *  [ Dt "Reg" ] menu pane...
1895      */
1896     i = k = InitArg(ToggleBG);
1897     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_DT_LABEL, MC_DEF_DT_LABEL);
1898     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1899     XtSetArg(argt[i], XmNrecomputeSize,                 True            ); i++;
1900     XtSetArg(argt[i], XmNuserData,              logoInfo.bitmapFile     ); i++;
1901
1902     options_dt = XmCreateToggleButtonGadget(session_menu,
1903                                                  "options_dt",
1904                                                  argt, i);
1905     XmStringFree(xmstr);
1906     XtAddCallback(options_dt,
1907                   XmNvalueChangedCallback,
1908                   MenuItemCB,
1909                   (XtPointer) OB_DT);
1910     /*XtManageChild(options_dt);   */
1911     /*
1912      *  [ Dt Lite ] menu pane...
1913      */
1914     i = k;
1915     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_DTLITE_LABEL, MC_DEF_DTLITE_LABEL);
1916     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1917     XtSetArg(argt[i], XmNrecomputeSize,                 True            ); i++;
1918
1919     options_dtlite = XmCreateToggleButtonGadget(session_menu,
1920                                                  "options_dtlite",
1921                                                  argt, i);
1922     XmStringFree(xmstr);
1923     XtAddCallback(options_dtlite,
1924                   XmNvalueChangedCallback,
1925                   MenuItemCB,
1926                   (XtPointer) OB_DTLITE);
1927
1928
1929     }
1930
1931 if ( session_menu != NULL ) {
1932         /*
1933          *  [ Language ] menu pane...
1934          *  attach language cascade menu to this pane
1935          */
1936         i = InitArg(CascadeBG);
1937         xmstr = ReadCatalogXms(MC_LABEL_SET, MC_SES_LABEL, MC_DEF_SES_LABEL);
1938         XtSetArg(argt[i], XmNlabelString,               xmstr           ); i++;
1939         XtSetArg(argt[i], XmNsubMenuId,                 session_menu       ); i++;
1940         XtSetArg(argt[i], XmNrecomputeSize,             True            ); i++;
1941         options_item[j] = XmCreateCascadeButtonGadget(options_menu,
1942                                 "session_menus", argt, i);
1943         XmStringFree(xmstr);
1944         j++;
1945
1946     /*
1947      *  separator...
1948      */
1949     i = InitArg(SeparatorG);
1950     options_item[j] = XmCreateSeparatorGadget(options_menu, "options_sep1",
1951                                                 argt, i);
1952     j++;
1953
1954     }
1955
1956
1957      
1958
1959
1960 #ifndef __apollo
1961     /*
1962      *  [ No Windows ] menu pane...
1963      */
1964     i = k = InitArg(PushBG);
1965     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_NW_LABEL, MC_DEF_NW_LABEL);
1966     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1967     options_item[j] = options_nowindows
1968                       = XmCreatePushButtonGadget(options_menu,
1969                                                  "options_noWindows",
1970                                                  argt, i);
1971     XmStringFree(xmstr);
1972     XtAddCallback(options_item[j], XmNactivateCallback,
1973                   MenuItemCB, (XtPointer) OB_NO_WINDOWS);
1974
1975     if (getenv(LOCATION) == NULL || strcmp(getenv(LOCATION), "local") != 0 )
1976         XtSetSensitive(options_item[j], False);
1977     j++;
1978 #endif
1979
1980
1981     /* 
1982      *  [ Restart Server ] menu pane...
1983      */
1984     i = k = InitArg(PushBG);
1985     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_RS_LABEL, MC_DEF_RS_LABEL);
1986     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
1987     options_item[j] = XmCreatePushButtonGadget(options_menu,
1988                                                  "options_restartServer",
1989                                                  argt, i); 
1990     XmStringFree(xmstr);
1991     XtAddCallback(options_item[j], XmNactivateCallback, 
1992                   MenuItemCB, (XtPointer) OB_RESTART_SERVER);
1993     j++;
1994
1995 #ifdef copyright_option
1996     /*
1997      *  separator...
1998      */
1999     i = InitArg(SeparatorG);
2000     options_item[j] = XmCreateSeparatorGadget(options_menu, "options_sep1",
2001                                                 argt, i);
2002     j++;
2003
2004
2005     /* 
2006      *  [ Copyright ] menu pane...
2007      */
2008     i = k = InitArg(PushBG);
2009     xmstr = ReadCatalogXms(MC_LABEL_SET, MC_COPY_LABEL, MC_DEF_COPY_LABEL);
2010     XtSetArg(argt[i], XmNlabelString,                   xmstr           ); i++;
2011     options_item[j] = XmCreatePushButtonGadget(options_menu, 
2012                                                  "options_copyright",
2013                                                  argt, i);
2014     XmStringFree(xmstr);
2015     XtAddCallback(options_item[j], XmNactivateCallback, 
2016                   MenuItemCB, (XtPointer) OB_COPYRIGHT);
2017     j++;
2018 #endif
2019
2020     /*
2021      *  manage the [Options] menu...
2022      */
2023     XtManageChildren(options_item, j);
2024
2025
2026
2027     /*
2028      *  If the DT Lite Session Manager is not available, remove the DT Lite
2029      *  and DT menu panes. The actual widgets must still be created since
2030      *  other code (ex. MenuItemCB()) tries to obtain some of their resources.
2031      */
2032      
2033     if  ( stat(DTLITESESSION, &statb) != 0 ||
2034           ((statb.st_mode & S_IXOTH) != S_IXOTH) ) {
2035
2036         XtUnmanageChild(options_dtlite);
2037 /*
2038         XtUnmanageChild(options_dt);
2039 */
2040     }
2041
2042     if ( getenv(PINGINTERVAL) != NULL )
2043         XtUnmanageChild(options_nowindows);
2044         
2045
2046 }
2047
2048
2049
2050
2051 /***************************************************************************
2052  *
2053  *  MyInsert
2054  *
2055  *  Local self-insert action for the text widget. The default action
2056  *  discards control characters, which are allowed in password.
2057  ***************************************************************************/
2058
2059 static void 
2060 MyInsert( Widget w, XEvent *event, char **params, Cardinal *num_params )
2061 {
2062     char           str[32];
2063     XComposeStatus compstatus;
2064     int            n;
2065
2066     n = XLookupString((XKeyEvent *)event, str, sizeof(str),
2067                       (KeySym *)NULL, &compstatus);
2068
2069     if (n > 0) {
2070        str[n] = '\0';
2071        XmTextFieldInsert(w, XmTextFieldGetInsertionPosition(w), str);
2072     }
2073 }
2074
2075 /***************************************************************************
2076  *
2077  *  MyBackspace
2078  *
2079  *  Local backspace action for the text widget. 
2080  *  Deletes the last character of the password string in the 
2081  *  widget for each backspace key press, and also does not move the cursor
2082  *  position in the widget.
2083  ***************************************************************************/
2084
2085 static void
2086 MyBackspace( Widget w, XEvent *event, char **params, Cardinal *num_params )
2087 {
2088   LoginTextPtr textdata;
2089
2090   textdata = GetLoginTextPtr(w);
2091
2092   if (textdata && !textdata->bEcho && (int) strlen(textdata->noechobuf) > 0)
2093   { 
2094     textdata->noechobuf[strlen(textdata->noechobuf) - 1] = '\0';
2095   }
2096 }
2097
2098
2099 /***************************************************************************
2100  *
2101  *  ErrorHandler
2102  *
2103  *  X protocol error handler to override the default
2104  ***************************************************************************/
2105
2106 static int 
2107 ErrorHandler( Display *dpy, XErrorEvent *event )
2108 {
2109     return 0;
2110 }
2111
2112
2113
2114
2115 /***************************************************************************
2116  *
2117  *  xtErrorHandler
2118  *
2119  *  Xt protocol error handler to override the default
2120  ***************************************************************************/
2121
2122 static void 
2123 xtErrorHandler( String msg )
2124 {
2125     LogError((unsigned char *) "%s\n", msg ) ;
2126     exit(NOTIFY_RESTART);
2127 }
2128
2129
2130
2131
2132 /***************************************************************************
2133  *
2134  *  xtWarningHandler
2135  *
2136  *  Xt protocol error handler to override the default
2137  ***************************************************************************/
2138
2139 static void 
2140 xtWarningHandler( String msg )
2141 {
2142     LogError( (unsigned char *) "%s\n", msg ) ;
2143     return ;
2144 }
2145
2146
2147
2148
2149 /***************************************************************************
2150  *
2151  *  MakeOptionsProc
2152  *
2153  *  Timeout routine to build options menu
2154  ***************************************************************************/
2155
2156 static void 
2157 MakeOptionsProc( XtPointer data, XtIntervalId *id )
2158 {
2159
2160     if (options_menu == NULL)
2161         MakeOptionsMenu();
2162     
2163     return;
2164 }
2165
2166
2167
2168
2169 /***************************************************************************
2170  *
2171  *  Terminate
2172  *
2173  *  Catch a SIGTERM and unmanage display
2174  ***************************************************************************/
2175
2176 static SIGVAL
2177 Terminate( int arg )
2178
2179 {
2180     if(-1 == write(1, "terminate", 9)) {
2181         perror(strerror(errno));
2182     }
2183     CleanupAndExit(NULL, NOTIFY_ABORT);
2184 }
2185
2186
2187
2188
2189 /***************************************************************************
2190  *
2191  *  DebugWidgetResources
2192  *
2193  *  Get widget resources
2194  ***************************************************************************/
2195
2196 typedef struct resource_values {
2197     int height;
2198     int width;
2199     int x;
2200     int y;
2201     int rightAttachment;
2202     int leftAttachment;
2203     int topAttachment;
2204     int bottomAttachment;
2205 } ResourceValues;
2206
2207 static void
2208 DebugWidgetResources(Widget w)
2209
2210 {
2211     struct resource_values      values;
2212     int i;
2213
2214     i = 0;
2215     bzero((char *) &values, sizeof(values));
2216     XtSetArg(argt[i], XmNheight,        &values.height); i++;
2217     XtSetArg(argt[i], XmNwidth,         &values.width); i++;
2218     XtSetArg(argt[i], XmNx,             &values.x); i++;
2219     XtSetArg(argt[i], XmNy,             &values.y); i++;
2220     XtSetArg(argt[i], XmNrightAttachment,       &values.rightAttachment); i++;
2221     XtSetArg(argt[i], XmNleftAttachment,        &values.leftAttachment); i++;
2222     XtSetArg(argt[i], XmNtopAttachment,         &values.topAttachment); i++;
2223     XtSetArg(argt[i], XmNbottomAttachment,      &values.bottomAttachment); i++;
2224
2225     XtGetValues(w, argt, i);
2226 }
2227
2228 /*
2229 /***************************************************************************
2230  *
2231  * GetDisplayName (void) - transform the display name into a "short"
2232  *   host name that is used to create a display-specific session.
2233  *
2234  * The display name should match one of the following patterns:
2235  *
2236  *   1. host            (non-qualified)
2237  *   2. host.domain
2238  *   3. host:n
2239  *   4. host:n.s
2240  *   5. host.domain:n
2241  *   6. host.domain:n.s
2242  *
2243  * Note that 1 and 2 will be used if the display name is actually
2244  * something like unix:0, local:0 or 0:0
2245  *
2246  ***************************************************************************/
2247 static char * 
2248 GetDisplayName (void)
2249 {
2250     char                host[MAXHOSTNAMELEN];
2251     static char         tmp[MAXHOSTNAMELEN + 3];
2252     char                * pch;
2253     char                * col;
2254     char                * dot;
2255
2256     pch = XDisplayString(dpyinfo.dpy);
2257
2258     if (!pch ||
2259         !strncmp (pch, "local:0", 7) ||
2260         !strncmp (pch, "unix:0", 6) ||
2261         !strncmp (pch, ":0.0", 4) ||
2262         !strncmp (pch, ":0", 2)) {
2263         gethostname (host, MAXHOSTNAMELEN);
2264         pch = host;
2265     }
2266
2267     col = strchr (pch, ':');
2268     dot = strchr (pch, '.');
2269
2270     if (!col) {
2271         if (dot) {
2272             strncpy (tmp, pch, dot - pch);      /* case #2 above */
2273             tmp[dot - pch] = '\000';
2274         } else {
2275             strcpy (tmp, pch);                  /* case #1 above */
2276         }
2277     } else {
2278         if (!dot || (dot > col)) {              /* case #3 and 4 above */
2279             strncpy (tmp, pch, col - pch);
2280             tmp[col - pch] = '\000';
2281         } else {                                /* case # 5 and 6 above */
2282             strncpy (tmp, pch, dot - pch);
2283             tmp[dot - pch] = '\000';
2284         }
2285     }
2286     
2287     strcat (tmp, ":0");
2288     return (tmp);
2289 }