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 <vcl/commandevent.hxx>
21 #include <vcl/menu.hxx>
22 #include <vcl/status.hxx>
23 #include <svl/stritem.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <sfx2/viewfrm.hxx>
27 #include <tmplctrl.hxx>
28 #include <ViewShellBase.hxx>
29 #include <drawdoc.hxx>
33 #include <sdresid.hxx>
34 #include <strings.hrc>
36 SFX_IMPL_STATUSBAR_CONTROL( SdTemplateControl
, SfxStringItem
);
38 // class SdTemplatePopup_Impl --------------------------------------------------
42 class SdTemplatePopup_Impl
: public PopupMenu
45 SdTemplatePopup_Impl();
47 sal_uInt16
GetCurId() const { return nCurId
; }
52 virtual void Select() override
;
57 SdTemplatePopup_Impl::SdTemplatePopup_Impl() :
63 void SdTemplatePopup_Impl::Select()
65 nCurId
= GetCurItemId();
68 // class SdTemplateControl ------------------------------------------
70 SdTemplateControl::SdTemplateControl( sal_uInt16 _nSlotId
,
73 SfxStatusBarControl( _nSlotId
, _nId
, rStb
)
75 GetStatusBar().SetQuickHelpText(GetId(), SdResId(STR_STATUSBAR_MASTERPAGE
));
78 SdTemplateControl::~SdTemplateControl()
82 void SdTemplateControl::StateChanged(
83 sal_uInt16
/*nSID*/, SfxItemState eState
, const SfxPoolItem
* pState
)
85 if( eState
!= SfxItemState::DEFAULT
|| pState
->IsVoidItem() )
86 GetStatusBar().SetItemText( GetId(), OUString() );
87 else if ( auto pStringItem
= dynamic_cast< const SfxStringItem
*>( pState
) )
89 msTemplate
= pStringItem
->GetValue();
90 GetStatusBar().SetItemText( GetId(), msTemplate
);
94 void SdTemplateControl::Paint( const UserDrawEvent
& )
98 void SdTemplateControl::Command( const CommandEvent
& rCEvt
)
100 if ( rCEvt
.GetCommand() != CommandEventId::ContextMenu
|| GetStatusBar().GetItemText( GetId() ).isEmpty() )
103 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
105 sd::ViewShellBase
* pViewShellBase
= sd::ViewShellBase::GetViewShellBase( pViewFrame
);
106 if( !pViewShellBase
)
109 SdDrawDocument
* pDoc
= pViewShellBase
->GetDocument();
113 ScopedVclPtrInstance
<SdTemplatePopup_Impl
> aPop
;
115 const sal_uInt16 nMasterCount
= pDoc
->GetMasterSdPageCount(PageKind::Standard
);
117 sal_uInt16 nCount
= 0;
118 for( sal_uInt16 nPage
= 0; nPage
< nMasterCount
; ++nPage
)
120 SdPage
* pMaster
= pDoc
->GetMasterSdPage(nPage
, PageKind::Standard
);
122 aPop
->InsertItem( ++nCount
, pMaster
->GetName() );
124 aPop
->Execute( &GetStatusBar(), rCEvt
.GetMousePosPixel());
126 sal_uInt16 nCurrId
= aPop
->GetCurId()-1;
127 if( nCurrId
< nMasterCount
)
129 SdPage
* pMaster
= pDoc
->GetMasterSdPage(nCurrId
, PageKind::Standard
);
130 SfxStringItem
aStyle( ATTR_PRESLAYOUT_NAME
, pMaster
->GetName() );
131 pViewFrame
->GetDispatcher()->ExecuteList(
132 SID_PRESENTATION_LAYOUT
, SfxCallMode::SLOT
, { &aStyle
});
133 pViewFrame
->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT
);
134 pViewFrame
->GetBindings().Invalidate(SID_STATUS_LAYOUT
);
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */