1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 // include --------------------------------------------------------------- 28 29 #ifndef SVX_LIGHT 30 31 #include <com/sun/star/container/XNameContainer.hpp> 32 #include "svx/XPropertyTable.hxx" 33 #include <unotools/ucbstreamhelper.hxx> 34 35 #include "xmlxtexp.hxx" 36 #include "xmlxtimp.hxx" 37 38 #endif 39 40 #include <tools/urlobj.hxx> 41 #include <vcl/virdev.hxx> 42 #include <svl/itemset.hxx> 43 #include <sfx2/docfile.hxx> 44 #include <svx/dialogs.hrc> 45 #include <svx/dialmgr.hxx> 46 #include <svx/xtable.hxx> 47 #include <svx/xpool.hxx> 48 #include <svx/xfillit0.hxx> 49 #include <svx/xflgrit.hxx> 50 51 #include <svx/svdorect.hxx> 52 #include <svx/svdmodel.hxx> 53 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx> 54 #include <svx/sdr/contact/displayinfo.hxx> 55 #include <vcl/svapp.hxx> 56 #include <svx/xlnclit.hxx> 57 #include <svx/xgrscit.hxx> 58 59 #define GLOBALOVERFLOW 60 61 using namespace com::sun::star; 62 using namespace rtl; 63 64 sal_Unicode const pszExtGradient[] = {'s','o','g'}; 65 66 char const aChckGradient[] = { 0x04, 0x00, 'S','O','G','L'}; // < 5.2 67 char const aChckGradient0[] = { 0x04, 0x00, 'S','O','G','0'}; // = 5.2 68 char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0 69 70 // -------------------- 71 // class XGradientList 72 // -------------------- 73 74 class impXGradientList 75 { 76 private: 77 VirtualDevice* mpVirtualDevice; 78 SdrModel* mpSdrModel; 79 SdrObject* mpBackgroundObject; 80 81 public: 82 impXGradientList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB) 83 : mpVirtualDevice(pV), 84 mpSdrModel(pM), 85 mpBackgroundObject(pB) 86 {} 87 88 ~impXGradientList() 89 { 90 delete mpVirtualDevice; 91 SdrObject::Free(mpBackgroundObject); 92 delete mpSdrModel; 93 } 94 95 VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; } 96 SdrObject* getBackgroundObject() const { return mpBackgroundObject; } 97 }; 98 99 void XGradientList::impCreate() 100 { 101 if(!mpData) 102 { 103 const Point aZero(0, 0); 104 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 105 106 VirtualDevice* pVirDev = new VirtualDevice; 107 OSL_ENSURE(0 != pVirDev, "XGradientList: no VirtualDevice created!" ); 108 pVirDev->SetMapMode(MAP_100TH_MM); 109 const Size aSize(pVirDev->PixelToLogic(Size(getUiBitmapWidth(), getUiBitmapHeight()))); 110 pVirDev->SetOutputSize(aSize); 111 pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode() 112 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 113 : DRAWMODE_DEFAULT); 114 pVirDev->SetBackground(rStyleSettings.GetFieldColor()); 115 116 SdrModel* pSdrModel = new SdrModel(); 117 OSL_ENSURE(0 != pSdrModel, "XGradientList: no SdrModel created!" ); 118 pSdrModel->GetItemPool().FreezeIdRanges(); 119 120 const Size aSinglePixel(pVirDev->PixelToLogic(Size(1, 1))); 121 const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight())); 122 SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize); 123 OSL_ENSURE(0 != pBackgroundObject, "XGradientList: no BackgroundObject created!" ); 124 pBackgroundObject->SetModel(pSdrModel); 125 pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT)); 126 pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID)); 127 pBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK))); 128 pBackgroundObject->SetMergedItem(XGradientStepCountItem(sal_uInt16((getUiBitmapWidth() + getUiBitmapHeight()) / 3))); 129 130 mpData = new impXGradientList(pVirDev, pSdrModel, pBackgroundObject); 131 OSL_ENSURE(0 != mpData, "XGradientList: data creation went wrong!" ); 132 } 133 } 134 135 void XGradientList::impDestroy() 136 { 137 if(mpData) 138 { 139 delete mpData; 140 mpData = 0; 141 } 142 } 143 144 XGradientList::XGradientList( const String& rPath, XOutdevItemPool* pInPool ) 145 : XPropertyList(rPath, pInPool ), 146 mpData(0) 147 { 148 } 149 150 XGradientList::~XGradientList() 151 { 152 if(mpData) 153 { 154 delete mpData; 155 mpData = 0; 156 } 157 } 158 159 XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex ) 160 { 161 return( (XGradientEntry*) XPropertyList::Replace( pEntry, nIndex ) ); 162 } 163 164 XGradientEntry* XGradientList::Remove(long nIndex) 165 { 166 return( (XGradientEntry*) XPropertyList::Remove( nIndex, 0 ) ); 167 } 168 169 XGradientEntry* XGradientList::GetGradient(long nIndex) const 170 { 171 return( (XGradientEntry*) XPropertyList::Get( nIndex, 0 ) ); 172 } 173 174 sal_Bool XGradientList::Load() 175 { 176 if( mbListDirty ) 177 { 178 mbListDirty = false; 179 180 INetURLObject aURL( maPath ); 181 182 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 183 { 184 DBG_ASSERT( !maPath.Len(), "invalid URL" ); 185 return sal_False; 186 } 187 188 aURL.Append( maName ); 189 190 if( !aURL.getExtension().getLength() ) 191 aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) ); 192 193 uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY ); 194 return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 195 196 } 197 return( sal_False ); 198 } 199 200 sal_Bool XGradientList::Save() 201 { 202 INetURLObject aURL( maPath ); 203 204 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 205 { 206 DBG_ASSERT( !maPath.Len(), "invalid URL" ); 207 return sal_False; 208 } 209 210 aURL.Append( maName ); 211 212 if( !aURL.getExtension().getLength() ) 213 aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) ); 214 215 uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY ); 216 return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 217 } 218 219 sal_Bool XGradientList::Create() 220 { 221 XubString aStr( SVX_RES( RID_SVXSTR_GRADIENT ) ); 222 xub_StrLen nLen; 223 224 aStr.AppendAscii(" 1"); 225 nLen = aStr.Len() - 1; 226 Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK ),RGB_Color(COL_WHITE ),XGRAD_LINEAR , 0,10,10, 0,100,100),aStr)); 227 aStr.SetChar(nLen, sal_Unicode('2')); 228 Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE ),RGB_Color(COL_RED ),XGRAD_AXIAL , 300,20,20,10,100,100),aStr)); 229 aStr.SetChar(nLen, sal_Unicode('3')); 230 Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED ),RGB_Color(COL_YELLOW ),XGRAD_RADIAL , 600,30,30,20,100,100),aStr)); 231 aStr.SetChar(nLen, sal_Unicode('4')); 232 Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN ),XGRAD_ELLIPTICAL, 900,40,40,30,100,100),aStr)); 233 aStr.SetChar(nLen, sal_Unicode('5')); 234 Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN ),RGB_Color(COL_MAGENTA),XGRAD_SQUARE , 1200,50,50,40,100,100),aStr)); 235 aStr.SetChar(nLen, sal_Unicode('6')); 236 Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),XGRAD_RECT , 1900,60,60,50,100,100),aStr)); 237 238 return( sal_True ); 239 } 240 241 Bitmap XGradientList::CreateBitmapForUI( long nIndex ) 242 { 243 impCreate(); 244 VirtualDevice* pVD = mpData->getVirtualDevice(); 245 SdrObject* pBackgroundObject = mpData->getBackgroundObject(); 246 247 const SfxItemSet& rItemSet = pBackgroundObject->GetMergedItemSet(); 248 pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT)); 249 pBackgroundObject->SetMergedItem(XFillGradientItem(rItemSet.GetPool(), GetGradient(nIndex)->GetGradient())); 250 251 sdr::contact::SdrObjectVector aObjectVector; 252 aObjectVector.push_back(pBackgroundObject); 253 sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0); 254 sdr::contact::DisplayInfo aDisplayInfo; 255 256 pVD->Erase(); 257 aPainter.ProcessDisplay(aDisplayInfo); 258 259 const Point aZero(0, 0); 260 return pVD->GetBitmap(aZero, pVD->GetOutputSize()); 261 } 262 263 ////////////////////////////////////////////////////////////////////////////// 264 // eof 265