1*10b918a5SAriel Constenla-Haile /************************************************************** 2*10b918a5SAriel Constenla-Haile * 3*10b918a5SAriel Constenla-Haile * Licensed to the Apache Software Foundation (ASF) under one 4*10b918a5SAriel Constenla-Haile * or more contributor license agreements. See the NOTICE file 5*10b918a5SAriel Constenla-Haile * distributed with this work for additional information 6*10b918a5SAriel Constenla-Haile * regarding copyright ownership. The ASF licenses this file 7*10b918a5SAriel Constenla-Haile * to you under the Apache License, Version 2.0 (the 8*10b918a5SAriel Constenla-Haile * "License"); you may not use this file except in compliance 9*10b918a5SAriel Constenla-Haile * with the License. You may obtain a copy of the License at 10*10b918a5SAriel Constenla-Haile * 11*10b918a5SAriel Constenla-Haile * http://www.apache.org/licenses/LICENSE-2.0 12*10b918a5SAriel Constenla-Haile * 13*10b918a5SAriel Constenla-Haile * Unless required by applicable law or agreed to in writing, 14*10b918a5SAriel Constenla-Haile * software distributed under the License is distributed on an 15*10b918a5SAriel Constenla-Haile * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*10b918a5SAriel Constenla-Haile * KIND, either express or implied. See the License for the 17*10b918a5SAriel Constenla-Haile * specific language governing permissions and limitations 18*10b918a5SAriel Constenla-Haile * under the License. 19*10b918a5SAriel Constenla-Haile * 20*10b918a5SAriel Constenla-Haile *************************************************************/ 21*10b918a5SAriel Constenla-Haile 22*10b918a5SAriel Constenla-Haile // MARKER(update_precomp.py): autogen include statement, do not remove 23*10b918a5SAriel Constenla-Haile #include "precompiled_framework.hxx" 24*10b918a5SAriel Constenla-Haile 25*10b918a5SAriel Constenla-Haile #include <uielement/popuptoolbarcontroller.hxx> 26*10b918a5SAriel Constenla-Haile #include <comphelper/processfactory.hxx> 27*10b918a5SAriel Constenla-Haile #include <svtools/imagemgr.hxx> 28*10b918a5SAriel Constenla-Haile #include <svtools/miscopt.hxx> 29*10b918a5SAriel Constenla-Haile #include <toolkit/helper/vclunohelper.hxx> 30*10b918a5SAriel Constenla-Haile #include <tools/urlobj.hxx> 31*10b918a5SAriel Constenla-Haile #include <unotools/moduleoptions.hxx> 32*10b918a5SAriel Constenla-Haile #include <vcl/svapp.hxx> 33*10b918a5SAriel Constenla-Haile #include <vcl/toolbox.hxx> 34*10b918a5SAriel Constenla-Haile #include <vos/mutex.hxx> 35*10b918a5SAriel Constenla-Haile 36*10b918a5SAriel Constenla-Haile #include <com/sun/star/awt/PopupMenuDirection.hpp> 37*10b918a5SAriel Constenla-Haile #include <com/sun/star/frame/PopupMenuControllerFactory.hpp> 38*10b918a5SAriel Constenla-Haile 39*10b918a5SAriel Constenla-Haile 40*10b918a5SAriel Constenla-Haile #define UNO_COMMAND_RECENT_FILE_LIST ".uno:RecentFileList" 41*10b918a5SAriel Constenla-Haile 42*10b918a5SAriel Constenla-Haile using rtl::OUString; 43*10b918a5SAriel Constenla-Haile namespace css = ::com::sun::star; 44*10b918a5SAriel Constenla-Haile 45*10b918a5SAriel Constenla-Haile namespace framework 46*10b918a5SAriel Constenla-Haile { 47*10b918a5SAriel Constenla-Haile 48*10b918a5SAriel Constenla-Haile PopupMenuToolbarController::PopupMenuToolbarController( 49*10b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext, 50*10b918a5SAriel Constenla-Haile const OUString &rPopupCommand ) 51*10b918a5SAriel Constenla-Haile : svt::ToolboxController() 52*10b918a5SAriel Constenla-Haile , m_xContext( xContext ) 53*10b918a5SAriel Constenla-Haile , m_bHasController( sal_False ) 54*10b918a5SAriel Constenla-Haile , m_aPopupCommand( rPopupCommand ) 55*10b918a5SAriel Constenla-Haile { 56*10b918a5SAriel Constenla-Haile } 57*10b918a5SAriel Constenla-Haile 58*10b918a5SAriel Constenla-Haile PopupMenuToolbarController::~PopupMenuToolbarController() 59*10b918a5SAriel Constenla-Haile { 60*10b918a5SAriel Constenla-Haile } 61*10b918a5SAriel Constenla-Haile 62*10b918a5SAriel Constenla-Haile void SAL_CALL PopupMenuToolbarController::dispose() 63*10b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException ) 64*10b918a5SAriel Constenla-Haile { 65*10b918a5SAriel Constenla-Haile svt::ToolboxController::dispose(); 66*10b918a5SAriel Constenla-Haile 67*10b918a5SAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex ); 68*10b918a5SAriel Constenla-Haile if( m_xPopupMenuController.is() ) 69*10b918a5SAriel Constenla-Haile { 70*10b918a5SAriel Constenla-Haile css::uno::Reference< css::lang::XComponent > xComponent( 71*10b918a5SAriel Constenla-Haile m_xPopupMenuController, css::uno::UNO_QUERY ); 72*10b918a5SAriel Constenla-Haile if( xComponent.is() ) 73*10b918a5SAriel Constenla-Haile { 74*10b918a5SAriel Constenla-Haile try 75*10b918a5SAriel Constenla-Haile { 76*10b918a5SAriel Constenla-Haile xComponent->dispose(); 77*10b918a5SAriel Constenla-Haile } 78*10b918a5SAriel Constenla-Haile catch (...) 79*10b918a5SAriel Constenla-Haile {} 80*10b918a5SAriel Constenla-Haile } 81*10b918a5SAriel Constenla-Haile m_xPopupMenuController.clear(); 82*10b918a5SAriel Constenla-Haile } 83*10b918a5SAriel Constenla-Haile 84*10b918a5SAriel Constenla-Haile m_xContext.clear(); 85*10b918a5SAriel Constenla-Haile m_xPopupMenuFactory.clear(); 86*10b918a5SAriel Constenla-Haile m_xPopupMenu.clear(); 87*10b918a5SAriel Constenla-Haile } 88*10b918a5SAriel Constenla-Haile 89*10b918a5SAriel Constenla-Haile void SAL_CALL PopupMenuToolbarController::initialize( 90*10b918a5SAriel Constenla-Haile const css::uno::Sequence< css::uno::Any >& aArguments ) 91*10b918a5SAriel Constenla-Haile throw ( css::uno::Exception, css::uno::RuntimeException ) 92*10b918a5SAriel Constenla-Haile { 93*10b918a5SAriel Constenla-Haile ToolboxController::initialize( aArguments ); 94*10b918a5SAriel Constenla-Haile 95*10b918a5SAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex ); 96*10b918a5SAriel Constenla-Haile if ( !m_aPopupCommand.getLength() ) 97*10b918a5SAriel Constenla-Haile m_aPopupCommand = m_aCommandURL; 98*10b918a5SAriel Constenla-Haile 99*10b918a5SAriel Constenla-Haile try 100*10b918a5SAriel Constenla-Haile { 101*10b918a5SAriel Constenla-Haile m_xPopupMenuFactory.set( 102*10b918a5SAriel Constenla-Haile css::frame::PopupMenuControllerFactory::create( m_xContext ) ); 103*10b918a5SAriel Constenla-Haile m_bHasController = m_xPopupMenuFactory->hasController( 104*10b918a5SAriel Constenla-Haile m_aPopupCommand, getModuleName() ); 105*10b918a5SAriel Constenla-Haile } 106*10b918a5SAriel Constenla-Haile catch (const css::uno::Exception& e) 107*10b918a5SAriel Constenla-Haile { 108*10b918a5SAriel Constenla-Haile OSL_TRACE( "PopupMenuToolbarController - caught an exception! %s", 109*10b918a5SAriel Constenla-Haile rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); 110*10b918a5SAriel Constenla-Haile (void) e; 111*10b918a5SAriel Constenla-Haile } 112*10b918a5SAriel Constenla-Haile 113*10b918a5SAriel Constenla-Haile vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 114*10b918a5SAriel Constenla-Haile ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) ); 115*10b918a5SAriel Constenla-Haile if ( pToolBox ) 116*10b918a5SAriel Constenla-Haile { 117*10b918a5SAriel Constenla-Haile ToolBoxItemBits nCurStyle( pToolBox->GetItemBits( m_nToolBoxId ) ); 118*10b918a5SAriel Constenla-Haile ToolBoxItemBits nSetStyle( getDropDownStyle() ); 119*10b918a5SAriel Constenla-Haile pToolBox->SetItemBits( m_nToolBoxId, 120*10b918a5SAriel Constenla-Haile m_bHasController ? 121*10b918a5SAriel Constenla-Haile nCurStyle | nSetStyle : 122*10b918a5SAriel Constenla-Haile nCurStyle & ~nSetStyle ); 123*10b918a5SAriel Constenla-Haile } 124*10b918a5SAriel Constenla-Haile 125*10b918a5SAriel Constenla-Haile } 126*10b918a5SAriel Constenla-Haile 127*10b918a5SAriel Constenla-Haile void SAL_CALL 128*10b918a5SAriel Constenla-Haile PopupMenuToolbarController::statusChanged( 129*10b918a5SAriel Constenla-Haile const css::frame::FeatureStateEvent& rEvent ) 130*10b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException ) 131*10b918a5SAriel Constenla-Haile { 132*10b918a5SAriel Constenla-Haile // TODO move to base class 133*10b918a5SAriel Constenla-Haile 134*10b918a5SAriel Constenla-Haile svt::ToolboxController::statusChanged( rEvent ); 135*10b918a5SAriel Constenla-Haile enable( rEvent.IsEnabled ); 136*10b918a5SAriel Constenla-Haile } 137*10b918a5SAriel Constenla-Haile 138*10b918a5SAriel Constenla-Haile css::uno::Reference< css::awt::XWindow > SAL_CALL 139*10b918a5SAriel Constenla-Haile PopupMenuToolbarController::createPopupWindow() 140*10b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException ) 141*10b918a5SAriel Constenla-Haile { 142*10b918a5SAriel Constenla-Haile css::uno::Reference< css::awt::XWindow > xRet; 143*10b918a5SAriel Constenla-Haile 144*10b918a5SAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex ); 145*10b918a5SAriel Constenla-Haile if ( !m_bHasController ) 146*10b918a5SAriel Constenla-Haile return xRet; 147*10b918a5SAriel Constenla-Haile 148*10b918a5SAriel Constenla-Haile createPopupMenuController(); 149*10b918a5SAriel Constenla-Haile 150*10b918a5SAriel Constenla-Haile vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 151*10b918a5SAriel Constenla-Haile ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) ); 152*10b918a5SAriel Constenla-Haile if ( !pToolBox ) 153*10b918a5SAriel Constenla-Haile return xRet; 154*10b918a5SAriel Constenla-Haile 155*10b918a5SAriel Constenla-Haile pToolBox->SetItemDown( m_nToolBoxId, sal_True ); 156*10b918a5SAriel Constenla-Haile sal_uInt16 nId = m_xPopupMenu->execute( 157*10b918a5SAriel Constenla-Haile css::uno::Reference< css::awt::XWindowPeer >( getParent(), css::uno::UNO_QUERY ), 158*10b918a5SAriel Constenla-Haile VCLUnoHelper::ConvertToAWTRect( pToolBox->GetItemRect( m_nToolBoxId ) ), 159*10b918a5SAriel Constenla-Haile css::awt::PopupMenuDirection::EXECUTE_DEFAULT ); 160*10b918a5SAriel Constenla-Haile pToolBox->SetItemDown( m_nToolBoxId, sal_False ); 161*10b918a5SAriel Constenla-Haile 162*10b918a5SAriel Constenla-Haile if ( nId ) 163*10b918a5SAriel Constenla-Haile functionExecuted( m_xPopupMenu->getCommand( nId ) ); 164*10b918a5SAriel Constenla-Haile 165*10b918a5SAriel Constenla-Haile return xRet; 166*10b918a5SAriel Constenla-Haile } 167*10b918a5SAriel Constenla-Haile 168*10b918a5SAriel Constenla-Haile void PopupMenuToolbarController::functionExecuted( const OUString &/*rCommand*/) 169*10b918a5SAriel Constenla-Haile { 170*10b918a5SAriel Constenla-Haile } 171*10b918a5SAriel Constenla-Haile 172*10b918a5SAriel Constenla-Haile sal_uInt16 PopupMenuToolbarController::getDropDownStyle() const 173*10b918a5SAriel Constenla-Haile { 174*10b918a5SAriel Constenla-Haile return TIB_DROPDOWN; 175*10b918a5SAriel Constenla-Haile } 176*10b918a5SAriel Constenla-Haile 177*10b918a5SAriel Constenla-Haile void PopupMenuToolbarController::createPopupMenuController() 178*10b918a5SAriel Constenla-Haile { 179*10b918a5SAriel Constenla-Haile if( !m_bHasController ) 180*10b918a5SAriel Constenla-Haile return; 181*10b918a5SAriel Constenla-Haile 182*10b918a5SAriel Constenla-Haile if ( !m_xPopupMenuController.is() ) 183*10b918a5SAriel Constenla-Haile { 184*10b918a5SAriel Constenla-Haile css::uno::Sequence< css::uno::Any > aArgs( 2 ); 185*10b918a5SAriel Constenla-Haile css::beans::PropertyValue aProp; 186*10b918a5SAriel Constenla-Haile 187*10b918a5SAriel Constenla-Haile aProp.Name = DECLARE_ASCII( "Frame" ); 188*10b918a5SAriel Constenla-Haile aProp.Value <<= m_xFrame; 189*10b918a5SAriel Constenla-Haile aArgs[0] <<= aProp; 190*10b918a5SAriel Constenla-Haile 191*10b918a5SAriel Constenla-Haile aProp.Name = DECLARE_ASCII( "ModuleIdentifier" ); 192*10b918a5SAriel Constenla-Haile aProp.Value <<= getModuleName(); 193*10b918a5SAriel Constenla-Haile aArgs[1] <<= aProp; 194*10b918a5SAriel Constenla-Haile try 195*10b918a5SAriel Constenla-Haile { 196*10b918a5SAriel Constenla-Haile m_xPopupMenu.set( 197*10b918a5SAriel Constenla-Haile m_xContext->getServiceManager()->createInstanceWithContext( 198*10b918a5SAriel Constenla-Haile DECLARE_ASCII( "com.sun.star.awt.PopupMenu" ), m_xContext ), 199*10b918a5SAriel Constenla-Haile css::uno::UNO_QUERY_THROW ); 200*10b918a5SAriel Constenla-Haile m_xPopupMenuController.set( 201*10b918a5SAriel Constenla-Haile m_xPopupMenuFactory->createInstanceWithArgumentsAndContext( 202*10b918a5SAriel Constenla-Haile m_aPopupCommand, aArgs, m_xContext), css::uno::UNO_QUERY_THROW ); 203*10b918a5SAriel Constenla-Haile 204*10b918a5SAriel Constenla-Haile m_xPopupMenuController->setPopupMenu( m_xPopupMenu ); 205*10b918a5SAriel Constenla-Haile } 206*10b918a5SAriel Constenla-Haile catch ( const css::uno::Exception &e ) 207*10b918a5SAriel Constenla-Haile { 208*10b918a5SAriel Constenla-Haile m_xPopupMenu.clear(); 209*10b918a5SAriel Constenla-Haile OSL_TRACE( "PopupMenuToolbarController - caught an exception! %s", 210*10b918a5SAriel Constenla-Haile rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); 211*10b918a5SAriel Constenla-Haile (void) e; 212*10b918a5SAriel Constenla-Haile } 213*10b918a5SAriel Constenla-Haile } 214*10b918a5SAriel Constenla-Haile } 215*10b918a5SAriel Constenla-Haile 216*10b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( WizardsToolbarController, 217*10b918a5SAriel Constenla-Haile ::cppu::OWeakObject, 218*10b918a5SAriel Constenla-Haile DECLARE_ASCII("com.sun.star.frame.ToolbarController"), 219*10b918a5SAriel Constenla-Haile DECLARE_ASCII("org.apache.openoffice.comp.framework.WizardsToolbarController") 220*10b918a5SAriel Constenla-Haile ) 221*10b918a5SAriel Constenla-Haile 222*10b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( WizardsToolbarController, {} ) 223*10b918a5SAriel Constenla-Haile 224*10b918a5SAriel Constenla-Haile WizardsToolbarController::WizardsToolbarController( 225*10b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext ) 226*10b918a5SAriel Constenla-Haile : PopupMenuToolbarController( xContext ) 227*10b918a5SAriel Constenla-Haile { 228*10b918a5SAriel Constenla-Haile } 229*10b918a5SAriel Constenla-Haile 230*10b918a5SAriel Constenla-Haile sal_uInt16 WizardsToolbarController::getDropDownStyle() const 231*10b918a5SAriel Constenla-Haile { 232*10b918a5SAriel Constenla-Haile return TIB_DROPDOWNONLY; 233*10b918a5SAriel Constenla-Haile } 234*10b918a5SAriel Constenla-Haile 235*10b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( OpenToolbarController, 236*10b918a5SAriel Constenla-Haile ::cppu::OWeakObject, 237*10b918a5SAriel Constenla-Haile DECLARE_ASCII("com.sun.star.frame.ToolbarController"), 238*10b918a5SAriel Constenla-Haile DECLARE_ASCII("org.apache.openoffice.comp.framework.OpenToolbarController") 239*10b918a5SAriel Constenla-Haile ) 240*10b918a5SAriel Constenla-Haile 241*10b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( OpenToolbarController, {} ) 242*10b918a5SAriel Constenla-Haile 243*10b918a5SAriel Constenla-Haile OpenToolbarController::OpenToolbarController( 244*10b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext ) 245*10b918a5SAriel Constenla-Haile : PopupMenuToolbarController( xContext, DECLARE_ASCII( UNO_COMMAND_RECENT_FILE_LIST ) ) 246*10b918a5SAriel Constenla-Haile { 247*10b918a5SAriel Constenla-Haile } 248*10b918a5SAriel Constenla-Haile 249*10b918a5SAriel Constenla-Haile 250*10b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( NewToolbarController, 251*10b918a5SAriel Constenla-Haile ::cppu::OWeakObject, 252*10b918a5SAriel Constenla-Haile DECLARE_ASCII("com.sun.star.frame.ToolbarController"), 253*10b918a5SAriel Constenla-Haile DECLARE_ASCII("org.apache.openoffice.comp.framework.NewToolbarController") 254*10b918a5SAriel Constenla-Haile ) 255*10b918a5SAriel Constenla-Haile 256*10b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( NewToolbarController, {} ) 257*10b918a5SAriel Constenla-Haile 258*10b918a5SAriel Constenla-Haile NewToolbarController::NewToolbarController( 259*10b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext ) 260*10b918a5SAriel Constenla-Haile : PopupMenuToolbarController( xContext ) 261*10b918a5SAriel Constenla-Haile { 262*10b918a5SAriel Constenla-Haile } 263*10b918a5SAriel Constenla-Haile 264*10b918a5SAriel Constenla-Haile void SAL_CALL 265*10b918a5SAriel Constenla-Haile NewToolbarController::statusChanged( 266*10b918a5SAriel Constenla-Haile const css::frame::FeatureStateEvent& rEvent ) 267*10b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException ) 268*10b918a5SAriel Constenla-Haile { 269*10b918a5SAriel Constenla-Haile if ( rEvent.IsEnabled ) 270*10b918a5SAriel Constenla-Haile { 271*10b918a5SAriel Constenla-Haile OUString aState; 272*10b918a5SAriel Constenla-Haile rEvent.State >>= aState; 273*10b918a5SAriel Constenla-Haile // set the image even if the state is not a string 274*10b918a5SAriel Constenla-Haile // this will set the image of the default module 275*10b918a5SAriel Constenla-Haile setItemImage( aState ); 276*10b918a5SAriel Constenla-Haile } 277*10b918a5SAriel Constenla-Haile 278*10b918a5SAriel Constenla-Haile enable( rEvent.IsEnabled ); 279*10b918a5SAriel Constenla-Haile } 280*10b918a5SAriel Constenla-Haile 281*10b918a5SAriel Constenla-Haile void NewToolbarController::functionExecuted( const OUString &rCommand ) 282*10b918a5SAriel Constenla-Haile { 283*10b918a5SAriel Constenla-Haile setItemImage( rCommand ); 284*10b918a5SAriel Constenla-Haile } 285*10b918a5SAriel Constenla-Haile 286*10b918a5SAriel Constenla-Haile /** 287*10b918a5SAriel Constenla-Haile it return the existing state of the given URL in the popupmenu of this toolbox control. 288*10b918a5SAriel Constenla-Haile 289*10b918a5SAriel Constenla-Haile If the given URL can be located as an action command of one menu item of the 290*10b918a5SAriel Constenla-Haile popup menu of this control, we return sal_True. Otherwhise we return sal_False. 291*10b918a5SAriel Constenla-Haile Further we return a fallback URL, in case we have to return sal_False. Because 292*10b918a5SAriel Constenla-Haile the outside code must select a valid item of the popup menu everytime ... 293*10b918a5SAriel Constenla-Haile and we define it here. By the way this m ethod was written to handle 294*10b918a5SAriel Constenla-Haile error situations gracefully. E.g. it can be called during creation time 295*10b918a5SAriel Constenla-Haile but then we have no valid menu. For this case we know another fallback URL. 296*10b918a5SAriel Constenla-Haile Then we return the private:factory/ URL of the default factory. 297*10b918a5SAriel Constenla-Haile 298*10b918a5SAriel Constenla-Haile @param rPopupMenu 299*10b918a5SAriel Constenla-Haile pounts to the popup menu, on which item we try to locate the given URL 300*10b918a5SAriel Constenla-Haile Can be NULL! Search will be supressed then. 301*10b918a5SAriel Constenla-Haile 302*10b918a5SAriel Constenla-Haile @param sURL 303*10b918a5SAriel Constenla-Haile the URL for searching 304*10b918a5SAriel Constenla-Haile 305*10b918a5SAriel Constenla-Haile @param sFallback 306*10b918a5SAriel Constenla-Haile contains the fallback URL in case we return FALSE 307*10b918a5SAriel Constenla-Haile Must point to valid memory! 308*10b918a5SAriel Constenla-Haile 309*10b918a5SAriel Constenla-Haile @param aImage 310*10b918a5SAriel Constenla-Haile contains the image of the menu for the URL. 311*10b918a5SAriel Constenla-Haile 312*10b918a5SAriel Constenla-Haile @return sal_True - if URL could be located as an item of the popup menu. 313*10b918a5SAriel Constenla-Haile sal_False - otherwhise. 314*10b918a5SAriel Constenla-Haile */ 315*10b918a5SAriel Constenla-Haile static sal_Bool Impl_ExistURLInMenu( 316*10b918a5SAriel Constenla-Haile const css::uno::Reference< css::awt::XPopupMenu > &rPopupMenu, 317*10b918a5SAriel Constenla-Haile OUString &sURL, 318*10b918a5SAriel Constenla-Haile OUString &sFallback, 319*10b918a5SAriel Constenla-Haile Image &aImage ) 320*10b918a5SAriel Constenla-Haile { 321*10b918a5SAriel Constenla-Haile sal_Bool bValidFallback( sal_False ); 322*10b918a5SAriel Constenla-Haile sal_uInt16 nCount( 0 ); 323*10b918a5SAriel Constenla-Haile if ( rPopupMenu.is() && ( nCount = rPopupMenu->getItemCount() ) && sURL.getLength() ) 324*10b918a5SAriel Constenla-Haile { 325*10b918a5SAriel Constenla-Haile for ( sal_uInt16 n = 0; n < nCount; ++n ) 326*10b918a5SAriel Constenla-Haile { 327*10b918a5SAriel Constenla-Haile sal_uInt16 nId = rPopupMenu->getItemId( n ); 328*10b918a5SAriel Constenla-Haile OUString aCmd( rPopupMenu->getCommand( nId ) ); 329*10b918a5SAriel Constenla-Haile 330*10b918a5SAriel Constenla-Haile if ( !bValidFallback && aCmd.getLength() ) 331*10b918a5SAriel Constenla-Haile { 332*10b918a5SAriel Constenla-Haile sFallback = aCmd; 333*10b918a5SAriel Constenla-Haile bValidFallback = sal_True; 334*10b918a5SAriel Constenla-Haile } 335*10b918a5SAriel Constenla-Haile 336*10b918a5SAriel Constenla-Haile // match even if the menu command is more detailed 337*10b918a5SAriel Constenla-Haile // (maybe an additional query) #i28667# 338*10b918a5SAriel Constenla-Haile if ( aCmd.match( sURL ) ) 339*10b918a5SAriel Constenla-Haile { 340*10b918a5SAriel Constenla-Haile sURL = aCmd; 341*10b918a5SAriel Constenla-Haile const css::uno::Reference< css::graphic::XGraphic > xGraphic( 342*10b918a5SAriel Constenla-Haile rPopupMenu->getItemImage( nId ) ); 343*10b918a5SAriel Constenla-Haile if ( xGraphic.is() ) 344*10b918a5SAriel Constenla-Haile aImage = Image( xGraphic ); 345*10b918a5SAriel Constenla-Haile return sal_True; 346*10b918a5SAriel Constenla-Haile } 347*10b918a5SAriel Constenla-Haile } 348*10b918a5SAriel Constenla-Haile } 349*10b918a5SAriel Constenla-Haile 350*10b918a5SAriel Constenla-Haile if ( !bValidFallback ) 351*10b918a5SAriel Constenla-Haile { 352*10b918a5SAriel Constenla-Haile rtl::OUStringBuffer aBuffer; 353*10b918a5SAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "private:factory/" ) ); 354*10b918a5SAriel Constenla-Haile aBuffer.append( SvtModuleOptions().GetDefaultModuleName() ); 355*10b918a5SAriel Constenla-Haile sFallback = aBuffer.makeStringAndClear(); 356*10b918a5SAriel Constenla-Haile } 357*10b918a5SAriel Constenla-Haile 358*10b918a5SAriel Constenla-Haile return sal_False; 359*10b918a5SAriel Constenla-Haile } 360*10b918a5SAriel Constenla-Haile 361*10b918a5SAriel Constenla-Haile /** We accept URL's here only, which exist as items of our internal popup menu. 362*10b918a5SAriel Constenla-Haile All other ones will be ignored and a fallback is used. 363*10b918a5SAriel Constenla-Haile */ 364*10b918a5SAriel Constenla-Haile void NewToolbarController::setItemImage( const OUString &rCommand ) 365*10b918a5SAriel Constenla-Haile { 366*10b918a5SAriel Constenla-Haile vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 367*10b918a5SAriel Constenla-Haile ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) ); 368*10b918a5SAriel Constenla-Haile if ( !pToolBox ) 369*10b918a5SAriel Constenla-Haile return; 370*10b918a5SAriel Constenla-Haile 371*10b918a5SAriel Constenla-Haile OUString aURL = rCommand; 372*10b918a5SAriel Constenla-Haile OUString sFallback; 373*10b918a5SAriel Constenla-Haile Image aMenuImage; 374*10b918a5SAriel Constenla-Haile 375*10b918a5SAriel Constenla-Haile sal_Bool bValid( Impl_ExistURLInMenu( m_xPopupMenu, aURL, sFallback, aMenuImage ) ); 376*10b918a5SAriel Constenla-Haile // do not change aURL if Impl_ExistURLInMenu returned sal_False 377*10b918a5SAriel Constenla-Haile // this allows later initialization of the PopupMenuController on createPopupWindow() 378*10b918a5SAriel Constenla-Haile // and works even if SvFileInformationManager does not know the module 379*10b918a5SAriel Constenla-Haile if ( !aURL.getLength() ) 380*10b918a5SAriel Constenla-Haile aURL = sFallback; 381*10b918a5SAriel Constenla-Haile 382*10b918a5SAriel Constenla-Haile sal_Bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge(); 383*10b918a5SAriel Constenla-Haile sal_Bool bHC = pToolBox->GetSettings().GetStyleSettings().GetHighContrastMode(); 384*10b918a5SAriel Constenla-Haile 385*10b918a5SAriel Constenla-Haile INetURLObject aURLObj( aURL ); 386*10b918a5SAriel Constenla-Haile Image aImage = SvFileInformationManager::GetImageNoDefault( aURLObj, bBig, bHC ); 387*10b918a5SAriel Constenla-Haile if ( !aImage ) 388*10b918a5SAriel Constenla-Haile { 389*10b918a5SAriel Constenla-Haile if ( !!aMenuImage ) 390*10b918a5SAriel Constenla-Haile aImage = aMenuImage; 391*10b918a5SAriel Constenla-Haile else if ( !bValid ) 392*10b918a5SAriel Constenla-Haile // If SvFileInformationManager didn't know the module, try with the default 393*10b918a5SAriel Constenla-Haile aImage = SvFileInformationManager::GetImageNoDefault( INetURLObject( sFallback ), bBig, bHC ); 394*10b918a5SAriel Constenla-Haile 395*10b918a5SAriel Constenla-Haile if ( !aImage ) 396*10b918a5SAriel Constenla-Haile aImage = SvFileInformationManager::GetImage( aURLObj, bBig, bHC ); 397*10b918a5SAriel Constenla-Haile } 398*10b918a5SAriel Constenla-Haile 399*10b918a5SAriel Constenla-Haile // if everything failed, just use the image associated with the toolbar item command 400*10b918a5SAriel Constenla-Haile if ( !aImage ) 401*10b918a5SAriel Constenla-Haile return; 402*10b918a5SAriel Constenla-Haile 403*10b918a5SAriel Constenla-Haile Size aBigSize( pToolBox->GetDefaultImageSize() ); 404*10b918a5SAriel Constenla-Haile if ( bBig && aImage.GetSizePixel() != aBigSize ) 405*10b918a5SAriel Constenla-Haile { 406*10b918a5SAriel Constenla-Haile BitmapEx aScaleBmpEx( aImage.GetBitmapEx() ); 407*10b918a5SAriel Constenla-Haile aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE ); 408*10b918a5SAriel Constenla-Haile pToolBox->SetItemImage( m_nToolBoxId, Image( aScaleBmpEx ) ); 409*10b918a5SAriel Constenla-Haile } 410*10b918a5SAriel Constenla-Haile else 411*10b918a5SAriel Constenla-Haile pToolBox->SetItemImage( m_nToolBoxId, aImage ); 412*10b918a5SAriel Constenla-Haile } 413*10b918a5SAriel Constenla-Haile 414*10b918a5SAriel Constenla-Haile 415*10b918a5SAriel Constenla-Haile } 416