forked from libui-ng/libui-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_unix.h
144 lines (133 loc) · 4.88 KB
/
ui_unix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// 7 april 2015
/*
This file assumes that you have included <gtk/gtk.h> and "ui.h" beforehand. It provides API-specific functions for interfacing with foreign controls on Unix systems that use GTK+ to provide their UI (currently all except Mac OS X).
*/
#ifndef __LIBUI_UI_UNIX_H__
#define __LIBUI_UI_UNIX_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct uiUnixControl uiUnixControl;
struct uiUnixControl {
uiControl c;
uiControl *parent;
gboolean addedBefore;
gboolean explicitlyHidden;
void (*SetContainer)(uiUnixControl *, GtkContainer *, gboolean);
};
#define uiUnixControl(this) ((uiUnixControl *) (this))
// TODO document
_UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gboolean);
#define uiUnixControlDefaultDestroy(type) \
static void type ## Destroy(uiControl *c) \
{ \
/* TODO is this safe on floating refs? */ \
g_object_unref(type(c)->widget); \
uiFreeControl(c); \
}
#define uiUnixControlDefaultHandle(type) \
static uintptr_t type ## Handle(uiControl *c) \
{ \
return (uintptr_t) (type(c)->widget); \
}
#define uiUnixControlDefaultParent(type) \
static uiControl *type ## Parent(uiControl *c) \
{ \
return uiUnixControl(c)->parent; \
}
#define uiUnixControlDefaultSetParent(type) \
static void type ## SetParent(uiControl *c, uiControl *parent) \
{ \
uiControlVerifySetParent(c, parent); \
uiUnixControl(c)->parent = parent; \
}
#define uiUnixControlDefaultToplevel(type) \
static int type ## Toplevel(uiControl *c) \
{ \
return 0; \
}
#define uiUnixControlDefaultVisible(type) \
static int type ## Visible(uiControl *c) \
{ \
return gtk_widget_get_visible(type(c)->widget); \
}
#define uiUnixControlDefaultShow(type) \
static void type ## Show(uiControl *c) \
{ \
/*TODO part of massive hack about hidden before*/uiUnixControl(c)->explicitlyHidden=FALSE; \
gtk_widget_show(type(c)->widget); \
}
#define uiUnixControlDefaultHide(type) \
static void type ## Hide(uiControl *c) \
{ \
/*TODO part of massive hack about hidden before*/uiUnixControl(c)->explicitlyHidden=TRUE; \
gtk_widget_hide(type(c)->widget); \
}
#define uiUnixControlDefaultEnabled(type) \
static int type ## Enabled(uiControl *c) \
{ \
return gtk_widget_get_sensitive(type(c)->widget); \
}
#define uiUnixControlDefaultEnable(type) \
static void type ## Enable(uiControl *c) \
{ \
gtk_widget_set_sensitive(type(c)->widget, TRUE); \
}
#define uiUnixControlDefaultDisable(type) \
static void type ## Disable(uiControl *c) \
{ \
gtk_widget_set_sensitive(type(c)->widget, FALSE); \
}
// TODO this whole addedBefore stuff is a MASSIVE HACK.
#define uiUnixControlDefaultSetContainer(type) \
static void type ## SetContainer(uiUnixControl *c, GtkContainer *container, gboolean remove) \
{ \
if (!uiUnixControl(c)->addedBefore) { \
g_object_ref_sink(type(c)->widget); /* our own reference, which we release in Destroy() */ \
/* massive hack notes: without any of this, nothing gets shown when we show a window; without the if, all things get shown even if some were explicitly hidden (TODO why don't we just show everything except windows on create? */ \
/*TODO*/if(!uiUnixControl(c)->explicitlyHidden) gtk_widget_show(type(c)->widget); \
uiUnixControl(c)->addedBefore = TRUE; \
} \
if (remove) \
gtk_container_remove(container, type(c)->widget); \
else \
gtk_container_add(container, type(c)->widget); \
}
#define uiUnixControlAllDefaultsExceptDestroy(type) \
uiUnixControlDefaultHandle(type) \
uiUnixControlDefaultParent(type) \
uiUnixControlDefaultSetParent(type) \
uiUnixControlDefaultToplevel(type) \
uiUnixControlDefaultVisible(type) \
uiUnixControlDefaultShow(type) \
uiUnixControlDefaultHide(type) \
uiUnixControlDefaultEnabled(type) \
uiUnixControlDefaultEnable(type) \
uiUnixControlDefaultDisable(type) \
uiUnixControlDefaultSetContainer(type)
#define uiUnixControlAllDefaults(type) \
uiUnixControlDefaultDestroy(type) \
uiUnixControlAllDefaultsExceptDestroy(type)
// TODO document
#define uiUnixNewControl(type, var) \
var = type(uiUnixAllocControl(sizeof (type), type ## Signature, #type)); \
uiControl(var)->Destroy = type ## Destroy; \
uiControl(var)->Handle = type ## Handle; \
uiControl(var)->Parent = type ## Parent; \
uiControl(var)->SetParent = type ## SetParent; \
uiControl(var)->Toplevel = type ## Toplevel; \
uiControl(var)->Visible = type ## Visible; \
uiControl(var)->Show = type ## Show; \
uiControl(var)->Hide = type ## Hide; \
uiControl(var)->Enabled = type ## Enabled; \
uiControl(var)->Enable = type ## Enable; \
uiControl(var)->Disable = type ## Disable; \
uiUnixControl(var)->SetContainer = type ## SetContainer;
// TODO document
_UI_EXTERN uiUnixControl *uiUnixAllocControl(size_t n, uint32_t typesig, const char *typenamestr);
// uiUnixStrdupText() takes the given string and produces a copy of it suitable for being freed by uiFreeText().
_UI_EXTERN char *uiUnixStrdupText(const char *);
#ifdef __cplusplus
}
#endif
#endif