1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
31 #include "taskpane/TitledControl.hxx"
33 #include "AccessibleTreeNode.hxx"
34 #include "taskpane/ControlContainer.hxx"
35 #include "TaskPaneFocusManager.hxx"
36 #include "taskpane/TaskPaneControlFactory.hxx"
37 #include <vcl/ctrl.hxx>
38 #include <vcl/svapp.hxx>
41 namespace sd
{ namespace toolpanel
{
44 TitledControl::TitledControl (
46 ::std::auto_ptr
<TreeNode
> pControl
,
48 const ClickHandler
& rClickHandler
,
49 TitleBar::TitleBarType eType
)
50 : ::Window (pParent
->GetWindow(), WB_TABSTOP
),
55 mpClickHandler(new ClickHandler(rClickHandler
))
57 mpControlContainer
->AddControl (::std::auto_ptr
<TreeNode
> (
58 new TitleBar (this, rTitle
, eType
, pControl
->IsExpandable())));
59 pControl
->SetParentNode (this);
60 mpControlContainer
->AddControl (pControl
);
62 FocusManager::Instance().RegisterDownLink( GetTitleBar()->GetWindow(), GetControl()->GetWindow() );
63 FocusManager::Instance().RegisterUpLink( GetControl()->GetWindow(), GetTitleBar()->GetWindow() );
65 SetBackground (Wallpaper());
67 GetTitleBar()->GetWindow()->Show ();
68 GetTitleBar()->GetWindow()->AddEventListener (
69 LINK(this,TitledControl
,WindowEventListener
));
77 TitledControl::~TitledControl (void)
79 GetTitleBar()->GetWindow()->RemoveEventListener (
80 LINK(this,TitledControl
,WindowEventListener
));
86 Size
TitledControl::GetPreferredSize (void)
89 if (GetControl() != NULL
)
91 aPreferredSize
= GetControl()->GetPreferredSize();
93 aPreferredSize
.Height() = 0;
96 aPreferredSize
= Size (GetSizePixel().Width(), 0);
97 if (aPreferredSize
.Width() == 0)
98 aPreferredSize
.Width() = 300;
99 aPreferredSize
.Height() += GetTitleBar()->GetPreferredHeight(
100 aPreferredSize
.Width());
102 return aPreferredSize
;
108 sal_Int32
TitledControl::GetPreferredWidth (sal_Int32 nHeight
)
110 int nPreferredWidth
= 0;
111 if (GetControl() != NULL
)
112 nPreferredWidth
= GetControl()->GetPreferredWidth(
113 nHeight
- GetTitleBar()->GetWindow()->GetSizePixel().Height());
115 nPreferredWidth
= GetSizePixel().Width();
116 if (nPreferredWidth
== 0)
117 nPreferredWidth
= 300;
119 return nPreferredWidth
;
125 sal_Int32
TitledControl::GetPreferredHeight (sal_Int32 nWidth
)
127 int nPreferredHeight
= 0;
128 if (IsExpanded() && GetControl()!=NULL
)
129 nPreferredHeight
= GetControl()->GetPreferredHeight(nWidth
);
130 nPreferredHeight
+= GetTitleBar()->GetPreferredHeight(nWidth
);
132 return nPreferredHeight
;
138 bool TitledControl::IsResizable (void)
141 && GetControl()->IsResizable();
147 ::Window
* TitledControl::GetWindow (void)
155 void TitledControl::Resize (void)
157 Size
aWindowSize (GetOutputSizePixel());
160 = GetTitleBar()->GetPreferredHeight(aWindowSize
.Width());
161 GetTitleBar()->GetWindow()->SetPosSizePixel (
163 Size (aWindowSize
.Width(), nTitleBarHeight
));
166 TreeNode
* pControl
= GetControl();
168 && pControl
->GetWindow() != NULL
169 && pControl
->GetWindow()->IsVisible())
171 pControl
->GetWindow()->SetPosSizePixel (
172 Point (0,nTitleBarHeight
),
173 Size (aWindowSize
.Width(), aWindowSize
.Height()-nTitleBarHeight
));
180 void TitledControl::GetFocus (void)
182 ::Window::GetFocus();
183 if (GetTitleBar() != NULL
)
184 GetTitleBar()->GrabFocus();
190 void TitledControl::KeyInput (const KeyEvent
& rEvent
)
192 KeyCode nCode
= rEvent
.GetKeyCode();
193 if (nCode
== KEY_SPACE
)
195 // Toggle the expansion state of the control (when toggling is
196 // supported.) The focus remains on this control.
197 GetParentNode()->GetControlContainer().SetExpansionState (
199 ControlContainer::ES_TOGGLE
);
201 else if (nCode
== KEY_RETURN
)
203 // Return, also called enter, enters the control and puts the
204 // focus to the first child. If the control is not yet
205 // expanded then do that first.
206 GetParentNode()->GetControlContainer().SetExpansionState (
208 ControlContainer::ES_EXPAND
);
210 if ( ! FocusManager::Instance().TransferFocus(this,nCode
))
212 // When already expanded then put focus on first child.
213 TreeNode
* pControl
= GetControl();
214 if (pControl
!=NULL
&& IsExpanded())
215 if (pControl
->GetWindow() != NULL
)
216 pControl
->GetWindow()->GrabFocus();
219 else if (nCode
== KEY_ESCAPE
)
221 if ( ! FocusManager::Instance().TransferFocus(this,nCode
))
222 // Put focus to parent.
223 GetParent()->GrabFocus();
226 Window::KeyInput (rEvent
);
232 const String
& TitledControl::GetTitle (void) const
240 bool TitledControl::Expand (bool bExpanded
)
242 bool bExpansionStateChanged (false);
244 if (IsExpandable() && IsEnabled())
246 if (GetTitleBar()->IsExpanded() != bExpanded
)
247 bExpansionStateChanged
|= GetTitleBar()->Expand (bExpanded
);
248 // Get the control. Use the bExpanded parameter as argument to
249 // indicate that a control is created via its factory only when it
250 // is to be expanded. When it is collapsed this is not necessary.
251 TreeNode
* pControl
= GetControl();
253 && GetControl()->IsExpanded() != bExpanded
)
255 bExpansionStateChanged
|= pControl
->Expand (bExpanded
);
257 if (bExpansionStateChanged
)
261 return bExpansionStateChanged
;
267 bool TitledControl::IsExpandable (void) const
269 const TreeNode
* pControl
= GetConstControl();
270 if (pControl
!= NULL
)
271 return pControl
->IsExpandable();
273 // When a control factory is given but the control has not yet been
274 // created we assume that the control is expandable.
281 bool TitledControl::IsExpanded (void) const
283 const TreeNode
* pControl
= GetConstControl();
284 if (pControl
!= NULL
)
285 return pControl
->IsExpanded();
290 void TitledControl::SetEnabledState(bool bFlag
)
294 GetParentNode()->GetControlContainer().SetExpansionState (
296 ControlContainer::ES_COLLAPSE
);
302 GetParentNode()->GetControlContainer().SetExpansionState (
304 ControlContainer::ES_EXPAND);
309 GetTitleBar()->SetEnabledState(bFlag
);
314 bool TitledControl::IsShowing (void) const
322 void TitledControl::Show (bool bVisible
)
324 if (mbVisible
!= bVisible
)
326 mbVisible
= bVisible
;
334 void TitledControl::UpdateStates (void)
341 TreeNode
* pControl
= GetControl();
342 if (pControl
!=NULL
&& pControl
->GetWindow() != NULL
)
344 if (IsVisible() && IsExpanded())
345 pControl
->GetWindow()->Show();
347 pControl
->GetWindow()->Hide();
354 IMPL_LINK(TitledControl
, WindowEventListener
,
355 VclSimpleEvent
*, pEvent
)
357 if (pEvent
!=NULL
&& pEvent
->ISA(VclWindowEvent
))
359 VclWindowEvent
* pWindowEvent
= static_cast<VclWindowEvent
*>(pEvent
);
360 switch (pWindowEvent
->GetId())
362 case VCLEVENT_WINDOW_MOUSEBUTTONUP
:
364 (*mpClickHandler
)(*this);
374 TreeNode
* TitledControl::GetControl (void)
376 return mpControlContainer
->GetControl(1);
382 const TreeNode
* TitledControl::GetConstControl () const
384 return const_cast<TitledControl
*>(this)->GetControl();
390 TitleBar
* TitledControl::GetTitleBar (void)
392 return static_cast<TitleBar
*>(mpControlContainer
->GetControl(0));
398 ::com::sun::star::uno::Reference
<
399 ::com::sun::star::accessibility::XAccessible
> TitledControl::CreateAccessibleObject (
400 const ::com::sun::star::uno::Reference
<
401 ::com::sun::star::accessibility::XAccessible
>& )
403 return new ::accessibility::AccessibleTreeNode(
407 ::com::sun::star::accessibility::AccessibleRole::LIST_ITEM
);
413 //===== TitledControlStandardClickHandler =====================================
415 TitledControlStandardClickHandler::TitledControlStandardClickHandler (
416 ControlContainer
& rControlContainer
,
417 ControlContainer::ExpansionState eExpansionState
)
418 : mrControlContainer(rControlContainer
),
419 meExpansionState(eExpansionState
)
426 void TitledControlStandardClickHandler::operator () (TitledControl
& rTitledControl
)
429 mrControlContainer
.SetExpansionState (&rTitledControl
, meExpansionState
);
432 } } // end of namespace ::sd::toolpanel