LibreOffice Module sw (master) 1
labelexp.cxx
Go to the documentation of this file.
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/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>
26
27using namespace ::com::sun::star;
28using namespace ::com::sun::star::lang;
29using namespace ::com::sun::star::container;
30using namespace ::com::sun::star::uno;
31
32void SwLabDlg::UpdateFieldInformation(uno::Reference< frame::XModel > const & xModel, const SwLabItem& rItem)
33{
34 uno::Reference< text::XTextFieldsSupplier > xFields(xModel, uno::UNO_QUERY);
35 uno::Reference< container::XNameAccess > xFieldMasters = xFields->getTextFieldMasters();
36
37 static const struct SwLabItemMap {
38 const char* pName;
39 OUString SwLabItem::*pValue;
40 } aArr[] = {
41 { "BC_PRIV_FIRSTNAME" , &SwLabItem::m_aPrivFirstName },
42 { "BC_PRIV_NAME" , &SwLabItem::m_aPrivName },
43 { "BC_PRIV_INITIALS" , &SwLabItem::m_aPrivShortCut },
44 { "BC_PRIV_FIRSTNAME_2", &SwLabItem::m_aPrivFirstName2 },
45 { "BC_PRIV_NAME_2" , &SwLabItem::m_aPrivName2 },
46 { "BC_PRIV_INITIALS_2" , &SwLabItem::m_aPrivShortCut2 },
47 { "BC_PRIV_STREET" , &SwLabItem::m_aPrivStreet },
48 { "BC_PRIV_ZIP" , &SwLabItem::m_aPrivZip },
49 { "BC_PRIV_CITY" , &SwLabItem::m_aPrivCity },
50 { "BC_PRIV_COUNTRY" , &SwLabItem::m_aPrivCountry },
51 { "BC_PRIV_STATE" , &SwLabItem::m_aPrivState },
52 { "BC_PRIV_TITLE" , &SwLabItem::m_aPrivTitle },
53 { "BC_PRIV_PROFESSION" , &SwLabItem::m_aPrivProfession },
54 { "BC_PRIV_PHONE" , &SwLabItem::m_aPrivPhone },
55 { "BC_PRIV_MOBILE" , &SwLabItem::m_aPrivMobile },
56 { "BC_PRIV_FAX" , &SwLabItem::m_aPrivFax },
57 { "BC_PRIV_WWW" , &SwLabItem::m_aPrivWWW },
58 { "BC_PRIV_MAIL" , &SwLabItem::m_aPrivMail },
59 { "BC_COMP_COMPANY" , &SwLabItem::m_aCompCompany },
60 { "BC_COMP_COMPANYEXT" , &SwLabItem::m_aCompCompanyExt },
61 { "BC_COMP_SLOGAN" , &SwLabItem::m_aCompSlogan },
62 { "BC_COMP_STREET" , &SwLabItem::m_aCompStreet },
63 { "BC_COMP_ZIP" , &SwLabItem::m_aCompZip },
64 { "BC_COMP_CITY" , &SwLabItem::m_aCompCity },
65 { "BC_COMP_COUNTRY" , &SwLabItem::m_aCompCountry },
66 { "BC_COMP_STATE" , &SwLabItem::m_aCompState },
67 { "BC_COMP_POSITION" , &SwLabItem::m_aCompPosition },
68 { "BC_COMP_PHONE" , &SwLabItem::m_aCompPhone },
69 { "BC_COMP_MOBILE" , &SwLabItem::m_aCompMobile },
70 { "BC_COMP_FAX" , &SwLabItem::m_aCompFax },
71 { "BC_COMP_WWW" , &SwLabItem::m_aCompWWW },
72 { "BC_COMP_MAIL" , &SwLabItem::m_aCompMail },
73 { nullptr, nullptr }
74 };
75
76 try
77 {
78 for( const SwLabItemMap* p = aArr; p->pName; ++p )
79 {
80 OUString uFieldName(
81 "com.sun.star.text.FieldMaster.User."
82 + OUString::createFromAscii(p->pName));
83 if( xFieldMasters->hasByName( uFieldName ))
84 {
85 uno::Any aFirstName = xFieldMasters->getByName( uFieldName );
86 uno::Reference< beans::XPropertySet > xField;
87 aFirstName >>= xField;
88 uno::Any aContent;
89 aContent <<= rItem.*p->pValue;
90 xField->setPropertyValue( UNO_NAME_CONTENT, aContent );
91 }
92 }
93 }
94 catch (const uno::RuntimeException&)
95 {
96
97 }
98
99 uno::Reference< container::XEnumerationAccess > xFieldAcc = xFields->getTextFields();
100 uno::Reference< util::XRefreshable > xRefresh(xFieldAcc, uno::UNO_QUERY);
101 xRefresh->refresh();
102}
103
104/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
static void UpdateFieldInformation(css::uno::Reference< css::frame::XModel > const &xModel, const SwLabItem &rItem)
Definition: labelexp.cxx:32
OUString m_aPrivName2
Definition: labimg.hxx:72
OUString m_aCompZip
Definition: labimg.hxx:90
OUString m_aCompMobile
Definition: labimg.hxx:96
OUString m_aCompPosition
Definition: labimg.hxx:94
OUString m_aCompCompanyExt
Definition: labimg.hxx:87
OUString m_aPrivWWW
Definition: labimg.hxx:84
OUString m_aPrivShortCut
Definition: labimg.hxx:70
OUString m_aPrivStreet
Definition: labimg.hxx:74
OUString m_aCompStreet
Definition: labimg.hxx:89
OUString m_aPrivFax
Definition: labimg.hxx:83
OUString m_aPrivFirstName2
Definition: labimg.hxx:71
OUString m_aPrivShortCut2
Definition: labimg.hxx:73
OUString m_aPrivMail
Definition: labimg.hxx:85
OUString m_aPrivCity
Definition: labimg.hxx:76
OUString m_aPrivCountry
Definition: labimg.hxx:77
OUString m_aPrivProfession
Definition: labimg.hxx:80
OUString m_aPrivMobile
Definition: labimg.hxx:82
OUString m_aCompPhone
Definition: labimg.hxx:95
OUString m_aCompCountry
Definition: labimg.hxx:92
OUString m_aCompMail
Definition: labimg.hxx:99
OUString m_aPrivFirstName
Definition: labimg.hxx:68
OUString m_aCompCity
Definition: labimg.hxx:91
OUString m_aPrivState
Definition: labimg.hxx:78
OUString m_aCompCompany
Definition: labimg.hxx:86
OUString m_aCompFax
Definition: labimg.hxx:97
OUString m_aPrivTitle
Definition: labimg.hxx:79
OUString m_aPrivPhone
Definition: labimg.hxx:81
OUString m_aCompSlogan
Definition: labimg.hxx:88
OUString m_aPrivName
Definition: labimg.hxx:69
OUString m_aCompWWW
Definition: labimg.hxx:98
OUString m_aPrivZip
Definition: labimg.hxx:75
OUString m_aCompState
Definition: labimg.hxx:93
void * p
const SvxPageUsage aArr[]
Reference< XModel > xModel
constexpr OUStringLiteral UNO_NAME_CONTENT
Definition: unoprnms.hxx:261