File size: 4,513 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
<?php
// $Header: /cvsroot/html2ps/box.select.php,v 1.24 2007/01/03 19:39:29 Konstantin Exp $

class SelectBox extends InlineControlBox {
  var $_name;
  var $_value;
  var $_options;

  function SelectBox($name, $value, $options) {
    // Call parent constructor
    $this->InlineBox();

    $this->_name    = $name;
    $this->_value   = $value;
    $this->_options = $options;
  }

  function &create(&$root, &$pipeline) {
    $name = $root->get_attribute('name');

    $value = "";
    $options = array();

    // Get option list
    $child = $root->first_child();
    $content = "";
    $size = 0;
    while ($child) {
      if ($child->node_type() == XML_ELEMENT_NODE) {
        $size = max($size, strlen($child->get_content()));
        if (empty($content) || $child->has_attribute("selected")) { 
          $content = preg_replace("/\s/"," ",$child->get_content());
          $value   = trim($child->get_content());
        };

        if ($child->has_attribute('value')) {
          $options[] = array($child->get_attribute('value'),
                             $child->get_content());
        } else {
          $options[] = array($child->get_content(),
                             $child->get_content());
        };
      };
      $child = $child->next_sibling();
    };
    $content = str_pad($content, $size*SIZE_SPACE_KOEFF + SELECT_SPACE_PADDING, " ");

    $box =& new SelectBox($name, $value, $options);
    $box->readCSS($pipeline->getCurrentCSSState());

    // Add text to be rendered in non-interactive mode
    $ibox = InlineBox::create_from_text($content, WHITESPACE_PRE, $pipeline);
    for ($i=0, $size = count($ibox->content); $i<$size; $i++) {
      $box->add_child($ibox->content[$i]);
    };

    return $box;
  }

  function show(&$driver) {   
    global $g_config;
    if ($g_config['renderforms']) {
      return $this->show_field($driver);
    } else {
      return $this->show_rendered($driver);
    };
  }

  function show_field(&$driver) {
    if (is_null(GenericFormattedBox::show($driver))) {
      return null;
    };

    $driver->field_select($this->get_left_padding(), 
                          $this->get_top_padding(),
                          $this->get_width()  + $this->get_padding_left() + $this->get_padding_right(),
                          $this->get_height(),
                          $this->_name,
                          $this->_value,
                          $this->_options);
    return true;
  }

  function show_rendered(&$driver) {
    // Now set the baseline of a button box to align it vertically when flowing isude the 
    // text line
    $this->default_baseline = $this->content[0]->baseline + $this->get_extra_top();
    $this->baseline         = $this->content[0]->baseline + $this->get_extra_top();

    if (is_null(GenericContainerBox::show($driver))) {
      return null;
    };

    $padding = $this->getCSSProperty(CSS_PADDING);
    $button_height = $this->get_height() + $padding->top->value + $padding->bottom->value;

    // Show arrow button box
    $driver->setrgbcolor(0.93, 0.93, 0.93);
    $driver->moveto($this->get_right_padding(), $this->get_top_padding());
    $driver->lineto($this->get_right_padding() - $button_height, $this->get_top_padding());
    $driver->lineto($this->get_right_padding() - $button_height, $this->get_bottom_padding());
    $driver->lineto($this->get_right_padding(), $this->get_bottom_padding());
    $driver->closepath();
    $driver->fill();

    // Show box boundary
    $driver->setrgbcolor(0,0,0);
    $driver->moveto($this->get_right_padding(), $this->get_top_padding());
    $driver->lineto($this->get_right_padding() - $button_height, $this->get_top_padding());
    $driver->lineto($this->get_right_padding() - $button_height, $this->get_bottom_padding());
    $driver->lineto($this->get_right_padding(), $this->get_bottom_padding());
    $driver->closepath();
    $driver->stroke();
  
    // Show arrow
    $driver->setrgbcolor(0,0,0);
    $driver->moveto($this->get_right_padding() - SELECT_BUTTON_TRIANGLE_PADDING,
                      $this->get_top_padding() - SELECT_BUTTON_TRIANGLE_PADDING);
    $driver->lineto($this->get_right_padding() - $button_height + SELECT_BUTTON_TRIANGLE_PADDING, 
                      $this->get_top_padding() - SELECT_BUTTON_TRIANGLE_PADDING);
    $driver->lineto($this->get_right_padding() - $button_height/2, $this->get_bottom_padding() + SELECT_BUTTON_TRIANGLE_PADDING);
    $driver->closepath();
    $driver->fill();

    return true;
  }
}
?>