Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "taskpane/SubToolPanel.hxx"
31 : :
32 : : #include "TaskPaneFocusManager.hxx"
33 : : #include "taskpane/TitleBar.hxx"
34 : : #include "taskpane/TitledControl.hxx"
35 : : #include "taskpane/ControlContainer.hxx"
36 : : #include "AccessibleTreeNode.hxx"
37 : : #include <vcl/decoview.hxx>
38 : : #include <vcl/svapp.hxx>
39 : :
40 : : namespace sd { namespace toolpanel {
41 : :
42 : :
43 : 17 : SubToolPanel::SubToolPanel (
44 : : Window& i_rParentWindow)
45 : : : Control (&i_rParentWindow, WB_DIALOGCONTROL),
46 : : TreeNode(NULL),
47 : : maWindowFiller(this),
48 : : mbIsRearrangePending(true),
49 : : mbIsLayoutPending(true),
50 : : mnChildrenWidth(0),
51 : : mnVerticalBorder(0),
52 : : mnVerticalGap(3),
53 [ + - ][ + - ]: 17 : mnHorizontalBorder(2)
[ + - ]
54 : : {
55 [ + - ][ + - ]: 17 : SetAccessibleName (::rtl::OUString("Sub Task Panel"));
[ + - ]
56 [ + - ]: 17 : mpControlContainer->SetMultiSelection (true);
57 : :
58 [ + - ]: 17 : SetBorderStyle (WINDOW_BORDER_NORMAL);
59 [ + - ][ + - ]: 17 : SetMapMode (MapMode(MAP_PIXEL));
[ + - ]
60 : :
61 : : // To reduce flickering during repaints make the container windows
62 : : // transparent and rely on their children to paint the whole area.
63 [ + - ][ + - ]: 17 : SetBackground(Wallpaper());
[ + - ]
64 : : maWindowFiller.SetBackground(
65 [ + - ][ + - ]: 17 : Application::GetSettings().GetStyleSettings().GetWindowColor());
[ + - ][ + - ]
66 : 17 : }
67 : :
68 : :
69 : :
70 : :
71 [ + - ][ + - ]: 17 : SubToolPanel::~SubToolPanel (void)
72 : : {
73 [ + - ]: 17 : sal_uInt32 nCount = mpControlContainer->GetControlCount();
74 [ - + ]: 17 : for (sal_uInt32 nIndex=0; nIndex<nCount; nIndex++)
75 : : {
76 : : TitledControl* pControl = static_cast<TitledControl*>(
77 [ # # ][ # # ]: 0 : mpControlContainer->GetControl(nIndex));
78 [ # # ]: 0 : pControl->GetControl()->GetWindow()->RemoveEventListener(
79 [ # # ][ # # ]: 0 : LINK(this,SubToolPanel,WindowEventListener));
[ # # ]
80 : : }
81 [ + - ]: 17 : mpControlContainer->DeleteChildren();
82 [ - + ]: 17 : }
83 : :
84 : :
85 : :
86 : :
87 : 0 : void SubToolPanel::Paint (const Rectangle& rRect)
88 : : {
89 [ # # ]: 0 : if (mbIsRearrangePending)
90 [ # # ]: 0 : Rearrange();
91 [ # # ]: 0 : if (mbIsLayoutPending)
92 [ # # ]: 0 : LayoutChildren();
93 [ # # ]: 0 : ::Window::Paint (rRect);
94 : :
95 : : // Paint the outer border and the space between every two children.
96 : 0 : Color aOriginalLineColor (GetLineColor());
97 : 0 : Color aOriginalFillColor (GetFillColor());
98 : :
99 [ # # ]: 0 : SetLineColor ();
100 [ # # ]: 0 : SetFillColor (GetSettings().GetStyleSettings().GetWindowColor());
101 : :
102 : 0 : Size aSize (GetOutputSizePixel());
103 : : // Paint left and right vertical border.
104 : : Rectangle aVerticalArea (
105 : : Point(0,0),
106 [ # # ]: 0 : Size(mnHorizontalBorder,aSize.Height()));
107 [ # # ]: 0 : DrawRect (aVerticalArea);
108 : 0 : aVerticalArea.Right() += mnHorizontalBorder + mnChildrenWidth - 1;
109 : 0 : aVerticalArea.Left() = aVerticalArea.Right() + mnHorizontalBorder;
110 [ # # ]: 0 : DrawRect (aVerticalArea);
111 : :
112 : : // Paint horizontal stripes.
113 : : Rectangle aStripeArea (
114 : : Point (mnHorizontalBorder,0),
115 [ # # ]: 0 : Size(mnChildrenWidth,0));
116 : 0 : StripeList::const_iterator iStripe;
117 [ # # ][ # # ]: 0 : for (iStripe=maStripeList.begin(); iStripe!=maStripeList.end(); ++iStripe)
[ # # ][ # # ]
118 : : {
119 [ # # ]: 0 : aStripeArea.Top() = iStripe->first;
120 [ # # ]: 0 : aStripeArea.Bottom() = iStripe->second;
121 [ # # ]: 0 : if (aStripeArea.Bottom() < 0)
122 : 0 : continue;
123 [ # # ]: 0 : if (aStripeArea.Top() >= aSize.Height())
124 : 0 : break;
125 [ # # ]: 0 : DrawRect (aStripeArea);
126 : : }
127 : :
128 [ # # ]: 0 : SetLineColor (aOriginalLineColor);
129 [ # # ]: 0 : SetFillColor (aOriginalFillColor);
130 : 0 : }
131 : :
132 : :
133 : :
134 : :
135 : 0 : void SubToolPanel::Resize (void)
136 : : {
137 : 0 : ::Window::Resize();
138 : 0 : mbIsRearrangePending = true;
139 : 0 : mbIsLayoutPending = true;
140 : 0 : }
141 : :
142 : :
143 : :
144 : :
145 : 0 : void SubToolPanel::RequestResize (void)
146 : : {
147 : 0 : mbIsRearrangePending = true;
148 : 0 : mbIsLayoutPending = true;
149 : 0 : Invalidate();
150 : 0 : }
151 : :
152 : :
153 : :
154 : :
155 : 0 : Size SubToolPanel::GetPreferredSize (void)
156 : : {
157 : 0 : return GetRequiredSize();
158 : : }
159 : :
160 : :
161 : :
162 : :
163 : 0 : sal_Int32 SubToolPanel::GetPreferredWidth (sal_Int32 )
164 : : {
165 : 0 : return GetPreferredSize().Width();
166 : : }
167 : :
168 : :
169 : :
170 : :
171 : 0 : sal_Int32 SubToolPanel::GetPreferredHeight (sal_Int32 )
172 : : {
173 : 0 : return GetPreferredSize().Height();
174 : : }
175 : :
176 : :
177 : :
178 : :
179 : 0 : bool SubToolPanel::IsResizable (void)
180 : : {
181 : 0 : return true;
182 : : }
183 : :
184 : :
185 : :
186 : :
187 : 0 : ::Window* SubToolPanel::GetWindow (void)
188 : : {
189 : 0 : return this;
190 : : }
191 : :
192 : :
193 : :
194 : :
195 : 0 : sal_Int32 SubToolPanel::GetMinimumWidth (void)
196 : : {
197 : 0 : return TreeNode::GetMinimumWidth();
198 : : }
199 : :
200 : :
201 : :
202 : :
203 : 0 : void SubToolPanel::ExpandControl (
204 : : TreeNode* pControl,
205 : : bool bExpansionState)
206 : : {
207 : : // Toggle expand status.
208 : 0 : pControl->Expand (bExpansionState);
209 : :
210 : 0 : Rearrange ();
211 : 0 : Invalidate ();
212 : 0 : }
213 : :
214 : :
215 : :
216 : :
217 : : /** This control shows an expansion bar for every control and in a
218 : : separate area below that expansion area it shows all controls each
219 : : with its title bar. When there is not enough space then show a
220 : : scroll bar in the control area.
221 : : */
222 : 0 : void SubToolPanel::Rearrange (void)
223 : : {
224 [ # # ]: 0 : Size aRequiredSize (GetRequiredSize());
225 [ # # ][ # # ]: 0 : if (aRequiredSize.Width()>0 && aRequiredSize.Height()>0)
[ # # ]
226 : : {
227 : 0 : Size aAvailableSize (GetOutputSizePixel());
228 : :
229 : : // Make the children at least as wide as the sub tool panel.
230 [ # # ]: 0 : if (aRequiredSize.Width() < aAvailableSize.Width())
231 : 0 : aRequiredSize.Width() = aAvailableSize.Width();
232 : 0 : mnChildrenWidth = -2*mnHorizontalBorder;
233 : 0 : mnChildrenWidth += aAvailableSize.Width();
234 : :
235 [ # # ]: 0 : LayoutChildren();
236 : :
237 : 0 : mbIsRearrangePending = false;
238 : : }
239 : 0 : }
240 : :
241 : :
242 : :
243 : :
244 : 0 : Size SubToolPanel::GetRequiredSize (void)
245 : : {
246 : : // First determine the width of the children. This is the maximum of
247 : : // the current window width and the individual minimum widths of the
248 : : // children.
249 : 0 : int nChildrenWidth (GetSizePixel().Width());
250 : 0 : unsigned int nCount = mpControlContainer->GetControlCount();
251 : : unsigned int nIndex;
252 [ # # ]: 0 : for (nIndex=0; nIndex<nCount; nIndex++)
253 : : {
254 : 0 : TreeNode* pChild = mpControlContainer->GetControl (nIndex);
255 : 0 : int nMinimumWidth (pChild->GetMinimumWidth());
256 [ # # ]: 0 : if (nMinimumWidth > nChildrenWidth)
257 : 0 : nChildrenWidth = nMinimumWidth;
258 : : }
259 : :
260 : : // Determine the accumulated width of all children when scaled to the
261 : : // minimum width.
262 : 0 : nChildrenWidth -= 2*mnHorizontalBorder;
263 : : Size aTotalSize (nChildrenWidth,
264 : 0 : 2*mnVerticalBorder + (nCount-1) * mnVerticalGap);
265 [ # # ]: 0 : for (nIndex=0; nIndex<nCount; nIndex++)
266 : : {
267 : 0 : TreeNode* pChild = mpControlContainer->GetControl (nIndex);
268 : 0 : sal_Int32 nHeight = pChild->GetPreferredHeight(nChildrenWidth);
269 : 0 : aTotalSize.Height() += nHeight;
270 : : }
271 : :
272 : 0 : return aTotalSize;
273 : : }
274 : :
275 : :
276 : :
277 : :
278 : 0 : sal_Int32 SubToolPanel::LayoutChildren (void)
279 : : {
280 : : // Determine vertical space that can be distributed to sizable children.
281 [ # # ]: 0 : unsigned int nCount (mpControlContainer->GetControlCount());
282 : 0 : unsigned int nResizableCount = 0;
283 [ # # ]: 0 : int nAvailableHeight = GetSizePixel().Height() - 2*mnVerticalBorder;
284 : : unsigned int nIndex;
285 [ # # ]: 0 : for (nIndex=0; nIndex<nCount; nIndex++)
286 : : {
287 [ # # ]: 0 : TreeNode* pChild = mpControlContainer->GetControl (nIndex);
288 [ # # ]: 0 : int nControlHeight = pChild->GetPreferredHeight(mnChildrenWidth);
289 [ # # ][ # # ]: 0 : if (pChild->IsResizable())
290 : 0 : nResizableCount++;
291 : : else
292 : 0 : nAvailableHeight -= nControlHeight;
293 : : }
294 : :
295 : 0 : maStripeList.clear();
296 : :
297 : 0 : Point aPosition (0,0);
298 : 0 : aPosition.X() += mnHorizontalBorder;
299 : : maStripeList.push_back( ::std::pair<int,int>(
300 : 0 : aPosition.Y(),
301 [ # # ][ # # ]: 0 : aPosition.Y() + mnVerticalBorder - 1));
302 : 0 : aPosition.Y() += mnVerticalBorder;
303 : :
304 : : // Place the controls one over the other.
305 [ # # ]: 0 : for (nIndex=0; nIndex<nCount; nIndex++)
306 : : {
307 [ # # ]: 0 : if (nIndex > 0)
308 : : {
309 : : maStripeList.push_back( ::std::pair<int,int>(
310 : 0 : aPosition.Y(),
311 [ # # ][ # # ]: 0 : aPosition.Y() + mnVerticalGap - 1));
312 : 0 : aPosition.Y() += mnVerticalGap;
313 : : }
314 [ # # ]: 0 : TreeNode* pChild = mpControlContainer->GetControl (nIndex);
315 [ # # ]: 0 : int nControlHeight = pChild->GetPreferredHeight(mnChildrenWidth);
316 [ # # ][ # # ]: 0 : if (pChild->IsResizable())
317 : : {
318 : 0 : nControlHeight = nAvailableHeight / nResizableCount;
319 : 0 : nResizableCount--;
320 : : }
321 : 0 : nAvailableHeight -= nControlHeight;
322 [ # # ]: 0 : pChild->GetWindow()->SetPosSizePixel(
323 : : aPosition,
324 [ # # ]: 0 : Size(mnChildrenWidth, nControlHeight));
325 : 0 : aPosition.Y() += nControlHeight;
326 : : }
327 : :
328 : : // If the children do not cover their parent window completely
329 : : // (regarding the height) we put a filler below that is responsible for
330 : : // painting the remaining space.
331 [ # # ]: 0 : int nWindowHeight = GetSizePixel().Height();
332 [ # # ]: 0 : if (aPosition.Y() < nWindowHeight)
333 : : {
334 : : maWindowFiller.SetPosSizePixel (
335 : : aPosition,
336 [ # # ]: 0 : Size(mnChildrenWidth, nWindowHeight-aPosition.Y()));
337 : : maStripeList.push_back( ::std::pair<int,int>(
338 : 0 : aPosition.Y(),
339 [ # # ][ # # ]: 0 : nWindowHeight-1));
340 : : // maScrollWindowFiller.Show();
341 : 0 : aPosition.Y() = nWindowHeight;
342 : : }
343 : : else
344 [ # # ]: 0 : maWindowFiller.Hide();
345 : :
346 : 0 : aPosition.Y() += mnVerticalBorder;
347 : 0 : mbIsLayoutPending = false;
348 : :
349 : 0 : return aPosition.Y();
350 : : }
351 : :
352 : :
353 : :
354 : :
355 : 0 : IMPL_LINK(SubToolPanel, WindowEventListener, VclSimpleEvent*, pEvent)
356 : : {
357 [ # # ][ # # ]: 0 : if (pEvent!=NULL && pEvent->ISA(VclWindowEvent))
[ # # ]
358 : : {
359 : 0 : VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent);
360 [ # # ]: 0 : switch (pWindowEvent->GetId())
361 : : {
362 : : case VCLEVENT_WINDOW_SHOW:
363 : : case VCLEVENT_WINDOW_HIDE:
364 : : case VCLEVENT_WINDOW_ACTIVATE:
365 : : case VCLEVENT_WINDOW_RESIZE:
366 : 0 : RequestResize();
367 : 0 : break;
368 : : }
369 : : }
370 : 0 : return 0;
371 : : }
372 : :
373 : :
374 : :
375 : :
376 : : ::com::sun::star::uno::Reference<
377 : 0 : ::com::sun::star::accessibility::XAccessible> SubToolPanel::CreateAccessibleObject (
378 : : const ::com::sun::star::uno::Reference<
379 : : ::com::sun::star::accessibility::XAccessible>& )
380 : : {
381 : : return new ::accessibility::AccessibleTreeNode (
382 : : *this,
383 : : "Sub Task Panel",
384 : : "Sub Task Panel",
385 [ # # ][ # # ]: 0 : ::com::sun::star::accessibility::AccessibleRole::PANEL);
[ # # ]
386 : : }
387 : :
388 : : } } // end of namespace ::sd::toolpanel
389 : :
390 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|