tdf#149907: sc: Add UItest
[LibreOffice.git] / sw / source / ui / envelp / labelexp.cxx
blob5ab0467c64447503ff7069b0d0ccb0f480a2fe81
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
22 #include <com/sun/star/util/XRefreshable.hpp>
23 #include <label.hxx>
24 #include <labimg.hxx>
25 #include <unoprnms.hxx>
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::container;
29 using namespace ::com::sun::star::uno;
31 void SwLabDlg::UpdateFieldInformation(uno::Reference< frame::XModel > const & xModel, const SwLabItem& rItem)
33 uno::Reference< text::XTextFieldsSupplier > xFields(xModel, uno::UNO_QUERY);
34 uno::Reference< container::XNameAccess > xFieldMasters = xFields->getTextFieldMasters();
36 static const struct SwLabItemMap {
37 const char* pName;
38 OUString SwLabItem::*pValue;
39 } aArr[] = {
40 { "BC_PRIV_FIRSTNAME" , &SwLabItem::m_aPrivFirstName },
41 { "BC_PRIV_NAME" , &SwLabItem::m_aPrivName },
42 { "BC_PRIV_INITIALS" , &SwLabItem::m_aPrivShortCut },
43 { "BC_PRIV_FIRSTNAME_2", &SwLabItem::m_aPrivFirstName2 },
44 { "BC_PRIV_NAME_2" , &SwLabItem::m_aPrivName2 },
45 { "BC_PRIV_INITIALS_2" , &SwLabItem::m_aPrivShortCut2 },
46 { "BC_PRIV_STREET" , &SwLabItem::m_aPrivStreet },
47 { "BC_PRIV_ZIP" , &SwLabItem::m_aPrivZip },
48 { "BC_PRIV_CITY" , &SwLabItem::m_aPrivCity },
49 { "BC_PRIV_COUNTRY" , &SwLabItem::m_aPrivCountry },
50 { "BC_PRIV_STATE" , &SwLabItem::m_aPrivState },
51 { "BC_PRIV_TITLE" , &SwLabItem::m_aPrivTitle },
52 { "BC_PRIV_PROFESSION" , &SwLabItem::m_aPrivProfession },
53 { "BC_PRIV_PHONE" , &SwLabItem::m_aPrivPhone },
54 { "BC_PRIV_MOBILE" , &SwLabItem::m_aPrivMobile },
55 { "BC_PRIV_FAX" , &SwLabItem::m_aPrivFax },
56 { "BC_PRIV_WWW" , &SwLabItem::m_aPrivWWW },
57 { "BC_PRIV_MAIL" , &SwLabItem::m_aPrivMail },
58 { "BC_COMP_COMPANY" , &SwLabItem::m_aCompCompany },
59 { "BC_COMP_COMPANYEXT" , &SwLabItem::m_aCompCompanyExt },
60 { "BC_COMP_SLOGAN" , &SwLabItem::m_aCompSlogan },
61 { "BC_COMP_STREET" , &SwLabItem::m_aCompStreet },
62 { "BC_COMP_ZIP" , &SwLabItem::m_aCompZip },
63 { "BC_COMP_CITY" , &SwLabItem::m_aCompCity },
64 { "BC_COMP_COUNTRY" , &SwLabItem::m_aCompCountry },
65 { "BC_COMP_STATE" , &SwLabItem::m_aCompState },
66 { "BC_COMP_POSITION" , &SwLabItem::m_aCompPosition },
67 { "BC_COMP_PHONE" , &SwLabItem::m_aCompPhone },
68 { "BC_COMP_MOBILE" , &SwLabItem::m_aCompMobile },
69 { "BC_COMP_FAX" , &SwLabItem::m_aCompFax },
70 { "BC_COMP_WWW" , &SwLabItem::m_aCompWWW },
71 { "BC_COMP_MAIL" , &SwLabItem::m_aCompMail },
72 { nullptr, nullptr }
75 try
77 for( const SwLabItemMap* p = aArr; p->pName; ++p )
79 OUString uFieldName(
80 "com.sun.star.text.FieldMaster.User."
81 + OUString::createFromAscii(p->pName));
82 if( xFieldMasters->hasByName( uFieldName ))
84 uno::Any aFirstName = xFieldMasters->getByName( uFieldName );
85 uno::Reference< beans::XPropertySet > xField;
86 aFirstName >>= xField;
87 uno::Any aContent;
88 aContent <<= rItem.*p->pValue;
89 xField->setPropertyValue( UNO_NAME_CONTENT, aContent );
93 catch (const uno::RuntimeException&)
98 uno::Reference< container::XEnumerationAccess > xFieldAcc = xFields->getTextFields();
99 uno::Reference< util::XRefreshable > xRefresh(xFieldAcc, uno::UNO_QUERY);
100 xRefresh->refresh();
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */