]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/xmcombo/demo.c
   2  * demo.c -- Example how to use a ComboBox 
   4  * compile and link with: 
   5  * $ cc -DFUNCPROTO ComboBoxDemo.c ComboBox.o -o ComboBoxDemo \ 
  10  * (c) 1993, 1994 Harald Albrecht 
  11  * Institut fuer Geometrie und Praktische Mathematik 
  12  * RWTH Aachen, Germany 
  13  * albrecht@igpm.rwth-aachen.de 
  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. 
  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. 
  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. 
  35 #include <Xm/Separator.h> 
  39 Widget TopLevel
, Form
, Button
, Text
, Sepp
, ComboBox1
, ComboBox2
, ComboBox3
, Label
; 
  41 void QuitCB(Widget w
, caddr_t pClientData
, caddr_t pCallData
) 
  45     text 
= XmComboBoxGetString(ComboBox1
); 
  46     fprintf(stderr
, "You choosed \"%s\" out of the first ComboBox\n", text
); 
  48     text 
= XmComboBoxGetString(ComboBox2
); 
  49     fprintf(stderr
, "You entered \"%s\" into the second ComboBox\n", text
); 
  51     fprintf(stderr
, "Bye! ... have fun with XmComboBox!\n"); 
  55 int main(int argc
, String argv
[]) 
  59     XtAppContext     AppContext
; 
  62     XtSetLanguageProc(NULL
,NULL
,NULL
);  
  64     TopLevel 
= XtAppInitialize(&AppContext
, "XFontSelDemo", NULL
, 0,  
  72     Form 
= XtVaCreateManagedWidget("form", xmFormWidgetClass
, TopLevel
, NULL
); 
  73     str 
= XmStringCreateLtoR("Click to quit", XmSTRING_DEFAULT_CHARSET
); 
  74     Button 
= XtVaCreateManagedWidget("quit", xmPushButtonWidgetClass
, Form
,  
  76                         XmNleftAttachment
, XmATTACH_FORM
,  
  78                         XmNtopAttachment
,  XmATTACH_FORM
,  
  82     XtAddCallback(Button
, XmNactivateCallback
, (XtCallbackProc
) QuitCB
, NULL
); 
  84     Sepp 
= XtVaCreateManagedWidget("separator1", xmSeparatorWidgetClass
, Form
,  
  85                         XmNleftAttachment
, XmATTACH_FORM
,  
  86                         XmNrightAttachment
, XmATTACH_FORM
, 
  87                         XmNtopAttachment
, XmATTACH_WIDGET
,  
  92     str 
= XmStringCreateLtoR("Choose one:", XmSTRING_DEFAULT_CHARSET
); 
  93     ComboBox1 
= XtVaCreateManagedWidget("combobox1", xmComboBoxWidgetClass
, Form
,  
  96                         XmNleftAttachment
, XmATTACH_FORM
,  
  98                         XmNrightAttachment
, XmATTACH_FORM
, 
 100                         XmNtopAttachment
, XmATTACH_WIDGET
,  
 107     /* Put string unordered into the combo box! They'll get sorted 
 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
); 
 133     str 
= XmStringCreateLtoR("Choose/edit:", XmSTRING_DEFAULT_CHARSET
); 
 134     ComboBox2 
= XtVaCreateManagedWidget("combobox2", xmComboBoxWidgetClass
, Form
,  
 137                         XmNleftAttachment
, XmATTACH_FORM
,  
 139                         XmNrightAttachment
, XmATTACH_FORM
, 
 141                         XmNtopAttachment
, XmATTACH_WIDGET
,  
 143                         XmNtopWidget
, ComboBox1
,  
 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
); 
 154     str 
= XmStringCreateLtoR("Static ComboBox:", XmSTRING_DEFAULT_CHARSET
); 
 155     ComboBox3 
= XtVaCreateManagedWidget("combobox3", xmComboBoxWidgetClass
, Form
,  
 160                         XmNleftAttachment
, XmATTACH_FORM
,  
 162                         XmNrightAttachment
, XmATTACH_FORM
, 
 164                         XmNtopAttachment
, XmATTACH_WIDGET
, 
 166                         XmNtopWidget
, ComboBox2
,  
 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
);  
 182     Sepp 
= XtVaCreateManagedWidget("separator", xmSeparatorWidgetClass
, Form
,  
 183                         XmNleftAttachment
, XmATTACH_FORM
,  
 184                         XmNrightAttachment
, XmATTACH_FORM
, 
 185                         XmNtopAttachment
, XmATTACH_WIDGET
,  
 187                         XmNtopWidget
, ComboBox3
,  
 190     str 
= XmStringCreateLtoR( 
 191 "xmComboBoxWidgetClass Demo\n\nby Harald Albrecht\n\n\ 
 192 albrecht@igpm.rwth-aachen.de", XmSTRING_DEFAULT_CHARSET
);  
 193     Label 
= XtVaCreateManagedWidget("label", xmLabelWidgetClass
, Form
,  
 195                         XmNleftAttachment
, XmATTACH_FORM
,  
 197                         XmNrightAttachment
, XmATTACH_FORM
,  
 199                         XmNbottomAttachment
, XmATTACH_FORM
,  
 201                         XmNtopAttachment
, XmATTACH_WIDGET
,  
 207     XtRealizeWidget(TopLevel
); 
 209     XtAppMainLoop(AppContext
); 
 210     return 0; /* Never will reach this */ 
 214 /* End of ComboBoxDemo.c */