Bearsampp 2025.8.29
Loading...
Searching...
No Matches
wb_windows.inc.php
Go to the documentation of this file.
1<?php
2
3/*******************************************************************************
4 *
5 * WINBINDER - The native Windows binding for PHP for PHP
6 *
7 * Copyright Hypervisual - see LICENSE.TXT for details
8 * Author: Rubem Pechansky (https://github.com/crispy-computing-machine/Winbinder)
9 *
10 * Refactor the below functions that begin with _ into your own Winbinder library
11 * Temp functions no longer exist.
12 *******************************************************************************/
13
14//------------------------------------------------------------- WINDOW FUNCTIONS
15
33if (!function_exists('wb_create_control')) {
34 function wb_create_control($parent, $class, $caption = "", $xpos = 0, $ypos = 0, $width = 0, $height = 0, $id = null, $style = 0, $lparam = null, $ntab = 0)
35 {
36 switch ($class) {
37 case Accel:
38 return wbtemp_set_accel_table($parent, $caption);
39
40 case ToolBar:
41 return wbtemp_create_toolbar($parent, $caption, $width, $height, $lparam);
42
43 case Menu:
44 return wbtemp_create_menu($parent, $caption);
45
46 case HyperLink:
47 return wbtemp_create_control(
48 $parent,
49 $class,
50 $caption,
51 $xpos,
52 $ypos,
53 $width,
54 $height,
55 $id,
56 $style,
57 is_null($lparam) ? NOCOLOR : $lparam,
58 $ntab
59 );
60
61 case ComboBox:
62 case ListBox:
63 case ListView:
64 $ctrl = wbtemp_create_control($parent, $class, $caption, $xpos, $ypos, $width, $height, $id, $style, $lparam, $ntab);
65 if (is_array($caption)) {
66 wb_set_text($ctrl, $caption[0]);
67 }
68
69 return $ctrl;
70
71 case TreeView:
72 $ctrl = wbtemp_create_control($parent, $class, $caption, $xpos, $ypos, $width, $height, $id, $style, $lparam, $ntab);
73 if (is_array($caption)) {
74 wb_set_text($ctrl, $caption[0]);
75 }
76
77 return $ctrl;
78
79 case Gauge:
80 case Slider:
81 case ScrollBar:
82 $ctrl = wbtemp_create_control($parent, $class, $caption, $xpos, $ypos, $width, $height, $id, $style, $lparam, $ntab);
83 if ($lparam) {
84 wb_set_value($ctrl, $lparam);
85 }
86
87 return $ctrl;
88
89 default:
90 return wbtemp_create_control($parent, $class, $caption, $xpos, $ypos, $width, $height, $id, $style, $lparam, $ntab);
91 }
92 }
93}
94
104if (!function_exists('wb_set_value')) {
105 function wb_set_value($ctrl, $value, $item = null)
106 {
107 if (!$ctrl) {
108 return null;
109 }
110
111 $class = wb_get_class($ctrl);
112 switch ($class) {
113 case ListView: // Array with items to be checked
114
115 if ($value === null) {
116 break;
117 } elseif (is_string($value) && strstr($value, ",")) {
118 $values = explode(",", $value);
119 } elseif (!is_array($value)) {
120 $values = array($value);
121 } else {
122 $values = $value;
123 }
124 foreach ($values as $index) {
125 wbtemp_set_listview_item_checked($ctrl, $index, 1);
126 }
127 break;
128
129 case TreeView: // Array with items to be checked
130
131 if ($item === null) {
132 $item = wbtemp_get_selected($ctrl);
133 }
134
135 return wbtemp_set_treeview_item_value($ctrl, $item, $value);
136
137 default:
138
139 if ($value !== null) {
140 return wbtemp_set_value($ctrl, $value, $item);
141 }
142 }
143 }
144}
145
146
156if (!function_exists('wb_get_text')) {
157 function wb_get_text($ctrl, $item = null, $subitem = null)
158 {
159 if (!$ctrl) {
160 return null;
161 }
162
163 if (wb_get_class($ctrl) == ListView) {
164 if ($item !== null) { // Valid item
165
166 $line = wbtemp_get_listview_text($ctrl, $item);
167 if ($subitem === null) {
168 return $line;
169 } else {
170 return $line[$subitem];
171 }
172 } else { // NULL item
173
174 $sel = wb_get_selected($ctrl);
175 if ($sel === null) { // Returns the entire table
176 $items = array();
177 for ($i = 0; ; $i++) {
178 $item = wbtemp_get_listview_text($ctrl, $i);
179 $all = implode('', $item);
180 if ($all == '') {
181 break;
182 }
183 $items[] = $item;
184 }
185
186 return $items ? $items : null;
187 } else {
188 $items = array();
189 foreach ($sel as $row) {
190 $items[] = wbtemp_get_listview_text($ctrl, $row);
191 }
192
193 return $items ? $items : null;
194 }
195 }
196 } elseif (wb_get_class($ctrl) == TreeView) {
197 if ($item) {
198 return wbtemp_get_treeview_item_text($ctrl, $item);
199 } else {
200 $sel = wb_get_selected($ctrl);
201 if ($sel === null) {
202 return null;
203 } else {
204 return wbtemp_get_text($ctrl);
205 }
206 }
207 } elseif (wb_get_class($ctrl) == ComboBox) {
208 return wbtemp_get_text($ctrl, $item === null ? -1 : $item);
209 } elseif (wb_get_class($ctrl) == ListBox) {
210 return wbtemp_get_text($ctrl, $item === null ? -1 : $item);
211 } else {
212 return wbtemp_get_text($ctrl, $item);
213 }
214 }
215}
216
230if (!function_exists('wb_set_text')) {
231 function wb_set_text($ctrl, $text, $item = null, $subitem = null)
232 {
233 if (!$ctrl) {
234 return null;
235 }
236
237 switch (wb_get_class($ctrl)) {
238 case ListView:
239
240 if ($item !== null) {
241 if (!is_array($text) && $subitem !== null) {
242 // Set text of a ListView cell according to $item and $subitem
243
244 wbtemp_set_listview_item_text($ctrl, $item, $subitem, $text);
245 } else {
246 // Set text of several ListView cells, ignoring $subitem
247
248 for ($sub = 0; $sub < count($text); $sub++) {
249 if ($text) {
250 if (($text[$sub] !== null)) {
251 wbtemp_set_listview_item_text($ctrl, $item, $sub, (string)$text[$sub]);
252 }
253 } else {
254 wbtemp_set_listview_item_text($ctrl, $item, $sub, "");
255 }
256 }
257 }
258 } else {
259 if (!is_array($text)) {
260 $text = explode(",", $text);
261 }
262
263 wb_delete_items($ctrl, null);
264
265 if (!$item) {
266 wbtemp_clear_listview_columns($ctrl);
267
268 // Create column headers
269 // In the loop below, passing -1 as the 'width' argument of wbtemp_create_listview_column()
270 // makes it calculate the column width automatically
271
272 for ($i = 0; $i < count($text); $i++) {
273 if (is_array($text[$i])) {
274 wbtemp_create_listview_column(
275 $ctrl,
276 $i,
277 (string)$text[$i][0],
278 isset($text[$i][1]) ? (int)$text[$i][1] : -1,
279 isset($text[$i][2]) ? (int)$text[$i][2] : WBC_LEFT
280 );
281 } else {
282 wbtemp_create_listview_column(
283 $ctrl,
284 $i,
285 (string)$text[$i],
286 -1,
287 0
288 );
289 }
290 }
291 }
292 }
293 break;
294
295 case ListBox:
296
297 if (!$text) {
298 wb_delete_items($ctrl);
299 } elseif (is_string($text)) {
300 if (strchr($text, "\r") || strchr($text, "\n")) {
301 $text = preg_split("/[\r\n,]/", $text);
302 wb_delete_items($ctrl);
303 foreach ($text as $str) {
304 wbtemp_create_item($ctrl, (string)$str);
305 }
306 } else {
307 $index = wb_send_message($ctrl, LB_FINDSTRINGEXACT, -1, wb_get_address($text));
308 wb_send_message($ctrl, LB_SETCURSEL, $index, 0);
309 }
310 } elseif (is_array($text)) {
311 wb_delete_items($ctrl);
312 foreach ($text as $str) {
313 wbtemp_create_item($ctrl, (string)$str);
314 }
315 }
316
317 return;
318
319 case ComboBox:
320
321 if (!$text) {
322 wb_delete_items($ctrl);
323 } elseif (is_string($text)) {
324 if (strchr($text, "\r") || strchr($text, "\n")) {
325 $text = preg_split("/[\r\n,]/", $text);
326 wb_delete_items($ctrl);
327 foreach ($text as $str) {
328 wbtemp_create_item($ctrl, (string)$str);
329 }
330 } else {
331 $index = wb_send_message($ctrl, CB_FINDSTRINGEXACT, -1, wb_get_address($text));
332 wb_send_message($ctrl, CB_SETCURSEL, $index, 0);
333 if ($index == -1) {
334 wb_send_message($ctrl, WM_SETTEXT, 0, wb_get_address($text));
335 }
336 }
337 } elseif (is_array($text)) {
338 wb_delete_items($ctrl);
339 foreach ($text as $str) {
340 wbtemp_create_item($ctrl, (string)$str);
341 }
342 }
343
344 return;
345
346 case TreeView:
347
348 if ($item) {
349 return wbtemp_set_treeview_item_text($ctrl, $item, $text);
350 } else {
351 return wb_create_items($ctrl, $text, true);
352 }
353
354 default:
355 // The (string) cast below works well but is a temporary fix, must be
356 // removed when wbtemp_set_text() accepts numeric types correctly
357 if (is_array($text)) {
358 return wbtemp_set_text($ctrl, $text, $item);
359 } else {
360 return wbtemp_set_text($ctrl, (string)$text, $item);
361 }
362 }
363 }
364}
365
375if (!function_exists('wb_set_selected')) {
376 function wb_set_selected($ctrl, $selitems = 0, $selected = true)
377 {
378 switch (wb_get_class($ctrl)) {
379 case ComboBox:
380 wb_send_message($ctrl, CB_SETCURSEL, (int)$selitems, 0);
381 break;
382
383 case ListBox:
384 wb_send_message($ctrl, LB_SETCURSEL, (int)$selitems, 0);
385 break;
386
387 case ListView:
388
389 if (is_null($selitems)) {
390 return wbtemp_select_all_listview_items($ctrl, false);
391 } elseif (is_array($selitems)) {
392 foreach ($selitems as $item) {
393 wbtemp_select_listview_item($ctrl, $item, $selected);
394 }
395
396 return true;
397 } else {
398 return wbtemp_select_listview_item($ctrl, $selitems, $selected);
399 }
400 break;
401
402 case Menu:
403 return wbtemp_set_menu_item_checked($ctrl, $selitems, $selected);
404
405 case TabControl:
406 wbtemp_select_tab($ctrl, (int)$selitems);
407 break;
408
409 case TreeView:
410 wbtemp_set_treeview_item_selected($ctrl, $selitems);
411 break;
412
413 default:
414 return false;
415 }
416
417 return true;
418 }
419}
420
431if (!function_exists('wb_create_items')) {
432 function wb_create_items($ctrl, $items, $clear = false, $param = null)
433 {
434 switch (wb_get_class($ctrl)) {
435 case ListView:
436
437 if ($clear) {
438 wb_send_message($ctrl, LVM_DELETEALLITEMS, 0, 0);
439 }
440
441 $last = -1;
442
443 // For each row
444
445 for ($i = 0; $i < count($items); $i++) {
446 if (!is_scalar($items[$i])) {
447 $last = wbtemp_create_listview_item(
448 $ctrl,
449 -1,
450 -1,
451 (string)$items[$i][0]
452 );
453 } else {
454 $last = wbtemp_create_listview_item(
455 $ctrl,
456 -1,
457 -1,
458 (string)$items[$i]
459 );
460 }
461 wbtemp_set_listview_item_text($ctrl, -1, 0, (string)$items[$i][0]);
462
463 // For each column except the first
464
465 for ($sub = 0; $sub < count($items[$i]) - 1; $sub++) {
466 if ($param) {
467 $result = call_user_func(
468 $param, // Callback function
469 $items[$i][$sub + 1], // Item value
470 $i, // Row
471 $sub // Column
472 );
473 wbtemp_set_listview_item_text($ctrl, $last, $sub + 1, $result);
474 } else {
475 wbtemp_set_listview_item_text($ctrl, $last, $sub + 1, (string)$items[$i][$sub + 1]);
476 }
477 }
478 }
479
480 return $last;
481 break;
482
483 case TreeView:
484
485 if ($clear) {
486 $handle = wb_delete_items($ctrl);
487 } // Empty the treeview
488
489 if (!$items) {
490 break;
491 }
492 $ret = array();
493 for ($i = 0; $i < count($items); $i++) {
494 $ret[] = wbtemp_create_treeview_item(
495 $ctrl,
496 (string)$items[$i][0], // Name
497 isset($items[$i][1]) ? $items[$i][1] : 0, // Value
498 isset($items[$i][2]) ? $items[$i][2] : 0, // Where
499 isset($items[$i][3]) ? $items[$i][3] : -1, // ImageIndex
500 isset($items[$i][4]) ? $items[$i][4] : -1, // SelectedImageIndex
501 isset($items[$i][5]) ? $items[$i][5] : 0 // InsertionType
502 );
503 }
504
505 return (count($ret) > 1 ? $ret : $ret[0]);
506 break;
507
508 case StatusBar:
509 wbtemp_create_statusbar_items($ctrl, $items, $clear, $param);
510 foreach ($items as $item) {
511 wb_set_text($ctrl, $item[0], key($item));
512 }
513
514 return true;
515
516 default:
517
518 if (is_array($items)) {
519 foreach ($items as $item) {
520 wbtemp_create_item($ctrl, $item);
521 }
522
523 return true;
524 } else {
525 return wbtemp_create_item($ctrl, $items);
526 }
527 break;
528 }
529 }
530}
531
544 if (!function_exists('wb_sys_dlg_open')) {
545 function wb_sys_dlg_open($parent = null, $title = null, $filter = null, $path = null, $filename = null, $flags = null)
546 {
547 $filter = _make_file_filter($filter ? $filter : $filename);
548
549 return wbtemp_sys_dlg_open($parent, $title, $filter, $path, $flags);
550 }
551 }
552
565 if (!function_exists('wb_sys_dlg_save')) {
566 function wb_sys_dlg_save($parent = null, $title = null, $filter = null, $path = null, $filename = null, $defext = null)
567 {
568 $filter = _make_file_filter($filter ? $filter : $filename);
569
570 return wbtemp_sys_dlg_save($parent, $title, $filter, $path, $filename, $defext);
571 }
572 }
573
574//----------------------------------------- AUXILIARY FUNCTIONS FOR INTERNAL USE
575
583 if (!function_exists('_make_file_filter')) {
584 function _make_file_filter($filter)
585 {
586 if (!$filter) {
587 return "All Files (*.*)\0*.*\0\0";
588 }
589
590 if (is_array($filter)) {
591 $result = "";
592 foreach ($filter as $line) {
593 $result .= "$line[0] ($line[1])\0$line[1]\0";
594 }
595 $result .= "\0";
596
597 return $result;
598 } else {
599 return $filter;
600 }
601 }
602 }
$result