/src/libetonyek/src/lib/contexts/IWORKGroupElement.cpp
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* |
3 | | * This file is part of the libetonyek project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #include "IWORKGroupElement.h" |
11 | | |
12 | | #include "IWORKCollector.h" |
13 | | #include "IWORKGeometryElement.h" |
14 | | #include "IWORKImageElement.h" |
15 | | #include "IWORKLineElement.h" |
16 | | #include "IWORKMediaElement.h" |
17 | | #include "IWORKShapeContext.h" |
18 | | #include "IWORKTableInfoElement.h" |
19 | | #include "IWORKTabularInfoElement.h" |
20 | | #include "IWORKToken.h" |
21 | | #include "IWORKXMLParserState.h" |
22 | | |
23 | | namespace libetonyek |
24 | | { |
25 | | |
26 | | IWORKGroupElement::IWORKGroupElement(IWORKXMLParserState &state) |
27 | 0 | : IWORKXMLElementContextBase(state) |
28 | 0 | , m_groupIsOpened(false) |
29 | 0 | { |
30 | 0 | } |
31 | | |
32 | | void IWORKGroupElement::startOfElement() |
33 | 0 | { |
34 | 0 | if (isCollector()) |
35 | 0 | { |
36 | 0 | getCollector().startLevel(); |
37 | 0 | getCollector().startGroup(); |
38 | 0 | } |
39 | 0 | } |
40 | | |
41 | | IWORKXMLContextPtr_t IWORKGroupElement::element(const int name) |
42 | 0 | { |
43 | 0 | switch (name) |
44 | 0 | { |
45 | 0 | case +IWORKToken::NS_URI_SF | IWORKToken::geometry : |
46 | 0 | return std::make_shared<IWORKGeometryElement>(getState()); |
47 | 0 | case +IWORKToken::NS_URI_SF | IWORKToken::group : |
48 | 0 | ensureClosed(); // checkme: creating a group in a group must be often possible |
49 | 0 | return std::make_shared<IWORKGroupElement>(getState()); |
50 | 0 | case +IWORKToken::NS_URI_SF | IWORKToken::image : |
51 | 0 | ensureOpened(); |
52 | 0 | return std::make_shared<IWORKImageElement>(getState()); |
53 | 0 | case +IWORKToken::NS_URI_SF | IWORKToken::line : |
54 | 0 | ensureOpened(); |
55 | 0 | return std::make_shared<IWORKLineElement>(getState()); |
56 | 0 | case +IWORKToken::NS_URI_SF | IWORKToken::media : |
57 | 0 | ensureOpened(); |
58 | 0 | return std::make_shared<IWORKMediaElement>(getState()); |
59 | 0 | case +IWORKToken::NS_URI_SF | IWORKToken::drawable_shape : |
60 | 0 | case +IWORKToken::NS_URI_SF | IWORKToken::shape : |
61 | 0 | ensureOpened(); |
62 | 0 | return std::make_shared<IWORKShapeContext>(getState()); |
63 | 0 | case +IWORKToken::NS_URI_SF | IWORKToken::table_info : |
64 | 0 | ensureClosed(); |
65 | 0 | return std::make_shared<IWORKTableInfoElement>(getState()); |
66 | 0 | case +IWORKToken::NS_URI_SF | IWORKToken::tabular_info : |
67 | 0 | ensureClosed(); |
68 | 0 | return std::make_shared<IWORKTabularInfoElement>(getState()); |
69 | 0 | default: |
70 | 0 | break; |
71 | 0 | } |
72 | | |
73 | 0 | return IWORKXMLContextPtr_t(); |
74 | 0 | } |
75 | | |
76 | | void IWORKGroupElement::endOfElement() |
77 | 0 | { |
78 | 0 | ensureClosed(); |
79 | 0 | if (isCollector()) |
80 | 0 | { |
81 | 0 | getCollector().endGroup(); |
82 | 0 | getCollector().endLevel(); |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | | void IWORKGroupElement::ensureOpened() |
87 | 0 | { |
88 | 0 | if (m_groupIsOpened || !isCollector()) |
89 | 0 | return; |
90 | 0 | getCollector().openGroup(); |
91 | 0 | m_groupIsOpened=true; |
92 | 0 | } |
93 | | |
94 | | void IWORKGroupElement::ensureClosed() |
95 | 0 | { |
96 | 0 | if (!m_groupIsOpened || !isCollector()) |
97 | 0 | return; |
98 | 0 | getCollector().closeGroup(); |
99 | 0 | m_groupIsOpened=false; |
100 | 0 | } |
101 | | |
102 | | } |
103 | | |
104 | | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |