xref: /aoo42x/main/sw/source/ui/envelp/envlop1.cxx (revision 8ef2f12b)
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 #ifdef SW_DLLIMPLEMENTATION
27 #undef SW_DLLIMPLEMENTATION
28 #endif
29 
30 
31 
32 #include "dbmgr.hxx"
33 #include <sfx2/app.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <swwait.hxx>
36 #include <viewopt.hxx>
37 
38 #include "wrtsh.hxx"
39 #include "errhdl.hxx"
40 #include "cmdid.h"
41 #include "helpid.h"
42 #include "envfmt.hxx"
43 #include "envlop.hxx"
44 #include "envprt.hxx"
45 #include "fmtcol.hxx"
46 #include "poolfmt.hxx"
47 #include "view.hxx"
48 
49 #include "envlop.hrc"
50 #include <comphelper/processfactory.hxx>
51 
52 #include <unomid.h>
53 
54 using namespace ::com::sun::star::lang;
55 using namespace ::com::sun::star::container;
56 using namespace ::com::sun::star::uno;
57 using namespace ::com::sun::star;
58 using namespace ::rtl;
59 
60 
61 //impl in envimg.cxx
62 extern SW_DLLPUBLIC String MakeSender();
63 
64 // --------------------------------------------------------------------------
65 
SwEnvPreview(SfxTabPage * pParent,const ResId & rResID)66 SwEnvPreview::SwEnvPreview(SfxTabPage* pParent, const ResId& rResID) :
67 
68 	Window(pParent, rResID)
69 
70 {
71 	SetMapMode(MapMode(MAP_PIXEL));
72 }
73 
74 // --------------------------------------------------------------------------
75 
76 
77 
~SwEnvPreview()78 SwEnvPreview::~SwEnvPreview()
79 {
80 }
81 
82 // ----------------------------------------------------------------------------
DataChanged(const DataChangedEvent & rDCEvt)83 void SwEnvPreview::DataChanged( const DataChangedEvent& rDCEvt )
84 {
85 	Window::DataChanged( rDCEvt );
86 	if ( DATACHANGED_SETTINGS == rDCEvt.GetType() )
87 		SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
88 }
89 
90 // ----------------------------------------------------------------------------
91 
Paint(const Rectangle &)92 void SwEnvPreview::Paint(const Rectangle &)
93 {
94 	const StyleSettings& rSettings = GetSettings().GetStyleSettings();
95 
96 	const SwEnvItem& rItem =
97 		((SwEnvDlg*) GetParent()->GetParent()->GetParent())->aEnvItem;
98 
99 	sal_uInt16 nPageW = (sal_uInt16) Max(rItem.lWidth, rItem.lHeight),
100 		   nPageH = (sal_uInt16) Min(rItem.lWidth, rItem.lHeight);
101 
102     float fx = (float)GetOutputSizePixel().Width () / (float)nPageW,
103           fy = (float)GetOutputSizePixel().Height() / (float)nPageH,
104           f  = 0.8f * ( fx < fy ? fx : fy );
105 
106 	Color aBack = rSettings.GetWindowColor( );
107     Color aFront = SwViewOption::GetFontColor();
108 	Color aMedium = Color(	( aBack.GetRed() + aFront.GetRed() ) / 2,
109 							( aBack.GetGreen() + aFront.GetGreen() ) / 2,
110 							( aBack.GetBlue() + aFront.GetBlue() ) / 2
111 						);
112 
113 	SetLineColor( aFront );
114 
115 	// Umschlag
116 	long   nW = (sal_uInt16) (f * nPageW),
117 		   nH = (sal_uInt16) (f * nPageH),
118 		   nX = (GetOutputSizePixel().Width () - nW) / 2,
119 		   nY = (GetOutputSizePixel().Height() - nH) / 2;
120 	SetFillColor( aBack );
121 	DrawRect(Rectangle(Point(nX, nY), Size(nW, nH)));
122 
123 	// Absender
124 	if (rItem.bSend)
125 	{
126 		long   nSendX = nX + (sal_uInt16) (f * rItem.lSendFromLeft),
127 			   nSendY = nY + (sal_uInt16) (f * rItem.lSendFromTop ),
128 			   nSendW = (sal_uInt16) (f * (rItem.lAddrFromLeft - rItem.lSendFromLeft)),
129 			   nSendH = (sal_uInt16) (f * (rItem.lAddrFromTop  - rItem.lSendFromTop  - 566));
130 		SetFillColor( aMedium );
131 
132 		DrawRect(Rectangle(Point(nSendX, nSendY), Size(nSendW, nSendH)));
133 	}
134 
135 	// Empfaenger
136 	long   nAddrX = nX + (sal_uInt16) (f * rItem.lAddrFromLeft),
137 		   nAddrY = nY + (sal_uInt16) (f * rItem.lAddrFromTop ),
138 		   nAddrW = (sal_uInt16) (f * (nPageW - rItem.lAddrFromLeft - 566)),
139 		   nAddrH = (sal_uInt16) (f * (nPageH - rItem.lAddrFromTop  - 566));
140 	SetFillColor( aMedium );
141 	DrawRect(Rectangle(Point(nAddrX, nAddrY), Size(nAddrW, nAddrH)));
142 
143 	// Briefmarke
144 	long   nStmpW = (sal_uInt16) (f * 1417 /* 2,5 cm */),
145 		   nStmpH = (sal_uInt16) (f * 1701 /* 3,0 cm */),
146 		   nStmpX = nX + nW - (sal_uInt16) (f * 566) - nStmpW,
147 		   nStmpY = nY + (sal_uInt16) (f * 566);
148 
149 	SetFillColor( aBack );
150 	DrawRect(Rectangle(Point(nStmpX, nStmpY), Size(nStmpW, nStmpH)));
151 }
152 
153 // --------------------------------------------------------------------------
154 
155 
156 
SwEnvDlg(Window * pParent,const SfxItemSet & rSet,SwWrtShell * pWrtSh,Printer * pPrt,sal_Bool bInsert)157 SwEnvDlg::SwEnvDlg(Window* pParent, const SfxItemSet& rSet,
158 					SwWrtShell* pWrtSh, Printer* pPrt, sal_Bool bInsert) :
159 
160 	SfxTabDialog(pParent, SW_RES(DLG_ENV), &rSet, sal_False, &aEmptyStr),
161 	sInsert(SW_RES(ST_INSERT)),
162 	sChange(SW_RES(ST_CHANGE)),
163 	aEnvItem((const SwEnvItem&) rSet.Get(FN_ENVELOP)),
164 	pSh(pWrtSh),
165 	pPrinter(pPrt),
166 	pAddresseeSet(0),
167 	pSenderSet(0)
168 {
169 	FreeResource();
170 
171 	GetOKButton().SetText(String(SW_RES(STR_BTN_NEWDOC)));
172 	GetOKButton().SetHelpId(HID_ENVELOP_PRINT);
173 	GetOKButton().SetHelpText(aEmptyStr);	// Damit generierter Hilfetext verwendet wird
174 	if (GetUserButton())
175 	{
176 		GetUserButton()->SetText(bInsert ? sInsert : sChange);
177 		GetUserButton()->SetHelpId(HID_ENVELOP_INSERT);
178 	}
179 
180 	AddTabPage(TP_ENV_ENV, SwEnvPage   ::Create, 0);
181 	AddTabPage(TP_ENV_FMT, SwEnvFmtPage::Create, 0);
182 	AddTabPage(TP_ENV_PRT, SwEnvPrtPage::Create, 0);
183 }
184 
185 // --------------------------------------------------------------------------
186 
187 
188 
~SwEnvDlg()189 SwEnvDlg::~SwEnvDlg()
190 {
191 	delete pAddresseeSet;
192 	delete pSenderSet;
193 }
194 
195 // --------------------------------------------------------------------------
196 
197 
198 
PageCreated(sal_uInt16 nId,SfxTabPage & rPage)199 void SwEnvDlg::PageCreated(sal_uInt16 nId, SfxTabPage &rPage)
200 {
201 	if (nId == TP_ENV_PRT)
202 	{
203 		((SwEnvPrtPage*)&rPage)->SetPrt(pPrinter);
204 	}
205 }
206 
207 // --------------------------------------------------------------------------
208 
Ok()209 short SwEnvDlg::Ok()
210 {
211 	short nRet = SfxTabDialog::Ok();
212 
213 	if (nRet == RET_OK || nRet == RET_USER)
214 	{
215 		if (pAddresseeSet)
216 		{
217 			SwTxtFmtColl* pColl = pSh->GetTxtCollFromPool(RES_POOLCOLL_JAKETADRESS);
218             pColl->SetFmtAttr(*pAddresseeSet);
219 		}
220 		if (pSenderSet)
221 		{
222 			SwTxtFmtColl* pColl = pSh->GetTxtCollFromPool(RES_POOLCOLL_SENDADRESS);
223             pColl->SetFmtAttr(*pSenderSet);
224 		}
225 	}
226 
227 	return nRet;
228 }
229 
230 // --------------------------------------------------------------------------
231 
232 
233 
SwEnvPage(Window * pParent,const SfxItemSet & rSet)234 SwEnvPage::SwEnvPage(Window* pParent, const SfxItemSet& rSet) :
235 
236 	SfxTabPage(pParent, SW_RES(TP_ENV_ENV), rSet),
237 
238 	aAddrText      (this, SW_RES(TXT_ADDR   )),
239 	aAddrEdit      (this, SW_RES(EDT_ADDR   )),
240 	aDatabaseFT    (this, SW_RES(FT_DATABASE)),
241 	aDatabaseLB    (this, SW_RES(LB_DATABASE)),
242 	aTableFT       (this, SW_RES(FT_TABLE   )),
243 	aTableLB       (this, SW_RES(LB_TABLE   )),
244 	aInsertBT      (this, SW_RES(BTN_INSERT )),
245 	aDBFieldFT     (this, SW_RES(FT_DBFIELD )),
246 	aDBFieldLB     (this, SW_RES(LB_DBFIELD )),
247 	aSenderBox     (this, SW_RES(BOX_SEND   )),
248 	aSenderEdit    (this, SW_RES(EDT_SEND   )),
249 	aPreview       (this, SW_RES(WIN_PREVIEW))
250 
251 {
252 	FreeResource();
253 	SetExchangeSupport();
254 	pSh = GetParent()->pSh;
255 
256 	// Handler installieren
257 	aDatabaseLB    .SetSelectHdl(LINK(this, SwEnvPage, DatabaseHdl	   ));
258 	aTableLB       .SetSelectHdl(LINK(this, SwEnvPage, DatabaseHdl	   ));
259 	aInsertBT      .SetClickHdl	(LINK(this, SwEnvPage, FieldHdl		   ));
260 	aSenderBox	   .SetClickHdl (LINK(this, SwEnvPage, SenderHdl       ));
261     aPreview.SetBorderStyle( WINDOW_BORDER_MONO );
262 
263 	SwDBData aData = pSh->GetDBData();
264 	sActDBName = aData.sDataSource;
265 	sActDBName += DB_DELIM;
266 	sActDBName += (String)aData.sCommand;
267 	InitDatabaseBox();
268 }
269 
270 // --------------------------------------------------------------------------
271 
272 
273 
~SwEnvPage()274 SwEnvPage::~SwEnvPage()
275 {
276 }
277 
278 // --------------------------------------------------------------------------
279 
280 
281 
IMPL_LINK(SwEnvPage,DatabaseHdl,ListBox *,pListBox)282 IMPL_LINK( SwEnvPage, DatabaseHdl, ListBox *, pListBox )
283 {
284 	SwWait aWait( *pSh->GetView().GetDocShell(), true );
285 
286 	if (pListBox == &aDatabaseLB)
287     {
288         sActDBName = pListBox->GetSelectEntry();
289         pSh->GetNewDBMgr()->GetTableNames(&aTableLB, sActDBName);
290         sActDBName += DB_DELIM;
291     }
292     else
293         sActDBName.SetToken(1, DB_DELIM, aTableLB.GetSelectEntry());
294     pSh->GetNewDBMgr()->GetColumnNames(
295         &aDBFieldLB, aDatabaseLB.GetSelectEntry(), aTableLB.GetSelectEntry());
296 	return 0;
297 }
298 
299 // --------------------------------------------------------------------------
300 
301 
302 
IMPL_LINK(SwEnvPage,FieldHdl,Button *,EMPTYARG)303 IMPL_LINK( SwEnvPage, FieldHdl, Button *, EMPTYARG )
304 {
305 	String aStr ( '<' );
306 	aStr += aDatabaseLB.GetSelectEntry();
307 	aStr += '.';
308 //	aStr += DB_DELIM;
309 	aStr += aTableLB.GetSelectEntry();
310 	aStr += '.';
311     aStr += aTableLB.GetEntryData(aTableLB.GetSelectEntryPos()) == 0 ? '0' : '1';
312 	aStr += '.';
313 //  aStr += DB_DELIM;
314 	aStr += aDBFieldLB.GetSelectEntry();
315 	aStr += '>';
316 	aAddrEdit.ReplaceSelected(aStr);
317 	Selection aSel = aAddrEdit.GetSelection();
318 	aAddrEdit.GrabFocus();
319 	aAddrEdit.SetSelection(aSel);
320 	return 0;
321 }
322 
323 // --------------------------------------------------------------------------
324 
325 
326 
IMPL_LINK(SwEnvPage,SenderHdl,Button *,EMPTYARG)327 IMPL_LINK( SwEnvPage, SenderHdl, Button *, EMPTYARG )
328 {
329 	const sal_Bool bEnable = aSenderBox.IsChecked();
330 	GetParent()->aEnvItem.bSend = bEnable;
331 	aSenderEdit.Enable(bEnable);
332 	if ( bEnable )
333     {
334 		aSenderEdit.GrabFocus();
335         if(!aSenderEdit.GetText().Len())
336             aSenderEdit.SetText(MakeSender());
337     }
338 	aPreview.Invalidate();
339 	return 0;
340 }
341 
342 // --------------------------------------------------------------------------
343 
344 
345 
InitDatabaseBox()346 void SwEnvPage::InitDatabaseBox()
347 {
348 	if (pSh->GetNewDBMgr())
349 	{
350 		aDatabaseLB.Clear();
351 		Sequence<OUString> aDataNames = SwNewDBMgr::GetExistingDatabaseNames();
352 		const OUString* pDataNames = aDataNames.getConstArray();
353 		for (long i = 0; i < aDataNames.getLength(); i++)
354 			aDatabaseLB.InsertEntry(pDataNames[i]);
355 
356 		String sDBName = sActDBName.GetToken( 0, DB_DELIM );
357 		String sTableName = sActDBName.GetToken( 1, DB_DELIM );
358 		aDatabaseLB.SelectEntry(sDBName);
359 		if (pSh->GetNewDBMgr()->GetTableNames(&aTableLB, sDBName))
360 		{
361 			aTableLB.SelectEntry(sTableName);
362             pSh->GetNewDBMgr()->GetColumnNames(&aDBFieldLB, sDBName, sTableName);
363 		}
364 		else
365 			aDBFieldLB.Clear();
366 
367 	}
368 }
369 
370 // --------------------------------------------------------------------------
371 
372 
373 
Create(Window * pParent,const SfxItemSet & rSet)374 SfxTabPage* SwEnvPage::Create(Window* pParent, const SfxItemSet& rSet)
375 {
376 	return new SwEnvPage(pParent, rSet);
377 }
378 
379 // --------------------------------------------------------------------------
380 
381 
382 
ActivatePage(const SfxItemSet & rSet)383 void SwEnvPage::ActivatePage(const SfxItemSet& rSet)
384 {
385 	SfxItemSet aSet(rSet);
386 	aSet.Put(GetParent()->aEnvItem);
387 	Reset(aSet);
388 }
389 
390 // --------------------------------------------------------------------------
391 
392 
393 
DeactivatePage(SfxItemSet * _pSet)394 int SwEnvPage::DeactivatePage(SfxItemSet* _pSet)
395 {
396 	FillItem(GetParent()->aEnvItem);
397     if( _pSet )
398         FillItemSet(*_pSet);
399 	return SfxTabPage::LEAVE_PAGE;
400 }
401 
402 // --------------------------------------------------------------------------
403 
404 
405 
FillItem(SwEnvItem & rItem)406 void SwEnvPage::FillItem(SwEnvItem& rItem)
407 {
408 	rItem.aAddrText = aAddrEdit  .GetText();
409 	rItem.bSend     = aSenderBox .IsChecked();
410 	rItem.aSendText = aSenderEdit.GetText();
411 }
412 
413 // --------------------------------------------------------------------------
414 
415 
416 
FillItemSet(SfxItemSet & rSet)417 sal_Bool SwEnvPage::FillItemSet(SfxItemSet& rSet)
418 {
419 	FillItem(GetParent()->aEnvItem);
420 	rSet.Put(GetParent()->aEnvItem);
421 	return sal_True;
422 }
423 
424 // ----------------------------------------------------------------------------
425 
426 
427 
Reset(const SfxItemSet & rSet)428 void SwEnvPage::Reset(const SfxItemSet& rSet)
429 {
430 	SwEnvItem aItem = (const SwEnvItem&) rSet.Get(FN_ENVELOP);
431 	aAddrEdit  .SetText(String(aItem.aAddrText).ConvertLineEnd());
432 	aSenderEdit.SetText(String(aItem.aSendText).ConvertLineEnd());
433 	aSenderBox .Check  (aItem.bSend);
434 	aSenderBox.GetClickHdl().Call(&aSenderBox);
435 }
436 
437 
438