1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10*b3f79822SAndrew Rist *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19*b3f79822SAndrew Rist *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #undef SC_DLLIMPLEMENTATION
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir
31cdf0e10cSrcweir //------------------------------------------------------------------
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <sfx2/app.hxx>
34cdf0e10cSrcweir #include <sfx2/docfile.hxx>
35cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
36cdf0e10cSrcweir #include <sfx2/docinsert.hxx>
37cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
38cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
39cdf0e10cSrcweir #include <svtools/ehdl.hxx>
40cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
41cdf0e10cSrcweir #include <vcl/waitobj.hxx>
42cdf0e10cSrcweir
43cdf0e10cSrcweir #include "linkarea.hxx"
44cdf0e10cSrcweir #include "linkarea.hrc"
45cdf0e10cSrcweir #include "scresid.hxx"
46cdf0e10cSrcweir #include "sc.hrc"
47cdf0e10cSrcweir #include "rangeutl.hxx"
48cdf0e10cSrcweir #include "docsh.hxx"
49cdf0e10cSrcweir #include "tablink.hxx"
50cdf0e10cSrcweir
51cdf0e10cSrcweir //==================================================================
52cdf0e10cSrcweir
ScLinkedAreaDlg(Window * pParent)53cdf0e10cSrcweir ScLinkedAreaDlg::ScLinkedAreaDlg( Window* pParent ) :
54cdf0e10cSrcweir ModalDialog ( pParent, ScResId( RID_SCDLG_LINKAREA ) ),
55cdf0e10cSrcweir //
56cdf0e10cSrcweir aFlLocation ( this, ScResId( FL_LOCATION ) ),
57cdf0e10cSrcweir aCbUrl ( this, ScResId( CB_URL ) ),
58cdf0e10cSrcweir aBtnBrowse ( this, ScResId( BTN_BROWSE ) ),
59cdf0e10cSrcweir aTxtHint ( this, ScResId( FT_HINT ) ),
60cdf0e10cSrcweir aFtRanges ( this, ScResId( FT_RANGES ) ),
61cdf0e10cSrcweir aLbRanges ( this, ScResId( LB_RANGES ) ),
62cdf0e10cSrcweir aBtnReload ( this, ScResId( BTN_RELOAD ) ),
63cdf0e10cSrcweir aNfDelay ( this, ScResId( NF_DELAY ) ),
64cdf0e10cSrcweir aFtSeconds ( this, ScResId( FT_SECONDS ) ),
65cdf0e10cSrcweir aBtnOk ( this, ScResId( BTN_OK ) ),
66cdf0e10cSrcweir aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
67cdf0e10cSrcweir aBtnHelp ( this, ScResId( BTN_HELP ) ),
68cdf0e10cSrcweir //
69cdf0e10cSrcweir pSourceShell( NULL ),
70cdf0e10cSrcweir pDocInserter( NULL )
71cdf0e10cSrcweir
72cdf0e10cSrcweir {
73cdf0e10cSrcweir FreeResource();
74cdf0e10cSrcweir
75cdf0e10cSrcweir aCbUrl.SetHelpId( HID_SCDLG_LINKAREAURL ); // SvtURLBox ctor always sets SID_OPENURL
76cdf0e10cSrcweir aCbUrl.SetSelectHdl( LINK( this, ScLinkedAreaDlg, FileHdl ) );
77cdf0e10cSrcweir aBtnBrowse.SetClickHdl( LINK( this, ScLinkedAreaDlg, BrowseHdl ) );
78cdf0e10cSrcweir aLbRanges.SetSelectHdl( LINK( this, ScLinkedAreaDlg, RangeHdl ) );
79cdf0e10cSrcweir aBtnReload.SetClickHdl( LINK( this, ScLinkedAreaDlg, ReloadHdl ) );
80cdf0e10cSrcweir UpdateEnable();
81cdf0e10cSrcweir
82cdf0e10cSrcweir aNfDelay.SetAccessibleName(aBtnReload.GetText());
83cdf0e10cSrcweir aNfDelay.SetAccessibleRelationLabeledBy(&aBtnReload);
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
~ScLinkedAreaDlg()86cdf0e10cSrcweir ScLinkedAreaDlg::~ScLinkedAreaDlg()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir // pSourceShell is deleted by aSourceRef
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
Execute()91cdf0e10cSrcweir short ScLinkedAreaDlg::Execute()
92cdf0e10cSrcweir {
93cdf0e10cSrcweir // set parent for file dialog or filter options
94cdf0e10cSrcweir
95cdf0e10cSrcweir Window* pOldDefParent = Application::GetDefDialogParent();
96cdf0e10cSrcweir Application::SetDefDialogParent( this );
97cdf0e10cSrcweir
98cdf0e10cSrcweir short nRet = ModalDialog::Execute();
99cdf0e10cSrcweir
100cdf0e10cSrcweir Application::SetDefDialogParent( pOldDefParent );
101cdf0e10cSrcweir
102cdf0e10cSrcweir return nRet;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
105cdf0e10cSrcweir #define FILTERNAME_HTML "HTML (StarCalc)"
106cdf0e10cSrcweir #define FILTERNAME_QUERY "calc_HTML_WebQuery"
107cdf0e10cSrcweir
IMPL_LINK(ScLinkedAreaDlg,BrowseHdl,PushButton *,EMPTYARG)108cdf0e10cSrcweir IMPL_LINK( ScLinkedAreaDlg, BrowseHdl, PushButton*, EMPTYARG )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir if ( !pDocInserter )
111cdf0e10cSrcweir pDocInserter = new sfx2::DocumentInserter(
112cdf0e10cSrcweir 0, String::CreateFromAscii( ScDocShell::Factory().GetShortName() ) );
113cdf0e10cSrcweir pDocInserter->StartExecuteModal( LINK( this, ScLinkedAreaDlg, DialogClosedHdl ) );
114cdf0e10cSrcweir return 0;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir
IMPL_LINK(ScLinkedAreaDlg,FileHdl,ComboBox *,EMPTYARG)117cdf0e10cSrcweir IMPL_LINK( ScLinkedAreaDlg, FileHdl, ComboBox*, EMPTYARG )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir String aEntered = aCbUrl.GetURL();
120cdf0e10cSrcweir if (pSourceShell)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir SfxMedium* pMed = pSourceShell->GetMedium();
123cdf0e10cSrcweir if ( pMed->GetName() == aEntered )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir // already loaded - nothing to do
126cdf0e10cSrcweir return 0;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
130cdf0e10cSrcweir String aFilter;
131cdf0e10cSrcweir String aOptions;
132cdf0e10cSrcweir // get filter name by looking at the file content (bWithContent = sal_True)
133cdf0e10cSrcweir // Break operation if any error occured inside.
134cdf0e10cSrcweir if (!ScDocumentLoader::GetFilterName( aEntered, aFilter, aOptions, sal_True, sal_True ))
135cdf0e10cSrcweir return 0;
136cdf0e10cSrcweir
137cdf0e10cSrcweir // #i53241# replace HTML filter with DataQuery filter
138cdf0e10cSrcweir if( aFilter.EqualsAscii( FILTERNAME_HTML ) )
139cdf0e10cSrcweir aFilter.AssignAscii( FILTERNAME_QUERY );
140cdf0e10cSrcweir
141cdf0e10cSrcweir LoadDocument( aEntered, aFilter, aOptions );
142cdf0e10cSrcweir
143cdf0e10cSrcweir UpdateSourceRanges();
144cdf0e10cSrcweir UpdateEnable();
145cdf0e10cSrcweir return 0;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
LoadDocument(const String & rFile,const String & rFilter,const String & rOptions)148cdf0e10cSrcweir void ScLinkedAreaDlg::LoadDocument( const String& rFile, const String& rFilter, const String& rOptions )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir if ( pSourceShell )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir // unload old document
153cdf0e10cSrcweir pSourceShell->DoClose();
154cdf0e10cSrcweir pSourceShell = NULL;
155cdf0e10cSrcweir aSourceRef.Clear();
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
158cdf0e10cSrcweir if ( rFile.Len() )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir WaitObject aWait( this );
161cdf0e10cSrcweir
162cdf0e10cSrcweir String aNewFilter = rFilter;
163cdf0e10cSrcweir String aNewOptions = rOptions;
164cdf0e10cSrcweir
165cdf0e10cSrcweir SfxErrorContext aEc( ERRCTX_SFX_OPENDOC, rFile );
166cdf0e10cSrcweir
167cdf0e10cSrcweir ScDocumentLoader aLoader( rFile, aNewFilter, aNewOptions, 0, sal_True ); // with interaction
168cdf0e10cSrcweir pSourceShell = aLoader.GetDocShell();
169cdf0e10cSrcweir if ( pSourceShell )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir sal_uLong nErr = pSourceShell->GetErrorCode();
172cdf0e10cSrcweir if (nErr)
173cdf0e10cSrcweir ErrorHandler::HandleError( nErr ); // including warnings
174cdf0e10cSrcweir
175cdf0e10cSrcweir aSourceRef = pSourceShell;
176cdf0e10cSrcweir aLoader.ReleaseDocRef(); // don't call DoClose in DocLoader dtor
177cdf0e10cSrcweir }
178cdf0e10cSrcweir }
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
InitFromOldLink(const String & rFile,const String & rFilter,const String & rOptions,const String & rSource,sal_uLong nRefresh)181cdf0e10cSrcweir void ScLinkedAreaDlg::InitFromOldLink( const String& rFile, const String& rFilter,
182cdf0e10cSrcweir const String& rOptions, const String& rSource,
183cdf0e10cSrcweir sal_uLong nRefresh )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir LoadDocument( rFile, rFilter, rOptions );
186cdf0e10cSrcweir if (pSourceShell)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir SfxMedium* pMed = pSourceShell->GetMedium();
189cdf0e10cSrcweir aCbUrl.SetText( pMed->GetName() );
190cdf0e10cSrcweir }
191cdf0e10cSrcweir else
192cdf0e10cSrcweir aCbUrl.SetText( EMPTY_STRING );
193cdf0e10cSrcweir
194cdf0e10cSrcweir UpdateSourceRanges();
195cdf0e10cSrcweir
196cdf0e10cSrcweir xub_StrLen nRangeCount = rSource.GetTokenCount();
197cdf0e10cSrcweir for ( xub_StrLen i=0; i<nRangeCount; i++ )
198cdf0e10cSrcweir {
199cdf0e10cSrcweir String aRange = rSource.GetToken(i);
200cdf0e10cSrcweir aLbRanges.SelectEntry( aRange );
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir sal_Bool bDoRefresh = ( nRefresh != 0 );
204cdf0e10cSrcweir aBtnReload.Check( bDoRefresh );
205cdf0e10cSrcweir if (bDoRefresh)
206cdf0e10cSrcweir aNfDelay.SetValue( nRefresh );
207cdf0e10cSrcweir
208cdf0e10cSrcweir UpdateEnable();
209cdf0e10cSrcweir }
210cdf0e10cSrcweir
IMPL_LINK(ScLinkedAreaDlg,RangeHdl,MultiListBox *,EMPTYARG)211cdf0e10cSrcweir IMPL_LINK( ScLinkedAreaDlg, RangeHdl, MultiListBox*, EMPTYARG )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir UpdateEnable();
214cdf0e10cSrcweir return 0;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
IMPL_LINK(ScLinkedAreaDlg,ReloadHdl,CheckBox *,EMPTYARG)217cdf0e10cSrcweir IMPL_LINK( ScLinkedAreaDlg, ReloadHdl, CheckBox*, EMPTYARG )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir UpdateEnable();
220cdf0e10cSrcweir return 0;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir
IMPL_LINK(ScLinkedAreaDlg,DialogClosedHdl,sfx2::FileDialogHelper *,_pFileDlg)223cdf0e10cSrcweir IMPL_LINK( ScLinkedAreaDlg, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir if ( _pFileDlg->GetError() != ERRCODE_NONE )
226cdf0e10cSrcweir return 0;
227cdf0e10cSrcweir
228cdf0e10cSrcweir SfxMedium* pMed = pDocInserter->CreateMedium();
229cdf0e10cSrcweir if ( pMed )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir WaitObject aWait( this );
232cdf0e10cSrcweir
233cdf0e10cSrcweir // #92296# replace HTML filter with DataQuery filter
234cdf0e10cSrcweir const String aHTMLFilterName( RTL_CONSTASCII_USTRINGPARAM( FILTERNAME_HTML ) );
235cdf0e10cSrcweir const String aWebQFilterName( RTL_CONSTASCII_USTRINGPARAM( FILTERNAME_QUERY ) );
236cdf0e10cSrcweir
237cdf0e10cSrcweir const SfxFilter* pFilter = pMed->GetFilter();
238cdf0e10cSrcweir if( pFilter && (pFilter->GetFilterName() == aHTMLFilterName) )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir const SfxFilter* pNewFilter =
241cdf0e10cSrcweir ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aWebQFilterName );
242cdf0e10cSrcweir if( pNewFilter )
243cdf0e10cSrcweir pMed->SetFilter( pNewFilter );
244cdf0e10cSrcweir }
245cdf0e10cSrcweir
246cdf0e10cSrcweir // ERRCTX_SFX_OPENDOC -> "Fehler beim Laden des Dokumentes"
247cdf0e10cSrcweir SfxErrorContext aEc( ERRCTX_SFX_OPENDOC, pMed->GetName() );
248cdf0e10cSrcweir
249cdf0e10cSrcweir if (pSourceShell)
250cdf0e10cSrcweir pSourceShell->DoClose(); // deleted when assigning aSourceRef
251cdf0e10cSrcweir
252cdf0e10cSrcweir pMed->UseInteractionHandler( sal_True ); // to enable the filter options dialog
253cdf0e10cSrcweir
254cdf0e10cSrcweir pSourceShell = new ScDocShell;
255cdf0e10cSrcweir aSourceRef = pSourceShell;
256cdf0e10cSrcweir pSourceShell->DoLoad( pMed );
257cdf0e10cSrcweir
258cdf0e10cSrcweir sal_uLong nErr = pSourceShell->GetErrorCode();
259cdf0e10cSrcweir if (nErr)
260cdf0e10cSrcweir ErrorHandler::HandleError( nErr ); // including warnings
261cdf0e10cSrcweir
262cdf0e10cSrcweir if ( !pSourceShell->GetError() ) // only errors
263cdf0e10cSrcweir {
264cdf0e10cSrcweir //aCbUrl.SetText( pSourceShell->GetTitle( SFX_TITLE_FULLNAME ) );
265cdf0e10cSrcweir aCbUrl.SetText( pMed->GetName() );
266cdf0e10cSrcweir }
267cdf0e10cSrcweir else
268cdf0e10cSrcweir {
269cdf0e10cSrcweir pSourceShell->DoClose();
270cdf0e10cSrcweir pSourceShell = NULL;
271cdf0e10cSrcweir aSourceRef.Clear();
272cdf0e10cSrcweir
273cdf0e10cSrcweir aCbUrl.SetText( EMPTY_STRING );
274cdf0e10cSrcweir }
275cdf0e10cSrcweir }
276cdf0e10cSrcweir
277cdf0e10cSrcweir UpdateSourceRanges();
278cdf0e10cSrcweir UpdateEnable();
279cdf0e10cSrcweir return 0;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir
282cdf0e10cSrcweir #undef FILTERNAME_HTML
283cdf0e10cSrcweir #undef FILTERNAME_QUERY
284cdf0e10cSrcweir
UpdateSourceRanges()285cdf0e10cSrcweir void ScLinkedAreaDlg::UpdateSourceRanges()
286cdf0e10cSrcweir {
287cdf0e10cSrcweir aLbRanges.SetUpdateMode( sal_False );
288cdf0e10cSrcweir
289cdf0e10cSrcweir aLbRanges.Clear();
290cdf0e10cSrcweir if ( pSourceShell )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir ScAreaNameIterator aIter( pSourceShell->GetDocument() );
293cdf0e10cSrcweir ScRange aDummy;
294cdf0e10cSrcweir String aName;
295cdf0e10cSrcweir while ( aIter.Next( aName, aDummy ) )
296cdf0e10cSrcweir aLbRanges.InsertEntry( aName );
297cdf0e10cSrcweir }
298cdf0e10cSrcweir
299cdf0e10cSrcweir aLbRanges.SetUpdateMode( sal_True );
300cdf0e10cSrcweir
301cdf0e10cSrcweir if ( aLbRanges.GetEntryCount() == 1 )
302cdf0e10cSrcweir aLbRanges.SelectEntryPos(0);
303cdf0e10cSrcweir }
304cdf0e10cSrcweir
UpdateEnable()305cdf0e10cSrcweir void ScLinkedAreaDlg::UpdateEnable()
306cdf0e10cSrcweir {
307cdf0e10cSrcweir sal_Bool bEnable = ( pSourceShell && aLbRanges.GetSelectEntryCount() );
308cdf0e10cSrcweir aBtnOk.Enable( bEnable );
309cdf0e10cSrcweir
310cdf0e10cSrcweir sal_Bool bReload = aBtnReload.IsChecked();
311cdf0e10cSrcweir aNfDelay.Enable( bReload );
312cdf0e10cSrcweir aFtSeconds.Enable( bReload );
313cdf0e10cSrcweir }
314cdf0e10cSrcweir
GetURL()315cdf0e10cSrcweir String ScLinkedAreaDlg::GetURL()
316cdf0e10cSrcweir {
317cdf0e10cSrcweir if (pSourceShell)
318cdf0e10cSrcweir {
319cdf0e10cSrcweir SfxMedium* pMed = pSourceShell->GetMedium();
320cdf0e10cSrcweir return pMed->GetName();
321cdf0e10cSrcweir }
322cdf0e10cSrcweir return EMPTY_STRING;
323cdf0e10cSrcweir }
324cdf0e10cSrcweir
GetFilter()325cdf0e10cSrcweir String ScLinkedAreaDlg::GetFilter()
326cdf0e10cSrcweir {
327cdf0e10cSrcweir if (pSourceShell)
328cdf0e10cSrcweir {
329cdf0e10cSrcweir SfxMedium* pMed = pSourceShell->GetMedium();
330cdf0e10cSrcweir return pMed->GetFilter()->GetFilterName();
331cdf0e10cSrcweir }
332cdf0e10cSrcweir return EMPTY_STRING;
333cdf0e10cSrcweir }
334cdf0e10cSrcweir
GetOptions()335cdf0e10cSrcweir String ScLinkedAreaDlg::GetOptions()
336cdf0e10cSrcweir {
337cdf0e10cSrcweir if (pSourceShell)
338cdf0e10cSrcweir {
339cdf0e10cSrcweir SfxMedium* pMed = pSourceShell->GetMedium();
340cdf0e10cSrcweir return ScDocumentLoader::GetOptions( *pMed );
341cdf0e10cSrcweir }
342cdf0e10cSrcweir return EMPTY_STRING;
343cdf0e10cSrcweir }
344cdf0e10cSrcweir
GetSource()345cdf0e10cSrcweir String ScLinkedAreaDlg::GetSource()
346cdf0e10cSrcweir {
347cdf0e10cSrcweir String aSource;
348cdf0e10cSrcweir sal_uInt16 nCount = aLbRanges.GetSelectEntryCount();
349cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++)
350cdf0e10cSrcweir {
351cdf0e10cSrcweir if (i > 0)
352cdf0e10cSrcweir aSource.Append( (sal_Unicode) ';' );
353cdf0e10cSrcweir aSource.Append( aLbRanges.GetSelectEntry( i ) );
354cdf0e10cSrcweir }
355cdf0e10cSrcweir return aSource;
356cdf0e10cSrcweir }
357cdf0e10cSrcweir
GetRefresh()358cdf0e10cSrcweir sal_uLong ScLinkedAreaDlg::GetRefresh()
359cdf0e10cSrcweir {
360cdf0e10cSrcweir if ( aBtnReload.IsChecked() )
361cdf0e10cSrcweir return sal::static_int_cast<sal_uLong>( aNfDelay.GetValue() );
362cdf0e10cSrcweir else
363cdf0e10cSrcweir return 0; // disabled
364cdf0e10cSrcweir }
365cdf0e10cSrcweir
366