2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: MultiView.c /main/5 1996/10/15 10:08:30 mustafa $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 * COMPONENT_NAME: Desktop File Manager (dtfile)
31 * Description: Contains the shared code for managing multiple toplevel
32 * main application window.
34 * FUNCTIONS: CreateMenuBtn
36 * _DtGlobalRestoreMenuSensitivity
37 * _DtGlobalSetMenuSensitivity
38 * _DtGlobalUpdateMenuItemState
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.
45 ****************************************************************************
46 ************************************<+>*************************************/
56 #include <Xm/CascadeBG.h>
57 #include <Xm/PushBG.h>
58 #include <Xm/RowColumn.h>
59 #include <Xm/SeparatoG.h>
60 #include <Xm/ToggleBG.h>
61 #include <Xm/MenuShellP.h>
63 #include <X11/ShellP.h>
66 #include <Dt/DtNlUtils.h>
67 #include <Dt/Connect.h>
70 #include "MultiView.h"
73 /******** Static Function Declarations ********/
75 extern void _DtGlobalUpdateMenuItemState(
79 unsigned int * globalMenuStates) ;
80 extern void _DtGlobalSetMenuSensitivity(
82 XtPointer client_data,
83 XtPointer call_data) ;
84 extern void _DtGlobalRestoreMenuSensitivity(
86 XtPointer client_data,
87 XtPointer call_data) ;
88 static Widget CreateMenuBtn(
94 /******** End Static Function Declarations ********/
96 extern Widget * findBtn;
97 extern Widget * change_directoryBtn;
98 extern Widget * preferencesBtn;
99 extern Widget * defaultEnvBtn;
100 extern Widget * filterBtn;
106 XtCallbackProc helpCallback,
108 Boolean createSharedComponents,
110 int numMenuComponents,
111 void (*getMenuDataProc)(),
112 void (*setMenuSensitivity)(),
113 void (*restoreMenuSensitivity)() )
120 Widget lastCascadeBtn = NULL;
121 Widget lastMenuPane = NULL;
122 char lastMenuPaneType = MENU_PANE;
123 Boolean firstMenuPane = True;
125 XmString labelString;
126 int pulldownIndex = 1;
127 int menuPaneIndex = 1;
128 int menuBtnIndex = 1;
130 /* Use our own menu control functions, if none specified */
131 if (setMenuSensitivity == NULL)
132 setMenuSensitivity = _DtGlobalSetMenuSensitivity;
133 if (restoreMenuSensitivity == NULL)
134 restoreMenuSensitivity = _DtGlobalRestoreMenuSensitivity;
136 /* Create the pulldown menu */
138 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
139 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
140 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
141 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
142 menubar = XmCreateMenuBar(parent, menuBarName, args, n);
143 XtManageChild(menubar);
145 XtAddCallback(menubar, XmNhelpCallback, helpCallback, helpData);
147 for (i = 0; i < numMenuComponents; i++)
151 switch (menuDesc[i].type)
153 case MENU_PULLDOWN_BUTTON:
155 labelString = XmStringCreateLocalized(menuDesc[i].label);
156 XtSetArg(args[n], XmNlabelString, labelString); n++;
157 if (menuDesc[i].mnemonic)
159 XtSetArg(args[n], XmNmnemonic, menuDesc[i].mnemonic[0]); n++;
161 XtSetArg(args[n], XmNmarginWidth, 6); n++;
162 child = XmCreateCascadeButtonGadget(menubar, menuDesc[i].name,
164 if (menuDesc[i].helpCallback)
166 XtAddCallback(child, XmNhelpCallback,
167 menuDesc[i].helpCallback, menuDesc[i].helpData);
169 if (menuDesc[i].isHelpBtn)
171 XtSetArg(args[0], XmNmenuHelpWidget, child);
172 XtSetValues(menubar, args, 1);
174 XtManageChild(child);
175 XmStringFree(labelString);
176 lastCascadeBtn = menuDesc[i].widget = child;
181 case SHARED_MENU_PANE:
184 if (createSharedComponents || (menuDesc[i].type == MENU_PANE))
186 child = XmCreatePulldownMenu(menubar, menuDesc[i].name, NULL, 0);
190 XtAddCallback(XtParent(child), XmNpopupCallback,
192 (XtPointer)getMenuDataProc);
193 XtAddCallback(XtParent(child), XmNpopdownCallback,
194 restoreMenuSensitivity,
195 (XtPointer)getMenuDataProc);
196 firstMenuPane = False;
199 if (menuDesc[i].helpCallback)
201 XtAddCallback(child, XmNhelpCallback,
202 menuDesc[i].helpCallback, menuDesc[i].helpData);
205 menuDesc[i].widget = child;
208 lastMenuPane = menuDesc[i].widget;
209 lastMenuPaneType = menuDesc[i].type;
210 XtSetArg(args[0], XmNsubMenuId, lastMenuPane);
211 XtSetValues(lastCascadeBtn, args, 1);
217 case MENU_TOGGLE_BUTTON:
220 /* Need to always make btns for non-shared menupanes */
221 if ((createSharedComponents) || (lastMenuPaneType == MENU_PANE))
223 child = CreateMenuBtn (lastMenuPane,
224 (menuDesc[i].type == MENU_BUTTON),
225 menuDesc + i, menuBtnIndex);
226 XtManageChild(child);
227 menuDesc[i].widget = child;
235 /* Need to always make components for non-shared menupanes */
236 if ((createSharedComponents) || (lastMenuPaneType == MENU_PANE))
238 child = XmCreateSeparatorGadget(lastMenuPane, menuDesc[i].name,
240 XtManageChild(child);
241 menuDesc[i].widget = child;
256 _DtGlobalSetMenuSensitivity(
258 XtPointer client_data,
259 XtPointer call_data )
264 XmMenuShellWidget mshell = (XmMenuShellWidget) w;
265 void (*getMenuData)() = (void(*)())client_data;
266 XtPointer mainRecord;
269 unsigned int * globalMenuStates;
270 unsigned int * viewMenuStates;
273 _XmGetActiveTopLevelMenu(mshell->composite.children[0], &mbar);
274 (*getMenuData)(mbar, &mainRecord, &menuDesc, &menuItemCount,
275 &globalMenuStates, &viewMenuStates);
276 XtSetArg(menuPaneArgs[0], XmNuserData, mainRecord);
278 for (i = 0; i < menuItemCount; i++)
280 switch (menuDesc[i].type)
282 case SHARED_MENU_PANE:
285 /* Need to do this to get help working */
286 XtSetValues(menuDesc[i].widget, menuPaneArgs, 1);
292 if ((menuDesc[i].maskBit) &&
293 ((*globalMenuStates & menuDesc[i].maskBit) !=
294 (*viewMenuStates & menuDesc[i].maskBit)))
296 _DtGlobalUpdateMenuItemState(menuDesc[i].widget,
298 *viewMenuStates & menuDesc[i].maskBit,
310 _DtGlobalRestoreMenuSensitivity(
312 XtPointer client_data,
313 XtPointer call_data )
317 XmMenuShellWidget mshell = (XmMenuShellWidget) w;
318 void (*getMenuData)() = (void (*)())client_data;
319 XtPointer mainRecord;
322 unsigned int * globalMenuStates;
323 unsigned int * viewMenuStates;
326 _XmGetActiveTopLevelMenu(mshell->composite.children[0], &mbar);
327 (*getMenuData)(mbar, &mainRecord, &menuDesc, &menuItemCount,
328 &globalMenuStates, &viewMenuStates);
330 for (i = 0; i < menuItemCount; i++)
332 if (menuDesc[i].type == MENU_BUTTON)
334 if ((menuDesc[i].maskBit) &&
335 ((*globalMenuStates & menuDesc[i].maskBit) == 0))
337 _DtGlobalUpdateMenuItemState(menuDesc[i].widget,
348 _DtGlobalUpdateMenuItemState(
352 unsigned int * globalMenuStates )
357 XtSetSensitive(btn, True);
358 *globalMenuStates |= mask;
362 if(btn != *findBtn &&
363 btn != *change_directoryBtn &&
364 btn != *preferencesBtn &&
365 btn != *defaultEnvBtn &&
368 XtSetSensitive(btn, False);
369 *globalMenuStates &= ~mask;
378 Boolean isPushButton,
385 XmString labelString;
388 labelString = XmStringCreateLocalized(menuDesc->label);
389 XtSetArg(args[n], XmNlabelString, labelString); n++;
390 XtSetArg(args[n], XmNmnemonic, menuDesc->mnemonic[0]); n++;
392 child = XmCreatePushButtonGadget(parent, menuDesc->name, args, n);
395 XtSetArg(args[n], XmNvisibleWhenOff,TRUE);n++;
396 child = XmCreateToggleButtonGadget(parent, menuDesc->name, args, n);
398 if (menuDesc->helpCallback)
400 XtAddCallback(child, XmNhelpCallback, menuDesc->helpCallback,
403 if (menuDesc->activateCallback)
407 XtAddCallback(child, XmNactivateCallback, menuDesc->activateCallback,
408 menuDesc->activateData);
412 XtAddCallback(child, XmNvalueChangedCallback,
413 menuDesc->activateCallback, menuDesc->activateData);
416 XmStringFree(labelString);