vgutil.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  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: vgutil.c /main/11 1998/11/03 19:17:12 mgreess $ */
  24. /* *
  25. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  26. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  27. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  28. * (c) Copyright 1993, 1994 Novell, Inc. *
  29. */
  30. /************************************<+>*************************************
  31. ****************************************************************************
  32. **
  33. ** File: vgutil.c
  34. **
  35. ** Project: HP Visual User Environment (DT)
  36. **
  37. ** Description: Utility file for Dtgreet application.
  38. **
  39. ** This file contains global data declarations, resource
  40. ** declarations, and various utility routines.
  41. **
  42. **
  43. ** (c) Copyright 1987, 1988, 1989 by Hewlett-Packard Company
  44. **
  45. **
  46. **
  47. ****************************************************************************
  48. ************************************<+>*************************************/
  49. /***************************************************************************
  50. *
  51. * Includes
  52. *
  53. ***************************************************************************/
  54. #include <stdio.h>
  55. #include <setjmp.h>
  56. #include <time.h>
  57. #include <sys/signal.h>
  58. #include <stdarg.h>
  59. #define Va_start(a,b) va_start(a,b)
  60. #include <unistd.h>
  61. #include <X11/Xlibint.h>
  62. #include <Xm/Xm.h>
  63. #include <Dt/MsgCatP.h>
  64. #include "vg.h"
  65. #include "vgmsg.h"
  66. /****************************************************************************
  67. *
  68. * Defines
  69. *
  70. ****************************************************************************/
  71. #define NLSPATH_ENV "NLSPATH=" \
  72. CDE_INSTALLATION_TOP "/nls/msg/%L/%N.cat:" \
  73. CDE_INSTALLATION_TOP "/lib/nls/msg/%L/%N.cat:" \
  74. CDE_INSTALLATION_TOP "/lib/nls/msg/%l/%t/%c/%N.cat:" \
  75. CDE_INSTALLATION_TOP "/lib/nls/msg/%l/%c/%N.cat"
  76. #define NLS_CATALOG "dtlogin"
  77. /***************************************************************************
  78. *
  79. * Procedure declarations
  80. *
  81. ***************************************************************************/
  82. static SIGVAL syncTimeout( int arg ) ;
  83. /***************************************************************************
  84. *
  85. * Global variables
  86. *
  87. ***************************************************************************/
  88. static nl_catd nl_fd; /* message catalog file descriptor */
  89. /***************************************************************************
  90. *
  91. * ChangeBell
  92. *
  93. * turn the keyboard bell on/off
  94. *
  95. * Input: "on", "off"
  96. ***************************************************************************/
  97. void
  98. ChangeBell( char *string )
  99. {
  100. static int percent = -1;
  101. XKeyboardControl control;
  102. XKeyboardState state;
  103. if ( strcmp (string, "on" ) == 0 )
  104. control.bell_percent = percent;
  105. if ( strcmp (string, "off") == 0 ) {
  106. XGetKeyboardControl(dpyinfo.dpy, &state);
  107. percent = state.bell_percent;
  108. control.bell_percent = 0;
  109. }
  110. if (percent >= 0)
  111. XChangeKeyboardControl(dpyinfo.dpy, KBBellPercent, &control);
  112. }
  113. /***************************************************************************
  114. *
  115. * InitArg
  116. *
  117. * Initialize the wiget argument list before creating the widget. These
  118. * are resources the user cannot override.
  119. *
  120. * The values chosen for these resources are not necessarily the Motif
  121. * defaults, but rather those that are most common for all the widgets. A
  122. * particular widget may override any of these choices before creation.
  123. ***************************************************************************/
  124. static XmTextScanType sarray[] = {XmSELECT_POSITION};
  125. int
  126. InitArg( WidgetType wtype )
  127. {
  128. int i;
  129. i = 0;
  130. /*
  131. * Core resource set...
  132. */
  133. /* bug workaround in toolkit */
  134. if (wtype == DrawingA ||
  135. wtype == Frame ||
  136. wtype == Label ||
  137. wtype == MessageBox ||
  138. wtype == PushB ||
  139. wtype == Text ) {
  140. XtSetArg(argt[i], XmNaccelerators, NULL ); i++;
  141. }
  142. if (wtype == DrawingA ||
  143. wtype == Frame ||
  144. wtype == Form ||
  145. wtype == Label ||
  146. wtype == MessageBox ||
  147. wtype == PushB ||
  148. wtype == Text ) {
  149. XtSetArg(argt[i], XmNancestorSensitive, True ); i++;
  150. /* XmNbackground, (set by user) */
  151. /* XmNbackgroundPixmap, (set by user) */
  152. /* XmNborderColor, (set by user) */
  153. /* XmNborderPixmap, (set by user) */
  154. XtSetArg(argt[i], XmNborderWidth, 0 ); i++;
  155. /* XmNcolormap, (default) */
  156. /* XmNdepth, (set by Xt) */
  157. XtSetArg(argt[i], XmNdestroyCallback, NULL ); i++;
  158. /* XmNheight, (set by user) */
  159. XtSetArg(argt[i], XmNmappedWhenManaged, True ); i++;
  160. /* XmNscreen, (default) */
  161. XtSetArg(argt[i], XmNsensitive, True ); i++;
  162. /* XmNtranslations, (default) */
  163. /* XmNwidth, (set by user) */
  164. /* XmNx, (set by user) */
  165. /* XmNy, (set by user) */
  166. }
  167. /*
  168. * Object resource set...
  169. */
  170. if (wtype == CascadeBG ||
  171. wtype == LabelG ||
  172. wtype == PushBG ||
  173. wtype == SeparatorG ||
  174. wtype == ToggleBG ) {
  175. XtSetArg(argt[i], XmNdestroyCallback, NULL ); i++;
  176. }
  177. /*
  178. * RectObj resource set...
  179. */
  180. if (wtype == CascadeBG ||
  181. wtype == LabelG ||
  182. wtype == PushBG ||
  183. wtype == SeparatorG ||
  184. wtype == ToggleBG ) {
  185. XtSetArg(argt[i], XmNancestorSensitive, True ); i++;
  186. XtSetArg(argt[i], XmNborderWidth, 0 ); i++;
  187. /* XmNheight, (set by user) */
  188. XtSetArg(argt[i], XmNsensitive, True ); i++;
  189. /* XmNwidth, (set by user) */
  190. /* XmNx, (set by user) */
  191. /* XmNy, (set by user) */
  192. }
  193. /*
  194. * XmGadget resource set...
  195. */
  196. if (wtype == CascadeBG ||
  197. wtype == LabelG ||
  198. wtype == PushBG ||
  199. wtype == SeparatorG ||
  200. wtype == ToggleBG ) {
  201. XtSetArg(argt[i], XmNhelpCallback, NULL ); i++;
  202. XtSetArg(argt[i], XmNhighlightOnEnter, True ); i++;
  203. /* XmNhighlightThickness,(set by user) */
  204. /* XmNshadowThickness, (set by user) */
  205. XtSetArg(argt[i], XmNtraversalOn, True ); i++;
  206. XtSetArg(argt[i], XmNunitType, appInfo.unitType ); i++;
  207. XtSetArg(argt[i], XmNuserData, NULL ); i++;
  208. }
  209. /*
  210. * Composite resource set...
  211. */
  212. if (wtype == DrawingA ||
  213. wtype == Frame ||
  214. wtype == Form ||
  215. wtype == MessageBox ) {
  216. XtSetArg(argt[i], XmNinsertPosition, NULL ); i++;
  217. }
  218. /*
  219. * XmPrimitive resource set...
  220. */
  221. if (wtype == Label ||
  222. wtype == PushB ||
  223. wtype == Text ) {
  224. /* XmNbottomShadowColor, (set by user) */
  225. /* XmNbottomShadowPixmap,(set by user) */
  226. /* XmNforeground, (set by user) */
  227. XtSetArg(argt[i], XmNhelpCallback, NULL ); i++;
  228. /* XmNhighlightColor, (set by user) */
  229. XtSetArg(argt[i], XmNhighlightOnEnter, False ); i++;
  230. /* XmNhighlightPixmap, (set by user) */
  231. /* XmNhighlightThickness,(set by user) */
  232. /* XmNshadowThickness, (set by user) */
  233. /* XmNtopShadowColor, (set by user) */
  234. /* XmNtopShadowPixmap, (set by user) */
  235. XtSetArg(argt[i], XmNtraversalOn, True ); i++;
  236. XtSetArg(argt[i], XmNunitType, appInfo.unitType ); i++;
  237. XtSetArg(argt[i], XmNuserData, NULL ); i++;
  238. }
  239. /*
  240. * XmForm Constraint resource set...
  241. */
  242. if (wtype == Form) {
  243. XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_NONE ); i++;
  244. XtSetArg(argt[i], XmNleftAttachment, XmATTACH_NONE ); i++;
  245. XtSetArg(argt[i], XmNresizable, False ); i++;
  246. XtSetArg(argt[i], XmNrightAttachment, XmATTACH_NONE ); i++;
  247. XtSetArg(argt[i], XmNtopAttachment, XmATTACH_NONE ); i++;
  248. }
  249. /*
  250. * XmManager resource set...
  251. */
  252. if (wtype == DrawingA ||
  253. wtype == Frame ||
  254. wtype == Form ||
  255. wtype == MessageBox ) {
  256. /* XmNbottomShadowColor, (set by user) */
  257. /* XmNbottomShadowPixmap,(set by user) */
  258. /* XmNforeground, (set by user) */
  259. XtSetArg(argt[i], XmNhelpCallback, NULL ); i++;
  260. /* XmNhighlightColor, (set by user) */
  261. /* XmNhighlightPixmap, (set by user) */
  262. /* XmNshadowThickness, (set by user) */
  263. /* XmNtopShadowColor, (set by user) */
  264. /* XmNtopShadowPixmap, (set by user) */
  265. XtSetArg(argt[i], XmNunitType, appInfo.unitType ); i++;
  266. XtSetArg(argt[i], XmNuserData, NULL ); i++;
  267. }
  268. /*
  269. * XmBulletinBoard resource set...
  270. */
  271. if (wtype == Form ||
  272. wtype == MessageBox ) {
  273. XtSetArg(argt[i], XmNallowOverlap, True ); i++;
  274. XtSetArg(argt[i], XmNautoUnmanage, True ); i++;
  275. XtSetArg(argt[i], XmNbuttonFontList, appInfo.labelFont ); i++;
  276. /* XmNcancelButton, (set by Xm) */
  277. /* XmNdefaultButton, (set by Xm) */
  278. XtSetArg(argt[i], XmNdefaultPosition, True ); i++;
  279. XtSetArg(argt[i], XmNdialogStyle, XmDIALOG_MODELESS ); i++;
  280. XtSetArg(argt[i], XmNdialogTitle, NULL ); i++;
  281. XtSetArg(argt[i], XmNfocusCallback, NULL ); i++;
  282. /*XtSetArg(argt[i], XmNlabelFontList, appInfo.textFont ); i++; */
  283. XtSetArg(argt[i], XmNmapCallback, NULL ); i++;
  284. XtSetArg(argt[i], XmNmarginHeight, FromMM(10) ); i++;
  285. XtSetArg(argt[i], XmNmarginWidth, FromMM(10) ); i++;
  286. XtSetArg(argt[i], XmNmapCallback, NULL ); i++;
  287. XtSetArg(argt[i], XmNnoResize, True ); i++;
  288. XtSetArg(argt[i], XmNresizePolicy, XmRESIZE_ANY ); i++;
  289. XtSetArg(argt[i], XmNshadowType, XmSHADOW_OUT ); i++;
  290. XtSetArg(argt[i], XmNstringDirection, XmSTRING_DIRECTION_L_TO_R );i++;
  291. XtSetArg(argt[i], XmNtextFontList, appInfo.textFont ); i++;
  292. XtSetArg(argt[i], XmNtextTranslations, NULL ); i++;
  293. XtSetArg(argt[i], XmNunmapCallback, NULL ); i++;
  294. }
  295. /*
  296. * XmCascadeButtonGadget resource set...
  297. */
  298. if (wtype == CascadeBG) {
  299. XtSetArg(argt[i], XmNactivateCallback, NULL ); i++;
  300. XtSetArg(argt[i], XmNcascadePixmap, XmUNSPECIFIED_PIXMAP ); i++;
  301. XtSetArg(argt[i], XmNcascadingCallback, NULL ); i++;
  302. XtSetArg(argt[i], XmNmappingDelay, 100 ); i++;
  303. XtSetArg(argt[i], XmNsubMenuId, 0 ); i++;
  304. }
  305. /*
  306. * XmDrawingArea resource set...
  307. */
  308. if (wtype == DrawingA) {
  309. XtSetArg(argt[i], XmNexposeCallback, NULL ); i++;
  310. XtSetArg(argt[i], XmNinputCallback, NULL ); i++;
  311. XtSetArg(argt[i], XmNmarginHeight, 0 ); i++;
  312. XtSetArg(argt[i], XmNmarginWidth, 0 ); i++;
  313. XtSetArg(argt[i], XmNresizeCallback, NULL ); i++;
  314. XtSetArg(argt[i], XmNresizePolicy, XmRESIZE_NONE ); i++;
  315. }
  316. /*
  317. * XmForm resource set...
  318. */
  319. if (wtype == Form) {
  320. XtSetArg(argt[i], XmNfractionBase, 100 ); i++;
  321. XtSetArg(argt[i], XmNhorizontalSpacing, 0 ); i++;
  322. XtSetArg(argt[i], XmNrubberPositioning, False ); i++;
  323. XtSetArg(argt[i], XmNverticalSpacing, 0 ); i++;
  324. }
  325. /*
  326. * XmFrame resource set...
  327. */
  328. if (wtype == Frame) {
  329. XtSetArg(argt[i], XmNmarginHeight, 0 ); i++;
  330. XtSetArg(argt[i], XmNmarginWidth, 0 ); i++;
  331. XtSetArg(argt[i], XmNshadowType, XmSHADOW_OUT ); i++;
  332. }
  333. /*
  334. * XmLabel/XmLabelGadget resource set...
  335. */
  336. if (wtype == CascadeBG ||
  337. wtype == Label ||
  338. wtype == LabelG ||
  339. wtype == PushB ||
  340. wtype == PushBG ||
  341. wtype == ToggleBG ) {
  342. XtSetArg(argt[i], XmNaccelerator, NULL ); i++;
  343. XtSetArg(argt[i], XmNacceleratorText, NULL ); i++;
  344. /* XtSetArg(argt[i], XmNalignment, XmALIGNMENT_CENTER ); i++;*/
  345. /* XmNalignment, (default) */
  346. XtSetArg(argt[i], XmNfontList, appInfo.labelFont ); i++;
  347. XtSetArg(argt[i], XmNlabelInsensitivePixmap,
  348. XmUNSPECIFIED_PIXMAP ); i++;
  349. XtSetArg(argt[i], XmNlabelPixmap, XmUNSPECIFIED_PIXMAP ); i++;
  350. XtSetArg(argt[i], XmNlabelString, NULL ); i++;
  351. XtSetArg(argt[i], XmNlabelType, XmSTRING ); i++;
  352. /* XmNmarginBottom, (default) */
  353. /* XmNmarginHeight, (default) */
  354. /* XmNmarginLeft, (default) */
  355. /* XmNmarginRight, (default) */
  356. /* XmNmarginTop, (default) */
  357. /* XmNmarginWidth, (default) */
  358. XtSetArg(argt[i], XmNmnemonic, NULL ); i++;
  359. XtSetArg(argt[i], XmNrecomputeSize, False ); i++;
  360. XtSetArg(argt[i], XmNuserData, NULL ); i++;
  361. XtSetArg(argt[i], XmNstringDirection, XmSTRING_DIRECTION_L_TO_R ); i++;
  362. }
  363. /*
  364. * XmMessageBox resource set...
  365. */
  366. if (wtype == MessageBox) {
  367. XtSetArg(argt[i], XmNcancelCallback, NULL ); i++;
  368. XtSetArg(argt[i], XmNcancelLabelString, NULL ); i++;
  369. XtSetArg(argt[i], XmNdefaultButtonType, XmDIALOG_OK_BUTTON ); i++;
  370. XtSetArg(argt[i], XmNdialogType, XmDIALOG_MESSAGE ); i++;
  371. XtSetArg(argt[i], XmNhelpLabelString, NULL ); i++;
  372. XtSetArg(argt[i], XmNmessageAlignment, XmALIGNMENT_BEGINNING ); i++;
  373. XtSetArg(argt[i], XmNmessageString, NULL ); i++;
  374. XtSetArg(argt[i], XmNminimizeButtons, FALSE ); i++;
  375. XtSetArg(argt[i], XmNokCallback, NULL ); i++;
  376. XtSetArg(argt[i], XmNokLabelString, NULL ); i++;
  377. /* XmNsymbolPixmap, (set by Xm) */
  378. }
  379. /*
  380. * XmPushButton/XmPushButtonGadget resource set...
  381. */
  382. if (wtype == PushB ||
  383. wtype == PushBG ) {
  384. XtSetArg(argt[i], XmNactivateCallback, NULL ); i++;
  385. XtSetArg(argt[i], XmNarmCallback, NULL ); i++;
  386. /* XmNarmColor, (set by user) */
  387. /* XmNarmPixmap, (set by user) */
  388. XtSetArg(argt[i], XmNdisarmCallback, NULL ); i++;
  389. XtSetArg(argt[i], XmNfillOnArm, True ); i++;
  390. XtSetArg(argt[i], XmNshowAsDefault, 0 ); i++;
  391. }
  392. /*
  393. * XmSeparatorGadget resource set...
  394. */
  395. if (wtype == SeparatorG) {
  396. XtSetArg(argt[i], XmNmargin, 0 ); i++;
  397. XtSetArg(argt[i], XmNorientation, XmHORIZONTAL ); i++;
  398. XtSetArg(argt[i], XmNseparatorType, XmSHADOW_ETCHED_IN ); i++;
  399. }
  400. /*
  401. * XmText resource set...
  402. */
  403. if (wtype == Text ) {
  404. XtSetArg(argt[i], XmNactivateCallback, NULL ); i++;
  405. XtSetArg(argt[i], XmNautoShowCursorPosition, True ); i++;
  406. XtSetArg(argt[i], XmNcursorPosition, 0 ); i++;
  407. XtSetArg(argt[i], XmNeditable, True ); i++;
  408. XtSetArg(argt[i], XmNeditMode, XmSINGLE_LINE_EDIT ); i++;
  409. XtSetArg(argt[i], XmNfocusCallback, NULL ); i++;
  410. XtSetArg(argt[i], XmNlosingFocusCallback, NULL ); i++;
  411. XtSetArg(argt[i], XmNmarginHeight, TEXT_MARGIN_HEIGHT ); i++;
  412. XtSetArg(argt[i], XmNmarginWidth, TEXT_MARGIN_WIDTH ); i++;
  413. XtSetArg(argt[i], XmNmaxLength, 20 ); i++;
  414. XtSetArg(argt[i], XmNmodifyVerifyCallback, NULL ); i++;
  415. XtSetArg(argt[i], XmNmotionVerifyCallback, NULL ); i++;
  416. /* XmNtopPosition, (default) */
  417. /* XmNvalue, (set by ??) */
  418. /* XmText Input Resource Set */
  419. XtSetArg(argt[i], XmNpendingDelete, True ); i++;
  420. XtSetArg(argt[i], XmNselectionArray, sarray ); i++;
  421. XtSetArg(argt[i], XmNselectThreshold, 1000 ); i++;
  422. /* XmText Output Resource Set */
  423. /* XmNblinkRate, (set by user) */
  424. XtSetArg(argt[i], XmNfontList, appInfo.labelFont ); i++;
  425. XtSetArg(argt[i], XmNcursorPositionVisible, True ); i++;
  426. XtSetArg(argt[i], XmNresizeHeight, False ); i++;
  427. XtSetArg(argt[i], XmNresizeWidth, False ); i++;
  428. /* XmNrows, (ignored) */
  429. /* XmNwordWrap, (ignored) */
  430. }
  431. /*
  432. * XmToggleButtonGadget resource set...
  433. */
  434. if (wtype == ToggleBG) {
  435. XtSetArg(argt[i], XmNarmCallback, NULL ); i++;
  436. XtSetArg(argt[i], XmNdisarmCallback, NULL ); i++;
  437. XtSetArg(argt[i], XmNfillOnSelect, True ); i++;
  438. XtSetArg(argt[i], XmNindicatorOn, True ); i++;
  439. XtSetArg(argt[i], XmNindicatorType, XmONE_OF_MANY ); i++;
  440. /* XmNselectColor, (set by user) */
  441. XtSetArg(argt[i], XmNselectInsensitivePixmap,
  442. XmUNSPECIFIED_PIXMAP ); i++;
  443. XtSetArg(argt[i], XmNselectPixmap, XmUNSPECIFIED_PIXMAP ); i++;
  444. XtSetArg(argt[i], XmNset, False ); i++;
  445. /* XmNspacing, (default) */
  446. XtSetArg(argt[i], XmNvalueChangedCallback,
  447. NULL ); i++;
  448. XtSetArg(argt[i], XmNvisibleWhenOff, False ); i++;
  449. }
  450. return (i);
  451. }
  452. /***************************************************************************
  453. *
  454. * FromMM
  455. *
  456. * Convert from 100th Millimeter units into the widget's units.
  457. *
  458. * This routine does NOT use the Motif Resolution Independence mechanism.
  459. * Unless the user informs the X-server as to the current monitor size (or
  460. * the monitor happens to be the default), it is possible that the
  461. * millimeter screen size returned by the X-server is incorrect. This
  462. * causes the Motif Resolution Independence mechanism to generate incorrect
  463. * values and skew the visuals.
  464. *
  465. * For ease of specification, all sizes internal to Dtgreet are specified
  466. * in a generic unit (approx. 100th Millimeters) and then converted to an
  467. * equivalent pixel value by this routine. All Dtgreet widgets default
  468. * to pixel unit type. Displays of the same resolution will contain
  469. * identical pixel values, but the actual size on the screen may vary
  470. * depending on the monitor size.
  471. *
  472. * There are three conversion values, one each for LowRes (640x480), MedRes
  473. * (1024x768), and HiRes (1280x1024) displays. They are calculated to
  474. * produce the same pixel values as does the Motif R.I. mechanism on the
  475. * HP 13" Low Res. display, 16" Med. Res. display and 19" Hi Res. display,
  476. * all pleasing visuals.
  477. *
  478. * If the user specifies the widgets unit type to be 100TH_MILLIMETERS, the
  479. * Motif Resolution Independence mechanism is reactivated and can be used by
  480. * the user. The internal sizes specified will not be converted by this
  481. * routine but rather internally by Motif.
  482. *
  483. ***************************************************************************/
  484. int
  485. FromMM( int mm )
  486. {
  487. int pixel;
  488. if ( appInfo.unitType == Xm100TH_MILLIMETERS )
  489. return(mm);
  490. /*
  491. * convert 100thMillimeters to Pixels. Do not round up to the next
  492. * pixel...
  493. */
  494. if ( HIRES )
  495. pixel = (mm * 0.035854); /* HiRes */
  496. else if ( MEDRES )
  497. pixel = (mm * 0.033574); /* MedRes */
  498. else
  499. pixel = (mm * 0.026016); /* LowRes */
  500. return(pixel);
  501. }
  502. /***************************************************************************
  503. *
  504. * FromPixel
  505. *
  506. * Convert from pixel units into the widget's units
  507. ***************************************************************************/
  508. int
  509. FromPixel( Widget w, int orientation, int pixel )
  510. {
  511. Arg argt[10];
  512. unsigned char unit_type;
  513. XtSetArg(argt[0], XmNunitType, &unit_type);
  514. XtGetValues(w, argt, 1);
  515. if (unit_type == XmPIXELS)
  516. return(pixel);
  517. else
  518. return(XmConvertUnits(w,
  519. orientation,
  520. XmPIXELS,
  521. pixel,
  522. (int)unit_type));
  523. }
  524. /***************************************************************************
  525. *
  526. * GetBiggest
  527. *
  528. * Utility function to help determine largest of a set of widgets.
  529. ***************************************************************************/
  530. void
  531. GetBiggest( Widget widget, Dimension *width, Dimension *height )
  532. {
  533. Dimension new_width, new_height;
  534. XtSetArg(argt[0], XmNwidth, &new_width);
  535. XtSetArg(argt[1], XmNheight, &new_height);
  536. XtGetValues(widget, argt, 2);
  537. if (width != NULL && new_width > *width)
  538. *width = new_width;
  539. if (height != NULL && new_height > *height)
  540. *height = new_height;
  541. }
  542. /***************************************************************************
  543. *
  544. * LogError
  545. *
  546. * send errors to the error log. This routine accepts a variable number
  547. * of arguments.
  548. ***************************************************************************/
  549. void
  550. LogError( unsigned char *fmt, ...)
  551. {
  552. va_list args;
  553. time_t timer;
  554. Va_start(args,fmt);
  555. if (errorLogFile && errorLogFile[0] &&
  556. (freopen(errorLogFile, "a", stderr) != NULL)) {
  557. timer = time(NULL);
  558. fprintf(stderr, "\n%s", ctime(&timer));
  559. fprintf (stderr, "error (pid %ld): ", (long)getpid());
  560. vfprintf (stderr, (char *)fmt, args);
  561. fflush (stderr);
  562. }
  563. va_end(args);
  564. }
  565. /***************************************************************************
  566. *
  567. * CloseCatalog
  568. *
  569. ***************************************************************************/
  570. void
  571. CloseCatalog(void)
  572. {
  573. CATCLOSE(nl_fd);
  574. }
  575. /***************************************************************************
  576. *
  577. * OpenCatalog
  578. *
  579. ***************************************************************************/
  580. void
  581. OpenCatalog(void)
  582. {
  583. static int initialized = 0;
  584. char *nlspath, *newnlspath;
  585. if (initialized) return;
  586. initialized = 1;
  587. nlspath = getenv("NLSPATH");
  588. if (NULL == nlspath || 0 == strlen(nlspath))
  589. {
  590. newnlspath = malloc(8 + strlen(NLSPATH_ENV) + 1);
  591. sprintf(newnlspath, "NLSPATH=%s", NLSPATH_ENV);
  592. }
  593. else
  594. {
  595. newnlspath = malloc(8 + strlen(nlspath) + 1 + strlen(NLSPATH_ENV) + 1);
  596. sprintf(newnlspath, "NLSPATH=%s:%s", nlspath, NLSPATH_ENV);
  597. }
  598. putenv(newnlspath);
  599. /*
  600. * open the message catalog. If the language_specific version cannot
  601. * be opened, try the default...
  602. */
  603. if (NULL != langenv)
  604. {
  605. nl_fd = CATOPEN(NLS_CATALOG, NL_CAT_LOCALE);
  606. if (0 > (long) nl_fd)
  607. LogError((unsigned char*) MC_DEF_LOG_NO_MSGCAT, langenv);
  608. }
  609. }
  610. /***************************************************************************
  611. *
  612. * ReadCatalog
  613. *
  614. * read a string from the message catalog and convert to unsigned char *
  615. ***************************************************************************/
  616. unsigned char *
  617. ReadCatalog(int setn, int msgn, char *dflt)
  618. {
  619. OpenCatalog();
  620. if ((0 > (long) nl_fd) || (NULL == langenv))
  621. return (unsigned char*) dflt;
  622. else
  623. return (unsigned char*) CATGETS(nl_fd, setn, msgn, dflt);
  624. }
  625. /***************************************************************************
  626. *
  627. * ReadCatalogXms
  628. *
  629. * read a string from the message catalog and convert to compound string
  630. ***************************************************************************/
  631. XmString
  632. ReadCatalogXms(int setn, int msgn, char *dflt)
  633. {
  634. OpenCatalog();
  635. if (0 > (long) nl_fd)
  636. return XmStringCreateLocalized(dflt);
  637. else
  638. return XmStringCreateLocalized((char*) ReadCatalog(setn, msgn, dflt));
  639. }
  640. /***************************************************************************
  641. *
  642. * SecureDisplay/UnsecureDisplay
  643. *
  644. * grab/release the server and keyboard
  645. ***************************************************************************/
  646. static sigjmp_buf syncJump;
  647. static int grabServer; /* Boolean on grabbing server */
  648. static int grabTimeout; /* timeout to grab server */
  649. static SIGVAL
  650. syncTimeout( int arg )
  651. {
  652. siglongjmp (syncJump, 1);
  653. }
  654. int
  655. SecureDisplay( void )
  656. {
  657. char *t;
  658. /*
  659. * get grab values from the environment...
  660. */
  661. grabServer = ((t = (char *)getenv(GRABSERVER)) == NULL ? 0 : atoi(t));
  662. grabTimeout = ((t = (char *)getenv(GRABTIMEOUT)) == NULL ? 0 : atoi(t));
  663. /*
  664. * grab server then the keyboard...
  665. */
  666. signal (SIGALRM, syncTimeout);
  667. if (sigsetjmp (syncJump, 1)) {
  668. LogError(ReadCatalog(MC_LOG_SET,MC_LOG_NO_SECDPY,MC_DEF_LOG_NO_SECDPY),
  669. dpyinfo.name);
  670. return(1);
  671. }
  672. alarm ((unsigned int) grabTimeout);
  673. XGrabServer (dpyinfo.dpy);
  674. if (XGrabKeyboard (dpyinfo.dpy,
  675. DefaultRootWindow (dpyinfo.dpy),
  676. True,
  677. GrabModeAsync,
  678. GrabModeAsync,
  679. CurrentTime) != GrabSuccess) {
  680. alarm (0);
  681. signal (SIGALRM, SIG_DFL);
  682. LogError(ReadCatalog(MC_LOG_SET,MC_LOG_NO_SECKEY,MC_DEF_LOG_NO_SECKEY),
  683. dpyinfo.name);
  684. return(1);
  685. }
  686. alarm (0);
  687. signal (SIGALRM, SIG_DFL);
  688. /* pseudoReset (dpy);*/
  689. /*
  690. * release server if grab not requested...
  691. */
  692. if (!grabServer)
  693. {
  694. XUngrabServer (dpyinfo.dpy);
  695. XSync (dpyinfo.dpy, 0);
  696. }
  697. return (0);
  698. }
  699. void
  700. UnsecureDisplay( void )
  701. {
  702. XUngrabKeyboard(dpyinfo.dpy, CurrentTime);
  703. if (grabServer)
  704. XUngrabServer (dpyinfo.dpy);
  705. XSync (dpyinfo.dpy, 0);
  706. }
  707. /***************************************************************************
  708. *
  709. * SetResourceDatabase
  710. *
  711. *
  712. * set up display's resource database with defaults and user values
  713. *
  714. * Starting with DT 3.0, the widget's unit type defaults to XmPIXELS
  715. * rather than Xm100TH_MILLIMETERS. For backwards compatibility, it is
  716. * necessary to determine if the user has specified Xm100TH_MILLIMETERS
  717. * for the widget's unit type.
  718. *
  719. ***************************************************************************/
  720. void
  721. SetResourceDatabase( void )
  722. {
  723. typedef struct {
  724. char *name;
  725. char *value;
  726. } DefResource;
  727. int i;
  728. char defaultWidth[32], defaultHeight[32];
  729. char *rmtype; /* for XrmGetResource() */
  730. XrmValue rmvalue; /* for XrmGetResource() */
  731. static XrmDatabase defDb;
  732. XrmDatabase userDb;
  733. static DefResource defResource[] = {
  734. { "*unitType", XmNPIXELS },
  735. { "*matte.x", "-1" },
  736. { "*matte.y", "-1" },
  737. { "*login_matte.topPosition", LOGIN_TOP_POSITION },
  738. { "*login_matte.bottomPosition", LOGIN_BOTTOM_POSITION },
  739. { "*login_matte.leftPosition", LOGIN_LEFT_POSITION },
  740. { "*login_matte.rightPosition", LOGIN_RIGHT_POSITION },
  741. { "*table.background", TABLE_BACKGROUND },
  742. { "*login_text.foreground", TEXT_FOREGROUND },
  743. { "*passwd_text.foreground", TEXT_FOREGROUND },
  744. };
  745. # define NUM_RESOURCES (sizeof defResource / sizeof defResource[0])
  746. static DefResource defResourceBW[] = {
  747. { "*background", BW_BACKGROUND },
  748. { "*foreground", BW_FOREGROUND },
  749. { "*login_text.background", BW_TEXT_BACKGROUND },
  750. { "*passwd_text.background", BW_TEXT_BACKGROUND },
  751. };
  752. # define NUM_BW_RESOURCES (sizeof defResourceBW / sizeof defResourceBW[0])
  753. static DefResource defResourceGS[] = {
  754. { "*logo*Background", BW_LOGO_BACKGROUND },
  755. };
  756. # define NUM_GS_RESOURCES (sizeof defResourceGS / sizeof defResourceGS[0])
  757. static DefResource defResourceCO[] = {
  758. { "*background", CO_BACKGROUND },
  759. { "*foreground", CO_FOREGROUND },
  760. { "*login_text.background", CO_TEXT_BACKGROUND },
  761. { "*passwd_text.background", CO_TEXT_BACKGROUND },
  762. { "*highlightColor", CO_HIGHLIGHT },
  763. { "*XmToggleButtonGadget*selectColor",
  764. CO_SELECTCOLOR },
  765. };
  766. # define NUM_CO_RESOURCES (sizeof defResourceCO / sizeof defResourceCO[0])
  767. #ifdef VG_TRACE
  768. vg_TRACE_EXECUTION("SetResourceDatabase ...");
  769. #endif /* VG_TRACE */
  770. /*
  771. * check if user specified 100TH_MILLIMETERS as the unit type...
  772. *
  773. * initialize the local control variable "appInfo.unitType" to the
  774. * unit type...
  775. */
  776. appInfo.unitType = XmPIXELS;
  777. if ( XrmGetResource(XtDatabase(dpyinfo.dpy),
  778. VnNmatteUnitType, VnCMatteUnitType,
  779. &rmtype, &rmvalue ) ) {
  780. if ( strcmp (rmvalue.addr, XmN100TH_MILLIMETERS) == 0 )
  781. appInfo.unitType = Xm100TH_MILLIMETERS;
  782. }
  783. /*
  784. * build new resource database with default values....
  785. */
  786. defDb = XtDatabase(dpyinfo.dpy);
  787. sprintf(defaultWidth, "%d", FromMM(MATTE_WIDTH));
  788. sprintf(defaultHeight, "%d", FromMM(MATTE_HEIGHT));
  789. /*
  790. XrmPutStringResource(&defDb, VnNmatteWidth, defaultWidth);
  791. XrmPutStringResource(&defDb, VnNmatteHeight, defaultHeight);
  792. */
  793. if(!XrmGetResource(defDb, "*labelFont", "*LabelFont",
  794. &rmtype, &rmvalue))
  795. XrmPutStringResource(&defDb, "*labelFont",
  796. ( HIRES ? LABEL_FONT_HRES : LABEL_FONT));
  797. if(!XrmGetResource(defDb, "*textFont", "*TextFont",
  798. &rmtype, &rmvalue))
  799. XrmPutStringResource(&defDb, "*textFont",
  800. ( LOWRES ? TEXT_FONT_LRES : TEXT_FONT));
  801. if(!XrmGetResource(defDb, "*greeting.fontList",
  802. "*Greeting.FontList", &rmtype, &rmvalue))
  803. XrmPutStringResource(&defDb, "*greeting.fontList", GREET_FONT);
  804. for (i = 0; i < NUM_RESOURCES; i++)
  805. XrmPutStringResource(&defDb,
  806. defResource[i].name,
  807. defResource[i].value);
  808. if ( dpyinfo.depth < 4 )
  809. for (i = 0; i < NUM_BW_RESOURCES; i++)
  810. XrmPutStringResource(&defDb,
  811. defResourceBW[i].name,
  812. defResourceBW[i].value);
  813. else
  814. for (i = 0; i < NUM_CO_RESOURCES; i++)
  815. XrmPutStringResource(&defDb,
  816. defResourceCO[i].name,
  817. defResourceCO[i].value);
  818. if ( dpyinfo.visual->class == GrayScale )
  819. for (i = 0; i < NUM_GS_RESOURCES; i++)
  820. XrmPutStringResource(&defDb,
  821. defResourceGS[i].name,
  822. defResourceGS[i].value);
  823. /*
  824. * merge user's specifications with program defaults...
  825. */
  826. /*
  827. * replace display's resource database with merged database...
  828. */
  829. /*
  830. * Try to compensate if the user specifies the matte dimensions in
  831. * 100TH_MILLIMETERS, but forgets to also specify that unit type...
  832. */
  833. userDb = XtDatabase(dpyinfo.dpy);
  834. if ( XrmGetResource(userDb, VnNmatteWidth, VnCMatteWidth,
  835. &rmtype, &rmvalue ) ) {
  836. sscanf(rmvalue.addr, "%d", &i);
  837. if ( appInfo.unitType == XmPIXELS && i >= dpyinfo.width ) {
  838. XrmPutStringResource(&userDb, VnNmatteWidth, defaultWidth);
  839. LogError(
  840. ReadCatalog(MC_LOG_SET,MC_LOG_BAD_MATTE,MC_DEF_LOG_BAD_MATTE),
  841. dpyinfo.name);
  842. }
  843. }
  844. if ( XrmGetResource(userDb, VnNmatteHeight, VnCMatteHeight,
  845. &rmtype, &rmvalue ) ) {
  846. sscanf(rmvalue.addr, "%d", &i);
  847. if ( appInfo.unitType == XmPIXELS && i >= dpyinfo.height ) {
  848. XrmPutStringResource(&userDb, VnNmatteHeight, defaultHeight);
  849. LogError(
  850. ReadCatalog(MC_LOG_SET,MC_LOG_BAD_HMATTE,MC_DEF_LOG_BAD_HMATTE),
  851. dpyinfo.name);
  852. }
  853. }
  854. }
  855. /***************************************************************************
  856. *
  857. * ToPixel
  858. *
  859. * Convert from the widget's units into pixel units
  860. ***************************************************************************/
  861. int
  862. ToPixel( Widget w, int orientation, int pixel )
  863. {
  864. Arg argt[10];
  865. unsigned char unit_type;
  866. XtSetArg(argt[0], XmNunitType, &unit_type);
  867. XtGetValues(w, argt, 1);
  868. if (unit_type == XmPIXELS)
  869. return(pixel);
  870. else {
  871. return(XmConvertUnits(w,
  872. orientation,
  873. (int)unit_type,
  874. pixel,
  875. XmPIXELS));
  876. }
  877. }