Location: PHPKode > projects > WCL - Web Control Library for PHP > IControl/EventController.php
<?php
/*
 * 	(C) Copyright by Christian Möller
 * 	All Rights reserved
 *
 * 	This file is part of the WCL (Web Control Library).
 *
 *  WCL is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Foobar is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with WCL.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * Event Controller 
 */

$event_mode		= false;
$event_context	= 0;

function enter_eventmode($context) {
	global 	$event_mode,
			$event_context;
			
	$event_mode = true;
	$event_context = $context;
}
function leave_eventmode() {
	global $event_mode;
	$event_mode = false;
}
function set_target($target) {
	global $event_context;
	$event_context->decl_type($target);
	$event_context->set_target($target);
}


function _eventmode_add($key, $value) {
	global 	$event_mode,
			$event_context;
	
	if ($event_mode)
		$event_context->set_user_iattrib($key, $value);
}
function _eventmode() {
	global $event_mode;
	return $event_mode;
}



class EventController {
	
	/* Keyboard Event Mappings */
	var	$onkeydown,
		$onkeyup,
		$onkeypress;
		
	/* Mouse Mappings */
	var	$onmousedown,
		$onmouseup,
		$onmouseclick,
		$onmouseenter,
		$onmouseleave,
		$onmouseover;
	
	/* State Events */
	var $onfocus,
		$onblur;
		
	function EventController()
	{ }
		
	function setEventHandler($event_handler, $delegate) {
		
		$tmp = explode("::", $event_handler);			// split input string
		
		$type = $tmp[0];
		$event_name = $tmp[1];
		
		$event_desc = new EventDescriptor();			// Create Event Descriptor
		
		switch ($type) {								// Lets look for the binding type
			case "php":
				$event_desc->set_server_handler($delegate);
				break;
			case "javascript":
				$event_desc->set_client_handler($delegate);
				break;
			default:
				die ("Error: Invalid event binding, only php or javascript supported!");
				break;
		}
		
		switch ($event_name) {
			case "onkeydown":
				$this->onkeydown = $event_desc;
				break;
			case "onkeyup":
				$this->onkeyup = $event_desc;
				break;
			case "onkeypress":
				$this->onkeypress = $event_desc;
				break;
			case "onmousedown":
				$this->onmousedown = $event_desc;
				break;
			case "onmouseup":
				$this->onmouseup = $event_desc;
				break;
			case "onmouseclick":
				$this->onmouseclick = $event_desc;
				break;
			case "onmouseenter":
				$this->onmouseenter = $event_desc;
				break;
			case "onmouseleave":
				$this->onmouseleave = $event_desc;
				break;
			case "onmouseover":
				$this->onmouseover = $event_desc;
				break;
			case "onfocus":
				$this->onfocus = $event_desc;
				break;
			case "onblur":
				$this->onblur = $event_desc;
				break;
			default:
				die ("Error: Invalid event name ".$event_name);
				
		}
		
	}

	function render_events()
	{
		$render_out = "";
		if ($this->onmouseclick) { $render_out .= ' onclick="'.$this->onmouseclick->render().'" '; }
		if ($this->onmouseup) { $render_out .= ' onmouseup="'.$this->onmouseup->render().'" '; }
		if ($this->onmousedown) { $render_out .= ' onmousedown="'.$this->onmousedown->render().'" '; }
		if ($this->onmouseenter) { $render_out .= ' onmouseover="'.$this->onmouseenter->render().'" '; }
		if ($this->onmouseleave) { $render_out .= ' onmouseout="'.$this->onmouseleave->render().'" '; }
		if ($this->onmouseover) { $render_out .= ' onmouseover="'.$this->onmouseover->render().'" '; }
		
		return $render_out;
	}
}

?>
Return current item: WCL - Web Control Library for PHP