xref: /AOO41X/main/sfx2/source/doc/objcont.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/document/UpdateDocMode.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/document/XStandaloneDocumentInfo.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/beans/XFastPropertySet.hpp>
39*cdf0e10cSrcweir #include <tools/cachestr.hxx>
40*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
41*cdf0e10cSrcweir #include <svl/style.hxx>
42*cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <svl/stritem.hxx>
45*cdf0e10cSrcweir #include <svl/intitem.hxx>
46*cdf0e10cSrcweir #include <svl/rectitem.hxx>
47*cdf0e10cSrcweir #include <svl/eitem.hxx>
48*cdf0e10cSrcweir #include <svl/urihelper.hxx>
49*cdf0e10cSrcweir #include <svl/ctloptions.hxx>
50*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
51*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
52*cdf0e10cSrcweir #include <unotools/securityoptions.hxx>
53*cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
54*cdf0e10cSrcweir #include <svtools/ehdl.hxx>
55*cdf0e10cSrcweir #include <tools/datetime.hxx>
56*cdf0e10cSrcweir #include <math.h>
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir #include <unotools/saveopt.hxx>
59*cdf0e10cSrcweir #include <unotools/useroptions.hxx>
60*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
61*cdf0e10cSrcweir #include <vcl/virdev.hxx>
62*cdf0e10cSrcweir #include <vcl/oldprintadaptor.hxx>
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #include <sfx2/app.hxx>
65*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
66*cdf0e10cSrcweir #include "appdata.hxx"
67*cdf0e10cSrcweir #include <sfx2/dinfdlg.hxx>
68*cdf0e10cSrcweir #include "fltfnc.hxx"
69*cdf0e10cSrcweir #include <sfx2/docfac.hxx>
70*cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
71*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
72*cdf0e10cSrcweir #include "objshimp.hxx"
73*cdf0e10cSrcweir #include <sfx2/evntconf.hxx>
74*cdf0e10cSrcweir #include "sfx2/sfxhelp.hxx"
75*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
76*cdf0e10cSrcweir #include <sfx2/printer.hxx>
77*cdf0e10cSrcweir #include "sfx2/basmgr.hxx"
78*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
79*cdf0e10cSrcweir #include <sfx2/doctempl.hxx>
80*cdf0e10cSrcweir #include "doc.hrc"
81*cdf0e10cSrcweir #include <sfx2/sfxbasemodel.hxx>
82*cdf0e10cSrcweir #include <sfx2/docfile.hxx>
83*cdf0e10cSrcweir #include <sfx2/request.hxx>
84*cdf0e10cSrcweir #include "openflag.hxx"
85*cdf0e10cSrcweir #include "querytemplate.hxx"
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir using namespace ::com::sun::star;
88*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir //====================================================================
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir //====================================================================
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir static
95*cdf0e10cSrcweir bool operator> (const util::DateTime& i_rLeft, const util::DateTime& i_rRight)
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir     if ( i_rLeft.Year != i_rRight.Year )
98*cdf0e10cSrcweir         return i_rLeft.Year > i_rRight.Year;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     if ( i_rLeft.Month != i_rRight.Month )
101*cdf0e10cSrcweir         return i_rLeft.Month > i_rRight.Month;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     if ( i_rLeft.Day != i_rRight.Day )
104*cdf0e10cSrcweir         return i_rLeft.Day > i_rRight.Day;
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     if ( i_rLeft.Hours != i_rRight.Hours )
107*cdf0e10cSrcweir         return i_rLeft.Hours > i_rRight.Hours;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     if ( i_rLeft.Minutes != i_rRight.Minutes )
110*cdf0e10cSrcweir         return i_rLeft.Minutes > i_rRight.Minutes;
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     if ( i_rLeft.Seconds != i_rRight.Seconds )
113*cdf0e10cSrcweir         return i_rLeft.Seconds > i_rRight.Seconds;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     if ( i_rLeft.HundredthSeconds != i_rRight.HundredthSeconds )
116*cdf0e10cSrcweir         return i_rLeft.HundredthSeconds > i_rRight.HundredthSeconds;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     return sal_False;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir ::boost::shared_ptr<GDIMetaFile>
123*cdf0e10cSrcweir SfxObjectShell::GetPreviewMetaFile( sal_Bool bFullContent ) const
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir 	return CreatePreviewMetaFile_Impl( bFullContent, sal_False );
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir ::boost::shared_ptr<GDIMetaFile>
130*cdf0e10cSrcweir SfxObjectShell::CreatePreviewMetaFile_Impl( sal_Bool bFullContent, sal_Bool bHighContrast ) const
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir 	// Nur wenn gerade nicht gedruckt wird, darf DoDraw aufgerufen
133*cdf0e10cSrcweir 	// werden, sonst wird u.U. der Printer abgeschossen !
134*cdf0e10cSrcweir 	SfxViewFrame *pFrame = SfxViewFrame::GetFirst( this );
135*cdf0e10cSrcweir 	if ( pFrame && pFrame->GetViewShell() &&
136*cdf0e10cSrcweir 		 pFrame->GetViewShell()->GetPrinter() &&
137*cdf0e10cSrcweir 		 pFrame->GetViewShell()->GetPrinter()->IsPrinting() )
138*cdf0e10cSrcweir 		 return ::boost::shared_ptr<GDIMetaFile>();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     ::boost::shared_ptr<GDIMetaFile> pFile(new GDIMetaFile);
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	VirtualDevice aDevice;
143*cdf0e10cSrcweir 	aDevice.EnableOutput( sal_False );
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	// adjust the output device if HC-metafile is requested
146*cdf0e10cSrcweir 	if ( bHighContrast )
147*cdf0e10cSrcweir 		aDevice.SetDrawMode( aDevice.GetDrawMode() | DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     MapMode aMode( ((SfxObjectShell*)this)->GetMapUnit() );
150*cdf0e10cSrcweir     aDevice.SetMapMode( aMode );
151*cdf0e10cSrcweir     pFile->SetPrefMapMode( aMode );
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     Size aTmpSize;
154*cdf0e10cSrcweir     sal_Int8 nAspect;
155*cdf0e10cSrcweir     if ( bFullContent )
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir         nAspect = ASPECT_CONTENT;
158*cdf0e10cSrcweir         aTmpSize = GetVisArea( nAspect ).GetSize();
159*cdf0e10cSrcweir     }
160*cdf0e10cSrcweir     else
161*cdf0e10cSrcweir     {
162*cdf0e10cSrcweir         nAspect = ASPECT_THUMBNAIL;
163*cdf0e10cSrcweir         aTmpSize = ((SfxObjectShell*)this)->GetFirstPageSize();
164*cdf0e10cSrcweir     }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     pFile->SetPrefSize( aTmpSize );
167*cdf0e10cSrcweir     DBG_ASSERT( aTmpSize.Height()*aTmpSize.Width(),
168*cdf0e10cSrcweir                 "size of first page is 0, overload GetFirstPageSize or set vis-area!" );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     pFile->Record( &aDevice );
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     LanguageType eLang;
173*cdf0e10cSrcweir     SvtCTLOptions*  pCTLOptions = new SvtCTLOptions;
174*cdf0e10cSrcweir     if ( SvtCTLOptions::NUMERALS_HINDI == pCTLOptions->GetCTLTextNumerals() )
175*cdf0e10cSrcweir         eLang = LANGUAGE_ARABIC_SAUDI_ARABIA;
176*cdf0e10cSrcweir     else if ( SvtCTLOptions::NUMERALS_ARABIC == pCTLOptions->GetCTLTextNumerals() )
177*cdf0e10cSrcweir         eLang = LANGUAGE_ENGLISH;
178*cdf0e10cSrcweir     else
179*cdf0e10cSrcweir         eLang = (LanguageType) Application::GetSettings().GetLanguage();
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     aDevice.SetDigitLanguage( eLang );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir     ((SfxObjectShell*)this)->DoDraw( &aDevice, Point(0,0), aTmpSize, JobSetup(), nAspect );
184*cdf0e10cSrcweir     pFile->Stop();
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 	return pFile;
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir //====================================================================
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir void SfxObjectShell::UpdateDocInfoForSave()
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir     uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	// clear user data if recommend (see 'Tools - Options - Open/StarOffice - Security')
196*cdf0e10cSrcweir 	if ( SvtSecurityOptions().IsOptionSet(
197*cdf0e10cSrcweir             SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO ) )
198*cdf0e10cSrcweir     {
199*cdf0e10cSrcweir 		xDocProps->resetUserData( ::rtl::OUString() );
200*cdf0e10cSrcweir     }
201*cdf0e10cSrcweir 	else if ( IsModified() )
202*cdf0e10cSrcweir 	{
203*cdf0e10cSrcweir 		String aUserName = SvtUserOptions().GetFullName();
204*cdf0e10cSrcweir 		if ( !IsUseUserData() )
205*cdf0e10cSrcweir         {
206*cdf0e10cSrcweir 			// remove all data pointing to the current user
207*cdf0e10cSrcweir             if (xDocProps->getAuthor().equals(aUserName)) {
208*cdf0e10cSrcweir                 xDocProps->setAuthor( ::rtl::OUString() );
209*cdf0e10cSrcweir             }
210*cdf0e10cSrcweir             xDocProps->setModifiedBy( ::rtl::OUString() );
211*cdf0e10cSrcweir             if (xDocProps->getPrintedBy().equals(aUserName)) {
212*cdf0e10cSrcweir                 xDocProps->setPrintedBy( ::rtl::OUString() );
213*cdf0e10cSrcweir             }
214*cdf0e10cSrcweir         }
215*cdf0e10cSrcweir 		else
216*cdf0e10cSrcweir 		{
217*cdf0e10cSrcweir 			// update ModificationAuthor, revision and editing time
218*cdf0e10cSrcweir             ::DateTime now;
219*cdf0e10cSrcweir             xDocProps->setModificationDate( util::DateTime(
220*cdf0e10cSrcweir                 now.Get100Sec(), now.GetSec(), now.GetMin(),
221*cdf0e10cSrcweir                 now.GetHour(), now.GetDay(), now.GetMonth(),
222*cdf0e10cSrcweir                 now.GetYear() ) );
223*cdf0e10cSrcweir             xDocProps->setModifiedBy( aUserName );
224*cdf0e10cSrcweir 			if ( !HasName() || pImp->bIsSaving )
225*cdf0e10cSrcweir 				// QUESTION: not in case of "real" SaveAs as this is meant to create a new document
226*cdf0e10cSrcweir 				UpdateTime_Impl( xDocProps );
227*cdf0e10cSrcweir 		}
228*cdf0e10cSrcweir 	}
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir //--------------------------------------------------------------------
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir static void
234*cdf0e10cSrcweir lcl_add(util::Duration & rDur, Time const& rTime)
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir     // here we don't care about overflow: rDur is converted back to seconds
237*cdf0e10cSrcweir     // anyway, and Time cannot store more than ~4000 hours
238*cdf0e10cSrcweir     rDur.Hours   += rTime.GetHour();
239*cdf0e10cSrcweir     rDur.Minutes += rTime.GetMin();
240*cdf0e10cSrcweir     rDur.Seconds += rTime.GetSec();
241*cdf0e10cSrcweir }
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir // Bearbeitungszeit aktualisieren
244*cdf0e10cSrcweir void SfxObjectShell::UpdateTime_Impl(
245*cdf0e10cSrcweir     const uno::Reference<document::XDocumentProperties> & i_xDocProps)
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir 	// Get old time from documentinfo
248*cdf0e10cSrcweir     const sal_Int32 secs = i_xDocProps->getEditingDuration();
249*cdf0e10cSrcweir     util::Duration editDuration(sal_False, 0, 0, 0,
250*cdf0e10cSrcweir             secs/3600, (secs%3600)/60, secs%60, 0);
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 	// Initialize some local member! Its neccessary for wollow operations!
253*cdf0e10cSrcweir 	DateTime	aNow					;	// Date and time at current moment
254*cdf0e10cSrcweir 	Time		n24Time		(24,0,0,0)	;	// Time-value for 24 hours - see follow calculation
255*cdf0e10cSrcweir 	sal_uIntPtr		nDays		= 0			;	// Count of days between now and last editing
256*cdf0e10cSrcweir 	Time		nAddTime	(0)			;	// Value to add on aOldTime
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 	// Safe impossible cases!
259*cdf0e10cSrcweir 	// User has changed time to the past between last editing and now ... its not possible!!!
260*cdf0e10cSrcweir 	DBG_ASSERT( !(aNow.GetDate()<pImp->nTime.GetDate()), "Timestamp of last change is in the past ?!..." );
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 	// Do the follow only, if user has NOT changed time to the past.
263*cdf0e10cSrcweir 	// Else add a time of 0 to aOldTime ... !!!
264*cdf0e10cSrcweir 	if (aNow.GetDate()>=pImp->nTime.GetDate())
265*cdf0e10cSrcweir 	{
266*cdf0e10cSrcweir 		// Get count of days last editing.
267*cdf0e10cSrcweir 		nDays = aNow.GetSecFromDateTime(pImp->nTime.GetDate())/86400 ;
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 		if (nDays==0)
270*cdf0e10cSrcweir 		{
271*cdf0e10cSrcweir 			// If no day between now and last editing - calculate time directly.
272*cdf0e10cSrcweir             nAddTime    =   (const Time&)aNow - (const Time&)pImp->nTime ;
273*cdf0e10cSrcweir 		}
274*cdf0e10cSrcweir 		else
275*cdf0e10cSrcweir 		// If time of working without save greater then 1 month (!) ....
276*cdf0e10cSrcweir 		// we add 0 to aOldTime!
277*cdf0e10cSrcweir 		if (nDays<=31)
278*cdf0e10cSrcweir 		{
279*cdf0e10cSrcweir 			// If 1 or up to 31 days between now and last editing - calculate time indirectly.
280*cdf0e10cSrcweir 			// nAddTime = (24h - nTime) + (nDays * 24h) + aNow
281*cdf0e10cSrcweir 			--nDays;
282*cdf0e10cSrcweir  			nAddTime	 =	nDays*n24Time.GetTime()	;
283*cdf0e10cSrcweir 			nAddTime	+=	n24Time-(const Time&)pImp->nTime		;
284*cdf0e10cSrcweir 			nAddTime	+=	aNow					;
285*cdf0e10cSrcweir 		}
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir         lcl_add(editDuration, nAddTime);
288*cdf0e10cSrcweir 	}
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 	pImp->nTime = aNow;
291*cdf0e10cSrcweir     try {
292*cdf0e10cSrcweir         const sal_Int32 newSecs( (editDuration.Hours*3600)
293*cdf0e10cSrcweir             + (editDuration.Minutes*60) + editDuration.Seconds);
294*cdf0e10cSrcweir         i_xDocProps->setEditingDuration(newSecs);
295*cdf0e10cSrcweir         i_xDocProps->setEditingCycles(i_xDocProps->getEditingCycles() + 1);
296*cdf0e10cSrcweir     }
297*cdf0e10cSrcweir     catch (lang::IllegalArgumentException &)
298*cdf0e10cSrcweir     {
299*cdf0e10cSrcweir         // ignore overflow
300*cdf0e10cSrcweir     }
301*cdf0e10cSrcweir }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir //--------------------------------------------------------------------
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir SfxDocumentInfoDialog* SfxObjectShell::CreateDocumentInfoDialog
306*cdf0e10cSrcweir (
307*cdf0e10cSrcweir 	Window*             pParent,
308*cdf0e10cSrcweir 	const SfxItemSet&   rSet
309*cdf0e10cSrcweir )
310*cdf0e10cSrcweir {
311*cdf0e10cSrcweir 	return new SfxDocumentInfoDialog(pParent, rSet);
312*cdf0e10cSrcweir }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir //--------------------------------------------------------------------
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir SfxStyleSheetBasePool* SfxObjectShell::GetStyleSheetPool()
317*cdf0e10cSrcweir {
318*cdf0e10cSrcweir 	return 0;
319*cdf0e10cSrcweir }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir void SfxObjectShell::SetOrganizerSearchMask(
322*cdf0e10cSrcweir 	SfxStyleSheetBasePool* pStylePool) const
323*cdf0e10cSrcweir {
324*cdf0e10cSrcweir 	pStylePool->SetSearchMask(
325*cdf0e10cSrcweir         SFX_STYLE_FAMILY_ALL,
326*cdf0e10cSrcweir 		SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir //--------------------------------------------------------------------
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir sal_uInt16 SfxObjectShell::GetContentCount(
332*cdf0e10cSrcweir     sal_uInt16 nIdx1,
333*cdf0e10cSrcweir     sal_uInt16 /*nIdx2*/)
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir 	switch(nIdx1)
336*cdf0e10cSrcweir 	{
337*cdf0e10cSrcweir 		case INDEX_IGNORE:
338*cdf0e10cSrcweir 			return DEF_CONTENT_COUNT;
339*cdf0e10cSrcweir 		case CONTENT_STYLE:
340*cdf0e10cSrcweir 		{
341*cdf0e10cSrcweir 			SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
342*cdf0e10cSrcweir 			if(!pStylePool)
343*cdf0e10cSrcweir 				return 0;
344*cdf0e10cSrcweir 			SetOrganizerSearchMask(pStylePool);
345*cdf0e10cSrcweir 			return pStylePool->Count();
346*cdf0e10cSrcweir 		}
347*cdf0e10cSrcweir 		case CONTENT_MACRO:
348*cdf0e10cSrcweir 			break;
349*cdf0e10cSrcweir /*
350*cdf0e10cSrcweir 		case CONTENT_CONFIG:
351*cdf0e10cSrcweir 			return ( GetConfigManager() ) ?
352*cdf0e10cSrcweir 						GetConfigManager()->GetItemCount() : 0;
353*cdf0e10cSrcweir 			break;
354*cdf0e10cSrcweir  */
355*cdf0e10cSrcweir 	}
356*cdf0e10cSrcweir 	return 0;
357*cdf0e10cSrcweir }
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir //--------------------------------------------------------------------
361*cdf0e10cSrcweir //TODO/CLEANUP: remove this method (it's virtual)
362*cdf0e10cSrcweir void  SfxObjectShell::TriggerHelpPI(sal_uInt16 nIdx1, sal_uInt16 nIdx2, sal_uInt16)
363*cdf0e10cSrcweir {
364*cdf0e10cSrcweir 	if(nIdx1==CONTENT_STYLE && nIdx2 != INDEX_IGNORE) //StyleSheets
365*cdf0e10cSrcweir 	{
366*cdf0e10cSrcweir 		SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
367*cdf0e10cSrcweir 		SetOrganizerSearchMask(pStylePool);
368*cdf0e10cSrcweir 	}
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir sal_Bool   SfxObjectShell::CanHaveChilds(sal_uInt16 nIdx1,
372*cdf0e10cSrcweir 									   sal_uInt16 nIdx2)
373*cdf0e10cSrcweir {
374*cdf0e10cSrcweir 	switch(nIdx1) {
375*cdf0e10cSrcweir 	case INDEX_IGNORE:
376*cdf0e10cSrcweir 		return sal_True;
377*cdf0e10cSrcweir 	case CONTENT_STYLE:
378*cdf0e10cSrcweir 		return INDEX_IGNORE == nIdx2 || !GetStyleSheetPool()? sal_False: sal_True;
379*cdf0e10cSrcweir 	case CONTENT_MACRO:
380*cdf0e10cSrcweir //!!    return INDEX_IGNORE == nIdx2? sal_False: sal_True;
381*cdf0e10cSrcweir 		return sal_False;
382*cdf0e10cSrcweir /*
383*cdf0e10cSrcweir 	case CONTENT_CONFIG:
384*cdf0e10cSrcweir 		return INDEX_IGNORE == nIdx2 ? sal_False : sal_True;
385*cdf0e10cSrcweir  */
386*cdf0e10cSrcweir 	}
387*cdf0e10cSrcweir 	return sal_False;
388*cdf0e10cSrcweir }
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir //--------------------------------------------------------------------
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir void SfxObjectShell::GetContent(String &rText,
393*cdf0e10cSrcweir 								Bitmap &rClosedBitmap,
394*cdf0e10cSrcweir 								Bitmap &rOpenedBitmap,
395*cdf0e10cSrcweir 								sal_Bool &bCanDel,
396*cdf0e10cSrcweir 								sal_uInt16 i,
397*cdf0e10cSrcweir 								sal_uInt16 nIdx1,
398*cdf0e10cSrcweir 								sal_uInt16 nIdx2 )
399*cdf0e10cSrcweir {
400*cdf0e10cSrcweir 	DBG_ERRORFILE( "Non high contrast method called. Please update calling code!" );
401*cdf0e10cSrcweir 	SfxObjectShell::GetContent( rText, rClosedBitmap, rOpenedBitmap, BMP_COLOR_NORMAL, bCanDel, i, nIdx1, nIdx2 );
402*cdf0e10cSrcweir }
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir //--------------------------------------------------------------------
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir void   SfxObjectShell::GetContent(String &rText,
407*cdf0e10cSrcweir 								  Bitmap &rClosedBitmap,
408*cdf0e10cSrcweir 								  Bitmap &rOpenedBitmap,
409*cdf0e10cSrcweir 								  BmpColorMode eColorMode,
410*cdf0e10cSrcweir 								  sal_Bool &bCanDel,
411*cdf0e10cSrcweir 								  sal_uInt16 i,
412*cdf0e10cSrcweir 								  sal_uInt16 nIdx1,
413*cdf0e10cSrcweir 								  sal_uInt16 /*nIdx2*/ )
414*cdf0e10cSrcweir {
415*cdf0e10cSrcweir 	bCanDel=sal_True;
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 	switch(nIdx1)
418*cdf0e10cSrcweir 	{
419*cdf0e10cSrcweir 		case INDEX_IGNORE:
420*cdf0e10cSrcweir 		{
421*cdf0e10cSrcweir 			sal_uInt16 nTextResId = 0;
422*cdf0e10cSrcweir 			sal_uInt16 nClosedBitmapResId = 0; // evtl. sp"ater mal unterschiedliche
423*cdf0e10cSrcweir 			sal_uInt16 nOpenedBitmapResId = 0; // "     "       "   "
424*cdf0e10cSrcweir 			switch(i)
425*cdf0e10cSrcweir 			{
426*cdf0e10cSrcweir 				case CONTENT_STYLE:
427*cdf0e10cSrcweir 					nTextResId = STR_STYLES;
428*cdf0e10cSrcweir 					if ( eColorMode == BMP_COLOR_NORMAL )
429*cdf0e10cSrcweir 					{
430*cdf0e10cSrcweir 						nClosedBitmapResId= BMP_STYLES_CLOSED;
431*cdf0e10cSrcweir 						nOpenedBitmapResId= BMP_STYLES_OPENED;
432*cdf0e10cSrcweir 					}
433*cdf0e10cSrcweir 					else
434*cdf0e10cSrcweir 					{
435*cdf0e10cSrcweir 						nClosedBitmapResId= BMP_STYLES_CLOSED_HC;
436*cdf0e10cSrcweir 						nOpenedBitmapResId= BMP_STYLES_OPENED_HC;
437*cdf0e10cSrcweir 					}
438*cdf0e10cSrcweir 					break;
439*cdf0e10cSrcweir 				case CONTENT_MACRO:
440*cdf0e10cSrcweir 					nTextResId = STR_MACROS;
441*cdf0e10cSrcweir 					if ( eColorMode == BMP_COLOR_NORMAL )
442*cdf0e10cSrcweir 					{
443*cdf0e10cSrcweir 						nClosedBitmapResId= BMP_STYLES_CLOSED;
444*cdf0e10cSrcweir 						nOpenedBitmapResId= BMP_STYLES_OPENED;
445*cdf0e10cSrcweir 					}
446*cdf0e10cSrcweir 					else
447*cdf0e10cSrcweir 					{
448*cdf0e10cSrcweir 						nClosedBitmapResId= BMP_STYLES_CLOSED_HC;
449*cdf0e10cSrcweir 						nOpenedBitmapResId= BMP_STYLES_OPENED_HC;
450*cdf0e10cSrcweir 					}
451*cdf0e10cSrcweir 					break;
452*cdf0e10cSrcweir /*
453*cdf0e10cSrcweir 				case CONTENT_CONFIG:
454*cdf0e10cSrcweir 					nTextResId = STR_CONFIG;
455*cdf0e10cSrcweir 					nClosedBitmapResId= BMP_STYLES_CLOSED;
456*cdf0e10cSrcweir 					nOpenedBitmapResId= BMP_STYLES_OPENED;
457*cdf0e10cSrcweir 					break;
458*cdf0e10cSrcweir  */
459*cdf0e10cSrcweir 			}
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir 			if ( nTextResId )
462*cdf0e10cSrcweir 			{
463*cdf0e10cSrcweir 				rText  = String(SfxResId(nTextResId));
464*cdf0e10cSrcweir 				rClosedBitmap = Bitmap(SfxResId(nClosedBitmapResId));
465*cdf0e10cSrcweir 				rOpenedBitmap = Bitmap(SfxResId(nOpenedBitmapResId));
466*cdf0e10cSrcweir 			}
467*cdf0e10cSrcweir 			break;
468*cdf0e10cSrcweir 		}
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir 		case CONTENT_STYLE:
471*cdf0e10cSrcweir 		{
472*cdf0e10cSrcweir 			SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
473*cdf0e10cSrcweir 			SetOrganizerSearchMask(pStylePool);
474*cdf0e10cSrcweir 			SfxStyleSheetBase *pStyle = (*pStylePool)[i];
475*cdf0e10cSrcweir 			rText = pStyle->GetName();
476*cdf0e10cSrcweir 			bCanDel=((pStyle->GetMask() & SFXSTYLEBIT_USERDEF)
477*cdf0e10cSrcweir 					 == SFXSTYLEBIT_USERDEF);
478*cdf0e10cSrcweir 			rClosedBitmap = rOpenedBitmap =
479*cdf0e10cSrcweir 				GetStyleFamilyBitmap(pStyle->GetFamily(), eColorMode );
480*cdf0e10cSrcweir 		}
481*cdf0e10cSrcweir 			break;
482*cdf0e10cSrcweir 		case CONTENT_MACRO:
483*cdf0e10cSrcweir 			break;
484*cdf0e10cSrcweir /*
485*cdf0e10cSrcweir 		case CONTENT_CONFIG:
486*cdf0e10cSrcweir 			if ( GetConfigManager() )
487*cdf0e10cSrcweir 			{
488*cdf0e10cSrcweir 				rText = GetConfigManager()->GetItem(i);
489*cdf0e10cSrcweir 				bCanDel = GetConfigManager()->CanDelete(i);
490*cdf0e10cSrcweir 			}
491*cdf0e10cSrcweir 			else
492*cdf0e10cSrcweir 				rText = String();
493*cdf0e10cSrcweir 			rClosedBitmap = Bitmap(SfxResId(BMP_STYLES_CLOSED));
494*cdf0e10cSrcweir 			rOpenedBitmap = Bitmap(SfxResId(BMP_STYLES_OPENED));
495*cdf0e10cSrcweir 			break;
496*cdf0e10cSrcweir */
497*cdf0e10cSrcweir 	}
498*cdf0e10cSrcweir }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir //--------------------------------------------------------------------
501*cdf0e10cSrcweir Bitmap SfxObjectShell::GetStyleFamilyBitmap( SfxStyleFamily eFamily )
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir 	DBG_ERRORFILE( "Non high contrast method called. Please update calling code!" );
504*cdf0e10cSrcweir 	return SfxObjectShell::GetStyleFamilyBitmap( eFamily, BMP_COLOR_NORMAL );
505*cdf0e10cSrcweir }
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir //--------------------------------------------------------------------
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir Bitmap SfxObjectShell::GetStyleFamilyBitmap(SfxStyleFamily eFamily, BmpColorMode eColorMode )
510*cdf0e10cSrcweir {
511*cdf0e10cSrcweir 	sal_uInt16 nResId = 0;
512*cdf0e10cSrcweir 	switch(eFamily)
513*cdf0e10cSrcweir 	{
514*cdf0e10cSrcweir 		case SFX_STYLE_FAMILY_CHAR:
515*cdf0e10cSrcweir 			nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY1 : BMP_STYLES_FAMILY1_HC;
516*cdf0e10cSrcweir 			break;
517*cdf0e10cSrcweir 		case SFX_STYLE_FAMILY_PARA:
518*cdf0e10cSrcweir 			nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY2 : BMP_STYLES_FAMILY2_HC;
519*cdf0e10cSrcweir 			break;
520*cdf0e10cSrcweir 		case SFX_STYLE_FAMILY_FRAME:
521*cdf0e10cSrcweir 			nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY3 : BMP_STYLES_FAMILY3_HC;
522*cdf0e10cSrcweir 			break;
523*cdf0e10cSrcweir 		case SFX_STYLE_FAMILY_PAGE :
524*cdf0e10cSrcweir 			nResId = ( eColorMode == BMP_COLOR_NORMAL ) ? BMP_STYLES_FAMILY4 : BMP_STYLES_FAMILY4_HC;
525*cdf0e10cSrcweir 			break;
526*cdf0e10cSrcweir 		case SFX_STYLE_FAMILY_PSEUDO:
527*cdf0e10cSrcweir 		case SFX_STYLE_FAMILY_ALL:
528*cdf0e10cSrcweir 			break;
529*cdf0e10cSrcweir 	}
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir 	if ( nResId )
532*cdf0e10cSrcweir 		return Bitmap(SfxResId(nResId));
533*cdf0e10cSrcweir 	else
534*cdf0e10cSrcweir 		return Bitmap();
535*cdf0e10cSrcweir }
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir //--------------------------------------------------------------------
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir sal_Bool SfxObjectShell::Insert(SfxObjectShell &rSource,
541*cdf0e10cSrcweir 							  sal_uInt16 nSourceIdx1,
542*cdf0e10cSrcweir 							  sal_uInt16 nSourceIdx2,
543*cdf0e10cSrcweir 							  sal_uInt16 /*nSourceIdx3*/,
544*cdf0e10cSrcweir 							  sal_uInt16 &nIdx1,
545*cdf0e10cSrcweir 							  sal_uInt16 &nIdx2,
546*cdf0e10cSrcweir 							  sal_uInt16 &/*nIdx3*/,
547*cdf0e10cSrcweir 							  sal_uInt16 &/*nDeleted*/)
548*cdf0e10cSrcweir {
549*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir 	if (INDEX_IGNORE == nIdx1 && CONTENT_STYLE == nSourceIdx1)
552*cdf0e10cSrcweir 		nIdx1 = CONTENT_STYLE;
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir 	if (CONTENT_STYLE == nSourceIdx1 && CONTENT_STYLE == nIdx1)
555*cdf0e10cSrcweir 	{
556*cdf0e10cSrcweir 		SfxStyleSheetBasePool* pHisPool  = rSource.GetStyleSheetPool();
557*cdf0e10cSrcweir 		SfxStyleSheetBasePool* pMyPool   = GetStyleSheetPool();
558*cdf0e10cSrcweir 		SetOrganizerSearchMask(pHisPool);
559*cdf0e10cSrcweir 		SetOrganizerSearchMask(pMyPool);
560*cdf0e10cSrcweir         SfxStyleSheetBase* pHisSheet = NULL;
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir         if ( pHisPool && pHisPool->Count() > nSourceIdx2 )
563*cdf0e10cSrcweir             pHisSheet = (*pHisPool)[nSourceIdx2];
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir 		// Einfuegen ist nur dann noetig, wenn ein StyleSheet
566*cdf0e10cSrcweir 		// zwischen unterschiedlichen(!) Pools bewegt wird
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir         if ( pHisSheet && pMyPool != pHisPool )
569*cdf0e10cSrcweir 		{
570*cdf0e10cSrcweir 			if (INDEX_IGNORE == nIdx2)
571*cdf0e10cSrcweir 			{
572*cdf0e10cSrcweir 				nIdx2 = pMyPool->Count();
573*cdf0e10cSrcweir 			}
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir 			// wenn so eine Vorlage schon existiert: loeschen!
576*cdf0e10cSrcweir 			String aOldName(pHisSheet->GetName());
577*cdf0e10cSrcweir 			SfxStyleFamily eOldFamily = pHisSheet->GetFamily();
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir 			SfxStyleSheetBase* pExist = pMyPool->Find(aOldName, eOldFamily);
580*cdf0e10cSrcweir 			// sal_uInt16 nOldHelpId = pExist->GetHelpId(??? VB ueberlegt sich was);
581*cdf0e10cSrcweir 			sal_Bool bUsedOrUserDefined;
582*cdf0e10cSrcweir 			if( pExist )
583*cdf0e10cSrcweir 			{
584*cdf0e10cSrcweir 				bUsedOrUserDefined =
585*cdf0e10cSrcweir 					pExist->IsUsed() || pExist->IsUserDefined();
586*cdf0e10cSrcweir 				if( ErrorHandler::HandleError(
587*cdf0e10cSrcweir 					*new MessageInfo( ERRCODE_SFXMSG_STYLEREPLACE, aOldName ) )
588*cdf0e10cSrcweir 					!= ERRCODE_BUTTON_OK )
589*cdf0e10cSrcweir 					return sal_False;
590*cdf0e10cSrcweir 				else
591*cdf0e10cSrcweir 				{
592*cdf0e10cSrcweir 					pMyPool->Replace( *pHisSheet, *pExist );
593*cdf0e10cSrcweir 					SetModified( sal_True );
594*cdf0e10cSrcweir 					nIdx2 = nIdx1 = INDEX_IGNORE;
595*cdf0e10cSrcweir 					return sal_True;
596*cdf0e10cSrcweir 				}
597*cdf0e10cSrcweir 			}
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir 			SfxStyleSheetBase& rNewSheet = pMyPool->Make(
600*cdf0e10cSrcweir 				aOldName, eOldFamily,
601*cdf0e10cSrcweir 				pHisSheet->GetMask(), nIdx2);
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir 			// ItemSet der neuen Vorlage fuellen
604*cdf0e10cSrcweir 			rNewSheet.GetItemSet().Set(pHisSheet->GetItemSet());
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 			// wer bekommt den Neuen als Parent? wer benutzt den Neuen als Follow?
607*cdf0e10cSrcweir 			SfxStyleSheetBase* pTestSheet = pMyPool->First();
608*cdf0e10cSrcweir 			while (pTestSheet)
609*cdf0e10cSrcweir 			{
610*cdf0e10cSrcweir 				if (pTestSheet->GetFamily() == eOldFamily &&
611*cdf0e10cSrcweir 					pTestSheet->HasParentSupport() &&
612*cdf0e10cSrcweir 					pTestSheet->GetParent() == aOldName)
613*cdf0e10cSrcweir 				{
614*cdf0e10cSrcweir 					pTestSheet->SetParent(aOldName);
615*cdf0e10cSrcweir 					// Verknuepfung neu aufbauen
616*cdf0e10cSrcweir 				}
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir 				if (pTestSheet->GetFamily() == eOldFamily &&
619*cdf0e10cSrcweir 					pTestSheet->HasFollowSupport() &&
620*cdf0e10cSrcweir 					pTestSheet->GetFollow() == aOldName)
621*cdf0e10cSrcweir 				{
622*cdf0e10cSrcweir 					pTestSheet->SetFollow(aOldName);
623*cdf0e10cSrcweir 					// Verknuepfung neu aufbauen
624*cdf0e10cSrcweir 				}
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir 				pTestSheet = pMyPool->Next();
627*cdf0e10cSrcweir 			}
628*cdf0e10cSrcweir 			bUsedOrUserDefined =
629*cdf0e10cSrcweir 				rNewSheet.IsUsed() || rNewSheet.IsUserDefined();
630*cdf0e10cSrcweir 
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir 			// hat der Neue einen Parent? wenn ja, mit gleichem Namen bei uns suchen
633*cdf0e10cSrcweir 			if (pHisSheet->HasParentSupport())
634*cdf0e10cSrcweir 			{
635*cdf0e10cSrcweir 				const String& rParentName = pHisSheet->GetParent();
636*cdf0e10cSrcweir 				if (0 != rParentName.Len())
637*cdf0e10cSrcweir 				{
638*cdf0e10cSrcweir 					SfxStyleSheetBase* pParentOfNew =
639*cdf0e10cSrcweir 						pMyPool->Find(rParentName, eOldFamily);
640*cdf0e10cSrcweir 					if (pParentOfNew)
641*cdf0e10cSrcweir 						rNewSheet.SetParent(rParentName);
642*cdf0e10cSrcweir 				}
643*cdf0e10cSrcweir 			}
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir 			// hat der Neue einen Follow? wenn ja, mit gleichem
646*cdf0e10cSrcweir 			// Namen bei uns suchen
647*cdf0e10cSrcweir 			if (pHisSheet->HasFollowSupport())
648*cdf0e10cSrcweir 			{
649*cdf0e10cSrcweir 				const String& rFollowName = pHisSheet->GetFollow();
650*cdf0e10cSrcweir 				if (0 != rFollowName.Len())
651*cdf0e10cSrcweir 				{
652*cdf0e10cSrcweir 					SfxStyleSheetBase* pFollowOfNew =
653*cdf0e10cSrcweir 						pMyPool->Find(rFollowName, eOldFamily);
654*cdf0e10cSrcweir 					if (pFollowOfNew)
655*cdf0e10cSrcweir 						rNewSheet.SetFollow(rFollowName);
656*cdf0e10cSrcweir 				}
657*cdf0e10cSrcweir 			}
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir 			SetModified( sal_True );
660*cdf0e10cSrcweir 			if( !bUsedOrUserDefined ) nIdx2 = nIdx1 = INDEX_IGNORE;
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir 			bRet = sal_True;
663*cdf0e10cSrcweir 		}
664*cdf0e10cSrcweir 		else
665*cdf0e10cSrcweir 			bRet = sal_False;
666*cdf0e10cSrcweir 	}
667*cdf0e10cSrcweir /*
668*cdf0e10cSrcweir 	else if (nSourceIdx1 == CONTENT_CONFIG)
669*cdf0e10cSrcweir 	{
670*cdf0e10cSrcweir 		nIdx1 = CONTENT_CONFIG;
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir 		SfxConfigManager *pCfgMgr = SFX_CFGMANAGER();
673*cdf0e10cSrcweir 		if ( !GetConfigManager() )
674*cdf0e10cSrcweir 		{
675*cdf0e10cSrcweir 			SetConfigManager(new SfxConfigManager(0, pCfgMgr));
676*cdf0e10cSrcweir 			SetTemplateConfig(sal_False);
677*cdf0e10cSrcweir 			if (this == Current())
678*cdf0e10cSrcweir 				GetConfigManager()->Activate(pCfgMgr);
679*cdf0e10cSrcweir 		}
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir 		if (GetConfigManager()->CopyItem(
682*cdf0e10cSrcweir 			nSourceIdx2, nIdx2, rSource.GetConfigManager()))
683*cdf0e10cSrcweir 		{
684*cdf0e10cSrcweir 			SetModified(sal_True);
685*cdf0e10cSrcweir 			bRet = sal_True;
686*cdf0e10cSrcweir             SFX_APP()->GetDispatcher_Impl()->Update_Impl(sal_True);
687*cdf0e10cSrcweir 		}
688*cdf0e10cSrcweir 	}
689*cdf0e10cSrcweir */
690*cdf0e10cSrcweir 	return bRet;
691*cdf0e10cSrcweir }
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir //--------------------------------------------------------------------
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir sal_Bool SfxObjectShell::Remove
696*cdf0e10cSrcweir (
697*cdf0e10cSrcweir 	sal_uInt16 nIdx1,
698*cdf0e10cSrcweir 	sal_uInt16 nIdx2,
699*cdf0e10cSrcweir 	sal_uInt16 /*nIdx3*/
700*cdf0e10cSrcweir )
701*cdf0e10cSrcweir {
702*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir 	if (CONTENT_STYLE == nIdx1)
705*cdf0e10cSrcweir 	{
706*cdf0e10cSrcweir 		SfxStyleSheetBasePool* pMyPool  = GetStyleSheetPool();
707*cdf0e10cSrcweir 
708*cdf0e10cSrcweir 		SetOrganizerSearchMask(pMyPool);
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir 		SfxStyleSheetBase* pMySheet =  (*pMyPool)[nIdx2];
711*cdf0e10cSrcweir 		String aName(pMySheet->GetName());
712*cdf0e10cSrcweir 		String aEmpty;
713*cdf0e10cSrcweir 		SfxStyleFamily  eFamily = pMySheet->GetFamily();
714*cdf0e10cSrcweir 		pMyPool->Remove(pMySheet);
715*cdf0e10cSrcweir 		bRet = sal_True;
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir 		SfxStyleSheetBase* pTestSheet = pMyPool->First();
718*cdf0e10cSrcweir 		while (pTestSheet)
719*cdf0e10cSrcweir 		{
720*cdf0e10cSrcweir 			if (pTestSheet->GetFamily() == eFamily &&
721*cdf0e10cSrcweir 				pTestSheet->HasParentSupport() &&
722*cdf0e10cSrcweir 				pTestSheet->GetParent() == aName)
723*cdf0e10cSrcweir 			{
724*cdf0e10cSrcweir 				pTestSheet->SetParent(aEmpty); // Verknuepfung aufloesen
725*cdf0e10cSrcweir 			}
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir 			if (pTestSheet->GetFamily() == eFamily &&
728*cdf0e10cSrcweir 				pTestSheet->HasFollowSupport() &&
729*cdf0e10cSrcweir 				pTestSheet->GetFollow() == aName)
730*cdf0e10cSrcweir 			{
731*cdf0e10cSrcweir 				pTestSheet->SetFollow(aEmpty); // Verknuepfung aufloesen
732*cdf0e10cSrcweir 			}
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir 			pTestSheet = pMyPool->Next();
735*cdf0e10cSrcweir 		}
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir 		SetModified( sal_True );
738*cdf0e10cSrcweir 	}
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir 	return bRet;
741*cdf0e10cSrcweir }
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir //--------------------------------------------------------------------
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir sal_Bool SfxObjectShell::Print
746*cdf0e10cSrcweir (
747*cdf0e10cSrcweir 	Printer&        rPrt,
748*cdf0e10cSrcweir 	sal_uInt16          nIdx1,
749*cdf0e10cSrcweir 	sal_uInt16          /*nIdx2*/,
750*cdf0e10cSrcweir 	sal_uInt16          /*nIdx3*/,
751*cdf0e10cSrcweir 	const String*   pObjectName
752*cdf0e10cSrcweir )
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir /*  [Beschreibung]
755*cdf0e10cSrcweir */
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir {
758*cdf0e10cSrcweir 	switch(nIdx1)
759*cdf0e10cSrcweir 	{
760*cdf0e10cSrcweir 	  case CONTENT_STYLE:
761*cdf0e10cSrcweir 		{
762*cdf0e10cSrcweir 			SfxStyleSheetBasePool *pStylePool = GetStyleSheetPool();
763*cdf0e10cSrcweir 			SetOrganizerSearchMask(pStylePool);
764*cdf0e10cSrcweir 			SfxStyleSheetIterator* pIter = pStylePool->CreateIterator(
765*cdf0e10cSrcweir 				pStylePool->GetSearchFamily(), pStylePool->GetSearchMask() );
766*cdf0e10cSrcweir 			sal_uInt16 nStyles = pIter->Count();
767*cdf0e10cSrcweir 			SfxStyleSheetBase *pStyle = pIter->First();
768*cdf0e10cSrcweir 			if ( !pStyle )
769*cdf0e10cSrcweir 				return sal_True;
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir             // pepare adaptor for old style StartPage/EndPage printing
772*cdf0e10cSrcweir             boost::shared_ptr< Printer > pPrinter( new Printer( rPrt.GetJobSetup() ) );
773*cdf0e10cSrcweir             vcl::OldStylePrintAdaptor* pAdaptor = new vcl::OldStylePrintAdaptor( pPrinter );
774*cdf0e10cSrcweir             boost::shared_ptr< vcl::PrinterController > pController( pAdaptor );
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir             pAdaptor->StartPage();
777*cdf0e10cSrcweir 
778*cdf0e10cSrcweir             pPrinter->SetMapMode(MapMode(MAP_10TH_MM));
779*cdf0e10cSrcweir 			Font aFont( DEFINE_CONST_UNICODE( "Arial" ), Size(0, 64));   // 18pt
780*cdf0e10cSrcweir 			aFont.SetWeight(WEIGHT_BOLD);
781*cdf0e10cSrcweir 			pPrinter->SetFont(aFont);
782*cdf0e10cSrcweir 			const Size aPageSize(pPrinter->GetOutputSize());
783*cdf0e10cSrcweir 			const sal_uInt16 nXIndent = 200;
784*cdf0e10cSrcweir 			sal_uInt16 nYIndent = 200;
785*cdf0e10cSrcweir 			Point aOutPos(nXIndent, nYIndent);
786*cdf0e10cSrcweir 			String aHeader(SfxResId(STR_PRINT_STYLES_HEADER));
787*cdf0e10cSrcweir 			if ( pObjectName )
788*cdf0e10cSrcweir 				aHeader += *pObjectName;
789*cdf0e10cSrcweir 			else
790*cdf0e10cSrcweir 				aHeader += GetTitle();
791*cdf0e10cSrcweir             long nTextHeight( pPrinter->GetTextHeight() );
792*cdf0e10cSrcweir 			pPrinter->DrawText(aOutPos, aHeader);
793*cdf0e10cSrcweir 			aOutPos.Y() += nTextHeight;
794*cdf0e10cSrcweir 			aOutPos.Y() += nTextHeight/2;
795*cdf0e10cSrcweir 			aFont.SetSize(Size(0, 35)); // 10pt
796*cdf0e10cSrcweir 			nStyles = 1;
797*cdf0e10cSrcweir 			while(pStyle)
798*cdf0e10cSrcweir 			{
799*cdf0e10cSrcweir 				// print template name
800*cdf0e10cSrcweir 				String aStr(pStyle->GetName());
801*cdf0e10cSrcweir 				aFont.SetWeight(WEIGHT_BOLD);
802*cdf0e10cSrcweir 				pPrinter->SetFont(aFont);
803*cdf0e10cSrcweir 				nTextHeight = pPrinter->GetTextHeight();
804*cdf0e10cSrcweir 				// check for new page
805*cdf0e10cSrcweir 				if ( aOutPos.Y() + nTextHeight*2 >
806*cdf0e10cSrcweir                     aPageSize.Height() - (long) nYIndent )
807*cdf0e10cSrcweir 				{
808*cdf0e10cSrcweir 					pAdaptor->EndPage();
809*cdf0e10cSrcweir 					pAdaptor->StartPage();
810*cdf0e10cSrcweir 					aOutPos.Y() = nYIndent;
811*cdf0e10cSrcweir 				}
812*cdf0e10cSrcweir 				pPrinter->DrawText(aOutPos, aStr);
813*cdf0e10cSrcweir 				aOutPos.Y() += nTextHeight;
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir 				// print template description
816*cdf0e10cSrcweir 				aFont.SetWeight(WEIGHT_NORMAL);
817*cdf0e10cSrcweir 				pPrinter->SetFont(aFont);
818*cdf0e10cSrcweir 				aStr = pStyle->GetDescription();
819*cdf0e10cSrcweir 				const char cDelim = ' ';
820*cdf0e10cSrcweir 				sal_uInt16 nStart = 0, nIdx = 0;
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir 				nTextHeight = pPrinter->GetTextHeight();
823*cdf0e10cSrcweir 				// break text into lines
824*cdf0e10cSrcweir 				while(nIdx < aStr.Len())
825*cdf0e10cSrcweir 				{
826*cdf0e10cSrcweir 					sal_uInt16	nOld = nIdx;
827*cdf0e10cSrcweir                     long nTextWidth;
828*cdf0e10cSrcweir 					nIdx = aStr.Search(cDelim, nStart);
829*cdf0e10cSrcweir 					nTextWidth = pPrinter->GetTextWidth(aStr, nStart, nIdx-nStart);
830*cdf0e10cSrcweir 					while(nIdx != STRING_NOTFOUND &&
831*cdf0e10cSrcweir 						  aOutPos.X() + nTextWidth <
832*cdf0e10cSrcweir                           aPageSize.Width() - (long) nXIndent)
833*cdf0e10cSrcweir 					{
834*cdf0e10cSrcweir 						nOld = nIdx;
835*cdf0e10cSrcweir 						nIdx = aStr.Search(cDelim, nIdx+1);
836*cdf0e10cSrcweir 						nTextWidth = pPrinter->GetTextWidth(aStr, nStart, nIdx-nStart);
837*cdf0e10cSrcweir 					}
838*cdf0e10cSrcweir 					String aTmp(aStr, nStart, nIdx == STRING_NOTFOUND?
839*cdf0e10cSrcweir 								STRING_LEN :
840*cdf0e10cSrcweir 								nOld-nStart);
841*cdf0e10cSrcweir 					if ( aTmp.Len() )
842*cdf0e10cSrcweir 					{
843*cdf0e10cSrcweir 						nStart = nOld+1;    // trailing space
844*cdf0e10cSrcweir 					}
845*cdf0e10cSrcweir 					else
846*cdf0e10cSrcweir 					{
847*cdf0e10cSrcweir 						sal_uInt16 nChar = 1;
848*cdf0e10cSrcweir 						while(
849*cdf0e10cSrcweir 							nStart + nChar < aStr.Len() &&
850*cdf0e10cSrcweir 							aOutPos.X() + pPrinter->GetTextWidth(
851*cdf0e10cSrcweir 								aStr, nStart, nChar) <
852*cdf0e10cSrcweir 							aPageSize.Width() - nXIndent)
853*cdf0e10cSrcweir 							++nChar;
854*cdf0e10cSrcweir 						aTmp = String(aStr, nStart, nChar-1);
855*cdf0e10cSrcweir 						nIdx = nStart + nChar;
856*cdf0e10cSrcweir 						nStart = nIdx;
857*cdf0e10cSrcweir 					}
858*cdf0e10cSrcweir 					if ( aOutPos.Y() + nTextHeight*2 >
859*cdf0e10cSrcweir 						aPageSize.Height() - nYIndent )
860*cdf0e10cSrcweir 					{
861*cdf0e10cSrcweir 						pAdaptor->EndPage();
862*cdf0e10cSrcweir 						pAdaptor->StartPage();
863*cdf0e10cSrcweir 						aOutPos.Y() = nYIndent;
864*cdf0e10cSrcweir 					}
865*cdf0e10cSrcweir 					pPrinter->DrawText(aOutPos, aTmp);
866*cdf0e10cSrcweir 					aOutPos.Y() += pPrinter->GetTextHeight();
867*cdf0e10cSrcweir 				}
868*cdf0e10cSrcweir 				pStyle = pIter->Next();
869*cdf0e10cSrcweir 			}
870*cdf0e10cSrcweir 			pAdaptor->EndPage();
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir             Printer::PrintJob( pController, rPrt.GetJobSetup() );
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir 			delete pIter;
875*cdf0e10cSrcweir 			break;
876*cdf0e10cSrcweir 		}
877*cdf0e10cSrcweir 	  default:
878*cdf0e10cSrcweir 		  return sal_False;
879*cdf0e10cSrcweir 	}
880*cdf0e10cSrcweir 	return sal_True;
881*cdf0e10cSrcweir }
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir //--------------------------------------------------------------------
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir void SfxObjectShell::LoadStyles
886*cdf0e10cSrcweir (
887*cdf0e10cSrcweir 	SfxObjectShell &rSource         /*  die Dokument-Vorlage, aus der
888*cdf0e10cSrcweir 											die Styles geladen werden sollen */
889*cdf0e10cSrcweir )
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir /*  [Beschreibung]
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir 	Diese Methode wird vom SFx gerufen, wenn aus einer Dokument-Vorlage
894*cdf0e10cSrcweir 	Styles nachgeladen werden sollen. Bestehende Styles soll dabei
895*cdf0e10cSrcweir 	"uberschrieben werden. Das Dokument mu"s daher neu formatiert werden.
896*cdf0e10cSrcweir 	Daher werden die Applikationen in der Regel diese Methode "uberladen
897*cdf0e10cSrcweir 	und in ihrer Implementierung die Implementierung der Basisklasse
898*cdf0e10cSrcweir 	rufen.
899*cdf0e10cSrcweir */
900*cdf0e10cSrcweir 
901*cdf0e10cSrcweir {
902*cdf0e10cSrcweir 	struct Styles_Impl
903*cdf0e10cSrcweir 	{
904*cdf0e10cSrcweir 		SfxStyleSheetBase *pSource;
905*cdf0e10cSrcweir 		SfxStyleSheetBase *pDest;
906*cdf0e10cSrcweir //      Styles_Impl () : pSource(0), pDest(0) {}
907*cdf0e10cSrcweir 	};
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir 	SfxStyleSheetBasePool *pSourcePool = rSource.GetStyleSheetPool();
910*cdf0e10cSrcweir 	DBG_ASSERT(pSourcePool, "Source-DocumentShell ohne StyleSheetPool");
911*cdf0e10cSrcweir 	SfxStyleSheetBasePool *pMyPool = GetStyleSheetPool();
912*cdf0e10cSrcweir 	DBG_ASSERT(pMyPool, "Dest-DocumentShell ohne StyleSheetPool");
913*cdf0e10cSrcweir 	pSourcePool->SetSearchMask(SFX_STYLE_FAMILY_ALL, 0xffff);
914*cdf0e10cSrcweir 	Styles_Impl *pFound = new Styles_Impl[pSourcePool->Count()];
915*cdf0e10cSrcweir 	sal_uInt16 nFound = 0;
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir 	SfxStyleSheetBase *pSource = pSourcePool->First();
918*cdf0e10cSrcweir 	while ( pSource )
919*cdf0e10cSrcweir 	{
920*cdf0e10cSrcweir 		SfxStyleSheetBase *pDest =
921*cdf0e10cSrcweir 			pMyPool->Find( pSource->GetName(), pSource->GetFamily() );
922*cdf0e10cSrcweir 		if ( !pDest )
923*cdf0e10cSrcweir 		{
924*cdf0e10cSrcweir 			pDest = &pMyPool->Make( pSource->GetName(),
925*cdf0e10cSrcweir 					pSource->GetFamily(), pSource->GetMask());
926*cdf0e10cSrcweir 			// Setzen des Parents, der Folgevorlage
927*cdf0e10cSrcweir 		}
928*cdf0e10cSrcweir 		pFound[nFound].pSource = pSource;
929*cdf0e10cSrcweir 		pFound[nFound].pDest = pDest;
930*cdf0e10cSrcweir 		++nFound;
931*cdf0e10cSrcweir 		pSource = pSourcePool->Next();
932*cdf0e10cSrcweir 	}
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < nFound; ++i )
935*cdf0e10cSrcweir 	{
936*cdf0e10cSrcweir 		pFound[i].pDest->GetItemSet().PutExtended(pFound[i].pSource->GetItemSet(), SFX_ITEM_DONTCARE, SFX_ITEM_DEFAULT);
937*cdf0e10cSrcweir //      pFound[i].pDest->SetHelpId(pFound[i].pSource->GetHelpId());
938*cdf0e10cSrcweir 		if(pFound[i].pSource->HasParentSupport())
939*cdf0e10cSrcweir 			pFound[i].pDest->SetParent(pFound[i].pSource->GetParent());
940*cdf0e10cSrcweir 		if(pFound[i].pSource->HasFollowSupport())
941*cdf0e10cSrcweir 			pFound[i].pDest->SetFollow(pFound[i].pSource->GetParent());
942*cdf0e10cSrcweir 	}
943*cdf0e10cSrcweir 	delete [] pFound;
944*cdf0e10cSrcweir }
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir //--------------------------------------------------------------------
947*cdf0e10cSrcweir 
948*cdf0e10cSrcweir void SfxObjectShell::UpdateFromTemplate_Impl(  )
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir /*  [Beschreibung]
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir 	Diese interne Methode pr"uft, ob das Dokument aus einem Template
953*cdf0e10cSrcweir 	erzeugt wurde, und ob dieses neuer ist als das Dokument. Ist dies
954*cdf0e10cSrcweir 	der Fall, wird der Benutzer gefragt, ob die Vorlagen (StyleSheets)
955*cdf0e10cSrcweir 	updated werden sollen. Wird dies positiv beantwortet, werden die
956*cdf0e10cSrcweir 	StyleSheets updated.
957*cdf0e10cSrcweir */
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir {
960*cdf0e10cSrcweir 	// Storage-medium?
961*cdf0e10cSrcweir 	SfxMedium *pFile = GetMedium();
962*cdf0e10cSrcweir 	DBG_ASSERT( pFile, "cannot UpdateFromTemplate without medium" );
963*cdf0e10cSrcweir 	if ( !pFile )
964*cdf0e10cSrcweir 		return;
965*cdf0e10cSrcweir 
966*cdf0e10cSrcweir 	if ( !::utl::LocalFileHelper::IsLocalFile( pFile->GetName() ) )
967*cdf0e10cSrcweir 		// update only for documents loaded from the local file system
968*cdf0e10cSrcweir 		return;
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir     // only for own storage formats
971*cdf0e10cSrcweir 	uno::Reference< embed::XStorage > xDocStor = pFile->GetStorage();
972*cdf0e10cSrcweir     if ( !pFile->GetFilter() || !pFile->GetFilter()->IsOwnFormat() )
973*cdf0e10cSrcweir 		return;
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir 	SFX_ITEMSET_ARG( pFile->GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
976*cdf0e10cSrcweir 	sal_Int16 bCanUpdateFromTemplate = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir     // created from template?
979*cdf0e10cSrcweir     uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
980*cdf0e10cSrcweir     ::rtl::OUString aTemplName( xDocProps->getTemplateName() );
981*cdf0e10cSrcweir     ::rtl::OUString aTemplURL( xDocProps->getTemplateURL() );
982*cdf0e10cSrcweir     String aFoundName;
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir     if ( aTemplName.getLength() || (aTemplURL.getLength() && !IsReadOnly()) )
985*cdf0e10cSrcweir 	{
986*cdf0e10cSrcweir         // try to locate template, first using filename
987*cdf0e10cSrcweir         // this must be done because writer global document uses this "great" idea to manage the templates of all parts
988*cdf0e10cSrcweir         // in the master document
989*cdf0e10cSrcweir         // but it is NOT an error if the template filename points not to a valid file
990*cdf0e10cSrcweir         SfxDocumentTemplates aTempl;
991*cdf0e10cSrcweir         aTempl.Construct();
992*cdf0e10cSrcweir         if ( aTemplURL.getLength() )
993*cdf0e10cSrcweir         {
994*cdf0e10cSrcweir             String aURL;
995*cdf0e10cSrcweir             if( ::utl::LocalFileHelper::ConvertSystemPathToURL( aTemplURL, GetMedium()->GetName(), aURL ) )
996*cdf0e10cSrcweir                 aFoundName = aURL;
997*cdf0e10cSrcweir         }
998*cdf0e10cSrcweir 
999*cdf0e10cSrcweir         if( !aFoundName.Len() && aTemplName.getLength() )
1000*cdf0e10cSrcweir             // if the template filename did not lead to success, try to get a file name for the logical template name
1001*cdf0e10cSrcweir             aTempl.GetFull( String(), aTemplName, aFoundName );
1002*cdf0e10cSrcweir 	}
1003*cdf0e10cSrcweir 
1004*cdf0e10cSrcweir     if ( aFoundName.Len() )
1005*cdf0e10cSrcweir 	{
1006*cdf0e10cSrcweir         // check existence of template storage
1007*cdf0e10cSrcweir         aTemplURL = aFoundName;
1008*cdf0e10cSrcweir 		sal_Bool bLoad = sal_False;
1009*cdf0e10cSrcweir 
1010*cdf0e10cSrcweir         // should the document checked against changes in the template ?
1011*cdf0e10cSrcweir         if ( IsQueryLoadTemplate() )
1012*cdf0e10cSrcweir 		{
1013*cdf0e10cSrcweir             // load document info of template
1014*cdf0e10cSrcweir             sal_Bool bOK = sal_False;
1015*cdf0e10cSrcweir 			util::DateTime aTemplDate;
1016*cdf0e10cSrcweir             try
1017*cdf0e10cSrcweir             {
1018*cdf0e10cSrcweir                 Reference < document::XStandaloneDocumentInfo > xDocInfo (
1019*cdf0e10cSrcweir                     ::comphelper::getProcessServiceFactory()->createInstance(
1020*cdf0e10cSrcweir                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
1021*cdf0e10cSrcweir                             "com.sun.star.document.StandaloneDocumentInfo") ) ),
1022*cdf0e10cSrcweir                     UNO_QUERY_THROW );
1023*cdf0e10cSrcweir                 Reference < beans::XFastPropertySet > xSet( xDocInfo,
1024*cdf0e10cSrcweir                     UNO_QUERY_THROW );
1025*cdf0e10cSrcweir                 xDocInfo->loadFromURL( aTemplURL );
1026*cdf0e10cSrcweir                 Any aAny = xSet->getFastPropertyValue( WID_DATE_MODIFIED );
1027*cdf0e10cSrcweir                 ::com::sun::star::util::DateTime aTmp;
1028*cdf0e10cSrcweir                 if ( aAny >>= aTemplDate )
1029*cdf0e10cSrcweir                 {
1030*cdf0e10cSrcweir                     // get modify date from document info
1031*cdf0e10cSrcweir                     bOK = sal_True;
1032*cdf0e10cSrcweir                 }
1033*cdf0e10cSrcweir             }
1034*cdf0e10cSrcweir             catch ( Exception& )
1035*cdf0e10cSrcweir             {
1036*cdf0e10cSrcweir             }
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir             // if modify date was read successfully
1039*cdf0e10cSrcweir             if ( bOK )
1040*cdf0e10cSrcweir 			{
1041*cdf0e10cSrcweir                 // compare modify data of template with the last check date of the document
1042*cdf0e10cSrcweir                 const util::DateTime aInfoDate( xDocProps->getTemplateDate() );
1043*cdf0e10cSrcweir 				if ( aTemplDate > aInfoDate )
1044*cdf0e10cSrcweir 				{
1045*cdf0e10cSrcweir                     // ask user
1046*cdf0e10cSrcweir                 	if( bCanUpdateFromTemplate == document::UpdateDocMode::QUIET_UPDATE
1047*cdf0e10cSrcweir                 	|| bCanUpdateFromTemplate == document::UpdateDocMode::FULL_UPDATE )
1048*cdf0e10cSrcweir 						bLoad = sal_True;
1049*cdf0e10cSrcweir 					else if ( bCanUpdateFromTemplate == document::UpdateDocMode::ACCORDING_TO_CONFIG )
1050*cdf0e10cSrcweir 					{
1051*cdf0e10cSrcweir                         String sMessage( SfxResId( STR_QRYTEMPL_MESSAGE ) );
1052*cdf0e10cSrcweir                         sMessage.SearchAndReplace( String::CreateFromAscii("$(ARG1)"), aTemplName );
1053*cdf0e10cSrcweir                         sfx2::QueryTemplateBox aBox( GetDialogParent(), sMessage );
1054*cdf0e10cSrcweir 						if ( RET_YES == aBox.Execute() )
1055*cdf0e10cSrcweir 							bLoad = sal_True;
1056*cdf0e10cSrcweir 					}
1057*cdf0e10cSrcweir 
1058*cdf0e10cSrcweir 					if( !bLoad )
1059*cdf0e10cSrcweir 					{
1060*cdf0e10cSrcweir                         // user refuses, so don't ask again for this document
1061*cdf0e10cSrcweir 						SetQueryLoadTemplate(sal_False);
1062*cdf0e10cSrcweir 						SetModified( sal_True );
1063*cdf0e10cSrcweir 					}
1064*cdf0e10cSrcweir 				}
1065*cdf0e10cSrcweir 			}
1066*cdf0e10cSrcweir 
1067*cdf0e10cSrcweir 			if ( bLoad )
1068*cdf0e10cSrcweir 			{
1069*cdf0e10cSrcweir                 // styles should be updated, create document in organizer mode to read in the styles
1070*cdf0e10cSrcweir                 //TODO: testen!
1071*cdf0e10cSrcweir                 SfxObjectShellLock xTemplDoc = CreateObjectByFactoryName( GetFactory().GetFactoryName(), SFX_CREATE_MODE_ORGANIZER );
1072*cdf0e10cSrcweir 				xTemplDoc->DoInitNew(0);
1073*cdf0e10cSrcweir 
1074*cdf0e10cSrcweir                 // TODO/MBA: do we need a BaseURL? Then LoadFrom must be extended!
1075*cdf0e10cSrcweir                 //xTemplDoc->SetBaseURL( aFoundName );
1076*cdf0e10cSrcweir 
1077*cdf0e10cSrcweir                 // TODO/LATER: make sure that we don't use binary templates!
1078*cdf0e10cSrcweir                 SfxMedium aMedium( aFoundName, STREAM_STD_READ );
1079*cdf0e10cSrcweir                 if ( xTemplDoc->LoadFrom( aMedium ) )
1080*cdf0e10cSrcweir 				{
1081*cdf0e10cSrcweir                     // transfer styles from xTemplDoc to this document
1082*cdf0e10cSrcweir                     // TODO/MBA: make sure that no BaseURL is needed in *this* document
1083*cdf0e10cSrcweir 					LoadStyles(*xTemplDoc);
1084*cdf0e10cSrcweir 
1085*cdf0e10cSrcweir                     // remember date/time of check
1086*cdf0e10cSrcweir                     xDocProps->setTemplateDate(aTemplDate);
1087*cdf0e10cSrcweir                     // TODO/LATER: new functionality to store document info is required ( didn't work for SO7 XML format )
1088*cdf0e10cSrcweir //REPLACE					pInfo->Save(xDocStor);
1089*cdf0e10cSrcweir 				}
1090*cdf0e10cSrcweir 			}
1091*cdf0e10cSrcweir 		}
1092*cdf0e10cSrcweir 	}
1093*cdf0e10cSrcweir }
1094*cdf0e10cSrcweir 
1095*cdf0e10cSrcweir sal_Bool SfxObjectShell::IsHelpDocument() const
1096*cdf0e10cSrcweir {
1097*cdf0e10cSrcweir     const SfxFilter* pFilter = GetMedium()->GetFilter();
1098*cdf0e10cSrcweir     return ( pFilter && pFilter->GetFilterName().CompareToAscii("writer_web_HTML_help") == COMPARE_EQUAL );
1099*cdf0e10cSrcweir }
1100*cdf0e10cSrcweir 
1101*cdf0e10cSrcweir void SfxObjectShell::ResetFromTemplate( const String& rTemplateName, const String& rFileName )
1102*cdf0e10cSrcweir {
1103*cdf0e10cSrcweir     // only care about reseting this data for openoffice formats otherwise
1104*cdf0e10cSrcweir     if ( IsOwnStorageFormat_Impl( *GetMedium())  )
1105*cdf0e10cSrcweir     {
1106*cdf0e10cSrcweir         uno::Reference<document::XDocumentProperties> xDocProps(getDocProperties());
1107*cdf0e10cSrcweir         xDocProps->setTemplateURL( ::rtl::OUString() );
1108*cdf0e10cSrcweir         xDocProps->setTemplateName( ::rtl::OUString() );
1109*cdf0e10cSrcweir         xDocProps->setTemplateDate( util::DateTime() );
1110*cdf0e10cSrcweir         xDocProps->resetUserData( ::rtl::OUString() );
1111*cdf0e10cSrcweir 
1112*cdf0e10cSrcweir     	// TODO/REFACTOR:
1113*cdf0e10cSrcweir     	// Title?
1114*cdf0e10cSrcweir 
1115*cdf0e10cSrcweir         if( ::utl::LocalFileHelper::IsLocalFile( rFileName ) )
1116*cdf0e10cSrcweir     	{
1117*cdf0e10cSrcweir             String aFoundName;
1118*cdf0e10cSrcweir             if( SFX_APP()->Get_Impl()->GetDocumentTemplates()->GetFull( String(), rTemplateName, aFoundName ) )
1119*cdf0e10cSrcweir             {
1120*cdf0e10cSrcweir                 INetURLObject aObj( rFileName );
1121*cdf0e10cSrcweir                 xDocProps->setTemplateURL( aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
1122*cdf0e10cSrcweir                 xDocProps->setTemplateName( rTemplateName );
1123*cdf0e10cSrcweir 
1124*cdf0e10cSrcweir                 ::DateTime now;
1125*cdf0e10cSrcweir                 xDocProps->setTemplateDate( util::DateTime(
1126*cdf0e10cSrcweir                     now.Get100Sec(), now.GetSec(), now.GetMin(),
1127*cdf0e10cSrcweir                     now.GetHour(), now.GetDay(), now.GetMonth(),
1128*cdf0e10cSrcweir                     now.GetYear() ) );
1129*cdf0e10cSrcweir 
1130*cdf0e10cSrcweir     			SetQueryLoadTemplate( sal_True );
1131*cdf0e10cSrcweir             }
1132*cdf0e10cSrcweir         }
1133*cdf0e10cSrcweir     }
1134*cdf0e10cSrcweir }
1135*cdf0e10cSrcweir 
1136*cdf0e10cSrcweir sal_Bool SfxObjectShell::IsQueryLoadTemplate() const
1137*cdf0e10cSrcweir {
1138*cdf0e10cSrcweir 	return pImp->bQueryLoadTemplate;
1139*cdf0e10cSrcweir }
1140*cdf0e10cSrcweir 
1141*cdf0e10cSrcweir sal_Bool SfxObjectShell::IsUseUserData() const
1142*cdf0e10cSrcweir {
1143*cdf0e10cSrcweir 	return pImp->bUseUserData;
1144*cdf0e10cSrcweir }
1145*cdf0e10cSrcweir 
1146*cdf0e10cSrcweir void SfxObjectShell::SetQueryLoadTemplate( sal_Bool bNew )
1147*cdf0e10cSrcweir {
1148*cdf0e10cSrcweir 	if ( pImp->bQueryLoadTemplate != bNew )
1149*cdf0e10cSrcweir 		SetModified( sal_True );
1150*cdf0e10cSrcweir 	pImp->bQueryLoadTemplate = bNew;
1151*cdf0e10cSrcweir }
1152*cdf0e10cSrcweir 
1153*cdf0e10cSrcweir void SfxObjectShell::SetUseUserData( sal_Bool bNew )
1154*cdf0e10cSrcweir {
1155*cdf0e10cSrcweir 	if ( pImp->bUseUserData != bNew )
1156*cdf0e10cSrcweir 		SetModified( sal_True );
1157*cdf0e10cSrcweir 	pImp->bUseUserData = bNew;
1158*cdf0e10cSrcweir }
1159*cdf0e10cSrcweir 
1160*cdf0e10cSrcweir sal_Bool SfxObjectShell::IsLoadReadonly() const
1161*cdf0e10cSrcweir {
1162*cdf0e10cSrcweir 	return pImp->bLoadReadonly;
1163*cdf0e10cSrcweir }
1164*cdf0e10cSrcweir 
1165*cdf0e10cSrcweir sal_Bool SfxObjectShell::IsSaveVersionOnClose() const
1166*cdf0e10cSrcweir {
1167*cdf0e10cSrcweir 	return pImp->bSaveVersionOnClose;
1168*cdf0e10cSrcweir }
1169*cdf0e10cSrcweir 
1170*cdf0e10cSrcweir void SfxObjectShell::SetLoadReadonly( sal_Bool bNew )
1171*cdf0e10cSrcweir {
1172*cdf0e10cSrcweir 	if ( pImp->bLoadReadonly != bNew )
1173*cdf0e10cSrcweir 		SetModified( sal_True );
1174*cdf0e10cSrcweir 	pImp->bLoadReadonly = bNew;
1175*cdf0e10cSrcweir }
1176*cdf0e10cSrcweir 
1177*cdf0e10cSrcweir void SfxObjectShell::SetSaveVersionOnClose( sal_Bool bNew )
1178*cdf0e10cSrcweir {
1179*cdf0e10cSrcweir 	if ( pImp->bSaveVersionOnClose != bNew )
1180*cdf0e10cSrcweir 		SetModified( sal_True );
1181*cdf0e10cSrcweir 	pImp->bSaveVersionOnClose = bNew;
1182*cdf0e10cSrcweir }
1183*cdf0e10cSrcweir 
1184*cdf0e10cSrcweir sal_uInt32 SfxObjectShell::GetModifyPasswordHash() const
1185*cdf0e10cSrcweir {
1186*cdf0e10cSrcweir     return pImp->m_nModifyPasswordHash;
1187*cdf0e10cSrcweir }
1188*cdf0e10cSrcweir 
1189*cdf0e10cSrcweir sal_Bool SfxObjectShell::SetModifyPasswordHash( sal_uInt32 nHash )
1190*cdf0e10cSrcweir {
1191*cdf0e10cSrcweir     if ( ( !IsReadOnly() && !IsReadOnlyUI() )
1192*cdf0e10cSrcweir       || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) )
1193*cdf0e10cSrcweir     {
1194*cdf0e10cSrcweir         // the hash can be changed only in editable documents,
1195*cdf0e10cSrcweir         // or during loading of document
1196*cdf0e10cSrcweir         pImp->m_nModifyPasswordHash = nHash;
1197*cdf0e10cSrcweir         return sal_True;
1198*cdf0e10cSrcweir     }
1199*cdf0e10cSrcweir 
1200*cdf0e10cSrcweir     return sal_False;
1201*cdf0e10cSrcweir }
1202*cdf0e10cSrcweir 
1203*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > SfxObjectShell::GetModifyPasswordInfo() const
1204*cdf0e10cSrcweir {
1205*cdf0e10cSrcweir     return pImp->m_aModifyPasswordInfo;
1206*cdf0e10cSrcweir }
1207*cdf0e10cSrcweir 
1208*cdf0e10cSrcweir sal_Bool SfxObjectShell::SetModifyPasswordInfo( const uno::Sequence< beans::PropertyValue >& aInfo )
1209*cdf0e10cSrcweir {
1210*cdf0e10cSrcweir     if ( ( !IsReadOnly() && !IsReadOnlyUI() )
1211*cdf0e10cSrcweir       || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) )
1212*cdf0e10cSrcweir     {
1213*cdf0e10cSrcweir         // the hash can be changed only in editable documents,
1214*cdf0e10cSrcweir         // or during loading of document
1215*cdf0e10cSrcweir         pImp->m_aModifyPasswordInfo = aInfo;
1216*cdf0e10cSrcweir         return sal_True;
1217*cdf0e10cSrcweir     }
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir     return sal_False;
1220*cdf0e10cSrcweir }
1221*cdf0e10cSrcweir 
1222*cdf0e10cSrcweir void SfxObjectShell::SetModifyPasswordEntered( sal_Bool bEntered )
1223*cdf0e10cSrcweir {
1224*cdf0e10cSrcweir     pImp->m_bModifyPasswordEntered = bEntered;
1225*cdf0e10cSrcweir }
1226*cdf0e10cSrcweir 
1227*cdf0e10cSrcweir sal_Bool SfxObjectShell::IsModifyPasswordEntered()
1228*cdf0e10cSrcweir {
1229*cdf0e10cSrcweir     return pImp->m_bModifyPasswordEntered;
1230*cdf0e10cSrcweir }
1231*cdf0e10cSrcweir 
1232