Source for file buttons.inc.php
Documentation is available at buttons.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
define('blImageBottom', 'blImageBottom');
define('blImageLeft', 'blImageLeft');
define('blImageRight', 'blImageRight');
define('blImageTop', 'blImageTop');
* BitBtn is a dynamic button with bitmap.
//Calls inherited constructor
* Returns the right path to the image to show
private function getImageSourcePath()
return dirname($_SERVER['SCRIPT_FILENAME']). '/'. $this->_imagesource;
$submitEventValue = $this->input->{$this->getJSWrapperHiddenFieldName()};
// check if the a click event has been fired
parent::dumpJavascript();
// only output the same function once;
// otherwise if for example two buttons use the same
// OnClick event handler it would be outputted twice.
// output the wrapper function
define('updateButtonTheme', 1);
function updateButtonTheme() {
var theme = qx.manager.object.AppearanceManager.getInstance().getAppearanceTheme();
var apar = theme.getAppearance('button');
var oldState = apar.state;
apar.state = function(vTheme, vStates) {
var res = oldState ? oldState.apply(this, arguments):{};
if (typeof(res) != 'undefined' && typeof(res.backgroundColor) != 'undefined')
delete res.backgroundColor;
echo "<script type=\"text/javascript\">updateButtonTheme();</script>\n";
// first let's get the image size
list ($imgwidth, $imgheight, $type, $attr) = $result;
if ($imgwidth > 0 && $imgheight > 0)
$btnimage = ",\"$this->_imagesource\",$imgwidth,$imgheight";
// set teh general properties of the button
echo " var ". $this->Name. " = new qx.ui.form.Button(\"$this->Caption\"$btnimage);\n";
// add the onclick wrapper to the event listener
$hiddenfield = $this->getJSWrapperHiddenFieldName();
$hiddenfield = "document.forms[0].$hiddenfield";
echo " $this->Name.addEventListener(\"execute\", function(){ var event = event || window.event; return $wrapperEvent(event, $hiddenfield, '$submitEventValue', null) } );\n";
// add the common JS events to the QWidget (0 = no JS OnChange event added)
// Call the OnShow event handler after all settings of the BitBtn
// have been outputted so it is possible to reset them in the OnShow event.
// add a hidden field so we can determine which event for the button was fired
$hiddenwrapperfield = $this->getJSWrapperHiddenFieldName();
echo "<input type=\"hidden\" id=\"$hiddenwrapperfield\" name=\"$hiddenwrapperfield\" value=\"\" />";
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);\n";
// adds Enabled, Visible, Font and Color property
// set font the the button's label
echo " var lblobj = $this->Name.getLabelObject();\n";
echo " if (lblobj) lblobj.setFont(\"{$this->Font->Size} '{ $this->Font->Family}' { $this->Font->Weight}\");\n ";
echo " $this->Name.setColor(new qx.renderer.color.Color('{$this->Font->Color}'));\n ";
echo " $this->Name.setIconPosition('$iconPos');\n";
$hint = $this->getHintAttribute();
echo " $this->Name.setHtmlAttribute('title', '$this->Hint');\n";
echo " ". $this->Name. ".setBackgroundColor(new qx.renderer.color.Color('$this->Color'));\n";
echo " ". $this->Name. ".setBackgroundColor(new qx.renderer.color.ColorObject('buttonface'));\n";
* Publish the events for the component
* Occurs when the user clicks the control.
* @return mixed Returns the event handler or null if no handler is set.
function getOnClick () { return $this->_onclick; }
* Occurs when the user clicks the control.
* @param mixed Event handler or null if no handler is set.
function setOnClick ($value) { $this->_onclick= $value; }
function defaultOnClick () { return null; }
* Publish the JS events for the component
function getjsOnBlur () { return $this->readjsOnBlur(); }
function setjsOnBlur ($value) { $this->writejsOnBlur($value); }
function getjsOnClick () { return $this->readjsOnClick(); }
function setjsOnClick ($value) { $this->writejsOnClick($value); }
function getjsOnDblClick () { return $this->readjsOnDblClick(); }
function setjsOnDblClick ($value) { $this->writejsOnDblClick($value); }
function getjsOnFocus () { return $this->readjsOnFocus(); }
function setjsOnFocus ($value) { $this->writejsOnFocus($value); }
function getjsOnMouseDown () { return $this->readjsOnMouseDown(); }
function setjsOnMouseDown ($value) { $this->writejsOnMouseDown($value); }
function getjsOnMouseUp () { return $this->readjsOnMouseUp(); }
function setjsOnMouseUp ($value) { $this->writejsOnMouseUp($value); }
function getjsOnMouseOver () { return $this->readjsOnMouseOver(); }
function setjsOnMouseOver ($value) { $this->writejsOnMouseOver($value); }
function getjsOnMouseMove () { return $this->readjsOnMouseMove(); }
function setjsOnMouseMove ($value) { $this->writejsOnMouseMove($value); }
function getjsOnMouseOut () { return $this->readjsOnMouseOut(); }
function setjsOnMouseOut ($value) { $this->writejsOnMouseOut($value); }
function getjsOnKeyPress () { return $this->readjsOnKeyPress(); }
function setjsOnKeyPress ($value) { $this->writejsOnKeyPress($value); }
function getjsOnKeyDown () { return $this->readjsOnKeyDown(); }
function setjsOnKeyDown ($value) { $this->writejsOnKeyDown($value); }
function getjsOnKeyUp () { return $this->readjsOnKeyUp(); }
function setjsOnKeyUp ($value) { $this->writejsOnKeyUp($value); }
* Publish the properties for the component
function getCaption() { return $this->readCaption(); }
function setCaption($value) { $this->writeCaption($value); }
function getColor() { return $this->readColor(); }
function setColor($value) { $this->writeColor($value); }
function getFont() { return $this->readFont(); }
function setFont($value) { $this->writeFont($value); }
function getEnabled() { return $this->readEnabled(); }
function setEnabled($value) { return $this->writeEnabled($value); }
* Source of the image that appears on the button.
* If empty no image is rendered on the button.
* Source of the image that appears on the button.
* If empty no image is rendered on the button.
function setImageSource($value) { $this->_imagesource = $value; }
function defaultImageSource() { return ""; }
* Specifies where the image appears on the bitmap button.
* @return enum (blImageBottom, blImageLeft, blImageRight, blImageTop)
* Specifies where the image appears on the bitmap button.
* @param enum (blImageBottom, blImageLeft, blImageRight, blImageTop)
function setButtonLayout($value) { $this->_buttonlayout= $value; }
function getParentFont() { return $this->readParentFont(); }
function setParentFont($value) { $this->writeParentFont($value); }
function getParentShowHint() { return $this->readParentShowHint(); }
function setParentShowHint($value) { $this->writeParentShowHint($value); }
function getPopupMenu() { return $this->readPopupMenu(); }
function setPopupMenu($value) { $this->writePopupMenu($value); }
function getShowHint() { return $this->readShowHint(); }
function setShowHint($value) { $this->writeShowHint($value); }
function getVisible() { return $this->readVisible(); }
function setVisible($value) { $this->writeVisible($value); }
* SpeedButton is a button that is used to execute commands or set modes.
* Use TSpeedButton to add a button to a group of buttons in a form. SpeedButton
* also introduces properties that allow speed buttons to work together as a group.
* Speed buttons are commonly grouped in panels to create specialized tool bars
//Calls inherited constructor
$this->ControlStyle = "csRenderOwner=1";
$this->ControlStyle = "csRenderAlso=SpeedButton";
$submitteddown = $this->input->{"{ $this->Name}Down"};
if (is_object($submitteddown) && $submitteddown->asString() != "")
$this->Down = ($submitteddown->asString() == "1") ? 1 : 0;
$down = ($this->Down) ? 1 : 0;
// set teh general properties of the button
echo " var $this->Name = new qx. ui. toolbar. RadioButton(\" $this->Caption\" $btnimage);\n ";
echo " $this->Name. setAppearance(' $this->Name');\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);\n ";
// add an changeChecked event listener so the hidden field can be updated
$hiddenfield = ($this->owner != null) ? "document. forms[0 ].{ $this->Name}Down" : "";
echo " $this->Name. addEventListener(\" changeChecked\", function() { $hiddenfield. value = ( this && this. getChecked()) ? 1 : 0; }, $this->Name);\n ";
// user cannot unselect a selected button
echo " $this->Name. setDisableUncheck( true);\n ";
// add radio manager only if group index is greater than 0 and the radio manager was not already outputted
echo " var sbmanager_$this->_groupindex = new qx.manager.selection.RadioManager(null, [$this->Name]);\n";
echo " sbmanager_$this->_groupindex.add($this->Name);\n";
echo " $this->Name.setChecked(true);\n";
// if not in a group then always uncheck it after a click
echo " $this->Name.addEventListener(\"execute\", function() { this.setChecked(false); }, $this->Name);\n";
// adds Enabled, Visible, Font and Color property
// set font the the button's label
echo " var lblobj = $this->Name.getLabelObject();\n";
echo " if (lblobj) lblobj.setFont(\"{$this->Font->Size} '{ $this->Font->Family}' { $this->Font->Weight}\");\n ";
if ($this->Font->Color != "")
echo " $this->Name.setColor(new qx.renderer.color.Color('{$this->Font->Color}'));\n ";
echo " $this->Name.setIconPosition('$iconPos');\n";
$hint = $this->getHintAttribute();
echo " $this->Name.setHtmlAttribute('title', '$this->Hint');\n";
//echo " $this->Name.setStyleProperty('cursor', '$this->Cursor');\n";
echo " $this->Name.setStyleProperty('cursor', '". strtolower(substr($this->Cursor, 2)). "');\n";
echo " ". $this->Name. ".setBackgroundColor(new qx.renderer.color.Color('$this->Color'));\n";
echo " ". $this->Name. ".setBackgroundColor(new qx.renderer.color.ColorObject('buttonface'));\n";
// add the onclick wrapper to the event listener
if ($this->_onclick != null && $this->Owner != null)
$hiddenfield = $this->getJSWrapperHiddenFieldName();
$hiddenfield = "document.forms[0].$hiddenfield";
echo " $this->Name.addEventListener(\"execute\", function(){ var event = event || window.event; return $wrapperEvent(event, $hiddenfield, '$submitEventValue', null) } );\n";
// add the common JS events to the QWidget (0 = no JS OnChange event added)
// Call the OnShow event handler after all settings of the BitBtn
// have been outputted so it is possible to reset them in the OnShow event.
// add a hidden field so we can determine which event for the button was fired
$hiddenwrapperfield = $this->getJSWrapperHiddenFieldName();
echo "<input type=\"hidden\" id=\"$hiddenwrapperfield\" name=\"$hiddenwrapperfield\" value=\"\" />";
parent::dumpHeaderCode();
define("appr $this->Name", 1);
$color = "this.bgcolor_default = ";
$color .= ($this->Color == "") ? "new qx.renderer.color.ColorObject(\"buttonface\");" : "new qx.renderer.color.Color('$this->Color');";
$border = " this.border_pressed = qx.renderer.border.BorderPresets.getInstance().". ($this->Flat ? "thinInset" : "inset"). ";\n"
. " this.border_over = qx.renderer.border.BorderPresets.getInstance().". ($this->Flat ? "thinOutset" : "outset"). ";\n"
. " this.border_default = qx.renderer.border.BorderPresets.getInstance().". ($this->Flat ? "none" : "outset"). ";\n";
<script type=\"text/javascript\">
var theme = qx.manager.object.AppearanceManager.getInstance().getAppearanceTheme();
theme.registerAppearance('$this->Name',
this.bgcolor_left = new qx.renderer.color.Color(\"#FFF0C9\");
this.checked_background = \"static/image/dotted_white.gif\";
initial : function(vTheme)
var ret = vTheme.initialFrom(\"toolbar-button\");
state : function(vTheme, vStates)
var vReturn = vTheme.stateFrom(\"toolbar-button\", vStates);
vReturn.backgroundColor = vStates.abandoned ? this.bgcolor_left : this.bgcolor_default;
vReturn.backgroundImage = vStates.checked && !vStates.over ? this.checked_background : null;
if (vStates.pressed || vStates.checked || vStates.abandoned) {
vReturn.border = this.border_pressed;
} else if (vStates.over) {
vReturn.border = this.border_over;
vReturn.border = this.border_default;
theme.setupAppearance(theme.getAppearance('$this->Name'));
* Increments a counter used to allow all up
* Decrements a counter used to allow all up
* Updates common properties of the group
* @see GroupIndex, AllowAllUp
// this prevents a recursive endless-loop (only one speed button can update the others at a time)
if ($this->_updating == 0 && $this->GroupIndex > 0)
if ($this->Owner != null && $this->Name != "")
foreach ($this->Owner->components->items as $k => $v)
// only update SpeedButtons which are in the same group, don't update itself
if ($v->Name != $this->Name && $v->className() == "SpeedButton" && $v->GroupIndex == $this->_groupindex)
$v->beginUpdateProperties();
$v->endUpdateProperties();
* Specifies whether all speed buttons in the group that contains this
* speed button can be unselected at the same time.
function getAllowAllUp() { return $this->_allowallup; }
* Specifies whether all speed buttons in the group that contains this
* speed button can be unselected at the same time.
function setAllowAllUp($value)
function defaultAllowAllUp() { return 0; }
* Specifies whether the button is selected (down) or unselected (up).
function getDown() { return $this->_down; }
* Specifies whether the button is selected (down) or unselected (up).
else if ($value != $this->_down)
function defaultDown() { return 0; }
* Determines whether the button has a 3D border that provides a raised
function getFlat() { return $this->_flat; }
* Determines whether the button has a 3D border that provides a raised
function setFlat($value) { $this->_flat= $value; }
function defaultFlat() { return 0; }
* Allows speed buttons to work together as a group.
* When GroupIndex is 0, the button behaves independently of all
* other buttons on the form. When the user clicks such a speed button,
* the button appears pressed (in its clicked state) and then returns to
* its normal up state when the user releases the mouse button.
function getGroupIndex() { return $this->_groupindex; }
* Allows speed buttons to work together as a group.
* When GroupIndex is 0, the button behaves independently of all
* other buttons on the form. When the user clicks such a speed button,
* the button appears pressed (in its clicked state) and then returns to
* its normal up state when the user releases the mouse button.
function setGroupIndex($value)
function defaultGroupIndex() { return 0; }
|