-
Notifications
You must be signed in to change notification settings - Fork 4
/
control-common.c
127 lines (111 loc) · 3 KB
/
control-common.c
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
#include "control-common.h"
#include "object.h"
#include <ui.h>
int is_control( int signature )
{
switch( signature )
{
// ONLY CONTROLS/WIDGETS
// IMPORTANT, NOT MENUS or IMAGES
case uiAreaSignature:
case uiBoxSignature:
case uiButtonSignature:
case uiCheckboxSignature:
case uiColorButtonSignature:
case uiComboboxSignature:
case uiDateTimePickerSignature:
case uiEditableComboboxSignature:
case uiEntrySignature:
case uiFontButtonSignature:
case uiFormSignature:
case uiGridSignature:
case uiGroupSignature:
case uiLabelSignature:
case uiImageBoxSignature:
case uiMultilineEntrySignature:
case uiProgressBarSignature:
case uiRadioButtonsSignature:
case uiSeparatorSignature:
case uiSliderSignature:
case uiSpinboxSignature:
case uiTabSignature:
case uiWindowSignature:
return 1;
default:
return 0;
}
}
uiControl* check_control( lua_State* L, int idx, int signature )
{
int s;
uiControl* c = (uiControl*) get_object( L, idx, &s );
if( is_control( s ) )
{
if( signature == 0 || signature == s )
{
return c;
}
}
luaL_error( L, "libui object is not a control" );
return 0;
}
int l_uiControlDestroy( lua_State* L )
{
uiControl* c = check_control( L, 1, 0 );
uiControlDestroy( c );
// destroy registry meta table
lua_pushlightuserdata( L, c );
lua_pushnil( L );
lua_settable( L, LUA_REGISTRYINDEX );
return 0;
}
static int l_uiControlParent( lua_State* L )
{
return object_copy( L, uiControlParent( check_control( L,-1, 0 ) ) );
}
static int l_uiControlSetParent( lua_State* L )
{
uiControl* c = check_control( L, 1, 0 );
uiControl* p = check_control( L, 2, 0 );
uiControlSetParent( c, p );
lua_pushvalue( L, 1 );
return 1;
}
#undef DECLARE_GETTER
#define DECLARE_GETTER( typename, action, type ) \
int l_ ## typename ## action( lua_State* L ) { \
lua_push ## type ( L, typename ## action ( (typename*) check_control( L, 1, 0 ) ) ); \
return 1; \
}
#undef DECLARE_ACTION
#define DECLARE_ACTION( typename, action ) \
int l_ ## typename ## action( lua_State* L ) { \
typename ## action ( (typename*) check_control( L, 1, 0 ) ); \
lua_pushvalue( L, 1 ); \
return 1; \
}
DECLARE_GETTER( uiControl, Handle, integer )
DECLARE_GETTER( uiControl, Visible, boolean )
DECLARE_ACTION( uiControl, Show )
DECLARE_ACTION( uiControl, Hide )
DECLARE_GETTER( uiControl, Enabled, boolean )
DECLARE_ACTION( uiControl, Enable )
DECLARE_ACTION( uiControl, Disable )
DECLARE_GETTER( uiControl, Toplevel, boolean )
DECLARE_GETTER( uiControl, EnabledToUser, boolean )
luaL_Reg control_common[] =
{
{ "Destroy", l_uiControlDestroy },
{ "Handle", l_uiControlHandle },
{ "Parent", l_uiControlParent },
{ "SetParent", l_uiControlSetParent },
{ "TopLevel", l_uiControlToplevel },
{ "Visible", l_uiControlVisible },
{ "Show", l_uiControlShow },
{ "Hide", l_uiControlHide },
{ "Enabled", l_uiControlEnabled },
{ "Enable", l_uiControlEnable },
{ "Disable", l_uiControlDisable },
{ "EnabledToUser", l_uiControlEnabledToUser },
{ 0, 0 }
};