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 libraries 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>
69 #include <Xm/XmPrivate.h> /* _XmGetActiveTopLevelMenu */
72 #include "MultiView.h"
75 /******** Static Function Declarations ********/
77 extern void _DtGlobalUpdateMenuItemState(
81 unsigned int * globalMenuStates) ;
82 extern void _DtGlobalSetMenuSensitivity(
84 XtPointer client_data,
85 XtPointer call_data) ;
86 extern void _DtGlobalRestoreMenuSensitivity(
88 XtPointer client_data,
89 XtPointer call_data) ;
90 static Widget CreateMenuBtn(
96 /******** End Static Function Declarations ********/
98 extern Widget * findBtn;
99 extern Widget * change_directoryBtn;
100 extern Widget * preferencesBtn;
101 extern Widget * defaultEnvBtn;
102 extern Widget * filterBtn;
108 XtCallbackProc helpCallback,
110 Boolean createSharedComponents,
112 int numMenuComponents,
113 void (*getMenuDataProc)(),
114 void (*setMenuSensitivity)(),
115 void (*restoreMenuSensitivity)() )
122 Widget lastCascadeBtn = NULL;
123 Widget lastMenuPane = NULL;
124 char lastMenuPaneType = MENU_PANE;
125 Boolean firstMenuPane = True;
127 XmString labelString;
128 int pulldownIndex = 1;
129 int menuPaneIndex = 1;
130 int menuBtnIndex = 1;
132 /* Use our own menu control functions, if none specified */
133 if (setMenuSensitivity == NULL)
134 setMenuSensitivity = _DtGlobalSetMenuSensitivity;
135 if (restoreMenuSensitivity == NULL)
136 restoreMenuSensitivity = _DtGlobalRestoreMenuSensitivity;
138 /* Create the pulldown menu */
140 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
141 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
142 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
143 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
144 menubar = XmCreateMenuBar(parent, menuBarName, args, n);
145 XtManageChild(menubar);
147 XtAddCallback(menubar, XmNhelpCallback, helpCallback, helpData);
149 for (i = 0; i < numMenuComponents; i++)
153 switch (menuDesc[i].type)
155 case MENU_PULLDOWN_BUTTON:
157 labelString = XmStringCreateLocalized(menuDesc[i].label);
158 XtSetArg(args[n], XmNlabelString, labelString); n++;
159 if (menuDesc[i].mnemonic)
161 XtSetArg(args[n], XmNmnemonic, menuDesc[i].mnemonic[0]); n++;
163 XtSetArg(args[n], XmNmarginWidth, 6); n++;
164 child = XmCreateCascadeButtonGadget(menubar, menuDesc[i].name,
166 if (menuDesc[i].helpCallback)
168 XtAddCallback(child, XmNhelpCallback,
169 menuDesc[i].helpCallback, menuDesc[i].helpData);
171 if (menuDesc[i].isHelpBtn)
173 XtSetArg(args[0], XmNmenuHelpWidget, child);
174 XtSetValues(menubar, args, 1);
176 XtManageChild(child);
177 XmStringFree(labelString);
178 lastCascadeBtn = menuDesc[i].widget = child;
183 case SHARED_MENU_PANE:
186 if (createSharedComponents || (menuDesc[i].type == MENU_PANE))
188 child = XmCreatePulldownMenu(menubar, menuDesc[i].name, NULL, 0);
192 XtAddCallback(XtParent(child), XmNpopupCallback,
194 (XtPointer)getMenuDataProc);
195 XtAddCallback(XtParent(child), XmNpopdownCallback,
196 restoreMenuSensitivity,
197 (XtPointer)getMenuDataProc);
198 firstMenuPane = False;
201 if (menuDesc[i].helpCallback)
203 XtAddCallback(child, XmNhelpCallback,
204 menuDesc[i].helpCallback, menuDesc[i].helpData);
207 menuDesc[i].widget = child;
210 lastMenuPane = menuDesc[i].widget;
211 lastMenuPaneType = menuDesc[i].type;
212 XtSetArg(args[0], XmNsubMenuId, lastMenuPane);
213 XtSetValues(lastCascadeBtn, args, 1);
219 case MENU_TOGGLE_BUTTON:
222 /* Need to always make btns for non-shared menupanes */
223 if ((createSharedComponents) || (lastMenuPaneType == MENU_PANE))
225 child = CreateMenuBtn (lastMenuPane,
226 (menuDesc[i].type == MENU_BUTTON),
227 menuDesc + i, menuBtnIndex);
228 XtManageChild(child);
229 menuDesc[i].widget = child;
237 /* Need to always make components for non-shared menupanes */
238 if ((createSharedComponents) || (lastMenuPaneType == MENU_PANE))
240 child = XmCreateSeparatorGadget(lastMenuPane, menuDesc[i].name,
242 XtManageChild(child);
243 menuDesc[i].widget = child;
258 _DtGlobalSetMenuSensitivity(
260 XtPointer client_data,
261 XtPointer call_data )
266 XmMenuShellWidget mshell = (XmMenuShellWidget) w;
267 void (*getMenuData)() = (void(*)())client_data;
268 XtPointer mainRecord;
271 unsigned int * globalMenuStates;
272 unsigned int * viewMenuStates;
275 _XmGetActiveTopLevelMenu(mshell->composite.children[0], &mbar);
276 (*getMenuData)(mbar, &mainRecord, &menuDesc, &menuItemCount,
277 &globalMenuStates, &viewMenuStates);
278 XtSetArg(menuPaneArgs[0], XmNuserData, mainRecord);
280 for (i = 0; i < menuItemCount; i++)
282 switch (menuDesc[i].type)
284 case SHARED_MENU_PANE:
287 /* Need to do this to get help working */
288 XtSetValues(menuDesc[i].widget, menuPaneArgs, 1);
294 if ((menuDesc[i].maskBit) &&
295 ((*globalMenuStates & menuDesc[i].maskBit) !=
296 (*viewMenuStates & menuDesc[i].maskBit)))
298 _DtGlobalUpdateMenuItemState(menuDesc[i].widget,
300 *viewMenuStates & menuDesc[i].maskBit,
312 _DtGlobalRestoreMenuSensitivity(
314 XtPointer client_data,
315 XtPointer call_data )
319 XmMenuShellWidget mshell = (XmMenuShellWidget) w;
320 void (*getMenuData)() = (void (*)())client_data;
321 XtPointer mainRecord;
324 unsigned int * globalMenuStates;
325 unsigned int * viewMenuStates;
328 _XmGetActiveTopLevelMenu(mshell->composite.children[0], &mbar);
329 (*getMenuData)(mbar, &mainRecord, &menuDesc, &menuItemCount,
330 &globalMenuStates, &viewMenuStates);
332 for (i = 0; i < menuItemCount; i++)
334 if (menuDesc[i].type == MENU_BUTTON)
336 if ((menuDesc[i].maskBit) &&
337 ((*globalMenuStates & menuDesc[i].maskBit) == 0))
339 _DtGlobalUpdateMenuItemState(menuDesc[i].widget,
350 _DtGlobalUpdateMenuItemState(
354 unsigned int * globalMenuStates )
359 XtSetSensitive(btn, True);
360 *globalMenuStates |= mask;
364 if(btn != *findBtn &&
365 btn != *change_directoryBtn &&
366 btn != *preferencesBtn &&
367 btn != *defaultEnvBtn &&
370 XtSetSensitive(btn, False);
371 *globalMenuStates &= ~mask;
380 Boolean isPushButton,
387 XmString labelString;
390 labelString = XmStringCreateLocalized(menuDesc->label);
391 XtSetArg(args[n], XmNlabelString, labelString); n++;
392 XtSetArg(args[n], XmNmnemonic, menuDesc->mnemonic[0]); n++;
394 child = XmCreatePushButtonGadget(parent, menuDesc->name, args, n);
397 XtSetArg(args[n], XmNvisibleWhenOff,TRUE);n++;
398 child = XmCreateToggleButtonGadget(parent, menuDesc->name, args, n);
400 if (menuDesc->helpCallback)
402 XtAddCallback(child, XmNhelpCallback, menuDesc->helpCallback,
405 if (menuDesc->activateCallback)
409 XtAddCallback(child, XmNactivateCallback, menuDesc->activateCallback,
410 menuDesc->activateData);
414 XtAddCallback(child, XmNvalueChangedCallback,
415 menuDesc->activateCallback, menuDesc->activateData);
418 XmStringFree(labelString);