This repository has been archived by the owner on Jan 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
phpwb_control_treeview.c
202 lines (151 loc) · 4.81 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
/*******************************************************************************
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 treeview control
*******************************************************************************/
//----------------------------------------------------------------- DEPENDENCIES
#include "phpwb.h"
//---------------------------------------------------------- EXTERNAL PROTOTYPES
extern UINT wbGetTreeViewItemLevel(PWBOBJ pwbo, HTREEITEM hItem);
//----------------------------------------------------------- EXPORTED FUNCTIONS
/* Returns the level of a node in a treeview */
ZEND_FUNCTION(wb_get_level)
{
LONG pwbo, item = 0;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"ll", &pwbo, &item) == FAILURE)
return;
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(wbtemp_set_treeview_item_selected)
{
LONG pwbo, item;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"ll", &pwbo, &item) == FAILURE)
return;
if(!wbIsWBObj((void *)pwbo, TRUE))
RETURN_NULL()
RETURN_BOOL(wbSetTreeViewItemSelected((PWBOBJ)pwbo, (HTREEITEM)item));
}
ZEND_FUNCTION(wbtemp_set_treeview_item_text)
{
LONG pwbo, item;
char *s;
int s_len;
TCHAR *wcs = 0;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"lls", &pwbo, &item, &s, &s_len) == FAILURE)
return;
if(!wbIsWBObj((void *)pwbo, TRUE))
RETURN_NULL()
wcs = Utf82WideChar(s, s_len);
RETURN_BOOL(wbSetTreeViewItemText((PWBOBJ)pwbo, (HTREEITEM)item, wcs));
}
ZEND_FUNCTION(wbtemp_get_treeview_item_text)
{
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)
return;
if(!wbIsWBObj((void *)pwbo, TRUE))
RETURN_NULL()
wbGetTreeViewItemText((PWBOBJ)pwbo, (HTREEITEM)item, szItem, MAX_ITEM_STRING - 1);
str = WideChar2Utf8(szItem, &str_len);
RETURN_STRING(str, TRUE)
}
/*
Change the item value.
If zparam is NULL, does not change associated value (does nothing).
*/
ZEND_FUNCTION(wbtemp_set_treeview_item_value)
{
LONG pwbo, item, lparam = 0;
zval *zparam, *zcopy;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"llz!", &pwbo, &item, &zparam) == FAILURE)
return;
if(!wbIsWBObj((void *)pwbo, TRUE))
RETURN_NULL()
switch(zparam->type) {
case IS_NULL: // Do not change lparam
lparam = 0;
break;
case IS_BOOL:
case IS_LONG:
case IS_STRING:
default:
// ****** Possible leak: Should free the existing copy of zparam here, if any
ALLOC_ZVAL(zcopy); // Create a copy of zparam
*zcopy = *zparam;
zval_copy_ctor(zcopy);
lparam = (LONG)zcopy;
break;
}
RETURN_BOOL(wbSetTreeViewItemValue((PWBOBJ)pwbo, (HTREEITEM)item, lparam));
}
/*
int wbtemp_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(wbtemp_create_treeview_item)
{
LONG pwbo, where = 0, img1 = -1, img2 = -1, insertiontype = 0;
char *str;
int str_len, lparam = 0;
zval *zparam = NULL, *zcopy;
BOOL setlparam = FALSE;
TCHAR *wcs = 0;
LONG ret;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"ls|zllll", &pwbo, &str, &str_len, &zparam, &where, &img1, &img2, &insertiontype) == FAILURE)
return;
if(!wbIsWBObj((void *)pwbo, TRUE))
RETURN_NULL()
switch(zparam->type) {
case IS_NULL: // Do not change lparam
lparam = 0;
setlparam = FALSE;
break;
case IS_BOOL:
case IS_LONG:
case IS_STRING:
default:
// ****** Possible leak: Should free the existing copy of zparam here, if any
ALLOC_ZVAL(zcopy); // Create a copy of zparam
*zcopy = *zparam;
zval_copy_ctor(zcopy);
lparam = (LONG)zcopy;
setlparam = TRUE;
break;
}
wcs = Utf82WideChar(str, str_len);
switch(insertiontype) {
case 0: // 'where' is the level of insertion
default:
ret = (LONG)wbAddTreeViewItemLevel((PWBOBJ)pwbo, where, wcs, lparam, setlparam, img1, img2);
break;
case 1: // 'where' is the sibling of the new node
ret = (LONG)wbAddTreeViewItemSibling((PWBOBJ)pwbo, (HTREEITEM)where, wcs, lparam, setlparam, img1, img2);
break;
case 2: // 'where' is the parent of the new node
ret = (LONG)wbAddTreeViewItemChild((PWBOBJ)pwbo, (HTREEITEM)where, wcs, lparam, setlparam, img1, img2);
break;
}
RETURN_LONG(ret);
}
//------------------------------------------------------------------ END OF FILE