LCOV - code coverage report
Current view: top level - sw/source/ui/envelp - labelexp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 101 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 9 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 <com/sun/star/lang/XMultiServiceFactory.hpp>
      21             : #include <com/sun/star/text/AutoTextContainer.hpp>
      22             : #include <com/sun/star/text/XTextFieldsSupplier.hpp>
      23             : #include <com/sun/star/util/XRefreshable.hpp>
      24             : #include <comphelper/processfactory.hxx>
      25             : #include <svtools/treelistentry.hxx>
      26             : #include <swtypes.hxx>
      27             : #include <labfmt.hxx>
      28             : #include <unotools.hxx>
      29             : #include <unoatxt.hxx>
      30             : #include <unomid.h>
      31             : #include <unoprnms.hxx>
      32             : 
      33             : using namespace ::com::sun::star;
      34             : using namespace ::com::sun::star::lang;
      35             : using namespace ::com::sun::star::container;
      36             : using namespace ::com::sun::star::uno;
      37             : using namespace ::comphelper;
      38             : 
      39           0 : void SwVisitingCardPage::InitFrameControl()
      40             : {
      41           0 :     Link<> aLink(LINK(this, SwVisitingCardPage, FrameControlInitializedHdl));
      42           0 :     m_pExampleWIN->Show();
      43           0 :     pExampleFrame = new SwOneExampleFrame( *m_pExampleWIN,
      44           0 :                                     EX_SHOW_BUSINESS_CARDS, &aLink );
      45             : 
      46           0 :     Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
      47             : 
      48             :     //now the AutoText ListBoxes have to be filled
      49             : 
      50           0 :     m_xAutoText = text::AutoTextContainer::create( xContext );
      51             : 
      52           0 :     uno::Sequence<OUString> aNames = m_xAutoText->getElementNames();
      53           0 :     const OUString* pGroups = aNames.getConstArray();
      54             : 
      55           0 :     for(sal_Int32 i = 0; i < aNames.getLength(); ++i)
      56             :     {
      57           0 :         uno::Any aGroup = m_xAutoText->getByName(pGroups[i]);
      58           0 :         uno::Reference< text::XAutoTextGroup >  xGroup;
      59           0 :         aGroup >>= xGroup;
      60           0 :         uno::Reference< container::XIndexAccess >  xIdxAcc(xGroup, uno::UNO_QUERY);
      61             :         try
      62             :         {
      63           0 :             if(!xIdxAcc.is() || xIdxAcc->getCount())
      64             :             {
      65           0 :                 uno::Reference< beans::XPropertySet >  xPrSet(xGroup, uno::UNO_QUERY);
      66           0 :                 uno::Any aTitle = xPrSet->getPropertyValue( UNO_NAME_TITLE );
      67           0 :                 OUString uTitle;
      68           0 :                 aTitle >>= uTitle;
      69           0 :                 const sal_Int32 nEntry = m_pAutoTextGroupLB->InsertEntry(uTitle);
      70           0 :                 m_pAutoTextGroupLB->SetEntryData(nEntry, new OUString(pGroups[i]));
      71             :             }
      72             :         }
      73           0 :         catch (const Exception&)
      74             :         {
      75             :         }
      76           0 :     }
      77           0 :     if(m_pAutoTextGroupLB->GetEntryCount())
      78             :     {
      79           0 :         if(LISTBOX_ENTRY_NOTFOUND == m_pAutoTextGroupLB->GetSelectEntryPos())
      80           0 :             m_pAutoTextGroupLB->SelectEntryPos(0);
      81             :         const OUString *pCurGroupName(
      82           0 :             static_cast<const OUString*>(m_pAutoTextGroupLB->GetSelectEntryData()));
      83           0 :         if(m_xAutoText->hasByName(*pCurGroupName))
      84             :         {
      85           0 :             uno::Any aGroup = m_xAutoText->getByName(*pCurGroupName);
      86             :             try
      87             :             {
      88           0 :                 uno::Reference< text::XAutoTextGroup >  xGroup;
      89           0 :                 aGroup >>= xGroup;
      90           0 :                 uno::Sequence< OUString > aBlockNames = xGroup->getElementNames();
      91           0 :                 uno::Sequence< OUString > aTitles = xGroup->getTitles() ;
      92             : 
      93           0 :                 SetUserData( aBlockNames.getLength(), aTitles.getConstArray(),
      94           0 :                             aBlockNames.getConstArray() );
      95             :             }
      96           0 :             catch (const uno::RuntimeException&)
      97             :             {
      98             :                 // we'll be her if path settings were wrong
      99           0 :             }
     100             :         }
     101           0 :     }
     102           0 : }
     103             : 
     104           0 : IMPL_LINK_NOARG(SwVisitingCardPage, FrameControlInitializedHdl)
     105             : {
     106           0 :     SvTreeListEntry* pSel = m_pAutoTextLB->FirstSelected();
     107           0 :     OUString sEntry;
     108           0 :     if( pSel )
     109           0 :         sEntry = *static_cast<OUString*>(pSel->GetUserData());
     110           0 :     uno::Reference< text::XTextCursor > & xCrsr = pExampleFrame->GetTextCursor();
     111           0 :     OUString uEntry(sEntry);
     112             : 
     113           0 :     if(LISTBOX_ENTRY_NOTFOUND != m_pAutoTextGroupLB->GetSelectEntryPos())
     114             :     {
     115           0 :         const OUString *pGroup( static_cast<const OUString*>(m_pAutoTextGroupLB->GetSelectEntryData()) );
     116           0 :         uno::Any aGroup = m_xAutoText->getByName(*pGroup);
     117           0 :         uno::Reference< text::XAutoTextGroup >  xGroup;
     118           0 :         aGroup >>= xGroup;
     119             : 
     120           0 :         if( !sEntry.isEmpty() && xGroup->hasByName( uEntry ) )
     121             :         {
     122           0 :             uno::Any aEntry(xGroup->getByName(uEntry));
     123           0 :             uno::Reference< text::XAutoTextEntry >  xEntry;
     124           0 :             aEntry >>= xEntry;
     125           0 :             if(xEntry.is())
     126             :             {
     127           0 :                 uno::Reference< text::XTextRange >  xRange(xCrsr, uno::UNO_QUERY);
     128           0 :                 xEntry->applyTo(xRange);
     129             :             }
     130           0 :             UpdateFields();
     131           0 :         }
     132             :     }
     133           0 :     return 0;
     134             : }
     135             : 
     136           0 : IMPL_LINK( SwVisitingCardPage, AutoTextSelectHdl, void*, pBox )
     137             : {
     138           0 :     if(m_xAutoText.is())
     139             :     {
     140           0 :         if (m_pAutoTextGroupLB == pBox)
     141             :         {
     142           0 :             const OUString *pGroup( static_cast<const OUString*>(m_pAutoTextGroupLB->GetSelectEntryData()));
     143           0 :             uno::Any aGroup = m_xAutoText->getByName(*pGroup);
     144           0 :             uno::Reference< text::XAutoTextGroup >  xGroup;
     145           0 :             aGroup >>= xGroup;
     146             : 
     147           0 :             ClearUserData();
     148           0 :             m_pAutoTextLB->Clear();
     149             : 
     150           0 :             uno::Sequence<OUString> aBlockNames = xGroup->getElementNames();
     151           0 :             uno::Sequence< OUString > aTitles = xGroup->getTitles() ;
     152           0 :             SetUserData( aBlockNames.getLength(), aTitles.getConstArray(),
     153           0 :                         aBlockNames.getConstArray() );
     154             :         }
     155           0 :         if(pExampleFrame->IsInitialized())
     156           0 :             pExampleFrame->ClearDocument( true );
     157             :     }
     158           0 :     return 0;
     159             : }
     160             : 
     161           0 : void SwVisitingCardPage::UpdateFields()
     162             : {
     163           0 :     uno::Reference< frame::XModel >  xModel;
     164           0 :     if( pExampleFrame && (xModel = pExampleFrame->GetModel()).is())
     165             :     {
     166           0 :         SwLabDlg::UpdateFieldInformation(xModel, aLabItem);
     167           0 :     }
     168           0 : }
     169             : 
     170           0 : void SwLabDlg::UpdateFieldInformation(uno::Reference< frame::XModel > & xModel, const SwLabItem& rItem)
     171             : {
     172           0 :     uno::Reference< text::XTextFieldsSupplier >  xFields(xModel, uno::UNO_QUERY);
     173           0 :     uno::Reference< container::XNameAccess >  xFieldMasters = xFields->getTextFieldMasters();
     174             : 
     175             :     static const struct _SwLabItemMap {
     176             :         const char* pName;
     177             :         OUString SwLabItem:: *pValue;
     178             :     }  aArr[] = {
     179             :         { "BC_PRIV_FIRSTNAME"  , &SwLabItem::aPrivFirstName },
     180             :         { "BC_PRIV_NAME"       , &SwLabItem::aPrivName },
     181             :         { "BC_PRIV_INITIALS"   , &SwLabItem::aPrivShortCut },
     182             :         { "BC_PRIV_FIRSTNAME_2", &SwLabItem::aPrivFirstName2 },
     183             :         { "BC_PRIV_NAME_2"     , &SwLabItem::aPrivName2 },
     184             :         { "BC_PRIV_INITIALS_2" , &SwLabItem::aPrivShortCut2 },
     185             :         { "BC_PRIV_STREET"     , &SwLabItem::aPrivStreet },
     186             :         { "BC_PRIV_ZIP"        , &SwLabItem::aPrivZip },
     187             :         { "BC_PRIV_CITY"       , &SwLabItem::aPrivCity },
     188             :         { "BC_PRIV_COUNTRY"    , &SwLabItem::aPrivCountry },
     189             :         { "BC_PRIV_STATE"      , &SwLabItem::aPrivState },
     190             :         { "BC_PRIV_TITLE"      , &SwLabItem::aPrivTitle },
     191             :         { "BC_PRIV_PROFESSION" , &SwLabItem::aPrivProfession },
     192             :         { "BC_PRIV_PHONE"      , &SwLabItem::aPrivPhone },
     193             :         { "BC_PRIV_MOBILE"     , &SwLabItem::aPrivMobile },
     194             :         { "BC_PRIV_FAX"        , &SwLabItem::aPrivFax },
     195             :         { "BC_PRIV_WWW"        , &SwLabItem::aPrivWWW },
     196             :         { "BC_PRIV_MAIL"       , &SwLabItem::aPrivMail },
     197             :         { "BC_COMP_COMPANY"    , &SwLabItem::aCompCompany },
     198             :         { "BC_COMP_COMPANYEXT" , &SwLabItem::aCompCompanyExt },
     199             :         { "BC_COMP_SLOGAN"     , &SwLabItem::aCompSlogan },
     200             :         { "BC_COMP_STREET"     , &SwLabItem::aCompStreet },
     201             :         { "BC_COMP_ZIP"        , &SwLabItem::aCompZip },
     202             :         { "BC_COMP_CITY"       , &SwLabItem::aCompCity },
     203             :         { "BC_COMP_COUNTRY"    , &SwLabItem::aCompCountry },
     204             :         { "BC_COMP_STATE"      , &SwLabItem::aCompState },
     205             :         { "BC_COMP_POSITION"   , &SwLabItem::aCompPosition },
     206             :         { "BC_COMP_PHONE"      , &SwLabItem::aCompPhone },
     207             :         { "BC_COMP_MOBILE"     , &SwLabItem::aCompMobile },
     208             :         { "BC_COMP_FAX"        , &SwLabItem::aCompFax },
     209             :         { "BC_COMP_WWW"        , &SwLabItem::aCompWWW },
     210             :         { "BC_COMP_MAIL"       , &SwLabItem::aCompMail },
     211             :         { 0, 0 }
     212             :     };
     213             : 
     214             :     try
     215             :     {
     216           0 :         for( const _SwLabItemMap* p = aArr; p->pName; ++p )
     217             :         {
     218             :             OUString uFieldName(
     219             :                 "com.sun.star.text.FieldMaster.User."
     220           0 :                 + OUString::createFromAscii(p->pName));
     221           0 :             if( xFieldMasters->hasByName( uFieldName ))
     222             :             {
     223           0 :                 uno::Any aFirstName = xFieldMasters->getByName( uFieldName );
     224           0 :                 uno::Reference< beans::XPropertySet >  xField;
     225           0 :                 aFirstName >>= xField;
     226           0 :                 uno::Any aContent;
     227           0 :                 aContent <<= rItem.*p->pValue;
     228           0 :                 xField->setPropertyValue( UNO_NAME_CONTENT, aContent );
     229             :             }
     230           0 :         }
     231             :     }
     232           0 :     catch (const uno::RuntimeException&)
     233             :     {
     234             : 
     235             :     }
     236             : 
     237           0 :     uno::Reference< container::XEnumerationAccess >  xFieldAcc = xFields->getTextFields();
     238           0 :     uno::Reference< util::XRefreshable >  xRefresh(xFieldAcc, uno::UNO_QUERY);
     239           0 :     xRefresh->refresh();
     240           0 : }
     241             : 
     242             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11