1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_framework.hxx" 30*cdf0e10cSrcweir #include <uielement/headermenucontroller.hxx> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 33*cdf0e10cSrcweir // my own includes 34*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 35*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 36*cdf0e10cSrcweir #include "services.h" 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #ifndef __FRAMEWORK_CLASSES_RESOURCE_HRC_ 39*cdf0e10cSrcweir #include <classes/resource.hrc> 40*cdf0e10cSrcweir #endif 41*cdf0e10cSrcweir #include <classes/fwlresid.hxx> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 44*cdf0e10cSrcweir // interface includes 45*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 46*cdf0e10cSrcweir #include <com/sun/star/awt/XDevice.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/awt/MenuItemStyle.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 55*cdf0e10cSrcweir // includes of other projects 56*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #ifndef _VCL_MENU_HXX_ 59*cdf0e10cSrcweir #include <vcl/menu.hxx> 60*cdf0e10cSrcweir #endif 61*cdf0e10cSrcweir #include <vcl/svapp.hxx> 62*cdf0e10cSrcweir #include <vcl/i18nhelp.hxx> 63*cdf0e10cSrcweir #include <tools/urlobj.hxx> 64*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 65*cdf0e10cSrcweir //#include <tools/solar.hrc> 66*cdf0e10cSrcweir #include <dispatch/uieventloghelper.hxx> 67*cdf0e10cSrcweir #include <vos/mutex.hxx> 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 70*cdf0e10cSrcweir // Defines 71*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 72*cdf0e10cSrcweir // 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir using namespace com::sun::star::uno; 75*cdf0e10cSrcweir using namespace com::sun::star::lang; 76*cdf0e10cSrcweir using namespace com::sun::star::frame; 77*cdf0e10cSrcweir using namespace com::sun::star::beans; 78*cdf0e10cSrcweir using namespace com::sun::star::util; 79*cdf0e10cSrcweir using namespace com::sun::star::style; 80*cdf0e10cSrcweir using namespace com::sun::star::container; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // Copied from Writer module 83*cdf0e10cSrcweir //#define RID_SW_SHELLRES (RID_SW_START + 1250 + 1) 84*cdf0e10cSrcweir //#define STR_ALLPAGE_HEADFOOT 14 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir const sal_uInt16 ALL_MENUITEM_ID = 1; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir namespace framework 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE ( HeaderMenuController , 92*cdf0e10cSrcweir OWeakObject , 93*cdf0e10cSrcweir SERVICENAME_POPUPMENUCONTROLLER , 94*cdf0e10cSrcweir IMPLEMENTATIONNAME_HEADERMENUCONTROLLER 95*cdf0e10cSrcweir ) 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir DEFINE_INIT_SERVICE ( HeaderMenuController, {} ) 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir HeaderMenuController::HeaderMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager,bool _bFooter ) : 100*cdf0e10cSrcweir svt::PopupMenuControllerBase( xServiceManager ) 101*cdf0e10cSrcweir ,m_bFooter(_bFooter) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir HeaderMenuController::~HeaderMenuController() 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // private function 110*cdf0e10cSrcweir void HeaderMenuController::fillPopupMenu( const Reference< ::com::sun::star::frame::XModel >& rModel, Reference< css::awt::XPopupMenu >& rPopupMenu ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu ); 113*cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = 0; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir resetPopupMenu( rPopupMenu ); 118*cdf0e10cSrcweir if ( pPopupMenu ) 119*cdf0e10cSrcweir pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu(); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir Reference< XStyleFamiliesSupplier > xStyleFamiliesSupplier( rModel, UNO_QUERY ); 122*cdf0e10cSrcweir if ( pVCLPopupMenu && xStyleFamiliesSupplier.is()) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir Reference< XNameAccess > xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies(); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir rtl::OUString aCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:InsertPageHeader" )); 127*cdf0e10cSrcweir rtl::OUString aHeaderFooterIsOnStr(RTL_CONSTASCII_USTRINGPARAM( "HeaderIsOn" )); 128*cdf0e10cSrcweir if ( m_bFooter ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir aCmd = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:InsertPageFooter" )); 131*cdf0e10cSrcweir aHeaderFooterIsOnStr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterIsOn" )); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir const rtl::OUString aIsPhysicalStr( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" )); 134*cdf0e10cSrcweir const rtl::OUString aDisplayNameStr( RTL_CONSTASCII_USTRINGPARAM( "DisplayName" )); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir try 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir Reference< XNameContainer > xNameContainer; 139*cdf0e10cSrcweir if ( xStyleFamilies->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageStyles" ))) >>= xNameContainer ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir Sequence< rtl::OUString > aSeqNames = xNameContainer->getElementNames(); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir sal_uInt16 nId = 2; 144*cdf0e10cSrcweir sal_uInt16 nCount = 0; 145*cdf0e10cSrcweir sal_Bool bAllOneState( sal_True ); 146*cdf0e10cSrcweir sal_Bool bLastCheck( sal_True ); 147*cdf0e10cSrcweir sal_Bool bFirstChecked( sal_False ); 148*cdf0e10cSrcweir sal_Bool bFirstItemInserted( sal_False ); 149*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < aSeqNames.getLength(); n++ ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir rtl::OUString aName = aSeqNames[n]; 152*cdf0e10cSrcweir Reference< XPropertySet > xPropSet( xNameContainer->getByName( aName ), UNO_QUERY ); 153*cdf0e10cSrcweir if ( xPropSet.is() ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir sal_Bool bIsPhysical( sal_False ); 156*cdf0e10cSrcweir if (( xPropSet->getPropertyValue( aIsPhysicalStr ) >>= bIsPhysical ) && bIsPhysical ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir rtl::OUString aDisplayName; 159*cdf0e10cSrcweir sal_Bool bHeaderIsOn( sal_False ); 160*cdf0e10cSrcweir xPropSet->getPropertyValue( aDisplayNameStr ) >>= aDisplayName; 161*cdf0e10cSrcweir xPropSet->getPropertyValue( aHeaderFooterIsOnStr ) >>= bHeaderIsOn; 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir rtl::OUStringBuffer aStrBuf( aCmd ); 164*cdf0e10cSrcweir aStrBuf.appendAscii( "?PageStyle:string="); 165*cdf0e10cSrcweir aStrBuf.append( aDisplayName ); 166*cdf0e10cSrcweir aStrBuf.appendAscii( "&On:bool=" ); 167*cdf0e10cSrcweir if ( !bHeaderIsOn ) 168*cdf0e10cSrcweir aStrBuf.appendAscii( "true" ); 169*cdf0e10cSrcweir else 170*cdf0e10cSrcweir aStrBuf.appendAscii( "false" ); 171*cdf0e10cSrcweir rtl::OUString aCommand( aStrBuf.makeStringAndClear() ); 172*cdf0e10cSrcweir pVCLPopupMenu->InsertItem( nId, aDisplayName, MIB_CHECKABLE ); 173*cdf0e10cSrcweir if ( !bFirstItemInserted ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir bFirstItemInserted = sal_True; 176*cdf0e10cSrcweir bFirstChecked = bHeaderIsOn; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir pVCLPopupMenu->SetItemCommand( nId, aCommand ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if ( bHeaderIsOn ) 182*cdf0e10cSrcweir pVCLPopupMenu->CheckItem( nId, sal_True ); 183*cdf0e10cSrcweir ++nId; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir // Check if all entries have the same state 186*cdf0e10cSrcweir if( bAllOneState && n && bHeaderIsOn != bLastCheck ) 187*cdf0e10cSrcweir bAllOneState = sal_False; 188*cdf0e10cSrcweir bLastCheck = bHeaderIsOn; 189*cdf0e10cSrcweir ++nCount; 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir if ( bAllOneState && ( nCount > 1 )) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir // Insert special item for all command 197*cdf0e10cSrcweir pVCLPopupMenu->InsertItem( ALL_MENUITEM_ID, String( FwlResId( STR_MENU_HEADFOOTALL )), 0, 0 ); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir rtl::OUStringBuffer aStrBuf( aCmd ); 200*cdf0e10cSrcweir aStrBuf.appendAscii( "?On:bool=" ); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir // Command depends on check state of first menu item entry 203*cdf0e10cSrcweir if ( !bFirstChecked ) 204*cdf0e10cSrcweir aStrBuf.appendAscii( "true" ); 205*cdf0e10cSrcweir else 206*cdf0e10cSrcweir aStrBuf.appendAscii( "false" ); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir pVCLPopupMenu->SetItemCommand( 1, aStrBuf.makeStringAndClear() ); 209*cdf0e10cSrcweir pVCLPopupMenu->InsertSeparator( 1 ); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir catch ( com::sun::star::container::NoSuchElementException& ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir // XEventListener 220*cdf0e10cSrcweir void SAL_CALL HeaderMenuController::disposing( const EventObject& ) throw ( RuntimeException ) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY ); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 225*cdf0e10cSrcweir m_xFrame.clear(); 226*cdf0e10cSrcweir m_xDispatch.clear(); 227*cdf0e10cSrcweir m_xServiceManager.clear(); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir if ( m_xPopupMenu.is() ) 230*cdf0e10cSrcweir m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY )); 231*cdf0e10cSrcweir m_xPopupMenu.clear(); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir // XStatusListener 235*cdf0e10cSrcweir void SAL_CALL HeaderMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir Reference< com::sun::star::frame::XModel > xModel; 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir if ( Event.State >>= xModel ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 242*cdf0e10cSrcweir m_xModel = xModel; 243*cdf0e10cSrcweir if ( m_xPopupMenu.is() ) 244*cdf0e10cSrcweir fillPopupMenu( xModel, m_xPopupMenu ); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir // XMenuListener 249*cdf0e10cSrcweir void HeaderMenuController::impl_select(const Reference< XDispatch >& _xDispatch,const ::com::sun::star::util::URL& aTargetURL) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir Sequence<PropertyValue> aArgs; 252*cdf0e10cSrcweir if(::comphelper::UiEventsLogger::isEnabled()) //#i88653# 253*cdf0e10cSrcweir UiEventLogHelper(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(m_bFooter ? "FooterMenuController" : "HeaderMenuController"))).log(m_xServiceManager, m_xFrame, aTargetURL, aArgs); 254*cdf0e10cSrcweir OSL_ENSURE(_xDispatch.is(),"HeaderMenuController::impl_select: No dispatch"); 255*cdf0e10cSrcweir if ( _xDispatch.is() ) 256*cdf0e10cSrcweir _xDispatch->dispatch( aTargetURL, aArgs ); 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir void SAL_CALL HeaderMenuController::updatePopupMenu() throw (::com::sun::star::uno::RuntimeException) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir osl::ResettableMutexGuard aLock( m_aMutex ); 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir throwIfDisposed(); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir Reference< com::sun::star::frame::XModel > xModel( m_xModel ); 266*cdf0e10cSrcweir aLock.clear(); 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir if ( !xModel.is() ) 269*cdf0e10cSrcweir svt::PopupMenuControllerBase::updatePopupMenu(); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir aLock.reset(); 272*cdf0e10cSrcweir if ( m_xPopupMenu.is() && m_xModel.is() ) 273*cdf0e10cSrcweir fillPopupMenu( m_xModel, m_xPopupMenu ); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir } 277