xref: /AOO41X/main/sw/source/ui/envelp/envprt.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #ifdef SW_DLLIMPLEMENTATION
32 #undef SW_DLLIMPLEMENTATION
33 #endif
34 
35 
36 #include <vcl/print.hxx>
37 #include <svtools/prnsetup.hxx>
38 
39 #include "swtypes.hxx"
40 #include "cmdid.h"
41 #include "envprt.hxx"
42 #include "envlop.hxx"
43 #include "uitool.hxx"
44 
45 #include "envprt.hrc"
46 
47 
48 
49 
50 
51 SwEnvPrtPage::SwEnvPrtPage(Window* pParent, const SfxItemSet& rSet) :
52 
53 	SfxTabPage(pParent, SW_RES(TP_ENV_PRT), rSet),
54 
55 	aAlignBox    (this, SW_RES(BOX_ALIGN  )),
56 	aTopButton   (this, SW_RES(BTN_TOP    )),
57 	aBottomButton(this, SW_RES(BTN_BOTTOM )),
58 	aRightText   (this, SW_RES(TXT_RIGHT  )),
59 	aRightField  (this, SW_RES(FLD_RIGHT  )),
60 	aDownText    (this, SW_RES(TXT_DOWN   )),
61 	aDownField   (this, SW_RES(FLD_DOWN   )),
62 	aPrinterInfo (this, SW_RES(TXT_PRINTER)),
63     aNoNameFL    (this, SW_RES(FL_NONAME )),
64     aPrinterFL   (this, SW_RES(FL_PRINTER )),
65 	aPrtSetup    (this, SW_RES(BTN_PRTSETUP))
66 
67 {
68 	FreeResource();
69 	SetExchangeSupport();
70 
71 	// Metriken
72 	FieldUnit eUnit = ::GetDfltMetric(sal_False);
73 	SetMetric(aRightField, eUnit);
74 	SetMetric(aDownField , eUnit);
75 
76 	// Handler installieren
77 	aTopButton   .SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
78 	aBottomButton.SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
79 
80 	aPrtSetup    .SetClickHdl(LINK(this, SwEnvPrtPage, ButtonHdl));
81 
82 	// Bitmaps
83 	aBottomButton.GetClickHdl().Call(&aBottomButton);
84 
85 	// ToolBox
86 	Size aSz = aAlignBox.CalcWindowSizePixel();
87 	aAlignBox.SetSizePixel(aSz);
88 //    aAlignBox.SetPosPixel(Point(aNoNameFL.GetPosPixel().X() + (aNoNameFL.GetSizePixel().Width() - aSz.Width()) / 2, aAlignBox.GetPosPixel().Y()));
89 	aAlignBox.SetClickHdl(LINK(this, SwEnvPrtPage, AlignHdl));
90 
91 }
92 
93 // --------------------------------------------------------------------------
94 
95 
96 
97 SwEnvPrtPage::~SwEnvPrtPage()
98 {
99 }
100 
101 // --------------------------------------------------------------------------
102 
103 
104 
105 IMPL_LINK( SwEnvPrtPage, ClickHdl, Button *, EMPTYARG )
106 {
107 	sal_Bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
108 	if (aBottomButton.IsChecked())
109 	{
110 		// Briefumschlaege von unten
111 		aAlignBox.SetItemImage(ITM_HOR_LEFT, Bitmap(SW_RES(bHC ? BMP_HOR_LEFT_LOWER_H : BMP_HOR_LEFT_LOWER)));
112 		aAlignBox.SetItemImage(ITM_HOR_CNTR, Bitmap(SW_RES(bHC ? BMP_HOR_CNTR_LOWER_H : BMP_HOR_CNTR_LOWER)));
113 		aAlignBox.SetItemImage(ITM_HOR_RGHT, Bitmap(SW_RES(bHC ? BMP_HOR_RGHT_LOWER_H : BMP_HOR_RGHT_LOWER)));
114 		aAlignBox.SetItemImage(ITM_VER_LEFT, Bitmap(SW_RES(bHC ? BMP_VER_LEFT_LOWER_H : BMP_VER_LEFT_LOWER)));
115 		aAlignBox.SetItemImage(ITM_VER_CNTR, Bitmap(SW_RES(bHC ? BMP_VER_CNTR_LOWER_H : BMP_VER_CNTR_LOWER)));
116 		aAlignBox.SetItemImage(ITM_VER_RGHT, Bitmap(SW_RES(bHC ? BMP_VER_RGHT_LOWER_H : BMP_VER_RGHT_LOWER)));
117 	}
118 	else
119 	{
120 		// Briefumschlaege von oben
121 		aAlignBox.SetItemImage(ITM_HOR_LEFT, Bitmap(SW_RES(bHC ? BMP_HOR_LEFT_UPPER_H : BMP_HOR_LEFT_UPPER)));
122 		aAlignBox.SetItemImage(ITM_HOR_CNTR, Bitmap(SW_RES(bHC ? BMP_HOR_CNTR_UPPER_H : BMP_HOR_CNTR_UPPER)));
123 		aAlignBox.SetItemImage(ITM_HOR_RGHT, Bitmap(SW_RES(bHC ? BMP_HOR_RGHT_UPPER_H : BMP_HOR_RGHT_UPPER)));
124 		aAlignBox.SetItemImage(ITM_VER_LEFT, Bitmap(SW_RES(bHC ? BMP_VER_LEFT_UPPER_H : BMP_VER_LEFT_UPPER)));
125 		aAlignBox.SetItemImage(ITM_VER_CNTR, Bitmap(SW_RES(bHC ? BMP_VER_CNTR_UPPER_H : BMP_VER_CNTR_UPPER)));
126 		aAlignBox.SetItemImage(ITM_VER_RGHT, Bitmap(SW_RES(bHC ? BMP_VER_RGHT_UPPER_H : BMP_VER_RGHT_UPPER)));
127 	}
128 	return 0;
129 }
130 
131 // --------------------------------------------------------------------------
132 
133 
134 
135 IMPL_LINK( SwEnvPrtPage, ButtonHdl, Button *, pBtn )
136 {
137 	if (pBtn == &aPrtSetup)
138 	{
139 		// Druck-Setup aufrufen
140 		if (pPrt)
141 		{
142 			PrinterSetupDialog* pDlg = new PrinterSetupDialog(this );
143 			pDlg->SetPrinter(pPrt);
144 			pDlg->Execute();
145 			delete pDlg;
146 			GrabFocus();
147 			aPrinterInfo.SetText(pPrt->GetName());
148 		}
149 	}
150 	return 0;
151 }
152 
153 // --------------------------------------------------------------------------
154 
155 
156 
157 IMPL_LINK( SwEnvPrtPage, AlignHdl, ToolBox *, EMPTYARG )
158 {
159 	if (aAlignBox.GetCurItemId())
160 	{
161 		for (sal_uInt16 i = ITM_HOR_LEFT; i <= ITM_VER_RGHT; i++)
162 			aAlignBox.CheckItem(i, sal_False);
163 		aAlignBox.CheckItem(aAlignBox.GetCurItemId(), sal_True);
164 	}
165 	else
166 	{
167 		// GetCurItemId() == 0 ist moeglich!
168 		const SwEnvItem& rItem = (const SwEnvItem&) GetItemSet().Get(FN_ENVELOP);
169 		aAlignBox.CheckItem((sal_uInt16) rItem.eAlign + ITM_HOR_LEFT, sal_True);
170 	}
171 	return 0;
172 }
173 
174 // --------------------------------------------------------------------------
175 
176 
177 
178 SfxTabPage* SwEnvPrtPage::Create(Window* pParent, const SfxItemSet& rSet)
179 {
180 	return new SwEnvPrtPage(pParent, rSet);
181 }
182 
183 // --------------------------------------------------------------------------
184 
185 
186 
187 void SwEnvPrtPage::ActivatePage(const SfxItemSet&)
188 {
189 	if (pPrt)
190 		aPrinterInfo.SetText(pPrt->GetName());
191 }
192 
193 // --------------------------------------------------------------------------
194 
195 
196 
197 int SwEnvPrtPage::DeactivatePage(SfxItemSet* _pSet)
198 {
199     if( _pSet )
200         FillItemSet(*_pSet);
201 	return SfxTabPage::LEAVE_PAGE;
202 }
203 
204 // --------------------------------------------------------------------------
205 
206 
207 
208 void SwEnvPrtPage::FillItem(SwEnvItem& rItem)
209 {
210 	sal_uInt16 nID = 0;
211 	for (sal_uInt16 i = ITM_HOR_LEFT; i <= ITM_VER_RGHT && !nID; i++)
212 		if (aAlignBox.IsItemChecked(i))
213 			nID = i;
214 
215 	rItem.eAlign          = (SwEnvAlign) (nID - ITM_HOR_LEFT);
216 	rItem.bPrintFromAbove = aTopButton.IsChecked();
217     rItem.lShiftRight     = static_cast< sal_Int32 >(GetFldVal(aRightField));
218     rItem.lShiftDown      = static_cast< sal_Int32 >(GetFldVal(aDownField ));
219 }
220 
221 // --------------------------------------------------------------------------
222 
223 
224 
225 sal_Bool SwEnvPrtPage::FillItemSet(SfxItemSet& rSet)
226 {
227 	FillItem(GetParent()->aEnvItem);
228 	rSet.Put(GetParent()->aEnvItem);
229 	return sal_True;
230 }
231 
232 // ----------------------------------------------------------------------------
233 
234 
235 
236 void SwEnvPrtPage::Reset(const SfxItemSet& rSet)
237 {
238 //    SfxItemSet aSet(rSet);
239 //    aSet.Put(GetParent()->aEnvItem);
240 
241 	// Item auslesen
242 	const SwEnvItem& rItem = (const SwEnvItem&) rSet.Get(FN_ENVELOP);
243 	aAlignBox.CheckItem((sal_uInt16) rItem.eAlign + ITM_HOR_LEFT);
244 
245 	if (rItem.bPrintFromAbove)
246 		aTopButton   .Check();
247 	else
248 		aBottomButton.Check();
249 
250 	SetFldVal(aRightField, rItem.lShiftRight);
251 	SetFldVal(aDownField , rItem.lShiftDown );
252 
253 	ActivatePage(rSet);
254 	ClickHdl(&aTopButton);
255 }
256 
257 
258 
259 
260