merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / toolpanel / ToolPanel.cxx
blob291e48eaa2b373104643dba12059d6a6c2ee5132
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: ToolPanel.cxx,v $
10 * $Revision: 1.14 $
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),
61 TreeNode (NULL),
62 mrViewShell(rViewShell),
63 mbRearrangeActive(false)
65 SetBackground (Wallpaper ());
71 ToolPanel::~ToolPanel (void)
78 sal_uInt32 ToolPanel::AddControl (
79 ::std::auto_ptr<ControlFactory> pControlFactory,
80 const String& rTitle,
81 ULONG nHelpId,
82 const TitledControl::ClickHandler& rClickHandler)
84 TitledControl* pTitledControl = new TitledControl (
85 this,
86 pControlFactory,
87 rTitle,
88 rClickHandler,
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();
94 if (pParent != NULL)
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.
103 if (pParent != NULL)
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
111 // current ones.
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 ();
134 Rearrange ();
140 void ToolPanel::Resize (void)
142 Control::Resize();
143 Rearrange ();
149 void ToolPanel::RequestResize (void)
151 Invalidate();
152 Rearrange ();
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.
181 sal_uInt32 nIndex;
182 for (nIndex=mpControlContainer->GetFirstIndex();
183 nIndex<nActiveControlIndex;
184 nIndex=mpControlContainer->GetNextIndex(nIndex))
186 TreeNode* pChild = mpControlContainer->GetControl(nIndex);
187 if (pChild != NULL)
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);
204 if (pChild != NULL)
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);
217 if (pChild != NULL)
218 pChild->GetWindow()->SetPosSizePixel (
219 aAvailableArea.TopLeft(),
220 aAvailableArea.GetSize());
222 mbRearrangeActive = false;
224 else
225 SetBackground (
226 Application::GetSettings().GetStyleSettings().GetDialogColor());
232 Size ToolPanel::GetPreferredSize (void)
234 return Size(300,300);
240 sal_Int32 ToolPanel::GetPreferredWidth (sal_Int32 )
242 return 300;
248 sal_Int32 ToolPanel::GetPreferredHeight (sal_Int32 )
250 return 300;
256 bool ToolPanel::IsResizable (void)
258 return true;
264 ::Window* ToolPanel::GetWindow (void)
266 return this;
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 (
286 rxParent,
287 String(SdResId(STR_RIGHT_PANE_TITLE)),
288 String(SdResId(STR_RIGHT_PANE_TITLE)),
289 *this);
292 } } // end of namespace ::sd::toolpanel