1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: headermenucontroller.cxx,v $
10 * $Revision: 1.10.40.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
33 #include <uielement/headermenucontroller.hxx>
35 //_________________________________________________________________________________________________________________
37 //_________________________________________________________________________________________________________________
38 #include <threadhelp/resetableguard.hxx>
41 #ifndef __FRAMEWORK_CLASSES_RESOURCE_HRC_
42 #include <classes/resource.hrc>
44 #include <classes/fwlresid.hxx>
46 //_________________________________________________________________________________________________________________
48 //_________________________________________________________________________________________________________________
49 #include <com/sun/star/awt/XDevice.hpp>
50 #include <com/sun/star/beans/PropertyValue.hpp>
51 #include <com/sun/star/awt/MenuItemStyle.hpp>
52 #include <com/sun/star/frame/XDispatchProvider.hpp>
53 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
54 #include <com/sun/star/container/XNameContainer.hpp>
55 #include <com/sun/star/beans/XPropertySet.hpp>
56 #include <com/sun/star/lang/DisposedException.hpp>
58 //_________________________________________________________________________________________________________________
59 // includes of other projects
60 //_________________________________________________________________________________________________________________
62 #ifndef _VCL_MENU_HXX_
63 #include <vcl/menu.hxx>
65 #include <vcl/svapp.hxx>
66 #include <vcl/i18nhelp.hxx>
67 #include <tools/urlobj.hxx>
68 #include <rtl/ustrbuf.hxx>
69 //#include <tools/solar.hrc>
70 #include <dispatch/uieventloghelper.hxx>
72 //_________________________________________________________________________________________________________________
74 //_________________________________________________________________________________________________________________
77 using namespace com::sun::star::uno
;
78 using namespace com::sun::star::lang
;
79 using namespace com::sun::star::frame
;
80 using namespace com::sun::star::beans
;
81 using namespace com::sun::star::util
;
82 using namespace com::sun::star::style
;
83 using namespace com::sun::star::container
;
85 // Copied from Writer module
86 //#define RID_SW_SHELLRES (RID_SW_START + 1250 + 1)
87 //#define STR_ALLPAGE_HEADFOOT 14
89 const USHORT ALL_MENUITEM_ID
= 1;
94 DEFINE_XSERVICEINFO_MULTISERVICE ( HeaderMenuController
,
96 SERVICENAME_POPUPMENUCONTROLLER
,
97 IMPLEMENTATIONNAME_HEADERMENUCONTROLLER
100 DEFINE_INIT_SERVICE ( HeaderMenuController
, {} )
102 HeaderMenuController::HeaderMenuController( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xServiceManager
,bool _bFooter
) :
103 PopupMenuControllerBase( xServiceManager
)
108 HeaderMenuController::~HeaderMenuController()
113 void HeaderMenuController::fillPopupMenu( const Reference
< ::com::sun::star::frame::XModel
>& rModel
, Reference
< css::awt::XPopupMenu
>& rPopupMenu
)
115 VCLXPopupMenu
* pPopupMenu
= (VCLXPopupMenu
*)VCLXMenu::GetImplementation( rPopupMenu
);
116 PopupMenu
* pVCLPopupMenu
= 0;
118 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
120 resetPopupMenu( rPopupMenu
);
122 pVCLPopupMenu
= (PopupMenu
*)pPopupMenu
->GetMenu();
124 Reference
< XStyleFamiliesSupplier
> xStyleFamiliesSupplier( rModel
, UNO_QUERY
);
125 if ( pVCLPopupMenu
&& xStyleFamiliesSupplier
.is())
127 Reference
< XNameAccess
> xStyleFamilies
= xStyleFamiliesSupplier
->getStyleFamilies();
129 rtl::OUString
aCmd( RTL_CONSTASCII_USTRINGPARAM( ".uno:InsertPageHeader" ));
130 rtl::OUString
aHeaderFooterIsOnStr(RTL_CONSTASCII_USTRINGPARAM( "HeaderIsOn" ));
133 aCmd
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:InsertPageFooter" ));
134 aHeaderFooterIsOnStr
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "FooterIsOn" ));
136 const rtl::OUString
aIsPhysicalStr( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ));
137 const rtl::OUString
aDisplayNameStr( RTL_CONSTASCII_USTRINGPARAM( "DisplayName" ));
141 Reference
< XNameContainer
> xNameContainer
;
142 if ( xStyleFamilies
->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageStyles" ))) >>= xNameContainer
)
144 Sequence
< rtl::OUString
> aSeqNames
= xNameContainer
->getElementNames();
148 sal_Bool
bAllOneState( sal_True
);
149 sal_Bool
bLastCheck( sal_True
);
150 sal_Bool
bFirstChecked( sal_False
);
151 sal_Bool
bFirstItemInserted( sal_False
);
152 for ( sal_Int32 n
= 0; n
< aSeqNames
.getLength(); n
++ )
154 rtl::OUString aName
= aSeqNames
[n
];
155 Reference
< XPropertySet
> xPropSet( xNameContainer
->getByName( aName
), UNO_QUERY
);
158 sal_Bool
bIsPhysical( sal_False
);
159 if (( xPropSet
->getPropertyValue( aIsPhysicalStr
) >>= bIsPhysical
) && bIsPhysical
)
161 rtl::OUString aDisplayName
;
162 sal_Bool
bHeaderIsOn( sal_False
);
163 xPropSet
->getPropertyValue( aDisplayNameStr
) >>= aDisplayName
;
164 xPropSet
->getPropertyValue( aHeaderFooterIsOnStr
) >>= bHeaderIsOn
;
166 rtl::OUStringBuffer
aStrBuf( aCmd
);
167 aStrBuf
.appendAscii( "?PageStyle:string=");
168 aStrBuf
.append( aDisplayName
);
169 aStrBuf
.appendAscii( "&On:bool=" );
171 aStrBuf
.appendAscii( "true" );
173 aStrBuf
.appendAscii( "false" );
174 rtl::OUString
aCommand( aStrBuf
.makeStringAndClear() );
175 pVCLPopupMenu
->InsertItem( nId
, aDisplayName
, MIB_CHECKABLE
);
176 if ( !bFirstItemInserted
)
178 bFirstItemInserted
= sal_True
;
179 bFirstChecked
= bHeaderIsOn
;
182 pVCLPopupMenu
->SetItemCommand( nId
, aCommand
);
185 pVCLPopupMenu
->CheckItem( nId
, sal_True
);
188 // Check if all entries have the same state
189 if( bAllOneState
&& n
&& bHeaderIsOn
!= bLastCheck
)
190 bAllOneState
= FALSE
;
191 bLastCheck
= bHeaderIsOn
;
197 if ( bAllOneState
&& ( nCount
> 1 ))
199 // Insert special item for all command
200 pVCLPopupMenu
->InsertItem( ALL_MENUITEM_ID
, String( FwlResId( STR_MENU_HEADFOOTALL
)), 0, 0 );
202 rtl::OUStringBuffer
aStrBuf( aCmd
);
203 aStrBuf
.appendAscii( "?On:bool=" );
205 // Command depends on check state of first menu item entry
206 if ( !bFirstChecked
)
207 aStrBuf
.appendAscii( "true" );
209 aStrBuf
.appendAscii( "false" );
211 pVCLPopupMenu
->SetItemCommand( 1, aStrBuf
.makeStringAndClear() );
212 pVCLPopupMenu
->InsertSeparator( 1 );
216 catch ( com::sun::star::container::NoSuchElementException
& )
223 void SAL_CALL
HeaderMenuController::disposing( const EventObject
& ) throw ( RuntimeException
)
225 Reference
< css::awt::XMenuListener
> xHolder(( OWeakObject
*)this, UNO_QUERY
);
227 ResetableGuard
aLock( m_aLock
);
230 m_xServiceManager
.clear();
232 if ( m_xPopupMenu
.is() )
233 m_xPopupMenu
->removeMenuListener( Reference
< css::awt::XMenuListener
>(( OWeakObject
*)this, UNO_QUERY
));
234 m_xPopupMenu
.clear();
238 void SAL_CALL
HeaderMenuController::statusChanged( const FeatureStateEvent
& Event
) throw ( RuntimeException
)
240 Reference
< com::sun::star::frame::XModel
> xModel
;
242 if ( Event
.State
>>= xModel
)
244 ResetableGuard
aLock( m_aLock
);
246 if ( m_xPopupMenu
.is() )
247 fillPopupMenu( xModel
, m_xPopupMenu
);
252 void HeaderMenuController::impl_select(const Reference
< XDispatch
>& _xDispatch
,const ::com::sun::star::util::URL
& aTargetURL
)
254 Sequence
<PropertyValue
> aArgs
;
255 if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
256 UiEventLogHelper(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(m_bFooter
? "FooterMenuController" : "HeaderMenuController"))).log(m_xServiceManager
, m_xFrame
, aTargetURL
, aArgs
);
257 _xDispatch
->dispatch( aTargetURL
, aArgs
);
260 void SAL_CALL
HeaderMenuController::updatePopupMenu() throw (::com::sun::star::uno::RuntimeException
)
262 ResetableGuard
aLock( m_aLock
);
265 throw DisposedException();
267 Reference
< com::sun::star::frame::XModel
> xModel( m_xModel
);
271 PopupMenuControllerBase::updatePopupMenu();
274 if ( m_xPopupMenu
.is() && m_xModel
.is() )
275 fillPopupMenu( m_xModel
, m_xPopupMenu
);