LibreOffice Module sw (master)  1
labprt.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 <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>
27 
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"))
40 {
42 
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 );
48 
49  SvtCommandOptions aCmdOpts;
50  if (aCmdOpts.Lookup(SvtCommandOptions::CMDOPTION_DISABLED, "Print"))
51  {
52  m_xPrinterFrame->hide();
53  }
54 }
55 
57 {
59 }
60 
61 IMPL_LINK( SwLabPrtPage, CountHdl, weld::Button&, rButton, void )
62 {
63  if (&rButton == m_xPrtSetup.get())
64  {
65  // Call printer setup
66  if (!pPrinter)
67  pPrinter = VclPtr<Printer>::Create();
68 
70  aDlg.SetPrinter(pPrinter);
71  aDlg.run();
72  rButton.grab_focus();
73  m_xPrinterInfo->set_label(pPrinter->GetName());
74  return;
75  }
76  const bool bEnable = &rButton == m_xSingleButton.get();
77  m_xSingleGrid->set_sensitive(bEnable);
78  m_xSynchronCB->set_sensitive(!bEnable);
79 
80  OSL_ENSURE(!bEnable || &rButton == m_xPageButton.get(), "NewButton?" );
81  if ( bEnable )
82  {
83  m_xColField->grab_focus();
84  }
85 }
86 
87 std::unique_ptr<SfxTabPage> SwLabPrtPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
88 {
89  return std::make_unique<SwLabPrtPage>(pPage, pController, *rSet );
90 }
91 
93 {
94  Reset(&rSet);
95 }
96 
98 {
99  if ( _pSet )
100  FillItemSet(_pSet);
101 
102  return DeactivateRC::LeavePage;
103 }
104 
106 {
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();
111 }
112 
114 {
115  SwLabItem aItem;
116  GetParentSwLabDlg()->GetLabItem(aItem);
117  FillItem(aItem);
118  rSet->Put(aItem);
119 
120  return true;
121 }
122 
124 {
125  SwLabItem aItem;
126  GetParentSwLabDlg()->GetLabItem(aItem);
127 
128  m_xColField->set_value(aItem.m_nCol);
129  m_xRowField->set_value(aItem.m_nRow);
130 
131  if (aItem.m_bPage)
132  {
133  m_xPageButton->set_active(true);
134  CountHdl(*m_xPageButton);
135  }
136  else
137  {
138  CountHdl(*m_xSingleButton);
139  m_xSingleButton->set_active(true);
140  }
141 
142  if (pPrinter)
143  {
144  // show printer
145  m_xPrinterInfo->set_label(pPrinter->GetName());
146  }
147  else
149 
150  m_xColField->set_max(aItem.m_nCols);
151  m_xRowField->set_max(aItem.m_nRows);
152 
153  m_xSynchronCB->set_active(aItem.m_bSynchron);
154 }
155 
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: labprt.cxx:87
const OUString & GetName() const
virtual short run() override
bool Lookup(CmdOption eOption, const OUString &aCommandURL) const
SwLabPrtPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: labprt.cxx:28
std::unique_ptr< weld::Label > m_xPrinterInfo
Definition: labprt.hxx:40
IMPL_LINK(SwLabPrtPage, CountHdl, weld::Button &, rButton, void)
Definition: labprt.cxx:61
std::unique_ptr< weld::SpinButton > m_xColField
Definition: labprt.hxx:37
static OUString GetDefaultPrinterName()
std::unique_ptr< weld::Widget > m_xPrinterFrame
Definition: labprt.hxx:36
void FillItem(SwLabItem &rItem)
Definition: labprt.cxx:105
VclPtr< Printer > pPrinter
Definition: labprt.hxx:31
std::unique_ptr< weld::Button > m_xPrtSetup
Definition: labprt.hxx:41
void SetExchangeSupport()
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: labprt.cxx:92
sal_Int32 m_nRows
Definition: labimg.hxx:57
std::unique_ptr< weld::CheckButton > m_xSynchronCB
Definition: labprt.hxx:39
virtual void Reset(const SfxItemSet *rSet) override
Definition: labprt.cxx:123
std::unique_ptr< weld::RadioButton > m_xSingleButton
Definition: labprt.hxx:34
sal_Int32 m_nCols
Definition: labimg.hxx:56
bool m_bPage
Definition: labimg.hxx:64
sal_Int32 m_nCol
Definition: labimg.hxx:58
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: labprt.cxx:113
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SwLabDlg * GetParentSwLabDlg()
Definition: labprt.hxx:45
virtual ~SwLabPrtPage() override
Definition: labprt.cxx:56
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: labprt.cxx:97
sal_Int32 m_nRow
Definition: labimg.hxx:59
bool m_bSynchron
Definition: labimg.hxx:65
static VclPtr< reference_type > Create(Arg &&...arg)
std::unique_ptr< weld::SpinButton > m_xRowField
Definition: labprt.hxx:38
DeactivateRC
std::unique_ptr< weld::RadioButton > m_xPageButton
Definition: labprt.hxx:33
void GetLabItem(SwLabItem &rItem)
Definition: label1.cxx:166
void SetPrinter(Printer *pNewPrinter)