123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $XConsortium: MultiView.c /main/5 1996/10/15 10:08:30 mustafa $ */
- /************************************<+>*************************************
- ****************************************************************************
- *
- * FILE: MultiView.c
- *
- * COMPONENT_NAME: Desktop File Manager (dtfile)
- *
- * Description: Contains the shared code for managing multiple toplevel
- * main application window.
- *
- * FUNCTIONS: CreateMenuBtn
- * _DtCreateMenuSystem
- * _DtGlobalRestoreMenuSensitivity
- * _DtGlobalSetMenuSensitivity
- * _DtGlobalUpdateMenuItemState
- *
- * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
- * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
- * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
- * (c) Copyright 1993, 1994, 1995 Novell, Inc.
- *
- ****************************************************************************
- ************************************<+>*************************************/
-
- #include <stdio.h>
- #include <signal.h>
- #include <pwd.h>
- #include <time.h>
- #include <Xm/XmP.h>
- #include <Xm/CascadeBG.h>
- #include <Xm/PushBG.h>
- #include <Xm/RowColumn.h>
- #include <Xm/SeparatoG.h>
- #include <Xm/ToggleBG.h>
- #include <Xm/MenuShellP.h>
- #include <X11/ShellP.h>
- #include <Dt/DtP.h>
- #include <Dt/DtNlUtils.h>
- #include <Dt/Connect.h>
- #include <Xm/XmPrivate.h> /* _XmGetActiveTopLevelMenu */
- #include "Encaps.h"
- #include "MultiView.h"
- /******** Static Function Declarations ********/
- extern void _DtGlobalUpdateMenuItemState(
- Widget btn,
- unsigned int mask,
- unsigned int on,
- unsigned int * globalMenuStates) ;
- extern void _DtGlobalSetMenuSensitivity(
- Widget w,
- XtPointer client_data,
- XtPointer call_data) ;
- extern void _DtGlobalRestoreMenuSensitivity(
- Widget w,
- XtPointer client_data,
- XtPointer call_data) ;
- static Widget CreateMenuBtn(
- Widget parent,
- Boolean isPushButton,
- MenuDesc * menuDesc,
- int btnIndex) ;
- /******** End Static Function Declarations ********/
- extern Widget * findBtn;
- extern Widget * change_directoryBtn;
- extern Widget * preferencesBtn;
- extern Widget * defaultEnvBtn;
- extern Widget * filterBtn;
- Widget
- _DtCreateMenuSystem(
- Widget parent,
- char * menuBarName,
- XtCallbackProc helpCallback,
- XtPointer helpData,
- Boolean createSharedComponents,
- MenuDesc * menuDesc,
- int numMenuComponents,
- void (*getMenuDataProc)(),
- void (*setMenuSensitivity)(),
- void (*restoreMenuSensitivity)() )
- {
- int n;
- int i;
- Arg args[20];
- Widget menubar;
- Widget lastCascadeBtn = NULL;
- Widget lastMenuPane = NULL;
- char lastMenuPaneType = MENU_PANE;
- Boolean firstMenuPane = True;
- Widget child;
- XmString labelString;
- int pulldownIndex = 1;
- int menuPaneIndex = 1;
- int menuBtnIndex = 1;
- /* Use our own menu control functions, if none specified */
- if (setMenuSensitivity == NULL)
- setMenuSensitivity = _DtGlobalSetMenuSensitivity;
- if (restoreMenuSensitivity == NULL)
- restoreMenuSensitivity = _DtGlobalRestoreMenuSensitivity;
- /* Create the pulldown menu */
- n = 0;
- XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
- XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
- XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
- menubar = XmCreateMenuBar(parent, menuBarName, args, n);
- XtManageChild(menubar);
- if (helpCallback)
- XtAddCallback(menubar, XmNhelpCallback, helpCallback, helpData);
- for (i = 0; i < numMenuComponents; i++)
- {
- n = 0;
- switch (menuDesc[i].type)
- {
- case MENU_PULLDOWN_BUTTON:
- {
- labelString = XmStringCreateLocalized(menuDesc[i].label);
- XtSetArg(args[n], XmNlabelString, labelString); n++;
- if (menuDesc[i].mnemonic)
- {
- XtSetArg(args[n], XmNmnemonic, menuDesc[i].mnemonic[0]); n++;
- }
- XtSetArg(args[n], XmNmarginWidth, 6); n++;
- child = XmCreateCascadeButtonGadget(menubar, menuDesc[i].name,
- args, n);
- if (menuDesc[i].helpCallback)
- {
- XtAddCallback(child, XmNhelpCallback,
- menuDesc[i].helpCallback, menuDesc[i].helpData);
- }
- if (menuDesc[i].isHelpBtn)
- {
- XtSetArg(args[0], XmNmenuHelpWidget, child);
- XtSetValues(menubar, args, 1);
- }
- XtManageChild(child);
- XmStringFree(labelString);
- lastCascadeBtn = menuDesc[i].widget = child;
- pulldownIndex++;
- break;
- }
- case SHARED_MENU_PANE:
- case MENU_PANE:
- {
- if (createSharedComponents || (menuDesc[i].type == MENU_PANE))
- {
- child = XmCreatePulldownMenu(menubar, menuDesc[i].name, NULL, 0);
- if (firstMenuPane)
- {
- XtAddCallback(XtParent(child), XmNpopupCallback,
- setMenuSensitivity,
- (XtPointer)getMenuDataProc);
- XtAddCallback(XtParent(child), XmNpopdownCallback,
- restoreMenuSensitivity,
- (XtPointer)getMenuDataProc);
- firstMenuPane = False;
- }
- if (menuDesc[i].helpCallback)
- {
- XtAddCallback(child, XmNhelpCallback,
- menuDesc[i].helpCallback, menuDesc[i].helpData);
- }
- menuDesc[i].widget = child;
- }
- lastMenuPane = menuDesc[i].widget;
- lastMenuPaneType = menuDesc[i].type;
- XtSetArg(args[0], XmNsubMenuId, lastMenuPane);
- XtSetValues(lastCascadeBtn, args, 1);
- menuBtnIndex = 1;
- menuPaneIndex++;
- break;
- }
- case MENU_TOGGLE_BUTTON:
- case MENU_BUTTON:
- {
- /* Need to always make btns for non-shared menupanes */
- if ((createSharedComponents) || (lastMenuPaneType == MENU_PANE))
- {
- child = CreateMenuBtn (lastMenuPane,
- (menuDesc[i].type == MENU_BUTTON),
- menuDesc + i, menuBtnIndex);
- XtManageChild(child);
- menuDesc[i].widget = child;
- }
- menuBtnIndex++;
- break;
- }
- case MENU_SEPARATOR:
- {
- /* Need to always make components for non-shared menupanes */
- if ((createSharedComponents) || (lastMenuPaneType == MENU_PANE))
- {
- child = XmCreateSeparatorGadget(lastMenuPane, menuDesc[i].name,
- NULL, 0);
- XtManageChild(child);
- menuDesc[i].widget = child;
- }
- break;
- }
- }
- }
- return(menubar);
- }
- /* ARGSUSED */
- void
- _DtGlobalSetMenuSensitivity(
- Widget w,
- XtPointer client_data,
- XtPointer call_data )
- {
- Arg menuPaneArgs[1];
- Widget mbar;
- XmMenuShellWidget mshell = (XmMenuShellWidget) w;
- void (*getMenuData)() = (void(*)())client_data;
- XtPointer mainRecord;
- MenuDesc * menuDesc;
- int menuItemCount;
- unsigned int * globalMenuStates;
- unsigned int * viewMenuStates;
- int i;
- _XmGetActiveTopLevelMenu(mshell->composite.children[0], &mbar);
- (*getMenuData)(mbar, &mainRecord, &menuDesc, &menuItemCount,
- &globalMenuStates, &viewMenuStates);
- XtSetArg(menuPaneArgs[0], XmNuserData, mainRecord);
- for (i = 0; i < menuItemCount; i++)
- {
- switch (menuDesc[i].type)
- {
- case SHARED_MENU_PANE:
- case MENU_PANE:
- {
- /* Need to do this to get help working */
- XtSetValues(menuDesc[i].widget, menuPaneArgs, 1);
- break;
- }
- case MENU_BUTTON:
- {
- if ((menuDesc[i].maskBit) &&
- ((*globalMenuStates & menuDesc[i].maskBit) !=
- (*viewMenuStates & menuDesc[i].maskBit)))
- {
- _DtGlobalUpdateMenuItemState(menuDesc[i].widget,
- menuDesc[i].maskBit,
- *viewMenuStates & menuDesc[i].maskBit,
- globalMenuStates);
- }
- break;
- }
- }
- }
- }
- /* ARGSUSED */
- void
- _DtGlobalRestoreMenuSensitivity(
- Widget w,
- XtPointer client_data,
- XtPointer call_data )
- {
- Widget mbar;
- XmMenuShellWidget mshell = (XmMenuShellWidget) w;
- void (*getMenuData)() = (void (*)())client_data;
- XtPointer mainRecord;
- MenuDesc * menuDesc;
- int menuItemCount;
- unsigned int * globalMenuStates;
- unsigned int * viewMenuStates;
- int i;
- _XmGetActiveTopLevelMenu(mshell->composite.children[0], &mbar);
- (*getMenuData)(mbar, &mainRecord, &menuDesc, &menuItemCount,
- &globalMenuStates, &viewMenuStates);
- for (i = 0; i < menuItemCount; i++)
- {
- if (menuDesc[i].type == MENU_BUTTON)
- {
- if ((menuDesc[i].maskBit) &&
- ((*globalMenuStates & menuDesc[i].maskBit) == 0))
- {
- _DtGlobalUpdateMenuItemState(menuDesc[i].widget,
- menuDesc[i].maskBit,
- True,
- globalMenuStates);
- }
- }
- }
- }
- void
- _DtGlobalUpdateMenuItemState(
- Widget btn,
- unsigned int mask,
- unsigned int on,
- unsigned int * globalMenuStates )
- {
- if (on != 0)
- {
- XtSetSensitive(btn, True);
- *globalMenuStates |= mask;
- }
- else
- {
- if(btn != *findBtn &&
- btn != *change_directoryBtn &&
- btn != *preferencesBtn &&
- btn != *defaultEnvBtn &&
- btn != *filterBtn )
- {
- XtSetSensitive(btn, False);
- *globalMenuStates &= ~mask;
- }
- }
- }
- static Widget
- CreateMenuBtn (
- Widget parent,
- Boolean isPushButton,
- MenuDesc * menuDesc,
- int btnIndex )
- {
- int n;
- Arg args[10];
- Widget child;
- XmString labelString;
- n = 0;
- labelString = XmStringCreateLocalized(menuDesc->label);
- XtSetArg(args[n], XmNlabelString, labelString); n++;
- XtSetArg(args[n], XmNmnemonic, menuDesc->mnemonic[0]); n++;
- if (isPushButton)
- child = XmCreatePushButtonGadget(parent, menuDesc->name, args, n);
- else
- {
- XtSetArg(args[n], XmNvisibleWhenOff,TRUE);n++;
- child = XmCreateToggleButtonGadget(parent, menuDesc->name, args, n);
- }
- if (menuDesc->helpCallback)
- {
- XtAddCallback(child, XmNhelpCallback, menuDesc->helpCallback,
- menuDesc->helpData);
- }
- if (menuDesc->activateCallback)
- {
- if (isPushButton)
- {
- XtAddCallback(child, XmNactivateCallback, menuDesc->activateCallback,
- menuDesc->activateData);
- }
- else
- {
- XtAddCallback(child, XmNvalueChangedCallback,
- menuDesc->activateCallback, menuDesc->activateData);
- }
- }
- XmStringFree(labelString);
- return (child);
- }
|