vgmain.c 64 KB

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