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