Spaces:
Sleeping
Sleeping
File size: 4,762 Bytes
07c3cdd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | <?php
// $Header: /cvsroot/html2ps/box.button.php,v 1.29 2007/01/24 18:55:43 Konstantin Exp $
/**
* @package HTML2PS
* @subpackage Document
*
* This file contains the class desribing layout and behavior of 'input type="button"'
* elements
*/
/**
* @package HTML2PS
* @subpackage Document
*
* The ButtonBox class desribes the HTML buttons layout. (Note that
* button elements have 'display' CSS property set to HTML2PS-specific
* '-button' value )
*
* @link http://www.w3.org/TR/html4/interact/forms.html#h-17.4 HTML 4.01 The INPUT element
*/
class ButtonBox extends InlineControlBox {
function get_max_width(&$context, $limit = 10E6) {
return
GenericContainerBox::get_max_width($context, $limit);
}
/**
* Create a new button element
*
* @param string $text text to be rendered on the button
*/
function ButtonBox() {
$this->InlineControlBox();
}
/**
* Create a new button element from the DOM tree element
*
* @param DOMElement $root pointer to the DOM tree element corresponding to the button.
*
* @return ButtonBox new button element
*/
function &create(&$root, &$pipeline) {
/**
* Button text is defined by its 'value' attrubute;
* if this attribute is not specified, we should provide some
* appropriate defaults depending on the exact button type:
* reset, submit or generic button.
*
* Default button text values are specified in config file config.inc.php.
*
* @see config.inc.php
* @see DEFAULT_SUBMIT_TEXT
* @see DEFAULT_RESET_TEXT
* @see DEFAULT_BUTTON_TEXT
*/
if ($root->has_attribute("value")) {
$text = $root->get_attribute("value");
} else {
$text = DEFAULT_BUTTON_TEXT;
};
$box =& new ButtonBox();
$box->readCSS($pipeline->getCurrentCSSState());
/**
* If button width is not constrained, then we'll add some space around the button text
*/
$text = " ".$text." ";
$box->_setup($text, $pipeline);
return $box;
}
function _setup($text, &$pipeline) {
/**
* Contents of the text box are somewhat similar to the inline box:
* a sequence of the text and whitespace boxes; we generate this sequence using
* the InlineBox, then copy contents of the created inline box to our button.
*
* @todo probably, create_from_text() function should be extracted to the common parent
* of inline boxes.
*/
$ibox = InlineBox::create_from_text($text, WHITESPACE_PRE, $pipeline);
$size = count($ibox->content);
for ($i=0; $i<$size; $i++) {
$this->add_child($ibox->content[$i]);
};
/**
* Button height includes vertical padding (e.g. the following two buttons
* <input type="button" value="test" style="padding: 10px; height: 50px;"/>
* <input type="button" value="test" style="padding: 0px; height: 30px;"/>
* are render by browsers with the same height!), so we'll need to adjust the
* height constraint, subtracting the vertical padding value from the constraint
* height value.
*/
$hc = $this->get_height_constraint();
if (!is_null($hc->constant)) {
$hc->constant[0] -= $this->get_padding_top() + $this->get_padding_bottom();
};
$this->put_height_constraint($hc);
}
/**
* Render the form field corresponding to this button
* (Will be overridden by subclasses; they may render more specific button types)
*
* @param OutputDriver $driver The output driver object
*/
function _render_field(&$driver) {
$driver->field_pushbutton($this->get_left_padding(),
$this->get_top_padding(),
$this->get_width() + $this->get_padding_left() + $this->get_padding_right(),
$this->get_height() + $this->get_padding_top() + $this->get_padding_bottom());
}
/**
* Render the button using the specified output driver
*
* @param OutputDriver $driver The output driver object
*
* @return boolean flag indicating an error (null value) or success (true)
*/
function show(&$driver) {
/**
* Set the baseline of a button box so that the button text will be aligned with
* the line box baseline
*/
$this->default_baseline = $this->content[0]->baseline + $this->get_extra_top();
$this->baseline = $this->content[0]->baseline + $this->get_extra_top();
/**
* Render the interactive button (if requested and possible)
*/
if ($GLOBALS['g_config']['renderforms']) {
$status = GenericContainerBox::show($driver);
$this->_render_field($driver);
} else {
$status = GenericContainerBox::show($driver);
};
return $status;
}
}
?> |