bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / xoutdev / xtabgrdt.cxx
blob5815678dacac3d29eb8cb9368ce82a316e08eaaa
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 .
20 #include "svx/XPropertyTable.hxx"
22 #include <vcl/virdev.hxx>
23 #include <svl/itemset.hxx>
24 #include <svx/dialogs.hrc>
25 #include <svx/dialmgr.hxx>
26 #include <svx/xtable.hxx>
27 #include <svx/xpool.hxx>
28 #include <svx/xfillit0.hxx>
29 #include <svx/xflgrit.hxx>
31 #include <svx/svdorect.hxx>
32 #include <svx/svdmodel.hxx>
33 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
34 #include <svx/sdr/contact/displayinfo.hxx>
35 #include <vcl/svapp.hxx>
36 #include <svx/xlnclit.hxx>
37 #include <svx/xgrscit.hxx>
39 using namespace com::sun::star;
41 class impXGradientList
43 private:
44 VirtualDevice* mpVirtualDevice;
45 SdrModel* mpSdrModel;
46 SdrObject* mpBackgroundObject;
48 public:
49 impXGradientList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB)
50 : mpVirtualDevice(pV),
51 mpSdrModel(pM),
52 mpBackgroundObject(pB)
55 ~impXGradientList()
57 delete mpVirtualDevice;
58 SdrObject::Free(mpBackgroundObject);
59 delete mpSdrModel;
62 VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
63 SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
66 void XGradientList::impCreate()
68 if(!mpData)
70 const Point aZero(0, 0);
71 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
73 VirtualDevice* pVirDev = new VirtualDevice;
74 OSL_ENSURE(0 != pVirDev, "XGradientList: no VirtualDevice created!" );
75 pVirDev->SetMapMode(MAP_100TH_MM);
76 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
77 const Size aSize(pVirDev->PixelToLogic(rSize));
78 pVirDev->SetOutputSize(aSize);
79 pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
80 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
81 : DRAWMODE_DEFAULT);
82 pVirDev->SetBackground(rStyleSettings.GetFieldColor());
84 SdrModel* pSdrModel = new SdrModel();
85 OSL_ENSURE(0 != pSdrModel, "XGradientList: no SdrModel created!" );
86 pSdrModel->GetItemPool().FreezeIdRanges();
88 const Size aSinglePixel(pVirDev->PixelToLogic(Size(1, 1)));
89 const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight()));
90 SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
91 OSL_ENSURE(0 != pBackgroundObject, "XGradientList: no BackgroundObject created!" );
92 pBackgroundObject->SetModel(pSdrModel);
93 pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT));
94 pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID));
95 pBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK)));
96 pBackgroundObject->SetMergedItem(XGradientStepCountItem(sal_uInt16((rSize.Width() + rSize.Height()) / 3)));
98 mpData = new impXGradientList(pVirDev, pSdrModel, pBackgroundObject);
99 OSL_ENSURE(0 != mpData, "XGradientList: data creation went wrong!" );
103 void XGradientList::impDestroy()
105 if(mpData)
107 delete mpData;
108 mpData = 0;
112 XGradientList::XGradientList( const String& rPath, XOutdevItemPool* pInPool )
113 : XPropertyList( XGRADIENT_LIST, rPath, pInPool ),
114 mpData(0)
118 XGradientList::~XGradientList()
120 if(mpData)
122 delete mpData;
123 mpData = 0;
127 XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex )
129 return( (XGradientEntry*) XPropertyList::Replace( pEntry, nIndex ) );
132 XGradientEntry* XGradientList::Remove(long nIndex)
134 return( (XGradientEntry*) XPropertyList::Remove( nIndex ) );
137 XGradientEntry* XGradientList::GetGradient(long nIndex) const
139 return( (XGradientEntry*) XPropertyList::Get( nIndex, 0 ) );
142 uno::Reference< container::XNameContainer > XGradientList::createInstance()
144 return uno::Reference< container::XNameContainer >(
145 SvxUnoXGradientTable_createInstance( this ),
146 uno::UNO_QUERY );
149 sal_Bool XGradientList::Create()
151 XubString aStr( SVX_RES( RID_SVXSTR_GRADIENT ) );
152 xub_StrLen nLen;
154 aStr.AppendAscii(" 1");
155 nLen = aStr.Len() - 1;
156 Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK ),RGB_Color(COL_WHITE ),XGRAD_LINEAR , 0,10,10, 0,100,100),aStr));
157 aStr.SetChar(nLen, sal_Unicode('2'));
158 Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE ),RGB_Color(COL_RED ),XGRAD_AXIAL , 300,20,20,10,100,100),aStr));
159 aStr.SetChar(nLen, sal_Unicode('3'));
160 Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED ),RGB_Color(COL_YELLOW ),XGRAD_RADIAL , 600,30,30,20,100,100),aStr));
161 aStr.SetChar(nLen, sal_Unicode('4'));
162 Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN ),XGRAD_ELLIPTICAL, 900,40,40,30,100,100),aStr));
163 aStr.SetChar(nLen, sal_Unicode('5'));
164 Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN ),RGB_Color(COL_MAGENTA),XGRAD_SQUARE , 1200,50,50,40,100,100),aStr));
165 aStr.SetChar(nLen, sal_Unicode('6'));
166 Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),XGRAD_RECT , 1900,60,60,50,100,100),aStr));
168 return( sal_True );
171 Bitmap XGradientList::CreateBitmapForUI( long nIndex )
173 impCreate();
174 VirtualDevice* pVD = mpData->getVirtualDevice();
175 SdrObject* pBackgroundObject = mpData->getBackgroundObject();
177 pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT));
178 pBackgroundObject->SetMergedItem(XFillGradientItem(GetGradient(nIndex)->GetGradient()));
180 sdr::contact::SdrObjectVector aObjectVector;
181 aObjectVector.push_back(pBackgroundObject);
182 sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
183 sdr::contact::DisplayInfo aDisplayInfo;
185 pVD->Erase();
186 aPainter.ProcessDisplay(aDisplayInfo);
188 const Point aZero(0, 0);
189 return pVD->GetBitmap(aZero, pVD->GetOutputSize());
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */