Update ooo320-m1
[ooovba.git] / svtools / source / dialogs / prnsetup.cxx
blob48acf2ed4883fd5c896acd2c2a685556e3af57b5
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: prnsetup.cxx,v $
10 * $Revision: 1.10 $
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_svtools.hxx"
33 #include <tools/debug.hxx>
34 #ifndef _VCL_PRINT_HXX
35 #include <vcl/print.hxx>
36 #endif
38 #ifndef GCC
39 #endif
41 #include <svtools/svtdata.hxx>
42 #include "prnsetup.hrc"
43 #include <svtools/prnsetup.hxx>
45 // =======================================================================
47 void ImplFillPrnDlgListBox( const Printer* pPrinter,
48 ListBox* pBox, PushButton* pPropBtn )
50 ImplFreePrnDlgListBox( pBox );
52 const std::vector<rtl::OUString>& rPrinters = Printer::GetPrinterQueues();
53 unsigned int nCount = rPrinters.size();
54 if ( nCount )
56 for( unsigned int i = 0; i < nCount; i++ )
57 pBox->InsertEntry( rPrinters[i] );
58 pBox->SelectEntry( pPrinter->GetName() );
61 pBox->Enable( nCount != 0 );
62 pPropBtn->Enable( pPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
65 // -----------------------------------------------------------------------
67 void ImplFreePrnDlgListBox( ListBox* pBox, BOOL bClear )
69 if ( bClear )
70 pBox->Clear();
73 // -----------------------------------------------------------------------
75 Printer* ImplPrnDlgListBoxSelect( ListBox* pBox, PushButton* pPropBtn,
76 Printer* pPrinter, Printer* pTempPrinter )
78 if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
80 const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
81 if( pInfo)
83 if ( !pTempPrinter )
85 if ( (pPrinter->GetName() == pInfo->GetPrinterName()) &&
86 (pPrinter->GetDriverName() == pInfo->GetDriver()) )
87 pTempPrinter = new Printer( pPrinter->GetJobSetup() );
88 else
89 pTempPrinter = new Printer( *pInfo );
91 else
93 if ( (pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
94 (pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
96 delete pTempPrinter;
97 pTempPrinter = new Printer( *pInfo );
101 pPropBtn->Enable( pTempPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
103 else
104 pPropBtn->Disable();
106 else
107 pPropBtn->Disable();
109 return pTempPrinter;
112 // -----------------------------------------------------------------------
114 Printer* ImplPrnDlgUpdatePrinter( Printer* pPrinter, Printer* pTempPrinter )
116 XubString aPrnName;
117 if ( pTempPrinter )
118 aPrnName = pTempPrinter->GetName();
119 else
120 aPrnName = pPrinter->GetName();
122 if ( ! Printer::GetQueueInfo( aPrnName, false ) )
124 if ( pTempPrinter )
125 delete pTempPrinter;
126 pTempPrinter = new Printer;
129 return pTempPrinter;
132 // -----------------------------------------------------------------------
134 void ImplPrnDlgUpdateQueueInfo( ListBox* pBox, QueueInfo& rInfo )
136 if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
138 const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
139 if( pInfo )
140 rInfo = *pInfo;
144 // -----------------------------------------------------------------------
146 static void ImplPrnDlgAddString( XubString& rStr, const XubString& rAddStr )
148 if ( rStr.Len() )
149 rStr.AppendAscii( "; " );
150 rStr += rAddStr;
153 // -----------------------------------------------------------------------
155 static void ImplPrnDlgAddResString( XubString& rStr, USHORT nResId )
157 SvtResId aResId( nResId );
158 XubString aAddStr( aResId );
159 ImplPrnDlgAddString( rStr, aAddStr );
162 // -----------------------------------------------------------------------
164 XubString ImplPrnDlgGetStatusText( const QueueInfo& rInfo )
166 XubString aStr;
167 ULONG nStatus = rInfo.GetStatus();
169 // Default-Printer
170 if ( rInfo.GetPrinterName().Len() &&
171 (rInfo.GetPrinterName() == Printer::GetDefaultPrinterName()) )
172 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DEFPRINTER );
174 // Status
175 if ( nStatus & QUEUE_STATUS_READY )
176 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_READY );
177 if ( nStatus & QUEUE_STATUS_PAUSED )
178 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAUSED );
179 if ( nStatus & QUEUE_STATUS_PENDING_DELETION )
180 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PENDING );
181 if ( nStatus & QUEUE_STATUS_BUSY )
182 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_BUSY );
183 if ( nStatus & QUEUE_STATUS_INITIALIZING )
184 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_INITIALIZING );
185 if ( nStatus & QUEUE_STATUS_WAITING )
186 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WAITING );
187 if ( nStatus & QUEUE_STATUS_WARMING_UP )
188 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WARMING_UP );
189 if ( nStatus & QUEUE_STATUS_PROCESSING )
190 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PROCESSING );
191 if ( nStatus & QUEUE_STATUS_PRINTING )
192 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PRINTING );
193 if ( nStatus & QUEUE_STATUS_OFFLINE )
194 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OFFLINE );
195 if ( nStatus & QUEUE_STATUS_ERROR )
196 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_ERROR );
197 if ( nStatus & QUEUE_STATUS_SERVER_UNKNOWN )
198 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_SERVER_UNKNOWN );
199 if ( nStatus & QUEUE_STATUS_PAPER_JAM )
200 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_JAM );
201 if ( nStatus & QUEUE_STATUS_PAPER_OUT )
202 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_OUT );
203 if ( nStatus & QUEUE_STATUS_MANUAL_FEED )
204 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_MANUAL_FEED );
205 if ( nStatus & QUEUE_STATUS_PAPER_PROBLEM )
206 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_PROBLEM );
207 if ( nStatus & QUEUE_STATUS_IO_ACTIVE )
208 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_IO_ACTIVE );
209 if ( nStatus & QUEUE_STATUS_OUTPUT_BIN_FULL )
210 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUTPUT_BIN_FULL );
211 if ( nStatus & QUEUE_STATUS_TONER_LOW )
212 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_TONER_LOW );
213 if ( nStatus & QUEUE_STATUS_NO_TONER )
214 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_NO_TONER );
215 if ( nStatus & QUEUE_STATUS_PAGE_PUNT )
216 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAGE_PUNT );
217 if ( nStatus & QUEUE_STATUS_USER_INTERVENTION )
218 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_USER_INTERVENTION );
219 if ( nStatus & QUEUE_STATUS_OUT_OF_MEMORY )
220 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUT_OF_MEMORY );
221 if ( nStatus & QUEUE_STATUS_DOOR_OPEN )
222 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DOOR_OPEN );
223 if ( nStatus & QUEUE_STATUS_POWER_SAVE )
224 ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_POWER_SAVE );
226 // Anzahl Jobs
227 ULONG nJobs = rInfo.GetJobs();
228 if ( nJobs && (nJobs != QUEUE_JOBS_DONTKNOW) )
230 XubString aJobStr( SvtResId( STR_SVT_PRNDLG_JOBCOUNT ) );
231 XubString aJobs( XubString::CreateFromInt32( nJobs ) );
232 aJobStr.SearchAndReplaceAscii( "%d", aJobs );
233 ImplPrnDlgAddString( aStr, aJobStr );
236 return aStr;
239 // =======================================================================
241 PrinterSetupDialog::PrinterSetupDialog( Window* pWindow ) :
242 ModalDialog ( pWindow, SvtResId( DLG_SVT_PRNDLG_PRNSETUPDLG ) ),
243 maFlPrinter ( this, SvtResId( FL_PRINTER ) ),
244 maFtName ( this, SvtResId( FT_NAME ) ),
245 maLbName ( this, SvtResId( LB_NAMES ) ),
246 maBtnProperties ( this, SvtResId( BTN_PROPERTIES ) ),
247 maBtnOptions ( this, SvtResId( BTN_OPTIONS ) ),
248 maFtStatus ( this, SvtResId( FT_STATUS ) ),
249 maFiStatus ( this, SvtResId( FI_STATUS ) ),
250 maFtType ( this, SvtResId( FT_TYPE ) ),
251 maFiType ( this, SvtResId( FI_TYPE ) ),
252 maFtLocation ( this, SvtResId( FT_LOCATION ) ),
253 maFiLocation ( this, SvtResId( FI_LOCATION ) ),
254 maFtComment ( this, SvtResId( FT_COMMENT ) ),
255 maFiComment ( this, SvtResId( FI_COMMENT ) ),
256 maFlSepButton ( this, SvtResId( FL_SEPBUTTON ) ),
257 maBtnOK ( this, SvtResId( BTN_OK ) ),
258 maBtnCancel ( this, SvtResId( BTN_CANCEL ) ),
259 maBtnHelp ( this, SvtResId( BTN_HELP ) )
261 FreeResource();
263 // show options button only if link is set
264 maBtnOptions.Hide();
266 mpPrinter = NULL;
267 mpTempPrinter = NULL;
269 maStatusTimer.SetTimeout( IMPL_PRINTDLG_STATUS_UPDATE );
270 maStatusTimer.SetTimeoutHdl( LINK( this, PrinterSetupDialog, ImplStatusHdl ) );
271 maBtnProperties.SetClickHdl( LINK( this, PrinterSetupDialog, ImplPropertiesHdl ) );
272 maLbName.SetSelectHdl( LINK( this, PrinterSetupDialog, ImplChangePrinterHdl ) );
275 // -----------------------------------------------------------------------
277 PrinterSetupDialog::~PrinterSetupDialog()
279 ImplFreePrnDlgListBox( &maLbName, FALSE );
280 delete mpTempPrinter;
283 // -----------------------------------------------------------------------
285 void PrinterSetupDialog::SetOptionsHdl( const Link& rLink )
287 maBtnOptions.SetClickHdl( rLink );
288 maBtnOptions.Show( rLink.IsSet() );
291 const Link& PrinterSetupDialog::GetOptionsHdl() const
293 return maBtnOptions.GetClickHdl();
296 void PrinterSetupDialog::ImplSetInfo()
298 const QueueInfo* pInfo = Printer::GetQueueInfo(maLbName.GetSelectEntry(), true);
299 if ( pInfo )
301 maFiType.SetText( pInfo->GetDriver() );
302 maFiLocation.SetText( pInfo->GetLocation() );
303 maFiComment.SetText( pInfo->GetComment() );
304 maFiStatus.SetText( ImplPrnDlgGetStatusText( *pInfo ) );
306 else
308 XubString aTempStr;
309 maFiType.SetText( aTempStr );
310 maFiLocation.SetText( aTempStr );
311 maFiComment.SetText( aTempStr );
312 maFiStatus.SetText( aTempStr );
316 // -----------------------------------------------------------------------
318 IMPL_LINK( PrinterSetupDialog, ImplStatusHdl, Timer*, EMPTYARG )
320 QueueInfo aInfo;
321 ImplPrnDlgUpdateQueueInfo( &maLbName, aInfo );
322 maFiStatus.SetText( ImplPrnDlgGetStatusText( aInfo ) );
324 return 0;
327 // -----------------------------------------------------------------------
329 IMPL_LINK( PrinterSetupDialog, ImplPropertiesHdl, void*, EMPTYARG )
331 if ( !mpTempPrinter )
332 mpTempPrinter = new Printer( mpPrinter->GetJobSetup() );
333 mpTempPrinter->Setup( this );
335 return 0;
338 // -----------------------------------------------------------------------
340 IMPL_LINK( PrinterSetupDialog, ImplChangePrinterHdl, void*, EMPTYARG )
342 mpTempPrinter = ImplPrnDlgListBoxSelect( &maLbName, &maBtnProperties,
343 mpPrinter, mpTempPrinter );
344 ImplSetInfo();
345 return 0;
348 // -----------------------------------------------------------------------
350 long PrinterSetupDialog::Notify( NotifyEvent& rNEvt )
352 if ( (rNEvt.GetType() == EVENT_GETFOCUS) && IsReallyVisible() )
353 ImplStatusHdl( &maStatusTimer );
355 return ModalDialog::Notify( rNEvt );
358 // -----------------------------------------------------------------------
360 void PrinterSetupDialog::DataChanged( const DataChangedEvent& rDCEvt )
362 if ( rDCEvt.GetType() == DATACHANGED_PRINTER )
364 mpTempPrinter = ImplPrnDlgUpdatePrinter( mpPrinter, mpTempPrinter );
365 Printer* pPrn;
366 if ( mpTempPrinter )
367 pPrn = mpTempPrinter;
368 else
369 pPrn = mpPrinter;
370 ImplFillPrnDlgListBox( pPrn, &maLbName, &maBtnProperties );
371 ImplSetInfo();
374 ModalDialog::DataChanged( rDCEvt );
377 // -----------------------------------------------------------------------
379 short PrinterSetupDialog::Execute()
381 if ( !mpPrinter || mpPrinter->IsPrinting() || mpPrinter->IsJobActive() )
383 DBG_ERRORFILE( "PrinterSetupDialog::Execute() - No Printer or printer is printing" );
384 return FALSE;
387 Printer::updatePrinters();
389 ImplFillPrnDlgListBox( mpPrinter, &maLbName, &maBtnProperties );
390 ImplSetInfo();
391 maStatusTimer.Start();
393 // Dialog starten
394 short nRet = ModalDialog::Execute();
396 // Wenn Dialog mit OK beendet wurde, dann die Daten updaten
397 if ( nRet == TRUE )
399 if ( mpTempPrinter )
400 mpPrinter->SetPrinterProps( mpTempPrinter );
403 maStatusTimer.Stop();
405 return nRet;