xref: /aoo42x/main/sw/source/ui/envelp/envprt.cxx (revision efeef26f)
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 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 
31 
32 #include <vcl/print.hxx>
33 #include <svtools/prnsetup.hxx>
34 
35 #include "swtypes.hxx"
36 #include "cmdid.h"
37 #include "envprt.hxx"
38 #include "envlop.hxx"
39 #include "uitool.hxx"
40 
41 #include "envprt.hrc"
42 
43 
44 
45 
46 
SwEnvPrtPage(Window * pParent,const SfxItemSet & rSet)47 SwEnvPrtPage::SwEnvPrtPage(Window* pParent, const SfxItemSet& rSet) :
48 
49 	SfxTabPage(pParent, SW_RES(TP_ENV_PRT), rSet),
50 
51 	aAlignBox    (this, SW_RES(BOX_ALIGN  )),
52 	aTopButton   (this, SW_RES(BTN_TOP    )),
53 	aBottomButton(this, SW_RES(BTN_BOTTOM )),
54 	aRightText   (this, SW_RES(TXT_RIGHT  )),
55 	aRightField  (this, SW_RES(FLD_RIGHT  )),
56 	aDownText    (this, SW_RES(TXT_DOWN   )),
57 	aDownField   (this, SW_RES(FLD_DOWN   )),
58 	aPrinterInfo (this, SW_RES(TXT_PRINTER)),
59     aNoNameFL    (this, SW_RES(FL_NONAME )),
60     aPrinterFL   (this, SW_RES(FL_PRINTER )),
61 	aPrtSetup    (this, SW_RES(BTN_PRTSETUP))
62 
63 {
64 	FreeResource();
65 	SetExchangeSupport();
66 
67 	// Metriken
68 	FieldUnit eUnit = ::GetDfltMetric(sal_False);
69 	SetMetric(aRightField, eUnit);
70 	SetMetric(aDownField , eUnit);
71 
72 	// Handler installieren
73 	aTopButton   .SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
74 	aBottomButton.SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
75 
76 	aPrtSetup    .SetClickHdl(LINK(this, SwEnvPrtPage, ButtonHdl));
77 
78 	// Bitmaps
79 	aBottomButton.GetClickHdl().Call(&aBottomButton);
80 
81 	// ToolBox
82 	Size aSz = aAlignBox.CalcWindowSizePixel();
83 	aAlignBox.SetSizePixel(aSz);
84 //    aAlignBox.SetPosPixel(Point(aNoNameFL.GetPosPixel().X() + (aNoNameFL.GetSizePixel().Width() - aSz.Width()) / 2, aAlignBox.GetPosPixel().Y()));
85 	aAlignBox.SetClickHdl(LINK(this, SwEnvPrtPage, AlignHdl));
86 
87 }
88 
89 // --------------------------------------------------------------------------
90 
91 
92 
~SwEnvPrtPage()93 SwEnvPrtPage::~SwEnvPrtPage()
94 {
95 }
96 
97 // --------------------------------------------------------------------------
98 
99 
100 
IMPL_LINK(SwEnvPrtPage,ClickHdl,Button *,EMPTYARG)101 IMPL_LINK( SwEnvPrtPage, ClickHdl, Button *, EMPTYARG )
102 {
103 	sal_Bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
104 	if (aBottomButton.IsChecked())
105 	{
106 		// Briefumschlaege von unten
107 		aAlignBox.SetItemImage(ITM_HOR_LEFT, Bitmap(SW_RES(bHC ? BMP_HOR_LEFT_LOWER_H : BMP_HOR_LEFT_LOWER)));
108 		aAlignBox.SetItemImage(ITM_HOR_CNTR, Bitmap(SW_RES(bHC ? BMP_HOR_CNTR_LOWER_H : BMP_HOR_CNTR_LOWER)));
109 		aAlignBox.SetItemImage(ITM_HOR_RGHT, Bitmap(SW_RES(bHC ? BMP_HOR_RGHT_LOWER_H : BMP_HOR_RGHT_LOWER)));
110 		aAlignBox.SetItemImage(ITM_VER_LEFT, Bitmap(SW_RES(bHC ? BMP_VER_LEFT_LOWER_H : BMP_VER_LEFT_LOWER)));
111 		aAlignBox.SetItemImage(ITM_VER_CNTR, Bitmap(SW_RES(bHC ? BMP_VER_CNTR_LOWER_H : BMP_VER_CNTR_LOWER)));
112 		aAlignBox.SetItemImage(ITM_VER_RGHT, Bitmap(SW_RES(bHC ? BMP_VER_RGHT_LOWER_H : BMP_VER_RGHT_LOWER)));
113 	}
114 	else
115 	{
116 		// Briefumschlaege von oben
117 		aAlignBox.SetItemImage(ITM_HOR_LEFT, Bitmap(SW_RES(bHC ? BMP_HOR_LEFT_UPPER_H : BMP_HOR_LEFT_UPPER)));
118 		aAlignBox.SetItemImage(ITM_HOR_CNTR, Bitmap(SW_RES(bHC ? BMP_HOR_CNTR_UPPER_H : BMP_HOR_CNTR_UPPER)));
119 		aAlignBox.SetItemImage(ITM_HOR_RGHT, Bitmap(SW_RES(bHC ? BMP_HOR_RGHT_UPPER_H : BMP_HOR_RGHT_UPPER)));
120 		aAlignBox.SetItemImage(ITM_VER_LEFT, Bitmap(SW_RES(bHC ? BMP_VER_LEFT_UPPER_H : BMP_VER_LEFT_UPPER)));
121 		aAlignBox.SetItemImage(ITM_VER_CNTR, Bitmap(SW_RES(bHC ? BMP_VER_CNTR_UPPER_H : BMP_VER_CNTR_UPPER)));
122 		aAlignBox.SetItemImage(ITM_VER_RGHT, Bitmap(SW_RES(bHC ? BMP_VER_RGHT_UPPER_H : BMP_VER_RGHT_UPPER)));
123 	}
124 	return 0;
125 }
126 
127 // --------------------------------------------------------------------------
128 
129 
130 
IMPL_LINK(SwEnvPrtPage,ButtonHdl,Button *,pBtn)131 IMPL_LINK( SwEnvPrtPage, ButtonHdl, Button *, pBtn )
132 {
133 	if (pBtn == &aPrtSetup)
134 	{
135 		// Druck-Setup aufrufen
136 		if (pPrt)
137 		{
138 			PrinterSetupDialog* pDlg = new PrinterSetupDialog(this );
139 			pDlg->SetPrinter(pPrt);
140 			pDlg->Execute();
141 			delete pDlg;
142 			GrabFocus();
143 			aPrinterInfo.SetText(pPrt->GetName());
144 		}
145 	}
146 	return 0;
147 }
148 
149 // --------------------------------------------------------------------------
150 
151 
152 
IMPL_LINK(SwEnvPrtPage,AlignHdl,ToolBox *,EMPTYARG)153 IMPL_LINK( SwEnvPrtPage, AlignHdl, ToolBox *, EMPTYARG )
154 {
155 	if (aAlignBox.GetCurItemId())
156 	{
157 		for (sal_uInt16 i = ITM_HOR_LEFT; i <= ITM_VER_RGHT; i++)
158 			aAlignBox.CheckItem(i, sal_False);
159 		aAlignBox.CheckItem(aAlignBox.GetCurItemId(), sal_True);
160 	}
161 	else
162 	{
163 		// GetCurItemId() == 0 ist moeglich!
164 		const SwEnvItem& rItem = (const SwEnvItem&) GetItemSet().Get(FN_ENVELOP);
165 		aAlignBox.CheckItem((sal_uInt16) rItem.eAlign + ITM_HOR_LEFT, sal_True);
166 	}
167 	return 0;
168 }
169 
170 // --------------------------------------------------------------------------
171 
172 
173 
Create(Window * pParent,const SfxItemSet & rSet)174 SfxTabPage* SwEnvPrtPage::Create(Window* pParent, const SfxItemSet& rSet)
175 {
176 	return new SwEnvPrtPage(pParent, rSet);
177 }
178 
179 // --------------------------------------------------------------------------
180 
181 
182 
ActivatePage(const SfxItemSet &)183 void SwEnvPrtPage::ActivatePage(const SfxItemSet&)
184 {
185 	if (pPrt)
186 		aPrinterInfo.SetText(pPrt->GetName());
187 }
188 
189 // --------------------------------------------------------------------------
190 
191 
192 
DeactivatePage(SfxItemSet * _pSet)193 int SwEnvPrtPage::DeactivatePage(SfxItemSet* _pSet)
194 {
195     if( _pSet )
196         FillItemSet(*_pSet);
197 	return SfxTabPage::LEAVE_PAGE;
198 }
199 
200 // --------------------------------------------------------------------------
201 
202 
203 
FillItem(SwEnvItem & rItem)204 void SwEnvPrtPage::FillItem(SwEnvItem& rItem)
205 {
206 	sal_uInt16 nID = 0;
207 	for (sal_uInt16 i = ITM_HOR_LEFT; i <= ITM_VER_RGHT && !nID; i++)
208 		if (aAlignBox.IsItemChecked(i))
209 			nID = i;
210 
211 	rItem.eAlign          = (SwEnvAlign) (nID - ITM_HOR_LEFT);
212 	rItem.bPrintFromAbove = aTopButton.IsChecked();
213     rItem.lShiftRight     = static_cast< sal_Int32 >(GetFldVal(aRightField));
214     rItem.lShiftDown      = static_cast< sal_Int32 >(GetFldVal(aDownField ));
215 }
216 
217 // --------------------------------------------------------------------------
218 
219 
220 
FillItemSet(SfxItemSet & rSet)221 sal_Bool SwEnvPrtPage::FillItemSet(SfxItemSet& rSet)
222 {
223 	FillItem(GetParent()->aEnvItem);
224 	rSet.Put(GetParent()->aEnvItem);
225 	return sal_True;
226 }
227 
228 // ----------------------------------------------------------------------------
229 
230 
231 
Reset(const SfxItemSet & rSet)232 void SwEnvPrtPage::Reset(const SfxItemSet& rSet)
233 {
234 //    SfxItemSet aSet(rSet);
235 //    aSet.Put(GetParent()->aEnvItem);
236 
237 	// Item auslesen
238 	const SwEnvItem& rItem = (const SwEnvItem&) rSet.Get(FN_ENVELOP);
239 	aAlignBox.CheckItem((sal_uInt16) rItem.eAlign + ITM_HOR_LEFT);
240 
241 	if (rItem.bPrintFromAbove)
242 		aTopButton   .Check();
243 	else
244 		aBottomButton.Check();
245 
246 	SetFldVal(aRightField, rItem.lShiftRight);
247 	SetFldVal(aDownField , rItem.lShiftDown );
248 
249 	ActivatePage(rSet);
250 	ClickHdl(&aTopButton);
251 }
252 
253 
254 
255 
256