<?php

/*******************************************************************************

 WINBINDER - The native Windows binding for PHP for PHP

 Copyright © Hypervisual - see LICENSE.TXT for details
 Author: Rubem Pechansky (http://winbinder.org/contact.php)

 Script to test wb_get_focus()

*******************************************************************************/

//------------------------------------------------------------ SYSTEM PARAMETERS

define("PATH_SCRIPT",	dirname(__FILE__) . "/");
define("PATH_DATA",		PATH_SCRIPT);
define("PATH_INC",		PATH_SCRIPT . "../include/");
define("PATH_RES",		PATH_SCRIPT . "../resources/");

//----------------------------------------------------------------- DEPENDENCIES

include PATH_INC . "winbinder.php";

//-------------------------------------------------------------------- CONSTANTS

define("APPNAME", 			"Focus tests");
define("ID_TIMER",			101);

// Control identifiers

define("IDC_FOCUS",			102);
define("ID_TIME",			103);
define("IDC_MODAL",			104);
define("IDC_MODELESS",		105);
define("IDC_MSGBOX",		106);

//-------------------------------------------------------------- EXECUTABLE CODE

create_main_window();
wb_main_loop();

//-------------------------------------------------------------------- FUNCTIONS

function create_main_window()
{
	// Create main window

	$mainwin = wb_create_window(NULL, AppWindow, APPNAME, WBC_CENTER, WBC_CENTER, 545, 320, WBC_INVISIBLE, 0);
	wb_set_handler($mainwin, "process_main");

	// Insert various controls

	wb_create_control($mainwin, CheckBox, "Checkbox 1", 14, 105, 91, 14, 0);
	wb_create_control($mainwin, CheckBox, "Checkbox 2", 14, 125, 91, 14, 0);
	$combo = wb_create_control($mainwin, ComboBox, "", 399, 4, 130, 195, 0, WBC_READONLY);
	wb_set_text($combo, "1\n2\n3");
	wb_create_control($mainwin, EditBox, "10", 169, 152, 145, 21, 0, WBC_MASKED);
	wb_create_control($mainwin, EditBox, "20", 226, 175, 89, 21, 0, WBC_NUMBER);
	wb_create_control($mainwin, EditBox, "30", 325, 61, 205, 55, 0, WBC_MULTILINE);
	wb_create_control($mainwin, EditBox, "40", 4, 175, 155, 21, 0, WBC_READONLY);
	wb_create_control($mainwin, EditBox, "50", 235, 104, 40, 19, 0, WBC_NUMBER);
	wb_create_control($mainwin, EditBox, "Hi", 148, 104, 40, 19, 0, WBC_NUMBER);
	wb_create_control($mainwin, EditBox, "Pack my box with five dozen liquor jugs", 4, 152, 155, 21, 0);
	wb_create_control($mainwin, Frame, "Group box", 4, 6, 140, 89, 0);
	wb_create_control($mainwin, Gauge, "Progress bar", 184, 35, 103, 14, 0);
	wb_create_control($mainwin, Label, "&Digits only:", 169, 180, 55, 21, 0, WBC_RIGHT);
	wb_create_control($mainwin, Label, "(Values)", 4, 204, 316, 26, 0, WBC_MULTILINE);
	wb_create_control($mainwin, Label, "Drag me:", 193, 52, 59, 14, 0, WBC_CENTER);
	wb_create_control($mainwin, Label, "Label", 148, 35, 26, 14, 0, WBC_RIGHT);
	$list = wb_create_control($mainwin, ListBox, "", 325, 4, 68, 52, 0);
	wb_set_text($list, "A\nB\nC");
	wb_create_control($mainwin, RTFEditBox, "Rich text", 325, 120, 205, 55, 0);
	wb_create_control($mainwin, RadioButton, "Opt. &B1", 74, 24, 58, 14, 0, WBC_GROUP);
	wb_create_control($mainwin, RadioButton, "&Opt. B2", 74, 48, 58, 14, 0);
	wb_create_control($mainwin, RadioButton, "O&pt. B3", 74, 73, 58, 14, 0);
	wb_create_control($mainwin, RadioButton, "Opt. A&1", 10, 24, 59, 14, 0, WBC_GROUP);
	wb_create_control($mainwin, RadioButton, "Opt. A&2", 10, 48, 59, 14, 0);
	wb_create_control($mainwin, RadioButton, "Opt. A&3", 10, 73, 59, 14, 0);
	wb_create_control($mainwin, ScrollBar, "Horizontal scroll", 148, 130, 145, 16, 0);
	wb_create_control($mainwin, ScrollBar, "Horizontal scroll", 154, 9, 136, 16, 0);
	wb_create_control($mainwin, ScrollBar, "Vertical scroll", 298, 4, 16, 126, 0);
	wb_create_control($mainwin, Slider, "Slider control", 148, 68, 145, 26, 0);
	wb_create_control($mainwin, Spinner, "Hello", 190, 104, 16, 19, 0);

	// Insert controls to monitor the focus

	wb_create_control($mainwin, PushButton, "Message box",     325, 180, 100, 24, IDC_MSGBOX);
	wb_create_control($mainwin, PushButton, "Modal dialog",    325, 210, 100, 24, IDC_MODAL);
	wb_create_control($mainwin, PushButton, "Modeless dialog", 325, 240, 100, 24, IDC_MODELESS);

	wb_create_control($mainwin, Label, "Time:", 10, 245, 80, 22, ID_TIME);
	wb_create_control($mainwin, Label, "...", 5, 265, 545, 22, IDC_FOCUS);

	$font = wb_create_font("Arial", 10, null, FTA_BOLD);
	wb_set_font(wb_get_control($mainwin, IDC_FOCUS), $font);
	wb_create_timer($mainwin, ID_TIMER, 100);
	process_main($mainwin, ID_TIMER);

	// Show window

	wb_set_visible($mainwin, true);
}

function process_main($window, $id)
{
	switch($id) {

		case ID_TIMER:
			wb_set_text(wb_get_control($window, ID_TIME), date("h:i:s A"));
			wb_set_text(wb_get_control($window, IDC_FOCUS), 'Focus: "' . wb_get_text(wb_get_focus()) . '"');
			break;

		case IDC_MSGBOX:
			wb_message_box($window, "Hello");
			break;

		case IDC_MODAL:
			$dlg = wb_create_window($window, ModalDialog, "Modal dialog box", WBC_CENTER, WBC_CENTER, 200, 100);
			wb_create_control($dlg, PushButton, "Close me", 40, 20, 100, 20, IDCLOSE);
			wb_set_handler($dlg, "process_dlg");
			break;

		case IDC_MODELESS:
			$dlg = wb_create_window($window, ModelessDialog, "Modeless dialog box", WBC_CENTER, WBC_CENTER, 200, 100);
			wb_create_control($dlg, PushButton, "Close me", 40, 20, 100, 20, IDCLOSE);
			wb_set_handler($dlg, "process_dlg");
			break;

		case IDCLOSE:
			if(wb_message_box($window, "Are your sure?", APPNAME, WBC_YESNO))
				wb_destroy_window($window);
			break;
	}
}

function process_dlg($window, $id)
{
	switch($id) {

		case IDCLOSE:
			wb_destroy_window($window);
			break;
	}
}

//-------------------------------------------------------------------------- END

?>