1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <XPropertyTable.hxx>
22 #include <osl/diagnose.h>
23 #include <vcl/virdev.hxx>
24 #include <svx/xtable.hxx>
25 #include <vcl/bitmapex.hxx>
26 #include <vcl/settings.hxx>
27 #include <vcl/svapp.hxx>
29 using namespace com::sun::star
;
31 XBitmapEntry
* XBitmapList::GetBitmap(tools::Long nIndex
) const
33 return static_cast<XBitmapEntry
*>( XPropertyList::Get(nIndex
) );
36 uno::Reference
< container::XNameContainer
> XBitmapList::createInstance()
38 return SvxUnoXBitmapTable_createInstance( *this );
41 bool XBitmapList::Create()
46 BitmapEx
XBitmapList::CreateBitmap( tools::Long nIndex
, const Size
& rSize
) const
48 OSL_ENSURE( nIndex
< Count(), "Access out of range" );
52 BitmapEx rBitmapEx
= GetBitmap( nIndex
)->GetGraphicObject().GetGraphic().GetBitmapEx();
53 ScopedVclPtrInstance
< VirtualDevice
> pVirtualDevice
;
54 pVirtualDevice
->SetOutputSizePixel(rSize
);
56 if(rBitmapEx
.IsAlpha())
58 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
60 if(rStyleSettings
.GetPreviewUsesCheckeredBackground())
62 const Point
aNull(0, 0);
63 static const sal_uInt32
nLen(8);
64 static const Color
aW(COL_WHITE
);
65 static const Color
aG(0xef, 0xef, 0xef);
67 pVirtualDevice
->DrawCheckered(aNull
, rSize
, nLen
, aW
, aG
);
71 pVirtualDevice
->SetBackground(rStyleSettings
.GetFieldColor());
72 pVirtualDevice
->Erase();
76 if(rBitmapEx
.GetSizePixel().Width() >= rSize
.Width() && rBitmapEx
.GetSizePixel().Height() >= rSize
.Height())
78 rBitmapEx
.Scale(rSize
);
79 pVirtualDevice
->DrawBitmapEx(Point(0, 0), rBitmapEx
);
83 const Size
aBitmapSize(rBitmapEx
.GetSizePixel());
85 for(tools::Long
y(0); y
< rSize
.Height(); y
+= aBitmapSize
.Height())
87 for(tools::Long
x(0); x
< rSize
.Width(); x
+= aBitmapSize
.Width())
89 pVirtualDevice
->DrawBitmapEx(
95 rBitmapEx
= pVirtualDevice
->GetBitmapEx(Point(0, 0), rSize
);
102 BitmapEx
XBitmapList::CreateBitmapForUI( tools::Long nIndex
)
104 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
105 const Size
& rSize
= rStyleSettings
.GetListBoxPreviewDefaultPixelSize();
106 return CreateBitmap(nIndex
, rSize
);
109 BitmapEx
XBitmapList::GetBitmapForPreview( tools::Long nIndex
, const Size
& rSize
)
111 return CreateBitmap(nIndex
, rSize
);
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */