Source for file menus.inc.php
Documentation is available at menus.inc.php
* This file is part of the VCL for PHP project
* Copyright (c) 2004-2007 qadram software <support@qadram.com>
* Checkout AUTHORS file for more information on the developers
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
//Calls inherited constructor
//TODO: Read this from the common POST object
if (!$this->owner->UseAjax)
if ((isset ($_POST[$this->Name. "_state"])) && ($_POST[$this->Name. "_state"]!= ''))
$this->callEvent('onclick',array('tag'=> $_POST[$this->Name. "_state"]));
//This function is used as a common click processor for all item clicks
echo '<script type="text/javascript">';
echo "function $this->Name". "_clickwrapper(e)\n";
if ($this->JsOnClick!= null)
echo " submit=". $this->JsOnClick. "(e);\n";
echo "var tag=e.getTarget().tag;\n";
echo "if ((tag!=0) && (submit))\n";
echo " var hid=findObj('$this->Name". "_state');\n";
echo " if (hid) hid.value=tag;\n";
$form = "document.". $this->owner->Name;
echo " if (($form.onsubmit) && (typeof($form.onsubmit) == 'function')) { $form.onsubmit(); }\n";
echo " $form.submit();\n";
echo " var m$level = new qx.ui.menu.Menu;\n";
echo " d.add(m$level);\n";
while(list ($k,$v)= each($items))
echo "var mb$level". "_$k = new qx.ui.menu.Separator();\n";
if ((isset ($v['Items'])) && (count($v['Items'])))
echo " var $sub = new qx.ui.menu.Menu;\n";
if (isset ($v['ImageIndex']))
$path= $this->Images->readImage($img);
echo " var mb$level" . "_$k = new qx.ui.menu.Button(\"$caption\", $img, null, $sub);\n";
echo " mb$level" . "_$k.addEventListener(\"execute\", " . $this->Name . "_clickwrapper);\n";
echo " mb$level" . "_$k.tag=$tag;\n";
echo " m$level.add(mb$level" . "_$k);\n";
if ((isset ($v['Items'])) && (count($v['Items'])))
echo " <!-- Topbutton Start -->\n";
echo " var mb = new qx.ui.toolbar.MenuButton(\"$caption\",$m);\n";
echo " $this->Name.add(mb);\n";
echo " <!-- Topbutton End -->\n";
echo " var ". $this->Name. " = new qx.ui.toolbar.ToolBar;\n";
echo " $this->Name.setLeft(0);\n";
echo " $this->Name.setTop(0);\n";
echo " $this->Name.setWidth($this->Width);\n";
echo " $this->Name.setHeight(". ($this->Height- 1). ");\n";
* Lists the images that can appear beside individual menu items.
function getImages() { return $this->_images; }
function defaultImages() { return ""; }
* Describes the elements of the menu.
* Use Items to access information about the elements in the menu.
* Item contain information about Caption, associated image and Tag.
* @return item collection
function getItems() { return $this->_items; }
function setItems($value) { $this->_items= $value; }
* Occurs when the user clicks menu item.
function readOnClick() { return $this->_onclick; }
function writeOnClick($value) { $this->_onclick= $value; }
//Publish some properties
function getFont() { return $this->readFont(); }
function setFont($value) { $this->writeFont($value); }
function getParentFont() { return $this->readParentFont(); }
function setParentFont($value) { $this->writeParentFont($value); }
function getAlignment() { return $this->readAlignment(); }
function setAlignment($value) { $this->writeAlignment($value); }
function getCaption() { return $this->readCaption(); }
function setCaption($value) { $this->writeCaption($value); }
function getColor() { return $this->readColor(); }
function setColor($value) { $this->writeColor($value); }
function getVisible() { return $this->readVisible(); }
function setVisible($value) { $this->writeVisible($value); }
function getOnClick() { return $this->readOnClick(); }
function setOnClick($value) { $this->writeOnClick($value); }
function getjsOnClick() { return $this->readjsOnClick(); }
function setjsOnClick($value) { $this->writejsOnClick($value); }
private function dumpMenuItems($name, $items, $level)
if (isset ($elements)) unset ($elements);
reset($items); // $this->_items -> $k
while(list ($index, $item) = each($items))
$caption= $item['Caption'];
$imageindex= $item['ImageIndex'];
$image = $this->_images->readImageByID($imageindex, 1);
$itemname = $name . "_it" . $level . "_" . $index;
echo " var $itemname = new qx.ui.menu.Separator();\n";
$subitems = $item['Items'];
if ((isset ($subitems)) && (count($subitems)))
$submenu = $name . "_sm" . $level . "_" . $index;
$this->dumpMenuItems($submenu, $subitems, ($level + 1));
echo " var $itemname = new qx.ui.menu.Button(\"$caption\", $image, null, $submenu);\n";
echo " var " . $itemname . "Cmd = new qx.client.Command();\n"
. " " . $itemname . "Cmd.addEventListener(\"execute\", function (e) { SubmitMenuEvent(e, $tag); });\n\n"
. " var $itemname = new qx.ui.menu.Button(\"$caption\", $image, " . $itemname . "Cmd);\n";
if ($level != 0) echo "var ";
echo "$name = new qx.ui.menu.Menu();\n"
. " $name.add(" . implode(",", $elements) . ");\n"
$this->writeImages($this->_images);
echo "<script type=\"text/javascript\">\n"
. " function CreateMenu()\n"
. " if (typeof $this->Name == 'undefined')\n"
. " var d = qx.ui.core.ClientDocument.getInstance();\n\n"
$this->dumpMenuItems($this->Name, $this->_items, 0);
. " function SubmitMenuEvent(e, tag)\n"
if ($this->JsOnClick!= null)
echo " submit=" . $this->JsOnClick . "(e);\n";
$form = "document." . $this->owner->Name;
echo " if ((tag!=0) && (submit)) {\n"
. " var hid=findObj('$this->Name". "_state');\n"
. " if (hid) hid.value=tag;\n"
. " if (($form.onsubmit) && (typedef($form.onsubmit)) == 'function') { alert('here'); $form.onsubmit(); }\n"
echo " function Show$this->Name(event, type)\n"
. " if(event.pageX || event.pageY){"
. " tempX = event.pageX\n"
. " tempY = event.pageY\n"
. " tempX = event.clientX + document.body.scrollLeft - document.body.clientLeft\n"
. " tempY = event.clientY + document.body.scrollTop - document.body.clientTop\n"
. " tempX = event.getPageX()\n"
. " tempY = event.getPageY()\n"
. " if (tempX < 0){tempX = 0}\n"
. " if (tempY < 0){tempY = 0}\n"
. " $this->Name.setLeft(tempX);\n"
. " $this->Name.setTop(tempY);\n"
. " $this->Name.show();\n"
* Lists the images that can appear beside individual menu items.
protected function readImages() { return $this->_images; }
function defaultImages() { return null; }
* Describes the elements of the menu.
* Use Items to access information about the elements in the menu.
* Item contain information about Caption, associated image and Tag.
* @return item collection
protected function readItems() { return $this->_items; }
protected function writeItems($value) { $this->_items= $value; }
* Occurs when the user clicks menu item.
protected function readOnClick() { return $this->_onclick; }
protected function writeOnClick($value) { $this->_onclick= $value; }
* Occurs when the user clicks menu item.
protected function readjsOnClick() { return $this->_jsonclick; }
protected function writejsOnClick($value) { $this->_jsonclick = $value; }
function getImages() { return $this->readImages(); }
function setImages($value) { $this->writeImages($value); }
function getItems() { return $this->readItems(); }
function setItems($value) { $this->writeItems($value); }
function getOnClick() { return $this->readOnClick(); }
function setOnClick($value) { $this->writeOnClick($value); }
function getjsOnClick() { return $this->readjsOnClick(); }
function setjsOnClick($value) { $this->writejsOnClick($value); }
|