LibreOffice Module sw (master) 1
envimg.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 <sal/config.h>
21
22#include <o3tl/any.hxx>
23#include <o3tl/string_view.hxx>
24#include <osl/diagnose.h>
25#include <editeng/paperinf.hxx>
26#include <com/sun/star/uno/Sequence.hxx>
27#include <rtl/ustrbuf.hxx>
30#include <swmodule.hxx>
31#include <swtypes.hxx>
32#include <envimg.hxx>
33#include <strings.hrc>
34
35#include <cmdid.h>
36
37#include <unomid.h>
38
39using namespace utl;
40using namespace ::com::sun::star::uno;
41
42
44
45OUString MakeSender()
46{
47 SvtUserOptions& rUserOpt = SW_MOD()->GetUserOptions();
48
49 const OUString sSenderToken(SwResId(STR_SENDER_TOKENS));
50 if (sSenderToken.isEmpty())
51 return OUString();
52
53 OUStringBuffer sRet;
54 sal_Int32 nSttPos = 0;
55 bool bLastLength = true;
56 do {
57 std::u16string_view sToken = o3tl::getToken(sSenderToken, 0, ';', nSttPos );
58 if (sToken == u"COMPANY")
59 {
60 sal_Int32 nOldLen = sRet.getLength();
61 sRet.append(rUserOpt.GetCompany());
62 bLastLength = sRet.getLength() != nOldLen;
63 }
64 else if (sToken == u"CR")
65 {
66 if(bLastLength)
67 sRet.append(SAL_NEWLINE_STRING);
68 bLastLength = true;
69 }
70 else if (sToken == u"FIRSTNAME")
71 sRet.append(rUserOpt.GetFirstName());
72 else if (sToken == u"LASTNAME")
73 sRet.append(rUserOpt.GetLastName());
74 else if (sToken == u"ADDRESS")
75 sRet.append(rUserOpt.GetStreet());
76 else if (sToken == u"COUNTRY")
77 sRet.append(rUserOpt.GetCountry());
78 else if (sToken == u"POSTALCODE")
79 sRet.append(rUserOpt.GetZip());
80 else if (sToken == u"CITY")
81 sRet.append(rUserOpt.GetCity());
82 else if (sToken == u"STATEPROV")
83 sRet.append(rUserOpt.GetState());
84 else if (!sToken.empty()) //spaces
85 sRet.append(sToken);
86 } while (nSttPos>=0);
87 return sRet.makeStringAndClear();
88}
89
92{
93 m_bSend = true;
95 m_nSendFromLeft = 566; // 1 cm
96 m_nSendFromTop = 566; // 1 cm
98 m_nWidth = aEnvSz.Width();
99 m_nHeight = aEnvSz.Height();
101 m_bPrintFromAbove = true;
102 m_nShiftRight = 0;
103 m_nShiftDown = 0;
104
105 m_nAddrFromLeft = std::max(m_nWidth, m_nHeight) / 2;
107}
108
110{
111 m_aAddrText = rItem.m_aAddrText;
112 m_bSend = rItem.m_bSend;
113 m_aSendText = rItem.m_aSendText;
118 m_nWidth = rItem.m_nWidth;
119 m_nHeight = rItem.m_nHeight;
120 m_eAlign = rItem.m_eAlign;
124 return *this;
125}
126
127bool SwEnvItem::operator ==(const SfxPoolItem& rItem) const
128{
129 assert(SfxPoolItem::operator==(rItem));
130 const SwEnvItem& rEnv = static_cast<const SwEnvItem&>( rItem);
131
132 return m_aAddrText == rEnv.m_aAddrText &&
133 m_bSend == rEnv.m_bSend &&
134 m_aSendText == rEnv.m_aSendText &&
139 m_nWidth == rEnv.m_nWidth &&
140 m_nHeight == rEnv.m_nHeight &&
141 m_eAlign == rEnv.m_eAlign &&
145}
146
148{
149 return new SwEnvItem(*this);
150}
151
153 ConfigItem("Office.Writer/Envelope")
154{
155 Sequence<OUString> aNames = GetPropertyNames();
156 Sequence<Any> aValues = GetProperties(aNames);
157 EnableNotification(aNames);
158 const Any* pValues = aValues.getConstArray();
159 OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
160 if(aValues.getLength() != aNames.getLength())
161 return;
162
163 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
164 {
165 if(pValues[nProp].hasValue())
166 {
167 switch(nProp)
168 {
169 case 0: pValues[nProp] >>= m_aEnvItem.m_aAddrText; break;// "Inscription/Addressee",
170 case 1: pValues[nProp] >>= m_aEnvItem.m_aSendText; break;// "Inscription/Sender",
171 case 2: m_aEnvItem.m_bSend = *o3tl::doAccess<bool>(pValues[nProp]); break;// "Inscription/UseSender",
172 case 3:
173 pValues[nProp] >>= m_aEnvItem.m_nAddrFromLeft;// "Format/AddresseeFromLeft",
175 break;
176 case 4:
177 pValues[nProp] >>= m_aEnvItem.m_nAddrFromTop; // "Format/AddresseeFromTop",
179 break;
180 case 5:
181 pValues[nProp] >>= m_aEnvItem.m_nSendFromLeft; // "Format/SenderFromLeft",
183 break;
184 case 6:
185 pValues[nProp] >>= m_aEnvItem.m_nSendFromTop;// "Format/SenderFromTop",
187 break;
188 case 7:
189 pValues[nProp] >>= m_aEnvItem.m_nWidth; // "Format/Width",
191 break;
192 case 8:
193 pValues[nProp] >>= m_aEnvItem.m_nHeight; // "Format/Height",
195 break;
196 case 9:
197 {
198 sal_Int32 nTemp = 0;
199 pValues[nProp] >>= nTemp; m_aEnvItem.m_eAlign = static_cast<SwEnvAlign>(nTemp); break;// "Print/Alignment",
200 }
201 case 10: m_aEnvItem.m_bPrintFromAbove = *o3tl::doAccess<bool>(pValues[nProp]); break;// "Print/FromAbove",
202 case 11:
205 break;
206 case 12:
209 break;// "Print/Down"
210 }
211 }
212 }
213}
214
216{
217}
218
220{
221 Sequence<OUString> aNames = GetPropertyNames();
222 Sequence<Any> aValues(aNames.getLength());
223 Any* pValues = aValues.getArray();
224
225 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
226 {
227 switch(nProp)
228 {
229 case 0: pValues[nProp] <<= m_aEnvItem.m_aAddrText; break;// "Inscription/Addressee",
230 case 1: pValues[nProp] <<= m_aEnvItem.m_aSendText; break;// "Inscription/Sender",
231 case 2: pValues[nProp] <<= m_aEnvItem.m_bSend; break;// "Inscription/UseSender",
232 case 3: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(m_aEnvItem.m_nAddrFromLeft)) ; break;// "Format/AddresseeFromLeft",
233 case 4: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(m_aEnvItem.m_nAddrFromTop)) ; break;// "Format/AddresseeFromTop",
234 case 5: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(m_aEnvItem.m_nSendFromLeft)) ; break;// "Format/SenderFromLeft",
235 case 6: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(m_aEnvItem.m_nSendFromTop)) ; break;// "Format/SenderFromTop",
236 case 7: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(m_aEnvItem.m_nWidth)) ; break;// "Format/Width",
237 case 8: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(m_aEnvItem.m_nHeight)) ; break;// "Format/Height",
238 case 9: pValues[nProp] <<= sal_Int32(m_aEnvItem.m_eAlign); break;// "Print/Alignment",
239 case 10: pValues[nProp] <<= m_aEnvItem.m_bPrintFromAbove; break;// "Print/FromAbove",
240 case 11: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(m_aEnvItem.m_nShiftRight));break; // "Print/Right",
241 case 12: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(m_aEnvItem.m_nShiftDown)); break;// "Print/Down"
242 }
243 }
244 PutProperties(aNames, aValues);
245}
246
247void SwEnvCfgItem::Notify( const css::uno::Sequence< OUString >& ) {}
248
250{
251 static const char* aPropNames[] =
252 {
253 "Inscription/Addressee", // 0
254 "Inscription/Sender", // 1
255 "Inscription/UseSender", // 2
256 "Format/AddresseeFromLeft", // 3
257 "Format/AddresseeFromTop", // 4
258 "Format/SenderFromLeft", // 5
259 "Format/SenderFromTop", // 6
260 "Format/Width", // 7
261 "Format/Height", // 8
262 "Print/Alignment", // 9
263 "Print/FromAbove", // 10
264 "Print/Right", // 11
265 "Print/Down" // 12
266 };
267 const int nCount = 13;
268 Sequence<OUString> aNames(nCount);
269 OUString* pNames = aNames.getArray();
270
271 for(int i = 0; i < nCount; i++)
272 pNames[i] = OUString::createFromAscii(aPropNames[i]);
273
274 return aNames;
275}
276
277bool SwEnvItem::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
278{
279 bool bRet = true;
280 switch(nMemberId & ~CONVERT_TWIPS)
281 {
282 case MID_ENV_ADDR_TEXT : rVal <<= m_aAddrText; break;
283 case MID_ENV_SEND : rVal <<= m_bSend; break;
284 case MID_SEND_TEXT : rVal <<= m_aSendText; break;
285 case MID_ENV_ADDR_FROM_LEFT : rVal <<= m_nAddrFromLeft; break;
286 case MID_ENV_ADDR_FROM_TOP : rVal <<= m_nAddrFromTop; break;
287 case MID_ENV_SEND_FROM_LEFT : rVal <<= m_nSendFromLeft; break;
288 case MID_ENV_SEND_FROM_TOP : rVal <<= m_nSendFromTop; break;
289 case MID_ENV_WIDTH : rVal <<= m_nWidth; break;
290 case MID_ENV_HEIGHT : rVal <<= m_nHeight; break;
291 case MID_ENV_ALIGN : rVal <<= static_cast<sal_Int16>(m_eAlign); break;
292 case MID_ENV_PRINT_FROM_ABOVE : rVal <<= m_bPrintFromAbove; break;
293 case MID_ENV_SHIFT_RIGHT : rVal <<= m_nShiftRight; break;
294 case MID_ENV_SHIFT_DOWN : rVal <<= m_nShiftDown; break;
295 default:
296 OSL_FAIL("Wrong memberId");
297 bRet = false;
298 }
299 return bRet;
300}
301
302bool SwEnvItem::PutValue(const Any& rVal, sal_uInt8 nMemberId)
303{
304 bool bRet = false;
305 switch(nMemberId & ~CONVERT_TWIPS)
306 {
307 case MID_ENV_ADDR_TEXT : bRet = (rVal >>= m_aAddrText); break;
308 case MID_ENV_SEND : bRet = (rVal >>= m_bSend); break;
309 case MID_SEND_TEXT : bRet = (rVal >>= m_aSendText); break;
310 case MID_ENV_ADDR_FROM_LEFT : bRet = (rVal >>= m_nAddrFromLeft); break;
311 case MID_ENV_ADDR_FROM_TOP : bRet = (rVal >>= m_nAddrFromTop); break;
312 case MID_ENV_SEND_FROM_LEFT : bRet = (rVal >>= m_nSendFromLeft); break;
313 case MID_ENV_SEND_FROM_TOP : bRet = (rVal >>= m_nSendFromTop); break;
314 case MID_ENV_WIDTH : bRet = (rVal >>= m_nWidth); break;
315 case MID_ENV_HEIGHT : bRet = (rVal >>= m_nHeight); break;
316 case MID_ENV_ALIGN :
317 {
318 sal_Int16 nTemp = 0;
319 bRet = (rVal >>= nTemp);
320 if (bRet)
321 m_eAlign = SwEnvAlign(nTemp);
322 break;
323 }
324 case MID_ENV_PRINT_FROM_ABOVE : bRet = (rVal >>= m_bPrintFromAbove); break;
325 case MID_ENV_SHIFT_RIGHT : bRet = (rVal >>= m_nShiftRight); break;
326 case MID_ENV_SHIFT_DOWN : bRet = (rVal >>= m_nShiftDown); break;
327 default:
328 OSL_FAIL("Wrong memberId");
329 }
330 return bRet;
331}
332
333/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
constexpr auto convertTwipToMm100(N n)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
OUString GetZip() const
OUString GetFirstName() const
OUString GetCountry() const
OUString GetCity() const
OUString GetCompany() const
OUString GetStreet() const
OUString GetState() const
OUString GetLastName() const
static Size GetPaperSize(Paper ePaper, MapUnit eUnit=MapUnit::MapTwip)
virtual void ImplCommit() override
Definition: envimg.cxx:219
virtual ~SwEnvCfgItem() override
Definition: envimg.cxx:215
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
Definition: envimg.cxx:247
static css::uno::Sequence< OUString > GetPropertyNames()
Definition: envimg.cxx:249
SwEnvItem m_aEnvItem
Definition: envimg.hxx:72
sal_Int32 m_nWidth
Definition: envimg.hxx:49
sal_Int32 m_nSendFromLeft
Definition: envimg.hxx:47
OUString m_aSendText
Definition: envimg.hxx:44
sal_Int32 m_nShiftDown
Definition: envimg.hxx:54
sal_Int32 m_nShiftRight
Definition: envimg.hxx:53
virtual SwEnvItem * Clone(SfxItemPool *=nullptr) const override
Definition: envimg.cxx:147
bool m_bPrintFromAbove
Definition: envimg.hxx:52
static SfxPoolItem * CreateDefault()
Definition: envimg.cxx:43
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: envimg.cxx:277
SwEnvItem()
Definition: envimg.cxx:90
OUString m_aAddrText
Definition: envimg.hxx:42
sal_Int32 m_nSendFromTop
Definition: envimg.hxx:48
SwEnvItem & operator=(const SwEnvItem &rItem)
Definition: envimg.cxx:109
SwEnvAlign m_eAlign
Definition: envimg.hxx:51
virtual bool operator==(const SfxPoolItem &rItem) const override
Definition: envimg.cxx:127
sal_Int32 m_nAddrFromTop
Definition: envimg.hxx:46
sal_Int32 m_nAddrFromLeft
Definition: envimg.hxx:45
sal_Int32 m_nHeight
Definition: envimg.hxx:50
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: envimg.cxx:302
bool m_bSend
Definition: envimg.hxx:43
static bool PutProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues, bool bAllLocales)
bool EnableNotification(const css::uno::Sequence< OUString > &rNames, bool bEnableInternalNotification=false)
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
#define FN_ENVELOP
Definition: cmdid.h:784
#define SAL_NEWLINE_STRING
int nCount
float u
OUString MakeSender()
Definition: envimg.cxx:45
SwEnvAlign
Definition: envimg.hxx:29
@ ENV_HOR_LEFT
Definition: envimg.hxx:30
int i
constexpr auto toTwips(N number, Length from)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
PAPER_ENV_C65
const PropertyStruct aPropNames[]
#define CONVERT_TWIPS
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
#define SW_MOD()
Definition: swmodule.hxx:254
unsigned char sal_uInt8
#define MID_ENV_ADDR_FROM_LEFT
Definition: unomid.h:136
#define MID_ENV_ADDR_TEXT
Definition: unomid.h:133
#define MID_ENV_PRINT_FROM_ABOVE
Definition: unomid.h:143
#define MID_SEND_TEXT
Definition: unomid.h:135
#define MID_ENV_WIDTH
Definition: unomid.h:140
#define MID_ENV_SEND
Definition: unomid.h:134
#define MID_ENV_ADDR_FROM_TOP
Definition: unomid.h:137
#define MID_ENV_ALIGN
Definition: unomid.h:142
#define MID_ENV_HEIGHT
Definition: unomid.h:141
#define MID_ENV_SHIFT_RIGHT
Definition: unomid.h:144
#define MID_ENV_SEND_FROM_LEFT
Definition: unomid.h:138
#define MID_ENV_SHIFT_DOWN
Definition: unomid.h:145
#define MID_ENV_SEND_FROM_TOP
Definition: unomid.h:139