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 #ifndef SD_TASKPANE_TREE_NODE_HXX
29 #define SD_TASKPANE_TREE_NODE_HXX
30 
31 #include "ILayoutableWindow.hxx"
32 #include <memory>
33 #include <vector>
34 #include <com/sun/star/accessibility/XAccessible.hpp>
35 #include <tools/link.hxx>
36 
37 namespace sd {
38 class ObjectBarManager;
39 }
40 
41 namespace sd { namespace toolpanel {
42 
43 class ControlContainer;
44 class TaskPaneShellManager;
45 
46 enum TreeNodeStateChangeEventId {
47     EID_CHILD_ADDED,
48     EID_ALL_CHILDREN_REMOVED,
49     EID_EXPANSION_STATE_CHANGED,
50     EID_FOCUSED_STATE_CHANGED,
51     EID_SHOWING_STATE_CHANGED
52 };
53 
54 
55 /** Base class for all members of the object hierarchy that makes up the
56     tool panel. In the task pane, there are multiple hierarchies of such nodes,
57     with every panel having an own tree. The pane node is the root of the tree, below
58     that there are SubToolPanels and Window/Control objects. At the
59     lowest level there are only Window or Control objects.
60 
61     This class provides the means of communication between objects on
62     different levels.
63 */
64 class TreeNode
65     : public ILayoutableWindow,
66       public ILayouter
67 {
68 public:
69     TreeNode (TreeNode* pParent);
70     virtual ~TreeNode (void);
71 
72     void SetParentNode (TreeNode* pNewParent);
73     TreeNode* GetParentNode (void);
74 
75     /** Return the Window pointer of a tree node.
76     */
77     virtual ::Window* GetWindow (void);
78 
79     /** Return a const pointer to the window of a tree node.
80     */
81     virtual const ::Window* GetConstWindow (void) const;
82 
83     /** Return the joined minimum width of all children, i.e. the largest of
84         the minimum widths.
85     */
86     virtual sal_Int32 GetMinimumWidth (void);
87 
88     /** The default implementaion always returns <FALSE/>
89     */
90     virtual bool IsResizable (void);
91 
92     /** Call this method whenever the size of one of the children of the
93         called node has to be changed, e.g. when the layout menu shows more
94         or less items than before.  As a typical result the node will layout
95         and resize its children according to their size requirements.
96 
97         Please remember that the size of the children can be changed in the
98         first place because scroll bars can give a node the space it needs.
99 
100         The default implementation passes this call to its parent.
101     */
102     virtual void RequestResize (void);
103 
104     /** The default implementation shows the window (when it exists) when
105         bExpansionState is <TRUE/>.  It hides the window otherwise.
106         @return
107             Returns <TRUE/> when the expansion state changes.  When an
108             expansion state is requested that is already in place then
109             <FALSE/> is returned.
110     */
111     virtual bool Expand (bool bExpansionState);
112 
113     /** The default implementation returns whether the window is showing.
114         When there is no window then it returns <FALSE/>.
115     */
116     virtual bool IsExpanded (void) const;
117 
118     /** Return whether the node can be expanded or collapsed.  The default
119         implementation always returns <TRUE/> when there is window and
120         <FALSE/> otherwise.  If <FALSE/> is returned
121         then Expand() may be called but it will not change the expansion
122         state.
123     */
124     virtual bool IsExpandable (void) const;
125 
126     /** The default implementation calls GetWindow()->Show().
127     */
128     virtual void Show (bool bVisibilityState);
129 
130     /** The default implementation returns GetWindow()->IsVisible().
131     */
132     virtual bool IsShowing (void) const;
133 
134     ControlContainer& GetControlContainer (void);
135 
136     /** Give each node access to a shell manage.  This usually is the shell
137         manager of the ToolPanelViewShell.
138 
139         At least the root node has to overwrite this method since the
140         default implementation simply returns the shell manager of its
141         parent.
142     */
143     virtual TaskPaneShellManager* GetShellManager (void);
144 
145     /** You will rarely need to overload this method.  To supply your own
146         accessible object you should overload CreateAccessible() instead.
147     */
148     virtual ::com::sun::star::uno::Reference<
149         ::com::sun::star::accessibility::XAccessible> GetAccessibleObject (void);
150 
151     /** Overload this method in order to supply a class specific accessible
152         object.
153         The default implementation will return a new instance of
154         AccessibleTreeNode.
155         @param rxParent
156             The accessible parent of the accessible object to create.  It is
157             not necessaryly the accessible object of the parent window of
158             GetWindow().
159 
160     */
161     virtual ::com::sun::star::uno::Reference<
162         ::com::sun::star::accessibility::XAccessible> CreateAccessibleObject (
163             const ::com::sun::star::uno::Reference<
164             ::com::sun::star::accessibility::XAccessible>&rxParent);
165 
166     /** Add a listener that will be informated in the future about state
167         changes of the tree node.  This includes adding and removing
168         children as well as focus, visibility, and expansion state.
169         Multiple calls are ignored.  Each listener is added only once.
170     */
171     void AddStateChangeListener (const Link& rListener);
172 
173     /** Call the state change listeners and pass a state change event with
174         the specified event id.  The source field is set to this.
175         @param pChild
176             This optional parameter makes sense only with the
177             EID_CHILD_ADDED event.
178     */
179     void FireStateChangeEvent (
180         TreeNodeStateChangeEventId eEventId,
181         TreeNode* pChild = NULL) const;
182 
183 protected:
184     ::std::auto_ptr<ControlContainer> mpControlContainer;
185 
186 private:
187     TreeNode* mpParent;
188     typedef ::std::vector<Link> StateChangeListenerContainer;
189     StateChangeListenerContainer maStateChangeListeners;
190 };
191 
192 
193 
194 
195 /** Objects of this class are sent to listeners to notify them about state
196     changes of a tree node.
197 */
198 class TreeNodeStateChangeEvent
199 {
200 public:
201 
202     TreeNodeStateChangeEvent (
203         const TreeNode& rNode,
204         TreeNodeStateChangeEventId eEventId,
205         TreeNode* pChild = NULL);
206 
207     const TreeNode& mrSource;
208     TreeNodeStateChangeEventId meEventId;
209     TreeNode* mpChild;
210 };
211 
212 } } // end of namespace ::sd::toolpanel
213 
214 #endif
215