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

 Code sample: Status bar

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

//------------------------------------------------------------ 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',		'Status bar examples');

// Control identifiers

define('IDC_ONE',	 		1001);
define('IDC_TWO',	 		1002);
define('IDC_SIX',	 		1003);
define('IDC_SET',	 		1004);

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

create_main_window();
wb_main_loop();

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

// Create main window

function create_main_window()
{
	global $statusbar;

	$mainwin = wb_create_window(NULL, ResizableWindow, APPNAME, WBC_CENTER, WBC_CENTER, 550, 200,
	  WBC_NOTIFY, WBC_DBLCLICK);

	wb_create_control($mainwin, PushButton, 'One segment',		20, 20, 120, 24, IDC_ONE);
	wb_create_control($mainwin, PushButton, 'Two segments',		20, 50, 120, 24, IDC_TWO);
	wb_create_control($mainwin, PushButton, 'Six segments',		20, 80, 120, 24, IDC_SIX);
	wb_create_control($mainwin, PushButton, 'Set 2nd segment',	20,110, 120, 24, IDC_SET);

	wb_set_handler($mainwin, 'process_main');

	// Create the status bar

	$statusbar = wb_create_control($mainwin, StatusBar, "Press a button");

	wb_create_items($statusbar, array(
		array('This has 120 pixels', 120),
		array('', 20),
		array('Just enough for this text', null),
		array('This one always extends to the end', null)
	));
	wb_set_visible($mainwin, true);
}

/* Main window processing */

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

	switch($id) {

		case IDC_ONE:
			wb_create_items($statusbar, array(
				array('One segment only: this is the default.'),
			));
			break;

		case IDC_TWO:
			wb_create_items($statusbar, array(
				array('', 80),
				array('This bar has two segments.'),
			));
			break;

		case IDC_SIX:
			wb_create_items($statusbar, array(
				array('This bar has six segments.'),
				array('Auto'),
				array('Auto'),
				array(''),
				array('', 10),
				array('Last segment'),
			));
			break;

		case IDC_SET:
			wb_set_text($statusbar, '2nd seg', 1);
			break;

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

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

?>