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