1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "inettbc.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #ifndef GCC 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir #include <com/sun/star/uno/Any.h> 36*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XFRAMESSUPLLIER_HPP_ 37*cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp> 38*cdf0e10cSrcweir #endif 39*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 40*cdf0e10cSrcweir #include <svl/eitem.hxx> 41*cdf0e10cSrcweir #include <svl/stritem.hxx> 42*cdf0e10cSrcweir #include <unotools/historyoptions.hxx> 43*cdf0e10cSrcweir #include <svl/folderrestriction.hxx> 44*cdf0e10cSrcweir #include <vcl/toolbox.hxx> 45*cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 46*cdf0e10cSrcweir #include <toolkit/unohlp.hxx> 47*cdf0e10cSrcweir #endif 48*cdf0e10cSrcweir #ifndef _VOS_THREAD_HXX //autogen 49*cdf0e10cSrcweir #include <vos/thread.hxx> 50*cdf0e10cSrcweir #endif 51*cdf0e10cSrcweir #ifndef _VOS_MUTEX_HXX //autogen 52*cdf0e10cSrcweir #include <vos/mutex.hxx> 53*cdf0e10cSrcweir #endif 54*cdf0e10cSrcweir #include <rtl/ustring.hxx> 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #include <svl/itemset.hxx> 57*cdf0e10cSrcweir #include <svl/urihelper.hxx> 58*cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 59*cdf0e10cSrcweir #include <svtools/asynclink.hxx> 60*cdf0e10cSrcweir #include <svtools/inettbc.hxx> 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx> 63*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #include <sfx2/sfx.hrc> 66*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 67*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 68*cdf0e10cSrcweir #include <sfx2/objsh.hxx> 69*cdf0e10cSrcweir #include "referers.hxx" 70*cdf0e10cSrcweir #include "sfxtypes.hxx" 71*cdf0e10cSrcweir #include "helper.hxx" 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 74*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 75*cdf0e10cSrcweir using namespace ::com::sun::star::util; 76*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 77*cdf0e10cSrcweir using namespace ::com::sun::star::task; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //*************************************************************************** 80*cdf0e10cSrcweir // SfxURLToolBoxControl_Impl 81*cdf0e10cSrcweir //*************************************************************************** 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL(SfxURLToolBoxControl_Impl,SfxStringItem) 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir SfxURLToolBoxControl_Impl::SfxURLToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox ) 86*cdf0e10cSrcweir : SfxToolBoxControl( nSlotId, nId, rBox ), 87*cdf0e10cSrcweir pAccExec( 0 ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CurrentURL" ))); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir SfxURLToolBoxControl_Impl::~SfxURLToolBoxControl_Impl() 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir delete pAccExec; 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir SvtURLBox* SfxURLToolBoxControl_Impl::GetURLBox() const 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir return (SvtURLBox*)GetToolBox().GetItemWindow( GetId() ); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir //*************************************************************************** 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir void SfxURLToolBoxControl_Impl::OpenURL( const String& rName, sal_Bool /*bNew*/ ) const 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir String aName; 107*cdf0e10cSrcweir String aFilter; 108*cdf0e10cSrcweir String aOptions; 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir INetURLObject aObj( rName ); 111*cdf0e10cSrcweir if ( aObj.GetProtocol() == INET_PROT_NOT_VALID ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir String aBaseURL = GetURLBox()->GetBaseURL(); 114*cdf0e10cSrcweir aName = SvtURLBox::ParseSmart( rName, aBaseURL, SvtPathOptions().GetWorkPath() ); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir else 117*cdf0e10cSrcweir aName = rName; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir if ( !aName.Len() ) 120*cdf0e10cSrcweir return; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY ); 123*cdf0e10cSrcweir if ( xDispatchProvider.is() && m_xServiceManager.is() ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir URL aTargetURL; 126*cdf0e10cSrcweir ::rtl::OUString aTarget( ::rtl::OUString::createFromAscii( "_default" )); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir aTargetURL.Complete = aName; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir getURLTransformer()->parseStrict( aTargetURL ); 131*cdf0e10cSrcweir Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTarget, 0 ); 132*cdf0e10cSrcweir if ( xDispatch.is() ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir Sequence< PropertyValue > aArgs( 2 ); 135*cdf0e10cSrcweir aArgs[0].Name = ::rtl::OUString::createFromAscii( "Referer" ); 136*cdf0e10cSrcweir aArgs[0].Value = makeAny( ::rtl::OUString::createFromAscii( SFX_REFERER_USER )); 137*cdf0e10cSrcweir aArgs[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" )); 138*cdf0e10cSrcweir aArgs[1].Value = makeAny( ::rtl::OUString( aName )); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir if ( aFilter.Len() ) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir aArgs.realloc( 4 ); 143*cdf0e10cSrcweir aArgs[2].Name = ::rtl::OUString::createFromAscii( "FilterOptions" ); 144*cdf0e10cSrcweir aArgs[2].Value = makeAny( ::rtl::OUString( aOptions )); 145*cdf0e10cSrcweir aArgs[3].Name = ::rtl::OUString::createFromAscii( "FilterName" ); 146*cdf0e10cSrcweir aArgs[3].Value = makeAny( ::rtl::OUString( aFilter )); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir SfxURLToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxURLToolBoxControl_Impl::ExecuteInfo; 150*cdf0e10cSrcweir pExecuteInfo->xDispatch = xDispatch; 151*cdf0e10cSrcweir pExecuteInfo->aTargetURL = aTargetURL; 152*cdf0e10cSrcweir pExecuteInfo->aArgs = aArgs; 153*cdf0e10cSrcweir Application::PostUserEvent( STATIC_LINK( 0, SfxURLToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir //-------------------------------------------------------------------- 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( SfxURLToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir try 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir // Asynchronous execution as this can lead to our own destruction! 165*cdf0e10cSrcweir // Framework can recycle our current frame and the layout manager disposes all user interface 166*cdf0e10cSrcweir // elements if a component gets detached from its frame! 167*cdf0e10cSrcweir pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs ); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir catch ( Exception& ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir delete pExecuteInfo; 174*cdf0e10cSrcweir return 0; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir Window* SfxURLToolBoxControl_Impl::CreateItemWindow( Window* pParent ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir SvtURLBox* pURLBox = new SvtURLBox( pParent ); 181*cdf0e10cSrcweir pURLBox->SetOpenHdl( LINK( this, SfxURLToolBoxControl_Impl, OpenHdl ) ); 182*cdf0e10cSrcweir pURLBox->SetSelectHdl( LINK( this, SfxURLToolBoxControl_Impl, SelectHdl ) ); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir return pURLBox; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir IMPL_LINK( SfxURLToolBoxControl_Impl, SelectHdl, void*, EMPTYARG ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir SvtURLBox* pURLBox = GetURLBox(); 190*cdf0e10cSrcweir String aName( pURLBox->GetURL() ); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if ( !pURLBox->IsTravelSelect() && aName.Len() ) 193*cdf0e10cSrcweir OpenURL( aName, sal_False ); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir return 1L; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir IMPL_LINK( SfxURLToolBoxControl_Impl, OpenHdl, void*, EMPTYARG ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir SvtURLBox* pURLBox = GetURLBox(); 201*cdf0e10cSrcweir OpenURL( pURLBox->GetURL(), pURLBox->IsCtrlOpen() ); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir if ( m_xServiceManager.is() ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir Reference< XFramesSupplier > xDesktop( m_xServiceManager->createInstance( 206*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" )), 207*cdf0e10cSrcweir UNO_QUERY ); 208*cdf0e10cSrcweir Reference< XFrame > xFrame( xDesktop->getActiveFrame(), UNO_QUERY ); 209*cdf0e10cSrcweir if ( xFrame.is() ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); 212*cdf0e10cSrcweir if ( pWin ) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir pWin->GrabFocus(); 215*cdf0e10cSrcweir pWin->ToTop( TOTOP_RESTOREWHENMIN ); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir return 1L; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir IMPL_LINK( SfxURLToolBoxControl_Impl, WindowEventListener, VclSimpleEvent*, pEvent ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir if ( pAccExec && 226*cdf0e10cSrcweir pEvent && 227*cdf0e10cSrcweir pEvent->ISA( VclWindowEvent ) && 228*cdf0e10cSrcweir ( pEvent->GetId() == VCLEVENT_WINDOW_KEYINPUT )) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir VclWindowEvent* pWinEvent = static_cast< VclWindowEvent* >( pEvent ); 231*cdf0e10cSrcweir KeyEvent* pKeyEvent = static_cast< KeyEvent* >( pWinEvent->GetData() ); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir pAccExec->execute( pKeyEvent->GetKeyCode() ); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir return 1; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir //*************************************************************************** 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir void SfxURLToolBoxControl_Impl::StateChanged 242*cdf0e10cSrcweir ( 243*cdf0e10cSrcweir sal_uInt16 nSID, 244*cdf0e10cSrcweir SfxItemState eState, 245*cdf0e10cSrcweir const SfxPoolItem* pState 246*cdf0e10cSrcweir ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir if ( nSID == SID_OPENURL ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir // Disable URL box if command is disabled #111014# 251*cdf0e10cSrcweir GetURLBox()->Enable( SFX_ITEM_DISABLED != eState ); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir if ( GetURLBox()->IsEnabled() ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir if( nSID == SID_FOCUSURLBOX ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir if ( GetURLBox()->IsVisible() ) 259*cdf0e10cSrcweir GetURLBox()->GrabFocus(); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir else if ( !GetURLBox()->IsModified() && SFX_ITEM_AVAILABLE == eState ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir SvtURLBox* pURLBox = GetURLBox(); 264*cdf0e10cSrcweir pURLBox->Clear(); 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > lList = SvtHistoryOptions().GetList(eHISTORY); 267*cdf0e10cSrcweir for (sal_Int32 i=0; i<lList.getLength(); ++i) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lProps = lList[i]; 270*cdf0e10cSrcweir for (sal_Int32 p=0; p<lProps.getLength(); ++p) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir if (lProps[p].Name != HISTORY_PROPERTYNAME_URL) 273*cdf0e10cSrcweir continue; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir ::rtl::OUString sURL; 276*cdf0e10cSrcweir if (!(lProps[p].Value>>=sURL) || !sURL.getLength()) 277*cdf0e10cSrcweir continue; 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir INetURLObject aURL ( sURL ); 280*cdf0e10cSrcweir String sMainURL( aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET ) ); 281*cdf0e10cSrcweir String sFile; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir if (::utl::LocalFileHelper::ConvertURLToSystemPath(sMainURL,sFile)) 284*cdf0e10cSrcweir pURLBox->InsertEntry(sFile); 285*cdf0e10cSrcweir else 286*cdf0e10cSrcweir pURLBox->InsertEntry(sMainURL); 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir const SfxStringItem *pURL = PTR_CAST(SfxStringItem,pState); 291*cdf0e10cSrcweir String aRep( pURL->GetValue() ); 292*cdf0e10cSrcweir INetURLObject aURL( aRep ); 293*cdf0e10cSrcweir INetProtocol eProt = aURL.GetProtocol(); 294*cdf0e10cSrcweir if ( eProt == INET_PROT_FILE ) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir pURLBox->SetText( aURL.PathToFileName() ); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir else 299*cdf0e10cSrcweir pURLBox->SetText( aURL.GetURLNoPass() ); 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304