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 10cdf0e10cSrcweir * 116d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 1115758ad8cSAriel 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 ); 190*d026be40SAriel Constenla-Haile rPopupMenu->setCommand( nItemId, rCommandURL ); 191cdf0e10cSrcweir 192cdf0e10cSrcweir bool bInternal = ( rCommandURL.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATIC_INTERNAL_CMD_PART ))) == 0); 193cdf0e10cSrcweir if ( !bInternal ) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir if ( !getDispatchFromCommandURL( rCommandURL ).is() ) 196cdf0e10cSrcweir m_xPopupMenu->enableItem( nItemId, sal_False ); 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 200cdf0e10cSrcweir 201cdf0e10cSrcweir Image aImage; 202cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); 203cdf0e10cSrcweir 204cdf0e10cSrcweir if ( rSettings.GetUseImagesInMenus() ) 205cdf0e10cSrcweir aImage = GetImageFromURL( m_xFrame, rCommandURL, sal_False, rSettings.GetHighContrastMode() ); 206cdf0e10cSrcweir 207cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( rPopupMenu ); 208cdf0e10cSrcweir if ( pPopupMenu ) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu(); 211cdf0e10cSrcweir if ( !!aImage ) 212cdf0e10cSrcweir pVCLPopupMenu->SetItemImage( nItemId, aImage ); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir m_aCommandVector.push_back( rCommandURL ); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir Reference< XDispatch > ToolbarsMenuController::getDispatchFromCommandURL( const rtl::OUString& rCommandURL ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir URL aTargetURL; 221cdf0e10cSrcweir Sequence<PropertyValue> aArgs; 222cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer; 223cdf0e10cSrcweir Reference< XFrame > xFrame; 224cdf0e10cSrcweir 225cdf0e10cSrcweir { 226cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 227cdf0e10cSrcweir xURLTransformer = m_xURLTransformer; 228cdf0e10cSrcweir xFrame = m_xFrame; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir aTargetURL.Complete = rCommandURL; 232cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 233cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( xFrame, UNO_QUERY ); 234cdf0e10cSrcweir if ( xDispatchProvider.is() ) 235cdf0e10cSrcweir return xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); 236cdf0e10cSrcweir else 237cdf0e10cSrcweir return Reference< XDispatch >(); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir // private function 241cdf0e10cSrcweir rtl::OUString ToolbarsMenuController::getUINameFromCommand( const rtl::OUString& rCommandURL ) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir rtl::OUString aLabel; 244cdf0e10cSrcweir 245cdf0e10cSrcweir if ( !m_bModuleIdentified ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir try 248cdf0e10cSrcweir { 249cdf0e10cSrcweir Reference< XModuleManager > xModuleManager( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW ); 250cdf0e10cSrcweir m_aModuleIdentifier = xModuleManager->identify( m_xFrame ); 251cdf0e10cSrcweir Reference< XNameAccess > xNameAccess( m_xServiceManager->createInstance( 252cdf0e10cSrcweir SERVICENAME_UICOMMANDDESCRIPTION ), 253cdf0e10cSrcweir UNO_QUERY ); 254cdf0e10cSrcweir xNameAccess->getByName( m_aModuleIdentifier ) >>= m_xUICommandDescription; 255cdf0e10cSrcweir } 256cdf0e10cSrcweir catch ( Exception& ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir } 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir if ( m_xUICommandDescription.is() ) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir try 264cdf0e10cSrcweir { 265cdf0e10cSrcweir Sequence< PropertyValue > aPropSeq; 266cdf0e10cSrcweir rtl::OUString aStr; 267cdf0e10cSrcweir if ( m_xUICommandDescription->getByName( rCommandURL ) >>= aPropSeq ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir if ( aPropSeq[i].Name.equalsAscii( "Label" )) 272cdf0e10cSrcweir { 273cdf0e10cSrcweir aPropSeq[i].Value >>= aStr; 274cdf0e10cSrcweir break; 275cdf0e10cSrcweir } 276cdf0e10cSrcweir } 277cdf0e10cSrcweir } 278cdf0e10cSrcweir aLabel = aStr; 279cdf0e10cSrcweir } 280cdf0e10cSrcweir catch ( Exception& ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir } 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir return aLabel; 286cdf0e10cSrcweir } 287cdf0e10cSrcweir 288cdf0e10cSrcweir static void fillHashMap( const Sequence< Sequence< ::com::sun::star::beans::PropertyValue > >& rSeqToolBars, 289cdf0e10cSrcweir ToolbarHashMap& rHashMap ) 290cdf0e10cSrcweir { 291cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rSeqToolBars.getLength(); i++ ) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir rtl::OUString aResourceURL; 294cdf0e10cSrcweir rtl::OUString aUIName; 295cdf0e10cSrcweir const PropertyValue* pProperties = rSeqToolBars[i].getConstArray(); 296cdf0e10cSrcweir for ( sal_Int32 j = 0; j < rSeqToolBars[i].getLength(); j++ ) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir if ( pProperties[j].Name.equalsAscii( ITEM_DESCRIPTOR_RESOURCEURL) ) 299cdf0e10cSrcweir pProperties[j].Value >>= aResourceURL; 300cdf0e10cSrcweir else if ( pProperties[j].Name.equalsAscii( ITEM_DESCRIPTOR_UINAME) ) 301cdf0e10cSrcweir pProperties[j].Value >>= aUIName; 302cdf0e10cSrcweir } 303cdf0e10cSrcweir 304cdf0e10cSrcweir if ( aResourceURL.getLength() > 0 && 305cdf0e10cSrcweir rHashMap.find( aResourceURL ) == rHashMap.end() ) 306cdf0e10cSrcweir rHashMap.insert( ToolbarHashMap::value_type( aResourceURL, aUIName )); 307cdf0e10cSrcweir } 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir // private function 311cdf0e10cSrcweir Sequence< Sequence< com::sun::star::beans::PropertyValue > > ToolbarsMenuController::getLayoutManagerToolbars( const Reference< ::com::sun::star::frame::XLayoutManager >& rLayoutManager ) 312cdf0e10cSrcweir { 313cdf0e10cSrcweir std::vector< ToolBarInfo > aToolBarArray; 314cdf0e10cSrcweir Sequence< Reference< XUIElement > > aUIElements = rLayoutManager->getElements(); 315cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aUIElements.getLength(); i++ ) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir Reference< XUIElement > xUIElement( aUIElements[i] ); 318cdf0e10cSrcweir Reference< XPropertySet > xPropSet( aUIElements[i], UNO_QUERY ); 319cdf0e10cSrcweir if ( xPropSet.is() && xUIElement.is() ) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir try 322cdf0e10cSrcweir { 323cdf0e10cSrcweir rtl::OUString aResName; 324cdf0e10cSrcweir sal_Int16 nType( -1 ); 325cdf0e10cSrcweir xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ))) >>= nType; 326cdf0e10cSrcweir xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ))) >>= aResName; 327cdf0e10cSrcweir 328cdf0e10cSrcweir if (( nType == ::com::sun::star::ui::UIElementType::TOOLBAR ) && 329cdf0e10cSrcweir ( aResName.getLength() > 0 )) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir ToolBarInfo aToolBarInfo; 332cdf0e10cSrcweir 333cdf0e10cSrcweir aToolBarInfo.aToolBarResName = aResName; 334cdf0e10cSrcweir 335cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 336cdf0e10cSrcweir Reference< css::awt::XWindow > xWindow( xUIElement->getRealInterface(), UNO_QUERY ); 337cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 338cdf0e10cSrcweir if ( pWindow ) 339cdf0e10cSrcweir aToolBarInfo.aToolBarUIName = pWindow->GetText(); 340cdf0e10cSrcweir 341cdf0e10cSrcweir aToolBarArray.push_back( aToolBarInfo ); 342cdf0e10cSrcweir } 343cdf0e10cSrcweir } 344cdf0e10cSrcweir catch ( Exception& ) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir } 347cdf0e10cSrcweir } 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir Sequence< com::sun::star::beans::PropertyValue > aTbSeq( 2 ); 351cdf0e10cSrcweir aTbSeq[0].Name = m_aPropUIName; 352cdf0e10cSrcweir aTbSeq[1].Name = m_aPropResourceURL; 353cdf0e10cSrcweir 354cdf0e10cSrcweir Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeq( aToolBarArray.size() ); 355cdf0e10cSrcweir const sal_uInt32 nCount = aToolBarArray.size(); 356cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir aTbSeq[0].Value <<= aToolBarArray[i].aToolBarUIName; 359cdf0e10cSrcweir aTbSeq[1].Value <<= aToolBarArray[i].aToolBarResName; 360cdf0e10cSrcweir aSeq[i] = aTbSeq; 361cdf0e10cSrcweir } 362cdf0e10cSrcweir 363cdf0e10cSrcweir return aSeq; 364cdf0e10cSrcweir } 365cdf0e10cSrcweir 366cdf0e10cSrcweir sal_Bool ToolbarsMenuController::isContextSensitiveToolbarNonVisible() 367cdf0e10cSrcweir { 368cdf0e10cSrcweir return m_bResetActive; 369cdf0e10cSrcweir } 370cdf0e10cSrcweir 371cdf0e10cSrcweir void ToolbarsMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu ) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 374cdf0e10cSrcweir resetPopupMenu( rPopupMenu ); 375cdf0e10cSrcweir 376cdf0e10cSrcweir m_aCommandVector.clear(); 377cdf0e10cSrcweir 378cdf0e10cSrcweir // Retrieve layout manager for additional information 379cdf0e10cSrcweir rtl::OUString aEmptyString; 380cdf0e10cSrcweir Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( m_xFrame )); 381cdf0e10cSrcweir 382cdf0e10cSrcweir m_bResetActive = sal_False; 383cdf0e10cSrcweir if ( xLayoutManager.is() ) 384cdf0e10cSrcweir { 385cdf0e10cSrcweir ToolbarHashMap aToolbarHashMap; 386cdf0e10cSrcweir 387cdf0e10cSrcweir if ( m_xDocCfgMgr.is() ) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeqDocToolBars = 390cdf0e10cSrcweir m_xDocCfgMgr->getUIElementsInfo( UIElementType::TOOLBAR ); 391cdf0e10cSrcweir fillHashMap( aSeqDocToolBars, aToolbarHashMap ); 392cdf0e10cSrcweir } 393cdf0e10cSrcweir 394cdf0e10cSrcweir if ( m_xModuleCfgMgr.is() ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeqToolBars = 397cdf0e10cSrcweir m_xModuleCfgMgr->getUIElementsInfo( UIElementType::TOOLBAR ); 398cdf0e10cSrcweir fillHashMap( aSeqToolBars, aToolbarHashMap ); 399cdf0e10cSrcweir } 400cdf0e10cSrcweir 401cdf0e10cSrcweir std::vector< ToolBarEntry > aSortedTbs; 402cdf0e10cSrcweir rtl::OUString aStaticCmdPart( RTL_CONSTASCII_USTRINGPARAM( STATIC_CMD_PART )); 403cdf0e10cSrcweir 404cdf0e10cSrcweir Sequence< Sequence< com::sun::star::beans::PropertyValue > > aSeqFrameToolBars = getLayoutManagerToolbars( xLayoutManager ); 405cdf0e10cSrcweir fillHashMap( aSeqFrameToolBars, aToolbarHashMap ); 406cdf0e10cSrcweir 407cdf0e10cSrcweir ToolbarHashMap::const_iterator pIter = aToolbarHashMap.begin(); 408cdf0e10cSrcweir while ( pIter != aToolbarHashMap.end() ) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir rtl::OUString aUIName = pIter->second; 411cdf0e10cSrcweir sal_Bool bHideFromMenu( sal_False ); 412cdf0e10cSrcweir sal_Bool bContextSensitive( sal_False ); 413cdf0e10cSrcweir sal_Bool bVisible( sal_False ); 414cdf0e10cSrcweir if ( aUIName.getLength() == 0 && 415cdf0e10cSrcweir m_xPersistentWindowState.is() ) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir try 418cdf0e10cSrcweir { 419cdf0e10cSrcweir Sequence< PropertyValue > aWindowState; 420cdf0e10cSrcweir Any a( m_xPersistentWindowState->getByName( pIter->first )); 421cdf0e10cSrcweir 422cdf0e10cSrcweir if ( a >>= aWindowState ) 423cdf0e10cSrcweir { 424cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aWindowState.getLength(); i++ ) 425cdf0e10cSrcweir { 426cdf0e10cSrcweir if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_UINAME )) 427cdf0e10cSrcweir aWindowState[i].Value >>= aUIName; 428cdf0e10cSrcweir else if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_HIDEFROMENU )) 429cdf0e10cSrcweir aWindowState[i].Value >>= bHideFromMenu; 430cdf0e10cSrcweir else if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXT )) 431cdf0e10cSrcweir aWindowState[i].Value >>= bContextSensitive; 432cdf0e10cSrcweir else if ( aWindowState[i].Name.equalsAscii( WINDOWSTATE_PROPERTY_VISIBLE )) 433cdf0e10cSrcweir aWindowState[i].Value >>= bVisible; 434cdf0e10cSrcweir } 435cdf0e10cSrcweir } 436cdf0e10cSrcweir } 437cdf0e10cSrcweir catch ( Exception& ) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir } 440cdf0e10cSrcweir 441cdf0e10cSrcweir // Check if we have to enable/disable "Reset" menu item 442cdf0e10cSrcweir if ( bContextSensitive && !bVisible ) 443cdf0e10cSrcweir m_bResetActive = sal_True; 444cdf0e10cSrcweir 445cdf0e10cSrcweir } 446cdf0e10cSrcweir 447cdf0e10cSrcweir if (( aUIName.getLength() > 0 ) && ( !bHideFromMenu )) 448cdf0e10cSrcweir { 449cdf0e10cSrcweir ToolBarEntry aTbEntry; 450cdf0e10cSrcweir aTbEntry.aUIName = aUIName; 451cdf0e10cSrcweir aTbEntry.aCommand = pIter->first; 452cdf0e10cSrcweir aTbEntry.bVisible = xLayoutManager->isElementVisible( pIter->first ); 453cdf0e10cSrcweir aTbEntry.bContextSensitive = bContextSensitive; 454cdf0e10cSrcweir aTbEntry.pCollatorWrapper = m_aIntlWrapper.getCaseCollator(); 455cdf0e10cSrcweir aSortedTbs.push_back( aTbEntry ); 456cdf0e10cSrcweir } 457cdf0e10cSrcweir pIter++; 458cdf0e10cSrcweir } 459cdf0e10cSrcweir 460cdf0e10cSrcweir // sort toolbars 461cdf0e10cSrcweir std::sort( aSortedTbs.begin(), aSortedTbs.end(), CompareToolBarEntry ); 462cdf0e10cSrcweir 463cdf0e10cSrcweir sal_Int16 nIndex( 1 ); 464cdf0e10cSrcweir const sal_uInt32 nCount = aSortedTbs.size(); 465cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir sal_uInt16 nItemCount = m_xPopupMenu->getItemCount(); 468cdf0e10cSrcweir m_xPopupMenu->insertItem( nIndex, aSortedTbs[i].aUIName, css::awt::MenuItemStyle::CHECKABLE, nItemCount ); 469cdf0e10cSrcweir if ( aSortedTbs[i].bVisible ) 470cdf0e10cSrcweir m_xPopupMenu->checkItem( nIndex, sal_True ); 471cdf0e10cSrcweir 472cdf0e10cSrcweir { 473cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 474cdf0e10cSrcweir VCLXPopupMenu* pXPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( m_xPopupMenu ); 475cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = (PopupMenu *)pXPopupMenu->GetMenu(); 476cdf0e10cSrcweir 477cdf0e10cSrcweir pVCLPopupMenu->SetUserValue( nIndex, sal_uIntPtr( aSortedTbs[i].bContextSensitive ? 1L : 0L )); 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir // use VCL popup menu pointer to set vital information that are not part of the awt implementation 481cdf0e10cSrcweir rtl::OUStringBuffer aStrBuf( aStaticCmdPart ); 482cdf0e10cSrcweir 483cdf0e10cSrcweir sal_Int32 n = aSortedTbs[i].aCommand.lastIndexOf( '/' ); 484cdf0e10cSrcweir if (( n > 0 ) && (( n+1 ) < aSortedTbs[i].aCommand.getLength() )) 485cdf0e10cSrcweir aStrBuf.append( aSortedTbs[i].aCommand.copy( n+1 )); 486cdf0e10cSrcweir 487cdf0e10cSrcweir rtl::OUString aCmd( aStrBuf.makeStringAndClear() ); 488cdf0e10cSrcweir 489cdf0e10cSrcweir // Store complete uno-command so it can also be dispatched. This is necessary to support 490cdf0e10cSrcweir // the test tool! 491*d026be40SAriel Constenla-Haile rPopupMenu->setCommand( nIndex, aCmd ); 492cdf0e10cSrcweir ++nIndex; 493cdf0e10cSrcweir } 494cdf0e10cSrcweir 495cdf0e10cSrcweir // Create commands for non-toolbars 496cdf0e10cSrcweir if ( m_aModuleIdentifier.equalsAscii( "com.sun.star.text.TextDocument" ) || 497cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.text.WebDocument" ) || 498cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.text.GlobalDocument" ) || 499cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.drawing.DrawingDocument" ) || 500cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.presentation.PresentationDocument" ) || 501cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" )) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir addCommand( m_xPopupMenu, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CMD_HYPERLINKBAR )), aEmptyString ); 504cdf0e10cSrcweir if ( m_aModuleIdentifier.equalsAscii( "com.sun.star.drawing.DrawingDocument" ) || 505cdf0e10cSrcweir m_aModuleIdentifier.equalsAscii( "com.sun.star.presentation.PresentationDocument" )) 506cdf0e10cSrcweir addCommand( m_xPopupMenu, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CMD_COLORBAR )), aEmptyString ); 507cdf0e10cSrcweir else if ( m_aModuleIdentifier.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" )) 508cdf0e10cSrcweir addCommand( m_xPopupMenu, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CMD_INPUTLINEBAR )), aEmptyString ); 509cdf0e10cSrcweir else 510cdf0e10cSrcweir addCommand( m_xPopupMenu, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CMD_FORMULABAR )), aEmptyString ); 511cdf0e10cSrcweir } 512cdf0e10cSrcweir 513cdf0e10cSrcweir sal_Bool bAddCommand( sal_True ); 514cdf0e10cSrcweir SvtCommandOptions aCmdOptions; 515cdf0e10cSrcweir rtl::OUString aConfigureToolbar( RTL_CONSTASCII_USTRINGPARAM( CONFIGURE_TOOLBARS )); 516cdf0e10cSrcweir 517cdf0e10cSrcweir if ( aCmdOptions.HasEntries( SvtCommandOptions::CMDOPTION_DISABLED )) 518cdf0e10cSrcweir { 519cdf0e10cSrcweir if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, 520cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONFIGURE_TOOLBARS_CMD )))) 521cdf0e10cSrcweir bAddCommand = sal_False; 522cdf0e10cSrcweir } 523cdf0e10cSrcweir 524cdf0e10cSrcweir if ( bAddCommand ) 525cdf0e10cSrcweir { 526cdf0e10cSrcweir // Create command for configure 527cdf0e10cSrcweir if ( m_xPopupMenu->getItemCount() > 0 ) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir sal_uInt16 nItemCount = m_xPopupMenu->getItemCount(); 530cdf0e10cSrcweir m_xPopupMenu->insertSeparator( nItemCount+1 ); 531cdf0e10cSrcweir } 532cdf0e10cSrcweir 533cdf0e10cSrcweir addCommand( m_xPopupMenu, aConfigureToolbar, aEmptyString ); 534cdf0e10cSrcweir } 535cdf0e10cSrcweir 536cdf0e10cSrcweir // Add separator if no configure has been added 537cdf0e10cSrcweir if ( !bAddCommand ) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir // Create command for configure 540cdf0e10cSrcweir if ( m_xPopupMenu->getItemCount() > 0 ) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir sal_uInt16 nItemCount = m_xPopupMenu->getItemCount(); 543cdf0e10cSrcweir m_xPopupMenu->insertSeparator( nItemCount+1 ); 544cdf0e10cSrcweir } 545cdf0e10cSrcweir } 546cdf0e10cSrcweir 547cdf0e10cSrcweir String aLabelStr = String( FwkResId( STR_RESTORE_TOOLBARS )); 548cdf0e10cSrcweir rtl::OUString aRestoreCmd( RTL_CONSTASCII_USTRINGPARAM( CMD_RESTOREVISIBILITY )); 549cdf0e10cSrcweir addCommand( m_xPopupMenu, aRestoreCmd, aLabelStr ); 550cdf0e10cSrcweir } 551cdf0e10cSrcweir } 552cdf0e10cSrcweir 553cdf0e10cSrcweir // XEventListener 554cdf0e10cSrcweir void SAL_CALL ToolbarsMenuController::disposing( const EventObject& ) throw ( RuntimeException ) 555cdf0e10cSrcweir { 556cdf0e10cSrcweir Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY ); 557cdf0e10cSrcweir 558cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 559cdf0e10cSrcweir m_xFrame.clear(); 560cdf0e10cSrcweir m_xDispatch.clear(); 561cdf0e10cSrcweir m_xDocCfgMgr.clear(); 562cdf0e10cSrcweir m_xModuleCfgMgr.clear(); 563cdf0e10cSrcweir m_xServiceManager.clear(); 564cdf0e10cSrcweir 565cdf0e10cSrcweir if ( m_xPopupMenu.is() ) 566cdf0e10cSrcweir m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY )); 567cdf0e10cSrcweir m_xPopupMenu.clear(); 568cdf0e10cSrcweir } 569cdf0e10cSrcweir 570cdf0e10cSrcweir // XStatusListener 571cdf0e10cSrcweir void SAL_CALL ToolbarsMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException ) 572cdf0e10cSrcweir { 573cdf0e10cSrcweir rtl::OUString aFeatureURL( Event.FeatureURL.Complete ); 574cdf0e10cSrcweir 575cdf0e10cSrcweir // All other status events will be processed here 576cdf0e10cSrcweir sal_Bool bSetCheckmark = sal_False; 577cdf0e10cSrcweir sal_Bool bCheckmark = sal_False; 578cdf0e10cSrcweir 579cdf0e10cSrcweir osl::ClearableMutexGuard aLock( m_aMutex ); 580cdf0e10cSrcweir Reference< css::awt::XPopupMenu > xPopupMenu( m_xPopupMenu ); 581cdf0e10cSrcweir aLock.clear(); 582cdf0e10cSrcweir 583cdf0e10cSrcweir if ( xPopupMenu.is() ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 586cdf0e10cSrcweir VCLXPopupMenu* pXPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( xPopupMenu ); 587cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = (PopupMenu *)pXPopupMenu->GetMenu(); 588cdf0e10cSrcweir 589cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < pVCLPopupMenu->GetItemCount(); i++ ) 590cdf0e10cSrcweir { 591cdf0e10cSrcweir sal_uInt16 nId = pVCLPopupMenu->GetItemId( i ); 592cdf0e10cSrcweir if ( nId == 0 ) 593cdf0e10cSrcweir continue; 594cdf0e10cSrcweir 595cdf0e10cSrcweir rtl::OUString aCmd = pVCLPopupMenu->GetItemCommand( nId ); 596cdf0e10cSrcweir if ( aCmd == aFeatureURL ) 597cdf0e10cSrcweir { 598cdf0e10cSrcweir // Enable/disable item 599cdf0e10cSrcweir pVCLPopupMenu->EnableItem( nId, Event.IsEnabled ); 600cdf0e10cSrcweir 601cdf0e10cSrcweir // Checkmark 602cdf0e10cSrcweir if ( Event.State >>= bCheckmark ) 603cdf0e10cSrcweir bSetCheckmark = sal_True; 604cdf0e10cSrcweir 605cdf0e10cSrcweir if ( bSetCheckmark ) 606cdf0e10cSrcweir pVCLPopupMenu->CheckItem( nId, bCheckmark ); 607cdf0e10cSrcweir else 608cdf0e10cSrcweir { 609cdf0e10cSrcweir rtl::OUString aItemText; 610cdf0e10cSrcweir 611cdf0e10cSrcweir if ( Event.State >>= aItemText ) 612cdf0e10cSrcweir pVCLPopupMenu->SetItemText( nId, aItemText ); 613cdf0e10cSrcweir } 614cdf0e10cSrcweir } 615cdf0e10cSrcweir } 616cdf0e10cSrcweir } 617cdf0e10cSrcweir } 618cdf0e10cSrcweir 619cdf0e10cSrcweir // XMenuListener 620*d026be40SAriel Constenla-Haile void SAL_CALL ToolbarsMenuController::itemSelected( const css::awt::MenuEvent& rEvent ) throw (RuntimeException) 621cdf0e10cSrcweir { 622cdf0e10cSrcweir Reference< css::awt::XPopupMenu > xPopupMenu; 623cdf0e10cSrcweir Reference< XMultiServiceFactory > xServiceManager; 624cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer; 625cdf0e10cSrcweir Reference< XFrame > xFrame; 626cdf0e10cSrcweir Reference< XNameAccess > xPersistentWindowState; 627cdf0e10cSrcweir 628cdf0e10cSrcweir osl::ClearableMutexGuard aLock( m_aMutex ); 629cdf0e10cSrcweir xPopupMenu = m_xPopupMenu; 630cdf0e10cSrcweir xServiceManager = m_xServiceManager; 631cdf0e10cSrcweir xURLTransformer = m_xURLTransformer; 632cdf0e10cSrcweir xFrame = m_xFrame; 633cdf0e10cSrcweir xPersistentWindowState = m_xPersistentWindowState; 634cdf0e10cSrcweir aLock.clear(); 635cdf0e10cSrcweir 636cdf0e10cSrcweir if ( xPopupMenu.is() ) 637cdf0e10cSrcweir { 638cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( xPopupMenu ); 639cdf0e10cSrcweir if ( pPopupMenu ) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 642cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu(); 643cdf0e10cSrcweir 644cdf0e10cSrcweir rtl::OUString aCmd( pVCLPopupMenu->GetItemCommand( rEvent.MenuId )); 645cdf0e10cSrcweir if ( aCmd.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATIC_INTERNAL_CMD_PART ))) == 0 ) 646cdf0e10cSrcweir { 647cdf0e10cSrcweir // Command to restore the visibility of all context sensitive toolbars 648cdf0e10cSrcweir Reference< XNameReplace > xNameReplace( xPersistentWindowState, UNO_QUERY ); 649cdf0e10cSrcweir if ( xPersistentWindowState.is() && xNameReplace.is() ) 650cdf0e10cSrcweir { 651cdf0e10cSrcweir try 652cdf0e10cSrcweir { 653cdf0e10cSrcweir Sequence< rtl::OUString > aElementNames = xPersistentWindowState->getElementNames(); 654cdf0e10cSrcweir sal_Int32 nCount = aElementNames.getLength(); 655cdf0e10cSrcweir bool bRefreshToolbars( false ); 656cdf0e10cSrcweir 657cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; i++ ) 658cdf0e10cSrcweir { 659cdf0e10cSrcweir try 660cdf0e10cSrcweir { 661cdf0e10cSrcweir rtl::OUString aElementName = aElementNames[i]; 662cdf0e10cSrcweir Sequence< PropertyValue > aWindowState; 663cdf0e10cSrcweir 664cdf0e10cSrcweir if ( xPersistentWindowState->getByName( aElementName ) >>= aWindowState ) 665cdf0e10cSrcweir { 666cdf0e10cSrcweir sal_Bool bVisible( sal_False ); 667cdf0e10cSrcweir sal_Bool bContextSensitive( sal_False ); 668cdf0e10cSrcweir sal_Int32 nVisibleIndex( -1 ); 669cdf0e10cSrcweir for ( sal_Int32 j = 0; j < aWindowState.getLength(); j++ ) 670cdf0e10cSrcweir { 671cdf0e10cSrcweir if ( aWindowState[j].Name.equalsAscii( WINDOWSTATE_PROPERTY_VISIBLE )) 672cdf0e10cSrcweir { 673cdf0e10cSrcweir aWindowState[j].Value >>= bVisible; 674cdf0e10cSrcweir nVisibleIndex = j; 675cdf0e10cSrcweir } 676cdf0e10cSrcweir else if ( aWindowState[j].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXT )) 677cdf0e10cSrcweir aWindowState[j].Value >>= bContextSensitive; 678cdf0e10cSrcweir } 679cdf0e10cSrcweir 680cdf0e10cSrcweir if ( !bVisible && bContextSensitive && nVisibleIndex >= 0 ) 681cdf0e10cSrcweir { 682cdf0e10cSrcweir // Default is: Every context sensitive toolbar is visible 683cdf0e10cSrcweir aWindowState[nVisibleIndex].Value <<= sal_True; 684cdf0e10cSrcweir xNameReplace->replaceByName( aElementName, makeAny( aWindowState )); 685cdf0e10cSrcweir bRefreshToolbars = true; 686cdf0e10cSrcweir } 687cdf0e10cSrcweir } 688cdf0e10cSrcweir } 689cdf0e10cSrcweir catch ( NoSuchElementException& ) 690cdf0e10cSrcweir { 691cdf0e10cSrcweir } 692cdf0e10cSrcweir } 693cdf0e10cSrcweir 694cdf0e10cSrcweir if ( bRefreshToolbars ) 695cdf0e10cSrcweir { 696cdf0e10cSrcweir Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( xFrame )); 697cdf0e10cSrcweir if ( xLayoutManager.is() ) 698cdf0e10cSrcweir { 699cdf0e10cSrcweir Reference< XPropertySet > xPropSet( xLayoutManager, UNO_QUERY ); 700cdf0e10cSrcweir if ( xPropSet.is() ) 701cdf0e10cSrcweir { 702cdf0e10cSrcweir try 703cdf0e10cSrcweir { 704cdf0e10cSrcweir xPropSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RefreshContextToolbarVisibility" )), makeAny( sal_True )); 705cdf0e10cSrcweir } 706cdf0e10cSrcweir catch ( RuntimeException& ) 707cdf0e10cSrcweir { 708cdf0e10cSrcweir } 709cdf0e10cSrcweir catch ( Exception& ) 710cdf0e10cSrcweir { 711cdf0e10cSrcweir } 712cdf0e10cSrcweir } 713cdf0e10cSrcweir } 714cdf0e10cSrcweir RefreshToolbars( xFrame ); 715cdf0e10cSrcweir } 716cdf0e10cSrcweir } 717cdf0e10cSrcweir catch ( RuntimeException& ) 718cdf0e10cSrcweir { 719cdf0e10cSrcweir throw; 720cdf0e10cSrcweir } 721cdf0e10cSrcweir catch ( Exception& ) 722cdf0e10cSrcweir { 723cdf0e10cSrcweir } 724cdf0e10cSrcweir } 725cdf0e10cSrcweir } 726cdf0e10cSrcweir else if ( aCmd.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATIC_CMD_PART ))) < 0 ) 727cdf0e10cSrcweir { 728cdf0e10cSrcweir URL aTargetURL; 729cdf0e10cSrcweir Sequence<PropertyValue> aArgs; 730cdf0e10cSrcweir 731cdf0e10cSrcweir aTargetURL.Complete = aCmd; 732cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 733cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); 734cdf0e10cSrcweir if ( xDispatchProvider.is() ) 735cdf0e10cSrcweir { 736cdf0e10cSrcweir Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( 737cdf0e10cSrcweir aTargetURL, ::rtl::OUString(), 0 ); 738cdf0e10cSrcweir 739cdf0e10cSrcweir ExecuteInfo* pExecuteInfo = new ExecuteInfo; 740cdf0e10cSrcweir pExecuteInfo->xDispatch = xDispatch; 741cdf0e10cSrcweir pExecuteInfo->aTargetURL = aTargetURL; 742cdf0e10cSrcweir pExecuteInfo->aArgs = aArgs; 743cdf0e10cSrcweir if(::comphelper::UiEventsLogger::isEnabled()) //#i88653# 744cdf0e10cSrcweir UiEventLogHelper(::rtl::OUString::createFromAscii("ToolbarsMenuController")).log(m_xServiceManager, m_xFrame, aTargetURL, aArgs); 745cdf0e10cSrcweir Application::PostUserEvent( STATIC_LINK(0, ToolbarsMenuController, ExecuteHdl_Impl), pExecuteInfo ); 746cdf0e10cSrcweir } 747cdf0e10cSrcweir } 748cdf0e10cSrcweir else 749cdf0e10cSrcweir { 750cdf0e10cSrcweir Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( xFrame )); 751cdf0e10cSrcweir if ( xLayoutManager.is() ) 752cdf0e10cSrcweir { 753cdf0e10cSrcweir // Extract toolbar name from the combined uno-command. 754cdf0e10cSrcweir sal_Int32 nIndex = aCmd.indexOf( '=' ); 755cdf0e10cSrcweir if (( nIndex > 0 ) && (( nIndex+1 ) < aCmd.getLength() )) 756cdf0e10cSrcweir { 757cdf0e10cSrcweir rtl::OUStringBuffer aBuf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATIC_PRIVATE_TB_RESOURCE ))); 758cdf0e10cSrcweir aBuf.append( aCmd.copy( nIndex+1 )); 759cdf0e10cSrcweir 760cdf0e10cSrcweir sal_Bool bShow( !pVCLPopupMenu->IsItemChecked( rEvent.MenuId )); 761cdf0e10cSrcweir rtl::OUString aToolBarResName( aBuf.makeStringAndClear() ); 762cdf0e10cSrcweir if ( bShow ) 763cdf0e10cSrcweir { 764cdf0e10cSrcweir xLayoutManager->createElement( aToolBarResName ); 765cdf0e10cSrcweir xLayoutManager->showElement( aToolBarResName ); 766cdf0e10cSrcweir } 767cdf0e10cSrcweir else 768cdf0e10cSrcweir { 769cdf0e10cSrcweir // closing means: 770cdf0e10cSrcweir // hide and destroy element 771cdf0e10cSrcweir xLayoutManager->hideElement( aToolBarResName ); 772cdf0e10cSrcweir xLayoutManager->destroyElement( aToolBarResName ); 773cdf0e10cSrcweir } 774cdf0e10cSrcweir } 775cdf0e10cSrcweir } 776cdf0e10cSrcweir } 777cdf0e10cSrcweir } 778cdf0e10cSrcweir } 779cdf0e10cSrcweir } 780cdf0e10cSrcweir 781*d026be40SAriel Constenla-Haile void SAL_CALL ToolbarsMenuController::itemActivated( const css::awt::MenuEvent& ) throw (RuntimeException) 782cdf0e10cSrcweir { 783cdf0e10cSrcweir std::vector< rtl::OUString > aCmdVector; 784cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); 785cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer( m_xURLTransformer ); 786cdf0e10cSrcweir { 787cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 788cdf0e10cSrcweir fillPopupMenu( m_xPopupMenu ); 789cdf0e10cSrcweir aCmdVector = m_aCommandVector; 790cdf0e10cSrcweir } 791cdf0e10cSrcweir 792cdf0e10cSrcweir // Update status for all commands inside our toolbars popup menu 793cdf0e10cSrcweir const sal_uInt32 nCount = aCmdVector.size(); 794cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 795cdf0e10cSrcweir { 796cdf0e10cSrcweir bool bInternal = ( aCmdVector[i].indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATIC_INTERNAL_CMD_PART ))) == 0); 797cdf0e10cSrcweir 798cdf0e10cSrcweir if ( !bInternal ) 799cdf0e10cSrcweir { 800cdf0e10cSrcweir URL aTargetURL; 801cdf0e10cSrcweir aTargetURL.Complete = aCmdVector[i]; 802cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 803cdf0e10cSrcweir Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); 804cdf0e10cSrcweir if ( xDispatch.is() ) 805cdf0e10cSrcweir { 806cdf0e10cSrcweir xDispatch->addStatusListener( SAL_STATIC_CAST( XStatusListener*, this ), aTargetURL ); 807cdf0e10cSrcweir xDispatch->removeStatusListener( SAL_STATIC_CAST( XStatusListener*, this ), aTargetURL ); 808cdf0e10cSrcweir } 809cdf0e10cSrcweir } 810cdf0e10cSrcweir else if ( aCmdVector[i].equalsAscii( CMD_RESTOREVISIBILITY )) 811cdf0e10cSrcweir { 812cdf0e10cSrcweir // Special code to determine the enable/disable state of this command 813cdf0e10cSrcweir FeatureStateEvent aFeatureStateEvent; 814cdf0e10cSrcweir aFeatureStateEvent.FeatureURL.Complete = aCmdVector[i]; 815cdf0e10cSrcweir aFeatureStateEvent.IsEnabled = isContextSensitiveToolbarNonVisible(); 816cdf0e10cSrcweir statusChanged( aFeatureStateEvent ); 817cdf0e10cSrcweir } 818cdf0e10cSrcweir } 819cdf0e10cSrcweir } 820cdf0e10cSrcweir 821cdf0e10cSrcweir // XPopupMenuController 822cdf0e10cSrcweir void SAL_CALL ToolbarsMenuController::setPopupMenu( const Reference< css::awt::XPopupMenu >& xPopupMenu ) throw ( RuntimeException ) 823cdf0e10cSrcweir { 824cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 825cdf0e10cSrcweir 826cdf0e10cSrcweir throwIfDisposed(); 827cdf0e10cSrcweir 828cdf0e10cSrcweir if ( m_xFrame.is() && !m_xPopupMenu.is() ) 829cdf0e10cSrcweir { 830cdf0e10cSrcweir // Create popup menu on demand 831cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 832cdf0e10cSrcweir 833cdf0e10cSrcweir m_xPopupMenu = xPopupMenu; 834cdf0e10cSrcweir m_xPopupMenu->addMenuListener( Reference< css::awt::XMenuListener >( (OWeakObject*)this, UNO_QUERY )); 835cdf0e10cSrcweir fillPopupMenu( m_xPopupMenu ); 836cdf0e10cSrcweir } 837cdf0e10cSrcweir } 838cdf0e10cSrcweir 839cdf0e10cSrcweir // XInitialization 840cdf0e10cSrcweir void SAL_CALL ToolbarsMenuController::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException ) 841cdf0e10cSrcweir { 842cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 843cdf0e10cSrcweir sal_Bool bInitalized( m_bInitialized ); 844cdf0e10cSrcweir if ( !bInitalized ) 845cdf0e10cSrcweir { 846cdf0e10cSrcweir svt::PopupMenuControllerBase::initialize(aArguments); 847cdf0e10cSrcweir 848cdf0e10cSrcweir if ( m_bInitialized ) 849cdf0e10cSrcweir { 850cdf0e10cSrcweir Reference< XModuleManager > xModuleManager( m_xServiceManager->createInstance( 851cdf0e10cSrcweir SERVICENAME_MODULEMANAGER ), 852cdf0e10cSrcweir UNO_QUERY ); 853cdf0e10cSrcweir Reference< XNameAccess > xPersistentWindowStateSupplier( m_xServiceManager->createInstance( 854cdf0e10cSrcweir SERVICENAME_WINDOWSTATECONFIGURATION ), 855cdf0e10cSrcweir UNO_QUERY ); 856cdf0e10cSrcweir 857cdf0e10cSrcweir // Retrieve persistent window state reference for our module 858cdf0e10cSrcweir if ( xPersistentWindowStateSupplier.is() && xModuleManager.is() ) 859cdf0e10cSrcweir { 860cdf0e10cSrcweir rtl::OUString aModuleIdentifier; 861cdf0e10cSrcweir try 862cdf0e10cSrcweir { 863cdf0e10cSrcweir aModuleIdentifier = xModuleManager->identify( m_xFrame ); 864cdf0e10cSrcweir xPersistentWindowStateSupplier->getByName( aModuleIdentifier ) >>= m_xPersistentWindowState; 865cdf0e10cSrcweir 866cdf0e10cSrcweir Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier; 867cdf0e10cSrcweir if ( m_xServiceManager.is() ) 868cdf0e10cSrcweir xModuleCfgSupplier = Reference< XModuleUIConfigurationManagerSupplier >( 869cdf0e10cSrcweir m_xServiceManager->createInstance( SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ), UNO_QUERY ); 870cdf0e10cSrcweir m_xModuleCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier ); 871cdf0e10cSrcweir 872cdf0e10cSrcweir Reference< XController > xController = m_xFrame->getController(); 873cdf0e10cSrcweir Reference< XModel > xModel; 874cdf0e10cSrcweir if ( xController.is() ) 875cdf0e10cSrcweir xModel = xController->getModel(); 876cdf0e10cSrcweir if ( xModel.is() ) 877cdf0e10cSrcweir { 878cdf0e10cSrcweir Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY ); 879cdf0e10cSrcweir if ( xUIConfigurationManagerSupplier.is() ) 880cdf0e10cSrcweir m_xDocCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager(); 881cdf0e10cSrcweir } 882cdf0e10cSrcweir m_aModuleIdentifier = aModuleIdentifier; 883cdf0e10cSrcweir } 884cdf0e10cSrcweir catch ( Exception& ) 885cdf0e10cSrcweir { 886cdf0e10cSrcweir } 887cdf0e10cSrcweir } 888cdf0e10cSrcweir } 889cdf0e10cSrcweir } 890cdf0e10cSrcweir } 891cdf0e10cSrcweir 892cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( ToolbarsMenuController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo ) 893cdf0e10cSrcweir { 894cdf0e10cSrcweir try 895cdf0e10cSrcweir { 896cdf0e10cSrcweir // Asynchronous execution as this can lead to our own destruction! 897cdf0e10cSrcweir // Framework can recycle our current frame and the layout manager disposes all user interface 898cdf0e10cSrcweir // elements if a component gets detached from its frame! 899cdf0e10cSrcweir if ( pExecuteInfo->xDispatch.is() ) 900cdf0e10cSrcweir { 901cdf0e10cSrcweir pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs ); 902cdf0e10cSrcweir } 903cdf0e10cSrcweir } 904cdf0e10cSrcweir catch ( Exception& ) 905cdf0e10cSrcweir { 906cdf0e10cSrcweir } 907cdf0e10cSrcweir 908cdf0e10cSrcweir delete pExecuteInfo; 909cdf0e10cSrcweir return 0; 910cdf0e10cSrcweir } 911cdf0e10cSrcweir 912cdf0e10cSrcweir } 913