update dev300-m58
[ooovba.git] / sd / source / ui / toolpanel / TaskPaneTreeNode.cxx
blobec7fc1a9205257eb2d11031206d002e7a0d1a66e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TaskPaneTreeNode.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "taskpane/TaskPaneTreeNode.hxx"
36 #include "taskpane/ControlContainer.hxx"
37 #include "taskpane/TitledControl.hxx"
39 #include <vector>
40 #include <algorithm>
42 namespace sd { namespace toolpanel {
44 TreeNode::TreeNode( TreeNode* pParent)
45 : mpControlContainer (new ControlContainer(this))
46 , mpParent (pParent)
47 , maStateChangeListeners()
54 TreeNode::~TreeNode (void)
61 bool TreeNode::IsLeaf (void)
63 return (mpControlContainer.get()==NULL);
69 bool TreeNode::IsRoot (void)
71 return (mpParent==NULL);
77 void TreeNode::SetParentNode (TreeNode* pNewParent)
79 mpParent = pNewParent;
80 GetWindow()->SetParent (pNewParent->GetWindow());
86 TreeNode* TreeNode::GetParentNode (void)
88 return mpParent;
94 ::Window* TreeNode::GetWindow (void)
96 return NULL;
102 const ::Window* TreeNode::GetConstWindow (void) const
104 return const_cast<TreeNode*>(this)->GetWindow();
110 sal_Int32 TreeNode::GetMinimumWidth (void)
112 sal_Int32 nTotalMinimumWidth = 0;
113 unsigned int nCount = mpControlContainer->GetControlCount();
114 for (unsigned int nIndex=0; nIndex<nCount; nIndex++)
116 TreeNode* pChild = mpControlContainer->GetControl (nIndex);
117 sal_Int32 nMinimumWidth = pChild->GetMinimumWidth ();
118 if (nMinimumWidth > nTotalMinimumWidth)
119 nTotalMinimumWidth = nMinimumWidth;
122 return nTotalMinimumWidth;;
128 ObjectBarManager* TreeNode::GetObjectBarManager (void)
130 if (mpParent != NULL)
131 return mpParent->GetObjectBarManager();
132 else
133 return NULL;
139 bool TreeNode::IsResizable (void)
141 return false;
147 void TreeNode::RequestResize (void)
149 if (mpParent != NULL)
150 mpParent->RequestResize();
156 ControlContainer& TreeNode::GetControlContainer (void)
158 return *mpControlContainer.get();
164 bool TreeNode::Expand (bool bExpansionState)
166 bool bExpansionStateChanged (false);
168 if (IsExpandable() && IsExpanded()!=bExpansionState)
170 if (bExpansionState)
171 GetWindow()->Show();
172 else
173 GetWindow()->Hide();
174 bExpansionStateChanged = true;
176 FireStateChangeEvent (EID_EXPANSION_STATE_CHANGED);
179 return bExpansionStateChanged;
185 bool TreeNode::IsExpanded (void) const
187 if (GetConstWindow()!=NULL)
188 return GetConstWindow()->IsVisible();
189 else
190 return false;
196 bool TreeNode::IsExpandable (void) const
198 return GetConstWindow()!=NULL;
204 void TreeNode::Show (bool bExpansionState)
206 if (GetWindow() != NULL)
208 bool bWasShowing (IsShowing());
209 GetWindow()->Show (bExpansionState);
210 if (bWasShowing != bExpansionState)
211 FireStateChangeEvent (EID_SHOWING_STATE_CHANGED);
218 bool TreeNode::IsShowing (void) const
220 const ::Window* pWindow = const_cast<TreeNode*>(this)->GetWindow();
221 if (pWindow != NULL)
222 return pWindow->IsVisible();
223 else
224 return false;
230 TaskPaneShellManager* TreeNode::GetShellManager (void)
232 if (mpParent != NULL)
233 return mpParent->GetShellManager();
234 else
235 return NULL;
241 ::com::sun::star::uno::Reference<
242 ::com::sun::star::accessibility::XAccessible> TreeNode::GetAccessibleObject (void)
244 ::com::sun::star::uno::Reference<
245 ::com::sun::star::accessibility::XAccessible> xAccessible;
246 ::Window* pWindow = GetWindow();
247 if (pWindow != NULL)
249 xAccessible = pWindow->GetAccessible(FALSE);
250 if ( ! xAccessible.is())
252 ::com::sun::star::uno::Reference<
253 ::com::sun::star::accessibility::XAccessible> xParent;
254 if (pWindow!=NULL && pWindow->GetAccessibleParentWindow()!=NULL)
255 xParent = pWindow->GetAccessibleParentWindow()->GetAccessible();
256 xAccessible = CreateAccessibleObject(xParent);
257 pWindow->SetAccessible(xAccessible);
260 return xAccessible;
266 ::com::sun::star::uno::Reference<
267 ::com::sun::star::accessibility::XAccessible> TreeNode::CreateAccessibleObject (
268 const ::com::sun::star::uno::Reference<
269 ::com::sun::star::accessibility::XAccessible>& )
271 if (GetWindow() != NULL)
272 return GetWindow()->CreateAccessible();
273 else
274 return NULL;
280 void TreeNode::AddStateChangeListener (const Link& rListener)
282 if (::std::find (
283 maStateChangeListeners.begin(),
284 maStateChangeListeners.end(),
285 rListener) == maStateChangeListeners.end())
287 maStateChangeListeners.push_back(rListener);
294 void TreeNode::RemoveStateChangeListener (const Link& rListener)
296 maStateChangeListeners.erase (
297 ::std::find (
298 maStateChangeListeners.begin(),
299 maStateChangeListeners.end(),
300 rListener));
306 void TreeNode::FireStateChangeEvent (
307 TreeNodeStateChangeEventId eEventId,
308 TreeNode* pChild) const
310 TreeNodeStateChangeEvent aEvent (*this, eEventId, pChild);
311 StateChangeListenerContainer aContainerCopy(maStateChangeListeners);
312 StateChangeListenerContainer::iterator aLink (aContainerCopy.begin());
313 StateChangeListenerContainer::iterator aEnd (aContainerCopy.end());
314 while (aLink!=aEnd)
316 aLink->Call (&aEvent);
317 ++aLink;
323 TreeNodeStateChangeEvent::TreeNodeStateChangeEvent (
324 const TreeNode& rNode,
325 TreeNodeStateChangeEventId eEventId,
326 TreeNode* pChild)
327 : mrSource(rNode),
328 meEventId(eEventId),
329 mpChild(pChild)
334 } } // end of namespace ::sd::toolpanel