Added CreateOptionChoice and UpdateOptionChoice
[grace.git] / src / widgets.h
blobe9a5eb356fdae8411c6ce1c29861ceef0656bf69
1 /*
2 * Grace - GRaphing, Advanced Computation and Exploration of data
4 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
6 * Copyright (c) 2012 Grace Development Team
8 * Maintained by Evgeny Stambulchik
11 * All Rights Reserved
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 /* Widgets */
30 #ifndef __WIDGETS_H_
31 #define __WIDGETS_H_
33 #include <config.h>
35 #ifdef MOTIF_GUI
36 /* for Widget */
37 #include <X11/Intrinsic.h>
38 #endif /* MOTIF_GUI */
40 #ifdef QT_GUI
41 #include "qtgui/qtinc.h"
42 #endif /* QT_GUI */
44 /* Timer */
45 typedef void (*Timer_CBProc)(void *anydata);
46 typedef struct {
47 unsigned long timer_id;
48 unsigned long interval;
49 Timer_CBProc cbproc;
50 void *anydata;
51 } Timer_CBdata;
52 Timer_CBdata *CreateTimer(unsigned long interval, Timer_CBProc cbproc, void *anydata);
53 void TimerStart(Timer_CBdata *cbdata);
55 /* Widgets */
56 void WidgetManage(Widget w);
57 void WidgetUnmanage(Widget w);
58 int WidgetIsManaged(Widget w);
59 void *WidgetGetUserData(Widget w);
60 void WidgetSetUserData(Widget w, void *udata);
61 void WidgetSetSensitive(Widget w, int onoff);
62 void WidgetSetFocus(Widget w);
63 void WidgetSetWidth(Widget w, unsigned int width);
64 void WidgetSetHeight(Widget w, unsigned int height);
65 void WidgetSetSize(Widget w, unsigned int width, unsigned int height);
66 void WidgetGetSize(Widget w, unsigned int *width, unsigned int *height);
68 typedef void (*Key_CBProc)(void *anydata);
69 typedef struct {
70 Widget w;
71 int modifiers;
72 int key;
73 Key_CBProc cbproc;
74 void *anydata;
75 } Key_CBData;
77 void AddWidgetKeyPressCB(Widget w, int key, Key_CBProc cbproc, void *anydata);
78 void AddWidgetKeyPressCB2(Widget w, int modifiers, int key, Key_CBProc cbproc, void *anydata);
80 void AddWidgetButtonPressCB(Widget w, int button, Key_CBProc cbproc, void *anydata);
82 typedef struct {
83 char **text;
84 int allow_change;
85 } TextValidate_CD;
87 typedef struct _Widget_CBData Widget_CBData;
88 typedef void (*Widget_CBProc)(Widget_CBData *wcbdata);
89 struct _Widget_CBData {
90 Widget w;
91 Widget_CBProc cbproc;
92 void *anydata;
93 void *calldata;
95 void AddWidgetCB(Widget w, const char *callback, Widget_CBProc cbproc, void *anydata);
97 /* Dialog Window */
98 Widget CreateDialogWindow(Widget parent, const char *s);
100 /* Dialog */
101 Widget CreateDialog(Widget parent, const char *s);
102 void DialogRaise(Widget form);
103 void DialogClose(Widget form);
104 void DialogSetResizable(Widget form, int onoff);
106 /* File selection box */
107 Widget CreateFileSelectionBox(Widget parent);
109 /* File selection filter */
110 void CreateFileSelectionFilter(Widget parent, Widget fsb);
112 /* File selection dialog */
113 typedef struct {
114 Widget FSB;
115 Widget rc;
116 } FSBStructure;
117 FSBStructure *CreateFSBDialog(Widget parent, char *s);
119 typedef int (*FSB_CBProc)(
120 FSBStructure *fsbp,
121 char *, /* filename */
122 void * /* data the application registered */
124 void AddFSBDialogCB(FSBStructure *fsbp, FSB_CBProc cbproc, void *anydata);
125 void FSBDialogSetPattern(FSBStructure *fsb, char *pattern);
126 void FSBDialogSetDirectory(FSBStructure *fsb, char *directory);
128 /* Containers */
129 Widget CreateVContainer(Widget parent);
130 Widget CreateHContainer(Widget parent);
132 /* Form */
133 Widget CreateForm(Widget parent);
134 void FormAddHChild(Widget form, Widget child);
135 void FormAddVChild(Widget form, Widget child);
136 void FormFixateHChild(Widget w);
137 void FormFixateVChild(Widget w);
139 /* Grid */
140 Widget CreateGrid(Widget parent, int ncols, int nrows);
141 void PlaceGridChild(Widget grid, Widget w, int col, int row);
143 /* Frame */
144 Widget CreateFrame(Widget parent, char *s);
146 /* Scrolled window */
147 Widget CreateScrolledWindow(Widget parent);
149 /* Paned window */
150 Widget CreatePanedWindow(Widget parent);
151 void PanedWindowSetMinWidth(Widget w, unsigned int width);
153 /* Tab */
154 Widget CreateTab(Widget parent);
155 Widget CreateTabPage(Widget parent, char *s);
156 void SelectTabPage(Widget tab, Widget w);
158 /* Separator */
159 Widget CreateSeparator(Widget parent);
161 /* Label */
162 Widget CreateLabel(Widget parent, char *s);
163 void LabelSetString(Widget w, char *s);
164 void LabelSetPixmap(Widget w, Pixmap pixmap);
166 /* Text edit */
167 Widget CreateLineTextEdit(Widget parent, int len);
168 Widget CreateMultiLineTextEdit(Widget parent, int nrows);
169 char *TextEditGetString(Widget w);
170 void TextEditSetString(Widget w, char *s);
172 /* Text */
173 typedef struct {
174 Widget label;
175 Widget form;
176 Widget text;
177 int locked;
178 } TextStructure;
180 void TextInsertString(TextStructure *cst, int pos, char *s);
181 int TextGetCursorPos(TextStructure *cst);
182 void TextSetCursorPos(TextStructure *cst, int pos);
183 int TextGetLastPosition(TextStructure *cst);
184 void TextSetLength(TextStructure *cst, int len);
185 void TextSetEditable(TextStructure *cst, int onoff);
187 /* Button */
188 typedef void (*Button_CBProc)(
189 Widget but,
190 void * /* data the application registered */
192 Widget CreateButton(Widget parent, char *label);
193 Widget CreateBitmapButton(Widget parent,
194 int width, int height, const unsigned char *bits);
196 #define ARROW_UP 1
197 #define ARROW_DOWN 2
198 Widget CreateArrowButton(Widget parent, int arrow_type);
200 /* ToggleButton */
201 typedef void (*TB_CBProc)(
202 Widget but,
203 int onoff, /* True/False */
204 void * /* data the application registered */
206 Widget CreateToggleButton(Widget parent, char *s);
207 int ToggleButtonGetState(Widget w);
208 void ToggleButtonSetState(Widget w, int value);
210 /* Scale */
211 Widget CreateScale(Widget parent, char *s, int min, int max, int delta);
212 void ScaleSetValue(Widget w, int value);
213 int ScaleGetValue(Widget w);
215 /* ComboBox */
216 typedef struct {
217 Widget combobox;
218 Widget popup;
219 } ComboBoxStructure;
220 ComboBoxStructure *CreateComboBox(Widget parent);
222 /* OptionChoice */
223 typedef struct _OptionStructure OptionStructure;
224 typedef struct {
225 int value;
226 char *label;
227 Pixmap pixmap;
228 unsigned long background;
229 unsigned long foreground;
230 } LabelOptionItem;
231 OptionStructure *CreateOptionChoice(Widget parent, char *labelstr, int ncols,
232 int nchoices, LabelOptionItem *items);
233 void UpdateOptionChoice(OptionStructure *optp, int nchoices, LabelOptionItem *items);
234 OptionStructure *CreateLabelOptionChoice(Widget parent, char *labelstr, int ncols,
235 int nchoices, LabelOptionItem *items);
236 OptionStructure *CreateLabelOptionChoiceVA(Widget parent, char *labelstr, ...);
237 void UpdateLabelOptionChoice(OptionStructure *optp, int nchoices, LabelOptionItem *items);
239 typedef struct {
240 int value;
241 unsigned char *bitmap;
242 } BitmapOptionItem;
243 OptionStructure *CreateBitmapOptionChoice(Widget parent, char *labelstr, int ncols,
244 int nchoices, int width, int height, BitmapOptionItem *items);
245 OptionStructure *CreateCharOptionChoice(Widget parent, char *s);
246 void UpdateCharOptionChoice(OptionStructure *opt, int font);
247 void SetOptionChoice(OptionStructure *opt, int value);
248 int GetOptionChoice(OptionStructure *opt);
249 void OptionChoiceSetColorUpdate(OptionStructure *opt, int update);
251 typedef void (*OC_CBProc)(
252 OptionStructure *opt,
253 int value, /* value */
254 void * /* data the application registered */
257 typedef struct {
258 OptionStructure *opt;
259 OC_CBProc cbproc;
260 void *anydata;
261 } OC_CBdata;
263 struct _OptionStructure {
264 int nchoices;
265 int ncols; /* preferred number of columns */
266 Widget menu;
267 Widget pulldown;
268 LabelOptionItem *items;
269 int cvalue;
270 int update_colors;
272 unsigned int cbnum;
273 OC_CBdata **cblist;
275 void AddOptionChoiceCB(OptionStructure *opt, OC_CBProc cbproc, void *anydata);
277 /* Menu */
278 Widget CreatePopupMenu(Widget parent);
279 void PopupMenuShow(Widget w, void *data);
280 Widget CreateMenuBar(Widget parent);
281 Widget CreateMenu(Widget parent, char *label, char mnemonic, int help);
282 Widget CreateMenuButton(Widget parent, char *label, char mnemonic,
283 Button_CBProc cb, void *data);
284 Widget CreateMenuButtonA(Widget parent, char *label, char mnemonic,
285 char *accelerator, char* acceleratorText, Button_CBProc cb, void *data);
286 Widget CreateMenuHelpButton(Widget parent, char *label, char mnemonic,
287 Widget form, char *ha);
288 Widget CreateMenuToggle(Widget parent, char *label, char mnemonic,
289 TB_CBProc cb, void *data);
290 Widget CreateMenuSeparator(Widget parent);
292 #endif /* __WIDGETS_H_ */