bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / envelp / envprt.cxx
blob1562fa9341e080db4e953948870ee16f01059c55
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/print.hxx>
21 #include <svtools/prnsetup.hxx>
23 #include "swtypes.hxx"
24 #include "cmdid.h"
25 #include "envprt.hxx"
26 #include "envlop.hxx"
27 #include "uitool.hxx"
29 #include "envprt.hrc"
31 SwEnvPrtPage::SwEnvPrtPage(Window* pParent, const SfxItemSet& rSet) :
33 SfxTabPage(pParent, SW_RES(TP_ENV_PRT), rSet),
35 aAlignBox (this, SW_RES(BOX_ALIGN )),
36 aTopButton (this, SW_RES(BTN_TOP )),
37 aBottomButton(this, SW_RES(BTN_BOTTOM )),
38 aRightText (this, SW_RES(TXT_RIGHT )),
39 aRightField (this, SW_RES(FLD_RIGHT )),
40 aDownText (this, SW_RES(TXT_DOWN )),
41 aDownField (this, SW_RES(FLD_DOWN )),
42 aPrinterInfo (this, SW_RES(TXT_PRINTER)),
43 aNoNameFL (this, SW_RES(FL_NONAME )),
44 aPrinterFL (this, SW_RES(FL_PRINTER )),
45 aPrtSetup (this, SW_RES(BTN_PRTSETUP))
48 FreeResource();
49 SetExchangeSupport();
51 // Metrics
52 FieldUnit eUnit = ::GetDfltMetric(sal_False);
53 SetMetric(aRightField, eUnit);
54 SetMetric(aDownField , eUnit);
56 // Install handlers
57 aTopButton .SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
58 aBottomButton.SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
60 aPrtSetup .SetClickHdl(LINK(this, SwEnvPrtPage, ButtonHdl));
62 // Bitmaps
63 aBottomButton.GetClickHdl().Call(&aBottomButton);
65 // ToolBox
66 Size aSz = aAlignBox.CalcWindowSizePixel();
67 aAlignBox.SetSizePixel(aSz);
68 aAlignBox.SetClickHdl(LINK(this, SwEnvPrtPage, AlignHdl));
71 SwEnvPrtPage::~SwEnvPrtPage()
75 IMPL_LINK_NOARG(SwEnvPrtPage, ClickHdl)
77 if (aBottomButton.IsChecked())
79 // Envelope from botton
80 aAlignBox.SetItemImage(ITM_HOR_LEFT, Bitmap(SW_RES(BMP_HOR_LEFT_LOWER)));
81 aAlignBox.SetItemImage(ITM_HOR_CNTR, Bitmap(SW_RES(BMP_HOR_CNTR_LOWER)));
82 aAlignBox.SetItemImage(ITM_HOR_RGHT, Bitmap(SW_RES(BMP_HOR_RGHT_LOWER)));
83 aAlignBox.SetItemImage(ITM_VER_LEFT, Bitmap(SW_RES(BMP_VER_LEFT_LOWER)));
84 aAlignBox.SetItemImage(ITM_VER_CNTR, Bitmap(SW_RES(BMP_VER_CNTR_LOWER)));
85 aAlignBox.SetItemImage(ITM_VER_RGHT, Bitmap(SW_RES(BMP_VER_RGHT_LOWER)));
87 else
89 // Envelope from top
90 aAlignBox.SetItemImage(ITM_HOR_LEFT, Bitmap(SW_RES(BMP_HOR_LEFT_UPPER)));
91 aAlignBox.SetItemImage(ITM_HOR_CNTR, Bitmap(SW_RES(BMP_HOR_CNTR_UPPER)));
92 aAlignBox.SetItemImage(ITM_HOR_RGHT, Bitmap(SW_RES(BMP_HOR_RGHT_UPPER)));
93 aAlignBox.SetItemImage(ITM_VER_LEFT, Bitmap(SW_RES(BMP_VER_LEFT_UPPER)));
94 aAlignBox.SetItemImage(ITM_VER_CNTR, Bitmap(SW_RES(BMP_VER_CNTR_UPPER)));
95 aAlignBox.SetItemImage(ITM_VER_RGHT, Bitmap(SW_RES(BMP_VER_RGHT_UPPER)));
97 return 0;
100 IMPL_LINK( SwEnvPrtPage, ButtonHdl, Button *, pBtn )
102 if (pBtn == &aPrtSetup)
104 // Call printer setup
105 if (pPrt)
107 PrinterSetupDialog* pDlg = new PrinterSetupDialog(this );
108 pDlg->SetPrinter(pPrt);
109 pDlg->Execute();
110 delete pDlg;
111 GrabFocus();
112 aPrinterInfo.SetText(pPrt->GetName());
115 return 0;
118 IMPL_LINK_NOARG(SwEnvPrtPage, AlignHdl)
120 if (aAlignBox.GetCurItemId())
122 for (sal_uInt16 i = ITM_HOR_LEFT; i <= ITM_VER_RGHT; i++)
123 aAlignBox.CheckItem(i, sal_False);
124 aAlignBox.CheckItem(aAlignBox.GetCurItemId(), sal_True);
126 else
128 // GetCurItemId() == 0 is possible!
129 const SwEnvItem& rItem = (const SwEnvItem&) GetItemSet().Get(FN_ENVELOP);
130 aAlignBox.CheckItem((sal_uInt16) rItem.eAlign + ITM_HOR_LEFT, sal_True);
132 return 0;
135 SfxTabPage* SwEnvPrtPage::Create(Window* pParent, const SfxItemSet& rSet)
137 return new SwEnvPrtPage(pParent, rSet);
140 void SwEnvPrtPage::ActivatePage(const SfxItemSet&)
142 if (pPrt)
143 aPrinterInfo.SetText(pPrt->GetName());
146 int SwEnvPrtPage::DeactivatePage(SfxItemSet* _pSet)
148 if( _pSet )
149 FillItemSet(*_pSet);
150 return SfxTabPage::LEAVE_PAGE;
153 void SwEnvPrtPage::FillItem(SwEnvItem& rItem)
155 sal_uInt16 nID = 0;
156 for (sal_uInt16 i = ITM_HOR_LEFT; i <= ITM_VER_RGHT && !nID; i++)
157 if (aAlignBox.IsItemChecked(i))
158 nID = i;
160 rItem.eAlign = (SwEnvAlign) (nID - ITM_HOR_LEFT);
161 rItem.bPrintFromAbove = aTopButton.IsChecked();
162 rItem.lShiftRight = static_cast< sal_Int32 >(GetFldVal(aRightField));
163 rItem.lShiftDown = static_cast< sal_Int32 >(GetFldVal(aDownField ));
166 sal_Bool SwEnvPrtPage::FillItemSet(SfxItemSet& rSet)
168 FillItem(GetParentSwEnvDlg()->aEnvItem);
169 rSet.Put(GetParentSwEnvDlg()->aEnvItem);
170 return sal_True;
173 void SwEnvPrtPage::Reset(const SfxItemSet& rSet)
175 // Read item
176 const SwEnvItem& rItem = (const SwEnvItem&) rSet.Get(FN_ENVELOP);
177 aAlignBox.CheckItem((sal_uInt16) rItem.eAlign + ITM_HOR_LEFT);
179 if (rItem.bPrintFromAbove)
180 aTopButton .Check();
181 else
182 aBottomButton.Check();
184 SetFldVal(aRightField, rItem.lShiftRight);
185 SetFldVal(aDownField , rItem.lShiftDown );
187 ActivatePage(rSet);
188 ClickHdl(&aTopButton);
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */