1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: envlop1.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
40 #include <sfx2/app.hxx>
41 #include <vcl/msgbox.hxx>
43 #include <viewopt.hxx>
53 #include "poolfmt.hxx"
57 #include <comphelper/processfactory.hxx>
61 using namespace ::com::sun::star::lang
;
62 using namespace ::com::sun::star::container
;
63 using namespace ::com::sun::star::uno
;
64 using namespace ::com::sun::star
;
65 using namespace ::rtl
;
69 extern SW_DLLPUBLIC String
MakeSender();
71 // --------------------------------------------------------------------------
73 SwEnvPreview::SwEnvPreview(SfxTabPage
* pParent
, const ResId
& rResID
) :
75 Window(pParent
, rResID
)
78 SetMapMode(MapMode(MAP_PIXEL
));
81 // --------------------------------------------------------------------------
85 SwEnvPreview::~SwEnvPreview()
89 // ----------------------------------------------------------------------------
90 void SwEnvPreview::DataChanged( const DataChangedEvent
& rDCEvt
)
92 Window::DataChanged( rDCEvt
);
93 if ( DATACHANGED_SETTINGS
== rDCEvt
.GetType() )
94 SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
97 // ----------------------------------------------------------------------------
99 void SwEnvPreview::Paint(const Rectangle
&)
101 const StyleSettings
& rSettings
= GetSettings().GetStyleSettings();
103 const SwEnvItem
& rItem
=
104 ((SwEnvDlg
*) GetParent()->GetParent()->GetParent())->aEnvItem
;
106 USHORT nPageW
= (USHORT
) Max(rItem
.lWidth
, rItem
.lHeight
),
107 nPageH
= (USHORT
) Min(rItem
.lWidth
, rItem
.lHeight
);
109 float fx
= static_cast< float >(GetOutputSizePixel().Width () / nPageW
),
110 fy
= static_cast< float >(GetOutputSizePixel().Height() / nPageH
),
111 f
= static_cast< float >(0.8 * ( fx
< fy
? fx
: fy
));
113 Color aBack
= rSettings
.GetWindowColor( );
114 Color aFront
= SwViewOption::GetFontColor();
115 Color aMedium
= Color( ( aBack
.GetRed() + aFront
.GetRed() ) / 2,
116 ( aBack
.GetGreen() + aFront
.GetGreen() ) / 2,
117 ( aBack
.GetBlue() + aFront
.GetBlue() ) / 2
120 SetLineColor( aFront
);
123 long nW
= (USHORT
) (f
* nPageW
),
124 nH
= (USHORT
) (f
* nPageH
),
125 nX
= (GetOutputSizePixel().Width () - nW
) / 2,
126 nY
= (GetOutputSizePixel().Height() - nH
) / 2;
127 SetFillColor( aBack
);
128 DrawRect(Rectangle(Point(nX
, nY
), Size(nW
, nH
)));
133 long nSendX
= nX
+ (USHORT
) (f
* rItem
.lSendFromLeft
),
134 nSendY
= nY
+ (USHORT
) (f
* rItem
.lSendFromTop
),
135 nSendW
= (USHORT
) (f
* (rItem
.lAddrFromLeft
- rItem
.lSendFromLeft
)),
136 nSendH
= (USHORT
) (f
* (rItem
.lAddrFromTop
- rItem
.lSendFromTop
- 566));
137 SetFillColor( aMedium
);
139 DrawRect(Rectangle(Point(nSendX
, nSendY
), Size(nSendW
, nSendH
)));
143 long nAddrX
= nX
+ (USHORT
) (f
* rItem
.lAddrFromLeft
),
144 nAddrY
= nY
+ (USHORT
) (f
* rItem
.lAddrFromTop
),
145 nAddrW
= (USHORT
) (f
* (nPageW
- rItem
.lAddrFromLeft
- 566)),
146 nAddrH
= (USHORT
) (f
* (nPageH
- rItem
.lAddrFromTop
- 566));
147 SetFillColor( aMedium
);
148 DrawRect(Rectangle(Point(nAddrX
, nAddrY
), Size(nAddrW
, nAddrH
)));
151 long nStmpW
= (USHORT
) (f
* 1417 /* 2,5 cm */),
152 nStmpH
= (USHORT
) (f
* 1701 /* 3,0 cm */),
153 nStmpX
= nX
+ nW
- (USHORT
) (f
* 566) - nStmpW
,
154 nStmpY
= nY
+ (USHORT
) (f
* 566);
156 SetFillColor( aBack
);
157 DrawRect(Rectangle(Point(nStmpX
, nStmpY
), Size(nStmpW
, nStmpH
)));
160 // --------------------------------------------------------------------------
164 SwEnvDlg::SwEnvDlg(Window
* pParent
, const SfxItemSet
& rSet
,
165 SwWrtShell
* pWrtSh
, Printer
* pPrt
, BOOL bInsert
) :
167 SfxTabDialog(pParent
, SW_RES(DLG_ENV
), &rSet
, FALSE
, &aEmptyStr
),
168 sInsert(SW_RES(ST_INSERT
)),
169 sChange(SW_RES(ST_CHANGE
)),
170 aEnvItem((const SwEnvItem
&) rSet
.Get(FN_ENVELOP
)),
178 GetOKButton().SetText(String(SW_RES(STR_BTN_NEWDOC
)));
179 GetOKButton().SetHelpId(HID_ENVELOP_PRINT
);
180 GetOKButton().SetHelpText(aEmptyStr
); // Damit generierter Hilfetext verwendet wird
183 GetUserButton()->SetText(bInsert
? sInsert
: sChange
);
184 GetUserButton()->SetHelpId(HID_ENVELOP_INSERT
);
187 AddTabPage(TP_ENV_ENV
, SwEnvPage ::Create
, 0);
188 AddTabPage(TP_ENV_FMT
, SwEnvFmtPage::Create
, 0);
189 AddTabPage(TP_ENV_PRT
, SwEnvPrtPage::Create
, 0);
192 // --------------------------------------------------------------------------
196 SwEnvDlg::~SwEnvDlg()
198 delete pAddresseeSet
;
202 // --------------------------------------------------------------------------
206 void SwEnvDlg::PageCreated(USHORT nId
, SfxTabPage
&rPage
)
208 if (nId
== TP_ENV_PRT
)
210 ((SwEnvPrtPage
*)&rPage
)->SetPrt(pPrinter
);
214 // --------------------------------------------------------------------------
218 short nRet
= SfxTabDialog::Ok();
220 if (nRet
== RET_OK
|| nRet
== RET_USER
)
224 SwTxtFmtColl
* pColl
= pSh
->GetTxtCollFromPool(RES_POOLCOLL_JAKETADRESS
);
225 pColl
->SetFmtAttr(*pAddresseeSet
);
229 SwTxtFmtColl
* pColl
= pSh
->GetTxtCollFromPool(RES_POOLCOLL_SENDADRESS
);
230 pColl
->SetFmtAttr(*pSenderSet
);
237 // --------------------------------------------------------------------------
241 SwEnvPage::SwEnvPage(Window
* pParent
, const SfxItemSet
& rSet
) :
243 SfxTabPage(pParent
, SW_RES(TP_ENV_ENV
), rSet
),
245 aAddrText (this, SW_RES(TXT_ADDR
)),
246 aAddrEdit (this, SW_RES(EDT_ADDR
)),
247 aDatabaseFT (this, SW_RES(FT_DATABASE
)),
248 aDatabaseLB (this, SW_RES(LB_DATABASE
)),
249 aTableFT (this, SW_RES(FT_TABLE
)),
250 aTableLB (this, SW_RES(LB_TABLE
)),
251 aInsertBT (this, SW_RES(BTN_INSERT
)),
252 aDBFieldFT (this, SW_RES(FT_DBFIELD
)),
253 aDBFieldLB (this, SW_RES(LB_DBFIELD
)),
254 aSenderBox (this, SW_RES(BOX_SEND
)),
255 aSenderEdit (this, SW_RES(EDT_SEND
)),
256 aPreview (this, SW_RES(WIN_PREVIEW
))
260 SetExchangeSupport();
261 pSh
= GetParent()->pSh
;
263 // Handler installieren
264 aDatabaseLB
.SetSelectHdl(LINK(this, SwEnvPage
, DatabaseHdl
));
265 aTableLB
.SetSelectHdl(LINK(this, SwEnvPage
, DatabaseHdl
));
266 aInsertBT
.SetClickHdl (LINK(this, SwEnvPage
, FieldHdl
));
267 aSenderBox
.SetClickHdl (LINK(this, SwEnvPage
, SenderHdl
));
268 aPreview
.SetBorderStyle( WINDOW_BORDER_MONO
);
270 SwDBData aData
= pSh
->GetDBData();
271 sActDBName
= aData
.sDataSource
;
272 sActDBName
+= DB_DELIM
;
273 sActDBName
+= (String
)aData
.sCommand
;
277 // --------------------------------------------------------------------------
281 SwEnvPage::~SwEnvPage()
285 // --------------------------------------------------------------------------
289 IMPL_LINK( SwEnvPage
, DatabaseHdl
, ListBox
*, pListBox
)
291 SwWait
aWait( *pSh
->GetView().GetDocShell(), TRUE
);
293 if (pListBox
== &aDatabaseLB
)
295 sActDBName
= pListBox
->GetSelectEntry();
296 pSh
->GetNewDBMgr()->GetTableNames(&aTableLB
, sActDBName
);
297 sActDBName
+= DB_DELIM
;
300 sActDBName
.SetToken(1, DB_DELIM
, aTableLB
.GetSelectEntry());
301 pSh
->GetNewDBMgr()->GetColumnNames(
302 &aDBFieldLB
, aDatabaseLB
.GetSelectEntry(), aTableLB
.GetSelectEntry());
306 // --------------------------------------------------------------------------
310 IMPL_LINK( SwEnvPage
, FieldHdl
, Button
*, EMPTYARG
)
313 aStr
+= aDatabaseLB
.GetSelectEntry();
316 aStr
+= aTableLB
.GetSelectEntry();
318 aStr
+= aTableLB
.GetEntryData(aTableLB
.GetSelectEntryPos()) == 0 ? '0' : '1';
321 aStr
+= aDBFieldLB
.GetSelectEntry();
323 aAddrEdit
.ReplaceSelected(aStr
);
324 Selection aSel
= aAddrEdit
.GetSelection();
325 aAddrEdit
.GrabFocus();
326 aAddrEdit
.SetSelection(aSel
);
330 // --------------------------------------------------------------------------
334 IMPL_LINK( SwEnvPage
, SenderHdl
, Button
*, EMPTYARG
)
336 const BOOL bEnable
= aSenderBox
.IsChecked();
337 GetParent()->aEnvItem
.bSend
= bEnable
;
338 aSenderEdit
.Enable(bEnable
);
341 aSenderEdit
.GrabFocus();
342 if(!aSenderEdit
.GetText().Len())
343 aSenderEdit
.SetText(MakeSender());
345 aPreview
.Invalidate();
349 // --------------------------------------------------------------------------
353 void SwEnvPage::InitDatabaseBox()
355 if (pSh
->GetNewDBMgr())
358 Sequence
<OUString
> aDataNames
= SwNewDBMgr::GetExistingDatabaseNames();
359 const OUString
* pDataNames
= aDataNames
.getConstArray();
360 for (long i
= 0; i
< aDataNames
.getLength(); i
++)
361 aDatabaseLB
.InsertEntry(pDataNames
[i
]);
363 String sDBName
= sActDBName
.GetToken( 0, DB_DELIM
);
364 String sTableName
= sActDBName
.GetToken( 1, DB_DELIM
);
365 aDatabaseLB
.SelectEntry(sDBName
);
366 if (pSh
->GetNewDBMgr()->GetTableNames(&aTableLB
, sDBName
))
368 aTableLB
.SelectEntry(sTableName
);
369 pSh
->GetNewDBMgr()->GetColumnNames(&aDBFieldLB
, sDBName
, sTableName
);
377 // --------------------------------------------------------------------------
381 SfxTabPage
* SwEnvPage::Create(Window
* pParent
, const SfxItemSet
& rSet
)
383 return new SwEnvPage(pParent
, rSet
);
386 // --------------------------------------------------------------------------
390 void SwEnvPage::ActivatePage(const SfxItemSet
& rSet
)
392 SfxItemSet
aSet(rSet
);
393 aSet
.Put(GetParent()->aEnvItem
);
397 // --------------------------------------------------------------------------
401 int SwEnvPage::DeactivatePage(SfxItemSet
* _pSet
)
403 FillItem(GetParent()->aEnvItem
);
406 return SfxTabPage::LEAVE_PAGE
;
409 // --------------------------------------------------------------------------
413 void SwEnvPage::FillItem(SwEnvItem
& rItem
)
415 rItem
.aAddrText
= aAddrEdit
.GetText();
416 rItem
.bSend
= aSenderBox
.IsChecked();
417 rItem
.aSendText
= aSenderEdit
.GetText();
420 // --------------------------------------------------------------------------
424 BOOL
SwEnvPage::FillItemSet(SfxItemSet
& rSet
)
426 FillItem(GetParent()->aEnvItem
);
427 rSet
.Put(GetParent()->aEnvItem
);
431 // ----------------------------------------------------------------------------
435 void SwEnvPage::Reset(const SfxItemSet
& rSet
)
437 SwEnvItem aItem
= (const SwEnvItem
&) rSet
.Get(FN_ENVELOP
);
438 aAddrEdit
.SetText(String(aItem
.aAddrText
).ConvertLineEnd());
439 aSenderEdit
.SetText(String(aItem
.aSendText
).ConvertLineEnd());
440 aSenderBox
.Check (aItem
.bSend
);
441 aSenderBox
.GetClickHdl().Call(&aSenderBox
);