1*c45d927aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c45d927aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c45d927aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c45d927aSAndrew Rist  * distributed with this work for additional information
6*c45d927aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c45d927aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c45d927aSAndrew Rist  * "License"); you may not use this file except in compliance
9*c45d927aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c45d927aSAndrew Rist  *
11*c45d927aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c45d927aSAndrew Rist  *
13*c45d927aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c45d927aSAndrew Rist  * software distributed under the License is distributed on an
15*c45d927aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c45d927aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c45d927aSAndrew Rist  * specific language governing permissions and limitations
18*c45d927aSAndrew Rist  * under the License.
19*c45d927aSAndrew Rist  *
20*c45d927aSAndrew Rist  *************************************************************/
21*c45d927aSAndrew Rist 
22*c45d927aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SD_TOOLPANEL_CONTROL_CONTAINER_HXX
25cdf0e10cSrcweir #define SD_TOOLPANEL_CONTROL_CONTAINER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <osl/mutex.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <vector>
30cdf0e10cSrcweir #include <memory>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir class Window;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace sd { namespace toolpanel {
35cdf0e10cSrcweir 
36cdf0e10cSrcweir class TreeNode;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /** This container manages the children of a TreeNode.  It handles the
39cdf0e10cSrcweir     expansion and visibility state of its child controls.  The container
40cdf0e10cSrcweir     does not do the layouting or painting of the controls.  Instead it asks
41cdf0e10cSrcweir     its owner to do that.
42cdf0e10cSrcweir 
43cdf0e10cSrcweir     The difference between expansion state and visibility is that when a
44cdf0e10cSrcweir     control is collapsed at least a title bar is shown for it.  When it is
45cdf0e10cSrcweir     not visible then even this title bar is not shown.  In that case the
46cdf0e10cSrcweir     user can not expand the control.  A control has to be visible in order
47cdf0e10cSrcweir     to be expanded or collapsed.
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     Whenever you expand or collapse, show or hide a child control then use
50cdf0e10cSrcweir     this container class.  Do not call the respective methods of the child
51cdf0e10cSrcweir     directly.
52cdf0e10cSrcweir */
53cdf0e10cSrcweir class ControlContainer
54cdf0e10cSrcweir {
55cdf0e10cSrcweir public:
56cdf0e10cSrcweir     enum VisibilityState { VS_SHOW, VS_HIDE, VS_TOGGLE };
57cdf0e10cSrcweir     enum ExpansionState { ES_EXPAND, ES_COLLAPSE, ES_TOGGLE };
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     /** Create a new control container.
60cdf0e10cSrcweir         @param pParent
61cdf0e10cSrcweir             This node is asked to re-calculate the size of its children when
62cdf0e10cSrcweir             a child of this container is expanded or collapsed.
63cdf0e10cSrcweir     */
64cdf0e10cSrcweir     ControlContainer (TreeNode* pNode);
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     virtual ~ControlContainer (void);
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     /** This is function makes sure that all children are deleted.  Call
69cdf0e10cSrcweir         this function from the destructor of a sub class to have all child
70cdf0e10cSrcweir         windows deleted before the destructor of another base class of that
71cdf0e10cSrcweir         sub class is called.  When that other base class is some kind of a
72cdf0e10cSrcweir         window it would otherwise complain that there are living children.
73cdf0e10cSrcweir     */
74cdf0e10cSrcweir     void DeleteChildren (void);
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     /** Add the given control to the set of controls managed by the
77cdf0e10cSrcweir         container.  This control is then expanded.
78cdf0e10cSrcweir         @return
79cdf0e10cSrcweir             Return the index under which the control has been inserted in
80cdf0e10cSrcweir             the container.  It is the same index that is returned by
81cdf0e10cSrcweir             GetControlIndex().
82cdf0e10cSrcweir     */
83cdf0e10cSrcweir     sal_uInt32 AddControl (::std::auto_ptr<TreeNode> pControl);
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     /** Expand (default) or collapse the specified control.  When
86cdf0e10cSrcweir         expanding a control in a single expansion environment then all
87cdf0e10cSrcweir         other controls are collapsed.  The specified control is being
88cdf0e10cSrcweir         made the active control as returned by GetActiveControl().
89cdf0e10cSrcweir     */
90cdf0e10cSrcweir     virtual void SetExpansionState (
91cdf0e10cSrcweir         sal_uInt32 nIndex,
92cdf0e10cSrcweir         ExpansionState aState);
93cdf0e10cSrcweir     virtual void SetExpansionState (
94cdf0e10cSrcweir         TreeNode* pControl,
95cdf0e10cSrcweir         ExpansionState aState);
96cdf0e10cSrcweir     virtual void SetVisibilityState (
97cdf0e10cSrcweir         sal_uInt32 nIndex,
98cdf0e10cSrcweir         VisibilityState aState);
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     /** Return the index of the given control.
101cdf0e10cSrcweir     */
102cdf0e10cSrcweir     sal_uInt32 GetControlIndex (TreeNode* pControl) const;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     /** Return the number of controls in the container.
105cdf0e10cSrcweir     */
106cdf0e10cSrcweir     sal_uInt32 GetControlCount (void) const;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     /** Return the number of visible controls in the container.
109cdf0e10cSrcweir     */
110cdf0e10cSrcweir     sal_uInt32 GetVisibleControlCount (void) const;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     /** Return the control with the specified index regardless of whether
113cdf0e10cSrcweir         that control is hidden or visible.
114cdf0e10cSrcweir     */
115cdf0e10cSrcweir     TreeNode* GetControl (sal_uInt32 nIndex) const;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /** Return the index of the control previous to that that is specified
118cdf0e10cSrcweir         by the given index.
119cdf0e10cSrcweir         @param nIndex
120cdf0e10cSrcweir             Index of the control for which to return the index of the
121cdf0e10cSrcweir             previous control.  This index is guaranteed not to be returned.
122cdf0e10cSrcweir         @param bIncludeHidden
123cdf0e10cSrcweir             This flag tells the method whether to include the controls that
124cdf0e10cSrcweir             are not visible in the search for the previous control.  When it
125cdf0e10cSrcweir             is <FALSE/> the hidden controls are skipped.
126cdf0e10cSrcweir         @param bCycle
127cdf0e10cSrcweir             When this flag is <TRUE/> then the search for the previous
128cdf0e10cSrcweir             control wraps arround when reaching the first control.
129cdf0e10cSrcweir         @return
130cdf0e10cSrcweir             Returns the index to the previous control or (sal_uInt32)-1 when
131cdf0e10cSrcweir             there is no previous control.  This would be the case when there
132cdf0e10cSrcweir             is only one (visible) child.
133cdf0e10cSrcweir     */
134cdf0e10cSrcweir     sal_uInt32 GetPreviousIndex (
135cdf0e10cSrcweir         sal_uInt32 nIndex,
136cdf0e10cSrcweir         bool bIncludeHidden=false,
137cdf0e10cSrcweir         bool bCycle=false) const;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     /** Return the index of the control next to that that is specified by
140cdf0e10cSrcweir         the given index.
141cdf0e10cSrcweir         @param nIndex
142cdf0e10cSrcweir             Index of the control for which to return the index of the next
143cdf0e10cSrcweir             control.  This index is guaranteed not to be returned.
144cdf0e10cSrcweir         @param bIncludeHidden
145cdf0e10cSrcweir             This flag tells the method whether to include the controls that
146cdf0e10cSrcweir             are not visible in the search for the next control.  When it is
147cdf0e10cSrcweir             <FALSE/> the hidden controls are skipped.
148cdf0e10cSrcweir         @param bCycle
149cdf0e10cSrcweir             When this flag is <TRUE/> then the search for the next control
150cdf0e10cSrcweir             wraps arround when reaching the last control.
151cdf0e10cSrcweir         @return
152cdf0e10cSrcweir             Returns the index to the next control or (sal_uInt32)-1 when
153cdf0e10cSrcweir             there is no next control.  This would be the case when there is
154cdf0e10cSrcweir             only one (visible) child.
155cdf0e10cSrcweir     */
156cdf0e10cSrcweir     sal_uInt32 GetNextIndex (
157cdf0e10cSrcweir         sal_uInt32 nIndex,
158cdf0e10cSrcweir         bool bIncludeHidden=false,
159cdf0e10cSrcweir         bool bCycle=false) const;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     void SetMultiSelection (bool bFlag);
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     /** This is method is called when the list of controls has changed,
164cdf0e10cSrcweir         i.e. a new control has been added.  The default implementation is
165cdf0e10cSrcweir         empty.  Overwrite this method in derived classes in order to react to
166cdf0e10cSrcweir         such changes.
167cdf0e10cSrcweir     */
168cdf0e10cSrcweir     virtual void ListHasChanged (void);
169cdf0e10cSrcweir 
170cdf0e10cSrcweir private:
171cdf0e10cSrcweir 	osl::Mutex maMutex;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     /// List of controls managed by a container.
174cdf0e10cSrcweir     typedef ::std::vector<TreeNode*> ControlList;
175cdf0e10cSrcweir     ControlList maControlList;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     /** This parent is used for resize requests when children are expanded
178cdf0e10cSrcweir         or collapsed.
179cdf0e10cSrcweir     */
180cdf0e10cSrcweir     TreeNode* mpNode;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     /** The index of the currently expanded control.  A value of
183cdf0e10cSrcweir         (sal_uInt32)-1 indicates that no control is active.  This may be the
184cdf0e10cSrcweir         case after adding controls to the container.
185cdf0e10cSrcweir     */
186cdf0e10cSrcweir     sal_uInt32 mnActiveControlIndex;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     bool mbMultiSelection;
189cdf0e10cSrcweir };
190cdf0e10cSrcweir 
191cdf0e10cSrcweir } } // end of namespace ::sd::toolpanel
192cdf0e10cSrcweir 
193cdf0e10cSrcweir #endif
194