forked from stefan-loewe/WinBinder
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathphpwb_control_treeview.c
225 lines (181 loc) · 6.1 KB
/
phpwb_control_treeview.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*******************************************************************************
WINBINDER - The native Windows binding for PHP for PHP
Copyright Hypervisual - see LICENSE.TXT for details
Author: Rubem Pechansky (https://github.com/crispy-computing-machine/Winbinder)
ZEND wrapper for treeview control
*******************************************************************************/
//----------------------------------------------------------------- DEPENDENCIES
#include "phpwb.h"
//---------------------------------------------------------- EXTERNAL PROTOTYPES
extern UINT64 wbGetTreeViewItemLevel(PWBOBJ pwbo, HTREEITEM hItem);
//----------------------------------------------------------- EXPORTED FUNCTIONS
/* Returns the level of a node in a treeview */
ZEND_FUNCTION(wb_get_level)
{
zend_long pwbo, item = 0;
// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &pwbo, &item) == FAILURE)
// ZEND_PARSE_PARAMETERS_START() takes two arguments minimal and maximal parameters count.
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_LONG(pwbo)
Z_PARAM_LONG(item)
ZEND_PARSE_PARAMETERS_END();
if (!wbIsWBObj((void *)pwbo, TRUE)){
RETURN_NULL();
}
if (((PWBOBJ)pwbo)->uClass == TreeView)
{
if (item)
{
RETURN_LONG(wbGetTreeViewItemLevel((PWBOBJ)pwbo, (HTREEITEM)item));
}
else
{
RETURN_NULL();
}
}
else
{
RETURN_NULL();
}
}
ZEND_FUNCTION(wb_set_treeview_item_selected)
{
zend_long pwbo, item;
//if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &pwbo, &item) == FAILURE)
// ZEND_PARSE_PARAMETERS_START() takes two arguments minimal and maximal parameters count.
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_LONG(pwbo)
Z_PARAM_LONG(item)
ZEND_PARSE_PARAMETERS_END();
if (!wbIsWBObj((void *)pwbo, TRUE)){
RETURN_BOOL(FALSE);
}
RETURN_BOOL(wbSetTreeViewItemSelected((PWBOBJ)pwbo, (HTREEITEM)item));
}
ZEND_FUNCTION(wb_set_treeview_item_text)
{
zend_long pwbo, item;
char *s;
size_t s_len;
TCHAR *wcs = 0;
// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lls", &pwbo, &item, &s, &s_len) == FAILURE)
// ZEND_PARSE_PARAMETERS_START() takes two arguments minimal and maximal parameters count.
ZEND_PARSE_PARAMETERS_START(3, 3)
Z_PARAM_LONG(pwbo)
Z_PARAM_LONG(item)
Z_PARAM_STRING(s,s_len)
ZEND_PARSE_PARAMETERS_END();
if (!wbIsWBObj((void *)pwbo, TRUE)){
RETURN_BOOL(FALSE);
}
wcs = Utf82WideChar(s, s_len);
RETURN_BOOL(wbSetTreeViewItemText((PWBOBJ)pwbo, (HTREEITEM)item, wcs));
}
ZEND_FUNCTION(wb_get_treeview_item_text)
{
zend_long pwbo, item = 0;
TCHAR szItem[MAX_ITEM_STRING];
char *str = 0;
int str_len = 0;
// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &pwbo, &item) == FAILURE)
// ZEND_PARSE_PARAMETERS_START() takes two arguments minimal and maximal parameters count.
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_LONG(pwbo)
Z_PARAM_LONG(item)
ZEND_PARSE_PARAMETERS_END();
if (!wbIsWBObj((void *)pwbo, TRUE)){
RETURN_BOOL(FALSE);
}
wbGetTreeViewItemText((PWBOBJ)pwbo, (HTREEITEM)item, szItem, MAX_ITEM_STRING - 1);
str = WideChar2Utf8(szItem, &str_len);
RETURN_STRINGL(str, str_len);
}
/*
Change the item value.
If zparam is NULL, does not change associated value (does nothing).
*/
ZEND_FUNCTION(wb_set_treeview_item_value)
{
zend_long pwbo, item, lparam = 0;
zval *zparam, zcopy;
// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llz!", &pwbo, &item, &zparam) == FAILURE)
// ZEND_PARSE_PARAMETERS_START() takes two arguments minimal and maximal parameters count.
ZEND_PARSE_PARAMETERS_START(3, 3)
Z_PARAM_LONG(pwbo)
Z_PARAM_LONG(item)
Z_PARAM_ZVAL(zparam)
ZEND_PARSE_PARAMETERS_END();
if (!wbIsWBObj((void *)pwbo, TRUE)){
RETURN_BOOL(FALSE);
}
switch (Z_TYPE_P(zparam))
{
case IS_NULL: // Do not change lparam
lparam = 0;
break;
default:
// ****** Possible leak: Should free the existing copy of zparam here, if any
ZVAL_LONG(&zcopy, 0);
zcopy = *zparam;
break;
}
RETURN_BOOL(wbSetTreeViewItemValue((PWBOBJ)pwbo, (HTREEITEM)item, lparam));
}
/*
int wb_create_treeview_item( int wbobject, string caption [, mixed param [, int where [, int image [, int selectedimage [, insertiontype]]]]])
Create a new treeview item and returns the HTREEITEM handle to it.
If zparam is NULL, does not change associated value.
*/
ZEND_FUNCTION(wb_create_treeview_item)
{
zend_long pwbo, where = 0, img1 = -1, img2 = -1, insertiontype = 0, lparam = 0;
char *str;
size_t str_len;
zval *zparam;
BOOL setlparam = FALSE;
TCHAR *wcs = 0;
LONG_PTR ret;
zend_bool where_isnull ,img1_isnull, img2_isnull, insertiontype_isnull;
//if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|zllll", &pwbo, &str, &str_len, &zparam, &where, &img1, &img2, &insertiontype) == FAILURE)
// ZEND_PARSE_PARAMETERS_START() takes two arguments minimal and maximal parameters count.
ZEND_PARSE_PARAMETERS_START(2, 7)
Z_PARAM_LONG(pwbo)
Z_PARAM_STRING(str,str_len)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_OR_NULL(zparam)
Z_PARAM_LONG_OR_NULL(where, where_isnull)
Z_PARAM_LONG_OR_NULL(img1, img1_isnull)
Z_PARAM_LONG_OR_NULL(img2, img2_isnull)
Z_PARAM_LONG_OR_NULL(insertiontype, insertiontype_isnull)
ZEND_PARSE_PARAMETERS_END();
if (!wbIsWBObj((void *)pwbo, TRUE))
RETURN_NULL();
/* wb_create_items value only integer|null or adress possible, otherwise we need to allocate memory ! GYW */
switch (Z_TYPE_P(zparam))
{
case IS_NULL: // Do not change lparam
lparam = 0;
setlparam = FALSE;
break;
default:
lparam = Z_LVAL_P(zparam);
setlparam = TRUE;
break;
}
wcs = Utf82WideChar(str, str_len);
switch (insertiontype)
{
case 0: // 'where' is the level of insertion
default:
ret = (LONG_PTR)wbAddTreeViewItemLevel((PWBOBJ)pwbo, where, wcs, lparam, setlparam, img1, img2);
break;
case 1: // 'where' is the sibling of the new node
ret = (LONG_PTR)wbAddTreeViewItemSibling((PWBOBJ)pwbo, (HTREEITEM)where, wcs, lparam, setlparam, img1, img2);
break;
case 2: // 'where' is the parent of the new node
ret = (LONG_PTR)wbAddTreeViewItemChild((PWBOBJ)pwbo, (HTREEITEM)where, wcs, lparam, setlparam, img1, img2);
break;
}
RETURN_LONG(ret);
}
//------------------------------------------------------------------ END OF FILE