16d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 36d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 46d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 56d739b60SAndrew Rist * distributed with this work for additional information 66d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 76d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 86d739b60SAndrew Rist * "License"); you may not use this file except in compliance 96d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 106d739b60SAndrew Rist * 116d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 126d739b60SAndrew Rist * 136d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 146d739b60SAndrew Rist * software distributed under the License is distributed on an 156d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 166d739b60SAndrew Rist * KIND, either express or implied. See the License for the 176d739b60SAndrew Rist * specific language governing permissions and limitations 186d739b60SAndrew Rist * under the License. 196d739b60SAndrew Rist * 206d739b60SAndrew Rist *************************************************************/ 216d739b60SAndrew Rist 226d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir #include <uielement/toolbarsmenucontroller.hxx> 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <algorithm> 29cdf0e10cSrcweir 30cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 31cdf0e10cSrcweir // my own includes 32cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 33cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 34cdf0e10cSrcweir #include "services.h" 35cdf0e10cSrcweir #ifndef __FRAMEWORK_CLASSES_RESOURCE_HRC_ 36cdf0e10cSrcweir #include <classes/resource.hrc> 37cdf0e10cSrcweir #endif 38cdf0e10cSrcweir #include <classes/fwkresid.hxx> 39cdf0e10cSrcweir #include <uiconfiguration/windowstateconfiguration.hxx> 40cdf0e10cSrcweir #include <framework/imageproducer.hxx> 41cdf0e10cSrcweir #include <framework/sfxhelperfunctions.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 44cdf0e10cSrcweir // interface includes 45cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 46cdf0e10cSrcweir #include <com/sun/star/awt/XDevice.hpp> 47cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 48cdf0e10cSrcweir #include <com/sun/star/awt/MenuItemStyle.hpp> 49cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 50cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 51cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 52cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp> 53cdf0e10cSrcweir #include <com/sun/star/ui/XUIElementSettings.hpp> 54cdf0e10cSrcweir #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> 55cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> 56cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp> 57cdf0e10cSrcweir 58cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 59cdf0e10cSrcweir // includes of other projects 60cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 61cdf0e10cSrcweir 62cdf0e10cSrcweir #ifndef _VCL_MENU_HXX_ 63cdf0e10cSrcweir #include <vcl/menu.hxx> 64cdf0e10cSrcweir #endif 65cdf0e10cSrcweir #include <vcl/svapp.hxx> 66cdf0e10cSrcweir #include <vcl/i18nhelp.hxx> 67cdf0e10cSrcweir #include <vcl/image.hxx> 68cdf0e10cSrcweir #include <tools/urlobj.hxx> 69cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 70cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 71cdf0e10cSrcweir #include <toolkit/unohlp.hxx> 72cdf0e10cSrcweir #endif 73cdf0e10cSrcweir #include <vcl/window.hxx> 74cdf0e10cSrcweir #include <svtools/menuoptions.hxx> 75cdf0e10cSrcweir #include <unotools/cmdoptions.hxx> 76cdf0e10cSrcweir #include <dispatch/uieventloghelper.hxx> 77cdf0e10cSrcweir #include <rtl/logfile.hxx> 78cdf0e10cSrcweir 79cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 80cdf0e10cSrcweir // Defines 81cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 82cdf0e10cSrcweir // 83cdf0e10cSrcweir 84cdf0e10cSrcweir using namespace ::com::sun::star; 85cdf0e10cSrcweir using namespace ::com::sun::star::uno; 86cdf0e10cSrcweir using namespace ::com::sun::star::lang; 87cdf0e10cSrcweir using namespace ::com::sun::star::frame; 88cdf0e10cSrcweir using namespace ::com::sun::star::beans; 89cdf0e10cSrcweir using namespace ::com::sun::star::util; 90cdf0e10cSrcweir using namespace ::com::sun::star::container; 91cdf0e10cSrcweir using namespace ::com::sun::star::frame; 92cdf0e10cSrcweir using namespace ::com::sun::star::ui; 93cdf0e10cSrcweir 94cdf0e10cSrcweir static const char CONFIGURE_TOOLBARS_CMD[] = "ConfigureDialog"; 95cdf0e10cSrcweir static const char CONFIGURE_TOOLBARS[] = ".uno:ConfigureDialog"; 96cdf0e10cSrcweir static const char CMD_COLORBAR[] = ".uno:ColorControl"; 97cdf0e10cSrcweir static const char CMD_HYPERLINKBAR[] = ".uno:InsertHyperlink"; 98cdf0e10cSrcweir static const char CMD_FORMULABAR[] = ".uno:InsertFormula"; 99cdf0e10cSrcweir static const char CMD_INPUTLINEBAR[] = ".uno:InputLineVisible"; 100cdf0e10cSrcweir static const char CMD_RESTOREVISIBILITY[] = ".cmd:RestoreVisibility"; 101cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_RESOURCEURL[] = "ResourceURL"; 102cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_UINAME[] = "UIName"; 103cdf0e10cSrcweir static const char STATIC_PRIVATE_TB_RESOURCE[] = "private:resource/toolbar/"; 104cdf0e10cSrcweir 105cdf0e10cSrcweir static const char STATIC_CMD_PART[] = ".uno:AvailableToolbars?Toolbar:string="; 106cdf0e10cSrcweir static const char STATIC_INTERNAL_CMD_PART[] = ".cmd:"; 107cdf0e10cSrcweir 108cdf0e10cSrcweir namespace framework 109cdf0e10cSrcweir { 110cdf0e10cSrcweir 111*5758ad8cSAriel Constenla-Haile typedef std::hash_map< rtl::OUString, rtl::OUString, rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > ToolbarHashMap; 112cdf0e10cSrcweir 113cdf0e10cSrcweir struct ToolBarEntry 114cdf0e10cSrcweir { 115cdf0e10cSrcweir rtl::OUString aUIName; 116cdf0e10cSrcweir rtl::OUString aCommand; 117cdf0e10cSrcweir sal_Bool bVisible; 118cdf0e10cSrcweir sal_Bool bContextSensitive; 119cdf0e10cSrcweir const CollatorWrapper* pCollatorWrapper; 120cdf0e10cSrcweir }; 121cdf0e10cSrcweir 122cdf0e10cSrcweir sal_Bool CompareToolBarEntry( const ToolBarEntry& aOne, const ToolBarEntry& aTwo ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir sal_Int32 nComp = aOne.pCollatorWrapper->compareString( aOne.aUIName, aTwo.aUIName ); 125cdf0e10cSrcweir 126cdf0e10cSrcweir if ( nComp < 0 ) 127cdf0e10cSrcweir return sal_True; 128cdf0e10cSrcweir else if ( nComp > 0 ) 129cdf0e10cSrcweir return sal_False; 130cdf0e10cSrcweir else 131cdf0e10cSrcweir return sal_False; 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir Reference< XLayoutManager > getLayoutManagerFromFrame( const Reference< XFrame >& rFrame ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir Reference< XPropertySet > xPropSet( rFrame, UNO_QUERY ); 137cdf0e10cSrcweir Reference< XLayoutManager > xLayoutManager; 138cdf0e10cSrcweir 139cdf0e10cSrcweir try 140cdf0e10cSrcweir { 141cdf0e10cSrcweir xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))) >>= xLayoutManager; 142cdf0e10cSrcweir } 143cdf0e10cSrcweir catch ( UnknownPropertyException& ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir return xLayoutManager; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir struct ToolBarInfo 151cdf0e10cSrcweir { 152cdf0e10cSrcweir rtl::OUString aToolBarResName; 153cdf0e10cSrcweir rtl::OUString aToolBarUIName; 154cdf0e10cSrcweir }; 155cdf0e10cSrcweir 156cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE ( ToolbarsMenuController , 157cdf0e10cSrcweir OWeakObject , 158cdf0e10cSrcweir SERVICENAME_POPUPMENUCONTROLLER , 159cdf0e10cSrcweir IMPLEMENTATIONNAME_TOOLBARSMENUCONTROLLER 160cdf0e10cSrcweir ) 161cdf0e10cSrcweir 162cdf0e10cSrcweir DEFINE_INIT_SERVICE ( ToolbarsMenuController, {} ) 163cdf0e10cSrcweir 164cdf0e10cSrcweir ToolbarsMenuController::ToolbarsMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) : 165cdf0e10cSrcweir svt::PopupMenuControllerBase( xServiceManager ), 166cdf0e10cSrcweir m_aPropUIName( RTL_CONSTASCII_USTRINGPARAM( "UIName" )), 167cdf0e10cSrcweir m_aPropResourceURL( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" )), 168cdf0e10cSrcweir m_bModuleIdentified( sal_False ), 169cdf0e10cSrcweir m_bResetActive( sal_False ), 170cdf0e10cSrcweir m_aIntlWrapper( xServiceManager, Application::GetSettings().GetLocale() ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir ToolbarsMenuController::~ToolbarsMenuController() 175cdf0e10cSrcweir { 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir void ToolbarsMenuController::addCommand( 179cdf0e10cSrcweir Reference< css::awt::XPopupMenu >& rPopupMenu, const rtl::OUString& rCommandURL, const rtl::OUString& rLabel ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir sal_uInt16 nItemId = m_xPopupMenu->getItemCount()+1; 182cdf0e10cSrcweir 183cdf0e10cSrcweir rtl::OUString aLabel; 184cdf0e10cSrcweir if ( rLabel.getLength() == 0 ) 185cdf0e10cSrcweir aLabel = getUINameFromCommand( rCommandURL ); 186cdf0e10cSrcweir else 187cdf0e10cSrcweir aLabel = rLabel; 188cdf0e10cSrcweir 189cdf0e10cSrcweir rPopupMenu->insertItem( nItemId, aLabel, 0, nItemId ); 190cdf0e10cSrcweir Reference< awt::XMenuExtended > xMenuExtended( m_xPopupMenu, UNO_QUERY ); 191cdf0e10cSrcweir xMenuExtended->setCommand( nItemId, rCommandURL ); 192cdf0e10cSrcweir 193cdf0e10cSrcweir bool bInternal = ( rCommandURL.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATIC_INTERNAL_CMD_PART ))) == 0); 194cdf0e10cSrcweir if ( !bInternal ) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir if ( !getDispatchFromCommandURL( rCommandURL ).is() ) 197cdf0e10cSrcweir m_xPopupMenu->enableItem( nItemId, sal_False ); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 201cdf0e10cSrcweir 202cdf0e10cSrcweir Image aImage; 203cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); 204cdf0e10cSrcweir 205cdf0e10cSrcweir if ( rSettings.GetUseImagesInMenus() ) 206cdf0e10cSrcweir aImage = GetImageFromURL( m_xFrame, rCommandURL, sal_False, rSettings.GetHighContrastMode() ); 207cdf0e10cSrcweir 208cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( rPopupMenu ); 209cdf0e10cSrcweir if ( pPopupMenu ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu(); 212cdf0e10cSrcweir if ( !!aImage ) 213cdf0e10cSrcweir pVCLPopupMenu->SetItemImage( nItemId, aImage ); 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir m_aCommandVector.push_back( rCommandURL ); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir Reference< XDispatch > ToolbarsMenuController::getDispatchFromCommandURL( const rtl::OUString& rCommandURL ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir URL aTargetURL; 222cdf0e10cSrcweir Sequence<PropertyValue> aArgs; 223cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer; 224cdf0e10cSrcweir Reference< XFrame > xFrame; 225cdf0e10cSrcweir 226cdf0e10cSrcweir { 227cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 228cdf0e10cSrcweir xURLTransformer = m_xURLTransformer; 229cdf0e10cSrcweir xFrame = m_xFrame; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir aTargetURL.Complete = rCommandURL; 233cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 234cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( xFrame, UNO_QUERY ); 235cdf0e10cSrcweir if ( xDispatchProvider.is() ) 236cdf0e10cSrcweir return xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); 237cdf0e10cSrcweir else 238cdf0e10cSrcweir return Reference< XDispatch >(); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir // private function 242cdf0e10cSrcweir rtl::OUString ToolbarsMenuController::getUINameFromCommand( const rtl::OUString& rCommandURL ) 243cdf0e10cSrcweir { 244cdf0e10cSrcweir rtl::OUString aLabel; 245cdf0e10cSrcweir 246cdf0e10cSrcweir if ( !m_bModuleIdentified ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir try 249cdf0e10cSrcweir { 250cdf0e10cSrcweir Reference< XModuleManager > xModuleManager( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW ); 251cdf0e10cSrcweir m_aModuleIdentifier = xModuleManager->identify( m_xFrame ); 252cdf0e10cSrcweir Reference< XNameAccess > xNameAccess( m_xServiceManager->createInstance( 253cdf0e10cSrcweir SERVICENAME_UICOMMANDDESCRIPTION ), 254cdf0e10cSrcweir UNO_QUERY ); 255cdf0e10cSrcweir xNameAccess->getByName( m_aModuleIdentifier ) >>= m_xUICommandDescription; 256cdf0e10cSrcweir } 257cdf0e10cSrcweir catch ( Exception& ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir } 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir if ( m_xUICommandDescription.is() ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir try 265cdf0e10cSrcweir { 266cdf0e10cSrcweir Sequence< PropertyValue > aPropSeq; 267cdf0e10cSrcweir rtl::OUString aStr; 268cdf0e10cSrcweir if ( m_xUICommandDescription->getByName( rCommandURL ) >>= aPropSeq ) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir if ( aPropSeq[i].Name.equalsAscii( "Label" )) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir aPropSeq[i].Value >>= aStr; 275cdf0e10cSrcweir break; 276cdf0e10cSrcweir } 277cdf0e10cSrcweir } 278cdf0e10cSrcweir } 279cdf0e10cSrcweir aLabel = aStr; 280cdf0e10cSrcweir } 281cdf0e10cSrcweir catch ( Exception& ) 282cdf0e10cSrcweir { 283cdf0e10cSrcweir } 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir return aLabel; 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir static void fillHashMap( const Sequence< Sequence< ::com::sun::star::beans::PropertyValue > >& rSeqToolBars, 290cdf0e10cSrcweir ToolbarHashMap& rHashMap ) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rSeqToolBars.getLength(); i++ ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir rtl::OUString aResourceURL; 295cdf0e10cSrcweir rtl::OUString aUIName; 296cdf0e10cSrcweir const PropertyValue* pProperties = rSeqToolBars[i].getConstArray(); 297cdf0e10cSrcweir for ( sal_Int32 j = 0; j < rSeqToolBars[i].getLength(); j++ ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir if ( pProperties[j].Name.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL) ) 300cdf0e10cSrcweir pProperties[j].Value >>= aResourceURL; 301cdf0e10cSrcweir else if ( pProperties[j].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) ) 302cdf0e10cSrcweir pProperties[j].Value >>= aUIName; 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir if ( aResourceURL.getLength() > 0 && 306cdf0e10cSrcweir rHashMap.find( aResourceURL ) == rHashMap.end() ) 307cdf0e10cSrcweir rHashMap.insert( ToolbarHashMap::value_type( aResourceURL, aUIName )); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir } 310cdf0e10cSrcweir 311cdf0e10cSrcweir // private function 312cdf0e10cSrcweir Sequence< Sequence< com::sun::star::beans::PropertyValue > > ToolbarsMenuController::getLayoutManagerToolbars( const Reference< ::com::sun::star::frame::XLayoutManager >& rLayoutManager ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir std::vector< ToolBarInfo > aToolBarArray; 315cdf0e10cSrcweir Sequence< Reference< XUIElement > > aUIElements = rLayoutManager->getElements(); 316cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aUIElements.getLength(); i++ ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir Reference< XUIElement > xUIElement( aUIElements[i] ); 319cdf0e10cSrcweir Reference< XPropertySet > xPropSet( aUIElements[i], UNO_QUERY ); 320cdf0e10cSrcweir if ( xPropSet.is() && xUIElement.is() ) 321cdf0e10cSrcweir { 322cdf0e10cSrcweir try 323cdf0e10cSrcweir { 324cdf0e10cSrcweir rtl::OUString aResName; 325cdf0e10cSrcweir sal_Int16 nType( -1 ); 326cdf0e10cSrcweir xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ))) >>= nType; 327cdf0e10cSrcweir xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ))) >>= aResName; 328cdf0e10cSrcweir 329cdf0e10cSrcweir if (( nType == ::com::sun::star::ui::UIElementType::TOOLBAR ) && 330cdf0e10cSrcweir ( aResName.getLength() > 0 )) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir ToolBarInfo aToolBarInfo; 333cdf0e10cSrcweir 334cdf0e10cSrcweir aToolBarInfo.aToolBarResName = aResName; 335cdf0e10cSrcweir 336cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 337cdf0e10cSrcweir Reference< css::awt::XWindow > xWindow( xUIElement->getRealInterface(), UNO_QUERY ); 338cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 339cdf0e10cSrcweir if ( pWindow ) 340cdf0e10cSrcweir aToolBarInfo.aToolBarUIName = pWindow->GetText(); 341cdf0e10cSrcweir 342cdf0e10cSrcweir aToolBarArray.push_back( aToolBarInfo ); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir } 345cdf0e10cSrcweir catch ( Exception& ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir } 348cdf0e10cSrcweir } 349cdf0e10cSrcweir } 350cdf0e10cSrcweir 351cdf0e10cSrcweir Sequence< com::sun::star::beans::PropertyValue > aTbSeq( 2 ); 352cdf0e10cSrcweir aTbSeq[0].Name = m_aPropUIName; 353cdf0e10cSrcweir aTbSeq[1].Name = m_aPropResourceURL; 354cdf0e10cSrcweir 355cdf0e10cSrcweir Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeq( aToolBarArray.size() ); 356cdf0e10cSrcweir const sal_uInt32 nCount = aToolBarArray.size(); 357cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 358cdf0e10cSrcweir { 359cdf0e10cSrcweir aTbSeq[0].Value <<= aToolBarArray[i].aToolBarUIName; 360cdf0e10cSrcweir aTbSeq[1].Value <<= aToolBarArray[i].aToolBarResName; 361cdf0e10cSrcweir aSeq[i] = aTbSeq; 362cdf0e10cSrcweir } 363cdf0e10cSrcweir 364cdf0e10cSrcweir return aSeq; 365cdf0e10cSrcweir } 366cdf0e10cSrcweir 367cdf0e10cSrcweir sal_Bool ToolbarsMenuController::isContextSensitiveToolbarNonVisible() 368cdf0e10cSrcweir { 369cdf0e10cSrcweir return m_bResetActive; 370cdf0e10cSrcweir } 371cdf0e10cSrcweir 372cdf0e10cSrcweir void ToolbarsMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu ) 373cdf0e10cSrcweir { 374cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 375cdf0e10cSrcweir resetPopupMenu( rPopupMenu ); 376cdf0e10cSrcweir 377cdf0e10cSrcweir m_aCommandVector.clear(); 378cdf0e10cSrcweir 379cdf0e10cSrcweir // Retrieve layout manager for additional information 380cdf0e10cSrcweir rtl::OUString aEmptyString; 381cdf0e10cSrcweir Reference< awt::XMenuExtended > xMenuExtended( rPopupMenu, UNO_QUERY ); 382cdf0e10cSrcweir Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( m_xFrame )); 383cdf0e10cSrcweir 384cdf0e10cSrcweir m_bResetActive = sal_False; 385cdf0e10cSrcweir if ( xLayoutManager.is() ) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir ToolbarHashMap aToolbarHashMap; 388cdf0e10cSrcweir 389cdf0e10cSrcweir if ( m_xDocCfgMgr.is() ) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeqDocToolBars = 392cdf0e10cSrcweir m_xDocCfgMgr->getUIElementsInfo( UIElementType::TOOLBAR ); 393cdf0e10cSrcweir fillHashMap( aSeqDocToolBars, aToolbarHashMap ); 394cdf0e10cSrcweir } 395cdf0e10cSrcweir 396cdf0e10cSrcweir if ( m_xModuleCfgMgr.is() ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeqToolBars = 399cdf0e10cSrcweir m_xModuleCfgMgr->getUIElementsInfo( UIElementType::TOOLBAR ); 400cdf0e10cSrcweir fillHashMap( aSeqToolBars, aToolbarHashMap ); 401cdf0e10cSrcweir } 402cdf0e10cSrcweir 403cdf0e10cSrcweir std::vector< ToolBarEntry > aSortedTbs; 404cdf0e10cSrcweir rtl::OUString aStaticCmdPart( RTL_CONSTASCII_USTRINGPARAM( STATIC_CMD_PART )); 405cdf0e10cSrcweir 406cdf0e10cSrcweir Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeqFrameToolBars = getLayoutManagerToolbars( xLayoutManager ); 407cdf0e10cSrcweir fillHashMap( aSeqFrameToolBars, aToolbarHashMap ); 408cdf0e10cSrcweir 409cdf0e10cSrcweir ToolbarHashMap::const_iterator pIter = aToolbarHashMap.begin(); 410cdf0e10cSrcweir while ( pIter != aToolbarHashMap.end() ) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir rtl::OUString aUIName = pIter->second; 413cdf0e10cSrcweir sal_Bool bHideFromMenu( sal_False ); 414cdf0e10cSrcweir sal_Bool bContextSensitive( sal_False ); 415cdf0e10cSrcweir sal_Bool bVisible( sal_False ); 416cdf0e10cSrcweir if ( aUIName.getLength() == 0 && 417cdf0e10cSrcweir m_xPersistentWindowState.is() ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir try 420cdf0e10cSrcweir { 421cdf0e10cSrcweir Sequence< PropertyValue > aWindowState; 422cdf0e10cSrcweir Any a( m_xPersistentWindowState->getByName( pIter->first )); 423cdf0e10cSrcweir 424cdf0e10cSrcweir if ( a >>= aWindowState ) 425cdf0e10cSrcweir { 426cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aWindowState.getLength(); i++ ) 427cdf0e10cSrcweir { 428cdf0e10cSrcweir if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_UINAME )) 429cdf0e10cSrcweir aWindowState[i].Value >>= aUIName; 430cdf0e10cSrcweir else if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_HIDEFROMENU )) 431cdf0e10cSrcweir aWindowState[i].Value >>= bHideFromMenu; 432cdf0e10cSrcweir else if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXT )) 433cdf0e10cSrcweir aWindowState[i].Value >>= bContextSensitive; 434cdf0e10cSrcweir else if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_VISIBLE )) 435cdf0e10cSrcweir aWindowState[i].Value >>= bVisible; 436cdf0e10cSrcweir } 437cdf0e10cSrcweir } 438cdf0e10cSrcweir } 439cdf0e10cSrcweir catch ( Exception& ) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir } 442cdf0e10cSrcweir 443cdf0e10cSrcweir // Check if we have to enable/disable "Reset" menu item 444cdf0e10cSrcweir if ( bContextSensitive && !bVisible ) 445cdf0e10cSrcweir m_bResetActive = sal_True; 446cdf0e10cSrcweir 447cdf0e10cSrcweir } 448cdf0e10cSrcweir 449cdf0e10cSrcweir if (( aUIName.getLength() > 0 ) && ( !bHideFromMenu )) 450cdf0e10cSrcweir { 451cdf0e10cSrcweir ToolBarEntry aTbEntry; 452cdf0e10cSrcweir aTbEntry.aUIName = aUIName; 453cdf0e10cSrcweir aTbEntry.aCommand = pIter->first; 454cdf0e10cSrcweir aTbEntry.bVisible = xLayoutManager->isElementVisible( pIter->first ); 455cdf0e10cSrcweir aTbEntry.bContextSensitive = bContextSensitive; 456cdf0e10cSrcweir aTbEntry.pCollatorWrapper = m_aIntlWrapper.getCaseCollator(); 457cdf0e10cSrcweir aSortedTbs.push_back( aTbEntry ); 458cdf0e10cSrcweir } 459cdf0e10cSrcweir pIter++; 460cdf0e10cSrcweir } 461cdf0e10cSrcweir 462cdf0e10cSrcweir // sort toolbars 463cdf0e10cSrcweir std::sort( aSortedTbs.begin(), aSortedTbs.end(), CompareToolBarEntry ); 464cdf0e10cSrcweir 465cdf0e10cSrcweir sal_Int16 nIndex( 1 ); 466cdf0e10cSrcweir const sal_uInt32 nCount = aSortedTbs.size(); 467cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 468cdf0e10cSrcweir { 469cdf0e10cSrcweir sal_uInt16 nItemCount = m_xPopupMenu->getItemCount(); 470cdf0e10cSrcweir m_xPopupMenu->insertItem( nIndex, aSortedTbs[i].aUIName, css::awt::MenuItemStyle::CHECKABLE, nItemCount ); 471cdf0e10cSrcweir if ( aSortedTbs[i].bVisible ) 472cdf0e10cSrcweir m_xPopupMenu->checkItem( nIndex, sal_True ); 473cdf0e10cSrcweir 474cdf0e10cSrcweir { 475cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 476cdf0e10cSrcweir VCLXPopupMenu* pXPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( m_xPopupMenu ); 477cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = (PopupMenu *)pXPopupMenu->GetMenu(); 478cdf0e10cSrcweir 479cdf0e10cSrcweir pVCLPopupMenu->SetUserValue( nIndex, sal_uIntPtr( aSortedTbs[i].bContextSensitive ? 1L : 0L )); 480cdf0e10cSrcweir } 481cdf0e10cSrcweir 482cdf0e10cSrcweir // use VCL popup menu pointer to set vital information that are not part of the awt implementation 483cdf0e10cSrcweir rtl::OUStringBuffer aStrBuf( aStaticCmdPart ); 484cdf0e10cSrcweir 485cdf0e10cSrcweir sal_Int32 n = aSortedTbs[i].aCommand.lastIndexOf( '/' ); 486cdf0e10cSrcweir if (( n > 0 ) && (( n+1 ) < aSortedTbs[i].aCommand.getLength() )) 487cdf0e10cSrcweir aStrBuf.append( aSortedTbs[i].aCommand.copy( n+1 )); 488cdf0e10cSrcweir 489cdf0e10cSrcweir rtl::OUString aCmd( aStrBuf.makeStringAndClear() ); 490cdf0e10cSrcweir 491cdf0e10cSrcweir // Store complete uno-command so it can also be dispatched. This is necessary to support 492cdf0e10cSrcweir // the test tool! 493cdf0e10cSrcweir xMenuExtended->setCommand( nIndex, aCmd ); 494cdf0e10cSrcweir ++nIndex; 495cdf0e10cSrcweir } 496cdf0e10cSrcweir 497cdf0e10cSrcweir // Create commands for non-toolbars 498cdf0e10cSrcweir if ( m_aModuleIdentifier.equalsAscii( "com.sun.star.text.TextDocument" ) || 499cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.text.WebDocument" ) || 500cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.text.GlobalDocument" ) || 501cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.drawing.DrawingDocument" ) || 502cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.presentation.PresentationDocument" ) || 503cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" )) 504cdf0e10cSrcweir { 505cdf0e10cSrcweir addCommand( m_xPopupMenu, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CMD_HYPERLINKBAR )), aEmptyString ); 506cdf0e10cSrcweir if ( m_aModuleIdentifier.equalsAscii( "com.sun.star.drawing.DrawingDocument" ) || 507cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.presentation.PresentationDocument" )) 508cdf0e10cSrcweir addCommand( m_xPopupMenu, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CMD_COLORBAR )), aEmptyString ); 509cdf0e10cSrcweir else if ( m_aModuleIdentifier.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" )) 510cdf0e10cSrcweir addCommand( m_xPopupMenu, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CMD_INPUTLINEBAR )), aEmptyString ); 511cdf0e10cSrcweir else 512cdf0e10cSrcweir addCommand( m_xPopupMenu, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CMD_FORMULABAR )), aEmptyString ); 513cdf0e10cSrcweir } 514cdf0e10cSrcweir 515cdf0e10cSrcweir sal_Bool bAddCommand( sal_True ); 516cdf0e10cSrcweir SvtCommandOptions aCmdOptions; 517cdf0e10cSrcweir rtl::OUString aConfigureToolbar( RTL_CONSTASCII_USTRINGPARAM( CONFIGURE_TOOLBARS )); 518cdf0e10cSrcweir 519cdf0e10cSrcweir if ( aCmdOptions.HasEntries( SvtCommandOptions::CMDOPTION_DISABLED )) 520cdf0e10cSrcweir { 521cdf0e10cSrcweir if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, 522cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONFIGURE_TOOLBARS_CMD )))) 523cdf0e10cSrcweir bAddCommand = sal_False; 524cdf0e10cSrcweir } 525cdf0e10cSrcweir 526cdf0e10cSrcweir if ( bAddCommand ) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir // Create command for configure 529cdf0e10cSrcweir if ( m_xPopupMenu->getItemCount() > 0 ) 530cdf0e10cSrcweir { 531cdf0e10cSrcweir sal_uInt16 nItemCount = m_xPopupMenu->getItemCount(); 532cdf0e10cSrcweir m_xPopupMenu->insertSeparator( nItemCount+1 ); 533cdf0e10cSrcweir } 534cdf0e10cSrcweir 535cdf0e10cSrcweir addCommand( m_xPopupMenu, aConfigureToolbar, aEmptyString ); 536cdf0e10cSrcweir } 537cdf0e10cSrcweir 538cdf0e10cSrcweir // Add separator if no configure has been added 539cdf0e10cSrcweir if ( !bAddCommand ) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir // Create command for configure 542cdf0e10cSrcweir if ( m_xPopupMenu->getItemCount() > 0 ) 543cdf0e10cSrcweir { 544cdf0e10cSrcweir sal_uInt16 nItemCount = m_xPopupMenu->getItemCount(); 545cdf0e10cSrcweir m_xPopupMenu->insertSeparator( nItemCount+1 ); 546cdf0e10cSrcweir } 547cdf0e10cSrcweir } 548cdf0e10cSrcweir 549cdf0e10cSrcweir String aLabelStr = String( FwkResId( STR_RESTORE_TOOLBARS )); 550cdf0e10cSrcweir rtl::OUString aRestoreCmd( RTL_CONSTASCII_USTRINGPARAM( CMD_RESTOREVISIBILITY )); 551cdf0e10cSrcweir addCommand( m_xPopupMenu, aRestoreCmd, aLabelStr ); 552cdf0e10cSrcweir } 553cdf0e10cSrcweir } 554cdf0e10cSrcweir 555cdf0e10cSrcweir // XEventListener 556cdf0e10cSrcweir void SAL_CALL ToolbarsMenuController::disposing( const EventObject& ) throw ( RuntimeException ) 557cdf0e10cSrcweir { 558cdf0e10cSrcweir Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY ); 559cdf0e10cSrcweir 560cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 561cdf0e10cSrcweir m_xFrame.clear(); 562cdf0e10cSrcweir m_xDispatch.clear(); 563cdf0e10cSrcweir m_xDocCfgMgr.clear(); 564cdf0e10cSrcweir m_xModuleCfgMgr.clear(); 565cdf0e10cSrcweir m_xServiceManager.clear(); 566cdf0e10cSrcweir 567cdf0e10cSrcweir if ( m_xPopupMenu.is() ) 568cdf0e10cSrcweir m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY )); 569cdf0e10cSrcweir m_xPopupMenu.clear(); 570cdf0e10cSrcweir } 571cdf0e10cSrcweir 572cdf0e10cSrcweir // XStatusListener 573cdf0e10cSrcweir void SAL_CALL ToolbarsMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException ) 574cdf0e10cSrcweir { 575cdf0e10cSrcweir rtl::OUString aFeatureURL( Event.FeatureURL.Complete ); 576cdf0e10cSrcweir 577cdf0e10cSrcweir // All other status events will be processed here 578cdf0e10cSrcweir sal_Bool bSetCheckmark = sal_False; 579cdf0e10cSrcweir sal_Bool bCheckmark = sal_False; 580cdf0e10cSrcweir 581cdf0e10cSrcweir osl::ClearableMutexGuard aLock( m_aMutex ); 582cdf0e10cSrcweir Reference< css::awt::XPopupMenu > xPopupMenu( m_xPopupMenu ); 583cdf0e10cSrcweir aLock.clear(); 584cdf0e10cSrcweir 585cdf0e10cSrcweir if ( xPopupMenu.is() ) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 588cdf0e10cSrcweir VCLXPopupMenu* pXPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( xPopupMenu ); 589cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = (PopupMenu *)pXPopupMenu->GetMenu(); 590cdf0e10cSrcweir 591cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < pVCLPopupMenu->GetItemCount(); i++ ) 592cdf0e10cSrcweir { 593cdf0e10cSrcweir sal_uInt16 nId = pVCLPopupMenu->GetItemId( i ); 594cdf0e10cSrcweir if ( nId == 0 ) 595cdf0e10cSrcweir continue; 596cdf0e10cSrcweir 597cdf0e10cSrcweir rtl::OUString aCmd = pVCLPopupMenu->GetItemCommand( nId ); 598cdf0e10cSrcweir if ( aCmd == aFeatureURL ) 599cdf0e10cSrcweir { 600cdf0e10cSrcweir // Enable/disable item 601cdf0e10cSrcweir pVCLPopupMenu->EnableItem( nId, Event.IsEnabled ); 602cdf0e10cSrcweir 603cdf0e10cSrcweir // Checkmark 604cdf0e10cSrcweir if ( Event.State >>= bCheckmark ) 605cdf0e10cSrcweir bSetCheckmark = sal_True; 606cdf0e10cSrcweir 607cdf0e10cSrcweir if ( bSetCheckmark ) 608cdf0e10cSrcweir pVCLPopupMenu->CheckItem( nId, bCheckmark ); 609cdf0e10cSrcweir else 610cdf0e10cSrcweir { 611cdf0e10cSrcweir rtl::OUString aItemText; 612cdf0e10cSrcweir 613cdf0e10cSrcweir if ( Event.State >>= aItemText ) 614cdf0e10cSrcweir pVCLPopupMenu->SetItemText( nId, aItemText ); 615cdf0e10cSrcweir } 616cdf0e10cSrcweir } 617cdf0e10cSrcweir } 618cdf0e10cSrcweir } 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir // XMenuListener 622cdf0e10cSrcweir void SAL_CALL ToolbarsMenuController::select( const css::awt::MenuEvent& rEvent ) throw (RuntimeException) 623cdf0e10cSrcweir { 624cdf0e10cSrcweir Reference< css::awt::XPopupMenu > xPopupMenu; 625cdf0e10cSrcweir Reference< XMultiServiceFactory > xServiceManager; 626cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer; 627cdf0e10cSrcweir Reference< XFrame > xFrame; 628cdf0e10cSrcweir Reference< XNameAccess > xPersistentWindowState; 629cdf0e10cSrcweir 630cdf0e10cSrcweir osl::ClearableMutexGuard aLock( m_aMutex ); 631cdf0e10cSrcweir xPopupMenu = m_xPopupMenu; 632cdf0e10cSrcweir xServiceManager = m_xServiceManager; 633cdf0e10cSrcweir xURLTransformer = m_xURLTransformer; 634cdf0e10cSrcweir xFrame = m_xFrame; 635cdf0e10cSrcweir xPersistentWindowState = m_xPersistentWindowState; 636cdf0e10cSrcweir aLock.clear(); 637cdf0e10cSrcweir 638cdf0e10cSrcweir if ( xPopupMenu.is() ) 639cdf0e10cSrcweir { 640cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( xPopupMenu ); 641cdf0e10cSrcweir if ( pPopupMenu ) 642cdf0e10cSrcweir { 643cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 644cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu(); 645cdf0e10cSrcweir 646cdf0e10cSrcweir rtl::OUString aCmd( pVCLPopupMenu->GetItemCommand( rEvent.MenuId )); 647cdf0e10cSrcweir if ( aCmd.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATIC_INTERNAL_CMD_PART ))) == 0 ) 648cdf0e10cSrcweir { 649cdf0e10cSrcweir // Command to restore the visibility of all context sensitive toolbars 650cdf0e10cSrcweir Reference< XNameReplace > xNameReplace( xPersistentWindowState, UNO_QUERY ); 651cdf0e10cSrcweir if ( xPersistentWindowState.is() && xNameReplace.is() ) 652cdf0e10cSrcweir { 653cdf0e10cSrcweir try 654cdf0e10cSrcweir { 655cdf0e10cSrcweir Sequence< rtl::OUString > aElementNames = xPersistentWindowState->getElementNames(); 656cdf0e10cSrcweir sal_Int32 nCount = aElementNames.getLength(); 657cdf0e10cSrcweir bool bRefreshToolbars( false ); 658cdf0e10cSrcweir 659cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; i++ ) 660cdf0e10cSrcweir { 661cdf0e10cSrcweir try 662cdf0e10cSrcweir { 663cdf0e10cSrcweir rtl::OUString aElementName = aElementNames[i]; 664cdf0e10cSrcweir Sequence< PropertyValue > aWindowState; 665cdf0e10cSrcweir 666cdf0e10cSrcweir if ( xPersistentWindowState->getByName( aElementName ) >>= aWindowState ) 667cdf0e10cSrcweir { 668cdf0e10cSrcweir sal_Bool bVisible( sal_False ); 669cdf0e10cSrcweir sal_Bool bContextSensitive( sal_False ); 670cdf0e10cSrcweir sal_Int32 nVisibleIndex( -1 ); 671cdf0e10cSrcweir for ( sal_Int32 j = 0; j < aWindowState.getLength(); j++ ) 672cdf0e10cSrcweir { 673cdf0e10cSrcweir if ( aWindowState[j].Name.equalsAscii( WINDOWSTATE_PROPERTY_VISIBLE )) 674cdf0e10cSrcweir { 675cdf0e10cSrcweir aWindowState[j].Value >>= bVisible; 676cdf0e10cSrcweir nVisibleIndex = j; 677cdf0e10cSrcweir } 678cdf0e10cSrcweir else if ( aWindowState[j].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXT )) 679cdf0e10cSrcweir aWindowState[j].Value >>= bContextSensitive; 680cdf0e10cSrcweir } 681cdf0e10cSrcweir 682cdf0e10cSrcweir if ( !bVisible && bContextSensitive && nVisibleIndex >= 0 ) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir // Default is: Every context sensitive toolbar is visible 685cdf0e10cSrcweir aWindowState[nVisibleIndex].Value <<= sal_True; 686cdf0e10cSrcweir xNameReplace->replaceByName( aElementName, makeAny( aWindowState )); 687cdf0e10cSrcweir bRefreshToolbars = true; 688cdf0e10cSrcweir } 689cdf0e10cSrcweir } 690cdf0e10cSrcweir } 691cdf0e10cSrcweir catch ( NoSuchElementException& ) 692cdf0e10cSrcweir { 693cdf0e10cSrcweir } 694cdf0e10cSrcweir } 695cdf0e10cSrcweir 696cdf0e10cSrcweir if ( bRefreshToolbars ) 697cdf0e10cSrcweir { 698cdf0e10cSrcweir Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( xFrame )); 699cdf0e10cSrcweir if ( xLayoutManager.is() ) 700cdf0e10cSrcweir { 701cdf0e10cSrcweir Reference< XPropertySet > xPropSet( xLayoutManager, UNO_QUERY ); 702cdf0e10cSrcweir if ( xPropSet.is() ) 703cdf0e10cSrcweir { 704cdf0e10cSrcweir try 705cdf0e10cSrcweir { 706cdf0e10cSrcweir xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RefreshContextToolbarVisibility" )), makeAny( sal_True )); 707cdf0e10cSrcweir } 708cdf0e10cSrcweir catch ( RuntimeException& ) 709cdf0e10cSrcweir { 710cdf0e10cSrcweir } 711cdf0e10cSrcweir catch ( Exception& ) 712cdf0e10cSrcweir { 713cdf0e10cSrcweir } 714cdf0e10cSrcweir } 715cdf0e10cSrcweir } 716cdf0e10cSrcweir RefreshToolbars( xFrame ); 717cdf0e10cSrcweir } 718cdf0e10cSrcweir } 719cdf0e10cSrcweir catch ( RuntimeException& ) 720cdf0e10cSrcweir { 721cdf0e10cSrcweir throw; 722cdf0e10cSrcweir } 723cdf0e10cSrcweir catch ( Exception& ) 724cdf0e10cSrcweir { 725cdf0e10cSrcweir } 726cdf0e10cSrcweir } 727cdf0e10cSrcweir } 728cdf0e10cSrcweir else if ( aCmd.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATIC_CMD_PART ))) < 0 ) 729cdf0e10cSrcweir { 730cdf0e10cSrcweir URL aTargetURL; 731cdf0e10cSrcweir Sequence<PropertyValue> aArgs; 732cdf0e10cSrcweir 733cdf0e10cSrcweir aTargetURL.Complete = aCmd; 734cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 735cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); 736cdf0e10cSrcweir if ( xDispatchProvider.is() ) 737cdf0e10cSrcweir { 738cdf0e10cSrcweir Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( 739cdf0e10cSrcweir aTargetURL, ::rtl::OUString(), 0 ); 740cdf0e10cSrcweir 741cdf0e10cSrcweir ExecuteInfo* pExecuteInfo = new ExecuteInfo; 742cdf0e10cSrcweir pExecuteInfo->xDispatch = xDispatch; 743cdf0e10cSrcweir pExecuteInfo->aTargetURL = aTargetURL; 744cdf0e10cSrcweir pExecuteInfo->aArgs = aArgs; 745cdf0e10cSrcweir if(::comphelper::UiEventsLogger::isEnabled()) //#i88653# 746cdf0e10cSrcweir UiEventLogHelper(::rtl::OUString::createFromAscii("ToolbarsMenuController")).log(m_xServiceManager, m_xFrame, aTargetURL, aArgs); 747cdf0e10cSrcweir Application::PostUserEvent( STATIC_LINK(0, ToolbarsMenuController, ExecuteHdl_Impl), pExecuteInfo ); 748cdf0e10cSrcweir } 749cdf0e10cSrcweir } 750cdf0e10cSrcweir else 751cdf0e10cSrcweir { 752cdf0e10cSrcweir Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( xFrame )); 753cdf0e10cSrcweir if ( xLayoutManager.is() ) 754cdf0e10cSrcweir { 755cdf0e10cSrcweir // Extract toolbar name from the combined uno-command. 756cdf0e10cSrcweir sal_Int32 nIndex = aCmd.indexOf( '=' ); 757cdf0e10cSrcweir if (( nIndex > 0 ) && (( nIndex+1 ) < aCmd.getLength() )) 758cdf0e10cSrcweir { 759cdf0e10cSrcweir rtl::OUStringBuffer aBuf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATIC_PRIVATE_TB_RESOURCE ))); 760cdf0e10cSrcweir aBuf.append( aCmd.copy( nIndex+1 )); 761cdf0e10cSrcweir 762cdf0e10cSrcweir sal_Bool bShow( !pVCLPopupMenu->IsItemChecked( rEvent.MenuId )); 763cdf0e10cSrcweir rtl::OUString aToolBarResName( aBuf.makeStringAndClear() ); 764cdf0e10cSrcweir if ( bShow ) 765cdf0e10cSrcweir { 766cdf0e10cSrcweir xLayoutManager->createElement( aToolBarResName ); 767cdf0e10cSrcweir xLayoutManager->showElement( aToolBarResName ); 768cdf0e10cSrcweir } 769cdf0e10cSrcweir else 770cdf0e10cSrcweir { 771cdf0e10cSrcweir // closing means: 772cdf0e10cSrcweir // hide and destroy element 773cdf0e10cSrcweir xLayoutManager->hideElement( aToolBarResName ); 774cdf0e10cSrcweir xLayoutManager->destroyElement( aToolBarResName ); 775cdf0e10cSrcweir } 776cdf0e10cSrcweir } 777cdf0e10cSrcweir } 778cdf0e10cSrcweir } 779cdf0e10cSrcweir } 780cdf0e10cSrcweir } 781cdf0e10cSrcweir } 782cdf0e10cSrcweir 783cdf0e10cSrcweir void SAL_CALL ToolbarsMenuController::activate( const css::awt::MenuEvent& ) throw (RuntimeException) 784cdf0e10cSrcweir { 785cdf0e10cSrcweir std::vector< rtl::OUString > aCmdVector; 786cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); 787cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer( m_xURLTransformer ); 788cdf0e10cSrcweir { 789cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 790cdf0e10cSrcweir fillPopupMenu( m_xPopupMenu ); 791cdf0e10cSrcweir aCmdVector = m_aCommandVector; 792cdf0e10cSrcweir } 793cdf0e10cSrcweir 794cdf0e10cSrcweir // Update status for all commands inside our toolbars popup menu 795cdf0e10cSrcweir const sal_uInt32 nCount = aCmdVector.size(); 796cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 797cdf0e10cSrcweir { 798cdf0e10cSrcweir bool bInternal = ( aCmdVector[i].indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATIC_INTERNAL_CMD_PART ))) == 0); 799cdf0e10cSrcweir 800cdf0e10cSrcweir if ( !bInternal ) 801cdf0e10cSrcweir { 802cdf0e10cSrcweir URL aTargetURL; 803cdf0e10cSrcweir aTargetURL.Complete = aCmdVector[i]; 804cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 805cdf0e10cSrcweir Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); 806cdf0e10cSrcweir if ( xDispatch.is() ) 807cdf0e10cSrcweir { 808cdf0e10cSrcweir xDispatch->addStatusListener( SAL_STATIC_CAST( XStatusListener*, this ), aTargetURL ); 809cdf0e10cSrcweir xDispatch->removeStatusListener( SAL_STATIC_CAST( XStatusListener*, this ), aTargetURL ); 810cdf0e10cSrcweir } 811cdf0e10cSrcweir } 812cdf0e10cSrcweir else if ( aCmdVector[i].equalsAscii( CMD_RESTOREVISIBILITY )) 813cdf0e10cSrcweir { 814cdf0e10cSrcweir // Special code to determine the enable/disable state of this command 815cdf0e10cSrcweir FeatureStateEvent aFeatureStateEvent; 816cdf0e10cSrcweir aFeatureStateEvent.FeatureURL.Complete = aCmdVector[i]; 817cdf0e10cSrcweir aFeatureStateEvent.IsEnabled = isContextSensitiveToolbarNonVisible(); 818cdf0e10cSrcweir statusChanged( aFeatureStateEvent ); 819cdf0e10cSrcweir } 820cdf0e10cSrcweir } 821cdf0e10cSrcweir } 822cdf0e10cSrcweir 823cdf0e10cSrcweir // XPopupMenuController 824cdf0e10cSrcweir void SAL_CALL ToolbarsMenuController::setPopupMenu( const Reference< css::awt::XPopupMenu >& xPopupMenu ) throw ( RuntimeException ) 825cdf0e10cSrcweir { 826cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 827cdf0e10cSrcweir 828cdf0e10cSrcweir throwIfDisposed(); 829cdf0e10cSrcweir 830cdf0e10cSrcweir if ( m_xFrame.is() && !m_xPopupMenu.is() ) 831cdf0e10cSrcweir { 832cdf0e10cSrcweir // Create popup menu on demand 833cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 834cdf0e10cSrcweir 835cdf0e10cSrcweir m_xPopupMenu = xPopupMenu; 836cdf0e10cSrcweir m_xPopupMenu->addMenuListener( Reference< css::awt::XMenuListener >( (OWeakObject*)this, UNO_QUERY )); 837cdf0e10cSrcweir fillPopupMenu( m_xPopupMenu ); 838cdf0e10cSrcweir } 839cdf0e10cSrcweir } 840cdf0e10cSrcweir 841cdf0e10cSrcweir // XInitialization 842cdf0e10cSrcweir void SAL_CALL ToolbarsMenuController::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException ) 843cdf0e10cSrcweir { 844cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 845cdf0e10cSrcweir sal_Bool bInitalized( m_bInitialized ); 846cdf0e10cSrcweir if ( !bInitalized ) 847cdf0e10cSrcweir { 848cdf0e10cSrcweir svt::PopupMenuControllerBase::initialize(aArguments); 849cdf0e10cSrcweir 850cdf0e10cSrcweir if ( m_bInitialized ) 851cdf0e10cSrcweir { 852cdf0e10cSrcweir Reference< XModuleManager > xModuleManager( m_xServiceManager->createInstance( 853cdf0e10cSrcweir SERVICENAME_MODULEMANAGER ), 854cdf0e10cSrcweir UNO_QUERY ); 855cdf0e10cSrcweir Reference< XNameAccess > xPersistentWindowStateSupplier( m_xServiceManager->createInstance( 856cdf0e10cSrcweir SERVICENAME_WINDOWSTATECONFIGURATION ), 857cdf0e10cSrcweir UNO_QUERY ); 858cdf0e10cSrcweir 859cdf0e10cSrcweir // Retrieve persistent window state reference for our module 860cdf0e10cSrcweir if ( xPersistentWindowStateSupplier.is() && xModuleManager.is() ) 861cdf0e10cSrcweir { 862cdf0e10cSrcweir rtl::OUString aModuleIdentifier; 863cdf0e10cSrcweir try 864cdf0e10cSrcweir { 865cdf0e10cSrcweir aModuleIdentifier = xModuleManager->identify( m_xFrame ); 866cdf0e10cSrcweir xPersistentWindowStateSupplier->getByName( aModuleIdentifier ) >>= m_xPersistentWindowState; 867cdf0e10cSrcweir 868cdf0e10cSrcweir Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier; 869cdf0e10cSrcweir if ( m_xServiceManager.is() ) 870cdf0e10cSrcweir xModuleCfgSupplier = Reference< XModuleUIConfigurationManagerSupplier >( 871cdf0e10cSrcweir m_xServiceManager->createInstance( SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ), UNO_QUERY ); 872cdf0e10cSrcweir m_xModuleCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier ); 873cdf0e10cSrcweir 874cdf0e10cSrcweir Reference< XController > xController = m_xFrame->getController(); 875cdf0e10cSrcweir Reference< XModel > xModel; 876cdf0e10cSrcweir if ( xController.is() ) 877cdf0e10cSrcweir xModel = xController->getModel(); 878cdf0e10cSrcweir if ( xModel.is() ) 879cdf0e10cSrcweir { 880cdf0e10cSrcweir Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY ); 881cdf0e10cSrcweir if ( xUIConfigurationManagerSupplier.is() ) 882cdf0e10cSrcweir m_xDocCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager(); 883cdf0e10cSrcweir } 884cdf0e10cSrcweir m_aModuleIdentifier = aModuleIdentifier; 885cdf0e10cSrcweir } 886cdf0e10cSrcweir catch ( Exception& ) 887cdf0e10cSrcweir { 888cdf0e10cSrcweir } 889cdf0e10cSrcweir } 890cdf0e10cSrcweir } 891cdf0e10cSrcweir } 892cdf0e10cSrcweir } 893cdf0e10cSrcweir 894cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( ToolbarsMenuController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo ) 895cdf0e10cSrcweir { 896cdf0e10cSrcweir try 897cdf0e10cSrcweir { 898cdf0e10cSrcweir // Asynchronous execution as this can lead to our own destruction! 899cdf0e10cSrcweir // Framework can recycle our current frame and the layout manager disposes all user interface 900cdf0e10cSrcweir // elements if a component gets detached from its frame! 901cdf0e10cSrcweir if ( pExecuteInfo->xDispatch.is() ) 902cdf0e10cSrcweir { 903cdf0e10cSrcweir pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs ); 904cdf0e10cSrcweir } 905cdf0e10cSrcweir } 906cdf0e10cSrcweir catch ( Exception& ) 907cdf0e10cSrcweir { 908cdf0e10cSrcweir } 909cdf0e10cSrcweir 910cdf0e10cSrcweir delete pExecuteInfo; 911cdf0e10cSrcweir return 0; 912cdf0e10cSrcweir } 913cdf0e10cSrcweir 914cdf0e10cSrcweir } 915