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 <vcl/msgbox.hxx>
33 #include <editeng/eeitem.hxx>
34 #include <sfx2/request.hxx>
35 #include <editeng/numitem.hxx>
36 #include <editeng/editeng.hxx>
37 #include <editeng/lrspitem.hxx>
38 #include <svx/svdopage.hxx>
39 #include <svx/svditer.hxx>
40 #include <svx/sdr/properties/properties.hxx>
42 #include <sfx2/viewfrm.hxx>
43 #include <svx/xlndsit.hxx>
44 #include <svx/xlnstit.hxx>
45 #include <svx/xlnedit.hxx>
47 #include "stlsheet.hxx"
49 #include "stlpool.hxx"
53 #include "drawview.hxx"
54 #include "drawdoc.hxx"
55 #include "DrawDocShell.hxx"
56 #include "DrawViewShell.hxx"
57 #include "ViewShell.hxx"
58 #include "res_bmp.hrc"
60 #include "prlayout.hxx"
61 #include "prltempl.hrc"
62 #include <svx/xfillit.hxx>
63 #include "sdresid.hxx"
64 #include "OutlineViewShell.hxx"
65 #include "strings.hrc"
67 #include "sdabstdlg.hxx"
68 #include <boost/scoped_ptr.hpp>
70 using namespace com::sun::star::uno
;
71 using namespace com::sun::star::container
;
72 using namespace com::sun::star::beans
;
73 using namespace com::sun::star::style
;
78 TYPEINIT1( FuTemplate
, FuPoor
);
80 FuTemplate::FuTemplate (
86 : FuPoor( pViewSh
, pWin
, pView
, pDoc
, rReq
)
90 rtl::Reference
<FuPoor
> FuTemplate::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
92 rtl::Reference
<FuPoor
> xFunc( new FuTemplate( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
93 xFunc
->DoExecute(rReq
);
97 void FuTemplate::DoExecute( SfxRequest
& rReq
)
99 const SfxItemSet
* pArgs
= rReq
.GetArgs();
100 sal_uInt16 nSId
= rReq
.GetSlot();
102 // get StyleSheet parameter
103 SfxStyleSheetBasePool
* pSSPool
= mpDoc
->GetDocSh()->GetStyleSheetPool();
104 SfxStyleSheetBase
* pStyleSheet
= NULL
;
106 const SfxPoolItem
* pItem
;
107 sal_uInt16 nFamily
= USHRT_MAX
;
108 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_FAMILY
,
111 nFamily
= static_cast<const SfxUInt16Item
&>( pArgs
->Get( SID_STYLE_FAMILY
) ).GetValue();
113 else if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_FAMILYNAME
,
116 OUString sFamily
= static_cast<const SfxStringItem
&>( pArgs
->Get( SID_STYLE_FAMILYNAME
) ).GetValue();
117 if (sFamily
== "graphics")
118 nFamily
= SD_STYLE_FAMILY_GRAPHICS
;
120 nFamily
= SD_STYLE_FAMILY_PSEUDO
;
124 sal_uInt16 nRetMask
= SFXSTYLEBIT_ALL
;
128 case SID_STYLE_APPLY
:
130 case SID_STYLE_DELETE
:
133 case SID_STYLE_FAMILY
:
134 case SID_STYLE_NEW_BY_EXAMPLE
:
136 SFX_REQUEST_ARG( rReq
, pNameItem
, SfxStringItem
, SID_APPLY_STYLE
, false );
137 SFX_REQUEST_ARG( rReq
, pFamilyItem
, SfxStringItem
, SID_STYLE_FAMILYNAME
, false );
138 if ( pFamilyItem
&& pNameItem
)
142 Reference
< XStyleFamiliesSupplier
> xModel(mpDoc
->GetDocSh()->GetModel(), UNO_QUERY_THROW
);
143 Reference
< XNameAccess
> xCont( xModel
->getStyleFamilies() );
144 Reference
< XNameAccess
> xStyles( xCont
->getByName(pFamilyItem
->GetValue()), UNO_QUERY_THROW
);
145 Reference
< XPropertySet
> xInfo( xStyles
->getByName( pNameItem
->GetValue() ), UNO_QUERY_THROW
);
148 xInfo
->getPropertyValue( "DisplayName" ) >>= aUIName
;
149 if ( !aUIName
.isEmpty() )
150 rReq
.AppendItem( SfxStringItem( nSId
, aUIName
) );
157 if (pArgs
&& pArgs
->GetItemState(nSId
) == SfxItemState::SET
)
158 aStyleName
= static_cast<const SfxStringItem
&>( pArgs
->Get( nSId
) ).GetValue();
166 SfxStyleSheetBase
*p
= pSSPool
->Find(aStyleName
, (SfxStyleFamily
) nFamily
, SFXSTYLEBIT_ALL
);
172 pStyleSheet
= &pSSPool
->Make( aStyleName
, (SfxStyleFamily
) nFamily
, SFXSTYLEBIT_USERDEF
);
174 if (pArgs
&& pArgs
->GetItemState(SID_STYLE_REFERENCE
) == SfxItemState::SET
)
176 OUString
aParentName(static_cast<const SfxStringItem
&>( pArgs
->Get(SID_STYLE_REFERENCE
)).GetValue());
177 pStyleSheet
->SetParent(aParentName
);
181 pStyleSheet
->SetParent(SD_RESSTR(STR_STANDARD_STYLESHEET_NAME
));
186 case SID_STYLE_NEW_BY_EXAMPLE
:
188 // at the moment, the dialog to enter the name of the template is still opened
189 SfxStyleSheetBase
*p
= pSSPool
->Find(aStyleName
, (SfxStyleFamily
) nFamily
, SFXSTYLEBIT_ALL
);
195 pStyleSheet
= &pSSPool
->Make( aStyleName
, (SfxStyleFamily
) nFamily
, SFXSTYLEBIT_USERDEF
);
196 pStyleSheet
->SetParent(SD_RESSTR(STR_STANDARD_STYLESHEET_NAME
));
201 pStyleSheet
= pSSPool
->Find( aStyleName
, (SfxStyleFamily
) nFamily
);
204 case SID_STYLE_DELETE
:
205 pStyleSheet
= pSSPool
->Find( aStyleName
, (SfxStyleFamily
) nFamily
);
208 pSSPool
->Remove( pStyleSheet
);
209 nRetMask
= sal_uInt16(true);
210 mpDoc
->SetChanged(true);
214 nRetMask
= sal_uInt16(false);
220 pStyleSheet
= pSSPool
->Find( aStyleName
, (SfxStyleFamily
) nFamily
);
221 pStyleSheet
->SetHidden( nSId
== SID_STYLE_HIDE
);
222 nRetMask
= sal_uInt16(true);
225 case SID_STYLE_APPLY
:
226 // apply the template to the document
227 pStyleSheet
= pSSPool
->Find( aStyleName
, (SfxStyleFamily
) nFamily
);
229 // do not set presentation styles, they will be set implicit
230 if ( pStyleSheet
&& pStyleSheet
->GetFamily() != SD_STYLE_FAMILY_PSEUDO
)
232 SfxStyleSheet
* pOldStyleSheet
= mpView
->GetStyleSheet();
235 if( // if the object had no style sheet, allow all
238 // allow if old and new style sheet has same family
239 pStyleSheet
->GetFamily() == pOldStyleSheet
->GetFamily() ||
241 // allow if old was background objects and new is graphics
242 (pStyleSheet
->GetFamily() == SD_STYLE_FAMILY_GRAPHICS
&& pOldStyleSheet
->GetHelpId( aStr
) == HID_PSEUDOSHEET_BACKGROUNDOBJECTS
) ||
244 // allow if old was presentation and we are a drawing document
245 (pOldStyleSheet
->GetFamily() == SD_STYLE_FAMILY_MASTERPAGE
&& mpDoc
->GetDocumentType() == DOCUMENT_TYPE_DRAW
) )
247 mpView
->SetStyleSheet( static_cast<SfxStyleSheet
*>(pStyleSheet
));
248 mpDoc
->SetChanged(true);
249 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_FAMILY2
);
254 case SID_STYLE_WATERCAN
:
256 if( !SD_MOD()->GetWaterCan() )
258 if (pArgs
&& pArgs
->GetItemState( nSId
) == SfxItemState::SET
)
260 aStyleName
= static_cast<const SfxStringItem
&>( pArgs
->Get( nSId
) ).GetValue();
261 SD_MOD()->SetWaterCan( true );
262 pStyleSheet
= pSSPool
->Find( aStyleName
, (SfxStyleFamily
) nFamily
);
264 // no presentation object templates, they are only allowed implicitly
265 if( pStyleSheet
&& pStyleSheet
->GetFamily() != SD_STYLE_FAMILY_PSEUDO
)
267 static_cast<SdStyleSheetPool
*>( pSSPool
)->SetActualStyleSheet( pStyleSheet
);
269 // we switch explicitly into selection mode
270 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute( SID_OBJECT_SELECT
,
271 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
275 SD_MOD()->SetWaterCan( false );
279 SD_MOD()->SetWaterCan( false );
280 // we have to re-enable to tools-bar
281 mpViewShell
->Invalidate();
295 PresentationObjects ePO
= PO_OUTLINE_1
;
299 boost::scoped_ptr
<SfxAbstractTabDialog
> pStdDlg
;
300 boost::scoped_ptr
<SfxAbstractTabDialog
> pPresDlg
;
301 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
302 bool bOldDocInOtherLanguage
= false;
303 SfxItemSet
aOriSet( pStyleSheet
->GetItemSet() );
305 SfxStyleFamily eFamily
= pStyleSheet
->GetFamily();
307 if (eFamily
== SD_STYLE_FAMILY_GRAPHICS
)
309 pStdDlg
.reset(pFact
? pFact
->CreateSdTabTemplateDlg( 0, mpDoc
->GetDocSh(), *pStyleSheet
, mpDoc
, mpView
) : 0);
311 else if (eFamily
== SD_STYLE_FAMILY_PSEUDO
)
313 OUString
aName(pStyleSheet
->GetName());
314 sal_uInt16 nDlgId
= 0;
316 if (aName
== SD_RESSTR(STR_PSEUDOSHEET_TITLE
))
318 nDlgId
= TAB_PRES_LAYOUT_TEMPLATE
;
321 else if (aName
== SD_RESSTR(STR_PSEUDOSHEET_SUBTITLE
))
323 nDlgId
= TAB_PRES_LAYOUT_TEMPLATE
;
327 SD_RESSTR(STR_PSEUDOSHEET_BACKGROUND
))
329 nDlgId
= TAB_PRES_LAYOUT_TEMPLATE_BACKGROUND
;
333 SD_RESSTR(STR_PSEUDOSHEET_BACKGROUNDOBJECTS
))
335 nDlgId
= TAB_PRES_LAYOUT_TEMPLATE
;
336 ePO
= PO_BACKGROUNDOBJECTS
;
339 SD_RESSTR(STR_PSEUDOSHEET_NOTES
))
341 nDlgId
= TAB_PRES_LAYOUT_TEMPLATE
;
344 else if(aName
.indexOf(SD_RESSTR(STR_PSEUDOSHEET_OUTLINE
)) != -1)
346 nDlgId
= TAB_PRES_LAYOUT_TEMPLATE
;
348 OUString
aOutlineStr(SD_RESSTR(STR_PSEUDOSHEET_OUTLINE
));
349 // determine number, mind the blank between name and number
350 OUString
aNumStr(aName
.copy(aOutlineStr
.getLength() + 1));
351 sal_uInt16 nLevel
= (sal_uInt16
)aNumStr
.toInt32();
354 case 1: ePO
= PO_OUTLINE_1
; break;
355 case 2: ePO
= PO_OUTLINE_2
; break;
356 case 3: ePO
= PO_OUTLINE_3
; break;
357 case 4: ePO
= PO_OUTLINE_4
; break;
358 case 5: ePO
= PO_OUTLINE_5
; break;
359 case 6: ePO
= PO_OUTLINE_6
; break;
360 case 7: ePO
= PO_OUTLINE_7
; break;
361 case 8: ePO
= PO_OUTLINE_8
; break;
362 case 9: ePO
= PO_OUTLINE_9
; break;
367 OSL_FAIL("StyleSheet from older version with different language");
368 bOldDocInOtherLanguage
= true;
371 if( !bOldDocInOtherLanguage
)
373 pPresDlg
.reset(pFact
? pFact
->CreateSdPresLayoutTemplateDlg( mpDocSh
, NULL
, SdResId(nDlgId
), *pStyleSheet
, ePO
, pSSPool
) : 0);
376 else if (eFamily
== SD_STYLE_FAMILY_CELL
)
380 sal_uInt16 nResult
= RET_CANCEL
;
381 const SfxItemSet
* pOutSet
= NULL
;
384 nResult
= pStdDlg
->Execute();
385 pOutSet
= pStdDlg
->GetOutputItemSet();
389 nResult
= pPresDlg
->Execute();
390 pOutSet
= pPresDlg
->GetOutputItemSet();
397 nRetMask
= pStyleSheet
->GetMask();
399 if (eFamily
== SD_STYLE_FAMILY_PSEUDO
)
401 SfxItemSet
aTempSet(*pOutSet
);
402 static_cast<SdStyleSheet
*>(pStyleSheet
)->AdjustToFontHeight(aTempSet
);
404 /* Special treatment: reset the INVALIDS to
405 NULL-Pointer (otherwise INVALIDs or pointer point
406 to DefaultItems in the template; both would
407 prevent the attribute inheritance) */
408 aTempSet
.ClearInvalidItems();
410 // EE_PARA_NUMBULLET item is only valid in first outline template
411 if( (ePO
>= PO_OUTLINE_2
) && (ePO
<= PO_OUTLINE_9
) )
413 if (aTempSet
.GetItemState(EE_PARA_NUMBULLET
) == SfxItemState::SET
)
415 SvxNumRule
aRule(*static_cast<const SvxNumBulletItem
*>(aTempSet
.GetItem(EE_PARA_NUMBULLET
))->GetNumRule());
417 OUString
sStyleName(SD_RESSTR(STR_PSEUDOSHEET_OUTLINE
) + " 1");
418 SfxStyleSheetBase
* pFirstStyleSheet
= pSSPool
->Find( sStyleName
, SD_STYLE_FAMILY_PSEUDO
);
422 pFirstStyleSheet
->GetItemSet().Put( SvxNumBulletItem( aRule
, EE_PARA_NUMBULLET
));
423 SdStyleSheet
* pRealSheet
= static_cast<SdStyleSheet
*>(pFirstStyleSheet
)->GetRealStyleSheet();
424 pRealSheet
->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED
));
427 aTempSet
.ClearItem( EE_PARA_NUMBULLET
);
431 pStyleSheet
->GetItemSet().Put(aTempSet
);
432 SdStyleSheet::BroadcastSdStyleSheetChange(pStyleSheet
, ePO
, pSSPool
);
435 SfxItemSet
& rAttr
= pStyleSheet
->GetItemSet();
437 sdr::properties::CleanupFillProperties( rAttr
);
439 // check for unique names of named items for xml
440 if( rAttr
.GetItemState( XATTR_FILLBITMAP
) == SfxItemState::SET
)
442 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_FILLBITMAP
);
443 SfxPoolItem
* pNewItem
= static_cast<const XFillBitmapItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
446 rAttr
.Put( *pNewItem
);
450 if( rAttr
.GetItemState( XATTR_LINEDASH
) == SfxItemState::SET
)
452 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_LINEDASH
);
453 SfxPoolItem
* pNewItem
= static_cast<const XLineDashItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
456 rAttr
.Put( *pNewItem
);
460 if( rAttr
.GetItemState( XATTR_LINESTART
) == SfxItemState::SET
)
462 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_LINESTART
);
463 SfxPoolItem
* pNewItem
= static_cast<const XLineStartItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
466 rAttr
.Put( *pNewItem
);
470 if( rAttr
.GetItemState( XATTR_LINEEND
) == SfxItemState::SET
)
472 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_LINEEND
);
473 SfxPoolItem
* pNewItem
= static_cast<const XLineEndItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
476 rAttr
.Put( *pNewItem
);
480 if( rAttr
.GetItemState( XATTR_FILLGRADIENT
) == SfxItemState::SET
)
482 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_FILLGRADIENT
);
483 SfxPoolItem
* pNewItem
= static_cast<const XFillGradientItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
486 rAttr
.Put( *pNewItem
);
490 if( rAttr
.GetItemState( XATTR_FILLFLOATTRANSPARENCE
) == SfxItemState::SET
)
492 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_FILLFLOATTRANSPARENCE
);
493 SfxPoolItem
* pNewItem
= static_cast<const XFillFloatTransparenceItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
496 rAttr
.Put( *pNewItem
);
500 if( rAttr
.GetItemState( XATTR_FILLHATCH
) == SfxItemState::SET
)
502 const SfxPoolItem
* pOldItem
= rAttr
.GetItem( XATTR_FILLHATCH
);
503 SfxPoolItem
* pNewItem
= static_cast<const XFillHatchItem
*>(pOldItem
)->checkForUniqueItem( mpDoc
);
506 rAttr
.Put( *pNewItem
);
511 static_cast<SfxStyleSheet
*>( pStyleSheet
)->Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED
) );
513 DrawViewShell
* pDrawViewShell
= dynamic_cast< DrawViewShell
* >( mpViewShell
);
516 PageKind ePageKind
= pDrawViewShell
->GetPageKind();
517 if( ePageKind
== PK_NOTES
|| ePageKind
== PK_HANDOUT
)
519 SdPage
* pPage
= mpViewShell
->GetActualPage();
521 if(pDrawViewShell
->GetEditMode() == EM_MASTERPAGE
)
523 pPage
= static_cast<SdPage
*>((&(pPage
->TRG_GetMasterPage())));
528 SdrObjListIter
aIter( *pPage
);
529 while( aIter
.IsMore() )
531 SdrObject
* pObj
= aIter
.Next();
532 if( pObj
->ISA(SdrPageObj
) )
535 pObj
->ActionChanged();
536 // pObj->SendRepaintBroadcast();
543 if( mpDoc
->GetOnlineSpell() )
545 const SfxPoolItem
* pTempItem
;
546 if( SfxItemState::SET
== rAttr
.GetItemState(EE_CHAR_LANGUAGE
, false, &pTempItem
) ||
547 SfxItemState::SET
== rAttr
.GetItemState(EE_CHAR_LANGUAGE_CJK
, false, &pTempItem
) ||
548 SfxItemState::SET
== rAttr
.GetItemState(EE_CHAR_LANGUAGE_CTL
, false, &pTempItem
) )
550 mpDoc
->StopOnlineSpelling();
551 mpDoc
->StartOnlineSpelling();
555 mpDoc
->SetChanged(true);
561 if( nSId
== SID_STYLE_NEW
)
562 pSSPool
->Remove( pStyleSheet
);
570 case SID_STYLE_NEW_BY_EXAMPLE
:
574 nRetMask
= pStyleSheet
->GetMask();
575 SfxItemSet
aCoreSet( mpDoc
->GetPool() );
576 mpView
->GetAttributes( aCoreSet
, true );
578 // if the object had a template, this becomes parent of the new template
579 SfxStyleSheet
* pOldStyle
= mpView
->GetStyleSheet();
581 // if pOldStyle == pStyleSheet -> recursion
582 if( pOldStyle
!= pStyleSheet
)
586 pStyleSheet
->SetParent(pOldStyle
->GetName());
589 SfxItemSet
* pStyleSet
= &pStyleSheet
->GetItemSet();
590 pStyleSet
->Put(aCoreSet
);
592 /* apply template (but not when somebody is editing a text.
593 To do this, the edit engine had to be capable to use
594 templates on a character level. */
595 if (!mpView
->GetTextEditObject())
597 mpView
->SetStyleSheet( static_cast<SfxStyleSheet
*>(pStyleSheet
));
600 static_cast<SfxStyleSheet
*>( pStyleSheet
)->Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED
) );
601 mpDoc
->SetChanged(true);
603 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_FAMILY2
);
609 case SID_STYLE_UPDATE_BY_EXAMPLE
:
611 if ((mpView
->AreObjectsMarked() && mpView
->GetMarkedObjectList().GetMarkCount() == 1) ||
612 mpView
->ISA(OutlineView
))
614 pStyleSheet
= mpView
->GetStyleSheet();
618 nRetMask
= pStyleSheet
->GetMask();
619 SfxItemSet
aCoreSet( mpDoc
->GetPool() );
620 mpView
->GetAttributes( aCoreSet
);
622 SfxItemSet
* pStyleSet
= &pStyleSheet
->GetItemSet();
623 pStyleSet
->Put( aCoreSet
);
625 mpView
->SetStyleSheet( static_cast<SfxStyleSheet
*>(pStyleSheet
));
627 static_cast<SfxStyleSheet
*>( pStyleSheet
)->Broadcast( SfxSimpleHint( SFX_HINT_DATACHANGED
) );
628 mpDoc
->SetChanged(true);
629 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_FAMILY2
);
636 if( nRetMask
!= SFXSTYLEBIT_ALL
)
637 rReq
.SetReturnValue( SfxUInt16Item( nSId
, nRetMask
) );
640 void FuTemplate::Activate()
644 void FuTemplate::Deactivate()
648 } // end of namespace sd
650 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */