Location: PHPKode > projects > WCL - Web Control Library for PHP > TabbedPane/TabbedPane.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/>.
 */

class wuiTabbedPane extends wuiPanel {
	
	var $tabs = array(),
		$headerclass,
		$contentclass,
		$selectedclass,
		$headerpanel,
		$contentpanel,
		$selectedIndex;
	
	function wuiTabbedPane($name) {
		parent::wuiPanel($name);
	}
	function add($control, $text) {
		$this->tabs[$text] = $control;
	}
	function setHeaderClass($class) {
		$this->headerclass = $class;
	}
	function setContentClass($class) {
		$this->contentclass = $class;
	}
	function setSelectedClass($class) {
		$this->selectedclass = $class;
	}
	function setSelected($index) {
		if (!_eventmode()) 
			if ($index < count($this->tabs)) $this->selectedIndex = $index;
		else 
			_eventmode("JAVASCRIPT_FOR_SELECTING_ITEMS", "");
	}
	function getSelected() {
		return $this->selectedIndex;
	}
	function getSelectedClass() {
		if (!_eventmode()) return $this->selectedclass;
	}
	function getHeaderClass() {
		if (!_eventmode()) return $this->headerclass;
	}
	// override render_controls method
	function render_controls() {
		
		$header_panel = new wuiPanel($this->name."header_panel");
		$content_panel = new wuiPanel($this->name."content_panel");
		$content_panel->setCAttrib($this->contentclass);
		
		// create tab headers 
		$id = 0;
		$ctl_array = array();
		
		foreach ($this->tabs as $tab_text=>$tab) {
			
			$tab_ctl = new wuiLabel($this->getName().($id)."_header");
			$tab_ctl->setText($tab_text);
			$tab_ctl->setSAttrib("float:left;");
			if (($id) != $this->selectedIndex)
				$tab_ctl->setCAttrib($this->headerclass);
			else 
				$tab_ctl->setCAttrib($this->selectedclass);
			$tab_ctl->setTextAlign(ALIGN_CENTER);
			$tab_ctl->setTextVAlign(VALIGN_MIDDLE);
			
			$header_panel->add($tab_ctl);
			if (($id) != $this->selectedIndex)
				$tab->setInvisible();
			else 	
				$tab->setVisible();
			$content_panel->add($tab);
			
			$id++;
		}

		$id = 0;
		foreach ($header_panel->getControls() as $control) {
			
			$control_mouseClick = new wuiEvent("onmouseclick", $control);

			# REGION MOUSE EVENT CLICK FOR TAB HEADER
			enter_eventmode($control_mouseClick);
			
				$controls = $content_panel->getControls();
				
				set_target($controls[$id]);
					$controls[$id]->setVisible();
			
				foreach ($header_panel->getControls() as $header_deactivate) {
					set_target($header_deactivate);
						$header_deactivate->setCAttrib($this->headerclass);
				}
				
				set_target($control);
					$control->setCAttrib($this->selectedclass);
	
				
				foreach ($content_panel->getControls() as $content_control) {
					if ($content_control != $controls[$id])	{
						set_target($content_control);
							$content_control->setInvisible();
					}
				}
			leave_eventmode();
			#ENDREGION
			
			$control->setEvent($control_mouseClick);
			$id++;
		}
		
		$content_panel->setSAttrib("clear: left;");
		$content = $header_panel->render().$content_panel->render();
		
		$this->headerpanel = $header_panel;
		$this->contentpanel = $content_panel;
		
		return $content;
	}
}

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