1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sd.hxx" 30 31 // include --------------------------------------------------------------- 32 33 34 #include <vcl/menu.hxx> 35 #include <vcl/status.hxx> 36 #include <svl/style.hxx> 37 #include <svl/stritem.hxx> 38 #include <sfx2/dispatch.hxx> 39 40 #include "tmplctrl.hxx" 41 #include "ViewShellBase.hxx" 42 #include "drawdoc.hxx" 43 #include "sdattr.hrc" 44 #include "app.hrc" 45 46 SFX_IMPL_STATUSBAR_CONTROL( SdTemplateControl, SfxStringItem ); 47 48 // class TemplatePopup_Impl -------------------------------------------------- 49 50 class TemplatePopup_Impl : public PopupMenu 51 { 52 public: 53 TemplatePopup_Impl(); 54 55 sal_uInt16 GetCurId() const { return nCurId; } 56 57 private: 58 sal_uInt16 nCurId; 59 60 virtual void Select(); 61 }; 62 63 // ----------------------------------------------------------------------- 64 65 TemplatePopup_Impl::TemplatePopup_Impl() : 66 PopupMenu(), 67 nCurId(USHRT_MAX) 68 { 69 } 70 71 // ----------------------------------------------------------------------- 72 73 void TemplatePopup_Impl::Select() 74 { 75 nCurId = GetCurItemId(); 76 } 77 78 // class SdTemplateControl ------------------------------------------ 79 80 SdTemplateControl::SdTemplateControl( sal_uInt16 _nSlotId, 81 sal_uInt16 _nId, 82 StatusBar& rStb ) : 83 SfxStatusBarControl( _nSlotId, _nId, rStb ) 84 { 85 } 86 87 // ----------------------------------------------------------------------- 88 89 SdTemplateControl::~SdTemplateControl() 90 { 91 } 92 93 // ----------------------------------------------------------------------- 94 95 void SdTemplateControl::StateChanged( 96 sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState ) 97 { 98 if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) ) 99 GetStatusBar().SetItemText( GetId(), String() ); 100 else if ( pState->ISA( SfxStringItem ) ) 101 { 102 msTemplate = ((SfxStringItem*)pState)->GetValue(); 103 GetStatusBar().SetItemText( GetId(), msTemplate ); 104 } 105 } 106 107 // ----------------------------------------------------------------------- 108 109 void SdTemplateControl::Paint( const UserDrawEvent& ) 110 { 111 GetStatusBar().SetItemText( GetId(), msTemplate ); 112 } 113 114 // ----------------------------------------------------------------------- 115 116 void SdTemplateControl::Command( const CommandEvent& rCEvt ) 117 { 118 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU && GetStatusBar().GetItemText( GetId() ).Len() ) 119 { 120 SfxViewFrame* pViewFrame = SfxViewFrame::Current(); 121 122 sd::ViewShellBase* pViewShellBase = sd::ViewShellBase::GetViewShellBase( pViewFrame ); 123 if( !pViewShellBase ) 124 return; 125 126 SdDrawDocument* pDoc = pViewShellBase->GetDocument(); 127 if( !pDoc ) 128 return; 129 130 CaptureMouse(); 131 TemplatePopup_Impl aPop; 132 { 133 const sal_uInt16 nMasterCount = pDoc->GetMasterSdPageCount(PK_STANDARD); 134 135 sal_uInt16 nCount = 0; 136 for( sal_uInt16 nPage = 0; nPage < nMasterCount; ++nPage ) 137 { 138 SdPage* pMaster = pDoc->GetMasterSdPage(nPage, PK_STANDARD); 139 if( pMaster ) 140 aPop.InsertItem( ++nCount, pMaster->GetName() ); 141 } 142 aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); 143 144 sal_uInt16 nCurrId = aPop.GetCurId()-1; 145 if( nCurrId < nMasterCount ) 146 { 147 SdPage* pMaster = pDoc->GetMasterSdPage(nCurrId, PK_STANDARD); 148 SfxStringItem aStyle( ATTR_PRESLAYOUT_NAME, pMaster->GetName() ); 149 pViewFrame->GetDispatcher()->Execute(SID_PRESENTATION_LAYOUT,SFX_CALLMODE_SLOT, &aStyle, 0L ); 150 pViewFrame->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT); 151 pViewFrame->GetBindings().Invalidate(SID_STATUS_LAYOUT); 152 } 153 } 154 155 ReleaseMouse(); 156 } 157 } 158 159 160 161