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