1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28 #include <hintids.hxx>
29 #include <tools/stream.hxx>
30 #include <tools/resid.hxx>
31 #include <sfx2/app.hxx>
32 #include <editeng/paperinf.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
34 #include <unotools/useroptions.hxx>
35 #include <tools/shl.hxx>
36 #include <swmodule.hxx>
37 #include <errhdl.hxx>
38 #include <swtypes.hxx>
39 #include <envimg.hxx>
40
41 #ifndef _CMDID_H
42 #include <cmdid.h>
43 #endif
44 #ifndef _ENVELP_HRC
45 #include <envelp.hrc>
46 #endif
47
48 #include <unomid.h>
49
50 #ifdef WNT
51 #define NEXTLINE UniString::CreateFromAscii("\r\n")
52 #else
53 #define NEXTLINE '\n'
54 #endif
55
56 using namespace utl;
57 using namespace rtl;
58 using namespace ::com::sun::star::uno;
59
60
61 TYPEINIT1_AUTOFACTORY( SwEnvItem, SfxPoolItem );
62
63 // --------------------------------------------------------------------------
MakeSender()64 SW_DLLPUBLIC String MakeSender()
65 {
66 SvtUserOptions& rUserOpt = SW_MOD()->GetUserOptions();
67
68 String sRet;
69 String sSenderToken(SW_RES(STR_SENDER_TOKENS));
70 xub_StrLen nSttPos = 0, nTokenCount = sSenderToken.GetTokenCount(';');
71 sal_Bool bLastLength = sal_True;
72 for( xub_StrLen i = 0; i < nTokenCount; i++ )
73 {
74 String sToken = sSenderToken.GetToken( 0, ';', nSttPos );
75 if(sToken.EqualsAscii("COMPANY"))
76 {
77 xub_StrLen nOldLen = sRet.Len();
78 sRet += (String)rUserOpt.GetCompany();
79 bLastLength = sRet.Len() != nOldLen;
80 }
81 else if(sToken.EqualsAscii("CR"))
82 {
83 if(bLastLength)
84 sRet +=NEXTLINE;
85 bLastLength = sal_True;
86 }
87 else if(sToken.EqualsAscii("FIRSTNAME"))
88 sRet += (String)rUserOpt.GetFirstName();
89 else if(sToken.EqualsAscii("LASTNAME"))
90 sRet += (String)rUserOpt.GetLastName();
91 else if(sToken.EqualsAscii("ADDRESS"))
92 sRet += (String)rUserOpt.GetStreet();
93 else if(sToken.EqualsAscii("COUNTRY"))
94 sRet += (String)rUserOpt.GetCountry();
95 else if(sToken.EqualsAscii("POSTALCODE"))
96 sRet += (String)rUserOpt.GetZip();
97 else if(sToken.EqualsAscii("CITY"))
98 sRet += (String)rUserOpt.GetCity();
99 else if(sToken.EqualsAscii("STATEPROV"))
100 sRet += (String)rUserOpt.GetState();
101 else if(sToken.Len()) //spaces
102 sRet += sToken;
103 }
104 return sRet;
105 }
106 // --------------------------------------------------------------------------
SwEnvItem()107 SwEnvItem::SwEnvItem() :
108 SfxPoolItem(FN_ENVELOP)
109 {
110 aAddrText = aEmptyStr;
111 bSend = sal_True;
112 aSendText = MakeSender();
113 lSendFromLeft = 566; // 1 cm
114 lSendFromTop = 566; // 1 cm
115 Size aEnvSz = SvxPaperInfo::GetPaperSize(PAPER_ENV_C65);
116 lWidth = aEnvSz.Width();
117 lHeight = aEnvSz.Height();
118 eAlign = ENV_HOR_LEFT;
119 bPrintFromAbove = sal_True;
120 lShiftRight = 0;
121 lShiftDown = 0;
122
123 lAddrFromLeft = Max(lWidth, lHeight) / 2;
124 lAddrFromTop = Min(lWidth, lHeight) / 2;
125 }
126 // --------------------------------------------------------------------------
SwEnvItem(const SwEnvItem & rItem)127 SwEnvItem::SwEnvItem(const SwEnvItem& rItem) :
128 SfxPoolItem(FN_ENVELOP),
129 aAddrText (rItem.aAddrText),
130 bSend (rItem.bSend),
131 aSendText (rItem.aSendText),
132 lAddrFromLeft (rItem.lAddrFromLeft),
133 lAddrFromTop (rItem.lAddrFromTop),
134 lSendFromLeft (rItem.lSendFromLeft),
135 lSendFromTop (rItem.lSendFromTop),
136 lWidth (rItem.lWidth),
137 lHeight (rItem.lHeight),
138 eAlign (rItem.eAlign),
139 bPrintFromAbove(rItem.bPrintFromAbove),
140 lShiftRight (rItem.lShiftRight),
141 lShiftDown (rItem.lShiftDown)
142 {
143 }
144
145 // --------------------------------------------------------------------------
operator =(const SwEnvItem & rItem)146 SwEnvItem& SwEnvItem::operator =(const SwEnvItem& rItem)
147 {
148 aAddrText = rItem.aAddrText;
149 bSend = rItem.bSend;
150 aSendText = rItem.aSendText;
151 lSendFromLeft = rItem.lSendFromLeft;
152 lSendFromTop = rItem.lSendFromTop;
153 lAddrFromLeft = rItem.lAddrFromLeft;
154 lAddrFromTop = rItem.lAddrFromTop;
155 lWidth = rItem.lWidth;
156 lHeight = rItem.lHeight;
157 eAlign = rItem.eAlign;
158 bPrintFromAbove = rItem.bPrintFromAbove;
159 lShiftRight = rItem.lShiftRight;
160 lShiftDown = rItem.lShiftDown;
161 return *this;
162 }
163 // --------------------------------------------------------------------------
operator ==(const SfxPoolItem & rItem) const164 int SwEnvItem::operator ==(const SfxPoolItem& rItem) const
165 {
166 const SwEnvItem& rEnv = (const SwEnvItem&) rItem;
167
168 return aAddrText == rEnv.aAddrText &&
169 bSend == rEnv.bSend &&
170 aSendText == rEnv.aSendText &&
171 lSendFromLeft == rEnv.lSendFromLeft &&
172 lSendFromTop == rEnv.lSendFromTop &&
173 lAddrFromLeft == rEnv.lAddrFromLeft &&
174 lAddrFromTop == rEnv.lAddrFromTop &&
175 lWidth == rEnv.lWidth &&
176 lHeight == rEnv.lHeight &&
177 eAlign == rEnv.eAlign &&
178 bPrintFromAbove == rEnv.bPrintFromAbove &&
179 lShiftRight == rEnv.lShiftRight &&
180 lShiftDown == rEnv.lShiftDown;
181 }
182
183 // --------------------------------------------------------------------------
Clone(SfxItemPool *) const184 SfxPoolItem* SwEnvItem::Clone(SfxItemPool*) const
185 {
186 return new SwEnvItem(*this);
187 }
188 // --------------------------------------------------------------------------
189 // --------------------------------------------------------------------------
SwEnvCfgItem()190 SwEnvCfgItem::SwEnvCfgItem() :
191 ConfigItem(C2U("Office.Writer/Envelope"))
192 {
193 Sequence<OUString> aNames = GetPropertyNames();
194 Sequence<Any> aValues = GetProperties(aNames);
195 EnableNotification(aNames);
196 const Any* pValues = aValues.getConstArray();
197 DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed");
198 if(aValues.getLength() == aNames.getLength())
199 {
200 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
201 {
202 if(pValues[nProp].hasValue())
203 {
204 switch(nProp)
205 {
206 case 0: pValues[nProp] >>= aEnvItem.aAddrText; break;// "Inscription/Addressee",
207 case 1: pValues[nProp] >>= aEnvItem.aSendText; break;// "Inscription/Sender",
208 case 2: aEnvItem.bSend = *(sal_Bool*)pValues[nProp].getValue(); break;// "Inscription/UseSender",
209 case 3:
210 pValues[nProp] >>= aEnvItem.lAddrFromLeft;// "Format/AddresseeFromLeft",
211 aEnvItem.lAddrFromLeft = MM100_TO_TWIP(aEnvItem.lAddrFromLeft);
212 break;
213 case 4:
214 pValues[nProp] >>= aEnvItem.lAddrFromTop; // "Format/AddresseeFromTop",
215 aEnvItem.lAddrFromTop = MM100_TO_TWIP(aEnvItem.lAddrFromTop);
216 break;
217 case 5:
218 pValues[nProp] >>= aEnvItem.lSendFromLeft; // "Format/SenderFromLeft",
219 aEnvItem.lSendFromLeft = MM100_TO_TWIP(aEnvItem.lSendFromLeft);
220 break;
221 case 6:
222 pValues[nProp] >>= aEnvItem.lSendFromTop;// "Format/SenderFromTop",
223 aEnvItem.lSendFromTop = MM100_TO_TWIP(aEnvItem.lSendFromTop);
224 break;
225 case 7:
226 pValues[nProp] >>= aEnvItem.lWidth; // "Format/Width",
227 aEnvItem.lWidth = MM100_TO_TWIP(aEnvItem.lWidth);
228 break;
229 case 8:
230 pValues[nProp] >>= aEnvItem.lHeight; // "Format/Height",
231 aEnvItem.lHeight = MM100_TO_TWIP(aEnvItem.lHeight);
232 break;
233 case 9:
234 {
235 sal_Int32 nTemp = 0;
236 pValues[nProp] >>= nTemp; aEnvItem.eAlign = (SwEnvAlign)nTemp; break;// "Print/Alignment",
237 }
238 case 10: aEnvItem.bPrintFromAbove = *(sal_Bool*)pValues[nProp].getValue(); break;// "Print/FromAbove",
239 case 11:
240 pValues[nProp] >>= aEnvItem.lShiftRight;
241 aEnvItem.lShiftRight = MM100_TO_TWIP(aEnvItem.lShiftRight);// "Print/Right",
242 break;
243 case 12:
244 pValues[nProp] >>= aEnvItem.lShiftDown;
245 aEnvItem.lShiftDown = MM100_TO_TWIP(aEnvItem.lShiftDown);
246 break;// "Print/Down"
247 }
248 }
249 }
250 }
251 }
252 /* -----------------------------26.09.00 14:04--------------------------------
253
254 ---------------------------------------------------------------------------*/
~SwEnvCfgItem()255 SwEnvCfgItem::~SwEnvCfgItem()
256 {
257 }
258 /* -----------------------------26.09.00 14:05--------------------------------
259
260 ---------------------------------------------------------------------------*/
Commit()261 void SwEnvCfgItem::Commit()
262 {
263 Sequence<OUString> aNames = GetPropertyNames();
264 Sequence<Any> aValues(aNames.getLength());
265 Any* pValues = aValues.getArray();
266
267 const Type& rType = ::getBooleanCppuType();
268 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
269 {
270 switch(nProp)
271 {
272 case 0: pValues[nProp] <<= aEnvItem.aAddrText; break;// "Inscription/Addressee",
273 case 1: pValues[nProp] <<= aEnvItem.aSendText; break;// "Inscription/Sender",
274 case 2: pValues[nProp].setValue(&aEnvItem.bSend, rType);break;// "Inscription/UseSender",
275 case 3: pValues[nProp] <<= static_cast <sal_Int32>(TWIP_TO_MM100(aEnvItem.lAddrFromLeft)) ; break;// "Format/AddresseeFromLeft",
276 case 4: pValues[nProp] <<= static_cast <sal_Int32>(TWIP_TO_MM100(aEnvItem.lAddrFromTop)) ; break;// "Format/AddresseeFromTop",
277 case 5: pValues[nProp] <<= static_cast <sal_Int32>(TWIP_TO_MM100(aEnvItem.lSendFromLeft)) ; break;// "Format/SenderFromLeft",
278 case 6: pValues[nProp] <<= static_cast <sal_Int32>(TWIP_TO_MM100(aEnvItem.lSendFromTop)) ; break;// "Format/SenderFromTop",
279 case 7: pValues[nProp] <<= static_cast <sal_Int32>(TWIP_TO_MM100(aEnvItem.lWidth)) ; break;// "Format/Width",
280 case 8: pValues[nProp] <<= static_cast <sal_Int32>(TWIP_TO_MM100(aEnvItem.lHeight)) ; break;// "Format/Height",
281 case 9: pValues[nProp] <<= sal_Int32(aEnvItem.eAlign); break;// "Print/Alignment",
282 case 10: pValues[nProp].setValue(&aEnvItem.bPrintFromAbove, rType); break;// "Print/FromAbove",
283 case 11: pValues[nProp] <<= static_cast <sal_Int32>(TWIP_TO_MM100(aEnvItem.lShiftRight));break; // "Print/Right",
284 case 12: pValues[nProp] <<= static_cast <sal_Int32>(TWIP_TO_MM100(aEnvItem.lShiftDown)); break;// "Print/Down"
285 }
286 }
287 PutProperties(aNames, aValues);
288 }
289
Notify(const::com::sun::star::uno::Sequence<rtl::OUString> &)290 void SwEnvCfgItem::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
291
292 /* -----------------------------26.09.00 14:04--------------------------------
293
294 ---------------------------------------------------------------------------*/
GetPropertyNames()295 Sequence<rtl::OUString> SwEnvCfgItem::GetPropertyNames()
296 {
297 static const char* aPropNames[] =
298 {
299 "Inscription/Addressee", // 0
300 "Inscription/Sender", // 1
301 "Inscription/UseSender", // 2
302 "Format/AddresseeFromLeft", // 3
303 "Format/AddresseeFromTop", // 4
304 "Format/SenderFromLeft", // 5
305 "Format/SenderFromTop", // 6
306 "Format/Width", // 7
307 "Format/Height", // 8
308 "Print/Alignment", // 9
309 "Print/FromAbove", // 10
310 "Print/Right", // 11
311 "Print/Down" // 12
312 };
313 const int nCount = 13;
314 Sequence<OUString> aNames(nCount);
315 OUString* pNames = aNames.getArray();
316 for(int i = 0; i < nCount; i++)
317 pNames[i] = OUString::createFromAscii(aPropNames[i]);
318 return aNames;
319 }
320
QueryValue(Any & rVal,sal_uInt8 nMemberId) const321 sal_Bool SwEnvItem::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
322 {
323 sal_Bool bRet = sal_True;
324 switch(nMemberId & ~CONVERT_TWIPS)
325 {
326 case MID_ENV_ADDR_TEXT : rVal <<= aAddrText; break;
327 case MID_ENV_SEND : rVal <<= bSend; break;
328 case MID_SEND_TEXT : rVal <<= aSendText; break;
329 case MID_ENV_ADDR_FROM_LEFT : rVal <<= lAddrFromLeft; break;
330 case MID_ENV_ADDR_FROM_TOP : rVal <<= lAddrFromTop; break;
331 case MID_ENV_SEND_FROM_LEFT : rVal <<= lSendFromLeft; break;
332 case MID_ENV_SEND_FROM_TOP : rVal <<= lSendFromTop; break;
333 case MID_ENV_WIDTH : rVal <<= lWidth; break;
334 case MID_ENV_HEIGHT : rVal <<= lHeight; break;
335 case MID_ENV_ALIGN : rVal <<= (sal_Int16) eAlign; break;
336 case MID_ENV_PRINT_FROM_ABOVE : rVal <<= bPrintFromAbove; break;
337 case MID_ENV_SHIFT_RIGHT : rVal <<= lShiftRight; break;
338 case MID_ENV_SHIFT_DOWN : rVal <<= lShiftDown; break;
339 default:
340 DBG_ERROR("Wrong memberId");
341 bRet = sal_False;
342 }
343 return bRet;
344 }
345 /* -----------------------------26.04.01 12:26--------------------------------
346
347 ---------------------------------------------------------------------------*/
PutValue(const Any & rVal,sal_uInt8 nMemberId)348 sal_Bool SwEnvItem::PutValue(const Any& rVal, sal_uInt8 nMemberId)
349 {
350 sal_Bool bRet = sal_False;
351 switch(nMemberId & ~CONVERT_TWIPS)
352 {
353 case MID_ENV_ADDR_TEXT : bRet = (rVal >>= aAddrText); break;
354 case MID_ENV_SEND : bRet = (rVal >>= bSend); break;
355 case MID_SEND_TEXT : bRet = (rVal >>= aSendText); break;
356 case MID_ENV_ADDR_FROM_LEFT : bRet = (rVal >>= lAddrFromLeft); break;
357 case MID_ENV_ADDR_FROM_TOP : bRet = (rVal >>= lAddrFromTop); break;
358 case MID_ENV_SEND_FROM_LEFT : bRet = (rVal >>= lSendFromLeft); break;
359 case MID_ENV_SEND_FROM_TOP : bRet = (rVal >>= lSendFromTop); break;
360 case MID_ENV_WIDTH : bRet = (rVal >>= lWidth); break;
361 case MID_ENV_HEIGHT : bRet = (rVal >>= lHeight); break;
362 case MID_ENV_ALIGN :
363 {
364 sal_Int16 nTemp = 0;
365 bRet = (rVal >>= nTemp);
366 if (bRet)
367 eAlign = SwEnvAlign(nTemp);
368 break;
369 }
370 case MID_ENV_PRINT_FROM_ABOVE : bRet = (rVal >>= bPrintFromAbove); break;
371 case MID_ENV_SHIFT_RIGHT : bRet = (rVal >>= lShiftRight); break;
372 case MID_ENV_SHIFT_DOWN : bRet = (rVal >>= lShiftDown); break;
373 default:
374 DBG_ERROR("Wrong memberId");
375 }
376 return bRet;
377 }
378