/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include "inettbc.hxx" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "referers.hxx" #include "sfxtypes.hxx" #include "helper.hxx" using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::util; using namespace ::com::sun::star::frame; using namespace ::com::sun::star::task; //*************************************************************************** // SfxURLToolBoxControl_Impl //*************************************************************************** SFX_IMPL_TOOLBOX_CONTROL(SfxURLToolBoxControl_Impl,SfxStringItem) SfxURLToolBoxControl_Impl::SfxURLToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox ) : SfxToolBoxControl( nSlotId, nId, rBox ), pAccExec( 0 ) { addStatusListener( rtl::OUString( ".uno:CurrentURL" )); } SfxURLToolBoxControl_Impl::~SfxURLToolBoxControl_Impl() { delete pAccExec; } SvtURLBox* SfxURLToolBoxControl_Impl::GetURLBox() const { return (SvtURLBox*)GetToolBox().GetItemWindow( GetId() ); } //*************************************************************************** void SfxURLToolBoxControl_Impl::OpenURL( const String& rName, sal_Bool /*bNew*/ ) const { String aName; String aFilter; String aOptions; INetURLObject aObj( rName ); if ( aObj.GetProtocol() == INET_PROT_NOT_VALID ) { String aBaseURL = GetURLBox()->GetBaseURL(); aName = SvtURLBox::ParseSmart( rName, aBaseURL, SvtPathOptions().GetWorkPath() ); } else aName = rName; if ( !aName.Len() ) return; Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY ); if ( xDispatchProvider.is() && m_xServiceManager.is() ) { URL aTargetURL; ::rtl::OUString aTarget( ::rtl::OUString("_default")); aTargetURL.Complete = aName; getURLTransformer()->parseStrict( aTargetURL ); Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTarget, 0 ); if ( xDispatch.is() ) { Sequence< PropertyValue > aArgs( 2 ); aArgs[0].Name = ::rtl::OUString("Referer"); aArgs[0].Value = makeAny( ::rtl::OUString(SFX_REFERER_USER )); aArgs[1].Name = ::rtl::OUString( "FileName" ); aArgs[1].Value = makeAny( ::rtl::OUString( aName )); if ( aFilter.Len() ) { aArgs.realloc( 4 ); aArgs[2].Name = ::rtl::OUString("FilterOptions"); aArgs[2].Value = makeAny( ::rtl::OUString( aOptions )); aArgs[3].Name = ::rtl::OUString("FilterName"); aArgs[3].Value = makeAny( ::rtl::OUString( aFilter )); } SfxURLToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxURLToolBoxControl_Impl::ExecuteInfo; pExecuteInfo->xDispatch = xDispatch; pExecuteInfo->aTargetURL = aTargetURL; pExecuteInfo->aArgs = aArgs; Application::PostUserEvent( STATIC_LINK( 0, SfxURLToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo ); } } } //-------------------------------------------------------------------- IMPL_STATIC_LINK_NOINSTANCE( SfxURLToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo ) { try { // Asynchronous execution as this can lead to our own destruction! // Framework can recycle our current frame and the layout manager disposes all user interface // elements if a component gets detached from its frame! pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs ); } catch ( Exception& ) { } delete pExecuteInfo; return 0; } Window* SfxURLToolBoxControl_Impl::CreateItemWindow( Window* pParent ) { SvtURLBox* pURLBox = new SvtURLBox( pParent ); pURLBox->SetOpenHdl( LINK( this, SfxURLToolBoxControl_Impl, OpenHdl ) ); pURLBox->SetSelectHdl( LINK( this, SfxURLToolBoxControl_Impl, SelectHdl ) ); return pURLBox; } IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, SelectHdl) { SvtURLBox* pURLBox = GetURLBox(); String aName( pURLBox->GetURL() ); if ( !pURLBox->IsTravelSelect() && aName.Len() ) OpenURL( aName, sal_False ); return 1L; } IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, OpenHdl) { SvtURLBox* pURLBox = GetURLBox(); OpenURL( pURLBox->GetURL(), pURLBox->IsCtrlOpen() ); if ( m_xServiceManager.is() ) { Reference< XFramesSupplier > xDesktop( m_xServiceManager->createInstance( ::rtl::OUString("com.sun.star.frame.Desktop")), UNO_QUERY ); Reference< XFrame > xFrame( xDesktop->getActiveFrame(), UNO_QUERY ); if ( xFrame.is() ) { Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); if ( pWin ) { pWin->GrabFocus(); pWin->ToTop( TOTOP_RESTOREWHENMIN ); } } } return 1L; } //*************************************************************************** void SfxURLToolBoxControl_Impl::StateChanged ( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) { if ( nSID == SID_OPENURL ) { // Disable URL box if command is disabled GetURLBox()->Enable( SFX_ITEM_DISABLED != eState ); } if ( GetURLBox()->IsEnabled() ) { if( nSID == SID_FOCUSURLBOX ) { if ( GetURLBox()->IsVisible() ) GetURLBox()->GrabFocus(); } else if ( !GetURLBox()->IsModified() && SFX_ITEM_AVAILABLE == eState ) { SvtURLBox* pURLBox = GetURLBox(); pURLBox->Clear(); ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > lList = SvtHistoryOptions().GetList(eHISTORY); for (sal_Int32 i=0; i lProps = lList[i]; for (sal_Int32 p=0; p>=sURL) || sURL.isEmpty()) continue; INetURLObject aURL ( sURL ); String sMainURL( aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET ) ); String sFile; if (::utl::LocalFileHelper::ConvertURLToSystemPath(sMainURL,sFile)) pURLBox->InsertEntry(sFile); else pURLBox->InsertEntry(sMainURL); } } const SfxStringItem *pURL = PTR_CAST(SfxStringItem,pState); String aRep( pURL->GetValue() ); INetURLObject aURL( aRep ); INetProtocol eProt = aURL.GetProtocol(); if ( eProt == INET_PROT_FILE ) { pURLBox->SetText( aURL.PathToFileName() ); } else pURLBox->SetText( aURL.GetURLNoPass() ); } } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */