update dev300-m58
[ooovba.git] / sw / source / ui / envelp / envprt.cxx
blob295f740cff2209a7ce5ecc164324740f122c6e24
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: envprt.cxx,v $
10 * $Revision: 1.12 $
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"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
39 #include <vcl/print.hxx>
40 #include <svtools/prnsetup.hxx>
42 #include "swtypes.hxx"
43 #include "cmdid.h"
44 #include "envprt.hxx"
45 #include "envlop.hxx"
46 #include "uitool.hxx"
48 #include "envprt.hrc"
54 SwEnvPrtPage::SwEnvPrtPage(Window* pParent, const SfxItemSet& rSet) :
56 SfxTabPage(pParent, SW_RES(TP_ENV_PRT), rSet),
58 aAlignBox (this, SW_RES(BOX_ALIGN )),
59 aTopButton (this, SW_RES(BTN_TOP )),
60 aBottomButton(this, SW_RES(BTN_BOTTOM )),
61 aRightText (this, SW_RES(TXT_RIGHT )),
62 aRightField (this, SW_RES(FLD_RIGHT )),
63 aDownText (this, SW_RES(TXT_DOWN )),
64 aDownField (this, SW_RES(FLD_DOWN )),
65 aPrinterInfo (this, SW_RES(TXT_PRINTER)),
66 aNoNameFL (this, SW_RES(FL_NONAME )),
67 aPrinterFL (this, SW_RES(FL_PRINTER )),
68 aPrtSetup (this, SW_RES(BTN_PRTSETUP))
71 FreeResource();
72 SetExchangeSupport();
74 // Metriken
75 FieldUnit eUnit = ::GetDfltMetric(FALSE);
76 SetMetric(aRightField, eUnit);
77 SetMetric(aDownField , eUnit);
79 // Handler installieren
80 aTopButton .SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
81 aBottomButton.SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
83 aPrtSetup .SetClickHdl(LINK(this, SwEnvPrtPage, ButtonHdl));
85 // Bitmaps
86 aBottomButton.GetClickHdl().Call(&aBottomButton);
88 // ToolBox
89 Size aSz = aAlignBox.CalcWindowSizePixel();
90 aAlignBox.SetSizePixel(aSz);
91 // aAlignBox.SetPosPixel(Point(aNoNameFL.GetPosPixel().X() + (aNoNameFL.GetSizePixel().Width() - aSz.Width()) / 2, aAlignBox.GetPosPixel().Y()));
92 aAlignBox.SetClickHdl(LINK(this, SwEnvPrtPage, AlignHdl));
96 // --------------------------------------------------------------------------
100 SwEnvPrtPage::~SwEnvPrtPage()
104 // --------------------------------------------------------------------------
108 IMPL_LINK( SwEnvPrtPage, ClickHdl, Button *, EMPTYARG )
110 sal_Bool bHC = GetDisplayBackground().GetColor().IsDark();
111 if (aBottomButton.IsChecked())
113 // Briefumschlaege von unten
114 aAlignBox.SetItemImage(ITM_HOR_LEFT, Bitmap(SW_RES(bHC ? BMP_HOR_LEFT_LOWER_H : BMP_HOR_LEFT_LOWER)));
115 aAlignBox.SetItemImage(ITM_HOR_CNTR, Bitmap(SW_RES(bHC ? BMP_HOR_CNTR_LOWER_H : BMP_HOR_CNTR_LOWER)));
116 aAlignBox.SetItemImage(ITM_HOR_RGHT, Bitmap(SW_RES(bHC ? BMP_HOR_RGHT_LOWER_H : BMP_HOR_RGHT_LOWER)));
117 aAlignBox.SetItemImage(ITM_VER_LEFT, Bitmap(SW_RES(bHC ? BMP_VER_LEFT_LOWER_H : BMP_VER_LEFT_LOWER)));
118 aAlignBox.SetItemImage(ITM_VER_CNTR, Bitmap(SW_RES(bHC ? BMP_VER_CNTR_LOWER_H : BMP_VER_CNTR_LOWER)));
119 aAlignBox.SetItemImage(ITM_VER_RGHT, Bitmap(SW_RES(bHC ? BMP_VER_RGHT_LOWER_H : BMP_VER_RGHT_LOWER)));
121 else
123 // Briefumschlaege von oben
124 aAlignBox.SetItemImage(ITM_HOR_LEFT, Bitmap(SW_RES(bHC ? BMP_HOR_LEFT_UPPER_H : BMP_HOR_LEFT_UPPER)));
125 aAlignBox.SetItemImage(ITM_HOR_CNTR, Bitmap(SW_RES(bHC ? BMP_HOR_CNTR_UPPER_H : BMP_HOR_CNTR_UPPER)));
126 aAlignBox.SetItemImage(ITM_HOR_RGHT, Bitmap(SW_RES(bHC ? BMP_HOR_RGHT_UPPER_H : BMP_HOR_RGHT_UPPER)));
127 aAlignBox.SetItemImage(ITM_VER_LEFT, Bitmap(SW_RES(bHC ? BMP_VER_LEFT_UPPER_H : BMP_VER_LEFT_UPPER)));
128 aAlignBox.SetItemImage(ITM_VER_CNTR, Bitmap(SW_RES(bHC ? BMP_VER_CNTR_UPPER_H : BMP_VER_CNTR_UPPER)));
129 aAlignBox.SetItemImage(ITM_VER_RGHT, Bitmap(SW_RES(bHC ? BMP_VER_RGHT_UPPER_H : BMP_VER_RGHT_UPPER)));
131 return 0;
134 // --------------------------------------------------------------------------
138 IMPL_LINK( SwEnvPrtPage, ButtonHdl, Button *, pBtn )
140 if (pBtn == &aPrtSetup)
142 // Druck-Setup aufrufen
143 if (pPrt)
145 PrinterSetupDialog* pDlg = new PrinterSetupDialog(this );
146 pDlg->SetPrinter(pPrt);
147 pDlg->Execute();
148 delete pDlg;
149 GrabFocus();
150 aPrinterInfo.SetText(pPrt->GetName());
153 return 0;
156 // --------------------------------------------------------------------------
160 IMPL_LINK( SwEnvPrtPage, AlignHdl, ToolBox *, EMPTYARG )
162 if (aAlignBox.GetCurItemId())
164 for (USHORT i = ITM_HOR_LEFT; i <= ITM_VER_RGHT; i++)
165 aAlignBox.CheckItem(i, FALSE);
166 aAlignBox.CheckItem(aAlignBox.GetCurItemId(), TRUE);
168 else
170 // GetCurItemId() == 0 ist moeglich!
171 const SwEnvItem& rItem = (const SwEnvItem&) GetItemSet().Get(FN_ENVELOP);
172 aAlignBox.CheckItem((USHORT) rItem.eAlign + ITM_HOR_LEFT, TRUE);
174 return 0;
177 // --------------------------------------------------------------------------
181 SfxTabPage* SwEnvPrtPage::Create(Window* pParent, const SfxItemSet& rSet)
183 return new SwEnvPrtPage(pParent, rSet);
186 // --------------------------------------------------------------------------
190 void SwEnvPrtPage::ActivatePage(const SfxItemSet&)
192 if (pPrt)
193 aPrinterInfo.SetText(pPrt->GetName());
196 // --------------------------------------------------------------------------
200 int SwEnvPrtPage::DeactivatePage(SfxItemSet* _pSet)
202 if( _pSet )
203 FillItemSet(*_pSet);
204 return SfxTabPage::LEAVE_PAGE;
207 // --------------------------------------------------------------------------
211 void SwEnvPrtPage::FillItem(SwEnvItem& rItem)
213 USHORT nID = 0;
214 for (USHORT i = ITM_HOR_LEFT; i <= ITM_VER_RGHT && !nID; i++)
215 if (aAlignBox.IsItemChecked(i))
216 nID = i;
218 rItem.eAlign = (SwEnvAlign) (nID - ITM_HOR_LEFT);
219 rItem.bPrintFromAbove = aTopButton.IsChecked();
220 rItem.lShiftRight = static_cast< sal_Int32 >(GetFldVal(aRightField));
221 rItem.lShiftDown = static_cast< sal_Int32 >(GetFldVal(aDownField ));
224 // --------------------------------------------------------------------------
228 BOOL SwEnvPrtPage::FillItemSet(SfxItemSet& rSet)
230 FillItem(GetParent()->aEnvItem);
231 rSet.Put(GetParent()->aEnvItem);
232 return TRUE;
235 // ----------------------------------------------------------------------------
239 void SwEnvPrtPage::Reset(const SfxItemSet& rSet)
241 // SfxItemSet aSet(rSet);
242 // aSet.Put(GetParent()->aEnvItem);
244 // Item auslesen
245 const SwEnvItem& rItem = (const SwEnvItem&) rSet.Get(FN_ENVELOP);
246 aAlignBox.CheckItem((USHORT) rItem.eAlign + ITM_HOR_LEFT);
248 if (rItem.bPrintFromAbove)
249 aTopButton .Check();
250 else
251 aBottomButton.Check();
253 SetFldVal(aRightField, rItem.lShiftRight);
254 SetFldVal(aDownField , rItem.lShiftDown );
256 ActivatePage(rSet);
257 ClickHdl(&aTopButton);