1<?php
2// $Header: /cvsroot/html2ps/box.inline.control.php,v 1.7 2006/09/07 18:38:12 Konstantin Exp $
3
4class InlineControlBox extends InlineBox {
5  function InlineControlBox() {
6    $this->InlineBox();
7  }
8
9  function get_min_width(&$context, $limit = 10E6) {
10    return $this->get_max_width($context, $limit);
11  }
12
13  function get_max_width(&$context, $limit = 10E6) {
14    return
15      GenericContainerBox::get_max_width($context, $limit) -
16      $this->_get_hor_extra();
17  }
18
19  function line_break_allowed() {
20    return false;
21  }
22
23  function reflow_static(&$parent, &$context) {
24    GenericFormattedBox::reflow($parent, $context);
25
26    // Determine the box width
27    $this->_calc_percentage_width($parent, $context);
28    $this->put_full_width($this->get_min_width($context, $parent->get_width()));
29    $this->setCSSProperty(CSS_WIDTH, new WCNone());
30
31    // Check if we need a line break here
32    $this->maybe_line_break($parent, $context);
33
34    // append to parent line box
35    $parent->append_line($this);
36
37    // Determine coordinates of upper-left _margin_ corner
38    $this->guess_corner($parent);
39
40    $this->reflow_content($context);
41
42    /**
43     * After text content have been reflown, we may determine the baseline of the control item itself;
44     *
45     * As there will be some extra whitespace on the top of the control box, we must add this whitespace
46     * to the calculated baseline value, so text before and after control item will be aligned
47     * with the text inside the box.
48     */
49    $this->default_baseline = $this->content[0]->baseline + $this->get_extra_top();
50    $this->baseline         = $this->content[0]->baseline + $this->get_extra_top();
51
52    // center the text vertically inside the control
53    $text =& $this->content[0];
54    $delta = ($text->get_top() - $text->get_height()/2) - ($this->get_top() - $this->get_height()/2);
55    $text->offset(0,-$delta);
56
57    // Offset parent current X coordinate
58    $parent->_current_x += $this->get_full_width();
59
60    // Extends parents height
61    $parent->extend_height($this->get_bottom_margin());
62  }
63
64  function setup_content($text, &$pipeline) {
65    /**
66     * Contents of the text box are somewhat similar to the inline box:
67     * a sequence of the text and whitespace boxes; we generate this sequence using
68     * the InlineBox, then copy contents of the created inline box to our button.
69     *
70     * @todo probably, create_from_text() function should be extracted to the common parent
71     * of inline boxes.
72     */
73    $ibox = InlineBox::create_from_text($text, WHITESPACE_PRE, $pipeline);
74
75    if (count($ibox->content) == 0) {
76      $this->append_child(TextBox::create(' ', 'iso-8859-1', $pipeline));
77    } else {
78      for ($i=0, $size = count($ibox->content); $i<$size; $i++) {
79        $this->append_child($ibox->content[$i]);
80      };
81    };
82  }
83
84  function show(&$viewport) {
85    // Now set the baseline of a button box to align it vertically when flowing isude the
86    // text line
87    $this->default_baseline = $this->content[0]->baseline + $this->get_extra_top();
88    $this->baseline         = $this->content[0]->baseline + $this->get_extra_top();
89
90    return GenericContainerBox::show($viewport);
91  }
92}
93?>