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/menu.hxx>
21 #include <vcl/status.hxx>
22 #include <svl/style.hxx>
23 #include <svl/stritem.hxx>
24 #include <sfx2/dispatch.hxx>
26 #include "tmplctrl.hxx"
27 #include "ViewShellBase.hxx"
28 #include "drawdoc.hxx"
31 #include <sdresid.hxx>
32 #include "strings.hrc"
34 SFX_IMPL_STATUSBAR_CONTROL( SdTemplateControl
, SfxStringItem
);
36 // class SdTemplatePopup_Impl --------------------------------------------------
38 class SdTemplatePopup_Impl
: public PopupMenu
41 SdTemplatePopup_Impl();
43 sal_uInt16
GetCurId() const { return nCurId
; }
48 virtual void Select() SAL_OVERRIDE
;
51 SdTemplatePopup_Impl::SdTemplatePopup_Impl() :
57 void SdTemplatePopup_Impl::Select()
59 nCurId
= GetCurItemId();
62 // class SdTemplateControl ------------------------------------------
64 SdTemplateControl::SdTemplateControl( sal_uInt16 _nSlotId
,
67 SfxStatusBarControl( _nSlotId
, _nId
, rStb
)
69 GetStatusBar().SetQuickHelpText(GetId(), SD_RESSTR(STR_STATUSBAR_MASTERPAGE
));
72 SdTemplateControl::~SdTemplateControl()
76 void SdTemplateControl::StateChanged(
77 sal_uInt16
/*nSID*/, SfxItemState eState
, const SfxPoolItem
* pState
)
79 if( eState
!= SfxItemState::DEFAULT
|| pState
->ISA( SfxVoidItem
) )
80 GetStatusBar().SetItemText( GetId(), OUString() );
81 else if ( pState
->ISA( SfxStringItem
) )
83 msTemplate
= static_cast<const SfxStringItem
*>(pState
)->GetValue();
84 GetStatusBar().SetItemText( GetId(), msTemplate
);
88 void SdTemplateControl::Paint( const UserDrawEvent
& )
90 GetStatusBar().SetItemText( GetId(), msTemplate
);
93 void SdTemplateControl::Command( const CommandEvent
& rCEvt
)
95 if ( rCEvt
.GetCommand() == CommandEventId::ContextMenu
&& !GetStatusBar().GetItemText( GetId() ).isEmpty() )
97 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
99 sd::ViewShellBase
* pViewShellBase
= sd::ViewShellBase::GetViewShellBase( pViewFrame
);
100 if( !pViewShellBase
)
103 SdDrawDocument
* pDoc
= pViewShellBase
->GetDocument();
107 SdTemplatePopup_Impl aPop
;
109 const sal_uInt16 nMasterCount
= pDoc
->GetMasterSdPageCount(PK_STANDARD
);
111 sal_uInt16 nCount
= 0;
112 for( sal_uInt16 nPage
= 0; nPage
< nMasterCount
; ++nPage
)
114 SdPage
* pMaster
= pDoc
->GetMasterSdPage(nPage
, PK_STANDARD
);
116 aPop
.InsertItem( ++nCount
, pMaster
->GetName() );
118 aPop
.Execute( &GetStatusBar(), rCEvt
.GetMousePosPixel());
120 sal_uInt16 nCurrId
= aPop
.GetCurId()-1;
121 if( nCurrId
< nMasterCount
)
123 SdPage
* pMaster
= pDoc
->GetMasterSdPage(nCurrId
, PK_STANDARD
);
124 SfxStringItem
aStyle( ATTR_PRESLAYOUT_NAME
, pMaster
->GetName() );
125 pViewFrame
->GetDispatcher()->Execute(SID_PRESENTATION_LAYOUT
,SfxCallMode::SLOT
, &aStyle
, 0L );
126 pViewFrame
->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT
);
127 pViewFrame
->GetBindings().Invalidate(SID_STATUS_LAYOUT
);
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */