2024.8.23
Loading...
Searching...
No Matches
class.winbinder.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Class WinBinder
12 *
13 * This class provides an interface to the WinBinder library, allowing for the creation and management
14 * of Windows GUI elements in PHP. It includes methods for creating windows, controls, handling events,
15 * and executing system commands.
16 */
18{
19 // Constants for control IDs and objects
20 const CTRL_ID = 0;
21 const CTRL_OBJ = 1;
22
23 // Constants for progress bar increment and new line
24 const INCR_PROGRESS_BAR = '++';
25 const NEW_LINE = '@nl@';
26
27 // Constants for message box types
28 const BOX_INFO = WBC_INFO;
29 const BOX_OK = WBC_OK;
30 const BOX_OKCANCEL = WBC_OKCANCEL;
31 const BOX_QUESTION = WBC_QUESTION;
32 const BOX_ERROR = WBC_STOP;
33 const BOX_WARNING = WBC_WARNING;
34 const BOX_YESNO = WBC_YESNO;
35 const BOX_YESNOCANCEL = WBC_YESNOCANCEL;
36
37 // Constants for cursor types
38 const CURSOR_ARROW = 'arrow';
39 const CURSOR_CROSS = 'cross';
40 const CURSOR_FINGER = 'finger';
41 const CURSOR_FORBIDDEN = 'forbidden';
42 const CURSOR_HELP = 'help';
43 const CURSOR_IBEAM = 'ibeam';
44 const CURSOR_NONE = null;
45 const CURSOR_SIZEALL = 'sizeall';
46 const CURSOR_SIZENESW = 'sizenesw';
47 const CURSOR_SIZENS = 'sizens';
48 const CURSOR_SIZENWSE = 'sizenwse';
49 const CURSOR_SIZEWE = 'sizewe';
50 const CURSOR_UPARROW = 'uparrow';
51 const CURSOR_WAIT = 'wait';
52 const CURSOR_WAITARROW = 'waitarrow';
53
54 // Constants for system information types
55 const SYSINFO_SCREENAREA = 'screenarea';
56 const SYSINFO_WORKAREA = 'workarea';
57
59 private $countCtrls;
60
61 public $callback;
62 public $gauge;
63
64 /**
65 * WinBinder constructor.
66 *
67 * Initializes the WinBinder class, sets the default window title, and resets control counters.
68 */
69 public function __construct()
70 {
71 global $bearsamppCore;
72 Util::logInitClass( $this );
73
74 $this->defaultTitle = APP_TITLE . ' ' . $bearsamppCore->getAppVersion();
75 $this->reset();
76 }
77
78 /**
79 * Writes a log message to the WinBinder log file.
80 *
81 * @param string $log The log message to write.
82 */
83 private static function writeLog($log)
84 {
85 global $bearsamppRoot;
86 Util::logDebug( $log, $bearsamppRoot->getWinbinderLogFilePath() );
87 }
88
89 /**
90 * Resets the control counter and callback array.
91 */
92 public function reset()
93 {
94 $this->countCtrls = 1000;
95 $this->callback = array();
96 }
97
98 /**
99 * Calls a WinBinder function with the specified parameters.
100 *
101 * @param string $function The name of the WinBinder function to call.
102 * @param array $params The parameters to pass to the function.
103 * @param bool $removeErrorHandler Whether to remove the error handler during the call.
104 *
105 * @return mixed The result of the function call.
106 */
107 private function callWinBinder($function, $params = array(), $removeErrorHandler = false)
108 {
109 $result = false;
110 if ( function_exists( $function ) ) {
111 if ( $removeErrorHandler ) {
112 $result = @call_user_func_array( $function, $params );
113 }
114 else {
115 $result = call_user_func_array( $function, $params );
116 }
117 }
118
119 return $result;
120 }
121
122 /**
123 * Creates a new window.
124 *
125 * @param mixed $parent The parent window or null for a top-level window.
126 * @param string $wclass The window class.
127 * @param string $caption The window caption.
128 * @param int $xPos The x-coordinate of the window.
129 * @param int $yPos The y-coordinate of the window.
130 * @param int $width The width of the window.
131 * @param int $height The height of the window.
132 * @param mixed $style The window style.
133 * @param mixed $params Additional parameters for the window.
134 *
135 * @return mixed The created window object.
136 */
137 public function createWindow($parent, $wclass, $caption, $xPos, $yPos, $width, $height, $style = null, $params = null)
138 {
139 global $bearsamppCore;
140
141 $caption = empty( $caption ) ? $this->defaultTitle : $this->defaultTitle . ' - ' . $caption;
142 $window = $this->callWinBinder( 'wb_create_window', array($parent, $wclass, $caption, $xPos, $yPos, $width, $height, $style, $params) );
143
144 // Set tiny window icon
145 $this->setImage( $window, $bearsamppCore->getResourcesPath() . '/homepage/img/icons/app.ico' );
146
147 return $window;
148 }
149
150 /**
151 * Creates a new control.
152 *
153 * @param mixed $parent The parent window or control.
154 * @param string $ctlClass The control class.
155 * @param string $caption The control caption.
156 * @param int $xPos The x-coordinate of the control.
157 * @param int $yPos The y-coordinate of the control.
158 * @param int $width The width of the control.
159 * @param int $height The height of the control.
160 * @param mixed $style The control style.
161 * @param mixed $params Additional parameters for the control.
162 *
163 * @return array An array containing the control ID and object.
164 */
165 public function createControl($parent, $ctlClass, $caption, $xPos, $yPos, $width, $height, $style = null, $params = null)
166 {
167 $this->countCtrls++;
168
169 return array(
170 self::CTRL_ID => $this->countCtrls,
171 self::CTRL_OBJ => $this->callWinBinder( 'wb_create_control', array(
172 $parent, $ctlClass, $caption, $xPos, $yPos, $width, $height, $this->countCtrls, $style, $params
173 ) ),
174 );
175 }
176
177 /**
178 * Creates a new application window.
179 *
180 * @param string $caption The window caption.
181 * @param int $width The width of the window.
182 * @param int $height The height of the window.
183 * @param mixed $style The window style.
184 * @param mixed $params Additional parameters for the window.
185 *
186 * @return mixed The created window object.
187 */
188 public function createAppWindow($caption, $width, $height, $style = null, $params = null)
189 {
190 return $this->createWindow( null, AppWindow, $caption, WBC_CENTER, WBC_CENTER, $width, $height, $style, $params );
191 }
192
193 /**
194 * Creates a new naked window.
195 *
196 * @param string $caption The window caption.
197 * @param int $width The width of the window.
198 * @param int $height The height of the window.
199 * @param mixed $style The window style.
200 * @param mixed $params Additional parameters for the window.
201 *
202 * @return mixed The created window object.
203 */
204 public function createNakedWindow($caption, $width, $height, $style = null, $params = null)
205 {
206 $window = $this->createWindow( null, NakedWindow, $caption, WBC_CENTER, WBC_CENTER, $width, $height, $style, $params );
207 $this->setArea( $window, $width, $height );
208
209 return $window;
210 }
211
212 /**
213 * Destroys a window.
214 *
215 * @param mixed $window The window object to destroy.
216 */
217 public function destroyWindow($window)
218 {
219 $this->callWinBinder( 'wb_destroy_window', array($window), true );
220 exit();
221 }
222
223 /**
224 * Starts the main event loop.
225 *
226 * @return mixed The result of the main loop.
227 */
228 public function mainLoop()
229 {
230 return $this->callWinBinder( 'wb_main_loop' );
231 }
232
233 /**
234 * Refreshes a WinBinder object.
235 *
236 * @param mixed $wbobject The WinBinder object to refresh.
237 *
238 * @return mixed The result of the refresh operation.
239 */
240 public function refresh($wbobject)
241 {
242 return $this->callWinBinder( 'wb_refresh', array($wbobject, true) );
243 }
244
245 /**
246 * Retrieves system information.
247 *
248 * @param string $info The type of system information to retrieve.
249 *
250 * @return mixed The retrieved system information.
251 */
252 public function getSystemInfo($info)
253 {
254 return $this->callWinBinder( 'wb_get_system_info', array($info) );
255 }
256
257 /**
258 * Draws an image on a WinBinder object.
259 *
260 * @param mixed $wbobject The WinBinder object to draw on.
261 * @param string $path The path to the image file.
262 * @param int $xPos The x-coordinate of the image.
263 * @param int $yPos The y-coordinate of the image.
264 * @param int $width The width of the image.
265 * @param int $height The height of the image.
266 *
267 * @return mixed The result of the draw operation.
268 */
269 public function drawImage($wbobject, $path, $xPos = 0, $yPos = 0, $width = 0, $height = 0)
270 {
271 $image = $this->callWinBinder( 'wb_load_image', array($path) );
272
273 return $this->callWinBinder( 'wb_draw_image', array($wbobject, $image, $xPos, $yPos, $width, $height) );
274 }
275
276 /**
277 * Draws text on a WinBinder object.
278 *
279 * @param mixed $parent The parent WinBinder object.
280 * @param string $caption The text to draw.
281 * @param int $xPos The x-coordinate of the text.
282 * @param int $yPos The y-coordinate of the text.
283 * @param int|null $width The width of the text area.
284 * @param int|null $height The height of the text area.
285 * @param mixed $font The font to use for the text.
286 *
287 * @return mixed The result of the draw operation.
288 */
289 public function drawText($parent, $caption, $xPos, $yPos, $width = null, $height = null, $font = null)
290 {
291 $caption = str_replace( self::NEW_LINE, PHP_EOL, $caption );
292 $width = $width == null ? 120 : $width;
293 $height = $height == null ? 25 : $height;
294
295 return $this->callWinBinder( 'wb_draw_text', array($parent, $caption, $xPos, $yPos, $width, $height, $font) );
296 }
297
298 /**
299 * Draws a rectangle on a WinBinder object.
300 *
301 * @param mixed $parent The parent WinBinder object.
302 * @param int $xPos The x-coordinate of the rectangle.
303 * @param int $yPos The y-coordinate of the rectangle.
304 * @param int $width The width of the rectangle.
305 * @param int $height The height of the rectangle.
306 * @param int $color The color of the rectangle.
307 * @param bool $filled Whether the rectangle should be filled.
308 *
309 * @return mixed The result of the draw operation.
310 */
311 public function drawRect($parent, $xPos, $yPos, $width, $height, $color = 15790320, $filled = true)
312 {
313 return $this->callWinBinder( 'wb_draw_rect', array($parent, $xPos, $yPos, $width, $height, $color, $filled) );
314 }
315
316 /**
317 * Draws a line on a WinBinder object.
318 *
319 * @param mixed $wbobject The WinBinder object to draw on.
320 * @param int $xStartPos The starting x-coordinate of the line.
321 * @param int $yStartPos The starting y-coordinate of the line.
322 * @param int $xEndPos The ending x-coordinate of the line.
323 * @param int $yEndPos The ending y-coordinate of the line.
324 * @param int $color The color of the line.
325 * @param int $height The height of the line.
326 *
327 * @return mixed The result of the draw operation.
328 */
329 public function drawLine($wbobject, $xStartPos, $yStartPos, $xEndPos, $yEndPos, $color, $height = 1)
330 {
331 return $this->callWinBinder( 'wb_draw_line', array($wbobject, $xStartPos, $yStartPos, $xEndPos, $yEndPos, $color, $height) );
332 }
333
334 /**
335 * Creates a font for use in WinBinder controls.
336 *
337 * @param string $fontName The name of the font.
338 * @param int|null $size The size of the font.
339 * @param int|null $color The color of the font.
340 * @param mixed $style The style of the font.
341 *
342 * @return mixed The created font object.
343 */
344 public function createFont($fontName, $size = null, $color = null, $style = null)
345 {
346 return $this->callWinBinder( 'wb_create_font', array($fontName, $size, $color, $style) );
347 }
348
349 /**
350 * Waits for an event on a WinBinder object.
351 *
352 * @param mixed $wbobject The WinBinder object to wait on.
353 *
354 * @return mixed The result of the wait operation.
355 */
356 public function wait($wbobject = null)
357 {
358 return $this->callWinBinder( 'wb_wait', array($wbobject), true );
359 }
360
361 /**
362 * Creates a timer for a WinBinder object.
363 *
364 * @param mixed $wbobject The WinBinder object to create the timer for.
365 * @param int $wait The wait time in milliseconds.
366 *
367 * @return array An array containing the timer ID and object.
368 */
369 public function createTimer($wbobject, $wait = 1000)
370 {
371 $this->countCtrls++;
372
373 return array(
374 self::CTRL_ID => $this->countCtrls,
375 self::CTRL_OBJ => $this->callWinBinder( 'wb_create_timer', array($wbobject, $this->countCtrls, $wait) )
376 );
377 }
378
379 /**
380 * Destroys a timer for a WinBinder object.
381 *
382 * @param mixed $wbobject The WinBinder object to destroy the timer for.
383 * @param mixed $timerobject The timer object to destroy.
384 *
385 * @return mixed The result of the destroy operation.
386 */
387 public function destroyTimer($wbobject, $timerobject)
388 {
389 return $this->callWinBinder( 'wb_destroy_timer', array($wbobject, $timerobject) );
390 }
391
392 /**
393 * Executes a system command.
394 *
395 * @param string $cmd The command to execute.
396 * @param string|null $params The parameters to pass to the command.
397 * @param bool $silent Whether to execute the command silently.
398 *
399 * @return mixed The result of the command execution.
400 */
401 public function exec($cmd, $params = null, $silent = false)
402 {
403 global $bearsamppCore;
404
405 if ( $silent ) {
406 $silent = '"' . $bearsamppCore->getScript( Core::SCRIPT_EXEC_SILENT ) . '" "' . $cmd . '"';
407 $cmd = 'wscript.exe';
408 $params = !empty( $params ) ? $silent . ' "' . $params . '"' : $silent;
409 }
410
411 $this->writeLog( 'exec: ' . $cmd . ' ' . $params );
412
413 return $this->callWinBinder( 'wb_exec', array($cmd, $params) );
414 }
415
416 /**
417 * Finds a file using WinBinder.
418 *
419 * @param string $filename The name of the file to find.
420 *
421 * @return mixed The result of the find operation.
422 */
423 public function findFile($filename)
424 {
425 $result = $this->callWinBinder( 'wb_find_file', array($filename) );
426 $this->writeLog( 'findFile ' . $filename . ': ' . $result );
427
428 return $result != $filename ? $result : false;
429 }
430
431 /**
432 * Sets an event handler for a WinBinder object.
433 *
434 * @param mixed $wbobject The WinBinder object to set the handler for.
435 * @param mixed $classCallback The class callback for the handler.
436 * @param mixed $methodCallback The method callback for the handler.
437 * @param mixed $launchTimer The timer to launch for the handler.
438 *
439 * @return mixed The result of the set handler operation.
440 */
441 public function setHandler($wbobject, $classCallback, $methodCallback, $launchTimer = null)
442 {
443 if ( $launchTimer != null ) {
444 $launchTimer = $this->createTimer( $wbobject, $launchTimer );
445 }
446
447 $this->callback[$wbobject] = array($classCallback, $methodCallback, $launchTimer);
448
449 return $this->callWinBinder( 'wb_set_handler', array($wbobject, '__winbinderEventHandler') );
450 }
451
452 /**
453 * Sets an image for a WinBinder object.
454 *
455 * @param mixed $wbobject The WinBinder object to set the image for.
456 * @param string $path The path to the image file.
457 *
458 * @return mixed The result of the set image operation.
459 */
460 public function setImage($wbobject, $path)
461 {
462 return $this->callWinBinder( 'wb_set_image', array($wbobject, $path) );
463 }
464
465 /**
466 * Sets the maximum length for a WinBinder object.
467 *
468 * @param mixed $wbobject The WinBinder object to set the maximum length for.
469 * @param int $length The maximum length to set.
470 *
471 * @return mixed The result of the set maximum length operation.
472 */
473 public function setMaxLength($wbobject, $length)
474 {
475 return $this->callWinBinder( 'wb_send_message', array($wbobject, 0x00c5, $length, 0) );
476 }
477
478 /**
479 * Sets the area of a WinBinder object.
480 *
481 * @param mixed $wbobject The WinBinder object to set the area for.
482 * @param int $width The width of the area.
483 * @param int $height The height of the area.
484 *
485 * @return mixed The result of the set area operation.
486 */
487 public function setArea($wbobject, $width, $height)
488 {
489 return $this->callWinBinder( 'wb_set_area', array($wbobject, WBC_TITLE, 0, 0, $width, $height) );
490 }
491
492 /**
493 * Retrieves the text from a WinBinder object.
494 *
495 * @param mixed $wbobject The WinBinder object to get the text from.
496 *
497 * @return mixed The retrieved text.
498 */
499 public function getText($wbobject)
500 {
501 return $this->callWinBinder( 'wb_get_text', array($wbobject) );
502 }
503
504 /**
505 * Sets the text for a WinBinder object.
506 *
507 * @param mixed $wbobject The WinBinder object to set the text for.
508 * @param string $content The text content to set.
509 *
510 * @return mixed The result of the set text operation.
511 */
512 public function setText($wbobject, $content)
513 {
514 $content = str_replace( self::NEW_LINE, PHP_EOL, $content );
515
516 return $this->callWinBinder( 'wb_set_text', array($wbobject, $content) );
517 }
518
519 /**
520 * Retrieves the value from a WinBinder object.
521 *
522 * @param mixed $wbobject The WinBinder object to get the value from.
523 *
524 * @return mixed The retrieved value.
525 */
526 public function getValue($wbobject)
527 {
528 return $this->callWinBinder( 'wb_get_value', array($wbobject) );
529 }
530
531 /**
532 * Sets the value for a WinBinder object.
533 *
534 * @param mixed $wbobject The WinBinder object to set the value for.
535 * @param mixed $content The value to set.
536 *
537 * @return mixed The result of the set value operation.
538 */
539 public function setValue($wbobject, $content)
540 {
541 return $this->callWinBinder( 'wb_set_value', array($wbobject, $content) );
542 }
543
544 /**
545 * Retrieves the focus from a WinBinder object.
546 *
547 * @return mixed The WinBinder object that has the focus.
548 */
549 public function getFocus()
550 {
551 return $this->callWinBinder( 'wb_get_focus' );
552 }
553
554 /**
555 * Sets the focus to a WinBinder object.
556 *
557 * @param mixed $wbobject The WinBinder object to set the focus to.
558 *
559 * @return mixed The result of the set focus operation.
560 */
561 public function setFocus($wbobject)
562 {
563 return $this->callWinBinder( 'wb_set_focus', array($wbobject) );
564 }
565
566 /**
567 * Sets the cursor type for a WinBinder object.
568 *
569 * @param mixed $wbobject The WinBinder object to set the cursor for.
570 * @param string $type The cursor type to set.
571 *
572 * @return mixed The result of the set cursor operation.
573 */
574 public function setCursor($wbobject, $type = self::CURSOR_ARROW)
575 {
576 return $this->callWinBinder( 'wb_set_cursor', array($wbobject, $type) );
577 }
578
579 /**
580 * Checks if a WinBinder object is enabled.
581 *
582 * @param mixed $wbobject The WinBinder object to check.
583 *
584 * @return mixed True if the object is enabled, false otherwise.
585 */
586 public function isEnabled($wbobject)
587 {
588 return $this->callWinBinder( 'wb_get_enabled', array($wbobject) );
589 }
590
591 /**
592 * Sets the enabled state for a WinBinder object.
593 *
594 * @param mixed $wbobject The WinBinder object to set the enabled state for.
595 * @param bool $enabled True to enable the object, false to disable it.
596 *
597 * @return mixed The result of the set enabled state operation.
598 */
599 public function setEnabled($wbobject, $enabled = true)
600 {
601 return $this->callWinBinder( 'wb_set_enabled', array($wbobject, $enabled) );
602 }
603
604 /**
605 * Disables a WinBinder object.
606 *
607 * @param mixed $wbobject The WinBinder object to disable.
608 *
609 * @return mixed The result of the disable operation.
610 */
611 public function setDisabled($wbobject)
612 {
613 return $this->setEnabled( $wbobject, false );
614 }
615
616 /**
617 * Sets the style for a WinBinder object.
618 *
619 * @param mixed $wbobject The WinBinder object to set the style for.
620 * @param mixed $style The style to set.
621 *
622 * @return mixed The result of the set style operation.
623 */
624 public function setStyle($wbobject, $style)
625 {
626 return $this->callWinBinder( 'wb_set_style', array($wbobject, $style) );
627 }
628
629 /**
630 * Sets the range for a WinBinder object.
631 *
632 * @param mixed $wbobject The WinBinder object to set the range for.
633 * @param int $min The minimum value of the range.
634 * @param int $max The maximum value of the range.
635 *
636 * @return mixed The result of the set range operation.
637 */
638 public function setRange($wbobject, $min, $max)
639 {
640 return $this->callWinBinder( 'wb_set_range', array($wbobject, $min, $max) );
641 }
642
643 /**
644 * Opens a system dialog to select a path.
645 *
646 * @param mixed $parent The parent window for the dialog.
647 * @param string $title The title of the dialog.
648 * @param string|null $path The initial path for the dialog.
649 *
650 * @return mixed The selected path.
651 */
652 public function sysDlgPath($parent, $title, $path = null)
653 {
654 return $this->callWinBinder( 'wb_sys_dlg_path', array($parent, $title, $path) );
655 }
656
657 /**
658 * Opens a system dialog to open a file.
659 *
660 * @param mixed $parent The parent window for the dialog.
661 * @param string $title The title of the dialog.
662 * @param string|null $filter The file filter for the dialog.
663 * @param string|null $path The initial path for the dialog.
664 *
665 * @return mixed The selected file path.
666 */
667 public function sysDlgOpen($parent, $title, $filter = null, $path = null)
668 {
669 return $this->callWinBinder( 'wb_sys_dlg_open', array($parent, $title, $filter, $path) );
670 }
671
672 /**
673 * Creates a label control.
674 *
675 * @param mixed $parent The parent window or control.
676 * @param string $caption The caption for the label.
677 * @param int $xPos The x-coordinate of the label.
678 * @param int $yPos The y-coordinate of the label.
679 * @param int|null $width The width of the label.
680 * @param int|null $height The height of the label.
681 * @param mixed $style The style for the label.
682 * @param mixed $params Additional parameters for the label.
683 *
684 * @return array An array containing the control ID and object.
685 */
686 public function createLabel($parent, $caption, $xPos, $yPos, $width = null, $height = null, $style = null, $params = null)
687 {
688 $caption = str_replace( self::NEW_LINE, PHP_EOL, $caption );
689 $width = $width == null ? 120 : $width;
690 $height = $height == null ? 25 : $height;
691
692 return $this->createControl( $parent, Label, $caption, $xPos, $yPos, $width, $height, $style, $params );
693 }
694
695 /**
696 * Creates an input text control.
697 *
698 * @param mixed $parent The parent window or control.
699 * @param string $value The initial value for the input text.
700 * @param int $xPos The x-coordinate of the input text.
701 * @param int $yPos The y-coordinate of the input text.
702 * @param int|null $width The width of the input text.
703 * @param int|null $height The height of the input text.
704 * @param int|null $maxLength The maximum length of the input text.
705 * @param mixed $style The style for the input text.
706 * @param mixed $params Additional parameters for the input text.
707 *
708 * @return array An array containing the control ID and object.
709 */
710 public function createInputText($parent, $value, $xPos, $yPos, $width = null, $height = null, $maxLength = null, $style = null, $params = null)
711 {
712 $value = str_replace( self::NEW_LINE, PHP_EOL, $value );
713 $width = $width == null ? 120 : $width;
714 $height = $height == null ? 25 : $height;
715 $inputText = $this->createControl( $parent, EditBox, (string) $value, $xPos, $yPos, $width, $height, $style, $params );
716 if ( is_numeric( $maxLength ) && $maxLength > 0 ) {
717 $this->setMaxLength( $inputText[self::CTRL_OBJ], $maxLength );
718 }
719
720 return $inputText;
721 }
722
723 /**
724 * Creates an edit box control.
725 *
726 * @param mixed $parent The parent window or control.
727 * @param string $value The initial value for the edit box.
728 * @param int $xPos The x-coordinate of the edit box.
729 * @param int $yPos The y-coordinate of the edit box.
730 * @param int|null $width The width of the edit box.
731 * @param int|null $height The height of the edit box.
732 * @param mixed $style The style for the edit box.
733 * @param mixed $params Additional parameters for the edit box.
734 *
735 * @return array An array containing the control ID and object.
736 */
737 public function createEditBox($parent, $value, $xPos, $yPos, $width = null, $height = null, $style = null, $params = null)
738 {
739 $value = str_replace( self::NEW_LINE, PHP_EOL, $value );
740 $width = $width == null ? 540 : $width;
741 $height = $height == null ? 340 : $height;
742 $editBox = $this->createControl( $parent, RTFEditBox, (string) $value, $xPos, $yPos, $width, $height, $style, $params );
743
744 return $editBox;
745 }
746
747 /**
748 * Creates a hyperlink control.
749 *
750 * @param mixed $parent The parent window or control.
751 * @param string $caption The caption for the hyperlink.
752 * @param int $xPos The x-coordinate of the hyperlink.
753 * @param int $yPos The y-coordinate of the hyperlink.
754 * @param int|null $width The width of the hyperlink.
755 * @param int|null $height The height of the hyperlink.
756 * @param mixed $style The style for the hyperlink.
757 * @param mixed $params Additional parameters for the hyperlink.
758 *
759 * @return array An array containing the control ID and object.
760 */
761 public function createHyperLink($parent, $caption, $xPos, $yPos, $width = null, $height = null, $style = null, $params = null)
762 {
763 $caption = str_replace( self::NEW_LINE, PHP_EOL, $caption );
764 $width = $width == null ? 120 : $width;
765 $height = $height == null ? 15 : $height;
766 $hyperLink = $this->createControl( $parent, HyperLink, (string) $caption, $xPos, $yPos, $width, $height, $style, $params );
767 $this->setCursor( $hyperLink[self::CTRL_OBJ], self::CURSOR_FINGER );
768
769 return $hyperLink;
770 }
771
772 /**
773 * Creates a radio button control.
774 *
775 * @param mixed $parent The parent window or control.
776 * @param string $caption The caption for the radio button.
777 * @param bool $checked Whether the radio button is checked.
778 * @param int $xPos The x-coordinate of the radio button.
779 * @param int $yPos The y-coordinate of the radio button.
780 * @param int|null $width The width of the radio button.
781 * @param int|null $height The height of the radio button.
782 * @param bool $startGroup Whether this radio button starts a new group.
783 *
784 * @return array An array containing the control ID and object.
785 */
786 public function createRadioButton($parent, $caption, $checked, $xPos, $yPos, $width = null, $height = null, $startGroup = false)
787 {
788 $caption = str_replace( self::NEW_LINE, PHP_EOL, $caption );
789 $width = $width == null ? 120 : $width;
790 $height = $height == null ? 25 : $height;
791
792 return $this->createControl( $parent, RadioButton, (string) $caption, $xPos, $yPos, $width, $height, $startGroup ? WBC_GROUP : null, $checked ? 1 : 0 );
793 }
794
795 /**
796 * Creates a button control.
797 *
798 * @param mixed $parent The parent window or control.
799 * @param string $caption The caption for the button.
800 * @param int $xPos The x-coordinate of the button.
801 * @param int $yPos The y-coordinate of the button.
802 * @param int|null $width The width of the button.
803 * @param int|null $height The height of the button.
804 * @param mixed $style The style for the button.
805 * @param mixed $params Additional parameters for the button.
806 *
807 * @return array An array containing the control ID and object.
808 */
809 public function createButton($parent, $caption, $xPos, $yPos, $width = null, $height = null, $style = null, $params = null)
810 {
811 $width = $width == null ? 80 : $width;
812 $height = $height == null ? 25 : $height;
813
814 return $this->createControl( $parent, PushButton, $caption, $xPos, $yPos, $width, $height, $style, $params );
815 }
816
817 /**
818 * Creates a progress bar control.
819 *
820 * @param mixed $parent The parent window or control.
821 * @param int $max The maximum value for the progress bar.
822 * @param int $xPos The x-coordinate of the progress bar.
823 * @param int $yPos The y-coordinate of the progress bar.
824 * @param int|null $width The width of the progress bar.
825 * @param int|null $height The height of the progress bar.
826 * @param mixed $style The style for the progress bar.
827 * @param mixed $params Additional parameters for the progress bar.
828 *
829 * @return array An array containing the control ID and object.
830 */
831 public function createProgressBar($parent, $max, $xPos, $yPos, $width = null, $height = null, $style = null, $params = null)
832 {
833 global $bearsamppLang;
834
835 $width = $width == null ? 200 : $width;
836 $height = $height == null ? 15 : $height;
837 $progressBar = $this->createControl( $parent, Gauge, $bearsamppLang->getValue( Lang::LOADING ), $xPos, $yPos, $width, $height, $style, $params );
838
839 $this->setRange( $progressBar[self::CTRL_OBJ], 0, $max );
840 $this->gauge[$progressBar[self::CTRL_OBJ]] = 0;
841
842 return $progressBar;
843 }
844
845 /**
846 * Increments the value of a progress bar.
847 *
848 * @param array $progressBar The progress bar control.
849 */
850 public function incrProgressBar($progressBar)
851 {
852 $this->setProgressBarValue( $progressBar, self::INCR_PROGRESS_BAR );
853 }
854
855 /**
856 * Resets the value of a progress bar to zero.
857 *
858 * @param array $progressBar The progress bar control.
859 */
860 public function resetProgressBar($progressBar)
861 {
862 $this->setProgressBarValue( $progressBar, 0 );
863 }
864
865 /**
866 * Sets the value of a progress bar.
867 *
868 * @param array $progressBar The progress bar control.
869 * @param mixed $value The value to set.
870 */
871 public function setProgressBarValue($progressBar, $value)
872 {
873 if ( $progressBar != null && isset( $progressBar[self::CTRL_OBJ] ) && isset( $this->gauge[$progressBar[self::CTRL_OBJ]] ) ) {
874 if ( strval( $value ) == self::INCR_PROGRESS_BAR ) {
875 $value = $this->gauge[$progressBar[self::CTRL_OBJ]] + 1;
876 }
877 if ( is_numeric( $value ) ) {
878 $this->gauge[$progressBar[self::CTRL_OBJ]] = $value;
879 $this->setValue( $progressBar[self::CTRL_OBJ], $value );
880 }
881 }
882 }
883
884 /**
885 * Sets the maximum value of a progress bar.
886 *
887 * @param array $progressBar The progress bar control.
888 * @param int $max The maximum value to set.
889 */
890 public function setProgressBarMax($progressBar, $max)
891 {
892 $this->setRange( $progressBar[self::CTRL_OBJ], 0, $max );
893 }
894
895 /**
896 * Displays a message box.
897 *
898 * @param string $message The message to display.
899 * @param int $type The type of message box.
900 * @param string|null $title The title of the message box.
901 *
902 * @return mixed The result of the message box operation.
903 */
904 public function messageBox($message, $type, $title = null)
905 {
906 global $bearsamppCore;
907
908 $message = str_replace( self::NEW_LINE, PHP_EOL, $message );
909 $messageBox = $this->callWinBinder( 'wb_message_box', array(
910 null, strlen( $message ) < 64 ? str_pad( $message, 64 ) : $message, // Pad message to display entire title
911 $title == null ? $this->defaultTitle : $this->defaultTitle . ' - ' . $title, $type
912 ) );
913
914 // TODO why does this create an error sometimes.
915 // Set tiny window icon
916 $this->setImage( $messageBox, $bearsamppCore->getResourcesPath() . '/homepage/img/icons/app.ico' );
917
918 return $messageBox;
919 }
920
921 /**
922 * Displays an informational message box.
923 *
924 * @param string $message The message to display.
925 * @param string|null $title The title of the message box.
926 *
927 * @return mixed The result of the message box operation.
928 */
929 public function messageBoxInfo($message, $title = null)
930 {
931 return $this->messageBox( $message, self::BOX_INFO, $title );
932 }
933
934 /**
935 * Displays an OK message box.
936 *
937 * @param string $message The message to display.
938 * @param string|null $title The title of the message box.
939 *
940 * @return mixed The result of the message box operation.
941 */
942 public function messageBoxOk($message, $title = null)
943 {
944 return $this->messageBox( $message, self::BOX_OK, $title );
945 }
946
947 /**
948 * Displays an OK/Cancel message box.
949 *
950 * @param string $message The message to display.
951 * @param string|null $title The title of the message box.
952 *
953 * @return mixed The result of the message box operation.
954 */
955 public function messageBoxOkCancel($message, $title = null)
956 {
957 return $this->messageBox( $message, self::BOX_OKCANCEL, $title );
958 }
959
960 /**
961 * Displays a question message box.
962 *
963 * @param string $message The message to display.
964 * @param string|null $title The title of the message box. If null, the default title will be used.
965 *
966 * @return mixed The result of the message box operation.
967 */
968 public function messageBoxQuestion($message, $title = null)
969 {
970 return $this->messageBox( $message, self::BOX_QUESTION, $title );
971 }
972
973 /**
974 * Displays an error message box.
975 *
976 * @param string $message The message to display.
977 * @param string|null $title The title of the message box. If null, the default title will be used.
978 *
979 * @return mixed The result of the message box operation.
980 */
981 public function messageBoxError($message, $title = null)
982 {
983 return $this->messageBox( $message, self::BOX_ERROR, $title );
984 }
985
986 /**
987 * Displays a warning message box.
988 *
989 * @param string $message The message to display.
990 * @param string|null $title The title of the message box. If null, the default title will be used.
991 *
992 * @return mixed The result of the message box operation.
993 */
994 public function messageBoxWarning($message, $title = null)
995 {
996 return $this->messageBox( $message, self::BOX_WARNING, $title );
997 }
998
999 /**
1000 * Displays a Yes/No message box.
1001 *
1002 * @param string $message The message to display.
1003 * @param string|null $title The title of the message box. If null, the default title will be used.
1004 *
1005 * @return mixed The result of the message box operation.
1006 */
1007 public function messageBoxYesNo($message, $title = null)
1008 {
1009 return $this->messageBox( $message, self::BOX_YESNO, $title );
1010 }
1011
1012 /**
1013 * Displays a Yes/No/Cancel message box.
1014 *
1015 * @param string $message The message to display.
1016 * @param string|null $title The title of the message box. If null, the default title will be used.
1017 *
1018 * @return mixed The result of the message box operation.
1019 */
1020 public function messageBoxYesNoCancel($message, $title = null)
1021 {
1022 return $this->messageBox( $message, self::BOX_YESNOCANCEL, $title );
1023 }
1024
1025}
1026
1027/**
1028 * Event handler for WinBinder events.
1029 *
1030 * This function is called by WinBinder when an event occurs. It retrieves the callback
1031 * associated with the window and executes it. If a timer is associated with the callback,
1032 * the timer is destroyed before executing the callback.
1033 *
1034 * @param mixed $window The window object where the event occurred.
1035 * @param int $id The ID of the event.
1036 * @param mixed $ctrl The control that triggered the event.
1037 * @param mixed $param1 The first parameter of the event.
1038 * @param mixed $param2 The second parameter of the event.
1039 */
1040function __winbinderEventHandler($window, $id, $ctrl, $param1, $param2)
1041{
1042 global $bearsamppWinbinder;
1043
1044 if ( $bearsamppWinbinder->callback[$window][2] != null ) {
1045 $bearsamppWinbinder->destroyTimer( $window, $bearsamppWinbinder->callback[$window][2][0] );
1046 }
1047
1048 call_user_func_array(
1049 array($bearsamppWinbinder->callback[$window][0], $bearsamppWinbinder->callback[$window][1]),
1050 array($window, $id, $ctrl, $param1, $param2)
1051 );
1052}
$result
global $bearsamppLang
global $bearsamppRoot
global $bearsamppCore
const SCRIPT_EXEC_SILENT
const LOADING
static logDebug($data, $file=null)
static logInitClass($classInstance)
exec($cmd, $params=null, $silent=false)
const CURSOR_SIZENS
sysDlgOpen($parent, $title, $filter=null, $path=null)
setHandler($wbobject, $classCallback, $methodCallback, $launchTimer=null)
static writeLog($log)
createNakedWindow($caption, $width, $height, $style=null, $params=null)
messageBoxYesNoCancel($message, $title=null)
createAppWindow($caption, $width, $height, $style=null, $params=null)
callWinBinder($function, $params=array(), $removeErrorHandler=false)
createEditBox($parent, $value, $xPos, $yPos, $width=null, $height=null, $style=null, $params=null)
incrProgressBar($progressBar)
messageBoxQuestion($message, $title=null)
createRadioButton($parent, $caption, $checked, $xPos, $yPos, $width=null, $height=null, $startGroup=false)
const CURSOR_WAITARROW
drawLine($wbobject, $xStartPos, $yStartPos, $xEndPos, $yEndPos, $color, $height=1)
setStyle($wbobject, $style)
sysDlgPath($parent, $title, $path=null)
const CURSOR_FORBIDDEN
messageBox($message, $type, $title=null)
setMaxLength($wbobject, $length)
const CURSOR_FINGER
refresh($wbobject)
createLabel($parent, $caption, $xPos, $yPos, $width=null, $height=null, $style=null, $params=null)
const CURSOR_UPARROW
createControl($parent, $ctlClass, $caption, $xPos, $yPos, $width, $height, $style=null, $params=null)
const CURSOR_SIZEWE
createButton($parent, $caption, $xPos, $yPos, $width=null, $height=null, $style=null, $params=null)
const CURSOR_SIZENESW
setText($wbobject, $content)
createTimer($wbobject, $wait=1000)
messageBoxInfo($message, $title=null)
createHyperLink($parent, $caption, $xPos, $yPos, $width=null, $height=null, $style=null, $params=null)
const SYSINFO_SCREENAREA
messageBoxOkCancel($message, $title=null)
createFont($fontName, $size=null, $color=null, $style=null)
setEnabled($wbobject, $enabled=true)
setFocus($wbobject)
const CURSOR_SIZENWSE
resetProgressBar($progressBar)
findFile($filename)
setProgressBarValue($progressBar, $value)
drawImage($wbobject, $path, $xPos=0, $yPos=0, $width=0, $height=0)
isEnabled($wbobject)
setArea($wbobject, $width, $height)
getText($wbobject)
drawText($parent, $caption, $xPos, $yPos, $width=null, $height=null, $font=null)
setImage($wbobject, $path)
const SYSINFO_WORKAREA
createProgressBar($parent, $max, $xPos, $yPos, $width=null, $height=null, $style=null, $params=null)
setValue($wbobject, $content)
setDisabled($wbobject)
setRange($wbobject, $min, $max)
messageBoxOk($message, $title=null)
const CURSOR_SIZEALL
const BOX_YESNOCANCEL
setCursor($wbobject, $type=self::CURSOR_ARROW)
const INCR_PROGRESS_BAR
getValue($wbobject)
createWindow($parent, $wclass, $caption, $xPos, $yPos, $width, $height, $style=null, $params=null)
messageBoxYesNo($message, $title=null)
setProgressBarMax($progressBar, $max)
destroyTimer($wbobject, $timerobject)
messageBoxError($message, $title=null)
drawRect($parent, $xPos, $yPos, $width, $height, $color=15790320, $filled=true)
messageBoxWarning($message, $title=null)
wait($wbobject=null)
getSystemInfo($info)
destroyWindow($window)
createInputText($parent, $value, $xPos, $yPos, $width=null, $height=null, $maxLength=null, $style=null, $params=null)
__winbinderEventHandler($window, $id, $ctrl, $param1, $param2)
const APP_TITLE
Definition root.php:12