<?php

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

 WINBINDER - The native Windows binding for PHP for PHP

 Copyright © Hypervisual - see LICENSE.TXT for details
 Author: Bartosz Ratajczyk (konkwistador AT go2 DOT pl)

 Editbox demo

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

//------------------------------------------------------------ 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",		"Edit Boxes");	// Application name

define("ID_LABEL1",	100);
define("ID_LABEL2",	101);
define("ID_LABEL3",	102);
define("ID_LABEL4",	103);
define("ID_LABEL5",	104);
define("ID_LABEL6",	105);
define("ID_EDIT1",	111);
define("ID_EDIT2",	112);
define("ID_EDIT3",	113);
define("ID_EDIT4",	114);
define("ID_EDIT5",	115);
define("ID_EDIT6",	116);
define("ID_CHKBX1",	131);
define("ID_FRAME1",	141);
define("ID_FRAME2",	142);
define("ID_FRAME3",	143);
define("ID_FRAME4",	144);
define("ID_FRAME5",	145);
define("ID_FRAME6",	145);

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

// create main window
$mainwin = wb_create_window(NULL, AppWindow, APPNAME, WBC_CENTER, WBC_CENTER, 350, 460, WBC_NOTIFY, WBC_KEYDOWN);

// create controls
wb_create_control($mainwin, Frame, "Centered edit box", 15, 15, 315, 48, ID_FRAME1);
wb_create_control($mainwin, Label, "Insert text", 30, 35, 50, 20, ID_LABEL1);
$eb = wb_create_control($mainwin, EditBox, "", 90, 32, 100, 20, ID_EDIT1, WBC_CENTER);
wb_create_control($mainwin, Label, "style: WBC_CENTERED", 200, 35, 120, 20);

wb_create_control($mainwin, Frame, "Disabled edit box", 15, 75, 315, 48, ID_FRAME2);
wb_create_control($mainwin, EditBox, "This edit box is disabled.", 30, 93, 160, 20, ID_EDIT2, WBC_DISABLED);
wb_create_control($mainwin, Label, "style: WBC_DISABLED", 200, 95, 120, 20, ID_LABEL2);

wb_create_control($mainwin, Frame, "Multiline edit box", 15, 135, 315, 108, ID_FRAME3);
wb_create_control($mainwin, EditBox, "This one has long, long, long, long (very long) wrapped text.", 30, 155, 160, 70, ID_EDIT3, WBC_MULTILINE);
wb_create_control($mainwin, Label, "style: WBC_MULTILINE", 200, 155, 120, 20, ID_LABEL3);

wb_create_control($mainwin, Frame, "Digits-only edit box", 15, 250, 315, 48, ID_FRAME4);
wb_create_control($mainwin, EditBox, "", 30, 270, 160, 20, ID_EDIT4, WBC_NUMBER);
wb_create_control($mainwin, Label, "style: WBC_NUMBER", 200, 270, 120, 20, ID_LABEL4);

wb_create_control($mainwin, Frame, "Read-only edit box", 15, 300, 315, 48, ID_FRAME5);
wb_create_control($mainwin, EditBox, "This text cannot be edited.", 30, 320, 160, 20, ID_EDIT5, WBC_READONLY);
wb_create_control($mainwin, Label, "style: WBC_READONLY", 200, 320, 120, 20, ID_LABEL5);

wb_create_control($mainwin, Frame, "Masked edit box", 15, 350, 315, 48, ID_FRAME6);
wb_create_control($mainwin, EditBox, "", 30, 370, 160, 20, ID_EDIT6, WBC_MASKED);
wb_create_control($mainwin, Label, "style: WBC_MASKED", 200, 370, 120, 20, ID_LABEL6);

$statusbar = wb_create_control($mainwin, StatusBar);

// Enter application loop

wb_set_handler($mainwin, "process_main");
wb_main_loop();

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

/* Process main window commands */

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

	global $eb, $statusbar;

	switch($id) {

		case ID_EDIT1:
		case ID_EDIT3:
		case ID_EDIT6:
			if($lparam1 == WBC_KEYDOWN)
				wb_set_text($statusbar, "Char $lparam2: " . chr($lparam2));
			break;
		break;

		case ID_CHKBX1:
			wb_set_enabled(wb_get_control($window, ID_EDIT1), !wb_get_enabled($eb));
		break;

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

}

//------------------------------------------------------------------ END OF FILE

?>