1 /* -*-c-*- */
2 #ifndef FVWMFORM_H
3 #define FVWMFORM_H
4 
5 /*  Modification History
6 
7  Created 12/20/98 Dan Espen:
8 
9  - FvwmForm.c got too big for my home machine to deal with.
10 
11  */
12 
13 #include "libs/Flocale.h"               /* for font definition stuff */
14 /*
15  * This next stuff should be more specific and customizable.
16  * For example padVText (above) was one of the things TXT_SPC
17  * controlled. (dje)
18  */
19 #define TEXT_SPC    3
20 /* This one, box_spc would have to be saved as part of an "item".
21    It's used for input boxes, buttons, and I think, choices.
22    dje */
23 #define BOX_SPC     3
24 /* Item_hspc is only used during the "massage phase"
25    has to be saved in items. */
26 #define ITEM_HSPC   10
27 #define ITEM_VSPC   5
28 
29 /* Control the areas that are realloced in chunks: */
30 #define ITEMS_PER_EXPANSION 32
31 #define CHOICES_PER_SEL_EXPANSION 8
32 #define BUTTON_COMMAND_EXPANSION 8
33 #define TIMEOUT_COMMAND_EXPANSION 8
34 
35 #define I_TEXT          1
36 #define I_INPUT         2
37 #define I_SELECT        3
38 #define I_CHOICE        4
39 #define I_BUTTON        5
40 #define I_TIMEOUT       6
41 #define I_SEPARATOR     7
42 
43 #define IS_SINGLE       1
44 #define IS_MULTIPLE     2
45 
46 #define IB_CONTINUE     1
47 #define IB_RESTART      2
48 #define IB_QUIT         3
49 
50 /* There is a "drawtable" for each item drawn in a form */
51 typedef struct _drawtable {
52   struct _drawtable *dt_next;           /* link list, circle */
53   char *dt_font_name;                   /* font name */
54   char *dt_color_names[4];
55   int dt_used;                          /* 1=used as text, 2 used as item */
56   unsigned long dt_colors[6];             /* text fore/back
57 					   button/choice/input fore/back
58 					   hilite and shadow (item only)
59 					   Note, need all 6 because choices
60 					   use them all */
61   GC dt_GC;                             /* graphic ctx used for text */
62   GC dt_item_GC;                        /* graphic ctx used for graphics */
63   FlocaleFont *dt_Ffont;                /* Fvwm font structure */
64   FlocaleWinString *dt_Fstr;            /* Fvwm string (handles multibyte) */
65 } DrawTable;
66 
67 /* An "item" is something in a form. Part of the structure is common
68    for all item types, the rest of the structure is a union. */
69 typedef union _item {
70   int type;                /* item type, one of I_TEXT .. I_BUTTON */
71   struct _head {           /* common header */
72     int type;
73     union _item *next;                  /* for all items linklist */
74     int win;               /* X window id */
75     char *name;            /* identifier name */
76     int size_x, size_y;    /* size of bounding box */
77     int pos_x, pos_y;      /* position of top-left corner */
78     DrawTable *dt_ptr;                  /* only used for items that need it */
79   } header;
80 
81   struct {                 /* I_TEXT */
82     struct _head head;
83     int n;                 /* string length */
84     char *value;           /* string to display */
85     unsigned long color;                /* color of text */
86   } text;
87 
88   struct {                 /* I_INPUT */
89     struct _head head;
90     int buf;               /* input string buffer */
91     int n;                 /* string length */
92     char *value;           /* input string */
93     char *init_value;      /* default string */
94     char *blanks;          /* blank string */
95     int size;              /* input field size */
96     int left;              /* position of the left-most displayed char */
97     union _item *next_input;            /* a ring of input fields */
98     union _item *prev_input;            /* for tabbing */
99     int value_history_count;            /* count of input history */
100     int value_history_yankat;           /* yank point between restarts */
101     char **value_history_ptr;           /* curr insertion point */
102   } input;
103   struct {                 /* I_SELECT */
104     struct _head head;
105     int key;               /* one of IS_MULTIPLE, IS_SINGLE */
106     int n;                 /* number of choices */
107     int choices_array_count;             /* current choices array size */
108     union _item **choices; /* list of choices */
109   } selection;
110   struct {                 /* I_CHOICE */
111     struct _head head;
112     int on;                /* selected or not */
113     int init_on;           /* initially selected or not */
114     char *value;           /* value if selected */
115     int n;                 /* text string length */
116     char *text;            /* text string */
117     union _item *sel;      /* selection it belongs to */
118   } choice;
119   struct {                 /* I_BUTTON */
120     struct _head head;
121     int key;               /* one of IB_CONTINUE, IB_RESTART, IB_QUIT */
122     int n;                 /* # of commands */
123     int len;               /* text length */
124     char *text;            /* text string */
125     int keypress;          /* short cut */
126     int button_array_size;              /* current size of next array */
127     char **commands;    /* Fvwm command to execute */
128   } button;
129   struct {              /* I_TIMEOUT */
130     struct _head head;
131     int timeleft;       /* seconds left on timer */
132     int len;            /* text length */
133     char *text;         /* text string */
134     char *command;    /* Fvwm command(s) to execute */
135   } timeout;
136   struct {              /* I_SEPARATOR */
137     struct _head head;
138   } separator;
139 } Item;
140 
141 #define L_LEFT        1
142 #define L_RIGHT       2
143 #define L_CENTER      3
144 #define L_LEFTRIGHT   4
145 #define MICRO_S_FOR_10MS 10000
146 #define VH_SIZE 50                      /* size of value history */
147 
148 /* There is one "line" structure for each line in the form.
149    "Lines" point at an array of "items". */
150 typedef struct _line {
151   struct _line *next;                   /* Pointer to next line */
152   int n;                                /* number of items on the line */
153   int justify;                          /* justification */
154   int size_x, size_y;                   /* size of bounding rectangle */
155   int item_array_size;                  /* track size */
156   Item **items;                         /* ptr to array of items */
157 } Line;
158 
159 /* Need a struct for the pointer color.
160    Since colors are unsigned, we need a flag to indicate whether
161    the color was ever set. */
162 typedef struct _ptrc {
163   XColor pointer_color;
164   char used;
165 } Ptr_color;
166 
167 /* There is one "form". Start of attempt to change that. */
168 typedef struct _form {
169 #if 0
170   struct _form *next;                   /* dje hmm. a linklist of forms? */
171 #endif
172   Item def_button;
173   int grab_server;                      /* set during parse used on display */
174   int server_grabbed;                   /* first time switch */
175   int gx, gy, have_geom;
176   int xneg, yneg;
177   int warp_pointer;
178   int max_width, total_height;          /* frame size */
179   unsigned long screen_background;
180   Item *cur_input;                      /* current input during parse and run */
181   Item *first_input;                    /* forms first input item during parse*/
182   Item *last_error;                     /* fvwm error message display area */
183   DrawTable *roots_dt;                  /* root draw tables linklist */
184   int abs_cursor;
185   int rel_cursor;
186   Window frame;
187   int padVText;                         /* vert space for text item */
188   char *leading;                        /* part of command to match for data */
189   char *file_to_read;                   /* file to read for data */
190   char *title;                          /* form title, NULL, use alias */
191   char *expand_buffer;                  /* buffer to expand commands in */
192   int expand_buffer_size;               /* current size */
193   char have_env_var;                    /* at least one env var on cmd line */
194   Cursor pointer[3];
195   Ptr_color p_c[6];                     /* fg/bg for pointers, used flag */
196   int activate_on_press;                /* activate button on press */
197 } Form;
198 
199 enum {input_pointer,button_pointer,button_in_pointer};
200 enum {input_fore,input_back,
201       button_fore,button_back,
202       button_in_fore,button_in_back};
203 
204 extern Form cur_form;                   /* current form */
205 #define CF cur_form                     /* I may want to undo this... */
206 
207   /* Globals: */
208 
209 /* Link list roots */
210 extern Item *root_item_ptr;             /* pointer to root of item list */
211 extern Line root_line;
212 extern Line *cur_line;
213 extern char preload_yorn;
214 extern Item *item;                             /* current during parse */
215 extern Item *cur_sel, *cur_button;             /* current during parse */
216 extern Display *dpy;
217 extern Atom wm_del_win;
218 extern int fd_x;                  /* fd for X connection */
219 extern Window root, ref;
220 extern int screen;
221 
222 enum { c_bg, c_fg, c_item_bg, c_item_fg, c_itemlo, c_itemhi };
223 extern char *color_names[4];
224 extern char bg_state;
225 extern char endDefaultsRead;
226 enum { f_text, f_input, f_button, f_timeout };
227 extern char *font_names[4];
228 extern char *screen_background_color;
229 
230 extern int colorset;
231 extern int itemcolorset;
232 
233 /* From FvwmAnimate start */
234 extern char *MyName;
235 extern int MyNameLen;
236 /* here is the old double parens trick. */
237 /* #define DEBUG */
238 #ifdef DEBUG
239 #define myfprintf(X) \
240   fprintf X;\
241   fflush (stderr);
242 #else
243 #define myfprintf(X)
244 #endif
245 
246 #define tempmyfprintf(X) \
247   fprintf X;\
248   fflush (stderr);
249 
250 extern int Channel[2];
251 
252 /* From FvwmAnimate end */
253 
254 /* prototypes */
255 void ReadXServer(void);                  /* ReadXServer.c */
256 void RedrawText(Item *item);             /* FvwmForm.c */
257 void RedrawTimeout(Item *item);          /* FvwmForm.c */
258 void RedrawItem (
259 	Item *item, int click, XEvent *pev); /* FvwmForm.c */
260 void UpdateRootTransapency(
261 	Bool pr_only, Bool do_draw);     /* FvwmForm.c */
262 void DoCommand (Item *cmd);              /* FvwmForm.c */
263 int FontWidth (XFontStruct *xfs);        /* FvwmForm.c */
264 void RedrawFrame (XEvent *pev);          /* FvwmForm.c */
265 char * ParseCommand (int, char *, char, int *, char **s); /* ParseCommand.c */
266 
267 RETSIGTYPE DeadPipe(int nonsense);            /* FvwmForm.c */
268 
269 #endif
270