Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <vcl/print.hxx>
21 : #include <svtools/prnsetup.hxx>
22 :
23 : #include "swtypes.hxx"
24 : #include "cmdid.h"
25 : #include "envprt.hxx"
26 : #include "envlop.hxx"
27 : #include "uitool.hxx"
28 :
29 : #include "envprt.hrc"
30 :
31 0 : SwEnvPrtPage::SwEnvPrtPage(Window* pParent, const SfxItemSet& rSet) :
32 :
33 : SfxTabPage(pParent, SW_RES(TP_ENV_PRT), rSet),
34 :
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 0 : aPrtSetup (this, SW_RES(BTN_PRTSETUP))
46 :
47 : {
48 0 : FreeResource();
49 0 : SetExchangeSupport();
50 :
51 : // Metrics
52 0 : FieldUnit eUnit = ::GetDfltMetric(sal_False);
53 0 : SetMetric(aRightField, eUnit);
54 0 : SetMetric(aDownField , eUnit);
55 :
56 : // Install handlers
57 0 : aTopButton .SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
58 0 : aBottomButton.SetClickHdl(LINK(this, SwEnvPrtPage, ClickHdl));
59 :
60 0 : aPrtSetup .SetClickHdl(LINK(this, SwEnvPrtPage, ButtonHdl));
61 :
62 : // Bitmaps
63 0 : aBottomButton.GetClickHdl().Call(&aBottomButton);
64 :
65 : // ToolBox
66 0 : Size aSz = aAlignBox.CalcWindowSizePixel();
67 0 : aAlignBox.SetSizePixel(aSz);
68 0 : aAlignBox.SetClickHdl(LINK(this, SwEnvPrtPage, AlignHdl));
69 0 : }
70 :
71 0 : SwEnvPrtPage::~SwEnvPrtPage()
72 : {
73 0 : }
74 :
75 0 : IMPL_LINK_NOARG(SwEnvPrtPage, ClickHdl)
76 : {
77 0 : if (aBottomButton.IsChecked())
78 : {
79 : // Envelope from botton
80 0 : aAlignBox.SetItemImage(ITM_HOR_LEFT, Bitmap(SW_RES(BMP_HOR_LEFT_LOWER)));
81 0 : aAlignBox.SetItemImage(ITM_HOR_CNTR, Bitmap(SW_RES(BMP_HOR_CNTR_LOWER)));
82 0 : aAlignBox.SetItemImage(ITM_HOR_RGHT, Bitmap(SW_RES(BMP_HOR_RGHT_LOWER)));
83 0 : aAlignBox.SetItemImage(ITM_VER_LEFT, Bitmap(SW_RES(BMP_VER_LEFT_LOWER)));
84 0 : aAlignBox.SetItemImage(ITM_VER_CNTR, Bitmap(SW_RES(BMP_VER_CNTR_LOWER)));
85 0 : aAlignBox.SetItemImage(ITM_VER_RGHT, Bitmap(SW_RES(BMP_VER_RGHT_LOWER)));
86 : }
87 : else
88 : {
89 : // Envelope from top
90 0 : aAlignBox.SetItemImage(ITM_HOR_LEFT, Bitmap(SW_RES(BMP_HOR_LEFT_UPPER)));
91 0 : aAlignBox.SetItemImage(ITM_HOR_CNTR, Bitmap(SW_RES(BMP_HOR_CNTR_UPPER)));
92 0 : aAlignBox.SetItemImage(ITM_HOR_RGHT, Bitmap(SW_RES(BMP_HOR_RGHT_UPPER)));
93 0 : aAlignBox.SetItemImage(ITM_VER_LEFT, Bitmap(SW_RES(BMP_VER_LEFT_UPPER)));
94 0 : aAlignBox.SetItemImage(ITM_VER_CNTR, Bitmap(SW_RES(BMP_VER_CNTR_UPPER)));
95 0 : aAlignBox.SetItemImage(ITM_VER_RGHT, Bitmap(SW_RES(BMP_VER_RGHT_UPPER)));
96 : }
97 0 : return 0;
98 : }
99 :
100 0 : IMPL_LINK( SwEnvPrtPage, ButtonHdl, Button *, pBtn )
101 : {
102 0 : if (pBtn == &aPrtSetup)
103 : {
104 : // Call printer setup
105 0 : if (pPrt)
106 : {
107 0 : PrinterSetupDialog* pDlg = new PrinterSetupDialog(this );
108 0 : pDlg->SetPrinter(pPrt);
109 0 : pDlg->Execute();
110 0 : delete pDlg;
111 0 : GrabFocus();
112 0 : aPrinterInfo.SetText(pPrt->GetName());
113 : }
114 : }
115 0 : return 0;
116 : }
117 :
118 0 : IMPL_LINK_NOARG(SwEnvPrtPage, AlignHdl)
119 : {
120 0 : if (aAlignBox.GetCurItemId())
121 : {
122 0 : for (sal_uInt16 i = ITM_HOR_LEFT; i <= ITM_VER_RGHT; i++)
123 0 : aAlignBox.CheckItem(i, sal_False);
124 0 : aAlignBox.CheckItem(aAlignBox.GetCurItemId(), sal_True);
125 : }
126 : else
127 : {
128 : // GetCurItemId() == 0 is possible!
129 0 : const SwEnvItem& rItem = (const SwEnvItem&) GetItemSet().Get(FN_ENVELOP);
130 0 : aAlignBox.CheckItem((sal_uInt16) rItem.eAlign + ITM_HOR_LEFT, sal_True);
131 : }
132 0 : return 0;
133 : }
134 :
135 0 : SfxTabPage* SwEnvPrtPage::Create(Window* pParent, const SfxItemSet& rSet)
136 : {
137 0 : return new SwEnvPrtPage(pParent, rSet);
138 : }
139 :
140 0 : void SwEnvPrtPage::ActivatePage(const SfxItemSet&)
141 : {
142 0 : if (pPrt)
143 0 : aPrinterInfo.SetText(pPrt->GetName());
144 0 : }
145 :
146 0 : int SwEnvPrtPage::DeactivatePage(SfxItemSet* _pSet)
147 : {
148 0 : if( _pSet )
149 0 : FillItemSet(*_pSet);
150 0 : return SfxTabPage::LEAVE_PAGE;
151 : }
152 :
153 0 : void SwEnvPrtPage::FillItem(SwEnvItem& rItem)
154 : {
155 0 : sal_uInt16 nID = 0;
156 0 : for (sal_uInt16 i = ITM_HOR_LEFT; i <= ITM_VER_RGHT && !nID; i++)
157 0 : if (aAlignBox.IsItemChecked(i))
158 0 : nID = i;
159 :
160 0 : rItem.eAlign = (SwEnvAlign) (nID - ITM_HOR_LEFT);
161 0 : rItem.bPrintFromAbove = aTopButton.IsChecked();
162 0 : rItem.lShiftRight = static_cast< sal_Int32 >(GetFldVal(aRightField));
163 0 : rItem.lShiftDown = static_cast< sal_Int32 >(GetFldVal(aDownField ));
164 0 : }
165 :
166 0 : sal_Bool SwEnvPrtPage::FillItemSet(SfxItemSet& rSet)
167 : {
168 0 : FillItem(GetParentSwEnvDlg()->aEnvItem);
169 0 : rSet.Put(GetParentSwEnvDlg()->aEnvItem);
170 0 : return sal_True;
171 : }
172 :
173 0 : void SwEnvPrtPage::Reset(const SfxItemSet& rSet)
174 : {
175 : // Read item
176 0 : const SwEnvItem& rItem = (const SwEnvItem&) rSet.Get(FN_ENVELOP);
177 0 : aAlignBox.CheckItem((sal_uInt16) rItem.eAlign + ITM_HOR_LEFT);
178 :
179 0 : if (rItem.bPrintFromAbove)
180 0 : aTopButton .Check();
181 : else
182 0 : aBottomButton.Check();
183 :
184 0 : SetFldVal(aRightField, rItem.lShiftRight);
185 0 : SetFldVal(aDownField , rItem.lShiftDown );
186 :
187 0 : ActivatePage(rSet);
188 0 : ClickHdl(&aTopButton);
189 0 : }
190 :
191 :
192 :
193 :
194 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|