CWS-TOOLING: integrate CWS os150
[LibreOffice.git] / sd / source / ui / toolpanel / SubToolPanel.cxx
blob4e85d8c9fec9ee6be50bf97435ddbee21c166245
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/SubToolPanel.hxx"
33 #include "TaskPaneFocusManager.hxx"
34 #include "taskpane/TitleBar.hxx"
35 #include "taskpane/TitledControl.hxx"
36 #include "taskpane/ControlContainer.hxx"
37 #include "AccessibleTreeNode.hxx"
38 #include <vcl/decoview.hxx>
39 #include <vcl/svapp.hxx>
41 namespace sd { namespace toolpanel {
44 SubToolPanel::SubToolPanel (
45 Window& i_rParentWindow)
46 : Control (&i_rParentWindow, WB_DIALOGCONTROL),
47 TreeNode(NULL),
48 maWindowFiller(this),
49 mbIsRearrangePending(true),
50 mbIsLayoutPending(true),
51 mnChildrenWidth(0),
52 mnVerticalBorder(0),
53 mnVerticalGap(3),
54 mnHorizontalBorder(2)
56 SetAccessibleName (
57 ::rtl::OUString::createFromAscii("Sub Task Panel"));
58 mpControlContainer->SetMultiSelection (true);
60 SetBorderStyle (WINDOW_BORDER_NORMAL);
61 SetMapMode (MapMode(MAP_PIXEL));
63 // To reduce flickering during repaints make the container windows
64 // transparent and rely on their children to paint the whole area.
65 SetBackground(Wallpaper());
66 maWindowFiller.SetBackground(
67 Application::GetSettings().GetStyleSettings().GetWindowColor());
73 SubToolPanel::~SubToolPanel (void)
75 sal_uInt32 nCount = mpControlContainer->GetControlCount();
76 for (sal_uInt32 nIndex=0; nIndex<nCount; nIndex++)
78 TitledControl* pControl = static_cast<TitledControl*>(
79 mpControlContainer->GetControl(nIndex));
80 pControl->GetControl()->GetWindow()->RemoveEventListener(
81 LINK(this,SubToolPanel,WindowEventListener));
83 mpControlContainer->DeleteChildren();
89 void SubToolPanel::Paint (const Rectangle& rRect)
91 if (mbIsRearrangePending)
92 Rearrange();
93 if (mbIsLayoutPending)
94 LayoutChildren();
95 ::Window::Paint (rRect);
97 // Paint the outer border and the space between every two children.
98 Color aOriginalLineColor (GetLineColor());
99 Color aOriginalFillColor (GetFillColor());
101 SetLineColor ();
102 SetFillColor (GetSettings().GetStyleSettings().GetWindowColor());
104 Size aSize (GetOutputSizePixel());
105 // Paint left and right vertical border.
106 Rectangle aVerticalArea (
107 Point(0,0),
108 Size(mnHorizontalBorder,aSize.Height()));
109 DrawRect (aVerticalArea);
110 aVerticalArea.Right() += mnHorizontalBorder + mnChildrenWidth - 1;
111 aVerticalArea.Left() = aVerticalArea.Right() + mnHorizontalBorder;
112 DrawRect (aVerticalArea);
114 // Paint horizontal stripes.
115 Rectangle aStripeArea (
116 Point (mnHorizontalBorder,0),
117 Size(mnChildrenWidth,0));
118 StripeList::const_iterator iStripe;
119 for (iStripe=maStripeList.begin(); iStripe!=maStripeList.end(); iStripe++)
121 aStripeArea.Top() = iStripe->first;
122 aStripeArea.Bottom() = iStripe->second;
123 if (aStripeArea.Bottom() < 0)
124 continue;
125 if (aStripeArea.Top() >= aSize.Height())
126 break;
127 DrawRect (aStripeArea);
130 SetLineColor (aOriginalLineColor);
131 SetFillColor (aOriginalFillColor);
137 void SubToolPanel::Resize (void)
139 ::Window::Resize();
140 mbIsRearrangePending = true;
141 mbIsLayoutPending = true;
147 void SubToolPanel::RequestResize (void)
149 mbIsRearrangePending = true;
150 mbIsLayoutPending = true;
151 Invalidate();
157 Size SubToolPanel::GetPreferredSize (void)
159 return GetRequiredSize();
165 sal_Int32 SubToolPanel::GetPreferredWidth (sal_Int32 )
167 return GetPreferredSize().Width();
173 sal_Int32 SubToolPanel::GetPreferredHeight (sal_Int32 )
175 return GetPreferredSize().Height();
181 bool SubToolPanel::IsResizable (void)
183 return true;
189 ::Window* SubToolPanel::GetWindow (void)
191 return this;
197 sal_Int32 SubToolPanel::GetMinimumWidth (void)
199 return TreeNode::GetMinimumWidth();
205 void SubToolPanel::ExpandControl (
206 TreeNode* pControl,
207 bool bExpansionState)
209 // Toggle expand status.
210 pControl->Expand (bExpansionState);
212 Rearrange ();
213 Invalidate ();
219 /** This control shows an expansion bar for every control and in a
220 separate area below that expansion area it shows all controls each
221 with its title bar. When there is not enough space then show a
222 scroll bar in the control area.
224 void SubToolPanel::Rearrange (void)
226 Size aRequiredSize (GetRequiredSize());
227 if (aRequiredSize.Width()>0 && aRequiredSize.Height()>0)
229 Size aAvailableSize (GetOutputSizePixel());
231 // Make the children at least as wide as the sub tool panel.
232 if (aRequiredSize.Width() < aAvailableSize.Width())
233 aRequiredSize.Width() = aAvailableSize.Width();
234 mnChildrenWidth = -2*mnHorizontalBorder;
235 mnChildrenWidth += aAvailableSize.Width();
237 LayoutChildren();
239 mbIsRearrangePending = false;
246 Size SubToolPanel::GetRequiredSize (void)
248 // First determine the width of the children. This is the maximum of
249 // the current window width and the individual minimum widths of the
250 // children.
251 int nChildrenWidth (GetSizePixel().Width());
252 unsigned int nCount = mpControlContainer->GetControlCount();
253 unsigned int nIndex;
254 for (nIndex=0; nIndex<nCount; nIndex++)
256 TreeNode* pChild = mpControlContainer->GetControl (nIndex);
257 int nMinimumWidth (pChild->GetMinimumWidth());
258 if (nMinimumWidth > nChildrenWidth)
259 nChildrenWidth = nMinimumWidth;
262 // Determine the accumulated width of all children when scaled to the
263 // minimum width.
264 nChildrenWidth -= 2*mnHorizontalBorder;
265 Size aTotalSize (nChildrenWidth,
266 2*mnVerticalBorder + (nCount-1) * mnVerticalGap);
267 for (nIndex=0; nIndex<nCount; nIndex++)
269 TreeNode* pChild = mpControlContainer->GetControl (nIndex);
270 sal_Int32 nHeight = pChild->GetPreferredHeight(nChildrenWidth);
271 aTotalSize.Height() += nHeight;
274 return aTotalSize;
280 sal_Int32 SubToolPanel::LayoutChildren (void)
282 // Determine vertical space that can be distributed to sizable children.
283 unsigned int nCount (mpControlContainer->GetControlCount());
284 unsigned int nResizableCount = 0;
285 int nAvailableHeight = GetSizePixel().Height() - 2*mnVerticalBorder;
286 unsigned int nIndex;
287 for (nIndex=0; nIndex<nCount; nIndex++)
289 TreeNode* pChild = mpControlContainer->GetControl (nIndex);
290 int nControlHeight = pChild->GetPreferredHeight(mnChildrenWidth);
291 if (pChild->IsResizable())
292 nResizableCount++;
293 else
294 nAvailableHeight -= nControlHeight;
297 maStripeList.clear();
299 Point aPosition (0,0);
300 aPosition.X() += mnHorizontalBorder;
301 maStripeList.push_back( ::std::pair<int,int>(
302 aPosition.Y(),
303 aPosition.Y() + mnVerticalBorder - 1));
304 aPosition.Y() += mnVerticalBorder;
306 // Place the controls one over the other.
307 for (nIndex=0; nIndex<nCount; nIndex++)
309 if (nIndex > 0)
311 maStripeList.push_back( ::std::pair<int,int>(
312 aPosition.Y(),
313 aPosition.Y() + mnVerticalGap - 1));
314 aPosition.Y() += mnVerticalGap;
316 TreeNode* pChild = mpControlContainer->GetControl (nIndex);
317 int nControlHeight = pChild->GetPreferredHeight(mnChildrenWidth);
318 if (pChild->IsResizable())
320 nControlHeight = nAvailableHeight / nResizableCount;
321 nResizableCount--;
323 nAvailableHeight -= nControlHeight;
324 pChild->GetWindow()->SetPosSizePixel(
325 aPosition,
326 Size(mnChildrenWidth, nControlHeight));
327 aPosition.Y() += nControlHeight;
330 // If the children do not cover their parent window completely
331 // (regarding the height) we put a filler below that is responsible for
332 // painting the remaining space.
333 int nWindowHeight = GetSizePixel().Height();
334 if (aPosition.Y() < nWindowHeight)
336 maWindowFiller.SetPosSizePixel (
337 aPosition,
338 Size(mnChildrenWidth, nWindowHeight-aPosition.Y()));
339 maStripeList.push_back( ::std::pair<int,int>(
340 aPosition.Y(),
341 nWindowHeight-1));
342 // maScrollWindowFiller.Show();
343 aPosition.Y() = nWindowHeight;
345 else
346 maWindowFiller.Hide();
348 aPosition.Y() += mnVerticalBorder;
349 mbIsLayoutPending = false;
351 return aPosition.Y();
357 IMPL_LINK(SubToolPanel, WindowEventListener, VclSimpleEvent*, pEvent)
359 if (pEvent!=NULL && pEvent->ISA(VclWindowEvent))
361 VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent);
362 switch (pWindowEvent->GetId())
364 case VCLEVENT_WINDOW_SHOW:
365 case VCLEVENT_WINDOW_HIDE:
366 case VCLEVENT_WINDOW_ACTIVATE:
367 case VCLEVENT_WINDOW_RESIZE:
368 RequestResize();
369 break;
372 return 0;
378 ::com::sun::star::uno::Reference<
379 ::com::sun::star::accessibility::XAccessible> SubToolPanel::CreateAccessibleObject (
380 const ::com::sun::star::uno::Reference<
381 ::com::sun::star::accessibility::XAccessible>& )
383 return new ::accessibility::AccessibleTreeNode (
384 *this,
385 ::rtl::OUString::createFromAscii("Sub Task Panel"),
386 ::rtl::OUString::createFromAscii("Sub Task Panel"),
387 ::com::sun::star::accessibility::AccessibleRole::PANEL);
390 } } // end of namespace ::sd::toolpanel