1<?php
2
3require_once DOKU_PLUGIN.'odt/ODT/elements/ODTStateElement.php';
4
5/**
6 * Interface iContainerAccess
7 *
8 * To prevent clashes with other interfaces function names all functions
9 * are prefixed with iCA_.
10 *
11 * @package ODT\iContainerAccess
12 */
13interface iContainerAccess
14{
15    public function isNested ();
16    public function addNestedContainer (iContainerAccess $nested);
17    public function getNestedContainers ();
18    public function determinePositionInContainer (array &$data, ODTStateElement $current);
19    public function getMaxWidthOfNestedContainer (ODTInternalParams $params, array $data);
20}
21
22/**
23 * ODTContainerElement:
24 * Class for extra code to support container elements (frame and table).
25 *
26 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
27 * @author  LarsDW223
28 */
29class ODTContainerElement
30{
31    // Container specific state data
32    protected $owner = NULL;
33    protected $is_nested = false;
34    protected $nestedContainers = array();
35
36    /**
37     * Constructor.
38     */
39    public function __construct(ODTStateElement $owner) {
40        $this->owner = $owner;
41    }
42
43    /**
44     * Determine and set the parent for this element.
45     * The parent is the previous element.
46     *
47     * If the container is nested in another table or frame,
48     * then the surrounding table or frame is the parent!
49     *
50     * @param ODTStateElement $previous
51     */
52    public function determineParent(ODTStateElement $previous) {
53        $container = $previous;
54        while (isset($container)) {
55            if ($container->getClass() == 'table-cell') {
56                $cell = $container;
57            }
58            if ($container->getClass() == 'table') {
59                break;
60            }
61            if ($container->getClass() == 'frame') {
62                break;
63            }
64            $container = $container->getParent();
65        }
66        if (!isset($container)) {
67            $this->owner->setParent($previous);
68        } else {
69            $this->owner->setParent($container);
70            $container->addNestedContainer ($this->owner);
71            $this->is_nested = true;
72        }
73    }
74
75    /**
76     * Is this container nested in another container
77     * (inserted into another table or frame)?
78     *
79     * @return boolean
80     */
81    public function isNested () {
82        return $this->is_nested;
83    }
84
85    public function addNestedContainer (iContainerAccess $nested) {
86        $this->nestedContainers [] = $nested;
87    }
88
89    public function getNestedContainers () {
90        return $this->nestedContainers;
91    }
92}
93