Startup.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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. /************************************<+>*************************************
  24. ****************************************************************************
  25. **
  26. ** File: Startup.c
  27. **
  28. ** Project: DT 3.0
  29. **
  30. ** Description: Controls the Dtstyle Startup dialog
  31. **
  32. **
  33. ** (c) Copyright Hewlett-Packard Company, 1990.
  34. **
  35. **
  36. **
  37. ****************************************************************************
  38. ************************************<+>*************************************/
  39. /*$XConsortium: Startup.c /main/6 1995/12/22 15:23:38 barstow $*/
  40. /* +++++++++++++++++++++++++++++++++++++++*/
  41. /* include files */
  42. /* +++++++++++++++++++++++++++++++++++++++*/
  43. #include <X11/Xlib.h>
  44. #include <Xm/MwmUtil.h>
  45. #include <errno.h>
  46. #include <Xm/Xm.h>
  47. #include <Xm/XmP.h>
  48. #include <Xm/DialogS.h>
  49. #include <Xm/Form.h>
  50. #include <Xm/MessageB.h>
  51. #include <Xm/PushBG.h>
  52. #include <Xm/RowColumn.h>
  53. #include <Xm/Scale.h>
  54. #include <Xm/LabelG.h>
  55. #include <Xm/ToggleBG.h>
  56. #include <Xm/VendorSEP.h>
  57. #include <Dt/DialogBox.h>
  58. #include <Dt/Icon.h>
  59. #include <Dt/TitleBox.h>
  60. #include <Dt/Message.h>
  61. #include <Dt/HourGlass.h>
  62. #include "Help.h"
  63. #include "Main.h"
  64. #include "SaveRestore.h"
  65. #include "Protocol.h"
  66. /*+++++++++++++++++++++++++++++++++++++++*/
  67. /* Internal Functions */
  68. /*+++++++++++++++++++++++++++++++++++++++*/
  69. static void GetStartupValues( void ) ;
  70. static Widget BuildStartup( Widget shell) ;
  71. static void MapStartup(
  72. Widget w,
  73. XtPointer client_data,
  74. XtPointer call_data) ;
  75. static void LayoutCB(
  76. Widget w,
  77. XtPointer client_data,
  78. XtPointer call_data) ;
  79. static void SetCurrentCB(
  80. Widget w,
  81. XtPointer client_data,
  82. XmToggleButtonCallbackStruct *call_data) ;
  83. static void SetHomeCB(
  84. Widget w,
  85. XtPointer client_data,
  86. XmToggleButtonCallbackStruct *call_data) ;
  87. static void SetConfirmCB(
  88. Widget w,
  89. XtPointer client_data,
  90. XmToggleButtonCallbackStruct *call_data) ;
  91. static void SetHomeSession(
  92. Widget w,
  93. XtPointer client_data,
  94. XtPointer call_data) ;
  95. static void SaveHomeOk(
  96. Widget w,
  97. XtPointer client_data,
  98. XtPointer call_data) ;
  99. static void ButtonCB(
  100. Widget w,
  101. XtPointer client_data,
  102. XtPointer call_data) ;
  103. /*+++++++++++++++++++++++++++++++++++++++*/
  104. /* Internal Variables */
  105. /*+++++++++++++++++++++++++++++++++++++++*/
  106. typedef struct {
  107. Widget startupForm;
  108. Widget resumeTgl;
  109. Widget homeTgl;
  110. Widget modeYesTgl;
  111. Widget modeNoTgl;
  112. Widget setHome;
  113. Widget dlg;
  114. int origStartState;
  115. int origConfirmMode;
  116. } Startup;
  117. static Startup startup;
  118. static saveRestore save = {FALSE, 0, };
  119. /*+++++++++++++++++++++++++++++++++++++++*/
  120. /* popup_startupBB */
  121. /*+++++++++++++++++++++++++++++++++++++++*/
  122. void
  123. popup_startupBB(
  124. Widget shell )
  125. {
  126. if (style.startupDialog == NULL)
  127. {
  128. if (smWindow != 0)
  129. {
  130. if (style.smState.smCompatMode)
  131. {
  132. InfoDialog(((char *)GETMESSAGE(7, 13,
  133. "This session was started from an X Window System\n\
  134. startup script. Startup settings are not valid,\n\
  135. since the session cannot be restored.")),
  136. style.startupDialog ? style.startupDialog : style.shell, False);
  137. return;
  138. }
  139. _DtTurnOnHourGlass(shell);
  140. GetStartupValues();
  141. BuildStartup(shell);
  142. XtManageChild(style.startupDialog);
  143. _DtTurnOffHourGlass(shell);
  144. }
  145. else /* SM not running - post error dialog */
  146. {
  147. InfoDialog(((char *)GETMESSAGE(7, 15,
  148. "The Session Manager is not running.\n\
  149. Startup settings are not valid.")),
  150. style.startupDialog ? style.startupDialog : style.shell, False);
  151. return;
  152. }
  153. }
  154. else
  155. {
  156. XtManageChild(style.startupDialog);
  157. raiseWindow(XtWindow(XtParent(style.startupDialog)));
  158. }
  159. }
  160. /*++++++++++++++++++++++++++++++++++++++++*/
  161. /* Get startup values ... used for cancel */
  162. /*++++++++++++++++++++++++++++++++++++++++*/
  163. static void
  164. GetStartupValues( void )
  165. {
  166. startup.origStartState = style.smState.smStartState;
  167. startup.origConfirmMode = style.smState.smConfirmMode;
  168. }
  169. /*++++++++++++++++++++++++++++++++++++++++*/
  170. /* build__startupBB */
  171. /*++++++++++++++++++++++++++++++++++++++++*/
  172. static Widget
  173. BuildStartup(
  174. Widget shell )
  175. {
  176. int n;
  177. Arg args[MAX_ARGS];
  178. XmString button_string[NUM_LABELS];
  179. XmString string;
  180. int count = 0;
  181. int count2 = 0;
  182. Widget widget_list[5],
  183. widget_list2[3],
  184. modeForm,
  185. shutdownRC;
  186. startup.dlg = NULL;
  187. /* Set up DialogBoxDialog button labels */
  188. button_string[0] = CMPSTR((String) _DtOkString);
  189. button_string[1] = CMPSTR((String) _DtCancelString);
  190. button_string[2] = CMPSTR((String) _DtHelpString);
  191. /* Create toplevel DialogBox */
  192. /* saveRestore
  193. * Note that save.poscnt has been initialized elsewhere.
  194. * save.posArgs may contain information from restoreStartup().*/
  195. XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);
  196. save.poscnt++;
  197. XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string);
  198. save.poscnt++;
  199. XtSetArg(save.posArgs[save.poscnt], XmNdefaultPosition, False);
  200. save.poscnt++;
  201. style.startupDialog =
  202. __DtCreateDialogBoxDialog(shell, "startupDlg", save.posArgs, save.poscnt);
  203. XtAddCallback(style.startupDialog, XmNcallback, ButtonCB, NULL);
  204. XtAddCallback(style.startupDialog, XmNhelpCallback,
  205. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_STARTUP_DIALOG);
  206. XmStringFree(button_string[0]);
  207. XmStringFree(button_string[1]);
  208. XmStringFree(button_string[2]);
  209. widget_list[0] = _DtDialogBoxGetButton(style.startupDialog,2);
  210. n=0;
  211. XtSetArg(args[n], XmNautoUnmanage, False); n++;
  212. XtSetArg(args[n], XmNcancelButton, widget_list[0]); n++;
  213. XtSetValues (style.startupDialog, args, n);
  214. n=0;
  215. XtSetArg(args[n], XmNtitle, ((char *)GETMESSAGE(7, 14, "Style Manager - Startup"))); n++;
  216. XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
  217. XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC ); n++;
  218. XtSetValues (XtParent(style.startupDialog), args, n);
  219. n = 0;
  220. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  221. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  222. XtSetArg(args[n], XmNallowOverlap, False); n++;
  223. XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
  224. startup.startupForm = XmCreateForm(style.startupDialog, "startupForm", args, n);
  225. n = 0;
  226. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  227. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  228. XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
  229. XtSetArg(args[n], XmNbehavior, XmICON_LABEL); n++;
  230. XtSetArg(args[n], XmNpixmapForeground, style.secBSCol); n++;
  231. XtSetArg(args[n], XmNpixmapBackground, style.secTSCol); n++;
  232. XtSetArg(args[n], XmNstring, NULL); n++;
  233. XtSetArg(args[n], XmNshadowThickness, 0); n++;
  234. XtSetArg(args[n], XmNimageName, STARTUP_ICON); n++;
  235. XtSetArg(args[n], XmNtraversalOn, False); n++;
  236. widget_list[count++] =
  237. _DtCreateIcon(startup.startupForm, "startupPict", args, n);
  238. if (style.smState.smDisplaySpecific)
  239. {
  240. char *pch1;
  241. char *pch2;
  242. pch1 = (char *)GETMESSAGE(7, 16, "Display-specific session:");
  243. pch2 = XtMalloc(strlen (pch1) +
  244. strlen (XDisplayName (getenv("DISPLAY"))) + 3);
  245. (void) sprintf(pch2, "%s\n%s", pch1, XDisplayName (getenv("DISPLAY")));
  246. n = 0;
  247. string = CMPSTR(pch2);
  248. XtSetArg(args[n], XmNleftWidget, widget_list[count-1]); n++;
  249. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  250. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  251. XtSetArg(args[n], XmNmarginLeft, 80); n++;
  252. XtSetArg(args[n], XmNlabelString, string); n++;
  253. widget_list[count++] =
  254. XmCreateLabelGadget(startup.startupForm, "sessionLabel", args, n);
  255. XmStringFree(string);
  256. XtFree(pch2);
  257. }
  258. n = 0;
  259. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  260. XtSetArg(args[n], XmNtopWidget, widget_list[count-1]); n++;
  261. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  262. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  263. XtSetArg(args[n], XmNmarginHeight, style.verticalSpacing); n++;
  264. XtSetArg(args[n], XmNmarginWidth, style.horizontalSpacing); n++;
  265. string = CMPSTR(((char *)GETMESSAGE(7, 3, "At Login:")));
  266. XtSetArg(args[n], XmNtitleString, string); n++;
  267. widget_list[count++] =
  268. _DtCreateTitleBox(startup.startupForm,"shutdownBox", args, n);
  269. XmStringFree(string);
  270. n = 0;
  271. XtSetArg(args[n], XmNmarginHeight, 0); n++;
  272. XtSetArg(args[n], XmNmarginWidth, 0); n++;
  273. shutdownRC= XmCreateRadioBox(widget_list[count-1],"shutdownRC", args, n);
  274. /*
  275. * For early versions of dtstyle, style.smState.smStartState could
  276. * be set to a value that is no longer supported. If this occurs,
  277. * no button will be selected, so initialize style.smState.smStartState
  278. * to a state that is supported.
  279. */
  280. if (style.smState.smStartState != DtSM_CURRENT_STATE &&
  281. style.smState.smStartState != DtSM_HOME_STATE)
  282. style.smState.smStartState = DtSM_CURRENT_STATE;
  283. n = 0;
  284. XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  285. string = CMPSTR(((char *)GETMESSAGE(7, 4, "Resume current session")));
  286. XtSetArg(args[n], XmNlabelString, string); n++;
  287. if (style.smState.smStartState == DtSM_CURRENT_STATE)
  288. {
  289. XtSetArg(args[n], XmNset, True); n++;
  290. }
  291. widget_list2[count2++] = startup.resumeTgl
  292. = XmCreateToggleButtonGadget(shutdownRC,"resumeTgl", args, n);
  293. XmStringFree(string);
  294. n = 0;
  295. XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  296. string = CMPSTR(((char *)GETMESSAGE(7, 5, "Return to Home session")));
  297. XtSetArg(args[n], XmNlabelString, string); n++;
  298. if (style.smState.smStartState == DtSM_HOME_STATE)
  299. {
  300. XtSetArg(args[n], XmNset, True); n++;
  301. }
  302. widget_list2[count2++] = startup.homeTgl
  303. = XmCreateToggleButtonGadget(shutdownRC,"homeTgl", args, n);
  304. XmStringFree(string);
  305. n = 0;
  306. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  307. XtSetArg(args[n], XmNtopWidget, widget_list[count-1]); n++;
  308. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  309. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  310. XtSetArg(args[n], XmNmarginHeight, style.verticalSpacing); n++;
  311. XtSetArg(args[n], XmNmarginWidth, style.horizontalSpacing); n++;
  312. string = CMPSTR(((char *)GETMESSAGE(7, 7, "Logout Confirmation Dialog:")));
  313. XtSetArg(args[n], XmNtitleString, string); n++;
  314. widget_list[count++] = _DtCreateTitleBox(startup.startupForm,"modeBox", args, n);
  315. XmStringFree(string);
  316. n = 0;
  317. XtSetArg(args[n], XmNmarginHeight, 0); n++;
  318. XtSetArg(args[n], XmNmarginWidth, 0); n++;
  319. XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
  320. modeForm = XmCreateRadioBox(widget_list[count-1], "modeForm", args, n);
  321. n = 0;
  322. XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  323. string = CMPSTR(((char *)GETMESSAGE(7, 8, "On")));
  324. XtSetArg(args[n], XmNlabelString, string ); n++;
  325. if (style.smState.smConfirmMode == DtSM_VERBOSE_MODE)
  326. {
  327. XtSetArg(args[n], XmNset, True); n++;
  328. }
  329. else {
  330. XtSetArg(args[n], XmNset, False); n++;
  331. }
  332. startup.modeYesTgl= XmCreateToggleButtonGadget(modeForm,"modeYesTgl", args, n);
  333. XmStringFree(string);
  334. n = 0;
  335. XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  336. string = CMPSTR(((char *)GETMESSAGE(7, 9, "Off")));
  337. XtSetArg(args[n], XmNlabelString, string ); n++;
  338. if (style.smState.smConfirmMode != DtSM_VERBOSE_MODE)
  339. {
  340. XtSetArg(args[n], XmNset, True); n++;
  341. }
  342. else {
  343. XtSetArg(args[n], XmNset, False); n++;
  344. }
  345. startup.modeNoTgl= XmCreateToggleButtonGadget(modeForm,"modeNoTgl", args, n);
  346. XmStringFree(string);
  347. n = 0;
  348. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  349. XtSetArg(args[n], XmNtopWidget, widget_list[count-1]); n++;
  350. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  351. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  352. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  353. XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT); n++;
  354. XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
  355. XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;
  356. string = CMPSTR(((char *)GETMESSAGE(7, 10, "Set Home Session ...")));
  357. XtSetArg(args[n], XmNlabelString, string); n++;
  358. widget_list[count++] = startup.setHome =
  359. XmCreatePushButtonGadget(startup.startupForm,"setPB", args, n);
  360. XmStringFree(string);
  361. XtAddCallback(style.startupDialog, XmNmapCallback, MapStartup, shell);
  362. XtAddCallback(style.startupDialog, XmNmapCallback, LayoutCB, shell);
  363. XtAddCallback(startup.resumeTgl, XmNvalueChangedCallback,
  364. (XtCallbackProc)SetCurrentCB, NULL);
  365. XtAddCallback(startup.homeTgl, XmNvalueChangedCallback,
  366. (XtCallbackProc)SetHomeCB, NULL);
  367. XtAddCallback(startup.modeYesTgl, XmNvalueChangedCallback,
  368. (XtCallbackProc)SetConfirmCB, NULL);
  369. XtAddCallback( widget_list[count-1], XmNactivateCallback,
  370. SetHomeSession, style.startupDialog);
  371. XtManageChild(modeForm);
  372. XtManageChild(startup.startupForm);
  373. XtManageChild(shutdownRC);
  374. XtManageChildren(widget_list2,count2);
  375. XtManageChild(startup.modeYesTgl);
  376. XtManageChild(startup.modeNoTgl);
  377. XtManageChildren(widget_list,count);
  378. return(style.startupDialog);
  379. }
  380. /*+++++++++++++++++++++++++++++++++++++++*/
  381. /* MapStartup */
  382. /*+++++++++++++++++++++++++++++++++++++++*/
  383. static void
  384. MapStartup(
  385. Widget w,
  386. XtPointer client_data,
  387. XtPointer call_data )
  388. {
  389. DtWsmRemoveWorkspaceFunctions (style.display, XtWindow(XtParent(w)));
  390. if (!save.restoreFlag)
  391. putDialog ((Widget)client_data, w);
  392. XtRemoveCallback(style.startupDialog, XmNmapCallback, MapStartup, NULL);
  393. }
  394. /*+++++++++++++++++++++++++++++++++++++++*/
  395. /* LayoutCB */
  396. /*+++++++++++++++++++++++++++++++++++++++*/
  397. static void
  398. LayoutCB(
  399. Widget w,
  400. XtPointer client_data,
  401. XtPointer call_data )
  402. {
  403. int n=0;
  404. Arg args[4];
  405. if (XtWidth(startup.startupForm) < (Dimension) (XtWidth(startup.setHome) +
  406. (2*style.horizontalSpacing)))
  407. {
  408. n=0;
  409. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  410. XtSetValues(startup.setHome, args, n);
  411. }
  412. XtRemoveCallback(style.startupDialog, XmNmapCallback, LayoutCB, NULL);
  413. }
  414. /*+++++++++++++++++++++++++++++++++++++++*/
  415. /* SetCurrentCB */
  416. /* tell SM to resume current session */
  417. /*+++++++++++++++++++++++++++++++++++++++*/
  418. static void
  419. SetCurrentCB(
  420. Widget w,
  421. XtPointer client_data,
  422. XmToggleButtonCallbackStruct *call_data )
  423. {
  424. if (call_data->set)
  425. style.smState.smStartState = DtSM_CURRENT_STATE;
  426. }
  427. /*+++++++++++++++++++++++++++++++++++++++*/
  428. /* SetHomeCB */
  429. /* tell SM to use home session */
  430. /*+++++++++++++++++++++++++++++++++++++++*/
  431. static void
  432. SetHomeCB(
  433. Widget w,
  434. XtPointer client_data,
  435. XmToggleButtonCallbackStruct *call_data )
  436. {
  437. if (call_data->set)
  438. style.smState.smStartState = DtSM_HOME_STATE;
  439. }
  440. /*+++++++++++++++++++++++++++++++++++++++*/
  441. /* SetConfirmCB */
  442. /* tell SM to be verbose or not */
  443. /*+++++++++++++++++++++++++++++++++++++++*/
  444. static void
  445. SetConfirmCB(
  446. Widget w,
  447. XtPointer client_data,
  448. XmToggleButtonCallbackStruct *call_data )
  449. {
  450. int n;
  451. Arg args[2];
  452. Boolean mode;
  453. if (call_data->set)
  454. style.smState.smConfirmMode = DtSM_VERBOSE_MODE;
  455. else
  456. {
  457. style.smState.smConfirmMode = DtSM_QUIET_MODE;
  458. }
  459. }
  460. /*+++++++++++++++++++++++++++++++++++++++*/
  461. /* SaveHomeOk */
  462. /*+++++++++++++++++++++++++++++++++++++++*/
  463. static void
  464. SaveHomeOk(
  465. Widget w,
  466. XtPointer client_data,
  467. XtPointer call_data )
  468. {
  469. SmSaveHomeSession(startup.origStartState, startup.origConfirmMode);
  470. }
  471. /*+++++++++++++++++++++++++++++++++++++++*/
  472. /* SetHomeSession */
  473. /* allow user to cancel out */
  474. /*+++++++++++++++++++++++++++++++++++++++*/
  475. static void
  476. SetHomeSession(
  477. Widget w,
  478. XtPointer client_data,
  479. XtPointer call_data )
  480. {
  481. int n=0;
  482. Arg args[6];
  483. Widget shell = (Widget) client_data;
  484. XmString string;
  485. XmString okstr, cancelstr;
  486. if (startup.dlg == NULL)
  487. {
  488. string = CMPSTR(((char *)GETMESSAGE(7, 11, "This will replace your home session with\nthe current session.\n\n Continue?")));
  489. XtSetArg(args[n], XmNmessageString, string); n++;
  490. okstr = CMPSTR((String) _DtOkString);
  491. cancelstr = CMPSTR((String) _DtCancelString);
  492. XtSetArg(args[n], XmNokLabelString, okstr); n++;
  493. XtSetArg(args[n], XmNcancelLabelString, cancelstr); n++;
  494. XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC ); n++;
  495. startup.dlg = XmCreateWarningDialog(shell, "QNotice", args, n);
  496. XtUnmanageChild (XmMessageBoxGetChild(startup.dlg, XmDIALOG_HELP_BUTTON));
  497. XtAddCallback(startup.dlg, XmNokCallback, SaveHomeOk, NULL);
  498. XmStringFree(string);
  499. XmStringFree(okstr);
  500. XmStringFree(cancelstr);
  501. n=0;
  502. XtSetArg (args[n], XmNmwmInputMode,
  503. MWM_INPUT_PRIMARY_APPLICATION_MODAL); n++;
  504. XtSetArg(args[n], XmNtitle, ((char *)GETMESSAGE(7, 12, "Warning"))); n++;
  505. XtSetValues (XtParent(startup.dlg), args, n);
  506. }
  507. XtManageChild(startup.dlg);
  508. }
  509. /*+++++++++++++++++++++++++++++++++++++++*/
  510. /* ButtonCB */
  511. /* CB for OK, Cancel, Help in DialogBox */
  512. /*+++++++++++++++++++++++++++++++++++++++*/
  513. static void
  514. ButtonCB(
  515. Widget w,
  516. XtPointer client_data,
  517. XtPointer call_data )
  518. {
  519. Arg set[1], unset[1];
  520. DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
  521. switch (cb->button_position)
  522. {
  523. case OK_BUTTON:
  524. XtUnmanageChild (w);
  525. if (XmToggleButtonGadgetGetState(startup.modeYesTgl))
  526. startup.origConfirmMode = DtSM_VERBOSE_MODE;
  527. else
  528. startup.origConfirmMode = DtSM_QUIET_MODE;
  529. SmNewStartupSettings();
  530. break;
  531. case CANCEL_BUTTON:
  532. XmToggleButtonGadgetSetState(startup.resumeTgl, True, True);
  533. XmToggleButtonGadgetSetState(startup.resumeTgl, False, True);
  534. XtSetArg(set[0], XmNset, True);
  535. XtSetArg(unset[0], XmNset, False);
  536. if (startup.origStartState == DtSM_CURRENT_STATE)
  537. XmToggleButtonGadgetSetState(startup.resumeTgl, True, True);
  538. else if (startup.origStartState == DtSM_HOME_STATE)
  539. XmToggleButtonGadgetSetState(startup.homeTgl, True, True);
  540. else
  541. /*
  542. * Reasonable default?
  543. */
  544. XmToggleButtonGadgetSetState(startup.resumeTgl, True, True);
  545. if (startup.origConfirmMode == DtSM_VERBOSE_MODE)
  546. XmToggleButtonGadgetSetState(startup.modeYesTgl, True, True);
  547. else
  548. XmToggleButtonGadgetSetState(startup.modeNoTgl, True, True);
  549. style.smState.smStartState = startup.origStartState;
  550. style.smState.smConfirmMode = startup.origConfirmMode;
  551. XtUnmanageChild (w);
  552. break;
  553. case HELP_BUTTON:
  554. XtCallCallbacks(style.startupDialog, XmNhelpCallback, (XtPointer)NULL);
  555. break;
  556. default:
  557. break;
  558. }
  559. }
  560. /************************************************************************
  561. * restoreStartup()
  562. *
  563. * restore any state information saved with saveStartup.
  564. * This is called from restoreSession with the application
  565. * shell and the special xrm database retrieved for restore.
  566. ************************************************************************/
  567. void
  568. restoreStartup(
  569. Widget shell,
  570. XrmDatabase db )
  571. {
  572. XrmName xrm_name[5];
  573. XrmRepresentation rep_type;
  574. XrmValue value;
  575. xrm_name [0] = XrmStringToQuark ("startupDlg");
  576. xrm_name [2] = 0;
  577. /* get x position */
  578. xrm_name [1] = XrmStringToQuark ("x");
  579. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  580. XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
  581. save.poscnt++;
  582. save.restoreFlag = True;
  583. }
  584. /* get y position */
  585. xrm_name [1] = XrmStringToQuark ("y");
  586. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  587. XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr));
  588. save.poscnt++;
  589. }
  590. xrm_name [1] = XrmStringToQuark ("ismapped");
  591. XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
  592. /* Are we supposed to be mapped? */
  593. if (strcmp(value.addr, "True") == 0)
  594. popup_startupBB(shell);
  595. }
  596. /************************************************************************
  597. * saveStartup()
  598. *
  599. * This routine will write out to the passed file descriptor any state
  600. * information this dialog needs. It is called from saveSessionCB with the
  601. * file already opened.
  602. * All information is saved in xrm format. There is no restriction
  603. * on what can be saved. It doesn't have to be defined or be part of any
  604. * widget or Xt definition. Just name and save it here and recover it in
  605. * restoreStartup. The suggested minimum is whether you are mapped, and
  606. * your location.
  607. ************************************************************************/
  608. void
  609. saveStartup(
  610. int fd )
  611. {
  612. Position x,y;
  613. char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
  614. XmVendorShellExtObject vendorExt;
  615. XmWidgetExtData extData;
  616. if (style.startupDialog != NULL) {
  617. if (XtIsManaged(style.startupDialog))
  618. sprintf(bufr, "*startupDlg.ismapped: True\n");
  619. else
  620. sprintf(bufr, "*startupDlg.ismapped: False\n");
  621. /* Get and write out the geometry info for our Window */
  622. x = XtX(XtParent(style.startupDialog));
  623. y = XtY(XtParent(style.startupDialog));
  624. /* Modify x & y to take into account window mgr frames
  625. * This is pretty bogus, but I don't know a better way to do it.
  626. */
  627. extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
  628. vendorExt = (XmVendorShellExtObject)extData->widget;
  629. x -= vendorExt->vendor.xOffset;
  630. y -= vendorExt->vendor.yOffset;
  631. sprintf(bufr, "%s*startupDlg.x: %d\n", bufr, x);
  632. sprintf(bufr, "%s*startupDlg.y: %d\n", bufr, y);
  633. if(-1 == write (fd, bufr, strlen(bufr))) {
  634. perror(strerror(errno));
  635. }
  636. }
  637. }