Phundament-Components
[ class tree: Phundament-Components ] [ index: Phundament-Components ] [ all elements ]

Source for file LMenu.php

Documentation is available at LMenu.php

  1. <?php
  2. /**
  3.  * class file.
  4.  *
  5.  * @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
  6.  * @copyright 2005, diemeisterei GmbH. All rights reserved.
  7.  * @author $Author: schmunk $
  8.  * @version $Revision: 313 $  $Date: 2006-07-30 21:04:58 +0000 (So, 30 Jul 2006) $
  9.  * @package Phundament.Components
  10.  * @subpackage WebControls
  11.  */
  12.  
  13. /**
  14.  * @todo doc
  15.  *
  16.  * @package System
  17.  * @subpackage Interfaces
  18.  */
  19.  
  20. {
  21. }
  22.  
  23. /**
  24.  * @todo doc
  25.  *
  26.  * @package System.Web.UI.WebControls
  27.  * @subpackage Navigation
  28.  */
  29.  
  30. class LBaseMenuNode extends TControl
  31. {
  32.     const MODE_INTEGER 1;
  33.     const MODE_DIRECTION 2;
  34.     const MODE_FLOAT 3;
  35.  
  36.     protected $_li_class;
  37.     protected $_ul_class;
  38.  
  39.     protected $_text = null;
  40.     protected $_level = 0;
  41.     protected $_direction = array();
  42.     protected $_width = array();
  43.     protected $_height = array();
  44.     protected $_style_id = array();
  45.     
  46.     public function getLevel(
  47.     return $this->_level}
  48.  
  49.     public function setDirection($value
  50.     $this->genericSet("_direction"$valueself::MODE_DIRECTION)}
  51.     public function getDirection($level = -1
  52.     return $this->genericGet("_direction"$level"V")}
  53.     
  54.     public function setWidth($value
  55.     $this->genericSet("_width"$valueself::MODE_FLOAT)}
  56.     public function getWidth($level 0
  57.     return $this->genericGet("_width"$levelnull)}
  58.  
  59.     public function setHeight($value
  60.     $this->genericSet("_height"$valueself::MODE_FLOAT)}
  61.     public function getHeight($level 0
  62.     return $this->genericGet("_height"$levelnull)}
  63.  
  64.     public function setStyleId($value
  65.     $this->genericSet("_style_id"$valueself::MODE_INTEGER)}
  66.     public function getStyleId($level = -1
  67.     return $this->genericGet("_style_id"$levelnull)}
  68.  
  69.     public function getText()
  70.     return $this->_text
  71.         
  72.     public function setText($value)
  73.     $this->_text = $value}
  74.         
  75.  
  76.     public function getMenu(
  77.     
  78.         $menu $this;
  79.         while (!$menu instanceof LMenu$menu $menu->Parent;
  80.         return $menu;        
  81.     }
  82.  
  83.     private function genericSet($aname$values$mode self::MODE_INTEGER)
  84.     {
  85.         $ar &$this->$aname;
  86.         $ar split(":"$values);
  87.         switch($mode)
  88.         {
  89.             case self::MODE_INTEGER:
  90.                 foreach($ar as $key => $dir)
  91.                     $ar[$keyTPropertyValue::ensureInteger($dir);
  92.                 break;
  93.             case self::MODE_DIRECTION:
  94.                 foreach($ar as $key => $dir)
  95.                     $ar[$keyTPropertyValue::ensureEnum($dirarray("V""H"));
  96.                 break;
  97.             case self::MODE_FLOAT:
  98.                 foreach($ar as $key => $dir)
  99.                     $ar[$keyTPropertyValue::ensureFloat($dir);
  100.                 break;
  101.         }
  102.     }
  103.     
  104.     private function genericGet($aname$level$default)
  105.     {
  106.         $ar &$this->$aname;
  107.         if (isset($ar[$level])) return $ar[$level];
  108.         else
  109.             if ($this->Parent instanceof LBaseMenuNode)
  110.                 return $this->Parent->genericGet($aname$level+1$default);
  111.             else
  112.                 return $default;
  113.     }
  114.     
  115.     public function addParsedObject($obj)
  116.     {
  117.         if (!$this instanceof IAcceptStringContent)
  118.             if (is_string($obj)) return;
  119.         $this->Controls[$obj;
  120.         if ($obj instanceof LBaseMenuNode)
  121.         {
  122.             $obj->_level $this->_level+1;    
  123.         }
  124.     }
  125.     
  126.     public function onLoad($param)
  127.     {
  128.         parent::onLoad($param);
  129.         $this->_li_class = $this->Menu->registerLIClass($this);
  130.         $this->_ul_class = $this->Menu->registerULClass($this);
  131.     }
  132.  
  133.     public function render($writer)
  134.     {
  135.         $nodes array();
  136.         $contents array();
  137.         foreach($this->Controls as $control)
  138.         {
  139.             if ($control instanceof LBaseMenuNode)
  140.                 $nodes[$control;
  141.             else
  142.                 $contents[$control;            
  143.         }
  144.         if (count($contents== && $this->_text)
  145.             $contents[$this->_text;
  146.  
  147.         $cc count($contents);
  148.         $cn count($nodes);
  149.  
  150.         if ($cc)
  151.         {
  152.             if ($this->_li_class !== null)
  153.                 $writer->addAttribute("class"$this->_li_class);
  154.             $writer->renderBeginTag('li');
  155.  
  156.             $sid $this->getStyleId();
  157.             if ($sid !== null)
  158.                 $writer->addAttribute("class""c".$sid);
  159.             $writer->renderBeginTag('a');
  160.  
  161.             foreach($contents as $control)
  162.             {
  163.                 if(is_string($control))
  164.                     $writer->write($control);
  165.                 else if($control instanceof TControl)
  166.                     $control->renderControl($writer);
  167.                 else if($control instanceof IRenderable)
  168.                     $control->render($writer);
  169.             }        
  170.             $writer->renderEndTag();
  171.         }
  172.         
  173.         if (count($nodes))
  174.         {
  175.             if ($this->_ul_class !== null)
  176.                 $writer->addAttribute("class"$this->_ul_class);
  177.             $writer->renderBeginTag('ul');
  178.             foreach($nodes as $node)
  179.                 $node->render($writer);
  180.             $writer->renderEndTag();
  181.         }
  182.  
  183.         if ($cc)
  184.         {
  185.             $writer->renderEndTag();
  186.         }
  187.     }
  188.  
  189. }
  190.  
  191.  
  192. /**
  193.  * @todo doc
  194.  *
  195.  * @package System.Web.UI.WebControls
  196.  * @subpackage Navigation
  197.  */
  198.  
  199. class LMenu extends LBaseMenuNode
  200. {
  201.     const MAXLEVEL 5;
  202.     
  203.     protected $_css = array();
  204.     protected $_li_classes = array();
  205.     protected $_ul_classes = array();
  206.     protected $_styles = array();
  207.     protected $_hover_styles = array();
  208.  
  209.     public function getStyle0(return $this->privateGetStyle($this->_styles0)}
  210.     public function getStyle1(return $this->privateGetStyle($this->_styles1)}
  211.     public function getStyle2(return $this->privateGetStyle($this->_styles2)}
  212.  
  213.     public function getHoverStyle0(return $this->privateGetStyle($this->_hover_styles0)}
  214.     public function getHoverStyle1(return $this->privateGetStyle($this->_hover_styles1)}
  215.     public function getHoverStyle2(return $this->privateGetStyle($this->_hover_styles2)}
  216.  
  217.     public function privateGetStyle(&$styles$num)
  218.     {
  219.         if (isset($styles[$num]))
  220.             return $styles[$num];
  221.         $styles[$numnew TPanelStyle();
  222.         return $styles[$num];        
  223.     }
  224.     
  225.     public function registerLIClass($node)
  226.     {
  227.         $w $node->getWidth();
  228.         $h $node->getHeight();
  229.         $d $node->getDirection();
  230.  
  231.         $uid array($w$d);
  232.         $hash md5(serialize($uid));
  233.         if (isset($this->_li_classes[$hash]))
  234.             return $this->_li_classes[$hash];
  235.         //var_dump("LI", $uid);
  236.         
  237.         $classname "c".count($this->_li_classes);
  238.         $this->_li_classes[$hash$classname;
  239.         
  240.         if ($d == "H")
  241.         {
  242.             $s array();
  243.             $s["float:left";
  244.             //$s[] = "background-color:red";
  245.             if ($w !== null$s["width:$w".$this->getUnit();
  246.         }
  247.         else
  248.         {
  249.             $s array();
  250.             $s["float:none";
  251.             //$s[] = "background-color:yellow";
  252.             if ($w !== null$s["width:$w".$this->getUnit();
  253.         }
  254.         $this->_css[$this->getCSSBlock("#".$this->ClientID." li.".$classname$s);  
  255.         return $classname;
  256.     }
  257.  
  258.     public function registerULClass($node)
  259.     {
  260.         $w $node->getWidth();
  261.         $h $node->getHeight();
  262.         $d $node->getDirection();
  263.  
  264.         $uid array($w$h$d);
  265.         $hash md5(serialize($uid));
  266.         if (isset($this->_ul_classes[$hash]))
  267.         {
  268.             return $this->_ul_classes[$hash];
  269.         }
  270.         
  271.         $classname "c".count($this->_ul_classes);
  272.         $this->_ul_classes[$hash$classname;
  273.         
  274.         if ($d == "H")
  275.         {
  276.             $s array();
  277.             $s["margin:0";
  278.         }
  279.         else
  280.         {
  281.             $s array();
  282.             $s["margin: -".($h $h.$this->getUnit("0")." 0 0 ".($w $w.$this->getUnit("0");
  283.         }
  284.         $s["width:50em";
  285.         $this->_css[$this->getCSSBlock("#".$this->ClientID." ul.".$classname$s);  
  286.         return $classname;
  287.     }
  288.  
  289.     public function onPreRender($param)
  290.     {
  291.         parent::onPreRender($param);
  292.  
  293.         $id $this->getClientId();
  294.  
  295.         foreach ($this->_styles as $key => $style)
  296.         {
  297.             $s array();
  298.             foreach($style->StyleFields as $field => $parm)
  299.                 $s[$field.":".$parm;
  300.             $cs split(";"$style->CustomStyle);
  301.             $s array_merge($s$cs);
  302.             $this->_css[$this->getCSSBlock("#".$this->ClientID." a.c".$key$s);  
  303.         }
  304.         
  305.         foreach ($this->_hover_styles as $key => $style)
  306.         {
  307.             $s array();
  308.             foreach($style->StyleFields as $field => $parm)
  309.                 $s[$field.":".$parm;
  310.             $cs split(";"$style->CustomStyle);
  311.             $s array_merge($s$cs);
  312.             $this->_css[$this->getCSSBlock("#".$this->ClientID." a.c".$key.":hover"$s);  
  313.         }
  314.  
  315.  
  316.         $this->_css[$this->getCSSBlock("#$id, #$id ul, #$id li"array
  317.             "padding:0",
  318.             "margin:0",
  319.         ));
  320.         $this->_css[$this->getCSSBlock("#$id, #$id ul"array
  321.             "list-style:none",
  322.         ));
  323.         $this->_css[$this->getCSSBlock("#$id a"array
  324.             "display:block",
  325.             //"padding:0.5em 1em",
  326.             //"background-color:transparent",
  327.             //"height:3em",
  328.         ));
  329.         /*
  330.         $this->_css[] = $this->getCSSBlock("#$id a:hover", array( 
  331.             "background-color:blue",
  332.         ));
  333.         */
  334.         
  335.         
  336.         $sel array("#$id li ul")
  337.         for($level 1$level self::MAXLEVEL$level++)
  338.             $sel["#$id li:hover ".str_repeat("ul "$level+1)
  339.         $this->_css[$this->getCSSBlock(implode(", "$sel)array
  340.             "position:absolute",
  341.             "left:-999em",
  342.         ));
  343.         $sel array()
  344.         for($level 0$level self::MAXLEVEL$level++)
  345.             $sel["#$id ".str_repeat("li "$level)."li:hover ul"
  346.         $this->_css[$this->getCSSBlock(implode(", "$sel)array
  347.             "left:auto",
  348.         ));
  349.  
  350.  
  351.         $this->Page->ClientScript->registerStyleSheet($this->ClientID."_CSS"implode("\n"$this->_css));
  352.     }
  353.  
  354.     public function render($writer)
  355.     {
  356.         $writer->addAttribute("id"$this->getClientId());
  357.         $writer->addStyleAttribute("width""50em");
  358.         $writer->renderBeginTag('ul');
  359.         $this->renderChildren($writer);
  360.         $writer->renderEndTag();
  361.         $writer->addStyleAttribute("clear""both");
  362.         $writer->renderBeginTag("div");
  363.         $writer->renderEndTag();
  364.     }    
  365.  
  366.     public function getUnit()
  367.     {
  368.         return "em";
  369.     }
  370.  
  371.     protected function getCSSBlock($sel$param)
  372.     {
  373.         return $sel." { ".implode(";"$param)." }";
  374.     }
  375.  
  376. }
  377.  
  378.  
  379.  
  380.  
  381. /**
  382.  * @todo doc
  383.  *
  384.  * @package System.Web.UI.WebControls
  385.  * @subpackage Navigation
  386.  */
  387.  
  388. {
  389.  
  390. /**
  391.  * @todo doc
  392.  *
  393.  * @package System.Web.UI.WebControls
  394.  * @subpackage Navigation
  395.  */
  396.  
  397. class LTemplateMenuNode extends LBaseMenuNode implements INamingContainerIAcceptStringContent
  398. {
  399.     protected $_tpl;
  400.     
  401.     public function getItemTemplate()
  402.     {
  403.         return $this->_tpl;
  404.     
  405.         
  406.     public function setItemTemplate($value)
  407.     {
  408.         $this->_tpl = $value;
  409.     }
  410.     
  411.     public function createChildControls()
  412.     {
  413.         if($tpl $this->getItemTemplate())
  414.         {
  415.             foreach($tpl->getDirective(as $name=>$value)
  416.             {
  417.                 if(is_string($value))
  418.                     $this->setSubProperty($name,$value);
  419.                 else
  420.                     throw new TConfigurationException('templatecontrol_directive_invalid',get_class($this),$name);
  421.             }
  422.             $tpl->instantiateIn($this);
  423.         }
  424.     }
  425.     
  426. }
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440. ?>

Documentation generated on Sun, 25 Feb 2007 16:11:06 +0100 by phpDocumentor 1.3.1