xref: /aoo41x/main/sd/source/core/stlsheet.cxx (revision 849b7249)
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_sd.hxx"
26 
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include <com/sun/star/style/XStyle.hpp>
30 
31 #include <osl/mutex.hxx>
32 #include <vos/mutex.hxx>
33 #include <vcl/svapp.hxx>
34 #include <comphelper/serviceinfohelper.hxx>
35 #include <boost/bind.hpp>
36 
37 #include "eetext.hxx"
38 #include <editeng/eeitem.hxx>
39 #include <editeng/fhgtitem.hxx>
40 #include <svx/svdoattr.hxx>
41 #include <editeng/ulspitem.hxx>
42 #include <svl/smplhint.hxx>
43 #include <svl/itemset.hxx>
44 
45 #include <svx/xflbmtit.hxx>
46 #include <svx/xflbstit.hxx>
47 #include <editeng/bulitem.hxx>
48 #include <editeng/lrspitem.hxx>
49 #include <svx/unoshprp.hxx>
50 #include <svx/unoshape.hxx>
51 #include <svx/svdpool.hxx>
52 #include "stlsheet.hxx"
53 #include "sdresid.hxx"
54 #include "sdpage.hxx"
55 #include "drawdoc.hxx"
56 #include "stlpool.hxx"
57 #include "glob.hrc"
58 #include "app.hrc"
59 #include "glob.hxx"
60 #include "helpids.h"
61 #include "../ui/inc/DrawViewShell.hxx"
62 #include "../ui/inc/ViewShellBase.hxx"
63 #include <editeng/boxitem.hxx>
64 
65 using ::rtl::OUString;
66 using ::osl::MutexGuard;
67 using ::osl::ClearableMutexGuard;
68 using ::cppu::OInterfaceContainerHelper;
69 using ::com::sun::star::table::BorderLine;
70 using namespace ::vos;
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::util;
73 using namespace ::com::sun::star::lang;
74 using namespace ::com::sun::star::style;
75 using namespace ::com::sun::star::beans;
76 using namespace ::com::sun::star::container;
77 using namespace ::com::sun::star::drawing;
78 
79 #define WID_STYLE_DISPNAME	7998
80 #define WID_STYLE_FAMILY	7999
81 
GetStylePropertySet()82 static SvxItemPropertySet& GetStylePropertySet()
83 {
84 	static const SfxItemPropertyMapEntry aFullPropertyMap_Impl[] =
85 	{
86 		{ RTL_CONSTASCII_STRINGPARAM("Family"),					WID_STYLE_FAMILY,		&::getCppuType((const OUString*)0),	PropertyAttribute::READONLY,	0},
87 		{ RTL_CONSTASCII_STRINGPARAM("UserDefinedAttributes"),	SDRATTR_XMLATTRIBUTES,	&XNameContainer::static_type(), 0,     0},
88 		{ RTL_CONSTASCII_STRINGPARAM("DisplayName"),			WID_STYLE_DISPNAME,		&::getCppuType((const OUString*)0),	PropertyAttribute::READONLY,	0},
89 
90 		SVX_UNOEDIT_NUMBERING_PROPERTIE,
91 		SHADOW_PROPERTIES
92 		LINE_PROPERTIES
93 		LINE_PROPERTIES_START_END
94 		FILL_PROPERTIES
95 		EDGERADIUS_PROPERTIES
96 		TEXT_PROPERTIES_DEFAULTS
97 		CONNECTOR_PROPERTIES
98 		SPECIAL_DIMENSIONING_PROPERTIES_DEFAULTS
99 		{ MAP_CHAR_LEN("TopBorder"),					SDRATTR_TABLE_BORDER,			&::getCppuType((const BorderLine*)0), 0, TOP_BORDER }, \
100 		{ MAP_CHAR_LEN("BottomBorder"), 				SDRATTR_TABLE_BORDER,			&::getCppuType((const BorderLine*)0), 0, BOTTOM_BORDER }, \
101 		{ MAP_CHAR_LEN("LeftBorder"),					SDRATTR_TABLE_BORDER,			&::getCppuType((const BorderLine*)0), 0, LEFT_BORDER }, \
102 		{ MAP_CHAR_LEN("RightBorder"),					SDRATTR_TABLE_BORDER,			&::getCppuType((const BorderLine*)0), 0, RIGHT_BORDER }, \
103 		{0,0,0,0,0,0}
104 	};
105 
106 	static SvxItemPropertySet aPropSet( aFullPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
107 	return aPropSet;
108 }
109 
110 class ModifyListenerForewarder : public SfxListener
111 {
112 public:
113 	ModifyListenerForewarder( SdStyleSheet* pStyleSheet );
114 
115 	virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint);
116 
117 private:
118 	SdStyleSheet* mpStyleSheet;
119 };
120 
ModifyListenerForewarder(SdStyleSheet * pStyleSheet)121 ModifyListenerForewarder::ModifyListenerForewarder( SdStyleSheet* pStyleSheet )
122 : mpStyleSheet( pStyleSheet )
123 {
124 	if( pStyleSheet )
125 	{
126 		SfxBroadcaster& rBC = static_cast< SfxBroadcaster& >( *pStyleSheet );
127 		StartListening( rBC );
128 	}
129 }
130 
Notify(SfxBroadcaster &,const SfxHint &)131 void ModifyListenerForewarder::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& /*rHint*/)
132 {
133 	if( mpStyleSheet )
134 		mpStyleSheet->notifyModifyListener();
135 }
136 
SdStyleSheet(const OUString & rDisplayName,SfxStyleSheetBasePool & _rPool,SfxStyleFamily eFamily,sal_uInt16 _nMask)137 SdStyleSheet::SdStyleSheet(const OUString& rDisplayName, SfxStyleSheetBasePool& _rPool, SfxStyleFamily eFamily, sal_uInt16 _nMask)
138 : SdStyleSheetBase( UniString( rDisplayName ), _rPool, eFamily, _nMask)
139 , ::cppu::BaseMutex()
140 , msApiName( rDisplayName )
141 , mxPool( const_cast< SfxStyleSheetBasePool* >(&_rPool) )
142 , mrBHelper( m_aMutex )
143 {
144 }
145 
SdStyleSheet(const SdStyleSheet & r)146 SdStyleSheet::SdStyleSheet( const SdStyleSheet & r )
147 : SdStyleSheetBase( r )
148 , ::cppu::BaseMutex()
149 , msApiName( r.msApiName )
150 , mxPool( r.mxPool )
151 , mrBHelper( m_aMutex )
152 {
153 }
154 
~SdStyleSheet()155 SdStyleSheet::~SdStyleSheet()
156 {
157 	delete pSet;
158 	pSet = NULL;	// damit nachfolgende Destruktoren eine Chance haben
159 }
160 
SetApiName(const OUString & rApiName)161 void SdStyleSheet::SetApiName( const OUString& rApiName )
162 {
163 	msApiName = rApiName;
164 }
165 
GetApiName() const166 rtl::OUString SdStyleSheet::GetApiName() const
167 {
168     if( msApiName.getLength() )
169         return msApiName;
170     else
171         return GetName();
172 }
173 
174 
Load(SvStream & rIn,sal_uInt16 nVersion)175 void SdStyleSheet::Load (SvStream& rIn, sal_uInt16 nVersion)
176 {
177 	SfxStyleSheetBase::Load(rIn, nVersion);
178 
179 	// Die Default-Maske war frueher 0xAFFE.
180 	// Aus dieser Default-Maske wurden die benoetigten Flags ausmaskiert.
181 	// Nun wurde das Flag SFXSTYLEBIT_READONLY eingefuehrt, was dazu
182 	// das alle StyleSheets read-only waren.
183 	// Da im Draw kein StyleSheet read-only sein soll, wird an dieser Stelle
184 	// das Flag zurueckgesetzt.
185 	nMask &= ~SFXSTYLEBIT_READONLY;
186 }
187 
188 /*************************************************************************
189 |*
190 |* Store
191 |*
192 \************************************************************************/
193 
Store(SvStream & rOut)194 void SdStyleSheet::Store(SvStream& rOut)
195 {
196 	SfxStyleSheetBase::Store(rOut);
197 }
198 
199 /*************************************************************************
200 |*
201 |* Parent setzen
202 |*
203 \************************************************************************/
204 
SetParent(const String & rParentName)205 sal_Bool SdStyleSheet::SetParent(const String& rParentName)
206 {
207 	sal_Bool bResult = sal_False;
208 
209 	if (SfxStyleSheet::SetParent(rParentName))
210 	{
211 		// PseudoStyleSheets haben keine eigenen ItemSets
212 		if (nFamily != SD_STYLE_FAMILY_PSEUDO)
213 		{
214 			if( rParentName.Len() )
215 			{
216 				SfxStyleSheetBase* pStyle = rPool.Find(rParentName, nFamily);
217 				if (pStyle)
218 				{
219 					bResult = sal_True;
220 					SfxItemSet& rParentSet = pStyle->GetItemSet();
221 					GetItemSet().SetParent(&rParentSet);
222 					Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
223 				}
224 			}
225 			else
226 			{
227 				bResult = sal_True;
228 				GetItemSet().SetParent(NULL);
229 				Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
230 			}
231 		}
232 		else
233 		{
234 			bResult = sal_True;
235 		}
236 	}
237 	return bResult;
238 }
239 
240 /*************************************************************************
241 |*
242 |* ItemSet ggfs. erzeugen und herausreichen
243 |*
244 \************************************************************************/
245 
GetItemSet()246 SfxItemSet& SdStyleSheet::GetItemSet()
247 {
248 	if (nFamily == SD_STYLE_FAMILY_GRAPHICS || nFamily == SD_STYLE_FAMILY_MASTERPAGE)
249 	{
250 		// ggfs. das ItemSet 'on demand' anlegen
251 		if (!pSet)
252 		{
253 			sal_uInt16 nWhichPairTable[] = { XATTR_LINE_FIRST, 				XATTR_LINE_LAST,
254 										 XATTR_FILL_FIRST, 				XATTR_FILL_LAST,
255 
256 										SDRATTR_SHADOW_FIRST, 			SDRATTR_SHADOW_LAST,
257 										SDRATTR_TEXT_MINFRAMEHEIGHT,	SDRATTR_TEXT_CONTOURFRAME,
258 
259 										SDRATTR_TEXT_WORDWRAP,			SDRATTR_TEXT_AUTOGROWSIZE,
260 
261 										SDRATTR_EDGE_FIRST,				SDRATTR_EDGE_LAST,
262 										SDRATTR_MEASURE_FIRST, 			SDRATTR_MEASURE_LAST,
263 
264 										EE_PARA_START, 					EE_CHAR_END,
265 
266 										SDRATTR_XMLATTRIBUTES,			SDRATTR_TEXT_USEFIXEDCELLHEIGHT,
267 
268 										SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
269 										0, 0 };
270 
271 			pSet = new SfxItemSet(GetPool().GetPool(), nWhichPairTable);
272 		}
273 
274 		return *pSet;
275 	}
276 
277 	else if( nFamily == SD_STYLE_FAMILY_CELL )
278 	{
279 		if (!pSet)
280 		{
281 			sal_uInt16 nWhichPairTable[] = { XATTR_LINE_FIRST, 				XATTR_LINE_LAST,
282 										 XATTR_FILL_FIRST, 				XATTR_FILL_LAST,
283 
284 										SDRATTR_SHADOW_FIRST, 			SDRATTR_SHADOW_LAST,
285 										SDRATTR_TEXT_MINFRAMEHEIGHT,	SDRATTR_TEXT_CONTOURFRAME,
286 
287 										SDRATTR_TEXT_WORDWRAP,			SDRATTR_TEXT_AUTOGROWSIZE,
288 
289 										EE_PARA_START, 					EE_CHAR_END,
290 
291 										SDRATTR_TABLE_FIRST,			SDRATTR_TABLE_LAST,
292 										SDRATTR_XMLATTRIBUTES,			SDRATTR_XMLATTRIBUTES,
293 
294 										0, 0 };
295 
296 			pSet = new SfxItemSet(GetPool().GetPool(), nWhichPairTable);
297 		}
298 
299 		return *pSet;
300 	}
301 
302 	// dies ist eine Stellvertretervorlage fuer die interne Vorlage des
303 	// aktuellen Praesentationslayouts: dessen ItemSet returnieren
304 	else
305 	{
306 //        return (GetRealStyleSheet()->GetItemSet());
307 
308 		SdStyleSheet* pSdSheet = GetRealStyleSheet();
309 
310 		if (pSdSheet)
311 		{
312 			return(pSdSheet->GetItemSet());
313 		}
314 		else
315 		{
316 			if (!pSet)
317 			{
318 				sal_uInt16 nWhichPairTable[] = { XATTR_LINE_FIRST,              XATTR_LINE_LAST,
319 											 XATTR_FILL_FIRST,              XATTR_FILL_LAST,
320 
321 											 SDRATTR_SHADOW_FIRST,          SDRATTR_SHADOW_LAST,
322 											 SDRATTR_TEXT_MINFRAMEHEIGHT,   SDRATTR_TEXT_CONTOURFRAME,
323 
324 											 SDRATTR_TEXT_WORDWRAP,			SDRATTR_TEXT_AUTOGROWSIZE,
325 
326 											 SDRATTR_EDGE_FIRST,            SDRATTR_EDGE_LAST,
327 											 SDRATTR_MEASURE_FIRST,         SDRATTR_MEASURE_LAST,
328 
329 											 EE_PARA_START,                 EE_CHAR_END,
330 
331 											SDRATTR_XMLATTRIBUTES,			SDRATTR_TEXT_USEFIXEDCELLHEIGHT,
332 
333 											SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
334 											 0, 0 };
335 
336 				pSet = new SfxItemSet(GetPool().GetPool(), nWhichPairTable);
337 			}
338 
339 			return(*pSet);
340 		}
341 	}
342 }
343 
344 /*************************************************************************
345 |*
346 |* IsUsed(), eine Vorlage gilt als benutzt, wenn sie von eingefuegten Objekten
347 |*			 oder von benutzten Vorlagen referenziert wird
348 |*
349 \************************************************************************/
350 
IsUsed() const351 sal_Bool SdStyleSheet::IsUsed() const
352 {
353 	sal_Bool bResult = sal_False;
354 
355 	sal_uInt16 nListenerCount = GetListenerCount();
356 	if (nListenerCount > 0)
357 	{
358 		for (sal_uInt16 n = 0; n < nListenerCount; n++)
359 		{
360 			SfxListener* pListener = GetListener(n);
361 			if( pListener == this )
362 				continue;
363 
364 			// NULL-Pointer ist im Listener-Array erlaubt
365 			if (pListener && pListener->ISA(SdrAttrObj))
366 			{
367 				bResult = ((SdrAttrObj*)pListener)->IsInserted();
368 			}
369 			else if (pListener && pListener->ISA(SfxStyleSheet))
370 			{
371 				bResult = ((SfxStyleSheet*)pListener)->IsUsed();
372 			}
373 			if (bResult)
374 				break;
375 		}
376 	}
377 
378 	if( !bResult )
379 	{
380 		MutexGuard aGuard( mrBHelper.rMutex );
381 
382 		OInterfaceContainerHelper * pContainer = mrBHelper.getContainer( XModifyListener::static_type() );
383 		if( pContainer )
384 		{
385 			Sequence< Reference< XInterface > > aModifyListeners( pContainer->getElements() );
386 			Reference< XInterface > *p = aModifyListeners.getArray();
387 			sal_Int32 nCount = aModifyListeners.getLength();
388 			while( nCount-- && !bResult )
389 			{
390 				Reference< XStyle > xStyle( *p++, UNO_QUERY );
391 				if( xStyle.is() )
392 					bResult = xStyle->isInUse();
393 			}
394 		}
395 	}
396 	return bResult;
397 }
398 
399 /*************************************************************************
400 |*
401 |* das StyleSheet ermitteln, fuer das dieses StyleSheet steht
402 |*
403 \************************************************************************/
404 
GetRealStyleSheet() const405 SdStyleSheet* SdStyleSheet::GetRealStyleSheet() const
406 {
407 	String aRealStyle;
408 	String aSep( RTL_CONSTASCII_USTRINGPARAM( SD_LT_SEPARATOR ));
409 	SdStyleSheet* pRealStyle = NULL;
410 	SdDrawDocument* pDoc = ((SdStyleSheetPool&) rPool).GetDoc();
411 
412     ::sd::DrawViewShell* pDrawViewShell = 0;
413 
414     ::sd::ViewShellBase* pBase = dynamic_cast< ::sd::ViewShellBase* >( SfxViewShell::Current() );
415     if( pBase )
416         pDrawViewShell = dynamic_cast< ::sd::DrawViewShell* >( pBase->GetMainViewShell().get() );
417 
418     if (pDrawViewShell && pDrawViewShell->GetDoc() == pDoc)
419     {
420         SdPage* pPage = pDrawViewShell->getCurrentPage();
421 		if( pPage )
422 		{
423 	        aRealStyle = pPage->GetLayoutName();
424 		    // cut after seperator string
425 			aRealStyle.Erase(aRealStyle.Search(aSep) + aSep.Len());
426 		}
427     }
428 
429 	if (aRealStyle.Len() == 0)
430 	{
431 		SdPage* pPage = pDoc->GetSdPage(0, PK_STANDARD);
432 
433 		if (pPage)
434 		{
435 			aRealStyle = pDoc->GetSdPage(0, PK_STANDARD)->GetLayoutName();
436 		}
437 		else
438 		{
439 			// Noch keine Seite vorhanden
440 			// Dieses kann beim Aktualisieren vonDokumentvorlagen vorkommen
441 			SfxStyleSheetIterator aIter(&rPool, SD_STYLE_FAMILY_MASTERPAGE);
442 			SfxStyleSheetBase* pSheet = aIter.First();
443 			if( pSheet )
444 				aRealStyle = pSheet->GetName();
445 		}
446 
447 		aRealStyle.Erase(aRealStyle.Search(aSep) + aSep.Len());
448 	}
449 
450 	// jetzt vom Namen (landessprachlich angepasst) auf den internen
451 	// Namen (unabhaengig von der Landessprache) mappen
452 	String aInternalName;
453 
454 	if (aName == String(SdResId(STR_PSEUDOSHEET_TITLE)))
455 	{
456 		aInternalName = String(SdResId(STR_LAYOUT_TITLE));
457 	}
458 	else if (aName == String(SdResId(STR_PSEUDOSHEET_SUBTITLE)))
459 	{
460 		aInternalName = String(SdResId(STR_LAYOUT_SUBTITLE));
461 	}
462 	else if (aName == String(SdResId(STR_PSEUDOSHEET_BACKGROUND)))
463 	{
464 		aInternalName = String(SdResId(STR_LAYOUT_BACKGROUND));
465 	}
466 	else if (aName == String(SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS)))
467 	{
468 		aInternalName = String(SdResId(STR_LAYOUT_BACKGROUNDOBJECTS));
469 	}
470 	else if (aName == String(SdResId(STR_PSEUDOSHEET_NOTES)))
471 	{
472 		aInternalName = String(SdResId(STR_LAYOUT_NOTES));
473 	}
474 	else
475 	{
476 		String aOutlineStr(SdResId(STR_PSEUDOSHEET_OUTLINE));
477 		sal_uInt16 nPos = aName.Search(aOutlineStr);
478 		if (nPos != STRING_NOTFOUND)
479 		{
480 			String aNumStr(aName.Copy(aOutlineStr.Len()));
481 			aInternalName = String(SdResId(STR_LAYOUT_OUTLINE));
482 			aInternalName += aNumStr;
483 		}
484 	}
485 
486 	aRealStyle += aInternalName;
487 	pRealStyle = static_cast< SdStyleSheet* >( rPool.Find(aRealStyle, SD_STYLE_FAMILY_MASTERPAGE) );
488 
489 #ifdef DBG_UTIL
490 	if( !pRealStyle )
491 	{
492 		SfxStyleSheetIterator aIter(&rPool, SD_STYLE_FAMILY_MASTERPAGE);
493 		if( aIter.Count() > 0 )
494 			// StyleSheet not found, but pool already loaded
495 			DBG_ASSERT(pRealStyle, "Internal StyleSheet not found");
496 	}
497 #endif
498 
499 	return pRealStyle;
500 }
501 
502 /*************************************************************************
503 |*
504 |* das PseudoStyleSheet ermitteln, durch das dieses StyleSheet vertreten wird
505 |*
506 \************************************************************************/
507 
GetPseudoStyleSheet() const508 SdStyleSheet* SdStyleSheet::GetPseudoStyleSheet() const
509 {
510 	SdStyleSheet* pPseudoStyle = NULL;
511 	String aSep( RTL_CONSTASCII_USTRINGPARAM( SD_LT_SEPARATOR ));
512 	String aStyleName(aName);
513 		// ohne Layoutnamen und Separator
514 	aStyleName.Erase(0, aStyleName.Search(aSep) + aSep.Len());
515 
516 	if (aStyleName == String(SdResId(STR_LAYOUT_TITLE)))
517 	{
518 		aStyleName = String(SdResId(STR_PSEUDOSHEET_TITLE));
519 	}
520 	else if (aStyleName == String(SdResId(STR_LAYOUT_SUBTITLE)))
521 	{
522 		aStyleName = String(SdResId(STR_PSEUDOSHEET_SUBTITLE));
523 	}
524 	else if (aStyleName == String(SdResId(STR_LAYOUT_BACKGROUND)))
525 	{
526 		aStyleName = String(SdResId(STR_PSEUDOSHEET_BACKGROUND));
527 	}
528 	else if (aStyleName == String(SdResId(STR_LAYOUT_BACKGROUNDOBJECTS)))
529 	{
530 		aStyleName = String(SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS));
531 	}
532 	else if (aStyleName == String(SdResId(STR_LAYOUT_NOTES)))
533 	{
534 		aStyleName = String(SdResId(STR_PSEUDOSHEET_NOTES));
535 	}
536 	else
537 	{
538 		String aOutlineStr((SdResId(STR_LAYOUT_OUTLINE)));
539 		sal_uInt16 nPos = aStyleName.Search(aOutlineStr);
540 		if (nPos != STRING_NOTFOUND)
541 		{
542 			String aNumStr(aStyleName.Copy(aOutlineStr.Len()));
543 			aStyleName = String(SdResId(STR_PSEUDOSHEET_OUTLINE));
544 			aStyleName += aNumStr;
545 		}
546 	}
547 
548 	pPseudoStyle = static_cast<SdStyleSheet*>(rPool.Find(aStyleName, SD_STYLE_FAMILY_PSEUDO));
549 	DBG_ASSERT(pPseudoStyle, "PseudoStyleSheet nicht gefunden");
550 
551 	return pPseudoStyle;
552 }
553 
554 
555 /*************************************************************************
556 |*
557 |* Notify
558 |*
559 \************************************************************************/
560 
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)561 void SdStyleSheet::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
562 {
563 	// erstmal die Basisklassenfunktionalitaet
564 	SfxStyleSheet::Notify(rBC, rHint);
565 
566 	// wenn der Stellvertreter ein Notify bezueglich geaenderter Attribute
567 	// bekommt, sorgt er dafuer, dass das eigentlich gemeinte StyleSheet
568 	// broadcastet
569 	SfxSimpleHint* pSimple = PTR_CAST(SfxSimpleHint, &rHint);
570 	sal_uLong nId = pSimple == NULL ? 0 : pSimple->GetId();
571 	if (nId == SFX_HINT_DATACHANGED && nFamily == SD_STYLE_FAMILY_PSEUDO)
572 	{
573 		SdStyleSheet* pRealStyle = GetRealStyleSheet();
574 		if (pRealStyle)
575 			pRealStyle->Broadcast(rHint);
576 	}
577 }
578 
579 /*************************************************************************
580 |* AdjustToFontHeight passt die Bulletbreite und den linken Texteinzug
581 |* des uebergebenen ItemSets dessen Fonthoehe an. Die neuen Werte werden so
582 |* berechnet, dass das Verhaeltnis zur Fonthoehe so ist wie im StyleSheet.
583 |*
584 |* bOnlyMissingItems legt fest, ob lediglich nicht gesetzte Items ergaenzt
585 |* (sal_True) oder explizit gesetzte Items ueberschreiben werden sollen (sal_False)
586 |*
587 \************************************************************************/
588 
AdjustToFontHeight(SfxItemSet & rSet,sal_Bool bOnlyMissingItems)589 void SdStyleSheet::AdjustToFontHeight(SfxItemSet& rSet, sal_Bool bOnlyMissingItems)
590 {
591 	// Bulletbreite und Texteinzug an neue Fonthoehe
592 	// anpassen, wenn sie nicht explizit gesetzt wurden
593 	SfxStyleFamily eFamily = nFamily;
594 	String aStyleName(aName);
595 	if (eFamily == SD_STYLE_FAMILY_PSEUDO)
596 	{
597 		SfxStyleSheet* pRealStyle = GetRealStyleSheet();
598 		eFamily = pRealStyle->GetFamily();
599 		aStyleName = pRealStyle->GetName();
600 	}
601 
602 	if (eFamily == SD_STYLE_FAMILY_MASTERPAGE &&
603 		aStyleName.Search(String(SdResId(STR_LAYOUT_OUTLINE))) != STRING_NOTFOUND &&
604 		rSet.GetItemState(EE_CHAR_FONTHEIGHT) == SFX_ITEM_SET)
605 	{
606 		const SfxItemSet* pCurSet = &GetItemSet();
607 		sal_uInt32 nNewHeight = ((SvxFontHeightItem&)rSet.Get(EE_CHAR_FONTHEIGHT)).GetHeight();
608 		sal_uInt32 nOldHeight = ((SvxFontHeightItem&)pCurSet->Get(EE_CHAR_FONTHEIGHT)).GetHeight();
609 
610 		if (rSet.GetItemState(EE_PARA_BULLET) != SFX_ITEM_SET || !bOnlyMissingItems)
611 		{
612 			const SvxBulletItem& rBItem = (const SvxBulletItem&)pCurSet->Get(EE_PARA_BULLET);
613 			double fBulletFraction = double(rBItem.GetWidth()) / nOldHeight;
614 			SvxBulletItem aNewBItem(rBItem);
615 			aNewBItem.SetWidth((sal_uInt32)(fBulletFraction * nNewHeight));
616 			rSet.Put(aNewBItem);
617 		}
618 
619 		if (rSet.GetItemState(EE_PARA_LRSPACE) != SFX_ITEM_SET || !bOnlyMissingItems)
620 		{
621 			const SvxLRSpaceItem& rLRItem = (const SvxLRSpaceItem&)pCurSet->Get(EE_PARA_LRSPACE);
622 			double fIndentFraction = double(rLRItem.GetTxtLeft()) / nOldHeight;
623 			SvxLRSpaceItem aNewLRItem(rLRItem);
624 			aNewLRItem.SetTxtLeft((sal_uInt16)(fIndentFraction * nNewHeight));
625 			double fFirstIndentFraction = double(rLRItem.GetTxtFirstLineOfst()) / nOldHeight;
626 			aNewLRItem.SetTxtFirstLineOfst((short)(fFirstIndentFraction * nNewHeight));
627 			rSet.Put(aNewLRItem);
628 		}
629 
630 		if (rSet.GetItemState(EE_PARA_ULSPACE) != SFX_ITEM_SET || !bOnlyMissingItems)
631 		{
632 			const SvxULSpaceItem& rULItem = (const SvxULSpaceItem&)pCurSet->Get(EE_PARA_ULSPACE);
633 			SvxULSpaceItem aNewULItem(rULItem);
634 			double fLowerFraction = double(rULItem.GetLower()) / nOldHeight;
635 			aNewULItem.SetLower((sal_uInt16)(fLowerFraction * nNewHeight));
636 			double fUpperFraction = double(rULItem.GetUpper()) / nOldHeight;
637 			aNewULItem.SetUpper((sal_uInt16)(fUpperFraction * nNewHeight));
638 			rSet.Put(aNewULItem);
639 		}
640 	}
641 }
642 
643 // --------------------------------------------------------------------
644 
HasFollowSupport() const645 sal_Bool SdStyleSheet::HasFollowSupport() const
646 {
647 	return sal_False;
648 }
649 
650 // --------------------------------------------------------------------
651 
HasParentSupport() const652 sal_Bool SdStyleSheet::HasParentSupport() const
653 {
654 	return sal_True;
655 }
656 
657 // --------------------------------------------------------------------
658 
HasClearParentSupport() const659 sal_Bool SdStyleSheet::HasClearParentSupport() const
660 {
661 	return sal_True;
662 }
663 
664 // --------------------------------------------------------------------
665 
SetName(const UniString & rName)666 sal_Bool SdStyleSheet::SetName( const UniString& rName )
667 {
668 	return SfxStyleSheet::SetName( rName );
669 }
670 
671 // --------------------------------------------------------------------
672 
SetHelpId(const String & r,sal_uLong nId)673 void SdStyleSheet::SetHelpId( const String& r, sal_uLong nId )
674 {
675 	SfxStyleSheet::SetHelpId( r, nId );
676 
677 	if( (nId >= HID_PSEUDOSHEET_OUTLINE1) && ( nId <= HID_PSEUDOSHEET_OUTLINE9 ) )
678 	{
679 		msApiName = OUString( RTL_CONSTASCII_USTRINGPARAM("outline") );
680 		msApiName += OUString( (sal_Unicode)( '1' + (nId - HID_PSEUDOSHEET_OUTLINE1) ) );
681 	}
682 	else
683 	{
684 		static struct ApiNameMap
685 		{
686 			const sal_Char* mpApiName;
687 			sal_uInt32		mnApiNameLength;
688 			sal_uInt32		mnHelpId;
689 		}
690 		pApiNameMap[] =
691 		{
692 			{ RTL_CONSTASCII_STRINGPARAM( "title" ),			HID_PSEUDOSHEET_TITLE },
693 			{ RTL_CONSTASCII_STRINGPARAM( "subtitle" ),			HID_PSEUDOSHEET_SUBTITLE },
694 			{ RTL_CONSTASCII_STRINGPARAM( "background" ),		HID_PSEUDOSHEET_BACKGROUND },
695 			{ RTL_CONSTASCII_STRINGPARAM( "backgroundobjects" ),HID_PSEUDOSHEET_BACKGROUNDOBJECTS },
696 			{ RTL_CONSTASCII_STRINGPARAM( "notes" ),			HID_PSEUDOSHEET_NOTES },
697 			{ RTL_CONSTASCII_STRINGPARAM( "standard" ),			HID_STANDARD_STYLESHEET_NAME },
698 			{ RTL_CONSTASCII_STRINGPARAM( "objectwitharrow" ),	HID_POOLSHEET_OBJWITHARROW },
699 			{ RTL_CONSTASCII_STRINGPARAM( "objectwithshadow" ),	HID_POOLSHEET_OBJWITHSHADOW },
700 			{ RTL_CONSTASCII_STRINGPARAM( "objectwithoutfill" ),HID_POOLSHEET_OBJWITHOUTFILL },
701 			{ RTL_CONSTASCII_STRINGPARAM( "text" ),				HID_POOLSHEET_TEXT },
702 			{ RTL_CONSTASCII_STRINGPARAM( "textbody" ),			HID_POOLSHEET_TEXTBODY },
703 			{ RTL_CONSTASCII_STRINGPARAM( "textbodyjustfied" ),	HID_POOLSHEET_TEXTBODY_JUSTIFY },
704 			{ RTL_CONSTASCII_STRINGPARAM( "textbodyindent" ),	HID_POOLSHEET_TEXTBODY_INDENT },
705 			{ RTL_CONSTASCII_STRINGPARAM( "title" ),			HID_POOLSHEET_TITLE },
706 			{ RTL_CONSTASCII_STRINGPARAM( "title1" ),			HID_POOLSHEET_TITLE1 },
707 			{ RTL_CONSTASCII_STRINGPARAM( "title2" ),			HID_POOLSHEET_TITLE2 },
708 			{ RTL_CONSTASCII_STRINGPARAM( "headline" ),			HID_POOLSHEET_HEADLINE },
709 			{ RTL_CONSTASCII_STRINGPARAM( "headline1" ),		HID_POOLSHEET_HEADLINE1 },
710 			{ RTL_CONSTASCII_STRINGPARAM( "headline2" ),		HID_POOLSHEET_HEADLINE2 },
711 			{ RTL_CONSTASCII_STRINGPARAM( "measure" ),			HID_POOLSHEET_MEASURE },
712 			{ 0, 0, 0 }
713 		};
714 
715 		ApiNameMap* p = pApiNameMap;
716 		while( p->mpApiName )
717 		{
718 			if( nId == p->mnHelpId )
719 			{
720 				msApiName = OUString( p->mpApiName, p->mnApiNameLength, RTL_TEXTENCODING_ASCII_US );
721 				break;
722 			}
723 			p++;
724 		}
725 	}
726 }
727 
728 // --------------------------------------------------------------------
729 
GetFamilyString(SfxStyleFamily eFamily)730 OUString SdStyleSheet::GetFamilyString( SfxStyleFamily eFamily )
731 {
732 	switch( eFamily )
733 	{
734 	case SD_STYLE_FAMILY_CELL:
735 		return OUString( RTL_CONSTASCII_USTRINGPARAM( "cell" ) );
736 	default:
737 		DBG_ERROR( "SdStyleSheet::GetFamilyString(), illegal family!" );
738 	case SD_STYLE_FAMILY_GRAPHICS:
739 		return OUString( RTL_CONSTASCII_USTRINGPARAM( "graphics" ) );
740 	}
741 }
742 
743 // --------------------------------------------------------------------
744 
throwIfDisposed()745 void SdStyleSheet::throwIfDisposed() throw (RuntimeException)
746 {
747 	if( !mxPool.is() )
748 		throw DisposedException();
749 }
750 
751 // --------------------------------------------------------------------
752 
CreateEmptyUserStyle(SfxStyleSheetBasePool & rPool,SfxStyleFamily eFamily)753 SdStyleSheet* SdStyleSheet::CreateEmptyUserStyle( SfxStyleSheetBasePool& rPool, SfxStyleFamily eFamily )
754 {
755 	OUString aPrefix( RTL_CONSTASCII_USTRINGPARAM("user") );
756 	OUString aName;
757 	sal_Int32 nIndex = 1;
758 	do
759 	{
760 		aName = aPrefix + OUString::valueOf( nIndex++ );
761 	}
762 	while( rPool.Find( aName, eFamily ) != 0 );
763 
764 	return new SdStyleSheet(aName, rPool, eFamily, SFXSTYLEBIT_USERDEF);
765 }
766 
767 // --------------------------------------------------------------------
768 // XInterface
769 // --------------------------------------------------------------------
770 
771 /*
772 Any SAL_CALL SdStyleSheet::queryInterface( const ::com::sun::star::uno::Type& aType ) throw (RuntimeException)
773 {
774 	return SdStyleSheetBase::queryInterface( aType );
775 }
776 
777 // --------------------------------------------------------------------
778 
779 void SAL_CALL SdStyleSheet::acquire(  ) throw ()
780 {
781 	SdStyleSheetBase::acquire();
782 }
783 
784 // --------------------------------------------------------------------
785 */
release()786 void SAL_CALL SdStyleSheet::release(  ) throw ()
787 {
788     if (osl_decrementInterlockedCount( &m_refCount ) == 0)
789 	{
790         // restore reference count:
791         osl_incrementInterlockedCount( &m_refCount );
792         if (! mrBHelper.bDisposed) try
793 		{
794             dispose();
795         }
796         catch (RuntimeException const& exc)
797 		{ // don't break throw ()
798             OSL_ENSURE(
799                 false, OUStringToOString(
800                     exc.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
801             static_cast<void>(exc);
802         }
803         OSL_ASSERT( mrBHelper.bDisposed );
804         SdStyleSheetBase::release();
805     }
806 }
807 
808 // --------------------------------------------------------------------
809 // XWeak
810 // --------------------------------------------------------------------
811 /*
812 Reference< XAdapter > SAL_CALL SdStyleSheet::queryAdapter(  ) throw (RuntimeException)
813 {
814 	return SdStyleSheetBase::queryAdapter();
815 }
816 
817 // --------------------------------------------------------------------
818 // XTypeProvider
819 // --------------------------------------------------------------------
820 
821 Sequence< Type > SAL_CALL SdStyleSheet::getTypes(  ) throw (RuntimeException)
822 {
823 	return SdStyleSheetBase::getTypes();
824 }
825 
826 // --------------------------------------------------------------------
827 
828 Sequence< ::sal_Int8 > SAL_CALL SdStyleSheet::getImplementationId(  ) throw (RuntimeException)
829 {
830 	return SdStyleSheetBase::getImplementationId();
831 }
832 */
833 // --------------------------------------------------------------------
834 // XComponent
835 // --------------------------------------------------------------------
836 
dispose()837 void SAL_CALL SdStyleSheet::dispose(  ) throw (RuntimeException)
838 {
839 	ClearableMutexGuard aGuard( mrBHelper.rMutex );
840     if (!mrBHelper.bDisposed && !mrBHelper.bInDispose)
841     {
842         mrBHelper.bInDispose = sal_True;
843         aGuard.clear();
844         try
845         {
846             // side effect: keeping a reference to this
847             EventObject aEvt( static_cast< OWeakObject * >( this ) );
848             try
849             {
850                 mrBHelper.aLC.disposeAndClear( aEvt );
851                 disposing();
852             }
853             catch (...)
854             {
855                 MutexGuard aGuard2( mrBHelper.rMutex );
856                 // bDisposed and bInDispose must be set in this order:
857                 mrBHelper.bDisposed = sal_True;
858                 mrBHelper.bInDispose = sal_False;
859                 throw;
860             }
861             MutexGuard aGuard2( mrBHelper.rMutex );
862             // bDisposed and bInDispose must be set in this order:
863             mrBHelper.bDisposed = sal_True;
864             mrBHelper.bInDispose = sal_False;
865         }
866         catch (RuntimeException &)
867         {
868             throw;
869         }
870         catch (Exception & exc)
871         {
872             throw RuntimeException(
873                 OUString( RTL_CONSTASCII_USTRINGPARAM(
874                               "unexpected UNO exception caught: ") ) +
875                 exc.Message, Reference< XInterface >() );
876         }
877     }
878 }
879 
880 // --------------------------------------------------------------------
881 
disposing()882 void SdStyleSheet::disposing()
883 {
884 	mxPool.clear();
885 }
886 
887 // --------------------------------------------------------------------
888 
addEventListener(const Reference<XEventListener> & xListener)889 void SAL_CALL SdStyleSheet::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException)
890 {
891     ClearableMutexGuard aGuard( mrBHelper.rMutex );
892 	if (mrBHelper.bDisposed || mrBHelper.bInDispose)
893 	{
894         aGuard.clear();
895         EventObject aEvt( static_cast< OWeakObject * >( this ) );
896 		xListener->disposing( aEvt );
897 	}
898     else
899     {
900         mrBHelper.addListener( ::getCppuType( &xListener ), xListener );
901     }
902 }
903 
904 // --------------------------------------------------------------------
905 
removeEventListener(const Reference<XEventListener> & xListener)906 void SAL_CALL SdStyleSheet::removeEventListener( const Reference< XEventListener >& xListener  ) throw (RuntimeException)
907 {
908     mrBHelper.removeListener( ::getCppuType( &xListener ), xListener );
909 }
910 
911 //------------------------------------------------------------------------
912 // XModifyBroadcaster
913 //------------------------------------------------------------------------
914 
addModifyListener(const Reference<XModifyListener> & xListener)915 void SAL_CALL SdStyleSheet::addModifyListener( const Reference< XModifyListener >& xListener ) throw (RuntimeException)
916 {
917 	ClearableMutexGuard aGuard( mrBHelper.rMutex );
918 	if (mrBHelper.bDisposed || mrBHelper.bInDispose)
919 	{
920 		aGuard.clear();
921 		EventObject aEvt( static_cast< OWeakObject * >( this ) );
922 		xListener->disposing( aEvt );
923 	}
924 	else
925 	{
926 		if( !mpModifyListenerForewarder.get() )
927 			mpModifyListenerForewarder.reset( new ModifyListenerForewarder( this ) );
928 		mrBHelper.addListener( XModifyListener::static_type(), xListener );
929 	}
930 }
931 
932 //------------------------------------------------------------------------
933 
removeModifyListener(const Reference<XModifyListener> & xListener)934 void SAL_CALL SdStyleSheet::removeModifyListener( const Reference< XModifyListener >& xListener ) throw (RuntimeException)
935 {
936 	mrBHelper.removeListener( XModifyListener::static_type(), xListener );
937 }
938 
939 //------------------------------------------------------------------------
940 
notifyModifyListener()941 void SdStyleSheet::notifyModifyListener()
942 {
943 	MutexGuard aGuard( mrBHelper.rMutex );
944 
945 	OInterfaceContainerHelper * pContainer = mrBHelper.getContainer( XModifyListener::static_type() );
946 	if( pContainer )
947 	{
948 		EventObject aEvt( static_cast< OWeakObject * >( this ) );
949 		pContainer->forEach<XModifyListener>( boost::bind( &XModifyListener::modified, _1, boost::cref( aEvt ) ) );
950 	}
951 }
952 
953 
954 // --------------------------------------------------------------------
955 // XServiceInfo
956 // --------------------------------------------------------------------
957 
getImplementationName()958 OUString SAL_CALL SdStyleSheet::getImplementationName() throw(RuntimeException)
959 {
960 	return OUString::createFromAscii( "SdStyleSheet" );
961 }
962 
963 // --------------------------------------------------------------------
964 
supportsService(const OUString & ServiceName)965 sal_Bool SAL_CALL SdStyleSheet::supportsService( const OUString& ServiceName ) throw(RuntimeException)
966 {
967 	return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
968 }
969 
970 // --------------------------------------------------------------------
971 
getSupportedServiceNames()972 Sequence< OUString > SAL_CALL SdStyleSheet::getSupportedServiceNames() throw(RuntimeException)
973 {
974 	Sequence< OUString > aNameSequence( 10 );
975 	OUString* pStrings = aNameSequence.getArray();
976 
977 	*pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.Style" ) );
978 	*pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.FillProperties" ) );
979 	*pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.LineProperties" ) );
980 	*pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.ShadowProperties" ) );
981 	*pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.ConnectorProperties" ) );
982 	*pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.MeasureProperties" ) );
983 	*pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphProperties" ) );
984 	*pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterProperties" ) );
985 	*pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.TextProperties" ) );
986 	*pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.Text" ) );
987 
988 	return aNameSequence;
989 }
990 
991 // --------------------------------------------------------------------
992 // XNamed
993 // --------------------------------------------------------------------
994 
getName()995 OUString SAL_CALL SdStyleSheet::getName() throw(RuntimeException)
996 {
997 	OGuard aGuard( Application::GetSolarMutex() );
998 	throwIfDisposed();
999 	return GetApiName();
1000 }
1001 
1002 // --------------------------------------------------------------------
1003 
setName(const OUString & rName)1004 void SAL_CALL SdStyleSheet::setName( const OUString& rName  ) throw(RuntimeException)
1005 {
1006 	OGuard aGuard( Application::GetSolarMutex() );
1007 	throwIfDisposed();
1008 
1009 	if( SetName( rName ) )
1010 	{
1011 		msApiName = rName;
1012 		Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
1013 	}
1014 }
1015 
1016 // --------------------------------------------------------------------
1017 // XStyle
1018 // --------------------------------------------------------------------
1019 
isUserDefined()1020 sal_Bool SAL_CALL SdStyleSheet::isUserDefined() throw(RuntimeException)
1021 {
1022 	OGuard aGuard( Application::GetSolarMutex() );
1023 	throwIfDisposed();
1024 	return IsUserDefined() ? sal_True : sal_False;
1025 }
1026 
1027 // --------------------------------------------------------------------
1028 
isInUse()1029 sal_Bool SAL_CALL SdStyleSheet::isInUse() throw(RuntimeException)
1030 {
1031 	OGuard aGuard( Application::GetSolarMutex() );
1032 	throwIfDisposed();
1033 	return IsUsed() ? sal_True : sal_False;
1034 }
1035 
1036 // --------------------------------------------------------------------
1037 
getParentStyle()1038 OUString SAL_CALL SdStyleSheet::getParentStyle() throw(RuntimeException)
1039 {
1040 	OGuard aGuard( Application::GetSolarMutex() );
1041 	throwIfDisposed();
1042 
1043 	if( GetParent().Len() )
1044 	{
1045 		SdStyleSheet* pParentStyle = static_cast< SdStyleSheet* >( mxPool->Find( GetParent(), nFamily ) );
1046 		if( pParentStyle )
1047 			return pParentStyle->msApiName;
1048 	}
1049 	return OUString();
1050 }
1051 
1052 // --------------------------------------------------------------------
1053 
setParentStyle(const OUString & rParentName)1054 void SAL_CALL SdStyleSheet::setParentStyle( const OUString& rParentName  ) throw(NoSuchElementException, RuntimeException)
1055 {
1056 	OGuard aGuard( Application::GetSolarMutex() );
1057 	throwIfDisposed();
1058 
1059 	if( rParentName.getLength() )
1060 	{
1061 		const SfxStyles& rStyles = mxPool->GetStyles();
1062 
1063 		for( SfxStyles::const_iterator iter( rStyles.begin() ); iter != rStyles.end(); iter++ )
1064 		{
1065 			SdStyleSheet* pStyle = static_cast< SdStyleSheet* >( (*iter).get() );
1066 			if( pStyle && (pStyle->nFamily == nFamily) && (pStyle->msApiName == rParentName) )
1067 			{
1068 				if( pStyle != this )
1069 					SetParent( pStyle->GetName() );
1070 				return;
1071 			}
1072 		}
1073 		throw NoSuchElementException();
1074 	}
1075 	else
1076 	{
1077 		SetParent( rParentName );
1078 	}
1079 }
1080 
1081 // --------------------------------------------------------------------
1082 // XPropertySet
1083 // --------------------------------------------------------------------
1084 
getPropertySetInfo()1085 Reference< XPropertySetInfo > SdStyleSheet::getPropertySetInfo() throw(RuntimeException)
1086 {
1087 	throwIfDisposed();
1088     static Reference< XPropertySetInfo > xInfo;
1089     if( !xInfo.is() )
1090         xInfo = GetStylePropertySet().getPropertySetInfo();
1091 	return xInfo;
1092 }
1093 
1094 // --------------------------------------------------------------------
1095 
setPropertyValue(const OUString & aPropertyName,const Any & aValue)1096 void SAL_CALL SdStyleSheet::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
1097 {
1098 	OGuard aGuard( Application::GetSolarMutex() );
1099 	throwIfDisposed();
1100 
1101 	const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( aPropertyName );
1102 	if( pEntry == NULL )
1103 	{
1104 		throw UnknownPropertyException();
1105 	}
1106 	else
1107 	{
1108 		if( pEntry->nWID == SDRATTR_TEXTDIRECTION )
1109 			return; // not yet implemented for styles
1110 
1111 		if( pEntry->nWID == WID_STYLE_FAMILY )
1112 			throw PropertyVetoException();
1113 
1114 		if( (pEntry->nWID == EE_PARA_NUMBULLET) && (GetFamily() == SD_STYLE_FAMILY_MASTERPAGE) )
1115 		{
1116 			String aStr;
1117 			const sal_uInt32 nTempHelpId = GetHelpId( aStr );
1118 
1119 			if( (nTempHelpId >= HID_PSEUDOSHEET_OUTLINE2) && (nTempHelpId <= HID_PSEUDOSHEET_OUTLINE9) )
1120 				return;
1121 		}
1122 
1123 		SfxItemSet &rStyleSet = GetItemSet();
1124 
1125 		if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
1126 		{
1127 			BitmapMode eMode;
1128 			if( aValue >>= eMode )
1129 			{
1130 				rStyleSet.Put( XFillBmpStretchItem( eMode == BitmapMode_STRETCH ) );
1131 				rStyleSet.Put( XFillBmpTileItem( eMode == BitmapMode_REPEAT ) );
1132 				return;
1133 			}
1134 			throw IllegalArgumentException();
1135 		}
1136 
1137 		SfxItemSet aSet( GetPool().GetPool(),	pEntry->nWID, pEntry->nWID);
1138 		aSet.Put( rStyleSet );
1139 
1140 		if( !aSet.Count() )
1141 		{
1142 			if( EE_PARA_NUMBULLET == pEntry->nWID )
1143 			{
1144 				Font aBulletFont;
1145 				SdStyleSheetPool::PutNumBulletItem( this, aBulletFont );
1146 				aSet.Put( rStyleSet );
1147 			}
1148 			else
1149 			{
1150 				aSet.Put( GetPool().GetPool().GetDefaultItem( pEntry->nWID ) );
1151 			}
1152 		}
1153 
1154 		if( pEntry->nMemberId == MID_NAME &&
1155 			( pEntry->nWID == XATTR_FILLBITMAP || pEntry->nWID == XATTR_FILLGRADIENT ||
1156 			  pEntry->nWID == XATTR_FILLHATCH || pEntry->nWID == XATTR_FILLFLOATTRANSPARENCE ||
1157 			  pEntry->nWID == XATTR_LINESTART || pEntry->nWID == XATTR_LINEEND || pEntry->nWID == XATTR_LINEDASH) )
1158 		{
1159 			OUString aTempName;
1160 			if(!(aValue >>= aTempName ))
1161 				throw IllegalArgumentException();
1162 
1163 			SvxShape::SetFillAttribute( pEntry->nWID, aTempName, aSet );
1164 		}
1165 		else if(!SvxUnoTextRangeBase::SetPropertyValueHelper( aSet, pEntry, aValue, aSet ))
1166 		{
1167 			SvxItemPropertySet_setPropertyValue( GetStylePropertySet(), pEntry, aValue, aSet );
1168 		}
1169 
1170 		rStyleSet.Put( aSet );
1171 		Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
1172 	}
1173 }
1174 
1175 // --------------------------------------------------------------------
1176 
getPropertyValue(const OUString & PropertyName)1177 Any SAL_CALL SdStyleSheet::getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1178 {
1179 	OGuard aGuard( Application::GetSolarMutex() );
1180 
1181 	throwIfDisposed();
1182 
1183 	const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( PropertyName );
1184 	if( pEntry == NULL )
1185 	{
1186 		throw UnknownPropertyException();
1187 	}
1188 	else
1189 	{
1190 		Any aAny;
1191 
1192 		if( pEntry->nWID == WID_STYLE_FAMILY )
1193 		{
1194 			if( nFamily == SD_STYLE_FAMILY_MASTERPAGE )
1195 			{
1196 				const OUString aLayoutName( GetName() );
1197 				aAny <<= aLayoutName.copy( 0, aLayoutName.indexOf(OUString( RTL_CONSTASCII_USTRINGPARAM(SD_LT_SEPARATOR) ) ) );
1198 			}
1199 			else
1200 			{
1201 				aAny <<= GetFamilyString(nFamily);
1202 			}
1203 		}
1204 		else if( pEntry->nWID == WID_STYLE_DISPNAME )
1205 		{
1206 			aAny <<= maDisplayName;
1207 		}
1208 		else if( pEntry->nWID == SDRATTR_TEXTDIRECTION )
1209 		{
1210 			aAny <<= sal_False;
1211 		}
1212 		else if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
1213 		{
1214 			SfxItemSet &rStyleSet = GetItemSet();
1215 
1216 			XFillBmpStretchItem* pStretchItem = (XFillBmpStretchItem*)rStyleSet.GetItem(XATTR_FILLBMP_STRETCH);
1217 			XFillBmpTileItem* pTileItem = (XFillBmpTileItem*)rStyleSet.GetItem(XATTR_FILLBMP_TILE);
1218 
1219 			if( pStretchItem && pTileItem )
1220 			{
1221 				if( pTileItem->GetValue() )
1222 					aAny <<= BitmapMode_REPEAT;
1223 				else if( pStretchItem->GetValue() )
1224 					aAny <<= BitmapMode_STRETCH;
1225 				else
1226 					aAny <<= BitmapMode_NO_REPEAT;
1227 			}
1228 		}
1229 		else
1230 		{
1231 			SfxItemSet aSet( GetPool().GetPool(),	pEntry->nWID, pEntry->nWID);
1232 
1233 			const SfxPoolItem* pItem;
1234 			SfxItemSet& rStyleSet = GetItemSet();
1235 
1236 			if( rStyleSet.GetItemState(	pEntry->nWID, sal_True, &pItem ) == SFX_ITEM_SET )
1237 				aSet.Put(  *pItem );
1238 
1239 			if( !aSet.Count() )
1240 				aSet.Put( GetPool().GetPool().GetDefaultItem( pEntry->nWID ) );
1241 
1242 			if(SvxUnoTextRangeBase::GetPropertyValueHelper( aSet, pEntry, aAny ))
1243 				return aAny;
1244 
1245 			// Hole Wert aus ItemSet
1246 			aAny = SvxItemPropertySet_getPropertyValue( GetStylePropertySet(),pEntry, aSet );
1247 		}
1248 
1249 		if( *pEntry->pType != aAny.getValueType() )
1250 		{
1251 			// since the sfx uint16 item now exports a sal_Int32, we may have to fix this here
1252 			if( ( *pEntry->pType == ::getCppuType((const sal_Int16*)0)) && aAny.getValueType() == ::getCppuType((const sal_Int32*)0) )
1253 			{
1254 				sal_Int32 nValue = 0;
1255 				aAny >>= nValue;
1256 				aAny <<= (sal_Int16)nValue;
1257 			}
1258 			else
1259 			{
1260 				DBG_ERROR("SvxShape::GetAnyForItem() Returnvalue has wrong Type!" );
1261 			}
1262 		}
1263 
1264 		return aAny;
1265 	}
1266 }
1267 
1268 // --------------------------------------------------------------------
1269 
addPropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)1270 void SAL_CALL SdStyleSheet::addPropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >&  ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) {}
removePropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)1271 void SAL_CALL SdStyleSheet::removePropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >&  ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) {}
addVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)1272 void SAL_CALL SdStyleSheet::addVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >&  ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) {}
removeVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)1273 void SAL_CALL SdStyleSheet::removeVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >&  ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) {}
1274 
1275 // --------------------------------------------------------------------
1276 // XPropertyState
1277 // --------------------------------------------------------------------
1278 
getPropertyState(const OUString & PropertyName)1279 PropertyState SAL_CALL SdStyleSheet::getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
1280 {
1281 	OGuard aGuard( Application::GetSolarMutex() );
1282 
1283 	throwIfDisposed();
1284 
1285 	const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( PropertyName );
1286 
1287 	if( pEntry == NULL )
1288 		throw UnknownPropertyException();
1289 
1290 	if( pEntry->nWID == WID_STYLE_FAMILY )
1291 	{
1292 		return PropertyState_DIRECT_VALUE;
1293 	}
1294 	else if( pEntry->nWID == SDRATTR_TEXTDIRECTION )
1295 	{
1296 		return PropertyState_DEFAULT_VALUE;
1297 	}
1298 	else if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
1299 	{
1300 		const SfxItemSet& rSet = GetItemSet();
1301 
1302 		if( rSet.GetItemState( XATTR_FILLBMP_STRETCH, false ) == SFX_ITEM_SET ||
1303 			rSet.GetItemState( XATTR_FILLBMP_TILE, false ) == SFX_ITEM_SET )
1304 		{
1305 			return PropertyState_DIRECT_VALUE;
1306 		}
1307 		else
1308 		{
1309 			return PropertyState_AMBIGUOUS_VALUE;
1310 		}
1311 	}
1312 	else
1313 	{
1314 		SfxItemSet &rStyleSet = GetItemSet();
1315 
1316 		PropertyState eState;
1317 
1318 		switch( rStyleSet.GetItemState( pEntry->nWID, sal_False ) )
1319 		{
1320 		case SFX_ITEM_READONLY:
1321 		case SFX_ITEM_SET:
1322 			eState = PropertyState_DIRECT_VALUE;
1323 			break;
1324 		case SFX_ITEM_DEFAULT:
1325 			eState = PropertyState_DEFAULT_VALUE;
1326 			break;
1327 //		case SFX_ITEM_DONTCARE:
1328 //		case SFX_ITEM_DISABLED:
1329 		default:
1330 			eState = PropertyState_AMBIGUOUS_VALUE;
1331 			break;
1332 		}
1333 
1334 		// if a item is set, this doesn't mean we want it :)
1335 		if( ( PropertyState_DIRECT_VALUE == eState ) )
1336 		{
1337 			switch( pEntry->nWID )
1338 			{
1339 			case XATTR_FILLBITMAP:
1340 			case XATTR_FILLGRADIENT:
1341 			case XATTR_FILLHATCH:
1342 			case XATTR_FILLFLOATTRANSPARENCE:
1343 			case XATTR_LINEEND:
1344 			case XATTR_LINESTART:
1345 			case XATTR_LINEDASH:
1346 				{
1347 					NameOrIndex* pItem = (NameOrIndex*)rStyleSet.GetItem((sal_uInt16)pEntry->nWID);
1348 					if( ( pItem == NULL ) || ( pItem->GetName().Len() == 0) )
1349 						eState = PropertyState_DEFAULT_VALUE;
1350 				}
1351 			}
1352 		}
1353 
1354 		return eState;
1355 	}
1356 }
1357 
1358 // --------------------------------------------------------------------
1359 
getPropertyStates(const Sequence<OUString> & aPropertyName)1360 Sequence< PropertyState > SAL_CALL SdStyleSheet::getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
1361 {
1362 	OGuard aGuard( Application::GetSolarMutex() );
1363 
1364 	throwIfDisposed();
1365 
1366 	sal_Int32 nCount = aPropertyName.getLength();
1367 	const OUString* pNames = aPropertyName.getConstArray();
1368 
1369 	Sequence< PropertyState > aPropertyStateSequence( nCount );
1370 	PropertyState* pState = aPropertyStateSequence.getArray();
1371 
1372 	while( nCount-- )
1373 		*pState++ = getPropertyState( *pNames++ );
1374 
1375 	return aPropertyStateSequence;
1376 }
1377 
1378 // --------------------------------------------------------------------
1379 
setPropertyToDefault(const OUString & PropertyName)1380 void SAL_CALL SdStyleSheet::setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
1381 {
1382 	OGuard aGuard( Application::GetSolarMutex() );
1383 
1384 	throwIfDisposed();
1385 
1386 	const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( PropertyName );
1387 	if( pEntry == NULL )
1388 		throw UnknownPropertyException();
1389 
1390 	SfxItemSet &rStyleSet = GetItemSet();
1391 
1392 	if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
1393 	{
1394 		rStyleSet.ClearItem( XATTR_FILLBMP_STRETCH );
1395 		rStyleSet.ClearItem( XATTR_FILLBMP_TILE );
1396 	}
1397 	else
1398 	{
1399 		rStyleSet.ClearItem( pEntry->nWID );
1400 	}
1401 	Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
1402 }
1403 
1404 // --------------------------------------------------------------------
1405 
getPropertyDefault(const OUString & aPropertyName)1406 Any SAL_CALL SdStyleSheet::getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1407 {
1408 	OGuard aGuard( Application::GetSolarMutex() );
1409 
1410 	throwIfDisposed();
1411 
1412 	const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( aPropertyName );
1413 	if( pEntry == NULL )
1414 		throw UnknownPropertyException();
1415     Any aRet;
1416 	if( pEntry->nWID == WID_STYLE_FAMILY )
1417 	{
1418 		aRet <<= GetFamilyString(nFamily);
1419 	}
1420 	else if( pEntry->nWID == SDRATTR_TEXTDIRECTION )
1421 	{
1422 		aRet <<= sal_False;
1423 	}
1424 	else if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
1425 	{
1426 		aRet <<= BitmapMode_REPEAT;
1427 	}
1428 	else
1429 	{
1430 		SfxItemPool& rMyPool = GetPool().GetPool();
1431 		SfxItemSet aSet( rMyPool,	pEntry->nWID, pEntry->nWID);
1432 		aSet.Put( rMyPool.GetDefaultItem( pEntry->nWID ) );
1433         aRet = SvxItemPropertySet_getPropertyValue( GetStylePropertySet(), pEntry, aSet );
1434 	}
1435     return aRet;
1436 }
1437 
1438 // --------------------------------------------------------------------
1439 
1440 /** this is used because our property map is not sorted yet */
getPropertyMapEntry(const OUString & rPropertyName) const1441 const SfxItemPropertySimpleEntry* SdStyleSheet::getPropertyMapEntry( const OUString& rPropertyName ) const throw()
1442 {
1443 	return GetStylePropertySet().getPropertyMapEntry(rPropertyName);
1444 }
1445 
1446