Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/drawing/ModuleDispatcher.hpp>
21 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 : #include <com/sun/star/frame/DispatchHelper.hpp>
23 :
24 : #include <comphelper/processfactory.hxx>
25 :
26 : #include <hintids.hxx>
27 : #include <tools/urlobj.hxx>
28 : #include <unotools/tempfile.hxx>
29 : #include <vcl/wrkwin.hxx>
30 : #include <vcl/msgbox.hxx>
31 : #include <svl/lckbitem.hxx>
32 : #include <svl/eitem.hxx>
33 : #include <svl/zforlist.hxx>
34 : #include <svl/zformat.hxx>
35 : #include <unotools/pathoptions.hxx>
36 : #include <svtools/transfer.hxx>
37 : #include <sfx2/dialogs.hrc>
38 : #include <sfx2/dinfdlg.hxx>
39 : #include <sfx2/request.hxx>
40 : #include <sfx2/dispatch.hxx>
41 : #include <sfx2/new.hxx>
42 : #include <sfx2/filedlghelper.hxx>
43 : #include <sfx2/printer.hxx>
44 : #include <sfx2/evntconf.hxx>
45 : #include <svtools/sfxecode.hxx>
46 : #include <sfx2/docfile.hxx>
47 : #include <sfx2/docfilt.hxx>
48 : #include <svx/svxids.hrc>
49 : #include <svx/drawitem.hxx>
50 : #include <editeng/svxacorr.hxx>
51 : #include <editeng/langitem.hxx>
52 : #include <svx/fmshell.hxx>
53 : #include <sfx2/linkmgr.hxx>
54 :
55 : #include <svtools/htmlcfg.hxx>
56 : #include <svx/ofaitem.hxx>
57 : #include <SwSmartTagMgr.hxx>
58 : #include <sfx2/app.hxx>
59 : #include <basic/sbstar.hxx>
60 : #include <basic/basmgr.hxx>
61 : #include <sot/storage.hxx>
62 : #include <comphelper/classids.hxx>
63 : #include <fmtcol.hxx>
64 : #include <swevent.hxx>
65 : #include <view.hxx>
66 : #include <docsh.hxx>
67 : #include <docary.hxx>
68 : #include <wrtsh.hxx>
69 : #include <fldbas.hxx>
70 : #include <viewopt.hxx>
71 : #include <globdoc.hxx>
72 : #include <fldwrap.hxx>
73 : #include <redlndlg.hxx>
74 : #include <docstyle.hxx>
75 : #include <doc.hxx>
76 : #include <IDocumentUndoRedo.hxx>
77 : #include <pagedesc.hxx>
78 : #include <shellio.hxx>
79 : #include <pview.hxx>
80 : #include <srcview.hxx>
81 : #include <poolfmt.hxx>
82 : #include <usrpref.hxx>
83 : #include <wdocsh.hxx>
84 : #include <unotxdoc.hxx>
85 : #include <acmplwrd.hxx>
86 : #include <swmodule.hxx>
87 : #include <unobaseclass.hxx>
88 : #include <swwait.hxx>
89 : #include <swcli.hxx>
90 :
91 : #include <cmdid.h>
92 : #include <globals.h>
93 : #include <helpid.h>
94 : #include <app.hrc>
95 : #include <poolfmt.hrc>
96 : #include <globals.hrc>
97 : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
98 : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
99 : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
100 : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
101 : #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
102 : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
103 : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
104 : #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
105 : #include <com/sun/star/script/vba/VBAEventId.hpp>
106 : #include <editeng/acorrcfg.hxx>
107 : #include <SwStyleNameMapper.hxx>
108 :
109 : #include <sfx2/fcontnr.hxx>
110 :
111 : #include "dialog.hrc"
112 : #include "swabstdlg.hxx"
113 :
114 : #include <ndtxt.hxx>
115 :
116 : #include <boost/scoped_ptr.hpp>
117 :
118 : using namespace ::com::sun::star::ui::dialogs;
119 : using namespace ::com::sun::star::lang;
120 : using namespace ::com::sun::star::uno;
121 : using namespace ::com::sun::star;
122 : using namespace ::sfx2;
123 :
124 : extern bool FindPhyStyle( SwDoc& , const OUString& , SfxStyleFamily );
125 :
126 : // create DocInfo (virtual)
127 0 : SfxDocumentInfoDialog* SwDocShell::CreateDocumentInfoDialog(
128 : Window *pParent, const SfxItemSet &rSet)
129 : {
130 0 : SfxDocumentInfoDialog* pDlg = new SfxDocumentInfoDialog(pParent, rSet);
131 : //only with statistics, when this document is being shown, not
132 : //from within the Doc-Manager
133 0 : SwDocShell* pDocSh = (SwDocShell*) SfxObjectShell::Current();
134 0 : if( pDocSh == this )
135 : {
136 : //Not for SourceView.
137 0 : SfxViewShell *pVSh = SfxViewShell::Current();
138 0 : if ( pVSh && !pVSh->ISA(SwSrcView) )
139 : {
140 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
141 : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
142 0 : pDlg->AddFontTabPage();
143 0 : pDlg->AddTabPage(TP_DOC_STAT, SW_RESSTR(STR_DOC_STAT),pFact->GetTabPageCreatorFunc( TP_DOC_STAT ),0);
144 : }
145 : }
146 0 : return pDlg;
147 : }
148 :
149 : // Disable "multiple layout"
150 :
151 0 : void SwDocShell::ToggleBrowserMode(sal_Bool bSet, SwView* _pView )
152 : {
153 0 : GetDoc()->set(IDocumentSettingAccess::BROWSE_MODE, bSet );
154 0 : UpdateFontList();
155 0 : SwView* pTempView = _pView ? _pView : (SwView*)GetView();
156 0 : if( pTempView )
157 : {
158 0 : pTempView->GetViewFrame()->GetBindings().Invalidate(FN_SHADOWCURSOR);
159 0 : if( !GetDoc()->getPrinter( false ) )
160 0 : pTempView->SetPrinter( GetDoc()->getPrinter( false ), SFX_PRINTER_PRINTER | SFX_PRINTER_JOBSETUP );
161 0 : GetDoc()->CheckDefaultPageFmt();
162 0 : SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this, false);
163 0 : while (pTmpFrm)
164 : {
165 0 : if( pTmpFrm != pTempView->GetViewFrame() )
166 : {
167 0 : pTmpFrm->DoClose();
168 0 : pTmpFrm = SfxViewFrame::GetFirst(this, false);
169 : }
170 : else
171 0 : pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this, false);
172 : }
173 0 : const SwViewOption& rViewOptions = *pTempView->GetWrtShell().GetViewOptions();
174 0 : pTempView->GetWrtShell().CheckBrowseView( sal_True );
175 0 : pTempView->CheckVisArea();
176 0 : if( bSet )
177 : {
178 0 : const SvxZoomType eType = (SvxZoomType)rViewOptions.GetZoomType();
179 0 : if ( SVX_ZOOM_PERCENT != eType)
180 0 : ((SwView*)GetView())->SetZoom( eType );
181 : }
182 0 : pTempView->InvalidateBorder();
183 0 : pTempView->SetNewWindowAllowed(!bSet);
184 : }
185 0 : }
186 : // End of disabled "multiple layout"
187 :
188 : // update text fields on document properties changes
189 0 : void SwDocShell::DoFlushDocInfo()
190 : {
191 0 : if ( !pDoc ) return;
192 :
193 0 : bool bUnlockView(true);
194 0 : if ( pWrtShell ) {
195 0 : bUnlockView = !pWrtShell->IsViewLocked();
196 0 : pWrtShell->LockView( sal_True ); // lock visible section
197 0 : pWrtShell->StartAllAction();
198 : }
199 :
200 0 : pDoc->DocInfoChgd();
201 :
202 0 : if ( pWrtShell ) {
203 0 : pWrtShell->EndAllAction();
204 0 : if ( bUnlockView ) {
205 0 : pWrtShell->LockView( sal_False );
206 : }
207 : }
208 : }
209 :
210 0 : static void lcl_processCompatibleSfxHint( const uno::Reference< script::vba::XVBAEventProcessor >& xVbaEvents, const SfxHint& rHint )
211 : {
212 : using namespace com::sun::star::script::vba::VBAEventId;
213 0 : if ( rHint.ISA( SfxEventHint ) )
214 : {
215 0 : uno::Sequence< uno::Any > aArgs;
216 0 : sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId();
217 0 : switch( nEventId )
218 : {
219 : case SFX_EVENT_CREATEDOC:
220 0 : xVbaEvents->processVbaEvent( DOCUMENT_NEW, aArgs );
221 0 : break;
222 : case SFX_EVENT_OPENDOC:
223 0 : xVbaEvents->processVbaEvent( DOCUMENT_OPEN, aArgs );
224 0 : break;
225 0 : }
226 : }
227 0 : }
228 :
229 : // Notification on DocInfo changes
230 0 : void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
231 : {
232 0 : if( !pDoc )
233 : {
234 0 : return ;
235 : }
236 :
237 0 : uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor();
238 0 : if( xVbaEvents.is() )
239 0 : lcl_processCompatibleSfxHint( xVbaEvents, rHint );
240 :
241 0 : sal_uInt16 nAction = 0;
242 0 : if( rHint.ISA(SfxSimpleHint) )
243 : {
244 : // switch for more actions
245 0 : switch( ((SfxSimpleHint&) rHint).GetId() )
246 : {
247 : case SFX_HINT_TITLECHANGED:
248 0 : if( GetMedium() )
249 0 : nAction = 2;
250 0 : break;
251 : }
252 : }
253 0 : else if( rHint.ISA(SfxEventHint) &&
254 0 : ((SfxEventHint&) rHint).GetEventId() == SFX_EVENT_LOADFINISHED )
255 : {
256 : // #i38126# - own action id
257 0 : nAction = 3;
258 : }
259 :
260 0 : if( nAction )
261 : {
262 0 : bool bUnlockView = true; //initializing prevents warning
263 0 : if( pWrtShell )
264 : {
265 0 : bUnlockView = !pWrtShell->IsViewLocked();
266 0 : pWrtShell->LockView( sal_True ); //lock visible section
267 0 : pWrtShell->StartAllAction();
268 : }
269 0 : switch( nAction )
270 : {
271 : case 2:
272 0 : pDoc->GetSysFldType( RES_FILENAMEFLD )->UpdateFlds();
273 0 : break;
274 : // #i38126# - own action for event LOADFINISHED
275 : // in order to avoid a modified document.
276 : // #i41679# - Also for the instance of <SwDoc>
277 : // it has to be assured, that it's not modified.
278 : // Perform the same as for action id 1, but disable <SetModified>.
279 : case 3:
280 : {
281 0 : const bool bResetModified = IsEnableSetModified();
282 0 : if ( bResetModified )
283 0 : EnableSetModified( false );
284 : // #i41679#
285 0 : const bool bIsDocModified = pDoc->IsModified();
286 :
287 0 : pDoc->DocInfoChgd( );
288 :
289 : // #i41679#
290 0 : if ( !bIsDocModified )
291 0 : pDoc->ResetModified();
292 0 : if ( bResetModified )
293 0 : EnableSetModified( true );
294 : }
295 0 : break;
296 : }
297 :
298 0 : if( pWrtShell )
299 : {
300 0 : pWrtShell->EndAllAction();
301 0 : if( bUnlockView )
302 0 : pWrtShell->LockView( sal_False );
303 : }
304 0 : }
305 : }
306 :
307 : // Notification Close Doc
308 0 : bool SwDocShell::PrepareClose( bool bUI )
309 : {
310 0 : bool nRet = SfxObjectShell::PrepareClose( bUI );
311 :
312 0 : if( nRet )
313 0 : EndListening( *this );
314 :
315 0 : if( pDoc && IsInPrepareClose() )
316 : {
317 0 : uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor();
318 0 : if( xVbaEvents.is() )
319 : {
320 : using namespace com::sun::star::script::vba::VBAEventId;
321 0 : uno::Sequence< uno::Any > aArgs;
322 0 : xVbaEvents->processVbaEvent( DOCUMENT_CLOSE, aArgs );
323 0 : }
324 : }
325 0 : return nRet;
326 : }
327 :
328 0 : void SwDocShell::Execute(SfxRequest& rReq)
329 : {
330 0 : const SfxItemSet* pArgs = rReq.GetArgs();
331 : const SfxPoolItem* pItem;
332 0 : sal_uInt16 nWhich = rReq.GetSlot();
333 0 : sal_Bool bDone = sal_False;
334 0 : switch ( nWhich )
335 : {
336 : case SID_AUTO_CORRECT_DLG:
337 : {
338 0 : SvxSwAutoFmtFlags* pAFlags = &SvxAutoCorrCfg::Get().GetAutoCorrect()->GetSwFlags();
339 0 : SwAutoCompleteWord& rACW = SwDoc::GetAutoCompleteWords();
340 :
341 0 : bool bOldLocked = rACW.IsLockWordLstLocked(),
342 0 : bOldAutoCmpltCollectWords = pAFlags->bAutoCmpltCollectWords;
343 :
344 0 : rACW.SetLockWordLstLocked( true );
345 :
346 0 : editeng::SortedAutoCompleteStrings aTmpLst( rACW.GetWordList() );
347 0 : pAFlags->m_pAutoCompleteList = &aTmpLst;
348 :
349 0 : SfxApplication* pApp = SFX_APP();
350 0 : SfxRequest aAppReq(SID_AUTO_CORRECT_DLG, SFX_CALLMODE_SYNCHRON, pApp->GetPool());
351 0 : SfxBoolItem aSwOptions( SID_AUTO_CORRECT_DLG, true );
352 0 : aAppReq.AppendItem(aSwOptions);
353 :
354 0 : pAFlags->pSmartTagMgr = &SwSmartTagMgr::Get();
355 :
356 0 : SfxItemSet aSet( pApp->GetPool(), SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG, SID_OPEN_SMARTTAGOPTIONS, SID_OPEN_SMARTTAGOPTIONS, 0 );
357 0 : aSet.Put( aSwOptions );
358 :
359 0 : const SfxPoolItem* pOpenSmartTagOptionsItem = 0;
360 0 : if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_OPEN_SMARTTAGOPTIONS, false, &pOpenSmartTagOptionsItem ) )
361 0 : aSet.Put( *static_cast<const SfxBoolItem*>(pOpenSmartTagOptionsItem) );
362 :
363 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
364 0 : SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog( RID_OFA_AUTOCORR_DLG, NULL, &aSet, NULL );
365 0 : pDlg->Execute();
366 0 : delete pDlg;
367 :
368 0 : rACW.SetLockWordLstLocked( bOldLocked );
369 :
370 0 : SwEditShell::SetAutoFmtFlags( pAFlags );
371 0 : rACW.SetMinWordLen( pAFlags->nAutoCmpltWordLen );
372 0 : rACW.SetMaxCount( pAFlags->nAutoCmpltListLen );
373 0 : if (pAFlags->m_pAutoCompleteList) // any changes?
374 : {
375 0 : rACW.CheckChangedList( aTmpLst );
376 : // clear the temp WordList pointer
377 0 : pAFlags->m_pAutoCompleteList = 0;
378 : }
379 : // remove all pointer we never delete the strings
380 0 : aTmpLst.clear();
381 :
382 0 : if( !bOldAutoCmpltCollectWords && bOldAutoCmpltCollectWords !=
383 : pAFlags->bAutoCmpltCollectWords )
384 : {
385 : // call on all Docs the idle formatter to start
386 : // the collection of Words
387 0 : TypeId aType = TYPE(SwDocShell);
388 0 : for( SwDocShell *pDocSh = (SwDocShell*)SfxObjectShell::GetFirst(&aType);
389 : pDocSh;
390 0 : pDocSh = (SwDocShell*)SfxObjectShell::GetNext( *pDocSh, &aType ) )
391 : {
392 0 : SwDoc* pTmp = pDocSh->GetDoc();
393 0 : if ( pTmp->GetCurrentViewShell() )
394 0 : pTmp->InvalidateAutoCompleteFlag();
395 : }
396 0 : }
397 : }
398 0 : break;
399 :
400 : case SID_PRINTPREVIEW:
401 : {
402 0 : sal_Bool bSet = sal_False;
403 0 : bool bFound = false, bOnly = true;
404 0 : SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this);
405 0 : SfxViewShell* pViewShell = SfxViewShell::Current();
406 0 : SwView* pCurrView = dynamic_cast< SwView *> ( pViewShell );
407 0 : sal_Bool bCurrent = IS_TYPE( SwPagePreview, pViewShell );
408 :
409 0 : while( pTmpFrm ) // search Preview
410 : {
411 0 : if( IS_TYPE( SwView, pTmpFrm->GetViewShell()) )
412 0 : bOnly = false;
413 0 : else if( IS_TYPE( SwPagePreview, pTmpFrm->GetViewShell()))
414 : {
415 0 : pTmpFrm->GetFrame().Appear();
416 0 : bFound = true;
417 : }
418 0 : if( bFound && !bOnly )
419 0 : break;
420 0 : pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this);
421 : }
422 :
423 0 : if( pArgs && SFX_ITEM_SET ==
424 0 : pArgs->GetItemState( SID_PRINTPREVIEW, false, &pItem ))
425 0 : bSet = ((SfxBoolItem*)pItem)->GetValue();
426 : else
427 0 : bSet = !bCurrent;
428 :
429 0 : sal_uInt16 nSlotId = 0;
430 0 : if( bSet && !bFound ) // Nothing found, so create new Preview
431 0 : nSlotId = SID_VIEWSHELL1;
432 0 : else if( bFound && !bSet )
433 0 : nSlotId = bOnly ? SID_VIEWSHELL0 : SID_VIEWSHELL1;
434 :
435 0 : if( nSlotId )
436 : {
437 : // PagePreview in the WebDocShell
438 : // is found under Id VIEWSHELL2.
439 0 : if( ISA(SwWebDocShell) && SID_VIEWSHELL1 == nSlotId )
440 0 : nSlotId = SID_VIEWSHELL2;
441 :
442 0 : if( pCurrView && pCurrView->GetDocShell() == this )
443 0 : pTmpFrm = pCurrView->GetViewFrame();
444 : else
445 0 : pTmpFrm = SfxViewFrame::GetFirst( this );
446 :
447 0 : if (pTmpFrm)
448 0 : pTmpFrm->GetDispatcher()->Execute( nSlotId, 0, 0, SFX_CALLMODE_ASYNCHRON );
449 : }
450 :
451 0 : rReq.SetReturnValue(SfxBoolItem(SID_PRINTPREVIEW, bSet ));
452 : }
453 0 : break;
454 : case SID_TEMPLATE_LOAD:
455 : {
456 0 : OUString aFileName;
457 : static sal_Bool bText = sal_True;
458 : static sal_Bool bFrame = sal_False;
459 : static sal_Bool bPage = sal_False;
460 : static sal_Bool bNum = sal_False;
461 : static sal_Bool bMerge = sal_False;
462 0 : sal_uInt16 nRet = USHRT_MAX;
463 :
464 0 : sal_uInt16 nFlags = bFrame ? SFX_LOAD_FRAME_STYLES : 0;
465 0 : if(bPage)
466 0 : nFlags|= SFX_LOAD_PAGE_STYLES;
467 0 : if(bNum)
468 0 : nFlags|= SFX_LOAD_NUM_STYLES;
469 0 : if(!nFlags || bText)
470 0 : nFlags|= SFX_LOAD_TEXT_STYLES;
471 0 : if(bMerge)
472 0 : nFlags|= SFX_MERGE_STYLES;
473 :
474 0 : if ( pArgs )
475 : {
476 0 : SFX_REQUEST_ARG( rReq, pTemplateItem, SfxStringItem, SID_TEMPLATE_NAME, false );
477 0 : if ( pTemplateItem )
478 : {
479 0 : aFileName = pTemplateItem->GetValue();
480 0 : SFX_REQUEST_ARG( rReq, pFlagsItem, SfxInt32Item, SID_TEMPLATE_LOAD, false );
481 0 : if ( pFlagsItem )
482 0 : nFlags = (sal_uInt16) pFlagsItem->GetValue();
483 : }
484 : }
485 :
486 0 : if ( aFileName.isEmpty() )
487 : {
488 0 : SvtPathOptions aPathOpt;
489 : SfxNewFileDialog* pNewFileDlg =
490 0 : new SfxNewFileDialog(&GetView()->GetViewFrame()->GetWindow(), SFXWB_LOAD_TEMPLATE);
491 0 : pNewFileDlg->SetTemplateFlags(nFlags);
492 :
493 0 : nRet = pNewFileDlg->Execute();
494 0 : if(RET_TEMPLATE_LOAD == nRet)
495 : {
496 0 : FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
497 0 : uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
498 :
499 0 : xFP->setDisplayDirectory( aPathOpt.GetWorkPath() );
500 :
501 0 : SfxObjectFactory &rFact = GetFactory();
502 0 : SfxFilterMatcher aMatcher( OUString::createFromAscii(rFact.GetShortName()) );
503 0 : SfxFilterMatcherIter aIter( aMatcher );
504 0 : uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
505 0 : const SfxFilter* pFlt = aIter.First();
506 0 : while( pFlt )
507 : {
508 : // --> OD #i117339#
509 0 : if( pFlt && pFlt->IsAllowedAsTemplate() &&
510 0 : ( pFlt->GetUserData() == "CXML" ||
511 0 : pFlt->GetUserData() == "CXMLV" ) )
512 : {
513 0 : const OUString sWild = pFlt->GetWildcard().getGlob();
514 0 : xFltMgr->appendFilter( pFlt->GetUIName(), sWild );
515 : }
516 0 : pFlt = aIter.Next();
517 : }
518 0 : bool bWeb = 0 != dynamic_cast< SwWebDocShell *>( this );
519 : const SfxFilter *pOwnFlt =
520 0 : SwDocShell::Factory().GetFilterContainer()->
521 0 : GetFilter4FilterName(OUString("writer8"));
522 :
523 : // make sure the default file format is also available
524 0 : if(bWeb)
525 : {
526 0 : const OUString sWild = pOwnFlt->GetWildcard().getGlob();
527 0 : xFltMgr->appendFilter( pOwnFlt->GetUIName(), sWild );
528 : }
529 :
530 0 : bool bError = false;
531 : // catch exception if wrong filter is selected - should not happen anymore
532 : try
533 : {
534 0 : xFltMgr->setCurrentFilter( pOwnFlt->GetUIName() );
535 : }
536 0 : catch (const uno::Exception&)
537 : {
538 0 : bError = true;
539 : }
540 :
541 0 : if( !bError && ERRCODE_NONE == aDlgHelper.Execute() )
542 : {
543 0 : aFileName = xFP->getFiles().getConstArray()[0];
544 0 : }
545 : }
546 0 : else if( RET_OK == nRet)
547 : {
548 0 : aFileName = pNewFileDlg->GetTemplateFileName();
549 : }
550 :
551 0 : nFlags = pNewFileDlg->GetTemplateFlags();
552 0 : rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aFileName ) );
553 0 : rReq.AppendItem( SfxInt32Item( SID_TEMPLATE_LOAD, (long) nFlags ) );
554 0 : delete pNewFileDlg;
555 : }
556 :
557 0 : if( !aFileName.isEmpty() )
558 : {
559 0 : SwgReaderOption aOpt;
560 0 : aOpt.SetTxtFmts( bText = (0 != (nFlags&SFX_LOAD_TEXT_STYLES) ));
561 0 : aOpt.SetFrmFmts( bFrame = (0 != (nFlags&SFX_LOAD_FRAME_STYLES)));
562 0 : aOpt.SetPageDescs( bPage = (0 != (nFlags&SFX_LOAD_PAGE_STYLES )));
563 0 : aOpt.SetNumRules( bNum = (0 != (nFlags&SFX_LOAD_NUM_STYLES )));
564 : //different meaning between SFX_MERGE_STYLES and aOpt.SetMerge!
565 0 : bMerge = 0 != (nFlags&SFX_MERGE_STYLES);
566 0 : aOpt.SetMerge( !bMerge );
567 :
568 0 : SetError( LoadStylesFromFile( aFileName, aOpt, sal_False ), OUString( OSL_LOG_PREFIX ));
569 0 : if ( !GetError() )
570 0 : rReq.Done();
571 0 : }
572 : }
573 0 : break;
574 : case SID_SOURCEVIEW:
575 : {
576 0 : SfxViewShell* pViewShell = GetView()
577 : ? (SfxViewShell*)GetView()
578 0 : : SfxViewShell::Current();
579 0 : SfxViewFrame* pViewFrm = pViewShell->GetViewFrame();
580 0 : SwSrcView* pSrcView = dynamic_cast< SwSrcView *>( pViewShell );
581 0 : if(!pSrcView)
582 : {
583 : // 3 possible state:
584 : // 1 - file unsaved -> save as HTML
585 : // 2 - file modified and HTML filter active -> save
586 : // 3 - file saved in non-HTML -> QueryBox to save as HTML
587 : const SfxFilter* pHtmlFlt =
588 : SwIoSystem::GetFilterOfFormat(
589 : OUString("HTML"),
590 0 : SwWebDocShell::Factory().GetFilterContainer() );
591 0 : sal_Bool bLocalHasName = HasName();
592 0 : if(bLocalHasName)
593 : {
594 : //check for filter type
595 0 : const SfxFilter* pFlt = GetMedium()->GetFilter();
596 0 : if(!pFlt || pFlt->GetUserData() != pHtmlFlt->GetUserData())
597 : {
598 0 : MessageDialog aQuery(&pViewFrm->GetWindow(),
599 0 : "SaveAsHTMLDialog", "modules/swriter/ui/saveashtmldialog.ui");
600 :
601 0 : if(RET_YES == aQuery.Execute())
602 0 : bLocalHasName = sal_False;
603 : else
604 0 : break;
605 : }
606 : }
607 0 : if(!bLocalHasName)
608 : {
609 0 : FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION, 0 );
610 0 : aDlgHelper.AddFilter( pHtmlFlt->GetFilterName(), pHtmlFlt->GetDefaultExtension() );
611 0 : aDlgHelper.SetCurrentFilter( pHtmlFlt->GetFilterName() );
612 0 : if( ERRCODE_NONE != aDlgHelper.Execute())
613 : {
614 0 : break;
615 : }
616 0 : OUString sPath = aDlgHelper.GetPath();
617 0 : SfxStringItem aName(SID_FILE_NAME, sPath);
618 0 : SfxStringItem aFilter(SID_FILTER_NAME, pHtmlFlt->GetName());
619 : const SfxBoolItem* pBool = (const SfxBoolItem*)
620 : pViewFrm->GetDispatcher()->Execute(
621 0 : SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON, &aName, &aFilter, 0L );
622 0 : if(!pBool || !pBool->GetValue())
623 0 : break;
624 : }
625 : }
626 :
627 : OSL_ENSURE(dynamic_cast<SwWebDocShell*>(this),
628 : "SourceView only in WebDocShell");
629 :
630 : // the SourceView is not the 1 for SwWebDocShell
631 0 : sal_uInt16 nSlot = SID_VIEWSHELL1;
632 0 : bool bSetModified = false;
633 0 : SfxPrinter* pSavePrinter = 0;
634 0 : if( 0 != pSrcView)
635 : {
636 0 : SfxPrinter* pTemp = GetDoc()->getPrinter( false );
637 0 : if(pTemp)
638 0 : pSavePrinter = new SfxPrinter(*pTemp);
639 0 : bSetModified = IsModified() || pSrcView->IsModified();
640 0 : if(pSrcView->IsModified()||pSrcView->HasSourceSaved())
641 : {
642 0 : utl::TempFile aTempFile;
643 0 : aTempFile.EnableKillingFile();
644 0 : pSrcView->SaveContent(aTempFile.GetURL());
645 0 : bDone = sal_True;
646 0 : SvxMacro aMac(aEmptyOUStr, aEmptyOUStr, STARBASIC);
647 0 : SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_OPENDOC ), aMac, this);
648 0 : SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_PREPARECLOSEDOC ), aMac, this);
649 0 : SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_ACTIVATEDOC ), aMac, this);
650 0 : SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_DEACTIVATEDOC ), aMac, this);
651 0 : ReloadFromHtml(aTempFile.GetURL(), pSrcView);
652 0 : nSlot = 0;
653 : }
654 : else
655 : {
656 0 : nSlot = SID_VIEWSHELL0;
657 : }
658 : }
659 0 : if(nSlot)
660 0 : pViewFrm->GetDispatcher()->Execute(nSlot, SFX_CALLMODE_SYNCHRON);
661 0 : if(bSetModified)
662 0 : GetDoc()->SetModified();
663 0 : if(pSavePrinter)
664 : {
665 0 : GetDoc()->setPrinter( pSavePrinter, true, true);
666 : //pSavePrinter must not be deleted again
667 : }
668 0 : pViewFrm->GetBindings().SetState(SfxBoolItem(SID_SOURCEVIEW, nSlot == SID_VIEWSHELL2));
669 0 : pViewFrm->GetBindings().Invalidate( SID_NEWWINDOW );
670 0 : pViewFrm->GetBindings().Invalidate( SID_BROWSER_MODE );
671 0 : pViewFrm->GetBindings().Invalidate( FN_PRINT_LAYOUT );
672 : }
673 0 : break;
674 : case SID_GET_COLORLIST:
675 : {
676 0 : SvxColorListItem* pColItem = (SvxColorListItem*)GetItem(SID_COLOR_TABLE);
677 0 : XColorListRef pList = pColItem->GetColorList();
678 0 : rReq.SetReturnValue(OfaRefItem<XColorList>(SID_GET_COLORLIST, pList));
679 : }
680 0 : break;
681 : case FN_ABSTRACT_STARIMPRESS:
682 : case FN_ABSTRACT_NEWDOC:
683 : {
684 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
685 : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
686 :
687 0 : boost::scoped_ptr<AbstractSwInsertAbstractDlg> pDlg(pFact->CreateSwInsertAbstractDlg(0));
688 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
689 0 : if(RET_OK == pDlg->Execute())
690 : {
691 0 : sal_uInt8 nLevel = pDlg->GetLevel();
692 0 : sal_uInt8 nPara = pDlg->GetPara();
693 0 : SwDoc* pSmryDoc = new SwDoc();
694 0 : SfxObjectShellLock xDocSh( new SwDocShell( pSmryDoc, SFX_CREATE_MODE_STANDARD));
695 0 : xDocSh->DoInitNew( 0 );
696 :
697 0 : bool bImpress = FN_ABSTRACT_STARIMPRESS == nWhich;
698 0 : pDoc->Summary( pSmryDoc, nLevel, nPara, bImpress );
699 0 : if( bImpress )
700 : {
701 0 : WriterRef xWrt;
702 : // mba: looks as if relative URLs don't make sense here
703 0 : ::GetRTFWriter( aEmptyOUStr, OUString(), xWrt );
704 0 : SvMemoryStream *pStrm = new SvMemoryStream();
705 0 : pStrm->SetBufferSize( 16348 );
706 0 : SwWriter aWrt( *pStrm, *pSmryDoc );
707 0 : ErrCode eErr = aWrt.Write( xWrt );
708 0 : if( !ERRCODE_TOERROR( eErr ) )
709 : {
710 0 : uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
711 0 : uno::Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext );
712 :
713 0 : OUString aCmd("SendOutlineToImpress");
714 0 : uno::Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
715 0 : pStrm->Seek( STREAM_SEEK_TO_END );
716 0 : pStrm->WriteChar( '\0' );
717 0 : pStrm->Seek( STREAM_SEEK_TO_BEGIN );
718 :
719 : // Transfer ownership of stream to a lockbytes object
720 0 : SvLockBytes aLockBytes( pStrm, true );
721 0 : SvLockBytesStat aStat;
722 0 : if ( aLockBytes.Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
723 : {
724 0 : sal_uInt32 nLen = aStat.nSize;
725 0 : sal_uLong nRead = 0;
726 0 : uno::Sequence< sal_Int8 > aSeq( nLen );
727 0 : aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead );
728 :
729 0 : uno::Sequence< beans::PropertyValue > aArgs(1);
730 0 : aArgs[0].Name = "RtfOutline";
731 0 : aArgs[0].Value <<= aSeq;
732 0 : xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aArgs );
733 0 : }
734 : }
735 : else
736 0 : ErrorHandler::HandleError(ErrCode( eErr ));
737 : }
738 : else
739 : {
740 : // Create new document
741 0 : SfxViewFrame *pFrame = SfxViewFrame::LoadDocument( *xDocSh, 0 );
742 0 : SwView *pCurrView = (SwView*) pFrame->GetViewShell();
743 :
744 : // Set document's title
745 0 : OUString aTmp( SW_RES(STR_ABSTRACT_TITLE) );
746 0 : aTmp += GetTitle();
747 0 : xDocSh->SetTitle( aTmp );
748 0 : pCurrView->GetWrtShell().SetNewDoc();
749 0 : pFrame->Show();
750 0 : pSmryDoc->SetModified();
751 0 : }
752 :
753 0 : }
754 : }
755 0 : break;
756 : case FN_OUTLINE_TO_CLIPBOARD:
757 : case FN_OUTLINE_TO_IMPRESS:
758 : {
759 0 : sal_Bool bEnable = IsEnableSetModified();
760 0 : EnableSetModified( false );
761 0 : WriterRef xWrt;
762 : // mba: looks as if relative URLs don't make sense here
763 0 : ::GetRTFWriter( OUString('O'), OUString(), xWrt );
764 0 : SvMemoryStream *pStrm = new SvMemoryStream();
765 0 : pStrm->SetBufferSize( 16348 );
766 0 : SwWriter aWrt( *pStrm, *GetDoc() );
767 0 : ErrCode eErr = aWrt.Write( xWrt );
768 0 : EnableSetModified( bEnable );
769 0 : if( !ERRCODE_TOERROR( eErr ) )
770 : {
771 0 : pStrm->Seek( STREAM_SEEK_TO_END );
772 0 : pStrm->WriteChar( '\0' );
773 0 : pStrm->Seek( STREAM_SEEK_TO_BEGIN );
774 0 : if ( nWhich == FN_OUTLINE_TO_IMPRESS )
775 : {
776 0 : uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
777 0 : uno::Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext );
778 :
779 0 : OUString aCmd("SendOutlineToImpress");
780 0 : uno::Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
781 0 : pStrm->Seek( STREAM_SEEK_TO_END );
782 0 : pStrm->WriteChar( '\0' );
783 0 : pStrm->Seek( STREAM_SEEK_TO_BEGIN );
784 :
785 : // Transfer ownership of stream to a lockbytes object
786 0 : SvLockBytes aLockBytes( pStrm, true );
787 0 : SvLockBytesStat aStat;
788 0 : if ( aLockBytes.Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
789 : {
790 0 : sal_uInt32 nLen = aStat.nSize;
791 0 : sal_uLong nRead = 0;
792 0 : uno::Sequence< sal_Int8 > aSeq( nLen );
793 0 : aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead );
794 :
795 0 : uno::Sequence< beans::PropertyValue > aArgs(1);
796 0 : aArgs[0].Name = "RtfOutline";
797 0 : aArgs[0].Value <<= aSeq;
798 0 : xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aArgs );
799 0 : }
800 : }
801 : else
802 : {
803 : TransferDataContainer* pClipCntnr =
804 0 : new TransferDataContainer;
805 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >
806 0 : xRef( pClipCntnr );
807 :
808 : pClipCntnr->CopyAnyData( FORMAT_RTF, (sal_Char*)
809 0 : pStrm->GetData(), pStrm->GetEndOfData() );
810 : pClipCntnr->CopyToClipboard(
811 0 : GetView()? (Window*)&GetView()->GetEditWin() : 0 );
812 0 : delete pStrm;
813 : }
814 : }
815 : else
816 0 : ErrorHandler::HandleError(ErrCode( eErr ));
817 : }
818 0 : break;
819 : case SID_SPELLCHECKER_CHANGED:
820 : //! false, true, true is on the save side but a probably overdone
821 0 : SW_MOD()->CheckSpellChanges(false, true, true, false );
822 0 : break;
823 :
824 : case SID_MAIL_PREPAREEXPORT:
825 : {
826 : //pWrtShell is not set in page preview
827 0 : if(pWrtShell)
828 0 : pWrtShell->StartAllAction();
829 0 : pDoc->UpdateFlds( NULL, false );
830 0 : pDoc->EmbedAllLinks();
831 0 : pDoc->RemoveInvisibleContent();
832 0 : if(pWrtShell)
833 0 : pWrtShell->EndAllAction();
834 : }
835 0 : break;
836 :
837 : case SID_MAIL_EXPORT_FINISHED:
838 : {
839 0 : if(pWrtShell)
840 0 : pWrtShell->StartAllAction();
841 : //try to undo the removal of invisible content
842 0 : pDoc->RestoreInvisibleContent();
843 0 : if(pWrtShell)
844 0 : pWrtShell->EndAllAction();
845 : }
846 0 : break;
847 : case FN_NEW_HTML_DOC:
848 : case FN_NEW_GLOBAL_DOC:
849 : {
850 0 : bDone = sal_False;
851 0 : bool bCreateHtml = FN_NEW_HTML_DOC == nWhich;
852 :
853 0 : bool bCreateByOutlineLevel = false;
854 0 : sal_Int32 nTemplateOutlineLevel = 0;
855 :
856 0 : OUString aFileName, aTemplateName;
857 0 : if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nWhich, false, &pItem ) )
858 : {
859 0 : aFileName = ((const SfxStringItem*)pItem)->GetValue();
860 0 : SFX_ITEMSET_ARG( pArgs, pTemplItem, SfxStringItem, SID_TEMPLATE_NAME, false );
861 0 : if ( pTemplItem )
862 0 : aTemplateName = pTemplItem->GetValue();
863 : }
864 0 : bool bError = false;
865 0 : if ( aFileName.isEmpty() )
866 : {
867 0 : FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE, 0 );
868 :
869 : const sal_Int16 nControlIds[] = {
870 : CommonFilePickerElementIds::PUSHBUTTON_OK,
871 : CommonFilePickerElementIds::PUSHBUTTON_CANCEL,
872 : CommonFilePickerElementIds::LISTBOX_FILTER,
873 : CommonFilePickerElementIds::CONTROL_FILEVIEW,
874 : CommonFilePickerElementIds::EDIT_FILEURL,
875 : ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION,
876 : ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
877 : 0
878 0 : };
879 :
880 : const char* aHTMLHelpIds[] =
881 : {
882 : HID_SEND_HTML_CTRL_PUSHBUTTON_OK,
883 : HID_SEND_HTML_CTRL_PUSHBUTTON_CANCEL,
884 : HID_SEND_HTML_CTRL_LISTBOX_FILTER,
885 : HID_SEND_HTML_CTRL_CONTROL_FILEVIEW,
886 : HID_SEND_HTML_CTRL_EDIT_FILEURL,
887 : HID_SEND_HTML_CTRL_CHECKBOX_AUTOEXTENSION,
888 : HID_SEND_HTML_CTRL_LISTBOX_TEMPLATE,
889 : ""
890 0 : };
891 :
892 : const char* aMasterHelpIds[] =
893 : {
894 : HID_SEND_MASTER_CTRL_PUSHBUTTON_OK,
895 : HID_SEND_MASTER_CTRL_PUSHBUTTON_CANCEL,
896 : HID_SEND_MASTER_CTRL_LISTBOX_FILTER,
897 : HID_SEND_MASTER_CTRL_CONTROL_FILEVIEW,
898 : HID_SEND_MASTER_CTRL_EDIT_FILEURL,
899 : HID_SEND_MASTER_CTRL_CHECKBOX_AUTOEXTENSION,
900 : HID_SEND_MASTER_CTRL_LISTBOX_TEMPLATE,
901 : ""
902 0 : };
903 :
904 0 : const char** pHelpIds = bCreateHtml ? aHTMLHelpIds : aMasterHelpIds;
905 0 : aDlgHelper.SetControlHelpIds( nControlIds, pHelpIds );
906 0 : uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
907 :
908 : const SfxFilter* pFlt;
909 : sal_uInt16 nStrId;
910 :
911 0 : if( bCreateHtml )
912 : {
913 : // for HTML there is only one filter!!
914 : pFlt = SwIoSystem::GetFilterOfFormat(
915 : OUString("HTML"),
916 0 : SwWebDocShell::Factory().GetFilterContainer() );
917 0 : nStrId = STR_LOAD_HTML_DOC;
918 : }
919 : else
920 : {
921 : // for Global-documents we now only offer the current one.
922 0 : pFlt = SwGlobalDocShell::Factory().GetFilterContainer()->
923 0 : GetFilter4Extension( OUString("odm") );
924 0 : nStrId = STR_LOAD_GLOBAL_DOC;
925 : }
926 :
927 0 : if( pFlt )
928 : {
929 0 : uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
930 0 : const OUString sWild = pFlt->GetWildcard().getGlob();
931 0 : xFltMgr->appendFilter( pFlt->GetUIName(), sWild );
932 : try
933 : {
934 0 : xFltMgr->setCurrentFilter( pFlt->GetUIName() ) ;
935 : }
936 0 : catch (const uno::Exception&)
937 : {
938 0 : bError = true;
939 0 : }
940 : }
941 0 : if(!bError)
942 : {
943 0 : uno::Reference<XFilePickerControlAccess> xCtrlAcc(xFP, UNO_QUERY);
944 :
945 0 : bool bOutline[MAXLEVEL] = {false};
946 0 : const SwOutlineNodes& rOutlNds = pDoc->GetNodes().GetOutLineNds();
947 0 : if( !rOutlNds.empty() )
948 : {
949 : int nLevel;
950 0 : for(sal_uInt16 n = 0; n < rOutlNds.size(); ++n )
951 0 : if( ( nLevel = rOutlNds[n]->GetTxtNode()->GetAttrOutlineLevel()) > 0 &&
952 0 : ! bOutline[nLevel-1] )
953 : {
954 0 : bOutline[nLevel-1] = true;
955 : }
956 : }
957 :
958 0 : const sal_uInt16 nStyleCount = pDoc->GetTxtFmtColls()->size();
959 0 : Sequence<OUString> aListBoxEntries( MAXLEVEL + nStyleCount);
960 0 : OUString* pEntries = aListBoxEntries.getArray();
961 0 : sal_Int32 nIdx = 0 ;
962 :
963 0 : OUString sOutline( SW_RESSTR(STR_FDLG_OUTLINE_LEVEL) );
964 0 : for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
965 : {
966 0 : if( bOutline[i] )
967 0 : pEntries[nIdx++] = sOutline + OUString::number( i+1 );
968 : }
969 :
970 0 : OUString sStyle( SW_RESSTR(STR_FDLG_STYLE) );
971 0 : for(sal_uInt16 i = 0; i < nStyleCount; ++i)
972 : {
973 0 : SwTxtFmtColl &rTxtColl = *(*pDoc->GetTxtFmtColls())[ i ];
974 0 : if( !rTxtColl.IsDefault() && rTxtColl.IsAtDocNodeSet() )
975 : {
976 0 : pEntries[nIdx++] = sStyle + rTxtColl.GetName();
977 : }
978 : }
979 :
980 0 : aListBoxEntries.realloc(nIdx);
981 0 : sal_Int16 nSelect = 0;
982 :
983 : try
984 : {
985 0 : Any aTemplates(&aListBoxEntries, ::getCppuType(&aListBoxEntries));
986 :
987 0 : xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
988 0 : ListboxControlActions::ADD_ITEMS , aTemplates );
989 0 : Any aSelectPos(&nSelect, ::getCppuType(&nSelect));
990 0 : xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
991 0 : ListboxControlActions::SET_SELECT_ITEM, aSelectPos );
992 0 : xCtrlAcc->setLabel( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
993 0 : OUString(SW_RES( STR_FDLG_TEMPLATE_NAME )));
994 : }
995 0 : catch (const Exception&)
996 : {
997 : OSL_FAIL("control acces failed");
998 : }
999 :
1000 0 : xFP->setTitle( SW_RESSTR( nStrId ));
1001 0 : SvtPathOptions aPathOpt;
1002 0 : xFP->setDisplayDirectory( aPathOpt.GetWorkPath() );
1003 0 : if( ERRCODE_NONE == aDlgHelper.Execute())
1004 : {
1005 0 : aFileName = xFP->getFiles().getConstArray()[0];
1006 0 : Any aTemplateValue = xCtrlAcc->getValue(
1007 : ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
1008 0 : ListboxControlActions::GET_SELECTED_ITEM );
1009 0 : OUString sTmpl;
1010 0 : aTemplateValue >>= sTmpl;
1011 :
1012 0 : sal_Int32 nColonPos = sTmpl.indexOf( ':' );
1013 0 : OUString sPrefix = sTmpl.copy( 0L, nColonPos );
1014 0 : if ( sPrefix == "Style" )
1015 : {
1016 0 : aTemplateName = sTmpl.copy( 7L ); //get string behind "Style: "
1017 : }
1018 0 : else if ( sPrefix == "Outline" )
1019 : {
1020 0 : nTemplateOutlineLevel = ( sTmpl.copy( 15L )).toInt32(); //get string behind "Outline: Leve ";
1021 0 : bCreateByOutlineLevel = true;
1022 : }
1023 :
1024 0 : if ( !aFileName.isEmpty() )
1025 : {
1026 0 : rReq.AppendItem( SfxStringItem( nWhich, aFileName ) );
1027 0 : if( !aTemplateName.isEmpty() )
1028 0 : rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aTemplateName ) );
1029 0 : }
1030 0 : }
1031 0 : }
1032 : }
1033 :
1034 0 : if( !aFileName.isEmpty() )
1035 : {
1036 0 : if( PrepareClose( false ) )
1037 : {
1038 0 : SwWait aWait( *this, true );
1039 :
1040 0 : if ( bCreateByOutlineLevel )
1041 : {
1042 : bDone = bCreateHtml
1043 0 : ? pDoc->GenerateHTMLDoc( aFileName, nTemplateOutlineLevel )
1044 0 : : pDoc->GenerateGlobalDoc( aFileName, nTemplateOutlineLevel );
1045 : }
1046 : else
1047 : {
1048 0 : const SwTxtFmtColl* pSplitColl = 0;
1049 0 : if ( !aTemplateName.isEmpty() )
1050 0 : pSplitColl = pDoc->FindTxtFmtCollByName(aTemplateName);
1051 : bDone = bCreateHtml
1052 0 : ? pDoc->GenerateHTMLDoc( aFileName, pSplitColl )
1053 0 : : pDoc->GenerateGlobalDoc( aFileName, pSplitColl );
1054 : }
1055 0 : if( bDone )
1056 : {
1057 0 : SfxStringItem aName( SID_FILE_NAME, aFileName );
1058 0 : SfxStringItem aReferer( SID_REFERER, aEmptyOUStr );
1059 0 : SfxViewShell* pViewShell = SfxViewShell::GetFirst();
1060 0 : while(pViewShell)
1061 : {
1062 : //search for the view that created the call
1063 0 : if(pViewShell->GetObjectShell() == this && pViewShell->GetDispatcher())
1064 : {
1065 : SfxFrameItem* pFrameItem = new SfxFrameItem( SID_DOCFRAME,
1066 0 : pViewShell->GetViewFrame() );
1067 0 : SfxDispatcher* pDispatch = pViewShell->GetDispatcher();
1068 : pDispatch->Execute(
1069 : SID_OPENDOC,
1070 : SFX_CALLMODE_ASYNCHRON,
1071 : &aName,
1072 : &aReferer,
1073 0 : pFrameItem, 0L );
1074 :
1075 0 : delete pFrameItem;
1076 0 : break;
1077 : }
1078 0 : pViewShell = SfxViewShell::GetNext(*pViewShell);
1079 0 : }
1080 0 : }
1081 : }
1082 0 : if( !bDone && !rReq.IsAPI() )
1083 : {
1084 0 : InfoBox( 0, SW_RESSTR( STR_CANTCREATE )).Execute();
1085 : }
1086 0 : }
1087 : }
1088 0 : rReq.SetReturnValue(SfxBoolItem( nWhich, bDone ));
1089 0 : if (bDone)
1090 0 : rReq.Done();
1091 : else
1092 0 : rReq.Ignore();
1093 0 : break;
1094 :
1095 : case SID_ATTR_YEAR2000:
1096 0 : if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nWhich , false, &pItem ))
1097 : {
1098 : OSL_ENSURE(pItem->ISA(SfxUInt16Item), "wrong Item");
1099 0 : sal_uInt16 nYear2K = ((SfxUInt16Item*)pItem)->GetValue();
1100 : // iterate over Views and put the State to FormShells
1101 :
1102 0 : SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( this );
1103 0 : SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : 0;
1104 0 : SwView* pCurrView = dynamic_cast< SwView* >( pViewShell );
1105 0 : while(pCurrView)
1106 : {
1107 0 : FmFormShell* pFormShell = pCurrView->GetFormShell();
1108 0 : if(pFormShell)
1109 0 : pFormShell->SetY2KState(nYear2K);
1110 0 : pVFrame = SfxViewFrame::GetNext( *pVFrame, this );
1111 0 : pViewShell = pVFrame ? pVFrame->GetViewShell() : 0;
1112 0 : pCurrView = dynamic_cast<SwView*>( pViewShell );
1113 : }
1114 0 : pDoc->GetNumberFormatter(sal_True)->SetYear2000(nYear2K);
1115 : }
1116 0 : break;
1117 : case FN_OPEN_FILE:
1118 : {
1119 0 : SfxViewShell* pViewShell = GetView();
1120 0 : if (!pViewShell)
1121 0 : pViewShell = SfxViewShell::Current();
1122 :
1123 0 : if (!pViewShell)
1124 : // Ok. I did my best.
1125 0 : break;
1126 :
1127 0 : SfxStringItem aApp(SID_DOC_SERVICE, OUString("com.sun.star.text.TextDocument"));
1128 0 : SfxStringItem aTarget(SID_TARGETNAME, OUString("_blank"));
1129 : pViewShell->GetDispatcher()->Execute(
1130 0 : SID_OPENDOC, SFX_CALLMODE_API|SFX_CALLMODE_SYNCHRON, &aApp, &aTarget, 0L);
1131 : }
1132 0 : break;
1133 :
1134 : default: OSL_FAIL("wrong Dispatcher");
1135 : }
1136 0 : }
1137 :
1138 : // #FIXME - align with NEW event stuff ( if possible )
1139 : #if 0
1140 : void lcl_processCompatibleSfxHint( const uno::Reference< document::XVbaEventsHelper >& xVbaEventsHelper, const SfxHint& rHint )
1141 : {
1142 : if ( rHint.ISA( SfxEventHint ) )
1143 : {
1144 : uno::Sequence< uno::Any > aArgs;
1145 : sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId();
1146 : switch( nEventId )
1147 : {
1148 : case SFX_EVENT_CREATEDOC:
1149 : {
1150 : xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_DOCUMENT_NEW, aArgs );
1151 : break;
1152 : }
1153 : case SFX_EVENT_OPENDOC:
1154 : {
1155 : xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_DOCUMENT_OPEN, aArgs );
1156 : break;
1157 : }
1158 : default:
1159 : {
1160 : //do nothing
1161 : }
1162 : }
1163 : }
1164 : }
1165 : #endif
1166 :
1167 0 : bool SwDocShell::DdeGetData( const OUString& rItem, const OUString& rMimeType,
1168 : uno::Any & rValue )
1169 : {
1170 0 : return pDoc->GetData( rItem, rMimeType, rValue );
1171 : }
1172 :
1173 0 : bool SwDocShell::DdeSetData( const OUString& rItem, const OUString& rMimeType,
1174 : const uno::Any & rValue )
1175 : {
1176 0 : return pDoc->SetData( rItem, rMimeType, rValue );
1177 : }
1178 :
1179 0 : ::sfx2::SvLinkSource* SwDocShell::DdeCreateLinkSource( const OUString& rItem )
1180 : {
1181 0 : return pDoc->CreateLinkSource( rItem );
1182 : }
1183 :
1184 0 : void SwDocShell::ReconnectDdeLink(SfxObjectShell& rServer)
1185 : {
1186 0 : if ( pDoc ) {
1187 0 : ::sfx2::LinkManager& rLinkManager = pDoc->GetLinkManager();
1188 0 : rLinkManager.ReconnectDdeLink(rServer);
1189 : }
1190 0 : }
1191 :
1192 0 : void SwDocShell::FillClass( SvGlobalName * pClassName,
1193 : sal_uInt32 * pClipFormat,
1194 : OUString * /*pAppName*/,
1195 : OUString * pLongUserName,
1196 : OUString * pUserName,
1197 : sal_Int32 nVersion,
1198 : bool bTemplate /* = false */) const
1199 : {
1200 0 : if (nVersion == SOFFICE_FILEFORMAT_60)
1201 : {
1202 0 : *pClassName = SvGlobalName( SO3_SW_CLASSID_60 );
1203 0 : *pClipFormat = SOT_FORMATSTR_ID_STARWRITER_60;
1204 0 : *pLongUserName = SW_RESSTR(STR_WRITER_DOCUMENT_FULLTYPE);
1205 : }
1206 0 : else if (nVersion == SOFFICE_FILEFORMAT_8)
1207 : {
1208 0 : *pClassName = SvGlobalName( SO3_SW_CLASSID_60 );
1209 0 : *pClipFormat = bTemplate ? SOT_FORMATSTR_ID_STARWRITER_8_TEMPLATE : SOT_FORMATSTR_ID_STARWRITER_8;
1210 0 : *pLongUserName = SW_RESSTR(STR_WRITER_DOCUMENT_FULLTYPE);
1211 : }
1212 : // #FIXME check with new Event handling
1213 : #if 0
1214 : uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper = pDoc->GetVbaEventsHelper();
1215 : if( xVbaEventsHelper.is() )
1216 : lcl_processCompatibleSfxHint( xVbaEventsHelper, rHint );
1217 : #endif
1218 :
1219 0 : *pUserName = SW_RESSTR(STR_HUMAN_SWDOC_NAME);
1220 0 : }
1221 :
1222 0 : void SwDocShell::SetModified( bool bSet )
1223 : {
1224 0 : SfxObjectShell::SetModified( bSet );
1225 0 : if( IsEnableSetModified())
1226 : {
1227 0 : if (!pDoc->IsInCallModified() )
1228 : {
1229 0 : EnableSetModified( false );
1230 0 : if( bSet )
1231 : {
1232 0 : sal_Bool bOld = pDoc->IsModified();
1233 0 : pDoc->SetModified();
1234 0 : if( !bOld )
1235 : {
1236 0 : pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
1237 : }
1238 : }
1239 : else
1240 0 : pDoc->ResetModified();
1241 :
1242 0 : EnableSetModified( true );
1243 : }
1244 :
1245 0 : UpdateChildWindows();
1246 0 : Broadcast(SfxSimpleHint(SFX_HINT_DOCCHANGED));
1247 : }
1248 0 : }
1249 :
1250 0 : void SwDocShell::UpdateChildWindows()
1251 : {
1252 : // if necessary newly initialize Flddlg (i.e. for TYP_SETVAR)
1253 0 : if(!GetView())
1254 0 : return;
1255 0 : SfxViewFrame* pVFrame = GetView()->GetViewFrame();
1256 : SwFldDlgWrapper *pWrp = (SwFldDlgWrapper*)pVFrame->
1257 0 : GetChildWindow( SwFldDlgWrapper::GetChildWindowId() );
1258 0 : if( pWrp )
1259 0 : pWrp->ReInitDlg( this );
1260 :
1261 : // if necessary newly initialize RedlineDlg
1262 : SwRedlineAcceptChild *pRed = (SwRedlineAcceptChild*)pVFrame->
1263 0 : GetChildWindow( SwRedlineAcceptChild::GetChildWindowId() );
1264 0 : if( pRed )
1265 0 : pRed->ReInitDlg( this );
1266 : }
1267 :
1268 : // #i48748#
1269 0 : class SwReloadFromHtmlReader : public SwReader
1270 : {
1271 : public:
1272 0 : SwReloadFromHtmlReader( SfxMedium& _rTmpMedium,
1273 : const OUString& _rFilename,
1274 : SwDoc* _pDoc )
1275 0 : : SwReader( _rTmpMedium, _rFilename, _pDoc )
1276 : {
1277 0 : SetBaseURL( _rFilename );
1278 0 : }
1279 : };
1280 :
1281 0 : void SwDocShell::ReloadFromHtml( const OUString& rStreamName, SwSrcView* pSrcView )
1282 : {
1283 0 : sal_Bool bModified = IsModified();
1284 :
1285 : // The HTTP-Header fields have to be removed, otherwise
1286 : // there are some from Meta-Tags dublicated or triplicated afterwards.
1287 0 : ClearHeaderAttributesForSourceViewHack();
1288 :
1289 : #ifndef DISABLE_SCRIPTING
1290 : // The Document-Basic also bites the dust ...
1291 : // A EnterBasicCall is not needed here, because nothing is called and
1292 : // there can't be any Dok-Basic, that has not yet been loaded inside
1293 : // of an HTML document.
1294 0 : SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
1295 : //#59620# HasBasic() shows, that there already is a BasicManager at the DocShell.
1296 : // That was always generated in HTML-Import, when there are
1297 : // Macros in the source code.
1298 0 : if( rHtmlOptions.IsStarBasic() && HasBasic())
1299 : {
1300 0 : BasicManager *pBasicMan = GetBasicManager();
1301 0 : if( pBasicMan && (pBasicMan != SFX_APP()->GetBasicManager()) )
1302 : {
1303 0 : sal_uInt16 nLibCount = pBasicMan->GetLibCount();
1304 0 : while( nLibCount )
1305 : {
1306 0 : StarBASIC *pBasic = pBasicMan->GetLib( --nLibCount );
1307 0 : if( pBasic )
1308 : {
1309 : // Notify the IDE
1310 0 : SfxUsrAnyItem aShellItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( GetModel() ) );
1311 0 : OUString aLibName( pBasic->GetName() );
1312 0 : SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName );
1313 : pSrcView->GetViewFrame()->GetDispatcher()->Execute(
1314 : SID_BASICIDE_LIBREMOVED,
1315 : SFX_CALLMODE_SYNCHRON,
1316 0 : &aShellItem, &aLibNameItem, 0L );
1317 :
1318 : // Only the modules are deleted from the standard-lib
1319 0 : if( nLibCount )
1320 0 : pBasicMan->RemoveLib( nLibCount, true );
1321 : else
1322 0 : pBasic->Clear();
1323 : }
1324 : }
1325 :
1326 : OSL_ENSURE( pBasicMan->GetLibCount() <= 1,
1327 : "Deleting Basics didn't work" );
1328 : }
1329 : }
1330 : #endif
1331 0 : sal_Bool bWasBrowseMode = pDoc->get(IDocumentSettingAccess::BROWSE_MODE);
1332 0 : RemoveLink();
1333 :
1334 : // now also the UNO-Model has to be informed about the new Doc #51535#
1335 0 : uno::Reference<text::XTextDocument> xDoc(GetBaseModel(), uno::UNO_QUERY);
1336 0 : text::XTextDocument* pxDoc = xDoc.get();
1337 0 : ((SwXTextDocument*)pxDoc)->InitNewDoc();
1338 :
1339 0 : AddLink();
1340 : //#116402# update font list when new document is created
1341 0 : UpdateFontList();
1342 0 : pDoc->set(IDocumentSettingAccess::BROWSE_MODE, bWasBrowseMode);
1343 0 : pSrcView->SetPool(&GetPool());
1344 :
1345 0 : const OUString& rMedname = GetMedium()->GetName();
1346 :
1347 : // The HTML template still has to be set
1348 0 : SetHTMLTemplate( *GetDoc() ); //Styles from HTML.vor
1349 :
1350 0 : SfxViewShell* pViewShell = GetView() ? (SfxViewShell*)GetView()
1351 0 : : SfxViewShell::Current();
1352 0 : SfxViewFrame* pViewFrm = pViewShell->GetViewFrame();
1353 0 : pViewFrm->GetDispatcher()->Execute( SID_VIEWSHELL0, SFX_CALLMODE_SYNCHRON );
1354 :
1355 0 : SubInitNew();
1356 :
1357 0 : SfxMedium aMed( rStreamName, STREAM_READ );
1358 : // #i48748# - use class <SwReloadFromHtmlReader>, because
1359 : // the base URL has to be set to the filename of the document <rMedname>
1360 : // and not to the base URL of the temporary file <aMed> in order to get
1361 : // the URLs of the linked graphics correctly resolved.
1362 0 : SwReloadFromHtmlReader aReader( aMed, rMedname, pDoc );
1363 :
1364 0 : aReader.Read( *ReadHTML );
1365 :
1366 0 : const SwView* pCurrView = GetView();
1367 : //in print layout the first page(s) may have been formatted as a mix of browse
1368 : //and print layout
1369 0 : if(!bWasBrowseMode && pCurrView)
1370 : {
1371 0 : SwWrtShell& rWrtSh = pCurrView->GetWrtShell();
1372 0 : if( rWrtSh.GetLayout())
1373 0 : rWrtSh.CheckBrowseView( sal_True );
1374 : }
1375 :
1376 : // Take HTTP-Header-Attibutes over into the DokInfo again.
1377 : // The Base-URL doesn't matter here because TLX uses the one from the document
1378 : // for absolutization.
1379 0 : SetHeaderAttributesForSourceViewHack();
1380 :
1381 0 : if(bModified && !IsReadOnly())
1382 0 : SetModified();
1383 : else
1384 0 : pDoc->ResetModified();
1385 0 : }
1386 :
1387 0 : sal_uLong SwDocShell::LoadStylesFromFile( const OUString& rURL,
1388 : SwgReaderOption& rOpt, sal_Bool bUnoCall )
1389 : {
1390 0 : sal_uLong nErr = 0;
1391 :
1392 : // Set filter:
1393 0 : OUString sFactory(OUString::createFromAscii(SwDocShell::Factory().GetShortName()));
1394 0 : SfxFilterMatcher aMatcher( sFactory );
1395 :
1396 : // search for filter in WebDocShell, too
1397 0 : SfxMedium aMed( rURL, STREAM_STD_READ );
1398 0 : const SfxFilter* pFlt = 0;
1399 0 : aMatcher.DetectFilter( aMed, &pFlt, false, false );
1400 0 : if(!pFlt)
1401 : {
1402 0 : OUString sWebFactory(OUString::createFromAscii(SwWebDocShell::Factory().GetShortName()));
1403 0 : SfxFilterMatcher aWebMatcher( sWebFactory );
1404 0 : aWebMatcher.DetectFilter( aMed, &pFlt, false, false );
1405 : }
1406 : // --> OD #i117339# - trigger import only for own formats
1407 0 : bool bImport( false );
1408 : {
1409 0 : if ( aMed.IsStorage() )
1410 : {
1411 : // As <SfxMedium.GetFilter().IsOwnFormat() resp. IsOwnTemplateFormat()
1412 : // does not work correct (e.g., MS Word 2007 XML Template),
1413 : // use workaround provided by MAV.
1414 0 : uno::Reference< embed::XStorage > xStorage = aMed.GetStorage();
1415 0 : if ( xStorage.is() )
1416 : {
1417 : // use <try-catch> on retrieving <MediaType> in order to check,
1418 : // if the storage is one of our own ones.
1419 : try
1420 : {
1421 0 : uno::Reference< beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY_THROW );
1422 0 : const OUString aMediaTypePropName( "MediaType" );
1423 0 : xProps->getPropertyValue( aMediaTypePropName );
1424 0 : bImport = true;
1425 : }
1426 0 : catch (const uno::Exception&)
1427 : {
1428 0 : bImport = false;
1429 : }
1430 0 : }
1431 : }
1432 : }
1433 0 : if ( bImport )
1434 : {
1435 0 : SwRead pRead = ReadXML;
1436 0 : boost::scoped_ptr<SwReader> pReader;
1437 0 : boost::scoped_ptr<SwPaM> pPam;
1438 : // the SW3IO - Reader need the pam/wrtshell, because only then he
1439 : // insert the styles!
1440 0 : if( bUnoCall )
1441 : {
1442 0 : SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfContent(), -1 );
1443 0 : pPam.reset(new SwPaM( aIdx ));
1444 0 : pReader.reset(new SwReader( aMed, rURL, *pPam ));
1445 : }
1446 : else
1447 : {
1448 0 : pReader.reset(new SwReader( aMed, rURL, *pWrtShell->GetCrsr() ));
1449 : }
1450 :
1451 0 : pRead->GetReaderOpt().SetTxtFmts( rOpt.IsTxtFmts() );
1452 0 : pRead->GetReaderOpt().SetFrmFmts( rOpt.IsFrmFmts() );
1453 0 : pRead->GetReaderOpt().SetPageDescs( rOpt.IsPageDescs() );
1454 0 : pRead->GetReaderOpt().SetNumRules( rOpt.IsNumRules() );
1455 0 : pRead->GetReaderOpt().SetMerge( rOpt.IsMerge() );
1456 :
1457 0 : if( bUnoCall )
1458 : {
1459 0 : UnoActionContext aAction( pDoc );
1460 0 : nErr = pReader->Read( *pRead );
1461 : }
1462 : else
1463 : {
1464 0 : pWrtShell->StartAllAction();
1465 0 : nErr = pReader->Read( *pRead );
1466 0 : pWrtShell->EndAllAction();
1467 0 : }
1468 : }
1469 :
1470 0 : return nErr;
1471 : }
1472 :
1473 : // Get a client for an embedded object if possible.
1474 0 : SfxInPlaceClient* SwDocShell::GetIPClient( const ::svt::EmbeddedObjectRef& xObjRef )
1475 : {
1476 0 : SfxInPlaceClient* pResult = NULL;
1477 :
1478 0 : SwWrtShell* pShell = GetWrtShell();
1479 0 : if ( pShell )
1480 : {
1481 0 : pResult = pShell->GetView().FindIPClient( xObjRef.GetObject(), (Window*)&pShell->GetView().GetEditWin() );
1482 0 : if ( !pResult )
1483 0 : pResult = new SwOleClient( &pShell->GetView(), &pShell->GetView().GetEditWin(), xObjRef );
1484 : }
1485 :
1486 0 : return pResult;
1487 : }
1488 :
1489 0 : int SwFindDocShell( SfxObjectShellRef& xDocSh,
1490 : SfxObjectShellLock& xLockRef,
1491 : const OUString& rFileName,
1492 : const OUString& rPasswd,
1493 : const OUString& rFilter,
1494 : sal_Int16 nVersion,
1495 : SwDocShell* pDestSh )
1496 : {
1497 0 : if ( rFileName.isEmpty() )
1498 0 : return 0;
1499 :
1500 : // 1. Does the file already exist in the list of all Documents?
1501 0 : INetURLObject aTmpObj( rFileName );
1502 0 : aTmpObj.SetMark( OUString() );
1503 :
1504 : // Iterate over the DocShell and get the ones with the name
1505 0 : TypeId aType( TYPE(SwDocShell) );
1506 :
1507 0 : SfxObjectShell* pShell = pDestSh;
1508 0 : bool bFirst = 0 != pShell;
1509 :
1510 0 : if( !bFirst )
1511 : // No DocShell passed, starting with the first from the DocShell list
1512 0 : pShell = SfxObjectShell::GetFirst( &aType );
1513 :
1514 0 : while( pShell )
1515 : {
1516 : // We want this one
1517 0 : SfxMedium* pMed = pShell->GetMedium();
1518 0 : if( pMed && pMed->GetURLObject() == aTmpObj )
1519 : {
1520 : const SfxPoolItem* pItem;
1521 0 : if( ( SFX_ITEM_SET == pMed->GetItemSet()->GetItemState(
1522 0 : SID_VERSION, false, &pItem ) )
1523 0 : ? (nVersion == ((SfxInt16Item*)pItem)->GetValue())
1524 : : !nVersion )
1525 : {
1526 : // Found, thus return
1527 0 : xDocSh = pShell;
1528 0 : return 1;
1529 : }
1530 : }
1531 :
1532 0 : if( bFirst )
1533 : {
1534 0 : bFirst = false;
1535 0 : pShell = SfxObjectShell::GetFirst( &aType );
1536 : }
1537 : else
1538 0 : pShell = SfxObjectShell::GetNext( *pShell, &aType );
1539 : }
1540 :
1541 : // 2. Open the file ourselves
1542 : SfxMedium* pMed = new SfxMedium( aTmpObj.GetMainURL(
1543 0 : INetURLObject::NO_DECODE ), STREAM_READ );
1544 0 : if( INET_PROT_FILE == aTmpObj.GetProtocol() )
1545 0 : pMed->Download(); // Touch the medium (download it)
1546 :
1547 0 : const SfxFilter* pSfxFlt = 0;
1548 0 : if( !pMed->GetError() )
1549 : {
1550 0 : SfxFilterMatcher aMatcher( OUString::createFromAscii(SwDocShell::Factory().GetShortName()) );
1551 :
1552 : // No Filter, so search for it. Else test if the one passed is a valid one
1553 0 : if( !rFilter.isEmpty() )
1554 : {
1555 0 : pSfxFlt = aMatcher.GetFilter4FilterName( rFilter );
1556 : }
1557 :
1558 0 : if( nVersion )
1559 0 : pMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion ));
1560 :
1561 0 : if( !rPasswd.isEmpty() )
1562 0 : pMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd ));
1563 :
1564 0 : if( !pSfxFlt )
1565 0 : aMatcher.DetectFilter( *pMed, &pSfxFlt, false, false );
1566 :
1567 0 : if( pSfxFlt )
1568 : {
1569 : // We cannot do anything without a Filter
1570 0 : pMed->SetFilter( pSfxFlt );
1571 :
1572 : // If the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure
1573 0 : xLockRef = new SwDocShell( SFX_CREATE_MODE_INTERNAL );
1574 0 : xDocSh = (SfxObjectShell*)xLockRef;
1575 0 : if( xDocSh->DoLoad( pMed ) )
1576 0 : return 2;
1577 0 : }
1578 : }
1579 :
1580 0 : if( !xDocSh.Is() ) // Medium still needs to be deleted
1581 0 : delete pMed;
1582 :
1583 0 : return 0;
1584 0 : }
1585 :
1586 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|