<?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)

 Tab control tests

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

//------------------------------------------------------------ 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("MAIN_TAB1",		1001);
define("MAIN_TAB2",		1002);

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

// Create main window

$mainwin = wb_create_window(NULL, PopupWindow, "Tab control tests", WBC_CENTER, WBC_CENTER, 580, 440, WBC_NOTIFY, WBC_HEADERSEL);

// Create tab control and tabs

//--------------------------------------------------- Create a tab control

$maintab = wb_create_control($mainwin, TabControl,
  "Tab1\nTab2\nTab3\nTab4\nTab5", 4, 4, 560, 185, MAIN_TAB1, WBC_VISIBLE);

// Create children controls

wb_create_control($maintab, Slider,		"",	   110, 30,140, 25, 	102, 0, 0, 0);
wb_create_control($maintab, ScrollBar,	"",		20, 30, 16,120, 	103, 0, 0, 0);
wb_create_control($maintab, ScrollBar,	"",	   115, 90,140, 16, 	104, 0, 0, 0);

wb_create_control($maintab, Label,		"Hi",	40, 40, 70, 20, 	201, 0, 0, 1);
wb_create_control($maintab, CheckBox,	"Op1",	40, 60, 70, 20, 	202, 0, 1, 1);
wb_create_control($maintab, CheckBox,	"Op2",	40, 80, 70, 20, 	203, 0, 0, 1);

wb_create_control($maintab, Label,		"Hi!",	40, 40, 70, 20, 	301, 0, 0, 1);
wb_create_control($maintab, RadioButton,"Op1",  40, 40, 60, 20, 	302, 0, 0, 2);
wb_create_control($maintab, RadioButton,"Op2",  40, 60, 60, 20, 	303, 0, 1, 2);
wb_create_control($maintab, RadioButton,"Op3",  40, 80, 60, 20, 	304, 0, 0, 2);

wb_create_control($maintab, Label,		"Hey",	40, 40, 70, 20, 	401, 0, 0, 3);
wb_create_control($maintab, CheckBox,	"Op1",	40, 60, 70, 20, 	402, 0, 0, 3);
wb_create_control($maintab, CheckBox,	"Op2",	40, 80, 70, 20, 	403, 0, 1, 3);

// Create a tab control inside the tab control...

$sectab = wb_create_control($maintab, TabControl,	"T1\nT2\nT3\nT4\nT5",	10, 10, 260, 140, 	2001, 0, 0, 4);

// ... and its controls

wb_create_control($sectab, Slider,		"",	    60, 10,140, 25, 	102, 0, 0, 0);
wb_create_control($sectab, ScrollBar,	"",		10, 10, 16, 80, 	103, 0, 0, 0);
wb_create_control($sectab, ScrollBar,	"",	    65, 50,140, 16, 	104, 0, 0, 0);

wb_create_control($sectab, Label,		"Hi",	20, 20, 70, 20, 	201, 0, 0, 1);
wb_create_control($sectab, CheckBox,	"Op1",	20, 40, 70, 20, 	202, 0, 0, 1);
wb_create_control($sectab, CheckBox,	"Op2",	20, 60, 70, 20, 	203, 0, 1, 1);

// Create another tab control inside the tab control...

$sectab2 = wb_create_control($maintab, TabControl,	"T1\nT2\nT3\nT4\nT5",	280, 10, 260, 140, 	2002, 0, 0, 4);

// ... and its controls

wb_create_control($sectab2, Slider,		"",	    60, 10,140, 25, 	102, 0, 0, 0);
wb_create_control($sectab2, ScrollBar,	"",		10, 10, 16, 80, 	103, 0, 0, 0);
wb_create_control($sectab2, ScrollBar,	"",	    65, 50,140, 16, 	104, 0, 0, 0);

wb_create_control($sectab2, Label,		"Hi",	20, 20, 70, 20, 	201, 0, 0, 1);
wb_create_control($sectab2, CheckBox,	"Op1",	20, 40, 70, 20, 	202, 0, 0, 1);
wb_create_control($sectab2, CheckBox,	"Op2",	20, 60, 70, 20, 	203, 0, 1, 1);

//--------------------------------------------------- Create a second tab control

$maintab2 = wb_create_control($mainwin, TabControl,
  "Tab1\nTab2\nTab3\nTab4\nTab5", 4, 204, 560, 185, MAIN_TAB2, WBC_VISIBLE);

// Create child controls

wb_create_control($maintab2, Slider,	"",	   110, 30,140, 25, 	102, 0, 0, 0);
wb_create_control($maintab2, ScrollBar,	"",		20, 30, 16,120, 	103, 0, 0, 0);
wb_create_control($maintab2, ScrollBar,	"",	   115, 90,140, 16, 	104, 0, 0, 0);

wb_create_control($maintab2, Label,		"Hi",	40, 40, 70, 20, 	201, 0, 0, 1);
wb_create_control($maintab2, CheckBox,	"Op1",	40, 60, 70, 20, 	202, 0, 1, 1);
wb_create_control($maintab2, CheckBox,	"Op2",	40, 80, 70, 20, 	203, 0, 0, 1);

wb_create_control($maintab2, Label,		"Hi!",	40, 40, 70, 20, 	301, 0, 0, 1);
wb_create_control($maintab2, RadioButton,"Op1", 40, 40, 60, 20, 	302, 0, 0, 2);
wb_create_control($maintab2, RadioButton,"Op2", 40, 60, 60, 20, 	303, 0, 1, 2);
wb_create_control($maintab2, RadioButton,"Op3", 40, 80, 60, 20, 	304, 0, 0, 2);

wb_create_control($maintab2, Label,		"Hey",	40, 40, 70, 20, 	401, 0, 0, 3);
wb_create_control($maintab2, CheckBox,	"Op1",	40, 60, 70, 20, 	402, 0, 0, 3);
wb_create_control($maintab2, CheckBox,	"Op2",	40, 80, 70, 20, 	403, 0, 1, 3);

// Create a tab control inside the tab control...

$sectab = wb_create_control($maintab2, TabControl,	"T1\nT2\nT3\nT4\nT5",	10, 10, 530, 140, 	2003, 0, 0, 4);

// ... and its controls

wb_create_control($sectab, Slider,		"",	    60, 10,140, 25, 	102, 0, 0, 0);
wb_create_control($sectab, ScrollBar,	"",		10, 10, 16, 80, 	103, 0, 0, 0);
wb_create_control($sectab, ScrollBar,	"",	    65, 50,140, 16, 	104, 0, 0, 0);

wb_create_control($sectab, Label,		"Hi",	20, 20, 70, 20, 	201, 0, 0, 1);
wb_create_control($sectab, CheckBox,	"Op1",	20, 40, 70, 20, 	202, 0, 0, 1);
wb_create_control($sectab, CheckBox,	"Op2",	20, 60, 70, 20, 	203, 0, 1, 1);

/*
// And a third level (which doesn't work yet)

$sectab4 = wb_create_control($sectab, TabControl,	"A\nB\nC\nD\nE",	220, 10, 290, 100, 	3001, 0, 0, 0);

// ... and its controls

wb_create_control($sectab4, Slider,		"",	    60, 10,140, 25, 	102, 0, 0, 0);
wb_create_control($sectab4, ScrollBar,	"",		10, 10, 16, 60, 	103, 0, 0, 0);
wb_create_control($sectab4, ScrollBar,	"",	    65, 50,140, 16, 	104, 0, 0, 0);
*/

//------------------------------------------------------ Select tabs

wb_set_selected($maintab, 4);
wb_set_selected($maintab2, 4);

// Almost done

$statusbar = wb_create_control($mainwin, StatusBar);
wb_set_handler($mainwin, "process_main");
wb_main_loop();

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

function process_main($window, $id, $ctrl, $lparam1=0, $lparam2=0)
{
	global $statusbar;

	switch($id) {

		case 102:
			$val = wb_get_value($ctrl);
			wb_set_value(wb_get_control($window, 103), $val);
			wb_set_value(wb_get_control($window, 104), $val);
			wb_set_text($statusbar, "Value: " . $val);
			break;

		case IDCLOSE:
			wb_destroy_window($window);
			break;

//		case MAIN_TAB1:
//		case MAIN_TAB2:
		default:
			if((wb_get_class($ctrl) == TabControl) && ($lparam1 & WBC_HEADERSEL)) {
				wb_set_text($statusbar, "Tab #$lparam2 of tab control #$id selected.");
			} else
				wb_set_text($statusbar, "Control ID: " . $id);
			break;

	}
}

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

?>