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(pParent, "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 {
60  disposeOnce();
61 }
62 
64 {
67 }
68 
69 IMPL_LINK( SwLabPrtPage, CountHdl, weld::Button&, rButton, void )
70 {
71  if (&rButton == m_xPrtSetup.get())
72  {
73  // Call printer setup
74  if (!pPrinter)
75  pPrinter = VclPtr<Printer>::Create();
76 
78  aDlg.SetPrinter(pPrinter);
79  aDlg.run();
80  rButton.grab_focus();
81  m_xPrinterInfo->set_label(pPrinter->GetName());
82  return;
83  }
84  const bool bEnable = &rButton == m_xSingleButton.get();
85  m_xSingleGrid->set_sensitive(bEnable);
86  m_xSynchronCB->set_sensitive(!bEnable);
87 
88  OSL_ENSURE(!bEnable || &rButton == m_xPageButton.get(), "NewButton?" );
89  if ( bEnable )
90  {
91  m_xColField->grab_focus();
92  }
93 }
94 
96 {
97  return VclPtr<SwLabPrtPage>::Create(pParent, *rSet );
98 }
99 
101 {
102  Reset(&rSet);
103 }
104 
106 {
107  if ( _pSet )
108  FillItemSet(_pSet);
109 
110  return DeactivateRC::LeavePage;
111 }
112 
114 {
115  rItem.m_bPage = m_xPageButton->get_active();
116  rItem.m_nCol = m_xColField->get_value();
117  rItem.m_nRow = m_xRowField->get_value();
118  rItem.m_bSynchron = m_xSynchronCB->get_active() && m_xSynchronCB->get_sensitive();
119 }
120 
122 {
123  SwLabItem aItem;
124  GetParentSwLabDlg()->GetLabItem(aItem);
125  FillItem(aItem);
126  rSet->Put(aItem);
127 
128  return true;
129 }
130 
132 {
133  SwLabItem aItem;
134  GetParentSwLabDlg()->GetLabItem(aItem);
135 
136  m_xColField->set_value(aItem.m_nCol);
137  m_xRowField->set_value(aItem.m_nRow);
138 
139  if (aItem.m_bPage)
140  {
141  m_xPageButton->set_active(true);
142  CountHdl(*m_xPageButton);
143  }
144  else
145  {
146  CountHdl(*m_xSingleButton);
147  m_xSingleButton->set_active(true);
148  }
149 
150  if (pPrinter)
151  {
152  // show printer
153  m_xPrinterInfo->set_label(pPrinter->GetName());
154  }
155  else
157 
158  m_xColField->set_max(aItem.m_nCols);
159  m_xRowField->set_max(aItem.m_nRows);
160 
161  m_xSynchronCB->set_active(aItem.m_bSynchron);
162 }
163 
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetName() const
virtual short run() override
bool Lookup(CmdOption eOption, const OUString &aCommandURL) const
std::unique_ptr< weld::Label > m_xPrinterInfo
Definition: labprt.hxx:38
IMPL_LINK(SwLabPrtPage, CountHdl, weld::Button &, rButton, void)
Definition: labprt.cxx:69
std::unique_ptr< weld::SpinButton > m_xColField
Definition: labprt.hxx:35
static OUString GetDefaultPrinterName()
std::unique_ptr< weld::Widget > m_xPrinterFrame
Definition: labprt.hxx:34
void FillItem(SwLabItem &rItem)
Definition: labprt.cxx:113
VclPtr< Printer > pPrinter
Definition: labprt.hxx:29
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: labprt.cxx:95
std::unique_ptr< weld::Button > m_xPrtSetup
Definition: labprt.hxx:39
void SetExchangeSupport()
virtual void dispose() override
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: labprt.cxx:100
sal_Int32 m_nRows
Definition: labimg.hxx:57
std::unique_ptr< weld::CheckButton > m_xSynchronCB
Definition: labprt.hxx:37
virtual void Reset(const SfxItemSet *rSet) override
Definition: labprt.cxx:131
std::unique_ptr< weld::RadioButton > m_xSingleButton
Definition: labprt.hxx:32
weld::Window * GetFrameWeld(SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
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:121
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SwLabDlg * GetParentSwLabDlg()
Definition: labprt.hxx:43
virtual ~SwLabPrtPage() override
Definition: labprt.cxx:58
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: labprt.cxx:105
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:36
virtual void dispose() override
Definition: labprt.cxx:63
DeactivateRC
std::unique_ptr< weld::RadioButton > m_xPageButton
Definition: labprt.hxx:31
SwLabPrtPage(TabPageParent pParent, const SfxItemSet &rSet)
Definition: labprt.cxx:30
void GetLabItem(SwLabItem &rItem)
Definition: label1.cxx:169
void SetPrinter(Printer *pNewPrinter)