MainWin.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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. /* $XConsortium: MainWin.c /main/8 1996/03/25 00:52:54 pascale $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: MainWin.c
  28. **
  29. ** Project: DT 3.0
  30. **
  31. ** Description: Controls the main Dtstyle dialog
  32. **
  33. **
  34. ****************************************************************************
  35. ************************************<+>*************************************/
  36. /*
  37. * (c) Copyright 1996 Digital Equipment Corporation.
  38. * (c) Copyright 1990, 1996 Hewlett-Packard Company.
  39. * (c) Copyright 1996 International Business Machines Corp.
  40. * (c) Copyright 1996 Sun Microsystems, Inc.
  41. * (c) Copyright 1996 Novell, Inc.
  42. * (c) Copyright 1996 FUJITSU LIMITED.
  43. * (c) Copyright 1996 Hitachi.
  44. */
  45. /*+++++++++++++++++++++++++++++++++++++++*/
  46. /* include files */
  47. /*+++++++++++++++++++++++++++++++++++++++*/
  48. #include <X11/Xlib.h>
  49. #include <Xm/MwmUtil.h>
  50. #include <signal.h>
  51. #include <errno.h>
  52. #include <Xm/Xm.h>
  53. #include <Xm/XmP.h>
  54. #include <Xm/CascadeB.h>
  55. #include <Xm/ColorObjP.h>
  56. #include <Xm/MainW.h>
  57. #include <Xm/Frame.h>
  58. #include <Xm/PushB.h>
  59. #include <Xm/RowColumn.h>
  60. #include <Xm/SeparatoG.h>
  61. /*
  62. #include <Dt/Box.h>
  63. */
  64. #include <Dt/Control.h>
  65. #include <Dt/DialogBox.h>
  66. #include <Dt/Icon.h>
  67. #include <Dt/IconFile.h>
  68. #include <Dt/HourGlass.h>
  69. #include <Dt/UserMsg.h>
  70. #include "Main.h"
  71. #include "ColorMain.h"
  72. #include "Backdrop.h"
  73. #include "Keyboard.h"
  74. #include "Mouse.h"
  75. #include "Audio.h"
  76. #include "Screen.h"
  77. #include "Dtwm.h"
  78. #include "Startup.h"
  79. #include "I18nMain.h"
  80. #include "Help.h"
  81. #include "SaveRestore.h"
  82. /*+++++++++++++++++++++++++++++++++++++++*/
  83. /* include extern functions */
  84. /*+++++++++++++++++++++++++++++++++++++++*/
  85. #include "MainWin.h"
  86. /*+++++++++++++++++++++++++++++++++++++++*/
  87. /* Local #defines */
  88. /*+++++++++++++++++++++++++++++++++++++++*/
  89. /*+++++++++++++++++++++++++++++++++++++++*/
  90. /* Internal Functions */
  91. /*+++++++++++++++++++++++++++++++++++++++*/
  92. static void _DtMapCB(
  93. Widget w,
  94. XtPointer client_data,
  95. XtPointer call_data) ;
  96. static void build_mainWindow( Widget shell) ;
  97. static void activateCB(
  98. Widget w,
  99. XtPointer client_data,
  100. XtPointer call_data) ;
  101. static void ProcessComponentList(
  102. Widget parent,
  103. Widget mainRC) ;
  104. /*+++++++++++++++++++++++++++++++++++++++*/
  105. /* Internal variables */
  106. /*+++++++++++++++++++++++++++++++++++++++*/
  107. static int colorUse = XmCO_BLACK_WHITE;
  108. static saveRestore save = {FALSE, 0, };
  109. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  110. /* init_mainWindow */
  111. /* */
  112. /* build if needed, otherwise just manage the mainWindow. */
  113. /* Assumes shell has been created */
  114. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  115. void
  116. init_mainWindow( Widget shell )
  117. {
  118. if (style.mainWindow == NULL) {
  119. build_mainWindow(shell);
  120. if (save.restoreFlag)
  121. XtAddCallback (shell, XtNpopupCallback, _DtMapCB, NULL);
  122. XtManageChild(style.mainWindow);
  123. XtPopup(shell, XtGrabNone);
  124. }
  125. else /* fix Shouldn't ever happen */
  126. XtManageChild(style.mainWindow);
  127. }
  128. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  129. /* _DtMapCB */
  130. /* first time only, set correct sizing in case font */
  131. /* size has changed (if so, saved size is wrong) */
  132. /* remove callback after first time */
  133. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  134. static void
  135. _DtMapCB(
  136. Widget w,
  137. XtPointer client_data,
  138. XtPointer call_data )
  139. {
  140. XSizeHints hints;
  141. if (save.restoreFlag)
  142. {
  143. hints.min_width = XtWidth(w);
  144. hints.min_height = XtHeight(w);
  145. hints.max_width = XtWidth(w);
  146. hints.max_height = XtHeight(w);
  147. hints.flags = PMinSize | PMaxSize;
  148. XSetWMNormalHints (style.display, XtWindow(w), &hints);
  149. }
  150. XtRemoveCallback(style.shell, XtNpopupCallback, _DtMapCB, NULL);
  151. }
  152. /*+++++++++++++++++++++++++++++++++++++++++++++*/
  153. /* build_mainWindow */
  154. /* */
  155. /* build the main window, but don't manage it. */
  156. /*+++++++++++++++++++++++++++++++++++++++++++++*/
  157. static void
  158. build_mainWindow(
  159. Widget shell )
  160. {
  161. int count, n, n2;
  162. Arg args[MAX_ARGS];
  163. Widget WidgList[10];
  164. Widget frame;
  165. Widget mainMenu;
  166. Widget mainRC;
  167. Widget filePulldown;
  168. Widget helpPulldown;
  169. Widget exitBtn;
  170. char *mnemonic;
  171. char *tmpStr;
  172. Pixmap pixmap;
  173. XmString labelString;
  174. Pixmap ditherPix;
  175. XmPixelSet pixelSet[XmCO_NUM_COLORS];
  176. Pixel bg;
  177. short a,i,p,s;
  178. /* saveRestore
  179. * Note that save.poscnt has been initialized elsewhere.
  180. * save.posArgs may contain information from restoreAudio().*/
  181. XtSetArg(save.posArgs[save.poscnt], XmNnoResize, True); save.poscnt++;
  182. XtSetArg(save.posArgs[save.poscnt], XmNresizePolicy, XmRESIZE_NONE); save.poscnt++;
  183. style.mainWindow= XmCreateMainWindow(shell,"mainWindow", save.posArgs, save.poscnt);
  184. XtAddCallback(style.mainWindow, XmNhelpCallback,
  185. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_MAIN_WINDOW);
  186. n = 0;
  187. tmpStr = (char *)XtMalloc(strlen(GETMESSAGE(4, 1, "Style Manager"))+1);
  188. sprintf(tmpStr, "%s", GETMESSAGE(4, 1, "Style Manager"));
  189. XtSetArg(args[n], XmNtitle, tmpStr); n++;
  190. XtSetArg(args[n], XmNiconName,
  191. (char *)GETMESSAGE(4, 37, "Style")); n++;
  192. XtSetValues(XtParent(style.mainWindow), args, n);
  193. XtFree(tmpStr);
  194. n = 0;
  195. mainMenu= XmCreateMenuBar(style.mainWindow,"mainMenu", args, n);
  196. XtAddCallback(mainMenu, XmNhelpCallback,
  197. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_MENUBAR);
  198. XtManageChild(mainMenu);
  199. /* create the pulldown widgets */
  200. n = 0;
  201. filePulldown= XmCreatePulldownMenu(mainMenu,"fileMenu", args, n );
  202. XtAddCallback(filePulldown, XmNhelpCallback,
  203. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_FILE_MENU);
  204. n = 0;
  205. helpPulldown= XmCreatePulldownMenu(mainMenu, "helpMenu" , args, n );
  206. XtAddCallback(helpPulldown, XmNhelpCallback,
  207. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_HELP_MENU);
  208. /* create the cascade butons */
  209. count = 0;
  210. n = 0;
  211. mnemonic = ((char *)GETMESSAGE(4, 2, "F"));
  212. XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
  213. labelString = CMPSTR((char *)GETMESSAGE(4, 3, "File"));
  214. XtSetArg(args[n], XmNlabelString, labelString); n++;
  215. XtSetArg(args[n], XmNsubMenuId, filePulldown); n++;
  216. XtSetArg (args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
  217. WidgList[count++]=
  218. XmCreateCascadeButton(mainMenu, "fileCascadeButton", args, n );
  219. XtAddCallback(WidgList[count-1], XmNhelpCallback,
  220. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_FILE_MENU);
  221. XmStringFree(labelString);
  222. n = 0;
  223. mnemonic = ((char *)GETMESSAGE(4, 4, "H"));
  224. XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
  225. labelString = CMPSTR((char *)GETMESSAGE(4, 5, "Help"));
  226. XtSetArg(args[n], XmNlabelString, labelString); n++;
  227. XtSetArg(args[n], XmNsubMenuId, helpPulldown); n++;
  228. XtSetArg (args[n], XmNmarginWidth, 6); n++;
  229. WidgList[count++]=
  230. XmCreateCascadeButton(mainMenu, "helpCascadeButton", args, n );
  231. XtAddCallback(WidgList[count-1], XmNhelpCallback,
  232. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_HELP_MENU);
  233. XmStringFree(labelString);
  234. n = 0;
  235. XtSetArg(args[n], XmNmenuHelpWidget, WidgList[count-1]); n++;
  236. XtSetValues (mainMenu, args, n);
  237. XtManageChildren (WidgList, count);
  238. /* create the File menu pane's buttons */
  239. n = 0;
  240. mnemonic = ((char *)GETMESSAGE(4, 53, "x"));
  241. XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
  242. labelString = CMPSTR((char *)GETMESSAGE(4, 7, "Exit"));
  243. XtSetArg(args[n], XmNlabelString, labelString); n++;
  244. exitBtn= XmCreatePushButton(filePulldown, "exit", args, n );
  245. XtAddCallback(exitBtn, XmNactivateCallback, activateCB_exitBtn, NULL);
  246. XtAddCallback(exitBtn, XmNhelpCallback,
  247. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_EXIT);
  248. XtManageChild(exitBtn);
  249. XmStringFree(labelString);
  250. /* create the Help menu pane's buttons */
  251. count =0;
  252. n = 0;
  253. mnemonic = ((char *)GETMESSAGE(4, 54, "v"));
  254. XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
  255. labelString = CMPSTR((char *)GETMESSAGE(4, 55, "Overview"));
  256. XtSetArg(args[n], XmNlabelString, labelString); n++;
  257. WidgList[count++]=
  258. XmCreatePushButton(helpPulldown, "overview", args, n );
  259. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  260. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_INTRODUCTION);
  261. XmStringFree(labelString);
  262. n = 0;
  263. WidgList[count++]=
  264. XmCreateSeparatorGadget(helpPulldown,"separator",args,n);
  265. n = 0;
  266. mnemonic = ((char *)GETMESSAGE(4, 43, "T"));
  267. XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
  268. labelString = CMPSTR((char *)GETMESSAGE(4, 56, "Tasks"));
  269. XtSetArg(args[n], XmNlabelString, labelString); n++;
  270. WidgList[count++]= XmCreatePushButton(helpPulldown, "tasks", args, n );
  271. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  272. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_TASKS);
  273. XmStringFree(labelString);
  274. n = 0;
  275. mnemonic = ((char *)GETMESSAGE(4, 45, "R"));
  276. XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
  277. labelString = CMPSTR((char *)GETMESSAGE(4, 57, "Reference"));
  278. XtSetArg(args[n], XmNlabelString, labelString); n++;
  279. WidgList[count++]= XmCreatePushButton(helpPulldown, "reference", args, n );
  280. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  281. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_REFERENCE);
  282. XmStringFree(labelString);
  283. n = 0;
  284. mnemonic = ((char *)GETMESSAGE(4, 47, "O"));
  285. XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
  286. labelString = CMPSTR((char *)GETMESSAGE(4, 48, "On Item"));
  287. XtSetArg(args[n], XmNlabelString, labelString); n++;
  288. WidgList[count++]= XmCreatePushButton(helpPulldown, "onItem", args, n );
  289. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  290. (XtCallbackProc)HelpModeCB, (XtPointer)NULL);
  291. XmStringFree(labelString);
  292. n = 0;
  293. WidgList[count++] =
  294. XmCreateSeparatorGadget(helpPulldown,"separator",args,n);
  295. n = 0;
  296. mnemonic = ((char *)GETMESSAGE(4, 49, "U"));
  297. XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
  298. labelString = CMPSTR((char *)GETMESSAGE(4, 58, "Using Help"));
  299. XtSetArg(args[n], XmNlabelString, labelString); n++;
  300. WidgList[count++]=
  301. XmCreatePushButton(helpPulldown, "usingHelp", args, n );
  302. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  303. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_USING);
  304. XmStringFree(labelString);
  305. n = 0;
  306. WidgList[count++] =
  307. XmCreateSeparatorGadget(helpPulldown,"separator",args,n);
  308. n = 0;
  309. mnemonic = ((char *)GETMESSAGE(4, 59, "A"));
  310. XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
  311. labelString = CMPSTR((char *)GETMESSAGE(4, 60, "About Style Manager"));
  312. XtSetArg(args[n], XmNlabelString, labelString); n++;
  313. WidgList[count++]= XmCreatePushButton(helpPulldown, "stylemanager", args, n );
  314. XtAddCallback(WidgList[count-1], XmNactivateCallback,
  315. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_VERSION);
  316. XmStringFree(labelString);
  317. XtManageChildren(WidgList, count);
  318. /* create frame and row column for icon gadgets */
  319. n = 0;
  320. XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
  321. XtSetArg(args[n], XmNshadowType, XmSHADOW_OUT); n++;
  322. XtSetArg(args[n], XmNshadowThickness, 1); n++;
  323. frame = XmCreateFrame(style.mainWindow, "frame", args, n);
  324. XtManageChild(frame);
  325. /* Save pixels for later use */
  326. /* primary top/bottom shadow -> fg/bg for pixmaps in primary areas */
  327. /* secondary top/bottom shadow -> fg/bg for pixmaps in secondary areas */
  328. /* secondary select color -> backgrounds of editable text areas */
  329. /* secondary foreground -> fill color on toggle indicators */
  330. /* Get the primary colors to be used later */
  331. n = 0;
  332. XtSetArg(args[n], XmNbackground, &bg); n++;
  333. XtGetValues(style.mainWindow, args, n);
  334. XmGetColors (style.screen, style.colormap, bg,
  335. NULL,
  336. &style.primTSCol,
  337. &style.primBSCol,
  338. NULL);
  339. /* Get the secondary colors to be used later */
  340. n = 0;
  341. XtSetArg(args[n], XmNbackground, &style.secBgCol); n++;
  342. XtGetValues(exitBtn, args, n);
  343. XmGetColors (style.screen, style.colormap, style.secBgCol,
  344. &style.tgSelectColor,
  345. &style.secTSCol,
  346. &style.secBSCol,
  347. &style.secSelectColor);
  348. if ((style.secTSCol == style.secBSCol) || /* B_W or shadowPixmaps==True */
  349. (!style.useMultiColorIcons)) /* multiColorIcons turned off */
  350. {
  351. /* force TS = White, BS = Black */
  352. style.secTSCol = style.primTSCol = WhitePixelOfScreen(style.screen);
  353. style.secBSCol = style.primBSCol = BlackPixelOfScreen(style.screen);
  354. }
  355. XmeGetPixelData(style.screenNum, &colorUse, pixelSet, &a, &i, &p, &s);
  356. n = 0;
  357. if (colorUse == XmCO_BLACK_WHITE)
  358. {
  359. ditherPix = XmGetPixmap (style.screen, "50_foreground",
  360. style.primBSCol,style.primTSCol);
  361. XtSetArg(args[n], XmNbackgroundPixmap, ditherPix); n++;
  362. }
  363. XtSetArg(args[n], XmNallowOverlap, False); n++;
  364. XtSetArg(args[n], XmNadjustLast, False); n++;
  365. XtSetArg(args[n], XmNpacking, XmPACK_TIGHT); n++;
  366. XtSetArg(args[n], XmNspacing, style.horizontalSpacing); n++;
  367. mainRC = XmCreateRowColumn(frame, "mainRC", args, n);
  368. XtManageChild(mainRC);
  369. n = 0;
  370. XtSetArg(args[n], XmNmenuBar, mainMenu); n++;
  371. XtSetArg(args[n], XmNcommandWindow, NULL); n++;
  372. XtSetArg(args[n], XmNworkWindow, frame); n++;
  373. XtSetValues (style.mainWindow, args, n);
  374. ProcessComponentList (shell, mainRC);
  375. }
  376. /*+++++++++++++++++++++++++++++++++++++++
  377. * ProcessComponentList();
  378. *
  379. *+++++++++++++++++++++++++++++++++++++++*/
  380. static void
  381. ProcessComponentList(
  382. Widget parent,
  383. Widget mainRC )
  384. {
  385. int count=0;
  386. int j=0;
  387. int n, n2;
  388. Arg args[MAX_ARGS];
  389. Widget componentWidget;
  390. int s;
  391. char *string;
  392. char *resString, *resString2;
  393. XmString cmp_string;
  394. int helpTag;
  395. char *dtIcon;
  396. int len;
  397. style.workProcs = False;
  398. if (style.xrdb.componentList == NULL) return;
  399. n = 0;
  400. XtSetArg(args[n], XmNalignment, XmALIGNMENT_CENTER); n++;
  401. XtSetArg(args[n], XmNpixmapPosition, XmPIXMAP_TOP); n++;
  402. XtSetArg(args[n], XmNshadowType, XmSHADOW_OUT); n++;
  403. n2 = 3; /* number of preset args for creating Icons */
  404. resString = strdup (style.xrdb.componentList);
  405. resString2 = resString;
  406. len = strlen(resString);
  407. string = strtok(resString, " ");
  408. s = 0;
  409. while (string != NULL)
  410. {
  411. /* check for valid name, duplicate name *** */
  412. /* create Icon in Dtstyle main window */
  413. n = n2;
  414. XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
  415. if (colorUse == XmCO_BLACK_WHITE)
  416. {
  417. XtSetArg(args[n], XmNuseEmbossedText, False); n++;
  418. }
  419. XtSetArg(args[n], XmNpixmapForeground, style.primBSCol); n++;
  420. XtSetArg(args[n], XmNpixmapBackground, style.primTSCol); n++;
  421. if (strcmp(string, COLOR) == 0)
  422. {
  423. cmp_string = CMPSTR(GETMESSAGE(4, 27, "Color"));
  424. helpTag = HELP_COLOR_BUTTON;
  425. dtIcon = _DtGetIconFileName(style.screen, COLOR_ICON, NULL, NULL, 0);
  426. style.workProcs = True;
  427. }
  428. else if (strcmp(string, FONT) == 0)
  429. {
  430. cmp_string = CMPSTR(GETMESSAGE(4, 28, "Font"));
  431. dtIcon = _DtGetIconFileName(style.screen, FONT_ICON, NULL, NULL, 0);
  432. helpTag = HELP_FONT_BUTTON;
  433. }
  434. else if (strcmp(string, BACKDROP) == 0)
  435. {
  436. cmp_string = CMPSTR(GETMESSAGE(4, 29, "Backdrop"));
  437. dtIcon = _DtGetIconFileName(style.screen, BACKDROP_ICON, NULL, NULL, 0);
  438. helpTag = HELP_BACKDROP_BUTTON;
  439. }
  440. else if (strcmp(string, KEYBOARD) == 0)
  441. {
  442. cmp_string = CMPSTR(GETMESSAGE(4, 30, "Keyboard"));
  443. dtIcon = _DtGetIconFileName(style.screen, KEYBOARD_ICON, NULL, NULL, 0);
  444. helpTag = HELP_KEYBOARD_BUTTON;
  445. }
  446. else if (strcmp(string, MOUSE) == 0)
  447. {
  448. cmp_string = CMPSTR(GETMESSAGE(4, 31, "Mouse"));
  449. dtIcon = _DtGetIconFileName(style.screen, MOUSE_ICON, NULL, NULL, 0);
  450. helpTag = HELP_MOUSE_BUTTON;
  451. }
  452. else if (strcmp(string, BEEP) == 0)
  453. {
  454. cmp_string = CMPSTR(GETMESSAGE(4, 32, "Beep"));
  455. dtIcon = _DtGetIconFileName(style.screen, BEEP_ICON, NULL, NULL, 0);
  456. helpTag = HELP_AUDIO_BUTTON;
  457. }
  458. else if (strcmp(string, SCREEN) == 0)
  459. {
  460. cmp_string = CMPSTR(GETMESSAGE(4, 33, "Screen"));
  461. dtIcon = _DtGetIconFileName(style.screen, SCREEN_ICON, NULL, NULL, 0);
  462. helpTag = HELP_SCREEN_BUTTON;
  463. }
  464. else if (strcmp(string, DTWM) == 0)
  465. {
  466. cmp_string = CMPSTR(GETMESSAGE(4, 38, "Window"));
  467. dtIcon = _DtGetIconFileName(style.screen, DTWM_ICON, NULL, NULL, 0);
  468. helpTag = HELP_DTWM_BUTTON;
  469. }
  470. else if (strcmp(string, STARTUP) == 0)
  471. {
  472. cmp_string = CMPSTR(GETMESSAGE(4, 35, "Startup"));
  473. dtIcon = _DtGetIconFileName(style.screen, STARTUP_ICON, NULL, NULL, 0);
  474. helpTag = HELP_STARTUP_BUTTON;
  475. }
  476. else if (strcmp(string, I18N) == 0)
  477. {
  478. cmp_string = CMPSTR(GETMESSAGE(4, 34, "Intl'"));
  479. dtIcon = _DtGetIconFileName(style.screen, I18N_ICON, NULL, NULL, 0);
  480. helpTag = HELP_I18N_BUTTON;
  481. }
  482. else
  483. {
  484. s += strlen(string) +1;
  485. if (resString+s >= resString2 + len)
  486. string = NULL;
  487. else
  488. string = strtok(resString+s, " ");
  489. continue;
  490. }
  491. XtSetArg(args[n], XmNimageName, dtIcon); n++;
  492. XtSetArg(args[n], XmNstring, cmp_string); n++;
  493. componentWidget = _DtCreateControl(mainRC, string, args, n);
  494. XtManageChild (componentWidget);
  495. XtAddCallback(componentWidget, XmNcallback, activateCB, string);
  496. XtAddCallback(componentWidget, XmNhelpCallback,
  497. (XtCallbackProc)HelpRequestCB, (XtPointer) (intptr_t) helpTag);
  498. XmStringFree(cmp_string);
  499. XtFree(dtIcon);
  500. s += strlen(string) +1;
  501. if (resString+s >= resString2 + len)
  502. string = NULL;
  503. else
  504. string = strtok(resString+s, " ");
  505. } /* while */
  506. }
  507. /*+++++++++++++++++++++++++++++++++++++++*/
  508. /* cancel all the dialogs (for exit) */
  509. /*+++++++++++++++++++++++++++++++++++++++*/
  510. void
  511. callCancels( void )
  512. {
  513. DtDialogBoxCallbackStruct CancelBut;
  514. char dialogStates[60];
  515. static Boolean calledAlready = False;
  516. if (!calledAlready) {
  517. dialogStates[0] = '\0';
  518. if(style.colorDialog != NULL && XtIsManaged(style.colorDialog)) {
  519. CancelBut.button_position = CANCEL_BUTTON;
  520. XtCallCallbacks(style.colorDialog, XmNcallback, &CancelBut);
  521. }
  522. if(style.fontDialog != NULL && XtIsManaged(style.fontDialog)) {
  523. CancelBut.button_position = CANCEL_BUTTON;
  524. XtCallCallbacks(style.fontDialog, XmNcallback, &CancelBut);
  525. }
  526. if(style.audioDialog != NULL && XtIsManaged(style.audioDialog)) {
  527. CancelBut.button_position = CANCEL_BUTTON;
  528. XtCallCallbacks(style.audioDialog, XmNcallback, &CancelBut);
  529. }
  530. if(style.kbdDialog != NULL && XtIsManaged(style.kbdDialog)) {
  531. CancelBut.button_position = CANCEL_BUTTON;
  532. XtCallCallbacks(style.kbdDialog, XmNcallback, &CancelBut);
  533. }
  534. if(style.mouseDialog != NULL && XtIsManaged(style.mouseDialog)) {
  535. CancelBut.button_position = CANCEL_BUTTON;
  536. XtCallCallbacks(style.mouseDialog, XmNcallback, &CancelBut);
  537. }
  538. if(style.screenDialog != NULL && XtIsManaged(style.screenDialog)) {
  539. CancelBut.button_position = CANCEL_BUTTON;
  540. XtCallCallbacks(style.screenDialog, XmNcallback, &CancelBut);
  541. }
  542. if(style.startupDialog != NULL && XtIsManaged(style.startupDialog)) {
  543. CancelBut.button_position = CANCEL_BUTTON;
  544. XtCallCallbacks(style.startupDialog, XmNcallback, &CancelBut);
  545. }
  546. if (dialogStates[0])
  547. _DtAddToResource(style.display, dialogStates);
  548. calledAlready = True;
  549. }
  550. }
  551. /*+++++++++++++++++++++++++++++++++++++++*/
  552. /* Menu CallBacks */
  553. /*+++++++++++++++++++++++++++++++++++++++*/
  554. void
  555. activateCB_exitBtn(
  556. Widget w,
  557. XtPointer client_data,
  558. XtPointer call_data )
  559. {
  560. /*callCancels() remembers whether its been called so it won't get called*/
  561. /*twice on logout.*/
  562. callCancels();
  563. XSync(style.display, 0);
  564. exit(0);
  565. }
  566. /*+++++++++++++++++++++++++++++++++++++++*/
  567. /* PushButton CallBacks */
  568. /*+++++++++++++++++++++++++++++++++++++++*/
  569. /*+++++++++++++++++++++++++++++++++++++++*/
  570. /* activateCB */
  571. /*+++++++++++++++++++++++++++++++++++++++*/
  572. static void
  573. activateCB(
  574. Widget w,
  575. XtPointer client_data,
  576. XtPointer call_data )
  577. {
  578. DtControlCallbackStruct *cbs =
  579. (DtControlCallbackStruct *) call_data;
  580. char *cd;
  581. cd = (char *) client_data;
  582. /* if any other event besides an activate
  583. event invokes this callback, don't invoke
  584. any dialogs. Just ignore the event.
  585. */
  586. if (cbs->reason != XmCR_ACTIVATE) return;
  587. if (strcmp(cd, COLOR) == 0)
  588. Customize(style.shell);
  589. else if (strcmp(cd, FONT) == 0)
  590. popup_fontBB(style.shell);
  591. else if (strcmp(cd, BACKDROP) == 0)
  592. BackdropDialog (style.shell);
  593. else if (strcmp(cd, KEYBOARD) == 0)
  594. popup_keyboardBB(style.shell);
  595. else if (strcmp(cd, MOUSE) == 0)
  596. popup_mouseBB(style.shell);
  597. else if (strcmp(cd, BEEP) == 0)
  598. popup_audioBB(style.shell);
  599. else if (strcmp(cd, SCREEN) == 0)
  600. popup_screenBB(style.shell);
  601. else if (strcmp(cd, DTWM) == 0)
  602. popup_dtwmBB(style.shell);
  603. else if (strcmp(cd, STARTUP) == 0)
  604. popup_startupBB(style.shell);
  605. else if (strcmp(cd, I18N) == 0)
  606. popup_i18nBB(style.shell);
  607. }
  608. /************************************************************************
  609. * restoreMain()
  610. *
  611. * restore any state information saved with saveMain.
  612. * This is called from restoreSession with the application
  613. * shell and the special xrm database retrieved for restore.
  614. ************************************************************************/
  615. void
  616. restoreMain(
  617. Widget shell,
  618. XrmDatabase db )
  619. {
  620. XrmName xrm_name[5];
  621. XrmRepresentation rep_type;
  622. XrmValue value;
  623. xrm_name [0] = XrmStringToQuark ("mainWindow");
  624. xrm_name [1] = XrmStringToQuark ("ismapped");
  625. xrm_name [2] = 0;
  626. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
  627. /* Are we supposed to be mapped? */
  628. if (strcmp(value.addr, "True") == 0) {
  629. save.poscnt = 0;
  630. /* get x position */
  631. xrm_name [1] = XrmStringToQuark ("x");
  632. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
  633. XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
  634. save.poscnt++;
  635. }
  636. /* get y position */
  637. xrm_name [1] = XrmStringToQuark ("y");
  638. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
  639. XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr));
  640. save.poscnt++;
  641. }
  642. save.restoreFlag = True;
  643. init_mainWindow(shell);
  644. }
  645. }
  646. else
  647. _DtSimpleError (progName, DtWarning, NULL, ((char *)GETMESSAGE(4,36,
  648. "No Dtstyle restore information available for current session")), NULL);
  649. }
  650. /************************************************************************
  651. * saveMain()
  652. *
  653. * This routine will write out to the passed file descriptor any state
  654. * information this dialog needs. It is called from saveSessionCB with the
  655. * file already opened.
  656. * All information is saved in xrm format. There is no restriction
  657. * on what can be saved. It doesn't have to be defined or be part of any
  658. * widget or Xt definition. Just name and save it here and recover it in
  659. * restoreMain. The suggested minimum is whether you are mapped, and your
  660. * location.
  661. ************************************************************************/
  662. void
  663. saveMain(
  664. int fd )
  665. {
  666. Position x,y;
  667. char bufr[1024]; /* size=[1024], make bigger if needed */
  668. if (style.mainWindow != NULL) {
  669. if (XtIsRealized(style.mainWindow))
  670. {
  671. sprintf(bufr, "*mainWindow.ismapped: True\n");
  672. WRITE_STR2FD(fd, bufr);
  673. }
  674. /* Get and write out the geometry info for our Window */
  675. x = XtX(XtParent(style.mainWindow));
  676. y = XtY(XtParent(style.mainWindow));
  677. snprintf(bufr, sizeof(bufr), "*mainWindow.x: %d\n", x);
  678. WRITE_STR2FD(fd, bufr);
  679. snprintf(bufr, sizeof(bufr), "*mainWindow.y: %d\n", y);
  680. WRITE_STR2FD(fd, bufr);
  681. }
  682. }