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 /* $TOG: IndexedOptionMenu.C /main/3 1997/11/21 18:42:21 mgreess $ */
30 * RESTRICTED CONFIDENTIAL INFORMATION:
32 * The information in this document is subject to special
33 * restrictions in a confidential disclosure agreement between
34 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
35 * document outside HP, IBM, Sun, USL, SCO, or Univel without
36 * Sun's specific written approval. This document and all copies
37 * and derivative works thereof must be returned or destroyed at
40 * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
45 * Common Desktop Environment
47 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
48 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
49 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
50 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
51 * (c) Copyright 1995 Digital Equipment Corp.
52 * (c) Copyright 1995 Fujitsu Limited
53 * (c) Copyright 1995 Hitachi, Ltd.
56 * RESTRICTED RIGHTS LEGEND
58 *Use, duplication, or disclosure by the U.S. Government is subject to
59 *restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
60 *Technical Data and Computer Software clause in DFARS 252.227-7013. Rights
61 *for non-DOD U.S. Government Departments and Agencies are as set forth in
62 *FAR 52.227-19(c)(1,2).
64 *Hewlett-Packard Company, 3000 Hanover Street, Palo Alto, CA 94304 U.S.A.
65 *International Business Machines Corp., Route 100, Somers, NY 10589 U.S.A.
66 *Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, CA 94043 U.S.A.
67 *Novell, Inc., 190 River Road, Summit, NJ 07901 U.S.A.
68 *Digital Equipment Corp., 111 Powdermill Road, Maynard, MA 01754, U.S.A.
69 *Fujitsu Limited, 1015, Kamikodanaka Nakahara-Ku, Kawasaki 211, Japan
70 *Hitachi, Ltd., 6, Kanda Surugadai 4-Chome, Chiyoda-ku, Tokyo 101, Japan
74 #include <X11/Intrinsic.h>
76 #include <Xm/DialogS.h>
79 #include <Xm/RowColumn.h>
80 #include <Xm/ToggleB.h>
83 #include "IndexedOptionMenu.h"
85 #include "dtmailopts.h"
87 IndexedOptionMenu::IndexedOptionMenu (
92 ) : UIComponent( "IndexedOptionMenu" )
102 _nmenu_items = nmenu_items;
103 if (nmenu_items && strings != NULL)
105 _strings = (char **) XtMalloc(nmenu_items * sizeof(char*));
106 for (int i=0; i<nmenu_items; i++)
107 _strings[i] = strings[i];
109 if (nmenu_items && data != NULL)
111 _data = (void **) XtMalloc(nmenu_items * sizeof(void*));
112 for (int i=0; i<nmenu_items; i++)
117 * Create the pulldown menu for the option menus,
118 * and populate it with pushbuttons.
119 * Attach the original strings used to generate
120 * the button labels to the buttons as userData.
122 menu = XmCreatePulldownMenu(parent, "Menu", NULL, 0);
123 _buttons = (Widget *) XtMalloc( _nmenu_items * sizeof(Widget) );
124 for (int i=0; i<_nmenu_items; i++)
126 static char button_label[32];
128 sprintf(button_label, "Button%d", i);
129 _buttons[i] = XmCreatePushButton(menu, button_label, NULL, 0);
130 xms = XmStringCreateLocalized(_strings[i]);
137 XtManageChild(_buttons[i]);
141 XtSetArg(args[nargs], XmNsubMenuId, menu); nargs++;
142 _w = XmCreateOptionMenu(parent, "IndexedOptionMenu", args, nargs);
143 installDestroyHandler();
145 //XtRealizeWidget(_w);
148 IndexedOptionMenu::IndexedOptionMenu (
154 ) : UIComponent( "IndexedOptionMenu" )
157 installDestroyHandler();
158 _nmenu_items = nmenu_items;
163 if (nmenu_items && strings != NULL)
165 _strings = (char **) XtMalloc(nmenu_items * sizeof(char*));
166 for (int i=0; i<nmenu_items; i++)
167 _strings[i] = strings[i];
169 if (nmenu_items && data != NULL)
171 _data = (void **) XtMalloc(nmenu_items * sizeof(void*));
172 for (int i=0; i<nmenu_items; i++)
175 if (nmenu_items && buttons != NULL)
177 _buttons = (Widget *) XtMalloc( _nmenu_items * sizeof(Widget) );
178 for (int i=0; i<nmenu_items; i++)
179 _buttons[i] = buttons[i];
184 IndexedOptionMenu::~IndexedOptionMenu (void)
189 XtFree((char *) _buttons);
191 XtFree((char *) _strings);
193 XtFree((char *) _data);
197 IndexedOptionMenu::addMenuButtonCallback(
199 XtCallbackProc callback,
200 XtPointer client_data)
202 for (int i=0; i<_nmenu_items; i++)
203 XtAddCallback(_buttons[i], callback_name, callback, client_data);
207 IndexedOptionMenu::getDataSpec (void)
209 int index = getIndexSpec();
214 IndexedOptionMenu::getIndexSpec (void)
222 XtVaGetValues(_w, XmNmenuHistory, &arg, NULL);
223 selected = (Widget)arg;
224 XtVaGetValues(selected, XmNuserData, &arg, NULL);
231 IndexedOptionMenu::getStringSpec(void)
233 int index = getIndexSpec();
234 return _strings[index];
238 IndexedOptionMenu::setSpec (int spec)
240 XtVaSetValues(_w, XmNmenuHistory, _buttons[spec], NULL );
244 IndexedOptionMenu::setSpec (const char *string)
246 int spec = stringToIndex(string);
247 if (spec >= _nmenu_items) return;
252 IndexedOptionMenu::setSpec (void *data)
254 int spec = dataToIndex(data);
255 if (spec >= _nmenu_items) return;
260 IndexedOptionMenu::dataToIndex (void *data)
264 for (index=0; index<_nmenu_items; index++)
265 if (! strncmp((char*) _data[index], (char*) data, strlen((char*) data)))
272 IndexedOptionMenu::stringToIndex (const char *string)
276 for (index=0; index<_nmenu_items; index++)
277 if (! strncmp(_strings[index], string, strlen(string)) )