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: ComboBoxObj.C /main/4 1995/11/06 09:39:21 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. *
31 #include "ComboBoxObj.h"
36 #include <Xm/ComboBox.h>
38 ComboBoxObj::ComboBoxObj(MotifUI *parent,
39 #if defined(USL) || defined(__uxp__)
40 void (*callback)(ComboBoxObj *, char *, int),
42 ComboBoxCallback callback,
47 : MotifUI(parent, name, NULL)
53 items_list = new XmString [n_items];
59 for (i = 0; i < n_items; i++)
60 items_list[i] = StringCreate(items[i]);
67 XmString xm_string = StringCreate(name);
68 _w = XtVaCreateManagedWidget("form", xmFormWidgetClass,
69 parent->InnerWidget(), NULL);
70 _label = XtVaCreateManagedWidget("form", xmLabelWidgetClass,
71 _w, XmNlabelString, xm_string,
72 XmNtopAttachment, XmATTACH_FORM,
73 XmNbottomAttachment, XmATTACH_FORM,
74 XmNleftAttachment, XmATTACH_FORM, NULL);
75 _combo_box = XtVaCreateManagedWidget("combo_box", xmComboBoxWidgetClass,
76 _w, XmNleftWidget, _label,
77 XmNleftAttachment, XmATTACH_WIDGET,
78 XmNrightAttachment, XmATTACH_FORM,
79 XmNtopAttachment, XmATTACH_FORM,
80 XmNbottomAttachment, XmATTACH_FORM,
81 XmNcomboBoxType, XmDROP_DOWN_LIST,
82 (items_list ? XmNitems : NULL),
84 XmNitemCount, n_items,
85 XmNvisibleItemCount, itemCount,
87 StringFree(xm_string);
91 _w = XtVaCreateManagedWidget("combo_box", xmComboBoxWidgetClass,
92 parent->InnerWidget(),
93 XmNcomboBoxType, XmDROP_DOWN_LIST,
94 (items_list ? XmNitems : NULL), items_list,
95 XmNitemCount, n_items,
96 XmNvisibleItemCount, itemCount, NULL);
100 _list = XtNameToWidget(_combo_box, "*List");
101 XtAddCallback(_combo_box, XmNselectionCallback, &ComboBoxObj::SelectCB,
106 for (i = 0; i < n_items; i++)
107 StringFree(items_list[i]);
112 char * ComboBoxObj::Item(int item)
116 XtVaGetValues(_list, XmNitems, &items, XmNitemCount, &n_items, NULL);
117 if (item < 0 || item > n_items - 1)
120 return StringExtract(items[item + 1]);
123 char * ComboBoxObj::Item(char *item)
125 XmString value = StringCreate(item);
126 int n = XmListItemExists(_list, value);
134 void ComboBoxObj::Add(char *item)
136 XmString value = StringCreate(item);
137 XmComboBoxAddItem(_combo_box, value, 0, True);
141 void ComboBoxObj::Delete(char *item)
143 XmString value = StringCreate(item);
144 int n = XmListItemPos(_list, value);
146 XmComboBoxDeletePos(_combo_box, n);
150 void ComboBoxObj::SelectCB(Widget, XtPointer client_data, XtPointer call_data)
152 ComboBoxObj *obj = (ComboBoxObj *) client_data;
153 XmComboBoxCallbackStruct * cb = (XmComboBoxCallbackStruct *)call_data;
156 char *item = obj->StringExtract(cb->item_or_text);
157 (*obj->_callback)(obj, item, cb->item_position);