1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/container/XNameAccess.hpp>
24 #include <futempl.hxx>
26 #include <editeng/editdata.hxx>
27 #include <editeng/bulletitem.hxx>
28 #include <svx/svxids.hrc>
29 #include <sfx2/bindings.hxx>
30 #include <svl/aeitem.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <editeng/eeitem.hxx>
33 #include <sfx2/request.hxx>
34 #include <editeng/numitem.hxx>
35 #include <editeng/editeng.hxx>
36 #include <editeng/lrspitem.hxx>
37 #include <svx/svdopage.hxx>
38 #include <editeng/colritem.hxx>
39 #include <editeng/brushitem.hxx>
40 #include <svx/svditer.hxx>
41 #include <svx/sdr/properties/properties.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <svx/xlndsit.hxx>
45 #include <svx/xlnstit.hxx>
46 #include <svx/xlnedit.hxx>
48 #include <stlsheet.hxx>
50 #include <stlpool.hxx>
54 #include <drawview.hxx>
55 #include <drawdoc.hxx>
56 #include <DrawDocShell.hxx>
57 #include <DrawViewShell.hxx>
58 #include <ViewShell.hxx>
60 #include <strings.hrc>
61 #include <prlayout.hxx>
62 #include <svx/xfillit.hxx>
63 #include <sdresid.hxx>
64 #include <OutlineViewShell.hxx>
66 #include <sdabstdlg.hxx>
69 using namespace com::sun::star::uno
;
70 using namespace com::sun::star::container
;
71 using namespace com::sun::star::beans
;
72 using namespace com::sun::star::style
;
78 FuTemplate::FuTemplate (
84 : FuPoor( pViewSh
, pWin
, pView
, pDoc
, rReq
)
88 rtl::Reference
<FuPoor
> FuTemplate::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
90 rtl::Reference
<FuPoor
> xFunc( new FuTemplate( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
91 xFunc
->DoExecute(rReq
);
95 void FuTemplate::DoExecute( SfxRequest
& rReq
)
97 const SfxItemSet
* pArgs
= rReq
.GetArgs();
98 sal_uInt16 nSId
= rReq
.GetSlot();
100 // get StyleSheet parameter
101 SfxStyleSheetBasePool
* pSSPool
= mpDoc
->GetDocSh()->GetStyleSheetPool();
102 SfxStyleSheetBase
* pStyleSheet
= nullptr;
104 const SfxPoolItem
* pItem
;
105 SfxStyleFamily nFamily
= SfxStyleFamily(USHRT_MAX
);
106 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_FAMILY
,
109 nFamily
= static_cast<SfxStyleFamily
>( pArgs
->Get( SID_STYLE_FAMILY
).GetValue());
111 else if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_FAMILYNAME
,
114 OUString sFamily
= pArgs
->Get( SID_STYLE_FAMILYNAME
).GetValue();
115 if (sFamily
== "graphics")
116 nFamily
= SfxStyleFamily::Para
;
118 nFamily
= SfxStyleFamily::Pseudo
;
122 sal_uInt16 nRetMask
= static_cast<sal_uInt16
>(SfxStyleSearchBits::All
);
126 case SID_STYLE_APPLY
:
128 case SID_STYLE_DELETE
:
131 case SID_STYLE_FAMILY
:
132 case SID_STYLE_NEW_BY_EXAMPLE
:
134 const SfxStringItem
* pNameItem
= rReq
.GetArg
<SfxStringItem
>(SID_APPLY_STYLE
);
135 const SfxStringItem
* pFamilyItem
= rReq
.GetArg
<SfxStringItem
>(SID_STYLE_FAMILYNAME
);
136 if ( pFamilyItem
&& pNameItem
)
140 Reference
< XStyleFamiliesSupplier
> xModel(mpDoc
->GetDocSh()->GetModel(), UNO_QUERY_THROW
);
141 Reference
< XNameAccess
> xCont( xModel
->getStyleFamilies() );
142 Reference
< XNameAccess
> xStyles( xCont
->getByName(pFamilyItem
->GetValue()), UNO_QUERY_THROW
);
143 Reference
< XPropertySet
> xInfo( xStyles
->getByName( pNameItem
->GetValue() ), UNO_QUERY_THROW
);
146 xInfo
->getPropertyValue( "DisplayName" ) >>= aUIName
;
147 if ( !aUIName
.isEmpty() )
148 rReq
.AppendItem( SfxStringItem( nSId
, aUIName
) );
155 if (pArgs
&& pArgs
->GetItemState(nSId
) == SfxItemState::SET
)
156 aStyleName
= static_cast<const SfxStringItem
&>( pArgs
->Get( nSId
) ).GetValue();
164 SfxStyleSheetBase
*p
= pSSPool
->Find(aStyleName
, nFamily
);
170 pStyleSheet
= &pSSPool
->Make( aStyleName
, nFamily
, SfxStyleSearchBits::UserDefined
);
172 if (pArgs
&& pArgs
->GetItemState(SID_STYLE_REFERENCE
) == SfxItemState::SET
)
174 OUString
aParentName( pArgs
->Get(SID_STYLE_REFERENCE
).GetValue());
175 pStyleSheet
->SetParent(aParentName
);
179 pStyleSheet
->SetParent(SdResId(STR_STANDARD_STYLESHEET_NAME
));
184 case SID_STYLE_NEW_BY_EXAMPLE
:
186 // at the moment, the dialog to enter the name of the template is still opened
187 SfxStyleSheetBase
*p
= pSSPool
->Find(aStyleName
, nFamily
);
193 pStyleSheet
= &pSSPool
->Make( aStyleName
, nFamily
, SfxStyleSearchBits::UserDefined
);
194 pStyleSheet
->SetParent(SdResId(STR_STANDARD_STYLESHEET_NAME
));
199 pStyleSheet
= pSSPool
->Find( aStyleName
, nFamily
);
202 case SID_STYLE_DELETE
:
203 pStyleSheet
= pSSPool
->Find( aStyleName
, nFamily
);
206 pSSPool
->Remove( pStyleSheet
);
207 nRetMask
= sal_uInt16(true);
212 nRetMask
= sal_uInt16(false);
218 pStyleSheet
= pSSPool
->Find( aStyleName
, nFamily
);
219 pStyleSheet
->SetHidden( nSId
== SID_STYLE_HIDE
);
220 nRetMask
= sal_uInt16(true);
223 case SID_STYLE_APPLY
:
224 // apply the template to the document
225 pStyleSheet
= pSSPool
->Find( aStyleName
, nFamily
);
227 // do not set presentation styles, they will be set implicit
228 if ( pStyleSheet
&& pStyleSheet
->GetFamily() != SfxStyleFamily::Pseudo
)
230 SfxStyleSheet
* pOldStyleSheet
= mpView
->GetStyleSheet();
233 if( // if the object had no style sheet, allow all
236 // allow if old and new style sheet has same family
237 pStyleSheet
->GetFamily() == pOldStyleSheet
->GetFamily() ||
239 // allow if old was background objects and new is graphics
240 (pStyleSheet
->GetFamily() == SfxStyleFamily::Para
&& pOldStyleSheet
->GetHelpId( aStr
) == HID_PSEUDOSHEET_BACKGROUNDOBJECTS
) ||
242 // allow if old was presentation and we are a drawing document
243 (pOldStyleSheet
->GetFamily() == SfxStyleFamily::Page
&& mpDoc
->GetDocumentType() == DocumentType::Draw
) )
245 mpView
->SetStyleSheet( static_cast<SfxStyleSheet
*>(pStyleSheet
));
247 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_FAMILY2
);
252 case SID_STYLE_WATERCAN
:
254 if( !SD_MOD()->GetWaterCan() )
256 if (pArgs
&& pArgs
->GetItemState( nSId
) == SfxItemState::SET
)
258 aStyleName
= static_cast<const SfxStringItem
&>( pArgs
->Get( nSId
) ).GetValue();
259 SD_MOD()->SetWaterCan( true );
260 pStyleSheet
= pSSPool
->Find( aStyleName
, nFamily
);
262 // no presentation object templates, they are only allowed implicitly
263 if( pStyleSheet
&& pStyleSheet
->GetFamily() != SfxStyleFamily::Pseudo
)
265 static_cast<SdStyleSheetPool
*>( pSSPool
)->SetActualStyleSheet( pStyleSheet
);
267 // we switch explicitly into selection mode
268 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute( SID_OBJECT_SELECT
,
269 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
273 SD_MOD()->SetWaterCan( false );
277 SD_MOD()->SetWaterCan( false );
278 // we have to re-enable to tools-bar
279 mpViewShell
->Invalidate();
293 PresentationObjects ePO
= PO_OUTLINE_1
;
297 ScopedVclPtr
<SfxAbstractTabDialog
> pStdDlg
;
298 ScopedVclPtr
<SfxAbstractTabDialog
> pPresDlg
;
299 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
300 bool bOldDocInOtherLanguage
= false;
302 SfxStyleFamily eFamily
= pStyleSheet
->GetFamily();
304 if (eFamily
== SfxStyleFamily::Para
)
306 pStdDlg
.disposeAndReset(pFact
? pFact
->CreateSdTabTemplateDlg(mpViewShell
->GetActiveWindow(), mpDoc
->GetDocSh(), *pStyleSheet
, mpDoc
, mpView
) : nullptr);
308 else if (eFamily
== SfxStyleFamily::Pseudo
)
310 OUString
aName(pStyleSheet
->GetName());
311 bool bBackground
= false;
313 if (aName
== SdResId(STR_PSEUDOSHEET_TITLE
))
317 else if (aName
== SdResId(STR_PSEUDOSHEET_SUBTITLE
))
322 SdResId(STR_PSEUDOSHEET_BACKGROUND
))
328 SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS
))
330 ePO
= PO_BACKGROUNDOBJECTS
;
333 SdResId(STR_PSEUDOSHEET_NOTES
))
337 else if(aName
.indexOf(SdResId(STR_PSEUDOSHEET_OUTLINE
)) != -1)
339 OUString
aOutlineStr(SdResId(STR_PSEUDOSHEET_OUTLINE
));
340 // determine number, mind the blank between name and number
341 OUString
aNumStr(aName
.copy(aOutlineStr
.getLength() + 1));
342 sal_uInt16 nLevel
= static_cast<sal_uInt16
>(aNumStr
.toInt32());
345 case 1: ePO
= PO_OUTLINE_1
; break;
346 case 2: ePO
= PO_OUTLINE_2
; break;
347 case 3: ePO
= PO_OUTLINE_3
; break;
348 case 4: ePO
= PO_OUTLINE_4
; break;
349 case 5: ePO
= PO_OUTLINE_5
; break;
350 case 6: ePO
= PO_OUTLINE_6
; break;
351 case 7: ePO
= PO_OUTLINE_7
; break;
352 case 8: ePO
= PO_OUTLINE_8
; break;
353 case 9: ePO
= PO_OUTLINE_9
; break;
358 OSL_FAIL("StyleSheet from older version with different language");
359 bOldDocInOtherLanguage
= true;
362 if( !bOldDocInOtherLanguage
)
364 pPresDlg
.disposeAndReset(pFact
? pFact
->CreateSdPresLayoutTemplateDlg( mpDocSh
, mpViewShell
->GetActiveWindow(), bBackground
, *pStyleSheet
, ePO
, pSSPool
) : nullptr);
368 sal_uInt16 nResult
= RET_CANCEL
;
369 const SfxItemSet
* pOutSet
= nullptr;
372 nResult
= pStdDlg
->Execute();
373 pOutSet
= pStdDlg
->GetOutputItemSet();
377 nResult
= pPresDlg
->Execute();
378 pOutSet
= pPresDlg
->GetOutputItemSet();
385 nRetMask
= static_cast<sal_uInt16
>(pStyleSheet
->GetMask());
387 if (eFamily
== SfxStyleFamily::Pseudo
)
389 SfxItemSet
aTempSet(*pOutSet
);
390 /* Extract SvxBrushItem out of set and insert SvxBackgroundColorItem */
391 const SvxBrushItem
* pBrushItem
= aTempSet
.GetItem
<SvxBrushItem
>( SID_ATTR_BRUSH_CHAR
);
395 SvxBackgroundColorItem
aBackColorItem(pBrushItem
->GetColor(), EE_CHAR_BKGCOLOR
);
396 aTempSet
.ClearItem( EE_CHAR_BKGCOLOR
);
397 aTempSet
.Put( aBackColorItem
);
399 static_cast<SdStyleSheet
*>(pStyleSheet
)->AdjustToFontHeight(aTempSet
);
401 /* Special treatment: reset the INVALIDS to
402 NULL-Pointer (otherwise INVALIDs or pointer point
403 to DefaultItems in the template; both would
404 prevent the attribute inheritance) */
405 aTempSet
.ClearInvalidItems();
407 // EE_PARA_NUMBULLET item is only valid in first outline template
408 if( (ePO
>= PO_OUTLINE_2
) && (ePO
<= PO_OUTLINE_9
) )
410 if (aTempSet
.GetItemState(EE_PARA_NUMBULLET
) == SfxItemState::SET
)
412 SvxNumRule
aRule(*aTempSet
.GetItem
<SvxNumBulletItem
>(EE_PARA_NUMBULLET
)->GetNumRule());
414 OUString
sStyleName(SdResId(STR_PSEUDOSHEET_OUTLINE
) + " 1");
415 SfxStyleSheetBase
* pFirstStyleSheet
= pSSPool
->Find( sStyleName
, SfxStyleFamily::Pseudo
);
419 pFirstStyleSheet
->GetItemSet().Put( SvxNumBulletItem( aRule
, EE_PARA_NUMBULLET
));
420 SdStyleSheet
* pRealSheet
= static_cast<SdStyleSheet
*>(pFirstStyleSheet
)->GetRealStyleSheet();
421 pRealSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
424 aTempSet
.ClearItem( EE_PARA_NUMBULLET
);
428 pStyleSheet
->GetItemSet().Put(aTempSet
);
429 SdStyleSheet::BroadcastSdStyleSheetChange(pStyleSheet
, ePO
, pSSPool
);
432 SfxItemSet
& rAttr
= pStyleSheet
->GetItemSet();
434 sdr::properties::CleanupFillProperties( rAttr
);
436 // check for unique names of named items for xml
437 if( rAttr
.GetItemState( XATTR_FILLBITMAP
) == SfxItemState::SET
)
439 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_FILLBITMAP
);
440 SfxPoolItem
* pNewItem
= static_cast<const XFillBitmapItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
443 rAttr
.Put( *pNewItem
);
447 if( rAttr
.GetItemState( XATTR_LINEDASH
) == SfxItemState::SET
)
449 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_LINEDASH
);
450 SfxPoolItem
* pNewItem
= static_cast<const XLineDashItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
453 rAttr
.Put( *pNewItem
);
457 if( rAttr
.GetItemState( XATTR_LINESTART
) == SfxItemState::SET
)
459 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_LINESTART
);
460 SfxPoolItem
* pNewItem
= static_cast<const XLineStartItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
463 rAttr
.Put( *pNewItem
);
467 if( rAttr
.GetItemState( XATTR_LINEEND
) == SfxItemState::SET
)
469 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_LINEEND
);
470 SfxPoolItem
* pNewItem
= static_cast<const XLineEndItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
473 rAttr
.Put( *pNewItem
);
477 if( rAttr
.GetItemState( XATTR_FILLGRADIENT
) == SfxItemState::SET
)
479 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_FILLGRADIENT
);
480 SfxPoolItem
* pNewItem
= static_cast<const XFillGradientItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
483 rAttr
.Put( *pNewItem
);
487 if( rAttr
.GetItemState( XATTR_FILLFLOATTRANSPARENCE
) == SfxItemState::SET
)
489 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_FILLFLOATTRANSPARENCE
);
490 SfxPoolItem
* pNewItem
= static_cast<const XFillFloatTransparenceItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
493 rAttr
.Put( *pNewItem
);
497 if( rAttr
.GetItemState( XATTR_FILLHATCH
) == SfxItemState::SET
)
499 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_FILLHATCH
);
500 SfxPoolItem
* pNewItem
= static_cast<const XFillHatchItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
503 rAttr
.Put( *pNewItem
);
508 static_cast<SfxStyleSheet
*>( pStyleSheet
)->Broadcast( SfxHint( SfxHintId::DataChanged
) );
510 DrawViewShell
* pDrawViewShell
= dynamic_cast< DrawViewShell
* >( mpViewShell
);
513 PageKind ePageKind
= pDrawViewShell
->GetPageKind();
514 if( ePageKind
== PageKind::Notes
|| ePageKind
== PageKind::Handout
)
516 SdPage
* pPage
= mpViewShell
->GetActualPage();
518 if(pDrawViewShell
->GetEditMode() == EditMode::MasterPage
)
520 pPage
= static_cast<SdPage
*>((&(pPage
->TRG_GetMasterPage())));
525 SdrObjListIter
aIter( *pPage
);
526 while( aIter
.IsMore() )
528 SdrObject
* pObj
= aIter
.Next();
529 if( dynamic_cast< const SdrPageObj
*>( pObj
) != nullptr )
532 pObj
->ActionChanged();
533 // pObj->SendRepaintBroadcast();
540 if( mpDoc
->GetOnlineSpell() )
542 const SfxPoolItem
* pTempItem
;
543 if( SfxItemState::SET
== rAttr
.GetItemState(EE_CHAR_LANGUAGE
, false, &pTempItem
) ||
544 SfxItemState::SET
== rAttr
.GetItemState(EE_CHAR_LANGUAGE_CJK
, false, &pTempItem
) ||
545 SfxItemState::SET
== rAttr
.GetItemState(EE_CHAR_LANGUAGE_CTL
, false, &pTempItem
) )
547 mpDoc
->StopOnlineSpelling();
548 mpDoc
->StartOnlineSpelling();
558 if( nSId
== SID_STYLE_NEW
)
559 pSSPool
->Remove( pStyleSheet
);
567 case SID_STYLE_NEW_BY_EXAMPLE
:
571 nRetMask
= static_cast<sal_uInt16
>(pStyleSheet
->GetMask());
572 SfxItemSet
aCoreSet( mpDoc
->GetPool() );
573 mpView
->GetAttributes( aCoreSet
, true );
575 // if the object had a template, this becomes parent of the new template
576 SfxStyleSheet
* pOldStyle
= mpView
->GetStyleSheet();
578 // if pOldStyle == pStyleSheet -> recursion
579 if( pOldStyle
!= pStyleSheet
)
583 pStyleSheet
->SetParent(pOldStyle
->GetName());
586 SfxItemSet
* pStyleSet
= &pStyleSheet
->GetItemSet();
587 pStyleSet
->Put(aCoreSet
);
589 /* apply template (but not when somebody is editing a text.
590 To do this, the edit engine had to be capable to use
591 templates on a character level. */
592 if (!mpView
->GetTextEditObject())
594 mpView
->SetStyleSheet( static_cast<SfxStyleSheet
*>(pStyleSheet
));
597 static_cast<SfxStyleSheet
*>( pStyleSheet
)->Broadcast( SfxHint( SfxHintId::DataChanged
) );
600 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_FAMILY2
);
606 case SID_STYLE_UPDATE_BY_EXAMPLE
:
608 if ((mpView
->AreObjectsMarked() && mpView
->GetMarkedObjectList().GetMarkCount() == 1) ||
609 dynamic_cast< const OutlineView
*>( mpView
) != nullptr)
611 pStyleSheet
= mpView
->GetStyleSheet();
615 nRetMask
= static_cast<sal_uInt16
>(pStyleSheet
->GetMask());
616 SfxItemSet
aCoreSet( mpDoc
->GetPool() );
617 mpView
->GetAttributes( aCoreSet
);
619 SfxItemSet
* pStyleSet
= &pStyleSheet
->GetItemSet();
620 pStyleSet
->Put( aCoreSet
);
622 mpView
->SetStyleSheet( static_cast<SfxStyleSheet
*>(pStyleSheet
));
624 static_cast<SfxStyleSheet
*>( pStyleSheet
)->Broadcast( SfxHint( SfxHintId::DataChanged
) );
626 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_FAMILY2
);
633 if( nRetMask
!= static_cast<sal_uInt16
>(SfxStyleSearchBits::All
) )
634 rReq
.SetReturnValue( SfxUInt16Item( nSId
, nRetMask
) );
637 void FuTemplate::Activate()
641 void FuTemplate::Deactivate()
645 } // end of namespace sd
647 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */