1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
/* -*- 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 <com/sun/star/uno/Any.h>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XFramesSupplier.hpp>
#include <com/sun/star/task/XInteractionHandler.hpp>
#include <svl/eitem.hxx>
#include <svl/stritem.hxx>
#include <unotools/historyoptions.hxx>
#include <vcl/toolbox.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <osl/thread.hxx>
#include <osl/mutex.hxx>
#include <rtl/ustring.hxx>
#include <svl/itemset.hxx>
#include <svl/urihelper.hxx>
#include <unotools/pathoptions.hxx>
#include <svtools/asynclink.hxx>
#include <svtools/inettbc.hxx>
#include <unotools/localfilehelper.hxx>
#include <comphelper/processfactory.hxx>
#include <sfx2/sfx.hrc>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/objsh.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 )
{
addStatusListener( OUString( ".uno:CurrentURL" ));
}
SfxURLToolBoxControl_Impl::~SfxURLToolBoxControl_Impl()
{
}
SvtURLBox* SfxURLToolBoxControl_Impl::GetURLBox() const
{
return static_cast<SvtURLBox*>(GetToolBox().GetItemWindow( GetId() ));
}
void SfxURLToolBoxControl_Impl::OpenURL( const OUString& rName, bool /*bNew*/ ) const
{
OUString aName;
OUString aFilter;
OUString aOptions;
INetURLObject aObj( rName );
if ( aObj.GetProtocol() == INetProtocol::NotValid )
{
OUString aBaseURL = GetURLBox()->GetBaseURL();
aName = SvtURLBox::ParseSmart( rName, aBaseURL, SvtPathOptions().GetWorkPath() );
}
else
aName = rName;
if ( aName.isEmpty() )
return;
Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY );
if ( xDispatchProvider.is() )
{
URL aTargetURL;
OUString aTarget( "_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 = "Referer";
aArgs[0].Value = makeAny( OUString( "private:user" ));
aArgs[1].Name = "FileName";
aArgs[1].Value = makeAny( OUString( aName ));
if ( !aFilter.isEmpty() )
{
aArgs.realloc( 4 );
aArgs[2].Name = "FilterOptions";
aArgs[2].Value = makeAny( OUString( aOptions ));
aArgs[3].Name = "FilterName";
aArgs[3].Value = makeAny( OUString( aFilter ));
}
SfxURLToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxURLToolBoxControl_Impl::ExecuteInfo;
pExecuteInfo->xDispatch = xDispatch;
pExecuteInfo->aTargetURL = aTargetURL;
pExecuteInfo->aArgs = aArgs;
Application::PostUserEvent( 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;
}
VclPtr<vcl::Window> SfxURLToolBoxControl_Impl::CreateItemWindow( vcl::Window* pParent )
{
VclPtrInstance<SvtURLBox> pURLBox( pParent );
pURLBox->SetOpenHdl( LINK( this, SfxURLToolBoxControl_Impl, OpenHdl ) );
pURLBox->SetSelectHdl( LINK( this, SfxURLToolBoxControl_Impl, SelectHdl ) );
return pURLBox.get();
}
IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, SelectHdl)
{
SvtURLBox* pURLBox = GetURLBox();
OUString aName( pURLBox->GetURL() );
if ( !pURLBox->IsTravelSelect() && !aName.isEmpty() )
OpenURL( aName, false );
return 1L;
}
IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, OpenHdl)
{
SvtURLBox* pURLBox = GetURLBox();
OpenURL( pURLBox->GetURL(), pURLBox->IsCtrlOpen() );
Reference< XDesktop2 > xDesktop = Desktop::create( m_xContext );
Reference< XFrame > xFrame( xDesktop->getActiveFrame(), UNO_QUERY );
if ( xFrame.is() )
{
vcl::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( SfxItemState::DISABLED != eState );
}
if ( GetURLBox()->IsEnabled() )
{
if( nSID == SID_FOCUSURLBOX )
{
if ( GetURLBox()->IsVisible() )
GetURLBox()->GrabFocus();
}
else if ( !GetURLBox()->IsModified() && SfxItemState::DEFAULT == eState )
{
SvtURLBox* pURLBox = GetURLBox();
pURLBox->Clear();
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > lList = SvtHistoryOptions().GetList(ePICKLIST);
for (sal_Int32 i=0; i<lList.getLength(); ++i)
{
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lProps = lList[i];
for (sal_Int32 p=0; p<lProps.getLength(); ++p)
{
if (lProps[p].Name != HISTORY_PROPERTYNAME_URL)
continue;
OUString sURL;
if (!(lProps[p].Value>>=sURL) || sURL.isEmpty())
continue;
INetURLObject aURL ( sURL );
OUString sMainURL( aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET ) );
OUString sFile;
if (::utl::LocalFileHelper::ConvertURLToSystemPath(sMainURL,sFile))
pURLBox->InsertEntry(sFile);
else
pURLBox->InsertEntry(sMainURL);
}
}
const SfxStringItem *pURL = PTR_CAST(SfxStringItem,pState);
OUString aRep( pURL->GetValue() );
INetURLObject aURL( aRep );
INetProtocol eProt = aURL.GetProtocol();
if ( eProt == INetProtocol::File )
{
pURLBox->SetText( aURL.PathToFileName() );
}
else
pURLBox->SetText( aURL.GetURLNoPass() );
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|