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