nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / ui / envelp / labprt.cxx
blobedede97189844c5068284a354bcb24b7825ab6d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include <label.hxx>
25 #include "labprt.hxx"
26 #include <labimg.hxx>
28 SwLabPrtPage::SwLabPrtPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
29 : SfxTabPage(pPage, pController, "modules/swriter/ui/labeloptionspage.ui", "LabelOptionsPage", &rSet)
30 , pPrinter(nullptr)
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"))
41 SetExchangeSupport();
43 // Install handlers
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())
65 // Call printer setup
66 if (!pPrinter)
67 pPrinter = VclPtr<Printer>::Create();
69 PrinterSetupDialog aDlg(GetFrameWeld());
70 aDlg.SetPrinter(pPrinter);
71 aDlg.run();
72 rButton.grab_focus();
73 m_xPrinterInfo->set_label(pPrinter->GetName());
74 return;
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?" );
81 if ( bEnable )
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 )
94 Reset(&rSet);
97 DeactivateRC SwLabPrtPage::DeactivatePage(SfxItemSet* _pSet)
99 if ( _pSet )
100 FillItemSet(_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)
115 SwLabItem aItem;
116 GetParentSwLabDlg()->GetLabItem(aItem);
117 FillItem(aItem);
118 rSet->Put(aItem);
120 return true;
123 void SwLabPrtPage::Reset(const SfxItemSet* )
125 SwLabItem aItem;
126 GetParentSwLabDlg()->GetLabItem(aItem);
128 m_xColField->set_value(aItem.m_nCol);
129 m_xRowField->set_value(aItem.m_nRow);
131 if (aItem.m_bPage)
133 m_xPageButton->set_active(true);
134 CountHdl(*m_xPageButton);
136 else
138 CountHdl(*m_xSingleButton);
139 m_xSingleButton->set_active(true);
142 if (pPrinter)
144 // show printer
145 m_xPrinterInfo->set_label(pPrinter->GetName());
147 else
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: */