define('IDC_SLIDER1002', 1002);
}
if (!defined('IDC_SCROLLBAR1003')) {
    define('IDC_SCROLLBAR1003', 1003);
}
if (!defined('IDC_GAUGE1004')) {
    define('IDC_GAUGE1004', 1004);
}
// Create window
$winmain = wb_create_window(null, ModalDialog, '(Empty Form)', WBC_CENTER, WBC_CENTER, 389, 315, 0x0, 0);
// Insert controls
$tab = $control = wb_create_control($winmain, TabControl, 'Tab1,Tab2,Tab3', 5, 20, 155, 240, IDC_TABCONTROL1001, 0x0, 0, 0);
$control = wb_create_control($tab, EditBox, 'EditBox2', 20, 13, 90, 20, IDC_EDITBOX1002, 0x0, 0, 0);
$control = wb_create_control($tab, EditBox, 'EditBox3', 20, 38, 90, 20, IDC_EDITBOX1003, 0x0, 0, 0);
$control = wb_create_control($tab, Label, 'Label4', 20, 73, 90, 15, IDC_LABEL1001, 0x0, 0, 0);
$control = wb_create_control($tab, Label, 'Label5', 20, 93, 90, 15, IDC_LABEL1001, 0x0, 0, 0);
$control = wb_create_control($tab, RadioButton, 'RadioButton6', 20, 123, 120, 15, IDC_RADIOBUTTON1001, 0x0, 0, 0);
$control = wb_create_control($winmain, CheckBox, 'CheckBox7', 185, 20, 120, 15, IDC_CHECKBOX1001, 0x0, 0, 0);
$ctrl = $control = wb_create_control($winmain, ComboBox, 'ComboBox8', 185, 40, 120, 60, IDC_COMBOBOX1003, 0x40, 0, 0);
wb_set_text($ctrl, explode(',', 'ComboBox8'));
$control = wb_create_control($winmain, EditBox, 'EditBox9', 185, 70, 90, 20, IDC_EDITBOX1004, 0x0, 0, 0);
$control = wb_create_control($winmain, ListView, 'ListView10,List12', 185, 100, 185, 75, IDC_LISTVIEW1001, 0x0, 0, 0);
$control = wb_create_control($winmain, ImageButton, 'resources\\ctrl_listbox3.bmp', 185, 190, 24, 24, IDC_IMAGEBUTTON1001, 0x0, 3, 0);
$control = wb_create_control($tab, EditBox, 'EditBox12', 25, 163, 90, 20, IDC_EDITBOX1001, 0x0, 0, 0);
$ctrl = $control = wb_create_control($winmain, Slider, 'Slider13', 260, 185, 100, 20, IDC_SLIDER1002, 0x0, 50, 0);
wb_set_value($ctrl, 50);
$ctrl = $control = wb_create_control($winmain, ScrollBar, 'ScrollBar14', 225, 185, 18, 82, IDC_SCROLLBAR1003, 0x0, 50, 0);
wb_set_value($ctrl, 50);
$ctrl = $control = wb_create_control($winmain, Gauge, 'Gauge15', 260, 215, 100, 20, IDC_GAUGE1004, 0x0, 50, 0);
wb_set_value($ctrl, 50);
// End controls
function create_project_dlg($parent)
{
    global $wb;
    include "fe_project.form.php";
    // 	Read various settings
    foreach ($wb->project_array as $var) {
        $var = strtolower($var);
        $ctrl = wb_get_control($wb->winproject, constant("IDC_" . strtoupper($var)));
        if (preg_match("/[\\d\\.\\,]+/", $wb->form[$wb->currentform]->{$var})) {
            wb_set_value($ctrl, $wb->form[$wb->currentform]->{$var});
        } else {
            if (wb_get_class($ctrl) != RadioButton && wb_get_class($ctrl) != CheckBox) {
                wb_set_text($ctrl, $wb->form[$wb->currentform]->{$var});
            }
        }
    }
    // Disable / enable controls according to context
    wb_set_enabled(wb_get_control($wb->winproject, IDC_LOCPREFIX), wb_get_value(wb_get_control($wb->winproject, IDC_LOCALIZE)));
    $val = wb_get_value(wb_get_control($wb->winproject, IDC_ISTABPAGE));
    wb_set_enabled(wb_get_control($wb->winproject, IDC_TABNUMBER), $val);
    wb_set_enabled(wb_get_control($wb->winproject, IDC_TABNUMBERSPINNER), $val);
    $hastext = wb_get_text(wb_get_control($wb->winproject, IDC_CTRLVAR)) !== '';
    wb_set_enabled(wb_get_control($wb->winproject, IDC_STARTCTRLVAL), $hastext);
    wb_set_handler($wb->winproject, "process_project");
    wb_set_visible($wb->winproject, true);
    set_default_accel($wb->winproject, false);
}
function process_options($window, $id, $ctrl)
{
    global $wb;
    switch ($id) {
        case IDC_WIREFRAME:
        case IDC_GRID:
            wb_set_value(wb_get_control($wb->mainwin, $id), wb_get_value($ctrl));
            break;
        case IDC_BROWSE:
            $current = wb_get_text(wb_get_control($window, IDC_FILEPATH));
            $path = wb_sys_dlg_path($window, 'Select default path for project files:', $current);
            if ($path) {
                wb_set_text(wb_get_control($window, IDC_FILEPATH), $path);
            }
            break;
        case IDOK:
            // 	Set various settings
            foreach ($wb->options_array as $var) {
                $var = strtolower($var);
                $ctrl = wb_get_control($wb->winoptions, constant("IDC_" . strtoupper($var)));
                if (wb_get_class($ctrl) == CheckBox) {
                    $wb->{$var} = wb_get_value($ctrl);
                } else {
                    $wb->{$var} = wb_get_text($ctrl);
                }
            }
            // Fall-through
        // Fall-through
        case IDCANCEL:
            set_default_accel();
            wb_destroy_window($window);
            break;
    }
}
function test_lists($window)
{
    // ListView
    $list = wb_get_control($window, IDC_LISTVIEW2027);
    wb_set_text($list, array(array("Home", 120), "Status", array("More", 50), array(0, 80)));
    wb_create_items($list, array(array("0", "First", "Done", "Less"), array(0, 0, "Second", "Hi"), array(200, 300, "Hi!", 876)));
    wb_set_text($list, array(444, 555, 666));
    //	wb_set_style($list, WBC_CHECKBOXES);
    wb_set_image($list, PATH_RES . "treeview.bmp", 0, GREEN, 10);
    //	wb_set_item_image($list, array(1, 1), 4);
    //	wb_delete_items($list, 0);
    wb_set_value($list, array(1, 2));
    wb_set_value($list, array(1, 3));
    //	wbtemp_set_listview_item_checked($list, 0, 1);
    // ListView II
    $list = wb_get_control($window, IDC_LISTVIEW2067);
    wb_set_text($list, array("No grid lines", "on this control!"));
    wb_create_items($list, array(array("To do this,", "set"), array("the control style", "to WS_BORDER")));
    // List boxes / combo boxes
    wb_set_text(wb_get_control($window, IDC_LISTBOX2018), "List 1\r\nOne more\rAnother\nEtc.\r\nMore...");
    wb_set_text(wb_get_control($window, IDC_COMBOBOX2010), array("Option 1", "Option 2", "More", "Etc."));
    wb_set_value(wb_get_control($window, IDC_UPDOWN2069), null, 0, 3);
    // Handler
    //	wb_set_handler($window, "process_test_lists");
}
function wb_create_control($parent, $class, $caption = "", $xpos = 0, $ypos = 0, $width = 0, $height = 0, $id = null, $style = 0, $lparam = null, $ntab = 0)
{
    switch ($class) {
        case Accel:
            return wbtemp_set_accel_table($parent, $caption);
        case ToolBar:
            return wbtemp_create_toolbar($parent, $caption, $width, $height, $lparam);
        case Menu:
            return wbtemp_create_menu($parent, $caption);
        case HyperLink:
            return wbtemp_create_control($parent, $class, $caption, $xpos, $ypos, $width, $height, $id, $style, is_null($lparam) ? NOCOLOR : $lparam, $ntab);
        case ComboBox:
        case ListBox:
        case ListView:
            $ctrl = wbtemp_create_control($parent, $class, $caption, $xpos, $ypos, $width, $height, $id, $style, $lparam, $ntab);
            if (is_array($caption)) {
                wb_set_text($ctrl, $caption[0]);
            }
            return $ctrl;
        case TreeView:
            $ctrl = wbtemp_create_control($parent, $class, $caption, $xpos, $ypos, $width, $height, $id, $style, $lparam, $ntab);
            if (is_array($caption)) {
                wb_set_text($ctrl, $caption[0]);
            }
            return $ctrl;
        case Gauge:
        case Slider:
        case ScrollBar:
            $ctrl = wbtemp_create_control($parent, $class, $caption, $xpos, $ypos, $width, $height, $id, $style, $lparam, $ntab);
            if ($lparam) {
                wb_set_value($ctrl, $lparam);
            }
            return $ctrl;
        default:
            return wbtemp_create_control($parent, $class, $caption, $xpos, $ypos, $width, $height, $id, $style, $lparam, $ntab);
    }
}
function process_main($window, $id, $ctrl)
{
    global $statusbar, $fmod, $mainwin;
    switch ($id) {
        case ID_INFOTIMER:
            $status = "´ÅÅÌ: " . $fmod->fmod_GetOutputName() . " ";
            $status .= "¸èÇú³¤¶È: " . $fmod->fmod_GetLenght(true) . " ·ÖÖÓ ";
            $status .= "ÒѲ¥·Å: " . $fmod->fmod_Msec2Time($fmod->fmod_GetTime(true)) . " sec ";
            if ($song_name = $fmod->fmodStreamUrl) {
                $status .= "Ãû³Æ: {$song_name} ";
            }
            wb_set_text($statusbar, $status);
            //		play position
            if ($fmod->fmod_GetLenght(false)) {
                wb_set_value(wb_get_control($mainwin, ID_PLAY_POS), round($fmod->fmod_GetTime(false) / $fmod->fmod_GetLenght(false), 2) * 100);
            }
            if ($fmod->fmod_GetTime(false) == $fmod->fmod_GetLenght(false)) {
                $fmod->fmod_StreamOpen($fmod->fmodStreamUrl);
                $fmod->fmod_StreamPlay();
            }
            break;
        case ID_OPEN:
            $filename = wb_sys_dlg_open();
            if ($filename) {
                if ($fmod->fmod_StreamOpen($filename)) {
                    $fmod->fmod_StreamPlay();
                    // returns true, then play
                } else {
                    wb_message_box($window, "Error opening Audiostream!\n" . $fmod->lasterror, APPNAME, WBC_INFO);
                }
            }
            break;
        case ID_CLOSE:
            $fmod->fmod_StreamStop();
            break;
        case ID_PLAY:
            $fmod->fmod_StreamPlay();
            break;
        case ID_STOP:
            $fmod->fmod_StreamStop();
            break;
        case ID_PAUSE:
            if ($fmod->fmodStreamState == 1) {
                switch ($fmod->fmodIsPaused) {
                    case 0:
                        $fmod->fmod_SoundPause(true);
                        wb_set_text($ctrl, "¼ÌÐø..");
                        break;
                    case 1:
                        $fmod->fmod_SoundPause(false);
                        wb_set_text($ctrl, "ÔÝÍ£");
                        break;
                }
            }
            break;
        case ID_MUTE:
            if ($fmod->fmodStreamState == 1) {
                switch ($fmod->fmodIsMuted) {
                    case 0:
                        $fmod->fmod_SoundMute(true);
                        wb_set_text($ctrl, "·ÅÒô");
                        break;
                    case 1:
                        $fmod->fmod_SoundMute(false);
                        wb_set_text($ctrl, "¾²Òô");
                        break;
                }
            }
            break;
        case ID_SURROUND:
            switch ($fmod->fmodSurroundEnabled) {
                case 0:
                    $fmod->fmod_SetSurround(true);
                    wb_set_text($ctrl, "Ñ­»·");
                    break;
                case 1:
                    $fmod->fmod_SetSurround(false);
                    wb_set_text($ctrl, "²»Ñ­»·");
                    break;
            }
            break;
        case ID_VOLUMEN:
            $fmod->fmod_SetVolumen(wb_get_value($ctrl));
            wb_set_text($statusbar, "ÒôÁ¿: " . $fmod->fmod_GetVolumen());
            break;
        case ID_BALANCE:
            $fmod->fmod_SetPanning(wb_get_value($ctrl));
            break;
        case ID_BALCENTER:
            $fmod->fmod_SetPanning(127);
            wb_set_value(wb_get_control($window, ID_BALANCE), 127);
            break;
        case IDCLOSE:
            $fmod->fmod_SoundClose();
            wb_release_library($fmod->fmodlib);
            wb_destroy_window($window);
            break;
    }
}
 function download_file($save_to_var = false)
 {
     $this->_update_download_status('connecting');
     // did a error happen? then stop the process!
     if ($this->status == 'error') {
         return false;
     }
     // build request:
     $http_request = $this->get_http_request();
     $host = $this->get_host();
     $port = $this->get_port();
     // did a error happen? then stop the process!
     if ($this->status == 'error') {
         return false;
     }
     // open connection:
     $errno = 0;
     $errstr = "";
     $connection = @fsockopen($host, $port, $errno, $errstr, 1);
     if (!$connection) {
         $this->_error('download_file', "connection failed: {$errstr} (#{$errno})");
         return false;
     }
     // send http header:
     if (!fwrite($connection, $http_request)) {
         $this->_error('download_file', 'could not send the http header!');
         return false;
     }
     // did a error happen? then stop the process!
     if ($this->status == 'error') {
         return false;
     }
     if (!$save_to_var) {
         // save content to this file:
         if (!($dll_file_handle = fopen($this->target_file, 'wb'))) {
             $this->_error('download_file', 'could not write to file!');
             return false;
         }
     }
     // needed variables:
     $content_size = 0;
     $current_size = 0;
     $reached_content = 0;
     $header = '';
     $buffer = '';
     $percent = 0;
     // set progressbar range to 100
     if ($this->wb_progressbar_active) {
         wb_set_range($this->wb_progressbar, 0, 100);
     }
     $this->_update_download_status('getting_header');
     while (!feof($connection) and $this->status != 'error') {
         if ($reached_content == 1) {
             //
             // getting data
             //
             // fill buffer
             $buffer = fgets($connection, 1024);
             // append buffer to file or variable
             if ($save_to_var) {
                 $this->file_contents .= $buffer;
             } else {
                 fwrite($dll_file_handle, $buffer);
             }
             // update cur size
             $current_size += strlen($buffer);
             // did the user hit ESC?
             if ($this->stop_key != NULL and wb_wait() == $this->stop_key) {
                 // then break
                 break;
             }
             if ($content_size != 0) {
                 $percent = round(100 / $content_size * $current_size);
                 if ($this->wb_progressbar_active) {
                     wb_set_value($this->wb_progressbar, $percent);
                 }
             }
         } else {
             // get header
             $buffer = fgets($connection, 2);
             $header .= $buffer;
             // end of header?
             if (strstr($header, $this->end_of_header)) {
                 $this->_update_download_status('downloading');
                 // save header
                 $this->header_str = $header;
                 // extract content size from header
                 $content_size = $this->get_content_length();
                 // update vars
                 $reached_content = 1;
                 $buffer = '';
             }
         }
     }
     // close download file
     if (!$save_to_var) {
         fclose($dll_file_handle);
     }
     // close connection
     if (!@fclose($connection)) {
         $this->_error('download_file', 'could not close the connection!');
     }
     $this->_update_download_status('finished');
     return true;
 }
function update_cat_controls($window)
{
    global $mainwin, $cat_table, $it_list;
    // Below: get id of selected treeview element. See comment in update_items()
    $it_list = wb_get_control($window, ID_TREE);
    $sel_text = wb_get_text($it_list);
    $cat_data = db_get_data("cat", null, "name");
    $sel_index = (int) array_search($sel_text, $cat_data);
    $cat_data = db_get_data("cat", null, "id");
    $id_cat = $cat_data[$sel_index];
    $id = db_get_id($cat_table, $sel_index);
    $data = db_get_data($cat_table, $id, null, "", FETCH_ASSOC);
    $data = $data[0];
    wb_set_text(wb_get_control($window, ID_NAME), $data["name"]);
    wb_set_value(wb_get_control($window, ID_LEVEL), $data["level"]);
    wb_set_enabled(wb_get_control($window, ID_SETITEM), $sel_text != "");
    wb_set_enabled(wb_get_control($window, ID_DELETEITEM), $sel_text != "");
}
function read_settings()
{
    global $wb;
    // Read data from INI file
    $wb->settings = parse_ini(file_get_contents(SYS_INIFILE));
    if (!isset($wb->settings['Settings'])) {
        $wb->settings = parse_ini("[Settings]\nmain_geom = \"100 100 730 575\"\nfilepath = \"\"\n wireframe = 0\n grid = 1\n ghost = 1\n showhex = 1\n autophp = 1\n constructionlines = 1\n showgrid = 1\n autopath = 1");
    }
    // 	Read various settings
    foreach ($wb->options_array as $var) {
        $ctrl = @wb_get_control($wb->mainwin, constant("IDC_" . strtoupper($var)));
        if ($ctrl) {
            $var = strtolower($var);
            $wb->{$var} = $wb->settings["Settings"][$var];
            if ($wb->{$var} !== '' && preg_match("/[\\d\\.\\,]+/", $wb->{$var})) {
                wb_set_value($ctrl, $wb->{$var});
            } else {
                wb_set_text($ctrl, $wb->{$var});
            }
        }
    }
    read_window_geom($wb->mainwin, "main", true);
}
function process_test_values($window, $id, $ctrl = 0, $lparam1 = 0, $lparam2 = 0)
{
    global $statusbar;
    if ($lparam1 == WBC_GETFOCUS) {
        wb_set_text($statusbar, "Focus to control {$id}");
        return false;
    }
    switch ($id) {
        case IDC_EDIT4069:
        case IDC_EDIT4071:
            if ($lparam1 == WBC_KEYDOWN) {
                wb_set_text($statusbar, "Char {$lparam2}: " . chr($lparam2));
            }
            break;
        case IDC_EDIT4057:
            if ($lparam1 == WBC_KEYDOWN) {
                wb_set_text($statusbar, "Char {$lparam2}: " . chr($lparam2));
                //				wb_set_text(wb_get_control($window, IDC_STATIC4048), $lparam2 . "\n" . chr($lparam2));
                break;
            }
            $text = wb_get_text(wb_get_control($window, IDC_EDIT4057));
            wb_set_text(wb_get_control($window, IDC_EDIT4058), $text);
            wb_set_text(wb_get_control($window, IDC_EDIT4059), $text);
            wb_set_text(wb_get_control($window, IDC_EDIT4065), implode(" ", array_fill(0, 20, $text)));
            break;
        case IDC_LISTBOX4053:
            if ($lparam1 & WBC_DBLCLICK) {
                wb_set_text(wb_get_control($window, IDC_STATIC4048), "Double-click");
            } else {
                wb_set_text(wb_get_control($window, IDC_STATIC4048), "Single click");
            }
            break;
        case IDC_HSCROLL4056:
        case IDC_SLIDER4011:
            $value = wb_get_value(wb_get_control($window, $id));
            wb_set_value(wb_get_control($window, IDC_PROGRESSBAR4007), $value);
            wb_set_text(wb_get_control($window, IDC_STATIC4019), $value);
            wb_set_value(wb_get_control($window, IDC_HSCROLL4026), $value);
            wb_set_value(wb_get_control($window, IDC_VSCROLL4051), $value);
            wb_set_value(wb_get_control($window, IDC_UPDOWN4028), $value);
            $value = wb_get_value(wb_get_control($window, $id));
            wb_set_text(wb_get_control($window, IDC_STATIC4048), "Control #{$id}: value [{$value}]\n");
            wb_set_value(wb_get_control($window, IDC_EDIT4052), $value);
            break;
        case IDC_RADIOBUTTON4014:
        case IDC_RADIOBUTTON4015:
        case IDC_RADIOBUTTON4016:
            $value = $id - IDC_RADIOBUTTON4014;
            wb_set_value(wb_get_control($window, IDC_LISTBOX4053), $value);
            wb_set_value(wb_get_control($window, IDC_COMBOBOX4054), $value);
            wb_set_value(wb_get_control($window, IDC_LISTBOX4055), $value);
            break;
        case IDC_CHECKBOX4034:
            wb_set_selected(wb_get_control($window, IDC_CHECKBOX4049), wb_get_selected($ctrl));
            $value = wb_get_value(wb_get_control($window, $id));
            wb_set_text(wb_get_control($window, IDC_STATIC4048), "Control #{$id}: value [{$value}]\n");
            break;
        case IDC_UPDOWN4028:
        case IDC_CHECKBOX4049:
            $value = wb_get_value(wb_get_control($window, $id));
            wb_set_text(wb_get_control($window, IDC_STATIC4048), "Control #{$id}: value [{$value}]\n");
            break;
    }
}