LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/fldui - flddinf.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 228 0.0 %
Date: 2012-12-17 Functions: 0 15 0.0 %
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 <sfx2/request.hxx>
      21             : #include <sfx2/frame.hxx>
      22             : #include <vcl/svapp.hxx>
      23             : #include <svl/zforlist.hxx>
      24             : #include <svl/zformat.hxx>
      25             : #include "svtools/treelistentry.hxx"
      26             : 
      27             : #include <helpid.h>
      28             : #include <swtypes.hxx>
      29             : #include <globals.hrc>
      30             : #include <fldbas.hxx>
      31             : #include <docufld.hxx>
      32             : #include <wrtsh.hxx>
      33             : 
      34             : #include <fldui.hrc>
      35             : 
      36             : #include <fldtdlg.hrc>
      37             : #include <flddinf.hxx>
      38             : #include <swmodule.hxx>
      39             : #include <view.hxx>
      40             : #include <com/sun/star/beans/XPropertySet.hpp>
      41             : #include <com/sun/star/util/Time.hpp>
      42             : #include <com/sun/star/util/DateTime.hpp>
      43             : #include <com/sun/star/util/Date.hpp>
      44             : 
      45             : #define USER_DATA_VERSION_1 "1"
      46             : #define USER_DATA_VERSION USER_DATA_VERSION_1
      47             : 
      48             : using namespace nsSwDocInfoSubType;
      49             : using namespace com::sun::star;
      50             : 
      51           0 : SwFldDokInfPage::SwFldDokInfPage(Window* pWindow, const SfxItemSet& rCoreSet ) :
      52             :     SwFldPage( pWindow, SW_RES( TP_FLD_DOKINF ), rCoreSet ),
      53             : 
      54             :     aTypeFT     (this, SW_RES(FT_DOKINFTYPE)),
      55             :     aTypeTLB    (this, SW_RES(TLB_DOKINFTYPE)),
      56             :     aSelectionFT(this, SW_RES(FT_DOKINFSELECTION)),
      57             :     aSelectionLB(this, SW_RES(LB_DOKINFSELECTION)),
      58             :     aFormatFT   (this, SW_RES(FT_DOKINFFORMAT)),
      59             :     aFormatLB   (this, SW_RES(LB_DOKINFFORMAT)),
      60             :     aFixedCB    (this, SW_RES(CB_DOKINFFIXEDCONTENT)),
      61             : 
      62             :     pSelEntry   (0),
      63           0 :     aInfoStr    (SW_RES(STR_DOKINF_INFO))
      64             : {
      65           0 :     FreeResource();
      66             : 
      67           0 :     aTypeTLB.SetHelpId(HID_FIELD_DINF_TYPE);
      68           0 :     aTypeTLB.SetSelectionMode(SINGLE_SELECTION);
      69           0 :     aTypeTLB.SetStyle(aTypeTLB.GetStyle()|WB_HASLINES|WB_CLIPCHILDREN|WB_SORT|WB_HASBUTTONS|WB_HASBUTTONSATROOT|WB_HSCROLL);
      70             :     // Don't set font, so that the control's font is adobted!
      71             :     // Otherwise at wrong font bug to OV.
      72           0 :     aTypeTLB.SetSpaceBetweenEntries(0);
      73             : 
      74           0 :     aTypeTLB.SetNodeDefaultImages();
      75             :     //enable 'active' language selection
      76           0 :     aFormatLB.SetShowLanguageControl(sal_True);
      77             : 
      78           0 :     SFX_ITEMSET_ARG( &rCoreSet, pItem, SfxUnoAnyItem, SID_DOCINFO, sal_False );
      79           0 :     if ( pItem )
      80           0 :         pItem->GetValue() >>= xCustomPropertySet;
      81           0 : }
      82             : 
      83           0 : SwFldDokInfPage::~SwFldDokInfPage()
      84             : {
      85           0 : }
      86             : 
      87           0 : void SwFldDokInfPage::Reset(const SfxItemSet& )
      88             : {
      89           0 :     Init(); // general initialisation
      90             : 
      91             :     // initialise TypeListBox
      92           0 :     aTypeTLB.SetUpdateMode(sal_False);
      93           0 :     aTypeTLB.Clear();
      94           0 :     pSelEntry = 0;
      95             : 
      96             :     // display SubTypes in TypeLB
      97           0 :     sal_uInt16 nTypeId = TYP_DOCINFOFLD;
      98           0 :     SvTreeListEntry* pEntry = 0;
      99             : 
     100           0 :     SvTreeListEntry* pInfo = 0;
     101             : 
     102           0 :     sal_uInt16 nSubType = USHRT_MAX;
     103           0 :     if (IsFldEdit())
     104             :     {
     105           0 :         const SwField* pCurField = GetCurField();
     106           0 :         nSubType = ((SwDocInfoField*)pCurField)->GetSubType() & 0xff;
     107           0 :         if( nSubType == DI_CUSTOM )
     108             :         {
     109           0 :             m_sOldCustomFieldName = static_cast<const SwDocInfoField*>(pCurField)->GetName();
     110             :         }
     111           0 :         aFormatLB.SetAutomaticLanguage(pCurField->IsAutomaticLanguage());
     112           0 :         SwWrtShell *pSh = GetWrtShell();
     113           0 :         if(pSh)
     114             :         {
     115           0 :             const SvNumberformat* pFormat = pSh->GetNumberFormatter()->GetEntry(pCurField->GetFormat());
     116           0 :             if(pFormat)
     117           0 :                 aFormatLB.SetLanguage(pFormat->GetLanguage());
     118             :         }
     119             :     }
     120             : 
     121           0 :     sal_uInt16 nSelEntryData = USHRT_MAX;
     122           0 :     String sUserData = GetUserData();
     123           0 :     if(sUserData.GetToken(0, ';').EqualsIgnoreCaseAscii(USER_DATA_VERSION_1))
     124             :     {
     125           0 :         String sVal = sUserData.GetToken(1, ';');
     126           0 :         nSelEntryData = static_cast< sal_uInt16 >(sVal.ToInt32());
     127             :     }
     128             : 
     129           0 :     std::vector<rtl::OUString> aLst;
     130           0 :     GetFldMgr().GetSubTypes(nTypeId, aLst);
     131           0 :     for(size_t i = 0; i < aLst.size(); ++i)
     132             :     {
     133           0 :         if (!IsFldEdit() || nSubType == i)
     134             :         {
     135           0 :             if (DI_CUSTOM == i)
     136             :             {
     137           0 :                 if(xCustomPropertySet.is() )
     138             :                 {
     139           0 :                     uno::Reference< beans::XPropertySetInfo > xSetInfo = xCustomPropertySet->getPropertySetInfo();
     140           0 :                     const uno::Sequence< beans::Property > rProperties = xSetInfo->getProperties();
     141             : 
     142           0 :                     if( rProperties.getLength() )
     143             :                     {
     144           0 :                         pInfo = aTypeTLB.InsertEntry( String(SW_RES( STR_CUSTOM )) );
     145           0 :                         pInfo->SetUserData(reinterpret_cast<void*>(USHRT_MAX));
     146             : 
     147           0 :                         for (sal_Int32 n=0; n < rProperties.getLength(); n++)
     148             :                         {
     149           0 :                             rtl::OUString sEntry = rProperties[n].Name;
     150           0 :                             pEntry = aTypeTLB.InsertEntry(sEntry, pInfo);
     151           0 :                             if(m_sOldCustomFieldName.equals( sEntry ))
     152             :                             {
     153           0 :                                 pSelEntry = pEntry;
     154           0 :                                 aTypeTLB.Expand( pInfo );
     155             :                             }
     156           0 :                             pEntry->SetUserData(reinterpret_cast<void*>(i));
     157           0 :                         }
     158           0 :                     }
     159             :                 }
     160             :             }
     161             :             else
     162             :             {
     163           0 :                 if (!(IsFldDlgHtmlMode() && (i == DI_EDIT || i == DI_THEMA || i == DI_PRINT)))
     164             :                 {
     165           0 :                     pEntry = aTypeTLB.InsertEntry(aLst[i]);
     166           0 :                     pEntry->SetUserData(reinterpret_cast<void*>(i));
     167             :                 }
     168             :             }
     169           0 :             if(nSelEntryData == i)
     170           0 :                 pSelEntry = pEntry;
     171             :         }
     172             :     }
     173             : 
     174             :     // select old Pos
     175           0 :     if (pSelEntry != 0)
     176             :     {
     177           0 :         aTypeTLB.Select(pSelEntry);
     178           0 :         nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
     179             :     }
     180           0 :     else if ( aTypeTLB.GetEntry(0) )
     181             :     {
     182           0 :         pSelEntry = aTypeTLB.GetEntry(0);
     183           0 :         nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
     184             :     }
     185             : 
     186           0 :     FillSelectionLB(nSubType);
     187           0 :     if ( pSelEntry )
     188           0 :         TypeHdl();
     189             : 
     190           0 :     aTypeTLB.SetUpdateMode(sal_True);
     191           0 :     aTypeTLB.SetSelectHdl(LINK(this, SwFldDokInfPage, TypeHdl));
     192           0 :     aTypeTLB.SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
     193           0 :     aSelectionLB.SetSelectHdl(LINK(this, SwFldDokInfPage, SubTypeHdl));
     194           0 :     aSelectionLB.SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
     195           0 :     aFormatLB.SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
     196             : 
     197           0 :     if (IsFldEdit())
     198             :     {
     199           0 :         nOldSel = aSelectionLB.GetSelectEntryPos();
     200           0 :         nOldFormat = GetCurField()->GetFormat();
     201           0 :         aFixedCB.SaveValue();
     202           0 :     }
     203           0 : }
     204             : 
     205           0 : IMPL_LINK_NOARG(SwFldDokInfPage, TypeHdl)
     206             : {
     207             :     // save old ListBoxPos
     208           0 :     SvTreeListEntry* pOldEntry = pSelEntry;
     209             : 
     210             :     // current ListBoxPos
     211           0 :     pSelEntry = aTypeTLB.FirstSelected();
     212             : 
     213           0 :     if(!pSelEntry)
     214             :     {
     215           0 :         pSelEntry = aTypeTLB.GetEntry(0);
     216           0 :         aTypeTLB.Select(pSelEntry);
     217             :     }
     218             :     else
     219             : 
     220           0 :     if (pOldEntry != pSelEntry)
     221           0 :         FillSelectionLB((sal_uInt16)(sal_uLong)pSelEntry->GetUserData());
     222             : 
     223           0 :     SubTypeHdl();
     224             : 
     225           0 :     return 0;
     226             : }
     227             : 
     228           0 : IMPL_LINK_NOARG(SwFldDokInfPage, SubTypeHdl)
     229             : {
     230           0 :     sal_uInt16 nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
     231           0 :     sal_uInt16 nPos = aSelectionLB.GetSelectEntryPos();
     232             :     sal_uInt16 nExtSubType;
     233           0 :     sal_uInt16 nNewType = 0;
     234             : 
     235           0 :     if (nSubType != DI_EDIT)
     236             :     {
     237           0 :         if (nPos == LISTBOX_ENTRY_NOTFOUND)
     238             :         {
     239           0 :             if (!aSelectionLB.GetEntryCount())
     240             :             {
     241           0 :                 aFormatLB.Clear();
     242           0 :                 aFormatLB.Enable(sal_False);
     243           0 :                 aFormatFT.Enable(sal_False);
     244           0 :                 if( nSubType == DI_CUSTOM )
     245             :                 {
     246             :                     //find out which type the custom field has - for a start set to DATE format
     247           0 :                     ::rtl::OUString sName = aTypeTLB.GetEntryText(pSelEntry);
     248             :                     try
     249             :                     {
     250           0 :                         uno::Any aVal = xCustomPropertySet->getPropertyValue( sName );
     251           0 :                         const uno::Type& rValueType = aVal.getValueType();
     252           0 :                         if( rValueType == ::getCppuType( (util::DateTime*)0 ))
     253             :                         {
     254           0 :                             nNewType = NUMBERFORMAT_DATETIME;
     255             :                         }
     256           0 :                         else if( rValueType == ::getCppuType( (util::Date*)0 ))
     257             :                         {
     258           0 :                             nNewType = NUMBERFORMAT_DATE;
     259             :                         }
     260           0 :                         else if( rValueType == ::getCppuType( (util::Time*)0 ))
     261             :                         {
     262           0 :                             nNewType = NUMBERFORMAT_TIME;
     263           0 :                         }
     264             :                     }
     265           0 :                     catch( const uno::Exception& )
     266             :                     {
     267           0 :                     }
     268             :                 }
     269             :                 else
     270           0 :                     return 0;
     271             :             }
     272           0 :             nPos = 0;
     273             :         }
     274             : 
     275           0 :         nExtSubType = (sal_uInt16)(sal_uLong)aSelectionLB.GetEntryData(nPos);
     276             :     }
     277             :     else
     278           0 :         nExtSubType = DI_SUB_TIME;
     279             : 
     280           0 :     sal_uInt16 nOldType = 0;
     281           0 :     sal_Bool bEnable = sal_False;
     282           0 :     sal_Bool bOneArea = sal_False;
     283             : 
     284           0 :     if (aFormatLB.IsEnabled())
     285           0 :         nOldType = aFormatLB.GetFormatType();
     286             : 
     287           0 :     switch (nExtSubType)
     288             :     {
     289             :         case DI_SUB_AUTHOR:
     290           0 :             break;
     291             : 
     292             :         case DI_SUB_DATE:
     293           0 :             nNewType = NUMBERFORMAT_DATE;
     294           0 :             bOneArea = sal_True;
     295           0 :             break;
     296             : 
     297             :         case DI_SUB_TIME:
     298           0 :             nNewType = NUMBERFORMAT_TIME;
     299           0 :             bOneArea = sal_True;
     300           0 :             break;
     301             :     }
     302           0 :     if (!nNewType)
     303             :     {
     304           0 :         aFormatLB.Clear();
     305             :     }
     306             :     else
     307             :     {
     308           0 :         if (nOldType != nNewType)
     309             :         {
     310           0 :             aFormatLB.SetFormatType(nNewType);
     311           0 :             aFormatLB.SetOneArea(bOneArea);
     312             :         }
     313           0 :         bEnable = sal_True;
     314             :     }
     315             : 
     316           0 :     sal_uLong nFormat = IsFldEdit() ? ((SwDocInfoField*)GetCurField())->GetFormat() : 0;
     317             : 
     318           0 :     sal_uInt16 nOldSubType = IsFldEdit() ? (((SwDocInfoField*)GetCurField())->GetSubType() & 0xff00) : 0;
     319             : 
     320           0 :     if (IsFldEdit())
     321             :     {
     322           0 :         nPos = aSelectionLB.GetSelectEntryPos();
     323           0 :         if (nPos != LISTBOX_ENTRY_NOTFOUND )
     324             :         {
     325           0 :             nSubType = (sal_uInt16)(sal_uLong)aSelectionLB.GetEntryData(nPos);
     326             : 
     327           0 :             nOldSubType &= ~DI_SUB_FIXED;
     328           0 :             if (nOldSubType == nSubType)
     329             :             {
     330           0 :                 if (!nFormat && (nNewType == NUMBERFORMAT_DATE || nNewType == NUMBERFORMAT_TIME))
     331             :                 {
     332           0 :                     SwWrtShell *pSh = GetWrtShell();
     333           0 :                     if(pSh)
     334             :                     {
     335           0 :                         SvNumberFormatter* pFormatter = pSh->GetNumberFormatter();
     336           0 :                         LanguageType eLang = aFormatLB.GetCurLanguage();
     337           0 :                         if (nNewType == NUMBERFORMAT_DATE)
     338           0 :                             nFormat = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_SHORT, eLang);
     339           0 :                         else if (nNewType == NUMBERFORMAT_TIME)
     340           0 :                             nFormat = pFormatter->GetFormatIndex( NF_TIME_HHMM, eLang);
     341             :                     }
     342             :                 }
     343           0 :                 aFormatLB.SetDefFormat(nFormat);
     344             :             }
     345             :         }
     346           0 :         else if( (nSubType == DI_CUSTOM)  && (nNewType != 0) )
     347             :         {
     348           0 :             aFormatLB.SetDefFormat(nFormat);
     349             :         }
     350             :     }
     351             : 
     352           0 :     aFormatLB.Enable(bEnable);
     353           0 :     aFormatFT.Enable(bEnable);
     354             : 
     355           0 :     if (bEnable && aFormatLB.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND)
     356             :     {
     357           0 :         aFormatLB.SelectEntryPos(0);
     358             :     }
     359             : 
     360           0 :     return 0;
     361             : }
     362             : 
     363           0 : sal_uInt16 SwFldDokInfPage::FillSelectionLB(sal_uInt16 nSubType)
     364             : {
     365             :     // fill Format-Listbox
     366           0 :     sal_uInt16 nTypeId = TYP_DOCINFOFLD;
     367             : 
     368           0 :     EnableInsert(nSubType != USHRT_MAX);
     369             : 
     370           0 :     if (nSubType == USHRT_MAX)  // Info-Text
     371           0 :         nSubType = DI_SUBTYPE_BEGIN;
     372             : 
     373           0 :     aSelectionLB.Clear();
     374             : 
     375           0 :     sal_uInt16 nSize = 0;
     376           0 :     sal_uInt16 nSelPos = USHRT_MAX;
     377           0 :     sal_uInt16 nExtSubType = IsFldEdit() ? (((SwDocInfoField*)GetCurField())->GetSubType() & 0xff00) : 0;
     378             : 
     379           0 :     if (IsFldEdit())
     380             :     {
     381           0 :         aFixedCB.Check((nExtSubType & DI_SUB_FIXED) != 0);
     382           0 :         nExtSubType = ((nExtSubType & ~DI_SUB_FIXED) >> 8) - 1;
     383             :     }
     384             : 
     385           0 :     if (nSubType < DI_CREATE || nSubType == DI_DOCNO || nSubType == DI_EDIT|| nSubType == DI_CUSTOM )
     386             :     {
     387             :         // Format Box is empty for Title and Time
     388             :     }
     389             :     else
     390             :     {
     391           0 :         nSize = GetFldMgr().GetFormatCount(nTypeId, sal_False, IsFldDlgHtmlMode());
     392           0 :         for (sal_uInt16 i = 0; i < nSize; i++)
     393             :         {
     394           0 :             sal_uInt16 nPos = aSelectionLB.InsertEntry(GetFldMgr().GetFormatStr(nTypeId, i));
     395           0 :             aSelectionLB.SetEntryData(nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId(nTypeId, i)));
     396           0 :             if (IsFldEdit() && i == nExtSubType)
     397           0 :                 nSelPos = nPos;
     398             :         }
     399             :     }
     400             : 
     401           0 :     sal_Bool bEnable = nSize != 0;
     402             : 
     403           0 :     if (nSize)
     404             :     {
     405           0 :         if (!aSelectionLB.GetSelectEntryCount())
     406           0 :             aSelectionLB.SelectEntryPos(nSelPos == USHRT_MAX ? 0 : nSelPos);
     407             : 
     408           0 :         bEnable = sal_True;
     409             :     }
     410             : 
     411           0 :     aSelectionFT.Enable(bEnable);
     412           0 :     aSelectionLB.Enable(bEnable);
     413             : 
     414           0 :     return nSize;
     415             : }
     416             : 
     417           0 : sal_Bool SwFldDokInfPage::FillItemSet(SfxItemSet& )
     418             : {
     419           0 :     if (!pSelEntry || (sal_uInt16)(sal_uLong)pSelEntry->GetUserData() == USHRT_MAX)
     420           0 :         return sal_False;
     421             : 
     422           0 :     sal_uInt16 nTypeId = TYP_DOCINFOFLD;
     423           0 :     sal_uInt16 nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
     424             : 
     425           0 :     sal_uLong nFormat = 0;
     426             : 
     427           0 :     sal_uInt16 nPos = aSelectionLB.GetSelectEntryPos();
     428             : 
     429           0 :     ::rtl::OUString aName;
     430           0 :     if (DI_CUSTOM == nSubType)
     431           0 :         aName = aTypeTLB.GetEntryText(pSelEntry);
     432             : 
     433           0 :     if (nPos != LISTBOX_ENTRY_NOTFOUND)
     434           0 :         nSubType |= (sal_uInt16)(sal_uLong)aSelectionLB.GetEntryData(nPos);
     435             : 
     436           0 :     if (aFixedCB.IsChecked())
     437           0 :         nSubType |= DI_SUB_FIXED;
     438             : 
     439           0 :     nPos = aFormatLB.GetSelectEntryPos();
     440           0 :     if(nPos != LISTBOX_ENTRY_NOTFOUND)
     441           0 :         nFormat = aFormatLB.GetFormat();
     442             : 
     443           0 :     if (!IsFldEdit() || nOldSel != aSelectionLB.GetSelectEntryPos() ||
     444           0 :         nOldFormat != nFormat || aFixedCB.GetState() != aFixedCB.GetSavedValue()
     445           0 :         || (DI_CUSTOM == nSubType && !aName.equals( m_sOldCustomFieldName )))
     446             :     {
     447             :         InsertFld(nTypeId, nSubType, aName, aEmptyStr, nFormat,
     448           0 :                 ' ', aFormatLB.IsAutomaticLanguage());
     449             :     }
     450             : 
     451           0 :     return sal_False;
     452             : }
     453             : 
     454           0 : SfxTabPage* SwFldDokInfPage::Create(    Window* pParent,
     455             :                         const SfxItemSet& rAttrSet )
     456             : {
     457           0 :     return ( new SwFldDokInfPage( pParent, rAttrSet ) );
     458             : }
     459             : 
     460           0 : sal_uInt16 SwFldDokInfPage::GetGroup()
     461             : {
     462           0 :     return GRP_REG;
     463             : }
     464             : 
     465           0 : void    SwFldDokInfPage::FillUserData()
     466             : {
     467           0 :     String sData(rtl::OUString(USER_DATA_VERSION));
     468           0 :     sData += ';';
     469           0 :     SvTreeListEntry* pEntry = aTypeTLB.FirstSelected();
     470           0 :     sal_uInt16 nTypeSel = pEntry ? sal::static_int_cast< sal_uInt16 >(reinterpret_cast< sal_uIntPtr >(pEntry->GetUserData())) : USHRT_MAX;
     471           0 :     sData += String::CreateFromInt32( nTypeSel );
     472           0 :     SetUserData(sData);
     473           0 : }
     474             : 
     475             : 
     476             : 
     477             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10