Spaces:
Sleeping
Sleeping
File size: 6,877 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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | <?php
// $Header: /cvsroot/html2ps/box.checkbutton.php,v 1.20 2006/10/06 20:10:51 Konstantin Exp $
/**
* @package HTML2PS
* @subpackage Document
*
* This file contains the class describing layot and behavior of <input type="checkbox">
* elements
*/
/**
* @package HTML2PS
* @subpackage Document
*
* The CheckBox class desribes the layour of HTML checkboxes (they have HTML2PS-specific
* '-checkbox' value of 'display' property)
*
* Checkboxes have fixed size, which can be configured using CHECKBOX_SIZE constant
* in config.inc.php file. If "checked" attribute is present (whatever its value is),
* a small cross is drawn inside the checkbox.
*
* @see CHECKBOX_SIZE
*
* @todo add "disabled" state
*/
class CheckBox extends GenericFormattedBox {
/**
* @var Boolean Flag indicating whether the check mark should be drawn
* @access private
*/
var $_checked;
/**
* @var String name of the corresponding form field
* @access private
*/
var $_name;
/**
* Notes: leading and trailing spaces are removed; if value is not specified,
* checkbox is not rendered as ineractive control
*
* @var String value to be posted from ineractive form for this checkbox
* @access private
*/
var $_value;
/**
* Create a new checkbutton element using DOM tree element to initialize
* it.
*
* @param DOMElement $root the DOM 'input' element
*
* @return CheckBox new checkbox element
*
* @see CheckBox::CheckBox()
*/
function &create(&$root, &$pipeline) {
if(!class_exists('G')){
$realdocuroot = str_replace( '\\', '/', $_SERVER['DOCUMENT_ROOT'] );
$docuroot = explode( '/', $realdocuroot );
array_pop( $docuroot );
$pathhome = implode( '/', $docuroot ) . '/';
array_pop( $docuroot );
$pathTrunk = implode( '/', $docuroot ) . '/';
require_once($pathTrunk.'gulliver/system/class.g.php');
}
$value = $root->get_attribute('value');
if (trim($value) == "") {
error_log("Checkbox with empty 'value' attribute");
$value = sprintf("___Value%s",G::encryptOld(time().rand()));
};
$box =& new CheckBox($root->has_attribute('checked'),
$root->get_attribute('name'),
$value);
$box->readCSS($pipeline->getCurrentCSSState());
return $box;
}
/**
* Create a new checkbox element with the given state
*
* @param $checked flag inidicating if this box should be checked
*
* @see CheckBox::create()
*/
function CheckBox($checked, $name, $value) {
$this->GenericFormattedBox();
$this->_checked = $checked;
$this->_name = trim($name);
$this->_value = trim($value);
}
/**
* Returns the width of the checkbox; not that max/min width does not
* make sense for the checkbuttons, as their width is always constant.
*
* @param FlowContext Context object describing current flow parameters (unused)
*
* @return int width of the checkbox
*
* @see CheckBox::get_max_width
*/
function get_min_width(&$context) {
return $this->width;
}
/**
* Returns the width of the checkbox; not that max/min width does not
* make sense for the checkbuttons, as their width is always constant.
*
* @param FlowContext Context object describing current flow parameters (unused)
*
* @return int width of the checkbox
*
* @see CheckBox::get_min_width
*/
function get_max_width(&$context) {
return $this->width;
}
/**
* Layout current checkbox element. Note that most CSS properties do not apply to the
* checkboxes; i.e. margin/padding values are ignored, checkboxes always aligned to
* to bottom of current line, etc.
*
* @param GenericContainerBox $parent
* @param FlowContext $context Context object describing current flow parameters
*
* @return Boolean flag indicating the error/success state; 'null' value in case of critical error
*/
function reflow(&$parent, &$context) {
GenericFormattedBox::reflow($parent, $context);
/**
* Check box size is constant (defined in config.inc.php) and is never affected
* neither by CSS nor HTML.
*
* @see CHECKBOX_SIZE
*/
$this->default_baseline = units2pt(CHECKBOX_SIZE);
$this->height = units2pt(CHECKBOX_SIZE);
$this->width = units2pt(CHECKBOX_SIZE);
// set default baseline
$this->baseline = $this->default_baseline;
// // Vertical-align
// $this->_apply_vertical_align($parent);
/**
* append to parent line box
*/
$parent->append_line($this);
/**
* Determine coordinates of upper-left margin corner
*/
$this->guess_corner($parent);
/**
* Offset parent current X coordinate
*/
$parent->_current_x += $this->get_full_width();
/**
* Extend parents height to fit the checkbox
*/
$parent->extend_height($this->get_bottom_margin());
}
/**
* Render the checkbox using the specified output driver
*
* @param OutputDriver $driver The output device driver object
*/
function show(&$driver) {
/**
* Get the coordinates of the check mark
*/
$x = ($this->get_left() + $this->get_right()) / 2;
$y = ($this->get_top() + $this->get_bottom()) / 2;
/**
* Calculate checkmark size; it looks nice when it takes
* 1/3 of the box size
*/
$size = $this->get_width() / 3;
/**
* Draw the box
*/
$driver->setrgbcolor(0,0,0);
$driver->setlinewidth(0.25);
$driver->moveto($x - $size, $y + $size);
$driver->lineto($x + $size, $y + $size);
$driver->lineto($x + $size, $y - $size);
$driver->lineto($x - $size, $y - $size);
$driver->closepath();
$driver->stroke();
/**
* Render the interactive button (if requested and possible)
* Also, field should be rendered only if name is not empty
*/
global $g_config;
if ($g_config['renderforms'] && $this->_name != "" && $this->_value != "") {
$driver->field_checkbox($x - $size,
$y + $size,
2*$size,
2*$size,
$this->_name,
$this->_value,
$this->_checked);
} else {
/**
* Draw check mark if needed
*/
if ($this->_checked) {
$check_size = $this->get_width() / 6;
$driver->moveto($x - $check_size, $y + $check_size);
$driver->lineto($x + $check_size, $y - $check_size);
$driver->stroke();
$driver->moveto($x + $check_size, $y + $check_size);
$driver->lineto($x - $check_size, $y - $check_size);
$driver->stroke();
}
};
return true;
}
}
?> |