merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / envelp / labprt.cxx
blob2e4ef15bfd58ab5d5f99242ac16427cd6997815c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: labprt.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
39 #include <svtools/prnsetup.hxx>
40 #include <svtools/cmdoptions.hxx>
41 #include <vcl/print.hxx>
42 #include <wrtsh.hxx>
43 #include <label.hxx>
44 #include <labprt.hxx>
45 #include <labimg.hxx>
46 #ifndef _LABIMP_HXX
47 #include "swuilabimp.hxx"
48 #endif
50 #ifndef _CMDID_H
51 #include <cmdid.h>
52 #endif
53 #ifndef _LABPRT_HRC
54 #include <labprt.hrc>
55 #endif
58 // --------------------------------------------------------------------------
62 SwLabPrtPage::SwLabPrtPage(Window* pParent, const SfxItemSet& rSet) :
64 SfxTabPage(pParent, SW_RES(TP_LAB_PRT), rSet),
66 pPrinter( 0 ),
67 aPageButton (this, SW_RES(BTN_PAGE )),
68 aSingleButton (this, SW_RES(BTN_SINGLE )),
69 aColText (this, SW_RES(TXT_COL )),
70 aColField (this, SW_RES(FLD_COL )),
71 aRowText (this, SW_RES(TXT_ROW )),
72 aRowField (this, SW_RES(FLD_ROW )),
73 aSynchronCB (this, SW_RES(CB_SYNCHRON)),
74 aFLDontKnow (this, SW_RES(FL_DONTKNOW)),
75 aPrinterInfo (this, SW_RES(INF_PRINTER)),
76 aPrtSetup (this, SW_RES(BTN_PRTSETUP)),
77 aFLPrinter (this, SW_RES(FL_PRINTER ))
80 FreeResource();
81 SetExchangeSupport();
83 // Handler installieren
84 Link aLk = LINK(this, SwLabPrtPage, CountHdl);
85 aPageButton .SetClickHdl( aLk );
86 aSingleButton.SetClickHdl( aLk );
88 aPrtSetup.SetClickHdl( aLk );
90 SvtCommandOptions aCmdOpts;
91 if ( aCmdOpts.Lookup(
92 SvtCommandOptions::CMDOPTION_DISABLED,
93 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Print" ) ) ) )
95 aPrinterInfo.Hide();
96 aPrtSetup.Hide();
97 aFLPrinter.Hide();
101 // --------------------------------------------------------------------------
105 SwLabPrtPage::~SwLabPrtPage()
107 if (pPrinter)
108 delete pPrinter;
111 // --------------------------------------------------------------------------
115 IMPL_LINK( SwLabPrtPage, CountHdl, Button *, pButton )
117 if (pButton == &aPrtSetup)
119 // Druck-Setup aufrufen
120 if (!pPrinter)
121 pPrinter = new Printer;
123 PrinterSetupDialog* pDlg = new PrinterSetupDialog(this );
124 pDlg->SetPrinter(pPrinter);
125 pDlg->Execute();
126 delete pDlg;
127 GrabFocus();
128 aPrinterInfo.SetText(pPrinter->GetName());
129 return 0;
131 const BOOL bEnable = pButton == &aSingleButton;
132 aColText .Enable(bEnable);
133 aColField.Enable(bEnable);
134 aRowText .Enable(bEnable);
135 aRowField.Enable(bEnable);
136 aSynchronCB.Enable(!bEnable);
138 if ( bEnable )
139 aColField.GrabFocus();
140 #ifndef PRODUCT
141 else
142 ASSERT( pButton == &aPageButton, "NewButton?" );
143 #endif
144 return 0;
147 // --------------------------------------------------------------------------
151 SfxTabPage* SwLabPrtPage::Create(Window* pParent, const SfxItemSet& rSet)
153 return new SwLabPrtPage( pParent, rSet );
156 // --------------------------------------------------------------------------
160 void SwLabPrtPage::ActivatePage( const SfxItemSet& rSet )
162 Reset(rSet);
165 // --------------------------------------------------------------------------
169 int SwLabPrtPage::DeactivatePage(SfxItemSet* _pSet)
171 if ( _pSet )
172 FillItemSet(*_pSet);
174 return TRUE;
177 // --------------------------------------------------------------------------
181 void SwLabPrtPage::FillItem(SwLabItem& rItem)
183 rItem.bPage = aPageButton.IsChecked();
184 rItem.nCol = (USHORT) aColField.GetValue();
185 rItem.nRow = (USHORT) aRowField.GetValue();
186 rItem.bSynchron = aSynchronCB.IsChecked() && aSynchronCB.IsEnabled();
189 // --------------------------------------------------------------------------
193 BOOL SwLabPrtPage::FillItemSet(SfxItemSet& rSet)
195 SwLabItem aItem;
196 GetParent()->GetLabItem(aItem);
197 FillItem(aItem);
198 rSet.Put(aItem);
200 return TRUE;
203 // --------------------------------------------------------------------------
207 void SwLabPrtPage::Reset(const SfxItemSet& )
209 SwLabItem aItem;
210 GetParent()->GetLabItem(aItem);
212 aColField.SetValue (aItem.nCol);
213 aRowField.SetValue (aItem.nRow);
215 if (aItem.bPage)
217 aPageButton.Check();
218 aPageButton.GetClickHdl().Call(&aPageButton);
220 else
222 aSingleButton.GetClickHdl().Call(&aSingleButton);
223 aSingleButton.Check();
226 if (pPrinter)
228 // Drucker anzeigen
229 aPrinterInfo.SetText(pPrinter->GetName());
231 else
232 aPrinterInfo.SetText(Printer::GetDefaultPrinterName());
234 aColField.SetMax(aItem.nCols);
235 aRowField.SetMax(aItem.nRows);
237 aColField.SetLast(aColField.GetMax());
238 aRowField.SetLast(aRowField.GetMax());
240 aSynchronCB.Check(aItem.bSynchron);