bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / toolpanel / TaskPaneTreeNode.cxx
blobdd74850955311635a55fdbbdbb6063c85944f827
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "taskpane/TaskPaneTreeNode.hxx"
23 #include "taskpane/ControlContainer.hxx"
24 #include "taskpane/TitledControl.hxx"
26 #include <vector>
27 #include <algorithm>
29 namespace sd { namespace toolpanel {
31 TreeNode::TreeNode( TreeNode* pParent)
32 : mpControlContainer (new ControlContainer(this))
33 , mpParent (pParent)
34 , maStateChangeListeners()
41 TreeNode::~TreeNode (void)
48 void TreeNode::SetParentNode (TreeNode* pNewParent)
50 mpParent = pNewParent;
51 GetWindow()->SetParent (pNewParent->GetWindow());
57 TreeNode* TreeNode::GetParentNode (void)
59 return mpParent;
65 ::Window* TreeNode::GetWindow (void)
67 return NULL;
73 const ::Window* TreeNode::GetConstWindow (void) const
75 return const_cast<TreeNode*>(this)->GetWindow();
81 sal_Int32 TreeNode::GetMinimumWidth (void)
83 sal_Int32 nTotalMinimumWidth = 0;
84 unsigned int nCount = mpControlContainer->GetControlCount();
85 for (unsigned int nIndex=0; nIndex<nCount; nIndex++)
87 TreeNode* pChild = mpControlContainer->GetControl (nIndex);
88 sal_Int32 nMinimumWidth = pChild->GetMinimumWidth ();
89 if (nMinimumWidth > nTotalMinimumWidth)
90 nTotalMinimumWidth = nMinimumWidth;
93 return nTotalMinimumWidth;
99 bool TreeNode::IsResizable (void)
101 return false;
107 void TreeNode::RequestResize (void)
109 if (mpParent != NULL)
110 mpParent->RequestResize();
116 ControlContainer& TreeNode::GetControlContainer (void)
118 return *mpControlContainer.get();
124 bool TreeNode::Expand (bool bExpansionState)
126 bool bExpansionStateChanged (false);
128 if (IsExpandable() && IsExpanded()!=bExpansionState)
130 if (bExpansionState)
131 GetWindow()->Show();
132 else
133 GetWindow()->Hide();
134 bExpansionStateChanged = true;
136 FireStateChangeEvent (EID_EXPANSION_STATE_CHANGED);
139 return bExpansionStateChanged;
145 bool TreeNode::IsExpanded (void) const
147 if (GetConstWindow()!=NULL)
148 return GetConstWindow()->IsVisible();
149 else
150 return false;
156 bool TreeNode::IsExpandable (void) const
158 return GetConstWindow()!=NULL;
164 void TreeNode::Show (bool bExpansionState)
166 if (GetWindow() != NULL)
168 bool bWasShowing (IsShowing());
169 GetWindow()->Show (bExpansionState);
170 if (bWasShowing != bExpansionState)
171 FireStateChangeEvent (EID_SHOWING_STATE_CHANGED);
178 bool TreeNode::IsShowing (void) const
180 const ::Window* pWindow = const_cast<TreeNode*>(this)->GetWindow();
181 if (pWindow != NULL)
182 return pWindow->IsVisible();
183 else
184 return false;
190 TaskPaneShellManager* TreeNode::GetShellManager (void)
192 if (mpParent != NULL)
193 return mpParent->GetShellManager();
194 else
195 return NULL;
201 ::com::sun::star::uno::Reference<
202 ::com::sun::star::accessibility::XAccessible> TreeNode::GetAccessibleObject (void)
204 ::com::sun::star::uno::Reference<
205 ::com::sun::star::accessibility::XAccessible> xAccessible;
206 ::Window* pWindow = GetWindow();
207 if (pWindow != NULL)
209 xAccessible = pWindow->GetAccessible(sal_False);
210 if ( ! xAccessible.is())
212 ::com::sun::star::uno::Reference<
213 ::com::sun::star::accessibility::XAccessible> xParent;
214 if (pWindow->GetAccessibleParentWindow()!=NULL)
215 xParent = pWindow->GetAccessibleParentWindow()->GetAccessible();
216 xAccessible = CreateAccessibleObject(xParent);
217 pWindow->SetAccessible(xAccessible);
220 return xAccessible;
226 ::com::sun::star::uno::Reference<
227 ::com::sun::star::accessibility::XAccessible> TreeNode::CreateAccessibleObject (
228 const ::com::sun::star::uno::Reference<
229 ::com::sun::star::accessibility::XAccessible>& )
231 if (GetWindow() != NULL)
232 return GetWindow()->CreateAccessible();
233 else
234 return NULL;
240 void TreeNode::AddStateChangeListener (const Link& rListener)
242 if (::std::find (
243 maStateChangeListeners.begin(),
244 maStateChangeListeners.end(),
245 rListener) == maStateChangeListeners.end())
247 maStateChangeListeners.push_back(rListener);
254 void TreeNode::FireStateChangeEvent (
255 TreeNodeStateChangeEventId eEventId,
256 TreeNode* pChild) const
258 TreeNodeStateChangeEvent aEvent (*this, eEventId, pChild);
259 StateChangeListenerContainer aContainerCopy(maStateChangeListeners);
260 StateChangeListenerContainer::iterator aLink (aContainerCopy.begin());
261 StateChangeListenerContainer::iterator aEnd (aContainerCopy.end());
262 while (aLink!=aEnd)
264 aLink->Call (&aEvent);
265 ++aLink;
271 TreeNodeStateChangeEvent::TreeNodeStateChangeEvent (
272 const TreeNode& rNode,
273 TreeNodeStateChangeEventId eEventId,
274 TreeNode* pChild)
275 : mrSource(rNode),
276 meEventId(eEventId),
277 mpChild(pChild)
282 } } // end of namespace ::sd::toolpanel
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */