1<?php 2// $Header: /cvsroot/html2ps/box.select.php,v 1.24 2007/01/03 19:39:29 Konstantin Exp $ 3 4class SelectBox extends InlineControlBox { 5 var $_name; 6 var $_value; 7 var $_options; 8 9 function SelectBox($name, $value, $options) { 10 // Call parent constructor 11 $this->InlineBox(); 12 13 $this->_name = $name; 14 $this->_value = $value; 15 $this->_options = $options; 16 } 17 18 function &create(&$root, &$pipeline) { 19 $name = $root->get_attribute('name'); 20 21 $value = ''; 22 $options = array(); 23 24 // Get option list 25 $child = $root->first_child(); 26 $content = ''; 27 $size = 0; 28 while ($child) { 29 if ($child->node_type() == XML_ELEMENT_NODE) { 30 $size = max($size, strlen($child->get_content())); 31 if (empty($content) || $child->has_attribute('selected')) { 32 $content = preg_replace('/\s/',' ',$child->get_content()); 33 $value = trim($child->get_content()); 34 }; 35 36 if ($child->has_attribute('value')) { 37 $options[] = array($child->get_attribute('value'), 38 $child->get_content()); 39 } else { 40 $options[] = array($child->get_content(), 41 $child->get_content()); 42 }; 43 }; 44 $child = $child->next_sibling(); 45 }; 46 $content = str_pad($content, $size*SIZE_SPACE_KOEFF + SELECT_SPACE_PADDING, ' '); 47 48 $box =& new SelectBox($name, $value, $options); 49 $box->readCSS($pipeline->get_current_css_state()); 50 $box->setup_content($content, $pipeline); 51 52 return $box; 53 } 54 55 function show(&$driver) { 56 global $g_config; 57 if ($g_config['renderforms']) { 58 return $this->show_field($driver); 59 } else { 60 return $this->show_rendered($driver); 61 }; 62 } 63 64 function show_field(&$driver) { 65 if (is_null(GenericFormattedBox::show($driver))) { 66 return null; 67 }; 68 69 $driver->field_select($this->get_left_padding(), 70 $this->get_top_padding(), 71 $this->get_width() + $this->get_padding_left() + $this->get_padding_right(), 72 $this->get_height(), 73 $this->_name, 74 $this->_value, 75 $this->_options); 76 return true; 77 } 78 79 function show_rendered(&$driver) { 80 // Now set the baseline of a button box to align it vertically when flowing isude the 81 // text line 82 $this->default_baseline = $this->content[0]->baseline + $this->get_extra_top(); 83 $this->baseline = $this->content[0]->baseline + $this->get_extra_top(); 84 85 if (is_null(GenericContainerBox::show($driver))) { 86 return null; 87 }; 88 89 $this->show_button($driver); 90 return true; 91 } 92 93 function show_button(&$driver) { 94 $padding = $this->get_css_property(CSS_PADDING); 95 $button_height = $this->get_height() + $padding->top->value + $padding->bottom->value; 96 97 // Show arrow button box 98 $driver->setrgbcolor(0.93, 0.93, 0.93); 99 $driver->moveto($this->get_right_padding(), $this->get_top_padding()); 100 $driver->lineto($this->get_right_padding() - $button_height, $this->get_top_padding()); 101 $driver->lineto($this->get_right_padding() - $button_height, $this->get_bottom_padding()); 102 $driver->lineto($this->get_right_padding(), $this->get_bottom_padding()); 103 $driver->closepath(); 104 $driver->fill(); 105 106 // Show box boundary 107 $driver->setrgbcolor(0,0,0); 108 $driver->moveto($this->get_right_padding(), $this->get_top_padding()); 109 $driver->lineto($this->get_right_padding() - $button_height, $this->get_top_padding()); 110 $driver->lineto($this->get_right_padding() - $button_height, $this->get_bottom_padding()); 111 $driver->lineto($this->get_right_padding(), $this->get_bottom_padding()); 112 $driver->closepath(); 113 $driver->stroke(); 114 115 // Show arrow 116 $driver->setrgbcolor(0,0,0); 117 $driver->moveto($this->get_right_padding() - SELECT_BUTTON_TRIANGLE_PADDING, 118 $this->get_top_padding() - SELECT_BUTTON_TRIANGLE_PADDING); 119 $driver->lineto($this->get_right_padding() - $button_height + SELECT_BUTTON_TRIANGLE_PADDING, 120 $this->get_top_padding() - SELECT_BUTTON_TRIANGLE_PADDING); 121 $driver->lineto($this->get_right_padding() - $button_height/2, $this->get_bottom_padding() + SELECT_BUTTON_TRIANGLE_PADDING); 122 $driver->closepath(); 123 $driver->fill(); 124 125 return true; 126 } 127} 128?>