LCOV - code coverage report
Current view: top level - sw/source/ui/fldui - flddinf.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 232 0.0 %
Date: 2014-04-11 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 <flddinf.hxx>
      37             : #include <swmodule.hxx>
      38             : #include <view.hxx>
      39             : #include <com/sun/star/beans/XPropertySet.hpp>
      40             : #include <com/sun/star/util/Time.hpp>
      41             : #include <com/sun/star/util/DateTime.hpp>
      42             : #include <com/sun/star/util/Date.hpp>
      43             : 
      44             : #define USER_DATA_VERSION_1 "1"
      45             : #define USER_DATA_VERSION USER_DATA_VERSION_1
      46             : 
      47             : using namespace nsSwDocInfoSubType;
      48             : using namespace com::sun::star;
      49             : 
      50           0 : SwFldDokInfPage::SwFldDokInfPage(Window* pParent, const SfxItemSet& rCoreSet)
      51             :     :  SwFldPage(pParent, "FldDocInfoPage",
      52             :         "modules/swriter/ui/flddocinfopage.ui", rCoreSet)
      53           0 :     , pSelEntry(0)
      54             : {
      55           0 :     get(m_pTypeTLB, "type");
      56           0 :     get(m_pSelection, "selectframe");
      57           0 :     get(m_pFormat, "formatframe");
      58           0 :     get(m_pSelectionLB, "select");
      59           0 :     get(m_pFormatLB, "format");
      60           0 :     get(m_pFixedCB, "fixed");
      61             : 
      62           0 :     long nHeight = m_pTypeTLB->GetTextHeight() * 20;
      63           0 :     m_pTypeTLB->set_height_request(nHeight);
      64           0 :     m_pSelectionLB->set_height_request(nHeight);
      65           0 :     m_pFormatLB->set_height_request(nHeight);
      66             : 
      67           0 :     long nWidth = m_pTypeTLB->LogicToPixel(Size(FIELD_COLUMN_WIDTH, 0), MapMode(MAP_APPFONT)).Width();
      68           0 :     m_pTypeTLB->set_width_request(nWidth);
      69           0 :     m_pFormatLB->set_width_request(nWidth);
      70           0 :     m_pSelectionLB->set_width_request(nWidth);
      71             : 
      72           0 :     m_pTypeTLB->SetSelectionMode(SINGLE_SELECTION);
      73           0 :     m_pTypeTLB->SetStyle(m_pTypeTLB->GetStyle()|WB_HASLINES|WB_CLIPCHILDREN|WB_SORT|WB_HASBUTTONS|WB_HASBUTTONSATROOT|WB_HSCROLL);
      74           0 :     m_pTypeTLB->SetOptimalImageIndent();
      75             :     // Don't set font, so that the control's font is adobted!
      76             :     // Otherwise at wrong font bug to OV.
      77           0 :     m_pTypeTLB->SetSpaceBetweenEntries(0);
      78             : 
      79           0 :     m_pTypeTLB->SetNodeDefaultImages();
      80             :     //enable 'active' language selection
      81           0 :     m_pFormatLB->SetShowLanguageControl(sal_True);
      82             : 
      83           0 :     SFX_ITEMSET_ARG( &rCoreSet, pItem, SfxUnoAnyItem, SID_DOCINFO, false );
      84           0 :     if ( pItem )
      85           0 :         pItem->GetValue() >>= xCustomPropertySet;
      86           0 : }
      87             : 
      88           0 : SwFldDokInfPage::~SwFldDokInfPage()
      89             : {
      90           0 : }
      91             : 
      92           0 : void SwFldDokInfPage::Reset(const SfxItemSet& )
      93             : {
      94           0 :     Init(); // general initialisation
      95             : 
      96             :     // initialise TypeListBox
      97           0 :     m_pTypeTLB->SetUpdateMode(false);
      98           0 :     m_pTypeTLB->Clear();
      99           0 :     pSelEntry = 0;
     100             : 
     101             :     // display SubTypes in TypeLB
     102           0 :     SvTreeListEntry* pEntry = 0;
     103             : 
     104           0 :     SvTreeListEntry* pInfo = 0;
     105             : 
     106           0 :     sal_uInt16 nSubType = USHRT_MAX;
     107           0 :     if (IsFldEdit())
     108             :     {
     109           0 :         const SwField* pCurField = GetCurField();
     110           0 :         nSubType = ((SwDocInfoField*)pCurField)->GetSubType() & 0xff;
     111           0 :         if( nSubType == DI_CUSTOM )
     112             :         {
     113           0 :             m_sOldCustomFieldName = static_cast<const SwDocInfoField*>(pCurField)->GetName();
     114             :         }
     115           0 :         m_pFormatLB->SetAutomaticLanguage(pCurField->IsAutomaticLanguage());
     116           0 :         SwWrtShell *pSh = GetWrtShell();
     117           0 :         if(pSh)
     118             :         {
     119           0 :             const SvNumberformat* pFormat = pSh->GetNumberFormatter()->GetEntry(pCurField->GetFormat());
     120           0 :             if(pFormat)
     121           0 :                 m_pFormatLB->SetLanguage(pFormat->GetLanguage());
     122             :         }
     123             :     }
     124             : 
     125           0 :     sal_Int32 nSelEntryData = LISTBOX_ENTRY_NOTFOUND;
     126           0 :     const OUString sUserData = GetUserData();
     127           0 :     if (sUserData.getToken(0, ';').equalsIgnoreAsciiCase(USER_DATA_VERSION_1))
     128             :     {
     129           0 :         nSelEntryData = sUserData.getToken(1, ';').toInt32();
     130             :     }
     131             : 
     132           0 :     std::vector<OUString> aLst;
     133           0 :     GetFldMgr().GetSubTypes(TYP_DOCINFOFLD, aLst);
     134           0 :     for(size_t i = 0; i < aLst.size(); ++i)
     135             :     {
     136           0 :         if (!IsFldEdit() || nSubType == i)
     137             :         {
     138           0 :             if (DI_CUSTOM == i)
     139             :             {
     140           0 :                 if(xCustomPropertySet.is() )
     141             :                 {
     142           0 :                     uno::Reference< beans::XPropertySetInfo > xSetInfo = xCustomPropertySet->getPropertySetInfo();
     143           0 :                     const uno::Sequence< beans::Property > rProperties = xSetInfo->getProperties();
     144             : 
     145           0 :                     if( rProperties.getLength() )
     146             :                     {
     147           0 :                         pInfo = m_pTypeTLB->InsertEntry( OUString(SW_RES( STR_CUSTOM )) );
     148           0 :                         pInfo->SetUserData(reinterpret_cast<void*>(USHRT_MAX));
     149             : 
     150           0 :                         for (sal_Int32 n=0; n < rProperties.getLength(); n++)
     151             :                         {
     152           0 :                             const OUString sEntry = rProperties[n].Name;
     153           0 :                             pEntry = m_pTypeTLB->InsertEntry(sEntry, pInfo);
     154           0 :                             if (m_sOldCustomFieldName == sEntry)
     155             :                             {
     156           0 :                                 pSelEntry = pEntry;
     157           0 :                                 m_pTypeTLB->Expand( pInfo );
     158             :                             }
     159           0 :                             pEntry->SetUserData(reinterpret_cast<void*>(i));
     160           0 :                         }
     161           0 :                     }
     162             :                 }
     163             :             }
     164             :             else
     165             :             {
     166           0 :                 if (!(IsFldDlgHtmlMode() && (i == DI_EDIT || i == DI_THEMA || i == DI_PRINT)))
     167             :                 {
     168           0 :                     pEntry = m_pTypeTLB->InsertEntry(aLst[i]);
     169           0 :                     pEntry->SetUserData(reinterpret_cast<void*>(i));
     170             :                 }
     171             :             }
     172           0 :             if(static_cast<size_t>(nSelEntryData) == i)
     173           0 :                 pSelEntry = pEntry;
     174             :         }
     175             :     }
     176             : 
     177             :     // select old Pos
     178           0 :     if (pSelEntry != 0)
     179             :     {
     180           0 :         m_pTypeTLB->Select(pSelEntry);
     181           0 :         nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
     182             :     }
     183           0 :     else if ( m_pTypeTLB->GetEntry(0) )
     184             :     {
     185           0 :         pSelEntry = m_pTypeTLB->GetEntry(0);
     186           0 :         nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
     187             :     }
     188             : 
     189           0 :     FillSelectionLB(nSubType);
     190           0 :     if ( pSelEntry )
     191           0 :         TypeHdl();
     192             : 
     193           0 :     m_pTypeTLB->SetUpdateMode(true);
     194           0 :     m_pTypeTLB->SetSelectHdl(LINK(this, SwFldDokInfPage, TypeHdl));
     195           0 :     m_pTypeTLB->SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
     196           0 :     m_pSelectionLB->SetSelectHdl(LINK(this, SwFldDokInfPage, SubTypeHdl));
     197           0 :     m_pSelectionLB->SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
     198           0 :     m_pFormatLB->SetDoubleClickHdl(LINK(this, SwFldDokInfPage, InsertHdl));
     199             : 
     200           0 :     if (IsFldEdit())
     201             :     {
     202           0 :         nOldSel = m_pSelectionLB->GetSelectEntryPos();
     203           0 :         nOldFormat = GetCurField()->GetFormat();
     204           0 :         m_pFixedCB->SaveValue();
     205           0 :     }
     206           0 : }
     207             : 
     208           0 : IMPL_LINK_NOARG(SwFldDokInfPage, TypeHdl)
     209             : {
     210             :     // save old ListBoxPos
     211           0 :     SvTreeListEntry* pOldEntry = pSelEntry;
     212             : 
     213             :     // current ListBoxPos
     214           0 :     pSelEntry = m_pTypeTLB->FirstSelected();
     215             : 
     216           0 :     if(!pSelEntry)
     217             :     {
     218           0 :         pSelEntry = m_pTypeTLB->GetEntry(0);
     219           0 :         m_pTypeTLB->Select(pSelEntry);
     220             :     }
     221           0 :     else if (pOldEntry != pSelEntry)
     222           0 :         FillSelectionLB((sal_uInt16)(sal_uLong)pSelEntry->GetUserData());
     223             : 
     224           0 :     SubTypeHdl();
     225             : 
     226           0 :     return 0;
     227             : }
     228             : 
     229           0 : IMPL_LINK_NOARG(SwFldDokInfPage, SubTypeHdl)
     230             : {
     231           0 :     sal_uInt16 nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
     232           0 :     sal_Int32 nPos = m_pSelectionLB->GetSelectEntryPos();
     233             :     sal_uInt16 nExtSubType;
     234           0 :     sal_uInt16 nNewType = 0;
     235             : 
     236           0 :     if (nSubType != DI_EDIT)
     237             :     {
     238           0 :         if (nPos == LISTBOX_ENTRY_NOTFOUND)
     239             :         {
     240           0 :             if (!m_pSelectionLB->GetEntryCount())
     241             :             {
     242           0 :                 m_pFormatLB->Clear();
     243           0 :                 m_pFormat->Enable(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 :                     const OUString sName = m_pTypeTLB->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)m_pSelectionLB->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 (m_pFormatLB->IsEnabled())
     285           0 :         nOldType = m_pFormatLB->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 :         m_pFormatLB->Clear();
     305             :     }
     306             :     else
     307             :     {
     308           0 :         if (nOldType != nNewType)
     309             :         {
     310           0 :             m_pFormatLB->SetFormatType(nNewType);
     311           0 :             m_pFormatLB->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 = m_pSelectionLB->GetSelectEntryPos();
     323           0 :         if (nPos != LISTBOX_ENTRY_NOTFOUND )
     324             :         {
     325           0 :             nSubType = (sal_uInt16)(sal_uLong)m_pSelectionLB->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 = m_pFormatLB->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 :                 m_pFormatLB->SetDefFormat(nFormat);
     344             :             }
     345             :         }
     346           0 :         else if( (nSubType == DI_CUSTOM)  && (nNewType != 0) )
     347             :         {
     348           0 :             m_pFormatLB->SetDefFormat(nFormat);
     349             :         }
     350             :     }
     351             : 
     352           0 :     m_pFormat->Enable(bEnable);
     353             : 
     354           0 :     if (bEnable && m_pFormatLB->GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND)
     355             :     {
     356           0 :         m_pFormatLB->SelectEntryPos(0);
     357             :     }
     358             : 
     359           0 :     return 0;
     360             : }
     361             : 
     362           0 : sal_Int32 SwFldDokInfPage::FillSelectionLB(sal_uInt16 nSubType)
     363             : {
     364             :     // fill Format-Listbox
     365           0 :     sal_uInt16 nTypeId = TYP_DOCINFOFLD;
     366             : 
     367           0 :     EnableInsert(nSubType != USHRT_MAX);
     368             : 
     369           0 :     if (nSubType == USHRT_MAX)  // Info-Text
     370           0 :         nSubType = DI_SUBTYPE_BEGIN;
     371             : 
     372           0 :     m_pSelectionLB->Clear();
     373             : 
     374           0 :     sal_uInt16 nSize = 0;
     375           0 :     sal_Int32 nSelPos = LISTBOX_ENTRY_NOTFOUND;
     376           0 :     sal_uInt16 nExtSubType = IsFldEdit() ? (((SwDocInfoField*)GetCurField())->GetSubType() & 0xff00) : 0;
     377             : 
     378           0 :     if (IsFldEdit())
     379             :     {
     380           0 :         m_pFixedCB->Check((nExtSubType & DI_SUB_FIXED) != 0);
     381           0 :         nExtSubType = ((nExtSubType & ~DI_SUB_FIXED) >> 8) - 1;
     382             :     }
     383             : 
     384           0 :     if (nSubType < DI_CREATE || nSubType == DI_DOCNO || nSubType == DI_EDIT|| nSubType == DI_CUSTOM )
     385             :     {
     386             :         // Format Box is empty for Title and Time
     387             :     }
     388             :     else
     389             :     {
     390           0 :         nSize = GetFldMgr().GetFormatCount(nTypeId, false, IsFldDlgHtmlMode());
     391           0 :         for (sal_uInt16 i = 0; i < nSize; i++)
     392             :         {
     393           0 :             sal_Int32 nPos = m_pSelectionLB->InsertEntry(GetFldMgr().GetFormatStr(nTypeId, i));
     394           0 :             m_pSelectionLB->SetEntryData(nPos, reinterpret_cast<void*>(GetFldMgr().GetFormatId(nTypeId, i)));
     395           0 :             if (IsFldEdit() && i == nExtSubType)
     396           0 :                 nSelPos = nPos;
     397             :         }
     398             :     }
     399             : 
     400           0 :     sal_Bool bEnable = nSize != 0;
     401             : 
     402           0 :     if (nSize)
     403             :     {
     404           0 :         if (!m_pSelectionLB->GetSelectEntryCount())
     405           0 :             m_pSelectionLB->SelectEntryPos(nSelPos == USHRT_MAX ? 0 : nSelPos);
     406             : 
     407           0 :         bEnable = sal_True;
     408             :     }
     409             : 
     410           0 :     m_pSelection->Enable(bEnable);
     411             : 
     412           0 :     return nSize;
     413             : }
     414             : 
     415           0 : bool SwFldDokInfPage::FillItemSet(SfxItemSet& )
     416             : {
     417           0 :     if (!pSelEntry || (sal_uInt16)(sal_uLong)pSelEntry->GetUserData() == USHRT_MAX)
     418           0 :         return false;
     419             : 
     420           0 :     sal_uInt16 nSubType = (sal_uInt16)(sal_uLong)pSelEntry->GetUserData();
     421             : 
     422           0 :     sal_uLong nFormat = 0;
     423             : 
     424           0 :     sal_Int32 nPos = m_pSelectionLB->GetSelectEntryPos();
     425             : 
     426           0 :     OUString aName;
     427           0 :     if (DI_CUSTOM == nSubType)
     428           0 :         aName = m_pTypeTLB->GetEntryText(pSelEntry);
     429             : 
     430           0 :     if (nPos != LISTBOX_ENTRY_NOTFOUND)
     431           0 :         nSubType |= (sal_uInt16)(sal_uLong)m_pSelectionLB->GetEntryData(nPos);
     432             : 
     433           0 :     if (m_pFixedCB->IsChecked())
     434           0 :         nSubType |= DI_SUB_FIXED;
     435             : 
     436           0 :     nPos = m_pFormatLB->GetSelectEntryPos();
     437           0 :     if(nPos != LISTBOX_ENTRY_NOTFOUND)
     438           0 :         nFormat = m_pFormatLB->GetFormat();
     439             : 
     440           0 :     if (!IsFldEdit() || nOldSel != m_pSelectionLB->GetSelectEntryPos() ||
     441           0 :         nOldFormat != nFormat || m_pFixedCB->GetState() != m_pFixedCB->GetSavedValue()
     442           0 :         || (DI_CUSTOM == nSubType && aName != m_sOldCustomFieldName ))
     443             :     {
     444             :         InsertFld(TYP_DOCINFOFLD, nSubType, aName, aEmptyOUStr, nFormat,
     445           0 :                 ' ', m_pFormatLB->IsAutomaticLanguage());
     446             :     }
     447             : 
     448           0 :     return false;
     449             : }
     450             : 
     451           0 : SfxTabPage* SwFldDokInfPage::Create(    Window* pParent,
     452             :                         const SfxItemSet& rAttrSet )
     453             : {
     454           0 :     return ( new SwFldDokInfPage( pParent, rAttrSet ) );
     455             : }
     456             : 
     457           0 : sal_uInt16 SwFldDokInfPage::GetGroup()
     458             : {
     459           0 :     return GRP_REG;
     460             : }
     461             : 
     462           0 : void    SwFldDokInfPage::FillUserData()
     463             : {
     464           0 :     SvTreeListEntry* pEntry = m_pTypeTLB->FirstSelected();
     465           0 :     sal_uInt16 nTypeSel = pEntry ? sal::static_int_cast< sal_uInt16 >(reinterpret_cast< sal_uIntPtr >(pEntry->GetUserData())) : USHRT_MAX;
     466           0 :     SetUserData(USER_DATA_VERSION ";" + OUString::number( nTypeSel ));
     467           0 : }
     468             : 
     469             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10