LibreOffice Module sw (master)  1
envprt.cxx
Go to the documentation of this file.
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 #include <svtools/unitconv.hxx>
23 
24 #include <swtypes.hxx>
25 #include <cmdid.h>
26 #include "envprt.hxx"
27 #include <envlop.hxx>
28 #include <uitool.hxx>
29 
30 #include <bitmaps.hlst>
31 
33  : SfxTabPage(pParent, "modules/swriter/ui/envprinterpage.ui", "EnvPrinterPage", &rSet)
34  , m_xUpper(m_xBuilder->weld_widget("upper"))
35  , m_xLower(m_xBuilder->weld_widget("lower"))
36  , m_xTopButton(m_xBuilder->weld_radio_button("top"))
37  , m_xBottomButton(m_xBuilder->weld_radio_button("bottom"))
38  , m_xRightField(m_xBuilder->weld_metric_spin_button("right", FieldUnit::CM))
39  , m_xDownField(m_xBuilder->weld_metric_spin_button("down", FieldUnit::CM))
40  , m_xPrinterInfo(m_xBuilder->weld_label("printername"))
41  , m_xPrtSetup(m_xBuilder->weld_button("setup"))
42  , m_aIdsL { m_xBuilder->weld_radio_button("horileftl"),
43  m_xBuilder->weld_radio_button("horicenterl"),
44  m_xBuilder->weld_radio_button("horirightl"),
45  m_xBuilder->weld_radio_button("vertleftl"),
46  m_xBuilder->weld_radio_button("vertcenterl"),
47  m_xBuilder->weld_radio_button("vertrightl") }
48  , m_aIdsU { m_xBuilder->weld_radio_button("horileftu"),
49  m_xBuilder->weld_radio_button("horicenteru"),
50  m_xBuilder->weld_radio_button("horirightu"),
51  m_xBuilder->weld_radio_button("vertleftu"),
52  m_xBuilder->weld_radio_button("vertcenteru"),
53  m_xBuilder->weld_radio_button("vertrightu") }
54 {
55  SetExchangeSupport();
56 
57  // Metrics
58  FieldUnit eUnit = ::GetDfltMetric(false);
59  ::SetFieldUnit(*m_xRightField, eUnit);
60  ::SetFieldUnit(*m_xDownField, eUnit);
61 
62  // Install handlers
63  m_xTopButton->connect_toggled(LINK(this, SwEnvPrtPage, ClickHdl));
64  m_xBottomButton->connect_toggled(LINK(this, SwEnvPrtPage, ClickHdl));
65 
66  m_xPrtSetup->connect_clicked(LINK(this, SwEnvPrtPage, ButtonHdl));
67 
68  for (auto& a : m_aIdsL)
69  a->connect_toggled(LINK(this, SwEnvPrtPage, LowerHdl));
70  for (auto& a : m_aIdsU)
71  a->connect_toggled(LINK(this, SwEnvPrtPage, UpperHdl));
72 
73  // Bitmaps
74  ClickHdl(*m_xBottomButton);
75 }
76 
78 {
79  disposeOnce();
80 }
81 
83 {
84  // Envelope from bottom, otherwise Envelope from top
85  const bool bLowerActive = m_xBottomButton->get_active();
86  m_xUpper->set_visible(!bLowerActive);
87  m_xLower->set_visible(bLowerActive);
88 }
89 
90 IMPL_LINK(SwEnvPrtPage, LowerHdl, weld::ToggleButton&, rButton, void)
91 {
92  for (int i = ENV_HOR_LEFT; i <= ENV_VER_RGHT; ++i)
93  {
94  if (&rButton == m_aIdsL[i].get())
95  {
96  m_aIdsU[i]->set_active(m_aIdsL[i]->get_active());
97  break;
98  }
99  }
100 }
101 
102 IMPL_LINK(SwEnvPrtPage, UpperHdl, weld::ToggleButton&, rButton, void)
103 {
104  for (int i = ENV_HOR_LEFT; i <= ENV_VER_RGHT; ++i)
105  {
106  if (&rButton == m_aIdsU[i].get())
107  {
108  m_aIdsL[i]->set_active(m_aIdsU[i]->get_active());
109  break;
110  }
111  }
112 }
113 
114 IMPL_LINK(SwEnvPrtPage, ButtonHdl, weld::Button&, rBtn, void)
115 {
116  if (&rBtn == m_xPrtSetup.get())
117  {
118  // Call printer setup
119  if (m_xPrt)
120  {
121  PrinterSetupDialog aDlg(GetDialogFrameWeld());
122  aDlg.SetPrinter(m_xPrt);
123  aDlg.run();
124  rBtn.grab_focus();
125  m_xPrinterInfo->set_label(m_xPrt->GetName());
126  }
127  }
128 }
129 
131 {
132  return VclPtr<SwEnvPrtPage>::Create(pParent, *rSet);
133 }
134 
136 {
137  if (m_xPrt)
138  m_xPrinterInfo->set_label(m_xPrt->GetName());
139 }
140 
142 {
143  if( _pSet )
144  FillItemSet(_pSet);
145  return DeactivateRC::LeavePage;
146 }
147 
149 {
150  int nOrient = 0;
151  for (int i = ENV_HOR_LEFT; i <= ENV_VER_RGHT; ++i)
152  {
153  assert(m_aIdsL[i]->get_active() == m_aIdsU[i]->get_active());
154  if (m_aIdsL[i]->get_active())
155  {
156  nOrient = i;
157  break;
158  }
159  }
160 
161  rItem.m_eAlign = static_cast<SwEnvAlign>(nOrient);
162  rItem.m_bPrintFromAbove = m_xTopButton->get_active();
165 }
166 
168 {
169  FillItem(GetParentSwEnvDlg()->aEnvItem);
170  rSet->Put(GetParentSwEnvDlg()->aEnvItem);
171  return true;
172 }
173 
175 {
176  // Read item
177  const SwEnvItem& rItem = static_cast<const SwEnvItem&>( rSet->Get(FN_ENVELOP) );
178  m_aIdsL[rItem.m_eAlign]->set_active(true);
179  m_aIdsU[rItem.m_eAlign]->set_active(true);
180 
181  if (rItem.m_bPrintFromAbove)
182  m_xTopButton->set_active(true);
183  else
184  m_xBottomButton->set_active(true);
185 
188 
189  ActivatePage(*rSet);
190  ClickHdl(*m_xTopButton);
191 }
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: envprt.cxx:135
bool m_bPrintFromAbove
Definition: envimg.hxx:52
FieldUnit
const OUString & GetName() const
SwEnvAlign m_eAlign
Definition: envimg.hxx:51
virtual short run() override
#define FN_ENVELOP
Definition: cmdid.h:721
virtual void Reset(const SfxItemSet *rSet) override
Definition: envprt.cxx:174
std::unique_ptr< weld::Label > m_xPrinterInfo
Definition: envprt.hxx:39
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: envprt.cxx:167
std::unique_ptr< weld::MetricSpinButton > m_xDownField
Definition: envprt.hxx:38
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: envprt.cxx:130
virtual ~SwEnvPrtPage() override
Definition: envprt.cxx:77
IMPL_LINK(SwEnvPrtPage, LowerHdl, weld::ToggleButton &, rButton, void)
Definition: envprt.cxx:90
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:702
std::unique_ptr< weld::Builder > m_xBuilder
int i
void FillItem(SwEnvItem &rItem)
Definition: envprt.cxx:148
sal_Int32 m_nShiftDown
Definition: envimg.hxx:54
SwEnvPrtPage(TabPageParent pParent, const SfxItemSet &rSet)
Definition: envprt.cxx:32
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
std::unique_ptr< weld::MetricSpinButton > m_xRightField
Definition: envprt.hxx:37
std::unique_ptr< weld::RadioButton > m_xTopButton
Definition: envprt.hxx:35
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
SwEnvDlg * GetParentSwEnvDlg()
Definition: envprt.hxx:53
static VclPtr< reference_type > Create(Arg &&...arg)
VclPtr< Printer > m_xPrt
Definition: envprt.hxx:45
std::unique_ptr< weld::RadioButton > m_xBottomButton
Definition: envprt.hxx:36
DeactivateRC
SwEnvAlign
Definition: envimg.hxx:28
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: envprt.cxx:141
IMPL_LINK_NOARG(SwEnvPrtPage, ClickHdl, weld::ToggleButton &, void)
Definition: envprt.cxx:82
int getfieldval(const weld::MetricSpinButton &rField)
Definition: envlop.hxx:30
sal_Int32 m_nShiftRight
Definition: envimg.hxx:53
void SetPrinter(Printer *pNewPrinter)
void setfieldval(weld::MetricSpinButton &rField, int lValue)
Definition: envlop.hxx:35