forked from wagy/WinBinder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
phpwb_control_menu.c
183 lines (131 loc) · 4.32 KB
/
phpwb_control_menu.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*******************************************************************************
WINBINDER - The native Windows binding for PHP for PHP
Copyright © Hypervisual - see LICENSE.TXT for details
Author: Rubem Pechansky (http://winbinder.org/contact.php)
ZEND wrapper for menu functions
*******************************************************************************/
//----------------------------------------------------------------- DEPENDENCIES
#include "phpwb.h"
//----------------------------------------------------------- EXPORTED FUNCTIONS
// TODO: allocate accel[] dynamically like pitem
ZEND_FUNCTION(wbtemp_create_menu)
{
int i, nelem;
zval *zarray = NULL, *entry = NULL;
HashTable *target_hash;
zend_long pwboParent;
PWBITEM *pitem = NULL;
LONG l;
char *str_accel = NULL;
ACCEL accel[MAX_ACCELS];
DWORD dwacc;
int naccel= 0;
// Get function parameters
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"lz!", &pwboParent, &zarray) == FAILURE)
return;
if(!wbIsWBObj((void *)pwboParent, TRUE))
RETURN_NULL()
if(Z_TYPE_P(zarray) == IS_ARRAY) {
target_hash = HASH_OF(zarray);
if(!target_hash)
RETURN_NULL();
nelem = zend_hash_num_elements(target_hash);
zend_hash_internal_pointer_reset(target_hash);
// Allocate memory for menu item pointers
pitem = emalloc(nelem * sizeof(PWBITEM));
// Loop to read array items
for(i = 0; i < nelem; i++) {
if((entry = zend_hash_get_current_data(target_hash)) == NULL) {
zend_error(E_WARNING, "Could not retrieve element %d from array in function %s()",
i, get_active_function_name(TSRMLS_C));
efree(pitem);
RETURN_NULL();
}
// Allocate memory for menu item description
pitem[i] = emalloc(sizeof(WBITEM));
switch(Z_TYPE_P(entry)) {
case IS_ARRAY: // A menu item is an array inside an array
parse_array(entry, "lssss", &pitem[i]->id, &pitem[i]->pszCaption, &pitem[i]->pszHint, &pitem[i]->pszImage, &str_accel);
pitem[i]->pszCaption = Utf82WideChar(pitem[i]->pszCaption, 0);
pitem[i]->pszHint = Utf82WideChar(pitem[i]->pszHint, 0);
pitem[i]->pszImage = Utf82WideChar(pitem[i]->pszImage, 0);
if(str_accel && *str_accel && naccel < MAX_ACCELS) {
dwacc = wbMakeAccelFromString(str_accel);
accel[naccel].key = LOWORD(dwacc);
accel[naccel].fVirt = (BYTE)HIWORD(dwacc);
accel[naccel].cmd = pitem[i]->id;
// printf(">>> %d %d %d\n", accel[naccel].key, accel[naccel].fVirt, accel[naccel].cmd);
naccel++;
}
break;
case IS_NULL: // Separator
pitem[i] = NULL;
break;
case IS_STRING: // Create first-level menu
pitem[i]->id = 0;
pitem[i]->index = 0;
pitem[i]->pszCaption = Utf82WideChar(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
pitem[i]->pszHint = NULL;
pitem[i]->pszImage = NULL;
break;
}
if(i < nelem - 1)
zend_hash_move_forward(target_hash);
}
// Create accelerator table
wbSetAccelerators((PWBOBJ)pwboParent, accel, naccel);
} else {
nelem = 0;
pitem = NULL;
}
// Create menu and attach it to window
l = (LONG)wbCreateMenu((PWBOBJ)pwboParent, pitem, nelem);
if(pitem)
efree(pitem);
RETURN_LONG(l);
}
ZEND_FUNCTION(wbtemp_get_menu_item_checked)
{
zend_long id;
zend_long pwbo;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"ll", &pwbo, &id) == FAILURE)
return;
((PWBOBJ)pwbo)->id = id;
RETURN_BOOL(wbGetMenuItemChecked((PWBOBJ)pwbo));
}
ZEND_FUNCTION(wbtemp_set_menu_item_checked)
{
zend_long id, b;
zend_long pwbo;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"lll", &pwbo, &id, &b) == FAILURE)
return;
((PWBOBJ)pwbo)->id = id;
RETURN_BOOL(wbSetMenuItemChecked((PWBOBJ)pwbo, b));
}
/*
Insert a bullet
NOTE: state is not used, must be 1
*/
ZEND_FUNCTION(wbtemp_set_menu_item_selected)
{
zend_long pwbo, id, state;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"lll", &pwbo, &id, &state) == FAILURE)
return;
((PWBOBJ)pwbo)->id = id;
RETURN_BOOL(wbSetMenuItemSelected((PWBOBJ)pwbo))
}
ZEND_FUNCTION(wbtemp_set_menu_item_image)
{
zend_long id, handle;
zend_long pwbo;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"lll", &pwbo, &id, &handle) == FAILURE)
return;
((PWBOBJ)pwbo)->id = id;
RETURN_BOOL(wbSetMenuItemImage((PWBOBJ)pwbo, (HANDLE)handle));
}
//------------------------------------------------------------------ END OF FILE