]> git.saurik.com Git - wxWidgets.git/blame - src/motif/xmcombo/demo.c
Compile corrections
[wxWidgets.git] / src / motif / xmcombo / demo.c
CommitLineData
8704bf74
JS
1/*
2 * demo.c -- Example how to use a ComboBox
3 *
4 * compile and link with:
5 * $ cc -DFUNCPROTO ComboBoxDemo.c ComboBox.o -o ComboBoxDemo \
6 * -lXm -lXt -lX11
7 * then run:
8 * $ ./ComboBoxDemo
9 *
10 * (c) 1993, 1994 Harald Albrecht
11 * Institut fuer Geometrie und Praktische Mathematik
12 * RWTH Aachen, Germany
13 * albrecht@igpm.rwth-aachen.de
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program (see the file COPYING for more details);
27 * if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
28 * Cambridge, MA 02139, USA.
29 *
30 */
31#include <stdio.h>
32#include <Xm/Xm.h>
33#include <Xm/Form.h>
34#include <Xm/Label.h>
35#include <Xm/Separator.h>
36#include <Xm/PushB.h>
37#include "combobox.h"
38
39Widget TopLevel, Form, Button, Text, Sepp, ComboBox1, ComboBox2, ComboBox3, Label;
40
41void QuitCB(Widget w, caddr_t pClientData, caddr_t pCallData)
42{
43 char *text;
44
45 text = XmComboBoxGetString(ComboBox1);
46 fprintf(stderr, "You choosed \"%s\" out of the first ComboBox\n", text);
47 XtFree(text);
48 text = XmComboBoxGetString(ComboBox2);
49 fprintf(stderr, "You entered \"%s\" into the second ComboBox\n", text);
50 XtFree(text);
51 fprintf(stderr, "Bye! ... have fun with XmComboBox!\n");
52 exit(0);
53} /* QuitCB */
54
55int main(int argc, String argv[])
56{
57 XmString str;
58 Boolean Trav;
59 XtAppContext AppContext;
60
61#if (XmREVISION > 1)
62 XtSetLanguageProc(NULL,NULL,NULL);
63#endif
64 TopLevel = XtAppInitialize(&AppContext, "XFontSelDemo", NULL, 0,
65#if (XmREVISION > 1)
66 &argc,
67#else
68 (Cardinal *) &argc,
69#endif
70 argv, NULL, NULL, 0);
71
72 Form = XtVaCreateManagedWidget("form", xmFormWidgetClass, TopLevel, NULL);
73 str = XmStringCreateLtoR("Click to quit", XmSTRING_DEFAULT_CHARSET);
74 Button = XtVaCreateManagedWidget("quit", xmPushButtonWidgetClass, Form,
75 XmNlabelString, str,
76 XmNleftAttachment, XmATTACH_FORM,
77 XmNleftOffset, 8,
78 XmNtopAttachment, XmATTACH_FORM,
79 XmNtopOffset, 8,
80 NULL);
81 XmStringFree(str);
82 XtAddCallback(Button, XmNactivateCallback, (XtCallbackProc) QuitCB, NULL);
83
84 Sepp = XtVaCreateManagedWidget("separator1", xmSeparatorWidgetClass, Form,
85 XmNleftAttachment, XmATTACH_FORM,
86 XmNrightAttachment, XmATTACH_FORM,
87 XmNtopAttachment, XmATTACH_WIDGET,
88 XmNtopOffset, 8,
89 XmNtopWidget, Button,
90 NULL);
91
92 str = XmStringCreateLtoR("Choose one:", XmSTRING_DEFAULT_CHARSET);
93 ComboBox1 = XtVaCreateManagedWidget("combobox1", xmComboBoxWidgetClass, Form,
94 XmNeditable, False,
95 XmNsorted, True,
96 XmNleftAttachment, XmATTACH_FORM,
97 XmNleftOffset, 8,
98 XmNrightAttachment, XmATTACH_FORM,
99 XmNrightOffset, 8,
100 XmNtopAttachment, XmATTACH_WIDGET,
101 XmNtopOffset, 8,
102 XmNtopWidget, Sepp,
103 XmNshowLabel, True,
104 XmNlabelString, str,
105 NULL);
106 XmStringFree(str);
107 /* Put string unordered into the combo box! They'll get sorted
108 * by the box.
109 */
110 str = XmStringCreateLtoR("William the conquerior", XmSTRING_DEFAULT_CHARSET);
111 XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str);
112 str = XmStringCreateLtoR("Karl der Gro\337e", XmSTRING_DEFAULT_CHARSET);
113 XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str);
114 str = XmStringCreateLtoR("Henry VIII & his chicken band", XmSTRING_DEFAULT_CHARSET);
115 XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str);
116 str = XmStringCreateLtoR("Louis XIV", XmSTRING_DEFAULT_CHARSET);
117 XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str);
118 str = XmStringCreateLtoR("Louis de Funes", XmSTRING_DEFAULT_CHARSET);
119 XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str);
120 str = XmStringCreateLtoR("Helmut Kohl", XmSTRING_DEFAULT_CHARSET);
121 XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str);
122 str = XmStringCreateLtoR("James Major", XmSTRING_DEFAULT_CHARSET);
123 XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str);
124 str = XmStringCreateLtoR("James Bond", XmSTRING_DEFAULT_CHARSET);
125 XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str);
126 str = XmStringCreateLtoR("Billy Boy (M$ Windoze)", XmSTRING_DEFAULT_CHARSET);
127 XmComboBoxAddItem(ComboBox1, str, 0); XmStringFree(str);
128 str = XmStringCreateLtoR("Francois Mitterand", XmSTRING_DEFAULT_CHARSET);
129 XmComboBoxAddItem(ComboBox1, str, 0);
130 XmComboBoxSelectItem(ComboBox1, str, False);
131 XmStringFree(str);
132
133 str = XmStringCreateLtoR("Choose/edit:", XmSTRING_DEFAULT_CHARSET);
134 ComboBox2 = XtVaCreateManagedWidget("combobox2", xmComboBoxWidgetClass, Form,
135 XmNeditable, True,
136 XmNsorted, True,
137 XmNleftAttachment, XmATTACH_FORM,
138 XmNleftOffset, 8,
139 XmNrightAttachment, XmATTACH_FORM,
140 XmNrightOffset, 8,
141 XmNtopAttachment, XmATTACH_WIDGET,
142 XmNtopOffset, 8,
143 XmNtopWidget, ComboBox1,
144 XmNshowLabel, True,
145 XmNlabelString, str,
146 NULL);
147 str = XmStringCreateLtoR("item can be edited after choosing it", XmSTRING_DEFAULT_CHARSET);
148 XmComboBoxAddItem(ComboBox2, str, 0); XmStringFree(str);
149 str = XmStringCreateLtoR("just to fill the list", XmSTRING_DEFAULT_CHARSET);
150 XmComboBoxAddItem(ComboBox2, str, 0); XmStringFree(str);
151 str = XmStringCreateLtoR("so it contains more entries", XmSTRING_DEFAULT_CHARSET);
152 XmComboBoxAddItem(ComboBox2, str, 0); XmStringFree(str);
153
154 str = XmStringCreateLtoR("Static ComboBox:", XmSTRING_DEFAULT_CHARSET);
155 ComboBox3 = XtVaCreateManagedWidget("combobox3", xmComboBoxWidgetClass, Form,
156 XmNeditable, True,
157 XmNstaticList, True,
158 XmNsorted, False,
159 XmNcolumns, 30,
160 XmNleftAttachment, XmATTACH_FORM,
161 XmNleftOffset, 8,
162 XmNrightAttachment, XmATTACH_FORM,
163 XmNrightOffset, 8,
164 XmNtopAttachment, XmATTACH_WIDGET,
165 XmNtopOffset, 8,
166 XmNtopWidget, ComboBox2,
167 XmNshowLabel, True,
168 XmNlabelString, str,
169 NULL);
170 XmStringFree(str);
171 str = XmStringCreateLtoR("ComboBox (noneditable)", XmSTRING_DEFAULT_CHARSET);
172 XmComboBoxAddItem(ComboBox3, str, 0); XmStringFree(str);
173 str = XmStringCreateLtoR("ComboBox (editable)", XmSTRING_DEFAULT_CHARSET);
174 XmComboBoxAddItem(ComboBox3, str, 0); XmStringFree(str);
175 str = XmStringCreateLtoR("ComboBox (editable & static List)", XmSTRING_DEFAULT_CHARSET);
176 XmComboBoxAddItem(ComboBox3, str, 0); XmStringFree(str);
177 str = XmStringCreateLtoR("Center widget", XmSTRING_DEFAULT_CHARSET);
178 XmComboBoxAddItem(ComboBox3, str, 0); XmStringFree(str);
179 str = XmStringCreateLtoR("The ButtonFace Library", XmSTRING_DEFAULT_CHARSET);
180 XmComboBoxAddItem(ComboBox3, str, 0); XmStringFree(str);
181
182 Sepp = XtVaCreateManagedWidget("separator", xmSeparatorWidgetClass, Form,
183 XmNleftAttachment, XmATTACH_FORM,
184 XmNrightAttachment, XmATTACH_FORM,
185 XmNtopAttachment, XmATTACH_WIDGET,
186 XmNtopOffset, 8,
187 XmNtopWidget, ComboBox3,
188 NULL);
189
190 str = XmStringCreateLtoR(
191"xmComboBoxWidgetClass Demo\n\nby Harald Albrecht\n\n\
192albrecht@igpm.rwth-aachen.de", XmSTRING_DEFAULT_CHARSET);
193 Label = XtVaCreateManagedWidget("label", xmLabelWidgetClass, Form,
194 XmNlabelString, str,
195 XmNleftAttachment, XmATTACH_FORM,
196 XmNleftOffset, 80,
197 XmNrightAttachment, XmATTACH_FORM,
198 XmNrightOffset, 80,
199 XmNbottomAttachment, XmATTACH_FORM,
200 XmNbottomOffset, 24,
201 XmNtopAttachment, XmATTACH_WIDGET,
202 XmNtopWidget, Sepp,
203 XmNtopOffset, 24,
204 NULL);
205 XmStringFree(str);
206
207 XtRealizeWidget(TopLevel);
208
209 XtAppMainLoop(AppContext);
210 return 0; /* Never will reach this */
211} /* main */
212
213
214/* End of ComboBoxDemo.c */