vgmain.c 63 KB

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