xref: /trunk/main/svtools/source/dialogs/prnsetup.cxx (revision 5900e8ec)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 #include <tools/debug.hxx>
27 #ifndef _VCL_PRINT_HXX
28 #include <vcl/print.hxx>
29 #endif
30 
31 #ifndef GCC
32 #endif
33 
34 #include <svtools/svtdata.hxx>
35 #include "prnsetup.hrc"
36 #include <svtools/prnsetup.hxx>
37 
38 // =======================================================================
39 
ImplFillPrnDlgListBox(const Printer * pPrinter,ListBox * pBox,PushButton * pPropBtn)40 void ImplFillPrnDlgListBox( const Printer* pPrinter,
41 							ListBox* pBox, PushButton* pPropBtn )
42 {
43 	ImplFreePrnDlgListBox( pBox );
44 
45     const std::vector<rtl::OUString>& rPrinters = Printer::GetPrinterQueues();
46 	unsigned int nCount = rPrinters.size();
47 	if ( nCount )
48 	{
49 		for( unsigned int i = 0; i < nCount; i++ )
50 			pBox->InsertEntry( rPrinters[i] );
51 		pBox->SelectEntry( pPrinter->GetName() );
52 	}
53 
54 	pBox->Enable( nCount != 0 );
55 	pPropBtn->Show( pPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
56 }
57 
58 // -----------------------------------------------------------------------
59 
ImplFreePrnDlgListBox(ListBox * pBox,sal_Bool bClear)60 void ImplFreePrnDlgListBox( ListBox* pBox, sal_Bool bClear )
61 {
62 	if ( bClear )
63 		pBox->Clear();
64 }
65 
66 // -----------------------------------------------------------------------
67 
ImplPrnDlgListBoxSelect(ListBox * pBox,PushButton * pPropBtn,Printer * pPrinter,Printer * pTempPrinter)68 Printer* ImplPrnDlgListBoxSelect( ListBox* pBox, PushButton* pPropBtn,
69 								  Printer* pPrinter, Printer* pTempPrinter )
70 {
71 	if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
72 	{
73 		const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
74         if( pInfo)
75         {
76             if ( !pTempPrinter )
77             {
78                 if ( (pPrinter->GetName() == pInfo->GetPrinterName()) &&
79                      (pPrinter->GetDriverName() == pInfo->GetDriver()) )
80                     pTempPrinter = new Printer( pPrinter->GetJobSetup() );
81                 else
82                     pTempPrinter = new Printer( *pInfo );
83             }
84             else
85             {
86                 if ( (pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
87                      (pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
88                 {
89                     delete pTempPrinter;
90                     pTempPrinter = new Printer( *pInfo );
91                 }
92             }
93 
94             pPropBtn->Enable( pTempPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
95         }
96         else
97             pPropBtn->Disable();
98 	}
99 	else
100 		pPropBtn->Disable();
101 
102 	return pTempPrinter;
103 }
104 
105 // -----------------------------------------------------------------------
106 
ImplPrnDlgUpdatePrinter(Printer * pPrinter,Printer * pTempPrinter)107 Printer* ImplPrnDlgUpdatePrinter( Printer* pPrinter, Printer* pTempPrinter )
108 {
109 	XubString aPrnName;
110 	if ( pTempPrinter )
111 		aPrnName = pTempPrinter->GetName();
112 	else
113 		aPrnName = pPrinter->GetName();
114 
115 	if ( ! Printer::GetQueueInfo( aPrnName, false ) )
116 	{
117 		if ( pTempPrinter )
118 			delete pTempPrinter;
119 		pTempPrinter = new Printer;
120 	}
121 
122 	return pTempPrinter;
123 }
124 
125 // -----------------------------------------------------------------------
126 
ImplPrnDlgUpdateQueueInfo(ListBox * pBox,QueueInfo & rInfo)127 void ImplPrnDlgUpdateQueueInfo( ListBox* pBox, QueueInfo& rInfo )
128 {
129 	if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
130 	{
131         const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
132         if( pInfo )
133 			rInfo = *pInfo;
134 	}
135 }
136 
137 // -----------------------------------------------------------------------
138 
ImplPrnDlgAddString(XubString & rStr,const XubString & rAddStr)139 static void ImplPrnDlgAddString( XubString& rStr, const XubString& rAddStr )
140 {
141 	if ( rStr.Len() )
142 		rStr.AppendAscii( "; " );
143 	rStr += rAddStr;
144 }
145 
146 // -----------------------------------------------------------------------
147 
ImplPrnDlgAddResString(XubString & rStr,sal_uInt16 nResId)148 static void ImplPrnDlgAddResString( XubString& rStr, sal_uInt16 nResId )
149 {
150 	SvtResId aResId( nResId );
151 	XubString aAddStr( aResId );
152 	ImplPrnDlgAddString( rStr, aAddStr );
153 }
154 
155 // -----------------------------------------------------------------------
156 
ImplPrnDlgGetStatusText(const QueueInfo & rInfo)157 XubString ImplPrnDlgGetStatusText( const QueueInfo& rInfo )
158 {
159 	XubString	aStr;
160 	sal_uLong		nStatus = rInfo.GetStatus();
161 
162 	// Default-Printer
163 	if ( rInfo.GetPrinterName().Len() &&
164 		 (rInfo.GetPrinterName() == Printer::GetDefaultPrinterName()) )
165 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DEFPRINTER );
166 
167 	// Status
168 	if ( nStatus & QUEUE_STATUS_READY )
169 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_READY );
170 	if ( nStatus & QUEUE_STATUS_PAUSED )
171 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAUSED );
172 	if ( nStatus & QUEUE_STATUS_PENDING_DELETION )
173 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PENDING );
174 	if ( nStatus & QUEUE_STATUS_BUSY )
175 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_BUSY );
176 	if ( nStatus & QUEUE_STATUS_INITIALIZING )
177 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_INITIALIZING );
178 	if ( nStatus & QUEUE_STATUS_WAITING )
179 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WAITING );
180 	if ( nStatus & QUEUE_STATUS_WARMING_UP )
181 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WARMING_UP );
182 	if ( nStatus & QUEUE_STATUS_PROCESSING )
183 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PROCESSING );
184 	if ( nStatus & QUEUE_STATUS_PRINTING )
185 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PRINTING );
186 	if ( nStatus & QUEUE_STATUS_OFFLINE )
187 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OFFLINE );
188 	if ( nStatus & QUEUE_STATUS_ERROR )
189 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_ERROR );
190 	if ( nStatus & QUEUE_STATUS_SERVER_UNKNOWN )
191 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_SERVER_UNKNOWN );
192 	if ( nStatus & QUEUE_STATUS_PAPER_JAM )
193 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_JAM );
194 	if ( nStatus & QUEUE_STATUS_PAPER_OUT )
195 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_OUT );
196 	if ( nStatus & QUEUE_STATUS_MANUAL_FEED )
197 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_MANUAL_FEED );
198 	if ( nStatus & QUEUE_STATUS_PAPER_PROBLEM )
199 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_PROBLEM );
200 	if ( nStatus & QUEUE_STATUS_IO_ACTIVE )
201 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_IO_ACTIVE );
202 	if ( nStatus & QUEUE_STATUS_OUTPUT_BIN_FULL )
203 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUTPUT_BIN_FULL );
204 	if ( nStatus & QUEUE_STATUS_TONER_LOW )
205 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_TONER_LOW );
206 	if ( nStatus & QUEUE_STATUS_NO_TONER )
207 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_NO_TONER );
208 	if ( nStatus & QUEUE_STATUS_PAGE_PUNT )
209 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAGE_PUNT );
210 	if ( nStatus & QUEUE_STATUS_USER_INTERVENTION )
211 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_USER_INTERVENTION );
212 	if ( nStatus & QUEUE_STATUS_OUT_OF_MEMORY )
213 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUT_OF_MEMORY );
214 	if ( nStatus & QUEUE_STATUS_DOOR_OPEN )
215 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DOOR_OPEN );
216 	if ( nStatus & QUEUE_STATUS_POWER_SAVE )
217 		ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_POWER_SAVE );
218 
219 	// Anzahl Jobs
220 	sal_uLong nJobs = rInfo.GetJobs();
221 	if ( nJobs && (nJobs != QUEUE_JOBS_DONTKNOW) )
222 	{
223 		XubString aJobStr( SvtResId( STR_SVT_PRNDLG_JOBCOUNT ) );
224 		XubString aJobs( XubString::CreateFromInt32( nJobs ) );
225 		aJobStr.SearchAndReplaceAscii( "%d", aJobs );
226 		ImplPrnDlgAddString( aStr, aJobStr );
227 	}
228 
229 	return aStr;
230 }
231 
232 // =======================================================================
233 
PrinterSetupDialog(Window * pWindow)234 PrinterSetupDialog::PrinterSetupDialog( Window* pWindow ) :
235 	ModalDialog 	( pWindow, SvtResId( DLG_SVT_PRNDLG_PRNSETUPDLG ) ),
236 	maFlPrinter		( this, SvtResId( FL_PRINTER ) ),
237 	maFtName		( this, SvtResId( FT_NAME ) ),
238 	maLbName		( this, SvtResId( LB_NAMES ) ),
239 	maBtnProperties ( this, SvtResId( BTN_PROPERTIES ) ),
240 	maBtnOptions    ( this, SvtResId( BTN_OPTIONS ) ),
241 	maFtStatus		( this, SvtResId( FT_STATUS ) ),
242 	maFiStatus		( this, SvtResId( FI_STATUS ) ),
243 	maFtType		( this, SvtResId( FT_TYPE ) ),
244 	maFiType		( this, SvtResId( FI_TYPE ) ),
245 	maFtLocation	( this, SvtResId( FT_LOCATION ) ),
246 	maFiLocation	( this, SvtResId( FI_LOCATION ) ),
247 	maFtComment 	( this, SvtResId( FT_COMMENT ) ),
248 	maFiComment 	( this, SvtResId( FI_COMMENT ) ),
249     maFlSepButton	( this, SvtResId( FL_SEPBUTTON ) ),
250 	maBtnOK 		( this, SvtResId( BTN_OK ) ),
251 	maBtnCancel 	( this, SvtResId( BTN_CANCEL ) ),
252 	maBtnHelp		( this, SvtResId( BTN_HELP ) )
253 {
254 	FreeResource();
255 
256     // show options button only if link is set
257     maBtnOptions.Hide();
258 
259 	mpPrinter		= NULL;
260 	mpTempPrinter	= NULL;
261 
262 	maStatusTimer.SetTimeout( IMPL_PRINTDLG_STATUS_UPDATE );
263 	maStatusTimer.SetTimeoutHdl( LINK( this, PrinterSetupDialog, ImplStatusHdl ) );
264 	maBtnProperties.SetClickHdl( LINK( this, PrinterSetupDialog, ImplPropertiesHdl ) );
265 	maLbName.SetSelectHdl( LINK( this, PrinterSetupDialog, ImplChangePrinterHdl ) );
266 }
267 
268 // -----------------------------------------------------------------------
269 
~PrinterSetupDialog()270 PrinterSetupDialog::~PrinterSetupDialog()
271 {
272 	ImplFreePrnDlgListBox( &maLbName, sal_False );
273 	delete mpTempPrinter;
274 }
275 
276 // -----------------------------------------------------------------------
277 
SetOptionsHdl(const Link & rLink)278 void PrinterSetupDialog::SetOptionsHdl( const Link& rLink )
279 {
280     maBtnOptions.SetClickHdl( rLink );
281     maBtnOptions.Show( rLink.IsSet() );
282 }
283 
GetOptionsHdl() const284 const Link& PrinterSetupDialog::GetOptionsHdl() const
285 {
286     return maBtnOptions.GetClickHdl();
287 }
288 
ImplSetInfo()289 void PrinterSetupDialog::ImplSetInfo()
290 {
291 	const QueueInfo* pInfo = Printer::GetQueueInfo(maLbName.GetSelectEntry(), true);
292 	if ( pInfo )
293 	{
294 		maFiType.SetText( pInfo->GetDriver() );
295 		maFiLocation.SetText( pInfo->GetLocation() );
296 		maFiComment.SetText( pInfo->GetComment() );
297 		maFiStatus.SetText( ImplPrnDlgGetStatusText( *pInfo ) );
298 	}
299 	else
300 	{
301 		XubString aTempStr;
302 		maFiType.SetText( aTempStr );
303 		maFiLocation.SetText( aTempStr );
304 		maFiComment.SetText( aTempStr );
305 		maFiStatus.SetText( aTempStr );
306 	}
307 }
308 
309 // -----------------------------------------------------------------------
310 
IMPL_LINK(PrinterSetupDialog,ImplStatusHdl,Timer *,EMPTYARG)311 IMPL_LINK( PrinterSetupDialog, ImplStatusHdl, Timer*, EMPTYARG )
312 {
313 	QueueInfo aInfo;
314 	ImplPrnDlgUpdateQueueInfo( &maLbName, aInfo );
315 	maFiStatus.SetText( ImplPrnDlgGetStatusText( aInfo ) );
316 
317 	return 0;
318 }
319 
320 // -----------------------------------------------------------------------
321 
IMPL_LINK(PrinterSetupDialog,ImplPropertiesHdl,void *,EMPTYARG)322 IMPL_LINK( PrinterSetupDialog, ImplPropertiesHdl, void*, EMPTYARG )
323 {
324 	if ( !mpTempPrinter )
325 		mpTempPrinter = new Printer( mpPrinter->GetJobSetup() );
326 	mpTempPrinter->Setup( this );
327 
328 	return 0;
329 }
330 
331 // -----------------------------------------------------------------------
332 
IMPL_LINK(PrinterSetupDialog,ImplChangePrinterHdl,void *,EMPTYARG)333 IMPL_LINK( PrinterSetupDialog, ImplChangePrinterHdl, void*, EMPTYARG )
334 {
335 	mpTempPrinter = ImplPrnDlgListBoxSelect( &maLbName, &maBtnProperties,
336 											 mpPrinter, mpTempPrinter );
337 	ImplSetInfo();
338 	return 0;
339 }
340 
341 // -----------------------------------------------------------------------
342 
Notify(NotifyEvent & rNEvt)343 long PrinterSetupDialog::Notify( NotifyEvent& rNEvt )
344 {
345 	if ( (rNEvt.GetType() == EVENT_GETFOCUS) && IsReallyVisible() )
346 		ImplStatusHdl( &maStatusTimer );
347 
348 	return ModalDialog::Notify( rNEvt );
349 }
350 
351 // -----------------------------------------------------------------------
352 
DataChanged(const DataChangedEvent & rDCEvt)353 void PrinterSetupDialog::DataChanged( const DataChangedEvent& rDCEvt )
354 {
355 	if ( rDCEvt.GetType() == DATACHANGED_PRINTER )
356 	{
357 		mpTempPrinter = ImplPrnDlgUpdatePrinter( mpPrinter, mpTempPrinter );
358 		Printer* pPrn;
359 		if ( mpTempPrinter )
360 			pPrn = mpTempPrinter;
361 		else
362 			pPrn = mpPrinter;
363 		ImplFillPrnDlgListBox( pPrn, &maLbName, &maBtnProperties );
364 		ImplSetInfo();
365 	}
366 
367 	ModalDialog::DataChanged( rDCEvt );
368 }
369 
370 // -----------------------------------------------------------------------
371 
Execute()372 short PrinterSetupDialog::Execute()
373 {
374 	if ( !mpPrinter || mpPrinter->IsPrinting() || mpPrinter->IsJobActive() )
375 	{
376 		DBG_ERRORFILE( "PrinterSetupDialog::Execute() - No Printer or printer is printing" );
377 		return sal_False;
378 	}
379 
380     Printer::updatePrinters();
381 
382 	ImplFillPrnDlgListBox( mpPrinter, &maLbName, &maBtnProperties );
383 	ImplSetInfo();
384 	maStatusTimer.Start();
385 
386 	// Dialog starten
387 	short nRet = ModalDialog::Execute();
388 
389 	// Wenn Dialog mit OK beendet wurde, dann die Daten updaten
390 	if ( nRet == sal_True )
391 	{
392 		if ( mpTempPrinter )
393 			mpPrinter->SetPrinterProps( mpTempPrinter );
394 	}
395 
396 	maStatusTimer.Stop();
397 
398 	return nRet;
399 }
400