Update ooo320-m1
[ooovba.git] / sd / source / ui / app / tmplctrl.cxx
bloba51ae386341ce6e4b7d5d5acf33c30e474bd1956
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tmplctrl.cxx,v $
11 * $Revision: 1.3 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sd.hxx"
35 // include ---------------------------------------------------------------
38 #include <vcl/menu.hxx>
39 #include <vcl/status.hxx>
40 #include <svtools/style.hxx>
41 #include <svtools/stritem.hxx>
42 #include <sfx2/dispatch.hxx>
44 #include "tmplctrl.hxx"
45 #include "ViewShellBase.hxx"
46 #include "drawdoc.hxx"
47 #include "sdattr.hrc"
48 #include "app.hrc"
50 SFX_IMPL_STATUSBAR_CONTROL( SdTemplateControl, SfxStringItem );
52 // class TemplatePopup_Impl --------------------------------------------------
54 class TemplatePopup_Impl : public PopupMenu
56 public:
57 TemplatePopup_Impl();
59 USHORT GetCurId() const { return nCurId; }
61 private:
62 USHORT nCurId;
64 virtual void Select();
67 // -----------------------------------------------------------------------
69 TemplatePopup_Impl::TemplatePopup_Impl() :
70 PopupMenu(),
71 nCurId(USHRT_MAX)
75 // -----------------------------------------------------------------------
77 void TemplatePopup_Impl::Select()
79 nCurId = GetCurItemId();
82 // class SdTemplateControl ------------------------------------------
84 SdTemplateControl::SdTemplateControl( USHORT _nSlotId,
85 USHORT _nId,
86 StatusBar& rStb ) :
87 SfxStatusBarControl( _nSlotId, _nId, rStb )
91 // -----------------------------------------------------------------------
93 SdTemplateControl::~SdTemplateControl()
97 // -----------------------------------------------------------------------
99 void SdTemplateControl::StateChanged(
100 USHORT /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
102 if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) )
103 GetStatusBar().SetItemText( GetId(), String() );
104 else if ( pState->ISA( SfxStringItem ) )
106 msTemplate = ((SfxStringItem*)pState)->GetValue();
107 GetStatusBar().SetItemText( GetId(), msTemplate );
111 // -----------------------------------------------------------------------
113 void SdTemplateControl::Paint( const UserDrawEvent& )
115 GetStatusBar().SetItemText( GetId(), msTemplate );
118 // -----------------------------------------------------------------------
120 void SdTemplateControl::Command( const CommandEvent& rCEvt )
122 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU && GetStatusBar().GetItemText( GetId() ).Len() )
124 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
126 sd::ViewShellBase* pViewShellBase = sd::ViewShellBase::GetViewShellBase( pViewFrame );
127 if( !pViewShellBase )
128 return;
130 SdDrawDocument* pDoc = pViewShellBase->GetDocument();
131 if( !pDoc )
132 return;
134 CaptureMouse();
135 TemplatePopup_Impl aPop;
137 const USHORT nMasterCount = pDoc->GetMasterSdPageCount(PK_STANDARD);
139 USHORT nCount = 0;
140 for( USHORT nPage = 0; nPage < nMasterCount; ++nPage )
142 SdPage* pMaster = pDoc->GetMasterSdPage(nPage, PK_STANDARD);
143 if( pMaster )
144 aPop.InsertItem( ++nCount, pMaster->GetName() );
146 aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
148 USHORT nCurrId = aPop.GetCurId()-1;
149 if( nCurrId < nMasterCount )
151 SdPage* pMaster = pDoc->GetMasterSdPage(nCurrId, PK_STANDARD);
152 SfxStringItem aStyle( ATTR_PRESLAYOUT_NAME, pMaster->GetName() );
153 pViewFrame->GetDispatcher()->Execute(SID_PRESENTATION_LAYOUT,SFX_CALLMODE_SLOT, &aStyle, 0L );
154 pViewFrame->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT);
155 pViewFrame->GetBindings().Invalidate(SID_STATUS_LAYOUT);
159 ReleaseMouse();