gui_defs.h 7.3 KB
Newer Older
1
2
3
4
5
#ifndef _GUI_DEFS_H_
#define _GUI_DEFS_H_

/* defines the private API of the GUI */

Cedric Roux's avatar
Cedric Roux committed
6
7
8
extern int volatile gui_logd;
#define LOGD(...) do { if (gui_logd) printf(__VA_ARGS__); } while (0)

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*************************************************************************/
/*                            logging macros                             */
/*************************************************************************/

#define ERR(...) \
  do { \
    printf("%s:%d:%s: ERROR: ", __FILE__, __LINE__, __FUNCTION__); \
    printf(__VA_ARGS__); \
    abort(); \
  } while (0)

#define WARN(...) \
  do { \
    printf("%s:%d:%s: WARNING: ", __FILE__, __LINE__, __FUNCTION__); \
    printf(__VA_ARGS__); \
  } while (0)

#define OOM ERR("out of memory\n")

/*************************************************************************/
/*                             widgets                                   */
/*************************************************************************/

enum widget_type {
Cedric Roux's avatar
Cedric Roux committed
33
  TOPLEVEL_WINDOW, CONTAINER, POSITIONER, TEXT_LIST, XY_PLOT, BUTTON, LABEL,
Cedric Roux's avatar
Cedric Roux committed
34
  TIMELINE, SPACE, IMAGE
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
};

struct widget_list;

struct widget {
  enum widget_type type;
  int id;
  int x;            /* allocated x after packing */
  int y;            /* allocated y after packing */
  int width;        /* allocated width after packing */
  int height;       /* allocated height after packing */
  struct widget_list *children;
  struct widget *parent;
  void (*repack)(gui *g, widget *this);
  void (*add_child)(gui *g, widget *this, widget *child, int position);
Cedric Roux's avatar
Cedric Roux committed
50
  void (*del_child)(gui *g, widget *this, widget *child);
51
52
53
  void (*allocate)(gui *g, widget *this, int x, int y, int width, int height);
  void (*hints)(gui *g, widget *this, int *width, int *height);
  void (*paint)(gui *g, widget *this);
Cedric Roux's avatar
Cedric Roux committed
54
  void (*clear)(gui *g, widget *this);
Cedric Roux's avatar
Cedric Roux committed
55
  /* user input */
56
57
  void (*button)(gui *g, widget *this, int x, int y, int key_modifiers,
      int button, int up);
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
};

struct widget_list {
  struct widget *item;
  struct widget_list *next;
  //struct widget_list *prev;  /* unused? */
  struct widget_list *last;  /* valid only for the head of the list */
};

struct toplevel_window_widget {
  struct widget common;
  void *x;                /* opaque X data (type x_window), used in x.c */
};

struct container_widget {
  struct widget common;
  int vertical;
  int hints_are_valid;     /* used to cache hints values */
  int hint_width;          /* cached hint values - invalid if */
  int hint_height;         /* repack_was_called == 1          */
78
79
  int *growable;
  int nchildren;
80
81
};

82
83
84
85
struct positioner_widget {
  struct widget common;
};

86
struct textlist_widget {
87
88
  struct widget common;
  char **text;
Cedric Roux's avatar
Cedric Roux committed
89
  int *color;
90
91
92
93
94
95
96
97
98
99
  int text_count;
  int wanted_width;
  int wanted_nlines;    /* number of lines of text the user wants to see */
  int allocated_nlines; /* actual number of visible lines */
  int starting_line;    /* points to the first visible line of text */
  int line_height;
  int baseline;
  int background_color;
};

100
struct xy_plot_plot {
101
102
103
  float *x;
  float *y;
  int npoints;
104
105
106
107
108
  int color;
};

struct xy_plot_widget {
  struct widget common;
109
110
111
112
113
114
115
116
117
  char *label;
  int label_width;
  int label_height;
  int label_baseline;
  int vrule_width;       /* the width of the vertical ruler text zone */
  float xmin, xmax;
  float ymin, ymax;
  int wanted_width;
  int wanted_height;
118
119
  struct xy_plot_plot *plots;
  int nplots;
120
121
};

Cedric Roux's avatar
Cedric Roux committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
struct timeline_subline {
  int *color;                  /* length = width of timeline widget
                                * value = -1 if no color
                                */
  int width;
  int background;              /* background color of the subline */
};

struct timeline_widget {
  struct widget common;
  int n;                         /* number of sublines */
  struct timeline_subline *s;
  int subline_height;
  int wanted_width;
};

138
139
140
141
142
143
144
145
146
147
148
149
150
struct button_widget {
  struct widget common;
};

struct label_widget {
  struct widget common;
  const char *t;
  int color;
  int width;         /* as given by the graphic's backend */
  int height;        /* as given by the graphic's backend */
  int baseline;      /* as given by the graphic's backend */
};

151
152
153
154
155
156
struct space_widget {
  struct widget common;
  int wanted_width;
  int wanted_height;
};

Cedric Roux's avatar
Cedric Roux committed
157
158
159
160
161
162
163
struct image_widget {
  struct widget common;
  int width;
  int height;
  void *x;             /* opaque X data (type x_image), used in x.c */
};

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*************************************************************************/
/*                             events                                    */
/*************************************************************************/

typedef void event;

enum event_type {
  DIRTY, REPACK
};

struct event {
  enum event_type type;
};

struct event_list {
  struct event *item;
  struct event_list *next;
  struct event_list *last;
};

struct dirty_event {
  struct event common;
  int id;
};

struct repack_event {
  struct event common;
  int id;
};

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*************************************************************************/
/*                           notifications                               */
/*************************************************************************/

/* same type as in gui.h */
typedef void (*notifier)(void *private, gui *g,
    char *notification, widget *w, void *notification_data);

struct notifier {
  notifier handler;
  unsigned long id;
  char *notification;
  widget *w;
  void *private;
  /* done is used bu gui_notify */
  int done;
};

212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*************************************************************************/
/*                          main structure                               */
/*************************************************************************/

struct gui {
  void                *lock;
  void                *x; /* opaque X data (type x_connection), used in x.c */
  struct widget_list  *toplevel;
  struct event_list   *queued_events;
  int                 event_pipe[2];
  int                 next_id;         /* tells what is the ID of
                                          the next created widget */
  int                 repainted;       /* set to 1 when some widget has
                                        * been repainted (TODO: can be any,
                                        * to be optimized) */
  void                *xwin;           /* set by a toplevel_window when
                                        * it paints itself, to be used
                                        * by its children */
230
231
232
  struct notifier     *notifiers;
  int                 notifiers_count;
  unsigned long       next_notifier_id;
233
234
235
236
237
238
239
240
241
};

/*************************************************************************/
/*                            internal functions                         */
/*************************************************************************/

widget *new_widget(struct gui *g, enum widget_type type, int size);
void widget_add_child_internal(
    gui *_gui, widget *parent, widget *child, int position);
Cedric Roux's avatar
Cedric Roux committed
242
243
void widget_del_child_internal(gui *_gui, widget *parent, widget *child);
int widget_get_child_position(gui *_gui, widget *parent, widget *child);
244
245
246
247
248
249
250
251

const char *widget_name(enum widget_type type);

void send_event(gui *gui, enum event_type type, ...);
void gui_events(gui *gui);

struct widget *find_widget(struct gui *g, int id);

252
253
254
void gui_notify(struct gui *g, char *notification, widget *w,
    void *notification_data);

255
#endif /* _GUI_DEFS_H_ */