LCOV - code coverage report
Current view: top level - sw/source/ui/envelp - labelexp.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 100 0.0 %
Date: 2014-04-14 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             :     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 :             (const OUString*)m_pAutoTextGroupLB->GetEntryData(m_pAutoTextGroupLB->GetSelectEntryPos()));
      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 = *(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             :         const OUString *pGroup( (const OUString*)m_pAutoTextGroupLB->GetEntryData(
     116           0 :                                     m_pAutoTextGroupLB->GetSelectEntryPos() ) );
     117           0 :         uno::Any aGroup = m_xAutoText->getByName(*pGroup);
     118           0 :         uno::Reference< text::XAutoTextGroup >  xGroup;
     119           0 :         aGroup >>= xGroup;
     120             : 
     121           0 :         if( !sEntry.isEmpty() && xGroup->hasByName( uEntry ) )
     122             :         {
     123           0 :             uno::Any aEntry(xGroup->getByName(uEntry));
     124           0 :             uno::Reference< text::XAutoTextEntry >  xEntry;
     125           0 :             aEntry >>= xEntry;
     126           0 :             if(xEntry.is())
     127             :             {
     128           0 :                 uno::Reference< text::XTextRange >  xRange(xCrsr, uno::UNO_QUERY);
     129           0 :                 xEntry->applyTo(xRange);
     130             :             }
     131           0 :             UpdateFields();
     132           0 :         }
     133             :     }
     134           0 :     return 0;
     135             : }
     136             : 
     137           0 : IMPL_LINK( SwVisitingCardPage, AutoTextSelectHdl, void*, pBox )
     138             : {
     139           0 :     if(m_xAutoText.is())
     140             :     {
     141           0 :         if (m_pAutoTextGroupLB == pBox)
     142             :         {
     143             :             const OUString *pGroup( (const OUString*)m_pAutoTextGroupLB->GetEntryData(
     144           0 :                                     m_pAutoTextGroupLB->GetSelectEntryPos()));
     145           0 :             uno::Any aGroup = m_xAutoText->getByName(*pGroup);
     146           0 :             uno::Reference< text::XAutoTextGroup >  xGroup;
     147           0 :             aGroup >>= xGroup;
     148             : 
     149           0 :             ClearUserData();
     150           0 :             m_pAutoTextLB->Clear();
     151             : 
     152           0 :             uno::Sequence<OUString> aBlockNames = xGroup->getElementNames();
     153           0 :             uno::Sequence< OUString > aTitles = xGroup->getTitles() ;
     154           0 :             SetUserData( aBlockNames.getLength(), aTitles.getConstArray(),
     155           0 :                         aBlockNames.getConstArray() );
     156             :         }
     157           0 :         if(pExampleFrame->IsInitialized())
     158           0 :             pExampleFrame->ClearDocument( sal_True );
     159             :     }
     160           0 :     return 0;
     161             : }
     162             : 
     163           0 : void SwVisitingCardPage::UpdateFields()
     164             : {
     165           0 :     uno::Reference< frame::XModel >  xModel;
     166           0 :     if( pExampleFrame && (xModel = pExampleFrame->GetModel()).is())
     167             :     {
     168           0 :         SwLabDlg::UpdateFieldInformation(xModel, aLabItem);
     169           0 :     }
     170           0 : }
     171             : 
     172           0 : void SwLabDlg::UpdateFieldInformation(uno::Reference< frame::XModel > & xModel, const SwLabItem& rItem)
     173             : {
     174           0 :     uno::Reference< text::XTextFieldsSupplier >  xFlds(xModel, uno::UNO_QUERY);
     175           0 :     uno::Reference< container::XNameAccess >  xFldMasters = xFlds->getTextFieldMasters();
     176             : 
     177             :     static const struct _SwLabItemMap {
     178             :         const char* pName;
     179             :         OUString SwLabItem:: *pValue;
     180             :     }  aArr[] = {
     181             :         { "BC_PRIV_FIRSTNAME"  , &SwLabItem::aPrivFirstName },
     182             :         { "BC_PRIV_NAME"       , &SwLabItem::aPrivName },
     183             :         { "BC_PRIV_INITIALS"   , &SwLabItem::aPrivShortCut },
     184             :         { "BC_PRIV_FIRSTNAME_2", &SwLabItem::aPrivFirstName2 },
     185             :         { "BC_PRIV_NAME_2"     , &SwLabItem::aPrivName2 },
     186             :         { "BC_PRIV_INITIALS_2" , &SwLabItem::aPrivShortCut2 },
     187             :         { "BC_PRIV_STREET"     , &SwLabItem::aPrivStreet },
     188             :         { "BC_PRIV_ZIP"        , &SwLabItem::aPrivZip },
     189             :         { "BC_PRIV_CITY"       , &SwLabItem::aPrivCity },
     190             :         { "BC_PRIV_COUNTRY"    , &SwLabItem::aPrivCountry },
     191             :         { "BC_PRIV_STATE"      , &SwLabItem::aPrivState },
     192             :         { "BC_PRIV_TITLE"      , &SwLabItem::aPrivTitle },
     193             :         { "BC_PRIV_PROFESSION" , &SwLabItem::aPrivProfession },
     194             :         { "BC_PRIV_PHONE"      , &SwLabItem::aPrivPhone },
     195             :         { "BC_PRIV_MOBILE"     , &SwLabItem::aPrivMobile },
     196             :         { "BC_PRIV_FAX"        , &SwLabItem::aPrivFax },
     197             :         { "BC_PRIV_WWW"        , &SwLabItem::aPrivWWW },
     198             :         { "BC_PRIV_MAIL"       , &SwLabItem::aPrivMail },
     199             :         { "BC_COMP_COMPANY"    , &SwLabItem::aCompCompany },
     200             :         { "BC_COMP_COMPANYEXT" , &SwLabItem::aCompCompanyExt },
     201             :         { "BC_COMP_SLOGAN"     , &SwLabItem::aCompSlogan },
     202             :         { "BC_COMP_STREET"     , &SwLabItem::aCompStreet },
     203             :         { "BC_COMP_ZIP"        , &SwLabItem::aCompZip },
     204             :         { "BC_COMP_CITY"       , &SwLabItem::aCompCity },
     205             :         { "BC_COMP_COUNTRY"    , &SwLabItem::aCompCountry },
     206             :         { "BC_COMP_STATE"      , &SwLabItem::aCompState },
     207             :         { "BC_COMP_POSITION"   , &SwLabItem::aCompPosition },
     208             :         { "BC_COMP_PHONE"      , &SwLabItem::aCompPhone },
     209             :         { "BC_COMP_MOBILE"     , &SwLabItem::aCompMobile },
     210             :         { "BC_COMP_FAX"        , &SwLabItem::aCompFax },
     211             :         { "BC_COMP_WWW"        , &SwLabItem::aCompWWW },
     212             :         { "BC_COMP_MAIL"       , &SwLabItem::aCompMail },
     213             :         { 0, 0 }
     214             :     };
     215             : 
     216             :     try
     217             :     {
     218           0 :         for( const _SwLabItemMap* p = aArr; p->pName; ++p )
     219             :         {
     220             :             OUString uFldName(
     221             :                 "com.sun.star.text.FieldMaster.User."
     222           0 :                 + OUString::createFromAscii(p->pName));
     223           0 :             if( xFldMasters->hasByName( uFldName ))
     224             :             {
     225           0 :                 uno::Any aFirstName = xFldMasters->getByName( uFldName );
     226           0 :                 uno::Reference< beans::XPropertySet >  xFld;
     227           0 :                 aFirstName >>= xFld;
     228           0 :                 uno::Any aContent;
     229           0 :                 aContent <<= rItem.*p->pValue;
     230           0 :                 xFld->setPropertyValue( UNO_NAME_CONTENT, aContent );
     231             :             }
     232           0 :         }
     233             :     }
     234           0 :     catch (const uno::RuntimeException&)
     235             :     {
     236             : 
     237             :     }
     238             : 
     239           0 :     uno::Reference< container::XEnumerationAccess >  xFldAcc = xFlds->getTextFields();
     240           0 :     uno::Reference< util::XRefreshable >  xRefresh(xFldAcc, uno::UNO_QUERY);
     241           0 :     xRefresh->refresh();
     242           0 : }
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10