15817
|
1 #ifndef GNT_WIDGET_H
|
|
2 #define GNT_WIDGET_H
|
|
3
|
|
4 #include <stdio.h>
|
|
5 #include <glib.h>
|
|
6 #include <ncurses.h>
|
|
7
|
|
8 #include "gntbindable.h"
|
|
9
|
|
10 #define GNT_TYPE_WIDGET (gnt_widget_get_gtype())
|
|
11 #define GNT_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_WIDGET, GntWidget))
|
|
12 #define GNT_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_WIDGET, GntWidgetClass))
|
|
13 #define GNT_IS_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_WIDGET))
|
|
14 #define GNT_IS_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_WIDGET))
|
|
15 #define GNT_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_WIDGET, GntWidgetClass))
|
|
16
|
|
17 #define GNT_WIDGET_FLAGS(obj) (GNT_WIDGET(obj)->priv.flags)
|
|
18 #define GNT_WIDGET_SET_FLAGS(obj, flags) (GNT_WIDGET_FLAGS(obj) |= flags)
|
|
19 #define GNT_WIDGET_UNSET_FLAGS(obj, flags) (GNT_WIDGET_FLAGS(obj) &= ~(flags))
|
|
20 #define GNT_WIDGET_IS_FLAG_SET(obj, flags) (GNT_WIDGET_FLAGS(obj) & (flags))
|
|
21
|
|
22 typedef struct _GnWidget GntWidget;
|
|
23 typedef struct _GnWidgetPriv GntWidgetPriv;
|
|
24 typedef struct _GnWidgetClass GntWidgetClass;
|
|
25
|
|
26 typedef enum _GnWidgetFlags
|
|
27 {
|
|
28 GNT_WIDGET_DESTROYING = 1 << 0,
|
|
29 GNT_WIDGET_CAN_TAKE_FOCUS = 1 << 1,
|
|
30 GNT_WIDGET_MAPPED = 1 << 2,
|
|
31 /* XXX: Need to set the following two as properties, and setup a callback whenever these
|
|
32 * get chnaged. */
|
|
33 GNT_WIDGET_NO_BORDER = 1 << 3,
|
|
34 GNT_WIDGET_NO_SHADOW = 1 << 4,
|
|
35 GNT_WIDGET_HAS_FOCUS = 1 << 5,
|
|
36 GNT_WIDGET_DRAWING = 1 << 6,
|
|
37 GNT_WIDGET_URGENT = 1 << 7,
|
|
38 GNT_WIDGET_GROW_X = 1 << 8,
|
|
39 GNT_WIDGET_GROW_Y = 1 << 9,
|
|
40 GNT_WIDGET_INVISIBLE = 1 << 10,
|
|
41 GNT_WIDGET_TRANSIENT = 1 << 11,
|
|
42 } GntWidgetFlags;
|
|
43
|
|
44 /* XXX: This will probably move elsewhere */
|
|
45 typedef enum _GnMouseEvent
|
|
46 {
|
|
47 GNT_LEFT_MOUSE_DOWN = 1,
|
|
48 GNT_RIGHT_MOUSE_DOWN,
|
|
49 GNT_MIDDLE_MOUSE_DOWN,
|
|
50 GNT_MOUSE_UP,
|
|
51 GNT_MOUSE_SCROLL_UP,
|
|
52 GNT_MOUSE_SCROLL_DOWN
|
|
53 } GntMouseEvent;
|
|
54
|
|
55 /* XXX: I'll have to ask grim what he's using this for in guifications. */
|
|
56 typedef enum _GnParamFlags
|
|
57 {
|
|
58 GNT_PARAM_SERIALIZABLE = 1 << G_PARAM_USER_SHIFT
|
|
59 } GntParamFlags;
|
|
60
|
|
61 struct _GnWidgetPriv
|
|
62 {
|
|
63 int x, y;
|
|
64 int width, height;
|
|
65 GntWidgetFlags flags;
|
|
66 char *name;
|
|
67
|
|
68 int minw, minh; /* Minimum size for the widget */
|
|
69 };
|
|
70
|
|
71 struct _GnWidget
|
|
72 {
|
|
73 GntBindable inherit;
|
|
74
|
|
75 GntWidget *parent;
|
|
76
|
|
77 GntWidgetPriv priv;
|
|
78 WINDOW *window;
|
|
79
|
|
80 void (*gnt_reserved1)(void);
|
|
81 void (*gnt_reserved2)(void);
|
|
82 void (*gnt_reserved3)(void);
|
|
83 void (*gnt_reserved4)(void);
|
|
84 };
|
|
85
|
|
86 struct _GnWidgetClass
|
|
87 {
|
|
88 GntBindableClass parent;
|
|
89
|
|
90 void (*map)(GntWidget *obj);
|
|
91 void (*show)(GntWidget *obj); /* This will call draw() and take focus (if it can take focus) */
|
|
92 void (*destroy)(GntWidget *obj);
|
|
93 void (*draw)(GntWidget *obj); /* This will draw the widget */
|
|
94 void (*hide)(GntWidget *obj);
|
|
95 void (*expose)(GntWidget *widget, int x, int y, int width, int height);
|
|
96 void (*gained_focus)(GntWidget *widget);
|
|
97 void (*lost_focus)(GntWidget *widget);
|
|
98
|
|
99 void (*size_request)(GntWidget *widget);
|
|
100 gboolean (*confirm_size)(GntWidget *widget, int x, int y);
|
|
101 void (*size_changed)(GntWidget *widget, int w, int h);
|
|
102 void (*set_position)(GntWidget *widget, int x, int y);
|
|
103 gboolean (*key_pressed)(GntWidget *widget, const char *key);
|
|
104 void (*activate)(GntWidget *widget);
|
|
105 gboolean (*clicked)(GntWidget *widget, GntMouseEvent event, int x, int y);
|
|
106
|
|
107 void (*gnt_reserved1)(void);
|
|
108 void (*gnt_reserved2)(void);
|
|
109 void (*gnt_reserved3)(void);
|
|
110 void (*gnt_reserved4)(void);
|
|
111 };
|
|
112
|
|
113 G_BEGIN_DECLS
|
|
114
|
|
115 GType gnt_widget_get_gtype(void);
|
|
116 void gnt_widget_destroy(GntWidget *widget);
|
|
117 void gnt_widget_show(GntWidget *widget);
|
|
118 void gnt_widget_draw(GntWidget *widget);
|
|
119 void gnt_widget_expose(GntWidget *widget, int x, int y, int width, int height);
|
|
120 void gnt_widget_hide(GntWidget *widget);
|
|
121
|
|
122 void gnt_widget_get_position(GntWidget *widget, int *x, int *y);
|
|
123 void gnt_widget_set_position(GntWidget *widget, int x, int y);
|
|
124 void gnt_widget_size_request(GntWidget *widget);
|
|
125 void gnt_widget_get_size(GntWidget *widget, int *width, int *height);
|
|
126 gboolean gnt_widget_set_size(GntWidget *widget, int width, int height);
|
|
127 gboolean gnt_widget_confirm_size(GntWidget *widget, int width, int height);
|
|
128
|
|
129 gboolean gnt_widget_key_pressed(GntWidget *widget, const char *keys);
|
|
130
|
|
131 gboolean gnt_widget_clicked(GntWidget *widget, GntMouseEvent event, int x, int y);
|
|
132
|
|
133 gboolean gnt_widget_set_focus(GntWidget *widget, gboolean set);
|
|
134 void gnt_widget_activate(GntWidget *widget);
|
|
135
|
|
136 void gnt_widget_set_name(GntWidget *widget, const char *name);
|
|
137
|
|
138 const char *gnt_widget_get_name(GntWidget *widget);
|
|
139
|
|
140 /* Widget-subclasses should call this from the draw-callback.
|
|
141 * Applications should just call gnt_widget_draw instead of this. */
|
|
142 void gnt_widget_queue_update(GntWidget *widget);
|
|
143
|
|
144 void gnt_widget_set_take_focus(GntWidget *widget, gboolean set);
|
|
145
|
|
146 void gnt_widget_set_visible(GntWidget *widget, gboolean set);
|
|
147
|
|
148 gboolean gnt_widget_has_shadow(GntWidget *widget);
|
|
149
|
|
150 G_END_DECLS
|
|
151
|
|
152 #endif /* GNT_WIDGET_H */
|