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_sfx2.hxx"
26
27 #include <sot/object.hxx>
28 #include <tools/stream.hxx>
29 #include <vcl/splitwin.hxx>
30 #include <svl/itemset.hxx>
31 #ifndef GCC
32 #endif
33
34 #include <sfx2/frmdescr.hxx>
35 #include <sfx2/app.hxx>
36
37 DBG_NAME(SfxFrameDescriptor);
38
39 #define VERSION (sal_uInt16) 3
40
41 struct SfxFrameDescriptor_Impl
42 {
43 Wallpaper* pWallpaper;
44 SfxItemSet* pArgs;
45 sal_Bool bEditable;
46
SfxFrameDescriptor_ImplSfxFrameDescriptor_Impl47 SfxFrameDescriptor_Impl() : pWallpaper( NULL ), pArgs( NULL ), bEditable( sal_True ) {}
~SfxFrameDescriptor_ImplSfxFrameDescriptor_Impl48 ~SfxFrameDescriptor_Impl()
49 {
50 delete pWallpaper;
51 delete pArgs;
52 }
53 };
54
SfxFrameDescriptor()55 SfxFrameDescriptor::SfxFrameDescriptor() :
56 aMargin( -1, -1 ),
57 nWidth( 0L ),
58 eScroll( ScrollingAuto ),
59 eSizeSelector( SIZE_ABS ),
60 nHasBorder( BORDER_YES ),
61 nItemId( 0 ),
62 bResizeHorizontal( sal_True ),
63 bResizeVertical( sal_True ),
64 bHasUI( sal_True ),
65 bReadOnly( sal_False )
66 {
67 DBG_CTOR(SfxFrameDescriptor, 0);
68
69 pImp = new SfxFrameDescriptor_Impl;
70 }
71
~SfxFrameDescriptor()72 SfxFrameDescriptor::~SfxFrameDescriptor()
73 {
74 DBG_DTOR(SfxFrameDescriptor, 0);
75 delete pImp;
76 }
77
GetArgs()78 SfxItemSet* SfxFrameDescriptor::GetArgs()
79 {
80 if( !pImp->pArgs )
81 pImp->pArgs = new SfxAllItemSet( SFX_APP()->GetPool() );
82 return pImp->pArgs;
83 }
84
SetURL(const String & rURL)85 void SfxFrameDescriptor::SetURL( const String& rURL )
86 {
87 aURL = INetURLObject(rURL);
88 SetActualURL( aURL );
89 }
90
SetURL(const INetURLObject & rURL)91 void SfxFrameDescriptor::SetURL( const INetURLObject& rURL )
92 {
93 aURL = rURL.GetMainURL( INetURLObject::DECODE_TO_IURI );
94 SetActualURL( aURL );
95 }
96
SetActualURL(const String & rURL)97 void SfxFrameDescriptor::SetActualURL( const String& rURL )
98 {
99 aActualURL = INetURLObject(rURL);
100 if ( pImp->pArgs )
101 pImp->pArgs->ClearItem();
102 }
103
SetActualURL(const INetURLObject & rURL)104 void SfxFrameDescriptor::SetActualURL( const INetURLObject& rURL )
105 {
106 SetActualURL(String(rURL.GetMainURL( INetURLObject::DECODE_TO_IURI )));
107 }
108
SetEditable(sal_Bool bSet)109 void SfxFrameDescriptor::SetEditable( sal_Bool bSet )
110 {
111 pImp->bEditable = bSet;
112 }
113
IsEditable() const114 sal_Bool SfxFrameDescriptor::IsEditable() const
115 {
116 return pImp->bEditable;
117 }
118
CompareOriginal(SfxFrameDescriptor & rDescr) const119 sal_Bool SfxFrameDescriptor::CompareOriginal( SfxFrameDescriptor& rDescr ) const
120 {
121 if( aURL != rDescr.aURL )
122 return sal_False;
123 else
124 return sal_True;
125 }
126
CheckContent() const127 sal_Bool SfxFrameDescriptor::CheckContent() const
128 {
129 sal_Bool bRet = !( aURL == aActualURL );
130 return bRet;
131 }
132
UnifyContent(sal_Bool bTakeActual)133 void SfxFrameDescriptor::UnifyContent( sal_Bool bTakeActual )
134 {
135 if ( bTakeActual )
136 aURL = aActualURL;
137 else
138 aActualURL = aURL;
139 }
140
Clone(sal_Bool bWithIds) const141 SfxFrameDescriptor* SfxFrameDescriptor::Clone( sal_Bool bWithIds ) const
142 {
143 SfxFrameDescriptor *pFrame = new SfxFrameDescriptor;
144
145 pFrame->aURL = aURL;
146 pFrame->aActualURL = aActualURL;
147 pFrame->aName = aName;
148 pFrame->aMargin = aMargin;
149 pFrame->nWidth = nWidth;
150 pFrame->eSizeSelector = eSizeSelector;
151 pFrame->eScroll = eScroll;
152 pFrame->bResizeHorizontal = bResizeHorizontal;
153 pFrame->bResizeVertical = bResizeVertical;
154 pFrame->nHasBorder = nHasBorder;
155 pFrame->bHasUI = bHasUI;
156 pFrame->SetReadOnly( IsReadOnly() );
157 pFrame->SetEditable( IsEditable() );
158 if ( pImp->pWallpaper )
159 pFrame->pImp->pWallpaper = new Wallpaper( *pImp->pWallpaper );
160 if( pImp->pArgs )
161 {
162 // Aktuell ist im Clone von SfxAllItemSets noch ein Bug...
163 pFrame->pImp->pArgs = new SfxAllItemSet( SFX_APP()->GetPool() );
164 pFrame->pImp->pArgs->Put(*pImp->pArgs);
165 }
166
167 if ( bWithIds )
168 pFrame->nItemId = nItemId;
169 else
170 pFrame->nItemId = 0;
171
172 return pFrame;
173 }
174
GetWinBits() const175 sal_uInt16 SfxFrameDescriptor::GetWinBits() const
176 {
177 sal_uInt16 nBits = 0;
178 if ( eSizeSelector == SIZE_REL )
179 nBits |= SWIB_RELATIVESIZE;
180 if ( eSizeSelector == SIZE_PERCENT )
181 nBits |= SWIB_PERCENTSIZE;
182 if ( !IsResizable() )
183 nBits |= SWIB_FIXED;
184 if ( !nWidth )
185 nBits |= SWIB_INVISIBLE;
186 return nBits;
187 }
188
HasFrameBorder() const189 sal_Bool SfxFrameDescriptor::HasFrameBorder() const
190 {
191 return (nHasBorder & BORDER_YES) != 0;
192 }
193
GetSize() const194 long SfxFrameDescriptor::GetSize() const
195 {
196 return nWidth;
197 }
198
TakeProperties(const SfxFrameProperties & rProp)199 void SfxFrameDescriptor::TakeProperties( const SfxFrameProperties& rProp )
200 {
201 aURL = aActualURL = INetURLObject(rProp.aURL);
202 aName = rProp.aName;
203 aMargin.Width() = rProp.lMarginWidth;
204 aMargin.Height() = rProp.lMarginHeight;
205 nWidth = rProp.lSize;
206 eScroll = rProp.eScroll;
207 eSizeSelector = rProp.eSizeSelector;
208 nHasBorder = rProp.bHasBorder ? BORDER_YES : BORDER_NO;
209 if ( rProp.bBorderSet )
210 nHasBorder |= BORDER_SET;
211 bResizeHorizontal = bResizeVertical = rProp.bResizable;
212 }
213
SetWallpaper(const Wallpaper & rWallpaper)214 void SfxFrameDescriptor::SetWallpaper( const Wallpaper& rWallpaper )
215 {
216 DELETEZ( pImp->pWallpaper );
217
218 if ( rWallpaper.GetStyle() != WALLPAPER_NULL )
219 pImp->pWallpaper = new Wallpaper( rWallpaper );
220 }
221
GetWallpaper() const222 const Wallpaper* SfxFrameDescriptor::GetWallpaper() const
223 {
224 return pImp->pWallpaper;
225 }
226
GetItemPos() const227 sal_uInt16 SfxFrameDescriptor::GetItemPos() const
228 {
229 return USHRT_MAX;
230 }
231
232
SfxFrameProperties(const SfxFrameDescriptor * pD)233 SfxFrameProperties::SfxFrameProperties( const SfxFrameDescriptor *pD )
234 : aURL( pD->GetURL().GetMainURL( INetURLObject::DECODE_TO_IURI ) )
235 , aName( pD->GetName() )
236 , lMarginWidth( pD->GetMargin().Width() )
237 , lMarginHeight( pD->GetMargin().Height() )
238 , lSize( pD->GetWidth() )
239 , lSetSize( SIZE_NOT_SET )
240 , lFrameSpacing( SPACING_NOT_SET )
241 , lInheritedFrameSpacing( SPACING_NOT_SET )
242 , eScroll( pD->GetScrollingMode() )
243 , eSizeSelector( pD->GetSizeSelector() )
244 , eSetSizeSelector( SIZE_REL )
245 , bHasBorder( pD->HasFrameBorder() )
246 , bBorderSet( pD->IsFrameBorderSet() )
247 , bResizable( pD->IsResizable() )
248 , bSetResizable( sal_False )
249 , bIsRootSet( sal_False )
250 , bIsInColSet( sal_False )
251 , bHasBorderInherited( sal_False )
252 , pFrame( pD->Clone() )
253 {
254 bBorderSet = sal_True;
255 }
256
operator =(const SfxFrameProperties & rProp)257 SfxFrameProperties& SfxFrameProperties::operator =(
258 const SfxFrameProperties &rProp )
259 {
260 aURL = rProp.aURL;
261 aName = rProp.aName;
262 lMarginWidth = rProp.lMarginWidth;
263 lMarginHeight = rProp.lMarginHeight;
264 lSize = rProp.lSize;
265 lSetSize = rProp.lSetSize;
266 lFrameSpacing = rProp.lFrameSpacing;
267 lInheritedFrameSpacing = rProp.lInheritedFrameSpacing;
268 eScroll = rProp.eScroll;
269 eSizeSelector = rProp.eSizeSelector;
270 eSetSizeSelector = rProp.eSetSizeSelector;
271 bHasBorder = rProp.bHasBorder;
272 bBorderSet = rProp.bBorderSet;
273 bResizable = rProp.bResizable;
274 bSetResizable = rProp.bSetResizable;
275 bIsRootSet = rProp.bIsRootSet;
276 bIsInColSet = rProp.bIsInColSet;
277 bHasBorderInherited = rProp.bHasBorderInherited;
278 pFrame = rProp.pFrame->Clone();
279 return *this;
280 }
281
operator ==(const SfxFrameProperties & rProp) const282 int SfxFrameProperties::operator ==( const SfxFrameProperties& rProp ) const
283 {
284 return aURL == rProp.aURL && aName == rProp.aName && lMarginWidth == rProp.lMarginWidth && lMarginHeight == rProp.lMarginHeight &&
285 lSize == rProp.lSize && eScroll == rProp.eScroll && eSizeSelector == rProp.eSizeSelector &&
286 lSetSize == rProp.lSetSize && lFrameSpacing == rProp.lFrameSpacing && eSetSizeSelector == rProp.eSetSizeSelector &&
287 bHasBorder == rProp.bHasBorder && bBorderSet == rProp.bBorderSet &&
288 bResizable == rProp.bResizable && bSetResizable == rProp.bSetResizable;
289 }
290
291 TYPEINIT1(SfxFrameDescriptorItem, SfxPoolItem);
292
~SfxFrameDescriptorItem()293 SfxFrameDescriptorItem::~SfxFrameDescriptorItem()
294 {}
295
operator ==(const SfxPoolItem & rAttr) const296 int SfxFrameDescriptorItem::operator==( const SfxPoolItem& rAttr ) const
297 {
298 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
299
300 return aProperties == ((SfxFrameDescriptorItem&)rAttr).aProperties;
301 }
302
303 // -----------------------------------------------------------------------
304
Clone(SfxItemPool *) const305 SfxPoolItem* SfxFrameDescriptorItem::Clone( SfxItemPool* ) const
306 {
307 return new SfxFrameDescriptorItem( *this );
308 }
309
310 //------------------------------------------------------------------------
311
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const312 SfxItemPresentation SfxFrameDescriptorItem::GetPresentation
313 (
314 SfxItemPresentation /*ePres*/,
315 SfxMapUnit /*eCoreUnit*/,
316 SfxMapUnit /*ePresUnit*/,
317 XubString& rText,
318 const IntlWrapper *
319 ) const
320 {
321 rText.Erase();
322 return SFX_ITEM_PRESENTATION_NONE;
323 }
324
325
326