xref: /trunk/main/oox/source/drawingml/diagram/diagramlayoutatoms.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/drawingml/diagram/diagramlayoutatoms.hxx"
29 
30 #include <functional>
31 #include <boost/bind.hpp>
32 
33 #include "oox/helper/attributelist.hxx"
34 #include "layoutnodecontext.hxx"
35 
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::xml::sax;
38 using namespace ::oox::core;
39 
40 namespace oox { namespace drawingml {
41 
42 
43 IteratorAttr::IteratorAttr( )
44     : mnAxis( 0 )
45     , mnCnt( 0 )
46     , mbHideLastTrans( false )
47     , mnPtType( 0 )
48     , mnSt( 0 )
49     , mnStep( 1 )
50 {
51 }
52 
53 void IteratorAttr::loadFromXAttr( const Reference< XFastAttributeList >& xAttr )
54 {
55     AttributeList attr( xAttr );
56     mnAxis = xAttr->getOptionalValueToken( XML_axis, 0 );
57     mnCnt = attr.getInteger( XML_cnt, 0 );
58     mbHideLastTrans = attr.getBool( XML_hideLastTrans, false );
59     mnPtType = xAttr->getOptionalValueToken( XML_ptType, 0 );
60     mnSt = attr.getInteger( XML_st, 0 );
61     mnStep = attr.getInteger( XML_step, 1 );
62 }
63 
64 
65 
66 ConditionAttr::ConditionAttr()
67     : mnFunc( 0 )
68     , mnArg( 0 )
69     , mnOp( 0 )
70 {
71 
72 }
73 
74 
75 void ConditionAttr::loadFromXAttr( const Reference< XFastAttributeList >& xAttr )
76 {
77     mnFunc = xAttr->getOptionalValueToken( XML_func, 0 );
78     // mnArg will be -1 for "none" or any other unknown value
79     mnArg = LayoutNodeContext::tagToVarIdx( xAttr->getOptionalValueToken( XML_arg, XML_none ) );
80     mnOp = xAttr->getOptionalValueToken( XML_op, 0 );
81     msVal = xAttr->getOptionalValue( XML_val );
82 }
83 
84 
85 void LayoutAtom::dump(int level)
86 {
87     OSL_TRACE( "level = %d - %s of type %s", level,
88                OUSTRING_TO_CSTR( msName ),
89                typeid(*this).name() );
90     std::for_each( mpChildNodes.begin(), mpChildNodes.end(),
91                   boost::bind( &LayoutAtom::dump, _1, level + 1 ) );
92 }
93 
94 
95 void ForEachAtom::processAtom()
96 {
97     // TODO there is likely some conditions
98     std::for_each( mpChildNodes.begin(), mpChildNodes.end(),
99                    boost::bind( &LayoutAtom::processAtom, _1 ) );
100 }
101 
102 /** call ConditionAtom::test() if pAtom is one
103  * if it is not a ConditionAtom, then return false.
104  */
105 static bool _test_atom( const LayoutAtomPtr & pAtom)
106 {
107     try {
108         bool bResult = false;
109         const ConditionAtomPtr pCond = boost::dynamic_pointer_cast< ConditionAtom >(pAtom);
110         if( pCond )
111         {
112             bResult = pCond->test();
113         }
114         return bResult;
115     }
116     catch(...)
117     {
118     }
119     return false;
120 }
121 
122 void ChooseAtom::processAtom()
123 {
124     std::vector< LayoutAtomPtr >::iterator
125         iter = std::find_if( mpChildNodes.begin(), mpChildNodes.end(),
126                              boost::bind( &_test_atom, _1 ) );
127     if( iter != mpChildNodes.end() )
128     {
129         // TODO do something
130         (*iter)->processAtom();
131     }
132 }
133 
134 bool ConditionAtom::test()
135 {
136     // TODO
137     return false;
138 }
139 
140 
141 } }
142