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 <svtools/prnsetup.hxx>
21 #include <unotools/cmdoptions.hxx>
22 #include <vcl/print.hxx>
23 #include <wrtsh.hxx>
24 #include <label.hxx>
25 #include "labprt.hxx"
26 #include <labimg.hxx>
27 
28 #include <cmdid.h>
29 
31  : SfxTabPage(pPage, pController, "modules/swriter/ui/labeloptionspage.ui", "LabelOptionsPage", &rSet)
32  , pPrinter(nullptr)
33  , m_xPageButton(m_xBuilder->weld_radio_button("entirepage"))
34  , m_xSingleButton(m_xBuilder->weld_radio_button("singlelabel"))
35  , m_xSingleGrid(m_xBuilder->weld_widget("singlegrid"))
36  , m_xPrinterFrame(m_xBuilder->weld_widget("printerframe"))
37  , m_xColField(m_xBuilder->weld_spin_button("cols"))
38  , m_xRowField(m_xBuilder->weld_spin_button("rows"))
39  , m_xSynchronCB(m_xBuilder->weld_check_button("synchronize"))
40  , m_xPrinterInfo(m_xBuilder->weld_label("printername"))
41  , m_xPrtSetup(m_xBuilder->weld_button("setup"))
42 {
44 
45  // Install handlers
46  Link<weld::Button&,void> aLk = LINK(this, SwLabPrtPage, CountHdl);
47  m_xPageButton->connect_clicked( aLk );
48  m_xSingleButton->connect_clicked( aLk );
49  m_xPrtSetup->connect_clicked( aLk );
50 
51  SvtCommandOptions aCmdOpts;
52  if (aCmdOpts.Lookup(SvtCommandOptions::CMDOPTION_DISABLED, "Print"))
53  {
54  m_xPrinterFrame->hide();
55  }
56 }
57 
59 {
61 }
62 
63 IMPL_LINK( SwLabPrtPage, CountHdl, weld::Button&, rButton, void )
64 {
65  if (&rButton == m_xPrtSetup.get())
66  {
67  // Call printer setup
68  if (!pPrinter)
69  pPrinter = VclPtr<Printer>::Create();
70 
72  aDlg.SetPrinter(pPrinter);
73  aDlg.run();
74  rButton.grab_focus();
75  m_xPrinterInfo->set_label(pPrinter->GetName());
76  return;
77  }
78  const bool bEnable = &rButton == m_xSingleButton.get();
79  m_xSingleGrid->set_sensitive(bEnable);
80  m_xSynchronCB->set_sensitive(!bEnable);
81 
82  OSL_ENSURE(!bEnable || &rButton == m_xPageButton.get(), "NewButton?" );
83  if ( bEnable )
84  {
85  m_xColField->grab_focus();
86  }
87 }
88 
89 std::unique_ptr<SfxTabPage> SwLabPrtPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
90 {
91  return std::make_unique<SwLabPrtPage>(pPage, pController, *rSet );
92 }
93 
95 {
96  Reset(&rSet);
97 }
98 
100 {
101  if ( _pSet )
102  FillItemSet(_pSet);
103 
104  return DeactivateRC::LeavePage;
105 }
106 
108 {
109  rItem.m_bPage = m_xPageButton->get_active();
110  rItem.m_nCol = m_xColField->get_value();
111  rItem.m_nRow = m_xRowField->get_value();
112  rItem.m_bSynchron = m_xSynchronCB->get_active() && m_xSynchronCB->get_sensitive();
113 }
114 
116 {
117  SwLabItem aItem;
118  GetParentSwLabDlg()->GetLabItem(aItem);
119  FillItem(aItem);
120  rSet->Put(aItem);
121 
122  return true;
123 }
124 
126 {
127  SwLabItem aItem;
128  GetParentSwLabDlg()->GetLabItem(aItem);
129 
130  m_xColField->set_value(aItem.m_nCol);
131  m_xRowField->set_value(aItem.m_nRow);
132 
133  if (aItem.m_bPage)
134  {
135  m_xPageButton->set_active(true);
136  CountHdl(*m_xPageButton);
137  }
138  else
139  {
140  CountHdl(*m_xSingleButton);
141  m_xSingleButton->set_active(true);
142  }
143 
144  if (pPrinter)
145  {
146  // show printer
147  m_xPrinterInfo->set_label(pPrinter->GetName());
148  }
149  else
151 
152  m_xColField->set_max(aItem.m_nCols);
153  m_xRowField->set_max(aItem.m_nRows);
154 
155  m_xSynchronCB->set_active(aItem.m_bSynchron);
156 }
157 
158 /* 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:89
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:30
std::unique_ptr< weld::Label > m_xPrinterInfo
Definition: labprt.hxx:40
IMPL_LINK(SwLabPrtPage, CountHdl, weld::Button &, rButton, void)
Definition: labprt.cxx:63
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:107
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:94
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:125
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:115
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SwLabDlg * GetParentSwLabDlg()
Definition: labprt.hxx:45
virtual ~SwLabPrtPage() override
Definition: labprt.cxx:58
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: labprt.cxx:99
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:170
void SetPrinter(Printer *pNewPrinter)