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