xref: /aoo42x/main/sfx2/source/sidebar/Deck.cxx (revision 8a1a651a)
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 "PanelTitleBar.hxx"
30 #include "Paint.hxx"
31 #include "Panel.hxx"
32 #include "ToolBoxBackground.hxx"
33 #include "sfx2/sidebar/Tools.hxx"
34 #include "sfx2/sidebar/Theme.hxx"
35 
36 #include <vcl/dockwin.hxx>
37 #include <vcl/scrbar.hxx>
38 #include <tools/svborder.hxx>
39 
40 #include <boost/bind.hpp>
41 
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 
45 
46 namespace sfx2 { namespace sidebar {
47 
48 
49 namespace {
50     static const sal_Int32 MinimalPanelHeight (25);
51 }
52 
53 
54 Deck::Deck (
55     const DeckDescriptor& rDeckDescriptor,
56     Window* pParentWindow,
57     const ::boost::function<void(void)>& rCloserAction)
58     : Window(pParentWindow, 0),
59       msId(rDeckDescriptor.msId),
60       maIcon(),
61       msIconURL(rDeckDescriptor.msIconURL),
62       msHighContrastIconURL(rDeckDescriptor.msHighContrastIconURL),
63       maPanels(),
64       mpTitleBar(new DeckTitleBar(rDeckDescriptor.msTitle, this, rCloserAction)),
65       mpScrollClipWindow(new Window(this)),
66       mpScrollContainer(new ScrollContainerWindow(mpScrollClipWindow.get())),
67       mpFiller(new Window(this)),
68       mpVerticalScrollBar(new ScrollBar(this))
69 {
70     SetBackground(Wallpaper());
71 
72     mpScrollClipWindow->SetBackground(Wallpaper());
73     mpScrollClipWindow->Show();
74 
75     mpScrollContainer->SetStyle(mpScrollContainer->GetStyle() | WB_DIALOGCONTROL);
76     mpScrollContainer->SetBackground(Wallpaper());
77     mpScrollContainer->Show();
78 
79     mpVerticalScrollBar->SetScrollHdl(LINK(this, Deck, HandleVerticalScrollBarChange));
80 
81 #ifdef DEBUG
82     SetText(A2S("Deck"));
83     mpScrollClipWindow->SetText(A2S("ScrollClipWindow"));
84     mpFiller->SetText(A2S("Filler"));
85     mpVerticalScrollBar->SetText(A2S("VerticalScrollBar"));
86 #endif
87 }
88 
89 
90 
91 
92 Deck::~Deck (void)
93 {
94     Dispose();
95 
96     // We have to explicitly trigger the destruction of panels.
97     // Otherwise that is done by one of our base class destructors
98     // without updating maPanels.
99     maPanels.clear();
100 }
101 
102 
103 
104 
105 void Deck::Dispose (void)
106 {
107     SharedPanelContainer aPanels;
108     aPanels.swap(maPanels);
109     for (SharedPanelContainer::iterator
110              iPanel(aPanels.begin()),
111              iEnd(aPanels.end());
112          iPanel!=iEnd;
113          ++iPanel)
114     {
115 		if (*iPanel)
116         {
117 			(*iPanel)->Dispose();
118             OSL_ASSERT(iPanel->unique());
119             iPanel->reset();
120         }
121     }
122 
123     mpTitleBar.reset();
124     mpFiller.reset();
125     mpVerticalScrollBar.reset();
126 }
127 
128 
129 
130 
131 const ::rtl::OUString& Deck::GetId (void) const
132 {
133     return msId;
134 }
135 
136 
137 
138 
139 DeckTitleBar* Deck::GetTitleBar (void) const
140 {
141     return mpTitleBar.get();
142 }
143 
144 
145 
146 
147 Rectangle Deck::GetContentArea (void) const
148 {
149     const Size aWindowSize (GetSizePixel());
150     const int nBorderSize (Theme::GetInteger(Theme::Int_DeckBorderSize));
151 
152     return Rectangle(
153         Theme::GetInteger(Theme::Int_DeckLeftPadding) + nBorderSize,
154         Theme::GetInteger(Theme::Int_DeckTopPadding) + nBorderSize,
155         aWindowSize.Width() - 1 - Theme::GetInteger(Theme::Int_DeckRightPadding) - nBorderSize,
156         aWindowSize.Height() - 1 - Theme::GetInteger(Theme::Int_DeckBottomPadding) - nBorderSize);
157 }
158 
159 
160 
161 
162 ::rtl::OUString Deck::GetIconURL (const bool bIsHighContrastModeActive) const
163 {
164     if (bIsHighContrastModeActive)
165         return msHighContrastIconURL;
166     else
167         return msIconURL;
168 }
169 
170 
171 
172 
173 void Deck::Paint (const Rectangle& rUpdateArea)
174 {
175     (void) rUpdateArea;
176 
177     const Size aWindowSize (GetSizePixel());
178     const SvBorder aPadding (
179             Theme::GetInteger(Theme::Int_DeckLeftPadding),
180             Theme::GetInteger(Theme::Int_DeckTopPadding),
181             Theme::GetInteger(Theme::Int_DeckRightPadding),
182             Theme::GetInteger(Theme::Int_DeckBottomPadding));
183 
184     // Paint deck background outside the border.
185     Rectangle aBox(
186         0,
187         0,
188         aWindowSize.Width() - 1,
189         aWindowSize.Height() - 1);
190     DrawHelper::DrawBorder(
191         *this,
192         aBox,
193         aPadding,
194         Theme::GetPaint(Theme::Paint_DeckBackground),
195         Theme::GetPaint(Theme::Paint_DeckBackground));
196 
197     // Paint the border.
198     const int nBorderSize (Theme::GetInteger(Theme::Int_DeckBorderSize));
199     aBox.Left() += aPadding.Left();
200     aBox.Top() += aPadding.Top();
201     aBox.Right() -= aPadding.Right();
202     aBox.Bottom() -= aPadding.Bottom();
203     const sfx2::sidebar::Paint& rHorizontalBorderPaint (Theme::GetPaint(Theme::Paint_HorizontalBorder));
204     DrawHelper::DrawBorder(
205         *this,
206         aBox,
207         SvBorder(nBorderSize, nBorderSize, nBorderSize, nBorderSize),
208         rHorizontalBorderPaint,
209         Theme::GetPaint(Theme::Paint_VerticalBorder));
210 }
211 
212 
213 
214 
215 void Deck::DataChanged (const DataChangedEvent& rEvent)
216 {
217     (void)rEvent;
218     RequestLayout();
219 }
220 
221 
222 
223 
224 long Deck::Notify (NotifyEvent& rEvent)
225 {
226     if (rEvent.GetType() == EVENT_COMMAND)
227     {
228         CommandEvent* pCommandEvent = reinterpret_cast<CommandEvent*>(rEvent.GetData());
229         if (pCommandEvent != NULL)
230             switch (pCommandEvent->GetCommand())
231             {
232                 case COMMAND_WHEEL:
233                     return ProcessWheelEvent(pCommandEvent, rEvent)
234                         ? sal_True
235                         : sal_False;
236 
237                 default:
238                     break;
239             }
240     }
241 
242     return Window::Notify(rEvent);
243 }
244 
245 
246 
247 
248 bool Deck::ProcessWheelEvent (
249     CommandEvent* pCommandEvent,
250     NotifyEvent& rEvent)
251 {
252     if ( ! mpVerticalScrollBar)
253         return false;
254     if ( ! mpVerticalScrollBar->IsVisible())
255         return false;
256 
257     // Ignore all wheel commands from outside the vertical scroll bar.
258     // Otherwise after a scroll we might land on a spin field and
259     // subsequent wheel events would change the value of that control.
260     if (rEvent.GetWindow() != mpVerticalScrollBar.get())
261         return true;
262 
263     // Get the wheel data and check that it describes a valid vertical
264     // scroll.
265     const CommandWheelData* pData = pCommandEvent->GetWheelData();
266     if (pData==NULL
267         || pData->GetModifier()
268         || pData->GetMode() != COMMAND_WHEEL_SCROLL
269         || pData->IsHorz())
270         return false;
271 
272     // Execute the actual scroll action.
273     long nDelta = pData->GetDelta();
274     mpVerticalScrollBar->DoScroll(
275         mpVerticalScrollBar->GetThumbPos() - nDelta);
276     return true;
277 }
278 
279 
280 
281 
282 void Deck::SetPanels (const SharedPanelContainer& rPanels)
283 {
284     maPanels = rPanels;
285 
286     RequestLayout();
287 }
288 
289 
290 
291 
292 const SharedPanelContainer& Deck::GetPanels (void) const
293 {
294     return maPanels;
295 }
296 
297 
298 
299 
300 void Deck::RequestLayout (void)
301 {
302     //    PrintWindowTree();
303 
304     DeckLayouter::LayoutDeck(
305         GetContentArea(),
306         maPanels,
307         *GetTitleBar(),
308         *mpScrollClipWindow,
309         *mpScrollContainer,
310         *mpFiller,
311         *mpVerticalScrollBar);
312 
313     Invalidate();
314 }
315 
316 
317 
318 
319 ::Window* Deck::GetPanelParentWindow (void)
320 {
321     return mpScrollContainer.get();
322 }
323 
324 
325 
326 
327 void Deck::ShowPanel (const Panel& rPanel)
328 {
329     if (mpVerticalScrollBar && mpVerticalScrollBar->IsVisible())
330     {
331         // Get vertical extent of the panel.
332         sal_Int32 nPanelTop (rPanel.GetPosPixel().Y());
333         const sal_Int32 nPanelBottom (nPanelTop + rPanel.GetSizePixel().Height() - 1);
334         // Add the title bar into the extent.
335         if (rPanel.GetTitleBar() != NULL && rPanel.GetTitleBar()->IsVisible())
336             nPanelTop = rPanel.GetTitleBar()->GetPosPixel().Y();
337 
338         // Determine what the new thumb position should be like.
339         // When the whole panel does not fit then make its top visible
340         // and it off at the bottom.
341         sal_Int32 nNewThumbPos (mpVerticalScrollBar->GetThumbPos());
342         if (nPanelBottom >= nNewThumbPos+mpVerticalScrollBar->GetVisibleSize())
343             nNewThumbPos = nPanelBottom - mpVerticalScrollBar->GetVisibleSize();
344         if (nPanelTop < nNewThumbPos)
345             nNewThumbPos = nPanelTop;
346 
347         mpVerticalScrollBar->SetThumbPos(nNewThumbPos);
348         mpScrollContainer->SetPosPixel(
349             Point(
350                 mpScrollContainer->GetPosPixel().X(),
351                 -nNewThumbPos));
352 
353     }
354 }
355 
356 
357 
358 
359 const char* GetWindowClassification (const Window* pWindow)
360 {
361     const String& rsName (pWindow->GetText());
362     if (rsName.Len() > 0)
363     {
364         return ::rtl::OUStringToOString(rsName, RTL_TEXTENCODING_ASCII_US).getStr();
365     }
366     else
367     {
368         static char msWindow[] = "window";
369         return msWindow;
370     }
371 }
372 
373 
374 void Deck::PrintWindowSubTree (Window* pRoot, int nIndentation)
375 {
376     static const char* sIndentation = "                                                                  ";
377     const Point aLocation (pRoot->GetPosPixel());
378     const Size aSize (pRoot->GetSizePixel());
379     const char* sClassification = GetWindowClassification(pRoot);
380     const char* sVisible = pRoot->IsVisible() ? "visible" : "hidden";
381     OSL_TRACE("%s%x %s %s +%d+%d x%dx%d",
382         sIndentation+strlen(sIndentation)-nIndentation*4,
383         pRoot,
384         sClassification,
385         sVisible,
386         aLocation.X(),aLocation.Y(),
387         aSize.Width(),aSize.Height());
388 
389     const sal_uInt16 nChildCount (pRoot->GetChildCount());
390     for (sal_uInt16 nIndex=0; nIndex<nChildCount; ++nIndex)
391         PrintWindowSubTree(pRoot->GetChild(nIndex), nIndentation+1);
392 }
393 
394 
395 
396 
397 void Deck::PrintWindowTree (void)
398 {
399     PrintWindowSubTree(this, 0);
400 }
401 
402 
403 
404 
405 void Deck::PrintWindowTree (const ::std::vector<Panel*>& rPanels)
406 {
407     (void)rPanels;
408 
409     PrintWindowTree();
410 }
411 
412 
413 
414 
415 IMPL_LINK(Deck, HandleVerticalScrollBarChange,void*, EMPTYARG)
416 {
417     const sal_Int32 nYOffset (-mpVerticalScrollBar->GetThumbPos());
418     mpScrollContainer->SetPosPixel(
419         Point(
420             mpScrollContainer->GetPosPixel().X(),
421             nYOffset));
422     return sal_True;
423 }
424 
425 
426 
427 
428 //----- Deck::ScrollContainerWindow -------------------------------------------
429 
430 Deck::ScrollContainerWindow::ScrollContainerWindow (Window* pParentWindow)
431     : Window(pParentWindow),
432       maSeparators()
433 {
434 #ifdef DEBUG
435     SetText(A2S("ScrollContainerWindow"));
436 #endif
437 }
438 
439 
440 
441 
442 Deck::ScrollContainerWindow::~ScrollContainerWindow (void)
443 {
444 }
445 
446 
447 
448 
449 void Deck::ScrollContainerWindow::Paint (const Rectangle& rUpdateArea)
450 {
451     (void)rUpdateArea;
452 
453     // Paint the separators.
454     const sal_Int32 nSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight));
455     const sal_Int32 nLeft  (0);
456     const sal_Int32 nRight (GetSizePixel().Width()-1);
457     const sfx2::sidebar::Paint& rHorizontalBorderPaint (Theme::GetPaint(Theme::Paint_HorizontalBorder));
458     for (::std::vector<sal_Int32>::const_iterator iY(maSeparators.begin()), iEnd(maSeparators.end());
459          iY!=iEnd;
460          ++iY)
461     {
462         DrawHelper::DrawHorizontalLine(
463             *this,
464             nLeft,
465             nRight,
466             *iY,
467             nSeparatorHeight,
468             rHorizontalBorderPaint);
469     }
470 }
471 
472 
473 
474 
475 void Deck::ScrollContainerWindow::SetSeparators (const ::std::vector<sal_Int32>& rSeparators)
476 {
477     maSeparators = rSeparators;
478 }
479 
480 
481 } } // end of namespace sfx2::sidebar
482