LCOV - code coverage report
Current view: top level - sfx2/source/dialog - dinfdlg.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2 1557 0.1 %
Date: 2014-04-11 Functions: 3 141 2.1 %
Legend: Lines: hit not hit

          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/DateTimeWithTimezone.hpp>
      45             : #include <com/sun/star/util/DateWithTimezone.hpp>
      46             : #include <com/sun/star/util/Duration.hpp>
      47             : #include <com/sun/star/document/XDocumentProperties.hpp>
      48             : #include <com/sun/star/document/CmisProperty.hpp>
      49             : 
      50             : #include <vcl/timer.hxx>
      51             : #include <vcl/settings.hxx>
      52             : #include <sfx2/dinfdlg.hxx>
      53             : #include <sfx2/securitypage.hxx>
      54             : #include <sfx2/sfxresid.hxx>
      55             : #include <sfx2/dinfedt.hxx>
      56             : #include <sfx2/frame.hxx>
      57             : #include <sfx2/viewfrm.hxx>
      58             : #include <sfx2/request.hxx>
      59             : #include <sfx2/passwd.hxx>
      60             : #include <sfx2/filedlghelper.hxx>
      61             : #include "helper.hxx"
      62             : #include <sfx2/objsh.hxx>
      63             : #include <sfx2/docfile.hxx>
      64             : #include <comphelper/storagehelper.hxx>
      65             : 
      66             : #include "documentfontsdialog.hxx"
      67             : #include <sfx2/sfx.hrc>
      68             : #include "dinfdlg.hrc"
      69             : #include "../appl/app.hrc"
      70             : #include "sfxlocal.hrc"
      71             : #include <dialog.hrc>
      72             : #include <vcl/help.hxx>
      73             : 
      74             : #include <algorithm>
      75             : 
      76             : using namespace ::com::sun::star;
      77             : using namespace ::com::sun::star::lang;
      78             : using namespace ::com::sun::star::ui::dialogs;
      79             : using namespace ::com::sun::star::uno;
      80             : 
      81             : const sal_uInt16 FONT_PAGE_ID = 99;
      82             : 
      83           0 : struct CustomProperty
      84             : {
      85             :     OUString             m_sName;
      86             :     com::sun::star::uno::Any    m_aValue;
      87             : 
      88           0 :     CustomProperty( const OUString& sName,
      89             :             const com::sun::star::uno::Any& rValue ) :
      90           0 :         m_sName( sName ), m_aValue( rValue ) {}
      91             : };
      92             : 
      93             : static
      94           0 : bool operator==(const util::DateTime &i_rLeft, const util::DateTime &i_rRight)
      95             : {
      96           0 :     return i_rLeft.Year             == i_rRight.Year
      97           0 :         && i_rLeft.Month            == i_rRight.Month
      98           0 :         && i_rLeft.Day              == i_rRight.Day
      99           0 :         && i_rLeft.Hours            == i_rRight.Hours
     100           0 :         && i_rLeft.Minutes          == i_rRight.Minutes
     101           0 :         && i_rLeft.Seconds          == i_rRight.Seconds
     102           0 :         && i_rLeft.NanoSeconds      == i_rRight.NanoSeconds
     103           0 :         && i_rLeft.IsUTC            == i_rRight.IsUTC;
     104             : }
     105             : 
     106             : // STATIC DATA -----------------------------------------------------------
     107         149 : TYPEINIT1_AUTOFACTORY(SfxDocumentInfoItem, SfxStringItem);
     108             : 
     109             : const sal_uInt16 HI_NAME = 1;
     110             : const sal_uInt16 HI_TYPE = 2;
     111             : const sal_uInt16 HI_VALUE = 3;
     112             : const sal_uInt16 HI_ACTION = 4;
     113             : 
     114             : static const char DOCUMENT_SIGNATURE_MENU_CMD[] = "Signature";
     115             : 
     116             : 
     117             : namespace {
     118             : 
     119           0 : OUString CreateSizeText( sal_Int64 nSize )
     120             : {
     121           0 :     OUString aUnitStr(" ");
     122           0 :     aUnitStr += SfxResId(STR_BYTES).toString();
     123           0 :     sal_Int64 nSize1 = nSize;
     124           0 :     sal_Int64 nSize2 = nSize1;
     125           0 :     sal_Int64 nMega = 1024 * 1024;
     126           0 :     sal_Int64 nGiga = nMega * 1024;
     127           0 :     double fSize = nSize;
     128           0 :     int nDec = 0;
     129             : 
     130           0 :     if ( nSize1 >= 10000 && nSize1 < nMega )
     131             :     {
     132           0 :         nSize1 /= 1024;
     133           0 :         aUnitStr = " ";
     134           0 :         aUnitStr += SfxResId(STR_KB).toString();
     135           0 :         fSize /= 1024;
     136           0 :         nDec = 0;
     137             :     }
     138           0 :     else if ( nSize1 >= nMega && nSize1 < nGiga )
     139             :     {
     140           0 :         nSize1 /= nMega;
     141           0 :         aUnitStr = " ";
     142           0 :         aUnitStr += SfxResId(STR_MB).toString();
     143           0 :         fSize /= nMega;
     144           0 :         nDec = 2;
     145             :     }
     146           0 :     else if ( nSize1 >= nGiga )
     147             :     {
     148           0 :         nSize1 /= nGiga;
     149           0 :         aUnitStr = " ";
     150           0 :         aUnitStr += SfxResId(STR_GB).toString();
     151           0 :         fSize /= nGiga;
     152           0 :         nDec = 3;
     153             :     }
     154           0 :     const SvtSysLocale aSysLocale;
     155           0 :     const LocaleDataWrapper& rLocaleWrapper = aSysLocale.GetLocaleData();
     156           0 :     OUString aSizeStr( rLocaleWrapper.getNum( nSize1, 0 ) );
     157           0 :     aSizeStr += aUnitStr;
     158           0 :     if ( nSize1 < nSize2 )
     159             :     {
     160           0 :         aSizeStr = ::rtl::math::doubleToUString( fSize,
     161             :                 rtl_math_StringFormat_F, nDec,
     162           0 :                 rLocaleWrapper.getNumDecimalSep()[0] );
     163           0 :         aSizeStr += aUnitStr;
     164             : 
     165           0 :         aSizeStr += " (";
     166           0 :         aSizeStr += rLocaleWrapper.getNum( nSize2, 0 );
     167           0 :         aSizeStr += " ";
     168           0 :         aSizeStr += SfxResId(STR_BYTES).toString();
     169           0 :         aSizeStr += ")";
     170             :     }
     171           0 :     return aSizeStr;
     172             : }
     173             : 
     174           0 : OUString ConvertDateTime_Impl( const OUString& rName,
     175             :     const util::DateTime& uDT, const LocaleDataWrapper& rWrapper )
     176             : {
     177           0 :     Date aD(uDT.Day, uDT.Month, uDT.Year);
     178           0 :     Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds);
     179           0 :      const OUString pDelim ( ", " );
     180           0 :      OUString aStr( rWrapper.getDate( aD ) );
     181           0 :      aStr += pDelim;
     182           0 :      aStr += rWrapper.getTime( aT, true, false );
     183           0 :      OUString aAuthor = comphelper::string::stripStart(rName, ' ');
     184           0 :      if (!aAuthor.isEmpty())
     185             :      {
     186           0 :         aStr += pDelim;
     187           0 :         aStr += aAuthor;
     188             :      }
     189           0 :      return aStr;
     190             : }
     191             : 
     192             : }
     193             : 
     194             : 
     195           0 : SfxDocumentInfoItem::SfxDocumentInfoItem()
     196             :     : SfxStringItem()
     197             :     , m_AutoloadDelay(0)
     198             :     , m_AutoloadURL()
     199             :     , m_isAutoloadEnabled(false)
     200             :     , m_DefaultTarget()
     201             :     , m_TemplateName()
     202             :     , m_Author()
     203             :     , m_CreationDate()
     204             :     , m_ModifiedBy()
     205             :     , m_ModificationDate()
     206             :     , m_PrintedBy()
     207             :     , m_PrintDate()
     208             :     , m_EditingCycles(0)
     209             :     , m_EditingDuration(0)
     210             :     , m_Description()
     211             :     , m_Keywords()
     212             :     , m_Subject()
     213             :     , m_Title()
     214             :     , m_bHasTemplate( true )
     215             :     , m_bDeleteUserData( false )
     216           0 :     , m_bUseUserData( true )
     217             : {
     218           0 : }
     219             : 
     220             : 
     221             : 
     222           0 : SfxDocumentInfoItem::SfxDocumentInfoItem( const OUString& rFile,
     223             :         const uno::Reference<document::XDocumentProperties>& i_xDocProps,
     224             :         const uno::Sequence<document::CmisProperty>& i_cmisProps,
     225             :         bool bIs )
     226             :     : SfxStringItem( SID_DOCINFO, rFile )
     227           0 :     , m_AutoloadDelay( i_xDocProps->getAutoloadSecs() )
     228           0 :     , m_AutoloadURL( i_xDocProps->getAutoloadURL() )
     229           0 :     , m_isAutoloadEnabled( (m_AutoloadDelay > 0) || !m_AutoloadURL.isEmpty() )
     230           0 :     , m_DefaultTarget( i_xDocProps->getDefaultTarget() )
     231           0 :     , m_TemplateName( i_xDocProps->getTemplateName() )
     232           0 :     , m_Author( i_xDocProps->getAuthor() )
     233           0 :     , m_CreationDate( i_xDocProps->getCreationDate() )
     234           0 :     , m_ModifiedBy( i_xDocProps->getModifiedBy() )
     235           0 :     , m_ModificationDate( i_xDocProps->getModificationDate() )
     236           0 :     , m_PrintedBy( i_xDocProps->getPrintedBy() )
     237           0 :     , m_PrintDate( i_xDocProps->getPrintDate() )
     238           0 :     , m_EditingCycles( i_xDocProps->getEditingCycles() )
     239           0 :     , m_EditingDuration( i_xDocProps->getEditingDuration() )
     240           0 :     , m_Description( i_xDocProps->getDescription() )
     241             :     , m_Keywords( ::comphelper::string::convertCommaSeparated(
     242           0 :                     i_xDocProps->getKeywords()) )
     243           0 :     , m_Subject( i_xDocProps->getSubject() )
     244           0 :     , m_Title( i_xDocProps->getTitle() )
     245             :     , m_bHasTemplate( true )
     246             :     , m_bDeleteUserData( false )
     247           0 :     , m_bUseUserData( bIs )
     248             : {
     249             :     try
     250             :     {
     251           0 :         Reference< beans::XPropertyContainer > xContainer = i_xDocProps->getUserDefinedProperties();
     252           0 :         if ( xContainer.is() )
     253             :         {
     254           0 :             Reference < beans::XPropertySet > xSet( xContainer, UNO_QUERY );
     255           0 :             const Sequence< beans::Property > lProps = xSet->getPropertySetInfo()->getProperties();
     256           0 :             const beans::Property* pProps = lProps.getConstArray();
     257           0 :             sal_Int32 nCount = lProps.getLength();
     258           0 :             for ( sal_Int32 i = 0; i < nCount; ++i )
     259             :             {
     260             :                 // "fix" property? => not a custom property => ignore it!
     261           0 :                 if (!(pProps[i].Attributes &
     262             :                         ::com::sun::star::beans::PropertyAttribute::REMOVABLE))
     263             :                 {
     264             :                     DBG_ASSERT(false, "non-removable user-defined property?");
     265           0 :                     continue;
     266             :                 }
     267             : 
     268           0 :                 uno::Any aValue = xSet->getPropertyValue(pProps[i].Name);
     269           0 :                 CustomProperty* pProp = new CustomProperty( pProps[i].Name, aValue );
     270           0 :                 m_aCustomProperties.push_back( pProp );
     271           0 :             }
     272             :         }
     273             : 
     274             :         // get CMIS properties
     275           0 :         m_aCmisProperties = i_cmisProps;
     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             : 
     312           0 :     m_aCmisProperties = rItem.m_aCmisProperties;
     313           0 : }
     314             : 
     315             : 
     316           0 : SfxDocumentInfoItem::~SfxDocumentInfoItem()
     317             : {
     318           0 :     ClearCustomProperties();
     319           0 : }
     320             : 
     321             : 
     322           0 : SfxPoolItem* SfxDocumentInfoItem::Clone( SfxItemPool * ) const
     323             : {
     324           0 :     return new SfxDocumentInfoItem( *this );
     325             : }
     326             : 
     327             : 
     328           0 : bool SfxDocumentInfoItem::operator==( const SfxPoolItem& rItem) const
     329             : {
     330           0 :     if (!(rItem.Type() == Type() && SfxStringItem::operator==(rItem)))
     331           0 :         return false;
     332           0 :     const SfxDocumentInfoItem& rInfoItem(static_cast<const SfxDocumentInfoItem&>(rItem));
     333             : 
     334             :     return
     335           0 :          m_AutoloadDelay        == rInfoItem.m_AutoloadDelay     &&
     336           0 :          m_AutoloadURL          == rInfoItem.m_AutoloadURL       &&
     337           0 :          m_isAutoloadEnabled    == rInfoItem.m_isAutoloadEnabled &&
     338           0 :          m_DefaultTarget        == rInfoItem.m_DefaultTarget     &&
     339           0 :          m_Author               == rInfoItem.m_Author            &&
     340           0 :          m_CreationDate         == rInfoItem.m_CreationDate      &&
     341           0 :          m_ModifiedBy           == rInfoItem.m_ModifiedBy        &&
     342           0 :          m_ModificationDate     == rInfoItem.m_ModificationDate  &&
     343           0 :          m_PrintedBy            == rInfoItem.m_PrintedBy         &&
     344           0 :          m_PrintDate            == rInfoItem.m_PrintDate         &&
     345           0 :          m_EditingCycles        == rInfoItem.m_EditingCycles     &&
     346           0 :          m_EditingDuration      == rInfoItem.m_EditingDuration   &&
     347           0 :          m_Description          == rInfoItem.m_Description       &&
     348           0 :          m_Keywords             == rInfoItem.m_Keywords          &&
     349           0 :          m_Subject              == rInfoItem.m_Subject           &&
     350           0 :          m_Title                == rInfoItem.m_Title             &&
     351           0 :          m_aCustomProperties.size() == rInfoItem.m_aCustomProperties.size() &&
     352             :          std::equal(m_aCustomProperties.begin(), m_aCustomProperties.end(),
     353           0 :             rInfoItem.m_aCustomProperties.begin()) &&
     354           0 :          m_aCmisProperties.getLength() == rInfoItem.m_aCmisProperties.getLength();
     355             : }
     356             : 
     357             : 
     358           0 : void SfxDocumentInfoItem::resetUserData(const OUString & i_rAuthor)
     359             : {
     360           0 :     setAuthor(i_rAuthor);
     361           0 :     DateTime now( DateTime::SYSTEM );
     362             :     setCreationDate( util::DateTime(
     363           0 :         now.GetNanoSec(), now.GetSec(), now.GetMin(), now.GetHour(),
     364           0 :         now.GetDay(), now.GetMonth(), now.GetYear(), false) );
     365           0 :     setModifiedBy(OUString());
     366           0 :     setPrintedBy(OUString());
     367           0 :     setModificationDate(util::DateTime());
     368           0 :     setPrintDate(util::DateTime());
     369           0 :     setEditingDuration(0);
     370           0 :     setEditingCycles(1);
     371           0 : }
     372             : 
     373             : 
     374           0 : void SfxDocumentInfoItem::UpdateDocumentInfo(
     375             :         const uno::Reference<document::XDocumentProperties>& i_xDocProps,
     376             :         bool i_bDoNotUpdateUserDefined) const
     377             : {
     378           0 :     if (isAutoloadEnabled()) {
     379           0 :         i_xDocProps->setAutoloadSecs(getAutoloadDelay());
     380           0 :         i_xDocProps->setAutoloadURL(getAutoloadURL());
     381             :     } else {
     382           0 :         i_xDocProps->setAutoloadSecs(0);
     383           0 :         i_xDocProps->setAutoloadURL(OUString());
     384             :     }
     385           0 :     i_xDocProps->setDefaultTarget(getDefaultTarget());
     386           0 :     i_xDocProps->setAuthor(getAuthor());
     387           0 :     i_xDocProps->setCreationDate(getCreationDate());
     388           0 :     i_xDocProps->setModifiedBy(getModifiedBy());
     389           0 :     i_xDocProps->setModificationDate(getModificationDate());
     390           0 :     i_xDocProps->setPrintedBy(getPrintedBy());
     391           0 :     i_xDocProps->setPrintDate(getPrintDate());
     392           0 :     i_xDocProps->setEditingCycles(getEditingCycles());
     393           0 :     i_xDocProps->setEditingDuration(getEditingDuration());
     394           0 :     i_xDocProps->setDescription(getDescription());
     395           0 :     i_xDocProps->setKeywords(
     396           0 :         ::comphelper::string::convertCommaSeparated(getKeywords()));
     397           0 :     i_xDocProps->setSubject(getSubject());
     398           0 :     i_xDocProps->setTitle(getTitle());
     399             : 
     400             :     // this is necessary in case of replaying a recorded macro:
     401             :     // in this case, the macro may contain the 4 old user-defined DocumentInfo
     402             :     // fields, but not any of the DocumentInfo properties;
     403             :     // as a consequence, most of the UserDefined properties of the
     404             :     // DocumentProperties would be summarily deleted here, which does not
     405             :     // seem like a good idea.
     406           0 :     if (i_bDoNotUpdateUserDefined)
     407           0 :         return;
     408             : 
     409             :     try
     410             :     {
     411           0 :         Reference< beans::XPropertyContainer > xContainer = i_xDocProps->getUserDefinedProperties();
     412           0 :         Reference < beans::XPropertySet > xSet( xContainer, UNO_QUERY );
     413           0 :         Reference< beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
     414           0 :         const Sequence< beans::Property > lProps = xSetInfo->getProperties();
     415           0 :         const beans::Property* pProps = lProps.getConstArray();
     416           0 :         sal_Int32 nCount = lProps.getLength();
     417           0 :         for ( sal_Int32 j = 0; j < nCount; ++j )
     418             :         {
     419           0 :             if ((pProps[j].Attributes &
     420             :                     ::com::sun::star::beans::PropertyAttribute::REMOVABLE))
     421             :             {
     422           0 :                 xContainer->removeProperty( pProps[j].Name );
     423             :             }
     424             :         }
     425             : 
     426           0 :         for ( sal_uInt32 k = 0; k < m_aCustomProperties.size(); ++k )
     427             :         {
     428             :             try
     429             :             {
     430           0 :                 xContainer->addProperty( m_aCustomProperties[k]->m_sName,
     431           0 :                     beans::PropertyAttribute::REMOVABLE, m_aCustomProperties[k]->m_aValue );
     432             :             }
     433           0 :             catch ( Exception& )
     434             :             {
     435             :                 SAL_WARN( "sfx.dialog", "SfxDocumentInfoItem::updateDocumentInfo(): exception while adding custom properties" );
     436             :             }
     437           0 :         }
     438             :     }
     439           0 :     catch ( Exception& )
     440             :     {
     441             :         SAL_WARN( "sfx.dialog", "SfxDocumentInfoItem::updateDocumentInfo(): exception while removing custom properties" );
     442             :     }
     443             : }
     444             : 
     445             : 
     446           0 : bool SfxDocumentInfoItem::IsDeleteUserData() const
     447             : {
     448           0 :     return m_bDeleteUserData;
     449             : }
     450             : 
     451           0 : void SfxDocumentInfoItem::SetDeleteUserData( bool bSet )
     452             : {
     453           0 :     m_bDeleteUserData = bSet;
     454           0 : }
     455             : 
     456           0 : bool SfxDocumentInfoItem::IsUseUserData() const
     457             : {
     458           0 :     return m_bUseUserData;
     459             : }
     460             : 
     461           0 : void SfxDocumentInfoItem::SetUseUserData( bool bSet )
     462             : {
     463           0 :     m_bUseUserData = bSet;
     464           0 : }
     465             : 
     466           0 : std::vector< CustomProperty* > SfxDocumentInfoItem::GetCustomProperties() const
     467             : {
     468           0 :     std::vector< CustomProperty* > aRet;
     469           0 :     for ( sal_uInt32 i = 0; i < m_aCustomProperties.size(); i++ )
     470             :     {
     471           0 :         CustomProperty* pProp = new CustomProperty( m_aCustomProperties[i]->m_sName,
     472           0 :                                                     m_aCustomProperties[i]->m_aValue );
     473           0 :         aRet.push_back( pProp );
     474             :     }
     475             : 
     476           0 :     return aRet;
     477             : }
     478             : 
     479           0 : void SfxDocumentInfoItem::ClearCustomProperties()
     480             : {
     481           0 :     for ( sal_uInt32 i = 0; i < m_aCustomProperties.size(); i++ )
     482           0 :         delete m_aCustomProperties[i];
     483           0 :     m_aCustomProperties.clear();
     484           0 : }
     485             : 
     486           0 : void SfxDocumentInfoItem::AddCustomProperty( const OUString& sName, const Any& rValue )
     487             : {
     488           0 :     CustomProperty* pProp = new CustomProperty( sName, rValue );
     489           0 :     m_aCustomProperties.push_back( pProp );
     490           0 : }
     491             : 
     492           0 : uno::Sequence< document::CmisProperty > SfxDocumentInfoItem::GetCmisProperties() const
     493             : {
     494           0 :     return m_aCmisProperties;
     495             : }
     496             : 
     497           0 : void SfxDocumentInfoItem::SetCmisProperties( Sequence< document::CmisProperty > cmisProps)
     498             : {
     499           0 :     m_aCmisProperties = cmisProps;
     500           0 : }
     501             : 
     502           0 : bool SfxDocumentInfoItem::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
     503             : {
     504           0 :     OUString aValue;
     505           0 :     sal_Int32 nValue = 0;
     506           0 :     bool bValue = false;
     507           0 :     bool bIsInt = false;
     508           0 :     bool bIsString = false;
     509           0 :     nMemberId &= ~CONVERT_TWIPS;
     510           0 :     switch ( nMemberId )
     511             :     {
     512             :         case MID_DOCINFO_USEUSERDATA:
     513           0 :             bValue = IsUseUserData();
     514           0 :             break;
     515             :         case MID_DOCINFO_DELETEUSERDATA:
     516           0 :             bValue = IsDeleteUserData();
     517           0 :             break;
     518             :         case MID_DOCINFO_AUTOLOADENABLED:
     519           0 :             bValue = isAutoloadEnabled();
     520           0 :             break;
     521             :         case MID_DOCINFO_AUTOLOADSECS:
     522           0 :             bIsInt = true;
     523           0 :             nValue = getAutoloadDelay();
     524           0 :             break;
     525             :         case MID_DOCINFO_AUTOLOADURL:
     526           0 :             bIsString = true;
     527           0 :             aValue = getAutoloadURL();
     528           0 :             break;
     529             :         case MID_DOCINFO_DEFAULTTARGET:
     530           0 :             bIsString = true;
     531           0 :             aValue = getDefaultTarget();
     532           0 :             break;
     533             :         case MID_DOCINFO_DESCRIPTION:
     534           0 :             bIsString = true;
     535           0 :             aValue = getDescription();
     536           0 :             break;
     537             :         case MID_DOCINFO_KEYWORDS:
     538           0 :             bIsString = true;
     539           0 :             aValue = getKeywords();
     540           0 :             break;
     541             :         case MID_DOCINFO_SUBJECT:
     542           0 :             bIsString = true;
     543           0 :             aValue = getSubject();
     544           0 :             break;
     545             :         case MID_DOCINFO_TITLE:
     546           0 :             bIsString = true;
     547           0 :             aValue = getTitle();
     548           0 :             break;
     549             :         default:
     550             :             OSL_FAIL("Wrong MemberId!");
     551           0 :             return false;
     552             :      }
     553             : 
     554           0 :     if ( bIsString )
     555           0 :         rVal <<= OUString( aValue );
     556           0 :     else if ( bIsInt )
     557           0 :         rVal <<= nValue;
     558             :     else
     559           0 :         rVal <<= bValue;
     560           0 :     return true;
     561             : }
     562             : 
     563           0 : bool SfxDocumentInfoItem::PutValue( const Any& rVal, sal_uInt8 nMemberId )
     564             : {
     565           0 :     OUString aValue;
     566           0 :     sal_Int32 nValue=0;
     567           0 :     bool bValue = false;
     568           0 :     bool bRet = false;
     569           0 :     nMemberId &= ~CONVERT_TWIPS;
     570           0 :     switch ( nMemberId )
     571             :     {
     572             :         case MID_DOCINFO_USEUSERDATA:
     573           0 :             bRet = (rVal >>= bValue);
     574           0 :             if ( bRet )
     575           0 :                 SetUseUserData( bValue );
     576           0 :             break;
     577             :         case MID_DOCINFO_DELETEUSERDATA:
     578             :             // QUESTION: deleting user data was done here; seems to be superfluous!
     579           0 :             bRet = (rVal >>= bValue);
     580           0 :             if ( bRet )
     581           0 :                 SetDeleteUserData( bValue );
     582           0 :             break;
     583             :         case MID_DOCINFO_AUTOLOADENABLED:
     584           0 :             bRet = (rVal >>= bValue);
     585           0 :             if ( bRet )
     586           0 :                 setAutoloadEnabled(bValue);
     587           0 :             break;
     588             :         case MID_DOCINFO_AUTOLOADSECS:
     589           0 :             bRet = (rVal >>= nValue);
     590           0 :             if ( bRet )
     591           0 :                 setAutoloadDelay(nValue);
     592           0 :             break;
     593             :         case MID_DOCINFO_AUTOLOADURL:
     594           0 :             bRet = (rVal >>= aValue);
     595           0 :             if ( bRet )
     596           0 :                 setAutoloadURL(aValue);
     597           0 :             break;
     598             :         case MID_DOCINFO_DEFAULTTARGET:
     599           0 :             bRet = (rVal >>= aValue);
     600           0 :             if ( bRet )
     601           0 :                 setDefaultTarget(aValue);
     602           0 :             break;
     603             :         case MID_DOCINFO_DESCRIPTION:
     604           0 :             bRet = (rVal >>= aValue);
     605           0 :             if ( bRet )
     606           0 :                 setDescription(aValue);
     607           0 :             break;
     608             :         case MID_DOCINFO_KEYWORDS:
     609           0 :             bRet = (rVal >>= aValue);
     610           0 :             if ( bRet )
     611           0 :                 setKeywords(aValue);
     612           0 :             break;
     613             :         case MID_DOCINFO_SUBJECT:
     614           0 :             bRet = (rVal >>= aValue);
     615           0 :             if ( bRet )
     616           0 :                 setSubject(aValue);
     617           0 :             break;
     618             :         case MID_DOCINFO_TITLE:
     619           0 :             bRet = (rVal >>= aValue);
     620           0 :             if ( bRet )
     621           0 :                 setTitle(aValue);
     622           0 :             break;
     623             :         default:
     624             :             OSL_FAIL("Wrong MemberId!");
     625           0 :             return false;
     626             :     }
     627             : 
     628           0 :     return bRet;
     629             : }
     630             : 
     631             : 
     632           0 : SfxDocumentDescPage::SfxDocumentDescPage( Window * pParent, const SfxItemSet& rItemSet )
     633             :     : SfxTabPage(pParent, "DescriptionInfoPage", "sfx/ui/descriptioninfopage.ui", rItemSet)
     634           0 :     , m_pInfoItem   ( NULL )
     635             : 
     636             : {
     637           0 :     get(m_pTitleEd, "title");
     638           0 :     get(m_pThemaEd, "subject");
     639           0 :     get(m_pKeywordsEd, "keywords");
     640           0 :     get(m_pCommentEd, "comments");
     641           0 : }
     642             : 
     643             : 
     644           0 : SfxTabPage *SfxDocumentDescPage::Create(Window *pParent, const SfxItemSet &rItemSet)
     645             : {
     646           0 :      return new SfxDocumentDescPage(pParent, rItemSet);
     647             : }
     648             : 
     649             : 
     650           0 : bool SfxDocumentDescPage::FillItemSet(SfxItemSet &rSet)
     651             : {
     652             :     // Test whether a change is present
     653           0 :     const bool bTitleMod = m_pTitleEd->IsModified();
     654           0 :     const bool bThemeMod = m_pThemaEd->IsModified();
     655           0 :     const bool bKeywordsMod = m_pKeywordsEd->IsModified();
     656           0 :     const bool bCommentMod = m_pCommentEd->IsModified();
     657           0 :     if ( !( bTitleMod || bThemeMod || bKeywordsMod || bCommentMod ) )
     658             :     {
     659           0 :         return false;
     660             :     }
     661             : 
     662             :     // Generating the output data
     663           0 :     const SfxPoolItem* pItem = NULL;
     664           0 :     SfxDocumentInfoItem* pInfo = NULL;
     665           0 :     SfxTabDialog* pDlg = GetTabDialog();
     666           0 :     const SfxItemSet* pExSet = NULL;
     667             : 
     668           0 :     if ( pDlg )
     669           0 :         pExSet = pDlg->GetExampleSet();
     670             : 
     671           0 :     if ( pExSet && SFX_ITEM_SET != pExSet->GetItemState( SID_DOCINFO, true, &pItem ) )
     672           0 :         pInfo = m_pInfoItem;
     673           0 :     else if ( pItem )
     674           0 :         pInfo = new SfxDocumentInfoItem( *(const SfxDocumentInfoItem *)pItem );
     675             : 
     676           0 :     if ( !pInfo )
     677             :     {
     678             :         SAL_WARN( "sfx.dialog", "SfxDocumentDescPage::FillItemSet(): no item found" );
     679           0 :         return false;
     680             :     }
     681             : 
     682           0 :     if ( bTitleMod )
     683             :     {
     684           0 :         pInfo->setTitle( m_pTitleEd->GetText() );
     685             :     }
     686           0 :     if ( bThemeMod )
     687             :     {
     688           0 :         pInfo->setSubject( m_pThemaEd->GetText() );
     689             :     }
     690           0 :     if ( bKeywordsMod )
     691             :     {
     692           0 :         pInfo->setKeywords( m_pKeywordsEd->GetText() );
     693             :     }
     694           0 :     if ( bCommentMod )
     695             :     {
     696           0 :         pInfo->setDescription( m_pCommentEd->GetText() );
     697             :     }
     698           0 :     rSet.Put( SfxDocumentInfoItem( *pInfo ) );
     699           0 :     if ( pInfo != m_pInfoItem )
     700             :     {
     701           0 :         delete pInfo;
     702             :     }
     703             : 
     704           0 :     return true;
     705             : }
     706             : 
     707             : 
     708           0 : void SfxDocumentDescPage::Reset(const SfxItemSet &rSet)
     709             : {
     710           0 :     m_pInfoItem = &(SfxDocumentInfoItem &)rSet.Get(SID_DOCINFO);
     711             : 
     712           0 :     m_pTitleEd->SetText( m_pInfoItem->getTitle() );
     713           0 :     m_pThemaEd->SetText( m_pInfoItem->getSubject() );
     714           0 :     m_pKeywordsEd->SetText( m_pInfoItem->getKeywords() );
     715           0 :     m_pCommentEd->SetText( m_pInfoItem->getDescription() );
     716             : 
     717           0 :     SFX_ITEMSET_ARG( &rSet, pROItem, SfxBoolItem, SID_DOC_READONLY, false );
     718           0 :     if ( pROItem && pROItem->GetValue() )
     719             :     {
     720           0 :         m_pTitleEd->SetReadOnly( true );
     721           0 :         m_pThemaEd->SetReadOnly( true );
     722           0 :         m_pKeywordsEd->SetReadOnly( true );
     723           0 :         m_pCommentEd->SetReadOnly( true );
     724             :     }
     725           0 : }
     726             : 
     727             : 
     728             : namespace
     729             : {
     730           0 :     OUString GetDateTimeString( sal_Int32 _nDate, sal_Int32 _nTime )
     731             :     {
     732           0 :         const LocaleDataWrapper& rWrapper( Application::GetSettings().GetLocaleDataWrapper() );
     733             : 
     734           0 :         Date aDate( _nDate );
     735           0 :         Time aTime( _nTime );
     736           0 :         OUString aStr( rWrapper.getDate( aDate ) );
     737           0 :         aStr += ", ";
     738           0 :         aStr += rWrapper.getTime( aTime );
     739           0 :         return aStr;
     740             :     }
     741             : 
     742             :     // copy from xmlsecurity/source/dialog/resourcemanager.cxx
     743           0 :     OUString GetContentPart( const OUString& _rRawString, const OUString& _rPartId )
     744             :     {
     745           0 :         OUString s;
     746             : 
     747           0 :         sal_Int32  nContStart = _rRawString.indexOf( _rPartId );
     748           0 :         if ( nContStart != -1 )
     749             :         {
     750           0 :             nContStart = nContStart + _rPartId.getLength();
     751           0 :             ++nContStart; // now its start of content, directly after Id
     752             : 
     753           0 :             sal_Int32  nContEnd = _rRawString.indexOf( ',', nContStart );
     754             : 
     755           0 :             s = _rRawString.copy( nContStart, nContEnd - nContStart );
     756             :         }
     757             : 
     758           0 :         return s;
     759             :     }
     760             : }
     761             : 
     762           0 : SfxDocumentPage::SfxDocumentPage(Window* pParent, const SfxItemSet& rItemSet)
     763             :     : SfxTabPage(pParent, "DocumentInfoPage", "sfx/ui/documentinfopage.ui", rItemSet)
     764             :     , bEnableUseUserData( false )
     765           0 :     , bHandleDelete( false )
     766             : {
     767           0 :     get(m_pBmp, "icon");
     768           0 :     get(m_pNameED, "nameed");
     769             : //FIXME    m_pNameED->SetAccessibleName( SfxResId( EDIT_FILE_NAME ).toString() );
     770           0 :     get(m_pChangePassBtn, "changepass");
     771             : 
     772           0 :     get(m_pShowTypeFT, "showtype");
     773           0 :     get(m_pReadOnlyCB, "readonlycb");
     774           0 :     get(m_pFileValFt, "showlocation");
     775           0 :     get(m_pShowSizeFT, "showsize");
     776           0 :     m_aUnknownSize = m_pShowSizeFT->GetText();
     777           0 :     m_pShowSizeFT->SetText(OUString());
     778             : 
     779           0 :     get(m_pCreateValFt, "showcreate");
     780           0 :     get(m_pChangeValFt, "showmodify");
     781           0 :     get(m_pSignedValFt, "showsigned");
     782           0 :     m_aMultiSignedStr = m_pSignedValFt->GetText();
     783           0 :     m_pSignedValFt->SetText(OUString());
     784           0 :     get(m_pSignatureBtn, "signature");
     785           0 :     get(m_pPrintValFt, "showprint");
     786           0 :     get(m_pTimeLogValFt, "showedittime");
     787           0 :     get(m_pDocNoValFt, "showrevision");
     788             : 
     789           0 :     get(m_pUseUserDataCB, "userdatacb");
     790           0 :     get(m_pDeleteBtn, "reset");
     791             : 
     792           0 :     get(m_pTemplFt, "templateft");
     793           0 :     get(m_pTemplValFt, "showtemplate");
     794             : 
     795           0 :     ImplUpdateSignatures();
     796           0 :     ImplCheckPasswordState();
     797           0 :     m_pChangePassBtn->SetClickHdl( LINK( this, SfxDocumentPage, ChangePassHdl ) );
     798           0 :     m_pSignatureBtn->SetClickHdl( LINK( this, SfxDocumentPage, SignatureHdl ) );
     799           0 :     m_pDeleteBtn->SetClickHdl( LINK( this, SfxDocumentPage, DeleteHdl ) );
     800             : 
     801             :     // [i96288] Check if the document signature command is enabled
     802             :     // on the main list enable/disable the pushbutton accordingly
     803           0 :     SvtCommandOptions aCmdOptions;
     804           0 :     if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED,
     805           0 :                              OUString( DOCUMENT_SIGNATURE_MENU_CMD ) ) )
     806           0 :         m_pSignatureBtn->Disable();
     807           0 : }
     808             : 
     809             : 
     810             : 
     811           0 : IMPL_LINK_NOARG(SfxDocumentPage, DeleteHdl)
     812             : {
     813           0 :     OUString aName;
     814           0 :     if ( bEnableUseUserData && m_pUseUserDataCB->IsChecked() )
     815           0 :         aName = SvtUserOptions().GetFullName();
     816           0 :     const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
     817           0 :     DateTime now( DateTime::SYSTEM );
     818             :     util::DateTime uDT(
     819           0 :         now.GetNanoSec(), now.GetSec(), now.GetMin(), now.GetHour(),
     820           0 :         now.GetDay(), now.GetMonth(), now.GetYear(), false);
     821           0 :     m_pCreateValFt->SetText( ConvertDateTime_Impl( aName, uDT, rLocaleWrapper ) );
     822           0 :     OUString aEmpty;
     823           0 :     m_pChangeValFt->SetText( aEmpty );
     824           0 :     m_pPrintValFt->SetText( aEmpty );
     825           0 :     const Time aTime( 0 );
     826           0 :     m_pTimeLogValFt->SetText( rLocaleWrapper.getDuration( aTime ) );
     827           0 :     m_pDocNoValFt->SetText(OUString('1'));
     828           0 :     bHandleDelete = true;
     829           0 :     return 0;
     830             : }
     831             : 
     832           0 : IMPL_LINK_NOARG(SfxDocumentPage, SignatureHdl)
     833             : {
     834           0 :     SfxObjectShell* pDoc = SfxObjectShell::Current();
     835           0 :     if( pDoc )
     836             :     {
     837           0 :         pDoc->SignDocumentContent();
     838             : 
     839           0 :         ImplUpdateSignatures();
     840             :     }
     841             : 
     842           0 :     return 0;
     843             : }
     844             : 
     845           0 : IMPL_LINK_NOARG(SfxDocumentPage, ChangePassHdl)
     846             : {
     847           0 :     SfxObjectShell* pShell = SfxObjectShell::Current();
     848             :     do
     849             :     {
     850           0 :         if (!pShell)
     851           0 :             break;
     852           0 :         SfxItemSet* pMedSet = pShell->GetMedium()->GetItemSet();
     853           0 :         if (!pMedSet)
     854           0 :             break;
     855           0 :         const SfxFilter* pFilter = pShell->GetMedium()->GetFilter();
     856           0 :         if (!pFilter)
     857           0 :             break;
     858             : 
     859           0 :         OUString aDocName;
     860           0 :         sfx2::RequestPassword(pFilter, aDocName, pMedSet);
     861           0 :         pShell->SetModified(true);
     862             :     }
     863             :     while (false);
     864           0 :     return 0;
     865             : }
     866             : 
     867           0 : void SfxDocumentPage::ImplUpdateSignatures()
     868             : {
     869           0 :     SfxObjectShell* pDoc = SfxObjectShell::Current();
     870           0 :     if ( pDoc )
     871             :     {
     872           0 :         SfxMedium* pMedium = pDoc->GetMedium();
     873           0 :         if ( pMedium && !pMedium->GetName().isEmpty() && pMedium->GetStorage().is() )
     874             :         {
     875             :             Reference< security::XDocumentDigitalSignatures > xD(
     876           0 :                 security::DocumentDigitalSignatures::createDefault(comphelper::getProcessComponentContext()) );
     877             : 
     878           0 :             OUString s;
     879           0 :             Sequence< security::DocumentSignatureInformation > aInfos;
     880           0 :             aInfos = xD->verifyDocumentContentSignatures( pMedium->GetZipStorageToSign_Impl(),
     881           0 :                                                             uno::Reference< io::XInputStream >() );
     882           0 :             if ( aInfos.getLength() > 1 )
     883           0 :                 s = m_aMultiSignedStr;
     884           0 :             else if ( aInfos.getLength() == 1 )
     885             :             {
     886           0 :                 OUString aCN_Id("CN");
     887           0 :                 const security::DocumentSignatureInformation& rInfo = aInfos[ 0 ];
     888           0 :                 s = GetDateTimeString( rInfo.SignatureDate, rInfo.SignatureTime );
     889           0 :                 s += ", ";
     890           0 :                 s += GetContentPart( rInfo.Signer->getSubjectName(), aCN_Id );
     891             :             }
     892           0 :             m_pSignedValFt->SetText( s );
     893             :         }
     894             :     }
     895           0 : }
     896             : 
     897           0 : void SfxDocumentPage::ImplCheckPasswordState()
     898             : {
     899           0 :     SfxObjectShell* pShell = SfxObjectShell::Current();
     900             :     do
     901             :     {
     902           0 :         if (!pShell)
     903           0 :             break;
     904           0 :         SfxItemSet* pMedSet = pShell->GetMedium()->GetItemSet();
     905           0 :         if (!pMedSet)
     906           0 :             break;
     907           0 :         SFX_ITEMSET_ARG( pMedSet, pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, false);
     908           0 :         uno::Sequence< beans::NamedValue > aEncryptionData;
     909           0 :         if (pEncryptionDataItem)
     910           0 :             pEncryptionDataItem->GetValue() >>= aEncryptionData;
     911             :         else
     912           0 :              break;
     913             : 
     914           0 :         if (!aEncryptionData.getLength())
     915           0 :              break;
     916           0 :         m_pChangePassBtn->Enable();
     917           0 :         return;
     918             :     }
     919             :     while (false);
     920           0 :     m_pChangePassBtn->Disable();
     921             : }
     922             : 
     923             : 
     924             : 
     925           0 : SfxTabPage* SfxDocumentPage::Create( Window* pParent, const SfxItemSet& rItemSet )
     926             : {
     927           0 :      return new SfxDocumentPage( pParent, rItemSet );
     928             : }
     929             : 
     930             : 
     931             : 
     932           0 : void SfxDocumentPage::EnableUseUserData()
     933             : {
     934           0 :     bEnableUseUserData = true;
     935           0 :     m_pUseUserDataCB->Show();
     936           0 :     m_pDeleteBtn->Show();
     937           0 : }
     938             : 
     939             : 
     940             : 
     941           0 : bool SfxDocumentPage::FillItemSet( SfxItemSet& rSet )
     942             : {
     943           0 :     bool bRet = false;
     944             : 
     945           0 :     if ( !bHandleDelete && bEnableUseUserData &&
     946           0 :          m_pUseUserDataCB->GetState() != m_pUseUserDataCB->GetSavedValue() &&
     947           0 :          GetTabDialog() && GetTabDialog()->GetExampleSet() )
     948             :     {
     949           0 :         const SfxItemSet* pExpSet = GetTabDialog()->GetExampleSet();
     950             :         const SfxPoolItem* pItem;
     951             : 
     952           0 :         if ( pExpSet && SFX_ITEM_SET == pExpSet->GetItemState( SID_DOCINFO, true, &pItem ) )
     953             :         {
     954           0 :             SfxDocumentInfoItem* m_pInfoItem = (SfxDocumentInfoItem*)pItem;
     955           0 :             bool bUseData = ( TRISTATE_TRUE == m_pUseUserDataCB->GetState() );
     956           0 :             m_pInfoItem->SetUseUserData( bUseData );
     957           0 :             rSet.Put( SfxDocumentInfoItem( *m_pInfoItem ) );
     958           0 :             bRet = true;
     959             :         }
     960             :     }
     961             : 
     962           0 :     if ( bHandleDelete )
     963             :     {
     964           0 :         const SfxItemSet* pExpSet = GetTabDialog()->GetExampleSet();
     965             :         const SfxPoolItem* pItem;
     966           0 :         if ( pExpSet && SFX_ITEM_SET == pExpSet->GetItemState( SID_DOCINFO, true, &pItem ) )
     967             :         {
     968           0 :             SfxDocumentInfoItem* m_pInfoItem = (SfxDocumentInfoItem*)pItem;
     969           0 :             bool bUseAuthor = bEnableUseUserData && m_pUseUserDataCB->IsChecked();
     970           0 :             SfxDocumentInfoItem newItem( *m_pInfoItem );
     971             :             newItem.resetUserData( bUseAuthor
     972             :                 ? SvtUserOptions().GetFullName()
     973           0 :                 : OUString() );
     974           0 :             m_pInfoItem->SetUseUserData( TRISTATE_TRUE == m_pUseUserDataCB->GetState() );
     975           0 :             newItem.SetUseUserData( TRISTATE_TRUE == m_pUseUserDataCB->GetState() );
     976             : 
     977           0 :             newItem.SetDeleteUserData( true );
     978           0 :             rSet.Put( newItem );
     979           0 :             bRet = true;
     980             :         }
     981             :     }
     982             : 
     983           0 :     if ( m_pNameED->IsModified() && !m_pNameED->GetText().isEmpty() )
     984             :     {
     985           0 :         rSet.Put( SfxStringItem( ID_FILETP_TITLE, m_pNameED->GetText() ) );
     986           0 :         bRet = true;
     987             :     }
     988             : 
     989             :     if ( /* m_pReadOnlyCB->IsModified() */ true )
     990             :     {
     991           0 :         rSet.Put( SfxBoolItem( ID_FILETP_READONLY, m_pReadOnlyCB->IsChecked() ) );
     992           0 :         bRet = true;
     993             :     }
     994             : 
     995           0 :     return bRet;
     996             : }
     997             : 
     998             : 
     999             : 
    1000           0 : void SfxDocumentPage::Reset( const SfxItemSet& rSet )
    1001             : {
    1002             :     // Determine the document information
    1003             :     const SfxDocumentInfoItem *m_pInfoItem =
    1004           0 :         &(const SfxDocumentInfoItem &)rSet.Get(SID_DOCINFO);
    1005             : 
    1006             :     // template data
    1007           0 :     if ( m_pInfoItem->HasTemplate() )
    1008           0 :         m_pTemplValFt->SetText( m_pInfoItem->getTemplateName() );
    1009             :     else
    1010             :     {
    1011           0 :         m_pTemplFt->Hide();
    1012           0 :         m_pTemplValFt->Hide();
    1013             :     }
    1014             : 
    1015             :     // determine file name
    1016           0 :     OUString aFile( m_pInfoItem->GetValue() );
    1017           0 :     OUString aFactory( aFile );
    1018           0 :     if ( aFile.getLength() > 2 && aFile[0] == '[' )
    1019             :     {
    1020           0 :         sal_Int32 nPos = aFile.indexOf( ']' );
    1021           0 :         aFactory = aFile.copy( 1, nPos-1  );
    1022           0 :         aFile = aFile.copy( nPos+1 );
    1023             :     }
    1024             : 
    1025             :     // determine name
    1026           0 :     OUString aName;
    1027           0 :     const SfxPoolItem* pItem = 0;
    1028           0 :     if ( SFX_ITEM_SET != rSet.GetItemState( ID_FILETP_TITLE, false, &pItem ) )
    1029             :     {
    1030           0 :         INetURLObject aURL(aFile);
    1031           0 :         aName = aURL.GetName( INetURLObject::DECODE_WITH_CHARSET );
    1032           0 :         if ( aName.isEmpty() || aURL.GetProtocol() == INET_PROT_PRIVATE )
    1033           0 :             aName = SfxResId( STR_NONAME ).toString();
    1034           0 :         m_pNameED->SetReadOnly( true );
    1035             :     }
    1036             :     else
    1037             :     {
    1038             :         DBG_ASSERT( pItem->IsA( TYPE( SfxStringItem ) ), "SfxDocumentPage:<SfxStringItem> expected" );
    1039           0 :         aName = ( ( SfxStringItem* ) pItem )->GetValue();
    1040             :     }
    1041           0 :     m_pNameED->SetText( aName );
    1042           0 :     m_pNameED->ClearModifyFlag();
    1043             : 
    1044             :     // determine RO-Flag
    1045           0 :     if ( SFX_ITEM_UNKNOWN == rSet.GetItemState( ID_FILETP_READONLY, false, &pItem )
    1046           0 :          || !pItem )
    1047           0 :         m_pReadOnlyCB->Hide();
    1048             :     else
    1049           0 :         m_pReadOnlyCB->Check( ( (SfxBoolItem*)pItem )->GetValue() );
    1050             : 
    1051             :     // determine context symbol
    1052           0 :     INetURLObject aURL;
    1053           0 :     aURL.SetSmartProtocol( INET_PROT_FILE );
    1054           0 :     aURL.SetSmartURL( aFactory);
    1055           0 :     const OUString& rMainURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
    1056           0 :     Image aImage = SvFileInformationManager::GetImage( aURL, true );
    1057             : 
    1058           0 :     if ( GetDPIScaleFactor() > 1)
    1059             :     {
    1060           0 :         BitmapEx b = aImage.GetBitmapEx();
    1061           0 :         b.Scale(GetDPIScaleFactor(), GetDPIScaleFactor());
    1062           0 :         aImage = Image(b);
    1063             :     }
    1064             : 
    1065           0 :     m_pBmp->SetImage( aImage );
    1066             : 
    1067             :     // determine size and type
    1068           0 :     OUString aSizeText( m_aUnknownSize );
    1069           0 :     if ( aURL.GetProtocol() == INET_PROT_FILE )
    1070           0 :         aSizeText = CreateSizeText( SfxContentHelper::GetSize( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) );
    1071           0 :     m_pShowSizeFT->SetText( aSizeText );
    1072             : 
    1073           0 :     OUString aDescription = SvFileInformationManager::GetDescription( INetURLObject(rMainURL) );
    1074           0 :     if ( aDescription.isEmpty() )
    1075           0 :         aDescription = SfxResId( STR_SFX_NEWOFFICEDOC ).toString();
    1076           0 :     m_pShowTypeFT->SetText( aDescription );
    1077             : 
    1078             :     // determine location
    1079           0 :     aURL.SetSmartURL( aFile);
    1080           0 :     if ( aURL.GetProtocol() == INET_PROT_FILE )
    1081             :     {
    1082           0 :         INetURLObject aPath( aURL );
    1083           0 :         aPath.setFinalSlash();
    1084           0 :         aPath.removeSegment();
    1085             :         // we know it's a folder -> don't need the final slash, but it's better for WB_PATHELLIPSIS
    1086           0 :         aPath.removeFinalSlash();
    1087           0 :         OUString aText( aPath.PathToFileName() ); //! (pb) MaxLen?
    1088           0 :         m_pFileValFt->SetText( aText );
    1089             :     }
    1090           0 :     else if ( aURL.GetProtocol() != INET_PROT_PRIVATE )
    1091           0 :         m_pFileValFt->SetText( aURL.GetPartBeforeLastName() );
    1092             : 
    1093             :     // handle access data
    1094           0 :     bool m_bUseUserData = m_pInfoItem->IsUseUserData();
    1095           0 :     const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
    1096             :     m_pCreateValFt->SetText( ConvertDateTime_Impl( m_pInfoItem->getAuthor(),
    1097           0 :         m_pInfoItem->getCreationDate(), rLocaleWrapper ) );
    1098           0 :     util::DateTime aTime( m_pInfoItem->getModificationDate() );
    1099           0 :     if ( aTime.Month > 0 )
    1100             :         m_pChangeValFt->SetText( ConvertDateTime_Impl(
    1101           0 :             m_pInfoItem->getModifiedBy(), aTime, rLocaleWrapper ) );
    1102           0 :     aTime = m_pInfoItem->getPrintDate();
    1103           0 :     if ( aTime.Month > 0 )
    1104             :         m_pPrintValFt->SetText( ConvertDateTime_Impl( m_pInfoItem->getPrintedBy(),
    1105           0 :             aTime, rLocaleWrapper ) );
    1106           0 :     const long nTime = m_pInfoItem->getEditingDuration();
    1107           0 :     if ( m_bUseUserData )
    1108             :     {
    1109           0 :         const Time aT( nTime/3600, (nTime%3600)/60, nTime%60 );
    1110           0 :         m_pTimeLogValFt->SetText( rLocaleWrapper.getDuration( aT ) );
    1111             :         m_pDocNoValFt->SetText( OUString::number(
    1112           0 :             m_pInfoItem->getEditingCycles() ) );
    1113             :     }
    1114             : 
    1115           0 :     TriState eState = (TriState)m_bUseUserData;
    1116             : 
    1117           0 :     if ( TRISTATE_INDET == eState )
    1118           0 :         m_pUseUserDataCB->EnableTriState( true );
    1119             : 
    1120           0 :     m_pUseUserDataCB->SetState( eState );
    1121           0 :     m_pUseUserDataCB->SaveValue();
    1122           0 :     m_pUseUserDataCB->Enable( bEnableUseUserData );
    1123           0 :     bHandleDelete = false;
    1124           0 :     m_pDeleteBtn->Enable( bEnableUseUserData );
    1125           0 : }
    1126             : 
    1127             : 
    1128           0 : SfxDocumentInfoDialog::SfxDocumentInfoDialog( Window* pParent,
    1129             :                                               const SfxItemSet& rItemSet )
    1130             :     : SfxTabDialog(0, pParent, "DocumentPropertiesDialog",
    1131             :         "sfx/ui/documentpropertiesdialog.ui", &rItemSet)
    1132           0 :     , m_nDocInfoId(0)
    1133             : {
    1134             :     const SfxDocumentInfoItem* m_pInfoItem =
    1135           0 :         &(const SfxDocumentInfoItem &)rItemSet.Get( SID_DOCINFO );
    1136             : 
    1137             : #ifdef DBG_UTIL
    1138             :     SFX_ITEMSET_ARG( &rItemSet, pURLItem, SfxStringItem, SID_BASEURL, false );
    1139             :     DBG_ASSERT( pURLItem, "No BaseURL provided for InternetTabPage!" );
    1140             : #endif
    1141             : 
    1142             :      // Determine the Titels
    1143           0 :     const SfxPoolItem* pItem = 0;
    1144           0 :     OUString aTitle( GetText() );
    1145           0 :     if ( SFX_ITEM_SET !=
    1146           0 :          rItemSet.GetItemState( SID_EXPLORER_PROPS_START, false, &pItem ) )
    1147             :     {
    1148             :         // File name
    1149           0 :         OUString aFile( m_pInfoItem->GetValue() );
    1150             : 
    1151           0 :         INetURLObject aURL;
    1152           0 :         aURL.SetSmartProtocol( INET_PROT_FILE );
    1153           0 :         aURL.SetSmartURL( aFile);
    1154           0 :         if ( INET_PROT_PRIV_SOFFICE != aURL.GetProtocol() )
    1155             :         {
    1156           0 :             OUString aLastName( aURL.GetLastName() );
    1157           0 :             if ( !aLastName.isEmpty() )
    1158           0 :                 aTitle += aLastName;
    1159             :             else
    1160           0 :                 aTitle += aFile;
    1161             :         }
    1162             :         else
    1163           0 :             aTitle += SfxResId( STR_NONAME ).toString();
    1164             :     }
    1165             :     else
    1166             :     {
    1167             :         DBG_ASSERT( pItem->IsA( TYPE( SfxStringItem ) ),
    1168             :                     "SfxDocumentInfoDialog:<SfxStringItem> expected" );
    1169           0 :         aTitle += ( ( SfxStringItem* ) pItem )->GetValue();
    1170             :     }
    1171           0 :     SetText( aTitle );
    1172             : 
    1173             :     // Property Pages
    1174           0 :     m_nDocInfoId = AddTabPage("general", SfxDocumentPage::Create, 0);
    1175           0 :     AddTabPage("description", SfxDocumentDescPage::Create, 0);
    1176           0 :     AddTabPage("customprops", SfxCustomPropertiesPage::Create, 0);
    1177           0 :     AddTabPage("cmisprops", SfxCmisPropertiesPage::Create, 0);
    1178           0 :     AddTabPage("security", SfxSecurityPage::Create, 0);
    1179           0 : }
    1180             : 
    1181             : 
    1182             : 
    1183           0 : void SfxDocumentInfoDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
    1184             : {
    1185           0 :     if ( m_nDocInfoId == nId )
    1186           0 :         ( (SfxDocumentPage&)rPage ).EnableUseUserData();
    1187           0 : }
    1188             : 
    1189           0 : void SfxDocumentInfoDialog::AddFontTabPage()
    1190             : {
    1191           0 :     AddTabPage( FONT_PAGE_ID, SfxResId( STR_FONT_TABPAGE ).toString(), SfxDocumentFontsPage::Create, 0);
    1192           0 : }
    1193             : 
    1194             : // class CustomPropertiesYesNoButton -------------------------------------
    1195             : 
    1196           0 : CustomPropertiesYesNoButton::CustomPropertiesYesNoButton( Window* pParent, const ResId& rResId ) :
    1197             :     Control( pParent, rResId ),
    1198           0 :     m_aYesButton( this, ResId( RB_PROPERTY_YES, *rResId.GetResMgr() ) ),
    1199           0 :     m_aNoButton ( this, ResId( RB_PROPERTY_NO, *rResId.GetResMgr() ) )
    1200             : {
    1201           0 :     FreeResource();
    1202           0 :     Wallpaper aWall( Color( COL_TRANSPARENT ) );
    1203           0 :     SetBackground( aWall );
    1204           0 :     SetBorderStyle( WINDOW_BORDER_MONO  );
    1205           0 :     CheckNo();
    1206           0 :     m_aYesButton.SetBackground( aWall );
    1207           0 :     m_aNoButton.SetBackground( aWall );
    1208           0 : }
    1209             : 
    1210           0 : class DurationDialog_Impl : public ModalDialog
    1211             : {
    1212             :     CheckBox*       m_pNegativeCB;
    1213             :     NumericField*   m_pYearNF;
    1214             :     NumericField*   m_pMonthNF;
    1215             :     NumericField*   m_pDayNF;
    1216             :     NumericField*   m_pHourNF;
    1217             :     NumericField*   m_pMinuteNF;
    1218             :     NumericField*   m_pSecondNF;
    1219             :     NumericField*   m_pMSecondNF;
    1220             : 
    1221             : public:
    1222             : 
    1223             :     DurationDialog_Impl( Window* pParent, const util::Duration& rDuration );
    1224             : 
    1225             :     util::Duration  GetDuration() const;
    1226             : };
    1227             : 
    1228           0 : DurationDialog_Impl::DurationDialog_Impl(Window* pParent,
    1229             :     const util::Duration& rDuration)
    1230             :     : ModalDialog(pParent, "EditDurationDialog",
    1231           0 :         "sfx/ui/editdurationdialog.ui")
    1232             : {
    1233           0 :     get(m_pNegativeCB, "negative");
    1234           0 :     get(m_pYearNF, "years");
    1235           0 :     get(m_pMonthNF, "months");
    1236           0 :     get(m_pDayNF, "days");
    1237           0 :     get(m_pHourNF, "hours");
    1238           0 :     get(m_pMinuteNF, "minutes");
    1239           0 :     get(m_pSecondNF, "seconds");
    1240           0 :     get(m_pMSecondNF, "milliseconds");
    1241             : 
    1242           0 :     m_pNegativeCB->Check(rDuration.Negative);
    1243           0 :     m_pYearNF->SetValue(rDuration.Years);
    1244           0 :     m_pMonthNF->SetValue(rDuration.Months);
    1245           0 :     m_pDayNF->SetValue(rDuration.Days);
    1246           0 :     m_pHourNF->SetValue(rDuration.Hours);
    1247           0 :     m_pMinuteNF->SetValue(rDuration.Minutes);
    1248           0 :     m_pSecondNF->SetValue(rDuration.Seconds);
    1249           0 :     m_pMSecondNF->SetValue(rDuration.NanoSeconds);
    1250           0 : }
    1251             : 
    1252           0 : util::Duration  DurationDialog_Impl::GetDuration() const
    1253             : {
    1254           0 :     util::Duration  aRet;
    1255           0 :     aRet.Negative = m_pNegativeCB->IsChecked();
    1256           0 :     aRet.Years = m_pYearNF->GetValue();
    1257           0 :     aRet.Months = m_pMonthNF->GetValue( );
    1258           0 :     aRet.Days = m_pDayNF->GetValue(   );
    1259           0 :     aRet.Hours  = m_pHourNF->GetValue( );
    1260           0 :     aRet.Minutes = m_pMinuteNF->GetValue();
    1261           0 :     aRet.Seconds = m_pSecondNF->GetValue();
    1262           0 :     aRet.NanoSeconds = m_pMSecondNF->GetValue();
    1263           0 :     return aRet;
    1264             : }
    1265             : 
    1266           0 : CustomPropertiesDurationField::CustomPropertiesDurationField( Window* pParent, const ResId& rResId, CustomPropertyLine* pLine ) :
    1267           0 :         Edit( pParent, rResId ), m_pLine( pLine )
    1268             : 
    1269             : {
    1270           0 :     SetDuration( util::Duration(false, 0, 0, 0, 0, 0, 0, 0) );
    1271           0 : }
    1272             : 
    1273           0 : CustomPropertiesDurationField::~CustomPropertiesDurationField()
    1274             : {
    1275           0 : }
    1276             : 
    1277           0 : void CustomPropertiesDurationField::RequestHelp( const HelpEvent& rHEvt )
    1278             : {
    1279           0 :     if ( rHEvt.GetMode() & HELPMODE_QUICK )
    1280             :     {
    1281           0 :         Size aSize( GetSizePixel() );
    1282           0 :         Rectangle aItemRect( rHEvt.GetMousePosPixel(), aSize );
    1283           0 :         if (Help::IsBalloonHelpEnabled())
    1284           0 :             Help::ShowBalloon( this, rHEvt.GetMousePosPixel(), GetText() );
    1285             :         else
    1286           0 :             Help::ShowQuickHelp( this, aItemRect, GetText(),
    1287           0 :                 QUICKHELP_LEFT|QUICKHELP_VCENTER );
    1288             :     }
    1289           0 : }
    1290             : 
    1291           0 : void CustomPropertiesDurationField::SetDuration( const util::Duration& rDuration )
    1292             : {
    1293           0 :     m_aDuration = rDuration;
    1294           0 :     OUString sText(rDuration.Negative ? OUString('-') : OUString('+'));
    1295           0 :     sText += m_pLine->m_sDurationFormat;
    1296           0 :     sText = sText.replaceFirst( "%1", OUString::number( rDuration.Years ) );
    1297           0 :     sText = sText.replaceFirst( "%2", OUString::number( rDuration.Months ) );
    1298           0 :     sText = sText.replaceFirst( "%3", OUString::number( rDuration.Days   ) );
    1299           0 :     sText = sText.replaceFirst( "%4", OUString::number( rDuration.Hours  ) );
    1300           0 :     sText = sText.replaceFirst( "%5", OUString::number( rDuration.Minutes) );
    1301           0 :     sText = sText.replaceFirst( "%6", OUString::number( rDuration.Seconds) );
    1302           0 :     SetText( sText );
    1303           0 : }
    1304             : 
    1305           0 : CustomPropertiesEditButton::CustomPropertiesEditButton( Window* pParent, const ResId& rResId, CustomPropertyLine* pLine ) :
    1306           0 :         PushButton( pParent, rResId ), m_pLine( pLine )
    1307             : {
    1308           0 :     SetClickHdl( LINK( this, CustomPropertiesEditButton, ClickHdl ));
    1309           0 : }
    1310             : 
    1311           0 : CustomPropertiesEditButton::~CustomPropertiesEditButton()
    1312             : {
    1313           0 : }
    1314             : 
    1315           0 : IMPL_LINK_NOARG(CustomPropertiesEditButton, ClickHdl)
    1316             : {
    1317           0 :     DurationDialog_Impl* pDurationDlg = new DurationDialog_Impl( this, m_pLine->m_aDurationField.GetDuration() );
    1318           0 :     if ( RET_OK == pDurationDlg->Execute() )
    1319           0 :         m_pLine->m_aDurationField.SetDuration( pDurationDlg->GetDuration() );
    1320           0 :     delete pDurationDlg;
    1321           0 :     return 1;
    1322             : }
    1323             : 
    1324           0 : void CustomPropertiesYesNoButton::Resize()
    1325             : {
    1326           0 :     const long nWidth = GetSizePixel().Width();
    1327           0 :     const long n3Width = LogicToPixel( Size( 3, 3 ), MAP_APPFONT ).Width();
    1328           0 :     const long nNewWidth = ( nWidth / 2 ) - n3Width - 2;
    1329           0 :     Size aSize = m_aYesButton.GetSizePixel();
    1330           0 :     const long nDelta = aSize.Width() - nNewWidth;
    1331           0 :     aSize.Width() = nNewWidth;
    1332           0 :     m_aYesButton.SetSizePixel( aSize );
    1333           0 :     Point aPos = m_aNoButton.GetPosPixel();
    1334           0 :     aPos.X() -= nDelta;
    1335           0 :     m_aNoButton.SetPosSizePixel( aPos, aSize );
    1336           0 : }
    1337             : 
    1338             : // struct CustomPropertyLine ---------------------------------------------
    1339           0 : CustomPropertyLine::CustomPropertyLine( Window* pParent ) :
    1340             :     m_aNameBox      ( pParent, SfxResId( SFX_CB_PROPERTY_NAME ) ),
    1341             :     m_aTypeBox      ( pParent, SfxResId( SFX_LB_PROPERTY_TYPE ), this ),
    1342             :     m_aValueEdit    ( pParent, SfxResId( SFX_ED_PROPERTY_VALUE ), this ),
    1343             :     m_aDateField    ( pParent, SfxResId( SFX_FLD_DATE), this),
    1344             :     m_aTimeField    ( pParent, SfxResId( SFX_FLD_TIME), this),
    1345             :     m_sDurationFormat( SfxResId( SFX_ST_DURATION_FORMAT ).toString() ),
    1346             :     m_aDurationField( pParent, SfxResId( SFX_FLD_DURATION), this),
    1347             :     m_aEditButton(    pParent, SfxResId( SFX_PB_EDIT ), this),
    1348             :     m_aYesNoButton  ( pParent, SfxResId( SFX_WIN_PROPERTY_YESNO ) ),
    1349             :     m_aRemoveButton ( pParent, SfxResId( SFX_PB_PROPERTY_REMOVE ), this ),
    1350             :     m_bIsRemoved    ( false ),
    1351           0 :     m_bTypeLostFocus( false )
    1352             : 
    1353             : {
    1354           0 :     m_aTimeField.SetExtFormat( EXTTIMEF_24H_LONG );
    1355           0 :     m_aDateField.SetExtDateFormat( XTDATEF_SYSTEM_SHORT_YYYY );
    1356             : 
    1357           0 :     m_aRemoveButton.SetModeImage(Image(SfxResId(SFX_IMG_PROPERTY_REMOVE)));
    1358           0 : }
    1359             : 
    1360           0 : void CustomPropertyLine::SetRemoved()
    1361             : {
    1362             :     DBG_ASSERT( !m_bIsRemoved, "CustomPropertyLine::SetRemoved(): line already removed" );
    1363           0 :     m_bIsRemoved = true;
    1364           0 :     m_aNameBox.Hide();
    1365           0 :     m_aTypeBox.Hide();
    1366           0 :     m_aValueEdit.Hide();
    1367           0 :     m_aDateField.Hide();
    1368           0 :     m_aTimeField.Hide();
    1369           0 :     m_aDurationField.Hide();
    1370           0 :     m_aEditButton.Hide();
    1371           0 :     m_aYesNoButton.Hide();
    1372           0 :     m_aRemoveButton.Hide();
    1373           0 : }
    1374             : 
    1375           0 : CustomPropertiesWindow::CustomPropertiesWindow(Window* pParent,
    1376             :     const OUString &rHeaderAccName,
    1377             :     const OUString &rHeaderAccType,
    1378             :     const OUString &rHeaderAccValue) :
    1379             :     Window(pParent),
    1380             :     m_aNameBox      ( this, SfxResId( SFX_CB_PROPERTY_NAME ) ),
    1381             :     m_aTypeBox      ( this, SfxResId( SFX_LB_PROPERTY_TYPE ) ),
    1382             :     m_aValueEdit    ( this, SfxResId( SFX_ED_PROPERTY_VALUE ) ),
    1383             :     m_aDateField    ( this, SfxResId( SFX_FLD_DATE) ),
    1384             :     m_aTimeField    ( this, SfxResId( SFX_FLD_TIME) ),
    1385             :     m_aDurationField( this, SfxResId( SFX_FLD_DURATION) ),
    1386             :     m_aEditButton(    this, SfxResId( SFX_PB_EDIT )),
    1387             :     m_aYesNoButton  ( this, SfxResId( SFX_WIN_PROPERTY_YESNO ) ),
    1388             :     m_aRemoveButton ( this, SfxResId( SFX_PB_PROPERTY_REMOVE ) ),
    1389             :     m_nScrollPos (0),
    1390             :     m_pCurrentLine (NULL),
    1391             :     m_aNumberFormatter( ::comphelper::getProcessComponentContext(),
    1392           0 :                         Application::GetSettings().GetLanguageTag().getLanguageType() )
    1393             : 
    1394             : {
    1395           0 :     m_aEditLoseFocusTimer.SetTimeout( 300 );
    1396           0 :     m_aEditLoseFocusTimer.SetTimeoutHdl( LINK( this, CustomPropertiesWindow, EditTimeoutHdl ) );
    1397           0 :     m_aBoxLoseFocusTimer.SetTimeout( 300 );
    1398           0 :     m_aBoxLoseFocusTimer.SetTimeoutHdl( LINK( this, CustomPropertiesWindow, BoxTimeoutHdl ) );
    1399             : 
    1400           0 :     m_aNameBox.SetAccessibleName(rHeaderAccName);
    1401           0 :     m_aTypeBox.SetAccessibleName(rHeaderAccType);
    1402           0 :     m_aValueEdit.SetAccessibleName(rHeaderAccValue);
    1403             : 
    1404           0 :     m_aNameBox.Hide();
    1405           0 :     m_aTypeBox.Hide();
    1406           0 :     m_aValueEdit.Hide();
    1407           0 :     m_aDateField.Hide();
    1408           0 :     m_aTimeField.Hide();
    1409           0 :     m_aDurationField.Hide();
    1410           0 :     m_aEditButton.Hide();
    1411           0 :     m_aYesNoButton.Hide();
    1412           0 :     m_aRemoveButton.Hide();
    1413             : 
    1414             :     m_nLineHeight =
    1415           0 :         ( m_aRemoveButton.GetPosPixel().Y() * 2 ) + m_aRemoveButton.GetSizePixel().Height();
    1416           0 : }
    1417             : 
    1418           0 : CustomPropertiesWindow::~CustomPropertiesWindow()
    1419             : {
    1420           0 :     m_aEditLoseFocusTimer.Stop();
    1421           0 :     m_aBoxLoseFocusTimer.Stop();
    1422           0 :     ClearAllLines();
    1423           0 : }
    1424             : 
    1425           0 : IMPL_LINK( CustomPropertiesWindow, TypeHdl, CustomPropertiesTypeBox*, pBox )
    1426             : {
    1427           0 :     sal_Int64 nType = sal_Int64( (sal_IntPtr)pBox->GetEntryData( pBox->GetSelectEntryPos() ) );
    1428           0 :     CustomPropertyLine* pLine = pBox->GetLine();
    1429           0 :     pLine->m_aValueEdit.Show( (CUSTOM_TYPE_TEXT == nType) || (CUSTOM_TYPE_NUMBER  == nType) );
    1430           0 :     pLine->m_aDateField.Show( (CUSTOM_TYPE_DATE == nType) || (CUSTOM_TYPE_DATETIME  == nType) );
    1431           0 :     pLine->m_aTimeField.Show( CUSTOM_TYPE_DATETIME  == nType );
    1432           0 :     pLine->m_aDurationField.Show( CUSTOM_TYPE_DURATION == nType );
    1433           0 :     pLine->m_aEditButton.Show( CUSTOM_TYPE_DURATION == nType );
    1434           0 :     pLine->m_aYesNoButton.Show( CUSTOM_TYPE_BOOLEAN == nType );
    1435             :     //adjust positions of date and time controls
    1436           0 :     if ( nType == CUSTOM_TYPE_DATE )
    1437           0 :         pLine->m_aDateField.SetPosSizePixel(pLine->m_aValueEdit.GetPosPixel(), pLine->m_aValueEdit.GetSizePixel());
    1438           0 :     else if ( nType == CUSTOM_TYPE_DATETIME)
    1439             :     {
    1440           0 :         pLine->m_aDateField.SetPosSizePixel( pLine->m_aDatePos, pLine->m_aDateTimeSize );
    1441           0 :         pLine->m_aTimeField.SetPosSizePixel(pLine->m_aTimePos, pLine->m_aDateTimeSize );
    1442             :     }
    1443             : 
    1444           0 :     return 0;
    1445             : }
    1446             : 
    1447           0 : IMPL_LINK( CustomPropertiesWindow, RemoveHdl, CustomPropertiesRemoveButton*, pButton )
    1448             : {
    1449           0 :     CustomPropertyLine* pLine = pButton->GetLine();
    1450             :     std::vector< CustomPropertyLine* >::iterator pFound =
    1451           0 :         std::find( m_aCustomPropertiesLines.begin(), m_aCustomPropertiesLines.end(), pLine );
    1452           0 :     if ( pFound != m_aCustomPropertiesLines.end() )
    1453             :     {
    1454           0 :         pLine = *pFound;
    1455           0 :         pLine->SetRemoved();
    1456           0 :         std::vector< CustomPropertyLine* >::iterator pIter = pFound + 1;
    1457           0 :         const long nDelta = GetLineHeight();
    1458           0 :         for ( ; pIter != m_aCustomPropertiesLines.end(); ++pIter )
    1459             :         {
    1460           0 :             pLine = *pIter;
    1461           0 :             if ( pLine->m_bIsRemoved )
    1462           0 :                 continue;
    1463             : 
    1464             :             Window* pWindows[] = {  &pLine->m_aNameBox, &pLine->m_aTypeBox, &pLine->m_aValueEdit,
    1465             :                                     &pLine->m_aDateField, &pLine->m_aTimeField,
    1466             :                                     &pLine->m_aDurationField, &pLine->m_aEditButton,
    1467           0 :                                     &pLine->m_aYesNoButton, &pLine->m_aRemoveButton, NULL };
    1468           0 :             Window** pCurrent = pWindows;
    1469           0 :             while ( *pCurrent )
    1470             :             {
    1471           0 :                 Point aPos = (*pCurrent)->GetPosPixel();
    1472           0 :                 aPos.Y() -= nDelta;
    1473           0 :                 (*pCurrent)->SetPosPixel( aPos );
    1474           0 :                 pCurrent++;
    1475             :             }
    1476             :         }
    1477             :     }
    1478             : 
    1479           0 :     m_aRemovedHdl.Call(0);
    1480           0 :     return 0;
    1481             : }
    1482             : 
    1483           0 : IMPL_LINK( CustomPropertiesWindow, EditLoseFocusHdl, CustomPropertiesEdit*, pEdit )
    1484             : {
    1485           0 :     if ( pEdit )
    1486             :     {
    1487           0 :         CustomPropertyLine* pLine = pEdit->GetLine();
    1488           0 :         if ( !pLine->m_bTypeLostFocus )
    1489             :         {
    1490           0 :             m_pCurrentLine = pLine;
    1491           0 :             m_aEditLoseFocusTimer.Start();
    1492             :         }
    1493             :         else
    1494           0 :             pLine->m_bTypeLostFocus = false;
    1495             :     }
    1496           0 :     return 0;
    1497             : }
    1498             : 
    1499           0 : IMPL_LINK( CustomPropertiesWindow, BoxLoseFocusHdl, CustomPropertiesTypeBox*, pBox )
    1500             : {
    1501           0 :     if ( pBox )
    1502             :     {
    1503           0 :         m_pCurrentLine = pBox->GetLine();
    1504           0 :         m_aBoxLoseFocusTimer.Start();
    1505             :     }
    1506             : 
    1507           0 :     return 0;
    1508             : }
    1509             : 
    1510           0 : IMPL_LINK_NOARG(CustomPropertiesWindow, EditTimeoutHdl)
    1511             : {
    1512           0 :     ValidateLine( m_pCurrentLine, false );
    1513           0 :     return 0;
    1514             : }
    1515             : 
    1516           0 : IMPL_LINK_NOARG(CustomPropertiesWindow, BoxTimeoutHdl)
    1517             : {
    1518           0 :     ValidateLine( m_pCurrentLine, true );
    1519           0 :     return 0;
    1520             : }
    1521             : 
    1522           0 : bool CustomPropertiesWindow::IsLineValid( CustomPropertyLine* pLine ) const
    1523             : {
    1524           0 :     bool bIsValid = true;
    1525           0 :     pLine->m_bTypeLostFocus = false;
    1526             :     sal_Int64 nType = sal_Int64(
    1527           0 :         (sal_IntPtr)pLine->m_aTypeBox.GetEntryData( pLine->m_aTypeBox.GetSelectEntryPos() ) );
    1528           0 :     OUString sValue = pLine->m_aValueEdit.GetText();
    1529           0 :     if ( sValue.isEmpty() )
    1530           0 :         return true;
    1531             : 
    1532           0 :     sal_uInt32 nIndex = 0xFFFFFFFF;
    1533           0 :     if ( CUSTOM_TYPE_NUMBER == nType )
    1534             :         nIndex = const_cast< SvNumberFormatter& >(
    1535           0 :             m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM );
    1536           0 :     else if ( CUSTOM_TYPE_DATE == nType )
    1537             :         nIndex = const_cast< SvNumberFormatter& >(
    1538           0 :             m_aNumberFormatter).GetFormatIndex( NF_DATE_SYS_DDMMYYYY );
    1539             : 
    1540           0 :     if ( nIndex != 0xFFFFFFFF )
    1541             :     {
    1542           0 :         sal_uInt32 nTemp = nIndex;
    1543           0 :         double fDummy = 0.0;
    1544             :         bIsValid = const_cast< SvNumberFormatter& >(
    1545           0 :             m_aNumberFormatter ).IsNumberFormat( sValue, nIndex, fDummy );
    1546           0 :         if ( bIsValid && nTemp != nIndex )
    1547             :             // sValue is a number but the format doesn't match the index
    1548           0 :             bIsValid = false;
    1549             :     }
    1550             : 
    1551           0 :     return bIsValid;
    1552             : }
    1553             : 
    1554           0 : void CustomPropertiesWindow::ValidateLine( CustomPropertyLine* pLine, bool bIsFromTypeBox )
    1555             : {
    1556           0 :     if ( !IsLineValid( pLine ) )
    1557             :     {
    1558           0 :         if ( bIsFromTypeBox ) // LoseFocus of TypeBox
    1559           0 :             pLine->m_bTypeLostFocus = true;
    1560           0 :         Window* pParent = GetParent()->GetParent();
    1561           0 :         if ( QueryBox( pParent, SfxResId( SFX_QB_WRONG_TYPE ) ).Execute() == RET_OK )
    1562           0 :             pLine->m_aTypeBox.SelectEntryPos( m_aTypeBox.GetEntryPos( (void*)CUSTOM_TYPE_TEXT ) );
    1563             :         else
    1564           0 :             pLine->m_aValueEdit.GrabFocus();
    1565             :     }
    1566           0 : }
    1567             : 
    1568           0 : void CustomPropertiesWindow::InitControls( HeaderBar* pHeaderBar, const ScrollBar* pScrollBar )
    1569             : {
    1570             :     DBG_ASSERT( pHeaderBar, "CustomPropertiesWindow::InitControls(): invalid headerbar" );
    1571             :     DBG_ASSERT( pScrollBar, "CustomPropertiesWindow::InitControls(): invalid scrollbar" );
    1572             : 
    1573           0 :     const long nOffset = 4;
    1574           0 :     const long nScrollBarWidth = pScrollBar->GetSizePixel().Width();
    1575           0 :     const long nButtonWidth = m_aRemoveButton.GetSizePixel().Width() + nScrollBarWidth + nOffset;
    1576           0 :     long nTypeWidth = m_aTypeBox.CalcMinimumSize().Width() + ( 2 * nOffset );
    1577           0 :     long nFullWidth = pHeaderBar->GetSizePixel().Width();
    1578           0 :     long nItemWidth = ( nFullWidth - nTypeWidth - nButtonWidth ) / 2;
    1579           0 :     pHeaderBar->SetItemSize( HI_NAME, nItemWidth );
    1580           0 :     pHeaderBar->SetItemSize( HI_TYPE, nTypeWidth );
    1581           0 :     pHeaderBar->SetItemSize( HI_VALUE, nItemWidth );
    1582           0 :     pHeaderBar->SetItemSize( HI_ACTION, nButtonWidth );
    1583             : 
    1584           0 :     Window* pWindows[] = { &m_aNameBox, &m_aTypeBox, &m_aValueEdit, &m_aRemoveButton, NULL };
    1585           0 :     Window** pCurrent = pWindows;
    1586           0 :     sal_uInt16 nPos = 0;
    1587           0 :     while ( *pCurrent )
    1588             :     {
    1589           0 :         Rectangle aRect = pHeaderBar->GetItemRect( pHeaderBar->GetItemId( nPos++ ) );
    1590           0 :         Size aSize = (*pCurrent)->GetSizePixel();
    1591           0 :         Point aPos = (*pCurrent)->GetPosPixel();
    1592           0 :         long nWidth = aRect.GetWidth() - nOffset;
    1593           0 :         if ( *pCurrent == &m_aRemoveButton )
    1594           0 :             nWidth -= pScrollBar->GetSizePixel().Width();
    1595           0 :         aSize.Width() = nWidth;
    1596           0 :         aPos.X() = aRect.getX() + ( nOffset / 2 );
    1597           0 :         (*pCurrent)->SetPosSizePixel( aPos, aSize );
    1598             : 
    1599           0 :         if ( *pCurrent == &m_aValueEdit )
    1600             :         {
    1601           0 :             Point aDurationPos( aPos );
    1602           0 :             m_aDurationField.SetPosPixel( aDurationPos );
    1603           0 :             Size aDurationSize(aSize);
    1604           0 :             aDurationSize.Width() -= (m_aEditButton.GetSizePixel().Width() + 3 );
    1605           0 :             m_aDurationField.SetSizePixel(aDurationSize);
    1606           0 :             aDurationPos.X() = aPos.X() - m_aEditButton.GetSizePixel().Width() + aSize.Width();
    1607           0 :             m_aEditButton.SetPosPixel(aDurationPos);
    1608           0 :             aSize = m_aYesNoButton.GetSizePixel();
    1609           0 :             aPos = m_aYesNoButton.GetPosPixel();
    1610           0 :             aSize.Width() = nWidth;
    1611           0 :             aPos.X() = aRect.getX() + ( nOffset / 2 );
    1612           0 :             m_aYesNoButton.SetPosSizePixel( aPos, aSize );
    1613           0 :             aSize.Width() /= 2;
    1614           0 :             aSize.Width() -= 2;
    1615           0 :             m_aDateField.SetPosSizePixel( aPos, aSize );
    1616           0 :             aPos.X() += aSize.Width() + 4;
    1617           0 :             m_aTimeField.SetPosSizePixel( aPos, aSize );
    1618             :         }
    1619             : 
    1620           0 :         pCurrent++;
    1621             :     }
    1622           0 : }
    1623             : 
    1624           0 : sal_uInt16 CustomPropertiesWindow::GetVisibleLineCount() const
    1625             : {
    1626           0 :     sal_uInt16 nCount = 0;
    1627           0 :     std::vector< CustomPropertyLine* >::const_iterator pIter;
    1628           0 :     for ( pIter = m_aCustomPropertiesLines.begin();
    1629           0 :             pIter != m_aCustomPropertiesLines.end(); ++pIter )
    1630             :     {
    1631           0 :         CustomPropertyLine* pLine = *pIter;
    1632           0 :         if ( !pLine->m_bIsRemoved )
    1633           0 :             nCount++;
    1634             :     }
    1635           0 :     return nCount;
    1636             : }
    1637             : 
    1638           0 : void CustomPropertiesWindow::updateLineWidth()
    1639             : {
    1640             :     Window* pWindows[] = {  &m_aNameBox, &m_aTypeBox, &m_aValueEdit,
    1641             :                             &m_aDateField, &m_aTimeField,
    1642             :                             &m_aDurationField, &m_aEditButton,
    1643           0 :                             &m_aYesNoButton, &m_aRemoveButton, NULL };
    1644             : 
    1645           0 :     for (std::vector< CustomPropertyLine* >::iterator aI =
    1646           0 :         m_aCustomPropertiesLines.begin(), aEnd = m_aCustomPropertiesLines.end();
    1647             :         aI != aEnd; ++aI)
    1648             :     {
    1649           0 :         CustomPropertyLine* pNewLine = *aI;
    1650             : 
    1651             :         Window* pNewWindows[] =
    1652             :             {   &pNewLine->m_aNameBox, &pNewLine->m_aTypeBox, &pNewLine->m_aValueEdit,
    1653             :                 &pNewLine->m_aDateField, &pNewLine->m_aTimeField,
    1654             :                 &pNewLine->m_aDurationField, &pNewLine->m_aEditButton,
    1655           0 :                 &pNewLine->m_aYesNoButton, &pNewLine->m_aRemoveButton, NULL };
    1656             : 
    1657           0 :         Window** pCurrent = pWindows;
    1658           0 :         Window** pNewCurrent = pNewWindows;
    1659           0 :         while ( *pCurrent )
    1660             :         {
    1661           0 :             Size aSize = (*pCurrent)->GetSizePixel();
    1662           0 :             Point aPos = (*pCurrent)->GetPosPixel();
    1663           0 :             aPos.Y() = (*pNewCurrent)->GetPosPixel().Y();
    1664           0 :             (*pNewCurrent)->SetPosSizePixel( aPos, aSize );
    1665           0 :             pCurrent++;
    1666           0 :             pNewCurrent++;
    1667             :         }
    1668             :     }
    1669           0 : }
    1670             : 
    1671           0 : void CustomPropertiesWindow::AddLine( const OUString& sName, Any& rAny )
    1672             : {
    1673           0 :     CustomPropertyLine* pNewLine = new CustomPropertyLine( this );
    1674           0 :     pNewLine->m_aTypeBox.SetSelectHdl( LINK( this, CustomPropertiesWindow, TypeHdl ) );
    1675           0 :     pNewLine->m_aRemoveButton.SetClickHdl( LINK( this, CustomPropertiesWindow, RemoveHdl ) );
    1676           0 :     pNewLine->m_aValueEdit.SetLoseFocusHdl( LINK( this, CustomPropertiesWindow, EditLoseFocusHdl ) );
    1677             :     //add lose focus handlers of date/time fields
    1678             : 
    1679           0 :     pNewLine->m_aTypeBox.SetLoseFocusHdl( LINK( this, CustomPropertiesWindow, BoxLoseFocusHdl ) );
    1680             : 
    1681           0 :     pNewLine->m_aNameBox.SetAccessibleName(m_aNameBox.GetAccessibleName());
    1682           0 :     pNewLine->m_aTypeBox.SetAccessibleName(m_aTypeBox.GetAccessibleName());
    1683           0 :     pNewLine->m_aValueEdit.SetAccessibleName(m_aValueEdit.GetAccessibleName());
    1684             : 
    1685           0 :     long nPos = GetVisibleLineCount() * GetLineHeight();
    1686           0 :     m_aCustomPropertiesLines.push_back( pNewLine );
    1687             :     Window* pWindows[] = {  &m_aNameBox, &m_aTypeBox, &m_aValueEdit,
    1688             :                             &m_aDateField, &m_aTimeField,
    1689             :                             &m_aDurationField, &m_aEditButton,
    1690           0 :                             &m_aYesNoButton, &m_aRemoveButton, NULL };
    1691             :     Window* pNewWindows[] =
    1692             :         {   &pNewLine->m_aNameBox, &pNewLine->m_aTypeBox, &pNewLine->m_aValueEdit,
    1693             :             &pNewLine->m_aDateField, &pNewLine->m_aTimeField,
    1694             :             &pNewLine->m_aDurationField, &pNewLine->m_aEditButton,
    1695           0 :             &pNewLine->m_aYesNoButton, &pNewLine->m_aRemoveButton, NULL };
    1696           0 :     Window** pCurrent = pWindows;
    1697           0 :     Window** pNewCurrent = pNewWindows;
    1698           0 :     while ( *pCurrent )
    1699             :     {
    1700           0 :         Size aSize = (*pCurrent)->GetSizePixel();
    1701           0 :         Point aPos = (*pCurrent)->GetPosPixel();
    1702           0 :         aPos.Y() += nPos;
    1703           0 :         aPos.Y() += m_nScrollPos;
    1704           0 :         (*pNewCurrent)->SetPosSizePixel( aPos, aSize );
    1705           0 :         (*pNewCurrent)->Show();
    1706           0 :         pCurrent++;
    1707           0 :         pNewCurrent++;
    1708             :     }
    1709             : 
    1710           0 :     pNewLine->m_aDatePos = pNewLine->m_aDateField.GetPosPixel();
    1711           0 :     pNewLine->m_aTimePos = pNewLine->m_aTimeField.GetPosPixel();
    1712           0 :     pNewLine->m_aDateTimeSize = pNewLine->m_aDateField.GetSizePixel();
    1713             : 
    1714           0 :     double nTmpValue = 0;
    1715           0 :     bool bTmpValue = false;
    1716           0 :     OUString sTmpValue;
    1717           0 :     util::DateTime aTmpDateTime;
    1718           0 :     util::Date aTmpDate;
    1719           0 :     util::DateTimeWithTimezone aTmpDateTimeTZ;
    1720           0 :     util::DateWithTimezone aTmpDateTZ;
    1721           0 :     util::Duration aTmpDuration;
    1722           0 :     SvtSysLocale aSysLocale;
    1723           0 :     const LocaleDataWrapper& rLocaleWrapper = aSysLocale.GetLocaleData();
    1724           0 :     pNewLine->m_aNameBox.SetText( sName );
    1725           0 :     sal_IntPtr nType = CUSTOM_TYPE_UNKNOWN;
    1726           0 :     OUString sValue;
    1727             : 
    1728           0 :     if ( rAny >>= nTmpValue )
    1729             :     {
    1730           0 :         sal_uInt32 nIndex = m_aNumberFormatter.GetFormatIndex( NF_NUMBER_SYSTEM );
    1731           0 :         m_aNumberFormatter.GetInputLineString( nTmpValue, nIndex, sValue );
    1732           0 :         pNewLine->m_aValueEdit.SetText( sValue );
    1733           0 :         nType = CUSTOM_TYPE_NUMBER;
    1734             :     }
    1735           0 :     else if ( rAny >>= bTmpValue )
    1736             :     {
    1737           0 :         sValue = ( bTmpValue ? rLocaleWrapper.getTrueWord() : rLocaleWrapper.getFalseWord() );
    1738           0 :         nType = CUSTOM_TYPE_BOOLEAN;
    1739             :     }
    1740           0 :     else if ( rAny >>= sTmpValue )
    1741             :     {
    1742           0 :         pNewLine->m_aValueEdit.SetText( sTmpValue );
    1743           0 :         nType = CUSTOM_TYPE_TEXT;
    1744             :     }
    1745           0 :     else if ( rAny >>= aTmpDate )
    1746             :     {
    1747           0 :         pNewLine->m_aDateField.SetDate( Date( aTmpDate.Day, aTmpDate.Month, aTmpDate.Year ) );
    1748           0 :         nType = CUSTOM_TYPE_DATE;
    1749             :     }
    1750           0 :     else if ( rAny >>= aTmpDateTime )
    1751             :     {
    1752           0 :         pNewLine->m_aDateField.SetDate( Date( aTmpDateTime.Day, aTmpDateTime.Month, aTmpDateTime.Year ) );
    1753           0 :         pNewLine->m_aTimeField.SetTime( Time( aTmpDateTime.Hours, aTmpDateTime.Minutes, aTmpDateTime.Seconds, aTmpDateTime.NanoSeconds ) );
    1754           0 :         pNewLine->m_aTimeField.m_isUTC = aTmpDateTime.IsUTC;
    1755           0 :         nType = CUSTOM_TYPE_DATETIME;
    1756             :     }
    1757           0 :     else if ( rAny >>= aTmpDateTZ )
    1758             :     {
    1759             :         pNewLine->m_aDateField.SetDate( Date( aTmpDateTZ.DateInTZ.Day,
    1760           0 :                     aTmpDateTZ.DateInTZ.Month, aTmpDateTZ.DateInTZ.Year ) );
    1761           0 :         pNewLine->m_aDateField.m_TZ = aTmpDateTZ.Timezone;
    1762           0 :         nType = CUSTOM_TYPE_DATE;
    1763             :     }
    1764           0 :     else if ( rAny >>= aTmpDateTimeTZ )
    1765             :     {
    1766           0 :         util::DateTime const& rDT(aTmpDateTimeTZ.DateTimeInTZ);
    1767           0 :         pNewLine->m_aDateField.SetDate( Date( rDT.Day, rDT.Month, rDT.Year ) );
    1768             :         pNewLine->m_aTimeField.SetTime( Time( rDT.Hours, rDT.Minutes,
    1769           0 :                     rDT.Seconds, rDT.NanoSeconds ) );
    1770           0 :         pNewLine->m_aTimeField.m_isUTC = rDT.IsUTC;
    1771           0 :         pNewLine->m_aDateField.m_TZ = aTmpDateTimeTZ.Timezone;
    1772           0 :         nType = CUSTOM_TYPE_DATETIME;
    1773             :     }
    1774           0 :     else if ( rAny >>= aTmpDuration )
    1775             :     {
    1776           0 :         nType = CUSTOM_TYPE_DURATION;
    1777           0 :         pNewLine->m_aDurationField.SetDuration( aTmpDuration );
    1778             :     }
    1779             : 
    1780           0 :     if ( nType != CUSTOM_TYPE_UNKNOWN )
    1781             :     {
    1782           0 :         if ( CUSTOM_TYPE_BOOLEAN == nType )
    1783             :         {
    1784           0 :             if ( bTmpValue )
    1785           0 :                 pNewLine->m_aYesNoButton.CheckYes();
    1786             :             else
    1787           0 :                 pNewLine->m_aYesNoButton.CheckNo();
    1788             :         }
    1789           0 :         pNewLine->m_aTypeBox.SelectEntryPos( m_aTypeBox.GetEntryPos( (void*)nType ) );
    1790             :     }
    1791             : 
    1792           0 :     TypeHdl( &pNewLine->m_aTypeBox );
    1793           0 :     pNewLine->m_aNameBox.GrabFocus();
    1794           0 : }
    1795             : 
    1796           0 : bool CustomPropertiesWindow::AreAllLinesValid() const
    1797             : {
    1798           0 :     bool bRet = true;
    1799           0 :     std::vector< CustomPropertyLine* >::const_iterator pIter;
    1800           0 :     for ( pIter = m_aCustomPropertiesLines.begin();
    1801           0 :             pIter != m_aCustomPropertiesLines.end(); ++pIter )
    1802             :     {
    1803           0 :         CustomPropertyLine* pLine = *pIter;
    1804           0 :         if ( !IsLineValid( pLine ) )
    1805             :         {
    1806           0 :             bRet = false;
    1807           0 :             break;
    1808             :         }
    1809             :     }
    1810             : 
    1811           0 :     return bRet;
    1812             : }
    1813             : 
    1814           0 : void CustomPropertiesWindow::ClearAllLines()
    1815             : {
    1816           0 :     std::vector< CustomPropertyLine* >::iterator pIter;
    1817           0 :     for ( pIter = m_aCustomPropertiesLines.begin();
    1818           0 :           pIter != m_aCustomPropertiesLines.end(); ++pIter )
    1819             :     {
    1820           0 :         CustomPropertyLine* pLine = *pIter;
    1821           0 :         pLine->SetRemoved();
    1822           0 :         delete pLine;
    1823             :     }
    1824           0 :     m_aCustomPropertiesLines.clear();
    1825           0 :     m_nScrollPos = 0;
    1826           0 : }
    1827             : 
    1828           0 : void CustomPropertiesWindow::DoScroll( sal_Int32 nNewPos )
    1829             : {
    1830           0 :     m_nScrollPos += nNewPos;
    1831           0 :     std::vector< CustomPropertyLine* >::iterator pIter;
    1832           0 :     for ( pIter = m_aCustomPropertiesLines.begin();
    1833           0 :             pIter != m_aCustomPropertiesLines.end(); ++pIter )
    1834             :     {
    1835           0 :         CustomPropertyLine* pLine = *pIter;
    1836           0 :         if ( pLine->m_bIsRemoved )
    1837           0 :             continue;
    1838             : 
    1839             :         Window* pWindows[] = {  &pLine->m_aNameBox, &pLine->m_aTypeBox, &pLine->m_aValueEdit, &pLine->m_aDateField, &pLine->m_aTimeField,
    1840           0 :                                 &pLine->m_aDurationField, &pLine->m_aEditButton, &pLine->m_aYesNoButton, &pLine->m_aRemoveButton, NULL };
    1841           0 :         Window** pCurrent = pWindows;
    1842           0 :         while ( *pCurrent )
    1843             :         {
    1844           0 :             Point aPos = (*pCurrent)->GetPosPixel();
    1845           0 :             aPos.Y() += nNewPos;
    1846           0 :             (*pCurrent)->SetPosPixel( aPos );
    1847           0 :             pCurrent++;
    1848             :         }
    1849             :     }
    1850           0 : }
    1851             : 
    1852           0 : Sequence< beans::PropertyValue > CustomPropertiesWindow::GetCustomProperties() const
    1853             : {
    1854           0 :     Sequence< beans::PropertyValue > aPropertiesSeq( m_aCustomPropertiesLines.size() );
    1855           0 :     sal_Int32 i = 0;
    1856           0 :     std::vector< CustomPropertyLine* >::const_iterator pIter;
    1857           0 :     for ( pIter = m_aCustomPropertiesLines.begin();
    1858           0 :             pIter != m_aCustomPropertiesLines.end(); ++pIter, ++i )
    1859             :     {
    1860           0 :         CustomPropertyLine* pLine = *pIter;
    1861           0 :         if ( pLine->m_bIsRemoved )
    1862           0 :             continue;
    1863             : 
    1864           0 :         OUString sPropertyName = pLine->m_aNameBox.GetText();
    1865           0 :         if ( !sPropertyName.isEmpty() )
    1866             :         {
    1867           0 :             aPropertiesSeq[i].Name = sPropertyName;
    1868             :             sal_Int64 nType = sal_Int64(
    1869           0 :                 (sal_IntPtr)pLine->m_aTypeBox.GetEntryData( pLine->m_aTypeBox.GetSelectEntryPos() ) );
    1870           0 :             if ( CUSTOM_TYPE_NUMBER == nType )
    1871             :             {
    1872           0 :                 double nValue = 0;
    1873             :                 sal_uInt32 nIndex = const_cast< SvNumberFormatter& >(
    1874           0 :                     m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM );
    1875             :                 bool bIsNum = const_cast< SvNumberFormatter& >( m_aNumberFormatter ).
    1876           0 :                     IsNumberFormat( pLine->m_aValueEdit.GetText(), nIndex, nValue );
    1877           0 :                 if ( bIsNum )
    1878           0 :                     aPropertiesSeq[i].Value <<= makeAny( nValue );
    1879             :             }
    1880           0 :             else if ( CUSTOM_TYPE_BOOLEAN == nType )
    1881             :             {
    1882           0 :                 bool bValue = pLine->m_aYesNoButton.IsYesChecked();
    1883           0 :                 aPropertiesSeq[i].Value <<= makeAny( bValue );
    1884             :             }
    1885           0 :             else if ( CUSTOM_TYPE_DATETIME == nType )
    1886             :             {
    1887           0 :                 Date aTmpDate = pLine->m_aDateField.GetDate();
    1888           0 :                 Time aTmpTime = pLine->m_aTimeField.GetTime();
    1889           0 :                 util::DateTime const aDateTime(aTmpTime.GetNanoSec(),
    1890           0 :                     aTmpTime.GetSec(), aTmpTime.GetMin(), aTmpTime.GetHour(),
    1891           0 :                     aTmpDate.GetDay(), aTmpDate.GetMonth(), aTmpDate.GetYear(),
    1892           0 :                     pLine->m_aTimeField.m_isUTC);
    1893           0 :                 if (pLine->m_aDateField.m_TZ.is_initialized())
    1894             :                 {
    1895           0 :                     aPropertiesSeq[i].Value <<= util::DateTimeWithTimezone(
    1896           0 :                             aDateTime, pLine->m_aDateField.m_TZ.get());
    1897             :                 }
    1898             :                 else
    1899             :                 {
    1900           0 :                     aPropertiesSeq[i].Value <<= aDateTime;
    1901             :                 }
    1902             :             }
    1903           0 :             else if ( CUSTOM_TYPE_DATE == nType )
    1904             :             {
    1905           0 :                 Date aTmpDate = pLine->m_aDateField.GetDate();
    1906           0 :                 util::Date const aDate(aTmpDate.GetDay(), aTmpDate.GetMonth(),
    1907           0 :                         aTmpDate.GetYear());
    1908           0 :                 if (pLine->m_aDateField.m_TZ.is_initialized())
    1909             :                 {
    1910           0 :                     aPropertiesSeq[i].Value <<= util::DateWithTimezone(
    1911           0 :                             aDate, pLine->m_aDateField.m_TZ.get());
    1912             :                 }
    1913             :                 else
    1914             :                 {
    1915           0 :                     aPropertiesSeq[i].Value <<= aDate;
    1916             :                 }
    1917             :             }
    1918           0 :             else if ( CUSTOM_TYPE_DURATION == nType )
    1919             :             {
    1920           0 :                 aPropertiesSeq[i].Value <<= pLine->m_aDurationField.GetDuration();
    1921             :             }
    1922             :             else
    1923             :             {
    1924           0 :                 OUString sValue( pLine->m_aValueEdit.GetText() );
    1925           0 :                 aPropertiesSeq[i].Value <<= makeAny( sValue );
    1926             :             }
    1927             :         }
    1928           0 :     }
    1929             : 
    1930           0 :     return aPropertiesSeq;
    1931             : }
    1932             : 
    1933           0 : CustomPropertiesControl::CustomPropertiesControl(Window* pParent)
    1934             :     : VclVBox(pParent)
    1935             :     , m_pHeaderBar(NULL)
    1936             :     , m_pBody(NULL)
    1937             :     , m_pPropertiesWin(NULL)
    1938             :     , m_pVertScroll(NULL)
    1939           0 :     , m_nThumbPos(0)
    1940             : {
    1941           0 : }
    1942             : 
    1943           0 : void CustomPropertiesControl::Init(VclBuilderContainer& rBuilder)
    1944             : {
    1945           0 :     m_pHeaderBar = new HeaderBar(this, WB_BUTTONSTYLE | WB_BOTTOMBORDER);
    1946           0 :     m_pBody = new VclHBox(this);
    1947           0 :     OUString sName = rBuilder.get<FixedText>("name")->GetText();
    1948           0 :     OUString sType = rBuilder.get<FixedText>("type")->GetText();
    1949           0 :     OUString sValue = rBuilder.get<FixedText>("value")->GetText();
    1950           0 :     m_pPropertiesWin = new CustomPropertiesWindow(m_pBody, sName, sType, sValue);
    1951           0 :     m_pVertScroll = new ScrollBar(m_pBody, WB_VERT);
    1952             : 
    1953           0 :     set_hexpand(true);
    1954           0 :     set_vexpand(true);
    1955           0 :     set_expand(true);
    1956           0 :     set_fill(true);
    1957             : 
    1958           0 :     m_pBody->set_hexpand(true);
    1959           0 :     m_pBody->set_vexpand(true);
    1960           0 :     m_pBody->set_expand(true);
    1961           0 :     m_pBody->set_fill(true);
    1962           0 :     m_pBody->Show();
    1963             : 
    1964           0 :     m_pPropertiesWin->set_hexpand(true);
    1965           0 :     m_pPropertiesWin->set_vexpand(true);
    1966           0 :     m_pPropertiesWin->set_expand(true);
    1967           0 :     m_pPropertiesWin->set_fill(true);
    1968           0 :     m_pPropertiesWin->Show();
    1969             : 
    1970           0 :     m_pPropertiesWin->SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFieldColor() ) );
    1971           0 :     m_pVertScroll->EnableDrag();
    1972           0 :     m_pVertScroll->Show();
    1973             : 
    1974           0 :     m_pHeaderBar->set_height_request(GetTextHeight() + 6);
    1975             : 
    1976           0 :     const HeaderBarItemBits nHeadBits = HIB_VCENTER | HIB_FIXED | HIB_FIXEDPOS | HIB_LEFT;
    1977             : 
    1978           0 :     m_pHeaderBar->InsertItem( HI_NAME, sName, 0, nHeadBits );
    1979           0 :     m_pHeaderBar->InsertItem( HI_TYPE, sType, 0, nHeadBits );
    1980           0 :     m_pHeaderBar->InsertItem( HI_VALUE, sValue, 0, nHeadBits );
    1981           0 :     m_pHeaderBar->InsertItem( HI_ACTION, OUString(), 0, nHeadBits );
    1982           0 :     m_pHeaderBar->Show();
    1983             : 
    1984           0 :     m_pPropertiesWin->SetRemovedHdl( LINK( this, CustomPropertiesControl, RemovedHdl ) );
    1985             : 
    1986           0 :     m_pVertScroll->SetRangeMin( 0 );
    1987           0 :     m_pVertScroll->SetRangeMax( 0 );
    1988           0 :     m_pVertScroll->SetVisibleSize( 0xFFFF );
    1989             : 
    1990           0 :     Link aScrollLink = LINK( this, CustomPropertiesControl, ScrollHdl );
    1991           0 :     m_pVertScroll->SetScrollHdl( aScrollLink );
    1992           0 : }
    1993             : 
    1994           0 : void CustomPropertiesControl::setAllocation(const Size &rAllocation)
    1995             : {
    1996           0 :     VclVBox::setAllocation(rAllocation);
    1997             : 
    1998           0 :     m_pPropertiesWin->InitControls( m_pHeaderBar, m_pVertScroll );
    1999           0 :     sal_Int32 nScrollOffset = m_pPropertiesWin->GetLineHeight();
    2000           0 :     sal_Int32 nVisibleEntries = m_pPropertiesWin->GetSizePixel().Height() / nScrollOffset;
    2001           0 :     m_pVertScroll->SetPageSize( nVisibleEntries - 1 );
    2002           0 :     m_pVertScroll->SetVisibleSize( nVisibleEntries );
    2003           0 :     m_pPropertiesWin->updateLineWidth();
    2004           0 : }
    2005             : 
    2006           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeCustomPropertiesControl(Window *pParent,
    2007             :     VclBuilder::stringmap &)
    2008             : {
    2009           0 :     return new CustomPropertiesControl(pParent);
    2010             : }
    2011             : 
    2012           0 : CustomPropertiesControl::~CustomPropertiesControl()
    2013             : {
    2014           0 :     delete m_pVertScroll;
    2015           0 :     delete m_pPropertiesWin;
    2016           0 :     delete m_pBody;
    2017           0 :     delete m_pHeaderBar;
    2018           0 : }
    2019             : 
    2020           0 : IMPL_LINK( CustomPropertiesControl, ScrollHdl, ScrollBar*, pScrollBar )
    2021             : {
    2022           0 :     sal_Int32 nOffset = m_pPropertiesWin->GetLineHeight();
    2023           0 :     nOffset *= ( m_nThumbPos - pScrollBar->GetThumbPos() );
    2024           0 :     m_nThumbPos = pScrollBar->GetThumbPos();
    2025           0 :     m_pPropertiesWin->DoScroll( nOffset );
    2026           0 :     return 0;
    2027             : }
    2028             : 
    2029           0 : IMPL_LINK_NOARG(CustomPropertiesControl, RemovedHdl)
    2030             : {
    2031           0 :     m_pVertScroll->SetRangeMax( m_pPropertiesWin->GetVisibleLineCount() + 1 );
    2032           0 :     if ( m_pPropertiesWin->GetOutputSizePixel().Height() < m_pPropertiesWin->GetVisibleLineCount() * m_pPropertiesWin->GetLineHeight() )
    2033           0 :         m_pVertScroll->DoScrollAction ( SCROLL_LINEUP );
    2034           0 :     return 0;
    2035             : }
    2036             : 
    2037           0 : void CustomPropertiesControl::AddLine( const OUString& sName, Any& rAny, bool bInteractive )
    2038             : {
    2039           0 :     m_pPropertiesWin->AddLine( sName, rAny );
    2040           0 :     m_pVertScroll->SetRangeMax( m_pPropertiesWin->GetVisibleLineCount() + 1 );
    2041           0 :     if ( bInteractive && m_pPropertiesWin->GetOutputSizePixel().Height() < m_pPropertiesWin->GetVisibleLineCount() * m_pPropertiesWin->GetLineHeight() )
    2042           0 :         m_pVertScroll->DoScroll( m_pPropertiesWin->GetVisibleLineCount() + 1 );
    2043           0 : }
    2044             : 
    2045             : // class SfxCustomPropertiesPage -----------------------------------------
    2046           0 : SfxCustomPropertiesPage::SfxCustomPropertiesPage( Window* pParent, const SfxItemSet& rItemSet )
    2047           0 :     : SfxTabPage(pParent, "CustomInfoPage", "sfx/ui/custominfopage.ui", rItemSet)
    2048             : {
    2049           0 :     get(m_pPropertiesCtrl, "properties");
    2050           0 :     m_pPropertiesCtrl->Init(*this);
    2051           0 :     get<PushButton>("add")->SetClickHdl(LINK(this, SfxCustomPropertiesPage, AddHdl));
    2052           0 : }
    2053             : 
    2054           0 : IMPL_LINK_NOARG(SfxCustomPropertiesPage, AddHdl)
    2055             : {
    2056           0 :     Any aAny;
    2057           0 :     m_pPropertiesCtrl->AddLine( OUString(), aAny, true );
    2058           0 :     return 0;
    2059             : }
    2060             : 
    2061           0 : bool SfxCustomPropertiesPage::FillItemSet( SfxItemSet& rSet )
    2062             : {
    2063           0 :     bool bModified = false;
    2064           0 :     const SfxPoolItem* pItem = NULL;
    2065           0 :     SfxDocumentInfoItem* pInfo = NULL;
    2066           0 :     bool bMustDelete = false;
    2067             : 
    2068           0 :     if ( GetTabDialog() && GetTabDialog()->GetExampleSet() )
    2069             :     {
    2070           0 :         if ( SFX_ITEM_SET !=
    2071           0 :                 GetTabDialog()->GetExampleSet()->GetItemState( SID_DOCINFO, true, &pItem ) )
    2072           0 :             pInfo = &( SfxDocumentInfoItem& )rSet.Get( SID_DOCINFO );
    2073             :         else
    2074             :         {
    2075           0 :             bMustDelete = true;
    2076           0 :             pInfo = new SfxDocumentInfoItem( *( const SfxDocumentInfoItem* ) pItem );
    2077             :         }
    2078             :     }
    2079             : 
    2080           0 :     if ( pInfo )
    2081             :     {
    2082             :         // If it's a CMIS document, we can't save custom properties
    2083           0 :         if ( pInfo->isCmisDocument( ) )
    2084             :         {
    2085           0 :             if ( bMustDelete )
    2086           0 :                 delete pInfo;
    2087           0 :             return false;
    2088             :         }
    2089             : 
    2090           0 :         pInfo->ClearCustomProperties();
    2091           0 :         Sequence< beans::PropertyValue > aPropertySeq = m_pPropertiesCtrl->GetCustomProperties();
    2092           0 :         sal_Int32 i = 0, nCount = aPropertySeq.getLength();
    2093           0 :         for ( ; i < nCount; ++i )
    2094             :         {
    2095           0 :             if ( !aPropertySeq[i].Name.isEmpty() )
    2096           0 :                 pInfo->AddCustomProperty( aPropertySeq[i].Name, aPropertySeq[i].Value );
    2097           0 :         }
    2098             :     }
    2099             : 
    2100           0 :     bModified = true; //!!!
    2101             : 
    2102           0 :     if (pInfo)
    2103             :     {
    2104           0 :         if ( bModified )
    2105           0 :             rSet.Put( *pInfo );
    2106           0 :         if ( bMustDelete )
    2107           0 :             delete pInfo;
    2108             :     }
    2109           0 :     return bModified;
    2110             : }
    2111             : 
    2112           0 : void SfxCustomPropertiesPage::Reset( const SfxItemSet& rItemSet )
    2113             : {
    2114           0 :     m_pPropertiesCtrl->ClearAllLines();
    2115           0 :     const SfxDocumentInfoItem* m_pInfoItem = &(const SfxDocumentInfoItem &)rItemSet.Get(SID_DOCINFO);
    2116           0 :     std::vector< CustomProperty* > aCustomProps = m_pInfoItem->GetCustomProperties();
    2117           0 :     for ( sal_uInt32 i = 0; i < aCustomProps.size(); i++ )
    2118             :     {
    2119           0 :         m_pPropertiesCtrl->AddLine( aCustomProps[i]->m_sName, aCustomProps[i]->m_aValue, false );
    2120           0 :     }
    2121           0 : }
    2122             : 
    2123           0 : int SfxCustomPropertiesPage::DeactivatePage( SfxItemSet* /*pSet*/ )
    2124             : {
    2125           0 :     int nRet = LEAVE_PAGE;
    2126           0 :     if ( !m_pPropertiesCtrl->AreAllLinesValid() )
    2127           0 :         nRet = KEEP_PAGE;
    2128           0 :     return nRet;
    2129             : }
    2130             : 
    2131           0 : SfxTabPage* SfxCustomPropertiesPage::Create( Window* pParent, const SfxItemSet& rItemSet )
    2132             : {
    2133           0 :     return new SfxCustomPropertiesPage( pParent, rItemSet );
    2134             : }
    2135             : 
    2136           0 : CmisValue::CmisValue( Window* pParent, const OUString& aStr )
    2137             : {
    2138           0 :     m_pUIBuilder = new VclBuilder( pParent, getUIRootDir(), "sfx/ui/cmisline.ui");
    2139           0 :     get( m_aValueEdit, "value");
    2140           0 :     m_aValueEdit->Show( true );
    2141           0 :     m_aValueEdit->SetText( aStr );
    2142           0 : }
    2143             : 
    2144           0 : CmisDateTime::CmisDateTime( Window* pParent, const util::DateTime& aDateTime )
    2145             : {
    2146           0 :     m_pUIBuilder = new VclBuilder( pParent, getUIRootDir(), "sfx/ui/cmisline.ui");
    2147           0 :     get( m_aDateField, "date");
    2148           0 :     get( m_aTimeField, "time");
    2149           0 :     m_aDateField->Show( true );
    2150           0 :     m_aTimeField->Show( true );
    2151           0 :     m_aDateField->SetDate( Date( aDateTime.Day, aDateTime.Month, aDateTime.Year ) );
    2152             :     m_aTimeField->SetTime( Time( aDateTime.Hours, aDateTime.Minutes,
    2153           0 :                            aDateTime.Seconds, aDateTime.NanoSeconds ) );
    2154           0 : }
    2155             : 
    2156           0 : CmisYesNo::CmisYesNo( Window* pParent, bool bValue )
    2157             : {
    2158           0 :     m_pUIBuilder = new VclBuilder( pParent, getUIRootDir(), "sfx/ui/cmisline.ui");
    2159           0 :     get( m_aYesButton, "yes");
    2160           0 :     get( m_aNoButton, "no");
    2161           0 :     m_aYesButton->Show( true );
    2162           0 :     m_aNoButton->Show( true );
    2163           0 :     if ( bValue )
    2164           0 :         m_aYesButton->Check( );
    2165             :     else
    2166           0 :         m_aNoButton->Check( );
    2167           0 : }
    2168             : 
    2169             : // struct CmisPropertyLine ---------------------------------------------
    2170           0 : CmisPropertyLine::CmisPropertyLine( Window* pParent )
    2171             : {
    2172           0 :     m_nNumValue = 1;
    2173           0 :     m_sId = "";
    2174           0 :     m_sType = CMIS_TYPE_STRING;
    2175           0 :     m_pUIBuilder = new VclBuilder( pParent, getUIRootDir(), "sfx/ui/cmisline.ui");
    2176           0 :     get( m_pFrame, "CmisFrame" );
    2177           0 :     get( m_aName, "name" );
    2178           0 :     get( m_aType, "type" );
    2179           0 :     m_pFrame->Enable();
    2180           0 : }
    2181             : 
    2182           0 : CmisPropertyLine::~CmisPropertyLine( )
    2183             : {
    2184           0 :     std::vector< CmisValue* >::iterator pIter;
    2185           0 :     for ( pIter = m_aValues.begin();
    2186           0 :           pIter != m_aValues.end(); ++pIter )
    2187             :     {
    2188           0 :         CmisValue* pValue = *pIter;
    2189           0 :         delete pValue;
    2190             :     }
    2191           0 :     m_aValues.clear();
    2192             : 
    2193           0 :     std::vector< CmisYesNo* >::iterator pIterYesNo;
    2194           0 :     for ( pIterYesNo = m_aYesNos.begin();
    2195           0 :           pIterYesNo != m_aYesNos.end(); ++pIterYesNo )
    2196             :     {
    2197           0 :         CmisYesNo* pYesNo = *pIterYesNo;
    2198           0 :         delete pYesNo;
    2199             :     }
    2200           0 :     m_aYesNos.clear();
    2201             : 
    2202           0 :     std::vector< CmisDateTime* >::iterator pIterDateTime;
    2203           0 :     for ( pIterDateTime = m_aDateTimes.begin();
    2204           0 :           pIterDateTime != m_aDateTimes.end(); ++pIterDateTime )
    2205             :     {
    2206           0 :         CmisDateTime* pDateTime = *pIterDateTime;
    2207           0 :         delete pDateTime;
    2208             :     }
    2209           0 :     m_aDateTimes.clear();
    2210             : 
    2211           0 : }
    2212             : 
    2213           0 : long CmisPropertyLine::getItemHeight() const
    2214             : {
    2215           0 :     return VclContainer::getLayoutRequisition(*m_pFrame).Height();
    2216             : }
    2217             : 
    2218             : // class CmisPropertiesWindow -----------------------------------------
    2219             : 
    2220           0 : CmisPropertiesWindow::CmisPropertiesWindow(SfxTabPage* pParent):
    2221             :     m_aNumberFormatter( ::comphelper::getProcessComponentContext(),
    2222           0 :                         Application::GetSettings().GetLanguageTag().getLanguageType() )
    2223             : 
    2224             : {
    2225           0 :     pParent->get(m_pBox, "CmisWindow");
    2226           0 :     CmisPropertyLine aTemp( m_pBox );
    2227           0 :     m_nItemHeight = aTemp.getItemHeight();
    2228           0 : };
    2229             : 
    2230           0 : CmisPropertiesWindow::~CmisPropertiesWindow()
    2231             : {
    2232           0 :     ClearAllLines();
    2233           0 : }
    2234             : 
    2235           0 : void CmisPropertiesWindow::ClearAllLines()
    2236             : {
    2237           0 :     std::vector< CmisPropertyLine* >::iterator pIter;
    2238           0 :     for ( pIter = m_aCmisPropertiesLines.begin();
    2239           0 :           pIter != m_aCmisPropertiesLines.end(); ++pIter )
    2240             :     {
    2241           0 :         CmisPropertyLine* pLine = *pIter;
    2242           0 :         delete pLine;
    2243             :     }
    2244           0 :     m_aCmisPropertiesLines.clear();
    2245           0 : }
    2246             : 
    2247           0 : sal_uInt16 CmisPropertiesWindow::GetLineCount() const
    2248             : {
    2249           0 :     sal_uInt16 nCount = 0;
    2250           0 :     std::vector< CmisPropertyLine* >::const_iterator pIter;
    2251           0 :     for ( pIter = m_aCmisPropertiesLines.begin();
    2252           0 :           pIter != m_aCmisPropertiesLines.end(); ++pIter )
    2253           0 :         nCount += ( (*pIter)->m_nNumValue + 1 );
    2254           0 :     return nCount;
    2255             : }
    2256             : 
    2257           0 : void CmisPropertiesWindow::AddLine( const OUString& sId, const OUString& sName,
    2258             :                                     const OUString& sType, const bool bUpdatable,
    2259             :                                     const bool bRequired, const bool bMultiValued,
    2260             :                                     const bool bOpenChoice, Any& /*aChoices*/, Any& rAny )
    2261             : {
    2262           0 :     CmisPropertyLine* pNewLine = new CmisPropertyLine( m_pBox );
    2263             : 
    2264           0 :     pNewLine->m_sId = sId;
    2265           0 :     pNewLine->m_sType = sType;
    2266           0 :     pNewLine->m_bUpdatable = bUpdatable;
    2267           0 :     pNewLine->m_bRequired = bRequired;
    2268           0 :     pNewLine->m_bMultiValued = bMultiValued;
    2269           0 :     pNewLine->m_bOpenChoice = bOpenChoice;
    2270             : 
    2271           0 :     if ( sType == CMIS_TYPE_INTEGER )
    2272             :     {
    2273           0 :         Sequence< sal_Int64 > seqValue;
    2274           0 :         rAny >>= seqValue;
    2275           0 :         sal_uInt32 nIndex = m_aNumberFormatter.GetFormatIndex( NF_NUMBER_SYSTEM );
    2276           0 :         sal_Int32 m_nNumValue = seqValue.getLength( );
    2277           0 :         for ( sal_Int32 i = 0; i < m_nNumValue; ++i )
    2278             :         {
    2279           0 :             OUString sValue;
    2280           0 :             m_aNumberFormatter.GetInputLineString( seqValue[i], nIndex, sValue );
    2281           0 :             CmisValue* pValue = new CmisValue( m_pBox, sValue );
    2282           0 :             pValue->m_aValueEdit->SetReadOnly( !bUpdatable );
    2283           0 :             pNewLine->m_aValues.push_back( pValue );
    2284           0 :         }
    2285             :     }
    2286           0 :     else if ( sType == CMIS_TYPE_DECIMAL )
    2287             :     {
    2288           0 :         Sequence< double > seqValue;
    2289           0 :         rAny >>= seqValue;
    2290           0 :         sal_uInt32 nIndex = m_aNumberFormatter.GetFormatIndex( NF_NUMBER_SYSTEM );
    2291           0 :         sal_Int32 m_nNumValue = seqValue.getLength( );
    2292           0 :         for ( sal_Int32 i = 0; i < m_nNumValue; ++i )
    2293             :         {
    2294           0 :             OUString sValue;
    2295           0 :             m_aNumberFormatter.GetInputLineString( seqValue[i], nIndex, sValue );
    2296           0 :             CmisValue* pValue = new CmisValue( m_pBox, sValue );
    2297           0 :             pValue->m_aValueEdit->SetReadOnly( !bUpdatable );
    2298           0 :             pNewLine->m_aValues.push_back( pValue );
    2299           0 :         }
    2300             : 
    2301             :     }
    2302           0 :     else if ( sType == CMIS_TYPE_BOOL )
    2303             :     {
    2304           0 :         Sequence< bool > seqValue;
    2305           0 :         rAny >>= seqValue;
    2306           0 :         sal_Int32 m_nNumValue = seqValue.getLength( );
    2307           0 :         for ( sal_Int32 i = 0; i < m_nNumValue; ++i )
    2308             :         {
    2309           0 :             CmisYesNo* pYesNo = new CmisYesNo( m_pBox, seqValue[i] );
    2310           0 :             pYesNo->m_aYesButton->Enable( bUpdatable );
    2311           0 :             pYesNo->m_aNoButton->Enable( bUpdatable );
    2312           0 :             pNewLine->m_aYesNos.push_back( pYesNo );
    2313           0 :         }
    2314             :     }
    2315           0 :     else if ( sType == CMIS_TYPE_STRING )
    2316             :     {
    2317           0 :         Sequence< OUString > seqValue;
    2318           0 :         rAny >>= seqValue;
    2319           0 :         sal_Int32 m_nNumValue = seqValue.getLength( );
    2320           0 :         for ( sal_Int32 i = 0; i < m_nNumValue; ++i )
    2321             :         {
    2322           0 :             CmisValue* pValue = new CmisValue( m_pBox, seqValue[i] );
    2323           0 :             pValue->m_aValueEdit->SetReadOnly( !bUpdatable );
    2324           0 :             pNewLine->m_aValues.push_back( pValue );
    2325           0 :         }
    2326             :     }
    2327           0 :     else if ( sType == CMIS_TYPE_DATETIME )
    2328             :     {
    2329           0 :         Sequence< util::DateTime > seqValue;
    2330           0 :         rAny >>= seqValue;
    2331           0 :         sal_Int32 m_nNumValue = seqValue.getLength( );
    2332           0 :         for ( sal_Int32 i = 0; i < m_nNumValue; ++i )
    2333             :         {
    2334           0 :             CmisDateTime* pDateTime = new CmisDateTime( m_pBox, seqValue[i]);
    2335           0 :             pDateTime->m_aDateField->SetReadOnly( !bUpdatable );
    2336           0 :             pDateTime->m_aTimeField->SetReadOnly( !bUpdatable );
    2337           0 :             pNewLine->m_aDateTimes.push_back( pDateTime );
    2338           0 :         }
    2339             : 
    2340             :     }
    2341           0 :     pNewLine->m_aName->SetText( sName );
    2342           0 :     pNewLine->m_aName->Show( true );
    2343           0 :     pNewLine->m_aType->SetText( sType );
    2344           0 :     pNewLine->m_aType->Show( true );
    2345             : 
    2346           0 :     m_aCmisPropertiesLines.push_back( pNewLine );
    2347           0 : }
    2348             : 
    2349           0 : void CmisPropertiesWindow::DoScroll( sal_Int32 nNewPos )
    2350             : {
    2351           0 :     m_pBox->SetPosPixel(Point(0, nNewPos));
    2352           0 : }
    2353             : 
    2354           0 : Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() const
    2355             : {
    2356           0 :     Sequence< document::CmisProperty > aPropertiesSeq( m_aCmisPropertiesLines.size() );
    2357           0 :     sal_Int32 i = 0;
    2358           0 :     std::vector< CmisPropertyLine* >::const_iterator pIter;
    2359           0 :     for ( pIter = m_aCmisPropertiesLines.begin();
    2360           0 :             pIter != m_aCmisPropertiesLines.end(); ++pIter, ++i )
    2361             :     {
    2362           0 :         CmisPropertyLine* pLine = *pIter;
    2363             : 
    2364           0 :         aPropertiesSeq[i].Id = pLine->m_sId;
    2365           0 :         aPropertiesSeq[i].Type = pLine->m_sType;
    2366           0 :         aPropertiesSeq[i].Updatable = pLine->m_bUpdatable;
    2367           0 :         aPropertiesSeq[i].Required = pLine->m_bRequired;
    2368           0 :         aPropertiesSeq[i].OpenChoice = pLine->m_bOpenChoice;
    2369           0 :         aPropertiesSeq[i].MultiValued = pLine->m_bMultiValued;
    2370             : 
    2371           0 :         OUString sPropertyName = pLine->m_aName->GetText();
    2372           0 :         if ( !sPropertyName.isEmpty() )
    2373             :         {
    2374           0 :             aPropertiesSeq[i].Name = sPropertyName;
    2375           0 :             OUString sType = pLine->m_aType->GetText( );
    2376           0 :             if ( CMIS_TYPE_DECIMAL == sType )
    2377             :             {
    2378             :                 sal_uInt32 nIndex = const_cast< SvNumberFormatter& >(
    2379           0 :                     m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM );
    2380           0 :                 Sequence< double > seqValue( pLine->m_aValues.size( ) );
    2381           0 :                 sal_Int32 k = 0;
    2382           0 :                 for ( std::vector< CmisValue*>::const_iterator it = pLine->m_aValues.begin();
    2383           0 :                     it != pLine->m_aValues.end(); ++it, ++k)
    2384             :                 {
    2385           0 :                     double dValue = 0.0;
    2386           0 :                     OUString sValue( (*it)->m_aValueEdit->GetText() );
    2387             :                     bool bIsNum = const_cast< SvNumberFormatter& >( m_aNumberFormatter ).
    2388           0 :                     IsNumberFormat( sValue, nIndex, dValue );
    2389           0 :                     if ( bIsNum )
    2390           0 :                         seqValue[k] = dValue;
    2391           0 :                 }
    2392           0 :                 aPropertiesSeq[i].Value <<= makeAny( seqValue );
    2393             :             }
    2394           0 :             else if ( CMIS_TYPE_INTEGER == sType )
    2395             :             {
    2396             :                 sal_uInt32 nIndex = const_cast< SvNumberFormatter& >(
    2397           0 :                     m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM );
    2398           0 :                 Sequence< sal_Int64 > seqValue( pLine->m_aValues.size( ) );
    2399           0 :                 sal_Int32 k = 0;
    2400           0 :                 for ( std::vector< CmisValue*>::const_iterator it = pLine->m_aValues.begin();
    2401           0 :                     it != pLine->m_aValues.end(); ++it, ++k)
    2402             :                 {
    2403           0 :                     double dValue = 0;
    2404           0 :                     OUString sValue( (*it)->m_aValueEdit->GetText() );
    2405             :                     bool bIsNum = const_cast< SvNumberFormatter& >( m_aNumberFormatter ).
    2406           0 :                     IsNumberFormat( sValue, nIndex, dValue );
    2407           0 :                     if ( bIsNum )
    2408           0 :                         seqValue[k] = (sal_Int64) dValue;
    2409           0 :                 }
    2410           0 :                 aPropertiesSeq[i].Value <<= makeAny( seqValue );
    2411             :             }
    2412           0 :             else if ( CMIS_TYPE_BOOL == sType )
    2413             :             {
    2414           0 :                 Sequence< bool > seqValue( pLine->m_aYesNos.size( ) );
    2415           0 :                 sal_Int32 k = 0;
    2416           0 :                 for ( std::vector< CmisYesNo*>::const_iterator it = pLine->m_aYesNos.begin();
    2417           0 :                     it != pLine->m_aYesNos.end(); ++it, ++k)
    2418             :                 {
    2419           0 :                     bool bValue = (*it)->m_aYesButton->IsChecked();
    2420           0 :                     seqValue[k] = bValue;
    2421             :                 }
    2422           0 :                 aPropertiesSeq[i].Value <<= makeAny( seqValue );
    2423             : 
    2424             :             }
    2425           0 :             else if ( CMIS_TYPE_DATETIME == sType )
    2426             :             {
    2427           0 :                 Sequence< util::DateTime > seqValue( pLine->m_aDateTimes.size( ) );
    2428           0 :                 sal_Int32 k = 0;
    2429           0 :                 for ( std::vector< CmisDateTime*>::const_iterator it = pLine->m_aDateTimes.begin();
    2430           0 :                     it != pLine->m_aDateTimes.end(); ++it, ++k)
    2431             :                 {
    2432           0 :                     Date aTmpDate = (*it)->m_aDateField->GetDate();
    2433           0 :                     Time aTmpTime = (*it)->m_aTimeField->GetTime();
    2434           0 :                     util::DateTime aDateTime( aTmpTime.GetNanoSec(), aTmpTime.GetSec(),
    2435           0 :                                               aTmpTime.GetMin(), aTmpTime.GetHour(),
    2436           0 :                                               aTmpDate.GetDay(), aTmpDate.GetMonth(),
    2437           0 :                                               aTmpDate.GetYear(), sal_True );
    2438           0 :                     seqValue[k] = aDateTime;
    2439             :                 }
    2440           0 :                 aPropertiesSeq[i].Value <<= makeAny( seqValue );
    2441             :             }
    2442             :             else
    2443             :             {
    2444           0 :                 Sequence< OUString > seqValue( pLine->m_aValues.size( ) );
    2445           0 :                 sal_Int32 k = 0;
    2446           0 :                 for ( std::vector< CmisValue*>::const_iterator it = pLine->m_aValues.begin();
    2447           0 :                     it != pLine->m_aValues.end(); ++it, ++k)
    2448             :                 {
    2449           0 :                     OUString sValue( (*it)->m_aValueEdit->GetText() );
    2450           0 :                     seqValue[k] = sValue;
    2451           0 :                 }
    2452           0 :                 aPropertiesSeq[i].Value <<= makeAny( seqValue );
    2453           0 :             }
    2454             :         }
    2455           0 :     }
    2456             : 
    2457           0 :     return aPropertiesSeq;
    2458             : }
    2459             : 
    2460           0 : CmisPropertiesControl::CmisPropertiesControl(SfxTabPage* pParent)
    2461             :     : m_pPropertiesWin( pParent )
    2462           0 :     , m_rScrolledWindow( *pParent->get<VclScrolledWindow>("CmisScroll"))
    2463           0 :     , m_rVertScroll( m_rScrolledWindow.getVertScrollBar())
    2464             : {
    2465           0 :     m_rScrolledWindow.setUserManagedScrolling(true);
    2466           0 :     m_rVertScroll.EnableDrag();
    2467           0 :     m_rVertScroll.Show( m_rScrolledWindow.GetStyle() & WB_VSCROLL);
    2468           0 :     m_rVertScroll.SetRangeMin(0);
    2469           0 :     m_rVertScroll.SetVisibleSize( 0xFFFF );
    2470             : 
    2471           0 :     Link aScrollLink = LINK( this, CmisPropertiesControl, ScrollHdl );
    2472           0 :     m_rVertScroll.SetScrollHdl( aScrollLink );
    2473           0 : }
    2474             : 
    2475           0 : void CmisPropertiesControl::ClearAllLines()
    2476             : {
    2477           0 :    m_pPropertiesWin.ClearAllLines();
    2478           0 : }
    2479             : 
    2480           0 : IMPL_LINK( CmisPropertiesControl, ScrollHdl, ScrollBar*, pScrollBar )
    2481             : {
    2482           0 :     sal_Int32 nOffset = m_pPropertiesWin.GetItemHeight();
    2483           0 :     nOffset *= ( pScrollBar->GetThumbPos() );
    2484           0 :     m_pPropertiesWin.DoScroll( -nOffset );
    2485           0 :     return 0;
    2486             : }
    2487             : 
    2488           0 : void CmisPropertiesControl::checkAutoVScroll()
    2489             : {
    2490           0 :     WinBits nBits = m_rScrolledWindow.GetStyle();
    2491           0 :     if (nBits & WB_VSCROLL)
    2492           0 :         return;
    2493           0 :     if (nBits & WB_AUTOVSCROLL)
    2494             :     {
    2495           0 :         bool bShow = m_rVertScroll.GetRangeMax() > m_rVertScroll.GetVisibleSize();
    2496           0 :         if (bShow != m_rVertScroll.IsVisible())
    2497           0 :             m_rVertScroll.Show(bShow);
    2498             :     }
    2499             : }
    2500             : 
    2501           0 : void CmisPropertiesControl::setScrollRange()
    2502             : {
    2503           0 :     sal_Int32 nScrollOffset = m_pPropertiesWin.GetItemHeight();
    2504           0 :     sal_Int32 nVisibleItems = m_rScrolledWindow.getVisibleChildSize().Height() / nScrollOffset;
    2505           0 :     m_rVertScroll.SetPageSize( nVisibleItems - 1 );
    2506           0 :     m_rVertScroll.SetVisibleSize( nVisibleItems );
    2507           0 :     m_rVertScroll.Scroll();
    2508           0 :     checkAutoVScroll();
    2509           0 : }
    2510             : 
    2511           0 : void CmisPropertiesControl::AddLine( const OUString& sId, const OUString& sName,
    2512             :                                      const OUString& sType, const bool bUpdatable,
    2513             :                                      const bool bRequired, const bool bMultiValued,
    2514             :                                      const bool bOpenChoice, Any& aChoices, Any& rAny
    2515             :                                      )
    2516             : {
    2517           0 :     m_rVertScroll.SetRangeMax( m_pPropertiesWin.GetLineCount() + 1 );
    2518           0 :     m_rVertScroll.DoScroll( m_pPropertiesWin.GetLineCount() + 1 );
    2519             :     m_pPropertiesWin.AddLine( sId, sName, sType, bUpdatable, bRequired, bMultiValued,
    2520           0 :                                bOpenChoice, aChoices, rAny );
    2521           0 :     checkAutoVScroll();
    2522           0 : }
    2523             : 
    2524             : // class SfxCmisPropertiesPage -----------------------------------------
    2525           0 : SfxCmisPropertiesPage::SfxCmisPropertiesPage( Window* pParent, const SfxItemSet& rItemSet )
    2526             :     : SfxTabPage(pParent, "CmisInfoPage", "sfx/ui/cmisinfopage.ui", rItemSet)
    2527           0 :     , m_pPropertiesCtrl( this )
    2528             : {
    2529           0 : }
    2530             : 
    2531           0 : bool SfxCmisPropertiesPage::FillItemSet( SfxItemSet& rSet )
    2532             : {
    2533           0 :     const SfxPoolItem* pItem = NULL;
    2534           0 :     SfxDocumentInfoItem* pInfo = NULL;
    2535           0 :     bool bMustDelete = false;
    2536             : 
    2537           0 :     if ( GetTabDialog() && GetTabDialog()->GetExampleSet() )
    2538             :     {
    2539           0 :         if ( SFX_ITEM_SET !=
    2540           0 :                 GetTabDialog()->GetExampleSet()->GetItemState( SID_DOCINFO, true, &pItem ) )
    2541           0 :             pInfo = &( SfxDocumentInfoItem& )rSet.Get( SID_DOCINFO );
    2542             :         else
    2543             :         {
    2544           0 :             bMustDelete = true;
    2545           0 :             pInfo = new SfxDocumentInfoItem( *( const SfxDocumentInfoItem* ) pItem );
    2546             :         }
    2547             :     }
    2548             : 
    2549           0 :     sal_Int32 modifiedNum = 0;
    2550           0 :     if ( pInfo )
    2551             :     {
    2552           0 :         Sequence< document::CmisProperty > aOldProps = pInfo->GetCmisProperties( );
    2553           0 :         Sequence< document::CmisProperty > aNewProps = m_pPropertiesCtrl.GetCmisProperties();
    2554             : 
    2555           0 :         std::vector< document::CmisProperty > changedProps;
    2556           0 :         for ( sal_Int32 i = 0; i< aNewProps.getLength( ); ++i )
    2557             :         {
    2558           0 :             if ( aOldProps[i].Updatable && !aNewProps[i].Id.isEmpty( ) )
    2559             :             {
    2560           0 :                 if ( aOldProps[i].Type == CMIS_TYPE_DATETIME )
    2561             :                 {
    2562           0 :                     Sequence< util::DateTime > oldValue;
    2563           0 :                     aOldProps[i].Value >>= oldValue;
    2564             :                     // We only edit hours and minutes
    2565             :                     // don't compare NanoSeconds and Seconds
    2566           0 :                     for ( sal_Int32 ii = 0; ii < oldValue.getLength( ); ++ii )
    2567             :                     {
    2568           0 :                         oldValue[ii].NanoSeconds = 0;
    2569           0 :                         oldValue[ii].Seconds = 0;
    2570             :                     }
    2571           0 :                     Sequence< util::DateTime > newValue;
    2572           0 :                     aNewProps[i].Value >>= newValue;
    2573           0 :                     if ( oldValue != newValue )
    2574             :                     {
    2575           0 :                         modifiedNum++;
    2576           0 :                         changedProps.push_back( aNewProps[i] );
    2577           0 :                     }
    2578             :                 }
    2579           0 :                 else if ( aOldProps[i].Value != aNewProps[i].Value )
    2580             :                 {
    2581           0 :                     modifiedNum++;
    2582           0 :                     changedProps.push_back( aNewProps[i] );
    2583             :                 }
    2584             :             }
    2585             :         }
    2586           0 :         Sequence< document::CmisProperty> aModifiedProps( modifiedNum );
    2587           0 :         sal_Int32 nCount = 0;
    2588           0 :         for( std::vector< document::CmisProperty>::const_iterator pIter = changedProps.begin();
    2589           0 :             pIter != changedProps.end( ); ++pIter )
    2590           0 :                 aModifiedProps[ nCount++ ] = *pIter;
    2591           0 :         pInfo->SetCmisProperties( aModifiedProps );
    2592           0 :         rSet.Put( *pInfo );
    2593           0 :         if ( bMustDelete )
    2594           0 :             delete pInfo;
    2595             :     }
    2596             : 
    2597           0 :     return modifiedNum;
    2598             : }
    2599             : 
    2600           0 : void SfxCmisPropertiesPage::Reset( const SfxItemSet& rItemSet )
    2601             : {
    2602           0 :     m_pPropertiesCtrl.ClearAllLines();
    2603           0 :     const SfxDocumentInfoItem* m_pInfoItem = &(const SfxDocumentInfoItem &)rItemSet.Get(SID_DOCINFO);
    2604           0 :     uno::Sequence< document::CmisProperty > aCmisProps = m_pInfoItem->GetCmisProperties();
    2605           0 :     for ( sal_Int32 i = 0; i < aCmisProps.getLength(); i++ )
    2606             :     {
    2607           0 :         m_pPropertiesCtrl.AddLine( aCmisProps[i].Id,
    2608           0 :                                    aCmisProps[i].Name,
    2609           0 :                                    aCmisProps[i].Type,
    2610           0 :                                    aCmisProps[i].Updatable,
    2611           0 :                                    aCmisProps[i].Required,
    2612           0 :                                    aCmisProps[i].MultiValued,
    2613           0 :                                    aCmisProps[i].OpenChoice,
    2614           0 :                                    aCmisProps[i].Choices,
    2615           0 :                                    aCmisProps[i].Value );
    2616             :     }
    2617           0 :     m_pPropertiesCtrl.setScrollRange();
    2618           0 : }
    2619             : 
    2620           0 : int SfxCmisPropertiesPage::DeactivatePage( SfxItemSet* /*pSet*/ )
    2621             : {
    2622           0 :     return LEAVE_PAGE;
    2623             : }
    2624             : 
    2625           0 : SfxTabPage* SfxCmisPropertiesPage::Create( Window* pParent, const SfxItemSet& rItemSet )
    2626             : {
    2627           0 :     return new SfxCmisPropertiesPage( pParent, rItemSet );
    2628         447 : }
    2629             : 
    2630             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10