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: Menu.C /main/3 1995/11/06 09:42:58 rswiston $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
32 #include "MainWindow.h"
34 #include <Xm/RowColumn.h>
36 #include <Xm/Separator.h>
37 #include <Xm/CascadeB.h>
39 Menu::Menu(MotifUI *parent, char *name, char *mnemonic, MenuType menu_type)
40 : MotifUI(parent, name, NULL)
42 CreateMenu(parent->InnerWidget(), name, NULL, mnemonic, menu_type);
45 Menu::Menu(MotifUI *parent, boolean /*has_title*/, char *title,
46 char *name, char *mnemonic, MenuType menu_type)
47 : MotifUI(parent, name, NULL)
49 CreateMenu(parent->InnerWidget(), name, NULL, mnemonic, menu_type);
50 CreateTitle(parent->InnerWidget(), NULL, title);
53 Menu::Menu(char *category, MotifUI *parent, char *name, char *mnemonic,
55 : MotifUI(parent, name, category)
57 CreateMenu(parent->InnerWidget(), name, category, mnemonic, menu_type);
60 Menu::Menu(char *category, MotifUI *parent, boolean /*has_title*/,
61 char *title, char *name, char *mnemonic, MenuType menu_type)
62 : MotifUI(parent, name, category)
64 CreateMenu(parent->InnerWidget(), name, category, mnemonic, menu_type);
65 CreateTitle(parent->InnerWidget(), category, title);
68 void Menu::SetRadio(boolean flag)
70 XtVaSetValues(_w, XmNradioBehavior, flag, NULL);
73 boolean Menu::SetActivity(boolean flag)
75 XtSetSensitive(_cascadeButton, flag);
79 void Menu::CreateMenu(Widget parent, char *name, char * /*category*/,
80 char *mnemonic, MenuType menu_type)
82 XmString xm_string = StringCreate(name);
86 switch (_menu_type = menu_type)
89 _w = XmCreatePulldownMenu(parent, "pulldown_menu", NULL, 0);
92 _w = XmCreateOptionMenu(parent, "option_menu", NULL, 0);
95 _w = XmCreatePopupMenu(parent, "popup_menu", NULL, 0);
96 XtVaSetValues(_w, XmNwhichButton, MotifUI::bMenuButton, NULL);
99 if (_menu_type != POPUP_MENU)
101 _cascadeButton = XtVaCreateManagedWidget("cascadeButton",
102 xmCascadeButtonWidgetClass,
104 XmNlabelString, xm_string,
105 XmNsubMenuId, _w, NULL);
109 XtVaGetValues(_cascadeButton, XmNbackground, &bg, NULL);
112 XtVaSetValues(_w, XmNuserData, (XtPointer)this, NULL);
113 XtAddCallback(_w, XmNmapCallback, &(Menu::MapCB), NULL);
114 XtAddCallback(_w, XmNunmapCallback, &(Menu::MapCB), NULL);
118 StringFree(xm_string);
120 XtVaSetValues(_cascadeButton,
121 XmNmnemonic, XStringToKeysym(mnemonic), NULL);
125 void Menu::CreateTitle(Widget /*parent*/, char *title, char * /*category*/)
127 XmString xm_string = StringCreate(title);
130 XtVaSetValues(_title, XmNlabelString, xm_string, NULL);
133 _title = XtVaCreateManagedWidget("title", xmLabelWidgetClass, _w,
134 XmNlabelString, xm_string, NULL);
135 _sep = XtVaCreateManagedWidget("separator", xmSeparatorWidgetClass, _w,
136 XmNseparatorType, XmDOUBLE_LINE, NULL);
138 StringFree(xm_string);
141 boolean Menu::SetName(char *name)
143 CreateTitle(_w, name, (char *) Category());
147 void Menu::MapCB(Widget w, XtPointer /*client_data*/, XtPointer /*call_data*/)
150 XtVaGetValues(w, XmNuserData, &obj, NULL);
152 XtVaGetValues(obj->_cascadeButton, XmNforeground, &fg, NULL);
157 XtVaSetValues(obj->_cascadeButton, XmNforeground, fg, NULL);