xref: /aoo41x/main/sfx2/source/dialog/dinfdlg.cxx (revision c3916d03)
1d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5d119d52dSAndrew Rist  * distributed with this work for additional information
6d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10d119d52dSAndrew Rist  *
11d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12d119d52dSAndrew Rist  *
13d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17d119d52dSAndrew Rist  * specific language governing permissions and limitations
18d119d52dSAndrew Rist  * under the License.
19d119d52dSAndrew Rist  *
20d119d52dSAndrew Rist  *************************************************************/
21d119d52dSAndrew Rist 
22d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tools/urlobj.hxx>
28cdf0e10cSrcweir #include <vcl/msgbox.hxx>
29cdf0e10cSrcweir #include <svl/eitem.hxx>
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
32cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
33cdf0e10cSrcweir #include <unotools/cmdoptions.hxx>
34cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
35cdf0e10cSrcweir #include <svl/urihelper.hxx>
36cdf0e10cSrcweir #include <unotools/useroptions.hxx>
37cdf0e10cSrcweir #include <svtools/imagemgr.hxx>
38cdf0e10cSrcweir #include <tools/datetime.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <memory>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <comphelper/string.hxx>
43cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
44cdf0e10cSrcweir #include <com/sun/star/security/DocumentSignatureInformation.hpp>
45cdf0e10cSrcweir #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
46cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
47cdf0e10cSrcweir #include <unotools/syslocale.hxx>
48cdf0e10cSrcweir #include <rtl/math.hxx>
49cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
50cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
51cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyContainer.hpp>
52cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
53cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp>
54cdf0e10cSrcweir #include <com/sun/star/util/Time.hpp>
55cdf0e10cSrcweir #include <com/sun/star/util/Duration.hpp>
56cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include <vcl/timer.hxx>
59cdf0e10cSrcweir #include "sfx2/dinfdlg.hxx"
60cdf0e10cSrcweir #include "sfx2/securitypage.hxx"
61cdf0e10cSrcweir #include "sfxresid.hxx"
62cdf0e10cSrcweir #include "dinfedt.hxx"
63cdf0e10cSrcweir #include <sfx2/frame.hxx>
64cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
65cdf0e10cSrcweir #include <sfx2/request.hxx>
66cdf0e10cSrcweir //#include "exptypes.hxx"
67cdf0e10cSrcweir #include "helper.hxx"
68cdf0e10cSrcweir #include <sfx2/objsh.hxx>
69cdf0e10cSrcweir #include <sfx2/docfile.hxx>
70cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #include <sfx2/sfx.hrc>
73cdf0e10cSrcweir #include "dinfdlg.hrc"
74cdf0e10cSrcweir #include "sfxlocal.hrc"
75cdf0e10cSrcweir #include <dialog.hrc>
76cdf0e10cSrcweir #include <vcl/help.hxx>
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #include <algorithm>
79cdf0e10cSrcweir 
80cdf0e10cSrcweir using namespace ::com::sun::star;
81cdf0e10cSrcweir using namespace ::com::sun::star::lang;
82cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
83cdf0e10cSrcweir using namespace ::com::sun::star::uno;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
86cdf0e10cSrcweir struct CustomProperty
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     ::rtl::OUString             m_sName;
89cdf0e10cSrcweir     com::sun::star::uno::Any    m_aValue;
90cdf0e10cSrcweir 
CustomPropertyCustomProperty91cdf0e10cSrcweir     CustomProperty( const ::rtl::OUString& sName,
92cdf0e10cSrcweir             const com::sun::star::uno::Any& rValue ) :
93cdf0e10cSrcweir         m_sName( sName ), m_aValue( rValue ) {}
94cdf0e10cSrcweir 
operator ==CustomProperty95cdf0e10cSrcweir     inline bool operator==( const CustomProperty& rProp )
96cdf0e10cSrcweir     { return m_sName.equals( rProp.m_sName ) && m_aValue == rProp.m_aValue; }
97cdf0e10cSrcweir };
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 
100cdf0e10cSrcweir static
operator ==(const util::DateTime & i_rLeft,const util::DateTime & i_rRight)101cdf0e10cSrcweir bool operator==(const util::DateTime &i_rLeft, const util::DateTime &i_rRight)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     return i_rLeft.Year             == i_rRight.Year
104cdf0e10cSrcweir         && i_rLeft.Month            == i_rRight.Month
105cdf0e10cSrcweir         && i_rLeft.Day              == i_rRight.Day
106cdf0e10cSrcweir         && i_rLeft.Hours            == i_rRight.Hours
107cdf0e10cSrcweir         && i_rLeft.Minutes          == i_rRight.Minutes
108cdf0e10cSrcweir         && i_rLeft.Seconds          == i_rRight.Seconds
109cdf0e10cSrcweir         && i_rLeft.HundredthSeconds == i_rRight.HundredthSeconds;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
113cdf0e10cSrcweir 
114cdf0e10cSrcweir TYPEINIT1_AUTOFACTORY(SfxDocumentInfoItem, SfxStringItem);
115cdf0e10cSrcweir 
116cdf0e10cSrcweir const sal_uInt16 HI_NAME = 1;
117cdf0e10cSrcweir const sal_uInt16 HI_TYPE = 2;
118cdf0e10cSrcweir const sal_uInt16 HI_VALUE = 3;
119cdf0e10cSrcweir const sal_uInt16 HI_ACTION = 4;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir static const char DOCUMENT_SIGNATURE_MENU_CMD[]      = "Signature";
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //------------------------------------------------------------------------
124cdf0e10cSrcweir String CreateSizeText( sal_uIntPtr nSize, sal_Bool bExtraBytes = sal_True, sal_Bool bSmartExtraBytes = sal_False );
CreateSizeText(sal_uIntPtr nSize,sal_Bool bExtraBytes,sal_Bool bSmartExtraBytes)125cdf0e10cSrcweir String CreateSizeText( sal_uIntPtr nSize, sal_Bool bExtraBytes, sal_Bool bSmartExtraBytes )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	String aUnitStr = ' ';
128cdf0e10cSrcweir 	aUnitStr += String( SfxResId(STR_BYTES) );
129cdf0e10cSrcweir 	sal_uIntPtr nSize1 = nSize;
130cdf0e10cSrcweir 	sal_uIntPtr nSize2 = nSize1;
131cdf0e10cSrcweir 	sal_uIntPtr nMega = 1024 * 1024;
132cdf0e10cSrcweir 	sal_uIntPtr nGiga = nMega * 1024;
133cdf0e10cSrcweir 	double fSize = nSize;
134cdf0e10cSrcweir 	int nDec = 0;
135cdf0e10cSrcweir 	sal_Bool bGB = sal_False;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	if ( nSize1 >= 10000 && nSize1 < nMega )
138cdf0e10cSrcweir 	{
139cdf0e10cSrcweir 		nSize1 /= 1024;
140cdf0e10cSrcweir 		aUnitStr = ' ';
141cdf0e10cSrcweir 		aUnitStr += String( SfxResId(STR_KB) );
142cdf0e10cSrcweir 		fSize /= 1024;
143cdf0e10cSrcweir 		nDec = 0;
144cdf0e10cSrcweir 	}
145cdf0e10cSrcweir 	else if ( nSize1 >= nMega && nSize1 < nGiga )
146cdf0e10cSrcweir 	{
147cdf0e10cSrcweir 		nSize1 /= nMega;
148cdf0e10cSrcweir 		aUnitStr = ' ';
149cdf0e10cSrcweir 		aUnitStr += String( SfxResId(STR_MB) );
150cdf0e10cSrcweir 		fSize /= nMega;
151cdf0e10cSrcweir 		nDec = 2;
152cdf0e10cSrcweir 	}
153cdf0e10cSrcweir 	else if ( nSize1 >= nGiga )
154cdf0e10cSrcweir 	{
155cdf0e10cSrcweir 		nSize1 /= nGiga;
156cdf0e10cSrcweir 		aUnitStr = ' ';
157cdf0e10cSrcweir 		aUnitStr += String( SfxResId(STR_GB) );
158cdf0e10cSrcweir 		bGB = sal_True;
159cdf0e10cSrcweir 		fSize /= nGiga;
160cdf0e10cSrcweir 		nDec = 3;
161cdf0e10cSrcweir 	}
162cf3a8bfbSPedro Giffuni     const SvtSysLocale aSysLocale;
163cf3a8bfbSPedro Giffuni 	const LocaleDataWrapper& rLocaleWrapper = aSysLocale.GetLocaleData();
164cdf0e10cSrcweir 	String aSizeStr( rLocaleWrapper.getNum( nSize1, 0 ) );
165cdf0e10cSrcweir 	aSizeStr += aUnitStr;
166cdf0e10cSrcweir 	if ( bExtraBytes && ( nSize1 < nSize2 ) )
167cdf0e10cSrcweir 	{
168cdf0e10cSrcweir         aSizeStr = ::rtl::math::doubleToUString( fSize,
169cdf0e10cSrcweir                 rtl_math_StringFormat_F, nDec,
170cdf0e10cSrcweir                 rLocaleWrapper.getNumDecimalSep().GetChar(0) );
171cdf0e10cSrcweir 		aSizeStr += aUnitStr;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 		aSizeStr += DEFINE_CONST_UNICODE(" (");
174cdf0e10cSrcweir 		aSizeStr += rLocaleWrapper.getNum( nSize2, 0 );
175cdf0e10cSrcweir 		aSizeStr += ' ';
176cdf0e10cSrcweir 		aSizeStr += String( SfxResId(STR_BYTES) );
177cdf0e10cSrcweir 		aSizeStr += ')';
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir 	else if ( bGB && bSmartExtraBytes )
180cdf0e10cSrcweir 	{
181cdf0e10cSrcweir 		nSize1 = nSize / nMega;
182cdf0e10cSrcweir 		aSizeStr = DEFINE_CONST_UNICODE(" (");
183cdf0e10cSrcweir 		aSizeStr += rLocaleWrapper.getNum( nSize1, 0 );
184cdf0e10cSrcweir 		aSizeStr += aUnitStr;
185cdf0e10cSrcweir 		aSizeStr += ')';
186cdf0e10cSrcweir 	}
187cdf0e10cSrcweir 	return aSizeStr;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
ConvertDateTime_Impl(const String & rName,const util::DateTime & uDT,const LocaleDataWrapper & rWrapper)190cdf0e10cSrcweir String ConvertDateTime_Impl( const String& rName,
191cdf0e10cSrcweir     const util::DateTime& uDT, const LocaleDataWrapper& rWrapper )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     Date aD(uDT.Day, uDT.Month, uDT.Year);
194cdf0e10cSrcweir     Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
195cdf0e10cSrcweir 	 const String pDelim ( DEFINE_CONST_UNICODE( ", "));
196cdf0e10cSrcweir 	 String aStr( rWrapper.getDate( aD ) );
197cdf0e10cSrcweir 	 aStr += pDelim;
198cdf0e10cSrcweir 	 aStr += rWrapper.getTime( aT, sal_True, sal_False );
199cdf0e10cSrcweir 	 String aAuthor = rName;
200cdf0e10cSrcweir 	 aAuthor.EraseLeadingChars();
201cdf0e10cSrcweir 	 if ( aAuthor.Len() )
202cdf0e10cSrcweir 	 {
203cdf0e10cSrcweir 		aStr += pDelim;
204cdf0e10cSrcweir 		aStr += aAuthor;
205cdf0e10cSrcweir 	 }
206cdf0e10cSrcweir 	 return aStr;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir //------------------------------------------------------------------------
210cdf0e10cSrcweir 
SfxDocumentInfoItem()211cdf0e10cSrcweir SfxDocumentInfoItem::SfxDocumentInfoItem()
212cdf0e10cSrcweir 	: SfxStringItem()
213cdf0e10cSrcweir     , m_AutoloadDelay(0)
214cdf0e10cSrcweir     , m_AutoloadURL()
215cdf0e10cSrcweir     , m_isAutoloadEnabled(sal_False)
216cdf0e10cSrcweir     , m_DefaultTarget()
217cdf0e10cSrcweir     , m_TemplateName()
218cdf0e10cSrcweir     , m_Author()
219cdf0e10cSrcweir     , m_CreationDate()
220cdf0e10cSrcweir     , m_ModifiedBy()
221cdf0e10cSrcweir     , m_ModificationDate()
222cdf0e10cSrcweir     , m_PrintedBy()
223cdf0e10cSrcweir     , m_PrintDate()
224cdf0e10cSrcweir     , m_EditingCycles(0)
225cdf0e10cSrcweir     , m_EditingDuration(0)
226cdf0e10cSrcweir     , m_Description()
227cdf0e10cSrcweir     , m_Keywords()
228cdf0e10cSrcweir     , m_Subject()
229cdf0e10cSrcweir     , m_Title()
230cdf0e10cSrcweir     , m_bHasTemplate( sal_True )
231cdf0e10cSrcweir     , m_bDeleteUserData( sal_False )
232cdf0e10cSrcweir     , m_bUseUserData( sal_True )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir //------------------------------------------------------------------------
237cdf0e10cSrcweir 
SfxDocumentInfoItem(const String & rFile,const uno::Reference<document::XDocumentProperties> & i_xDocProps,sal_Bool bIs)238cdf0e10cSrcweir SfxDocumentInfoItem::SfxDocumentInfoItem( const String& rFile,
239cdf0e10cSrcweir         const uno::Reference<document::XDocumentProperties>& i_xDocProps,
240cdf0e10cSrcweir         sal_Bool bIs )
241cdf0e10cSrcweir 	: SfxStringItem( SID_DOCINFO, rFile )
242cdf0e10cSrcweir     , m_AutoloadDelay( i_xDocProps->getAutoloadSecs() )
243cdf0e10cSrcweir     , m_AutoloadURL( i_xDocProps->getAutoloadURL() )
244cdf0e10cSrcweir     , m_isAutoloadEnabled( (m_AutoloadDelay > 0) || m_AutoloadURL.getLength() )
245cdf0e10cSrcweir     , m_DefaultTarget( i_xDocProps->getDefaultTarget() )
246cdf0e10cSrcweir     , m_TemplateName( i_xDocProps->getTemplateName() )
247cdf0e10cSrcweir     , m_Author( i_xDocProps->getAuthor() )
248cdf0e10cSrcweir     , m_CreationDate( i_xDocProps->getCreationDate() )
249cdf0e10cSrcweir     , m_ModifiedBy( i_xDocProps->getModifiedBy() )
250cdf0e10cSrcweir     , m_ModificationDate( i_xDocProps->getModificationDate() )
251cdf0e10cSrcweir     , m_PrintedBy( i_xDocProps->getPrintedBy() )
252cdf0e10cSrcweir     , m_PrintDate( i_xDocProps->getPrintDate() )
253cdf0e10cSrcweir     , m_EditingCycles( i_xDocProps->getEditingCycles() )
254cdf0e10cSrcweir     , m_EditingDuration( i_xDocProps->getEditingDuration() )
255cdf0e10cSrcweir     , m_Description( i_xDocProps->getDescription() )
256cdf0e10cSrcweir     , m_Keywords( ::comphelper::string::convertCommaSeparated(
257cdf0e10cSrcweir                     i_xDocProps->getKeywords()) )
258cdf0e10cSrcweir     , m_Subject( i_xDocProps->getSubject() )
259cdf0e10cSrcweir     , m_Title( i_xDocProps->getTitle() )
260cdf0e10cSrcweir     , m_bHasTemplate( sal_True )
261cdf0e10cSrcweir     , m_bDeleteUserData( sal_False )
262cdf0e10cSrcweir     , m_bUseUserData( bIs )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir     try
265cdf0e10cSrcweir     {
266cdf0e10cSrcweir         Reference< beans::XPropertyContainer > xContainer = i_xDocProps->getUserDefinedProperties();
267cdf0e10cSrcweir         if ( xContainer.is() )
268cdf0e10cSrcweir         {
269cdf0e10cSrcweir             Reference < beans::XPropertySet > xSet( xContainer, UNO_QUERY );
270cdf0e10cSrcweir             const Sequence< beans::Property > lProps = xSet->getPropertySetInfo()->getProperties();
271cdf0e10cSrcweir             const beans::Property* pProps = lProps.getConstArray();
272cdf0e10cSrcweir             sal_Int32 nCount = lProps.getLength();
273cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < nCount; ++i )
274cdf0e10cSrcweir             {
275cdf0e10cSrcweir                 // "fix" property? => not a custom property => ignore it!
276cdf0e10cSrcweir                 if (!(pProps[i].Attributes &
277cdf0e10cSrcweir                         ::com::sun::star::beans::PropertyAttribute::REMOVABLE))
278cdf0e10cSrcweir                 {
279cdf0e10cSrcweir                     DBG_ASSERT(false, "non-removable user-defined property?");
280cdf0e10cSrcweir                     continue;
281cdf0e10cSrcweir                 }
282cdf0e10cSrcweir 
283cdf0e10cSrcweir                 uno::Any aValue = xSet->getPropertyValue(pProps[i].Name);
284cdf0e10cSrcweir                 CustomProperty* pProp = new CustomProperty( pProps[i].Name, aValue );
285cdf0e10cSrcweir                 m_aCustomProperties.push_back( pProp );
286cdf0e10cSrcweir             }
287cdf0e10cSrcweir         }
288cdf0e10cSrcweir     }
289cdf0e10cSrcweir     catch ( Exception& ) {}
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir //------------------------------------------------------------------------
293cdf0e10cSrcweir 
SfxDocumentInfoItem(const SfxDocumentInfoItem & rItem)294cdf0e10cSrcweir SfxDocumentInfoItem::SfxDocumentInfoItem( const SfxDocumentInfoItem& rItem )
295cdf0e10cSrcweir 	: SfxStringItem( rItem )
296cdf0e10cSrcweir     , m_AutoloadDelay( rItem.getAutoloadDelay() )
297cdf0e10cSrcweir     , m_AutoloadURL( rItem.getAutoloadURL() )
298cdf0e10cSrcweir     , m_isAutoloadEnabled( rItem.isAutoloadEnabled() )
299cdf0e10cSrcweir     , m_DefaultTarget( rItem.getDefaultTarget() )
300cdf0e10cSrcweir     , m_TemplateName( rItem.getTemplateName() )
301cdf0e10cSrcweir     , m_Author( rItem.getAuthor() )
302cdf0e10cSrcweir     , m_CreationDate( rItem.getCreationDate() )
303cdf0e10cSrcweir     , m_ModifiedBy( rItem.getModifiedBy() )
304cdf0e10cSrcweir     , m_ModificationDate( rItem.getModificationDate() )
305cdf0e10cSrcweir     , m_PrintedBy( rItem.getPrintedBy() )
306cdf0e10cSrcweir     , m_PrintDate( rItem.getPrintDate() )
307cdf0e10cSrcweir     , m_EditingCycles( rItem.getEditingCycles() )
308cdf0e10cSrcweir     , m_EditingDuration( rItem.getEditingDuration() )
309cdf0e10cSrcweir     , m_Description( rItem.getDescription() )
310cdf0e10cSrcweir     , m_Keywords( rItem.getKeywords() )
311cdf0e10cSrcweir     , m_Subject( rItem.getSubject() )
312cdf0e10cSrcweir     , m_Title( rItem.getTitle() )
313cdf0e10cSrcweir     , m_bHasTemplate( rItem.m_bHasTemplate )
314cdf0e10cSrcweir     , m_bDeleteUserData( rItem.m_bDeleteUserData )
315cdf0e10cSrcweir     , m_bUseUserData( rItem.m_bUseUserData )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir     for ( sal_uInt32 i = 0; i < rItem.m_aCustomProperties.size(); i++ )
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir         CustomProperty* pProp = new CustomProperty( rItem.m_aCustomProperties[i]->m_sName,
320cdf0e10cSrcweir                                                     rItem.m_aCustomProperties[i]->m_aValue );
321cdf0e10cSrcweir         m_aCustomProperties.push_back( pProp );
322cdf0e10cSrcweir     }
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir //------------------------------------------------------------------------
326cdf0e10cSrcweir 
~SfxDocumentInfoItem()327cdf0e10cSrcweir SfxDocumentInfoItem::~SfxDocumentInfoItem()
328cdf0e10cSrcweir {
329cdf0e10cSrcweir     ClearCustomProperties();
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir //------------------------------------------------------------------------
333cdf0e10cSrcweir 
Clone(SfxItemPool *) const334cdf0e10cSrcweir SfxPoolItem* SfxDocumentInfoItem::Clone( SfxItemPool * ) const
335cdf0e10cSrcweir {
336cdf0e10cSrcweir 	return new SfxDocumentInfoItem( *this );
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir //------------------------------------------------------------------------
340cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rItem) const341cdf0e10cSrcweir int SfxDocumentInfoItem::operator==( const SfxPoolItem& rItem) const
342cdf0e10cSrcweir {
343cdf0e10cSrcweir 	if (!(rItem.Type() == Type() && SfxStringItem::operator==(rItem))) {
344cdf0e10cSrcweir         return false;
345cdf0e10cSrcweir     }
346cdf0e10cSrcweir     const SfxDocumentInfoItem& rInfoItem(
347cdf0e10cSrcweir         static_cast<const SfxDocumentInfoItem&>(rItem));
348cdf0e10cSrcweir 
349cdf0e10cSrcweir     return
350cdf0e10cSrcweir          m_AutoloadDelay        == rInfoItem.m_AutoloadDelay     &&
351cdf0e10cSrcweir          m_AutoloadURL          == rInfoItem.m_AutoloadURL       &&
352cdf0e10cSrcweir          m_isAutoloadEnabled    == rInfoItem.m_isAutoloadEnabled &&
353cdf0e10cSrcweir          m_DefaultTarget        == rInfoItem.m_DefaultTarget     &&
354cdf0e10cSrcweir          m_Author               == rInfoItem.m_Author            &&
355cdf0e10cSrcweir          m_CreationDate         == rInfoItem.m_CreationDate      &&
356cdf0e10cSrcweir          m_ModifiedBy           == rInfoItem.m_ModifiedBy        &&
357cdf0e10cSrcweir          m_ModificationDate     == rInfoItem.m_ModificationDate  &&
358cdf0e10cSrcweir          m_PrintedBy            == rInfoItem.m_PrintedBy         &&
359cdf0e10cSrcweir          m_PrintDate            == rInfoItem.m_PrintDate         &&
360cdf0e10cSrcweir          m_EditingCycles        == rInfoItem.m_EditingCycles     &&
361cdf0e10cSrcweir          m_EditingDuration      == rInfoItem.m_EditingDuration   &&
362cdf0e10cSrcweir          m_Description          == rInfoItem.m_Description       &&
363cdf0e10cSrcweir          m_Keywords             == rInfoItem.m_Keywords          &&
364cdf0e10cSrcweir          m_Subject              == rInfoItem.m_Subject           &&
365cdf0e10cSrcweir          m_Title                == rInfoItem.m_Title             &&
366cdf0e10cSrcweir          m_aCustomProperties.size() == rInfoItem.m_aCustomProperties.size() &&
367cdf0e10cSrcweir          std::equal(m_aCustomProperties.begin(), m_aCustomProperties.end(),
368cdf0e10cSrcweir             rInfoItem.m_aCustomProperties.begin());
369cdf0e10cSrcweir }
370cdf0e10cSrcweir 
371cdf0e10cSrcweir //------------------------------------------------------------------------
372cdf0e10cSrcweir 
resetUserData(const::rtl::OUString & i_rAuthor)373cdf0e10cSrcweir void SfxDocumentInfoItem::resetUserData(const ::rtl::OUString & i_rAuthor)
374cdf0e10cSrcweir {
375cdf0e10cSrcweir     setAuthor(i_rAuthor);
376cdf0e10cSrcweir     DateTime now;
377cdf0e10cSrcweir     setCreationDate( util::DateTime(
378cdf0e10cSrcweir         now.Get100Sec(), now.GetSec(), now.GetMin(), now.GetHour(),
379cdf0e10cSrcweir         now.GetDay(), now.GetMonth(), now.GetYear() ) );
380cdf0e10cSrcweir     setModifiedBy(::rtl::OUString());
381cdf0e10cSrcweir     setPrintedBy(::rtl::OUString());
382cdf0e10cSrcweir     setModificationDate(util::DateTime());
383cdf0e10cSrcweir     setPrintDate(util::DateTime());
384cdf0e10cSrcweir     setEditingDuration(0);
385cdf0e10cSrcweir     setEditingCycles(1);
386cdf0e10cSrcweir }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir //------------------------------------------------------------------------
389cdf0e10cSrcweir 
UpdateDocumentInfo(const uno::Reference<document::XDocumentProperties> & i_xDocProps,bool i_bDoNotUpdateUserDefined) const390cdf0e10cSrcweir void SfxDocumentInfoItem::UpdateDocumentInfo(
391cdf0e10cSrcweir         const uno::Reference<document::XDocumentProperties>& i_xDocProps,
392cdf0e10cSrcweir         bool i_bDoNotUpdateUserDefined) const
393cdf0e10cSrcweir {
394cdf0e10cSrcweir     if (isAutoloadEnabled()) {
395cdf0e10cSrcweir         i_xDocProps->setAutoloadSecs(getAutoloadDelay());
396cdf0e10cSrcweir         i_xDocProps->setAutoloadURL(getAutoloadURL());
397cdf0e10cSrcweir     } else {
398cdf0e10cSrcweir         i_xDocProps->setAutoloadSecs(0);
399cdf0e10cSrcweir         i_xDocProps->setAutoloadURL(::rtl::OUString());
400cdf0e10cSrcweir     }
401cdf0e10cSrcweir     i_xDocProps->setDefaultTarget(getDefaultTarget());
402cdf0e10cSrcweir //    i_xDocProps->setTemplateName(getTemplateName());
403cdf0e10cSrcweir     i_xDocProps->setAuthor(getAuthor());
404cdf0e10cSrcweir     i_xDocProps->setCreationDate(getCreationDate());
405cdf0e10cSrcweir     i_xDocProps->setModifiedBy(getModifiedBy());
406cdf0e10cSrcweir     i_xDocProps->setModificationDate(getModificationDate());
407cdf0e10cSrcweir     i_xDocProps->setPrintedBy(getPrintedBy());
408cdf0e10cSrcweir     i_xDocProps->setPrintDate(getPrintDate());
409cdf0e10cSrcweir     i_xDocProps->setEditingCycles(getEditingCycles());
410cdf0e10cSrcweir     i_xDocProps->setEditingDuration(getEditingDuration());
411cdf0e10cSrcweir     i_xDocProps->setDescription(getDescription());
412cdf0e10cSrcweir     i_xDocProps->setKeywords(
413cdf0e10cSrcweir         ::comphelper::string::convertCommaSeparated(getKeywords()));
414cdf0e10cSrcweir     i_xDocProps->setSubject(getSubject());
415cdf0e10cSrcweir     i_xDocProps->setTitle(getTitle());
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     // this is necessary in case of replaying a recorded macro:
418cdf0e10cSrcweir     // in this case, the macro may contain the 4 old user-defined DocumentInfo
419cdf0e10cSrcweir     // fields, but not any of the DocumentInfo properties;
420cdf0e10cSrcweir     // as a consequence, most of the UserDefined properties of the
421cdf0e10cSrcweir     // DocumentProperties would be summarily deleted here, which does not
422cdf0e10cSrcweir     // seem like a good idea.
423cdf0e10cSrcweir     if (i_bDoNotUpdateUserDefined)
424cdf0e10cSrcweir         return;
425cdf0e10cSrcweir 
426cdf0e10cSrcweir     try
427cdf0e10cSrcweir     {
428cdf0e10cSrcweir         Reference< beans::XPropertyContainer > xContainer = i_xDocProps->getUserDefinedProperties();
429cdf0e10cSrcweir         Reference < beans::XPropertySet > xSet( xContainer, UNO_QUERY );
430cdf0e10cSrcweir         Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
431cdf0e10cSrcweir         const Sequence< beans::Property > lProps = xSetInfo->getProperties();
432cdf0e10cSrcweir         const beans::Property* pProps = lProps.getConstArray();
433cdf0e10cSrcweir         sal_Int32 nCount = lProps.getLength();
434cdf0e10cSrcweir         for ( sal_Int32 j = 0; j < nCount; ++j )
435cdf0e10cSrcweir         {
436cdf0e10cSrcweir             if ((pProps[j].Attributes &
437cdf0e10cSrcweir                     ::com::sun::star::beans::PropertyAttribute::REMOVABLE))
438cdf0e10cSrcweir             {
439cdf0e10cSrcweir                 xContainer->removeProperty( pProps[j].Name );
440cdf0e10cSrcweir             }
441cdf0e10cSrcweir         }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir         for ( sal_uInt32 k = 0; k < m_aCustomProperties.size(); ++k )
444cdf0e10cSrcweir         {
445cdf0e10cSrcweir             try
446cdf0e10cSrcweir             {
447cdf0e10cSrcweir                 xContainer->addProperty( m_aCustomProperties[k]->m_sName,
448cdf0e10cSrcweir                     beans::PropertyAttribute::REMOVABLE, m_aCustomProperties[k]->m_aValue );
449cdf0e10cSrcweir             }
450cdf0e10cSrcweir             catch ( Exception& )
451cdf0e10cSrcweir             {
452cdf0e10cSrcweir                 DBG_ERRORFILE( "SfxDocumentInfoItem::updateDocumentInfo(): exception while adding custom properties" );
453cdf0e10cSrcweir             }
454cdf0e10cSrcweir         }
455cdf0e10cSrcweir     }
456cdf0e10cSrcweir     catch ( Exception& )
457cdf0e10cSrcweir     {
458cdf0e10cSrcweir         DBG_ERRORFILE( "SfxDocumentInfoItem::updateDocumentInfo(): exception while removing custom properties" );
459cdf0e10cSrcweir     }
460cdf0e10cSrcweir }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir //------------------------------------------------------------------------
463cdf0e10cSrcweir 
IsDeleteUserData() const464cdf0e10cSrcweir sal_Bool SfxDocumentInfoItem::IsDeleteUserData() const
465cdf0e10cSrcweir {
466cdf0e10cSrcweir     return m_bDeleteUserData;
467cdf0e10cSrcweir }
468cdf0e10cSrcweir 
SetDeleteUserData(sal_Bool bSet)469cdf0e10cSrcweir void SfxDocumentInfoItem::SetDeleteUserData( sal_Bool bSet )
470cdf0e10cSrcweir {
471cdf0e10cSrcweir     m_bDeleteUserData = bSet;
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
IsUseUserData() const474cdf0e10cSrcweir sal_Bool SfxDocumentInfoItem::IsUseUserData() const
475cdf0e10cSrcweir {
476cdf0e10cSrcweir     return m_bUseUserData;
477cdf0e10cSrcweir }
478cdf0e10cSrcweir 
SetUseUserData(sal_Bool bSet)479cdf0e10cSrcweir void SfxDocumentInfoItem::SetUseUserData( sal_Bool bSet )
480cdf0e10cSrcweir {
481cdf0e10cSrcweir     m_bUseUserData = bSet;
482cdf0e10cSrcweir }
483cdf0e10cSrcweir 
GetCustomProperties() const484cdf0e10cSrcweir std::vector< CustomProperty* > SfxDocumentInfoItem::GetCustomProperties() const
485cdf0e10cSrcweir {
486cdf0e10cSrcweir     std::vector< CustomProperty* > aRet;
487cdf0e10cSrcweir     for ( sal_uInt32 i = 0; i < m_aCustomProperties.size(); i++ )
488cdf0e10cSrcweir     {
489cdf0e10cSrcweir         CustomProperty* pProp = new CustomProperty( m_aCustomProperties[i]->m_sName,
490cdf0e10cSrcweir                                                     m_aCustomProperties[i]->m_aValue );
491cdf0e10cSrcweir         aRet.push_back( pProp );
492cdf0e10cSrcweir     }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir     return aRet;
495cdf0e10cSrcweir }
496cdf0e10cSrcweir 
ClearCustomProperties()497cdf0e10cSrcweir void SfxDocumentInfoItem::ClearCustomProperties()
498cdf0e10cSrcweir {
499cdf0e10cSrcweir     for ( sal_uInt32 i = 0; i < m_aCustomProperties.size(); i++ )
500cdf0e10cSrcweir         delete m_aCustomProperties[i];
501cdf0e10cSrcweir     m_aCustomProperties.clear();
502cdf0e10cSrcweir }
503cdf0e10cSrcweir 
AddCustomProperty(const::rtl::OUString & sName,const Any & rValue)504cdf0e10cSrcweir void SfxDocumentInfoItem::AddCustomProperty( const ::rtl::OUString& sName, const Any& rValue )
505cdf0e10cSrcweir {
506cdf0e10cSrcweir     CustomProperty* pProp = new CustomProperty( sName, rValue );
507cdf0e10cSrcweir     m_aCustomProperties.push_back( pProp );
508cdf0e10cSrcweir }
509cdf0e10cSrcweir 
QueryValue(Any & rVal,sal_uInt8 nMemberId) const510cdf0e10cSrcweir sal_Bool SfxDocumentInfoItem::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
511cdf0e10cSrcweir {
512cdf0e10cSrcweir     String aValue;
513cdf0e10cSrcweir     sal_Int32 nValue = 0;
514cdf0e10cSrcweir 	sal_Bool bValue = sal_False;
515cdf0e10cSrcweir     sal_Bool bIsInt = sal_False;
516cdf0e10cSrcweir     sal_Bool bIsString = sal_False;
517cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
518cdf0e10cSrcweir     switch ( nMemberId )
519cdf0e10cSrcweir     {
520cdf0e10cSrcweir 		case MID_DOCINFO_USEUSERDATA:
521cdf0e10cSrcweir 			bValue = IsUseUserData();
522cdf0e10cSrcweir 			break;
523cdf0e10cSrcweir 		case MID_DOCINFO_DELETEUSERDATA:
524cdf0e10cSrcweir 			bValue = IsDeleteUserData();
525cdf0e10cSrcweir 			break;
526cdf0e10cSrcweir 		case MID_DOCINFO_AUTOLOADENABLED:
527cdf0e10cSrcweir 			bValue = isAutoloadEnabled();
528cdf0e10cSrcweir 			break;
529cdf0e10cSrcweir 		case MID_DOCINFO_AUTOLOADSECS:
530cdf0e10cSrcweir 			bIsInt = sal_True;
531cdf0e10cSrcweir 			nValue = getAutoloadDelay();
532cdf0e10cSrcweir 			break;
533cdf0e10cSrcweir 		case MID_DOCINFO_AUTOLOADURL:
534cdf0e10cSrcweir 			bIsString = sal_True;
535cdf0e10cSrcweir 			aValue = getAutoloadURL();
536cdf0e10cSrcweir 			break;
537cdf0e10cSrcweir 		case MID_DOCINFO_DEFAULTTARGET:
538cdf0e10cSrcweir 			bIsString = sal_True;
539cdf0e10cSrcweir 			aValue = getDefaultTarget();
540cdf0e10cSrcweir 			break;
541cdf0e10cSrcweir         case MID_DOCINFO_DESCRIPTION:
542cdf0e10cSrcweir 			bIsString = sal_True;
543cdf0e10cSrcweir             aValue = getDescription();
544cdf0e10cSrcweir             break;
545cdf0e10cSrcweir         case MID_DOCINFO_KEYWORDS:
546cdf0e10cSrcweir 			bIsString = sal_True;
547cdf0e10cSrcweir             aValue = getKeywords();
548cdf0e10cSrcweir             break;
549cdf0e10cSrcweir         case MID_DOCINFO_SUBJECT:
550cdf0e10cSrcweir 			bIsString = sal_True;
551cdf0e10cSrcweir             aValue = getSubject();
552cdf0e10cSrcweir             break;
553cdf0e10cSrcweir         case MID_DOCINFO_TITLE:
554cdf0e10cSrcweir 			bIsString = sal_True;
555cdf0e10cSrcweir             aValue = getTitle();
556cdf0e10cSrcweir             break;
557cdf0e10cSrcweir         default:
558cdf0e10cSrcweir 			DBG_ERROR("Wrong MemberId!");
559cdf0e10cSrcweir             return sal_False;
560cdf0e10cSrcweir 	 }
561cdf0e10cSrcweir 
562cdf0e10cSrcweir 	if ( bIsString )
563cdf0e10cSrcweir 		rVal <<= ::rtl::OUString( aValue );
564cdf0e10cSrcweir 	else if ( bIsInt )
565cdf0e10cSrcweir 		rVal <<= nValue;
566cdf0e10cSrcweir 	else
567cdf0e10cSrcweir 		rVal <<= bValue;
568cdf0e10cSrcweir     return sal_True;
569cdf0e10cSrcweir }
570cdf0e10cSrcweir 
PutValue(const Any & rVal,sal_uInt8 nMemberId)571cdf0e10cSrcweir sal_Bool SfxDocumentInfoItem::PutValue( const Any& rVal, sal_uInt8 nMemberId )
572cdf0e10cSrcweir {
573cdf0e10cSrcweir     ::rtl::OUString aValue;
574cdf0e10cSrcweir     sal_Int32 nValue=0;
575cdf0e10cSrcweir 	sal_Bool bValue = sal_False;
576cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
577cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
578cdf0e10cSrcweir     switch ( nMemberId )
579cdf0e10cSrcweir     {
580cdf0e10cSrcweir 		case MID_DOCINFO_USEUSERDATA:
581cdf0e10cSrcweir 			bRet = (rVal >>= bValue);
582cdf0e10cSrcweir 			if ( bRet )
583cdf0e10cSrcweir 				SetUseUserData( bValue );
584cdf0e10cSrcweir 			break;
585cdf0e10cSrcweir 		case MID_DOCINFO_DELETEUSERDATA:
586cdf0e10cSrcweir 			// QUESTION: deleting user data was done here; seems to be superfluous!
587cdf0e10cSrcweir 			bRet = (rVal >>= bValue);
588cdf0e10cSrcweir 			if ( bRet )
589cdf0e10cSrcweir 				SetDeleteUserData( bValue );
590cdf0e10cSrcweir 			break;
591cdf0e10cSrcweir 		case MID_DOCINFO_AUTOLOADENABLED:
592cdf0e10cSrcweir 			bRet = (rVal >>= bValue);
593cdf0e10cSrcweir 			if ( bRet )
594cdf0e10cSrcweir 				setAutoloadEnabled(bValue);
595cdf0e10cSrcweir 			break;
596cdf0e10cSrcweir 		case MID_DOCINFO_AUTOLOADSECS:
597cdf0e10cSrcweir 			bRet = (rVal >>= nValue);
598cdf0e10cSrcweir 			if ( bRet )
599cdf0e10cSrcweir 				setAutoloadDelay(nValue);
600cdf0e10cSrcweir 			break;
601cdf0e10cSrcweir 		case MID_DOCINFO_AUTOLOADURL:
602cdf0e10cSrcweir 			bRet = (rVal >>= aValue);
603cdf0e10cSrcweir 			if ( bRet )
604cdf0e10cSrcweir 				setAutoloadURL(aValue);
605cdf0e10cSrcweir 			break;
606cdf0e10cSrcweir 		case MID_DOCINFO_DEFAULTTARGET:
607cdf0e10cSrcweir 			bRet = (rVal >>= aValue);
608cdf0e10cSrcweir 			if ( bRet )
609cdf0e10cSrcweir 				setDefaultTarget(aValue);
610cdf0e10cSrcweir 			break;
611cdf0e10cSrcweir         case MID_DOCINFO_DESCRIPTION:
612cdf0e10cSrcweir 			bRet = (rVal >>= aValue);
613cdf0e10cSrcweir 			if ( bRet )
614cdf0e10cSrcweir                 setDescription(aValue);
615cdf0e10cSrcweir             break;
616cdf0e10cSrcweir         case MID_DOCINFO_KEYWORDS:
617cdf0e10cSrcweir 			bRet = (rVal >>= aValue);
618cdf0e10cSrcweir 			if ( bRet )
619cdf0e10cSrcweir                 setKeywords(aValue);
620cdf0e10cSrcweir             break;
621cdf0e10cSrcweir         case MID_DOCINFO_SUBJECT:
622cdf0e10cSrcweir 			bRet = (rVal >>= aValue);
623cdf0e10cSrcweir 			if ( bRet )
624cdf0e10cSrcweir                 setSubject(aValue);
625cdf0e10cSrcweir             break;
626cdf0e10cSrcweir         case MID_DOCINFO_TITLE:
627cdf0e10cSrcweir 			bRet = (rVal >>= aValue);
628cdf0e10cSrcweir 			if ( bRet )
629cdf0e10cSrcweir                 setTitle(aValue);
630cdf0e10cSrcweir             break;
631cdf0e10cSrcweir         default:
632cdf0e10cSrcweir 			DBG_ERROR("Wrong MemberId!");
633cdf0e10cSrcweir             return sal_False;
634cdf0e10cSrcweir     }
635cdf0e10cSrcweir 
636cdf0e10cSrcweir     return bRet;
637cdf0e10cSrcweir }
638cdf0e10cSrcweir 
639cdf0e10cSrcweir //------------------------------------------------------------------------
640cdf0e10cSrcweir 
SfxDocumentDescPage(Window * pParent,const SfxItemSet & rItemSet)641cdf0e10cSrcweir SfxDocumentDescPage::SfxDocumentDescPage( Window * pParent, const SfxItemSet& rItemSet )  :
642cdf0e10cSrcweir 
643cdf0e10cSrcweir     SfxTabPage( pParent, SfxResId( TP_DOCINFODESC ), rItemSet ),
644cdf0e10cSrcweir 
645cdf0e10cSrcweir     aTitleFt    ( this, SfxResId( FT_TITLE ) ),
646cdf0e10cSrcweir     aTitleEd    ( this, SfxResId( ED_TITLE ) ),
647cdf0e10cSrcweir     aThemaFt    ( this, SfxResId( FT_THEMA ) ),
648cdf0e10cSrcweir     aThemaEd    ( this, SfxResId( ED_THEMA ) ),
649cdf0e10cSrcweir     aKeywordsFt ( this, SfxResId( FT_KEYWORDS ) ),
650cdf0e10cSrcweir     aKeywordsEd ( this, SfxResId( ED_KEYWORDS ) ),
651cdf0e10cSrcweir     aCommentFt  ( this, SfxResId( FT_COMMENT ) ),
652cdf0e10cSrcweir     aCommentEd  ( this, SfxResId( ED_COMMENT ) ),
653cdf0e10cSrcweir 
654cdf0e10cSrcweir     pInfoItem   ( NULL )
655cdf0e10cSrcweir 
656cdf0e10cSrcweir {
657cdf0e10cSrcweir     FreeResource();
658cdf0e10cSrcweir }
659cdf0e10cSrcweir 
660cdf0e10cSrcweir //------------------------------------------------------------------------
661cdf0e10cSrcweir 
Create(Window * pParent,const SfxItemSet & rItemSet)662cdf0e10cSrcweir SfxTabPage *SfxDocumentDescPage::Create(Window *pParent, const SfxItemSet &rItemSet)
663cdf0e10cSrcweir {
664cdf0e10cSrcweir 	 return new SfxDocumentDescPage(pParent, rItemSet);
665cdf0e10cSrcweir }
666cdf0e10cSrcweir 
667cdf0e10cSrcweir //------------------------------------------------------------------------
668cdf0e10cSrcweir 
FillItemSet(SfxItemSet & rSet)669cdf0e10cSrcweir sal_Bool SfxDocumentDescPage::FillItemSet(SfxItemSet &rSet)
670cdf0e10cSrcweir {
671cdf0e10cSrcweir 	// Pruefung, ob eine Aenderung vorliegt
672cdf0e10cSrcweir 	const sal_Bool bTitleMod = aTitleEd.IsModified();
673cdf0e10cSrcweir 	const sal_Bool bThemeMod = aThemaEd.IsModified();
674cdf0e10cSrcweir 	const sal_Bool bKeywordsMod = aKeywordsEd.IsModified();
675cdf0e10cSrcweir 	const sal_Bool bCommentMod = aCommentEd.IsModified();
676cdf0e10cSrcweir 	if( !( bTitleMod || bThemeMod || bKeywordsMod || bCommentMod ) )
677cdf0e10cSrcweir 	{
678cdf0e10cSrcweir 		return sal_False;
679cdf0e10cSrcweir 	}
680cdf0e10cSrcweir 
681cdf0e10cSrcweir 	// Erzeugung der Ausgabedaten
682cdf0e10cSrcweir     const SfxPoolItem* pItem = NULL;
683cdf0e10cSrcweir     SfxDocumentInfoItem* pInfo = NULL;
684cdf0e10cSrcweir 	SfxTabDialog* pDlg = GetTabDialog();
685cdf0e10cSrcweir 	const SfxItemSet* pExSet = NULL;
686cdf0e10cSrcweir 
687cdf0e10cSrcweir 	if ( pDlg )
688cdf0e10cSrcweir 		pExSet = pDlg->GetExampleSet();
689cdf0e10cSrcweir 
690cdf0e10cSrcweir 	if ( pExSet && SFX_ITEM_SET != pExSet->GetItemState( SID_DOCINFO, sal_True, &pItem ) )
691cdf0e10cSrcweir 		pInfo = pInfoItem;
692cdf0e10cSrcweir     else if ( pItem )
693cdf0e10cSrcweir         pInfo = new SfxDocumentInfoItem( *(const SfxDocumentInfoItem *)pItem );
694cdf0e10cSrcweir 
695cdf0e10cSrcweir     if ( !pInfo )
696cdf0e10cSrcweir     {
697cdf0e10cSrcweir         DBG_ERRORFILE( "SfxDocumentDescPage::FillItemSet(): no item found" );
698cdf0e10cSrcweir         return sal_False;
699cdf0e10cSrcweir     }
700cdf0e10cSrcweir 
701cdf0e10cSrcweir     if( bTitleMod )
702cdf0e10cSrcweir 	{
703cdf0e10cSrcweir 		pInfo->setTitle( aTitleEd.GetText() );
704cdf0e10cSrcweir 	}
705cdf0e10cSrcweir 	if( bThemeMod )
706cdf0e10cSrcweir 	{
707cdf0e10cSrcweir 		pInfo->setSubject( aThemaEd.GetText() );
708cdf0e10cSrcweir 	}
709cdf0e10cSrcweir 	if( bKeywordsMod )
710cdf0e10cSrcweir 	{
711cdf0e10cSrcweir 		pInfo->setKeywords( aKeywordsEd.GetText() );
712cdf0e10cSrcweir 	}
713cdf0e10cSrcweir 	if( bCommentMod )
714cdf0e10cSrcweir 	{
715cdf0e10cSrcweir 		pInfo->setDescription( aCommentEd.GetText() );
716cdf0e10cSrcweir 	}
717cdf0e10cSrcweir 	rSet.Put( SfxDocumentInfoItem( *pInfo ) );
718cdf0e10cSrcweir 	if( pInfo != pInfoItem )
719cdf0e10cSrcweir 	{
720cdf0e10cSrcweir 		delete pInfo;
721cdf0e10cSrcweir 	}
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 	return sal_True;
724cdf0e10cSrcweir }
725cdf0e10cSrcweir 
726cdf0e10cSrcweir //------------------------------------------------------------------------
727cdf0e10cSrcweir 
Reset(const SfxItemSet & rSet)728cdf0e10cSrcweir void SfxDocumentDescPage::Reset(const SfxItemSet &rSet)
729cdf0e10cSrcweir {
730cdf0e10cSrcweir 	 pInfoItem = &(SfxDocumentInfoItem &)rSet.Get(SID_DOCINFO);
731cdf0e10cSrcweir 
732cdf0e10cSrcweir 	 aTitleEd.SetText( pInfoItem->getTitle() );
733cdf0e10cSrcweir 	 aThemaEd.SetText( pInfoItem->getSubject() );
734cdf0e10cSrcweir 	 aKeywordsEd.SetText( pInfoItem->getKeywords() );
735cdf0e10cSrcweir 	 aCommentEd.SetText( pInfoItem->getDescription() );
736cdf0e10cSrcweir 
737cdf0e10cSrcweir      SFX_ITEMSET_ARG( &rSet, pROItem, SfxBoolItem, SID_DOC_READONLY, sal_False );
738cdf0e10cSrcweir 	 if ( pROItem && pROItem->GetValue() )
739cdf0e10cSrcweir 	 {
740cdf0e10cSrcweir 		aTitleEd.SetReadOnly( sal_True );
741cdf0e10cSrcweir 		aThemaEd.SetReadOnly( sal_True );
742cdf0e10cSrcweir 		aKeywordsEd.SetReadOnly( sal_True );
743cdf0e10cSrcweir 		aCommentEd.SetReadOnly( sal_True );
744cdf0e10cSrcweir 	}
745cdf0e10cSrcweir }
746cdf0e10cSrcweir 
747cdf0e10cSrcweir //------------------------------------------------------------------------
748cdf0e10cSrcweir 
749cdf0e10cSrcweir namespace
750cdf0e10cSrcweir {
GetDateTimeString(sal_Int32 _nDate,sal_Int32 _nTime)751cdf0e10cSrcweir 	String GetDateTimeString( sal_Int32 _nDate, sal_Int32 _nTime )
752cdf0e10cSrcweir 	{
753cdf0e10cSrcweir 		LocaleDataWrapper aWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
754cdf0e10cSrcweir 
755cdf0e10cSrcweir 		Date aDate( _nDate );
756cdf0e10cSrcweir 		Time aTime( _nTime );
757cdf0e10cSrcweir 		String aStr( aWrapper.getDate( aDate ) );
758cdf0e10cSrcweir 		aStr.AppendAscii( ", " );
759cdf0e10cSrcweir 		aStr += aWrapper.getTime( aTime );
760cdf0e10cSrcweir 		return aStr;
761cdf0e10cSrcweir 	}
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 	// copy from xmlsecurity/source/dialog/resourcemanager.cxx
GetContentPart(const String & _rRawString,const String & _rPartId)764cdf0e10cSrcweir 	String GetContentPart( const String& _rRawString, const String& _rPartId )
765cdf0e10cSrcweir 	{
766cdf0e10cSrcweir 		String		s;
767cdf0e10cSrcweir 
768cdf0e10cSrcweir 		xub_StrLen	nContStart = _rRawString.Search( _rPartId );
769cdf0e10cSrcweir 		if( nContStart != STRING_NOTFOUND )
770cdf0e10cSrcweir 		{
771cdf0e10cSrcweir 			nContStart = nContStart + _rPartId.Len();
772cdf0e10cSrcweir 			++nContStart;					// now it's start of content, directly after Id
773cdf0e10cSrcweir 
774cdf0e10cSrcweir 			xub_StrLen	nContEnd = _rRawString.Search( sal_Unicode( ',' ), nContStart );
775cdf0e10cSrcweir 
776cdf0e10cSrcweir 			s = String( _rRawString, nContStart, nContEnd - nContStart );
777cdf0e10cSrcweir 		}
778cdf0e10cSrcweir 
779cdf0e10cSrcweir 		return s;
780cdf0e10cSrcweir 	}
781cdf0e10cSrcweir 
782cdf0e10cSrcweir }
783cdf0e10cSrcweir 
SfxDocumentPage(Window * pParent,const SfxItemSet & rItemSet)784cdf0e10cSrcweir SfxDocumentPage::SfxDocumentPage( Window* pParent, const SfxItemSet& rItemSet ) :
785cdf0e10cSrcweir 
786cdf0e10cSrcweir 	SfxTabPage( pParent, SfxResId( TP_DOCINFODOC ), rItemSet ),
787cdf0e10cSrcweir 
788cdf0e10cSrcweir     aBmp1           ( this, SfxResId( BMP_FILE_1 ) ),
789cdf0e10cSrcweir     aNameED         ( this, SfxResId( ED_FILE_NAME ) ),
790cdf0e10cSrcweir 
791cdf0e10cSrcweir     aLine1FL        ( this, SfxResId( FL_FILE_1 ) ),
792cdf0e10cSrcweir     aTypeFT         ( this, SfxResId( FT_FILE_TYP ) ),
793cdf0e10cSrcweir     aShowTypeFT     ( this, SfxResId( FT_FILE_SHOW_TYP ) ),
794cdf0e10cSrcweir     aReadOnlyCB     ( this, SfxResId( CB_FILE_READONLY ) ),
795cdf0e10cSrcweir     aFileFt         ( this, SfxResId( FT_FILE ) ),
796cdf0e10cSrcweir     aFileValFt      ( this, SfxResId( FT_FILE_VAL ) ),
797cdf0e10cSrcweir     aSizeFT         ( this, SfxResId( FT_FILE_SIZE ) ),
798cdf0e10cSrcweir     aShowSizeFT     ( this, SfxResId( FT_FILE_SHOW_SIZE ) ),
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     aLine2FL        ( this, SfxResId( FL_FILE_2 ) ),
801cdf0e10cSrcweir     aCreateFt       ( this, SfxResId( FT_CREATE ) ),
802cdf0e10cSrcweir     aCreateValFt    ( this, SfxResId( FT_CREATE_VAL ) ),
803cdf0e10cSrcweir     aChangeFt       ( this, SfxResId( FT_CHANGE ) ),
804cdf0e10cSrcweir     aChangeValFt    ( this, SfxResId( FT_CHANGE_VAL ) ),
805cdf0e10cSrcweir     aSignedFt       ( this, SfxResId( FT_SIGNED ) ),
806cdf0e10cSrcweir     aSignedValFt    ( this, SfxResId( FT_SIGNED_VAL ) ),
807cdf0e10cSrcweir     aSignatureBtn   ( this, SfxResId( BTN_SIGNATURE ) ),
808cdf0e10cSrcweir     aPrintFt        ( this, SfxResId( FT_PRINT ) ),
809cdf0e10cSrcweir     aPrintValFt     ( this, SfxResId( FT_PRINT_VAL ) ),
810cdf0e10cSrcweir     aTimeLogFt      ( this, SfxResId( FT_TIMELOG ) ),
811cdf0e10cSrcweir     aTimeLogValFt   ( this, SfxResId( FT_TIMELOG_VAL ) ),
812cdf0e10cSrcweir     aDocNoFt        ( this, SfxResId( FT_DOCNO ) ),
813cdf0e10cSrcweir     aDocNoValFt     ( this, SfxResId( FT_DOCNO_VAL ) ),
814cdf0e10cSrcweir     aUseUserDataCB  ( this, SfxResId( CB_USE_USERDATA ) ),
815cdf0e10cSrcweir     aDeleteBtn      ( this, SfxResId( BTN_DELETE ) ),
816cdf0e10cSrcweir 
817cdf0e10cSrcweir     aLine3FL        ( this, SfxResId( FL_FILE_3 ) ),
818cdf0e10cSrcweir     aTemplFt        ( this, SfxResId( FT_TEMPL ) ),
819cdf0e10cSrcweir     aTemplValFt     ( this, SfxResId( FT_TEMPL_VAL ) ),
820cdf0e10cSrcweir 
821cdf0e10cSrcweir 	aUnknownSize	( SfxResId( STR_UNKNOWNSIZE ) ),
822cdf0e10cSrcweir 	aMultiSignedStr	( SfxResId( STR_MULTSIGNED ) ),
823cdf0e10cSrcweir 
824cdf0e10cSrcweir 	bEnableUseUserData	( sal_False ),
825cdf0e10cSrcweir 	bHandleDelete		( sal_False )
826cdf0e10cSrcweir 
827cdf0e10cSrcweir {
828cdf0e10cSrcweir 	aNameED.SetAccessibleName(String(SfxResId(EDIT_FILE_NAME)));
829cdf0e10cSrcweir 	FreeResource();
830cdf0e10cSrcweir 
831cdf0e10cSrcweir     ImplUpdateSignatures();
832cdf0e10cSrcweir 	aDeleteBtn.SetClickHdl( LINK( this, SfxDocumentPage, DeleteHdl ) );
833cdf0e10cSrcweir 	aSignatureBtn.SetClickHdl( LINK( this, SfxDocumentPage, SignatureHdl ) );
834cdf0e10cSrcweir 
835cdf0e10cSrcweir     // if the button text is too wide, then broaden it
836cdf0e10cSrcweir     const long nOffset = 12;
837cdf0e10cSrcweir     String sText = aSignatureBtn.GetText();
838cdf0e10cSrcweir     long nTxtW = aSignatureBtn.GetTextWidth( sText );
839cdf0e10cSrcweir     if ( sText.Search( '~' ) == STRING_NOTFOUND )
840cdf0e10cSrcweir         nTxtW += nOffset;
841cdf0e10cSrcweir     long nBtnW = aSignatureBtn.GetSizePixel().Width();
842cdf0e10cSrcweir     if ( nTxtW >= nBtnW )
843cdf0e10cSrcweir     {
844cdf0e10cSrcweir         long nDelta = Max( nTxtW - nBtnW, nOffset/3 );
845cdf0e10cSrcweir         Size aNewSize = aSignatureBtn.GetSizePixel();
846cdf0e10cSrcweir         aNewSize.Width() += nDelta;
847cdf0e10cSrcweir         aSignatureBtn.SetSizePixel( aNewSize );
848cdf0e10cSrcweir         aDeleteBtn.SetSizePixel( aNewSize );
849cdf0e10cSrcweir         // and give them a new position
850cdf0e10cSrcweir         Point aNewPos = aSignatureBtn.GetPosPixel();
851cdf0e10cSrcweir         aNewPos.X() -= nDelta;
852cdf0e10cSrcweir         aSignatureBtn.SetPosPixel( aNewPos );
853cdf0e10cSrcweir         aNewPos = aDeleteBtn.GetPosPixel();
854cdf0e10cSrcweir         aNewPos.X() -= nDelta;
855cdf0e10cSrcweir         aDeleteBtn.SetPosPixel( aNewPos );
856cdf0e10cSrcweir 
857cdf0e10cSrcweir         aNewSize = aSignedValFt.GetSizePixel();
858cdf0e10cSrcweir         aNewSize.Width() -= nDelta;
859cdf0e10cSrcweir         aSignedValFt.SetSizePixel( aNewSize );
860cdf0e10cSrcweir         aNewSize = aUseUserDataCB.GetSizePixel();
861cdf0e10cSrcweir         aNewSize.Width() -= nDelta;
862cdf0e10cSrcweir         aUseUserDataCB.SetSizePixel( aNewSize );
863cdf0e10cSrcweir     }
864cdf0e10cSrcweir     // See i96288
865cdf0e10cSrcweir     // Check if the document signature command is enabled
866cdf0e10cSrcweir     // on the main list enable/disable the pushbutton accordingly
867cdf0e10cSrcweir     SvtCommandOptions aCmdOptions;
868cdf0e10cSrcweir     if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED,
869cdf0e10cSrcweir                              rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( DOCUMENT_SIGNATURE_MENU_CMD ) ) ) )
870cdf0e10cSrcweir         aSignatureBtn.Disable();
871cdf0e10cSrcweir }
872cdf0e10cSrcweir 
873cdf0e10cSrcweir //------------------------------------------------------------------------
874cdf0e10cSrcweir 
IMPL_LINK(SfxDocumentPage,DeleteHdl,PushButton *,EMPTYARG)875cdf0e10cSrcweir IMPL_LINK( SfxDocumentPage, DeleteHdl, PushButton*, EMPTYARG )
876cdf0e10cSrcweir {
877cdf0e10cSrcweir 	String aName;
878cdf0e10cSrcweir 	if ( bEnableUseUserData && aUseUserDataCB.IsChecked() )
879cdf0e10cSrcweir     	aName = SvtUserOptions().GetFullName();
880cdf0e10cSrcweir 	LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
881cdf0e10cSrcweir     DateTime now;
882cdf0e10cSrcweir     util::DateTime uDT(
883cdf0e10cSrcweir         now.Get100Sec(), now.GetSec(), now.GetMin(), now.GetHour(),
884cdf0e10cSrcweir         now.GetDay(), now.GetMonth(), now.GetYear() );
885cdf0e10cSrcweir 	aCreateValFt.SetText( ConvertDateTime_Impl( aName, uDT, aLocaleWrapper ) );
886cdf0e10cSrcweir 	XubString aEmpty;
887cdf0e10cSrcweir 	aChangeValFt.SetText( aEmpty );
888cdf0e10cSrcweir 	aPrintValFt.SetText( aEmpty );
889cdf0e10cSrcweir 	const Time aTime( 0 );
890cdf0e10cSrcweir 	aTimeLogValFt.SetText( aLocaleWrapper.getDuration( aTime ) );
891cdf0e10cSrcweir 	aDocNoValFt.SetText( '1' );
892cdf0e10cSrcweir 	bHandleDelete = sal_True;
893cdf0e10cSrcweir 	return 0;
894cdf0e10cSrcweir }
895cdf0e10cSrcweir 
IMPL_LINK(SfxDocumentPage,SignatureHdl,PushButton *,EMPTYARG)896cdf0e10cSrcweir IMPL_LINK( SfxDocumentPage, SignatureHdl, PushButton*, EMPTYARG )
897cdf0e10cSrcweir {
898cdf0e10cSrcweir 	SfxObjectShell*	pDoc = SfxObjectShell::Current();
899cdf0e10cSrcweir 	if( pDoc )
900cdf0e10cSrcweir 	{
901cdf0e10cSrcweir         pDoc->SignDocumentContent();
902cdf0e10cSrcweir 
903cdf0e10cSrcweir         ImplUpdateSignatures();
904cdf0e10cSrcweir     }
905cdf0e10cSrcweir 
906cdf0e10cSrcweir     return 0;
907cdf0e10cSrcweir }
908cdf0e10cSrcweir 
ImplUpdateSignatures()909cdf0e10cSrcweir void SfxDocumentPage::ImplUpdateSignatures()
910cdf0e10cSrcweir {
911cdf0e10cSrcweir 	SfxObjectShell*	pDoc = SfxObjectShell::Current();
912cdf0e10cSrcweir 	if( pDoc )
913cdf0e10cSrcweir 	{
914cdf0e10cSrcweir 		SfxMedium* pMedium = pDoc->GetMedium();
915cdf0e10cSrcweir         if ( pMedium && pMedium->GetName().Len() && pMedium->GetStorage().is() )
916cdf0e10cSrcweir 		{
917cdf0e10cSrcweir 			Reference< security::XDocumentDigitalSignatures > xD(
918cdf0e10cSrcweir 				comphelper::getProcessServiceFactory()->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ) ), uno::UNO_QUERY );
919cdf0e10cSrcweir 
920cdf0e10cSrcweir 			if( xD.is() )
921cdf0e10cSrcweir 			{
922cdf0e10cSrcweir 				String s;
923cdf0e10cSrcweir 				Sequence< security::DocumentSignatureInformation > aInfos;
924cdf0e10cSrcweir 				aInfos = xD->verifyDocumentContentSignatures( pMedium->GetZipStorageToSign_Impl(),
925cdf0e10cSrcweir 																uno::Reference< io::XInputStream >() );
926cdf0e10cSrcweir 				if( aInfos.getLength() > 1 )
927cdf0e10cSrcweir 				{
928cdf0e10cSrcweir 					s = aMultiSignedStr;
929cdf0e10cSrcweir 				}
930cdf0e10cSrcweir 				else if( aInfos.getLength() == 1 )
931cdf0e10cSrcweir 				{
932cdf0e10cSrcweir 					String aCN_Id( String::CreateFromAscii( "CN" ) );
933cdf0e10cSrcweir 					const security::DocumentSignatureInformation& rInfo = aInfos[ 0 ];
934cdf0e10cSrcweir 					s = GetDateTimeString( rInfo.SignatureDate, rInfo.SignatureTime );
935cdf0e10cSrcweir 					s.AppendAscii( ", " );
936cdf0e10cSrcweir 					s += GetContentPart( rInfo.Signer->getSubjectName(), aCN_Id );
937cdf0e10cSrcweir 				}
938cdf0e10cSrcweir 				aSignedValFt.SetText( s );
939cdf0e10cSrcweir 			}
940cdf0e10cSrcweir 		}
941cdf0e10cSrcweir 	}
942cdf0e10cSrcweir }
943cdf0e10cSrcweir 
944cdf0e10cSrcweir //------------------------------------------------------------------------
945cdf0e10cSrcweir 
Create(Window * pParent,const SfxItemSet & rItemSet)946cdf0e10cSrcweir SfxTabPage* SfxDocumentPage::Create( Window* pParent, const SfxItemSet& rItemSet )
947cdf0e10cSrcweir {
948cdf0e10cSrcweir 	 return new SfxDocumentPage( pParent, rItemSet );
949cdf0e10cSrcweir }
950cdf0e10cSrcweir 
951cdf0e10cSrcweir //------------------------------------------------------------------------
952cdf0e10cSrcweir 
EnableUseUserData()953cdf0e10cSrcweir void SfxDocumentPage::EnableUseUserData()
954cdf0e10cSrcweir {
955cdf0e10cSrcweir 	bEnableUseUserData = sal_True;
956cdf0e10cSrcweir 	aUseUserDataCB.Show();
957cdf0e10cSrcweir 	aDeleteBtn.Show();
958cdf0e10cSrcweir }
959cdf0e10cSrcweir 
960cdf0e10cSrcweir //------------------------------------------------------------------------
961cdf0e10cSrcweir 
FillItemSet(SfxItemSet & rSet)962cdf0e10cSrcweir sal_Bool SfxDocumentPage::FillItemSet( SfxItemSet& rSet )
963cdf0e10cSrcweir {
964cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
965cdf0e10cSrcweir 
966cdf0e10cSrcweir 	if ( !bHandleDelete && bEnableUseUserData &&
967cdf0e10cSrcweir 		 aUseUserDataCB.GetState() != aUseUserDataCB.GetSavedValue() &&
968cdf0e10cSrcweir 		 GetTabDialog() && GetTabDialog()->GetExampleSet() )
969cdf0e10cSrcweir 	{
970cdf0e10cSrcweir 		const SfxItemSet* pExpSet = GetTabDialog()->GetExampleSet();
971cdf0e10cSrcweir 		const SfxPoolItem* pItem;
972cdf0e10cSrcweir 
973cdf0e10cSrcweir 		if ( pExpSet && SFX_ITEM_SET == pExpSet->GetItemState( SID_DOCINFO, sal_True, &pItem ) )
974cdf0e10cSrcweir 		{
975cdf0e10cSrcweir 			SfxDocumentInfoItem* pInfoItem = (SfxDocumentInfoItem*)pItem;
976cdf0e10cSrcweir 			sal_Bool bUseData = ( STATE_CHECK == aUseUserDataCB.GetState() );
977cdf0e10cSrcweir 			pInfoItem->SetUseUserData( bUseData );
978cdf0e10cSrcweir /*
979cdf0e10cSrcweir 			if ( !bUseData )
980cdf0e10cSrcweir 			{
981cdf0e10cSrcweir 				// "Benutzerdaten verwenden" ausgeschaltet ->
982cdf0e10cSrcweir 				// den Benutzer aus den Stamps l"oschen
983cdf0e10cSrcweir 				String aEmptyUser;
984cdf0e10cSrcweir 				aInfo.SetCreated(
985cdf0e10cSrcweir 					SfxStamp( aEmptyUser, aInfo.GetCreated().GetTime() ) );
986cdf0e10cSrcweir 				aInfo.SetChanged(
987cdf0e10cSrcweir 					SfxStamp( aEmptyUser, aInfo.GetChanged().GetTime() ) );
988cdf0e10cSrcweir 				aInfo.SetPrinted(
989cdf0e10cSrcweir 					SfxStamp( aEmptyUser, aInfo.GetPrinted().GetTime() ) );
990cdf0e10cSrcweir 			}
991cdf0e10cSrcweir */
992cdf0e10cSrcweir 			rSet.Put( SfxDocumentInfoItem( *pInfoItem ) );
993cdf0e10cSrcweir 			bRet = sal_True;
994cdf0e10cSrcweir 		}
995cdf0e10cSrcweir 	}
996cdf0e10cSrcweir 
997cdf0e10cSrcweir 	if ( bHandleDelete )
998cdf0e10cSrcweir 	{
999cdf0e10cSrcweir 		const SfxItemSet* pExpSet = GetTabDialog()->GetExampleSet();
1000cdf0e10cSrcweir 		const SfxPoolItem* pItem;
1001cdf0e10cSrcweir 		if ( pExpSet && SFX_ITEM_SET == pExpSet->GetItemState( SID_DOCINFO, sal_True, &pItem ) )
1002cdf0e10cSrcweir 		{
1003cdf0e10cSrcweir 			SfxDocumentInfoItem* pInfoItem = (SfxDocumentInfoItem*)pItem;
1004cdf0e10cSrcweir 			sal_Bool bUseAuthor = bEnableUseUserData && aUseUserDataCB.IsChecked();
1005cdf0e10cSrcweir 			SfxDocumentInfoItem newItem( *pInfoItem );
1006cdf0e10cSrcweir             newItem.resetUserData( bUseAuthor
1007cdf0e10cSrcweir                 ? SvtUserOptions().GetFullName()
1008cdf0e10cSrcweir                 : ::rtl::OUString() );
1009cdf0e10cSrcweir 			pInfoItem->SetUseUserData( STATE_CHECK == aUseUserDataCB.GetState() );
1010cdf0e10cSrcweir 			newItem.SetUseUserData( STATE_CHECK == aUseUserDataCB.GetState() );
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir 			newItem.SetDeleteUserData( sal_True );
1013cdf0e10cSrcweir 			rSet.Put( newItem );
1014cdf0e10cSrcweir 			bRet = sal_True;
1015cdf0e10cSrcweir 		}
1016cdf0e10cSrcweir 	}
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir 	if ( aNameED.IsModified() && aNameED.GetText().Len() )
1019cdf0e10cSrcweir 	{
1020cdf0e10cSrcweir 		rSet.Put( SfxStringItem( ID_FILETP_TITLE, aNameED.GetText() ) );
1021cdf0e10cSrcweir 		bRet = sal_True;
1022cdf0e10cSrcweir 	}
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir 	if ( /* aReadOnlyCB.IsModified() */ sal_True )
1025cdf0e10cSrcweir 	{
1026cdf0e10cSrcweir 		rSet.Put( SfxBoolItem( ID_FILETP_READONLY, aReadOnlyCB.IsChecked() ) );
1027cdf0e10cSrcweir 		bRet = sal_True;
1028cdf0e10cSrcweir 	}
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir 	return bRet;
1031cdf0e10cSrcweir }
1032cdf0e10cSrcweir 
1033cdf0e10cSrcweir //------------------------------------------------------------------------
1034cdf0e10cSrcweir 
Reset(const SfxItemSet & rSet)1035cdf0e10cSrcweir void SfxDocumentPage::Reset( const SfxItemSet& rSet )
1036cdf0e10cSrcweir {
1037cdf0e10cSrcweir 	// Bestimmung der Dokumentinformationen
1038cdf0e10cSrcweir 	const SfxDocumentInfoItem *pInfoItem =
1039cdf0e10cSrcweir 		&(const SfxDocumentInfoItem &)rSet.Get(SID_DOCINFO);
1040cdf0e10cSrcweir 
1041cdf0e10cSrcweir 	// template data
1042cdf0e10cSrcweir 	if ( pInfoItem->HasTemplate() )
1043cdf0e10cSrcweir 	{
1044cdf0e10cSrcweir 		aTemplValFt.SetText( pInfoItem->getTemplateName() );
1045cdf0e10cSrcweir 	}
1046cdf0e10cSrcweir 	else
1047cdf0e10cSrcweir 	{
1048cdf0e10cSrcweir 		aTemplFt.Hide();
1049cdf0e10cSrcweir 		aTemplValFt.Hide();
1050cdf0e10cSrcweir 	}
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir 	// determine file name
1053cdf0e10cSrcweir 	String aFile( pInfoItem->GetValue() );
1054cdf0e10cSrcweir 	String aFactory( aFile );
1055cdf0e10cSrcweir 	if ( aFile.Len() > 2 && aFile.GetChar(0) == '[' )
1056cdf0e10cSrcweir 	{
1057cdf0e10cSrcweir 		sal_uInt16 nPos = aFile.Search( ']' );
1058cdf0e10cSrcweir 		aFactory = aFile.Copy( 1, nPos-1  );
1059cdf0e10cSrcweir 		aFile = aFile.Copy( nPos+1 );
1060cdf0e10cSrcweir 	}
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir 	// determine name
1063cdf0e10cSrcweir 	String aName;
1064cdf0e10cSrcweir 	const SfxPoolItem* pItem = 0;
1065cdf0e10cSrcweir 	if ( SFX_ITEM_SET != rSet.GetItemState( ID_FILETP_TITLE, sal_False, &pItem ) )
1066cdf0e10cSrcweir 	{
1067cdf0e10cSrcweir 		INetURLObject aURL(aFile);
1068cdf0e10cSrcweir 		aName = aURL.GetName( INetURLObject::DECODE_WITH_CHARSET );
1069cdf0e10cSrcweir 		if ( !aName.Len() || aURL.GetProtocol() == INET_PROT_PRIVATE )
1070cdf0e10cSrcweir 			aName = String( SfxResId( STR_NONAME ) );
1071cdf0e10cSrcweir 		aNameED.SetReadOnly( sal_True );
1072cdf0e10cSrcweir 	}
1073cdf0e10cSrcweir 	else
1074cdf0e10cSrcweir 	{
1075cdf0e10cSrcweir 		DBG_ASSERT( pItem->IsA( TYPE( SfxStringItem ) ), "SfxDocumentPage:<SfxStringItem> erwartet" );
1076cdf0e10cSrcweir 		aName = ( ( SfxStringItem* ) pItem )->GetValue();
1077cdf0e10cSrcweir 	}
1078cdf0e10cSrcweir 	aNameED.SetText( aName );
1079cdf0e10cSrcweir 	aNameED.ClearModifyFlag();
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir 	// determine RO-Flag
1082cdf0e10cSrcweir 	if ( SFX_ITEM_UNKNOWN == rSet.GetItemState( ID_FILETP_READONLY, sal_False, &pItem )
1083cdf0e10cSrcweir 		 || !pItem )
1084cdf0e10cSrcweir 		aReadOnlyCB.Hide();
1085cdf0e10cSrcweir 	else
1086cdf0e10cSrcweir 		aReadOnlyCB.Check( ( (SfxBoolItem*)pItem )->GetValue() );
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir 	// determine context symbol
1089cdf0e10cSrcweir 	INetURLObject aURL;
1090cdf0e10cSrcweir 	aURL.SetSmartProtocol( INET_PROT_FILE );
1091cdf0e10cSrcweir 	aURL.SetSmartURL( aFactory);
1092cdf0e10cSrcweir 	const String& rMainURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
1093cdf0e10cSrcweir     aBmp1.SetImage( SvFileInformationManager::GetImage( aURL, sal_True ) );
1094cdf0e10cSrcweir 
1095cdf0e10cSrcweir 	// determine size and type
1096cdf0e10cSrcweir 	String aSizeText( aUnknownSize );
1097cdf0e10cSrcweir 	if ( aURL.GetProtocol() == INET_PROT_FILE )
1098cdf0e10cSrcweir 		aSizeText = CreateSizeText( SfxContentHelper::GetSize( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) );
1099cdf0e10cSrcweir 	aShowSizeFT.SetText( aSizeText );
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir 	String aDescription = SvFileInformationManager::GetDescription( INetURLObject(rMainURL) );
1102cdf0e10cSrcweir 	if ( aDescription.Len() == 0 )
1103cdf0e10cSrcweir 		aDescription = String( SfxResId( STR_SFX_NEWOFFICEDOC ) );
1104cdf0e10cSrcweir 	aShowTypeFT.SetText( aDescription );
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir 	// determine location
1107cdf0e10cSrcweir 	aURL.SetSmartURL( aFile);
1108cdf0e10cSrcweir 	if ( aURL.GetProtocol() == INET_PROT_FILE )
1109cdf0e10cSrcweir 	{
1110cdf0e10cSrcweir 		INetURLObject aPath( aURL );
1111cdf0e10cSrcweir 		aPath.setFinalSlash();
1112cdf0e10cSrcweir 		aPath.removeSegment();
1113cdf0e10cSrcweir         // we know it's a folder -> don't need the final slash, but it's better for WB_PATHELLIPSIS
1114cdf0e10cSrcweir         aPath.removeFinalSlash();
1115cdf0e10cSrcweir         String aText( aPath.PathToFileName() ); //! (pb) MaxLen?
1116cdf0e10cSrcweir 		aFileValFt.SetText( aText );
1117cdf0e10cSrcweir 	}
1118cdf0e10cSrcweir 	else if ( aURL.GetProtocol() != INET_PROT_PRIVATE )
1119cdf0e10cSrcweir 		aFileValFt.SetText( aURL.GetPartBeforeLastName() );
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir 	// handle access data
1122cdf0e10cSrcweir     sal_Bool m_bUseUserData = pInfoItem->IsUseUserData();
1123cdf0e10cSrcweir 	LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
1124cdf0e10cSrcweir 	aCreateValFt.SetText( ConvertDateTime_Impl( pInfoItem->getAuthor(),
1125cdf0e10cSrcweir         pInfoItem->getCreationDate(), aLocaleWrapper ) );
1126cdf0e10cSrcweir 	util::DateTime aTime( pInfoItem->getModificationDate() );
1127cdf0e10cSrcweir //	if ( aTime.IsValid() )
1128cdf0e10cSrcweir 	if ( aTime.Month > 0 )
1129cdf0e10cSrcweir 		aChangeValFt.SetText( ConvertDateTime_Impl(
1130cdf0e10cSrcweir             pInfoItem->getModifiedBy(), aTime, aLocaleWrapper ) );
1131cdf0e10cSrcweir 	aTime = pInfoItem->getPrintDate();
1132cdf0e10cSrcweir //	if ( aTime.IsValid())
1133cdf0e10cSrcweir 	if ( aTime.Month > 0 )
1134cdf0e10cSrcweir 		aPrintValFt.SetText( ConvertDateTime_Impl( pInfoItem->getPrintedBy(),
1135cdf0e10cSrcweir             aTime, aLocaleWrapper ) );
1136cdf0e10cSrcweir 	const long nTime = pInfoItem->getEditingDuration();
1137cdf0e10cSrcweir     if ( m_bUseUserData )
1138cdf0e10cSrcweir     {
1139cdf0e10cSrcweir 		const Time aT( nTime/3600, (nTime%3600)/60, nTime%60 );
1140cdf0e10cSrcweir 		aTimeLogValFt.SetText( aLocaleWrapper.getDuration( aT ) );
1141cdf0e10cSrcweir 		aDocNoValFt.SetText( String::CreateFromInt32(
1142cdf0e10cSrcweir             pInfoItem->getEditingCycles() ) );
1143cdf0e10cSrcweir 	}
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir     TriState eState = (TriState)m_bUseUserData;
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir 	if ( STATE_DONTKNOW == eState )
1148cdf0e10cSrcweir 		aUseUserDataCB.EnableTriState( sal_True );
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir 	aUseUserDataCB.SetState( eState );
1151cdf0e10cSrcweir 	aUseUserDataCB.SaveValue();
1152cdf0e10cSrcweir 	aUseUserDataCB.Enable( bEnableUseUserData );
1153cdf0e10cSrcweir 	bHandleDelete = sal_False;
1154cdf0e10cSrcweir 	aDeleteBtn.Enable( bEnableUseUserData );
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir 
1157cdf0e10cSrcweir //------------------------------------------------------------------------
1158cdf0e10cSrcweir 
SfxInternetPage(Window * pParent,const SfxItemSet & rItemSet)1159cdf0e10cSrcweir SfxInternetPage::SfxInternetPage( Window* pParent, const SfxItemSet& rItemSet ) :
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir 	SfxTabPage( pParent, SfxResId( TP_DOCINFORELOAD ), rItemSet ),
1162cdf0e10cSrcweir 
1163cdf0e10cSrcweir 	aRBNoAutoUpdate		( this, SfxResId( RB_NOAUTOUPDATE		) ),
1164cdf0e10cSrcweir 
1165cdf0e10cSrcweir 	aRBReloadUpdate		( this, SfxResId( RB_RELOADUPDATE		) ),
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir 	aRBForwardUpdate	( this, SfxResId( RB_FORWARDUPDATE		) ),
1168cdf0e10cSrcweir 	aFTEvery			( this, SfxResId( FT_EVERY				) ),
1169cdf0e10cSrcweir 	aNFReload			( this, SfxResId( ED_RELOAD			) ),
1170cdf0e10cSrcweir 	aFTReloadSeconds	( this, SfxResId( FT_RELOADSECS		) ),
1171cdf0e10cSrcweir 	aFTAfter			( this, SfxResId( FT_AFTER				) ),
1172cdf0e10cSrcweir 	aNFAfter			( this, SfxResId( ED_FORWARD			) ),
1173cdf0e10cSrcweir 	aFTAfterSeconds		( this, SfxResId( FT_FORWARDSECS		) ),
1174cdf0e10cSrcweir 	aFTURL				( this, SfxResId( FT_URL				) ),
1175cdf0e10cSrcweir 	aEDForwardURL		( this, SfxResId( ED_URL				) ),
1176cdf0e10cSrcweir 	aPBBrowseURL		( this, SfxResId( PB_BROWSEURL			) ),
1177cdf0e10cSrcweir 	aFTFrame			( this, SfxResId( FT_FRAME				) ),
1178cdf0e10cSrcweir 	aCBFrame			( this, SfxResId( CB_FRAME				) ),
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir 	aForwardErrorMessg	(		SfxResId( STR_FORWARD_ERRMSSG	) ),
1181cdf0e10cSrcweir     pInfoItem           ( NULL ),
1182cdf0e10cSrcweir     pFileDlg            ( NULL ),
1183cdf0e10cSrcweir     eState              ( S_Init )
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir {
1186cdf0e10cSrcweir 	FreeResource();
1187cdf0e10cSrcweir 	pInfoItem = &( SfxDocumentInfoItem& ) rItemSet.Get( SID_DOCINFO );
1188cdf0e10cSrcweir 	TargetList			aList;
1189cdf0e10cSrcweir 	SfxViewFrame*		pFrame = SfxViewFrame::Current();
1190cdf0e10cSrcweir 	if( pFrame )
1191cdf0e10cSrcweir     {
1192cdf0e10cSrcweir         pFrame = pFrame->GetTopViewFrame();
1193cdf0e10cSrcweir         if( pFrame )
1194cdf0e10cSrcweir         {
1195cdf0e10cSrcweir             pFrame->GetTargetList( aList );
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir             String*			pObj;
1198cdf0e10cSrcweir             for( sal_uInt16 nPos = ( sal_uInt16 ) aList.Count() ; nPos ; )
1199cdf0e10cSrcweir             {
1200cdf0e10cSrcweir                 pObj = aList.GetObject( --nPos );
1201cdf0e10cSrcweir                 aCBFrame.InsertEntry( *pObj );
1202cdf0e10cSrcweir                 delete pObj;
1203cdf0e10cSrcweir             }
1204cdf0e10cSrcweir         }
1205cdf0e10cSrcweir 	}
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir 	aRBNoAutoUpdate.SetClickHdl( LINK( this, SfxInternetPage, ClickHdlNoUpdate ) );
1208cdf0e10cSrcweir 	aRBReloadUpdate.SetClickHdl( LINK( this, SfxInternetPage, ClickHdlReload ) );
1209cdf0e10cSrcweir 	aRBForwardUpdate.SetClickHdl( LINK( this, SfxInternetPage, ClickHdlForward ) );
1210cdf0e10cSrcweir 	aPBBrowseURL.SetClickHdl( LINK( this, SfxInternetPage, ClickHdlBrowseURL ) );
1211cdf0e10cSrcweir 
1212cdf0e10cSrcweir 	aForwardErrorMessg.SearchAndReplaceAscii( "%PLACEHOLDER%", aRBForwardUpdate.GetText() );
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir 	ChangeState( S_NoUpdate );
1215cdf0e10cSrcweir }
1216cdf0e10cSrcweir 
1217cdf0e10cSrcweir //------------------------------------------------------------------------
1218cdf0e10cSrcweir 
~SfxInternetPage()1219cdf0e10cSrcweir SfxInternetPage::~SfxInternetPage()
1220cdf0e10cSrcweir {
1221cdf0e10cSrcweir     delete pFileDlg;
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir //------------------------------------------------------------------------
1225cdf0e10cSrcweir 
ChangeState(STATE eNewState)1226cdf0e10cSrcweir void SfxInternetPage::ChangeState( STATE eNewState )
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir 	DBG_ASSERT( eNewState != S_Init, "*SfxInternetPage::ChangeState(): new state init is supposed to not work here!" );
1229cdf0e10cSrcweir 
1230cdf0e10cSrcweir 	if( eState == eNewState  )
1231cdf0e10cSrcweir 		return;
1232cdf0e10cSrcweir 
1233cdf0e10cSrcweir 	switch( eState )
1234cdf0e10cSrcweir 	{
1235cdf0e10cSrcweir 		case S_Init:
1236cdf0e10cSrcweir 			EnableNoUpdate( sal_True );
1237cdf0e10cSrcweir 			EnableReload( sal_False );
1238cdf0e10cSrcweir 			EnableForward( sal_False );
1239cdf0e10cSrcweir 			break;
1240cdf0e10cSrcweir 		case S_NoUpdate:
1241cdf0e10cSrcweir 			EnableNoUpdate( sal_False );
1242cdf0e10cSrcweir 			if( eNewState == S_Reload )
1243cdf0e10cSrcweir 				EnableReload( sal_True );
1244cdf0e10cSrcweir 			else
1245cdf0e10cSrcweir 				EnableForward( sal_True );
1246cdf0e10cSrcweir 			break;
1247cdf0e10cSrcweir 		case S_Reload:
1248cdf0e10cSrcweir 			EnableReload( sal_False );
1249cdf0e10cSrcweir 			if( eNewState == S_NoUpdate )
1250cdf0e10cSrcweir 				EnableNoUpdate( sal_True );
1251cdf0e10cSrcweir 			else
1252cdf0e10cSrcweir 				EnableForward( sal_True );
1253cdf0e10cSrcweir 			break;
1254cdf0e10cSrcweir 		case S_Forward:
1255cdf0e10cSrcweir 			EnableForward( sal_False );
1256cdf0e10cSrcweir 			if( eNewState == S_NoUpdate )
1257cdf0e10cSrcweir 				EnableNoUpdate( sal_True );
1258cdf0e10cSrcweir 			else
1259cdf0e10cSrcweir 				EnableReload( sal_True );
1260cdf0e10cSrcweir 			break;
1261cdf0e10cSrcweir 		default:
1262cdf0e10cSrcweir 			DBG_ERROR( "*SfxInternetPage::SetState(): unhandled state!" );
1263cdf0e10cSrcweir 	}
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir 	eState = eNewState;
1266cdf0e10cSrcweir }
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir //------------------------------------------------------------------------
1269cdf0e10cSrcweir 
EnableNoUpdate(sal_Bool bEnable)1270cdf0e10cSrcweir void SfxInternetPage::EnableNoUpdate( sal_Bool bEnable )
1271cdf0e10cSrcweir {
1272cdf0e10cSrcweir 	if( bEnable )
1273cdf0e10cSrcweir 		aRBNoAutoUpdate.Check();
1274cdf0e10cSrcweir }
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir //------------------------------------------------------------------------
1277cdf0e10cSrcweir 
EnableReload(sal_Bool bEnable)1278cdf0e10cSrcweir void SfxInternetPage::EnableReload( sal_Bool bEnable )
1279cdf0e10cSrcweir {
1280cdf0e10cSrcweir 	aFTEvery.Enable( bEnable );
1281cdf0e10cSrcweir 	aNFReload.Enable( bEnable );
1282cdf0e10cSrcweir 	aFTReloadSeconds.Enable( bEnable );
1283cdf0e10cSrcweir 
1284cdf0e10cSrcweir 	if( bEnable )
1285cdf0e10cSrcweir 		aRBReloadUpdate.Check();
1286cdf0e10cSrcweir }
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir //------------------------------------------------------------------------
1289cdf0e10cSrcweir 
EnableForward(sal_Bool bEnable)1290cdf0e10cSrcweir void SfxInternetPage::EnableForward( sal_Bool bEnable )
1291cdf0e10cSrcweir {
1292cdf0e10cSrcweir 	aFTAfter.Enable( bEnable );
1293cdf0e10cSrcweir 	aNFAfter.Enable( bEnable );
1294cdf0e10cSrcweir 	aFTAfterSeconds.Enable( bEnable );
1295cdf0e10cSrcweir 	aFTURL.Enable( bEnable );
1296cdf0e10cSrcweir 	aEDForwardURL.Enable( bEnable );
1297cdf0e10cSrcweir 	aPBBrowseURL.Enable( bEnable );
1298cdf0e10cSrcweir 	aFTFrame.Enable( bEnable );
1299cdf0e10cSrcweir 	aCBFrame.Enable( bEnable );
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir 	if( bEnable )
1302cdf0e10cSrcweir 		aRBForwardUpdate.Check();
1303cdf0e10cSrcweir }
1304cdf0e10cSrcweir 
1305cdf0e10cSrcweir //------------------------------------------------------------------------
1306cdf0e10cSrcweir 
IMPL_LINK(SfxInternetPage,ClickHdlNoUpdate,Control *,pCtrl)1307cdf0e10cSrcweir IMPL_LINK( SfxInternetPage, ClickHdlNoUpdate, Control*, pCtrl )
1308cdf0e10cSrcweir {
1309cdf0e10cSrcweir     (void)pCtrl; //unused
1310cdf0e10cSrcweir 	ChangeState( S_NoUpdate );
1311cdf0e10cSrcweir 	return 0;
1312cdf0e10cSrcweir }
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir //------------------------------------------------------------------------
1315cdf0e10cSrcweir 
IMPL_LINK(SfxInternetPage,ClickHdlReload,Control *,pCtrl)1316cdf0e10cSrcweir IMPL_LINK( SfxInternetPage, ClickHdlReload, Control*, pCtrl )
1317cdf0e10cSrcweir {
1318cdf0e10cSrcweir     (void)pCtrl; //unused
1319cdf0e10cSrcweir 	ChangeState( S_Reload );
1320cdf0e10cSrcweir 	return 0;
1321cdf0e10cSrcweir }
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir //------------------------------------------------------------------------
1324cdf0e10cSrcweir 
IMPL_LINK(SfxInternetPage,ClickHdlForward,Control *,pCtrl)1325cdf0e10cSrcweir IMPL_LINK( SfxInternetPage, ClickHdlForward, Control*, pCtrl )
1326cdf0e10cSrcweir {
1327cdf0e10cSrcweir     (void)pCtrl; //unused
1328cdf0e10cSrcweir 	ChangeState( S_Forward );
1329cdf0e10cSrcweir 	return 0;
1330cdf0e10cSrcweir }
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir //------------------------------------------------------------------------
1333cdf0e10cSrcweir 
IMPL_LINK(SfxInternetPage,ClickHdlBrowseURL,PushButton *,EMPTYARG)1334cdf0e10cSrcweir IMPL_LINK( SfxInternetPage, ClickHdlBrowseURL, PushButton*, EMPTYARG )
1335cdf0e10cSrcweir {
1336cdf0e10cSrcweir     if ( !pFileDlg )
1337cdf0e10cSrcweir         pFileDlg = new sfx2::FileDialogHelper( TemplateDescription::FILEOPEN_SIMPLE, WB_OPEN );
1338cdf0e10cSrcweir     pFileDlg->SetDisplayDirectory( aEDForwardURL.GetText() );
1339cdf0e10cSrcweir     pFileDlg->StartExecuteModal( LINK( this, SfxInternetPage, DialogClosedHdl ) );
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir     return 0;
1342cdf0e10cSrcweir }
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir //------------------------------------------------------------------------
1345cdf0e10cSrcweir 
IMPL_LINK(SfxInternetPage,DialogClosedHdl,sfx2::FileDialogHelper *,EMPTYARG)1346cdf0e10cSrcweir IMPL_LINK( SfxInternetPage, DialogClosedHdl, sfx2::FileDialogHelper*, EMPTYARG )
1347cdf0e10cSrcweir {
1348cdf0e10cSrcweir     DBG_ASSERT( pFileDlg, "SfxInternetPage::DialogClosedHdl(): no file dialog" );
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir     if ( ERRCODE_NONE == pFileDlg->GetError() )
1351cdf0e10cSrcweir         aEDForwardURL.SetText( pFileDlg->GetPath() );
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir     return 0;
1354cdf0e10cSrcweir }
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir //------------------------------------------------------------------------
1357cdf0e10cSrcweir 
FillItemSet(SfxItemSet & rSet)1358cdf0e10cSrcweir sal_Bool SfxInternetPage::FillItemSet( SfxItemSet& rSet )
1359cdf0e10cSrcweir {
1360cdf0e10cSrcweir 	const SfxPoolItem*			pItem = NULL;
1361cdf0e10cSrcweir 	SfxDocumentInfoItem*		pInfo = NULL;
1362cdf0e10cSrcweir 	SfxTabDialog*				pDlg = GetTabDialog();
1363cdf0e10cSrcweir 	const SfxItemSet*			pExSet = NULL;
1364cdf0e10cSrcweir 
1365cdf0e10cSrcweir 	if( pDlg )
1366cdf0e10cSrcweir 		pExSet = pDlg->GetExampleSet();
1367cdf0e10cSrcweir 
1368cdf0e10cSrcweir 	if( pExSet && SFX_ITEM_SET != pExSet->GetItemState( SID_DOCINFO, sal_True, &pItem ) )
1369cdf0e10cSrcweir 		pInfo = pInfoItem;
1370cdf0e10cSrcweir     else if ( pItem )
1371cdf0e10cSrcweir         pInfo = new SfxDocumentInfoItem( *(const SfxDocumentInfoItem*)pItem );
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir     if ( !pInfo )
1374cdf0e10cSrcweir     {
1375cdf0e10cSrcweir         DBG_ERRORFILE( "SfxInternetPage::FillItemSet(): no item found" );
1376cdf0e10cSrcweir         return sal_False;
1377cdf0e10cSrcweir     }
1378cdf0e10cSrcweir 
1379cdf0e10cSrcweir     DBG_ASSERT( eState != S_Init, "*SfxInternetPage::FillItemSet(): state init is not acceptable at this point!" );
1380cdf0e10cSrcweir 
1381cdf0e10cSrcweir 	sal_Bool						bEnableReload = sal_False;
1382cdf0e10cSrcweir 	::std::auto_ptr< String >	aURL( NULL );
1383cdf0e10cSrcweir 	::std::auto_ptr< String >	aFrame( NULL );
1384cdf0e10cSrcweir 	sal_uIntPtr						nDelay = 0;
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir 	switch( eState )
1387cdf0e10cSrcweir 	{
1388cdf0e10cSrcweir 		case S_NoUpdate:
1389cdf0e10cSrcweir 			break;
1390cdf0e10cSrcweir 		case S_Reload:
1391cdf0e10cSrcweir 			bEnableReload = sal_True;
1392cdf0e10cSrcweir 			aURL = ::std::auto_ptr< String >( new String() );
1393cdf0e10cSrcweir 			aFrame = ::std::auto_ptr< String >( new String() );
1394cdf0e10cSrcweir 			nDelay = static_cast<sal_uIntPtr>(aNFReload.GetValue());
1395cdf0e10cSrcweir 			break;
1396cdf0e10cSrcweir 		case S_Forward:
1397cdf0e10cSrcweir 			DBG_ASSERT( aEDForwardURL.GetText().Len(), "+SfxInternetPage::FillItemSet(): empty URL should be not possible for forward option!" );
1398cdf0e10cSrcweir 
1399cdf0e10cSrcweir 			bEnableReload = sal_True;
1400cdf0e10cSrcweir             aURL = ::std::auto_ptr< String >( new String( URIHelper::SmartRel2Abs( INetURLObject(aBaseURL), aEDForwardURL.GetText(), URIHelper::GetMaybeFileHdl(), true ) ) );
1401cdf0e10cSrcweir 			aFrame = ::std::auto_ptr< String >( new String( aCBFrame.GetText() ) );
1402cdf0e10cSrcweir 			nDelay = static_cast<sal_uIntPtr>(aNFAfter.GetValue());
1403cdf0e10cSrcweir 			break;
1404cdf0e10cSrcweir               default:
1405cdf0e10cSrcweir                   break;
1406cdf0e10cSrcweir 	}
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir 	pInfo->setAutoloadEnabled( bEnableReload );
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir 	if( bEnableReload )
1411cdf0e10cSrcweir 	{
1412cdf0e10cSrcweir 		pInfo->setAutoloadURL( *aURL.get() );
1413cdf0e10cSrcweir 		pInfo->setDefaultTarget( *aFrame.get() );
1414cdf0e10cSrcweir 		pInfo->setAutoloadDelay( nDelay );
1415cdf0e10cSrcweir 	}
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir 	rSet.Put( *pInfo );
1418cdf0e10cSrcweir 	if( pInfo != pInfoItem )
1419cdf0e10cSrcweir 		delete pInfo;
1420cdf0e10cSrcweir 	return sal_True;
1421cdf0e10cSrcweir }
1422cdf0e10cSrcweir 
1423cdf0e10cSrcweir //------------------------------------------------------------------------
1424cdf0e10cSrcweir 
Create(Window * pParent,const SfxItemSet & rItemSet)1425cdf0e10cSrcweir SfxTabPage *SfxInternetPage::Create( Window* pParent, const SfxItemSet& rItemSet )
1426cdf0e10cSrcweir {
1427cdf0e10cSrcweir 	return new SfxInternetPage(pParent, rItemSet);
1428cdf0e10cSrcweir }
1429cdf0e10cSrcweir 
1430cdf0e10cSrcweir //------------------------------------------------------------------------
1431cdf0e10cSrcweir 
Reset(const SfxItemSet & rSet)1432cdf0e10cSrcweir void SfxInternetPage::Reset( const SfxItemSet& rSet )
1433cdf0e10cSrcweir {
1434cdf0e10cSrcweir 	pInfoItem = &( SfxDocumentInfoItem& ) rSet.Get( SID_DOCINFO );
1435cdf0e10cSrcweir     SFX_ITEMSET_ARG( &rSet, pURLItem, SfxStringItem, SID_BASEURL, sal_False );
1436cdf0e10cSrcweir     DBG_ASSERT( pURLItem, "No BaseURL provided for InternetTabPage!" );
1437cdf0e10cSrcweir     if ( pURLItem )
1438cdf0e10cSrcweir         aBaseURL = pURLItem->GetValue();
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir 	STATE				eNewState = S_NoUpdate;
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir 	if( pInfoItem->isAutoloadEnabled() )
1443cdf0e10cSrcweir 	{
1444cdf0e10cSrcweir 		const String&	rURL = pInfoItem->getAutoloadURL();
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir 		if( rURL.Len() )
1447cdf0e10cSrcweir 		{
1448cdf0e10cSrcweir 			aNFAfter.SetValue( pInfoItem->getAutoloadDelay() );
1449cdf0e10cSrcweir 			aEDForwardURL.SetText( rURL );
1450cdf0e10cSrcweir 			aCBFrame.SetText( pInfoItem->getDefaultTarget() );
1451cdf0e10cSrcweir 			eNewState = S_Forward;
1452cdf0e10cSrcweir 		}
1453cdf0e10cSrcweir 		else
1454cdf0e10cSrcweir 		{
1455cdf0e10cSrcweir 			aNFReload.SetValue( pInfoItem->getAutoloadDelay() );
1456cdf0e10cSrcweir 			eNewState = S_Reload;
1457cdf0e10cSrcweir 		}
1458cdf0e10cSrcweir 	}
1459cdf0e10cSrcweir 
1460cdf0e10cSrcweir 	ChangeState( eNewState );
1461cdf0e10cSrcweir 
1462cdf0e10cSrcweir 	// #102907# ------------------------
1463cdf0e10cSrcweir     SFX_ITEMSET_ARG( &rSet, pROItem, SfxBoolItem, SID_DOC_READONLY, sal_False );
1464cdf0e10cSrcweir 	if ( pROItem && pROItem->GetValue() )
1465cdf0e10cSrcweir 	{
1466cdf0e10cSrcweir 		aRBNoAutoUpdate.Disable();
1467cdf0e10cSrcweir 		aRBReloadUpdate.Disable();
1468cdf0e10cSrcweir 		aRBForwardUpdate.Disable();
1469cdf0e10cSrcweir 		aNFReload.Disable();
1470cdf0e10cSrcweir 		aNFAfter.Disable();
1471cdf0e10cSrcweir 		aEDForwardURL.Disable();
1472cdf0e10cSrcweir 		aPBBrowseURL.Disable();
1473cdf0e10cSrcweir 		aCBFrame.Disable();
1474cdf0e10cSrcweir 		aFTEvery.Disable();
1475cdf0e10cSrcweir 		aFTReloadSeconds.Disable();
1476cdf0e10cSrcweir 		aFTAfter.Disable();
1477cdf0e10cSrcweir 		aFTAfterSeconds.Disable();
1478cdf0e10cSrcweir 		aFTURL.Disable();
1479cdf0e10cSrcweir 		aFTFrame.Disable();
1480cdf0e10cSrcweir 	}
1481cdf0e10cSrcweir }
1482cdf0e10cSrcweir 
1483cdf0e10cSrcweir //------------------------------------------------------------------------
1484cdf0e10cSrcweir 
DeactivatePage(SfxItemSet *)1485cdf0e10cSrcweir int SfxInternetPage::DeactivatePage( SfxItemSet* /*pSet*/ )
1486cdf0e10cSrcweir {
1487cdf0e10cSrcweir 	int				nRet = LEAVE_PAGE;
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir 	if( eState == S_Forward && !aEDForwardURL.GetText().Len() )
1490cdf0e10cSrcweir 	{
1491cdf0e10cSrcweir 		ErrorBox	aErrBox( this, WB_OK, aForwardErrorMessg );
1492cdf0e10cSrcweir 		aErrBox.Execute();
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir 		nRet = KEEP_PAGE;
1495cdf0e10cSrcweir 	}
1496cdf0e10cSrcweir 
1497cdf0e10cSrcweir 	return nRet;
1498cdf0e10cSrcweir }
1499cdf0e10cSrcweir 
1500cdf0e10cSrcweir //------------------------------------------------------------------------
1501cdf0e10cSrcweir 
SfxDocumentInfoDialog(Window * pParent,const SfxItemSet & rItemSet)1502cdf0e10cSrcweir SfxDocumentInfoDialog::SfxDocumentInfoDialog( Window* pParent,
1503cdf0e10cSrcweir 											  const SfxItemSet& rItemSet ) :
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir 	SfxTabDialog( 0, pParent, SfxResId( SID_DOCINFO ), &rItemSet )
1506cdf0e10cSrcweir 
1507cdf0e10cSrcweir {
1508cdf0e10cSrcweir 	FreeResource();
1509cdf0e10cSrcweir 
1510cdf0e10cSrcweir 	 const SfxDocumentInfoItem* pInfoItem =
1511cdf0e10cSrcweir 		&(const SfxDocumentInfoItem &)rItemSet.Get( SID_DOCINFO );
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir #ifdef DBG_UTIL
1514cdf0e10cSrcweir     SFX_ITEMSET_ARG( &rItemSet, pURLItem, SfxStringItem, SID_BASEURL, sal_False );
1515cdf0e10cSrcweir     DBG_ASSERT( pURLItem, "No BaseURL provided for InternetTabPage!" );
1516cdf0e10cSrcweir #endif
1517cdf0e10cSrcweir 
1518cdf0e10cSrcweir 	 // Bestimmung des Titels
1519cdf0e10cSrcweir 	const SfxPoolItem* pItem = 0;
1520cdf0e10cSrcweir 	String aTitle( GetText() );
1521cdf0e10cSrcweir 	if ( SFX_ITEM_SET !=
1522cdf0e10cSrcweir 		 rItemSet.GetItemState( SID_EXPLORER_PROPS_START, sal_False, &pItem ) )
1523cdf0e10cSrcweir 	{
1524cdf0e10cSrcweir 		// Dateiname
1525cdf0e10cSrcweir 		String aFile( pInfoItem->GetValue() );
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir 		INetURLObject aURL;
1528cdf0e10cSrcweir 		aURL.SetSmartProtocol( INET_PROT_FILE );
1529cdf0e10cSrcweir 		aURL.SetSmartURL( aFile);
1530cdf0e10cSrcweir 		if ( INET_PROT_PRIV_SOFFICE != aURL.GetProtocol() )
1531cdf0e10cSrcweir 		{
1532cdf0e10cSrcweir 			String aLastName( aURL.GetLastName() );
1533cdf0e10cSrcweir 			if ( aLastName.Len() )
1534cdf0e10cSrcweir 				aTitle += aLastName;
1535cdf0e10cSrcweir 			else
1536cdf0e10cSrcweir 				aTitle += aFile;
1537cdf0e10cSrcweir 		}
1538cdf0e10cSrcweir 		else
1539cdf0e10cSrcweir 			aTitle += String( SfxResId( STR_NONAME ) );
1540cdf0e10cSrcweir 	}
1541cdf0e10cSrcweir 	else
1542cdf0e10cSrcweir 	{
1543cdf0e10cSrcweir 		DBG_ASSERT( pItem->IsA( TYPE( SfxStringItem ) ),
1544cdf0e10cSrcweir 					"SfxDocumentInfoDialog:<SfxStringItem> erwartet" );
1545cdf0e10cSrcweir 		aTitle += ( ( SfxStringItem* ) pItem )->GetValue();
1546cdf0e10cSrcweir 	}
1547cdf0e10cSrcweir 	SetText( aTitle );
1548cdf0e10cSrcweir 
1549cdf0e10cSrcweir 	// Eigenschaftenseiten
1550cdf0e10cSrcweir 	AddTabPage(TP_DOCINFODESC, SfxDocumentDescPage::Create, 0);
1551cdf0e10cSrcweir 	AddTabPage(TP_DOCINFODOC, SfxDocumentPage::Create, 0);
1552cdf0e10cSrcweir     AddTabPage(TP_CUSTOMPROPERTIES, SfxCustomPropertiesPage::Create, 0);
1553cdf0e10cSrcweir     AddTabPage(TP_DOCINFORELOAD, SfxInternetPage::Create, 0);
1554cdf0e10cSrcweir     AddTabPage(TP_DOCINFOSECURITY, SfxSecurityPage::Create, 0);
1555cdf0e10cSrcweir }
1556cdf0e10cSrcweir 
1557cdf0e10cSrcweir // -----------------------------------------------------------------------
1558cdf0e10cSrcweir 
PageCreated(sal_uInt16 nId,SfxTabPage & rPage)1559cdf0e10cSrcweir void SfxDocumentInfoDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
1560cdf0e10cSrcweir {
1561cdf0e10cSrcweir 	if ( TP_DOCINFODOC == nId )
1562cdf0e10cSrcweir 		( (SfxDocumentPage&)rPage ).EnableUseUserData();
1563cdf0e10cSrcweir }
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir // class CustomPropertiesYesNoButton -------------------------------------
1566cdf0e10cSrcweir 
CustomPropertiesYesNoButton(Window * pParent,const ResId & rResId)1567cdf0e10cSrcweir CustomPropertiesYesNoButton::CustomPropertiesYesNoButton( Window* pParent, const ResId& rResId ) :
1568cdf0e10cSrcweir     Control( pParent, rResId ),
1569cdf0e10cSrcweir     m_aYesButton( this, ResId( RB_PROPERTY_YES, *rResId.GetResMgr() ) ),
1570cdf0e10cSrcweir     m_aNoButton ( this, ResId( RB_PROPERTY_NO, *rResId.GetResMgr() ) )
1571cdf0e10cSrcweir {
1572cdf0e10cSrcweir     FreeResource();
1573cdf0e10cSrcweir     Wallpaper aWall( Color( COL_TRANSPARENT ) );
1574cdf0e10cSrcweir     SetBackground( aWall );
1575cdf0e10cSrcweir     SetBorderStyle( WINDOW_BORDER_MONO  );
1576cdf0e10cSrcweir     CheckNo();
1577cdf0e10cSrcweir     m_aYesButton.SetBackground( aWall );
1578cdf0e10cSrcweir     m_aNoButton.SetBackground( aWall );
1579cdf0e10cSrcweir }
1580cdf0e10cSrcweir class DurationDialog_Impl : public ModalDialog
1581cdf0e10cSrcweir {
1582cdf0e10cSrcweir     FixedLine       aDurationFL;
1583cdf0e10cSrcweir 
1584cdf0e10cSrcweir     OKButton        aOKPB;
1585cdf0e10cSrcweir     CancelButton    aCancelPB;
1586cdf0e10cSrcweir     HelpButton      aHelpPB;
1587cdf0e10cSrcweir 
1588cdf0e10cSrcweir     CheckBox        aNegativeCB;
1589cdf0e10cSrcweir     FixedText       aYearFT;
1590cdf0e10cSrcweir     NumericField    aYearNF;
1591cdf0e10cSrcweir     FixedText       aMonthFT;
1592cdf0e10cSrcweir     NumericField    aMonthNF;
1593cdf0e10cSrcweir     FixedText       aDayFT;
1594cdf0e10cSrcweir     NumericField    aDayNF;
1595cdf0e10cSrcweir     FixedText       aHourFT;
1596cdf0e10cSrcweir     NumericField    aHourNF;
1597cdf0e10cSrcweir     FixedText       aMinuteFT;
1598cdf0e10cSrcweir     NumericField    aMinuteNF;
1599cdf0e10cSrcweir     FixedText       aSecondFT;
1600cdf0e10cSrcweir     NumericField    aSecondNF;
1601cdf0e10cSrcweir     FixedText       aMSecondFT;
1602cdf0e10cSrcweir     NumericField    aMSecondNF;
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir public:
1605cdf0e10cSrcweir 
1606cdf0e10cSrcweir     DurationDialog_Impl( Window* pParent, const util::Duration& rDuration );
1607cdf0e10cSrcweir     ~DurationDialog_Impl();
1608cdf0e10cSrcweir 
1609cdf0e10cSrcweir     util::Duration  GetDuration() const;
1610cdf0e10cSrcweir };
1611cdf0e10cSrcweir /*-- 20.11.2009 15:40:46---------------------------------------------------
1612cdf0e10cSrcweir 
1613cdf0e10cSrcweir   -----------------------------------------------------------------------*/
DurationDialog_Impl(Window * pParent,const util::Duration & rDuration)1614cdf0e10cSrcweir DurationDialog_Impl::DurationDialog_Impl(
1615cdf0e10cSrcweir     Window* pParent, const util::Duration& rDuration)
1616cdf0e10cSrcweir         :   ModalDialog( pParent, SfxResId( RID_EDIT_DURATIONS ) ),
1617cdf0e10cSrcweir             aDurationFL(this, SfxResId( FL_DURATION       )),
1618cdf0e10cSrcweir             aOKPB(      this, SfxResId( PB_OK       )),
1619cdf0e10cSrcweir             aCancelPB(  this, SfxResId( PB_CANCEL   )),
1620cdf0e10cSrcweir             aHelpPB(    this, SfxResId( PB_HELP     )),
1621cdf0e10cSrcweir             aNegativeCB(this, SfxResId( CB_NEGATIVE     )),
1622cdf0e10cSrcweir             aYearFT(    this, SfxResId( FT_YEAR         )),
1623cdf0e10cSrcweir             aYearNF(    this, SfxResId( ED_YEAR         )),
1624cdf0e10cSrcweir             aMonthFT(   this, SfxResId( FT_MONTH        )),
1625cdf0e10cSrcweir             aMonthNF(   this, SfxResId( ED_MONTH        )),
1626cdf0e10cSrcweir             aDayFT(     this, SfxResId( FT_DAY          )),
1627cdf0e10cSrcweir             aDayNF(     this, SfxResId( ED_DAY          )),
1628cdf0e10cSrcweir             aHourFT(    this, SfxResId( FT_HOUR         )),
1629cdf0e10cSrcweir             aHourNF(    this, SfxResId( ED_HOUR         )),
1630cdf0e10cSrcweir             aMinuteFT(  this, SfxResId( FT_MINUTE       )),
1631cdf0e10cSrcweir             aMinuteNF(  this, SfxResId( ED_MINUTE       )),
1632cdf0e10cSrcweir             aSecondFT(  this, SfxResId( FT_SECOND       )),
1633cdf0e10cSrcweir             aSecondNF(  this, SfxResId( ED_SECOND       )),
1634cdf0e10cSrcweir             aMSecondFT( this, SfxResId( FT_MSECOND      )),
1635cdf0e10cSrcweir             aMSecondNF( this, SfxResId( ED_MSECOND      ))
1636cdf0e10cSrcweir {
1637cdf0e10cSrcweir     FreeResource();
1638cdf0e10cSrcweir     aNegativeCB.Check(rDuration.Negative);
1639cdf0e10cSrcweir     aYearNF.SetValue(rDuration.Years);
1640cdf0e10cSrcweir     aMonthNF.SetValue(rDuration.Months );
1641cdf0e10cSrcweir     aDayNF.SetValue(rDuration.Days   );
1642cdf0e10cSrcweir     aHourNF.SetValue(rDuration.Hours  );
1643cdf0e10cSrcweir     aMinuteNF.SetValue(rDuration.Minutes);
1644cdf0e10cSrcweir     aSecondNF.SetValue(rDuration.Seconds);
1645cdf0e10cSrcweir     aMSecondNF.SetValue(rDuration.MilliSeconds);
1646cdf0e10cSrcweir }
1647cdf0e10cSrcweir /*-- 20.11.2009 16:08:55---------------------------------------------------
1648cdf0e10cSrcweir 
1649cdf0e10cSrcweir   -----------------------------------------------------------------------*/
~DurationDialog_Impl()1650cdf0e10cSrcweir DurationDialog_Impl::~DurationDialog_Impl()
1651cdf0e10cSrcweir {
1652cdf0e10cSrcweir }
1653cdf0e10cSrcweir /*-- 20.11.2009 15:41:47---------------------------------------------------
1654cdf0e10cSrcweir 
1655cdf0e10cSrcweir   -----------------------------------------------------------------------*/
GetDuration() const1656cdf0e10cSrcweir util::Duration  DurationDialog_Impl::GetDuration() const
1657cdf0e10cSrcweir {
1658cdf0e10cSrcweir     util::Duration  aRet;
1659cdf0e10cSrcweir     aRet.Negative = aNegativeCB.IsChecked();
1660cdf0e10cSrcweir     aRet.Years = aYearNF.GetValue();
1661cdf0e10cSrcweir     aRet.Months = aMonthNF.GetValue( );
1662cdf0e10cSrcweir     aRet.Days = aDayNF.GetValue(   );
1663cdf0e10cSrcweir     aRet.Hours  = aHourNF.GetValue( );
1664cdf0e10cSrcweir     aRet.Minutes = aMinuteNF.GetValue();
1665cdf0e10cSrcweir     aRet.Seconds = aSecondNF.GetValue();
1666cdf0e10cSrcweir     aRet.MilliSeconds = aMSecondNF.GetValue();
1667cdf0e10cSrcweir     return aRet;
1668cdf0e10cSrcweir }
1669cdf0e10cSrcweir 
1670cdf0e10cSrcweir /*-- 20.11.2009 15:30:58---------------------------------------------------
1671cdf0e10cSrcweir 
1672cdf0e10cSrcweir   -----------------------------------------------------------------------*/
CustomPropertiesDurationField(Window * pParent,const ResId & rResId,CustomPropertyLine * pLine)1673cdf0e10cSrcweir CustomPropertiesDurationField::CustomPropertiesDurationField( Window* pParent, const ResId& rResId, CustomPropertyLine* pLine ) :
1674cdf0e10cSrcweir         Edit( pParent, rResId ), m_pLine( pLine )
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir {
1677cdf0e10cSrcweir     SetDuration( util::Duration(false, 0, 0, 0, 0, 0, 0, 0) );
1678cdf0e10cSrcweir }
1679cdf0e10cSrcweir /*-- 23.11.2009 08:46:02---------------------------------------------------
1680cdf0e10cSrcweir 
1681cdf0e10cSrcweir   -----------------------------------------------------------------------*/
~CustomPropertiesDurationField()1682cdf0e10cSrcweir CustomPropertiesDurationField::~CustomPropertiesDurationField()
1683cdf0e10cSrcweir {
1684cdf0e10cSrcweir }
1685cdf0e10cSrcweir /*-- 23.11.2009 09:23:35---------------------------------------------------
1686cdf0e10cSrcweir 
1687cdf0e10cSrcweir   -----------------------------------------------------------------------*/
RequestHelp(const HelpEvent & rHEvt)1688cdf0e10cSrcweir void CustomPropertiesDurationField::RequestHelp( const HelpEvent& rHEvt )
1689cdf0e10cSrcweir {
1690cdf0e10cSrcweir     if( rHEvt.GetMode() & HELPMODE_QUICK )
1691cdf0e10cSrcweir     {
1692cdf0e10cSrcweir         Size aSize( GetSizePixel() );
1693cdf0e10cSrcweir         Rectangle aItemRect( rHEvt.GetMousePosPixel(), aSize );
1694cdf0e10cSrcweir         if(Help::IsBalloonHelpEnabled())
1695cdf0e10cSrcweir             Help::ShowBalloon( this, rHEvt.GetMousePosPixel(), GetText() );
1696cdf0e10cSrcweir         else
1697cdf0e10cSrcweir             Help::ShowQuickHelp( this, aItemRect, GetText(),
1698cdf0e10cSrcweir                 QUICKHELP_LEFT|QUICKHELP_VCENTER );
1699cdf0e10cSrcweir     }
1700cdf0e10cSrcweir }
1701cdf0e10cSrcweir /*-- 20.11.2009 15:30:58---------------------------------------------------
1702cdf0e10cSrcweir 
1703cdf0e10cSrcweir   -----------------------------------------------------------------------*/
SetDuration(const util::Duration & rDuration)1704cdf0e10cSrcweir void CustomPropertiesDurationField::SetDuration( const util::Duration& rDuration )
1705cdf0e10cSrcweir {
1706cdf0e10cSrcweir     m_aDuration = rDuration;
1707cdf0e10cSrcweir     String sText(rDuration.Negative ? '-' : '+');
1708cdf0e10cSrcweir     sText += m_pLine->m_sDurationFormat;
1709cdf0e10cSrcweir     sText.SearchAndReplace(String::CreateFromAscii( "%1"), String::CreateFromInt32( rDuration.Years ) );
1710cdf0e10cSrcweir     sText.SearchAndReplace(String::CreateFromAscii( "%2"), String::CreateFromInt32( rDuration.Months ) );
1711cdf0e10cSrcweir     sText.SearchAndReplace(String::CreateFromAscii( "%3"), String::CreateFromInt32( rDuration.Days   ) );
1712cdf0e10cSrcweir     sText.SearchAndReplace(String::CreateFromAscii( "%4"), String::CreateFromInt32( rDuration.Hours  ) );
1713cdf0e10cSrcweir     sText.SearchAndReplace(String::CreateFromAscii( "%5"), String::CreateFromInt32( rDuration.Minutes) );
1714cdf0e10cSrcweir     sText.SearchAndReplace(String::CreateFromAscii( "%6"), String::CreateFromInt32( rDuration.Seconds) );
1715cdf0e10cSrcweir     SetText( sText );
1716cdf0e10cSrcweir }
1717cdf0e10cSrcweir /*-- 23.11.2009 08:51:15---------------------------------------------------
1718cdf0e10cSrcweir 
1719cdf0e10cSrcweir   -----------------------------------------------------------------------*/
CustomPropertiesEditButton(Window * pParent,const ResId & rResId,CustomPropertyLine * pLine)1720cdf0e10cSrcweir CustomPropertiesEditButton::CustomPropertiesEditButton( Window* pParent, const ResId& rResId, CustomPropertyLine* pLine ) :
1721cdf0e10cSrcweir         PushButton( pParent, rResId ), m_pLine( pLine )
1722cdf0e10cSrcweir {
1723cdf0e10cSrcweir     SetClickHdl( LINK( this, CustomPropertiesEditButton, ClickHdl ));
1724cdf0e10cSrcweir }
1725cdf0e10cSrcweir /*-- 23.11.2009 08:51:15---------------------------------------------------
1726cdf0e10cSrcweir 
1727cdf0e10cSrcweir   -----------------------------------------------------------------------*/
~CustomPropertiesEditButton()1728cdf0e10cSrcweir CustomPropertiesEditButton::~CustomPropertiesEditButton()
1729cdf0e10cSrcweir {
1730cdf0e10cSrcweir }
1731cdf0e10cSrcweir /*-- 23.11.2009 08:47:37---------------------------------------------------
1732cdf0e10cSrcweir 
1733cdf0e10cSrcweir   -----------------------------------------------------------------------*/
IMPL_LINK(CustomPropertiesEditButton,ClickHdl,PushButton *,EMPTYARG)1734cdf0e10cSrcweir IMPL_LINK( CustomPropertiesEditButton, ClickHdl, PushButton*, EMPTYARG )
1735cdf0e10cSrcweir {
1736cdf0e10cSrcweir     DurationDialog_Impl* pDurationDlg = new DurationDialog_Impl( this, m_pLine->m_aDurationField.GetDuration() );
1737cdf0e10cSrcweir     if( RET_OK == pDurationDlg->Execute() )
1738cdf0e10cSrcweir         m_pLine->m_aDurationField.SetDuration( pDurationDlg->GetDuration() );
1739cdf0e10cSrcweir     delete pDurationDlg;
1740cdf0e10cSrcweir     return 1;
1741cdf0e10cSrcweir }
1742cdf0e10cSrcweir //--------------------------------------------------------------------------
Resize()1743cdf0e10cSrcweir void CustomPropertiesYesNoButton::Resize()
1744cdf0e10cSrcweir {
1745cdf0e10cSrcweir     const long nWidth = GetSizePixel().Width();
1746cdf0e10cSrcweir     const long n3Width = LogicToPixel( Size( 3, 3 ), MAP_APPFONT ).Width();
1747cdf0e10cSrcweir     const long nNewWidth = ( nWidth / 2 ) - n3Width - 2;
1748cdf0e10cSrcweir     Size aSize = m_aYesButton.GetSizePixel();
1749cdf0e10cSrcweir     const long nDelta = aSize.Width() - nNewWidth;
1750cdf0e10cSrcweir     aSize.Width() = nNewWidth;
1751cdf0e10cSrcweir     m_aYesButton.SetSizePixel( aSize );
1752cdf0e10cSrcweir     Point aPos = m_aNoButton.GetPosPixel();
1753cdf0e10cSrcweir     aPos.X() -= nDelta;
1754cdf0e10cSrcweir     m_aNoButton.SetPosSizePixel( aPos, aSize );
1755cdf0e10cSrcweir }
1756cdf0e10cSrcweir 
1757cdf0e10cSrcweir // struct CustomPropertyLine ---------------------------------------------
1758cdf0e10cSrcweir 
CustomPropertyLine(Window * pParent)1759cdf0e10cSrcweir CustomPropertyLine::CustomPropertyLine( Window* pParent ) :
1760cdf0e10cSrcweir     m_aNameBox      ( pParent, SfxResId( SFX_CB_PROPERTY_NAME ) ),
1761cdf0e10cSrcweir     m_aTypeBox      ( pParent, SfxResId( SFX_LB_PROPERTY_TYPE ), this ),
1762cdf0e10cSrcweir     m_aValueEdit    ( pParent, SfxResId( SFX_ED_PROPERTY_VALUE ), this ),
1763cdf0e10cSrcweir     m_aDateField    ( pParent, SfxResId( SFX_FLD_DATE), this),
1764cdf0e10cSrcweir     m_aTimeField    ( pParent, SfxResId( SFX_FLD_TIME), this),
1765cdf0e10cSrcweir     m_sDurationFormat( SfxResId( SFX_ST_DURATION_FORMAT )),
1766cdf0e10cSrcweir     m_aDurationField( pParent, SfxResId( SFX_FLD_DURATION), this),
1767cdf0e10cSrcweir     m_aEditButton(    pParent, SfxResId( SFX_PB_EDIT ), this),
1768cdf0e10cSrcweir     m_aYesNoButton  ( pParent, SfxResId( SFX_WIN_PROPERTY_YESNO ) ),
1769cdf0e10cSrcweir     m_aRemoveButton ( pParent, SfxResId( SFX_PB_PROPERTY_REMOVE ), this ),
1770cdf0e10cSrcweir     m_bIsRemoved    ( false ),
1771cdf0e10cSrcweir     m_bTypeLostFocus( false )
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir {
1774cdf0e10cSrcweir     m_aTimeField.SetExtFormat( EXTTIMEF_24H_LONG );
1775cdf0e10cSrcweir     m_aDateField.SetExtDateFormat( XTDATEF_SYSTEM_SHORT_YYYY );
1776cdf0e10cSrcweir 
1777cdf0e10cSrcweir     m_aRemoveButton.SetModeImage( SfxResId( SFX_IMG_PROPERTY_REMOVE ), BMP_COLOR_NORMAL );
1778cdf0e10cSrcweir     m_aRemoveButton.SetModeImage( SfxResId( SFX_IMG_PROPERTY_REMOVE_HC ), BMP_COLOR_HIGHCONTRAST );
1779cdf0e10cSrcweir }
1780cdf0e10cSrcweir 
SetRemoved()1781cdf0e10cSrcweir void CustomPropertyLine::SetRemoved()
1782cdf0e10cSrcweir {
1783cdf0e10cSrcweir     DBG_ASSERT( !m_bIsRemoved, "CustomPropertyLine::SetRemoved(): line already removed" );
1784cdf0e10cSrcweir     m_bIsRemoved = true;
1785cdf0e10cSrcweir     m_aNameBox.Hide();
1786cdf0e10cSrcweir     m_aTypeBox.Hide();
1787cdf0e10cSrcweir     m_aValueEdit.Hide();
1788cdf0e10cSrcweir     m_aDateField.Hide();
1789cdf0e10cSrcweir     m_aTimeField.Hide();
1790cdf0e10cSrcweir     m_aDurationField.Hide();
1791cdf0e10cSrcweir     m_aEditButton.Hide();
1792cdf0e10cSrcweir     m_aYesNoButton.Hide();
1793cdf0e10cSrcweir     m_aRemoveButton.Hide();
1794cdf0e10cSrcweir }
1795cdf0e10cSrcweir 
1796cdf0e10cSrcweir // class CustomPropertiesWindow ------------------------------------------
1797cdf0e10cSrcweir 
CustomPropertiesWindow(Window * pParent,const ResId & rResId)1798cdf0e10cSrcweir CustomPropertiesWindow::CustomPropertiesWindow( Window* pParent, const ResId& rResId ) :
1799cdf0e10cSrcweir 
1800cdf0e10cSrcweir     Window( pParent, rResId ),
1801cdf0e10cSrcweir     m_aNameBox      ( this, SfxResId( SFX_CB_PROPERTY_NAME ) ),
1802cdf0e10cSrcweir     m_aTypeBox      ( this, SfxResId( SFX_LB_PROPERTY_TYPE ) ),
1803cdf0e10cSrcweir     m_aValueEdit    ( this, SfxResId( SFX_ED_PROPERTY_VALUE ) ),
1804cdf0e10cSrcweir     m_aDateField    ( this, SfxResId( SFX_FLD_DATE) ),
1805cdf0e10cSrcweir     m_aTimeField    ( this, SfxResId( SFX_FLD_TIME) ),
1806cdf0e10cSrcweir     m_aDurationField( this, SfxResId( SFX_FLD_DURATION) ),
1807cdf0e10cSrcweir     m_aEditButton(    this, SfxResId( SFX_PB_EDIT )),
1808cdf0e10cSrcweir     m_aYesNoButton  ( this, SfxResId( SFX_WIN_PROPERTY_YESNO ) ),
1809cdf0e10cSrcweir     m_aRemoveButton ( this, SfxResId( SFX_PB_PROPERTY_REMOVE ) ),
1810cdf0e10cSrcweir 	m_nScrollPos (0),
1811cdf0e10cSrcweir     m_aNumberFormatter( ::comphelper::getProcessServiceFactory(),
1812cdf0e10cSrcweir                         Application::GetSettings().GetLanguage() )
1813cdf0e10cSrcweir 
1814cdf0e10cSrcweir {
1815cdf0e10cSrcweir     m_aEditLoseFocusTimer.SetTimeout( 300 );
1816cdf0e10cSrcweir     m_aEditLoseFocusTimer.SetTimeoutHdl( LINK( this, CustomPropertiesWindow, EditTimeoutHdl ) );
1817cdf0e10cSrcweir     m_aBoxLoseFocusTimer.SetTimeout( 300 );
1818cdf0e10cSrcweir     m_aBoxLoseFocusTimer.SetTimeoutHdl( LINK( this, CustomPropertiesWindow, BoxTimeoutHdl ) );
1819cdf0e10cSrcweir 
1820cdf0e10cSrcweir 	ResMgr* pResMgr = rResId.GetResMgr();
1821cdf0e10cSrcweir 	m_aNameBox.SetAccessibleName( String( ResId( STR_HEADER_NAME, *pResMgr ) ) );
1822cdf0e10cSrcweir 	m_aTypeBox.SetAccessibleName( String( ResId( STR_HEADER_TYPE, *pResMgr ) ) );
1823cdf0e10cSrcweir 	m_aValueEdit.SetAccessibleName( String( ResId( STR_HEADER_VALUE, *pResMgr ) ) );
1824cdf0e10cSrcweir }
1825cdf0e10cSrcweir 
~CustomPropertiesWindow()1826cdf0e10cSrcweir CustomPropertiesWindow::~CustomPropertiesWindow()
1827cdf0e10cSrcweir {
1828cdf0e10cSrcweir     m_aEditLoseFocusTimer.Stop();
1829cdf0e10cSrcweir     m_aBoxLoseFocusTimer.Stop();
1830cdf0e10cSrcweir     ClearAllLines();
1831cdf0e10cSrcweir }
1832cdf0e10cSrcweir 
IMPL_LINK(CustomPropertiesWindow,TypeHdl,CustomPropertiesTypeBox *,pBox)1833cdf0e10cSrcweir IMPL_LINK( CustomPropertiesWindow, TypeHdl, CustomPropertiesTypeBox*, pBox )
1834cdf0e10cSrcweir {
1835cdf0e10cSrcweir     sal_Int64 nType = sal_Int64( (long)pBox->GetEntryData( pBox->GetSelectEntryPos() ) );
1836cdf0e10cSrcweir     CustomPropertyLine* pLine = pBox->GetLine();
1837cdf0e10cSrcweir     pLine->m_aValueEdit.Show( (CUSTOM_TYPE_TEXT == nType) || (CUSTOM_TYPE_NUMBER  == nType) );
1838cdf0e10cSrcweir     pLine->m_aDateField.Show( (CUSTOM_TYPE_DATE == nType) || (CUSTOM_TYPE_DATETIME  == nType) );
1839cdf0e10cSrcweir     pLine->m_aTimeField.Show( CUSTOM_TYPE_DATETIME  == nType );
1840cdf0e10cSrcweir     pLine->m_aDurationField.Show( CUSTOM_TYPE_DURATION == nType );
1841cdf0e10cSrcweir     pLine->m_aEditButton.Show( CUSTOM_TYPE_DURATION == nType );
1842cdf0e10cSrcweir     pLine->m_aYesNoButton.Show( CUSTOM_TYPE_BOOLEAN == nType );
1843cdf0e10cSrcweir     //adjust positions of date and time controls
1844cdf0e10cSrcweir     if( nType == CUSTOM_TYPE_DATE )
1845cdf0e10cSrcweir     {
1846cdf0e10cSrcweir         pLine->m_aDateField.SetPosSizePixel(pLine->m_aValueEdit.GetPosPixel(), pLine->m_aValueEdit.GetSizePixel());
1847cdf0e10cSrcweir     }
1848cdf0e10cSrcweir     else if( nType == CUSTOM_TYPE_DATETIME)
1849cdf0e10cSrcweir     {
1850*c3916d03SAriel Constenla-Haile         const long nPosY( pLine->m_aDateField.GetPosPixel().Y() );
1851*c3916d03SAriel Constenla-Haile         pLine->m_aDateField.SetPosPixel( ::Point( m_nDatePosX, nPosY ) );
1852*c3916d03SAriel Constenla-Haile         pLine->m_aTimeField.SetPosPixel( ::Point( m_nTimePosX, nPosY ) );
1853cdf0e10cSrcweir     }
1854cdf0e10cSrcweir 
1855cdf0e10cSrcweir     return 0;
1856cdf0e10cSrcweir }
1857cdf0e10cSrcweir 
IMPL_LINK(CustomPropertiesWindow,RemoveHdl,CustomPropertiesRemoveButton *,pButton)1858cdf0e10cSrcweir IMPL_LINK( CustomPropertiesWindow, RemoveHdl, CustomPropertiesRemoveButton*, pButton )
1859cdf0e10cSrcweir {
1860cdf0e10cSrcweir     CustomPropertyLine* pLine = pButton->GetLine();
1861cdf0e10cSrcweir     std::vector< CustomPropertyLine* >::iterator pFound =
1862cdf0e10cSrcweir         std::find( m_aCustomPropertiesLines.begin(), m_aCustomPropertiesLines.end(), pLine );
1863cdf0e10cSrcweir     if ( pFound != m_aCustomPropertiesLines.end() )
1864cdf0e10cSrcweir     {
1865cdf0e10cSrcweir         pLine = *pFound;
1866cdf0e10cSrcweir         pLine->SetRemoved();
1867cdf0e10cSrcweir         std::vector< CustomPropertyLine* >::iterator pIter = pFound + 1;
1868cdf0e10cSrcweir         const long nDelta = GetLineHeight();
1869cdf0e10cSrcweir         for ( ; pIter != m_aCustomPropertiesLines.end(); ++pIter )
1870cdf0e10cSrcweir         {
1871cdf0e10cSrcweir             pLine = *pIter;
1872cdf0e10cSrcweir             if ( pLine->m_bIsRemoved )
1873cdf0e10cSrcweir                 continue;
1874cdf0e10cSrcweir 
1875*c3916d03SAriel Constenla-Haile             Window* pWindows[] = {  &pLine->m_aNameBox,
1876*c3916d03SAriel Constenla-Haile                                     &pLine->m_aTypeBox,
1877*c3916d03SAriel Constenla-Haile                                     &pLine->m_aValueEdit,
1878*c3916d03SAriel Constenla-Haile                                     &pLine->m_aDateField,
1879*c3916d03SAriel Constenla-Haile                                     &pLine->m_aTimeField,
1880*c3916d03SAriel Constenla-Haile                                     &pLine->m_aDurationField,
1881*c3916d03SAriel Constenla-Haile                                     &pLine->m_aEditButton,
1882*c3916d03SAriel Constenla-Haile                                     &pLine->m_aYesNoButton,
1883*c3916d03SAriel Constenla-Haile                                     &pLine->m_aRemoveButton, NULL };
1884cdf0e10cSrcweir             Window** pCurrent = pWindows;
1885cdf0e10cSrcweir             while ( *pCurrent )
1886cdf0e10cSrcweir             {
1887cdf0e10cSrcweir                 Point aPos = (*pCurrent)->GetPosPixel();
1888cdf0e10cSrcweir                 aPos.Y() -= nDelta;
1889cdf0e10cSrcweir                 (*pCurrent)->SetPosPixel( aPos );
1890cdf0e10cSrcweir                 pCurrent++;
1891cdf0e10cSrcweir             }
1892cdf0e10cSrcweir         }
1893cdf0e10cSrcweir     }
1894cdf0e10cSrcweir 
1895cdf0e10cSrcweir 	m_aRemovedHdl.Call(0);
1896cdf0e10cSrcweir     return 0;
1897cdf0e10cSrcweir }
1898cdf0e10cSrcweir 
IMPL_LINK(CustomPropertiesWindow,EditLoseFocusHdl,CustomPropertiesEdit *,pEdit)1899cdf0e10cSrcweir IMPL_LINK( CustomPropertiesWindow, EditLoseFocusHdl, CustomPropertiesEdit*, pEdit )
1900cdf0e10cSrcweir {
1901cdf0e10cSrcweir     if ( pEdit )
1902cdf0e10cSrcweir     {
1903cdf0e10cSrcweir         CustomPropertyLine* pLine = pEdit->GetLine();
1904cdf0e10cSrcweir         if ( !pLine->m_bTypeLostFocus )
1905cdf0e10cSrcweir         {
1906cdf0e10cSrcweir             m_pCurrentLine = pLine;
1907cdf0e10cSrcweir             m_aEditLoseFocusTimer.Start();
1908cdf0e10cSrcweir         }
1909cdf0e10cSrcweir         else
1910cdf0e10cSrcweir             pLine->m_bTypeLostFocus = false;
1911cdf0e10cSrcweir     }
1912cdf0e10cSrcweir     return 0;
1913cdf0e10cSrcweir }
1914cdf0e10cSrcweir 
IMPL_LINK(CustomPropertiesWindow,BoxLoseFocusHdl,CustomPropertiesTypeBox *,pBox)1915cdf0e10cSrcweir IMPL_LINK( CustomPropertiesWindow, BoxLoseFocusHdl, CustomPropertiesTypeBox*, pBox )
1916cdf0e10cSrcweir {
1917cdf0e10cSrcweir     if ( pBox )
1918cdf0e10cSrcweir     {
1919cdf0e10cSrcweir         m_pCurrentLine = pBox->GetLine();
1920cdf0e10cSrcweir         m_aBoxLoseFocusTimer.Start();
1921cdf0e10cSrcweir     }
1922cdf0e10cSrcweir 
1923cdf0e10cSrcweir     return 0;
1924cdf0e10cSrcweir }
1925cdf0e10cSrcweir 
IMPL_LINK(CustomPropertiesWindow,EditTimeoutHdl,Timer *,EMPTYARG)1926cdf0e10cSrcweir IMPL_LINK( CustomPropertiesWindow, EditTimeoutHdl, Timer*, EMPTYARG )
1927cdf0e10cSrcweir {
1928cdf0e10cSrcweir     ValidateLine( m_pCurrentLine, false );
1929cdf0e10cSrcweir     return 0;
1930cdf0e10cSrcweir }
1931cdf0e10cSrcweir 
IMPL_LINK(CustomPropertiesWindow,BoxTimeoutHdl,Timer *,EMPTYARG)1932cdf0e10cSrcweir IMPL_LINK( CustomPropertiesWindow, BoxTimeoutHdl, Timer*, EMPTYARG )
1933cdf0e10cSrcweir {
1934cdf0e10cSrcweir     ValidateLine( m_pCurrentLine, true );
1935cdf0e10cSrcweir     return 0;
1936cdf0e10cSrcweir }
1937cdf0e10cSrcweir 
IsLineValid(CustomPropertyLine * pLine) const1938cdf0e10cSrcweir bool CustomPropertiesWindow::IsLineValid( CustomPropertyLine* pLine ) const
1939cdf0e10cSrcweir {
1940cdf0e10cSrcweir     bool bIsValid = true;
1941cdf0e10cSrcweir     pLine->m_bTypeLostFocus = false;
1942cdf0e10cSrcweir     sal_Int64 nType = sal_Int64(
1943cdf0e10cSrcweir         (long)pLine->m_aTypeBox.GetEntryData( pLine->m_aTypeBox.GetSelectEntryPos() ) );
1944cdf0e10cSrcweir     String sValue = pLine->m_aValueEdit.GetText();
1945cdf0e10cSrcweir     if ( sValue.Len() == 0 )
1946cdf0e10cSrcweir         return true;
1947cdf0e10cSrcweir 
1948cdf0e10cSrcweir     double fDummy = 0.0;
1949cdf0e10cSrcweir     sal_uInt32 nIndex = 0xFFFFFFFF;
1950cdf0e10cSrcweir     if ( CUSTOM_TYPE_NUMBER == nType )
1951cdf0e10cSrcweir         nIndex = const_cast< SvNumberFormatter& >(
1952cdf0e10cSrcweir             m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM );
1953cdf0e10cSrcweir     else if ( CUSTOM_TYPE_DATE == nType )
1954cdf0e10cSrcweir         nIndex = const_cast< SvNumberFormatter& >(
1955cdf0e10cSrcweir             m_aNumberFormatter).GetFormatIndex( NF_DATE_SYS_DDMMYYYY );
1956cdf0e10cSrcweir 
1957cdf0e10cSrcweir     if ( nIndex != 0xFFFFFFFF )
1958cdf0e10cSrcweir     {
1959cdf0e10cSrcweir         sal_uInt32 nTemp = nIndex;
1960cdf0e10cSrcweir         bIsValid = const_cast< SvNumberFormatter& >(
1961cdf0e10cSrcweir             m_aNumberFormatter ).IsNumberFormat( sValue, nIndex, fDummy ) != sal_False;
1962cdf0e10cSrcweir         if ( bIsValid && nTemp != nIndex )
1963cdf0e10cSrcweir             // sValue is a number but the format doesn't match the index
1964cdf0e10cSrcweir             bIsValid = false;
1965cdf0e10cSrcweir     }
1966cdf0e10cSrcweir 
1967cdf0e10cSrcweir     return bIsValid;
1968cdf0e10cSrcweir }
1969cdf0e10cSrcweir 
ValidateLine(CustomPropertyLine * pLine,bool bIsFromTypeBox)1970cdf0e10cSrcweir void CustomPropertiesWindow::ValidateLine( CustomPropertyLine* pLine, bool bIsFromTypeBox )
1971cdf0e10cSrcweir {
1972cdf0e10cSrcweir     if ( !IsLineValid( pLine ) )
1973cdf0e10cSrcweir     {
1974cdf0e10cSrcweir         if ( bIsFromTypeBox ) // LoseFocus of TypeBox
1975cdf0e10cSrcweir             pLine->m_bTypeLostFocus = true;
1976cdf0e10cSrcweir         Window* pParent = GetParent()->GetParent();
1977cdf0e10cSrcweir         if ( QueryBox( pParent, SfxResId( SFX_QB_WRONG_TYPE ) ).Execute() == RET_OK )
1978cdf0e10cSrcweir             pLine->m_aTypeBox.SelectEntryPos( m_aTypeBox.GetEntryPos( (void*)CUSTOM_TYPE_TEXT ) );
1979cdf0e10cSrcweir         else
1980cdf0e10cSrcweir             pLine->m_aValueEdit.GrabFocus();
1981cdf0e10cSrcweir     }
1982cdf0e10cSrcweir }
1983cdf0e10cSrcweir 
InitControls(HeaderBar * pHeaderBar,const ScrollBar * pScrollBar)1984cdf0e10cSrcweir void CustomPropertiesWindow::InitControls( HeaderBar* pHeaderBar, const ScrollBar* pScrollBar )
1985cdf0e10cSrcweir {
1986cdf0e10cSrcweir     DBG_ASSERT( pHeaderBar, "CustomPropertiesWindow::InitControls(): invalid headerbar" );
1987cdf0e10cSrcweir     DBG_ASSERT( pScrollBar, "CustomPropertiesWindow::InitControls(): invalid scrollbar" );
1988cdf0e10cSrcweir 
1989cdf0e10cSrcweir     m_aNameBox.Hide();
1990cdf0e10cSrcweir     m_aTypeBox.Hide();
1991cdf0e10cSrcweir     m_aValueEdit.Hide();
1992cdf0e10cSrcweir     m_aDateField.Hide();
1993cdf0e10cSrcweir     m_aTimeField.Hide();
1994cdf0e10cSrcweir     m_aDurationField.Hide();
1995cdf0e10cSrcweir     m_aEditButton.Hide();
1996cdf0e10cSrcweir     m_aYesNoButton.Hide();
1997cdf0e10cSrcweir     m_aRemoveButton.Hide();
1998cdf0e10cSrcweir 
1999cdf0e10cSrcweir     const long nOffset = 4;
2000cdf0e10cSrcweir     const long nScrollBarWidth = pScrollBar->GetSizePixel().Width();
2001cdf0e10cSrcweir     const long nButtonWidth = m_aRemoveButton.GetSizePixel().Width() + nScrollBarWidth + nOffset;
2002cdf0e10cSrcweir     long nTypeWidth = m_aTypeBox.CalcMinimumSize().Width() + ( 2 * nOffset );
2003cdf0e10cSrcweir     long nFullWidth = pHeaderBar->GetSizePixel().Width();
2004cdf0e10cSrcweir     long nItemWidth = ( nFullWidth - nTypeWidth - nButtonWidth ) / 2;
2005cdf0e10cSrcweir     pHeaderBar->SetItemSize( HI_NAME, nItemWidth );
2006cdf0e10cSrcweir     pHeaderBar->SetItemSize( HI_TYPE, nTypeWidth );
2007cdf0e10cSrcweir     pHeaderBar->SetItemSize( HI_VALUE, nItemWidth );
2008cdf0e10cSrcweir     pHeaderBar->SetItemSize( HI_ACTION, nButtonWidth );
2009cdf0e10cSrcweir 
2010cdf0e10cSrcweir     Window* pWindows[] = { &m_aNameBox, &m_aTypeBox, &m_aValueEdit, &m_aRemoveButton, NULL };
2011cdf0e10cSrcweir     Window** pCurrent = pWindows;
2012cdf0e10cSrcweir     sal_uInt16 nPos = 0;
2013cdf0e10cSrcweir     while ( *pCurrent )
2014cdf0e10cSrcweir     {
2015cdf0e10cSrcweir         Rectangle aRect = pHeaderBar->GetItemRect( pHeaderBar->GetItemId( nPos++ ) );
2016cdf0e10cSrcweir         Size aSize = (*pCurrent)->GetSizePixel();
2017cdf0e10cSrcweir         Point aPos = (*pCurrent)->GetPosPixel();
2018cdf0e10cSrcweir         long nWidth = aRect.getWidth() - nOffset;
2019cdf0e10cSrcweir         if ( *pCurrent == &m_aRemoveButton )
2020cdf0e10cSrcweir             nWidth -= pScrollBar->GetSizePixel().Width();
2021cdf0e10cSrcweir         aSize.Width() = nWidth;
2022cdf0e10cSrcweir         aPos.X() = aRect.getX() + ( nOffset / 2 );
2023cdf0e10cSrcweir         (*pCurrent)->SetPosSizePixel( aPos, aSize );
2024cdf0e10cSrcweir 
2025cdf0e10cSrcweir         if ( *pCurrent == &m_aValueEdit )
2026cdf0e10cSrcweir         {
2027cdf0e10cSrcweir             Point aDurationPos( aPos );
2028cdf0e10cSrcweir             m_aDurationField.SetPosPixel( aDurationPos );
2029cdf0e10cSrcweir             Size aDurationSize(aSize);
2030cdf0e10cSrcweir             aDurationSize.Width() -= (m_aEditButton.GetSizePixel().Width() + 3 );
2031cdf0e10cSrcweir             m_aDurationField.SetSizePixel(aDurationSize);
2032cdf0e10cSrcweir             aDurationPos.X() = aPos.X() - m_aEditButton.GetSizePixel().Width() + aSize.Width();
2033cdf0e10cSrcweir             m_aEditButton.SetPosPixel(aDurationPos);
2034cdf0e10cSrcweir             aSize = m_aYesNoButton.GetSizePixel();
2035cdf0e10cSrcweir             aPos = m_aYesNoButton.GetPosPixel();
2036cdf0e10cSrcweir             aSize.Width() = nWidth;
2037cdf0e10cSrcweir             aPos.X() = aRect.getX() + ( nOffset / 2 );
2038cdf0e10cSrcweir             m_aYesNoButton.SetPosSizePixel( aPos, aSize );
2039cdf0e10cSrcweir             aSize.Width() /= 2;
2040cdf0e10cSrcweir             aSize.Width() -= 2;
2041cdf0e10cSrcweir             m_aDateField.SetPosSizePixel( aPos, aSize );
2042cdf0e10cSrcweir             aPos.X() += aSize.Width() + 4;
2043cdf0e10cSrcweir             m_aTimeField.SetPosSizePixel( aPos, aSize );
2044cdf0e10cSrcweir         }
2045cdf0e10cSrcweir 
2046cdf0e10cSrcweir         pCurrent++;
2047cdf0e10cSrcweir     }
2048cdf0e10cSrcweir 
2049cdf0e10cSrcweir     m_nLineHeight =
2050cdf0e10cSrcweir         ( m_aRemoveButton.GetPosPixel().Y() * 2 ) + m_aRemoveButton.GetSizePixel().Height();
2051*c3916d03SAriel Constenla-Haile 
2052*c3916d03SAriel Constenla-Haile     m_nDatePosX = m_aDateField.GetPosPixel().X();
2053*c3916d03SAriel Constenla-Haile     m_nTimePosX = m_aTimeField.GetPosPixel().X();
2054cdf0e10cSrcweir }
2055cdf0e10cSrcweir 
GetVisibleLineCount() const2056cdf0e10cSrcweir sal_uInt16 CustomPropertiesWindow::GetVisibleLineCount() const
2057cdf0e10cSrcweir {
2058cdf0e10cSrcweir     sal_uInt16 nCount = 0;
2059cdf0e10cSrcweir     std::vector< CustomPropertyLine* >::const_iterator pIter;
2060cdf0e10cSrcweir     for ( pIter = m_aCustomPropertiesLines.begin();
2061cdf0e10cSrcweir             pIter != m_aCustomPropertiesLines.end(); ++pIter )
2062cdf0e10cSrcweir     {
2063cdf0e10cSrcweir         CustomPropertyLine* pLine = *pIter;
2064cdf0e10cSrcweir         if ( !pLine->m_bIsRemoved )
2065cdf0e10cSrcweir             nCount++;
2066cdf0e10cSrcweir     }
2067cdf0e10cSrcweir     return nCount;
2068cdf0e10cSrcweir }
2069cdf0e10cSrcweir 
AddLine(const::rtl::OUString & sName,Any & rAny)2070cdf0e10cSrcweir void CustomPropertiesWindow::AddLine( const ::rtl::OUString& sName, Any& rAny )
2071cdf0e10cSrcweir {
2072cdf0e10cSrcweir     CustomPropertyLine* pNewLine = new CustomPropertyLine( this );
2073cdf0e10cSrcweir     pNewLine->m_aTypeBox.SetSelectHdl( LINK( this, CustomPropertiesWindow, TypeHdl ) );
2074cdf0e10cSrcweir     pNewLine->m_aRemoveButton.SetClickHdl( LINK( this, CustomPropertiesWindow, RemoveHdl ) );
2075cdf0e10cSrcweir     pNewLine->m_aValueEdit.SetLoseFocusHdl( LINK( this, CustomPropertiesWindow, EditLoseFocusHdl ) );
2076cdf0e10cSrcweir     //add lose focus handlers of date/time fields
2077cdf0e10cSrcweir 
2078cdf0e10cSrcweir     pNewLine->m_aTypeBox.SetLoseFocusHdl( LINK( this, CustomPropertiesWindow, BoxLoseFocusHdl ) );
2079cdf0e10cSrcweir 
2080cdf0e10cSrcweir 	pNewLine->m_aNameBox.SetAccessibleName(m_aNameBox.GetAccessibleName());
2081cdf0e10cSrcweir 	pNewLine->m_aTypeBox.SetAccessibleName(m_aTypeBox.GetAccessibleName());
2082cdf0e10cSrcweir 	pNewLine->m_aValueEdit.SetAccessibleName(m_aValueEdit.GetAccessibleName());
2083cdf0e10cSrcweir 
2084cdf0e10cSrcweir     long nPos = GetVisibleLineCount() * GetLineHeight();
2085cdf0e10cSrcweir     m_aCustomPropertiesLines.push_back( pNewLine );
2086cdf0e10cSrcweir     Window* pWindows[] = {  &m_aNameBox, &m_aTypeBox, &m_aValueEdit,
2087cdf0e10cSrcweir                             &m_aDateField, &m_aTimeField,
2088cdf0e10cSrcweir                             &m_aDurationField, &m_aEditButton,
2089cdf0e10cSrcweir                             &m_aYesNoButton, &m_aRemoveButton, NULL };
2090cdf0e10cSrcweir     Window* pNewWindows[] =
2091cdf0e10cSrcweir         {   &pNewLine->m_aNameBox, &pNewLine->m_aTypeBox, &pNewLine->m_aValueEdit,
2092cdf0e10cSrcweir             &pNewLine->m_aDateField, &pNewLine->m_aTimeField,
2093cdf0e10cSrcweir             &pNewLine->m_aDurationField, &pNewLine->m_aEditButton,
2094cdf0e10cSrcweir             &pNewLine->m_aYesNoButton, &pNewLine->m_aRemoveButton, NULL };
2095cdf0e10cSrcweir     Window** pCurrent = pWindows;
2096cdf0e10cSrcweir     Window** pNewCurrent = pNewWindows;
2097cdf0e10cSrcweir     while ( *pCurrent )
2098cdf0e10cSrcweir     {
2099cdf0e10cSrcweir         Size aSize = (*pCurrent)->GetSizePixel();
2100cdf0e10cSrcweir         Point aPos = (*pCurrent)->GetPosPixel();
2101cdf0e10cSrcweir         aPos.Y() += nPos;
2102cdf0e10cSrcweir 		aPos.Y() += m_nScrollPos;
2103cdf0e10cSrcweir         (*pNewCurrent)->SetPosSizePixel( aPos, aSize );
2104cdf0e10cSrcweir         (*pNewCurrent)->Show();
2105cdf0e10cSrcweir         pCurrent++;
2106cdf0e10cSrcweir         pNewCurrent++;
2107cdf0e10cSrcweir     }
2108cdf0e10cSrcweir 
2109cdf0e10cSrcweir     double nTmpValue = 0;
2110cdf0e10cSrcweir     bool bTmpValue = false;
2111cdf0e10cSrcweir     ::rtl::OUString sTmpValue;
2112cdf0e10cSrcweir     util::DateTime aTmpDateTime;
2113cdf0e10cSrcweir     util::Date aTmpDate;
2114cdf0e10cSrcweir     util::Duration aTmpDuration;
2115cdf0e10cSrcweir     SvtSysLocale aSysLocale;
2116cdf0e10cSrcweir     const LocaleDataWrapper& rLocaleWrapper = aSysLocale.GetLocaleData();
2117cdf0e10cSrcweir     pNewLine->m_aNameBox.SetText( sName );
2118cdf0e10cSrcweir     sal_Int32 nType = CUSTOM_TYPE_UNKNOWN;
2119cdf0e10cSrcweir     String sValue;
2120cdf0e10cSrcweir 
2121cdf0e10cSrcweir     if ( rAny >>= nTmpValue )
2122cdf0e10cSrcweir     {
2123cdf0e10cSrcweir         sal_uInt32 nIndex = m_aNumberFormatter.GetFormatIndex( NF_NUMBER_SYSTEM );
2124cdf0e10cSrcweir         m_aNumberFormatter.GetInputLineString( nTmpValue, nIndex, sValue );
2125cdf0e10cSrcweir         pNewLine->m_aValueEdit.SetText( sValue );
2126cdf0e10cSrcweir         nType = CUSTOM_TYPE_NUMBER;
2127cdf0e10cSrcweir     }
2128cdf0e10cSrcweir     else if ( rAny >>= bTmpValue )
2129cdf0e10cSrcweir     {
2130cdf0e10cSrcweir         sValue = ( bTmpValue ? rLocaleWrapper.getTrueWord() : rLocaleWrapper.getFalseWord() );
2131cdf0e10cSrcweir         nType = CUSTOM_TYPE_BOOLEAN;
2132cdf0e10cSrcweir     }
2133cdf0e10cSrcweir     else if ( rAny >>= sTmpValue )
2134cdf0e10cSrcweir     {
2135cdf0e10cSrcweir         pNewLine->m_aValueEdit.SetText( sTmpValue );
2136cdf0e10cSrcweir         nType = CUSTOM_TYPE_TEXT;
2137cdf0e10cSrcweir     }
2138cdf0e10cSrcweir     else if ( rAny >>= aTmpDate )
2139cdf0e10cSrcweir     {
2140cdf0e10cSrcweir         nType = CUSTOM_TYPE_DATE;
2141cdf0e10cSrcweir         pNewLine->m_aDateField.SetDate( Date( aTmpDate.Day, aTmpDate.Month, aTmpDate.Year ) );
2142cdf0e10cSrcweir 
2143cdf0e10cSrcweir     }
2144cdf0e10cSrcweir     else if ( rAny >>= aTmpDuration )
2145cdf0e10cSrcweir     {
2146cdf0e10cSrcweir         nType = CUSTOM_TYPE_DURATION;
2147cdf0e10cSrcweir         pNewLine->m_aDurationField.SetDuration( aTmpDuration );
2148cdf0e10cSrcweir     }
2149cdf0e10cSrcweir     else if ( rAny >>= aTmpDateTime )
2150cdf0e10cSrcweir     {
2151cdf0e10cSrcweir         pNewLine->m_aDateField.SetDate( Date( aTmpDateTime.Day, aTmpDateTime.Month, aTmpDateTime.Year ) );
2152cdf0e10cSrcweir         pNewLine->m_aTimeField.SetTime( Time( aTmpDateTime.Hours, aTmpDateTime.Minutes, aTmpDateTime.Seconds, aTmpDateTime.HundredthSeconds ) );
2153cdf0e10cSrcweir 
2154cdf0e10cSrcweir         nType = CUSTOM_TYPE_DATETIME;
2155cdf0e10cSrcweir     }
2156cdf0e10cSrcweir 
2157cdf0e10cSrcweir     if ( nType != CUSTOM_TYPE_UNKNOWN )
2158cdf0e10cSrcweir     {
2159cdf0e10cSrcweir         if ( CUSTOM_TYPE_BOOLEAN == nType )
2160cdf0e10cSrcweir         {
2161cdf0e10cSrcweir             if ( bTmpValue )
2162cdf0e10cSrcweir                 pNewLine->m_aYesNoButton.CheckYes();
2163cdf0e10cSrcweir             else
2164cdf0e10cSrcweir                 pNewLine->m_aYesNoButton.CheckNo();
2165cdf0e10cSrcweir         }
2166cdf0e10cSrcweir         pNewLine->m_aTypeBox.SelectEntryPos( m_aTypeBox.GetEntryPos( (void*)nType ) );
2167cdf0e10cSrcweir     }
2168cdf0e10cSrcweir 
2169cdf0e10cSrcweir     TypeHdl( &pNewLine->m_aTypeBox );
2170cdf0e10cSrcweir     pNewLine->m_aNameBox.GrabFocus();
2171cdf0e10cSrcweir }
2172cdf0e10cSrcweir 
AreAllLinesValid() const2173cdf0e10cSrcweir bool CustomPropertiesWindow::AreAllLinesValid() const
2174cdf0e10cSrcweir {
2175cdf0e10cSrcweir     bool bRet = true;
2176cdf0e10cSrcweir     std::vector< CustomPropertyLine* >::const_iterator pIter;
2177cdf0e10cSrcweir     for ( pIter = m_aCustomPropertiesLines.begin();
2178cdf0e10cSrcweir             pIter != m_aCustomPropertiesLines.end(); ++pIter )
2179cdf0e10cSrcweir     {
2180cdf0e10cSrcweir         CustomPropertyLine* pLine = *pIter;
2181cdf0e10cSrcweir         if ( !IsLineValid( pLine ) )
2182cdf0e10cSrcweir         {
2183cdf0e10cSrcweir             bRet = false;
2184cdf0e10cSrcweir             break;
2185cdf0e10cSrcweir         }
2186cdf0e10cSrcweir     }
2187cdf0e10cSrcweir 
2188cdf0e10cSrcweir     return bRet;
2189cdf0e10cSrcweir }
2190cdf0e10cSrcweir 
ClearAllLines()2191cdf0e10cSrcweir void CustomPropertiesWindow::ClearAllLines()
2192cdf0e10cSrcweir {
2193cdf0e10cSrcweir     std::vector< CustomPropertyLine* >::iterator pIter;
2194cdf0e10cSrcweir     for ( pIter = m_aCustomPropertiesLines.begin();
2195cdf0e10cSrcweir           pIter != m_aCustomPropertiesLines.end(); ++pIter )
2196cdf0e10cSrcweir     {
2197cdf0e10cSrcweir         CustomPropertyLine* pLine = *pIter;
2198cdf0e10cSrcweir         pLine->SetRemoved();
2199cdf0e10cSrcweir         delete pLine;
2200cdf0e10cSrcweir     }
2201cdf0e10cSrcweir     m_aCustomPropertiesLines.clear();
2202cdf0e10cSrcweir 	m_nScrollPos = 0;
2203cdf0e10cSrcweir }
2204cdf0e10cSrcweir 
DoScroll(sal_Int32 nNewPos)2205cdf0e10cSrcweir void CustomPropertiesWindow::DoScroll( sal_Int32 nNewPos )
2206cdf0e10cSrcweir {
2207cdf0e10cSrcweir 	m_nScrollPos += nNewPos;
2208cdf0e10cSrcweir 	std::vector< CustomPropertyLine* >::iterator pIter;
2209cdf0e10cSrcweir     for ( pIter = m_aCustomPropertiesLines.begin();
2210cdf0e10cSrcweir             pIter != m_aCustomPropertiesLines.end(); ++pIter )
2211cdf0e10cSrcweir     {
2212cdf0e10cSrcweir         CustomPropertyLine* pLine = *pIter;
2213cdf0e10cSrcweir         if ( pLine->m_bIsRemoved )
2214cdf0e10cSrcweir             continue;
2215cdf0e10cSrcweir 
2216*c3916d03SAriel Constenla-Haile         Window* pWindows[] = {  &pLine->m_aNameBox,
2217*c3916d03SAriel Constenla-Haile                                 &pLine->m_aTypeBox,
2218*c3916d03SAriel Constenla-Haile                                 &pLine->m_aValueEdit,
2219*c3916d03SAriel Constenla-Haile                                 &pLine->m_aDurationField,
2220*c3916d03SAriel Constenla-Haile                                 &pLine->m_aEditButton,
2221*c3916d03SAriel Constenla-Haile                                 &pLine->m_aDateField,
2222*c3916d03SAriel Constenla-Haile                                 &pLine->m_aTimeField,
2223*c3916d03SAriel Constenla-Haile                                 &pLine->m_aYesNoButton,
2224*c3916d03SAriel Constenla-Haile                                 &pLine->m_aRemoveButton, NULL };
2225cdf0e10cSrcweir         Window** pCurrent = pWindows;
2226cdf0e10cSrcweir         while ( *pCurrent )
2227cdf0e10cSrcweir         {
2228cdf0e10cSrcweir             Point aPos = (*pCurrent)->GetPosPixel();
2229cdf0e10cSrcweir             aPos.Y() += nNewPos;
2230cdf0e10cSrcweir             (*pCurrent)->SetPosPixel( aPos );
2231cdf0e10cSrcweir             pCurrent++;
2232cdf0e10cSrcweir         }
2233cdf0e10cSrcweir     }
2234cdf0e10cSrcweir }
2235cdf0e10cSrcweir 
DoesCustomPropertyExist(const String & rName) const2236cdf0e10cSrcweir bool CustomPropertiesWindow::DoesCustomPropertyExist( const String& rName ) const
2237cdf0e10cSrcweir {
2238cdf0e10cSrcweir     bool bRet = false;
2239cdf0e10cSrcweir     std::vector< CustomPropertyLine* >::const_iterator pIter;
2240cdf0e10cSrcweir     for ( pIter = m_aCustomPropertiesLines.begin();
2241cdf0e10cSrcweir             pIter != m_aCustomPropertiesLines.end(); ++pIter )
2242cdf0e10cSrcweir     {
2243cdf0e10cSrcweir         CustomPropertyLine* pLine = *pIter;
2244cdf0e10cSrcweir         if ( !pLine->m_bIsRemoved && pLine->m_aNameBox.GetText() == rName )
2245cdf0e10cSrcweir         {
2246cdf0e10cSrcweir             bRet = true;
2247cdf0e10cSrcweir             break;
2248cdf0e10cSrcweir         }
2249cdf0e10cSrcweir     }
2250cdf0e10cSrcweir 
2251cdf0e10cSrcweir     return bRet;
2252cdf0e10cSrcweir }
2253cdf0e10cSrcweir 
GetCustomProperties() const2254cdf0e10cSrcweir Sequence< beans::PropertyValue > CustomPropertiesWindow::GetCustomProperties() const
2255cdf0e10cSrcweir {
2256cdf0e10cSrcweir     Sequence< beans::PropertyValue > aPropertiesSeq( m_aCustomPropertiesLines.size() );
2257cdf0e10cSrcweir     sal_Int32 i = 0;
2258cdf0e10cSrcweir     std::vector< CustomPropertyLine* >::const_iterator pIter;
2259cdf0e10cSrcweir     for ( pIter = m_aCustomPropertiesLines.begin();
2260cdf0e10cSrcweir             pIter != m_aCustomPropertiesLines.end(); ++pIter, ++i )
2261cdf0e10cSrcweir     {
2262cdf0e10cSrcweir         CustomPropertyLine* pLine = *pIter;
2263cdf0e10cSrcweir         if ( pLine->m_bIsRemoved )
2264cdf0e10cSrcweir             continue;
2265cdf0e10cSrcweir 
2266cdf0e10cSrcweir         String sPropertyName = pLine->m_aNameBox.GetText();
2267cdf0e10cSrcweir         if ( sPropertyName.Len() > 0 )
2268cdf0e10cSrcweir         {
2269cdf0e10cSrcweir             aPropertiesSeq[i].Name = sPropertyName;
2270cdf0e10cSrcweir             sal_Int64 nType = sal_Int64(
2271cdf0e10cSrcweir                 (long)pLine->m_aTypeBox.GetEntryData( pLine->m_aTypeBox.GetSelectEntryPos() ) );
2272cdf0e10cSrcweir             if ( CUSTOM_TYPE_NUMBER == nType )
2273cdf0e10cSrcweir             {
2274cdf0e10cSrcweir                 double nValue = 0;
2275cdf0e10cSrcweir                 sal_uInt32 nIndex = const_cast< SvNumberFormatter& >(
2276cdf0e10cSrcweir                     m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM );
2277cdf0e10cSrcweir                 sal_Bool bIsNum = const_cast< SvNumberFormatter& >( m_aNumberFormatter ).
2278cdf0e10cSrcweir                     IsNumberFormat( pLine->m_aValueEdit.GetText(), nIndex, nValue );
2279cdf0e10cSrcweir                 if ( bIsNum )
2280cdf0e10cSrcweir                     aPropertiesSeq[i].Value <<= makeAny( nValue );
2281cdf0e10cSrcweir             }
2282cdf0e10cSrcweir             else if ( CUSTOM_TYPE_BOOLEAN == nType )
2283cdf0e10cSrcweir             {
2284cdf0e10cSrcweir                 bool bValue = pLine->m_aYesNoButton.IsYesChecked();
2285cdf0e10cSrcweir                 aPropertiesSeq[i].Value <<= makeAny( bValue );
2286cdf0e10cSrcweir             }
2287cdf0e10cSrcweir             else if ( CUSTOM_TYPE_DATETIME == nType )
2288cdf0e10cSrcweir             {
2289cdf0e10cSrcweir                 Date aTmpDate = pLine->m_aDateField.GetDate();
2290cdf0e10cSrcweir                 Time aTmpTime = pLine->m_aTimeField.GetTime();
2291cdf0e10cSrcweir                 util::DateTime aDateTime(aTmpTime.Get100Sec(), aTmpTime.GetSec(), aTmpTime.GetMin(), aTmpTime.GetHour(),
2292cdf0e10cSrcweir                         aTmpDate.GetDay(), aTmpDate.GetMonth(), aTmpDate.GetYear() );
2293cdf0e10cSrcweir                 aPropertiesSeq[i].Value <<= aDateTime;
2294cdf0e10cSrcweir             }
2295cdf0e10cSrcweir             else if ( CUSTOM_TYPE_DURATION == nType )
2296cdf0e10cSrcweir             {
2297cdf0e10cSrcweir                 aPropertiesSeq[i].Value <<= pLine->m_aDurationField.GetDuration();
2298cdf0e10cSrcweir             }
2299cdf0e10cSrcweir             else if ( CUSTOM_TYPE_DATE == nType )
2300cdf0e10cSrcweir             {
2301cdf0e10cSrcweir                 Date aTmpDate = pLine->m_aDateField.GetDate();
2302cdf0e10cSrcweir                 util::Date aDate(aTmpDate.GetDay(), aTmpDate.GetMonth(), aTmpDate.GetYear());
2303cdf0e10cSrcweir                 aPropertiesSeq[i].Value <<= aDate;
2304cdf0e10cSrcweir 
2305cdf0e10cSrcweir             }
2306cdf0e10cSrcweir             else
2307cdf0e10cSrcweir             {
2308cdf0e10cSrcweir                 ::rtl::OUString sValue( pLine->m_aValueEdit.GetText() );
2309cdf0e10cSrcweir                 aPropertiesSeq[i].Value <<= makeAny( sValue );
2310cdf0e10cSrcweir             }
2311cdf0e10cSrcweir         }
2312cdf0e10cSrcweir     }
2313cdf0e10cSrcweir 
2314cdf0e10cSrcweir     return aPropertiesSeq;
2315cdf0e10cSrcweir }
2316cdf0e10cSrcweir 
2317cdf0e10cSrcweir // class CustomPropertiesControl -----------------------------------------
2318cdf0e10cSrcweir 
CustomPropertiesControl(Window * pParent,const ResId & rResId)2319cdf0e10cSrcweir CustomPropertiesControl::CustomPropertiesControl( Window* pParent, const ResId& rResId ) :
2320cdf0e10cSrcweir 
2321cdf0e10cSrcweir     Control( pParent, rResId ),
2322cdf0e10cSrcweir 
2323cdf0e10cSrcweir     m_aHeaderBar    ( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER ),
2324cdf0e10cSrcweir     m_aPropertiesWin( this, ResId( WIN_PROPERTIES, *rResId.GetResMgr() ) ),
2325cdf0e10cSrcweir     m_aVertScroll   ( this, ResId( SB_VERTICAL, *rResId.GetResMgr() ) ),
2326cdf0e10cSrcweir 
2327cdf0e10cSrcweir     m_bIsInitialized( false ),
2328cdf0e10cSrcweir     m_nThumbPos     ( 0 )
2329cdf0e10cSrcweir 
2330cdf0e10cSrcweir {
2331cdf0e10cSrcweir     m_aPropertiesWin.SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) );
2332cdf0e10cSrcweir     m_aVertScroll.EnableDrag();
2333cdf0e10cSrcweir     m_aVertScroll.Show();
2334cdf0e10cSrcweir     long nWidth = GetOutputSizePixel().Width();
2335cdf0e10cSrcweir     m_aHeaderBar.SetPosSizePixel( Point(), Size( nWidth, m_aVertScroll.GetPosPixel().Y() ) );
2336cdf0e10cSrcweir     const HeaderBarItemBits nHeadBits = HIB_VCENTER | HIB_FIXED | HIB_FIXEDPOS | HIB_LEFT;
2337cdf0e10cSrcweir     nWidth = nWidth / 4;
2338cdf0e10cSrcweir     ResMgr* pResMgr = rResId.GetResMgr();
2339cdf0e10cSrcweir     m_aHeaderBar.InsertItem( HI_NAME, String( ResId( STR_HEADER_NAME, *pResMgr ) ), nWidth, nHeadBits );
2340cdf0e10cSrcweir     m_aHeaderBar.InsertItem( HI_TYPE, String( ResId( STR_HEADER_TYPE, *pResMgr ) ), nWidth, nHeadBits );
2341cdf0e10cSrcweir     m_aHeaderBar.InsertItem( HI_VALUE, String( ResId( STR_HEADER_VALUE, *pResMgr ) ), nWidth, nHeadBits );
2342cdf0e10cSrcweir     m_aHeaderBar.InsertItem( HI_ACTION, String( ResId( STR_HEADER_ACTION, *pResMgr ) ), nWidth, nHeadBits );
2343cdf0e10cSrcweir     m_aHeaderBar.Show();
2344cdf0e10cSrcweir 
2345cdf0e10cSrcweir     FreeResource();
2346cdf0e10cSrcweir 
2347cdf0e10cSrcweir     XubString sTEST = m_aHeaderBar.GetItemText( HI_NAME );
2348cdf0e10cSrcweir 
2349cdf0e10cSrcweir     m_aPropertiesWin.InitControls( &m_aHeaderBar, &m_aVertScroll );
2350cdf0e10cSrcweir 	m_aPropertiesWin.SetRemovedHdl( LINK( this, CustomPropertiesControl, RemovedHdl ) );
2351cdf0e10cSrcweir 
2352cdf0e10cSrcweir     m_aVertScroll.SetRangeMin( 0 );
2353cdf0e10cSrcweir     sal_Int32 nScrollOffset = m_aPropertiesWin.GetLineHeight();
2354cdf0e10cSrcweir     sal_Int32 nVisibleEntries = m_aPropertiesWin.GetSizePixel().Height() / nScrollOffset;
2355cdf0e10cSrcweir     m_aVertScroll.SetRangeMax( nVisibleEntries );
2356cdf0e10cSrcweir     m_aVertScroll.SetPageSize( nVisibleEntries - 1 );
2357cdf0e10cSrcweir     m_aVertScroll.SetVisibleSize( nVisibleEntries );
2358cdf0e10cSrcweir 
2359cdf0e10cSrcweir     Point aPos = m_aHeaderBar.GetPosPixel();
2360cdf0e10cSrcweir     Size aSize = m_aHeaderBar.GetSizePixel();
2361cdf0e10cSrcweir     aPos = m_aVertScroll.GetPosPixel();
2362cdf0e10cSrcweir     aSize = m_aVertScroll.GetSizePixel();
2363cdf0e10cSrcweir 
2364cdf0e10cSrcweir     Link aScrollLink = LINK( this, CustomPropertiesControl, ScrollHdl );
2365cdf0e10cSrcweir     m_aVertScroll.SetScrollHdl( aScrollLink );
2366cdf0e10cSrcweir //    m_aVertScroll.SetEndScrollHdl( aScrollLink );
2367cdf0e10cSrcweir }
2368cdf0e10cSrcweir 
~CustomPropertiesControl()2369cdf0e10cSrcweir CustomPropertiesControl::~CustomPropertiesControl()
2370cdf0e10cSrcweir {
2371cdf0e10cSrcweir }
2372cdf0e10cSrcweir 
Initialize()2373cdf0e10cSrcweir void CustomPropertiesControl::Initialize()
2374cdf0e10cSrcweir {
2375cdf0e10cSrcweir }
2376cdf0e10cSrcweir 
IMPL_LINK(CustomPropertiesControl,ScrollHdl,ScrollBar *,pScrollBar)2377cdf0e10cSrcweir IMPL_LINK( CustomPropertiesControl, ScrollHdl, ScrollBar*, pScrollBar )
2378cdf0e10cSrcweir {
2379cdf0e10cSrcweir     sal_Int32 nOffset = m_aPropertiesWin.GetLineHeight();
2380cdf0e10cSrcweir     nOffset *= ( m_nThumbPos - pScrollBar->GetThumbPos() );
2381cdf0e10cSrcweir     m_nThumbPos = pScrollBar->GetThumbPos();
2382cdf0e10cSrcweir     m_aPropertiesWin.DoScroll( nOffset );
2383cdf0e10cSrcweir     return 0;
2384cdf0e10cSrcweir }
2385cdf0e10cSrcweir 
IMPL_LINK(CustomPropertiesControl,RemovedHdl,void *,EMPTYARG)2386cdf0e10cSrcweir IMPL_LINK( CustomPropertiesControl, RemovedHdl, void*, EMPTYARG )
2387cdf0e10cSrcweir {
2388cdf0e10cSrcweir     m_aVertScroll.SetRangeMax( m_aPropertiesWin.GetVisibleLineCount() + 1 );
2389cdf0e10cSrcweir 	if ( m_aPropertiesWin.GetOutputSizePixel().Height() < m_aPropertiesWin.GetVisibleLineCount() * m_aPropertiesWin.GetLineHeight() )
2390cdf0e10cSrcweir 		m_aVertScroll.DoScrollAction ( SCROLL_LINEUP );
2391cdf0e10cSrcweir 	return 0;
2392cdf0e10cSrcweir }
2393cdf0e10cSrcweir 
AddLine(const::rtl::OUString & sName,Any & rAny,bool bInteractive)2394cdf0e10cSrcweir void CustomPropertiesControl::AddLine( const ::rtl::OUString& sName, Any& rAny, bool bInteractive )
2395cdf0e10cSrcweir {
2396cdf0e10cSrcweir     m_aPropertiesWin.AddLine( sName, rAny );
2397cdf0e10cSrcweir     m_aVertScroll.SetRangeMax( m_aPropertiesWin.GetVisibleLineCount() + 1 );
2398cdf0e10cSrcweir 	if ( bInteractive && m_aPropertiesWin.GetOutputSizePixel().Height() < m_aPropertiesWin.GetVisibleLineCount() * m_aPropertiesWin.GetLineHeight() )
2399cdf0e10cSrcweir 		m_aVertScroll.DoScroll( m_aPropertiesWin.GetVisibleLineCount() + 1 );
2400cdf0e10cSrcweir }
2401cdf0e10cSrcweir 
2402cdf0e10cSrcweir // class SfxCustomPropertiesPage -----------------------------------------
2403cdf0e10cSrcweir 
SfxCustomPropertiesPage(Window * pParent,const SfxItemSet & rItemSet)2404cdf0e10cSrcweir SfxCustomPropertiesPage::SfxCustomPropertiesPage( Window* pParent, const SfxItemSet& rItemSet ) :
2405cdf0e10cSrcweir 
2406cdf0e10cSrcweir     SfxTabPage( pParent, SfxResId( TP_CUSTOMPROPERTIES ), rItemSet ),
2407cdf0e10cSrcweir     m_aPropertiesCtrl   ( this, SfxResId( CTRL_PROPERTIES ) ),
2408cdf0e10cSrcweir     m_aAddBtn           ( this, SfxResId( BTN_ADD ) ),
2409cdf0e10cSrcweir     m_aPropertiesFT     ( this, SfxResId( FT_PROPERTIES ) )
2410cdf0e10cSrcweir 
2411cdf0e10cSrcweir {
2412cdf0e10cSrcweir     FreeResource();
2413cdf0e10cSrcweir 
2414cdf0e10cSrcweir     m_aAddBtn.SetClickHdl( LINK( this, SfxCustomPropertiesPage, AddHdl ) );
2415cdf0e10cSrcweir }
2416cdf0e10cSrcweir 
IMPL_LINK(SfxCustomPropertiesPage,AddHdl,PushButton *,EMPTYARG)2417cdf0e10cSrcweir IMPL_LINK( SfxCustomPropertiesPage, AddHdl, PushButton*, EMPTYARG )
2418cdf0e10cSrcweir {
2419cdf0e10cSrcweir     Any aAny;
2420cdf0e10cSrcweir     m_aPropertiesCtrl.AddLine( ::rtl::OUString(), aAny, true );
2421cdf0e10cSrcweir     return 0;
2422cdf0e10cSrcweir }
2423cdf0e10cSrcweir 
FillItemSet(SfxItemSet & rSet)2424cdf0e10cSrcweir sal_Bool SfxCustomPropertiesPage::FillItemSet( SfxItemSet& rSet )
2425cdf0e10cSrcweir {
2426cdf0e10cSrcweir     sal_Bool bModified = sal_False;
2427cdf0e10cSrcweir     const SfxPoolItem*      pItem = NULL;
2428cdf0e10cSrcweir     SfxDocumentInfoItem*    pInfo = NULL;
2429cdf0e10cSrcweir     bool                    bMustDelete = false;
2430cdf0e10cSrcweir 
2431cdf0e10cSrcweir     if ( GetTabDialog() && GetTabDialog()->GetExampleSet() )
2432cdf0e10cSrcweir     {
2433cdf0e10cSrcweir         if( SFX_ITEM_SET !=
2434cdf0e10cSrcweir                 GetTabDialog()->GetExampleSet()->GetItemState( SID_DOCINFO, sal_True, &pItem ) )
2435cdf0e10cSrcweir             pInfo = &( SfxDocumentInfoItem& )rSet.Get( SID_DOCINFO );
2436cdf0e10cSrcweir         else
2437cdf0e10cSrcweir         {
2438cdf0e10cSrcweir             bMustDelete = true;
2439cdf0e10cSrcweir             pInfo = new SfxDocumentInfoItem( *( const SfxDocumentInfoItem* ) pItem );
2440cdf0e10cSrcweir         }
2441cdf0e10cSrcweir     }
2442cdf0e10cSrcweir 
2443cdf0e10cSrcweir     if ( pInfo )
2444cdf0e10cSrcweir     {
2445cdf0e10cSrcweir         pInfo->ClearCustomProperties();
2446cdf0e10cSrcweir         Sequence< beans::PropertyValue > aPropertySeq = m_aPropertiesCtrl.GetCustomProperties();
2447cdf0e10cSrcweir         sal_Int32 i = 0, nCount = aPropertySeq.getLength();
2448cdf0e10cSrcweir         for ( ; i < nCount; ++i )
2449cdf0e10cSrcweir         {
2450cdf0e10cSrcweir             if ( aPropertySeq[i].Name.getLength() > 0 )
2451cdf0e10cSrcweir                 pInfo->AddCustomProperty( aPropertySeq[i].Name, aPropertySeq[i].Value );
2452cdf0e10cSrcweir         }
2453cdf0e10cSrcweir     }
2454cdf0e10cSrcweir 
2455cdf0e10cSrcweir     bModified = sal_True; //!!!
2456cdf0e10cSrcweir     if ( bModified )
2457cdf0e10cSrcweir         rSet.Put( *pInfo );
2458cdf0e10cSrcweir     if ( bMustDelete )
2459cdf0e10cSrcweir         delete pInfo;
2460cdf0e10cSrcweir     return bModified;
2461cdf0e10cSrcweir }
2462cdf0e10cSrcweir 
Reset(const SfxItemSet & rItemSet)2463cdf0e10cSrcweir void SfxCustomPropertiesPage::Reset( const SfxItemSet& rItemSet )
2464cdf0e10cSrcweir {
2465cdf0e10cSrcweir     m_aPropertiesCtrl.ClearAllLines();
2466cdf0e10cSrcweir     const SfxDocumentInfoItem* pInfoItem = &(const SfxDocumentInfoItem &)rItemSet.Get(SID_DOCINFO);
2467cdf0e10cSrcweir     std::vector< CustomProperty* > aCustomProps = pInfoItem->GetCustomProperties();
2468cdf0e10cSrcweir     for ( sal_uInt32 i = 0; i < aCustomProps.size(); i++ )
2469cdf0e10cSrcweir     {
2470cdf0e10cSrcweir         m_aPropertiesCtrl.AddLine( aCustomProps[i]->m_sName, aCustomProps[i]->m_aValue, false );
2471cdf0e10cSrcweir     }
2472cdf0e10cSrcweir }
2473cdf0e10cSrcweir 
DeactivatePage(SfxItemSet *)2474cdf0e10cSrcweir int SfxCustomPropertiesPage::DeactivatePage( SfxItemSet* /*pSet*/ )
2475cdf0e10cSrcweir {
2476cdf0e10cSrcweir     int nRet = LEAVE_PAGE;
2477cdf0e10cSrcweir     if ( !m_aPropertiesCtrl.AreAllLinesValid() )
2478cdf0e10cSrcweir         nRet = KEEP_PAGE;
2479cdf0e10cSrcweir     return nRet;
2480cdf0e10cSrcweir }
2481cdf0e10cSrcweir 
Create(Window * pParent,const SfxItemSet & rItemSet)2482cdf0e10cSrcweir SfxTabPage* SfxCustomPropertiesPage::Create( Window* pParent, const SfxItemSet& rItemSet )
2483cdf0e10cSrcweir {
2484cdf0e10cSrcweir     return new SfxCustomPropertiesPage( pParent, rItemSet );
2485cdf0e10cSrcweir }
2486cdf0e10cSrcweir 
2487