bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / envelp / labprt.cxx
blobde6a37ed61d3a0bb569a67fcb9ffe59c94df13ca
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 <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 #include "swuilabimp.hxx"
29 #include <cmdid.h>
30 #include <labprt.hrc>
32 SwLabPrtPage::SwLabPrtPage(Window* pParent, const SfxItemSet& rSet) :
34 SfxTabPage(pParent, SW_RES(TP_LAB_PRT), rSet),
36 pPrinter( 0 ),
37 aFLDontKnow (this, SW_RES(FL_DONTKNOW)),
38 aPageButton (this, SW_RES(BTN_PAGE )),
39 aSingleButton (this, SW_RES(BTN_SINGLE )),
40 aColText (this, SW_RES(TXT_COL )),
41 aColField (this, SW_RES(FLD_COL )),
42 aRowText (this, SW_RES(TXT_ROW )),
43 aRowField (this, SW_RES(FLD_ROW )),
44 aSynchronCB (this, SW_RES(CB_SYNCHRON)),
45 aFLPrinter (this, SW_RES(FL_PRINTER )),
46 aPrinterInfo (this, SW_RES(INF_PRINTER)),
47 aPrtSetup (this, SW_RES(BTN_PRTSETUP))
50 FreeResource();
51 SetExchangeSupport();
53 // Install handlers
54 Link aLk = LINK(this, SwLabPrtPage, CountHdl);
55 aPageButton .SetClickHdl( aLk );
56 aSingleButton.SetClickHdl( aLk );
58 aPrtSetup.SetClickHdl( aLk );
60 SvtCommandOptions aCmdOpts;
61 if ( aCmdOpts.Lookup(
62 SvtCommandOptions::CMDOPTION_DISABLED,
63 OUString( "Print" ) ) )
65 aPrinterInfo.Hide();
66 aPrtSetup.Hide();
67 aFLPrinter.Hide();
71 SwLabPrtPage::~SwLabPrtPage()
73 delete pPrinter;
76 IMPL_LINK( SwLabPrtPage, CountHdl, Button *, pButton )
78 if (pButton == &aPrtSetup)
80 // Call printer setup
81 if (!pPrinter)
82 pPrinter = new Printer;
84 PrinterSetupDialog* pDlg = new PrinterSetupDialog(this );
85 pDlg->SetPrinter(pPrinter);
86 pDlg->Execute();
87 delete pDlg;
88 GrabFocus();
89 aPrinterInfo.SetText(pPrinter->GetName());
90 return 0;
92 const sal_Bool bEnable = pButton == &aSingleButton;
93 aColText .Enable(bEnable);
94 aColField.Enable(bEnable);
95 aRowText .Enable(bEnable);
96 aRowField.Enable(bEnable);
97 aSynchronCB.Enable(!bEnable);
99 OSL_ENSURE(!bEnable || pButton == &aPageButton, "NewButton?" );
100 if ( bEnable )
102 aColField.GrabFocus();
104 return 0;
107 SfxTabPage* SwLabPrtPage::Create(Window* pParent, const SfxItemSet& rSet)
109 return new SwLabPrtPage( pParent, rSet );
112 void SwLabPrtPage::ActivatePage( const SfxItemSet& rSet )
114 Reset(rSet);
117 int SwLabPrtPage::DeactivatePage(SfxItemSet* _pSet)
119 if ( _pSet )
120 FillItemSet(*_pSet);
122 return sal_True;
125 void SwLabPrtPage::FillItem(SwLabItem& rItem)
127 rItem.bPage = aPageButton.IsChecked();
128 rItem.nCol = (sal_uInt16) aColField.GetValue();
129 rItem.nRow = (sal_uInt16) aRowField.GetValue();
130 rItem.bSynchron = aSynchronCB.IsChecked() && aSynchronCB.IsEnabled();
133 sal_Bool SwLabPrtPage::FillItemSet(SfxItemSet& rSet)
135 SwLabItem aItem;
136 GetParentSwLabDlg()->GetLabItem(aItem);
137 FillItem(aItem);
138 rSet.Put(aItem);
140 return sal_True;
143 void SwLabPrtPage::Reset(const SfxItemSet& )
145 SwLabItem aItem;
146 GetParentSwLabDlg()->GetLabItem(aItem);
148 aColField.SetValue (aItem.nCol);
149 aRowField.SetValue (aItem.nRow);
151 if (aItem.bPage)
153 aPageButton.Check();
154 aPageButton.GetClickHdl().Call(&aPageButton);
156 else
158 aSingleButton.GetClickHdl().Call(&aSingleButton);
159 aSingleButton.Check();
162 if (pPrinter)
164 // show printer
165 aPrinterInfo.SetText(pPrinter->GetName());
167 else
168 aPrinterInfo.SetText(Printer::GetDefaultPrinterName());
170 aColField.SetMax(aItem.nCols);
171 aRowField.SetMax(aItem.nRows);
173 aColField.SetLast(aColField.GetMax());
174 aRowField.SetLast(aRowField.GetMax());
176 aSynchronCB.Check(aItem.bSynchron);
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */