1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: inettbc.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include "inettbc.hxx"
38 #include <com/sun/star/uno/Any.h>
39 #ifndef _COM_SUN_STAR_FRAME_XFRAMESSUPLLIER_HPP_
40 #include <com/sun/star/frame/XFramesSupplier.hpp>
42 #include <com/sun/star/task/XInteractionHandler.hpp>
43 #include <svtools/eitem.hxx>
44 #include <svtools/stritem.hxx>
45 #include <svtools/cancel.hxx>
46 #include <svtools/historyoptions.hxx>
47 #include <svtools/folderrestriction.hxx>
48 #include <vcl/toolbox.hxx>
49 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
50 #include <toolkit/unohlp.hxx>
52 #ifndef _VOS_THREAD_HXX //autogen
53 #include <vos/thread.hxx>
55 #ifndef _VOS_MUTEX_HXX //autogen
56 #include <vos/mutex.hxx>
58 #include <rtl/ustring.hxx>
60 #include <svtools/itemset.hxx>
61 #include <svtools/urihelper.hxx>
62 #include <svtools/pathoptions.hxx>
63 #include <svtools/asynclink.hxx>
64 #include <svtools/inettbc.hxx>
66 #include <unotools/localfilehelper.hxx>
67 #include <comphelper/processfactory.hxx>
69 #include <sfx2/sfx.hrc>
70 #include <sfx2/dispatch.hxx>
71 #include <sfx2/viewfrm.hxx>
72 #include <sfx2/objsh.hxx>
73 #include "referers.hxx"
74 #include "sfxtypes.hxx"
77 using namespace ::com::sun::star::uno
;
78 using namespace ::com::sun::star::beans
;
79 using namespace ::com::sun::star::util
;
80 using namespace ::com::sun::star::frame
;
81 using namespace ::com::sun::star::task
;
83 //***************************************************************************
84 // SfxURLToolBoxControl_Impl
85 //***************************************************************************
87 SFX_IMPL_TOOLBOX_CONTROL(SfxURLToolBoxControl_Impl
,SfxStringItem
)
89 SfxURLToolBoxControl_Impl::SfxURLToolBoxControl_Impl( USHORT nSlotId
, USHORT nId
, ToolBox
& rBox
)
90 : SfxToolBoxControl( nSlotId
, nId
, rBox
),
93 addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CurrentURL" )));
96 SfxURLToolBoxControl_Impl::~SfxURLToolBoxControl_Impl()
101 SvtURLBox
* SfxURLToolBoxControl_Impl::GetURLBox() const
103 return (SvtURLBox
*)GetToolBox().GetItemWindow( GetId() );
106 //***************************************************************************
108 void SfxURLToolBoxControl_Impl::OpenURL( const String
& rName
, BOOL
/*bNew*/ ) const
114 INetURLObject
aObj( rName
);
115 if ( aObj
.GetProtocol() == INET_PROT_NOT_VALID
)
117 String aBaseURL
= GetURLBox()->GetBaseURL();
118 aName
= SvtURLBox::ParseSmart( rName
, aBaseURL
, SvtPathOptions().GetWorkPath() );
126 Reference
< XDispatchProvider
> xDispatchProvider( getFrameInterface(), UNO_QUERY
);
127 if ( xDispatchProvider
.is() && m_xServiceManager
.is() )
130 ::rtl::OUString
aTarget( ::rtl::OUString::createFromAscii( "_default" ));
132 aTargetURL
.Complete
= aName
;
134 getURLTransformer()->parseStrict( aTargetURL
);
135 Reference
< XDispatch
> xDispatch
= xDispatchProvider
->queryDispatch( aTargetURL
, aTarget
, 0 );
136 if ( xDispatch
.is() )
138 Sequence
< PropertyValue
> aArgs( 2 );
139 aArgs
[0].Name
= ::rtl::OUString::createFromAscii( "Referer" );
140 aArgs
[0].Value
= makeAny( ::rtl::OUString::createFromAscii( SFX_REFERER_USER
));
141 aArgs
[1].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" ));
142 aArgs
[1].Value
= makeAny( ::rtl::OUString( aName
));
147 aArgs
[2].Name
= ::rtl::OUString::createFromAscii( "FilterOptions" );
148 aArgs
[2].Value
= makeAny( ::rtl::OUString( aOptions
));
149 aArgs
[3].Name
= ::rtl::OUString::createFromAscii( "FilterName" );
150 aArgs
[3].Value
= makeAny( ::rtl::OUString( aFilter
));
153 SfxURLToolBoxControl_Impl::ExecuteInfo
* pExecuteInfo
= new SfxURLToolBoxControl_Impl::ExecuteInfo
;
154 pExecuteInfo
->xDispatch
= xDispatch
;
155 pExecuteInfo
->aTargetURL
= aTargetURL
;
156 pExecuteInfo
->aArgs
= aArgs
;
157 Application::PostUserEvent( STATIC_LINK( 0, SfxURLToolBoxControl_Impl
, ExecuteHdl_Impl
), pExecuteInfo
);
162 //--------------------------------------------------------------------
164 IMPL_STATIC_LINK_NOINSTANCE( SfxURLToolBoxControl_Impl
, ExecuteHdl_Impl
, ExecuteInfo
*, pExecuteInfo
)
168 // Asynchronous execution as this can lead to our own destruction!
169 // Framework can recycle our current frame and the layout manager disposes all user interface
170 // elements if a component gets detached from its frame!
171 pExecuteInfo
->xDispatch
->dispatch( pExecuteInfo
->aTargetURL
, pExecuteInfo
->aArgs
);
182 Window
* SfxURLToolBoxControl_Impl::CreateItemWindow( Window
* pParent
)
184 SvtURLBox
* pURLBox
= new SvtURLBox( pParent
);
185 pURLBox
->SetOpenHdl( LINK( this, SfxURLToolBoxControl_Impl
, OpenHdl
) );
186 pURLBox
->SetSelectHdl( LINK( this, SfxURLToolBoxControl_Impl
, SelectHdl
) );
191 IMPL_LINK( SfxURLToolBoxControl_Impl
, SelectHdl
, void*, EMPTYARG
)
193 SvtURLBox
* pURLBox
= GetURLBox();
194 String
aName( pURLBox
->GetURL() );
196 if ( !pURLBox
->IsTravelSelect() && aName
.Len() )
197 OpenURL( aName
, FALSE
);
202 IMPL_LINK( SfxURLToolBoxControl_Impl
, OpenHdl
, void*, EMPTYARG
)
204 SvtURLBox
* pURLBox
= GetURLBox();
205 OpenURL( pURLBox
->GetURL(), pURLBox
->IsCtrlOpen() );
207 if ( m_xServiceManager
.is() )
209 Reference
< XFramesSupplier
> xDesktop( m_xServiceManager
->createInstance(
210 ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" )),
212 Reference
< XFrame
> xFrame( xDesktop
->getActiveFrame(), UNO_QUERY
);
215 Window
* pWin
= VCLUnoHelper::GetWindow( xFrame
->getContainerWindow() );
219 pWin
->ToTop( TOTOP_RESTOREWHENMIN
);
227 IMPL_LINK( SfxURLToolBoxControl_Impl
, WindowEventListener
, VclSimpleEvent
*, pEvent
)
231 pEvent
->ISA( VclWindowEvent
) &&
232 ( pEvent
->GetId() == VCLEVENT_WINDOW_KEYINPUT
))
234 VclWindowEvent
* pWinEvent
= static_cast< VclWindowEvent
* >( pEvent
);
235 KeyEvent
* pKeyEvent
= static_cast< KeyEvent
* >( pWinEvent
->GetData() );
237 pAccExec
->execute( pKeyEvent
->GetKeyCode() );
243 //***************************************************************************
245 void SfxURLToolBoxControl_Impl::StateChanged
249 const SfxPoolItem
* pState
252 if ( nSID
== SID_OPENURL
)
254 // Disable URL box if command is disabled #111014#
255 GetURLBox()->Enable( SFX_ITEM_DISABLED
!= eState
);
258 if ( GetURLBox()->IsEnabled() )
260 if( nSID
== SID_FOCUSURLBOX
)
262 if ( GetURLBox()->IsVisible() )
263 GetURLBox()->GrabFocus();
265 else if ( !GetURLBox()->IsModified() && SFX_ITEM_AVAILABLE
== eState
)
267 SvtURLBox
* pURLBox
= GetURLBox();
270 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> > lList
= SvtHistoryOptions().GetList(eHISTORY
);
271 for (sal_Int32 i
=0; i
<lList
.getLength(); ++i
)
273 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> lProps
= lList
[i
];
274 for (sal_Int32 p
=0; p
<lProps
.getLength(); ++p
)
276 if (lProps
[p
].Name
!= HISTORY_PROPERTYNAME_URL
)
279 ::rtl::OUString sURL
;
280 if (!(lProps
[p
].Value
>>=sURL
) || !sURL
.getLength())
283 INetURLObject
aURL ( sURL
);
284 String
sMainURL( aURL
.GetMainURL( INetURLObject::DECODE_WITH_CHARSET
) );
287 if (::utl::LocalFileHelper::ConvertURLToSystemPath(sMainURL
,sFile
))
288 pURLBox
->InsertEntry(sFile
);
290 pURLBox
->InsertEntry(sMainURL
);
294 const SfxStringItem
*pURL
= PTR_CAST(SfxStringItem
,pState
);
295 String
aRep( pURL
->GetValue() );
296 INetURLObject
aURL( aRep
);
297 INetProtocol eProt
= aURL
.GetProtocol();
298 if ( eProt
== INET_PROT_FILE
)
300 pURLBox
->SetText( aURL
.PathToFileName() );
303 pURLBox
->SetText( aURL
.GetURLNoPass() );
308 //***************************************************************************
309 // SfxCancelToolBoxControl_Impl
310 //***************************************************************************
312 SFX_IMPL_TOOLBOX_CONTROL(SfxCancelToolBoxControl_Impl
,SfxBoolItem
)
314 //***************************************************************************
316 SfxCancelToolBoxControl_Impl::SfxCancelToolBoxControl_Impl( USHORT nSlotId
, USHORT nId
, ToolBox
& rBox
) :
317 SfxToolBoxControl( nSlotId
, nId
, rBox
)
321 //***************************************************************************
323 SfxPopupWindowType
SfxCancelToolBoxControl_Impl::GetPopupWindowType() const
325 return SFX_POPUPWINDOW_ONTIMEOUT
;
328 //***************************************************************************
330 SfxPopupWindow
* SfxCancelToolBoxControl_Impl::CreatePopupWindow()
333 BOOL bExecute
= FALSE
, bSeparator
= FALSE
;
335 for ( SfxCancelManager
*pCancelMgr
= SfxViewFrame::Current()->GetTopViewFrame()->GetCancelManager();
337 pCancelMgr
= pCancelMgr
->GetParent() )
339 for ( USHORT n
=0; n
<pCancelMgr
->GetCancellableCount(); ++n
)
341 if ( !n
&& bSeparator
)
343 aMenu
.InsertSeparator();
346 String aItemText
= pCancelMgr
->GetCancellable(n
)->GetTitle();
347 if ( aItemText
.Len() > 50 )
349 aItemText
.Erase( 48 );
350 aItemText
+= DEFINE_CONST_UNICODE("...");
352 aMenu
.InsertItem( nIndex
++, aItemText
);
358 ToolBox
& rToolBox
= GetToolBox();
359 USHORT nId
= bExecute
? aMenu
.Execute( &rToolBox
, rToolBox
.GetPointerPosPixel() ) : 0;
360 GetToolBox().EndSelection();
365 String aSearchText
= aMenu
.GetItemText(nId
);
366 for ( SfxCancelManager
*pCancelMgr
= SfxViewFrame::Current()->GetTopViewFrame()->GetCancelManager();
368 pCancelMgr
= pCancelMgr
->GetParent() )
370 for ( USHORT n
= 0; n
< pCancelMgr
->GetCancellableCount(); ++n
)
372 SfxCancellable
*pCancel
= pCancelMgr
->GetCancellable(n
);
373 String aItemText
= pCancel
->GetTitle();
374 if ( aItemText
.Len() > 50 )
376 aItemText
.Erase( 48 );
377 aItemText
+= DEFINE_CONST_UNICODE("...");
380 if ( aItemText
== aSearchText
)
393 //***************************************************************************
395 void SfxCancelToolBoxControl_Impl::StateChanged
399 const SfxPoolItem
* pState
402 SfxVoidItem
aVoidItem( nSID
);
403 //SfxToolBoxControl::StateChanged( nSID, eState, pState ? &aVoidItem : 0 );
404 SfxToolBoxControl::StateChanged( nSID
, eState
, pState
);