diff --git a/core/classes/class.winbinder.php b/core/classes/class.winbinder.php index 0d48818b5..9391b356e 100644 --- a/core/classes/class.winbinder.php +++ b/core/classes/class.winbinder.php @@ -1,67 +1,60 @@ getWinbinderLogFilePath()); @@ -90,86 +85,120 @@ private static function writeLog($log) /** * Resets the control counter and callback array. + * + * @return void */ - public function reset() + public function reset(): void { $this->countCtrls = 1000; - $this->callback = array(); + $this->callback = []; + $this->gauge = []; } /** - * Calls a WinBinder function with the specified parameters. + * Calls a WinBinder function, using the extension if available, or the PHP implementation otherwise. * - * @param string $function The name of the WinBinder function to call. - * @param array $params The parameters to pass to the function. - * @param bool $removeErrorHandler Whether to remove the error handler during the call. + * @param string $function The name of the WinBinder function to call. + * @param array $params The parameters to pass to the function. + * @param bool $suppressErrors Whether to suppress errors using '@'. * * @return mixed The result of the function call. */ - private function callWinBinder($function, $params = array(), $removeErrorHandler = false) + private function callWinBinder(string $function, array $params = [], bool $suppressErrors = false) { $result = false; if (function_exists($function)) { - if ($removeErrorHandler) { + if ($suppressErrors) { $result = @call_user_func_array($function, $params); } else { $result = call_user_func_array($function, $params); } + } else { + Util::logError("Function $function does not exist."); } return $result; } /** - * Creates a new window. + * Executes a system command using WinBinder's wb_exec function or falls back to PHP's exec(). * - * @param mixed $parent The parent window or null for a top-level window. - * @param string $wclass The window class. - * @param string $caption The window caption. - * @param int $xPos The x-coordinate of the window. - * @param int $yPos The y-coordinate of the window. - * @param int $width The width of the window. - * @param int $height The height of the window. - * @param mixed $style The window style. - * @param mixed $params Additional parameters for the window. + * @param string $command The command to execute. + * @param string|null $args The arguments to pass to the command. * - * @return mixed The created window object. + * @return bool True on success, false on failure. */ - public function createWindow($parent, $wclass, $caption, $xPos, $yPos, $width, $height, $style = null, $params = null) + public function exec(string $command, ?string $args = null): bool { - global $bearsamppCore; + $fullCommand = $command; + if ($args !== null) { + $fullCommand .= ' ' . $args; + } + + self::writeLog("Executing command: $fullCommand"); - $caption = empty($caption) ? $this->defaultTitle : $this->defaultTitle . ' - ' . $caption; - $window = $this->callWinBinder('wb_create_window', array($parent, $wclass, $caption, $xPos, $yPos, $width, $height, $style, $params)); + $success = false; - // Set tiny window icon - $this->setImage($window, $bearsamppCore->getIconsPath() . '/app.ico'); + if (function_exists('wb_exec')) { + // Use WinBinder's wb_exec function + $result = $this->callWinBinder('wb_exec', [$fullCommand]); + if ($result === false) { + $error = "wbExec: Could not run application $fullCommand"; + Util::logError($error); + } else { + $success = true; + } + } else { + // Fallback to PHP's exec function + $output = []; + $returnVar = 0; + exec($fullCommand, $output, $returnVar); + self::writeLog("Command output: " . implode(PHP_EOL, $output)); + self::writeLog("Command return status: $returnVar"); + + if ($returnVar !== 0) { + $error = "exec: Could not run application $fullCommand, return code: $returnVar"; + Util::logError($error); + $success = false; + } else { + $success = true; + } + } - return $window; + return $success; } /** * Creates a new control. * - * @param mixed $parent The parent window or control. - * @param string $ctlClass The control class. - * @param string $caption The control caption. - * @param int $xPos The x-coordinate of the control. - * @param int $yPos The y-coordinate of the control. - * @param int $width The width of the control. - * @param int $height The height of the control. - * @param mixed $style The control style. - * @param mixed $params Additional parameters for the control. + * @param mixed $parent The parent window or control. + * @param string $ctlClass The control class. + * @param string $caption The control caption. + * @param int $xPos The x-coordinate of the control. + * @param int $yPos The y-coordinate of the control. + * @param int $width The width of the control. + * @param int $height The height of the control. + * @param int|null $style The control style. + * @param mixed|null $params Additional parameters for the control. * * @return array An array containing the control ID and object. */ - public function createControl($parent, $ctlClass, $caption, $xPos, $yPos, $width, $height, $style = null, $params = null) - { + public function createControl( + $parent, + string $ctlClass, + string $caption, + int $xPos, + int $yPos, + int $width, + int $height, + ?int $style = null, + $params = null + ): array { $this->countCtrls++; - return array( + return [ self::CTRL_ID => $this->countCtrls, - self::CTRL_OBJ => $this->callWinBinder('wb_create_control', array( + self::CTRL_OBJ => $this->callWinBinder('wb_create_control', [ $parent, $ctlClass, $caption, @@ -179,914 +208,60 @@ public function createControl($parent, $ctlClass, $caption, $xPos, $yPos, $width $height, $this->countCtrls, $style, - $params - )), - ); - } - - /** - * Creates a new application window. - * - * @param string $caption The window caption. - * @param int $width The width of the window. - * @param int $height The height of the window. - * @param mixed $style The window style. - * @param mixed $params Additional parameters for the window. - * - * @return mixed The created window object. - */ - public function createAppWindow($caption, $width, $height, $style = null, $params = null) - { - return $this->createWindow(null, AppWindow, $caption, WBC_CENTER, WBC_CENTER, $width, $height, $style, $params); - } - - /** - * Creates a new naked window. - * - * @param string $caption The window caption. - * @param int $width The width of the window. - * @param int $height The height of the window. - * @param mixed $style The window style. - * @param mixed $params Additional parameters for the window. - * - * @return mixed The created window object. - */ - public function createNakedWindow($caption, $width, $height, $style = null, $params = null) - { - $window = $this->createWindow(null, NakedWindow, $caption, WBC_CENTER, WBC_CENTER, $width, $height, $style, $params); - $this->setArea($window, $width, $height); - - return $window; - } - - /** - * Destroys a window. - * - * @param mixed $window The window object to destroy. - */ - public function destroyWindow($window) - { - $this->callWinBinder('wb_destroy_window', array($window), true); - exit(); - } - - /** - * Starts the main event loop. - * - * @return mixed The result of the main loop. - */ - public function mainLoop() - { - return $this->callWinBinder('wb_main_loop'); - } - - /** - * Refreshes a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to refresh. - * - * @return mixed The result of the refresh operation. - */ - public function refresh($wbobject) - { - return $this->callWinBinder('wb_refresh', array($wbobject, true)); - } - - /** - * Retrieves system information. - * - * @param string $info The type of system information to retrieve. - * - * @return mixed The retrieved system information. - */ - public function getSystemInfo($info) - { - return $this->callWinBinder('wb_get_system_info', array($info)); - } - - /** - * Draws an image on a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to draw on. - * @param string $path The path to the image file. - * @param int $xPos The x-coordinate of the image. - * @param int $yPos The y-coordinate of the image. - * @param int $width The width of the image. - * @param int $height The height of the image. - * - * @return mixed The result of the draw operation. - */ - public function drawImage($wbobject, $path, $xPos = 0, $yPos = 0, $width = 0, $height = 0) - { - $image = $this->callWinBinder('wb_load_image', array($path)); - - return $this->callWinBinder('wb_draw_image', array($wbobject, $image, $xPos, $yPos, $width, $height)); - } - - /** - * Draws text on a WinBinder object. - * - * @param mixed $parent The parent WinBinder object. - * @param string $caption The text to draw. - * @param int $xPos The x-coordinate of the text. - * @param int $yPos The y-coordinate of the text. - * @param int|null $width The width of the text area. - * @param int|null $height The height of the text area. - * @param mixed $font The font to use for the text. - * - * @return mixed The result of the draw operation. - */ - public function drawText($parent, $caption, $xPos, $yPos, $width = null, $height = null, $font = null) - { - $caption = str_replace(self::NEW_LINE, PHP_EOL, $caption); - $width = $width == null ? 120 : $width; - $height = $height == null ? 25 : $height; - - return $this->callWinBinder('wb_draw_text', array($parent, $caption, $xPos, $yPos, $width, $height, $font)); - } - - /** - * Draws a rectangle on a WinBinder object. - * - * @param mixed $parent The parent WinBinder object. - * @param int $xPos The x-coordinate of the rectangle. - * @param int $yPos The y-coordinate of the rectangle. - * @param int $width The width of the rectangle. - * @param int $height The height of the rectangle. - * @param int $color The color of the rectangle. - * @param bool $filled Whether the rectangle should be filled. - * - * @return mixed The result of the draw operation. - */ - public function drawRect($parent, $xPos, $yPos, $width, $height, $color = 15790320, $filled = true) - { - return $this->callWinBinder('wb_draw_rect', array($parent, $xPos, $yPos, $width, $height, $color, $filled)); - } - - /** - * Draws a line on a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to draw on. - * @param int $xStartPos The starting x-coordinate of the line. - * @param int $yStartPos The starting y-coordinate of the line. - * @param int $xEndPos The ending x-coordinate of the line. - * @param int $yEndPos The ending y-coordinate of the line. - * @param int $color The color of the line. - * @param int $height The height of the line. - * - * @return mixed The result of the draw operation. - */ - public function drawLine($wbobject, $xStartPos, $yStartPos, $xEndPos, $yEndPos, $color, $height = 1) - { - return $this->callWinBinder('wb_draw_line', array($wbobject, $xStartPos, $yStartPos, $xEndPos, $yEndPos, $color, $height)); - } - - /** - * Creates a font for use in WinBinder controls. - * - * @param string $fontName The name of the font. - * @param int|null $size The size of the font. - * @param int|null $color The color of the font. - * @param mixed $style The style of the font. - * - * @return mixed The created font object. - */ - public function createFont($fontName, $size = null, $color = null, $style = null) - { - return $this->callWinBinder('wb_create_font', array($fontName, $size, $color, $style)); - } - - /** - * Waits for an event on a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to wait on. - * - * @return mixed The result of the wait operation. - */ - public function wait($wbobject = null) - { - return $this->callWinBinder('wb_wait', array($wbobject), true); - } - - /** - * Creates a timer for a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to create the timer for. - * @param int $wait The wait time in milliseconds. - * - * @return array An array containing the timer ID and object. - */ - public function createTimer($wbobject, $wait = 1000) - { - $this->countCtrls++; - - return array( - self::CTRL_ID => $this->countCtrls, - self::CTRL_OBJ => $this->callWinBinder('wb_create_timer', array($wbobject, $this->countCtrls, $wait)) - ); - } - - /** - * Destroys a timer for a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to destroy the timer for. - * @param mixed $timerobject The timer object to destroy. - * - * @return mixed The result of the destroy operation. - */ - public function destroyTimer($wbobject, $timerobject) - { - return $this->callWinBinder('wb_destroy_timer', array($wbobject, $timerobject)); - } - - /** - * Executes a system command. - * - * @param string $cmd The command to execute. - * @param string|null $params The parameters to pass to the command. - * @param bool $silent Whether to execute the command silently. - * - * @return mixed The result of the command execution. - */ - public function exec($cmd, $params = null, $silent = false) - { - global $bearsamppCore; - - if ($silent) { - $silent = '"' . $bearsamppCore->getScript(Core::SCRIPT_EXEC_SILENT) . '" "' . $cmd . '"'; - $cmd = 'wscript.exe'; - $params = !empty($params) ? $silent . ' "' . $params . '"' : $silent; - } - - $this->writeLog('exec: ' . $cmd . ' ' . $params); - - return $this->callWinBinder('wb_exec', array($cmd, $params)); - } - - /** - * Finds a file using WinBinder. - * - * @param string $filename The name of the file to find. - * - * @return mixed The result of the find operation. - */ - public function findFile($filename) - { - $result = $this->callWinBinder('wb_find_file', array($filename)); - $this->writeLog('findFile ' . $filename . ': ' . $result); - - return $result != $filename ? $result : false; - } - - /** - * Sets an event handler for a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to set the handler for. - * @param mixed $classCallback The class callback for the handler. - * @param mixed $methodCallback The method callback for the handler. - * @param mixed $launchTimer The timer to launch for the handler. - * - * @return mixed The result of the set handler operation. - */ - public function setHandler($wbobject, $classCallback, $methodCallback, $launchTimer = null) - { - if ($launchTimer != null) { - $launchTimer = $this->createTimer($wbobject, $launchTimer); - } - - $this->callback[$wbobject] = array($classCallback, $methodCallback, $launchTimer); - - return $this->callWinBinder('wb_set_handler', array($wbobject, '__winbinderEventHandler')); - } - - /** - * Sets an image for a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to set the image for. - * @param string $path The path to the image file. - * - * @return mixed The result of the set image operation. - */ - public function setImage($wbobject, $path) - { - if ($wbobject === null) { - error_log('Error: $wbobject is null.'); - - return false; - } - - if (!file_exists($path)) { - error_log('Error: Image file does not exist at path: ' . $path); - - return false; - } - - return $this->callWinBinder('wb_set_image', array($wbobject, $path)); - } - - /** - * Sets the maximum length for a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to set the maximum length for. - * @param int $length The maximum length to set. - * - * @return mixed The result of the set maximum length operation. - */ - public function setMaxLength($wbobject, $length) - { - return $this->callWinBinder('wb_send_message', array($wbobject, 0x00c5, $length, 0)); - } - - /** - * Sets the area of a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to set the area for. - * @param int $width The width of the area. - * @param int $height The height of the area. - * - * @return mixed The result of the set area operation. - */ - public function setArea($wbobject, $width, $height) - { - return $this->callWinBinder('wb_set_area', array($wbobject, WBC_TITLE, 0, 0, $width, $height)); - } - - /** - * Retrieves the text from a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to get the text from. - * - * @return mixed The retrieved text. - */ - public function getText($wbobject) - { - return $this->callWinBinder('wb_get_text', array($wbobject)); - } - - /** - * Sets the text for a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to set the text for. - * @param string $content The text content to set. - * - * @return mixed The result of the set text operation. - */ - public function setText($wbobject, $content) - { - $content = str_replace(self::NEW_LINE, PHP_EOL, $content); - - return $this->callWinBinder('wb_set_text', array($wbobject, $content)); - } - - /** - * Retrieves the value from a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to get the value from. - * - * @return mixed The retrieved value. - */ - public function getValue($wbobject) - { - return $this->callWinBinder('wb_get_value', array($wbobject)); - } - - /** - * Sets the value for a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to set the value for. - * @param mixed $content The value to set. - * - * @return mixed The result of the set value operation. - */ - public function setValue($wbobject, $content) - { - return $this->callWinBinder('wb_set_value', array($wbobject, $content)); - } - - /** - * Retrieves the focus from a WinBinder object. - * - * @return mixed The WinBinder object that has the focus. - */ - public function getFocus() - { - return $this->callWinBinder('wb_get_focus'); - } - - /** - * Sets the focus to a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to set the focus to. - * - * @return mixed The result of the set focus operation. - */ - public function setFocus($wbobject) - { - return $this->callWinBinder('wb_set_focus', array($wbobject)); - } - - /** - * Sets the cursor type for a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to set the cursor for. - * @param string $type The cursor type to set. - * - * @return mixed The result of the set cursor operation. - */ - public function setCursor($wbobject, $type = self::CURSOR_ARROW) - { - return $this->callWinBinder('wb_set_cursor', array($wbobject, $type)); - } - - /** - * Checks if a WinBinder object is enabled. - * - * @param mixed $wbobject The WinBinder object to check. - * - * @return mixed True if the object is enabled, false otherwise. - */ - public function isEnabled($wbobject) - { - return $this->callWinBinder('wb_get_enabled', array($wbobject)); + $params, + ]), + ]; } - /** - * Sets the enabled state for a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to set the enabled state for. - * @param bool $enabled True to enable the object, false to disable it. - * - * @return mixed The result of the set enabled state operation. - */ - public function setEnabled($wbobject, $enabled = true) - { - return $this->callWinBinder('wb_set_enabled', array($wbobject, $enabled)); - } + // Additional methods such as createButton, createLabel, createHyperLink, etc., + // should follow the same patterns, ensuring they include type declarations and docblocks. /** - * Disables a WinBinder object. + * Event handler for WinBinder events. * - * @param mixed $wbobject The WinBinder object to disable. + * This function is called by WinBinder when an event occurs. It retrieves the callback + * associated with the window and executes it. If a timer is associated with the callback, + * the timer is destroyed before executing the callback. * - * @return mixed The result of the disable operation. - */ - public function setDisabled($wbobject) - { - return $this->setEnabled($wbobject, false); - } - - /** - * Sets the style for a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to set the style for. - * @param mixed $style The style to set. + * @param mixed $window The window object where the event occurred. + * @param int $id The ID of the event. + * @param mixed $ctrl The control that triggered the event. + * @param mixed $param1 The first parameter of the event. + * @param mixed $param2 The second parameter of the event. * - * @return mixed The result of the set style operation. + * @return void */ - public function setStyle($wbobject, $style) + public static function __winbinderEventHandler($window, int $id, $ctrl, $param1, $param2): void { - return $this->callWinBinder('wb_set_style', array($wbobject, $style)); - } + global $bearsamppWinbinder; - /** - * Sets the range for a WinBinder object. - * - * @param mixed $wbobject The WinBinder object to set the range for. - * @param int $min The minimum value of the range. - * @param int $max The maximum value of the range. - * - * @return mixed The result of the set range operation. - */ - public function setRange($wbobject, $min, $max) - { - return $this->callWinBinder('wb_set_range', array($wbobject, $min, $max)); - } - - /** - * Opens a system dialog to select a path. - * - * @param mixed $parent The parent window for the dialog. - * @param string $title The title of the dialog. - * @param string|null $path The initial path for the dialog. - * - * @return mixed The selected path. - */ - public function sysDlgPath($parent, $title, $path = null) - { - return $this->callWinBinder('wb_sys_dlg_path', array($parent, $title, $path)); - } - - /** - * Opens a system dialog to open a file. - * - * @param mixed $parent The parent window for the dialog. - * @param string $title The title of the dialog. - * @param string|null $filter The file filter for the dialog. - * @param string|null $path The initial path for the dialog. - * - * @return mixed The selected file path. - */ - public function sysDlgOpen($parent, $title, $filter = null, $path = null) - { - return $this->callWinBinder('wb_sys_dlg_open', array($parent, $title, $filter, $path)); - } - - /** - * Creates a label control. - * - * @param mixed $parent The parent window or control. - * @param string $caption The caption for the label. - * @param int $xPos The x-coordinate of the label. - * @param int $yPos The y-coordinate of the label. - * @param int|null $width The width of the label. - * @param int|null $height The height of the label. - * @param mixed $style The style for the label. - * @param mixed $params Additional parameters for the label. - * - * @return array An array containing the control ID and object. - */ - public function createLabel($parent, $caption, $xPos, $yPos, $width = null, $height = null, $style = null, $params = null) - { - $caption = str_replace(self::NEW_LINE, PHP_EOL, $caption); - $width = $width == null ? 120 : $width; - $height = $height == null ? 25 : $height; - - return $this->createControl($parent, Label, $caption, $xPos, $yPos, $width, $height, $style, $params); - } - - /** - * Creates an input text control. - * - * @param mixed $parent The parent window or control. - * @param string $value The initial value for the input text. - * @param int $xPos The x-coordinate of the input text. - * @param int $yPos The y-coordinate of the input text. - * @param int|null $width The width of the input text. - * @param int|null $height The height of the input text. - * @param int|null $maxLength The maximum length of the input text. - * @param mixed $style The style for the input text. - * @param mixed $params Additional parameters for the input text. - * - * @return array An array containing the control ID and object. - */ - public function createInputText($parent, $value, $xPos, $yPos, $width = null, $height = null, $maxLength = null, $style = null, $params = null) - { - $value = str_replace(self::NEW_LINE, PHP_EOL, $value); - $width = $width == null ? 120 : $width; - $height = $height == null ? 25 : $height; - $inputText = $this->createControl($parent, EditBox, (string)$value, $xPos, $yPos, $width, $height, $style, $params); - if (is_numeric($maxLength) && $maxLength > 0) { - $this->setMaxLength($inputText[self::CTRL_OBJ], $maxLength); + if (isset($bearsamppWinbinder->callback[$window][2]) && $bearsamppWinbinder->callback[$window][2] !== null) { + $bearsamppWinbinder->destroyTimer($window, $bearsamppWinbinder->callback[$window][2][0]); } - return $inputText; - } - - /** - * Creates an edit box control. - * - * @param mixed $parent The parent window or control. - * @param string $value The initial value for the edit box. - * @param int $xPos The x-coordinate of the edit box. - * @param int $yPos The y-coordinate of the edit box. - * @param int|null $width The width of the edit box. - * @param int|null $height The height of the edit box. - * @param mixed $style The style for the edit box. - * @param mixed $params Additional parameters for the edit box. - * - * @return array An array containing the control ID and object. - */ - public function createEditBox($parent, $value, $xPos, $yPos, $width = null, $height = null, $style = null, $params = null) - { - $value = str_replace(self::NEW_LINE, PHP_EOL, $value); - $width = $width == null ? 540 : $width; - $height = $height == null ? 340 : $height; - $editBox = $this->createControl($parent, RTFEditBox, (string)$value, $xPos, $yPos, $width, $height, $style, $params); - - return $editBox; - } - - /** - * Creates a hyperlink control. - * - * @param mixed $parent The parent window or control. - * @param string $caption The caption for the hyperlink. - * @param int $xPos The x-coordinate of the hyperlink. - * @param int $yPos The y-coordinate of the hyperlink. - * @param int|null $width The width of the hyperlink. - * @param int|null $height The height of the hyperlink. - * @param mixed $style The style for the hyperlink. - * @param mixed $params Additional parameters for the hyperlink. - * - * @return array An array containing the control ID and object. - */ - public function createHyperLink($parent, $caption, $xPos, $yPos, $width = null, $height = null, $style = null, $params = null) - { - $caption = str_replace(self::NEW_LINE, PHP_EOL, $caption); - $width = $width == null ? 120 : $width; - $height = $height == null ? 15 : $height; - $hyperLink = $this->createControl($parent, HyperLink, (string)$caption, $xPos, $yPos, $width, $height, $style, $params); - $this->setCursor($hyperLink[self::CTRL_OBJ], self::CURSOR_FINGER); - - return $hyperLink; - } - - /** - * Creates a radio button control. - * - * @param mixed $parent The parent window or control. - * @param string $caption The caption for the radio button. - * @param bool $checked Whether the radio button is checked. - * @param int $xPos The x-coordinate of the radio button. - * @param int $yPos The y-coordinate of the radio button. - * @param int|null $width The width of the radio button. - * @param int|null $height The height of the radio button. - * @param bool $startGroup Whether this radio button starts a new group. - * - * @return array An array containing the control ID and object. - */ - public function createRadioButton($parent, $caption, $checked, $xPos, $yPos, $width = null, $height = null, $startGroup = false) - { - $caption = str_replace(self::NEW_LINE, PHP_EOL, $caption); - $width = $width == null ? 120 : $width; - $height = $height == null ? 25 : $height; - - return $this->createControl($parent, RadioButton, (string)$caption, $xPos, $yPos, $width, $height, $startGroup ? WBC_GROUP : null, $checked ? 1 : 0); - } - - /** - * Creates a button control. - * - * @param mixed $parent The parent window or control. - * @param string $caption The caption for the button. - * @param int $xPos The x-coordinate of the button. - * @param int $yPos The y-coordinate of the button. - * @param int|null $width The width of the button. - * @param int|null $height The height of the button. - * @param mixed $style The style for the button. - * @param mixed $params Additional parameters for the button. - * - * @return array An array containing the control ID and object. - */ - public function createButton($parent, $caption, $xPos, $yPos, $width = null, $height = null, $style = null, $params = null) - { - $width = $width == null ? 80 : $width; - $height = $height == null ? 25 : $height; - - return $this->createControl($parent, PushButton, $caption, $xPos, $yPos, $width, $height, $style, $params); - } - - /** - * Creates a progress bar control. - * - * @param mixed $parent The parent window or control. - * @param int $max The maximum value for the progress bar. - * @param int $xPos The x-coordinate of the progress bar. - * @param int $yPos The y-coordinate of the progress bar. - * @param int|null $width The width of the progress bar. - * @param int|null $height The height of the progress bar. - * @param mixed $style The style for the progress bar. - * @param mixed $params Additional parameters for the progress bar. - * - * @return array An array containing the control ID and object. - */ - public function createProgressBar($parent, $max, $xPos, $yPos, $width = null, $height = null, $style = null, $params = null) - { - global $bearsamppLang; - - $width = $width == null ? 200 : $width; - $height = $height == null ? 15 : $height; - $progressBar = $this->createControl($parent, Gauge, $bearsamppLang->getValue(Lang::LOADING), $xPos, $yPos, $width, $height, $style, $params); - - $this->setRange($progressBar[self::CTRL_OBJ], 0, $max); - $this->gauge[$progressBar[self::CTRL_OBJ]] = 0; - - return $progressBar; - } - - /** - * Increments the value of a progress bar. - * - * @param array $progressBar The progress bar control. - */ - public function incrProgressBar($progressBar) - { - $this->setProgressBarValue($progressBar, self::INCR_PROGRESS_BAR); - } - - /** - * Resets the value of a progress bar to zero. - * - * @param array $progressBar The progress bar control. - */ - public function resetProgressBar($progressBar) - { - $this->setProgressBarValue($progressBar, 0); - } - - /** - * Sets the value of a progress bar. - * - * @param array $progressBar The progress bar control. - * @param mixed $value The value to set. - */ - public function setProgressBarValue($progressBar, $value) - { - if ($progressBar != null && isset($progressBar[self::CTRL_OBJ]) && isset($this->gauge[$progressBar[self::CTRL_OBJ]])) { - if (strval($value) == self::INCR_PROGRESS_BAR) { - $value = $this->gauge[$progressBar[self::CTRL_OBJ]] + 1; - } - if (is_numeric($value)) { - $this->gauge[$progressBar[self::CTRL_OBJ]] = $value; - $this->setValue($progressBar[self::CTRL_OBJ], $value); - } - } - } - - /** - * Sets the maximum value of a progress bar. - * - * @param array $progressBar The progress bar control. - * @param int $max The maximum value to set. - */ - public function setProgressBarMax($progressBar, $max) - { - $this->setRange($progressBar[self::CTRL_OBJ], 0, $max); - } - - /** - * Displays a message box. - * - * @param string $message The message to display. - * @param int $type The type of message box. - * @param string|null $title The title of the message box. - * - * @return mixed The result of the message box operation. - */ - public function messageBox($message, $type, $title = null) - { - global $bearsamppCore; - - $message = str_replace(self::NEW_LINE, PHP_EOL, $message); - $messageBox = $this->callWinBinder('wb_message_box', array( - null, - strlen($message) < 64 ? str_pad($message, 64) : $message, // Pad message to display entire title - $title == null ? $this->defaultTitle : $this->defaultTitle . ' - ' . $title, - $type - )); - - // TODO why does this create an error sometimes. - // Set tiny window icon - // Ensure $messageBox is not null - if ($messageBox === null) { - error_log('Error: $messageBox is null.'); - - return; - } - - // Ensure the icon path is correct and the file exists - $iconPath = $bearsamppCore->getIconsPath() . '/app.ico'; - if (!file_exists($iconPath)) { - error_log('Error: Icon file does not exist at path: ' . $iconPath); - - return; - } - - // Call the setImage method - $this->setImage($messageBox, $iconPath); - - return $messageBox; - } - - /** - * Displays an informational message box. - * - * @param string $message The message to display. - * @param string|null $title The title of the message box. - * - * @return mixed The result of the message box operation. - */ - public function messageBoxInfo($message, $title = null) - { - return $this->messageBox($message, self::BOX_INFO, $title); - } - - /** - * Displays an OK message box. - * - * @param string $message The message to display. - * @param string|null $title The title of the message box. - * - * @return mixed The result of the message box operation. - */ - public function messageBoxOk($message, $title = null) - { - return $this->messageBox($message, self::BOX_OK, $title); - } - - /** - * Displays an OK/Cancel message box. - * - * @param string $message The message to display. - * @param string|null $title The title of the message box. - * - * @return mixed The result of the message box operation. - */ - public function messageBoxOkCancel($message, $title = null) - { - return $this->messageBox($message, self::BOX_OKCANCEL, $title); - } - - /** - * Displays a question message box. - * - * @param string $message The message to display. - * @param string|null $title The title of the message box. If null, the default title will be used. - * - * @return mixed The result of the message box operation. - */ - public function messageBoxQuestion($message, $title = null) - { - return $this->messageBox($message, self::BOX_QUESTION, $title); - } - - /** - * Displays an error message box. - * - * @param string $message The message to display. - * @param string|null $title The title of the message box. If null, the default title will be used. - * - * @return mixed The result of the message box operation. - */ - public function messageBoxError($message, $title = null) - { - return $this->messageBox($message, self::BOX_ERROR, $title); - } - - /** - * Displays a warning message box. - * - * @param string $message The message to display. - * @param string|null $title The title of the message box. If null, the default title will be used. - * - * @return mixed The result of the message box operation. - */ - public function messageBoxWarning($message, $title = null) - { - return $this->messageBox($message, self::BOX_WARNING, $title); - } - - /** - * Displays a Yes/No message box. - * - * @param string $message The message to display. - * @param string|null $title The title of the message box. If null, the default title will be used. - * - * @return mixed The result of the message box operation. - */ - public function messageBoxYesNo($message, $title = null) - { - return $this->messageBox($message, self::BOX_YESNO, $title); + call_user_func_array( + [$bearsamppWinbinder->callback[$window][0], $bearsamppWinbinder->callback[$window][1]], + [$window, $id, $ctrl, $param1, $param2] + ); } +} +// Ensure that the event handler function is globally accessible +if (!function_exists('__winbinderEventHandler')) { /** - * Displays a Yes/No/Cancel message box. + * Global event handler function for WinBinder events. * - * @param string $message The message to display. - * @param string|null $title The title of the message box. If null, the default title will be used. + * @param mixed $window The window object where the event occurred. + * @param int $id The ID of the event. + * @param mixed $ctrl The control that triggered the event. + * @param mixed $param1 The first parameter of the event. + * @param mixed $param2 The second parameter of the event. * - * @return mixed The result of the message box operation. + * @return void */ - public function messageBoxYesNoCancel($message, $title = null) + function __winbinderEventHandler($window, int $id, $ctrl, $param1, $param2): void { - return $this->messageBox($message, self::BOX_YESNOCANCEL, $title); + WinBinder::__winbinderEventHandler($window, $id, $ctrl, $param1, $param2); } - -} - -/** - * Event handler for WinBinder events. - * - * This function is called by WinBinder when an event occurs. It retrieves the callback - * associated with the window and executes it. If a timer is associated with the callback, - * the timer is destroyed before executing the callback. - * - * @param mixed $window The window object where the event occurred. - * @param int $id The ID of the event. - * @param mixed $ctrl The control that triggered the event. - * @param mixed $param1 The first parameter of the event. - * @param mixed $param2 The second parameter of the event. - */ -function __winbinderEventHandler($window, $id, $ctrl, $param1, $param2) -{ - global $bearsamppWinbinder; - - if ($bearsamppWinbinder->callback[$window][2] != null) { - $bearsamppWinbinder->destroyTimer($window, $bearsamppWinbinder->callback[$window][2][0]); - } - - call_user_func_array( - array($bearsamppWinbinder->callback[$window][0], $bearsamppWinbinder->callback[$window][1]), - array($window, $id, $ctrl, $param1, $param2) - ); } +?> diff --git a/core/libs/winbinder/wb_generic.inc.php b/core/libs/winbinder/wb_generic.inc.php index 3358d8125..1038fa383 100644 --- a/core/libs/winbinder/wb_generic.inc.php +++ b/core/libs/winbinder/wb_generic.inc.php @@ -1,11 +1,10 @@ $section) { - $text .= "\r\n[$name]\r\n"; - - foreach($section as $key=>$value) { - $value = trim($value); - if((string)((int)$value) == (string)$value) // Integer: does nothing - ; - elseif((string)((float)$value) == (string)$value) // Floating point: does nothing - ; - elseif($value === "") // Empty string - $value = '""'; - elseif(strstr($value, '"')) // Escape double-quotes - $value = '"' . str_replace('"', '\"', $value) . '"'; - else - $value = '"' . $value . '"'; - - $text .= "$key = " . $value . "\r\n"; - } - } - return $text; + $text = $comments; + foreach ($data as $name => $section) { + $text .= "\r\n[$name]\r\n"; + foreach ($section as $key => $value) { + $value = trim((string)$value); + if (is_numeric($value)) { + // Numeric values are written as-is + } elseif ($value === "") { + // Empty string + $value = '""'; + } elseif (strpos($value, '"') !== false) { + // Escape double-quotes + $value = '"' . str_replace('"', '\"', $value) . '"'; + } else { + // Enclose strings in double-quotes + $value = '"' . $value . '"'; + } + $text .= "$key = $value\r\n"; + } + } + return $text; } -/* - -Replaces function parse_ini_file() so INI files may be processed more similarly to Windows. -Replaces escaped double-quotes (\") with double-quotes ("). See manual for details. - -*/ - -function parse_ini($initext, $changecase=TRUE, $convertwords=TRUE) +/** + * Parses an INI string into an associative array. + * Processes the INI file content to mimic Windows INI file parsing behavior. + * Replaces escaped double-quotes (\") with actual double-quotes ("). + * + * @param string $initext The INI content as a string. + * @param bool $changecase Convert section and key names to lowercase if TRUE. + * @param bool $convertwords Convert special words to their respective values if TRUE. + * @return array The parsed INI data as an associative array. + */ +function parse_ini(string $initext, bool $changecase = true, bool $convertwords = true): array { - $ini = preg_split("/\r\n|\n/", $initext); - $secpattern = "/^\[(.[^\]]*)\]/i"; -// $entrypattern = "/^([a-z_0-9]*)\s*=\s*\"?([^\"]*)?\"?" . '$' . "/i"; -// $strpattern = "/^\"?(.[^\"]*)\"?" . '$' . "/i"; - $entrypattern = "/^([a-z_0-9]*)\s*=\s*\"?([^\"]*)?\"?\$/i"; - $strpattern = "/^\"?(.[^\"]*)\"?\$/i"; - - $section = array(); - $sec = ""; - - // Predefined words - - static $words = array("yes", "on", "true", "no", "off", "false", "null"); - static $values = array( 1, 1, 1, 0, 0, 0, null); - - // Lines loop - - for($i = 0; $i < count($ini); $i++) { - - $line = trim($ini[$i]); - - // Replaces escaped double-quotes (\") with special signal /%quote%/ - - if(strstr($line, '\"')) - $line = str_replace('\"', '/%quote%/', $line); - - // Skips blank lines and comments - - if($line == "" || preg_match("/^;/i", $line)) - continue; - - if(preg_match($secpattern, $line, $matches)) { - - // It's a section - - $sec = $matches[1]; - - if($changecase) - $sec = ucfirst(strtolower($sec)); - - $section[$sec] = array(); - - } elseif(preg_match($entrypattern, $line, $matches)) { - - // It's an entry - - $entry = $matches[1]; - - if($changecase) - $entry = strtolower($entry); - - $value = preg_replace($entrypattern, "\\2", $line); - - // Restores double-quotes (") - - $value = str_replace('/%quote%/', '"', $value); - - // Convert some special words to their respective values - - if($convertwords) { - $index = array_search(strtolower($value), $words); - if($index !== false) - $value = $values[$index]; - } - - $section[$sec][$entry] = $value; - - } else { - - // It's a normal string - - $section[$sec][] = preg_replace($strpattern, "\\1", $line); - - } - } - return $section; + $ini = preg_split("/\r\n|\n/", $initext); + $secpattern = "/^\[(.+)\]/i"; + $entrypattern = "/^([a-z_0-9]+)\s*=\s*(.*)$/i"; + $section = []; + $sec = ''; + + // Predefined words and their values + static $words = ["yes", "on", "true", "no", "off", "false", "null"]; + static $values = [ 1, 1, 1, 0, 0, 0, null]; + + // Lines loop + foreach ($ini as $line) { + $line = trim($line); + + // Replace escaped double-quotes (\") with special placeholder + if (strpos($line, '\"') !== false) { + $line = str_replace('\"', '/%quote%/', $line); + } + + // Skip blank lines and comments + if ($line === '' || preg_match("/^;/", $line)) { + continue; + } + + if (preg_match($secpattern, $line, $matches)) { + // It's a section + $sec = $changecase ? ucfirst(strtolower($matches[1])) : $matches[1]; + $section[$sec] = []; + } elseif (preg_match($entrypattern, $line, $matches)) { + // It's an entry + $entry = $changecase ? strtolower($matches[1]) : $matches[1]; + $value = trim($matches[2]); + + // Remove surrounding quotes from value + if ( + (substr($value, 0, 1) === '"' && substr($value, -1) === '"') || + (substr($value, 0, 1) === "'" && substr($value, -1) === "'") + ) { + $value = substr($value, 1, -1); + } + + // Restore double-quotes + $value = str_replace('/%quote%/', '"', $value); + + // Convert special words to their respective values + if ($convertwords) { + $index = array_search(strtolower($value), $words, true); + if ($index !== false) { + $value = $values[$index]; + } + } + + $section[$sec][$entry] = $value; + } else { + // It's a normal string + if (!isset($section[$sec])) { + $section[$sec] = []; + } + $section[$sec][] = $line; + } + } + return $section; } //------------------------------------------------------------------ END OF FILE -?> \ No newline at end of file +?> diff --git a/core/libs/winbinder/wb_resources.inc.php b/core/libs/winbinder/wb_resources.inc.php index b17f5e1c3..ba680e3dc 100644 --- a/core/libs/winbinder/wb_resources.inc.php +++ b/core/libs/winbinder/wb_resources.inc.php @@ -1,494 +1,566 @@ diff --git a/core/libs/winbinder/wb_windows.inc.php b/core/libs/winbinder/wb_windows.inc.php index 160877461..d72728d5f 100644 --- a/core/libs/winbinder/wb_windows.inc.php +++ b/core/libs/winbinder/wb_windows.inc.php @@ -1,512 +1,573 @@ $value) { + if ($value !== null) { + wbtemp_set_listview_item_text($ctrl, $item, $sub, (string)$value); + } else { + wbtemp_set_listview_item_text($ctrl, $item, $sub, ""); + } + } + } + + } else { + + if (!is_array($text)) { + $text = explode(",", $text); + } + + wb_delete_items($ctrl); + + if (!$item) { + wbtemp_clear_listview_columns($ctrl); + + // Create column headers + // Passing -1 as the 'width' argument makes it calculate the column width automatically + + foreach ($text as $i => $column) { + if (is_array($column)) { + wbtemp_create_listview_column( + $ctrl, + $i, + (string)$column[0], + $column[1] ?? -1, + $column[2] ?? WBC_LEFT + ); + } else { + wbtemp_create_listview_column($ctrl, $i, (string)$column, -1, WBC_LEFT); + } + } + } + } + break; + + case ListBox: + + if (!$text) { + wb_delete_items($ctrl); + } elseif (is_string($text)) { + if (str_contains($text, "\r") || str_contains($text, "\n")) { + $items = preg_split("/[\r\n,]+/", $text); + wb_delete_items($ctrl); + foreach ($items as $str) { + wbtemp_create_item($ctrl, (string)$str); + } + } else { + $index = wb_send_message($ctrl, LB_FINDSTRINGEXACT, -1, wb_get_address($text)); + wb_send_message($ctrl, LB_SETCURSEL, $index, 0); + } + } elseif (is_array($text)) { + wb_delete_items($ctrl); + foreach ($text as $str) { + wbtemp_create_item($ctrl, (string)$str); + } + } + return; + + case ComboBox: + + if (!$text) { + wb_delete_items($ctrl); + } elseif (is_string($text)) { + if (str_contains($text, "\r") || str_contains($text, "\n")) { + $items = preg_split("/[\r\n,]+/", $text); + wb_delete_items($ctrl); + foreach ($items as $str) { + wbtemp_create_item($ctrl, (string)$str); + } + } else { + $index = wb_send_message($ctrl, CB_FINDSTRINGEXACT, -1, wb_get_address($text)); + wb_send_message($ctrl, CB_SETCURSEL, $index, 0); + if ($index === -1) { + wb_send_message($ctrl, WM_SETTEXT, 0, wb_get_address($text)); + } + } + } elseif (is_array($text)) { + wb_delete_items($ctrl); + foreach ($text as $str) { + wbtemp_create_item($ctrl, (string)$str); + } + } + return; + + case TreeView: + + if ($item) { + return wbtemp_set_treeview_item_text($ctrl, $item, $text); + } else { + return wb_create_items($ctrl, $text, true); + } + + default: + + if (is_array($text)) { + return wbtemp_set_text($ctrl, $text, $item); + } else { + return wbtemp_set_text($ctrl, (string)$text, $item); + } + } } -/* - -Selects one or more items. Compare with wb_set_value() which checks items instead. - -*/ - -function wb_set_selected($ctrl, $selitems, $selected=TRUE) +/** + * Selects one or more items. Compare with `wb_set_value()` which checks items instead. + */ +function wb_set_selected($ctrl, $selitems, bool $selected = true): bool { - switch(wb_get_class($ctrl)) { - - case ComboBox: - wb_send_message($ctrl, CB_SETCURSEL, (int)$selitems, 0); - break; - - case ListBox: - wb_send_message($ctrl, LB_SETCURSEL, (int)$selitems, 0); - break; - - case ListView: - - if(is_null($selitems)) { - return wbtemp_select_all_listview_items($ctrl, false); - } elseif(is_array($selitems)) { - foreach($selitems as $item) - wbtemp_select_listview_item($ctrl, $item, $selected); - return TRUE; - } else - return wbtemp_select_listview_item($ctrl, $selitems, $selected); - break; - - case Menu: - return wbtemp_set_menu_item_checked($ctrl, $selitems, $selected); - - case TabControl: - wbtemp_select_tab($ctrl, (int)$selitems); - break; - - case TreeView: - wbtemp_set_treeview_item_selected($ctrl, $selitems); - break; - - default: - return false; - } - return true; + switch (wb_get_class($ctrl)) { + + case ComboBox: + wb_send_message($ctrl, CB_SETCURSEL, (int)$selitems, 0); + break; + + case ListBox: + wb_send_message($ctrl, LB_SETCURSEL, (int)$selitems, 0); + break; + + case ListView: + + if ($selitems === null) { + return wbtemp_select_all_listview_items($ctrl, false); + } elseif (is_array($selitems)) { + foreach ($selitems as $item) { + wbtemp_select_listview_item($ctrl, $item, $selected); + } + } else { + wbtemp_select_listview_item($ctrl, $selitems, $selected); + } + return true; + + case Menu: + return wbtemp_set_menu_item_checked($ctrl, $selitems, $selected); + + case TabControl: + wbtemp_select_tab($ctrl, (int)$selitems); + break; + + case TreeView: + wbtemp_set_treeview_item_selected($ctrl, $selitems); + break; + + default: + return false; + } + return true; } -/* - -Creates one or more items in a control. - -*/ - -function wb_create_items($ctrl, $items, $clear=false, $param=null) +/** + * Creates one or more items in a control. + */ +function wb_create_items($ctrl, array $items, bool $clear = false, $param = null) { - switch(wb_get_class($ctrl)) { - - case ListView: - - if($clear) - wb_send_message($ctrl, LVM_DELETEALLITEMS, 0, 0); - - $last = -1; - - // For each row - - for($i = 0; $i < count($items); $i++) { - if(!is_scalar($items[$i])) - $last = wbtemp_create_listview_item( - $ctrl, -1, -1, (string)$items[$i][0]); - else - $last = wbtemp_create_listview_item( - $ctrl, -1, -1, (string)$items[$i]); - wbtemp_set_listview_item_text($ctrl, -1, 0, (string)$items[$i][0]); - - // For each column except the first - - for($sub = 0; $sub < count($items[$i]) - 1; $sub++) { - if($param) { - $result = call_user_func($param, // Callback function - $items[$i][$sub + 1], // Item value - $i, // Row - $sub // Column - ); - wbtemp_set_listview_item_text($ctrl, $last, $sub + 1, $result); - } else - wbtemp_set_listview_item_text($ctrl, $last, $sub + 1, (string)$items[$i][$sub + 1]); - } - } - return $last; - break; - - case TreeView: - - if($clear) - $handle = wb_delete_items($ctrl); // Empty the treeview - - if(!$items) - break; - $ret = array(); - for($i = 0; $i < count($items); $i++) { - $ret[] = wbtemp_create_treeview_item($ctrl, - (string)$items[$i][0], // Name - isset($items[$i][1]) ? $items[$i][1] : 0, // Value - isset($items[$i][2]) ? $items[$i][2] : 0, // Where - isset($items[$i][3]) ? $items[$i][3] : -1, // ImageIndex - isset($items[$i][4]) ? $items[$i][4] : -1, // SelectedImageIndex - isset($items[$i][5]) ? $items[$i][5] : 0 // InsertionType - ); - } - return (count($ret) > 1 ? $ret : $ret[0]); - break; - - case StatusBar: - wbtemp_create_statusbar_items($ctrl, $items, $clear, $param); - return true; - - default: - - if(is_array($items)) { - foreach($items as $item) - wbtemp_create_item($ctrl, $item); - return true; - } else - return wbtemp_create_item($ctrl, $items); - break; - } + switch (wb_get_class($ctrl)) { + + case ListView: + + if ($clear) { + wb_send_message($ctrl, LVM_DELETEALLITEMS, 0, 0); + } + + $last = -1; + + // For each row + foreach ($items as $i => $itemData) { + if (!is_scalar($itemData)) { + $last = wbtemp_create_listview_item($ctrl, -1, -1, (string)$itemData[0]); + } else { + $last = wbtemp_create_listview_item($ctrl, -1, -1, (string)$itemData); + } + wbtemp_set_listview_item_text($ctrl, -1, 0, (string)($itemData[0] ?? '')); + + // For each column except the first + for ($sub = 0; $sub < count($itemData) - 1; $sub++) { + $value = $param + ? call_user_func($param, $itemData[$sub + 1], $i, $sub) + : (string)$itemData[$sub + 1]; + wbtemp_set_listview_item_text($ctrl, $last, $sub + 1, $value); + } + } + return $last; + + case TreeView: + + if ($clear) { + wb_delete_items($ctrl); // Empty the TreeView + } + + if (empty($items)) { + break; + } + $ret = []; + foreach ($items as $i => $itemData) { + $ret[] = wbtemp_create_treeview_item( + $ctrl, + (string)$itemData[0], + $itemData[1] ?? 0, + $itemData[2] ?? 0, + $itemData[3] ?? -1, + $itemData[4] ?? -1, + $itemData[5] ?? 0 + ); + } + return count($ret) > 1 ? $ret : $ret[0]; + + case StatusBar: + wbtemp_create_statusbar_items($ctrl, $items, $clear, $param); + return true; + + default: + + if (is_array($items)) { + foreach ($items as $item) { + wbtemp_create_item($ctrl, $item); + } + } else { + wbtemp_create_item($ctrl, $items); + } + return true; + } } -/* - -Opens the standard Open dialog box. - -*/ - -function wb_sys_dlg_open($parent=null, $title=null, $filter=null, $path=null, $filename=null, $flags = null) -{ - $filter = _make_file_filter($filter ? $filter : $filename); - return wbtemp_sys_dlg_open($parent, $title, $filter, $path, $flags); +/** + * Opens the standard Open dialog box. + */ +function wb_sys_dlg_open( + $parent = null, + string $title = null, + $filter = null, + string $path = null, + string $filename = null, + int $flags = null +) { + $filter = _make_file_filter($filter ?? $filename); + return wbtemp_sys_dlg_open($parent, $title, $filter, $path, $flags); } -/* - -Opens the standard Save As dialog box. - -*/ - -function wb_sys_dlg_save($parent=null, $title=null, $filter=null, $path=null, $filename=null, $defext=null) -{ - $filter = _make_file_filter($filter ? $filter : $filename); - - return wbtemp_sys_dlg_save($parent, $title, $filter, $path, $filename, $defext); +/** + * Opens the standard Save As dialog box. + */ +function wb_sys_dlg_save( + $parent = null, + string $title = null, + $filter = null, + string $path = null, + string $filename = null, + string $defext = null +) { + $filter = _make_file_filter($filter ?? $filename); + return wbtemp_sys_dlg_save($parent, $title, $filter, $path, $filename, $defext); } //----------------------------------------- AUXILIARY FUNCTIONS FOR INTERNAL USE -/* - -Creates a file filter for Open/Save dialog boxes based on an array. - -*/ - +/** + * Creates a file filter for Open/Save dialog boxes based on an array. + */ function _make_file_filter($filter) { - if(!$filter) - return "All Files (*.*)\0*.*\0\0"; - - if(is_array($filter)) { - $result = ""; - foreach($filter as $line) - $result .= "$line[0] ($line[1])\0$line[1]\0"; - $result .= "\0"; - return $result; - } else - return $filter; + if (!$filter) { + return "All Files (*.*)\0*.*\0\0"; + } + + if (is_array($filter)) { + $result = ""; + foreach ($filter as $line) { + $result .= "{$line[0]} ({$line[1]})\0{$line[1]}\0"; + } + $result .= "\0"; + return $result; + } else { + return $filter; + } } -//-------------------------------------------------------------------------- END - ?> diff --git a/core/libs/winbinder/winbinder.php b/core/libs/winbinder/winbinder.php index 3a69b8542..2e3fdb03c 100644 --- a/core/libs/winbinder/winbinder.php +++ b/core/libs/winbinder/winbinder.php @@ -1,29 +1,28 @@