xref: /aoo42x/main/sfx2/source/sidebar/Deck.cxx (revision 45da7d5e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "precompiled_sfx2.hxx"
23 
24 #include "Deck.hxx"
25 #include "DeckDescriptor.hxx"
26 #include "DeckLayouter.hxx"
27 #include "DrawHelper.hxx"
28 #include "DeckTitleBar.hxx"
29 #include "Paint.hxx"
30 #include "Panel.hxx"
31 #include "ToolBoxBackground.hxx"
32 #include "Tools.hxx"
33 #include "sfx2/sidebar/Theme.hxx"
34 
35 #include <vcl/dockwin.hxx>
36 #include <vcl/scrbar.hxx>
37 #include <tools/svborder.hxx>
38 
39 #include <boost/bind.hpp>
40 
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 
44 
45 namespace sfx2 { namespace sidebar {
46 
47 
48 namespace {
49     static const sal_Int32 MinimalPanelHeight (25);
50 }
51 
52 
53 Deck::Deck (
54     const DeckDescriptor& rDeckDescriptor,
55     Window* pParentWindow,
56     const ::boost::function<void(void)>& rCloserAction)
57     : Window(pParentWindow, 0),
58       msId(rDeckDescriptor.msId),
59       maIcon(),
60       msIconURL(rDeckDescriptor.msIconURL),
61       msHighContrastIconURL(rDeckDescriptor.msHighContrastIconURL),
62       maPanels(),
63       mpTitleBar(new DeckTitleBar(rDeckDescriptor.msTitle, this, rCloserAction)),
64       mpScrollClipWindow(new Window(this)),
65       mpScrollContainer(new ScrollContainerWindow(mpScrollClipWindow.get())),
66       mpFiller(new Window(this)),
67       mpVerticalScrollBar(new ScrollBar(this))
68 {
69     SetBackground(Wallpaper());
70 
71     mpScrollClipWindow->SetBackground(Wallpaper());
72     mpScrollClipWindow->Show();
73 
74     mpScrollContainer->SetStyle(mpScrollContainer->GetStyle() | WB_DIALOGCONTROL);
75     mpScrollContainer->SetBackground(Wallpaper());
76     mpScrollContainer->Show();
77 
78     mpVerticalScrollBar->SetScrollHdl(LINK(this, Deck, HandleVerticalScrollBarChange));
79 
80 #ifdef DEBUG
81     SetText(A2S("Deck"));
82     mpScrollClipWindow->SetText(A2S("ScrollClipWindow"));
83     mpFiller->SetText(A2S("Filler"));
84     mpVerticalScrollBar->SetText(A2S("VerticalScrollBar"));
85 #endif
86 }
87 
88 
89 
90 
91 Deck::~Deck (void)
92 {
93     Dispose();
94 
95     // We have to explicitly trigger the destruction of panels.
96     // Otherwise that is done by one of our base class destructors
97     // without updating maPanels.
98     maPanels.clear();
99 }
100 
101 
102 
103 
104 void Deck::Dispose (void)
105 {
106     SharedPanelContainer aPanels;
107     aPanels.swap(maPanels);
108     for (SharedPanelContainer::iterator
109              iPanel(aPanels.begin()),
110              iEnd(aPanels.end());
111          iPanel!=iEnd;
112          ++iPanel)
113     {
114 		if (*iPanel)
115         {
116 			(*iPanel)->Dispose();
117             OSL_ASSERT(iPanel->unique());
118             iPanel->reset();
119         }
120     }
121 
122     mpTitleBar.reset();
123     mpFiller.reset();
124     mpVerticalScrollBar.reset();
125 }
126 
127 
128 
129 
130 const ::rtl::OUString& Deck::GetId (void) const
131 {
132     return msId;
133 }
134 
135 
136 
137 
138 DeckTitleBar* Deck::GetTitleBar (void) const
139 {
140     return mpTitleBar.get();
141 }
142 
143 
144 
145 
146 Rectangle Deck::GetContentArea (void) const
147 {
148     const Size aWindowSize (GetSizePixel());
149     const int nBorderSize (Theme::GetInteger(Theme::Int_DeckBorderSize));
150 
151     return Rectangle(
152         Theme::GetInteger(Theme::Int_DeckLeftPadding) + nBorderSize,
153         Theme::GetInteger(Theme::Int_DeckTopPadding) + nBorderSize,
154         aWindowSize.Width() - 1 - Theme::GetInteger(Theme::Int_DeckRightPadding) - nBorderSize,
155         aWindowSize.Height() - 1 - Theme::GetInteger(Theme::Int_DeckBottomPadding) - nBorderSize);
156 }
157 
158 
159 
160 
161 ::rtl::OUString Deck::GetIconURL (const bool bIsHighContrastModeActive) const
162 {
163     if (bIsHighContrastModeActive)
164         return msHighContrastIconURL;
165     else
166         return msIconURL;
167 }
168 
169 
170 
171 
172 void Deck::Paint (const Rectangle& rUpdateArea)
173 {
174     (void) rUpdateArea;
175 
176     const Size aWindowSize (GetSizePixel());
177     const SvBorder aPadding (
178             Theme::GetInteger(Theme::Int_DeckLeftPadding),
179             Theme::GetInteger(Theme::Int_DeckTopPadding),
180             Theme::GetInteger(Theme::Int_DeckRightPadding),
181             Theme::GetInteger(Theme::Int_DeckBottomPadding));
182 
183     // Paint deck background outside the border.
184     Rectangle aBox(
185         0,
186         0,
187         aWindowSize.Width() - 1,
188         aWindowSize.Height() - 1);
189     DrawHelper::DrawBorder(
190         *this,
191         aBox,
192         aPadding,
193         Theme::GetPaint(Theme::Paint_DeckBackground),
194         Theme::GetPaint(Theme::Paint_DeckBackground));
195 
196     // Paint the border.
197     const int nBorderSize (Theme::GetInteger(Theme::Int_DeckBorderSize));
198     aBox.Left() += aPadding.Left();
199     aBox.Top() += aPadding.Top();
200     aBox.Right() -= aPadding.Right();
201     aBox.Bottom() -= aPadding.Bottom();
202     const sfx2::sidebar::Paint& rHorizontalBorderPaint (Theme::GetPaint(Theme::Paint_HorizontalBorder));
203     DrawHelper::DrawBorder(
204         *this,
205         aBox,
206         SvBorder(nBorderSize, nBorderSize, nBorderSize, nBorderSize),
207         rHorizontalBorderPaint,
208         Theme::GetPaint(Theme::Paint_VerticalBorder));
209 }
210 
211 
212 
213 
214 void Deck::DataChanged (const DataChangedEvent& rEvent)
215 {
216     (void)rEvent;
217     RequestLayout();
218 }
219 
220 
221 
222 
223 void Deck::SetPanels (const SharedPanelContainer& rPanels)
224 {
225     maPanels = rPanels;
226 
227     RequestLayout();
228 }
229 
230 
231 
232 
233 const SharedPanelContainer& Deck::GetPanels (void) const
234 {
235     return maPanels;
236 }
237 
238 
239 
240 
241 void Deck::RequestLayout (void)
242 {
243     //    PrintWindowTree();
244 
245     DeckLayouter::LayoutDeck(
246         GetContentArea(),
247         maPanels,
248         *GetTitleBar(),
249         *mpScrollClipWindow,
250         *mpScrollContainer,
251         *mpFiller,
252         *mpVerticalScrollBar);
253 
254     Invalidate();
255 }
256 
257 
258 
259 
260 ::Window* Deck::GetPanelParentWindow (void)
261 {
262     return mpScrollContainer.get();
263 }
264 
265 
266 
267 
268 const char* GetWindowClassification (const Window* pWindow)
269 {
270     const String& rsName (pWindow->GetText());
271     if (rsName.Len() > 0)
272     {
273         return ::rtl::OUStringToOString(rsName, RTL_TEXTENCODING_ASCII_US).getStr();
274     }
275     else
276     {
277         static char msWindow[] = "window";
278         return msWindow;
279     }
280 }
281 
282 
283 void Deck::PrintWindowSubTree (Window* pRoot, int nIndentation)
284 {
285     static const char* sIndentation = "                                                                  ";
286     const Point aLocation (pRoot->GetPosPixel());
287     const Size aSize (pRoot->GetSizePixel());
288     const char* sClassification = GetWindowClassification(pRoot);
289     const char* sVisible = pRoot->IsVisible() ? "visible" : "hidden";
290     OSL_TRACE("%s%x %s %s +%d+%d x%dx%d",
291         sIndentation+strlen(sIndentation)-nIndentation*4,
292         pRoot,
293         sClassification,
294         sVisible,
295         aLocation.X(),aLocation.Y(),
296         aSize.Width(),aSize.Height());
297 
298     const sal_uInt16 nChildCount (pRoot->GetChildCount());
299     for (sal_uInt16 nIndex=0; nIndex<nChildCount; ++nIndex)
300         PrintWindowSubTree(pRoot->GetChild(nIndex), nIndentation+1);
301 }
302 
303 
304 
305 
306 void Deck::PrintWindowTree (void)
307 {
308     PrintWindowSubTree(this, 0);
309 }
310 
311 
312 
313 
314 void Deck::PrintWindowTree (const ::std::vector<Panel*>& rPanels)
315 {
316     (void)rPanels;
317 
318     PrintWindowTree();
319 }
320 
321 
322 
323 
324 IMPL_LINK(Deck, HandleVerticalScrollBarChange,void*, EMPTYARG)
325 {
326     const sal_Int32 nYOffset (-mpVerticalScrollBar->GetThumbPos());
327     mpScrollContainer->SetPosPixel(
328         Point(
329             mpScrollContainer->GetPosPixel().X(),
330             nYOffset));
331     return sal_True;
332 }
333 
334 
335 
336 
337 //----- Deck::ScrollContainerWindow -------------------------------------------
338 
339 Deck::ScrollContainerWindow::ScrollContainerWindow (Window* pParentWindow)
340     : Window(pParentWindow),
341       maSeparators()
342 {
343 #ifdef DEBUG
344     SetText(A2S("ScrollContainerWindow"));
345 #endif
346 }
347 
348 
349 
350 
351 Deck::ScrollContainerWindow::~ScrollContainerWindow (void)
352 {
353 }
354 
355 
356 
357 
358 void Deck::ScrollContainerWindow::Paint (const Rectangle& rUpdateArea)
359 {
360     (void)rUpdateArea;
361 
362     // Paint the separators.
363     const sal_Int32 nSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight));
364     const sal_Int32 nLeft  (0);
365     const sal_Int32 nRight (GetSizePixel().Width()-1);
366     const sfx2::sidebar::Paint& rHorizontalBorderPaint (Theme::GetPaint(Theme::Paint_HorizontalBorder));
367     for (::std::vector<sal_Int32>::const_iterator iY(maSeparators.begin()), iEnd(maSeparators.end());
368          iY!=iEnd;
369          ++iY)
370     {
371         DrawHelper::DrawHorizontalLine(
372             *this,
373             nLeft,
374             nRight,
375             *iY,
376             nSeparatorHeight,
377             rHorizontalBorderPaint);
378     }
379 }
380 
381 
382 
383 
384 void Deck::ScrollContainerWindow::SetSeparators (const ::std::vector<sal_Int32>& rSeparators)
385 {
386     maSeparators = rSeparators;
387 }
388 
389 } } // end of namespace sfx2::sidebar
390