Update ooo320-m1
[ooovba.git] / sd / source / ui / toolpanel / SlideSorterCacheDisplay.cxx
blobbc5d74cfe136c19800edbcf70917e92cf34863b8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlideSorterCacheDisplay.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "taskpane/SlideSorterCacheDisplay.hxx"
36 #ifdef USE_SLIDE_SORTER_CACHE_DISPLAY
38 #include "taskpane/ScrollPanel.hxx"
39 #include "taskpane/TaskPaneControlFactory.hxx"
41 #include <vcl/window.hxx>
42 #include <vcl/lstbox.hxx>
43 #include <vcl/button.hxx>
45 namespace {
47 static const Color maBackgroundColor (255,250,245);
49 class PageCacheWindow : public ::Window
51 public:
52 PageCacheWindow (
53 ::Window* pParentWindow,
54 ::sd::toolpanel::SlideSorterCacheDisplay* pDisplay)
55 : ::Window(pParentWindow),
56 mpDisplay(pDisplay)
58 SetBackground(Wallpaper(maBackgroundColor));
61 virtual void Paint (const Rectangle& rBoundingBox)
62 { mpDisplay->Paint(rBoundingBox); ::Window::Paint(rBoundingBox); }
63 virtual void Resize (void) { mpDisplay->Resize(); ::Window::Resize(); }
65 private:
66 ::sd::toolpanel::SlideSorterCacheDisplay* mpDisplay;
73 namespace sd { namespace toolpanel {
75 ::std::map<const SdDrawDocument*, SlideSorterCacheDisplay*> SlideSorterCacheDisplay::maDisplays;
77 /** This factory class is used to create instances of TestPanel. It can be
78 extended so that its constructor stores arguments that later are passed
79 to new TestPanel objects.
81 class SlideSorterCacheDisplayFactory
82 : public ControlFactory
84 public:
85 SlideSorterCacheDisplayFactory (const SdDrawDocument* pDocument)
86 : mpDocument(pDocument)
90 protected:
91 virtual TreeNode* InternalCreateControl (TreeNode* pTreeNode)
93 SlideSorterCacheDisplay* pDisplay = SlideSorterCacheDisplay::Instance(mpDocument);
94 pDisplay->SetParentWindow(pTreeNode->GetWindow());
95 pDisplay->SetParentNode(pTreeNode);
96 return pDisplay;
99 private:
100 const SdDrawDocument* mpDocument;
109 SlideSorterCacheDisplay::SlideSorterCacheDisplay (const SdDrawDocument* pDocument)
110 : TreeNode(NULL),
111 mpWindow(NULL),
112 mnPageCount(0),
113 mnColumnCount(0),
114 mnRowCount(0),
115 maCellSize(0,0),
116 mnHorizontalBorder(0),
117 mnVerticalBorder(0)
119 SlideSorterCacheDisplay::AddInstance(pDocument,this);
125 SlideSorterCacheDisplay::~SlideSorterCacheDisplay (void)
127 if (mpWindow != NULL)
128 delete mpWindow;
129 SlideSorterCacheDisplay::RemoveInstance(this);
135 void SlideSorterCacheDisplay::SetParentWindow (::Window* pParentWindow)
137 mpWindow = new PageCacheWindow(pParentWindow, this);
143 std::auto_ptr<ControlFactory> SlideSorterCacheDisplay::CreateControlFactory (
144 const SdDrawDocument* pDocument)
146 return std::auto_ptr<ControlFactory>(new SlideSorterCacheDisplayFactory(pDocument));
152 void SlideSorterCacheDisplay::Paint (const Rectangle& rBoundingBox)
154 if (maCellSize.Width()>0 && maCellSize.Height()>0 && mpWindow!=NULL)
156 Color maSavedFillColor (mpWindow->GetFillColor());
157 Color maSavedLineColor (mpWindow->GetLineColor());
158 sal_Int32 nC0 = (rBoundingBox.Left() - mnHorizontalBorder) / maCellSize.Width();
159 sal_Int32 nC1 = (rBoundingBox.Right() - mnHorizontalBorder) / maCellSize.Width();
160 sal_Int32 nR0 = (rBoundingBox.Top() - mnVerticalBorder) / maCellSize.Height();
161 sal_Int32 nR1 = (rBoundingBox.Bottom() - mnVerticalBorder) / maCellSize.Height();
162 for (sal_Int32 nC=nC0; nC<=nC1; ++nC)
163 for (sal_Int32 nR=nR0; nR<=nR1; ++nR)
165 sal_Int32 nPageIndex (nC + nR*mnColumnCount);
166 if (nPageIndex < mnPageCount)
168 Rectangle aBox (GetPageBox(nPageIndex));
169 if ( ! maPageDescriptors[nPageIndex].mbVisible)
171 mpWindow->SetLineColor();
172 mpWindow->SetFillColor(maBackgroundColor);
173 mpWindow->DrawRect(aBox);
175 aBox.Left() += maCellSize.Width()/4;
176 aBox.Right() -= maCellSize.Width()/4;
177 aBox.Top() += maCellSize.Height()/4;
178 aBox.Bottom() -= maCellSize.Height()/4;
181 switch (maPageDescriptors[nPageIndex].meStatus)
183 case NONE : mpWindow->SetFillColor (Color(95,255,128)); break;
184 case RENDERING : mpWindow->SetFillColor (Color(236,125,128)); break;
185 case IN_QUEUE_PRIORITY_0 : mpWindow->SetFillColor (Color(255,243,0)); break;
186 case IN_QUEUE_PRIORITY_1 : mpWindow->SetFillColor (Color(255,199,0)); break;
187 case IN_QUEUE_PRIORITY_2 : mpWindow->SetFillColor (Color(20,255,128)); break;
188 default : mpWindow->SetFillColor (COL_BLACK); break;
190 mpWindow->SetLineColor(COL_BLACK);
191 mpWindow->DrawRect(aBox);
193 if ( ! maPageDescriptors[nPageIndex].mbUpToDate)
194 mpWindow->DrawLine(aBox.TopLeft(), aBox.BottomRight());
197 mpWindow->SetLineColor(maSavedLineColor);
198 mpWindow->SetFillColor(maSavedFillColor);
205 void SlideSorterCacheDisplay::Resize (void)
207 if (mpWindow != NULL)
209 double nW = mpWindow->GetSizePixel().Width();
210 double nH = mpWindow->GetSizePixel().Height();
211 if (nH > 0)
213 double nAspect = nW / nH;
214 sal_Int32 nR = 1;
215 sal_Int32 nC = 1;
216 while (nR * nC < mnPageCount)
218 if (double(nC) / double(nR) > nAspect)
219 ++nR;
220 else
221 ++nC;
223 double nAspect2 = double(nC) / double(nR);
225 mnRowCount = nR;
226 mnColumnCount = nC;
227 mnHorizontalGap = 2;
228 mnVerticalGap = 2;
229 maCellSize = Size(
230 (int)((nW-(nC-1)*mnHorizontalGap) / nC),
231 (int)((nH-(nR-1)*mnVerticalGap) / nR));
232 mnHorizontalBorder = (int)(nW - nC*maCellSize.Width() - ((nC-1)*mnHorizontalGap))/2;
233 mnVerticalBorder = (int)(nH - nR*maCellSize.Height() - ((nR-1)*mnVerticalGap))/2;
241 SlideSorterCacheDisplay* SlideSorterCacheDisplay::Instance (const SdDrawDocument* pDocument)
243 SlideSorterCacheDisplay* pDisplay = NULL;
244 ::std::map<const SdDrawDocument*, SlideSorterCacheDisplay*>::iterator iDisplay;
245 for (iDisplay=maDisplays.begin(); iDisplay!=maDisplays.end(); ++iDisplay)
246 if (iDisplay->first == pDocument)
247 pDisplay = iDisplay->second;
249 if (pDisplay == NULL)
251 pDisplay = new SlideSorterCacheDisplay(pDocument);
254 return pDisplay;
260 void SlideSorterCacheDisplay::SetPageCount (sal_Int32 nPageCount)
262 mnPageCount = nPageCount;
263 maPageDescriptors.resize(nPageCount);
264 Resize();
265 if (mpWindow != NULL)
266 mpWindow->Invalidate();
272 void SlideSorterCacheDisplay::SetPageStatus (sal_Int32 nPageIndex, PageStatus eStatus)
274 ProvideSize(nPageIndex);
275 maPageDescriptors[nPageIndex].meStatus = eStatus;
276 PaintPage(nPageIndex);
282 void SlideSorterCacheDisplay::SetPageVisibility (sal_Int32 nPageIndex, bool bVisible)
284 ProvideSize(nPageIndex);
285 maPageDescriptors[nPageIndex].mbVisible = bVisible;
286 PaintPage(nPageIndex);
292 void SlideSorterCacheDisplay::SetUpToDate (sal_Int32 nPageIndex, bool bUpToDate)
294 ProvideSize(nPageIndex);
295 maPageDescriptors[nPageIndex].mbUpToDate = bUpToDate;
296 PaintPage(nPageIndex);
302 Rectangle SlideSorterCacheDisplay::GetPageBox (sal_Int32 nPageIndex)
304 sal_Int32 nRow = nPageIndex / mnColumnCount;
305 sal_Int32 nColumn = nPageIndex % mnColumnCount;
306 return Rectangle(
307 Point(mnHorizontalBorder + nColumn * maCellSize.Width() + nColumn*mnHorizontalGap,
308 mnVerticalBorder + nRow * maCellSize.Height() + nRow*mnVerticalGap),
309 maCellSize);
315 void SlideSorterCacheDisplay::AddInstance (
316 const SdDrawDocument* pDocument,
317 SlideSorterCacheDisplay* pControl)
319 maDisplays[pDocument] = pControl;
325 void SlideSorterCacheDisplay::RemoveInstance (SlideSorterCacheDisplay* pControl)
327 ::std::map<const SdDrawDocument*, SlideSorterCacheDisplay*>::iterator iDisplay;
328 for (iDisplay=maDisplays.begin(); iDisplay!=maDisplays.end(); ++iDisplay)
329 if (iDisplay->second == pControl)
331 maDisplays.erase(iDisplay);
332 break;
339 void SlideSorterCacheDisplay::ProvideSize (sal_Int32 nPageIndex)
341 if (maPageDescriptors.size() <= (sal_uInt32)nPageIndex)
342 maPageDescriptors.resize(nPageIndex+1);
343 if (mnPageCount <= nPageIndex)
344 mnPageCount = nPageIndex;
350 Size SlideSorterCacheDisplay::GetPreferredSize (void)
352 return Size(100,100);
358 sal_Int32 SlideSorterCacheDisplay::GetPreferredWidth (sal_Int32 nHeigh)
360 return GetPreferredSize().Width();
366 sal_Int32 SlideSorterCacheDisplay::GetPreferredHeight (sal_Int32 nWidth)
368 return GetPreferredSize().Height();
373 ::Window* SlideSorterCacheDisplay::GetWindow (void)
375 return mpWindow;
381 bool SlideSorterCacheDisplay::IsResizable (void)
383 return true;
389 bool SlideSorterCacheDisplay::IsExpandable (void) const
391 return true;
397 bool SlideSorterCacheDisplay::IsExpanded (void) const
399 return true;
405 void SlideSorterCacheDisplay::PaintPage (sal_Int32 nPageIndex)
407 if (mpWindow != NULL)
409 Paint(GetPageBox(nPageIndex));
414 } } // end of namespace ::sd::toolpanel
416 #endif