xref: /trunk/main/sfx2/source/sidebar/Deck.cxx (revision 52d13b84)
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 "sfx2/sidebar/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 void Deck::ShowPanel (const Panel& rPanel)
269 {
270     if (mpVerticalScrollBar && mpVerticalScrollBar->IsVisible())
271     {
272         // Get vertical extent of the panel.
273         sal_Int32 nPanelTop (rPanel.GetPosPixel().Y());
274         const sal_Int32 nPanelBottom (nPanelTop + rPanel.GetSizePixel().Height() - 1);
275         // Add the title bar into the extent.
276         if (rPanel.GetTitleBar() != NULL && rPanel.GetTitleBar()->IsVisible())
277             nPanelTop = rPanel.GetTitleBar()->GetPosPixel().Y();
278 
279 
280         // Determine what the new thumb position should be like.
281         // When the whole panel does not fit then make its top visible
282         // and it off at the bottom.
283         sal_Int32 nNewThumbPos (mpVerticalScrollBar->GetThumbPos());
284         if (nPanelBottom >= nNewThumbPos+mpVerticalScrollBar->GetVisibleSize())
285             nNewThumbPos = nPanelBottom - mpVerticalScrollBar->GetVisibleSize();
286         if (nPanelTop < nNewThumbPos)
287             nNewThumbPos = nPanelTop;
288 
289         mpVerticalScrollBar->SetThumbPos(nNewThumbPos);
290         mpScrollContainer->SetPosPixel(
291             Point(
292                 mpScrollContainer->GetPosPixel().X(),
293                 -nNewThumbPos));
294 
295     }
296 }
297 
298 
299 
300 
301 const char* GetWindowClassification (const Window* pWindow)
302 {
303     const String& rsName (pWindow->GetText());
304     if (rsName.Len() > 0)
305     {
306         return ::rtl::OUStringToOString(rsName, RTL_TEXTENCODING_ASCII_US).getStr();
307     }
308     else
309     {
310         static char msWindow[] = "window";
311         return msWindow;
312     }
313 }
314 
315 
316 void Deck::PrintWindowSubTree (Window* pRoot, int nIndentation)
317 {
318     static const char* sIndentation = "                                                                  ";
319     const Point aLocation (pRoot->GetPosPixel());
320     const Size aSize (pRoot->GetSizePixel());
321     const char* sClassification = GetWindowClassification(pRoot);
322     const char* sVisible = pRoot->IsVisible() ? "visible" : "hidden";
323     OSL_TRACE("%s%x %s %s +%d+%d x%dx%d",
324         sIndentation+strlen(sIndentation)-nIndentation*4,
325         pRoot,
326         sClassification,
327         sVisible,
328         aLocation.X(),aLocation.Y(),
329         aSize.Width(),aSize.Height());
330 
331     const sal_uInt16 nChildCount (pRoot->GetChildCount());
332     for (sal_uInt16 nIndex=0; nIndex<nChildCount; ++nIndex)
333         PrintWindowSubTree(pRoot->GetChild(nIndex), nIndentation+1);
334 }
335 
336 
337 
338 
339 void Deck::PrintWindowTree (void)
340 {
341     PrintWindowSubTree(this, 0);
342 }
343 
344 
345 
346 
347 void Deck::PrintWindowTree (const ::std::vector<Panel*>& rPanels)
348 {
349     (void)rPanels;
350 
351     PrintWindowTree();
352 }
353 
354 
355 
356 
357 IMPL_LINK(Deck, HandleVerticalScrollBarChange,void*, EMPTYARG)
358 {
359     const sal_Int32 nYOffset (-mpVerticalScrollBar->GetThumbPos());
360     mpScrollContainer->SetPosPixel(
361         Point(
362             mpScrollContainer->GetPosPixel().X(),
363             nYOffset));
364     return sal_True;
365 }
366 
367 
368 
369 
370 //----- Deck::ScrollContainerWindow -------------------------------------------
371 
372 Deck::ScrollContainerWindow::ScrollContainerWindow (Window* pParentWindow)
373     : Window(pParentWindow),
374       maSeparators()
375 {
376 #ifdef DEBUG
377     SetText(A2S("ScrollContainerWindow"));
378 #endif
379 }
380 
381 
382 
383 
384 Deck::ScrollContainerWindow::~ScrollContainerWindow (void)
385 {
386 }
387 
388 
389 
390 
391 void Deck::ScrollContainerWindow::Paint (const Rectangle& rUpdateArea)
392 {
393     (void)rUpdateArea;
394 
395     // Paint the separators.
396     const sal_Int32 nSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight));
397     const sal_Int32 nLeft  (0);
398     const sal_Int32 nRight (GetSizePixel().Width()-1);
399     const sfx2::sidebar::Paint& rHorizontalBorderPaint (Theme::GetPaint(Theme::Paint_HorizontalBorder));
400     for (::std::vector<sal_Int32>::const_iterator iY(maSeparators.begin()), iEnd(maSeparators.end());
401          iY!=iEnd;
402          ++iY)
403     {
404         DrawHelper::DrawHorizontalLine(
405             *this,
406             nLeft,
407             nRight,
408             *iY,
409             nSeparatorHeight,
410             rHorizontalBorderPaint);
411     }
412 }
413 
414 
415 
416 
417 void Deck::ScrollContainerWindow::SetSeparators (const ::std::vector<sal_Int32>& rSeparators)
418 {
419     maSeparators = rSeparators;
420 }
421 
422 } } // end of namespace sfx2::sidebar
423