1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
22 #include <svtools/unitconv.hxx>
29 SwEnvPrtPage::SwEnvPrtPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
30 : SfxTabPage(pPage
, pController
, "modules/swriter/ui/envprinterpage.ui", "EnvPrinterPage", &rSet
)
31 , m_xUpper(m_xBuilder
->weld_widget("upper"))
32 , m_xLower(m_xBuilder
->weld_widget("lower"))
33 , m_xTopButton(m_xBuilder
->weld_radio_button("top"))
34 , m_xBottomButton(m_xBuilder
->weld_radio_button("bottom"))
35 , m_xRightField(m_xBuilder
->weld_metric_spin_button("right", FieldUnit::CM
))
36 , m_xDownField(m_xBuilder
->weld_metric_spin_button("down", FieldUnit::CM
))
37 , m_xPrinterInfo(m_xBuilder
->weld_label("printername"))
38 , m_xPrtSetup(m_xBuilder
->weld_button("setup"))
39 , m_aIdsL
{ m_xBuilder
->weld_radio_button("horileftl"),
40 m_xBuilder
->weld_radio_button("horicenterl"),
41 m_xBuilder
->weld_radio_button("horirightl"),
42 m_xBuilder
->weld_radio_button("vertleftl"),
43 m_xBuilder
->weld_radio_button("vertcenterl"),
44 m_xBuilder
->weld_radio_button("vertrightl") }
45 , m_aIdsU
{ m_xBuilder
->weld_radio_button("horileftu"),
46 m_xBuilder
->weld_radio_button("horicenteru"),
47 m_xBuilder
->weld_radio_button("horirightu"),
48 m_xBuilder
->weld_radio_button("vertleftu"),
49 m_xBuilder
->weld_radio_button("vertcenteru"),
50 m_xBuilder
->weld_radio_button("vertrightu") }
55 FieldUnit eUnit
= ::GetDfltMetric(false);
56 ::SetFieldUnit(*m_xRightField
, eUnit
);
57 ::SetFieldUnit(*m_xDownField
, eUnit
);
60 m_xTopButton
->connect_toggled(LINK(this, SwEnvPrtPage
, ClickHdl
));
61 m_xBottomButton
->connect_toggled(LINK(this, SwEnvPrtPage
, ClickHdl
));
63 m_xPrtSetup
->connect_clicked(LINK(this, SwEnvPrtPage
, ButtonHdl
));
65 for (auto& a
: m_aIdsL
)
66 a
->connect_toggled(LINK(this, SwEnvPrtPage
, LowerHdl
));
67 for (auto& a
: m_aIdsU
)
68 a
->connect_toggled(LINK(this, SwEnvPrtPage
, UpperHdl
));
71 ClickHdl(*m_xBottomButton
);
74 SwEnvPrtPage::~SwEnvPrtPage()
79 IMPL_LINK_NOARG(SwEnvPrtPage
, ClickHdl
, weld::ToggleButton
&, void)
81 // Envelope from bottom, otherwise Envelope from top
82 const bool bLowerActive
= m_xBottomButton
->get_active();
83 m_xUpper
->set_visible(!bLowerActive
);
84 m_xLower
->set_visible(bLowerActive
);
87 IMPL_LINK(SwEnvPrtPage
, LowerHdl
, weld::ToggleButton
&, rButton
, void)
89 for (int i
= ENV_HOR_LEFT
; i
<= ENV_VER_RGHT
; ++i
)
91 if (&rButton
== m_aIdsL
[i
].get())
93 m_aIdsU
[i
]->set_active(m_aIdsL
[i
]->get_active());
99 IMPL_LINK(SwEnvPrtPage
, UpperHdl
, weld::ToggleButton
&, rButton
, void)
101 for (int i
= ENV_HOR_LEFT
; i
<= ENV_VER_RGHT
; ++i
)
103 if (&rButton
== m_aIdsU
[i
].get())
105 m_aIdsL
[i
]->set_active(m_aIdsU
[i
]->get_active());
111 IMPL_LINK(SwEnvPrtPage
, ButtonHdl
, weld::Button
&, rBtn
, void)
113 if (&rBtn
== m_xPrtSetup
.get())
115 // Call printer setup
118 PrinterSetupDialog
aDlg(GetFrameWeld());
119 aDlg
.SetPrinter(m_xPrt
);
122 m_xPrinterInfo
->set_label(m_xPrt
->GetName());
127 std::unique_ptr
<SfxTabPage
> SwEnvPrtPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rSet
)
129 return std::make_unique
<SwEnvPrtPage
>(pPage
, pController
, *rSet
);
132 void SwEnvPrtPage::ActivatePage(const SfxItemSet
&)
135 m_xPrinterInfo
->set_label(m_xPrt
->GetName());
138 DeactivateRC
SwEnvPrtPage::DeactivatePage(SfxItemSet
* _pSet
)
142 return DeactivateRC::LeavePage
;
145 void SwEnvPrtPage::FillItem(SwEnvItem
& rItem
)
148 for (int i
= ENV_HOR_LEFT
; i
<= ENV_VER_RGHT
; ++i
)
150 assert(m_aIdsL
[i
]->get_active() == m_aIdsU
[i
]->get_active());
151 if (m_aIdsL
[i
]->get_active())
158 rItem
.m_eAlign
= static_cast<SwEnvAlign
>(nOrient
);
159 rItem
.m_bPrintFromAbove
= m_xTopButton
->get_active();
160 rItem
.m_nShiftRight
= getfieldval(*m_xRightField
);
161 rItem
.m_nShiftDown
= getfieldval(*m_xDownField
);
164 bool SwEnvPrtPage::FillItemSet(SfxItemSet
* rSet
)
166 FillItem(GetParentSwEnvDlg()->aEnvItem
);
167 rSet
->Put(GetParentSwEnvDlg()->aEnvItem
);
171 void SwEnvPrtPage::Reset(const SfxItemSet
* rSet
)
174 const SwEnvItem
& rItem
= static_cast<const SwEnvItem
&>( rSet
->Get(FN_ENVELOP
) );
175 m_aIdsL
[rItem
.m_eAlign
]->set_active(true);
176 m_aIdsU
[rItem
.m_eAlign
]->set_active(true);
178 if (rItem
.m_bPrintFromAbove
)
179 m_xTopButton
->set_active(true);
181 m_xBottomButton
->set_active(true);
183 setfieldval(*m_xRightField
, rItem
.m_nShiftRight
);
184 setfieldval(*m_xDownField
, rItem
.m_nShiftDown
);
187 ClickHdl(*m_xTopButton
);
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */