fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / toolpanel / SlideSorterCacheDisplay.cxx
blob059ab35a87d82c4b2443e79664f0cb9f3d135e87
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "taskpane/SlideSorterCacheDisplay.hxx"
23 #ifdef USE_SLIDE_SORTER_CACHE_DISPLAY
25 #include "taskpane/ScrollPanel.hxx"
26 #include "taskpane/TaskPaneControlFactory.hxx"
28 #include <vcl/window.hxx>
29 #include <vcl/lstbox.hxx>
30 #include <vcl/button.hxx>
32 namespace {
34 static const Color maBackgroundColor (255,250,245);
36 class PageCacheWindow : public ::Window
38 public:
39 PageCacheWindow (
40 ::Window* pParentWindow,
41 ::sd::toolpanel::SlideSorterCacheDisplay* pDisplay)
42 : ::Window(pParentWindow),
43 mpDisplay(pDisplay)
45 SetBackground(Wallpaper(maBackgroundColor));
48 virtual void Paint (const Rectangle& rBoundingBox)
49 { mpDisplay->Paint(rBoundingBox); ::Window::Paint(rBoundingBox); }
50 virtual void Resize (void) { mpDisplay->Resize(); ::Window::Resize(); }
52 private:
53 ::sd::toolpanel::SlideSorterCacheDisplay* mpDisplay;
60 namespace sd { namespace toolpanel {
62 ::std::map<const SdDrawDocument*, SlideSorterCacheDisplay*> SlideSorterCacheDisplay::maDisplays;
64 SlideSorterCacheDisplay::SlideSorterCacheDisplay (const SdDrawDocument* pDocument)
65 : TreeNode(NULL),
66 mpWindow(NULL),
67 mnPageCount(0),
68 mnColumnCount(0),
69 mnRowCount(0),
70 maCellSize(0,0),
71 mnHorizontalBorder(0),
72 mnVerticalBorder(0)
74 SlideSorterCacheDisplay::AddInstance(pDocument,this);
80 SlideSorterCacheDisplay::~SlideSorterCacheDisplay (void)
82 if (mpWindow != NULL)
83 delete mpWindow;
84 SlideSorterCacheDisplay::RemoveInstance(this);
90 void SlideSorterCacheDisplay::SetParentWindow (::Window* pParentWindow)
92 mpWindow = new PageCacheWindow(pParentWindow, this);
98 void SlideSorterCacheDisplay::Paint (const Rectangle& rBoundingBox)
100 if (maCellSize.Width()>0 && maCellSize.Height()>0 && mpWindow!=NULL)
102 Color maSavedFillColor (mpWindow->GetFillColor());
103 Color maSavedLineColor (mpWindow->GetLineColor());
104 sal_Int32 nC0 = (rBoundingBox.Left() - mnHorizontalBorder) / maCellSize.Width();
105 sal_Int32 nC1 = (rBoundingBox.Right() - mnHorizontalBorder) / maCellSize.Width();
106 sal_Int32 nR0 = (rBoundingBox.Top() - mnVerticalBorder) / maCellSize.Height();
107 sal_Int32 nR1 = (rBoundingBox.Bottom() - mnVerticalBorder) / maCellSize.Height();
108 for (sal_Int32 nC=nC0; nC<=nC1; ++nC)
109 for (sal_Int32 nR=nR0; nR<=nR1; ++nR)
111 sal_Int32 nPageIndex (nC + nR*mnColumnCount);
112 if (nPageIndex < mnPageCount)
114 Rectangle aBox (GetPageBox(nPageIndex));
115 if ( ! maPageDescriptors[nPageIndex].mbVisible)
117 mpWindow->SetLineColor();
118 mpWindow->SetFillColor(maBackgroundColor);
119 mpWindow->DrawRect(aBox);
121 aBox.Left() += maCellSize.Width()/4;
122 aBox.Right() -= maCellSize.Width()/4;
123 aBox.Top() += maCellSize.Height()/4;
124 aBox.Bottom() -= maCellSize.Height()/4;
127 switch (maPageDescriptors[nPageIndex].meStatus)
129 case NONE : mpWindow->SetFillColor (Color(95,255,128)); break;
130 case RENDERING : mpWindow->SetFillColor (Color(236,125,128)); break;
131 case IN_QUEUE_PRIORITY_0 : mpWindow->SetFillColor (Color(255,243,0)); break;
132 case IN_QUEUE_PRIORITY_1 : mpWindow->SetFillColor (Color(255,199,0)); break;
133 case IN_QUEUE_PRIORITY_2 : mpWindow->SetFillColor (Color(20,255,128)); break;
134 default : mpWindow->SetFillColor (COL_BLACK); break;
136 mpWindow->SetLineColor(COL_BLACK);
137 mpWindow->DrawRect(aBox);
139 if ( ! maPageDescriptors[nPageIndex].mbUpToDate)
140 mpWindow->DrawLine(aBox.TopLeft(), aBox.BottomRight());
143 mpWindow->SetLineColor(maSavedLineColor);
144 mpWindow->SetFillColor(maSavedFillColor);
151 void SlideSorterCacheDisplay::Resize (void)
153 if (mpWindow != NULL)
155 double nW = mpWindow->GetSizePixel().Width();
156 double nH = mpWindow->GetSizePixel().Height();
157 if (nH > 0)
159 double nAspect = nW / nH;
160 sal_Int32 nR = 1;
161 sal_Int32 nC = 1;
162 while (nR * nC < mnPageCount)
164 if (double(nC) / double(nR) > nAspect)
165 ++nR;
166 else
167 ++nC;
170 mnRowCount = nR;
171 mnColumnCount = nC;
172 mnHorizontalGap = 2;
173 mnVerticalGap = 2;
174 maCellSize = Size(
175 (int)((nW-(nC-1)*mnHorizontalGap) / nC),
176 (int)((nH-(nR-1)*mnVerticalGap) / nR));
177 mnHorizontalBorder = (int)(nW - nC*maCellSize.Width() - ((nC-1)*mnHorizontalGap))/2;
178 mnVerticalBorder = (int)(nH - nR*maCellSize.Height() - ((nR-1)*mnVerticalGap))/2;
186 SlideSorterCacheDisplay* SlideSorterCacheDisplay::Instance (const SdDrawDocument* pDocument)
188 SlideSorterCacheDisplay* pDisplay = NULL;
189 ::std::map<const SdDrawDocument*, SlideSorterCacheDisplay*>::iterator iDisplay;
190 for (iDisplay=maDisplays.begin(); iDisplay!=maDisplays.end(); ++iDisplay)
191 if (iDisplay->first == pDocument)
192 pDisplay = iDisplay->second;
194 if (pDisplay == NULL)
196 pDisplay = new SlideSorterCacheDisplay(pDocument);
199 return pDisplay;
205 void SlideSorterCacheDisplay::SetPageCount (sal_Int32 nPageCount)
207 mnPageCount = nPageCount;
208 maPageDescriptors.resize(nPageCount);
209 Resize();
210 if (mpWindow != NULL)
211 mpWindow->Invalidate();
217 void SlideSorterCacheDisplay::SetPageStatus (sal_Int32 nPageIndex, PageStatus eStatus)
219 ProvideSize(nPageIndex);
220 maPageDescriptors[nPageIndex].meStatus = eStatus;
221 PaintPage(nPageIndex);
227 void SlideSorterCacheDisplay::SetPageVisibility (sal_Int32 nPageIndex, bool bVisible)
229 ProvideSize(nPageIndex);
230 maPageDescriptors[nPageIndex].mbVisible = bVisible;
231 PaintPage(nPageIndex);
237 void SlideSorterCacheDisplay::SetUpToDate (sal_Int32 nPageIndex, bool bUpToDate)
239 ProvideSize(nPageIndex);
240 maPageDescriptors[nPageIndex].mbUpToDate = bUpToDate;
241 PaintPage(nPageIndex);
247 Rectangle SlideSorterCacheDisplay::GetPageBox (sal_Int32 nPageIndex)
249 sal_Int32 nRow = nPageIndex / mnColumnCount;
250 sal_Int32 nColumn = nPageIndex % mnColumnCount;
251 return Rectangle(
252 Point(mnHorizontalBorder + nColumn * maCellSize.Width() + nColumn*mnHorizontalGap,
253 mnVerticalBorder + nRow * maCellSize.Height() + nRow*mnVerticalGap),
254 maCellSize);
260 void SlideSorterCacheDisplay::AddInstance (
261 const SdDrawDocument* pDocument,
262 SlideSorterCacheDisplay* pControl)
264 maDisplays[pDocument] = pControl;
270 void SlideSorterCacheDisplay::RemoveInstance (SlideSorterCacheDisplay* pControl)
272 ::std::map<const SdDrawDocument*, SlideSorterCacheDisplay*>::iterator iDisplay;
273 for (iDisplay=maDisplays.begin(); iDisplay!=maDisplays.end(); ++iDisplay)
274 if (iDisplay->second == pControl)
276 maDisplays.erase(iDisplay);
277 break;
284 void SlideSorterCacheDisplay::ProvideSize (sal_Int32 nPageIndex)
286 if (maPageDescriptors.size() <= (sal_uInt32)nPageIndex)
287 maPageDescriptors.resize(nPageIndex+1);
288 if (mnPageCount <= nPageIndex)
289 mnPageCount = nPageIndex;
295 Size SlideSorterCacheDisplay::GetPreferredSize (void)
297 return Size(100,100);
303 sal_Int32 SlideSorterCacheDisplay::GetPreferredWidth (sal_Int32 nHeigh)
305 return GetPreferredSize().Width();
311 sal_Int32 SlideSorterCacheDisplay::GetPreferredHeight (sal_Int32 nWidth)
313 return GetPreferredSize().Height();
318 ::Window* SlideSorterCacheDisplay::GetWindow (void)
320 return mpWindow;
326 bool SlideSorterCacheDisplay::IsResizable (void)
328 return true;
334 bool SlideSorterCacheDisplay::IsExpandable (void) const
336 return true;
342 bool SlideSorterCacheDisplay::IsExpanded (void) const
344 return true;
350 void SlideSorterCacheDisplay::PaintPage (sal_Int32 nPageIndex)
352 if (mpWindow != NULL)
354 Paint(GetPageBox(nPageIndex));
359 } } // end of namespace ::sd::toolpanel
361 #endif
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */