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 <osl/diagnose.h>
21 #include <svtools/prnsetup.hxx>
22 #include <unotools/cmdoptions.hxx>
23 #include <vcl/print.hxx>
28 SwLabPrtPage::SwLabPrtPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
29 : SfxTabPage(pPage
, pController
, "modules/swriter/ui/labeloptionspage.ui", "LabelOptionsPage", &rSet
)
31 , m_xPageButton(m_xBuilder
->weld_radio_button("entirepage"))
32 , m_xSingleButton(m_xBuilder
->weld_radio_button("singlelabel"))
33 , m_xSingleGrid(m_xBuilder
->weld_widget("singlegrid"))
34 , m_xPrinterFrame(m_xBuilder
->weld_widget("printerframe"))
35 , m_xColField(m_xBuilder
->weld_spin_button("cols"))
36 , m_xRowField(m_xBuilder
->weld_spin_button("rows"))
37 , m_xSynchronCB(m_xBuilder
->weld_check_button("synchronize"))
38 , m_xPrinterInfo(m_xBuilder
->weld_label("printername"))
39 , m_xPrtSetup(m_xBuilder
->weld_button("setup"))
44 Link
<weld::Button
&,void> aLk
= LINK(this, SwLabPrtPage
, CountHdl
);
45 m_xPageButton
->connect_clicked( aLk
);
46 m_xSingleButton
->connect_clicked( aLk
);
47 m_xPrtSetup
->connect_clicked( aLk
);
49 SvtCommandOptions aCmdOpts
;
50 if (aCmdOpts
.Lookup(SvtCommandOptions::CMDOPTION_DISABLED
, "Print"))
52 m_xPrinterFrame
->hide();
56 SwLabPrtPage::~SwLabPrtPage()
58 pPrinter
.disposeAndClear();
61 IMPL_LINK( SwLabPrtPage
, CountHdl
, weld::Button
&, rButton
, void )
63 if (&rButton
== m_xPrtSetup
.get())
67 pPrinter
= VclPtr
<Printer
>::Create();
69 PrinterSetupDialog
aDlg(GetFrameWeld());
70 aDlg
.SetPrinter(pPrinter
);
73 m_xPrinterInfo
->set_label(pPrinter
->GetName());
76 const bool bEnable
= &rButton
== m_xSingleButton
.get();
77 m_xSingleGrid
->set_sensitive(bEnable
);
78 m_xSynchronCB
->set_sensitive(!bEnable
);
80 OSL_ENSURE(!bEnable
|| &rButton
== m_xPageButton
.get(), "NewButton?" );
83 m_xColField
->grab_focus();
87 std::unique_ptr
<SfxTabPage
> SwLabPrtPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rSet
)
89 return std::make_unique
<SwLabPrtPage
>(pPage
, pController
, *rSet
);
92 void SwLabPrtPage::ActivatePage( const SfxItemSet
& rSet
)
97 DeactivateRC
SwLabPrtPage::DeactivatePage(SfxItemSet
* _pSet
)
102 return DeactivateRC::LeavePage
;
105 void SwLabPrtPage::FillItem(SwLabItem
& rItem
)
107 rItem
.m_bPage
= m_xPageButton
->get_active();
108 rItem
.m_nCol
= m_xColField
->get_value();
109 rItem
.m_nRow
= m_xRowField
->get_value();
110 rItem
.m_bSynchron
= m_xSynchronCB
->get_active() && m_xSynchronCB
->get_sensitive();
113 bool SwLabPrtPage::FillItemSet(SfxItemSet
* rSet
)
116 GetParentSwLabDlg()->GetLabItem(aItem
);
123 void SwLabPrtPage::Reset(const SfxItemSet
* )
126 GetParentSwLabDlg()->GetLabItem(aItem
);
128 m_xColField
->set_value(aItem
.m_nCol
);
129 m_xRowField
->set_value(aItem
.m_nRow
);
133 m_xPageButton
->set_active(true);
134 CountHdl(*m_xPageButton
);
138 CountHdl(*m_xSingleButton
);
139 m_xSingleButton
->set_active(true);
145 m_xPrinterInfo
->set_label(pPrinter
->GetName());
148 m_xPrinterInfo
->set_label(Printer::GetDefaultPrinterName());
150 m_xColField
->set_max(aItem
.m_nCols
);
151 m_xRowField
->set_max(aItem
.m_nRows
);
153 m_xSynchronCB
->set_active(aItem
.m_bSynchron
);
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */