1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <hintids.hxx>
#include <comphelper/string.hxx>
#include <tools/stream.hxx>
#include <tools/resid.hxx>
#include <sfx2/app.hxx>
#include <editeng/paperinf.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <unotools/useroptions.hxx>
#include <swmodule.hxx>
#include <swtypes.hxx>
#include <envimg.hxx>
#include <cmdid.h>
#include <envelp.hrc>
#include <unomid.h>
#ifdef WNT
#define NEXTLINE "\r\n"
#else
#define NEXTLINE "\n"
#endif
using namespace utl;
using namespace css::uno;
TYPEINIT1_AUTOFACTORY( SwEnvItem, SfxPoolItem );
OUString MakeSender()
{
SvtUserOptions& rUserOpt = SW_MOD()->GetUserOptions();
OUString sRet;
OUString sSenderToken(SW_RES(STR_SENDER_TOKENS));
sal_Int32 nTokenCount = comphelper::string::getTokenCount(sSenderToken, ';');
sal_Int32 nSttPos = 0;
bool bLastLength = true;
for( sal_Int32 i = 0; i < nTokenCount; i++ )
{
OUString sToken = sSenderToken.getToken( 0, ';', nSttPos );
if (sToken == "COMPANY")
{
sal_Int32 nOldLen = sRet.getLength();
sRet += rUserOpt.GetCompany();
bLastLength = sRet.getLength() != nOldLen;
}
else if (sToken == "CR")
{
if(bLastLength)
sRet += NEXTLINE;
bLastLength = true;
}
else if (sToken == "FIRSTNAME")
sRet += rUserOpt.GetFirstName();
else if (sToken == "LASTNAME")
sRet += rUserOpt.GetLastName();
else if (sToken == "ADDRESS")
sRet += rUserOpt.GetStreet();
else if (sToken == "COUNTRY")
sRet += rUserOpt.GetCountry();
else if (sToken == "POSTALCODE")
sRet += rUserOpt.GetZip();
else if (sToken == "CITY")
sRet += rUserOpt.GetCity();
else if (sToken == "STATEPROV")
sRet += rUserOpt.GetState();
else if (!sToken.isEmpty()) //spaces
sRet += sToken;
}
return sRet;
}
SwEnvItem::SwEnvItem() :
SfxPoolItem(FN_ENVELOP)
{
aAddrText = aEmptyOUStr;
bSend = true;
aSendText = MakeSender();
lSendFromLeft = 566; // 1 cm
lSendFromTop = 566; // 1 cm
Size aEnvSz = SvxPaperInfo::GetPaperSize(PAPER_ENV_C65);
lWidth = aEnvSz.Width();
lHeight = aEnvSz.Height();
eAlign = ENV_HOR_LEFT;
bPrintFromAbove = true;
lShiftRight = 0;
lShiftDown = 0;
lAddrFromLeft = std::max(lWidth, lHeight) / 2;
lAddrFromTop = std::min(lWidth, lHeight) / 2;
}
SwEnvItem::SwEnvItem(const SwEnvItem& rItem) :
SfxPoolItem(FN_ENVELOP),
aAddrText (rItem.aAddrText),
bSend (rItem.bSend),
aSendText (rItem.aSendText),
lAddrFromLeft (rItem.lAddrFromLeft),
lAddrFromTop (rItem.lAddrFromTop),
lSendFromLeft (rItem.lSendFromLeft),
lSendFromTop (rItem.lSendFromTop),
lWidth (rItem.lWidth),
lHeight (rItem.lHeight),
eAlign (rItem.eAlign),
bPrintFromAbove(rItem.bPrintFromAbove),
lShiftRight (rItem.lShiftRight),
lShiftDown (rItem.lShiftDown)
{
}
SwEnvItem& SwEnvItem::operator =(const SwEnvItem& rItem)
{
aAddrText = rItem.aAddrText;
bSend = rItem.bSend;
aSendText = rItem.aSendText;
lSendFromLeft = rItem.lSendFromLeft;
lSendFromTop = rItem.lSendFromTop;
lAddrFromLeft = rItem.lAddrFromLeft;
lAddrFromTop = rItem.lAddrFromTop;
lWidth = rItem.lWidth;
lHeight = rItem.lHeight;
eAlign = rItem.eAlign;
bPrintFromAbove = rItem.bPrintFromAbove;
lShiftRight = rItem.lShiftRight;
lShiftDown = rItem.lShiftDown;
return *this;
}
bool SwEnvItem::operator ==(const SfxPoolItem& rItem) const
{
const SwEnvItem& rEnv = static_cast<const SwEnvItem&>( rItem);
return aAddrText == rEnv.aAddrText &&
bSend == rEnv.bSend &&
aSendText == rEnv.aSendText &&
lSendFromLeft == rEnv.lSendFromLeft &&
lSendFromTop == rEnv.lSendFromTop &&
lAddrFromLeft == rEnv.lAddrFromLeft &&
lAddrFromTop == rEnv.lAddrFromTop &&
lWidth == rEnv.lWidth &&
lHeight == rEnv.lHeight &&
eAlign == rEnv.eAlign &&
bPrintFromAbove == rEnv.bPrintFromAbove &&
lShiftRight == rEnv.lShiftRight &&
lShiftDown == rEnv.lShiftDown;
}
SfxPoolItem* SwEnvItem::Clone(SfxItemPool*) const
{
return new SwEnvItem(*this);
}
SwEnvCfgItem::SwEnvCfgItem() :
ConfigItem("Office.Writer/Envelope")
{
Sequence<OUString> aNames = GetPropertyNames();
Sequence<Any> aValues = GetProperties(aNames);
EnableNotification(aNames);
const Any* pValues = aValues.getConstArray();
OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
if(aValues.getLength() == aNames.getLength())
{
for(int nProp = 0; nProp < aNames.getLength(); nProp++)
{
if(pValues[nProp].hasValue())
{
switch(nProp)
{
case 0: pValues[nProp] >>= aEnvItem.aAddrText; break;// "Inscription/Addressee",
case 1: pValues[nProp] >>= aEnvItem.aSendText; break;// "Inscription/Sender",
case 2: aEnvItem.bSend = *static_cast<sal_Bool const *>(pValues[nProp].getValue()); break;// "Inscription/UseSender",
case 3:
pValues[nProp] >>= aEnvItem.lAddrFromLeft;// "Format/AddresseeFromLeft",
aEnvItem.lAddrFromLeft = convertMm100ToTwip(aEnvItem.lAddrFromLeft);
break;
case 4:
pValues[nProp] >>= aEnvItem.lAddrFromTop; // "Format/AddresseeFromTop",
aEnvItem.lAddrFromTop = convertMm100ToTwip(aEnvItem.lAddrFromTop);
break;
case 5:
pValues[nProp] >>= aEnvItem.lSendFromLeft; // "Format/SenderFromLeft",
aEnvItem.lSendFromLeft = convertMm100ToTwip(aEnvItem.lSendFromLeft);
break;
case 6:
pValues[nProp] >>= aEnvItem.lSendFromTop;// "Format/SenderFromTop",
aEnvItem.lSendFromTop = convertMm100ToTwip(aEnvItem.lSendFromTop);
break;
case 7:
pValues[nProp] >>= aEnvItem.lWidth; // "Format/Width",
aEnvItem.lWidth = convertMm100ToTwip(aEnvItem.lWidth);
break;
case 8:
pValues[nProp] >>= aEnvItem.lHeight; // "Format/Height",
aEnvItem.lHeight = convertMm100ToTwip(aEnvItem.lHeight);
break;
case 9:
{
sal_Int32 nTemp = 0;
pValues[nProp] >>= nTemp; aEnvItem.eAlign = (SwEnvAlign)nTemp; break;// "Print/Alignment",
}
case 10: aEnvItem.bPrintFromAbove = *static_cast<sal_Bool const *>(pValues[nProp].getValue()); break;// "Print/FromAbove",
case 11:
pValues[nProp] >>= aEnvItem.lShiftRight;
aEnvItem.lShiftRight = convertMm100ToTwip(aEnvItem.lShiftRight);// "Print/Right",
break;
case 12:
pValues[nProp] >>= aEnvItem.lShiftDown;
aEnvItem.lShiftDown = convertMm100ToTwip(aEnvItem.lShiftDown);
break;// "Print/Down"
}
}
}
}
}
SwEnvCfgItem::~SwEnvCfgItem()
{
}
void SwEnvCfgItem::ImplCommit()
{
Sequence<OUString> aNames = GetPropertyNames();
Sequence<Any> aValues(aNames.getLength());
Any* pValues = aValues.getArray();
for(int nProp = 0; nProp < aNames.getLength(); nProp++)
{
switch(nProp)
{
case 0: pValues[nProp] <<= aEnvItem.aAddrText; break;// "Inscription/Addressee",
case 1: pValues[nProp] <<= aEnvItem.aSendText; break;// "Inscription/Sender",
case 2: pValues[nProp] <<= aEnvItem.bSend; break;// "Inscription/UseSender",
case 3: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lAddrFromLeft)) ; break;// "Format/AddresseeFromLeft",
case 4: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lAddrFromTop)) ; break;// "Format/AddresseeFromTop",
case 5: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lSendFromLeft)) ; break;// "Format/SenderFromLeft",
case 6: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lSendFromTop)) ; break;// "Format/SenderFromTop",
case 7: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lWidth)) ; break;// "Format/Width",
case 8: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lHeight)) ; break;// "Format/Height",
case 9: pValues[nProp] <<= sal_Int32(aEnvItem.eAlign); break;// "Print/Alignment",
case 10: pValues[nProp] <<= aEnvItem.bPrintFromAbove; break;// "Print/FromAbove",
case 11: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lShiftRight));break; // "Print/Right",
case 12: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lShiftDown)); break;// "Print/Down"
}
}
PutProperties(aNames, aValues);
}
void SwEnvCfgItem::Notify( const css::uno::Sequence< OUString >& ) {}
Sequence<OUString> SwEnvCfgItem::GetPropertyNames()
{
static const char* aPropNames[] =
{
"Inscription/Addressee", // 0
"Inscription/Sender", // 1
"Inscription/UseSender", // 2
"Format/AddresseeFromLeft", // 3
"Format/AddresseeFromTop", // 4
"Format/SenderFromLeft", // 5
"Format/SenderFromTop", // 6
"Format/Width", // 7
"Format/Height", // 8
"Print/Alignment", // 9
"Print/FromAbove", // 10
"Print/Right", // 11
"Print/Down" // 12
};
const int nCount = 13;
Sequence<OUString> aNames(nCount);
OUString* pNames = aNames.getArray();
for(int i = 0; i < nCount; i++)
pNames[i] = OUString::createFromAscii(aPropNames[i]);
return aNames;
}
bool SwEnvItem::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
{
bool bRet = true;
switch(nMemberId & ~CONVERT_TWIPS)
{
case MID_ENV_ADDR_TEXT : rVal <<= aAddrText; break;
case MID_ENV_SEND : rVal <<= bSend; break;
case MID_SEND_TEXT : rVal <<= aSendText; break;
case MID_ENV_ADDR_FROM_LEFT : rVal <<= lAddrFromLeft; break;
case MID_ENV_ADDR_FROM_TOP : rVal <<= lAddrFromTop; break;
case MID_ENV_SEND_FROM_LEFT : rVal <<= lSendFromLeft; break;
case MID_ENV_SEND_FROM_TOP : rVal <<= lSendFromTop; break;
case MID_ENV_WIDTH : rVal <<= lWidth; break;
case MID_ENV_HEIGHT : rVal <<= lHeight; break;
case MID_ENV_ALIGN : rVal <<= (sal_Int16) eAlign; break;
case MID_ENV_PRINT_FROM_ABOVE : rVal <<= bPrintFromAbove; break;
case MID_ENV_SHIFT_RIGHT : rVal <<= lShiftRight; break;
case MID_ENV_SHIFT_DOWN : rVal <<= lShiftDown; break;
default:
OSL_FAIL("Wrong memberId");
bRet = false;
}
return bRet;
}
bool SwEnvItem::PutValue(const Any& rVal, sal_uInt8 nMemberId)
{
bool bRet = false;
switch(nMemberId & ~CONVERT_TWIPS)
{
case MID_ENV_ADDR_TEXT : bRet = (rVal >>= aAddrText); break;
case MID_ENV_SEND : bRet = (rVal >>= bSend); break;
case MID_SEND_TEXT : bRet = (rVal >>= aSendText); break;
case MID_ENV_ADDR_FROM_LEFT : bRet = (rVal >>= lAddrFromLeft); break;
case MID_ENV_ADDR_FROM_TOP : bRet = (rVal >>= lAddrFromTop); break;
case MID_ENV_SEND_FROM_LEFT : bRet = (rVal >>= lSendFromLeft); break;
case MID_ENV_SEND_FROM_TOP : bRet = (rVal >>= lSendFromTop); break;
case MID_ENV_WIDTH : bRet = (rVal >>= lWidth); break;
case MID_ENV_HEIGHT : bRet = (rVal >>= lHeight); break;
case MID_ENV_ALIGN :
{
sal_Int16 nTemp = 0;
bRet = (rVal >>= nTemp);
if (bRet)
eAlign = SwEnvAlign(nTemp);
break;
}
case MID_ENV_PRINT_FROM_ABOVE : bRet = (rVal >>= bPrintFromAbove); break;
case MID_ENV_SHIFT_RIGHT : bRet = (rVal >>= lShiftRight); break;
case MID_ENV_SHIFT_DOWN : bRet = (rVal >>= lShiftDown); break;
default:
OSL_FAIL("Wrong memberId");
}
return bRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|