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