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" )
99 _nmenu_items = nmenu_items;
100 if (nmenu_items && strings != NULL)
102 _strings = (char **) XtMalloc(nmenu_items * sizeof(char*));
103 for (int i=0; i<nmenu_items; i++)
104 _strings[i] = strings[i];
106 if (nmenu_items && data != NULL)
108 _data = (void **) XtMalloc(nmenu_items * sizeof(void*));
109 for (int i=0; i<nmenu_items; i++)
114 * Create the pulldown menu for the option menus,
115 * and populate it with pushbuttons.
116 * Attach the original strings used to generate
117 * the button labels to the buttons as userData.
119 menu = XmCreatePulldownMenu(parent, "Menu", NULL, 0);
120 _buttons = (Widget *) XtMalloc( _nmenu_items * sizeof(Widget) );
121 for (int i=0; i<_nmenu_items; i++)
123 static char button_label[32];
125 sprintf(button_label, "Button%d", i);
126 _buttons[i] = XmCreatePushButton(menu, button_label, NULL, 0);
127 xms = XmStringCreateLocalized(_strings[i]);
134 XtManageChild(_buttons[i]);
138 XtSetArg(args[nargs], XmNsubMenuId, menu); nargs++;
139 _w = XmCreateOptionMenu(parent, "IndexedOptionMenu", args, nargs);
140 installDestroyHandler();
142 //XtRealizeWidget(_w);
145 IndexedOptionMenu::IndexedOptionMenu (
151 ) : UIComponent( "IndexedOptionMenu" )
154 installDestroyHandler();
155 _nmenu_items = nmenu_items;
160 if (nmenu_items && strings != NULL)
162 _strings = (char **) XtMalloc(nmenu_items * sizeof(char*));
163 for (int i=0; i<nmenu_items; i++)
164 _strings[i] = strings[i];
166 if (nmenu_items && data != NULL)
168 _data = (void **) XtMalloc(nmenu_items * sizeof(void*));
169 for (int i=0; i<nmenu_items; i++)
172 if (nmenu_items && buttons != NULL)
174 _buttons = (Widget *) XtMalloc( _nmenu_items * sizeof(Widget) );
175 for (int i=0; i<nmenu_items; i++)
176 _buttons[i] = buttons[i];
181 IndexedOptionMenu::~IndexedOptionMenu (void)
186 XtFree((char *) _buttons);
188 XtFree((char *) _strings);
190 XtFree((char *) _data);
194 IndexedOptionMenu::addMenuButtonCallback(
196 XtCallbackProc callback,
197 XtPointer client_data)
199 for (int i=0; i<_nmenu_items; i++)
200 XtAddCallback(_buttons[i], callback_name, callback, client_data);
204 IndexedOptionMenu::getDataSpec (void)
206 int index = getIndexSpec();
211 IndexedOptionMenu::getIndexSpec (void)
218 XtVaGetValues(_w, XmNmenuHistory, &selected, NULL);
219 XtVaGetValues(selected, XmNuserData, &data, NULL);
225 IndexedOptionMenu::getStringSpec(void)
227 int index = getIndexSpec();
228 return _strings[index];
232 IndexedOptionMenu::setSpec (int spec)
234 XtVaSetValues(_w, XmNmenuHistory, _buttons[spec], NULL );
238 IndexedOptionMenu::setSpec (const char *string)
240 int spec = stringToIndex(string);
241 if (spec >= _nmenu_items) return;
246 IndexedOptionMenu::setSpec (void *data)
248 int spec = dataToIndex(data);
249 if (spec >= _nmenu_items) return;
254 IndexedOptionMenu::dataToIndex (void *data)
258 for (index=0; index<_nmenu_items; index++)
259 if (! strncmp((char*) _data[index], (char*) data, strlen((char*) data)))
266 IndexedOptionMenu::stringToIndex (const char *string)
270 for (index=0; index<_nmenu_items; index++)
271 if (! strncmp(_strings[index], string, strlen(string)) )