VCL
[ class tree: VCL ] [ index: VCL ] [ all elements ]

Source for file menus.inc.php

Documentation is available at menus.inc.php

  1. <?php
  2. /**
  3. *  This file is part of the VCL for PHP project
  4. *
  5. *  Copyright (c) 2004-2007 qadram software <support@qadram.com>
  6. *
  7. *  Checkout AUTHORS file for more information on the developers
  8. *
  9. *  This library is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU Lesser General Public
  11. *  License as published by the Free Software Foundation; either
  12. *  version 2.1 of the License, or (at your option) any later version.
  13. *
  14. *  This library is distributed in the hope that it will be useful,
  15. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. *  Lesser General Public License for more details.
  18. *
  19. *  You should have received a copy of the GNU Lesser General Public
  20. *  License along with this library; if not, write to the Free Software
  21. *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  22. *  USA
  23. *
  24. */
  25.  
  26. use_unit("controls.inc.php");
  27. use_unit("extctrls.inc.php");
  28.  
  29.  
  30. /**
  31.  * qooxdoo MainMenu
  32.  *
  33.  */
  34. class CustomMainMenu extends QWidget
  35. {
  36.         protected $_items=array();
  37.         protected $_onclick=null;
  38.         protected $_images=null;
  39.  
  40.         function __construct($aowner=null)
  41.         {
  42.                 //Calls inherited constructor
  43.                 parent::__construct($aowner);
  44.  
  45.                 $this->Width=300;
  46.                 $this->Height=24;
  47.         }
  48.  
  49.         function init()
  50.         {
  51.                 //TODO: Read this from the common POST object
  52.                 if (!$this->owner->UseAjax)
  53.                 {
  54.                         if ((isset($_POST[$this->Name."_state"])) && ($_POST[$this->Name."_state"]!=''))
  55.                         {
  56.                                 $this->callEvent('onclick',array('tag'=>$_POST[$this->Name."_state"]));
  57.                         }
  58.                 }
  59.         }
  60.  
  61.         function dumpHeaderCode()
  62.         {
  63.                 parent::dumpHeaderCode();
  64.                 //This function is used as a common click processor for all item clicks
  65.                 echo '<script type="text/javascript">';
  66.                 echo "function $this->Name"."_clickwrapper(e)\n";
  67.                 echo "{\n";
  68.                 echo " submit=true; \n";
  69.                 if (($this->ControlState csDesigning!= csDesigning)
  70.                 {
  71.                         if ($this->JsOnClick!=null)
  72.                         {
  73.                                 echo "   submit=".$this->JsOnClick."(e);\n";
  74.                         }
  75.                 }
  76.                 echo "var tag=e.getTarget().tag;\n";
  77.                 echo "if ((tag!=0) && (submit))\n";
  78.                 echo "  {\n";
  79.                 echo "  var hid=findObj('$this->Name"."_state');\n";
  80.                 echo "  if (hid) hid.value=tag;\n";
  81.                 if (($this->ControlState csDesigning!= csDesigning)
  82.                 {
  83.                         $form "document.".$this->owner->Name;
  84.                         echo "  if (($form.onsubmit) && (typeof($form.onsubmit) == 'function')) { $form.onsubmit(); }\n";
  85.                         echo "  $form.submit();\n";
  86.                 }
  87.                 echo "  }\n";
  88.                 echo "}\n";
  89.                 echo '</script>';
  90.         }
  91.  
  92.  
  93.             function loaded()
  94.             {
  95.                 parent::loaded();
  96.                 $this->setImages($this->_images);
  97.             }
  98.  
  99.  
  100.  
  101.         /**
  102.          * Dump all menu items
  103.          *
  104.          * @param array $items 
  105.          * @param integer $level 
  106.          * @param boolean $create 
  107.          * @return string 
  108.          */
  109.         function dumpMenuItems($items,$level,$create=true)
  110.         {
  111.                 if ($create)
  112.                 {
  113.                         echo "  var m$level = new qx.ui.menu.Menu;\n";
  114.                         echo "  d.add(m$level);\n";
  115.                 }
  116.                 reset($items);
  117.                 while(list($k,$v)=each($items))
  118.                 {
  119.                         $caption=$v['Caption'];
  120.                         $tag=$v['Tag'];
  121.                         if ($tag==''$tag=0;
  122.  
  123.                         if ($caption=='-')
  124.                         {
  125.                                 echo "var mb$level"."_$k = new qx.ui.menu.Separator();\n";
  126.                         }
  127.                         else
  128.                         {
  129.                                 $sub='null';
  130.                                 if ((isset($v['Items'])) && (count($v['Items'])))
  131.                                 {
  132.                                   $sub="m".($level+1);
  133.                                         echo "  var $sub = new qx.ui.menu.Menu;\n";
  134.                                         echo "  d.add($sub);\n";
  135.                                 }
  136.  
  137.                         $img='null';
  138.                 if (($this->ControlState csDesigning)!==csDesigning)
  139.                 {
  140.                         if (isset($v['ImageIndex']))
  141.                         {
  142.                                 $img=$v['ImageIndex'];
  143.                                 if ($img<>'')
  144.                                 {
  145.                                         if ($this->Images!=null)
  146.                                         {
  147.                                                 $path=$this->Images->readImage($img);
  148.                                                 if ($path===false)
  149.                                                 {
  150.                                                         $img='null';
  151.                                                 }
  152.                                                 else
  153.                                                 {
  154.                                                         $img='"'.$path.'"';
  155.                                                 }
  156.                                         }
  157.                                 }
  158.                                 else $img='null';
  159.                         }
  160.                 }
  161.  
  162.                                 echo "  var mb$level"_$k = new qx.ui.menu.Button(\"$caption\", $imgnull$sub);\n";
  163.                                 echo "  mb$level"_$k.addEventListener(\"execute\", $this->Name "_clickwrapper);\n";
  164.                                 echo "  mb$level"_$k.tag=$tag;\n";
  165.                         }
  166.  
  167.                         echo "  m$level.add(mb$level"_$k);\n";
  168.  
  169.                         if ((isset($v['Items'])) && (count($v['Items'])))
  170.                         {
  171.                                 $this->dumpMenuItems($v['Items'],$level+1false);
  172.                         }
  173.                 }
  174.                 return('m'.$level);
  175.         }
  176.  
  177.         /**
  178.          * Dump the top items
  179.          *
  180.          */
  181.         function dumpTopButtons()
  182.         {
  183.                 reset($this->_items);
  184.                 while(list($k,$v)=each($this->_items))
  185.                 {
  186.                         echo "  <!-- Topbutton Start -->\n";
  187.                         $caption=$v['Caption'];
  188.                         $m='null';
  189.                         if (isset($v['Items'])) $m=$this->dumpMenuItems($v['Items'],0);
  190.                         echo "  var mb = new qx.ui.toolbar.MenuButton(\"$caption\",$m);\n";
  191.                         __QLibrary_SetCursor("mb"$this->Cursor);
  192.                         echo "  $this->Name.add(mb);\n";
  193.                         echo "  <!-- Topbutton End -->\n";
  194.                 }
  195.  
  196.         }
  197.  
  198.         function dumpContents()
  199.         {
  200.                 $this->dumpCommonContentsTop();
  201.                 echo "        var ".$this->Name."    = new qx.ui.toolbar.ToolBar;\n";
  202.                 echo "        $this->Name.setLeft(0);\n";
  203.                 echo "        $this->Name.setTop(0);\n";
  204.                 echo "        $this->Name.setWidth($this->Width);\n";
  205.                 echo "        $this->Name.setHeight(".($this->Height-1).");\n";
  206.  
  207.                 __QLibrary_SetCursor($this->Name$this->Cursor);
  208.  
  209.                 $this->dumpTopButtons();
  210.                 $this->dumpCommonContentsBottom();
  211.         }
  212.  
  213.         /**
  214.          * Lists the images that can appear beside individual menu items.
  215.          *
  216.          * @return ImageList 
  217.          */
  218.         function getImages(return $this->_images}
  219.         function setImages($value$this->_images=$this->fixupProperty($value)}
  220.         function defaultImages(return ""}
  221.         /**
  222.          * Describes the elements of the menu.
  223.          * Use Items to access information about the elements in the menu.
  224.          * Item contain information about Caption, associated image and Tag.
  225.          *
  226.          * @return item collection
  227.          */
  228.  
  229.         function getItems()             return $this->_items}
  230.         function setItems($value)       $this->_items=$value}
  231.         /**
  232.          * OnClick event
  233.          * Occurs when the user clicks menu item.
  234.          */
  235.         function readOnClick()          return $this->_onclick}
  236.         function writeOnClick($value)   $this->_onclick=$value}
  237.         }
  238.  
  239. class MainMenu extends CustomMainMenu
  240. {
  241.         //Publish some properties
  242.         
  243.         function getFont(return $this->readFont()}
  244.         function setFont($value$this->writeFont($value)}
  245.  
  246.         function getParentFont(return $this->readParentFont()}
  247.         function setParentFont($value$this->writeParentFont($value)}
  248.  
  249.         function getAlignment(return $this->readAlignment()}
  250.         function setAlignment($value$this->writeAlignment($value)}
  251.  
  252.         function getCaption(return $this->readCaption()}
  253.         function setCaption($value$this->writeCaption($value)}
  254.  
  255.         function getColor(return $this->readColor()}
  256.         function setColor($value$this->writeColor($value)}
  257.  
  258.         function getVisible(return $this->readVisible()}
  259.         function setVisible($value$this->writeVisible($value)}
  260.  
  261.         function getOnClick()           return $this->readOnClick()}
  262.         function setOnClick($value)     $this->writeOnClick($value)}
  263.  
  264.         function getjsOnClick()         return $this->readjsOnClick()}
  265.         function setjsOnClick($value)   $this->writejsOnClick($value)}
  266. }
  267.  
  268. /**
  269. * PopupMenu class
  270. */
  271. class CustomPopupMenu extends Component
  272. {
  273.         protected $_items=array();
  274.         protected $_onclick=null;
  275.         protected $_jsonclick=null;
  276.         protected $_images = null;
  277.  
  278.         private function dumpMenuItems($name$items$level)
  279.         {
  280.                 if (isset($elements)) unset($elements);
  281.  
  282.                 reset($items);                     // $this->_items -> $k
  283.                 while(list($index$itemeach($items))
  284.         {
  285.                         $caption=$item['Caption'];
  286.  
  287.                         $imageindex=$item['ImageIndex'];
  288.                         if (($this->_images != null&& (is_object($this->_images)))
  289.                 {
  290.                                 $image $this->_images->readImageByID($imageindex1);
  291.                         }
  292.                         else
  293.                         {
  294.                                 $image "null";
  295.                 }
  296.  
  297.                         $tag $item['Tag'];
  298.                         if ($tag == ''$tag=0;
  299.  
  300.                         $itemname $name "_it" $level "_" $index;
  301.  
  302.                         if ($caption=='-')
  303.                         {
  304.                                 echo "    var $itemname = new qx.ui.menu.Separator();\n";
  305.                         }
  306.                         else
  307.                         {
  308.                                 $submenu "null";
  309.                                 $subitems $item['Items'];
  310.                                 // check if has subitems
  311.  
  312.                                 if ((isset($subitems)) && (count($subitems)))
  313.                                 {
  314.                                         $submenu $name "_sm" $level "_" $index;
  315.                                         $this->dumpMenuItems($submenu$subitems($level 1));
  316.  
  317.                                         echo "    var $itemname = new qx.ui.menu.Button(\"$caption\", $imagenull$submenu);\n";
  318.                                 }
  319.                                 else
  320.                                 {
  321.                                         echo "    var " $itemname "Cmd = new qx.client.Command();\n"
  322.                                            . "    " $itemname "Cmd.addEventListener(\"execute\", function (e{  SubmitMenuEvent(e$tag); });\n\n"
  323.                                            . "    var $itemname = new qx.ui.menu.Button(\"$caption\", $image$itemname "Cmd);\n";
  324.                                 }
  325.                         }
  326.                         $elements[$itemname;
  327.                 }
  328.  
  329.                 if (isset($elements))
  330.                 {
  331.                         echo "      ";
  332.                         if ($level != 0echo "var ";
  333.                         echo "$name = new qx.ui.menu.Menu();\n"
  334.                            . "    $name.add(implode(","$elements");\n"
  335.                            . "    d.add($name);\n\n";
  336.                         unset($elements);
  337.                 }
  338.         }
  339.  
  340.         function loaded()
  341.         {
  342.                 parent::loaded();
  343.                 $this->writeImages($this->_images);
  344.         }
  345.  
  346.         function dumpHeaderCode()
  347.         {
  348.                 __QLibrary_InitLib();
  349.  
  350.                 parent::dumpHeaderCode();
  351.  
  352.                 if (($this->ControlState csDesigning)!==csDesigning)
  353.                 {
  354.                         echo "<script type=\"text/javascript\">\n"
  355.                            . "<!--\n"
  356.                            . "  var $this->Name;\n"
  357.                            . "\n"
  358.                            . "  function CreateMenu()\n"
  359.                            . "  {\n"
  360.                            . "    if (typeof $this->Name == 'undefined')\n"
  361.                            . "    {\n"
  362.                            . "      var d = qx.ui.core.ClientDocument.getInstance();\n\n"
  363.                            . "\n";
  364.  
  365.                         $this->dumpMenuItems($this->Name$this->_items0);
  366.  
  367.                         echo "    }\n"
  368.                            . "  }\n"
  369.                            . "\n"
  370.                            . "  function SubmitMenuEvent(e, tag)\n"
  371.                            . "{\n"
  372.                            . "    submit=true;\n";
  373.  
  374.                         if (($this->ControlState csDesigning!= csDesigning)
  375.                         {
  376.                                 if ($this->JsOnClick!=null)
  377.                                 {
  378.                                         echo "    submit=" $this->JsOnClick "(e);\n";
  379.                                 }
  380.  
  381.                                 $form "document." $this->owner->Name;
  382.                                 echo "    if ((tag!=0) && (submit)) {\n"
  383.                                    . "      var hid=findObj('$this->Name"."_state');\n"
  384.                                    . "      if (hid) hid.value=tag;\n"
  385.                                    . "      if (($form.onsubmit) && (typedef($form.onsubmit)) == 'function') { alert('here'); $form.onsubmit(); }\n"
  386.                                    . "      $form.submit();\n"
  387.                            . "}\n";
  388.                         }
  389.                         echo "  }\n\n";
  390.  
  391.                         echo "  function Show$this->Name(eventtype)\n"
  392.                            . "  {\n"
  393.                            . "    CreateMenu();\n"
  394.                            . "    if (type == 0) {\n"
  395.                            . "      var tempX = 0\n"
  396.                            . "      var tempY = 0\n"
  397.                            . "      if(event.pageX || event.pageY){"
  398.                            . "        tempX = event.pageX\n"
  399.                            . "        tempY = event.pageY\n"
  400.                            . "      } else {\n"
  401.                            . "        tempX = event.clientX + document.body.scrollLeft - document.body.clientLeft\n"
  402.                            . "        tempY = event.clientY + document.body.scrollTop - document.body.clientTop\n"
  403.                            . "      }\n"
  404.                            . "    } else {\n"
  405.                            . "      tempX = event.getPageX()\n"
  406.                            . "      tempY = event.getPageY()\n"
  407.                            . "    }\n"
  408.                            . "    if (tempX < 0){tempX = 0}\n"
  409.                            . "    if (tempY < 0){tempY = 0}\n"
  410.                            . "\n"
  411.                            . "    $this->Name.setLeft(tempX);\n"
  412.                            . "    $this->Name.setTop(tempY);\n"
  413.                            . "    $this->Name.show();\n"
  414.                            . "  }\n"
  415.                            . "-->\n"
  416.                            . "</script>\n";
  417.                 }
  418.         }
  419.  
  420.         /**
  421.          * Lists the images that can appear beside individual menu items.
  422.          *
  423.          * @return ImageList 
  424.          */
  425.         protected function readImages()         return $this->_images}
  426.         protected function writeImages($value)  $this->_images = $this->fixupProperty($value)}
  427.         function defaultImages()                return null}
  428.         /**
  429.          * Describes the elements of the menu.
  430.          * Use Items to access information about the elements in the menu.
  431.          * Item contain information about Caption, associated image and Tag.
  432.          *
  433.          * @return item collection
  434.          */
  435.         protected function readItems()          return $this->_items}
  436.         protected function writeItems($value)   $this->_items=$value}
  437.         /**
  438.          * OnClick event
  439.          * Occurs when the user clicks menu item.
  440.          */
  441.         protected function readOnClick()        return $this->_onclick}
  442.         protected function writeOnClick($value$this->_onclick=$value}
  443.         /**
  444.          * OnJsClick event
  445.          * Occurs when the user clicks menu item.
  446.          */
  447.         protected function readjsOnClick()      return $this->_jsonclick}
  448.         protected function writejsOnClick($value$this->_jsonclick = $value}
  449. }
  450.  
  451. class PopupMenu extends CustomPopupMenu
  452. {
  453.         // publish properties
  454.         
  455.         function getImages()                    return $this->readImages()}
  456.         function setImages($value)              $this->writeImages($value)}
  457.  
  458.         function getItems()                     return $this->readItems()}
  459.         function setItems($value)               $this->writeItems($value)}
  460.  
  461.         // publish events
  462.         
  463.         function getOnClick()                   return $this->readOnClick()}
  464.         function setOnClick($value)             $this->writeOnClick($value)}
  465.  
  466.         function getjsOnClick()                 return $this->readjsOnClick()}
  467.         function setjsOnClick($value)           $this->writejsOnClick($value)}
  468. }
  469.  
  470. ?>

Documentation generated on Tue, 27 Mar 2007 13:35:18 +0200 by phpDocumentor 1.3.1