MultiView.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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: MultiView.c /main/5 1996/10/15 10:08:30 mustafa $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. *
  27. * FILE: MultiView.c
  28. *
  29. * COMPONENT_NAME: Desktop File Manager (dtfile)
  30. *
  31. * Description: Contains the shared code for managing multiple toplevel
  32. * main application window.
  33. *
  34. * FUNCTIONS: CreateMenuBtn
  35. * _DtCreateMenuSystem
  36. * _DtGlobalRestoreMenuSensitivity
  37. * _DtGlobalSetMenuSensitivity
  38. * _DtGlobalUpdateMenuItemState
  39. *
  40. * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
  41. * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
  42. * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
  43. * (c) Copyright 1993, 1994, 1995 Novell, Inc.
  44. *
  45. ****************************************************************************
  46. ************************************<+>*************************************/
  47. #include <stdio.h>
  48. #include <signal.h>
  49. #include <pwd.h>
  50. #include <time.h>
  51. #include <Xm/XmP.h>
  52. #include <Xm/CascadeBG.h>
  53. #include <Xm/PushBG.h>
  54. #include <Xm/RowColumn.h>
  55. #include <Xm/SeparatoG.h>
  56. #include <Xm/ToggleBG.h>
  57. #include <Xm/MenuShellP.h>
  58. #include <X11/ShellP.h>
  59. #include <Dt/DtP.h>
  60. #include <Dt/DtNlUtils.h>
  61. #include <Dt/Connect.h>
  62. #include <Xm/XmPrivate.h> /* _XmGetActiveTopLevelMenu */
  63. #include "Encaps.h"
  64. #include "MultiView.h"
  65. /******** Static Function Declarations ********/
  66. extern void _DtGlobalUpdateMenuItemState(
  67. Widget btn,
  68. unsigned int mask,
  69. unsigned int on,
  70. unsigned int * globalMenuStates) ;
  71. extern void _DtGlobalSetMenuSensitivity(
  72. Widget w,
  73. XtPointer client_data,
  74. XtPointer call_data) ;
  75. extern void _DtGlobalRestoreMenuSensitivity(
  76. Widget w,
  77. XtPointer client_data,
  78. XtPointer call_data) ;
  79. static Widget CreateMenuBtn(
  80. Widget parent,
  81. Boolean isPushButton,
  82. MenuDesc * menuDesc,
  83. int btnIndex) ;
  84. /******** End Static Function Declarations ********/
  85. extern Widget * findBtn;
  86. extern Widget * change_directoryBtn;
  87. extern Widget * preferencesBtn;
  88. extern Widget * defaultEnvBtn;
  89. extern Widget * filterBtn;
  90. Widget
  91. _DtCreateMenuSystem(
  92. Widget parent,
  93. char * menuBarName,
  94. XtCallbackProc helpCallback,
  95. XtPointer helpData,
  96. Boolean createSharedComponents,
  97. MenuDesc * menuDesc,
  98. int numMenuComponents,
  99. void (*getMenuDataProc)(),
  100. void (*setMenuSensitivity)(),
  101. void (*restoreMenuSensitivity)() )
  102. {
  103. int n;
  104. int i;
  105. Arg args[20];
  106. Widget menubar;
  107. Widget lastCascadeBtn = NULL;
  108. Widget lastMenuPane = NULL;
  109. char lastMenuPaneType = MENU_PANE;
  110. Boolean firstMenuPane = True;
  111. Widget child;
  112. XmString labelString;
  113. int pulldownIndex = 1;
  114. int menuPaneIndex = 1;
  115. int menuBtnIndex = 1;
  116. /* Use our own menu control functions, if none specified */
  117. if (setMenuSensitivity == NULL)
  118. setMenuSensitivity = _DtGlobalSetMenuSensitivity;
  119. if (restoreMenuSensitivity == NULL)
  120. restoreMenuSensitivity = _DtGlobalRestoreMenuSensitivity;
  121. /* Create the pulldown menu */
  122. n = 0;
  123. XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
  124. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  125. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  126. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  127. menubar = XmCreateMenuBar(parent, menuBarName, args, n);
  128. XtManageChild(menubar);
  129. if (helpCallback)
  130. XtAddCallback(menubar, XmNhelpCallback, helpCallback, helpData);
  131. for (i = 0; i < numMenuComponents; i++)
  132. {
  133. n = 0;
  134. switch (menuDesc[i].type)
  135. {
  136. case MENU_PULLDOWN_BUTTON:
  137. {
  138. labelString = XmStringCreateLocalized(menuDesc[i].label);
  139. XtSetArg(args[n], XmNlabelString, labelString); n++;
  140. if (menuDesc[i].mnemonic)
  141. {
  142. XtSetArg(args[n], XmNmnemonic, menuDesc[i].mnemonic[0]); n++;
  143. }
  144. XtSetArg(args[n], XmNmarginWidth, 6); n++;
  145. child = XmCreateCascadeButtonGadget(menubar, menuDesc[i].name,
  146. args, n);
  147. if (menuDesc[i].helpCallback)
  148. {
  149. XtAddCallback(child, XmNhelpCallback,
  150. menuDesc[i].helpCallback, menuDesc[i].helpData);
  151. }
  152. if (menuDesc[i].isHelpBtn)
  153. {
  154. XtSetArg(args[0], XmNmenuHelpWidget, child);
  155. XtSetValues(menubar, args, 1);
  156. }
  157. XtManageChild(child);
  158. XmStringFree(labelString);
  159. lastCascadeBtn = menuDesc[i].widget = child;
  160. pulldownIndex++;
  161. break;
  162. }
  163. case SHARED_MENU_PANE:
  164. case MENU_PANE:
  165. {
  166. if (createSharedComponents || (menuDesc[i].type == MENU_PANE))
  167. {
  168. child = XmCreatePulldownMenu(menubar, menuDesc[i].name, NULL, 0);
  169. if (firstMenuPane)
  170. {
  171. XtAddCallback(XtParent(child), XmNpopupCallback,
  172. setMenuSensitivity,
  173. (XtPointer)getMenuDataProc);
  174. XtAddCallback(XtParent(child), XmNpopdownCallback,
  175. restoreMenuSensitivity,
  176. (XtPointer)getMenuDataProc);
  177. firstMenuPane = False;
  178. }
  179. if (menuDesc[i].helpCallback)
  180. {
  181. XtAddCallback(child, XmNhelpCallback,
  182. menuDesc[i].helpCallback, menuDesc[i].helpData);
  183. }
  184. menuDesc[i].widget = child;
  185. }
  186. lastMenuPane = menuDesc[i].widget;
  187. lastMenuPaneType = menuDesc[i].type;
  188. XtSetArg(args[0], XmNsubMenuId, lastMenuPane);
  189. XtSetValues(lastCascadeBtn, args, 1);
  190. menuBtnIndex = 1;
  191. menuPaneIndex++;
  192. break;
  193. }
  194. case MENU_TOGGLE_BUTTON:
  195. case MENU_BUTTON:
  196. {
  197. /* Need to always make btns for non-shared menupanes */
  198. if ((createSharedComponents) || (lastMenuPaneType == MENU_PANE))
  199. {
  200. child = CreateMenuBtn (lastMenuPane,
  201. (menuDesc[i].type == MENU_BUTTON),
  202. menuDesc + i, menuBtnIndex);
  203. XtManageChild(child);
  204. menuDesc[i].widget = child;
  205. }
  206. menuBtnIndex++;
  207. break;
  208. }
  209. case MENU_SEPARATOR:
  210. {
  211. /* Need to always make components for non-shared menupanes */
  212. if ((createSharedComponents) || (lastMenuPaneType == MENU_PANE))
  213. {
  214. child = XmCreateSeparatorGadget(lastMenuPane, menuDesc[i].name,
  215. NULL, 0);
  216. XtManageChild(child);
  217. menuDesc[i].widget = child;
  218. }
  219. break;
  220. }
  221. }
  222. }
  223. return(menubar);
  224. }
  225. /* ARGSUSED */
  226. void
  227. _DtGlobalSetMenuSensitivity(
  228. Widget w,
  229. XtPointer client_data,
  230. XtPointer call_data )
  231. {
  232. Arg menuPaneArgs[1];
  233. Widget mbar;
  234. XmMenuShellWidget mshell = (XmMenuShellWidget) w;
  235. void (*getMenuData)() = (void(*)())client_data;
  236. XtPointer mainRecord;
  237. MenuDesc * menuDesc;
  238. int menuItemCount;
  239. unsigned int * globalMenuStates;
  240. unsigned int * viewMenuStates;
  241. int i;
  242. _XmGetActiveTopLevelMenu(mshell->composite.children[0], &mbar);
  243. (*getMenuData)(mbar, &mainRecord, &menuDesc, &menuItemCount,
  244. &globalMenuStates, &viewMenuStates);
  245. XtSetArg(menuPaneArgs[0], XmNuserData, mainRecord);
  246. for (i = 0; i < menuItemCount; i++)
  247. {
  248. switch (menuDesc[i].type)
  249. {
  250. case SHARED_MENU_PANE:
  251. case MENU_PANE:
  252. {
  253. /* Need to do this to get help working */
  254. XtSetValues(menuDesc[i].widget, menuPaneArgs, 1);
  255. break;
  256. }
  257. case MENU_BUTTON:
  258. {
  259. if ((menuDesc[i].maskBit) &&
  260. ((*globalMenuStates & menuDesc[i].maskBit) !=
  261. (*viewMenuStates & menuDesc[i].maskBit)))
  262. {
  263. _DtGlobalUpdateMenuItemState(menuDesc[i].widget,
  264. menuDesc[i].maskBit,
  265. *viewMenuStates & menuDesc[i].maskBit,
  266. globalMenuStates);
  267. }
  268. break;
  269. }
  270. }
  271. }
  272. }
  273. /* ARGSUSED */
  274. void
  275. _DtGlobalRestoreMenuSensitivity(
  276. Widget w,
  277. XtPointer client_data,
  278. XtPointer call_data )
  279. {
  280. Widget mbar;
  281. XmMenuShellWidget mshell = (XmMenuShellWidget) w;
  282. void (*getMenuData)() = (void (*)())client_data;
  283. XtPointer mainRecord;
  284. MenuDesc * menuDesc;
  285. int menuItemCount;
  286. unsigned int * globalMenuStates;
  287. unsigned int * viewMenuStates;
  288. int i;
  289. _XmGetActiveTopLevelMenu(mshell->composite.children[0], &mbar);
  290. (*getMenuData)(mbar, &mainRecord, &menuDesc, &menuItemCount,
  291. &globalMenuStates, &viewMenuStates);
  292. for (i = 0; i < menuItemCount; i++)
  293. {
  294. if (menuDesc[i].type == MENU_BUTTON)
  295. {
  296. if ((menuDesc[i].maskBit) &&
  297. ((*globalMenuStates & menuDesc[i].maskBit) == 0))
  298. {
  299. _DtGlobalUpdateMenuItemState(menuDesc[i].widget,
  300. menuDesc[i].maskBit,
  301. True,
  302. globalMenuStates);
  303. }
  304. }
  305. }
  306. }
  307. void
  308. _DtGlobalUpdateMenuItemState(
  309. Widget btn,
  310. unsigned int mask,
  311. unsigned int on,
  312. unsigned int * globalMenuStates )
  313. {
  314. if (on != 0)
  315. {
  316. XtSetSensitive(btn, True);
  317. *globalMenuStates |= mask;
  318. }
  319. else
  320. {
  321. if(btn != *findBtn &&
  322. btn != *change_directoryBtn &&
  323. btn != *preferencesBtn &&
  324. btn != *defaultEnvBtn &&
  325. btn != *filterBtn )
  326. {
  327. XtSetSensitive(btn, False);
  328. *globalMenuStates &= ~mask;
  329. }
  330. }
  331. }
  332. static Widget
  333. CreateMenuBtn (
  334. Widget parent,
  335. Boolean isPushButton,
  336. MenuDesc * menuDesc,
  337. int btnIndex )
  338. {
  339. int n;
  340. Arg args[10];
  341. Widget child;
  342. XmString labelString;
  343. n = 0;
  344. labelString = XmStringCreateLocalized(menuDesc->label);
  345. XtSetArg(args[n], XmNlabelString, labelString); n++;
  346. XtSetArg(args[n], XmNmnemonic, menuDesc->mnemonic[0]); n++;
  347. if (isPushButton)
  348. child = XmCreatePushButtonGadget(parent, menuDesc->name, args, n);
  349. else
  350. {
  351. XtSetArg(args[n], XmNvisibleWhenOff,TRUE);n++;
  352. child = XmCreateToggleButtonGadget(parent, menuDesc->name, args, n);
  353. }
  354. if (menuDesc->helpCallback)
  355. {
  356. XtAddCallback(child, XmNhelpCallback, menuDesc->helpCallback,
  357. menuDesc->helpData);
  358. }
  359. if (menuDesc->activateCallback)
  360. {
  361. if (isPushButton)
  362. {
  363. XtAddCallback(child, XmNactivateCallback, menuDesc->activateCallback,
  364. menuDesc->activateData);
  365. }
  366. else
  367. {
  368. XtAddCallback(child, XmNvalueChangedCallback,
  369. menuDesc->activateCallback, menuDesc->activateData);
  370. }
  371. }
  372. XmStringFree(labelString);
  373. return (child);
  374. }