xref: /aoo42x/main/sfx2/source/sidebar/Deck.cxx (revision 7a32b0c8)
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),
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->Show();
72     mpScrollClipWindow->SetBackground(Wallpaper());
73     mpScrollContainer->Show();
74     mpScrollContainer->SetBackground(Wallpaper());
75 
76     mpVerticalScrollBar->SetScrollHdl(LINK(this, Deck, HandleVerticalScrollBarChange));
77 
78 #ifdef DEBUG
79     OSL_TRACE("creating Deck at %x", this);
80     SetText(A2S("Deck"));
81     mpScrollClipWindow->SetText(A2S("ScrollClipWindow"));
82     mpFiller->SetText(A2S("Filler"));
83     mpVerticalScrollBar->SetText(A2S("VerticalScrollBar"));
84 #endif
85 }
86 
87 
88 
89 
90 Deck::~Deck (void)
91 {
92     OSL_TRACE("destroying Deck at %x", this);
93     Dispose();
94 }
95 
96 
97 
98 
99 void Deck::Dispose (void)
100 {
101     PanelContainer aPanels;
102     aPanels.swap(maPanels);
103     for (PanelContainer::const_iterator
104              iPanel(aPanels.begin()),
105              iEnd(aPanels.end());
106          iPanel!=iEnd;
107          ++iPanel)
108     {
109 		if (*iPanel != NULL)
110 			(*iPanel)->Dispose();
111     }
112 
113     mpTitleBar.reset();
114     mpFiller.reset();
115     mpVerticalScrollBar.reset();
116 }
117 
118 
119 
120 
121 const ::rtl::OUString& Deck::GetId (void) const
122 {
123     return msId;
124 }
125 
126 
127 
128 
129 DeckTitleBar* Deck::GetTitleBar (void) const
130 {
131     return mpTitleBar.get();
132 }
133 
134 
135 
136 
137 Rectangle Deck::GetContentArea (void) const
138 {
139     const Size aWindowSize (GetSizePixel());
140     const int nBorderSize (Theme::GetInteger(Theme::Int_DeckBorderSize));
141 
142     return Rectangle(
143         Theme::GetInteger(Theme::Int_DeckLeftPadding) + nBorderSize,
144         Theme::GetInteger(Theme::Int_DeckTopPadding) + nBorderSize,
145         aWindowSize.Width() - 1 - Theme::GetInteger(Theme::Int_DeckRightPadding) - nBorderSize,
146         aWindowSize.Height() - 1 - Theme::GetInteger(Theme::Int_DeckBottomPadding) - nBorderSize);
147 }
148 
149 
150 
151 
152 ::rtl::OUString Deck::GetIconURL (const bool bIsHighContrastModeActive) const
153 {
154     if (bIsHighContrastModeActive)
155         return msHighContrastIconURL;
156     else
157         return msIconURL;
158 }
159 
160 
161 
162 
163 void Deck::Paint (const Rectangle& rUpdateArea)
164 {
165     (void) rUpdateArea;
166 
167     const Size aWindowSize (GetSizePixel());
168     const SvBorder aPadding (
169             Theme::GetInteger(Theme::Int_DeckLeftPadding),
170             Theme::GetInteger(Theme::Int_DeckTopPadding),
171             Theme::GetInteger(Theme::Int_DeckRightPadding),
172             Theme::GetInteger(Theme::Int_DeckBottomPadding));
173 
174     // Paint deck background outside the border.
175     Rectangle aBox(
176         0,
177         0,
178         aWindowSize.Width() - 1,
179         aWindowSize.Height() - 1);
180     DrawHelper::DrawBorder(
181         *this,
182         aBox,
183         aPadding,
184         Theme::GetPaint(Theme::Paint_DeckBackground),
185         Theme::GetPaint(Theme::Paint_DeckBackground));
186 
187     // Paint the border.
188     const int nBorderSize (Theme::GetInteger(Theme::Int_DeckBorderSize));
189     aBox.Left() += aPadding.Left();
190     aBox.Top() += aPadding.Top();
191     aBox.Right() -= aPadding.Right();
192     aBox.Bottom() -= aPadding.Bottom();
193     const sfx2::sidebar::Paint& rHorizontalBorderPaint (Theme::GetPaint(Theme::Paint_HorizontalBorder));
194     DrawHelper::DrawBorder(
195         *this,
196         aBox,
197         SvBorder(nBorderSize, nBorderSize, nBorderSize, nBorderSize),
198         rHorizontalBorderPaint,
199         Theme::GetPaint(Theme::Paint_VerticalBorder));
200 }
201 
202 
203 
204 
205 void Deck::DataChanged (const DataChangedEvent& rEvent)
206 {
207     (void)rEvent;
208     RequestLayout();
209 }
210 
211 
212 
213 
214 void Deck::SetPanels (const ::std::vector<Panel*>& rPanels)
215 {
216     maPanels.clear();
217     maPanels.reserve(rPanels.size());
218     for (::std::vector<Panel*>::const_iterator iPanel(rPanels.begin()),iEnd(rPanels.end());
219          iPanel!=iEnd;
220          ++iPanel)
221     {
222         maPanels.push_back(*iPanel);
223     }
224 
225     RequestLayout();
226 }
227 
228 
229 
230 
231 void Deck::RequestLayout (void)
232 {
233     PrintWindowTree();
234 
235     DeckLayouter::LayoutDeck(
236         GetContentArea(),
237         maPanels,
238         *GetTitleBar(),
239         *mpScrollClipWindow,
240         *mpScrollContainer,
241         *mpFiller,
242         *mpVerticalScrollBar);
243 
244     Invalidate();
245 }
246 
247 
248 
249 
250 ::Window* Deck::GetPanelParentWindow (void)
251 {
252     return mpScrollContainer.get();
253 }
254 
255 
256 
257 
258 const char* GetWindowClassification (const Window* pWindow)
259 {
260     const String& rsName (pWindow->GetText());
261     if (rsName.Len() > 0)
262     {
263         return ::rtl::OUStringToOString(rsName, RTL_TEXTENCODING_ASCII_US).getStr();
264     }
265     else
266     {
267         static char msWindow[] = "window";
268         return msWindow;
269     }
270 }
271 
272 
273 void Deck::PrintWindowSubTree (Window* pRoot, int nIndentation)
274 {
275     static char* sIndentation = "                                                                  ";
276     const Point aLocation (pRoot->GetPosPixel());
277     const Size aSize (pRoot->GetSizePixel());
278     const char* sClassification = GetWindowClassification(pRoot);
279     const char* sVisible = pRoot->IsVisible() ? "visible" : "hidden";
280     OSL_TRACE("%s%x %s %s +%d+%d x%dx%d",
281         sIndentation+strlen(sIndentation)-nIndentation*4,
282         pRoot,
283         sClassification,
284         sVisible,
285         aLocation.X(),aLocation.Y(),
286         aSize.Width(),aSize.Height());
287 
288     const sal_uInt16 nChildCount (pRoot->GetChildCount());
289     for (sal_uInt16 nIndex=0; nIndex<nChildCount; ++nIndex)
290         PrintWindowSubTree(pRoot->GetChild(nIndex), nIndentation+1);
291 }
292 
293 
294 
295 
296 void Deck::PrintWindowTree (void)
297 {
298     PrintWindowSubTree(this, 0);
299 }
300 
301 
302 
303 
304 void Deck::PrintWindowTree (const ::std::vector<Panel*>& rPanels)
305 {
306     (void)rPanels;
307 
308     PrintWindowTree();
309 }
310 
311 
312 
313 
314 IMPL_LINK(Deck, HandleVerticalScrollBarChange,void*, EMPTYARG)
315 {
316     const sal_Int32 nYOffset (-mpVerticalScrollBar->GetThumbPos());
317     mpScrollContainer->SetPosPixel(
318         Point(
319             mpScrollContainer->GetPosPixel().X(),
320             nYOffset));
321     return sal_True;
322 }
323 
324 
325 
326 
327 //----- Deck::ScrollContainerWindow -------------------------------------------
328 
329 Deck::ScrollContainerWindow::ScrollContainerWindow (Window* pParentWindow)
330     : Window(pParentWindow),
331       maSeparators()
332 {
333 #ifdef DEBUG
334     SetText(A2S("ScrollContainerWindow"));
335 #endif
336 }
337 
338 
339 
340 
341 Deck::ScrollContainerWindow::~ScrollContainerWindow (void)
342 {
343 }
344 
345 
346 
347 
348 void Deck::ScrollContainerWindow::Paint (const Rectangle& rUpdateArea)
349 {
350     (void)rUpdateArea;
351 
352     // Paint the separators.
353     const sal_Int32 nSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight));
354     const sal_Int32 nLeft  (0);
355     const sal_Int32 nRight (GetSizePixel().Width()-1);
356     const sfx2::sidebar::Paint& rHorizontalBorderPaint (Theme::GetPaint(Theme::Paint_HorizontalBorder));
357     for (::std::vector<sal_Int32>::const_iterator iY(maSeparators.begin()), iEnd(maSeparators.end());
358          iY!=iEnd;
359          ++iY)
360     {
361         DrawHelper::DrawHorizontalLine(
362             *this,
363             nLeft,
364             nRight,
365             *iY,
366             nSeparatorHeight,
367             rHorizontalBorderPaint);
368     }
369 }
370 
371 
372 
373 
374 void Deck::ScrollContainerWindow::SetSeparators (const ::std::vector<sal_Int32>& rSeparators)
375 {
376     maSeparators = rSeparators;
377 }
378 
379 } } // end of namespace sfx2::sidebar
380