Update ooo320-m1
[ooovba.git] / svx / source / sdr / properties / textproperties.cxx
blob229ba89db59ed8b703bb8401b63652113a2be494
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: textproperties.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/properties/textproperties.hxx>
34 #include <svtools/itemset.hxx>
35 #include <svtools/style.hxx>
36 #include <svtools/itemiter.hxx>
37 #include <svtools/smplhint.hxx>
38 #include <svx/svddef.hxx>
39 #include <svx/svdotext.hxx>
40 #include <svx/svdoutl.hxx>
41 #include <svx/writingmodeitem.hxx>
42 #include <svx/svdmodel.hxx>
43 #include <svx/outlobj.hxx>
44 #include <svx/xflclit.hxx>
45 #include <svx/adjitem.hxx>
46 #include <svx/svdetc.hxx>
47 #include <svx/editeng.hxx>
48 #include <svx/flditem.hxx>
49 #include <svx/xlnwtit.hxx>
50 #include <svx/svdpool.hxx>
52 //////////////////////////////////////////////////////////////////////////////
54 namespace sdr
56 namespace properties
58 SfxItemSet& TextProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
60 return *(new SfxItemSet(rPool,
62 // range from SdrAttrObj
63 SDRATTR_START, SDRATTR_SHADOW_LAST,
64 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
65 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
67 // range from SdrTextObj
68 EE_ITEMS_START, EE_ITEMS_END,
70 // end
71 0, 0));
74 TextProperties::TextProperties(SdrObject& rObj)
75 : AttributeProperties(rObj),
76 maVersion(0)
80 TextProperties::TextProperties(const TextProperties& rProps, SdrObject& rObj)
81 : AttributeProperties(rProps, rObj),
82 maVersion(rProps.getVersion())
86 TextProperties::~TextProperties()
90 BaseProperties& TextProperties::Clone(SdrObject& rObj) const
92 return *(new TextProperties(*this, rObj));
95 void TextProperties::ItemSetChanged(const SfxItemSet& rSet)
97 SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
98 sal_Int32 nText = rObj.getTextCount();
100 // #i101556# ItemSet has changed -> new version
101 maVersion++;
103 while( --nText >= 0 )
105 SdrText* pText = rObj.getText( nText );
107 OutlinerParaObject* pParaObj = pText ? pText->GetOutlinerParaObject() : 0;
109 if(pParaObj)
111 const bool bTextEdit = rObj.IsTextEditActive() && (rObj.getActiveText() == pText);
113 // handle outliner attributes
114 GetObjectItemSet();
115 Outliner* pOutliner = rObj.GetTextEditOutliner();
117 if(!bTextEdit)
119 pOutliner = &rObj.ImpGetDrawOutliner();
120 pOutliner->SetText(*pParaObj);
123 sal_uInt32 nParaCount(pOutliner->GetParagraphCount());
125 for(sal_uInt16 nPara = 0; nPara < nParaCount; nPara++)
127 SfxItemSet aSet(pOutliner->GetParaAttribs(nPara));
128 aSet.Put(rSet);
129 pOutliner->SetParaAttribs(nPara, aSet);
132 if(!bTextEdit)
134 if(nParaCount)
136 // force ItemSet
137 GetObjectItemSet();
139 SfxItemSet aNewSet(pOutliner->GetParaAttribs(0L));
140 mpItemSet->Put(aNewSet);
143 OutlinerParaObject* pTemp = pOutliner->CreateParaObject(0, (sal_uInt16)nParaCount);
144 pOutliner->Clear();
146 rObj.NbcSetOutlinerParaObjectForText(pTemp,pText);
151 // Extra-Repaint for radical layout changes (#43139#)
152 if(SFX_ITEM_SET == rSet.GetItemState(SDRATTR_TEXT_CONTOURFRAME))
154 // Here only repaint wanted
155 rObj.ActionChanged();
156 //rObj.BroadcastObjectChange();
159 // call parent
160 AttributeProperties::ItemSetChanged(rSet);
163 void TextProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
165 SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
167 // #i25616#
168 sal_Int32 nOldLineWidth(0L);
170 if(XATTR_LINEWIDTH == nWhich && rObj.DoesSupportTextIndentingOnLineWidthChange())
172 nOldLineWidth = ((const XLineWidthItem&)GetItem(XATTR_LINEWIDTH)).GetValue();
175 if(pNewItem && (SDRATTR_TEXTDIRECTION == nWhich))
177 sal_Bool bVertical(com::sun::star::text::WritingMode_TB_RL == ((SvxWritingModeItem*)pNewItem)->GetValue());
178 rObj.SetVerticalWriting(bVertical);
181 // #95501# reset to default
182 if(!pNewItem && !nWhich && rObj.HasText() )
184 SdrOutliner& rOutliner = rObj.ImpGetDrawOutliner();
186 sal_Int32 nCount = rObj.getTextCount();
187 while( nCount-- )
189 SdrText* pText = rObj.getText( nCount );
190 OutlinerParaObject* pParaObj = pText->GetOutlinerParaObject();
191 rOutliner.SetText(*pParaObj);
192 sal_uInt32 nParaCount(rOutliner.GetParagraphCount());
194 if(nParaCount)
196 ESelection aSelection( 0, 0, EE_PARA_ALL, EE_PARA_ALL);
197 rOutliner.RemoveAttribs(aSelection, sal_True, 0);
199 OutlinerParaObject* pTemp = rOutliner.CreateParaObject(0, (sal_uInt16)nParaCount);
200 rOutliner.Clear();
202 rObj.NbcSetOutlinerParaObjectForText( pTemp, pText );
207 // call parent
208 AttributeProperties::ItemChange( nWhich, pNewItem );
210 // #i25616#
211 if(XATTR_LINEWIDTH == nWhich && rObj.DoesSupportTextIndentingOnLineWidthChange())
213 const sal_Int32 nNewLineWidth(((const XLineWidthItem&)GetItem(XATTR_LINEWIDTH)).GetValue());
214 const sal_Int32 nDifference((nNewLineWidth - nOldLineWidth) / 2);
216 if(nDifference)
218 const sal_Bool bLineVisible(XLINE_NONE != ((const XLineStyleItem&)(GetItem(XATTR_LINESTYLE))).GetValue());
220 if(bLineVisible)
222 const sal_Int32 nLeftDist(((const SdrTextLeftDistItem&)GetItem(SDRATTR_TEXT_LEFTDIST)).GetValue());
223 const sal_Int32 nRightDist(((const SdrTextRightDistItem&)GetItem(SDRATTR_TEXT_RIGHTDIST)).GetValue());
224 const sal_Int32 nUpperDist(((const SdrTextUpperDistItem&)GetItem(SDRATTR_TEXT_UPPERDIST)).GetValue());
225 const sal_Int32 nLowerDist(((const SdrTextLowerDistItem&)GetItem(SDRATTR_TEXT_LOWERDIST)).GetValue());
227 SetObjectItemDirect(SdrTextLeftDistItem(nLeftDist + nDifference));
228 SetObjectItemDirect(SdrTextRightDistItem(nRightDist + nDifference));
229 SetObjectItemDirect(SdrTextUpperDistItem(nUpperDist + nDifference));
230 SetObjectItemDirect(SdrTextLowerDistItem(nLowerDist + nDifference));
236 void TextProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
238 SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
240 // call parent
241 AttributeProperties::SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
243 // #i101556# StyleSheet has changed -> new version
244 maVersion++;
246 if( rObj.GetModel() /*&& !rObj.IsTextEditActive()*/ && !rObj.IsLinkedText() )
248 SdrOutliner& rOutliner = rObj.ImpGetDrawOutliner();
250 sal_Int32 nText = rObj.getTextCount();
252 while( --nText >= 0 )
254 SdrText* pText = rObj.getText( nText );
256 OutlinerParaObject* pParaObj = pText ? pText->GetOutlinerParaObject() : 0;
257 if( !pParaObj )
258 continue;
260 // apply StyleSheet to all paragraphs
261 rOutliner.SetText(*pParaObj);
262 sal_uInt32 nParaCount(rOutliner.GetParagraphCount());
264 if(nParaCount)
266 for(sal_uInt16 nPara = 0; nPara < nParaCount; nPara++)
268 SfxItemSet* pTempSet = 0L;
270 // since setting the stylesheet removes all para attributes
271 if(bDontRemoveHardAttr)
273 // we need to remember them if we want to keep them
274 pTempSet = new SfxItemSet(rOutliner.GetParaAttribs(nPara));
277 if(GetStyleSheet())
279 if((OBJ_OUTLINETEXT == rObj.GetTextKind()) && (SdrInventor == rObj.GetObjInventor()))
281 String aNewStyleSheetName(GetStyleSheet()->GetName());
282 aNewStyleSheetName.Erase(aNewStyleSheetName.Len() - 1, 1);
283 sal_Int16 nDepth = rOutliner.GetDepth((sal_uInt16)nPara);
284 aNewStyleSheetName += String::CreateFromInt32( nDepth <= 0 ? 1 : nDepth + 1);
286 SdrModel* pModel = rObj.GetModel();
287 SfxStyleSheetBasePool* pStylePool = (pModel != NULL) ? pModel->GetStyleSheetPool() : 0L;
288 SfxStyleSheet* pNewStyle = (SfxStyleSheet*)pStylePool->Find(aNewStyleSheetName, GetStyleSheet()->GetFamily());
289 DBG_ASSERT( pNewStyle, "AutoStyleSheetName - Style not found!" );
291 if(pNewStyle)
293 rOutliner.SetStyleSheet(nPara, pNewStyle);
296 else
298 rOutliner.SetStyleSheet(nPara, GetStyleSheet());
301 else
303 // remove StyleSheet
304 rOutliner.SetStyleSheet(nPara, 0L);
307 if(bDontRemoveHardAttr)
309 if(pTempSet)
311 // restore para attributes
312 rOutliner.SetParaAttribs(nPara, *pTempSet);
315 else
317 if(pNewStyleSheet)
319 // remove all hard paragraph attributes
320 // which occur in StyleSheet, take care of
321 // parents (!)
322 SfxItemIter aIter(pNewStyleSheet->GetItemSet());
323 const SfxPoolItem* pItem = aIter.FirstItem();
325 while(pItem)
327 if(!IsInvalidItem(pItem))
329 sal_uInt16 nW(pItem->Which());
331 if(nW >= EE_ITEMS_START && nW <= EE_ITEMS_END)
333 rOutliner.QuickRemoveCharAttribs((sal_uInt16)nPara, nW);
336 pItem = aIter.NextItem();
341 if(pTempSet)
343 delete pTempSet;
347 OutlinerParaObject* pTemp = rOutliner.CreateParaObject(0, (sal_uInt16)nParaCount);
348 rOutliner.Clear();
349 rObj.NbcSetOutlinerParaObjectForText(pTemp, pText);
354 if(rObj.IsTextFrame())
356 rObj.NbcAdjustTextFrameWidthAndHeight();
360 void TextProperties::ForceDefaultAttributes()
362 SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
364 if( rObj.GetObjInventor() == SdrInventor )
366 const sal_uInt16 nSdrObjKind = rObj.GetObjIdentifier();
368 if( nSdrObjKind == OBJ_TITLETEXT || nSdrObjKind == OBJ_OUTLINETEXT )
369 return; // no defaults for presentation objects
372 bool bTextFrame(rObj.IsTextFrame());
374 // force ItemSet
375 GetObjectItemSet();
377 if(bTextFrame)
379 mpItemSet->Put(XLineStyleItem(XLINE_NONE));
380 mpItemSet->Put(XFillColorItem(String(), Color(COL_WHITE)));
381 mpItemSet->Put(XFillStyleItem(XFILL_NONE));
383 else
385 mpItemSet->Put(SvxAdjustItem(SVX_ADJUST_CENTER, EE_PARA_JUST));
386 mpItemSet->Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_CENTER));
387 mpItemSet->Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
391 void TextProperties::ForceStyleToHardAttributes()
393 // #i61284# call parent first to get the hard ObjectItemSet
394 AttributeProperties::ForceStyleToHardAttributes();
396 // #i61284# push hard ObjectItemSet to OutlinerParaObject attributes
397 // using existing functionality
398 GetObjectItemSet(); // force ItemSet
399 ItemSetChanged(*mpItemSet);
401 // now the standard TextProperties stuff
402 SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
404 if(rObj.GetModel()
405 && !rObj.IsTextEditActive()
406 && !rObj.IsLinkedText())
408 Outliner* pOutliner = SdrMakeOutliner(OUTLINERMODE_OUTLINEOBJECT, rObj.GetModel());
409 sal_Int32 nText = rObj.getTextCount();
411 while( --nText >= 0 )
413 SdrText* pText = rObj.getText( nText );
415 OutlinerParaObject* pParaObj = pText ? pText->GetOutlinerParaObject() : 0;
416 if( !pParaObj )
417 continue;
419 pOutliner->SetText(*pParaObj);
421 sal_uInt32 nParaCount(pOutliner->GetParagraphCount());
423 if(nParaCount)
425 sal_Bool bBurnIn(sal_False);
427 for(sal_uInt16 nPara = 0; nPara < nParaCount; nPara++)
429 SfxStyleSheet* pSheet = pOutliner->GetStyleSheet(nPara);
431 if(pSheet)
433 SfxItemSet aParaSet(pOutliner->GetParaAttribs(nPara));
434 SfxItemSet aSet(*aParaSet.GetPool());
435 aSet.Put(pSheet->GetItemSet());
437 /** the next code handles a special case for paragraphs that contain a
438 url field. The color for URL fields is either the system color for
439 urls or the char color attribute that formats the portion in which the
440 url field is contained.
441 When we set a char color attribute to the paragraphs item set from the
442 styles item set, we would have this char color attribute as an attribute
443 that is spanned over the complete paragraph after xml import due to some
444 problems in the xml import (using a XCursor on import so it does not know
445 the paragraphs and can't set char attributes to paragraphs ).
447 To avoid this, as soon as we try to set a char color attribute from the style
449 1. check if we have at least one url field in this paragraph
450 2. if we found at least one url field, we span the char color attribute over
451 all portions that are not url fields and remove the char color attribute
452 from the paragraphs item set
455 sal_Bool bHasURL(sal_False);
457 if(aSet.GetItemState(EE_CHAR_COLOR) == SFX_ITEM_SET)
459 EditEngine* pEditEngine = const_cast<EditEngine*>(&(pOutliner->GetEditEngine()));
460 EECharAttribArray aAttribs;
461 pEditEngine->GetCharAttribs((sal_uInt16)nPara, aAttribs);
462 sal_uInt16 nAttrib;
464 for(nAttrib = 0; nAttrib < aAttribs.Count(); nAttrib++)
466 struct EECharAttrib aAttrib(aAttribs.GetObject(nAttrib));
468 if(EE_FEATURE_FIELD == aAttrib.pAttr->Which())
470 if(aAttrib.pAttr)
472 SvxFieldItem* pFieldItem = (SvxFieldItem*)aAttrib.pAttr;
474 if(pFieldItem)
476 const SvxFieldData* pData = pFieldItem->GetField();
478 if(pData && pData->ISA(SvxURLField))
480 bHasURL = sal_True;
481 break;
488 if(bHasURL)
490 SfxItemSet aColorSet(*aSet.GetPool(), EE_CHAR_COLOR, EE_CHAR_COLOR );
491 aColorSet.Put(aSet, FALSE);
493 ESelection aSel((sal_uInt16)nPara, 0);
495 for(nAttrib = 0; nAttrib < aAttribs.Count(); nAttrib++)
497 struct EECharAttrib aAttrib(aAttribs.GetObject(nAttrib));
499 if(EE_FEATURE_FIELD == aAttrib.pAttr->Which())
501 aSel.nEndPos = aAttrib.nStart;
503 if(aSel.nStartPos != aSel.nEndPos)
505 pEditEngine->QuickSetAttribs(aColorSet, aSel);
508 aSel.nStartPos = aAttrib.nEnd;
512 aSel.nEndPos = pEditEngine->GetTextLen((sal_uInt16)nPara);
514 if(aSel.nStartPos != aSel.nEndPos)
516 pEditEngine->QuickSetAttribs( aColorSet, aSel );
522 aSet.Put(aParaSet, FALSE);
524 if(bHasURL)
526 aSet.ClearItem(EE_CHAR_COLOR);
529 pOutliner->SetParaAttribs(nPara, aSet);
530 bBurnIn = sal_True; // #i51163# Flag was set wrong
534 if(bBurnIn)
536 OutlinerParaObject* pTemp = pOutliner->CreateParaObject(0, (sal_uInt16)nParaCount);
537 rObj.NbcSetOutlinerParaObjectForText(pTemp,pText);
541 pOutliner->Clear();
543 delete pOutliner;
547 void TextProperties::SetObjectItemNoBroadcast(const SfxPoolItem& rItem)
549 GetObjectItemSet();
550 mpItemSet->Put(rItem);
554 void TextProperties::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
556 // call parent
557 AttributeProperties::Notify(rBC, rHint);
559 SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
560 if(rObj.HasText())
562 if(HAS_BASE(SfxStyleSheet, &rBC))
564 SfxSimpleHint* pSimple = PTR_CAST(SfxSimpleHint, &rHint);
565 sal_uInt32 nId(pSimple ? pSimple->GetId() : 0L);
567 if(SFX_HINT_DATACHANGED == nId)
569 rObj.SetPortionInfoChecked(sal_False);
571 sal_Int32 nText = rObj.getTextCount();
572 while( --nText > 0 )
574 OutlinerParaObject* pParaObj = rObj.getText(nText )->GetOutlinerParaObject();
575 if( pParaObj )
576 pParaObj->ClearPortionInfo();
578 rObj.SetTextSizeDirty();
580 if(rObj.IsTextFrame() && rObj.NbcAdjustTextFrameWidthAndHeight())
582 // here only repaint wanted
583 rObj.ActionChanged();
584 //rObj.BroadcastObjectChange();
587 // #i101556# content of StyleSheet has changed -> new version
588 maVersion++;
591 if(SFX_HINT_DYING == nId)
593 rObj.SetPortionInfoChecked(sal_False);
594 sal_Int32 nText = rObj.getTextCount();
595 while( --nText > 0 )
597 OutlinerParaObject* pParaObj = rObj.getText(nText )->GetOutlinerParaObject();
598 if( pParaObj )
599 pParaObj->ClearPortionInfo();
603 else if(HAS_BASE(SfxStyleSheetBasePool, &rBC))
605 SfxStyleSheetHintExtended* pExtendedHint = PTR_CAST(SfxStyleSheetHintExtended, &rHint);
607 if(pExtendedHint
608 && SFX_STYLESHEET_MODIFIED == pExtendedHint->GetHint())
610 String aOldName(pExtendedHint->GetOldName());
611 String aNewName(pExtendedHint->GetStyleSheet()->GetName());
612 SfxStyleFamily eFamily = pExtendedHint->GetStyleSheet()->GetFamily();
614 if(!aOldName.Equals(aNewName))
616 sal_Int32 nText = rObj.getTextCount();
617 while( --nText > 0 )
619 OutlinerParaObject* pParaObj = rObj.getText(nText )->GetOutlinerParaObject();
620 if( pParaObj )
621 pParaObj->ChangeStyleSheetName(eFamily, aOldName, aNewName);
629 // #i101556# Handout version information
630 sal_uInt32 TextProperties::getVersion() const
632 return maVersion;
634 } // end of namespace properties
635 } // end of namespace sdr
637 //////////////////////////////////////////////////////////////////////////////
638 // eof