1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sfx2.hxx" 30 31 #include <sot/object.hxx> 32 #include <tools/stream.hxx> 33 #include <vcl/splitwin.hxx> 34 #include <svl/itemset.hxx> 35 #ifndef GCC 36 #endif 37 38 #include <sfx2/frmdescr.hxx> 39 #include <sfx2/app.hxx> 40 41 DBG_NAME(SfxFrameDescriptor); 42 43 #define VERSION (sal_uInt16) 3 44 45 struct SfxFrameDescriptor_Impl 46 { 47 Wallpaper* pWallpaper; 48 SfxItemSet* pArgs; 49 sal_Bool bEditable; 50 51 SfxFrameDescriptor_Impl() : pWallpaper( NULL ), pArgs( NULL ), bEditable( sal_True ) {} 52 ~SfxFrameDescriptor_Impl() 53 { 54 delete pWallpaper; 55 delete pArgs; 56 } 57 }; 58 59 SfxFrameDescriptor::SfxFrameDescriptor() : 60 aMargin( -1, -1 ), 61 nWidth( 0L ), 62 eScroll( ScrollingAuto ), 63 eSizeSelector( SIZE_ABS ), 64 nHasBorder( BORDER_YES ), 65 nItemId( 0 ), 66 bResizeHorizontal( sal_True ), 67 bResizeVertical( sal_True ), 68 bHasUI( sal_True ), 69 bReadOnly( sal_False ) 70 { 71 DBG_CTOR(SfxFrameDescriptor, 0); 72 73 pImp = new SfxFrameDescriptor_Impl; 74 } 75 76 SfxFrameDescriptor::~SfxFrameDescriptor() 77 { 78 DBG_DTOR(SfxFrameDescriptor, 0); 79 delete pImp; 80 } 81 82 SfxItemSet* SfxFrameDescriptor::GetArgs() 83 { 84 if( !pImp->pArgs ) 85 pImp->pArgs = new SfxAllItemSet( SFX_APP()->GetPool() ); 86 return pImp->pArgs; 87 } 88 89 void SfxFrameDescriptor::SetURL( const String& rURL ) 90 { 91 aURL = INetURLObject(rURL); 92 SetActualURL( aURL ); 93 } 94 95 void SfxFrameDescriptor::SetURL( const INetURLObject& rURL ) 96 { 97 aURL = rURL.GetMainURL( INetURLObject::DECODE_TO_IURI ); 98 SetActualURL( aURL ); 99 } 100 101 void SfxFrameDescriptor::SetActualURL( const String& rURL ) 102 { 103 aActualURL = INetURLObject(rURL); 104 if ( pImp->pArgs ) 105 pImp->pArgs->ClearItem(); 106 } 107 108 void SfxFrameDescriptor::SetActualURL( const INetURLObject& rURL ) 109 { 110 SetActualURL(String(rURL.GetMainURL( INetURLObject::DECODE_TO_IURI ))); 111 } 112 113 void SfxFrameDescriptor::SetEditable( sal_Bool bSet ) 114 { 115 pImp->bEditable = bSet; 116 } 117 118 sal_Bool SfxFrameDescriptor::IsEditable() const 119 { 120 return pImp->bEditable; 121 } 122 123 sal_Bool SfxFrameDescriptor::CompareOriginal( SfxFrameDescriptor& rDescr ) const 124 { 125 if( aURL != rDescr.aURL ) 126 return sal_False; 127 else 128 return sal_True; 129 } 130 131 sal_Bool SfxFrameDescriptor::CheckContent() const 132 { 133 sal_Bool bRet = !( aURL == aActualURL ); 134 return bRet; 135 } 136 137 void SfxFrameDescriptor::UnifyContent( sal_Bool bTakeActual ) 138 { 139 if ( bTakeActual ) 140 aURL = aActualURL; 141 else 142 aActualURL = aURL; 143 } 144 145 SfxFrameDescriptor* SfxFrameDescriptor::Clone( sal_Bool bWithIds ) const 146 { 147 SfxFrameDescriptor *pFrame = new SfxFrameDescriptor; 148 149 pFrame->aURL = aURL; 150 pFrame->aActualURL = aActualURL; 151 pFrame->aName = aName; 152 pFrame->aMargin = aMargin; 153 pFrame->nWidth = nWidth; 154 pFrame->eSizeSelector = eSizeSelector; 155 pFrame->eScroll = eScroll; 156 pFrame->bResizeHorizontal = bResizeHorizontal; 157 pFrame->bResizeVertical = bResizeVertical; 158 pFrame->nHasBorder = nHasBorder; 159 pFrame->bHasUI = bHasUI; 160 pFrame->SetReadOnly( IsReadOnly() ); 161 pFrame->SetEditable( IsEditable() ); 162 if ( pImp->pWallpaper ) 163 pFrame->pImp->pWallpaper = new Wallpaper( *pImp->pWallpaper ); 164 if( pImp->pArgs ) 165 { 166 // Aktuell ist im Clone von SfxAllItemSets noch ein Bug... 167 pFrame->pImp->pArgs = new SfxAllItemSet( SFX_APP()->GetPool() ); 168 pFrame->pImp->pArgs->Put(*pImp->pArgs); 169 } 170 171 if ( bWithIds ) 172 pFrame->nItemId = nItemId; 173 else 174 pFrame->nItemId = 0; 175 176 return pFrame; 177 } 178 179 sal_uInt16 SfxFrameDescriptor::GetWinBits() const 180 { 181 sal_uInt16 nBits = 0; 182 if ( eSizeSelector == SIZE_REL ) 183 nBits |= SWIB_RELATIVESIZE; 184 if ( eSizeSelector == SIZE_PERCENT ) 185 nBits |= SWIB_PERCENTSIZE; 186 if ( !IsResizable() ) 187 nBits |= SWIB_FIXED; 188 if ( !nWidth ) 189 nBits |= SWIB_INVISIBLE; 190 return nBits; 191 } 192 193 sal_Bool SfxFrameDescriptor::HasFrameBorder() const 194 { 195 return (nHasBorder & BORDER_YES) != 0; 196 } 197 198 long SfxFrameDescriptor::GetSize() const 199 { 200 return nWidth; 201 } 202 203 void SfxFrameDescriptor::TakeProperties( const SfxFrameProperties& rProp ) 204 { 205 aURL = aActualURL = INetURLObject(rProp.aURL); 206 aName = rProp.aName; 207 aMargin.Width() = rProp.lMarginWidth; 208 aMargin.Height() = rProp.lMarginHeight; 209 nWidth = rProp.lSize; 210 eScroll = rProp.eScroll; 211 eSizeSelector = rProp.eSizeSelector; 212 nHasBorder = rProp.bHasBorder ? BORDER_YES : BORDER_NO; 213 if ( rProp.bBorderSet ) 214 nHasBorder |= BORDER_SET; 215 bResizeHorizontal = bResizeVertical = rProp.bResizable; 216 } 217 218 void SfxFrameDescriptor::SetWallpaper( const Wallpaper& rWallpaper ) 219 { 220 DELETEZ( pImp->pWallpaper ); 221 222 if ( rWallpaper.GetStyle() != WALLPAPER_NULL ) 223 pImp->pWallpaper = new Wallpaper( rWallpaper ); 224 } 225 226 const Wallpaper* SfxFrameDescriptor::GetWallpaper() const 227 { 228 return pImp->pWallpaper; 229 } 230 231 sal_uInt16 SfxFrameDescriptor::GetItemPos() const 232 { 233 return USHRT_MAX; 234 } 235 236 237 SfxFrameProperties::SfxFrameProperties( const SfxFrameDescriptor *pD ) 238 : aURL( pD->GetURL().GetMainURL( INetURLObject::DECODE_TO_IURI ) ) 239 , aName( pD->GetName() ) 240 , lMarginWidth( pD->GetMargin().Width() ) 241 , lMarginHeight( pD->GetMargin().Height() ) 242 , lSize( pD->GetWidth() ) 243 , lSetSize( SIZE_NOT_SET ) 244 , lFrameSpacing( SPACING_NOT_SET ) 245 , lInheritedFrameSpacing( SPACING_NOT_SET ) 246 , eScroll( pD->GetScrollingMode() ) 247 , eSizeSelector( pD->GetSizeSelector() ) 248 , eSetSizeSelector( SIZE_REL ) 249 , bHasBorder( pD->HasFrameBorder() ) 250 , bBorderSet( pD->IsFrameBorderSet() ) 251 , bResizable( pD->IsResizable() ) 252 , bSetResizable( sal_False ) 253 , bIsRootSet( sal_False ) 254 , bIsInColSet( sal_False ) 255 , bHasBorderInherited( sal_False ) 256 , pFrame( pD->Clone() ) 257 { 258 bBorderSet = sal_True; 259 } 260 261 SfxFrameProperties& SfxFrameProperties::operator =( 262 const SfxFrameProperties &rProp ) 263 { 264 aURL = rProp.aURL; 265 aName = rProp.aName; 266 lMarginWidth = rProp.lMarginWidth; 267 lMarginHeight = rProp.lMarginHeight; 268 lSize = rProp.lSize; 269 lSetSize = rProp.lSetSize; 270 lFrameSpacing = rProp.lFrameSpacing; 271 lInheritedFrameSpacing = rProp.lInheritedFrameSpacing; 272 eScroll = rProp.eScroll; 273 eSizeSelector = rProp.eSizeSelector; 274 eSetSizeSelector = rProp.eSetSizeSelector; 275 bHasBorder = rProp.bHasBorder; 276 bBorderSet = rProp.bBorderSet; 277 bResizable = rProp.bResizable; 278 bSetResizable = rProp.bSetResizable; 279 bIsRootSet = rProp.bIsRootSet; 280 bIsInColSet = rProp.bIsInColSet; 281 bHasBorderInherited = rProp.bHasBorderInherited; 282 pFrame = rProp.pFrame->Clone(); 283 return *this; 284 } 285 286 int SfxFrameProperties::operator ==( const SfxFrameProperties& rProp ) const 287 { 288 return aURL == rProp.aURL && aName == rProp.aName && lMarginWidth == rProp.lMarginWidth && lMarginHeight == rProp.lMarginHeight && 289 lSize == rProp.lSize && eScroll == rProp.eScroll && eSizeSelector == rProp.eSizeSelector && 290 lSetSize == rProp.lSetSize && lFrameSpacing == rProp.lFrameSpacing && eSetSizeSelector == rProp.eSetSizeSelector && 291 bHasBorder == rProp.bHasBorder && bBorderSet == rProp.bBorderSet && 292 bResizable == rProp.bResizable && bSetResizable == rProp.bSetResizable; 293 } 294 295 TYPEINIT1(SfxFrameDescriptorItem, SfxPoolItem); 296 297 SfxFrameDescriptorItem::~SfxFrameDescriptorItem() 298 {} 299 300 int SfxFrameDescriptorItem::operator==( const SfxPoolItem& rAttr ) const 301 { 302 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" ); 303 304 return aProperties == ((SfxFrameDescriptorItem&)rAttr).aProperties; 305 } 306 307 // ----------------------------------------------------------------------- 308 309 SfxPoolItem* SfxFrameDescriptorItem::Clone( SfxItemPool* ) const 310 { 311 return new SfxFrameDescriptorItem( *this ); 312 } 313 314 //------------------------------------------------------------------------ 315 316 SfxItemPresentation SfxFrameDescriptorItem::GetPresentation 317 ( 318 SfxItemPresentation /*ePres*/, 319 SfxMapUnit /*eCoreUnit*/, 320 SfxMapUnit /*ePresUnit*/, 321 XubString& rText, 322 const IntlWrapper * 323 ) const 324 { 325 rText.Erase(); 326 return SFX_ITEM_PRESENTATION_NONE; 327 } 328 329 330