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 <svtools/prnsetup.hxx>
21 #include <unotools/cmdoptions.hxx>
22 #include <vcl/print.hxx>
27 SwLabPrtPage::SwLabPrtPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
28 : SfxTabPage(pPage
, pController
, u
"modules/swriter/ui/labeloptionspage.ui"_ustr
, u
"LabelOptionsPage"_ustr
, &rSet
)
30 , m_xPageButton(m_xBuilder
->weld_radio_button(u
"entirepage"_ustr
))
31 , m_xSingleButton(m_xBuilder
->weld_radio_button(u
"singlelabel"_ustr
))
32 , m_xSingleGrid(m_xBuilder
->weld_widget(u
"singlegrid"_ustr
))
33 , m_xPrinterFrame(m_xBuilder
->weld_widget(u
"printerframe"_ustr
))
34 , m_xColField(m_xBuilder
->weld_spin_button(u
"cols"_ustr
))
35 , m_xRowField(m_xBuilder
->weld_spin_button(u
"rows"_ustr
))
36 , m_xSynchronCB(m_xBuilder
->weld_check_button(u
"synchronize"_ustr
))
37 , m_xPrinterInfo(m_xBuilder
->weld_label(u
"printername"_ustr
))
38 , m_xPrtSetup(m_xBuilder
->weld_button(u
"setup"_ustr
))
43 Link
<weld::Toggleable
&,void> aLk
= LINK(this, SwLabPrtPage
, CountHdl
);
44 m_xPageButton
->connect_toggled(aLk
);
45 m_xSingleButton
->connect_toggled(aLk
);
46 m_xPrtSetup
->connect_clicked(LINK(this, SwLabPrtPage
, PrtSetupHdl
));
48 SvtCommandOptions aCmdOpts
;
49 if (aCmdOpts
.LookupDisabled(u
"Print"_ustr
))
51 m_xPrinterFrame
->hide();
55 SwLabPrtPage::~SwLabPrtPage()
57 m_pPrinter
.disposeAndClear();
60 IMPL_LINK( SwLabPrtPage
, PrtSetupHdl
, weld::Button
&, rButton
, void )
64 m_pPrinter
= VclPtr
<Printer
>::Create();
66 PrinterSetupDialog
aDlg(GetFrameWeld());
67 aDlg
.SetPrinter(m_pPrinter
);
70 m_xPrinterInfo
->set_label(m_pPrinter
->GetName());
73 IMPL_LINK(SwLabPrtPage
, CountHdl
, weld::Toggleable
&, rButton
, void)
75 if (!rButton
.get_active())
78 const bool bEnable
= m_xSingleButton
->get_active();
79 m_xSingleGrid
->set_sensitive(bEnable
);
80 m_xSynchronCB
->set_sensitive(!bEnable
);
83 m_xColField
->grab_focus();
86 std::unique_ptr
<SfxTabPage
> SwLabPrtPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rSet
)
88 return std::make_unique
<SwLabPrtPage
>(pPage
, pController
, *rSet
);
91 void SwLabPrtPage::ActivatePage( const SfxItemSet
& rSet
)
96 DeactivateRC
SwLabPrtPage::DeactivatePage(SfxItemSet
* _pSet
)
101 return DeactivateRC::LeavePage
;
104 void SwLabPrtPage::FillItem(SwLabItem
& rItem
)
106 rItem
.m_bPage
= m_xPageButton
->get_active();
107 rItem
.m_nCol
= m_xColField
->get_value();
108 rItem
.m_nRow
= m_xRowField
->get_value();
109 rItem
.m_bSynchron
= m_xSynchronCB
->get_active() && m_xSynchronCB
->get_sensitive();
112 bool SwLabPrtPage::FillItemSet(SfxItemSet
* rSet
)
115 GetParentSwLabDlg()->GetLabItem(aItem
);
122 void SwLabPrtPage::Reset(const SfxItemSet
* )
125 GetParentSwLabDlg()->GetLabItem(aItem
);
127 m_xColField
->set_value(aItem
.m_nCol
);
128 m_xRowField
->set_value(aItem
.m_nRow
);
132 m_xPageButton
->set_active(true);
133 CountHdl(*m_xPageButton
);
137 CountHdl(*m_xSingleButton
);
138 m_xSingleButton
->set_active(true);
144 m_xPrinterInfo
->set_label(m_pPrinter
->GetName());
147 m_xPrinterInfo
->set_label(Printer::GetDefaultPrinterName());
149 m_xColField
->set_max(aItem
.m_nCols
);
150 m_xRowField
->set_max(aItem
.m_nRows
);
152 m_xSynchronCB
->set_active(aItem
.m_bSynchron
);
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */