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

 Double-click 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",		"Double-click test");

// Control identifiers

define("ID_EDIT",			101);
define("ID_ITEMLIST",		102);
define("ID_DESCRIPTION",	103);

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

$items = array(
	"This code demonstrates how",
	"to process the double-click",
	"event. A single-click",
	"in the list box generates",
	"one action, while a double-click",
	"generates another one.",
);

// Create main window

$mainwin = wb_create_window(NULL, PopupWindow, APPNAME, WBC_CENTER, WBC_CENTER, 305, 240,
  WBC_NOTIFY, WBC_DBLCLICK);
wb_set_handler($mainwin, "process_main");

// Create controls

wb_create_control($mainwin, EditBox, "", 10, 15, 225, 22, ID_EDIT);
wb_create_control($mainwin, PushButton, "Change", 240, 14, 50, 24, IDOK, WBC_DISABLED);
wb_create_control($mainwin, EditBox, "", 10,150, 280, 22, ID_DESCRIPTION, WBC_READONLY);
wb_create_control($mainwin, StatusBar, "Click to select, Double-click to edit", $mainwin, 0, 0, 0);
$itemlist = wb_create_control($mainwin, ListBox, "", 10, 45, 280,100, ID_ITEMLIST);

// Fill up list with items

wb_set_text($itemlist, $items);

// Start

wb_main_loop();

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

/* Main window processing */

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

	switch($id) {

		case ID_ITEMLIST:
			if($lparam == WBC_DBLCLICK) {
				wb_set_text(wb_get_control($window, ID_EDIT), wb_get_text($ctrl));
				wb_set_text(wb_get_control($window, ID_DESCRIPTION), "");
				wb_set_enabled(wb_get_control($window, IDOK), TRUE);
			} else {
				wb_set_text(wb_get_control($window, ID_EDIT), "");
				wb_set_text(wb_get_control($window, ID_DESCRIPTION), wb_get_text($ctrl));
				wb_set_enabled(wb_get_control($window, IDOK), FALSE);
			}
			break;

		case IDOK:
			$text = trim(wb_get_text(wb_get_control($window, ID_EDIT)));
			if($text) {
				$items[wb_get_selected($itemlist)] = $text;
				wb_set_text($itemlist, $items);
				wb_set_text(wb_get_control($window, ID_EDIT), "");
			}
			break;

		case IDCLOSE:
			//save_columns("item", $itemlist);
			wb_destroy_window($window);
			break;
	}
}

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

?>