1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ToolPanel.cxx,v $
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/ToolPanel.hxx"
36 #include "TaskPaneFocusManager.hxx"
37 #include "taskpane/TitleBar.hxx"
38 #include "taskpane/TitledControl.hxx"
39 #include "taskpane/ControlContainer.hxx"
40 #include "TaskPaneViewShell.hxx"
41 #include "taskpane/TaskPaneControlFactory.hxx"
42 #include "AccessibleTaskPane.hxx"
44 #include "strings.hrc"
45 #include "sdresid.hxx"
46 #include <vcl/decoview.hxx>
47 #include <vcl/menu.hxx>
48 #include <vcl/svapp.hxx>
50 namespace sd
{ namespace toolpanel
{
53 /** Use WB_DIALOGCONTROL as argument for the Control constructor to
54 let VCL handle focus traveling. In addition the control
55 descriptors have to use WB_TABSTOP.
57 ToolPanel::ToolPanel (
58 Window
* pParentWindow
,
59 TaskPaneViewShell
& rViewShell
)
60 : Control (pParentWindow
, WB_DIALOGCONTROL
),
62 mrViewShell(rViewShell
),
63 mbRearrangeActive(false)
65 SetBackground (Wallpaper ());
71 ToolPanel::~ToolPanel (void)
78 sal_uInt32
ToolPanel::AddControl (
79 ::std::auto_ptr
<ControlFactory
> pControlFactory
,
82 const TitledControl::ClickHandler
& rClickHandler
)
84 TitledControl
* pTitledControl
= new TitledControl (
89 TitleBar::TBT_CONTROL_TITLE
);
90 ::std::auto_ptr
<TreeNode
> pChild (pTitledControl
);
92 // Get the (grand) parent window which is focus-wise our parent.
93 Window
* pParent
= GetParent();
95 pParent
= pParent
->GetParent();
97 FocusManager
& rFocusManager (FocusManager::Instance());
98 int nControlCount (mpControlContainer
->GetControlCount());
100 // Add a link up from every control to the parent. A down link is added
101 // only for the first control so that when entering the sub tool panel
102 // the focus is set to the first control.
105 if (nControlCount
== 1)
106 rFocusManager
.RegisterDownLink(pParent
, pChild
->GetWindow());
107 rFocusManager
.RegisterUpLink(pChild
->GetWindow(), pParent
);
110 // Replace the old links for cycling between first and last child by
112 if (nControlCount
> 0)
114 ::Window
* pFirst
= mpControlContainer
->GetControl(0)->GetWindow();
115 ::Window
* pLast
= mpControlContainer
->GetControl(nControlCount
-1)->GetWindow();
116 rFocusManager
.RemoveLinks(pFirst
,pLast
);
117 rFocusManager
.RemoveLinks(pLast
,pFirst
);
119 rFocusManager
.RegisterLink(pFirst
,pChild
->GetWindow(), KEY_UP
);
120 rFocusManager
.RegisterLink(pChild
->GetWindow(),pFirst
, KEY_DOWN
);
123 pTitledControl
->GetWindow()->SetHelpId(nHelpId
);
125 return mpControlContainer
->AddControl (pChild
);
131 void ToolPanel::ListHasChanged (void)
133 mpControlContainer
->ListHasChanged ();
140 void ToolPanel::Resize (void)
149 void ToolPanel::RequestResize (void)
158 /** Subtract the space for the title bars from the available space and
159 give the remaining space to the active control.
161 void ToolPanel::Rearrange (void)
163 // Prevent recursive calls.
164 if ( ! mbRearrangeActive
&& mpControlContainer
->GetVisibleControlCount()>0)
166 mbRearrangeActive
= true;
168 SetBackground (Wallpaper ());
170 // Make the area that is covered by the children a little bit
171 // smaller so that a frame is visible arround them.
172 Rectangle
aAvailableArea (Point(0,0), GetOutputSizePixel());
174 int nWidth
= aAvailableArea
.GetWidth();
175 sal_uInt32
nControlCount (mpControlContainer
->GetControlCount());
176 sal_uInt32
nActiveControlIndex (
177 mpControlContainer
->GetActiveControlIndex());
179 // Place title bars of controls above the active control and thereby
180 // determine the top of the active control.
182 for (nIndex
=mpControlContainer
->GetFirstIndex();
183 nIndex
<nActiveControlIndex
;
184 nIndex
=mpControlContainer
->GetNextIndex(nIndex
))
186 TreeNode
* pChild
= mpControlContainer
->GetControl(nIndex
);
189 sal_uInt32 nHeight
= pChild
->GetPreferredHeight (nWidth
);
190 pChild
->GetWindow()->SetPosSizePixel (
191 aAvailableArea
.TopLeft(),
192 Size(nWidth
, nHeight
));
193 aAvailableArea
.Top() += nHeight
;
197 // Place title bars of controls below the active control and thereby
198 // determine the bottom of the active control.
199 for (nIndex
=mpControlContainer
->GetLastIndex();
200 nIndex
<nControlCount
&& nIndex
!=nActiveControlIndex
;
201 nIndex
=mpControlContainer
->GetPreviousIndex(nIndex
))
203 TreeNode
* pChild
= mpControlContainer
->GetControl(nIndex
);
206 sal_uInt32 nHeight
= pChild
->GetPreferredHeight (nWidth
);
207 pChild
->GetWindow()->SetPosSizePixel (
208 Point(aAvailableArea
.Left(),
209 aAvailableArea
.Bottom()-nHeight
+1),
210 Size(nWidth
, nHeight
));
211 aAvailableArea
.Bottom() -= nHeight
;
215 // Finally place the active control.
216 TreeNode
* pChild
= mpControlContainer
->GetControl(nActiveControlIndex
);
218 pChild
->GetWindow()->SetPosSizePixel (
219 aAvailableArea
.TopLeft(),
220 aAvailableArea
.GetSize());
222 mbRearrangeActive
= false;
226 Application::GetSettings().GetStyleSettings().GetDialogColor());
232 Size
ToolPanel::GetPreferredSize (void)
234 return Size(300,300);
240 sal_Int32
ToolPanel::GetPreferredWidth (sal_Int32
)
248 sal_Int32
ToolPanel::GetPreferredHeight (sal_Int32
)
256 bool ToolPanel::IsResizable (void)
264 ::Window
* ToolPanel::GetWindow (void)
272 TaskPaneShellManager
* ToolPanel::GetShellManager (void)
274 return &mrViewShell
.GetSubShellManager();
280 ::com::sun::star::uno::Reference
<
281 ::com::sun::star::accessibility::XAccessible
> ToolPanel::CreateAccessibleObject (
282 const ::com::sun::star::uno::Reference
<
283 ::com::sun::star::accessibility::XAccessible
>& rxParent
)
285 return new ::accessibility::AccessibleTaskPane (
287 String(SdResId(STR_RIGHT_PANE_TITLE
)),
288 String(SdResId(STR_RIGHT_PANE_TITLE
)),
292 } } // end of namespace ::sd::toolpanel