Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// $Header: /cvsroot/html2ps/box.radiobutton.php,v 1.20 2006/11/11 13:43:51 Konstantin Exp $
3
 
4
require_once(HTML2PS_DIR.'box.inline.simple.php');
5
 
6
class RadioBox extends SimpleInlineBox {
7
  var $_checked;
8
 
9
  /**
10
   * @var String name of radio button group
11
   * @access private
12
   */
13
  var $_group_name;
14
 
15
  /**
16
   * @var String value to be posted as this radio button value
17
   * @access private
18
   */
19
  var $_value;
20
 
21
  function &create(&$root, &$pipeline) {
22
    $checked = $root->has_attribute('checked');
23
 
24
    $value   = $root->get_attribute('value');
25
    if (trim($value) == "") {
26
      error_log("Radiobutton with empty 'value' attribute");
27
      $value = sprintf("___Value%s",md5(time().rand()));
28
    };
29
 
30
    $css_state = $pipeline->get_current_css_state();
31
 
32
    $box =& new RadioBox($checked, $value,
33
                         $css_state->get_property(CSS_HTML2PS_FORM_RADIOGROUP));
34
    $box->readCSS($css_state);
35
    return $box;
36
  }
37
 
38
  function RadioBox($checked, $value, $group_name) {
39
    // Call parent constructor
40
    $this->GenericBox();
41
 
42
    // Check the box state
43
    $this->_checked = $checked;
44
 
45
    /**
46
     * Store the form value for this radio button
47
     */
48
    $this->_value = trim($value);
49
 
50
    $this->_group_name = $group_name;
51
 
52
    // Setup box size:
53
    $this->default_baseline = units2pt(RADIOBUTTON_SIZE);
54
    $this->height           = units2pt(RADIOBUTTON_SIZE);
55
    $this->width            = units2pt(RADIOBUTTON_SIZE);
56
 
57
    $this->setCSSProperty(CSS_DISPLAY,'-radio');
58
  }
59
 
60
  // Inherited from GenericFormattedBox
61
  function get_min_width(&$context) {
62
    return $this->get_full_width($context);
63
  }
64
 
65
  function get_max_width(&$context) {
66
    return $this->get_full_width($context);
67
  }
68
 
69
  function get_max_width_natural(&$context) {
70
    return $this->get_full_width($context);
71
  }
72
 
73
  function reflow(&$parent, &$context) {
74
    GenericFormattedBox::reflow($parent, $context);
75
 
76
    // set default baseline
77
    $this->baseline = $this->default_baseline;
78
 
79
    // append to parent line box
80
    $parent->append_line($this);
81
 
82
    // Determine coordinates of upper-left _margin_ corner
83
    $this->guess_corner($parent);
84
 
85
    // Offset parent current X coordinate
86
    $parent->_current_x += $this->get_full_width();
87
 
88
    // Extends parents height
89
    $parent->extend_height($this->get_bottom_margin());
90
  }
91
 
92
  function show(&$driver) {
93
    // Cet check center
94
    $x = ($this->get_left() + $this->get_right()) / 2;
95
    $y = ($this->get_top() + $this->get_bottom()) / 2;
96
 
97
    // Calculate checkbox size
98
    $size = $this->get_width() / 3;
99
 
100
    // Draw checkbox
101
    $driver->setlinewidth(0.25);
102
    $driver->circle($x, $y, $size);
103
    $driver->stroke();
104
 
105
    /**
106
     * Render the interactive button (if requested and possible)
107
     * Also, if no value were specified, then this radio button should not be interactive
108
     */
109
    global $g_config;
110
    if ($g_config['renderforms'] && $this->_value != "") {
111
      $driver->field_radio($x - $size,
112
                           $y + $size,
113
                           2*$size,
114
                           2*$size,
115
                           $this->_group_name,
116
                           $this->_value,
117
                           $this->_checked);
118
    } else {
119
      // Draw checkmark if needed
120
      if ($this->_checked) {
121
        $check_size = $this->get_width() / 6;
122
 
123
        $driver->circle($x, $y, $check_size);
124
        $driver->fill();
125
      }
126
    };
127
 
128
    return true;
129
  }
130
 
131
  function get_ascender() {
132
    return $this->get_height();
133
  }
134
 
135
  function get_descender() {
136
    return 0;
137
  }
138
}
139
?>