15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
55b190011SAndrew Rist * distributed with this work for additional information
65b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
75b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist * "License"); you may not use this file except in compliance
95b190011SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
115b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
135b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist * software distributed under the License is distributed on an
155b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist * KIND, either express or implied. See the License for the
175b190011SAndrew Rist * specific language governing permissions and limitations
185b190011SAndrew Rist * under the License.
19cdf0e10cSrcweir *
205b190011SAndrew Rist *************************************************************/
215b190011SAndrew Rist
225b190011SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "view/SlsPageObjectPainter.hxx"
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "model/SlsPageDescriptor.hxx"
29cdf0e10cSrcweir #include "view/SlideSorterView.hxx"
30cdf0e10cSrcweir #include "view/SlsPageObjectLayouter.hxx"
31cdf0e10cSrcweir #include "view/SlsLayouter.hxx"
32cdf0e10cSrcweir #include "view/SlsTheme.hxx"
33cdf0e10cSrcweir #include "view/SlsButtonBar.hxx"
34cdf0e10cSrcweir #include "SlsFramePainter.hxx"
35cdf0e10cSrcweir #include "cache/SlsPageCache.hxx"
36cdf0e10cSrcweir #include "controller/SlsProperties.hxx"
37cdf0e10cSrcweir #include "Window.hxx"
38cdf0e10cSrcweir #include "sdpage.hxx"
39cdf0e10cSrcweir #include "sdresid.hxx"
40cdf0e10cSrcweir #include <vcl/svapp.hxx>
41cdf0e10cSrcweir #include <vcl/vclenum.hxx>
42cdf0e10cSrcweir #include <vcl/virdev.hxx>
43cdf0e10cSrcweir #include <boost/scoped_ptr.hpp>
44cdf0e10cSrcweir
45cdf0e10cSrcweir using namespace ::drawinglayer::primitive2d;
46cdf0e10cSrcweir
47cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace view {
48cdf0e10cSrcweir
49cdf0e10cSrcweir namespace {
50cdf0e10cSrcweir
Blend(const sal_uInt8 nValue1,const sal_uInt8 nValue2,const double nWeight)51cdf0e10cSrcweir sal_uInt8 Blend (
52cdf0e10cSrcweir const sal_uInt8 nValue1,
53cdf0e10cSrcweir const sal_uInt8 nValue2,
54cdf0e10cSrcweir const double nWeight)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir const double nValue (nValue1*(1-nWeight) + nValue2 * nWeight);
57cdf0e10cSrcweir if (nValue < 0)
58cdf0e10cSrcweir return 0;
59cdf0e10cSrcweir else if (nValue > 255)
60cdf0e10cSrcweir return 255;
61cdf0e10cSrcweir else
62cdf0e10cSrcweir return (sal_uInt8)nValue;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir
ClampColorChannel(const double nValue)65cdf0e10cSrcweir sal_uInt8 ClampColorChannel (const double nValue)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir if (nValue <= 0)
68cdf0e10cSrcweir return 0;
69cdf0e10cSrcweir else if (nValue >= 255)
70cdf0e10cSrcweir return 255;
71cdf0e10cSrcweir else
72cdf0e10cSrcweir return sal_uInt8(nValue);
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
CalculateColorChannel(const double nColor1,const double nColor2,const double nAlpha1,const double nAlpha2,const double nAlpha0)75cdf0e10cSrcweir sal_uInt8 CalculateColorChannel(
76cdf0e10cSrcweir const double nColor1,
77cdf0e10cSrcweir const double nColor2,
78cdf0e10cSrcweir const double nAlpha1,
79cdf0e10cSrcweir const double nAlpha2,
80cdf0e10cSrcweir const double nAlpha0)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir if (nAlpha0 == 0)
83cdf0e10cSrcweir return 0;
84cdf0e10cSrcweir
85cdf0e10cSrcweir const double nColor0 ((nAlpha1*nColor1 + nAlpha1*nAlpha2*nColor1 + nAlpha2*nColor2) / nAlpha0);
86cdf0e10cSrcweir return ClampColorChannel(255 * nColor0);
87cdf0e10cSrcweir }
88cdf0e10cSrcweir
89cdf0e10cSrcweir } // end of anonymous namespace
90cdf0e10cSrcweir
91cdf0e10cSrcweir
92cdf0e10cSrcweir
93cdf0e10cSrcweir
94cdf0e10cSrcweir //===== PageObjectPainter =====================================================
95cdf0e10cSrcweir
PageObjectPainter(const SlideSorter & rSlideSorter)96cdf0e10cSrcweir PageObjectPainter::PageObjectPainter (
97cdf0e10cSrcweir const SlideSorter& rSlideSorter)
98cdf0e10cSrcweir : mrLayouter(rSlideSorter.GetView().GetLayouter()),
99cdf0e10cSrcweir mpPageObjectLayouter(),
100cdf0e10cSrcweir mpCache(rSlideSorter.GetView().GetPreviewCache()),
101cdf0e10cSrcweir mpProperties(rSlideSorter.GetProperties()),
102cdf0e10cSrcweir mpTheme(rSlideSorter.GetTheme()),
103cdf0e10cSrcweir mpPageNumberFont(Theme::GetFont(Theme::Font_PageNumber, *rSlideSorter.GetContentWindow())),
104cdf0e10cSrcweir mpShadowPainter(new FramePainter(mpTheme->GetIcon(Theme::Icon_RawShadow))),
105cdf0e10cSrcweir mpFocusBorderPainter(new FramePainter(mpTheme->GetIcon(Theme::Icon_FocusBorder))),
106cdf0e10cSrcweir maNormalBackground(),
107cdf0e10cSrcweir maSelectionBackground(),
108cdf0e10cSrcweir maFocusedSelectionBackground(),
109cdf0e10cSrcweir maMouseOverBackground(),
110cdf0e10cSrcweir maMouseOverFocusedBackground(),
111cdf0e10cSrcweir msUnhideString(mpTheme->GetString(Theme::String_Unhide)),
1126194c063SMichael Stahl mrButtonBar(rSlideSorter.GetView().GetButtonBar()),
1136194c063SMichael Stahl maSize()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir // Replace the color (not the alpha values) in the focus border with a
116cdf0e10cSrcweir // color derived from the current selection color.
117cdf0e10cSrcweir Color aColor (mpTheme->GetColor(Theme::Color_Selection));
118cdf0e10cSrcweir sal_uInt16 nHue, nSat, nBri;
119cdf0e10cSrcweir aColor.RGBtoHSB(nHue, nSat, nBri);
120cdf0e10cSrcweir aColor = Color::HSBtoRGB(nHue, 28, 65);
121cdf0e10cSrcweir mpFocusBorderPainter->AdaptColor(aColor, true);
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir
125cdf0e10cSrcweir
126cdf0e10cSrcweir
~PageObjectPainter(void)127cdf0e10cSrcweir PageObjectPainter::~PageObjectPainter (void)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir
132cdf0e10cSrcweir
133cdf0e10cSrcweir
PaintPageObject(OutputDevice & rDevice,const model::SharedPageDescriptor & rpDescriptor)134cdf0e10cSrcweir void PageObjectPainter::PaintPageObject (
135cdf0e10cSrcweir OutputDevice& rDevice,
136cdf0e10cSrcweir const model::SharedPageDescriptor& rpDescriptor)
137cdf0e10cSrcweir {
138053b1516SAndre Fischer if (UpdatePageObjectLayouter())
139cdf0e10cSrcweir {
140053b1516SAndre Fischer // Turn off antialiasing to avoid the bitmaps from being
141053b1516SAndre Fischer // shifted by fractions of a pixel and thus show blurry edges.
142cdf0e10cSrcweir const sal_uInt16 nSavedAntialiasingMode (rDevice.GetAntialiasing());
143cdf0e10cSrcweir rDevice.SetAntialiasing(nSavedAntialiasingMode & ~ANTIALIASING_ENABLE_B2DDRAW);
144cdf0e10cSrcweir
145cdf0e10cSrcweir PaintBackground(rDevice, rpDescriptor);
146cdf0e10cSrcweir PaintPreview(rDevice, rpDescriptor);
147cdf0e10cSrcweir PaintPageNumber(rDevice, rpDescriptor);
148cdf0e10cSrcweir PaintTransitionEffect(rDevice, rpDescriptor);
149cdf0e10cSrcweir mrButtonBar.Paint(rDevice, rpDescriptor);
150cdf0e10cSrcweir
151cdf0e10cSrcweir rDevice.SetAntialiasing(nSavedAntialiasingMode);
152cdf0e10cSrcweir }
153053b1516SAndre Fischer }
154053b1516SAndre Fischer
155053b1516SAndre Fischer
156053b1516SAndre Fischer
157053b1516SAndre Fischer
UpdatePageObjectLayouter(void)158053b1516SAndre Fischer bool PageObjectPainter::UpdatePageObjectLayouter (void)
159053b1516SAndre Fischer {
160053b1516SAndre Fischer // The page object layouter is quite volatile. It may have been replaced
161053b1516SAndre Fischer // since the last call. Update it now.
162053b1516SAndre Fischer mpPageObjectLayouter = mrLayouter.GetPageObjectLayouter();
163053b1516SAndre Fischer if ( ! mpPageObjectLayouter)
164053b1516SAndre Fischer {
165053b1516SAndre Fischer OSL_ASSERT(mpPageObjectLayouter);
166053b1516SAndre Fischer return false;
167053b1516SAndre Fischer }
168053b1516SAndre Fischer else
169053b1516SAndre Fischer return true;
170053b1516SAndre Fischer }
171cdf0e10cSrcweir
172cdf0e10cSrcweir
173cdf0e10cSrcweir
174cdf0e10cSrcweir
NotifyResize(const bool bForce)175cdf0e10cSrcweir void PageObjectPainter::NotifyResize (const bool bForce)
176cdf0e10cSrcweir {
1776194c063SMichael Stahl if (bForce || ! mpPageObjectLayouter)
1786194c063SMichael Stahl InvalidateBitmaps();
179053b1516SAndre Fischer else if (UpdatePageObjectLayouter())
1806194c063SMichael Stahl {
1816194c063SMichael Stahl const Size aSize (mpPageObjectLayouter->GetSize(
1826194c063SMichael Stahl PageObjectLayouter::FocusIndicator,
1836194c063SMichael Stahl PageObjectLayouter::WindowCoordinateSystem));
1846194c063SMichael Stahl if ( maSize!=aSize)
1856194c063SMichael Stahl {
1866194c063SMichael Stahl maSize = aSize;
1876194c063SMichael Stahl InvalidateBitmaps();
1886194c063SMichael Stahl }
1896194c063SMichael Stahl }
1906194c063SMichael Stahl }
1916194c063SMichael Stahl
1926194c063SMichael Stahl
1936194c063SMichael Stahl
1946194c063SMichael Stahl
InvalidateBitmaps(void)1956194c063SMichael Stahl void PageObjectPainter::InvalidateBitmaps (void)
1966194c063SMichael Stahl {
197cdf0e10cSrcweir maNormalBackground.SetEmpty();
198cdf0e10cSrcweir maSelectionBackground.SetEmpty();
199cdf0e10cSrcweir maFocusedSelectionBackground.SetEmpty();
200cdf0e10cSrcweir maFocusedBackground.SetEmpty();
201cdf0e10cSrcweir maMouseOverBackground.SetEmpty();
202cdf0e10cSrcweir maMouseOverFocusedBackground.SetEmpty();
203cdf0e10cSrcweir maMouseOverSelectedAndFocusedBackground.SetEmpty();
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
206cdf0e10cSrcweir
207cdf0e10cSrcweir
208cdf0e10cSrcweir
SetTheme(const::boost::shared_ptr<view::Theme> & rpTheme)209cdf0e10cSrcweir void PageObjectPainter::SetTheme (const ::boost::shared_ptr<view::Theme>& rpTheme)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir mpTheme = rpTheme;
212cdf0e10cSrcweir NotifyResize(true);
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir
216cdf0e10cSrcweir
217cdf0e10cSrcweir
PaintBackground(OutputDevice & rDevice,const model::SharedPageDescriptor & rpDescriptor)218cdf0e10cSrcweir void PageObjectPainter::PaintBackground (
219cdf0e10cSrcweir OutputDevice& rDevice,
220cdf0e10cSrcweir const model::SharedPageDescriptor& rpDescriptor)
221cdf0e10cSrcweir {
222cdf0e10cSrcweir const Rectangle aBox (mpPageObjectLayouter->GetBoundingBox(
223cdf0e10cSrcweir rpDescriptor,
224cdf0e10cSrcweir PageObjectLayouter::FocusIndicator,
225cdf0e10cSrcweir PageObjectLayouter::ModelCoordinateSystem));
226cdf0e10cSrcweir
227cdf0e10cSrcweir const Bitmap& rBackground (GetBackgroundForState(rpDescriptor, rDevice));
228cdf0e10cSrcweir rDevice.DrawBitmap(aBox.TopLeft(), rBackground);
229cdf0e10cSrcweir
230cdf0e10cSrcweir // Fill the interior of the preview area with the default background
231cdf0e10cSrcweir // color of the page.
232cdf0e10cSrcweir SdPage* pPage = rpDescriptor->GetPage();
233cdf0e10cSrcweir if (pPage != NULL)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir rDevice.SetFillColor(pPage->GetPageBackgroundColor(NULL));
236cdf0e10cSrcweir rDevice.SetLineColor(pPage->GetPageBackgroundColor(NULL));
237cdf0e10cSrcweir const Rectangle aPreviewBox (mpPageObjectLayouter->GetBoundingBox(
238cdf0e10cSrcweir rpDescriptor,
239cdf0e10cSrcweir PageObjectLayouter::Preview,
240cdf0e10cSrcweir PageObjectLayouter::ModelCoordinateSystem));
241cdf0e10cSrcweir rDevice.DrawRect(aPreviewBox);
242cdf0e10cSrcweir }
243cdf0e10cSrcweir }
244cdf0e10cSrcweir
245cdf0e10cSrcweir
246cdf0e10cSrcweir
247cdf0e10cSrcweir
PaintPreview(OutputDevice & rDevice,const model::SharedPageDescriptor & rpDescriptor) const248cdf0e10cSrcweir void PageObjectPainter::PaintPreview (
249cdf0e10cSrcweir OutputDevice& rDevice,
250cdf0e10cSrcweir const model::SharedPageDescriptor& rpDescriptor) const
251cdf0e10cSrcweir {
252cdf0e10cSrcweir const Rectangle aBox (mpPageObjectLayouter->GetBoundingBox(
253cdf0e10cSrcweir rpDescriptor,
254cdf0e10cSrcweir PageObjectLayouter::Preview,
255cdf0e10cSrcweir PageObjectLayouter::ModelCoordinateSystem));
256cdf0e10cSrcweir
257*b862c97cSHerbert Dürr if( bool(mpCache))
258cdf0e10cSrcweir {
259cdf0e10cSrcweir const SdrPage* pPage = rpDescriptor->GetPage();
260cdf0e10cSrcweir mpCache->SetPreciousFlag(pPage, true);
261cdf0e10cSrcweir
262cdf0e10cSrcweir const Bitmap aPreview (GetPreviewBitmap(rpDescriptor, &rDevice));
263cdf0e10cSrcweir if ( ! aPreview.IsEmpty())
264cdf0e10cSrcweir {
265cdf0e10cSrcweir if (aPreview.GetSizePixel() != aBox.GetSize())
266cdf0e10cSrcweir rDevice.DrawBitmap(aBox.TopLeft(), aBox.GetSize(), aPreview);
267cdf0e10cSrcweir else
268cdf0e10cSrcweir rDevice.DrawBitmap(aBox.TopLeft(), aPreview);
269cdf0e10cSrcweir }
270cdf0e10cSrcweir }
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir
274cdf0e10cSrcweir
275cdf0e10cSrcweir
CreateMarkedPreview(const Size & rSize,const Bitmap & rPreview,const BitmapEx & rOverlay,const OutputDevice * pReferenceDevice) const276cdf0e10cSrcweir Bitmap PageObjectPainter::CreateMarkedPreview (
277cdf0e10cSrcweir const Size& rSize,
278cdf0e10cSrcweir const Bitmap& rPreview,
279cdf0e10cSrcweir const BitmapEx& rOverlay,
280cdf0e10cSrcweir const OutputDevice* pReferenceDevice) const
281cdf0e10cSrcweir {
282cdf0e10cSrcweir ::boost::scoped_ptr<VirtualDevice> pDevice;
283cdf0e10cSrcweir if (pReferenceDevice != NULL)
284cdf0e10cSrcweir pDevice.reset(new VirtualDevice(*pReferenceDevice));
285cdf0e10cSrcweir else
286cdf0e10cSrcweir pDevice.reset(new VirtualDevice());
287cdf0e10cSrcweir pDevice->SetOutputSizePixel(rSize);
288cdf0e10cSrcweir
289cdf0e10cSrcweir pDevice->DrawBitmap(Point(0,0), rSize, rPreview);
290cdf0e10cSrcweir
291cdf0e10cSrcweir // Paint bitmap tiled over the preview to mark it as excluded.
292cdf0e10cSrcweir const sal_Int32 nIconWidth (rOverlay.GetSizePixel().Width());
293cdf0e10cSrcweir const sal_Int32 nIconHeight (rOverlay.GetSizePixel().Height());
294cdf0e10cSrcweir if (nIconWidth>0 && nIconHeight>0)
295cdf0e10cSrcweir {
296cdf0e10cSrcweir for (sal_Int32 nX=0; nX<rSize.Width(); nX+=nIconWidth)
297cdf0e10cSrcweir for (sal_Int32 nY=0; nY<rSize.Height(); nY+=nIconHeight)
298cdf0e10cSrcweir pDevice->DrawBitmapEx(Point(nX,nY), rOverlay);
299cdf0e10cSrcweir }
300cdf0e10cSrcweir return pDevice->GetBitmap(Point(0,0), rSize);
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
303cdf0e10cSrcweir
304cdf0e10cSrcweir
305cdf0e10cSrcweir
GetPreviewBitmap(const model::SharedPageDescriptor & rpDescriptor,const OutputDevice * pReferenceDevice) const306cdf0e10cSrcweir Bitmap PageObjectPainter::GetPreviewBitmap (
307cdf0e10cSrcweir const model::SharedPageDescriptor& rpDescriptor,
308cdf0e10cSrcweir const OutputDevice* pReferenceDevice) const
309cdf0e10cSrcweir {
310cdf0e10cSrcweir const SdrPage* pPage = rpDescriptor->GetPage();
311cdf0e10cSrcweir const bool bIsExcluded (rpDescriptor->HasState(model::PageDescriptor::ST_Excluded));
312cdf0e10cSrcweir
313cdf0e10cSrcweir if (bIsExcluded)
314cdf0e10cSrcweir {
315cdf0e10cSrcweir Bitmap aMarkedPreview (mpCache->GetMarkedPreviewBitmap(pPage,false));
316cdf0e10cSrcweir const Rectangle aPreviewBox (mpPageObjectLayouter->GetBoundingBox(
317cdf0e10cSrcweir rpDescriptor,
318cdf0e10cSrcweir PageObjectLayouter::Preview,
319cdf0e10cSrcweir PageObjectLayouter::ModelCoordinateSystem));
320cdf0e10cSrcweir if (aMarkedPreview.IsEmpty() || aMarkedPreview.GetSizePixel()!=aPreviewBox.GetSize())
321cdf0e10cSrcweir {
322cdf0e10cSrcweir aMarkedPreview = CreateMarkedPreview(
323cdf0e10cSrcweir aPreviewBox.GetSize(),
324cdf0e10cSrcweir mpCache->GetPreviewBitmap(pPage,true),
325cdf0e10cSrcweir mpTheme->GetIcon(Theme::Icon_HideSlideOverlay),
326cdf0e10cSrcweir pReferenceDevice);
327cdf0e10cSrcweir mpCache->SetMarkedPreviewBitmap(pPage, aMarkedPreview);
328cdf0e10cSrcweir }
329cdf0e10cSrcweir return aMarkedPreview;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir else
332cdf0e10cSrcweir {
333cdf0e10cSrcweir return mpCache->GetPreviewBitmap(pPage,false);
334cdf0e10cSrcweir }
335cdf0e10cSrcweir }
336cdf0e10cSrcweir
337cdf0e10cSrcweir
338cdf0e10cSrcweir
339cdf0e10cSrcweir
PaintPageNumber(OutputDevice & rDevice,const model::SharedPageDescriptor & rpDescriptor) const340cdf0e10cSrcweir void PageObjectPainter::PaintPageNumber (
341cdf0e10cSrcweir OutputDevice& rDevice,
342cdf0e10cSrcweir const model::SharedPageDescriptor& rpDescriptor) const
343cdf0e10cSrcweir {
344cdf0e10cSrcweir const Rectangle aBox (mpPageObjectLayouter->GetBoundingBox(
345cdf0e10cSrcweir rpDescriptor,
346cdf0e10cSrcweir PageObjectLayouter::PageNumber,
347cdf0e10cSrcweir PageObjectLayouter::ModelCoordinateSystem));
348cdf0e10cSrcweir
349cdf0e10cSrcweir // Determine the color of the page number.
350cdf0e10cSrcweir Color aPageNumberColor (mpTheme->GetColor(Theme::Color_PageNumberDefault));
351cdf0e10cSrcweir if (rpDescriptor->HasState(model::PageDescriptor::ST_MouseOver) ||
352cdf0e10cSrcweir rpDescriptor->HasState(model::PageDescriptor::ST_Selected))
353cdf0e10cSrcweir {
354cdf0e10cSrcweir // Page number is painted on background for hover or selection or
355cdf0e10cSrcweir // both. Each of these background colors has a predefined luminance
356cdf0e10cSrcweir // which is compatible with the PageNumberHover color.
357cdf0e10cSrcweir aPageNumberColor = Color(mpTheme->GetColor(Theme::Color_PageNumberHover));
358cdf0e10cSrcweir }
359cdf0e10cSrcweir else
360cdf0e10cSrcweir {
361cdf0e10cSrcweir const Color aBackgroundColor (mpTheme->GetColor(Theme::Color_Background));
362cdf0e10cSrcweir const sal_Int32 nBackgroundLuminance (aBackgroundColor.GetLuminance());
363cdf0e10cSrcweir // When the background color is black then this is interpreted as
364cdf0e10cSrcweir // high contrast mode and the font color is set to white.
365cdf0e10cSrcweir if (nBackgroundLuminance == 0)
366cdf0e10cSrcweir aPageNumberColor = Color(mpTheme->GetColor(Theme::Color_PageNumberHighContrast));
367cdf0e10cSrcweir else
368cdf0e10cSrcweir {
369cdf0e10cSrcweir // Compare luminance of default page number color and background
370cdf0e10cSrcweir // color. When the two are similar then use a darker
371cdf0e10cSrcweir // (preferred) or brighter font color.
372cdf0e10cSrcweir const sal_Int32 nFontLuminance (aPageNumberColor.GetLuminance());
373cdf0e10cSrcweir if (abs(nBackgroundLuminance - nFontLuminance) < 60)
374cdf0e10cSrcweir {
375cdf0e10cSrcweir if (nBackgroundLuminance > nFontLuminance-30)
376cdf0e10cSrcweir aPageNumberColor = Color(mpTheme->GetColor(Theme::Color_PageNumberBrightBackground));
377cdf0e10cSrcweir else
378cdf0e10cSrcweir aPageNumberColor = Color(mpTheme->GetColor(Theme::Color_PageNumberDarkBackground));
379cdf0e10cSrcweir }
380cdf0e10cSrcweir }
381cdf0e10cSrcweir }
382cdf0e10cSrcweir
383cdf0e10cSrcweir // Paint the page number.
384cdf0e10cSrcweir OSL_ASSERT(rpDescriptor->GetPage()!=NULL);
385cdf0e10cSrcweir const sal_Int32 nPageNumber ((rpDescriptor->GetPage()->GetPageNum() - 1) / 2 + 1);
386cdf0e10cSrcweir const String sPageNumber (String::CreateFromInt32(nPageNumber));
387cdf0e10cSrcweir rDevice.SetFont(*mpPageNumberFont);
388cdf0e10cSrcweir rDevice.SetTextColor(aPageNumberColor);
389cdf0e10cSrcweir rDevice.DrawText(aBox, sPageNumber, TEXT_DRAW_RIGHT | TEXT_DRAW_VCENTER);
390cdf0e10cSrcweir }
391cdf0e10cSrcweir
392cdf0e10cSrcweir
393cdf0e10cSrcweir
394cdf0e10cSrcweir
PaintTransitionEffect(OutputDevice & rDevice,const model::SharedPageDescriptor & rpDescriptor) const395cdf0e10cSrcweir void PageObjectPainter::PaintTransitionEffect (
396cdf0e10cSrcweir OutputDevice& rDevice,
397cdf0e10cSrcweir const model::SharedPageDescriptor& rpDescriptor) const
398cdf0e10cSrcweir {
399cdf0e10cSrcweir const SdPage* pPage = rpDescriptor->GetPage();
400cdf0e10cSrcweir if (pPage!=NULL && pPage->getTransitionType() > 0)
401cdf0e10cSrcweir {
402cdf0e10cSrcweir const Rectangle aBox (mpPageObjectLayouter->GetBoundingBox(
403cdf0e10cSrcweir rpDescriptor,
404cdf0e10cSrcweir PageObjectLayouter::TransitionEffectIndicator,
405cdf0e10cSrcweir PageObjectLayouter::ModelCoordinateSystem));
406cdf0e10cSrcweir
407cdf0e10cSrcweir rDevice.DrawBitmapEx(
408cdf0e10cSrcweir aBox.TopLeft(),
409cdf0e10cSrcweir mpPageObjectLayouter->GetTransitionEffectIcon().GetBitmapEx());
410cdf0e10cSrcweir }
411cdf0e10cSrcweir }
412cdf0e10cSrcweir
413cdf0e10cSrcweir
414cdf0e10cSrcweir
415cdf0e10cSrcweir
GetBackgroundForState(const model::SharedPageDescriptor & rpDescriptor,const OutputDevice & rReferenceDevice)416cdf0e10cSrcweir Bitmap& PageObjectPainter::GetBackgroundForState (
417cdf0e10cSrcweir const model::SharedPageDescriptor& rpDescriptor,
418cdf0e10cSrcweir const OutputDevice& rReferenceDevice)
419cdf0e10cSrcweir {
420cdf0e10cSrcweir enum State { None = 0x00, Selected = 0x01, MouseOver = 0x02, Focused = 0x04 };
421cdf0e10cSrcweir const int eState =
422cdf0e10cSrcweir (rpDescriptor->HasState(model::PageDescriptor::ST_Selected) ? Selected : None)
423cdf0e10cSrcweir | (rpDescriptor->HasState(model::PageDescriptor::ST_MouseOver) ? MouseOver : None)
424cdf0e10cSrcweir | (rpDescriptor->HasState(model::PageDescriptor::ST_Focused) ? Focused : None);
425cdf0e10cSrcweir
426cdf0e10cSrcweir switch (eState)
427cdf0e10cSrcweir {
428cdf0e10cSrcweir case MouseOver | Selected | Focused:
429cdf0e10cSrcweir return GetBackground(
430cdf0e10cSrcweir maMouseOverSelectedAndFocusedBackground,
431cdf0e10cSrcweir Theme::Gradient_MouseOverSelectedAndFocusedPage,
432cdf0e10cSrcweir rReferenceDevice,
433cdf0e10cSrcweir true);
434cdf0e10cSrcweir
435cdf0e10cSrcweir case MouseOver | Selected:
436cdf0e10cSrcweir case MouseOver:
437cdf0e10cSrcweir return GetBackground(
438cdf0e10cSrcweir maMouseOverBackground,
439cdf0e10cSrcweir Theme::Gradient_MouseOverPage,
440cdf0e10cSrcweir rReferenceDevice,
441cdf0e10cSrcweir false);
442cdf0e10cSrcweir
443cdf0e10cSrcweir case MouseOver | Focused:
444cdf0e10cSrcweir return GetBackground(
445cdf0e10cSrcweir maMouseOverFocusedBackground,
446cdf0e10cSrcweir Theme::Gradient_MouseOverPage,
447cdf0e10cSrcweir rReferenceDevice,
448cdf0e10cSrcweir true);
449cdf0e10cSrcweir
450cdf0e10cSrcweir case Selected | Focused:
451cdf0e10cSrcweir return GetBackground(
452cdf0e10cSrcweir maFocusedSelectionBackground,
453cdf0e10cSrcweir Theme::Gradient_SelectedAndFocusedPage,
454cdf0e10cSrcweir rReferenceDevice,
455cdf0e10cSrcweir true);
456cdf0e10cSrcweir
457cdf0e10cSrcweir case Selected:
458cdf0e10cSrcweir return GetBackground(
459cdf0e10cSrcweir maSelectionBackground,
460cdf0e10cSrcweir Theme::Gradient_SelectedPage,
461cdf0e10cSrcweir rReferenceDevice,
462cdf0e10cSrcweir false);
463cdf0e10cSrcweir
464cdf0e10cSrcweir case Focused:
465cdf0e10cSrcweir return GetBackground(
466cdf0e10cSrcweir maFocusedBackground,
467cdf0e10cSrcweir Theme::Gradient_FocusedPage,
468cdf0e10cSrcweir rReferenceDevice,
469cdf0e10cSrcweir true);
470cdf0e10cSrcweir
471cdf0e10cSrcweir case None:
472cdf0e10cSrcweir default:
473cdf0e10cSrcweir return GetBackground(
474cdf0e10cSrcweir maNormalBackground,
475cdf0e10cSrcweir Theme::Gradient_NormalPage,
476cdf0e10cSrcweir rReferenceDevice,
477cdf0e10cSrcweir false);
478cdf0e10cSrcweir }
479cdf0e10cSrcweir }
480cdf0e10cSrcweir
481cdf0e10cSrcweir
482cdf0e10cSrcweir
483cdf0e10cSrcweir
GetBackground(Bitmap & rBackground,Theme::GradientColorType eType,const OutputDevice & rReferenceDevice,const bool bHasFocusBorder)484cdf0e10cSrcweir Bitmap& PageObjectPainter::GetBackground(
485cdf0e10cSrcweir Bitmap& rBackground,
486cdf0e10cSrcweir Theme::GradientColorType eType,
487cdf0e10cSrcweir const OutputDevice& rReferenceDevice,
488cdf0e10cSrcweir const bool bHasFocusBorder)
489cdf0e10cSrcweir {
490cdf0e10cSrcweir if (rBackground.IsEmpty())
491cdf0e10cSrcweir rBackground = CreateBackgroundBitmap(rReferenceDevice, eType, bHasFocusBorder);
492cdf0e10cSrcweir return rBackground;
493cdf0e10cSrcweir }
494cdf0e10cSrcweir
495cdf0e10cSrcweir
496cdf0e10cSrcweir
497cdf0e10cSrcweir
CreateBackgroundBitmap(const OutputDevice & rReferenceDevice,const Theme::GradientColorType eColorType,const bool bHasFocusBorder) const498cdf0e10cSrcweir Bitmap PageObjectPainter::CreateBackgroundBitmap(
499cdf0e10cSrcweir const OutputDevice& rReferenceDevice,
500cdf0e10cSrcweir const Theme::GradientColorType eColorType,
501cdf0e10cSrcweir const bool bHasFocusBorder) const
502cdf0e10cSrcweir {
503cdf0e10cSrcweir const Size aSize (mpPageObjectLayouter->GetSize(
504cdf0e10cSrcweir PageObjectLayouter::FocusIndicator,
505cdf0e10cSrcweir PageObjectLayouter::WindowCoordinateSystem));
506cdf0e10cSrcweir const Rectangle aPageObjectBox (mpPageObjectLayouter->GetBoundingBox(
507cdf0e10cSrcweir Point(0,0),
508cdf0e10cSrcweir PageObjectLayouter::PageObject,
509cdf0e10cSrcweir PageObjectLayouter::ModelCoordinateSystem));
510cdf0e10cSrcweir VirtualDevice aBitmapDevice (rReferenceDevice);
511cdf0e10cSrcweir aBitmapDevice.SetOutputSizePixel(aSize);
512cdf0e10cSrcweir
513cdf0e10cSrcweir // Fill the background with the background color of the slide sorter.
514cdf0e10cSrcweir const Color aBackgroundColor (mpTheme->GetColor(Theme::Color_Background));
515cdf0e10cSrcweir aBitmapDevice.SetFillColor(aBackgroundColor);
516cdf0e10cSrcweir aBitmapDevice.SetLineColor(aBackgroundColor);
517cdf0e10cSrcweir aBitmapDevice.DrawRect(Rectangle(Point(0,0), aSize));
518cdf0e10cSrcweir
519cdf0e10cSrcweir // Paint the slide area with a linear gradient that starts some pixels
520cdf0e10cSrcweir // below the top and ends some pixels above the bottom.
521cdf0e10cSrcweir const Color aTopColor(mpTheme->GetGradientColor(eColorType, Theme::Fill1));
522cdf0e10cSrcweir const Color aBottomColor(mpTheme->GetGradientColor(eColorType, Theme::Fill2));
523cdf0e10cSrcweir if (aTopColor != aBottomColor)
524cdf0e10cSrcweir {
525cdf0e10cSrcweir const sal_Int32 nHeight (aPageObjectBox.GetHeight());
526cdf0e10cSrcweir const sal_Int32 nDefaultConstantSize(nHeight/4);
527cdf0e10cSrcweir const sal_Int32 nMinimalGradientSize(40);
528cdf0e10cSrcweir const sal_Int32 nY1 (
529cdf0e10cSrcweir ::std::max<sal_Int32>(
530cdf0e10cSrcweir 0,
531cdf0e10cSrcweir ::std::min<sal_Int32>(
532cdf0e10cSrcweir nDefaultConstantSize,
533cdf0e10cSrcweir (nHeight - nMinimalGradientSize)/2)));
534cdf0e10cSrcweir const sal_Int32 nY2 (nHeight-nY1);
535cdf0e10cSrcweir const sal_Int32 nTop (aPageObjectBox.Top());
536cdf0e10cSrcweir for (sal_Int32 nY=0; nY<nHeight; ++nY)
537cdf0e10cSrcweir {
538cdf0e10cSrcweir if (nY<=nY1)
539cdf0e10cSrcweir aBitmapDevice.SetLineColor(aTopColor);
540cdf0e10cSrcweir else if (nY>=nY2)
541cdf0e10cSrcweir aBitmapDevice.SetLineColor(aBottomColor);
542cdf0e10cSrcweir else
543cdf0e10cSrcweir {
544cdf0e10cSrcweir Color aColor (aTopColor);
545cdf0e10cSrcweir aColor.Merge(aBottomColor, 255 * (nY2-nY) / (nY2-nY1));
546cdf0e10cSrcweir aBitmapDevice.SetLineColor(aColor);
547cdf0e10cSrcweir }
548cdf0e10cSrcweir aBitmapDevice.DrawLine(
549cdf0e10cSrcweir Point(aPageObjectBox.Left(), nY+nTop),
550cdf0e10cSrcweir Point(aPageObjectBox.Right(), nY+nTop));
551cdf0e10cSrcweir }
552cdf0e10cSrcweir }
553cdf0e10cSrcweir else
554cdf0e10cSrcweir {
555cdf0e10cSrcweir aBitmapDevice.SetFillColor(aTopColor);
556cdf0e10cSrcweir aBitmapDevice.DrawRect(aPageObjectBox);
557cdf0e10cSrcweir }
558cdf0e10cSrcweir
559cdf0e10cSrcweir // Paint the simple border and, for some backgrounds, the focus border.
560cdf0e10cSrcweir if (bHasFocusBorder)
561cdf0e10cSrcweir mpFocusBorderPainter->PaintFrame(aBitmapDevice, aPageObjectBox);
562cdf0e10cSrcweir else
563cdf0e10cSrcweir PaintBorder(aBitmapDevice, eColorType, aPageObjectBox);
564cdf0e10cSrcweir
565cdf0e10cSrcweir // Get bounding box of the preview around which a shadow is painted.
566cdf0e10cSrcweir // Compensate for the border around the preview.
567cdf0e10cSrcweir const Rectangle aBox (mpPageObjectLayouter->GetBoundingBox(
568cdf0e10cSrcweir Point(0,0),
569cdf0e10cSrcweir PageObjectLayouter::Preview,
570cdf0e10cSrcweir PageObjectLayouter::ModelCoordinateSystem));
571cdf0e10cSrcweir Rectangle aFrameBox (aBox.Left()-1,aBox.Top()-1,aBox.Right()+1,aBox.Bottom()+1);
572cdf0e10cSrcweir mpShadowPainter->PaintFrame(aBitmapDevice, aFrameBox);
573cdf0e10cSrcweir
574cdf0e10cSrcweir return aBitmapDevice.GetBitmap (Point(0,0),aSize);
575cdf0e10cSrcweir }
576cdf0e10cSrcweir
577cdf0e10cSrcweir
578cdf0e10cSrcweir
579cdf0e10cSrcweir
PaintBorder(OutputDevice & rDevice,const Theme::GradientColorType eColorType,const Rectangle & rBox) const580cdf0e10cSrcweir void PageObjectPainter::PaintBorder (
581cdf0e10cSrcweir OutputDevice& rDevice,
582cdf0e10cSrcweir const Theme::GradientColorType eColorType,
583cdf0e10cSrcweir const Rectangle& rBox) const
584cdf0e10cSrcweir {
585cdf0e10cSrcweir rDevice.SetFillColor();
586cdf0e10cSrcweir const sal_Int32 nBorderWidth (1);
587cdf0e10cSrcweir for (int nIndex=0; nIndex<nBorderWidth; ++nIndex)
588cdf0e10cSrcweir {
589cdf0e10cSrcweir const int nDelta (nIndex);
590cdf0e10cSrcweir rDevice.SetLineColor(mpTheme->GetGradientColor(eColorType, Theme::Border2));
591cdf0e10cSrcweir rDevice.DrawLine(
592cdf0e10cSrcweir Point(rBox.Left()-nDelta, rBox.Top()-nDelta),
593cdf0e10cSrcweir Point(rBox.Left()-nDelta, rBox.Bottom()+nDelta));
594cdf0e10cSrcweir rDevice.DrawLine(
595cdf0e10cSrcweir Point(rBox.Left()-nDelta, rBox.Bottom()+nDelta),
596cdf0e10cSrcweir Point(rBox.Right()+nDelta, rBox.Bottom()+nDelta));
597cdf0e10cSrcweir rDevice.DrawLine(
598cdf0e10cSrcweir Point(rBox.Right()+nDelta, rBox.Bottom()+nDelta),
599cdf0e10cSrcweir Point(rBox.Right()+nDelta, rBox.Top()-nDelta));
600cdf0e10cSrcweir
601cdf0e10cSrcweir rDevice.SetLineColor(mpTheme->GetGradientColor(eColorType, Theme::Border1));
602cdf0e10cSrcweir rDevice.DrawLine(
603cdf0e10cSrcweir Point(rBox.Left()-nDelta, rBox.Top()-nDelta),
604cdf0e10cSrcweir Point(rBox.Right()+nDelta, rBox.Top()-nDelta));
605cdf0e10cSrcweir }
606cdf0e10cSrcweir }
607cdf0e10cSrcweir
608cdf0e10cSrcweir
609cdf0e10cSrcweir
610cdf0e10cSrcweir } } } // end of namespace sd::slidesorter::view
611