Update ooo320-m1
[ooovba.git] / sfx2 / source / doc / objcont.cxx
blob36ec2c8c8867faec7fa49f106bf3c2ed1785b6fb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objcont.cxx,v $
10 * $Revision: 1.78 $
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_sfx2.hxx"
34 #include <com/sun/star/uno/Reference.hxx>
36 #include <com/sun/star/document/XDocumentProperties.hpp>
37 #include <com/sun/star/document/UpdateDocMode.hpp>
38 #include <com/sun/star/frame/XLayoutManager.hpp>
39 #include <com/sun/star/embed/ElementModes.hpp>
40 #include <com/sun/star/document/XStandaloneDocumentInfo.hpp>
41 #include <com/sun/star/beans/XFastPropertySet.hpp>
42 #include <tools/cachestr.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <svtools/style.hxx>
45 #include <vcl/wrkwin.hxx>
47 #include <svtools/stritem.hxx>
48 #include <svtools/intitem.hxx>
49 #include <svtools/rectitem.hxx>
50 #include <svtools/eitem.hxx>
51 #include <svtools/urihelper.hxx>
52 #include <svtools/ctloptions.hxx>
53 #include <comphelper/processfactory.hxx>
54 #include <comphelper/storagehelper.hxx>
55 #include <svtools/securityoptions.hxx>
56 #include <svtools/sfxecode.hxx>
57 #include <svtools/ehdl.hxx>
58 #include <tools/datetime.hxx>
59 #include <math.h>
61 #include <svtools/saveopt.hxx>
62 #include <svtools/useroptions.hxx>
63 #include <unotools/localfilehelper.hxx>
64 #include <vcl/virdev.hxx>
66 #include <sfx2/app.hxx>
67 #include "sfxresid.hxx"
68 #include "appdata.hxx"
69 #include <sfx2/dinfdlg.hxx>
70 #include "fltfnc.hxx"
71 #include <sfx2/docfac.hxx>
72 #include <sfx2/viewsh.hxx>
73 #include <sfx2/objsh.hxx>
74 #include "objshimp.hxx"
75 #include <sfx2/evntconf.hxx>
76 #include "sfxhelp.hxx"
77 #include <sfx2/dispatch.hxx>
78 #include <sfx2/printer.hxx>
79 #include <sfx2/topfrm.hxx>
80 #include "basmgr.hxx"
81 #include <sfx2/doctempl.hxx>
82 #include "doc.hrc"
83 #include <sfx2/sfxbasemodel.hxx>
84 #include <sfx2/docfile.hxx>
85 #include <sfx2/request.hxx>
86 #include "openflag.hxx"
87 #include "querytemplate.hxx"
89 using namespace ::com::sun::star;
90 using namespace ::com::sun::star::uno;
92 //====================================================================
94 #define SFX_WINDOWS_STREAM "SfxWindows"
95 #define SFX_PREVIEW_STREAM "SfxPreview"
97 //====================================================================
99 static
100 bool operator> (const util::DateTime& i_rLeft, const util::DateTime& i_rRight)
102 if ( i_rLeft.Year != i_rRight.Year )
103 return i_rLeft.Year > i_rRight.Year;
105 if ( i_rLeft.Month != i_rRight.Month )
106 return i_rLeft.Month > i_rRight.Month;
108 if ( i_rLeft.Day != i_rRight.Day )
109 return i_rLeft.Day > i_rRight.Day;
111 if ( i_rLeft.Hours != i_rRight.Hours )
112 return i_rLeft.Hours > i_rRight.Hours;
114 if ( i_rLeft.Minutes != i_rRight.Minutes )
115 return i_rLeft.Minutes > i_rRight.Minutes;
117 if ( i_rLeft.Seconds != i_rRight.Seconds )
118 return i_rLeft.Seconds > i_rRight.Seconds;
120 if ( i_rLeft.HundredthSeconds != i_rRight.HundredthSeconds )
121 return i_rLeft.HundredthSeconds > i_rRight.HundredthSeconds;
123 return sal_False;
127 ::boost::shared_ptr<GDIMetaFile>
128 SfxObjectShell::GetPreviewMetaFile( sal_Bool bFullContent ) const
130 return CreatePreviewMetaFile_Impl( bFullContent, sal_False );
134 ::boost::shared_ptr<GDIMetaFile>
135 SfxObjectShell::CreatePreviewMetaFile_Impl( sal_Bool bFullContent, sal_Bool bHighContrast ) const
137 // Nur wenn gerade nicht gedruckt wird, darf DoDraw aufgerufen
138 // werden, sonst wird u.U. der Printer abgeschossen !
139 SfxViewFrame *pFrame = SfxViewFrame::GetFirst( this );
140 if ( pFrame && pFrame->GetViewShell() &&
141 pFrame->GetViewShell()->GetPrinter() &&
142 pFrame->GetViewShell()->GetPrinter()->IsPrinting() )
143 return ::boost::shared_ptr<GDIMetaFile>();
145 ::boost::shared_ptr<GDIMetaFile> pFile(new GDIMetaFile);
147 VirtualDevice aDevice;
148 aDevice.EnableOutput( FALSE );
150 // adjust the output device if HC-metafile is requested
151 if ( bHighContrast )
152 aDevice.SetDrawMode( aDevice.GetDrawMode() | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
154 MapMode aMode( ((SfxObjectShell*)this)->GetMapUnit() );
155 aDevice.SetMapMode( aMode );
156 pFile->SetPrefMapMode( aMode );
158 Size aTmpSize;
159 sal_Int8 nAspect;
160 if ( bFullContent )
162 nAspect = ASPECT_CONTENT;
163 aTmpSize = GetVisArea( nAspect ).GetSize();
165 else
167 nAspect = ASPECT_THUMBNAIL;
168 aTmpSize = ((SfxObjectShell*)this)->GetFirstPageSize();
171 pFile->SetPrefSize( aTmpSize );
172 DBG_ASSERT( aTmpSize.Height()*aTmpSize.Width(),
173 "size of first page is 0, overload GetFirstPageSize or set vis-area!" );
175 pFile->Record( &aDevice );
177 LanguageType eLang;
178 SvtCTLOptions* pCTLOptions = new SvtCTLOptions;
179 if ( SvtCTLOptions::NUMERALS_HINDI == pCTLOptions->GetCTLTextNumerals() )
180 eLang = LANGUAGE_ARABIC_SAUDI_ARABIA;
181 else if ( SvtCTLOptions::NUMERALS_ARABIC == pCTLOptions->GetCTLTextNumerals() )
182 eLang = LANGUAGE_ENGLISH;
183 else
184 eLang = (LanguageType) Application::GetSettings().GetLanguage();
186 aDevice.SetDigitLanguage( eLang );
188 ((SfxObjectShell*)this)->DoDraw( &aDevice, Point(0,0), aTmpSize, JobSetup(), nAspect );
189 pFile->Stop();
191 return pFile;
194 //REMOVE FASTBOOL SfxObjectShell::SaveWindows_Impl( SvStorage &rStor ) const
195 //REMOVE {
196 //REMOVE SvStorageStreamRef xStream = rStor.OpenStream( DEFINE_CONST_UNICODE( SFX_WINDOWS_STREAM ),
197 //REMOVE STREAM_TRUNC | STREAM_STD_READWRITE);
198 //REMOVE if ( !xStream )
199 //REMOVE return FALSE;
200 //REMOVE
201 //REMOVE xStream->SetBufferSize(1024);
202 //REMOVE xStream->SetVersion( rStor.GetVersion() );
203 //REMOVE
204 //REMOVE // "uber alle Fenster iterieren (aber aktives Window zuletzt)
205 //REMOVE SfxViewFrame *pActFrame = SfxViewFrame::Current();
206 //REMOVE if ( !pActFrame || pActFrame->GetObjectShell() != this )
207 //REMOVE pActFrame = SfxViewFrame::GetFirst(this);
208 //REMOVE
209 //REMOVE String aActWinData;
210 //REMOVE for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this, TYPE(SfxTopViewFrame) ); pFrame;
211 //REMOVE pFrame = SfxViewFrame::GetNext(*pFrame, this, TYPE(SfxTopViewFrame) ) )
212 //REMOVE {
213 //REMOVE // Bei Dokumenten, die Outplace aktiv sind, kann beim Speichern auch schon die View weg sein!
214 //REMOVE if ( pFrame->GetViewShell() )
215 //REMOVE {
216 //REMOVE SfxTopFrame* pTop = (SfxTopFrame*) pFrame->GetFrame();
217 //REMOVE pTop->GetTopWindow_Impl();
218 //REMOVE
219 //REMOVE char cToken = ',';
220 //REMOVE const BOOL bActWin = pActFrame == pFrame;
221 //REMOVE String aUserData;
222 //REMOVE pFrame->GetViewShell()->WriteUserData(aUserData);
223 //REMOVE
224 //REMOVE // assemble ini-data
225 //REMOVE String aWinData;
226 //REMOVE aWinData += String::CreateFromInt32( pFrame->GetCurViewId() );
227 //REMOVE aWinData += cToken;
228 //REMOVE /*
229 //REMOVE if ( !pWin || pWin->IsMaximized() )
230 //REMOVE aWinData += SFX_WINSIZE_MAX;
231 //REMOVE else if ( pWin->IsMinimized() )
232 //REMOVE aWinData += SFX_WINSIZE_MIN;
233 //REMOVE else
234 //REMOVE */
235 //REMOVE aWinData += cToken;
236 //REMOVE aWinData += aUserData;
237 //REMOVE
238 //REMOVE // aktives kennzeichnen
239 //REMOVE aWinData += cToken;
240 //REMOVE aWinData += bActWin ? '1' : '0';
241 //REMOVE
242 //REMOVE // je nachdem merken oder abspeichern
243 //REMOVE if ( bActWin )
244 //REMOVE aActWinData = aWinData;
245 //REMOVE else
246 //REMOVE xStream->WriteByteString( aWinData );
247 //REMOVE }
248 //REMOVE }
249 //REMOVE
250 //REMOVE // aktives Window hinterher
251 //REMOVE xStream->WriteByteString( aActWinData );
252 //REMOVE return !xStream->GetError();
253 //REMOVE }
255 //====================================================================
257 SfxViewFrame* SfxObjectShell::LoadWindows_Impl( SfxTopFrame *pPreferedFrame )
259 DBG_ASSERT( pPreferedFrame, "Call without preferred Frame is not supported anymore!" );
260 if ( pImp->bLoadingWindows || !pPreferedFrame )
261 return NULL;
263 DBG_ASSERT( GetMedium(), "A Medium should exist here!");
264 if( !GetMedium() )
265 return 0;
267 // get correct mode
268 SFX_APP();
269 SfxViewFrame *pPrefered = pPreferedFrame ? pPreferedFrame->GetCurrentViewFrame() : 0;
270 SvtSaveOptions aOpt;
271 BOOL bLoadDocWins = aOpt.IsSaveDocWins() && !pPrefered;
273 // try to get viewdata information for XML format
274 REFERENCE < XVIEWDATASUPPLIER > xViewDataSupplier( GetModel(), ::com::sun::star::uno::UNO_QUERY );
275 REFERENCE < XINDEXACCESS > xViewData;
277 if ( xViewDataSupplier.is() )
279 xViewData = xViewDataSupplier->getViewData();
280 if ( !xViewData.is() )
281 return NULL;
283 else
284 return NULL;
286 SfxViewFrame *pActiveFrame = 0;
287 String aWinData;
288 SfxItemSet *pSet = GetMedium()->GetItemSet();
290 pImp->bLoadingWindows = TRUE;
291 BOOL bLoaded = FALSE;
292 sal_Int32 nView = 0;
294 // get saved information for all views
295 while ( TRUE )
297 USHORT nViewId = 0;
298 FASTBOOL bMaximized=FALSE;
299 String aPosSize;
300 String aUserData; // used in the binary format
301 SEQUENCE < PROPERTYVALUE > aSeq; // used in the XML format
303 // XML format
304 // active view is the first view in the container
305 FASTBOOL bActive = ( nView == 0 );
307 if ( nView == xViewData->getCount() )
308 // finished
309 break;
311 // get viewdata and look for the stored ViewId
312 ::com::sun::star::uno::Any aAny = xViewData->getByIndex( nView++ );
313 if ( aAny >>= aSeq )
315 for ( sal_Int32 n=0; n<aSeq.getLength(); n++ )
317 const PROPERTYVALUE& rProp = aSeq[n];
318 if ( rProp.Name.compareToAscii("ViewId") == COMPARE_EQUAL )
320 ::rtl::OUString aId;
321 rProp.Value >>= aId;
322 String aTmp( aId );
323 aTmp.Erase( 0, 4 ); // format is like in "view3"
324 nViewId = (USHORT) aTmp.ToInt32();
325 break;
330 // load only active view, but current item is not the active one ?
331 // in XML format the active view is the first one
332 if ( !bLoadDocWins && !bActive )
333 break;
335 // check for minimized/maximized/size
336 if ( aPosSize.EqualsAscii( "max" ) )
337 bMaximized = TRUE;
338 else if ( aPosSize.EqualsAscii( "min" ) )
340 bMaximized = TRUE;
341 bActive = FALSE;
343 else
344 bMaximized = FALSE;
346 Point aPt;
347 Size aSz;
349 pSet->ClearItem( SID_USER_DATA );
350 SfxViewFrame *pFrame = 0;
351 if ( pPrefered )
353 // use the frame from the arguments, but don't set a window size
354 pFrame = pPrefered;
355 if ( pFrame->GetViewShell() || !pFrame->GetObjectShell() )
357 pSet->ClearItem( SID_VIEW_POS_SIZE );
358 pSet->ClearItem( SID_WIN_POSSIZE );
359 pSet->Put( SfxUInt16Item( SID_VIEW_ID, nViewId ) );
361 // avoid flickering controllers
362 SfxBindings &rBind = pFrame->GetBindings();
363 rBind.ENTERREGISTRATIONS();
365 // set document into frame
366 pPreferedFrame->InsertDocument( this );
368 // restart controller updating
369 rBind.LEAVEREGISTRATIONS();
371 else
373 // create new view
374 pFrame->CreateView_Impl( nViewId );
377 else
379 if ( bLoadDocWins )
381 // open in the background
382 pSet->Put( SfxUInt16Item( SID_VIEW_ZOOM_MODE, 0 ) );
383 if ( !bMaximized )
384 pSet->Put( SfxRectangleItem( SID_VIEW_POS_SIZE, Rectangle( aPt, aSz ) ) );
387 pSet->Put( SfxUInt16Item( SID_VIEW_ID, nViewId ) );
389 if ( pPreferedFrame )
391 // Frame "ubergeben, allerdings ist der noch leer
392 pPreferedFrame->InsertDocument( this );
393 pFrame = pPreferedFrame->GetCurrentViewFrame();
395 else
397 pFrame = SfxTopFrame::Create( this, nViewId, FALSE, pSet )->GetCurrentViewFrame();
400 // only temporary data, don't hold it in the itemset
401 pSet->ClearItem( SID_VIEW_POS_SIZE );
402 pSet->ClearItem( SID_WIN_POSSIZE );
403 pSet->ClearItem( SID_VIEW_ZOOM_MODE );
406 bLoaded = TRUE;
408 // UserData hier einlesen, da es ansonsten immer mit bBrowse=TRUE
409 // aufgerufen wird, beim Abspeichern wurde aber bBrowse=FALSE verwendet
410 if ( pFrame && pFrame->GetViewShell() )
412 if ( aUserData.Len() )
413 pFrame->GetViewShell()->ReadUserData( aUserData, !bLoadDocWins );
414 else if ( aSeq.getLength() )
415 pFrame->GetViewShell()->ReadUserDataSequence( aSeq, !bLoadDocWins );
418 // perhaps there are more windows to load
419 pPreferedFrame = NULL;
421 if ( bActive )
422 pActiveFrame = pFrame;
424 if( pPrefered || !bLoadDocWins )
425 // load only active window
426 break;
429 if ( pActiveFrame )
431 if ( !pPrefered )
432 // activate frame
433 pActiveFrame->MakeActive_Impl( TRUE );
436 pImp->bLoadingWindows = FALSE;
437 return pPrefered && bLoaded ? pPrefered : pActiveFrame;
440 //====================================================================
442 void SfxObjectShell::UpdateDocInfoForSave()
444 uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
446 // clear user data if recommend (see 'Tools - Options - Open/StarOffice - Security')
447 if ( SvtSecurityOptions().IsOptionSet(
448 SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO ) )
450 xDocProps->resetUserData( ::rtl::OUString() );
452 else if ( IsModified() )
454 String aUserName = SvtUserOptions().GetFullName();
455 if ( !IsUseUserData() )
457 // remove all data pointing to the current user
458 if (xDocProps->getAuthor().equals(aUserName)) {
459 xDocProps->setAuthor( ::rtl::OUString() );
461 xDocProps->setModifiedBy( ::rtl::OUString() );
462 if (xDocProps->getPrintedBy().equals(aUserName)) {
463 xDocProps->setPrintedBy( ::rtl::OUString() );
466 else
468 // update ModificationAuthor, revision and editing time
469 ::DateTime now;
470 xDocProps->setModificationDate( util::DateTime(
471 now.Get100Sec(), now.GetSec(), now.GetMin(),
472 now.GetHour(), now.GetDay(), now.GetMonth(),
473 now.GetYear() ) );
474 xDocProps->setModifiedBy( aUserName );
475 if ( !HasName() || pImp->bIsSaving )
476 // QUESTION: not in case of "real" SaveAs as this is meant to create a new document
477 UpdateTime_Impl( xDocProps );
482 //--------------------------------------------------------------------
484 // Bearbeitungszeit aktualisieren
485 void SfxObjectShell::UpdateTime_Impl(
486 const uno::Reference<document::XDocumentProperties> & i_xDocProps)
488 // Get old time from documentinfo
489 sal_Int32 secs = i_xDocProps->getEditingDuration();
490 Time aOldTime(secs/3600, (secs%3600)/60, secs%60);
492 // Initialize some local member! Its neccessary for wollow operations!
493 DateTime aNow ; // Date and time at current moment
494 Time n24Time (24,0,0,0) ; // Time-value for 24 hours - see follow calculation
495 ULONG nDays = 0 ; // Count of days between now and last editing
496 Time nAddTime (0) ; // Value to add on aOldTime
498 // Safe impossible cases!
499 // User has changed time to the past between last editing and now ... its not possible!!!
500 DBG_ASSERT( !(aNow.GetDate()<pImp->nTime.GetDate()), "Timestamp of last change is in the past ?!..." );
502 // Do the follow only, if user has NOT changed time to the past.
503 // Else add a time of 0 to aOldTime ... !!!
504 if (aNow.GetDate()>=pImp->nTime.GetDate())
506 // Get count of days last editing.
507 nDays = aNow.GetSecFromDateTime(pImp->nTime.GetDate())/86400 ;
509 if (nDays==0)
511 // If no day between now and last editing - calculate time directly.
512 nAddTime = (const Time&)aNow - (const Time&)pImp->nTime ;
514 else
515 // If time of working without save greater then 1 month (!) ....
516 // we add 0 to aOldTime!
517 if (nDays<=31)
519 // If 1 or up to 31 days between now and last editing - calculate time indirectly.
520 // nAddTime = (24h - nTime) + (nDays * 24h) + aNow
521 --nDays;
522 nAddTime = nDays*n24Time.GetTime() ;
523 nAddTime += n24Time-(const Time&)pImp->nTime ;
524 nAddTime += aNow ;
527 aOldTime += nAddTime;
530 pImp->nTime = aNow;
531 try {
532 i_xDocProps->setEditingDuration(
533 aOldTime.GetHour()*3600+aOldTime.GetMin()*60+aOldTime.GetSec());
534 i_xDocProps->setEditingCycles(i_xDocProps->getEditingCycles() + 1);
536 catch (lang::IllegalArgumentException &)
538 // ignore overflow
542 //--------------------------------------------------------------------
544 SfxDocumentInfoDialog* SfxObjectShell::CreateDocumentInfoDialog
546 Window* pParent,
547 const SfxItemSet& rSet
550 return new SfxDocumentInfoDialog(pParent, rSet);
553 //--------------------------------------------------------------------
555 SfxStyleSheetBasePool* SfxObjectShell::GetStyleSheetPool()
557 return 0;
560 void SfxObjectShell::SetOrganizerSearchMask(
561 SfxStyleSheetBasePool* pStylePool) const
563 pStylePool->SetSearchMask(
564 SFX_STYLE_FAMILY_ALL,
565 SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
568 //--------------------------------------------------------------------
570 USHORT SfxObjectShell::GetContentCount(
571 USHORT nIdx1,
572 USHORT /*nIdx2*/)
574 switch(nIdx1)
576 case INDEX_IGNORE:
577 return DEF_CONTENT_COUNT;
578 case CONTENT_STYLE:
580 SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
581 if(!pStylePool)
582 return 0;
583 SetOrganizerSearchMask(pStylePool);
584 return pStylePool->Count();
586 case CONTENT_MACRO:
587 break;
589 case CONTENT_CONFIG:
590 return ( GetConfigManager() ) ?
591 GetConfigManager()->GetItemCount() : 0;
592 break;
595 return 0;
599 //--------------------------------------------------------------------
600 //TODO/CLEANUP: remove this method (it's virtual)
601 void SfxObjectShell::TriggerHelpPI(USHORT nIdx1, USHORT nIdx2, USHORT)
603 if(nIdx1==CONTENT_STYLE && nIdx2 != INDEX_IGNORE) //StyleSheets
605 SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
606 SetOrganizerSearchMask(pStylePool);
607 #ifdef WIR_KOENNEN_WIEDER_HILFE_FUER_STYLESHEETS
608 SfxStyleSheetBase *pStyle = (*pStylePool)[nIdx2];
609 if(pStyle)
611 String aHelpFile;
612 ULONG nHelpId=pStyle->GetHelpId(aHelpFile);
613 SfxHelpPI* pHelpPI = SFX_APP()->GetHelpPI();
614 if ( pHelpPI && nHelpId )
615 pHelpPI->LoadTopic( nHelpId );
617 #endif
621 BOOL SfxObjectShell::CanHaveChilds(USHORT nIdx1,
622 USHORT nIdx2)
624 switch(nIdx1) {
625 case INDEX_IGNORE:
626 return TRUE;
627 case CONTENT_STYLE:
628 return INDEX_IGNORE == nIdx2 || !GetStyleSheetPool()? FALSE: TRUE;
629 case CONTENT_MACRO:
630 //!! return INDEX_IGNORE == nIdx2? FALSE: TRUE;
631 return FALSE;
633 case CONTENT_CONFIG:
634 return INDEX_IGNORE == nIdx2 ? FALSE : TRUE;
637 return FALSE;
640 //--------------------------------------------------------------------
642 void SfxObjectShell::GetContent(String &rText,
643 Bitmap &rClosedBitmap,
644 Bitmap &rOpenedBitmap,
645 BOOL &bCanDel,
646 USHORT i,
647 USHORT nIdx1,
648 USHORT nIdx2 )
650 DBG_ERRORFILE( "Non high contrast method called. Please update calling code!" );
651 SfxObjectShell::GetContent( rText, rClosedBitmap, rOpenedBitmap, BMP_COLOR_NORMAL, bCanDel, i, nIdx1, nIdx2 );
654 //--------------------------------------------------------------------
656 void SfxObjectShell::GetContent(String &rText,
657 Bitmap &rClosedBitmap,
658 Bitmap &rOpenedBitmap,
659 BmpColorMode eColorMode,
660 BOOL &bCanDel,
661 USHORT i,
662 USHORT nIdx1,
663 USHORT /*nIdx2*/ )
665 bCanDel=TRUE;
667 switch(nIdx1)
669 case INDEX_IGNORE:
671 USHORT nTextResId = 0;
672 USHORT nClosedBitmapResId = 0; // evtl. sp"ater mal unterschiedliche
673 USHORT nOpenedBitmapResId = 0; // " " " "
674 switch(i)
676 case CONTENT_STYLE:
677 nTextResId = STR_STYLES;
678 if ( eColorMode == BMP_COLOR_NORMAL )
680 nClosedBitmapResId= BMP_STYLES_CLOSED;
681 nOpenedBitmapResId= BMP_STYLES_OPENED;
683 else
685 nClosedBitmapResId= BMP_STYLES_CLOSED_HC;
686 nOpenedBitmapResId= BMP_STYLES_OPENED_HC;
688 break;
689 case CONTENT_MACRO:
690 nTextResId = STR_MACROS;
691 if ( eColorMode == BMP_COLOR_NORMAL )
693 nClosedBitmapResId= BMP_STYLES_CLOSED;
694 nOpenedBitmapResId= BMP_STYLES_OPENED;
696 else
698 nClosedBitmapResId= BMP_STYLES_CLOSED_HC;
699 nOpenedBitmapResId= BMP_STYLES_OPENED_HC;
701 break;
703 case CONTENT_CONFIG:
704 nTextResId = STR_CONFIG;
705 nClosedBitmapResId= BMP_STYLES_CLOSED;
706 nOpenedBitmapResId= BMP_STYLES_OPENED;
707 break;
711 if ( nTextResId )
713 rText = String(SfxResId(nTextResId));
714 rClosedBitmap = Bitmap(SfxResId(nClosedBitmapResId));
715 rOpenedBitmap = Bitmap(SfxResId(nOpenedBitmapResId));
717 break;
720 case CONTENT_STYLE:
722 SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
723 SetOrganizerSearchMask(pStylePool);
724 SfxStyleSheetBase *pStyle = (*pStylePool)[i];
725 rText = pStyle->GetName();
726 bCanDel=((pStyle->GetMask() & SFXSTYLEBIT_USERDEF)
727 == SFXSTYLEBIT_USERDEF);
728 rClosedBitmap = rOpenedBitmap =
729 GetStyleFamilyBitmap(pStyle->GetFamily(), eColorMode );
731 break;
732 case CONTENT_MACRO:
733 break;
735 case CONTENT_CONFIG:
736 if ( GetConfigManager() )
738 rText = GetConfigManager()->GetItem(i);
739 bCanDel = GetConfigManager()->CanDelete(i);
741 else
742 rText = String();
743 rClosedBitmap = Bitmap(SfxResId(BMP_STYLES_CLOSED));
744 rOpenedBitmap = Bitmap(SfxResId(BMP_STYLES_OPENED));
745 break;
750 //--------------------------------------------------------------------
751 Bitmap SfxObjectShell::GetStyleFamilyBitmap( SfxStyleFamily eFamily )
753 DBG_ERRORFILE( "Non high contrast method called. Please update calling code!" );
754 return SfxObjectShell::GetStyleFamilyBitmap( eFamily, BMP_COLOR_NORMAL );
757 //--------------------------------------------------------------------
759 Bitmap SfxObjectShell::GetStyleFamilyBitmap(SfxStyleFamily eFamily, BmpColorMode eColorMode )
761 USHORT nResId = 0;
762 switch(eFamily)
764 case SFX_STYLE_FAMILY_CHAR:
765 nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY1 : BMP_STYLES_FAMILY1_HC;
766 break;
767 case SFX_STYLE_FAMILY_PARA:
768 nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY2 : BMP_STYLES_FAMILY2_HC;
769 break;
770 case SFX_STYLE_FAMILY_FRAME:
771 nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY3 : BMP_STYLES_FAMILY3_HC;
772 break;
773 case SFX_STYLE_FAMILY_PAGE :
774 nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY4 : BMP_STYLES_FAMILY4_HC;
775 break;
776 case SFX_STYLE_FAMILY_PSEUDO:
777 case SFX_STYLE_FAMILY_ALL:
778 break;
781 if ( nResId )
782 return Bitmap(SfxResId(nResId));
783 else
784 return Bitmap();
788 //--------------------------------------------------------------------
790 BOOL SfxObjectShell::Insert(SfxObjectShell &rSource,
791 USHORT nSourceIdx1,
792 USHORT nSourceIdx2,
793 USHORT /*nSourceIdx3*/,
794 USHORT &nIdx1,
795 USHORT &nIdx2,
796 USHORT &/*nIdx3*/,
797 USHORT &/*nDeleted*/)
799 BOOL bRet = FALSE;
801 if (INDEX_IGNORE == nIdx1 && CONTENT_STYLE == nSourceIdx1)
802 nIdx1 = CONTENT_STYLE;
804 if (CONTENT_STYLE == nSourceIdx1 && CONTENT_STYLE == nIdx1)
806 SfxStyleSheetBasePool* pHisPool = rSource.GetStyleSheetPool();
807 SfxStyleSheetBasePool* pMyPool = GetStyleSheetPool();
808 SetOrganizerSearchMask(pHisPool);
809 SetOrganizerSearchMask(pMyPool);
810 SfxStyleSheetBase* pHisSheet = NULL;
812 if ( pHisPool && pHisPool->Count() > nSourceIdx2 )
813 pHisSheet = (*pHisPool)[nSourceIdx2];
815 // Einfuegen ist nur dann noetig, wenn ein StyleSheet
816 // zwischen unterschiedlichen(!) Pools bewegt wird
818 if ( pHisSheet && pMyPool != pHisPool )
820 if (INDEX_IGNORE == nIdx2)
822 nIdx2 = pMyPool->Count();
825 // wenn so eine Vorlage schon existiert: loeschen!
826 String aOldName(pHisSheet->GetName());
827 SfxStyleFamily eOldFamily = pHisSheet->GetFamily();
829 SfxStyleSheetBase* pExist = pMyPool->Find(aOldName, eOldFamily);
830 // USHORT nOldHelpId = pExist->GetHelpId(??? VB ueberlegt sich was);
831 BOOL bUsedOrUserDefined;
832 if( pExist )
834 bUsedOrUserDefined =
835 pExist->IsUsed() || pExist->IsUserDefined();
836 if( ErrorHandler::HandleError(
837 *new MessageInfo( ERRCODE_SFXMSG_STYLEREPLACE, aOldName ) )
838 != ERRCODE_BUTTON_OK )
839 return FALSE;
840 else
842 pMyPool->Replace( *pHisSheet, *pExist );
843 SetModified( TRUE );
844 nIdx2 = nIdx1 = INDEX_IGNORE;
845 return TRUE;
849 SfxStyleSheetBase& rNewSheet = pMyPool->Make(
850 aOldName, eOldFamily,
851 pHisSheet->GetMask(), nIdx2);
853 // ItemSet der neuen Vorlage fuellen
854 rNewSheet.GetItemSet().Set(pHisSheet->GetItemSet());
856 // wer bekommt den Neuen als Parent? wer benutzt den Neuen als Follow?
857 SfxStyleSheetBase* pTestSheet = pMyPool->First();
858 while (pTestSheet)
860 if (pTestSheet->GetFamily() == eOldFamily &&
861 pTestSheet->HasParentSupport() &&
862 pTestSheet->GetParent() == aOldName)
864 pTestSheet->SetParent(aOldName);
865 // Verknuepfung neu aufbauen
868 if (pTestSheet->GetFamily() == eOldFamily &&
869 pTestSheet->HasFollowSupport() &&
870 pTestSheet->GetFollow() == aOldName)
872 pTestSheet->SetFollow(aOldName);
873 // Verknuepfung neu aufbauen
876 pTestSheet = pMyPool->Next();
878 bUsedOrUserDefined =
879 rNewSheet.IsUsed() || rNewSheet.IsUserDefined();
882 // hat der Neue einen Parent? wenn ja, mit gleichem Namen bei uns suchen
883 if (pHisSheet->HasParentSupport())
885 const String& rParentName = pHisSheet->GetParent();
886 if (0 != rParentName.Len())
888 SfxStyleSheetBase* pParentOfNew =
889 pMyPool->Find(rParentName, eOldFamily);
890 if (pParentOfNew)
891 rNewSheet.SetParent(rParentName);
895 // hat der Neue einen Follow? wenn ja, mit gleichem
896 // Namen bei uns suchen
897 if (pHisSheet->HasFollowSupport())
899 const String& rFollowName = pHisSheet->GetFollow();
900 if (0 != rFollowName.Len())
902 SfxStyleSheetBase* pFollowOfNew =
903 pMyPool->Find(rFollowName, eOldFamily);
904 if (pFollowOfNew)
905 rNewSheet.SetFollow(rFollowName);
909 SetModified( TRUE );
910 if( !bUsedOrUserDefined ) nIdx2 = nIdx1 = INDEX_IGNORE;
912 bRet = TRUE;
914 else
915 bRet = FALSE;
918 else if (nSourceIdx1 == CONTENT_CONFIG)
920 nIdx1 = CONTENT_CONFIG;
922 SfxConfigManager *pCfgMgr = SFX_CFGMANAGER();
923 if ( !GetConfigManager() )
925 SetConfigManager(new SfxConfigManager(0, pCfgMgr));
926 SetTemplateConfig(FALSE);
927 if (this == Current())
928 GetConfigManager()->Activate(pCfgMgr);
931 if (GetConfigManager()->CopyItem(
932 nSourceIdx2, nIdx2, rSource.GetConfigManager()))
934 SetModified(TRUE);
935 bRet = TRUE;
936 SFX_APP()->GetDispatcher_Impl()->Update_Impl(TRUE);
940 return bRet;
943 //--------------------------------------------------------------------
945 BOOL SfxObjectShell::Remove
947 USHORT nIdx1,
948 USHORT nIdx2,
949 USHORT /*nIdx3*/
952 BOOL bRet = FALSE;
954 if (CONTENT_STYLE == nIdx1)
956 SfxStyleSheetBasePool* pMyPool = GetStyleSheetPool();
958 SetOrganizerSearchMask(pMyPool);
960 SfxStyleSheetBase* pMySheet = (*pMyPool)[nIdx2];
961 String aName(pMySheet->GetName());
962 String aEmpty;
963 SfxStyleFamily eFamily = pMySheet->GetFamily();
964 if (pMySheet)
966 pMyPool->Remove(pMySheet);
967 bRet = TRUE;
970 SfxStyleSheetBase* pTestSheet = pMyPool->First();
971 while (pTestSheet)
973 if (pTestSheet->GetFamily() == eFamily &&
974 pTestSheet->HasParentSupport() &&
975 pTestSheet->GetParent() == aName)
977 pTestSheet->SetParent(aEmpty); // Verknuepfung aufloesen
980 if (pTestSheet->GetFamily() == eFamily &&
981 pTestSheet->HasFollowSupport() &&
982 pTestSheet->GetFollow() == aName)
984 pTestSheet->SetFollow(aEmpty); // Verknuepfung aufloesen
987 pTestSheet = pMyPool->Next();
989 if(bRet)
990 SetModified( TRUE );
993 else if (nIdx1 == CONTENT_CONFIG)
995 if (GetConfigManager()->RemoveItem(nIdx2))
997 SetModified(TRUE);
998 bRet = TRUE;
999 SFX_APP()->GetDispatcher_Impl()->Update_Impl(TRUE);
1003 return bRet;
1006 //--------------------------------------------------------------------
1008 BOOL SfxObjectShell::Print
1010 Printer& rPrt,
1011 USHORT nIdx1,
1012 USHORT /*nIdx2*/,
1013 USHORT /*nIdx3*/,
1014 const String* pObjectName
1017 /* [Beschreibung]
1021 switch(nIdx1)
1023 case CONTENT_STYLE:
1025 SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
1026 SetOrganizerSearchMask(pStylePool);
1027 SfxStyleSheetIterator* pIter = pStylePool->CreateIterator(
1028 pStylePool->GetSearchFamily(), pStylePool->GetSearchMask() );
1029 USHORT nStyles = pIter->Count();
1030 SfxStyleSheetBase *pStyle = pIter->First();
1031 if ( !pStyle )
1032 return TRUE;
1034 if ( !rPrt.StartJob(String(SfxResId(STR_STYLES))) )
1036 delete pIter;
1037 return FALSE;
1039 if ( !rPrt.StartPage() )
1041 delete pIter;
1042 return FALSE;
1044 Reference< task::XStatusIndicator > xStatusIndicator;
1045 xStatusIndicator = SFX_APP()->GetStatusIndicator();
1046 if ( xStatusIndicator.is() )
1047 xStatusIndicator->start( String(SfxResId(STR_PRINT_STYLES)), nStyles );
1049 rPrt.SetMapMode(MapMode(MAP_10TH_MM));
1050 Font aFont( DEFINE_CONST_UNICODE( "Arial" ), Size(0, 64)); // 18pt
1051 aFont.SetWeight(WEIGHT_BOLD);
1052 rPrt.SetFont(aFont);
1053 const Size aPageSize(rPrt.GetOutputSize());
1054 const USHORT nXIndent = 200;
1055 USHORT nYIndent = 200;
1056 Point aOutPos(nXIndent, nYIndent);
1057 String aHeader(SfxResId(STR_PRINT_STYLES_HEADER));
1058 if ( pObjectName )
1059 aHeader += *pObjectName;
1060 else
1061 aHeader += GetTitle();
1062 long nTextHeight( rPrt.GetTextHeight() );
1063 rPrt.DrawText(aOutPos, aHeader);
1064 aOutPos.Y() += nTextHeight;
1065 aOutPos.Y() += nTextHeight/2;
1066 aFont.SetSize(Size(0, 35)); // 10pt
1067 nStyles = 1;
1068 while(pStyle)
1070 if ( xStatusIndicator.is() )
1071 xStatusIndicator->setValue( nStyles++ );
1072 // Ausgabe des Vorlagennamens
1073 String aStr(pStyle->GetName());
1074 aFont.SetWeight(WEIGHT_BOLD);
1075 rPrt.SetFont(aFont);
1076 nTextHeight = rPrt.GetTextHeight();
1077 // Seitenwechsel
1078 if ( aOutPos.Y() + nTextHeight*2 >
1079 aPageSize.Height() - (long) nYIndent )
1081 rPrt.EndPage();
1082 rPrt.StartPage();
1083 aOutPos.Y() = nYIndent;
1085 rPrt.DrawText(aOutPos, aStr);
1086 aOutPos.Y() += nTextHeight;
1088 // Ausgabe der Vorlagenbeschreibung
1089 aFont.SetWeight(WEIGHT_NORMAL);
1090 rPrt.SetFont(aFont);
1091 aStr = pStyle->GetDescription();
1092 const char cDelim = ' ';
1093 USHORT nStart = 0, nIdx = 0;
1095 nTextHeight = rPrt.GetTextHeight();
1096 // wie viele Worte passen auf eine Zeile
1097 while(nIdx < aStr.Len())
1099 USHORT nOld = nIdx;
1100 long nTextWidth;
1101 nIdx = aStr.Search(cDelim, nStart);
1102 nTextWidth = rPrt.GetTextWidth(aStr, nStart, nIdx-nStart);
1103 while(nIdx != STRING_NOTFOUND &&
1104 aOutPos.X() + nTextWidth <
1105 aPageSize.Width() - (long) nXIndent)
1107 nOld = nIdx;
1108 nIdx = aStr.Search(cDelim, nIdx+1);
1109 nTextWidth = rPrt.GetTextWidth(aStr, nStart, nIdx-nStart);
1111 String aTmp(aStr, nStart, nIdx == STRING_NOTFOUND?
1112 STRING_LEN :
1113 nOld-nStart);
1114 if ( aTmp.Len() )
1116 nStart = nOld+1; // wegen trailing space
1118 else
1120 USHORT nChar = 1;
1121 while(
1122 nStart + nChar < aStr.Len() &&
1123 aOutPos.X() + rPrt.GetTextWidth(
1124 aStr, nStart, nChar) <
1125 aPageSize.Width() - nXIndent)
1126 ++nChar;
1127 aTmp = String(aStr, nStart, nChar-1);
1128 nIdx = nStart + nChar;
1129 nStart = nIdx;
1131 if ( aOutPos.Y() + nTextHeight*2 >
1132 aPageSize.Height() - nYIndent )
1134 rPrt.EndPage();
1135 rPrt.StartPage();
1136 aOutPos.Y() = nYIndent;
1138 rPrt.DrawText(aOutPos, aTmp);
1139 aOutPos.Y() += rPrt.GetTextHeight();
1141 pStyle = pIter->Next();
1143 rPrt.EndPage();
1144 rPrt.EndJob();
1145 if ( xStatusIndicator.is() )
1146 xStatusIndicator->end();
1147 delete pIter;
1148 break;
1150 default:
1151 return FALSE;
1153 return TRUE;
1156 //--------------------------------------------------------------------
1158 void SfxObjectShell::LoadStyles
1160 SfxObjectShell &rSource /* die Dokument-Vorlage, aus der
1161 die Styles geladen werden sollen */
1164 /* [Beschreibung]
1166 Diese Methode wird vom SFx gerufen, wenn aus einer Dokument-Vorlage
1167 Styles nachgeladen werden sollen. Bestehende Styles soll dabei
1168 "uberschrieben werden. Das Dokument mu"s daher neu formatiert werden.
1169 Daher werden die Applikationen in der Regel diese Methode "uberladen
1170 und in ihrer Implementierung die Implementierung der Basisklasse
1171 rufen.
1175 struct Styles_Impl
1177 SfxStyleSheetBase *pSource;
1178 SfxStyleSheetBase *pDest;
1179 // Styles_Impl () : pSource(0), pDest(0) {}
1182 SfxStyleSheetBasePool *pSourcePool = rSource.GetStyleSheetPool();
1183 DBG_ASSERT(pSourcePool, "Source-DocumentShell ohne StyleSheetPool");
1184 SfxStyleSheetBasePool *pMyPool = GetStyleSheetPool();
1185 DBG_ASSERT(pMyPool, "Dest-DocumentShell ohne StyleSheetPool");
1186 pSourcePool->SetSearchMask(SFX_STYLE_FAMILY_ALL, 0xffff);
1187 Styles_Impl *pFound = new Styles_Impl[pSourcePool->Count()];
1188 USHORT nFound = 0;
1190 SfxStyleSheetBase *pSource = pSourcePool->First();
1191 while ( pSource )
1193 SfxStyleSheetBase *pDest =
1194 pMyPool->Find( pSource->GetName(), pSource->GetFamily() );
1195 if ( !pDest )
1197 pDest = &pMyPool->Make( pSource->GetName(),
1198 pSource->GetFamily(), pSource->GetMask());
1199 // Setzen des Parents, der Folgevorlage
1201 pFound[nFound].pSource = pSource;
1202 pFound[nFound].pDest = pDest;
1203 ++nFound;
1204 pSource = pSourcePool->Next();
1207 for ( USHORT i = 0; i < nFound; ++i )
1209 pFound[i].pDest->GetItemSet().PutExtended(pFound[i].pSource->GetItemSet(), SFX_ITEM_DONTCARE, SFX_ITEM_DEFAULT);
1210 // pFound[i].pDest->SetHelpId(pFound[i].pSource->GetHelpId());
1211 if(pFound[i].pSource->HasParentSupport())
1212 pFound[i].pDest->SetParent(pFound[i].pSource->GetParent());
1213 if(pFound[i].pSource->HasFollowSupport())
1214 pFound[i].pDest->SetFollow(pFound[i].pSource->GetParent());
1216 delete [] pFound;
1219 //--------------------------------------------------------------------
1221 void SfxObjectShell::UpdateFromTemplate_Impl( )
1223 /* [Beschreibung]
1225 Diese interne Methode pr"uft, ob das Dokument aus einem Template
1226 erzeugt wurde, und ob dieses neuer ist als das Dokument. Ist dies
1227 der Fall, wird der Benutzer gefragt, ob die Vorlagen (StyleSheets)
1228 updated werden sollen. Wird dies positiv beantwortet, werden die
1229 StyleSheets updated.
1233 // Storage-medium?
1234 SfxMedium *pFile = GetMedium();
1235 DBG_ASSERT( pFile, "cannot UpdateFromTemplate without medium" );
1236 if ( !pFile )
1237 return;
1239 if ( !::utl::LocalFileHelper::IsLocalFile( pFile->GetName() ) )
1240 // update only for documents loaded from the local file system
1241 return;
1243 // only for own storage formats
1244 uno::Reference< embed::XStorage > xDocStor = pFile->GetStorage();
1245 if ( !pFile->GetFilter() || !pFile->GetFilter()->IsOwnFormat() )
1246 return;
1248 SFX_ITEMSET_ARG( pFile->GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
1249 sal_Int16 bCanUpdateFromTemplate = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
1251 // created from template?
1252 uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
1253 ::rtl::OUString aTemplName( xDocProps->getTemplateName() );
1254 ::rtl::OUString aTemplURL( xDocProps->getTemplateURL() );
1255 String aFoundName;
1257 if ( aTemplName.getLength() || (aTemplURL.getLength() && !IsReadOnly()) )
1259 // try to locate template, first using filename
1260 // this must be done because writer global document uses this "great" idea to manage the templates of all parts
1261 // in the master document
1262 // but it is NOT an error if the template filename points not to a valid file
1263 SfxDocumentTemplates aTempl;
1264 aTempl.Construct();
1265 if ( aTemplURL.getLength() )
1267 String aURL;
1268 if( ::utl::LocalFileHelper::ConvertSystemPathToURL( aTemplURL, GetMedium()->GetName(), aURL ) )
1269 aFoundName = aURL;
1272 if( !aFoundName.Len() && aTemplName.getLength() )
1273 // if the template filename did not lead to success, try to get a file name for the logical template name
1274 aTempl.GetFull( String(), aTemplName, aFoundName );
1277 if ( aFoundName.Len() )
1279 // check existence of template storage
1280 aTemplURL = aFoundName;
1281 BOOL bLoad = FALSE;
1283 // should the document checked against changes in the template ?
1284 if ( IsQueryLoadTemplate() )
1286 // load document info of template
1287 BOOL bOK = FALSE;
1288 util::DateTime aTemplDate;
1291 Reference < document::XStandaloneDocumentInfo > xDocInfo (
1292 ::comphelper::getProcessServiceFactory()->createInstance(
1293 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
1294 "com.sun.star.document.StandaloneDocumentInfo") ) ),
1295 UNO_QUERY_THROW );
1296 Reference < beans::XFastPropertySet > xSet( xDocInfo,
1297 UNO_QUERY_THROW );
1298 xDocInfo->loadFromURL( aTemplURL );
1299 Any aAny = xSet->getFastPropertyValue( WID_DATE_MODIFIED );
1300 ::com::sun::star::util::DateTime aTmp;
1301 if ( aAny >>= aTemplDate )
1303 // get modify date from document info
1304 bOK = TRUE;
1307 catch ( Exception& )
1311 // if modify date was read successfully
1312 if ( bOK )
1314 // compare modify data of template with the last check date of the document
1315 const util::DateTime aInfoDate( xDocProps->getTemplateDate() );
1316 if ( aTemplDate > aInfoDate )
1318 // ask user
1319 if( bCanUpdateFromTemplate == document::UpdateDocMode::QUIET_UPDATE
1320 || bCanUpdateFromTemplate == document::UpdateDocMode::FULL_UPDATE )
1321 bLoad = TRUE;
1322 else if ( bCanUpdateFromTemplate == document::UpdateDocMode::ACCORDING_TO_CONFIG )
1324 String sMessage( SfxResId( STR_QRYTEMPL_MESSAGE ) );
1325 sMessage.SearchAndReplace( String::CreateFromAscii("$(ARG1)"), aTemplName );
1326 sfx2::QueryTemplateBox aBox( GetDialogParent(), sMessage );
1327 if ( RET_YES == aBox.Execute() )
1328 bLoad = TRUE;
1331 if( !bLoad )
1333 // user refuses, so don't ask again for this document
1334 SetQueryLoadTemplate(FALSE);
1335 SetModified( TRUE );
1340 if ( bLoad )
1342 // styles should be updated, create document in organizer mode to read in the styles
1343 //TODO: testen!
1344 SfxObjectShellLock xTemplDoc = CreateObjectByFactoryName( GetFactory().GetFactoryName(), SFX_CREATE_MODE_ORGANIZER );
1345 xTemplDoc->DoInitNew(0);
1347 // TODO/MBA: do we need a BaseURL? Then LoadFrom must be extended!
1348 //xTemplDoc->SetBaseURL( aFoundName );
1350 // TODO/LATER: make sure that we don't use binary templates!
1351 SfxMedium aMedium( aFoundName, STREAM_STD_READ );
1352 if ( xTemplDoc->LoadFrom( aMedium ) )
1354 // transfer styles from xTemplDoc to this document
1355 // TODO/MBA: make sure that no BaseURL is needed in *this* document
1356 LoadStyles(*xTemplDoc);
1358 // remember date/time of check
1359 xDocProps->setTemplateDate(aTemplDate);
1360 // TODO/LATER: new functionality to store document info is required ( didn't work for SO7 XML format )
1361 //REPLACE pInfo->Save(xDocStor);
1365 SfxConfigManager *pCfgMgr = SFX_CFGMANAGER();
1367 SfxConfigManager *pTemplCfg = new SfxConfigManager(aTemplStor, pCfgMgr);
1368 SetConfigManager(pTemplCfg);
1369 SetTemplateConfig(TRUE);
1371 // Falls der gerade zerst"orte CfgMgr des Dokuments der
1372 // aktive war, pCfgMgr lieber neu holen
1373 pCfgMgr = SFX_CFGMANAGER();
1375 // ggf. den neuen ConfigManager aktivieren
1376 if ( this == SfxObjectShell::Current() )
1377 pTemplCfg->Activate(pCfgMgr);
1380 // Template und Template-DocInfo werden nicht mehr gebraucht
1381 // delete pTemplInfo;
1386 SfxObjectShellRef MakeObjectShellForOrganizer_Impl( const String& aTargetURL, BOOL bForWriting )
1388 // check for own format
1389 SfxObjectShellRef xDoc;
1390 StreamMode nMode = bForWriting ? SFX_STREAM_READWRITE : SFX_STREAM_READONLY;
1391 SfxMedium *pMed = new SfxMedium( aTargetURL, nMode, FALSE, 0 );
1392 const SfxFilter* pFilter = NULL;
1393 pMed->UseInteractionHandler(TRUE);
1394 if( SFX_APP()->GetFilterMatcher().GuessFilter( *pMed, &pFilter ) == ERRCODE_NONE && pFilter && pFilter->IsOwnFormat() )
1396 // create document
1397 xDoc = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_ORGANIZER );
1398 if ( xDoc.Is() )
1400 // partially load, so don't use DoLoad!
1401 xDoc->DoInitNew(0);
1402 // TODO/LATER: make sure that we don't use binary templates!
1403 if( xDoc->LoadFrom( *pMed ) )
1405 // connect to storage, abandon temp. storage
1406 xDoc->DoSaveCompleted( pMed );
1408 else
1409 xDoc.Clear();
1412 else
1413 delete pMed;
1415 return xDoc;
1418 sal_Bool SfxObjectShell::IsHelpDocument() const
1420 const SfxFilter* pFilter = GetMedium()->GetFilter();
1421 return ( pFilter && pFilter->GetFilterName().CompareToAscii("writer_web_HTML_help") == COMPARE_EQUAL );
1424 void SfxObjectShell::ResetFromTemplate( const String& rTemplateName, const String& rFileName )
1426 // only care about reseting this data for openoffice formats otherwise
1427 if ( IsOwnStorageFormat_Impl( *GetMedium()) )
1429 uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
1430 xDocProps->setTemplateURL( ::rtl::OUString() );
1431 xDocProps->setTemplateName( ::rtl::OUString() );
1432 xDocProps->setTemplateDate( util::DateTime() );
1433 xDocProps->resetUserData( ::rtl::OUString() );
1435 // TODO/REFACTOR:
1436 // Title?
1438 if( ::utl::LocalFileHelper::IsLocalFile( rFileName ) )
1440 String aFoundName;
1441 if( SFX_APP()->Get_Impl()->GetDocumentTemplates()->GetFull( String(), rTemplateName, aFoundName ) )
1443 INetURLObject aObj( rFileName );
1444 xDocProps->setTemplateURL( aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
1445 xDocProps->setTemplateName( rTemplateName );
1447 ::DateTime now;
1448 xDocProps->setTemplateDate( util::DateTime(
1449 now.Get100Sec(), now.GetSec(), now.GetMin(),
1450 now.GetHour(), now.GetDay(), now.GetMonth(),
1451 now.GetYear() ) );
1453 SetQueryLoadTemplate( sal_True );
1459 sal_Bool SfxObjectShell::IsQueryLoadTemplate() const
1461 return pImp->bQueryLoadTemplate;
1464 sal_Bool SfxObjectShell::IsUseUserData() const
1466 return pImp->bUseUserData;
1469 void SfxObjectShell::SetQueryLoadTemplate( sal_Bool bNew )
1471 if ( pImp->bQueryLoadTemplate != bNew )
1472 SetModified( TRUE );
1473 pImp->bQueryLoadTemplate = bNew;
1476 void SfxObjectShell::SetUseUserData( sal_Bool bNew )
1478 if ( pImp->bUseUserData != bNew )
1479 SetModified( TRUE );
1480 pImp->bUseUserData = bNew;
1483 sal_Bool SfxObjectShell::IsLoadReadonly() const
1485 return pImp->bLoadReadonly;
1488 sal_Bool SfxObjectShell::IsSaveVersionOnClose() const
1490 return pImp->bSaveVersionOnClose;
1493 void SfxObjectShell::SetLoadReadonly( sal_Bool bNew )
1495 if ( pImp->bLoadReadonly != bNew )
1496 SetModified( TRUE );
1497 pImp->bLoadReadonly = bNew;
1500 void SfxObjectShell::SetSaveVersionOnClose( sal_Bool bNew )
1502 if ( pImp->bSaveVersionOnClose != bNew )
1503 SetModified( TRUE );
1504 pImp->bSaveVersionOnClose = bNew;