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"
32 SFX_IMPL_STATUSBAR_CONTROL( SdTemplateControl
, SfxStringItem
);
34 // class SdTemplatePopup_Impl --------------------------------------------------
36 class SdTemplatePopup_Impl
: public PopupMenu
39 SdTemplatePopup_Impl();
41 sal_uInt16
GetCurId() const { return nCurId
; }
46 virtual void Select();
49 // -----------------------------------------------------------------------
51 SdTemplatePopup_Impl::SdTemplatePopup_Impl() :
57 // -----------------------------------------------------------------------
59 void SdTemplatePopup_Impl::Select()
61 nCurId
= GetCurItemId();
64 // class SdTemplateControl ------------------------------------------
66 SdTemplateControl::SdTemplateControl( sal_uInt16 _nSlotId
,
69 SfxStatusBarControl( _nSlotId
, _nId
, rStb
)
73 // -----------------------------------------------------------------------
75 SdTemplateControl::~SdTemplateControl()
79 // -----------------------------------------------------------------------
81 void SdTemplateControl::StateChanged(
82 sal_uInt16
/*nSID*/, SfxItemState eState
, const SfxPoolItem
* pState
)
84 if( eState
!= SFX_ITEM_AVAILABLE
|| pState
->ISA( SfxVoidItem
) )
85 GetStatusBar().SetItemText( GetId(), String() );
86 else if ( pState
->ISA( SfxStringItem
) )
88 msTemplate
= ((SfxStringItem
*)pState
)->GetValue();
89 GetStatusBar().SetItemText( GetId(), msTemplate
);
93 // -----------------------------------------------------------------------
95 void SdTemplateControl::Paint( const UserDrawEvent
& )
97 GetStatusBar().SetItemText( GetId(), msTemplate
);
100 // -----------------------------------------------------------------------
102 void SdTemplateControl::Command( const CommandEvent
& rCEvt
)
104 if ( rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
&& GetStatusBar().GetItemText( GetId() ).Len() )
106 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
108 sd::ViewShellBase
* pViewShellBase
= sd::ViewShellBase::GetViewShellBase( pViewFrame
);
109 if( !pViewShellBase
)
112 SdDrawDocument
* pDoc
= pViewShellBase
->GetDocument();
117 SdTemplatePopup_Impl aPop
;
119 const sal_uInt16 nMasterCount
= pDoc
->GetMasterSdPageCount(PK_STANDARD
);
121 sal_uInt16 nCount
= 0;
122 for( sal_uInt16 nPage
= 0; nPage
< nMasterCount
; ++nPage
)
124 SdPage
* pMaster
= pDoc
->GetMasterSdPage(nPage
, PK_STANDARD
);
126 aPop
.InsertItem( ++nCount
, pMaster
->GetName() );
128 aPop
.Execute( &GetStatusBar(), rCEvt
.GetMousePosPixel());
130 sal_uInt16 nCurrId
= aPop
.GetCurId()-1;
131 if( nCurrId
< nMasterCount
)
133 SdPage
* pMaster
= pDoc
->GetMasterSdPage(nCurrId
, PK_STANDARD
);
134 SfxStringItem
aStyle( ATTR_PRESLAYOUT_NAME
, pMaster
->GetName() );
135 pViewFrame
->GetDispatcher()->Execute(SID_PRESENTATION_LAYOUT
,SFX_CALLMODE_SLOT
, &aStyle
, 0L );
136 pViewFrame
->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT
);
137 pViewFrame
->GetBindings().Invalidate(SID_STATUS_LAYOUT
);
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */