1 
2 /* This file contains all the header definitions for working with this
3  * library of functions that make X stuff a lot easier to swallow.
4  *
5  *              --  This code under the GNU copyleft --
6  *
7  *   Dominic Giampaolo
8  *   dbg@sgi.com
9  */
10 
11 #ifndef _LIBSX_H_    /* prevent accidental re-inclusions */
12 #define _LIBSX_H_
13 
14 #include <X11/Intrinsic.h>
15 
16 
17 /*
18  * General prototypes for the setup functions
19  */
20 int    OpenDisplay(int argc, char **argv);
21 int    GLOpenDisplay(int argc, char **argv, int *attributes);
22 void   ShowDisplay(void);
23 
24 void   MainLoop(void);
25 void   SyncDisplay(void);
26 
27 
28 Widget MakeWindow(char *window_name, char *display_name, int exclusive);
29 void   SetCurrentWindow(Widget w);
30 void   CloseWindow(void);
31 
32 /* #define's for use with MakeWindow() */
33 #define SAME_DISPLAY         NULL
34 #define NONEXCLUSIVE_WINDOW  0
35 #define EXCLUSIVE_WINDOW     1
36 
37 
38 /* #define for use with SetCurrentWindow() */
39 #define ORIGINAL_WINDOW  NULL
40 
41 
42 Widget MakeForm(Widget parent, int where1, Widget from1, int whr2, Widget fr2);
43 void   SetForm(Widget form);
44 
45 /* for use w/MakeForm() and SetForm() */
46 #define TOP_LEVEL_FORM  NULL
47 
48 
49 /*
50  * These are typedef's for the various styles of callback functions.
51  */
52 typedef void (*ButtonCB)(Widget w, void *data);
53 typedef void (*StringCB)(Widget w, char *string, void *data);
54 typedef void (*ScrollCB)(Widget w, float new_val, void *data);
55 typedef void (*ListCB)(Widget w, char *string, int index, void *data);
56 
57 /*
58  * These typedef's are for drawing area callbacks only.
59  */
60 typedef void (*RedisplayCB)(Widget w, int new_width, int new_height, void *d);
61 typedef void (*MouseButtonCB)(Widget w, int button, int x, int y, void *dat);
62 typedef void (*KeyCB)(Widget w, char *input, int up_or_down, void *data);
63 typedef void (*MotionCB)(Widget w, int x, int y, void *data);
64 
65 
66 
67 /*
68  * Prototypes for the widget creation functions.  General functions
69  * that apply to any widget (such as setting its color or position) follow
70  * after these.
71  */
72 
73 
74 /*
75  * Button and Label Widget routines.
76  */
77 Widget MakeButton(char *label, ButtonCB function, void *data);
78 Widget MakeLabel(char *txt);
79 
80 /*
81  * Toggle Widget routines.
82  */
83 Widget MakeToggle(char *txt, int state, Widget w, ButtonCB func, void *d);
84 void   SetToggleState(Widget w, int state);
85 int    GetToggleState(Widget w);
86 
87 
88 
89 /*
90  * Drawing Area and drawing functions.
91  */
92 
93 Widget MakeDrawArea(int width, int height, RedisplayCB redisplay, void *data);
94 
95 void   SetButtonDownCB(Widget w, MouseButtonCB button_down);
96 void   SetButtonUpCB(Widget w, MouseButtonCB button_up);
97 void   SetKeypressCB(Widget w, KeyCB keypress);
98 void   SetMouseMotionCB(Widget w, MotionCB motion);
99 
100 void   SetColor(int color);
101 void   SetDrawMode(int mode);
102 
103 #define SANE_XOR  0x7f  /* A sane mode for drawing XOR lines and stuff */
104 
105 void   SetLineWidth(int width);
106 void   SetDrawArea(Widget w);
107 void   GetDrawAreaSize(int *w, int *h);
108 
109 void   ClearDrawArea(void);
110 
111 void   DrawPixel(int x1, int y1);
112 int    GetPixel(int x1, int y1);
113 void   DrawLine(int x1, int y1, int x2, int y2);
114 void   DrawPolyline(XPoint *points, int n);
115 void   DrawFilledPolygon (XPoint *points, int n);
116 void   DrawFilledBox(int x, int y, int width, int height);
117 void   DrawBox(int x, int y, int width, int height);
118 void   DrawText(char *string, int x, int y);
119 void   DrawArc(int x, int y, int width, int height, int angle1, int angle2);
120 void   DrawFilledArc(int x, int y, int w, int h, int angle1, int angle2);
121 void   DrawImage(char *data, int x, int y, int width, int height);
122 void   DrawBitmap(char *data, int x, int y, int width, int height);
123 void   GetImage(char *data, int x, int y, int width, int height);
124 
125 void   ScrollDrawArea(int dx, int dy, int x1,int y1, int x2, int y2);
126 
127 void   SwapBuffers(void);  /* only if libsx compiled with -DOPENGL_SUPPORT */
128 
129 
130 
131 /*
132  * String Entry routines.
133  */
134 Widget  MakeStringEntry(char *txt, int size, StringCB func, void *data);
135 void    SetStringEntry(Widget w, char *new_text);
136 char   *GetStringEntry(Widget w);
137 
138 
139 /*
140  * Ascii Text display widget routines.
141  */
142 Widget  MakeTextWidget(char *txt, int is_file, int editable, int w, int h);
143 void    SetTextWidgetText(Widget w, char *text, int is_file);
144 char   *GetTextWidgetText(Widget w);
145 
146 
147 
148 
149 /*
150  * Scrollbar routines.
151  */
152 Widget MakeHorizScrollbar(int len,    ScrollCB scroll_func, void *data);
153 Widget MakeVertScrollbar( int height, ScrollCB scroll_func, void *data);
154 void   SetScrollbar(Widget w, float where, float max, float size_shown);
155 
156 
157 
158 /*
159  * Scrolled list routines.
160  */
161 Widget MakeScrollList(char **list, int width, int height, ListCB func,void *d);
162 void   SetCurrentListItem(Widget w, int list_index);
163 int    GetCurrentListItem(Widget w);
164 void   ChangeScrollList(Widget w, char **new_list);
165 
166 
167 
168 /*
169  * Menu and MenuItem routines.
170  */
171 Widget MakeMenu(char *name);
172 Widget MakeMenuItem(Widget menu, char *name, ButtonCB func, void *arg);
173 
174 void   SetMenuItemChecked(Widget w, int state);
175 int    GetMenuItemChecked(Widget w);
176 
177 
178 
179 
180 /*
181  * Widget position setting functions (used to do algorithmic layout).
182  */
183 void  SetWidgetPos(Widget w, int where1, Widget from1,int where2,Widget from2);
184 
185 /*
186  * define's for button/gadget placement, used to call SetWidgetPos()
187  */
188 #define NO_CARE       0x00 /* don't care where the gadget is placed */
189 #define PLACE_RIGHT   0x01 /* place me to the right of specified gadget */
190 #define PLACE_UNDER   0x02 /* place me under the specified gadget */
191 
192 
193 
194 void AttachEdge(Widget w, int edge, int attach_to);
195 
196 #define LEFT_EDGE      0x00   /* These #define's specify which edge we want */
197 #define RIGHT_EDGE     0x01
198 #define TOP_EDGE       0x02
199 #define BOTTOM_EDGE    0x03
200 
201 
202 #define ATTACH_LEFT    0x00   /* attach given edge to the left side of form */
203 #define ATTACH_RIGHT   0x01   /* attach given edge to the right side of form */
204 #define ATTACH_TOP     0x02   /* attach given edge to the top of the form */
205 #define ATTACH_BOTTOM  0x03   /* attach given edge to the bottom of the form */
206 
207 
208 
209 /*
210  * General Setting/Getting of Widget attributes.  These apply to any
211  * type of widget.
212  */
213 void  SetFgColor(Widget w, int color);
214 void  SetBgColor(Widget w, int color);
215 void  SetBorderColor(Widget w, int color);
216 
217 int   GetFgColor(Widget w);
218 int   GetBgColor(Widget w);
219 
220 void  SetLabel(Widget w, char *txt);
221 
222 void  SetWidgetState(Widget w, int state);    /* turn widgets on and off */
223 int   GetWidgetState(Widget w);
224 
225 void  SetWidgetBitmap(Widget w, char *data, int width, int height);
226 
227 void  Beep(void);
228 
229 
230 /*
231  * Font things.
232  */
233 typedef XFontStruct *XFont;     /* make it a little easier to read */
234 
235 XFont GetFont(char *fontname);
236 void  SetWidgetFont(Widget w, XFont f);
237 XFont GetWidgetFont(Widget w);
238 void  FreeFont(XFont f);
239 int   FontHeight(XFont f);
240 int   TextWidth(XFont f, char *txt);
241 
242 
243 
244 /*
245  * Miscellaneous functions.
246  */
247 typedef void (*GeneralCB)(void *data);
248 typedef void (*IOCallback)(void *data, int *fd);
249 
250 void  AddTimeOut(unsigned long interval, GeneralCB func, void *data);
251 void  AddReadCallback(int fd,  IOCallback func, void *data);
252 void  AddWriteCallback(int fd, IOCallback func, void *data);
253 
254 
255 /*
256  * User-input functions
257  */
258 char *GetString(char *blurb, char *default_string);
259 int   GetYesNo(char *question);
260 
261 
262 
263 
264 /*
265  * Colormap things.
266  */
267 
268 extern int WHITE,        /* Global color values to use for drawing in color */
269            BLACK,
270            RED,
271            GREEN,
272            BLUE,
273            YELLOW;
274 
275 
276 /*
277  * Getting/Setting/Freeing Color and Colormap function prototypes
278  */
279 void GetStandardColors(void);
280 int  GetNamedColor(char *name);
281 int  GetRGBColor(int r, int g, int b);
282 void FreeStandardColors(void);
283 
284 
285 int  GetPrivateColor(void);
286 void SetPrivateColor(int which, int r, int g, int b);
287 void FreePrivateColor(int which);
288 
289 
290 /*
291  * The following functions completely take over the display colormap.
292  *                       ** Use with caution **
293  */
294 int  GetAllColors(void);
295 void SetColorMap(int num);
296 void SetMyColorMap(int n, unsigned char *r, unsigned char *g,unsigned char *b);
297 void FreeAllColors(void);
298 
299 
300 /*
301  * define's for use in calling SetColorMap()
302  */
303 #define GREY_SCALE_1    0   /* grey-scale with a few other colors */
304 #define GREY_SCALE_2    1   /* pure grey-scale (0-255) */
305 #define RAINBOW_1       2   /* different types of rainbows/bands of colors */
306 #define RAINBOW_2       3
307 
308 
309 
310 
311 #endif /* _LIBSX_H_ */
312