merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / app / docshini.cxx
blobb2ce3411c414b34c05fc9f9b27dcf176982916e3
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 <i18npool/mslangid.hxx>
41 #include <sot/storinfo.hxx>
42 #include <sot/storage.hxx>
43 #include <svtools/zforlist.hxx>
44 #include <svtools/ctrltool.hxx>
45 #include <svtools/lingucfg.hxx>
46 #include <sfx2/docfile.hxx>
47 #ifndef _OFA_MISCCFG_HXX //autogen
48 #include <svtools/misccfg.hxx>
49 #endif
50 #include <sfx2/printer.hxx>
51 #include <sfx2/bindings.hxx>
52 #include <svx/asiancfg.hxx>
53 #include <svx/unolingu.hxx>
54 #include <sfx2/request.hxx>
55 #include <svtools/intitem.hxx>
56 #include <svx/adjitem.hxx>
57 #ifndef _SVX_AKRNTEM_HXX
58 #include <svx/akrnitem.hxx>
59 #endif
60 #include <linguistic/lngprops.hxx>
61 #include <com/sun/star/document/UpdateDocMode.hpp>
62 #include <com/sun/star/i18n/ScriptType.hpp>
63 #include <rtl/logfile.hxx>
64 #include <sfx2/docfilt.hxx>
65 #include <svx/xtable.hxx>
66 #ifndef _SVX_DRAWITEM_HXX //autogen
68 #include <svx/drawitem.hxx>
69 #endif
70 #include <svx/fhgtitem.hxx>
71 #include <svx/fontitem.hxx>
72 #include <svx/flstitem.hxx>
73 #ifndef _SVX_TSTPITEM_HXX //autogen
74 #include <svx/tstpitem.hxx>
75 #endif
76 #include <svx/langitem.hxx>
77 #include <svx/colritem.hxx>
78 #include <svx/hyznitem.hxx>
79 #include <svx/svxacorr.hxx>
81 #include <vcl/svapp.hxx>
82 #include <view.hxx>
83 #include <prtopt.hxx>
84 #include <fmtcol.hxx>
85 #ifndef _DOCSH_HXX
86 #include <docsh.hxx>
87 #endif
88 #ifndef _WDOCSH_HXX
89 #include <wdocsh.hxx>
90 #endif
91 #include <swmodule.hxx>
92 #include <doc.hxx>
93 #include <docfac.hxx>
94 #include <docstyle.hxx>
95 #include <shellio.hxx>
96 #include <tox.hxx>
97 #include <swdtflvr.hxx>
98 #ifndef _DBMGR_HXX
99 #include <dbmgr.hxx>
100 #endif
101 #include <usrpref.hxx>
102 #include <fontcfg.hxx>
103 #include <poolfmt.hxx>
104 #ifndef _MODCFG_HXX
105 #include <modcfg.hxx>
106 #endif
107 #ifndef _GLOBDOC_HXX
108 #include <globdoc.hxx>
109 #endif
110 #include <ndole.hxx>
111 #include <mdiexp.hxx>
112 #include <unotxdoc.hxx>
113 #include <linkenum.hxx>
114 #include <swwait.hxx>
115 #include <wrtsh.hxx>
116 #include <swerror.h>
117 #ifndef _GLOBALS_HRC
118 #include <globals.hrc>
119 #endif
122 // #i18732#
123 #include <fmtfollowtextflow.hxx>
125 #include <unochart.hxx>
127 // text grid
128 #include <tgrditem.hxx>
130 using namespace ::com::sun::star::i18n;
131 using namespace ::com::sun::star::lang;
132 using namespace ::com::sun::star::uno;
133 using namespace ::com::sun::star;
134 using ::rtl::OUString;
136 /*-----------------21.09.96 15.29-------------------
138 --------------------------------------------------*/
141 /*--------------------------------------------------------------------
142 Beschreibung: Document laden
143 --------------------------------------------------------------------*/
146 sal_Bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
148 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::InitNew" );
150 sal_Bool bRet = SfxObjectShell::InitNew( xStor );
151 ASSERT( GetMapUnit() == MAP_TWIP, "map unit is not twip!" );
152 sal_Bool bHTMLTemplSet = sal_False;
153 if( bRet )
155 AddLink(); // pDoc / pIo ggf. anlegen
157 sal_Bool bWeb = ISA( SwWebDocShell );
158 if ( bWeb )
159 bHTMLTemplSet = SetHTMLTemplate( *GetDoc() );//Styles aus HTML.vor
160 else if( ISA( SwGlobalDocShell ) )
161 GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true); // Globaldokument
165 //JP 12.07.95: so einfach waere es fuer die neu Mimik
166 pDoc->SetDefault( SvxTabStopItem( 1,
167 GetStar Writer App()->GetUsrPref()->GetDefTabDist(),
168 SVX_TAB_ADJUST_DEFAULT,
169 RES_PARATR_TABSTOP));
171 if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
172 SwTransferable::InitOle( this, *pDoc );
174 // set forbidden characters if necessary
175 SvxAsianConfig aAsian;
176 Sequence<Locale> aLocales = aAsian.GetStartEndCharLocales();
177 if(aLocales.getLength())
179 const Locale* pLocales = aLocales.getConstArray();
180 for(sal_Int32 i = 0; i < aLocales.getLength(); i++)
182 ForbiddenCharacters aForbidden;
183 aAsian.GetStartEndChars( pLocales[i], aForbidden.beginLine, aForbidden.endLine);
184 LanguageType eLang = SvxLocaleToLanguage(pLocales[i]);
185 pDoc->setForbiddenCharacters( eLang, aForbidden);
188 pDoc->set(IDocumentSettingAccess::KERN_ASIAN_PUNCTUATION,
189 !aAsian.IsKerningWesternTextOnly());
190 pDoc->setCharacterCompressionType(static_cast<SwCharCompressType>(aAsian.GetCharDistanceCompression()));
191 pDoc->setPrintData(*SW_MOD()->GetPrtOptions(bWeb));
193 SubInitNew();
195 // fuer alle
197 SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
198 SfxPrinter* pPrt = pDoc->getPrinter( false );
200 String sEntry;
201 USHORT aFontWhich[] =
202 { RES_CHRATR_FONT,
203 RES_CHRATR_CJK_FONT,
204 RES_CHRATR_CTL_FONT
206 USHORT aFontHeightWhich[] =
208 RES_CHRATR_FONTSIZE,
209 RES_CHRATR_CJK_FONTSIZE,
210 RES_CHRATR_CTL_FONTSIZE
212 USHORT aFontIds[] =
214 FONT_STANDARD,
215 FONT_STANDARD_CJK,
216 FONT_STANDARD_CTL
218 USHORT nFontTypes[] =
220 DEFAULTFONT_LATIN_TEXT,
221 DEFAULTFONT_CJK_TEXT,
222 DEFAULTFONT_CTL_TEXT
224 USHORT aLangTypes[] =
226 RES_CHRATR_LANGUAGE,
227 RES_CHRATR_CJK_LANGUAGE,
228 RES_CHRATR_CTL_LANGUAGE
231 for(sal_uInt8 i = 0; i < 3; i++)
233 USHORT nFontWhich = aFontWhich[i];
234 USHORT nFontId = aFontIds[i];
235 SvxFontItem* pFontItem = 0;
236 const SvxLanguageItem& rLang = (const SvxLanguageItem&)pDoc->GetDefault( aLangTypes[i] );
237 LanguageType eLanguage = rLang.GetLanguage();
238 if(!pStdFont->IsFontDefault(nFontId))
240 sEntry = pStdFont->GetFontFor(nFontId);
241 sal_Bool bDelete = sal_False;
242 const SfxFont* pFnt = pPrt ? pPrt->GetFontByName(sEntry): 0;
243 if(!pFnt)
245 pFnt = new SfxFont( FAMILY_DONTKNOW, sEntry, PITCH_DONTKNOW,
246 ::gsl_getSystemTextEncoding() );
247 bDelete = sal_True;
249 pFontItem = new SvxFontItem(pFnt->GetFamily(), pFnt->GetName(),
250 aEmptyStr, pFnt->GetPitch(), pFnt->GetCharSet(), nFontWhich);
251 if(bDelete)
253 delete (SfxFont*) pFnt;
254 bDelete = sal_False;
257 else
259 // #107782# OJ use korean language if latin was used
260 if ( i == 0 )
262 LanguageType eUiLanguage = Application::GetSettings().GetUILanguage();
263 switch( eUiLanguage )
265 case LANGUAGE_KOREAN:
266 case LANGUAGE_KOREAN_JOHAB:
267 eLanguage = eUiLanguage;
268 break;
272 Font aLangDefFont = OutputDevice::GetDefaultFont(
273 nFontTypes[i],
274 eLanguage,
275 DEFAULTFONT_FLAGS_ONLYONE );
276 pFontItem = new SvxFontItem(aLangDefFont.GetFamily(), aLangDefFont.GetName(),
277 aEmptyStr, aLangDefFont.GetPitch(), aLangDefFont.GetCharSet(), nFontWhich);
279 pDoc->SetDefault(*pFontItem);
280 if( !bHTMLTemplSet )
282 SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD);
283 pColl->ResetFmtAttr(nFontWhich);
285 delete pFontItem;
286 sal_Int32 nFontHeight = pStdFont->GetFontHeight( FONT_STANDARD, i, eLanguage );
287 if(nFontHeight <= 0)
288 nFontHeight = pStdFont->GetDefaultHeightFor( nFontId, eLanguage );
289 pDoc->SetDefault(SvxFontHeightItem( nFontHeight, 100, aFontHeightWhich[i] ));
290 if( !bHTMLTemplSet )
292 SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD);
293 pColl->ResetFmtAttr(aFontHeightWhich[i]);
297 USHORT aFontIdPoolId[] =
299 FONT_OUTLINE, RES_POOLCOLL_HEADLINE_BASE,
300 FONT_LIST, RES_POOLCOLL_NUMBUL_BASE,
301 FONT_CAPTION, RES_POOLCOLL_LABEL,
302 FONT_INDEX, RES_POOLCOLL_REGISTER_BASE,
303 FONT_OUTLINE_CJK, RES_POOLCOLL_HEADLINE_BASE,
304 FONT_LIST_CJK, RES_POOLCOLL_NUMBUL_BASE,
305 FONT_CAPTION_CJK, RES_POOLCOLL_LABEL,
306 FONT_INDEX_CJK, RES_POOLCOLL_REGISTER_BASE,
307 FONT_OUTLINE_CTL, RES_POOLCOLL_HEADLINE_BASE,
308 FONT_LIST_CTL, RES_POOLCOLL_NUMBUL_BASE,
309 FONT_CAPTION_CTL, RES_POOLCOLL_LABEL,
310 FONT_INDEX_CTL, RES_POOLCOLL_REGISTER_BASE
313 USHORT nFontWhich = RES_CHRATR_FONT;
314 USHORT nFontHeightWhich = RES_CHRATR_FONTSIZE;
315 LanguageType eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_LANGUAGE )).GetLanguage();
316 for(sal_uInt8 nIdx = 0; nIdx < 24; nIdx += 2)
318 if(nIdx == 8)
320 nFontWhich = RES_CHRATR_CJK_FONT;
321 nFontHeightWhich = RES_CHRATR_CJK_FONTSIZE;
322 eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CJK_LANGUAGE )).GetLanguage();
324 else if(nIdx == 16)
326 nFontWhich = RES_CHRATR_CTL_FONT;
327 nFontHeightWhich = RES_CHRATR_CTL_FONTSIZE;
328 eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CTL_LANGUAGE )).GetLanguage();
330 SwTxtFmtColl *pColl = 0;
331 if(!pStdFont->IsFontDefault(aFontIdPoolId[nIdx]))
333 sEntry = pStdFont->GetFontFor(aFontIdPoolId[nIdx]);
334 sal_Bool bDelete = sal_False;
335 const SfxFont* pFnt = pPrt ? pPrt->GetFontByName(sEntry): 0;
336 if(!pFnt)
338 pFnt = new SfxFont( FAMILY_DONTKNOW, sEntry, PITCH_DONTKNOW,
339 ::gsl_getSystemTextEncoding() );
340 bDelete = sal_True;
342 pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]);
343 if( !bHTMLTemplSet ||
344 SFX_ITEM_SET != pColl->GetAttrSet().GetItemState(
345 nFontWhich, sal_False ) )
347 pColl->SetFmtAttr(SvxFontItem(pFnt->GetFamily(), pFnt->GetName(),
348 aEmptyStr, pFnt->GetPitch(), pFnt->GetCharSet(), nFontWhich));
350 if(bDelete)
352 delete (SfxFont*) pFnt;
355 sal_Int32 nFontHeight = pStdFont->GetFontHeight( static_cast< sal_Int8 >(aFontIdPoolId[nIdx]), 0, eLanguage );
356 if(nFontHeight <= 0)
357 nFontHeight = pStdFont->GetDefaultHeightFor( aFontIdPoolId[nIdx], eLanguage );
358 if(!pColl)
359 pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]);
360 SvxFontHeightItem aFontHeight( (const SvxFontHeightItem&)pColl->GetFmtAttr( nFontHeightWhich, sal_True ));
361 if(aFontHeight.GetHeight() != sal::static_int_cast<sal_uInt32, sal_Int32>(nFontHeight))
363 aFontHeight.SetHeight(nFontHeight);
364 pColl->SetFmtAttr( aFontHeight );
369 /* #106748# If the default frame direction of a document is RTL
370 the default adjusment is to the right. */
371 if( !bHTMLTemplSet &&
372 FRMDIR_HORI_RIGHT_TOP == GetDefaultFrameDirection(GetAppLanguage()) )
373 pDoc->SetDefault( SvxAdjustItem(SVX_ADJUST_RIGHT, RES_PARATR_ADJUST ) );
375 // OD 09.10.2003 #i18732# - set dynamic pool default for
376 // item RES_FOLLOW_TEXT_FLOW to FALSE for *new document*.
377 // Thus, redo this change in method <SwDoc::RemoveAllFmtLanguageDependencies()>,
378 // which is called from <SwDocShell::ConvertFrom(..)> in order to restore
379 // the static pool default.
380 pDoc->SetDefault( SwFmtFollowTextFlow( FALSE ) );
382 // --> collapsing borders FME 2005-05-27 #i29550#
383 pDoc->SetDefault( SfxBoolItem( RES_COLLAPSING_BORDERS, TRUE ) );
384 // <-- collapsing
386 //#i16874# AutoKerning as default for new documents
387 pDoc->SetDefault( SvxAutoKernItem( sal_True, RES_CHRATR_AUTOKERN ) );
389 // --> OD 2005-02-10 #i42080# - Due to the several calls of method <SetDefault(..)>
390 // at the document instance, the document is modified. Thus, reset this
391 // status here. Note: In method <SubInitNew()> this is also done.
392 pDoc->ResetModified();
393 // <--
395 return bRet;
398 /*--------------------------------------------------------------------
399 Beschreibung: Ctor mit SfxCreateMode ?????
400 --------------------------------------------------------------------*/
403 SwDocShell::SwDocShell( SfxObjectCreateMode eMode, sal_Bool _bScriptingSupport ) :
404 SfxObjectShell ( eMode ),
405 pDoc(0),
406 pFontList(0),
407 pView( 0 ),
408 pWrtShell( 0 ),
409 pOLEChildList( 0 ),
410 nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
411 bInUpdateFontList(false)
413 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::SwDocShell" );
414 if ( !_bScriptingSupport )
415 SetHasNoBasic();
416 Init_Impl();
419 /*--------------------------------------------------------------------
420 Beschreibung: Ctor / Dtor
421 --------------------------------------------------------------------*/
424 SwDocShell::SwDocShell( SwDoc *pD, SfxObjectCreateMode eMode ):
425 SfxObjectShell ( eMode ),
426 pDoc(pD),
427 pFontList(0),
428 pView( 0 ),
429 pWrtShell( 0 ),
430 pOLEChildList( 0 ),
431 nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
432 bInUpdateFontList(false)
434 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::SwDocShell" );
435 Init_Impl();
438 /*--------------------------------------------------------------------
439 Beschreibung: Dtor
440 --------------------------------------------------------------------*/
443 SwDocShell::~SwDocShell()
445 // disable chart related objects now because in ~SwDoc it may be to late for this
446 if( pDoc )
448 pDoc->GetChartControllerHelper().Disconnect();
449 SwChartDataProvider *pPCD = pDoc->GetChartDataProvider();
450 if (pPCD)
451 pPCD->dispose();
454 RemoveLink();
455 delete pFontList;
457 // wir als BroadCaster werden auch unser eigener Listener
458 // (fuer DocInfo/FileNamen/....)
459 EndListening( *this );
460 SvxColorTableItem* pColItem = (SvxColorTableItem*)GetItem(SID_COLOR_TABLE);
461 // wird nur die DocInfo fuer den Explorer gelesen, ist das Item nicht da
462 if(pColItem)
464 XColorTable* pTable = pColItem->GetColorTable();
465 // wurde eine neue Table angelegt, muss sie auch geloescht werden.
466 if((void*)pTable != (void*)(XColorTable::GetStdColorTable()) )
467 delete pTable;
470 delete pOLEChildList;
472 /* -----------------------------10.09.2001 15:59------------------------------
474 ---------------------------------------------------------------------------*/
475 void SwDocShell::Init_Impl()
477 SetPool(&SW_MOD()->GetPool());
478 SetBaseModel(new SwXTextDocument(this));
479 // wir als BroadCaster werden auch unser eigener Listener
480 // (fuer DocInfo/FileNamen/....)
481 StartListening( *this );
482 //position of the "Automatic" style filter for the stylist (app.src)
483 SetAutoStyleFilterIndex(3);
485 // set map unit to twip
486 SetMapUnit( MAP_TWIP );
488 /*--------------------------------------------------------------------
489 Beschreibung: AddLink
490 --------------------------------------------------------------------*/
493 void SwDocShell::AddLink()
495 if( !pDoc )
497 SwDocFac aFactory;
498 pDoc = aFactory.GetDoc();
499 pDoc->acquire();
500 pDoc->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell) );
502 else
503 pDoc->acquire();
504 pDoc->SetDocShell( this ); // am Doc den DocShell-Pointer setzen
505 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
506 ((SwXTextDocument*)xDoc.get())->Reactivate(this);
508 SetPool(&pDoc->GetAttrPool());
510 // am besten erst wenn eine sdbcx::View erzeugt wird !!!
511 pDoc->SetOle2Link(LINK(this, SwDocShell, Ole2ModifiedHdl));
514 /*--------------------------------------------------------------------
515 Beschreibung: neue FontList erzeugen Aenderung Drucker
516 --------------------------------------------------------------------*/
519 void SwDocShell::UpdateFontList()
521 if(!bInUpdateFontList)
523 bInUpdateFontList = true;
524 ASSERT(pDoc, "Kein Doc keine FontList");
525 if( pDoc )
527 delete pFontList;
528 pFontList = new FontList( pDoc->getReferenceDevice( true ) );
529 PutItem( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) );
531 bInUpdateFontList = false;
535 /*--------------------------------------------------------------------
536 Beschreibung: RemoveLink
537 --------------------------------------------------------------------*/
540 void SwDocShell::RemoveLink()
542 // Uno-Object abklemmen
543 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
544 ((SwXTextDocument*)xDoc.get())->Invalidate();
545 aFinishedTimer.Stop();
546 if(pDoc)
548 if( mxBasePool.is() )
550 static_cast<SwDocStyleSheetPool*>(mxBasePool.get())->dispose();
551 mxBasePool.clear();
553 sal_Int8 nRefCt = static_cast< sal_Int8 >(pDoc->release());
554 pDoc->SetOle2Link(Link());
555 pDoc->SetDocShell( 0 );
556 if( !nRefCt )
557 delete pDoc;
558 pDoc = 0; // wir haben das Doc nicht mehr !!
561 void SwDocShell::InvalidateModel()
563 // Uno-Object abklemmen
564 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
565 ((SwXTextDocument*)xDoc.get())->Invalidate();
567 void SwDocShell::ReactivateModel()
569 // Uno-Object abklemmen
570 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
571 ((SwXTextDocument*)xDoc.get())->Reactivate(this);
574 /*--------------------------------------------------------------------
575 Beschreibung: Laden, Default-Format
576 --------------------------------------------------------------------*/
579 sal_Bool SwDocShell::Load( SfxMedium& rMedium )
581 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::Load" );
582 sal_Bool bRet = sal_False;
583 if( SfxObjectShell::Load( rMedium ))
585 RTL_LOGFILE_CONTEXT_TRACE( aLog, "after SfxInPlaceObject::Load" );
586 if( pDoc ) // fuer Letzte Version !!
587 RemoveLink(); // das existierende Loslassen
589 AddLink(); // Link setzen und Daten updaten !!
591 // Das Laden
592 // fuer MD
593 ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
594 mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
595 if(GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
597 SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
598 nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
601 SwWait aWait( *this, sal_True );
602 sal_uInt32 nErr = ERR_SWG_READ_ERROR;
603 switch( GetCreateMode() )
605 // case SFX_CREATE_MODE_INTERNAL:
606 // nErr = 0;
607 // break;
609 case SFX_CREATE_MODE_ORGANIZER:
611 if( ReadXML )
613 ReadXML->SetOrganizerMode( TRUE );
614 SwReader aRdr( rMedium, aEmptyStr, pDoc );
615 nErr = aRdr.Read( *ReadXML );
616 ReadXML->SetOrganizerMode( FALSE );
619 break;
621 case SFX_CREATE_MODE_INTERNAL:
622 case SFX_CREATE_MODE_EMBEDDED:
624 // fuer MWERKS (Mac-Compiler): kann nicht selbststaendig casten
625 SwTransferable::InitOle( this, *pDoc );
627 // SfxProgress unterdruecken, wenn man Embedded ist
628 SW_MOD()->SetEmbeddedLoadSave( sal_True );
629 // kein break;
631 case SFX_CREATE_MODE_STANDARD:
632 case SFX_CREATE_MODE_PREVIEW:
634 Reader *pReader = ReadXML;
635 if( pReader )
637 // die DocInfo vom Doc am DocShell-Medium setzen
638 RTL_LOGFILE_CONTEXT_TRACE( aLog, "before ReadDocInfo" );
639 SwReader aRdr( rMedium, aEmptyStr, pDoc );
640 RTL_LOGFILE_CONTEXT_TRACE( aLog, "before Read" );
641 nErr = aRdr.Read( *pReader );
642 RTL_LOGFILE_CONTEXT_TRACE( aLog, "after Read" );
644 // If a XML document is loaded, the global doc/web doc
645 // flags have to be set, because they aren't loaded
646 // by this formats.
647 if( ISA( SwWebDocShell ) )
649 if( !pDoc->get(IDocumentSettingAccess::HTML_MODE) )
650 pDoc->set(IDocumentSettingAccess::HTML_MODE, true);
652 if( ISA( SwGlobalDocShell ) )
654 if( !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
655 pDoc->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
658 #ifndef PRODUCT
659 else
660 ASSERT( !this, "ohne Sw3Reader geht nichts" );
661 #endif
663 break;
665 default:
666 ASSERT( !this, "Load: new CreateMode?" );
670 UpdateFontList();
671 InitDraw();
673 SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
674 bRet = !IsError( nErr );
676 // --> OD 2006-11-07 #i59688#
677 // // StartFinishedLoading rufen.
678 // if( bRet && !pDoc->IsInLoadAsynchron() &&
679 // GetCreateMode() == SFX_CREATE_MODE_STANDARD )
680 // StartLoadFinishedTimer();
681 if ( bRet && !pDoc->IsInLoadAsynchron() &&
682 GetCreateMode() == SFX_CREATE_MODE_STANDARD )
684 LoadingFinished();
686 // <--
688 // SfxProgress unterdruecken, wenn man Embedded ist
689 SW_MOD()->SetEmbeddedLoadSave( sal_False );
692 return bRet;
695 /*--------------------------------------------------------------------
696 Beschreibung:
697 --------------------------------------------------------------------*/
700 sal_Bool SwDocShell::LoadFrom( SfxMedium& rMedium )
702 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "SwDocShell::LoadFrom" );
703 sal_Bool bRet = sal_False;
704 if( pDoc )
705 RemoveLink();
707 AddLink(); // Link setzen und Daten updaten !!
709 do { // middle check loop
710 sal_uInt32 nErr = ERR_SWG_READ_ERROR;
711 //const String& rNm = pStor->GetName();
712 String aStreamName;
713 aStreamName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("styles.xml"));
714 uno::Reference < container::XNameAccess > xAccess( rMedium.GetStorage(), uno::UNO_QUERY );
715 if ( xAccess->hasByName( aStreamName ) && rMedium.GetStorage()->isStreamElement( aStreamName ) )
717 // Das Laden
718 SwWait aWait( *this, sal_True );
720 ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
721 mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
722 if( ReadXML )
724 ReadXML->SetOrganizerMode( TRUE );
725 SwReader aRdr( rMedium, aEmptyStr, pDoc );
726 nErr = aRdr.Read( *ReadXML );
727 ReadXML->SetOrganizerMode( FALSE );
731 else
733 DBG_ERROR("Code removed!");
735 //TODO/LATER: looks like some binary stuff?!
736 // sollte es sich um eine 2. Vrolage handeln ??
737 if( SvStorage::IsStorageFile( rNm ) )
738 break;
740 const SfxFilter* pFltr = SwIoSystem::GetFileFilter( rNm, aEmptyStr );
741 if( !pFltr || !pFltr->GetUserData().EqualsAscii( FILTER_SWG ))
742 break;
744 SfxMedium aMed( rNm, STREAM_STD_READ, FALSE );
745 if( 0 == ( nErr = aMed.GetInStream()->GetError() ) )
747 SwWait aWait( *this, sal_True );
748 SwReader aRead( aMed, rNm, pDoc );
749 nErr = aRead.Read( *ReadSwg );
754 SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
755 bRet = !IsError( nErr );
757 } while( sal_False );
759 SfxObjectShell::LoadFrom( rMedium );
760 pDoc->ResetModified();
761 return bRet;
765 void SwDocShell::SubInitNew()
767 ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
768 mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
769 UpdateFontList();
770 InitDraw();
772 pDoc->setLinkUpdateMode( GLOBALSETTING );
773 pDoc->setFieldUpdateFlags( AUTOUPD_GLOBALSETTING );
775 sal_Bool bWeb = ISA(SwWebDocShell);
777 sal_uInt16 nRange[] = {
778 RES_PARATR_ADJUST, RES_PARATR_ADJUST,
779 RES_CHRATR_COLOR, RES_CHRATR_COLOR,
780 RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
781 RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
782 RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
783 0, 0, 0 };
784 if(!bWeb)
786 nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 3 ] = RES_PARATR_TABSTOP;
787 nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 2 ] = RES_PARATR_HYPHENZONE;
789 SfxItemSet aDfltSet( pDoc->GetAttrPool(), nRange );
791 //! get lingu options without loading lingu DLL
792 SvtLinguOptions aLinguOpt;
794 SvtLinguConfig().GetOptions( aLinguOpt );
796 sal_Int16 nVal = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
797 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
798 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
799 aDfltSet.Put( SvxLanguageItem( nVal, RES_CHRATR_LANGUAGE ) );
800 aDfltSet.Put( SvxLanguageItem( eCJK, RES_CHRATR_CJK_LANGUAGE ) );
801 aDfltSet.Put( SvxLanguageItem( eCTL, RES_CHRATR_CTL_LANGUAGE ) );
803 if(!bWeb)
805 SvxHyphenZoneItem aHyp( (SvxHyphenZoneItem&) pDoc->GetDefault(
806 RES_PARATR_HYPHENZONE) );
807 aHyp.GetMinLead() = static_cast< BYTE >(aLinguOpt.nHyphMinLeading);
808 aHyp.GetMinTrail() = static_cast< BYTE >(aLinguOpt.nHyphMinTrailing);
810 aDfltSet.Put( aHyp );
812 sal_uInt16 nNewPos = static_cast< sal_uInt16 >(SW_MOD()->GetUsrPref(FALSE)->GetDefTab());
813 if( nNewPos )
814 aDfltSet.Put( SvxTabStopItem( 1, nNewPos,
815 SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP ) );
817 aDfltSet.Put( SvxColorItem( Color( COL_AUTO ), RES_CHRATR_COLOR ) );
819 pDoc->SetDefault( aDfltSet );
821 //default page mode for text grid
822 if(!bWeb)
824 sal_Bool bSquaredPageMode = SW_MOD()->GetUsrPref(FALSE)->IsSquaredPageMode();
825 pDoc->SetDefaultPageMode( bSquaredPageMode );
828 pDoc->ResetModified();
832 * Document Interface Access
834 IDocumentDeviceAccess* SwDocShell::getIDocumentDeviceAccess() { return pDoc; }
835 const IDocumentSettingAccess* SwDocShell::getIDocumentSettingAccess() const { return pDoc; }
836 IDocumentChartDataProviderAccess* SwDocShell::getIDocumentChartDataProviderAccess() { return pDoc; }