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