update dev300-m58
[ooovba.git] / sw / source / ui / app / docshini.cxx
blob5fde691f717d90ba8e407dfb040e132df3285c0b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docshini.cxx,v $
10 * $Revision: 1.67 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
37 #ifndef _SVX_DIALOGS_HRC
38 #include <svx/dialogs.hrc>
39 #endif
40 #include <sot/storinfo.hxx>
41 #include <sot/storage.hxx>
42 #include <svtools/zforlist.hxx>
43 #include <svtools/ctrltool.hxx>
44 #include <svtools/lingucfg.hxx>
45 #include <sfx2/docfile.hxx>
46 #ifndef _OFA_MISCCFG_HXX //autogen
47 #include <svtools/misccfg.hxx>
48 #endif
49 #include <sfx2/printer.hxx>
50 #include <sfx2/bindings.hxx>
51 #include <svx/asiancfg.hxx>
52 #include <svx/unolingu.hxx>
53 #include <sfx2/request.hxx>
54 #include <svtools/intitem.hxx>
55 #include <svx/adjitem.hxx>
56 #ifndef _SVX_AKRNTEM_HXX
57 #include <svx/akrnitem.hxx>
58 #endif
59 #include <linguistic/lngprops.hxx>
60 #include <com/sun/star/document/UpdateDocMode.hpp>
61 #include <rtl/logfile.hxx>
62 #include <sfx2/docfilt.hxx>
63 #include <svx/xtable.hxx>
64 #ifndef _SVX_DRAWITEM_HXX //autogen
66 #include <svx/drawitem.hxx>
67 #endif
68 #include <svx/fhgtitem.hxx>
69 #include <svx/fontitem.hxx>
70 #include <svx/flstitem.hxx>
71 #ifndef _SVX_TSTPITEM_HXX //autogen
72 #include <svx/tstpitem.hxx>
73 #endif
74 #include <svx/langitem.hxx>
75 #include <svx/colritem.hxx>
76 #include <svx/hyznitem.hxx>
77 #include <svx/svxacorr.hxx>
79 #include <vcl/svapp.hxx>
80 #include <view.hxx>
81 #include <prtopt.hxx>
82 #include <fmtcol.hxx>
83 #ifndef _DOCSH_HXX
84 #include <docsh.hxx>
85 #endif
86 #ifndef _WDOCSH_HXX
87 #include <wdocsh.hxx>
88 #endif
89 #include <swmodule.hxx>
90 #include <doc.hxx>
91 #include <docfac.hxx>
92 #include <docstyle.hxx>
93 #include <shellio.hxx>
94 #include <tox.hxx>
95 #include <swdtflvr.hxx>
96 #ifndef _DBMGR_HXX
97 #include <dbmgr.hxx>
98 #endif
99 #include <usrpref.hxx>
100 #include <fontcfg.hxx>
101 #include <poolfmt.hxx>
102 #ifndef _MODCFG_HXX
103 #include <modcfg.hxx>
104 #endif
105 #ifndef _GLOBDOC_HXX
106 #include <globdoc.hxx>
107 #endif
108 #include <ndole.hxx>
109 #include <mdiexp.hxx>
110 #include <unotxdoc.hxx>
111 #include <linkenum.hxx>
112 #include <swwait.hxx>
113 #include <wrtsh.hxx>
114 #include <swerror.h>
115 #ifndef _GLOBALS_HRC
116 #include <globals.hrc>
117 #endif
120 // #i18732#
121 #include <fmtfollowtextflow.hxx>
123 #include <unochart.hxx>
125 // text grid
126 #include <tgrditem.hxx>
128 using namespace ::com::sun::star::i18n;
129 using namespace ::com::sun::star::lang;
130 using namespace ::com::sun::star::uno;
131 using namespace ::com::sun::star;
132 using ::rtl::OUString;
134 /*-----------------21.09.96 15.29-------------------
136 --------------------------------------------------*/
139 /*--------------------------------------------------------------------
140 Beschreibung: Document laden
141 --------------------------------------------------------------------*/
144 sal_Bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
146 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::InitNew" );
148 sal_Bool bRet = SfxObjectShell::InitNew( xStor );
149 ASSERT( GetMapUnit() == MAP_TWIP, "map unit is not twip!" );
150 sal_Bool bHTMLTemplSet = sal_False;
151 if( bRet )
153 AddLink(); // pDoc / pIo ggf. anlegen
155 sal_Bool bWeb = ISA( SwWebDocShell );
156 if ( bWeb )
157 bHTMLTemplSet = SetHTMLTemplate( *GetDoc() );//Styles aus HTML.vor
158 else if( ISA( SwGlobalDocShell ) )
159 GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true); // Globaldokument
163 //JP 12.07.95: so einfach waere es fuer die neu Mimik
164 pDoc->SetDefault( SvxTabStopItem( 1,
165 GetStar Writer App()->GetUsrPref()->GetDefTabDist(),
166 SVX_TAB_ADJUST_DEFAULT,
167 RES_PARATR_TABSTOP));
169 if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
170 SwTransferable::InitOle( this, *pDoc );
172 // set forbidden characters if necessary
173 SvxAsianConfig aAsian;
174 Sequence<Locale> aLocales = aAsian.GetStartEndCharLocales();
175 if(aLocales.getLength())
177 const Locale* pLocales = aLocales.getConstArray();
178 for(sal_Int32 i = 0; i < aLocales.getLength(); i++)
180 ForbiddenCharacters aForbidden;
181 aAsian.GetStartEndChars( pLocales[i], aForbidden.beginLine, aForbidden.endLine);
182 LanguageType eLang = SvxLocaleToLanguage(pLocales[i]);
183 pDoc->setForbiddenCharacters( eLang, aForbidden);
186 pDoc->set(IDocumentSettingAccess::KERN_ASIAN_PUNCTUATION,
187 !aAsian.IsKerningWesternTextOnly());
188 pDoc->setCharacterCompressionType(static_cast<SwCharCompressType>(aAsian.GetCharDistanceCompression()));
189 pDoc->setPrintData(*SW_MOD()->GetPrtOptions(bWeb));
191 SubInitNew();
193 // fuer alle
195 SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
196 SfxPrinter* pPrt = pDoc->getPrinter( false );
198 String sEntry;
199 USHORT aFontWhich[] =
200 { RES_CHRATR_FONT,
201 RES_CHRATR_CJK_FONT,
202 RES_CHRATR_CTL_FONT
204 USHORT aFontHeightWhich[] =
206 RES_CHRATR_FONTSIZE,
207 RES_CHRATR_CJK_FONTSIZE,
208 RES_CHRATR_CTL_FONTSIZE
210 USHORT aFontIds[] =
212 FONT_STANDARD,
213 FONT_STANDARD_CJK,
214 FONT_STANDARD_CTL
216 USHORT nFontTypes[] =
218 DEFAULTFONT_LATIN_TEXT,
219 DEFAULTFONT_CJK_TEXT,
220 DEFAULTFONT_CTL_TEXT
222 USHORT aLangTypes[] =
224 RES_CHRATR_LANGUAGE,
225 RES_CHRATR_CJK_LANGUAGE,
226 RES_CHRATR_CTL_LANGUAGE
229 for(sal_uInt8 i = 0; i < 3; i++)
231 USHORT nFontWhich = aFontWhich[i];
232 USHORT nFontId = aFontIds[i];
233 SvxFontItem* pFontItem = 0;
234 const SvxLanguageItem& rLang = (const SvxLanguageItem&)pDoc->GetDefault( aLangTypes[i] );
235 LanguageType eLanguage = rLang.GetLanguage();
236 if(!pStdFont->IsFontDefault(nFontId))
238 sEntry = pStdFont->GetFontFor(nFontId);
239 sal_Bool bDelete = sal_False;
240 const SfxFont* pFnt = pPrt ? pPrt->GetFontByName(sEntry): 0;
241 if(!pFnt)
243 pFnt = new SfxFont( FAMILY_DONTKNOW, sEntry, PITCH_DONTKNOW,
244 ::gsl_getSystemTextEncoding() );
245 bDelete = sal_True;
247 pFontItem = new SvxFontItem(pFnt->GetFamily(), pFnt->GetName(),
248 aEmptyStr, pFnt->GetPitch(), pFnt->GetCharSet(), nFontWhich);
249 if(bDelete)
251 delete (SfxFont*) pFnt;
252 bDelete = sal_False;
255 else
257 // #107782# OJ use korean language if latin was used
258 if ( i == 0 )
260 LanguageType eUiLanguage = Application::GetSettings().GetUILanguage();
261 switch( eUiLanguage )
263 case LANGUAGE_KOREAN:
264 case LANGUAGE_KOREAN_JOHAB:
265 eLanguage = eUiLanguage;
266 break;
270 Font aLangDefFont = OutputDevice::GetDefaultFont(
271 nFontTypes[i],
272 eLanguage,
273 DEFAULTFONT_FLAGS_ONLYONE );
274 pFontItem = new SvxFontItem(aLangDefFont.GetFamily(), aLangDefFont.GetName(),
275 aEmptyStr, aLangDefFont.GetPitch(), aLangDefFont.GetCharSet(), nFontWhich);
277 pDoc->SetDefault(*pFontItem);
278 if( !bHTMLTemplSet )
280 SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD);
281 pColl->ResetFmtAttr(nFontWhich);
283 delete pFontItem;
284 sal_Int32 nFontHeight = pStdFont->GetFontHeight( FONT_STANDARD, i, eLanguage );
285 if(nFontHeight <= 0)
286 nFontHeight = pStdFont->GetDefaultHeightFor( nFontId, eLanguage );
287 pDoc->SetDefault(SvxFontHeightItem( nFontHeight, 100, aFontHeightWhich[i] ));
288 if( !bHTMLTemplSet )
290 SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD);
291 pColl->ResetFmtAttr(aFontHeightWhich[i]);
295 USHORT aFontIdPoolId[] =
297 FONT_OUTLINE, RES_POOLCOLL_HEADLINE_BASE,
298 FONT_LIST, RES_POOLCOLL_NUMBUL_BASE,
299 FONT_CAPTION, RES_POOLCOLL_LABEL,
300 FONT_INDEX, RES_POOLCOLL_REGISTER_BASE,
301 FONT_OUTLINE_CJK, RES_POOLCOLL_HEADLINE_BASE,
302 FONT_LIST_CJK, RES_POOLCOLL_NUMBUL_BASE,
303 FONT_CAPTION_CJK, RES_POOLCOLL_LABEL,
304 FONT_INDEX_CJK, RES_POOLCOLL_REGISTER_BASE,
305 FONT_OUTLINE_CTL, RES_POOLCOLL_HEADLINE_BASE,
306 FONT_LIST_CTL, RES_POOLCOLL_NUMBUL_BASE,
307 FONT_CAPTION_CTL, RES_POOLCOLL_LABEL,
308 FONT_INDEX_CTL, RES_POOLCOLL_REGISTER_BASE
311 USHORT nFontWhich = RES_CHRATR_FONT;
312 USHORT nFontHeightWhich = RES_CHRATR_FONTSIZE;
313 LanguageType eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_LANGUAGE )).GetLanguage();
314 for(sal_uInt8 nIdx = 0; nIdx < 24; nIdx += 2)
316 if(nIdx == 8)
318 nFontWhich = RES_CHRATR_CJK_FONT;
319 nFontHeightWhich = RES_CHRATR_CJK_FONTSIZE;
320 eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CJK_LANGUAGE )).GetLanguage();
322 else if(nIdx == 16)
324 nFontWhich = RES_CHRATR_CTL_FONT;
325 nFontHeightWhich = RES_CHRATR_CTL_FONTSIZE;
326 eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CTL_LANGUAGE )).GetLanguage();
328 SwTxtFmtColl *pColl = 0;
329 if(!pStdFont->IsFontDefault(aFontIdPoolId[nIdx]))
331 sEntry = pStdFont->GetFontFor(aFontIdPoolId[nIdx]);
332 sal_Bool bDelete = sal_False;
333 const SfxFont* pFnt = pPrt ? pPrt->GetFontByName(sEntry): 0;
334 if(!pFnt)
336 pFnt = new SfxFont( FAMILY_DONTKNOW, sEntry, PITCH_DONTKNOW,
337 ::gsl_getSystemTextEncoding() );
338 bDelete = sal_True;
340 pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]);
341 if( !bHTMLTemplSet ||
342 SFX_ITEM_SET != pColl->GetAttrSet().GetItemState(
343 nFontWhich, sal_False ) )
345 pColl->SetFmtAttr(SvxFontItem(pFnt->GetFamily(), pFnt->GetName(),
346 aEmptyStr, pFnt->GetPitch(), pFnt->GetCharSet(), nFontWhich));
348 if(bDelete)
350 delete (SfxFont*) pFnt;
353 sal_Int32 nFontHeight = pStdFont->GetFontHeight( static_cast< sal_Int8 >(aFontIdPoolId[nIdx]), 0, eLanguage );
354 if(nFontHeight <= 0)
355 nFontHeight = pStdFont->GetDefaultHeightFor( aFontIdPoolId[nIdx], eLanguage );
356 if(!pColl)
357 pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]);
358 SvxFontHeightItem aFontHeight( (const SvxFontHeightItem&)pColl->GetFmtAttr( nFontHeightWhich, sal_True ));
359 if(aFontHeight.GetHeight() != sal::static_int_cast<sal_uInt32, sal_Int32>(nFontHeight))
361 aFontHeight.SetHeight(nFontHeight);
362 pColl->SetFmtAttr( aFontHeight );
367 /* #106748# If the default frame direction of a document is RTL
368 the default adjusment is to the right. */
369 if( !bHTMLTemplSet &&
370 FRMDIR_HORI_RIGHT_TOP == GetDefaultFrameDirection(GetAppLanguage()) )
371 pDoc->SetDefault( SvxAdjustItem(SVX_ADJUST_RIGHT, RES_PARATR_ADJUST ) );
373 // OD 09.10.2003 #i18732# - set dynamic pool default for
374 // item RES_FOLLOW_TEXT_FLOW to FALSE for *new document*.
375 // Thus, redo this change in method <SwDoc::RemoveAllFmtLanguageDependencies()>,
376 // which is called from <SwDocShell::ConvertFrom(..)> in order to restore
377 // the static pool default.
378 pDoc->SetDefault( SwFmtFollowTextFlow( FALSE ) );
380 // --> collapsing borders FME 2005-05-27 #i29550#
381 pDoc->SetDefault( SfxBoolItem( RES_COLLAPSING_BORDERS, TRUE ) );
382 // <-- collapsing
384 //#i16874# AutoKerning as default for new documents
385 pDoc->SetDefault( SvxAutoKernItem( sal_True, RES_CHRATR_AUTOKERN ) );
387 // --> OD 2005-02-10 #i42080# - Due to the several calls of method <SetDefault(..)>
388 // at the document instance, the document is modified. Thus, reset this
389 // status here. Note: In method <SubInitNew()> this is also done.
390 pDoc->ResetModified();
391 // <--
393 return bRet;
396 /*--------------------------------------------------------------------
397 Beschreibung: Ctor mit SfxCreateMode ?????
398 --------------------------------------------------------------------*/
401 SwDocShell::SwDocShell( SfxObjectCreateMode eMode, sal_Bool _bScriptingSupport ) :
402 SfxObjectShell ( eMode ),
403 pDoc(0),
404 pFontList(0),
405 pView( 0 ),
406 pWrtShell( 0 ),
407 pOLEChildList( 0 ),
408 nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
409 bInUpdateFontList(false)
411 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::SwDocShell" );
412 if ( !_bScriptingSupport )
413 SetHasNoBasic();
414 Init_Impl();
417 /*--------------------------------------------------------------------
418 Beschreibung: Ctor / Dtor
419 --------------------------------------------------------------------*/
422 SwDocShell::SwDocShell( SwDoc *pD, SfxObjectCreateMode eMode ):
423 SfxObjectShell ( eMode ),
424 pDoc(pD),
425 pFontList(0),
426 pView( 0 ),
427 pWrtShell( 0 ),
428 pOLEChildList( 0 ),
429 nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
430 bInUpdateFontList(false)
432 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::SwDocShell" );
433 Init_Impl();
436 /*--------------------------------------------------------------------
437 Beschreibung: Dtor
438 --------------------------------------------------------------------*/
441 SwDocShell::~SwDocShell()
443 // disable chart related objects now because in ~SwDoc it may be to late for this
444 if( pDoc )
446 pDoc->GetChartControllerHelper().Disconnect();
447 SwChartDataProvider *pPCD = pDoc->GetChartDataProvider();
448 if (pPCD)
449 pPCD->dispose();
452 RemoveLink();
453 delete pFontList;
455 // wir als BroadCaster werden auch unser eigener Listener
456 // (fuer DocInfo/FileNamen/....)
457 EndListening( *this );
458 SvxColorTableItem* pColItem = (SvxColorTableItem*)GetItem(SID_COLOR_TABLE);
459 // wird nur die DocInfo fuer den Explorer gelesen, ist das Item nicht da
460 if(pColItem)
462 XColorTable* pTable = pColItem->GetColorTable();
463 // wurde eine neue Table angelegt, muss sie auch geloescht werden.
464 if((void*)pTable != (void*)(XColorTable::GetStdColorTable()) )
465 delete pTable;
468 delete pOLEChildList;
470 /* -----------------------------10.09.2001 15:59------------------------------
472 ---------------------------------------------------------------------------*/
473 void SwDocShell::Init_Impl()
475 SetPool(&SW_MOD()->GetPool());
476 SetBaseModel(new SwXTextDocument(this));
477 // wir als BroadCaster werden auch unser eigener Listener
478 // (fuer DocInfo/FileNamen/....)
479 StartListening( *this );
480 //position of the "Automatic" style filter for the stylist (app.src)
481 SetAutoStyleFilterIndex(3);
483 // set map unit to twip
484 SetMapUnit( MAP_TWIP );
486 /*--------------------------------------------------------------------
487 Beschreibung: AddLink
488 --------------------------------------------------------------------*/
491 void SwDocShell::AddLink()
493 if( !pDoc )
495 SwDocFac aFactory;
496 pDoc = aFactory.GetDoc();
497 pDoc->acquire();
498 pDoc->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell) );
500 else
501 pDoc->acquire();
502 pDoc->SetDocShell( this ); // am Doc den DocShell-Pointer setzen
503 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
504 ((SwXTextDocument*)xDoc.get())->Reactivate(this);
506 SetPool(&pDoc->GetAttrPool());
508 // am besten erst wenn eine sdbcx::View erzeugt wird !!!
509 pDoc->SetOle2Link(LINK(this, SwDocShell, Ole2ModifiedHdl));
512 /*--------------------------------------------------------------------
513 Beschreibung: neue FontList erzeugen Aenderung Drucker
514 --------------------------------------------------------------------*/
517 void SwDocShell::UpdateFontList()
519 if(!bInUpdateFontList)
521 bInUpdateFontList = true;
522 ASSERT(pDoc, "Kein Doc keine FontList");
523 if( pDoc )
525 delete pFontList;
526 pFontList = new FontList( pDoc->getReferenceDevice( true ) );
527 PutItem( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) );
529 bInUpdateFontList = false;
533 /*--------------------------------------------------------------------
534 Beschreibung: RemoveLink
535 --------------------------------------------------------------------*/
538 void SwDocShell::RemoveLink()
540 // Uno-Object abklemmen
541 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
542 ((SwXTextDocument*)xDoc.get())->Invalidate();
543 aFinishedTimer.Stop();
544 if(pDoc)
546 if( mxBasePool.is() )
548 static_cast<SwDocStyleSheetPool*>(mxBasePool.get())->dispose();
549 mxBasePool.clear();
551 sal_Int8 nRefCt = static_cast< sal_Int8 >(pDoc->release());
552 pDoc->SetOle2Link(Link());
553 pDoc->SetDocShell( 0 );
554 if( !nRefCt )
555 delete pDoc;
556 pDoc = 0; // wir haben das Doc nicht mehr !!
559 void SwDocShell::InvalidateModel()
561 // Uno-Object abklemmen
562 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
563 ((SwXTextDocument*)xDoc.get())->Invalidate();
565 void SwDocShell::ReactivateModel()
567 // Uno-Object abklemmen
568 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
569 ((SwXTextDocument*)xDoc.get())->Reactivate(this);
572 /*--------------------------------------------------------------------
573 Beschreibung: Laden, Default-Format
574 --------------------------------------------------------------------*/
577 sal_Bool SwDocShell::Load( SfxMedium& rMedium )
579 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::Load" );
580 sal_Bool bRet = sal_False;
581 if( SfxObjectShell::Load( rMedium ))
583 RTL_LOGFILE_CONTEXT_TRACE( aLog, "after SfxInPlaceObject::Load" );
584 if( pDoc ) // fuer Letzte Version !!
585 RemoveLink(); // das existierende Loslassen
587 AddLink(); // Link setzen und Daten updaten !!
589 // Das Laden
590 // fuer MD
591 ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
592 mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
593 if(GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
595 SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
596 nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
599 SwWait aWait( *this, sal_True );
600 sal_uInt32 nErr = ERR_SWG_READ_ERROR;
601 switch( GetCreateMode() )
603 // case SFX_CREATE_MODE_INTERNAL:
604 // nErr = 0;
605 // break;
607 case SFX_CREATE_MODE_ORGANIZER:
609 if( ReadXML )
611 ReadXML->SetOrganizerMode( TRUE );
612 SwReader aRdr( rMedium, aEmptyStr, pDoc );
613 nErr = aRdr.Read( *ReadXML );
614 ReadXML->SetOrganizerMode( FALSE );
617 break;
619 case SFX_CREATE_MODE_INTERNAL:
620 case SFX_CREATE_MODE_EMBEDDED:
622 // fuer MWERKS (Mac-Compiler): kann nicht selbststaendig casten
623 SwTransferable::InitOle( this, *pDoc );
625 // SfxProgress unterdruecken, wenn man Embedded ist
626 SW_MOD()->SetEmbeddedLoadSave( sal_True );
627 // kein break;
629 case SFX_CREATE_MODE_STANDARD:
630 case SFX_CREATE_MODE_PREVIEW:
632 Reader *pReader = ReadXML;
633 if( pReader )
635 // die DocInfo vom Doc am DocShell-Medium setzen
636 RTL_LOGFILE_CONTEXT_TRACE( aLog, "before ReadDocInfo" );
637 SwReader aRdr( rMedium, aEmptyStr, pDoc );
638 RTL_LOGFILE_CONTEXT_TRACE( aLog, "before Read" );
639 nErr = aRdr.Read( *pReader );
640 RTL_LOGFILE_CONTEXT_TRACE( aLog, "after Read" );
642 // If a XML document is loaded, the global doc/web doc
643 // flags have to be set, because they aren't loaded
644 // by this formats.
645 if( ISA( SwWebDocShell ) )
647 if( !pDoc->get(IDocumentSettingAccess::HTML_MODE) )
648 pDoc->set(IDocumentSettingAccess::HTML_MODE, true);
650 if( ISA( SwGlobalDocShell ) )
652 if( !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
653 pDoc->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
656 #ifndef PRODUCT
657 else
658 ASSERT( !this, "ohne Sw3Reader geht nichts" );
659 #endif
661 break;
663 default:
664 ASSERT( !this, "Load: new CreateMode?" );
668 UpdateFontList();
669 InitDraw();
671 SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
672 bRet = !IsError( nErr );
674 // --> OD 2006-11-07 #i59688#
675 // // StartFinishedLoading rufen.
676 // if( bRet && !pDoc->IsInLoadAsynchron() &&
677 // GetCreateMode() == SFX_CREATE_MODE_STANDARD )
678 // StartLoadFinishedTimer();
679 if ( bRet && !pDoc->IsInLoadAsynchron() &&
680 GetCreateMode() == SFX_CREATE_MODE_STANDARD )
682 LoadingFinished();
684 // <--
686 // SfxProgress unterdruecken, wenn man Embedded ist
687 SW_MOD()->SetEmbeddedLoadSave( sal_False );
690 return bRet;
693 /*--------------------------------------------------------------------
694 Beschreibung:
695 --------------------------------------------------------------------*/
698 sal_Bool SwDocShell::LoadFrom( SfxMedium& rMedium )
700 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::LoadFrom" );
701 sal_Bool bRet = sal_False;
702 if( pDoc )
703 RemoveLink();
705 AddLink(); // Link setzen und Daten updaten !!
707 do { // middle check loop
708 sal_uInt32 nErr = ERR_SWG_READ_ERROR;
709 //const String& rNm = pStor->GetName();
710 String aStreamName;
711 aStreamName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("styles.xml"));
712 uno::Reference < container::XNameAccess > xAccess( rMedium.GetStorage(), uno::UNO_QUERY );
713 if ( xAccess->hasByName( aStreamName ) && rMedium.GetStorage()->isStreamElement( aStreamName ) )
715 // Das Laden
716 SwWait aWait( *this, sal_True );
718 ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
719 mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
720 if( ReadXML )
722 ReadXML->SetOrganizerMode( TRUE );
723 SwReader aRdr( rMedium, aEmptyStr, pDoc );
724 nErr = aRdr.Read( *ReadXML );
725 ReadXML->SetOrganizerMode( FALSE );
729 else
731 DBG_ERROR("Code removed!");
733 //TODO/LATER: looks like some binary stuff?!
734 // sollte es sich um eine 2. Vrolage handeln ??
735 if( SvStorage::IsStorageFile( rNm ) )
736 break;
738 const SfxFilter* pFltr = SwIoSystem::GetFileFilter( rNm, aEmptyStr );
739 if( !pFltr || !pFltr->GetUserData().EqualsAscii( FILTER_SWG ))
740 break;
742 SfxMedium aMed( rNm, STREAM_STD_READ, FALSE );
743 if( 0 == ( nErr = aMed.GetInStream()->GetError() ) )
745 SwWait aWait( *this, sal_True );
746 SwReader aRead( aMed, rNm, pDoc );
747 nErr = aRead.Read( *ReadSwg );
752 SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
753 bRet = !IsError( nErr );
755 } while( sal_False );
757 SfxObjectShell::LoadFrom( rMedium );
758 pDoc->ResetModified();
759 return bRet;
763 void SwDocShell::SubInitNew()
765 ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
766 mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
767 UpdateFontList();
768 InitDraw();
770 pDoc->setLinkUpdateMode( GLOBALSETTING );
771 pDoc->setFieldUpdateFlags( AUTOUPD_GLOBALSETTING );
773 sal_Bool bWeb = ISA(SwWebDocShell);
775 sal_uInt16 nRange[] = {
776 RES_PARATR_ADJUST, RES_PARATR_ADJUST,
777 RES_CHRATR_COLOR, RES_CHRATR_COLOR,
778 RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
779 RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
780 RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
781 0, 0, 0 };
782 if(!bWeb)
784 nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 3 ] = RES_PARATR_TABSTOP;
785 nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 2 ] = RES_PARATR_HYPHENZONE;
787 SfxItemSet aDfltSet( pDoc->GetAttrPool(), nRange );
789 //! get lingu options without loading lingu DLL
790 SvtLinguOptions aLinguOpt;
792 SvtLinguConfig().GetOptions( aLinguOpt );
794 sal_Int16 nVal = aLinguOpt.nDefaultLanguage,
795 eCJK = aLinguOpt.nDefaultLanguage_CJK,
796 eCTL = aLinguOpt.nDefaultLanguage_CTL;
797 aDfltSet.Put( SvxLanguageItem( nVal, RES_CHRATR_LANGUAGE ) );
798 aDfltSet.Put( SvxLanguageItem( eCJK, RES_CHRATR_CJK_LANGUAGE ) );
799 aDfltSet.Put( SvxLanguageItem( eCTL, RES_CHRATR_CTL_LANGUAGE ) );
801 if(!bWeb)
803 SvxHyphenZoneItem aHyp( (SvxHyphenZoneItem&) pDoc->GetDefault(
804 RES_PARATR_HYPHENZONE) );
805 aHyp.GetMinLead() = static_cast< BYTE >(aLinguOpt.nHyphMinLeading);
806 aHyp.GetMinTrail() = static_cast< BYTE >(aLinguOpt.nHyphMinTrailing);
808 aDfltSet.Put( aHyp );
810 sal_uInt16 nNewPos = static_cast< sal_uInt16 >(SW_MOD()->GetUsrPref(FALSE)->GetDefTab());
811 if( nNewPos )
812 aDfltSet.Put( SvxTabStopItem( 1, nNewPos,
813 SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP ) );
815 aDfltSet.Put( SvxColorItem( Color( COL_AUTO ), RES_CHRATR_COLOR ) );
817 pDoc->SetDefault( aDfltSet );
819 //default page mode for text grid
820 if(!bWeb)
822 sal_Bool bSquaredPageMode = SW_MOD()->GetUsrPref(FALSE)->IsSquaredPageMode();
823 pDoc->SetDefaultPageMode( bSquaredPageMode );
826 pDoc->ResetModified();
830 * Document Interface Access
832 IDocumentDeviceAccess* SwDocShell::getIDocumentDeviceAccess() { return pDoc; }
833 const IDocumentSettingAccess* SwDocShell::getIDocumentSettingAccess() const { return pDoc; }
834 IDocumentChartDataProviderAccess* SwDocShell::getIDocumentChartDataProviderAccess() { return pDoc; }