Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "svx/XPropertyTable.hxx"
21 :
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>
30 :
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>
38 :
39 : using namespace com::sun::star;
40 :
41 : class impXGradientList
42 : {
43 : private:
44 : VirtualDevice* mpVirtualDevice;
45 : SdrModel* mpSdrModel;
46 : SdrObject* mpBackgroundObject;
47 :
48 : public:
49 0 : impXGradientList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB)
50 : : mpVirtualDevice(pV),
51 : mpSdrModel(pM),
52 0 : mpBackgroundObject(pB)
53 0 : {}
54 :
55 0 : ~impXGradientList()
56 : {
57 0 : delete mpVirtualDevice;
58 0 : SdrObject::Free(mpBackgroundObject);
59 0 : delete mpSdrModel;
60 0 : }
61 :
62 0 : VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
63 0 : SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
64 : };
65 :
66 0 : void XGradientList::impCreate()
67 : {
68 0 : if(!mpData)
69 : {
70 0 : const Point aZero(0, 0);
71 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
72 :
73 0 : VirtualDevice* pVirDev = new VirtualDevice;
74 : OSL_ENSURE(0 != pVirDev, "XGradientList: no VirtualDevice created!" );
75 0 : pVirDev->SetMapMode(MAP_100TH_MM);
76 0 : const Size aSize(pVirDev->PixelToLogic(Size(BITMAP_WIDTH, BITMAP_HEIGHT)));
77 0 : pVirDev->SetOutputSize(aSize);
78 0 : pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
79 : ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
80 0 : : DRAWMODE_DEFAULT);
81 :
82 0 : SdrModel* pSdrModel = new SdrModel();
83 : OSL_ENSURE(0 != pSdrModel, "XGradientList: no SdrModel created!" );
84 0 : pSdrModel->GetItemPool().FreezeIdRanges();
85 :
86 0 : const Size aSinglePixel(pVirDev->PixelToLogic(Size(1, 1)));
87 0 : const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight()));
88 0 : SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
89 : OSL_ENSURE(0 != pBackgroundObject, "XGradientList: no BackgroundObject created!" );
90 0 : pBackgroundObject->SetModel(pSdrModel);
91 0 : pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT));
92 0 : pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID));
93 0 : pBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK)));
94 0 : pBackgroundObject->SetMergedItem(XGradientStepCountItem(sal_uInt16((BITMAP_WIDTH + BITMAP_HEIGHT) / 3)));
95 :
96 0 : mpData = new impXGradientList(pVirDev, pSdrModel, pBackgroundObject);
97 : OSL_ENSURE(0 != mpData, "XGradientList: data creation went wrong!" );
98 : }
99 0 : }
100 :
101 0 : void XGradientList::impDestroy()
102 : {
103 0 : if(mpData)
104 : {
105 0 : delete mpData;
106 0 : mpData = 0;
107 : }
108 0 : }
109 :
110 363 : XGradientList::XGradientList( const String& rPath, XOutdevItemPool* pInPool ) :
111 : XPropertyList( XGRADIENT_LIST, rPath, pInPool ),
112 363 : mpData( NULL )
113 : {
114 363 : pBmpList = new BitmapList_impl();
115 363 : }
116 :
117 546 : XGradientList::~XGradientList()
118 : {
119 182 : if(mpData)
120 : {
121 0 : delete mpData;
122 0 : mpData = 0;
123 : }
124 364 : }
125 :
126 0 : XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex )
127 : {
128 0 : return( (XGradientEntry*) XPropertyList::Replace( pEntry, nIndex ) );
129 : }
130 :
131 0 : XGradientEntry* XGradientList::Remove(long nIndex)
132 : {
133 0 : return( (XGradientEntry*) XPropertyList::Remove( nIndex ) );
134 : }
135 :
136 0 : XGradientEntry* XGradientList::GetGradient(long nIndex) const
137 : {
138 0 : return( (XGradientEntry*) XPropertyList::Get( nIndex, 0 ) );
139 : }
140 :
141 3 : uno::Reference< container::XNameContainer > XGradientList::createInstance()
142 : {
143 : return uno::Reference< container::XNameContainer >(
144 : SvxUnoXGradientTable_createInstance( this ),
145 3 : uno::UNO_QUERY );
146 : }
147 :
148 1 : sal_Bool XGradientList::Create()
149 : {
150 1 : XubString aStr( SVX_RES( RID_SVXSTR_GRADIENT ) );
151 : xub_StrLen nLen;
152 :
153 1 : aStr.AppendAscii(" 1");
154 1 : nLen = aStr.Len() - 1;
155 1 : Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK ),RGB_Color(COL_WHITE ),XGRAD_LINEAR , 0,10,10, 0,100,100),aStr));
156 1 : aStr.SetChar(nLen, sal_Unicode('2'));
157 1 : Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE ),RGB_Color(COL_RED ),XGRAD_AXIAL , 300,20,20,10,100,100),aStr));
158 1 : aStr.SetChar(nLen, sal_Unicode('3'));
159 1 : Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED ),RGB_Color(COL_YELLOW ),XGRAD_RADIAL , 600,30,30,20,100,100),aStr));
160 1 : aStr.SetChar(nLen, sal_Unicode('4'));
161 1 : Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN ),XGRAD_ELLIPTICAL, 900,40,40,30,100,100),aStr));
162 1 : aStr.SetChar(nLen, sal_Unicode('5'));
163 1 : Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN ),RGB_Color(COL_MAGENTA),XGRAD_SQUARE , 1200,50,50,40,100,100),aStr));
164 1 : aStr.SetChar(nLen, sal_Unicode('6'));
165 1 : Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),XGRAD_RECT , 1900,60,60,50,100,100),aStr));
166 :
167 1 : return( sal_True );
168 : }
169 :
170 0 : sal_Bool XGradientList::CreateBitmapsForUI()
171 : {
172 0 : impCreate();
173 :
174 0 : for( long i = 0; i < Count(); i++)
175 : {
176 0 : Bitmap* pBmp = CreateBitmapForUI( i, sal_False );
177 : DBG_ASSERT( pBmp, "XGradientList: Bitmap(UI) konnte nicht erzeugt werden!" );
178 :
179 0 : if( pBmp )
180 : {
181 0 : if ( (size_t)i < pBmpList->size() ) {
182 0 : pBmpList->insert( pBmpList->begin() + i, pBmp );
183 : } else {
184 0 : pBmpList->push_back( pBmp );
185 : }
186 : }
187 : }
188 :
189 0 : impDestroy();
190 :
191 0 : return( sal_False );
192 : }
193 :
194 0 : Bitmap* XGradientList::CreateBitmapForUI( long nIndex, sal_Bool bDelete )
195 : {
196 0 : impCreate();
197 0 : VirtualDevice* pVD = mpData->getVirtualDevice();
198 0 : SdrObject* pBackgroundObject = mpData->getBackgroundObject();
199 :
200 0 : pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT));
201 0 : pBackgroundObject->SetMergedItem(XFillGradientItem(GetGradient(nIndex)->GetGradient()));
202 :
203 0 : sdr::contact::SdrObjectVector aObjectVector;
204 0 : aObjectVector.push_back(pBackgroundObject);
205 0 : sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
206 0 : sdr::contact::DisplayInfo aDisplayInfo;
207 :
208 0 : aPainter.ProcessDisplay(aDisplayInfo);
209 :
210 0 : const Point aZero(0, 0);
211 0 : Bitmap* pBitmap = new Bitmap(pVD->GetBitmap(aZero, pVD->GetOutputSize()));
212 :
213 0 : if(bDelete)
214 : {
215 0 : impDestroy();
216 : }
217 :
218 0 : return pBitmap;
219 : }
220 :
221 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|