1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef CHART2_OBJECTHIERARCHY_HXX
24 #define CHART2_OBJECTHIERARCHY_HXX
25 
26 #include "ObjectIdentifier.hxx"
27 
28 #include <rtl/ustring.hxx>
29 #include <com/sun/star/chart2/XChartDocument.hpp>
30 #include <com/sun/star/awt/KeyEvent.hpp>
31 
32 #include <memory>
33 #include <vector>
34 
35 namespace chart
36 {
37 
38 class ExplicitValueProvider;
39 
40 namespace impl
41 {
42 class ImplObjectHierarchy;
43 }
44 
45 class ObjectHierarchy
46 {
47 public:
48     typedef ObjectIdentifier tOID;
49     typedef ::std::vector< tOID > tChildContainer;
50 
51     /** @param bFlattenDiagram
52             If <TRUE/>, the content of the diaram (data series, wall, floor,
53             etc.) is treated as being at the same level as the diagram. (This is
54             used for keyboard navigation).
55      */
56     explicit ObjectHierarchy(
57         const ::com::sun::star::uno::Reference<
58             ::com::sun::star::chart2::XChartDocument > & xChartDocument,
59         ExplicitValueProvider * pExplicitValueProvider = 0,
60         bool bFlattenDiagram = false,
61         bool bOrderingForElementSelector = false );
62     ~ObjectHierarchy();
63 
64     static tOID      getRootNodeOID();
65     static bool      isRootNode( const tOID& rOID );
66 
67     /// equal to getChildren( getRootNodeOID())
68     tChildContainer  getTopLevelChildren() const;
69     bool             hasChildren( const tOID& rParent ) const;
70     tChildContainer  getChildren( const tOID& rParent ) const;
71 
72     tChildContainer  getSiblings( const tOID& rNode ) const;
73 
74     /// The result is empty, if the node cannot be found in the tree
75     tOID             getParent( const tOID& rNode ) const;
76     /// @returns -1, if no parent can be determined
77     sal_Int32        getIndexInParent( const tOID& rNode ) const;
78 
79 private:
80 
81     ::std::auto_ptr< impl::ImplObjectHierarchy > m_apImpl;
82 };
83 
84 class ObjectKeyNavigation
85 {
86 public:
87     explicit ObjectKeyNavigation( const ObjectHierarchy::tOID & rCurrentOID,
88                                   const ::com::sun::star::uno::Reference<
89                                       ::com::sun::star::chart2::XChartDocument > & xChartDocument,
90                                   ExplicitValueProvider * pExplicitValueProvider = 0 );
91 
92     bool handleKeyEvent( const ::com::sun::star::awt::KeyEvent & rEvent );
93     ObjectHierarchy::tOID getCurrentSelection() const;
94 
95 private:
96     void setCurrentSelection( const ObjectHierarchy::tOID& rOID );
97     bool first();
98     bool last();
99     bool next();
100     bool previous();
101     bool up();
102     bool down();
103     bool veryFirst();
104     bool veryLast();
105 
106     ObjectHierarchy::tOID m_aCurrentOID;
107     ::com::sun::star::uno::Reference<
108             ::com::sun::star::chart2::XChartDocument > m_xChartDocument;
109     ExplicitValueProvider * m_pExplicitValueProvider;
110     bool m_bStepDownInDiagram;
111 };
112 
113 } //  namespace chart
114 
115 // CHART2_OBJECTHIERARCHY_HXX
116 #endif
117