xref: /trunk/main/sw/source/ui/envelp/labprt.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #ifdef SW_DLLIMPLEMENTATION
32 #undef SW_DLLIMPLEMENTATION
33 #endif
34 
35 
36 #include <svtools/prnsetup.hxx>
37 #include <unotools/cmdoptions.hxx>
38 #include <vcl/print.hxx>
39 #include <wrtsh.hxx>
40 #include <label.hxx>
41 #include <labprt.hxx>
42 #include <labimg.hxx>
43 #ifndef _LABIMP_HXX
44 #include "swuilabimp.hxx"
45 #endif
46 
47 #ifndef _CMDID_H
48 #include <cmdid.h>
49 #endif
50 #ifndef _LABPRT_HRC
51 #include <labprt.hrc>
52 #endif
53 
54 
55 // --------------------------------------------------------------------------
56 
57 
58 
59 SwLabPrtPage::SwLabPrtPage(Window* pParent, const SfxItemSet& rSet) :
60 
61 	SfxTabPage(pParent, SW_RES(TP_LAB_PRT), rSet),
62 
63 	pPrinter( 0 ),
64     aFLDontKnow    (this, SW_RES(FL_DONTKNOW)),
65     aPageButton    (this, SW_RES(BTN_PAGE   )),
66 	aSingleButton  (this, SW_RES(BTN_SINGLE )),
67 	aColText	   (this, SW_RES(TXT_COL    )),
68 	aColField	   (this, SW_RES(FLD_COL    )),
69 	aRowText	   (this, SW_RES(TXT_ROW    )),
70 	aRowField	   (this, SW_RES(FLD_ROW    )),
71 	aSynchronCB	   (this, SW_RES(CB_SYNCHRON)),
72 	aFLPrinter     (this, SW_RES(FL_PRINTER )),
73     aPrinterInfo   (this, SW_RES(INF_PRINTER)),
74 	aPrtSetup	   (this, SW_RES(BTN_PRTSETUP))
75 
76 {
77 	FreeResource();
78 	SetExchangeSupport();
79 
80 	// Handler installieren
81 	Link aLk = LINK(this, SwLabPrtPage, CountHdl);
82 	aPageButton  .SetClickHdl( aLk );
83 	aSingleButton.SetClickHdl( aLk );
84 
85 	aPrtSetup.SetClickHdl( aLk );
86 
87     SvtCommandOptions aCmdOpts;
88     if ( aCmdOpts.Lookup(
89              SvtCommandOptions::CMDOPTION_DISABLED,
90              rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Print"  ) ) ) )
91     {
92         aPrinterInfo.Hide();
93         aPrtSetup.Hide();
94         aFLPrinter.Hide();
95     }
96 }
97 
98 // --------------------------------------------------------------------------
99 
100 
101 
102 SwLabPrtPage::~SwLabPrtPage()
103 {
104 	if (pPrinter)
105 		delete pPrinter;
106 }
107 
108 // --------------------------------------------------------------------------
109 
110 
111 
112 IMPL_LINK( SwLabPrtPage, CountHdl, Button *, pButton )
113 {
114 	if (pButton == &aPrtSetup)
115 	{
116 		// Druck-Setup aufrufen
117 		if (!pPrinter)
118 			pPrinter = new Printer;
119 
120 		PrinterSetupDialog* pDlg = new PrinterSetupDialog(this );
121 		pDlg->SetPrinter(pPrinter);
122 		pDlg->Execute();
123 		delete pDlg;
124 		GrabFocus();
125 		aPrinterInfo.SetText(pPrinter->GetName());
126 		return 0;
127 	}
128 	const sal_Bool bEnable = pButton == &aSingleButton;
129 	aColText .Enable(bEnable);
130 	aColField.Enable(bEnable);
131 	aRowText .Enable(bEnable);
132 	aRowField.Enable(bEnable);
133 	aSynchronCB.Enable(!bEnable);
134 
135 	if ( bEnable )
136 		aColField.GrabFocus();
137 #ifdef DBG_UTIL
138 	else
139 		ASSERT( pButton == &aPageButton, "NewButton?" );
140 #endif
141 	return 0;
142 }
143 
144 // --------------------------------------------------------------------------
145 
146 
147 
148 SfxTabPage* SwLabPrtPage::Create(Window* pParent, const SfxItemSet& rSet)
149 {
150 	return new SwLabPrtPage( pParent, rSet );
151 }
152 
153 // --------------------------------------------------------------------------
154 
155 
156 
157 void SwLabPrtPage::ActivatePage( const SfxItemSet& rSet )
158 {
159 	Reset(rSet);
160 }
161 
162 // --------------------------------------------------------------------------
163 
164 
165 
166 int SwLabPrtPage::DeactivatePage(SfxItemSet* _pSet)
167 {
168     if ( _pSet )
169         FillItemSet(*_pSet);
170 
171 	return sal_True;
172 }
173 
174 // --------------------------------------------------------------------------
175 
176 
177 
178 void SwLabPrtPage::FillItem(SwLabItem& rItem)
179 {
180 	rItem.bPage = aPageButton.IsChecked();
181 	rItem.nCol	= (sal_uInt16) aColField.GetValue();
182 	rItem.nRow	= (sal_uInt16) aRowField.GetValue();
183 	rItem.bSynchron = aSynchronCB.IsChecked() && aSynchronCB.IsEnabled();
184 }
185 
186 // --------------------------------------------------------------------------
187 
188 
189 
190 sal_Bool SwLabPrtPage::FillItemSet(SfxItemSet& rSet)
191 {
192 	SwLabItem aItem;
193 	GetParent()->GetLabItem(aItem);
194 	FillItem(aItem);
195 	rSet.Put(aItem);
196 
197 	return sal_True;
198 }
199 
200 // --------------------------------------------------------------------------
201 
202 
203 
204 void SwLabPrtPage::Reset(const SfxItemSet& )
205 {
206 	SwLabItem aItem;
207 	GetParent()->GetLabItem(aItem);
208 
209 	aColField.SetValue	 (aItem.nCol);
210 	aRowField.SetValue	 (aItem.nRow);
211 
212 	if (aItem.bPage)
213 	{
214 		aPageButton.Check();
215 		aPageButton.GetClickHdl().Call(&aPageButton);
216 	}
217 	else
218 	{
219 		aSingleButton.GetClickHdl().Call(&aSingleButton);
220 		aSingleButton.Check();
221 	}
222 
223 	if (pPrinter)
224 	{
225 		// Drucker anzeigen
226 		aPrinterInfo.SetText(pPrinter->GetName());
227 	}
228 	else
229 		aPrinterInfo.SetText(Printer::GetDefaultPrinterName());
230 
231 	aColField.SetMax(aItem.nCols);
232 	aRowField.SetMax(aItem.nRows);
233 
234 	aColField.SetLast(aColField.GetMax());
235 	aRowField.SetLast(aRowField.GetMax());
236 
237 	aSynchronCB.Check(aItem.bSynchron);
238 }
239 
240 
241 
242 
243