1*6d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6d739b60SAndrew Rist * distributed with this work for additional information 6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance 9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6d739b60SAndrew Rist * software distributed under the License is distributed on an 15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the 17*6d739b60SAndrew Rist * specific language governing permissions and limitations 18*6d739b60SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*6d739b60SAndrew Rist *************************************************************/ 21*6d739b60SAndrew Rist 22*6d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 28cdf0e10cSrcweir // my own includes 29cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <limits.h> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include "framework/bmkmenu.hxx" 34cdf0e10cSrcweir #include <general.h> 35cdf0e10cSrcweir #include <macros/debug/assertion.hxx> 36cdf0e10cSrcweir #include <framework/imageproducer.hxx> 37cdf0e10cSrcweir #include <framework/menuconfiguration.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 40cdf0e10cSrcweir // interface includes 41cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 42cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h> 43cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp> 44cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 45cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX 46cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 47cdf0e10cSrcweir #endif 48cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 49cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 50cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 51cdf0e10cSrcweir 52cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53cdf0e10cSrcweir // includes of other projects 54cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 55cdf0e10cSrcweir #include <tools/config.hxx> 56cdf0e10cSrcweir #include <vcl/svapp.hxx> 57cdf0e10cSrcweir #include <unotools/dynamicmenuoptions.hxx> 58cdf0e10cSrcweir #include <svtools/menuoptions.hxx> 59cdf0e10cSrcweir #include <rtl/logfile.hxx> 60cdf0e10cSrcweir 61cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 62cdf0e10cSrcweir // namespace 63cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 64cdf0e10cSrcweir 65cdf0e10cSrcweir using namespace ::comphelper; 66cdf0e10cSrcweir using namespace ::com::sun::star::uno; 67cdf0e10cSrcweir using namespace ::com::sun::star::lang; 68cdf0e10cSrcweir using namespace ::com::sun::star::util; 69cdf0e10cSrcweir using namespace ::com::sun::star::frame; 70cdf0e10cSrcweir using namespace ::com::sun::star::beans; 71cdf0e10cSrcweir 72cdf0e10cSrcweir namespace framework 73cdf0e10cSrcweir { 74cdf0e10cSrcweir 75cdf0e10cSrcweir void GetMenuEntry( 76cdf0e10cSrcweir Sequence< PropertyValue >& aDynamicMenuEntry, 77cdf0e10cSrcweir ::rtl::OUString& rTitle, 78cdf0e10cSrcweir ::rtl::OUString& rURL, 79cdf0e10cSrcweir ::rtl::OUString& rFrame, 80cdf0e10cSrcweir ::rtl::OUString& rImageId ); 81cdf0e10cSrcweir 82cdf0e10cSrcweir class BmkMenu_Impl 83cdf0e10cSrcweir { 84cdf0e10cSrcweir private: 85cdf0e10cSrcweir static sal_uInt16 m_nMID; 86cdf0e10cSrcweir 87cdf0e10cSrcweir public: 88cdf0e10cSrcweir BmkMenu* m_pRoot; 89cdf0e10cSrcweir sal_Bool m_bInitialized; 90cdf0e10cSrcweir 91cdf0e10cSrcweir BmkMenu_Impl( BmkMenu* pRoot ); 92cdf0e10cSrcweir BmkMenu_Impl(); 93cdf0e10cSrcweir ~BmkMenu_Impl(); 94cdf0e10cSrcweir 95cdf0e10cSrcweir static sal_uInt16 GetMID(); 96cdf0e10cSrcweir }; 97cdf0e10cSrcweir 98cdf0e10cSrcweir sal_uInt16 BmkMenu_Impl::m_nMID = BMKMENU_ITEMID_START; 99cdf0e10cSrcweir 100cdf0e10cSrcweir BmkMenu_Impl::BmkMenu_Impl( BmkMenu* pRoot ) : 101cdf0e10cSrcweir m_pRoot(pRoot), 102cdf0e10cSrcweir m_bInitialized(sal_False) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir BmkMenu_Impl::BmkMenu_Impl() : 107cdf0e10cSrcweir m_pRoot(0), 108cdf0e10cSrcweir m_bInitialized(sal_False) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir BmkMenu_Impl::~BmkMenu_Impl() 113cdf0e10cSrcweir { 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir sal_uInt16 BmkMenu_Impl::GetMID() 117cdf0e10cSrcweir { 118cdf0e10cSrcweir m_nMID++; 119cdf0e10cSrcweir if( !m_nMID ) 120cdf0e10cSrcweir m_nMID = BMKMENU_ITEMID_START; 121cdf0e10cSrcweir return m_nMID; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir // ------------------------------------------------------------------------ 125cdf0e10cSrcweir 126cdf0e10cSrcweir BmkMenu::BmkMenu( com::sun::star::uno::Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType, BmkMenu* pRoot ) 127cdf0e10cSrcweir :AddonMenu(xFrame) 128cdf0e10cSrcweir ,m_nType( nType ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir _pImp = new BmkMenu_Impl( pRoot ); 131cdf0e10cSrcweir Initialize(); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir BmkMenu::BmkMenu( Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType ) 135cdf0e10cSrcweir :AddonMenu(xFrame) 136cdf0e10cSrcweir ,m_nType( nType ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir _pImp = new BmkMenu_Impl(); 139cdf0e10cSrcweir Initialize(); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir BmkMenu::~BmkMenu() 143cdf0e10cSrcweir { 144cdf0e10cSrcweir delete _pImp; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir void BmkMenu::Initialize() 148cdf0e10cSrcweir { 149cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::BmkMenu::Initialize" ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir if( _pImp->m_bInitialized ) 152cdf0e10cSrcweir return; 153cdf0e10cSrcweir 154cdf0e10cSrcweir _pImp->m_bInitialized = sal_True; 155cdf0e10cSrcweir 156cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > aDynamicMenuEntries; 157cdf0e10cSrcweir 158cdf0e10cSrcweir if ( m_nType == BmkMenu::BMK_NEWMENU ) 159cdf0e10cSrcweir aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU ); 160cdf0e10cSrcweir else if ( m_nType == BmkMenu::BMK_WIZARDMENU ) 161cdf0e10cSrcweir aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_WIZARDMENU ); 162cdf0e10cSrcweir 163cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); 164cdf0e10cSrcweir sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus(); 165cdf0e10cSrcweir 166cdf0e10cSrcweir ::rtl::OUString aTitle; 167cdf0e10cSrcweir ::rtl::OUString aURL; 168cdf0e10cSrcweir ::rtl::OUString aTargetFrame; 169cdf0e10cSrcweir ::rtl::OUString aImageId; 170cdf0e10cSrcweir 171cdf0e10cSrcweir sal_Bool bIsHiContrastMode = rSettings.GetHighContrastMode(); 172cdf0e10cSrcweir 173cdf0e10cSrcweir sal_uInt32 i, nCount = aDynamicMenuEntries.getLength(); 174cdf0e10cSrcweir for ( i = 0; i < nCount; ++i ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir GetMenuEntry( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageId ); 177cdf0e10cSrcweir 178cdf0e10cSrcweir if ( !aTitle.getLength() && !aURL.getLength() ) 179cdf0e10cSrcweir continue; 180cdf0e10cSrcweir 181cdf0e10cSrcweir if ( aURL == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:separator" ))) 182cdf0e10cSrcweir InsertSeparator(); 183cdf0e10cSrcweir else 184cdf0e10cSrcweir { 185cdf0e10cSrcweir sal_Bool bImageSet = sal_False; 186cdf0e10cSrcweir sal_uInt16 nId = CreateMenuId(); 187cdf0e10cSrcweir 188cdf0e10cSrcweir if ( bShowMenuImages ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir if ( aImageId.getLength() > 0 ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir Image aImage = GetImageFromURL( m_xFrame, aImageId, sal_False, bIsHiContrastMode ); 193cdf0e10cSrcweir if ( !!aImage ) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir bImageSet = sal_True; 196cdf0e10cSrcweir InsertItem( nId, aTitle, aImage ); 197cdf0e10cSrcweir } 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir if ( !bImageSet ) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir Image aImage = GetImageFromURL( m_xFrame, aURL, sal_False, bIsHiContrastMode ); 203cdf0e10cSrcweir if ( !aImage ) 204cdf0e10cSrcweir InsertItem( nId, aTitle ); 205cdf0e10cSrcweir else 206cdf0e10cSrcweir InsertItem( nId, aTitle, aImage ); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir } 209cdf0e10cSrcweir else 210cdf0e10cSrcweir InsertItem( nId, aTitle ); 211cdf0e10cSrcweir 212cdf0e10cSrcweir // Store values from configuration to the New and Wizard menu entries to enable 213cdf0e10cSrcweir // sfx2 based code to support high contrast mode correctly! 214cdf0e10cSrcweir MenuConfiguration::Attributes* pUserAttributes = new MenuConfiguration::Attributes( aTargetFrame, aImageId ); 215cdf0e10cSrcweir SetUserValue( nId, (sal_uIntPtr)pUserAttributes ); 216cdf0e10cSrcweir 217cdf0e10cSrcweir SetItemCommand( nId, aURL ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir } 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir sal_uInt16 BmkMenu::CreateMenuId() 223cdf0e10cSrcweir { 224cdf0e10cSrcweir return BmkMenu_Impl::GetMID(); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir void GetMenuEntry 228cdf0e10cSrcweir ( 229cdf0e10cSrcweir Sequence< PropertyValue >& aDynamicMenuEntry, 230cdf0e10cSrcweir ::rtl::OUString& rTitle, 231cdf0e10cSrcweir ::rtl::OUString& rURL, 232cdf0e10cSrcweir ::rtl::OUString& rFrame, 233cdf0e10cSrcweir ::rtl::OUString& rImageId 234cdf0e10cSrcweir ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL ) 239cdf0e10cSrcweir aDynamicMenuEntry[i].Value >>= rURL; 240cdf0e10cSrcweir else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE ) 241cdf0e10cSrcweir aDynamicMenuEntry[i].Value >>= rTitle; 242cdf0e10cSrcweir else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER ) 243cdf0e10cSrcweir aDynamicMenuEntry[i].Value >>= rImageId; 244cdf0e10cSrcweir else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME ) 245cdf0e10cSrcweir aDynamicMenuEntry[i].Value >>= rFrame; 246cdf0e10cSrcweir } 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251