Files
libreoffice/svtools/source/dialogs/prnsetup.cxx

400 lines
13 KiB
C++
Raw Normal View History

2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:07:07 +00:00
*
* $RCSfile: prnsetup.cxx,v $
2000-09-18 16:07:07 +00:00
*
* $Revision: 1.8 $
2000-09-18 16:07:07 +00:00
*
* last change: $Author: hr $ $Date: 2007-06-27 21:28:58 $
2000-09-18 16:07:07 +00:00
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
2000-09-18 16:07:07 +00:00
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
2000-09-18 16:07:07 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
2000-09-18 16:07:07 +00:00
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2000-09-18 16:07:07 +00:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
2000-09-18 16:07:07 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svtools.hxx"
2000-09-18 16:07:07 +00:00
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _VCL_PRINT_HXX
#include <vcl/print.hxx>
#endif
#ifndef GCC
#endif
2000-09-18 16:07:07 +00:00
#include <svtools/svtdata.hxx>
2000-09-18 16:07:07 +00:00
#include "prnsetup.hrc"
#include <svtools/prnsetup.hxx>
2000-09-18 16:07:07 +00:00
// =======================================================================
void ImplFillPrnDlgListBox( const Printer* pPrinter,
ListBox* pBox, PushButton* pPropBtn )
{
ImplFreePrnDlgListBox( pBox );
const std::vector<rtl::OUString>& rPrinters = Printer::GetPrinterQueues();
unsigned int nCount = rPrinters.size();
2000-09-18 16:07:07 +00:00
if ( nCount )
{
for( unsigned int i = 0; i < nCount; i++ )
pBox->InsertEntry( rPrinters[i] );
2000-09-18 16:07:07 +00:00
pBox->SelectEntry( pPrinter->GetName() );
}
pBox->Enable( nCount != 0 );
pPropBtn->Enable( pPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
}
// -----------------------------------------------------------------------
void ImplFreePrnDlgListBox( ListBox* pBox, BOOL bClear )
{
if ( bClear )
pBox->Clear();
}
// -----------------------------------------------------------------------
Printer* ImplPrnDlgListBoxSelect( ListBox* pBox, PushButton* pPropBtn,
Printer* pPrinter, Printer* pTempPrinter )
{
if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
{
const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
if( pInfo)
2000-09-18 16:07:07 +00:00
{
if ( !pTempPrinter )
{
if ( (pPrinter->GetName() == pInfo->GetPrinterName()) &&
(pPrinter->GetDriverName() == pInfo->GetDriver()) )
pTempPrinter = new Printer( pPrinter->GetJobSetup() );
else
pTempPrinter = new Printer( *pInfo );
}
2000-09-18 16:07:07 +00:00
else
{
if ( (pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
(pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
{
delete pTempPrinter;
pTempPrinter = new Printer( *pInfo );
}
2000-09-18 16:07:07 +00:00
}
pPropBtn->Enable( pTempPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
}
else
pPropBtn->Disable();
2000-09-18 16:07:07 +00:00
}
else
pPropBtn->Disable();
return pTempPrinter;
}
// -----------------------------------------------------------------------
Printer* ImplPrnDlgUpdatePrinter( Printer* pPrinter, Printer* pTempPrinter )
{
XubString aPrnName;
if ( pTempPrinter )
aPrnName = pTempPrinter->GetName();
else
aPrnName = pPrinter->GetName();
if ( ! Printer::GetQueueInfo( aPrnName, false ) )
2000-09-18 16:07:07 +00:00
{
if ( pTempPrinter )
delete pTempPrinter;
pTempPrinter = new Printer;
}
return pTempPrinter;
}
// -----------------------------------------------------------------------
void ImplPrnDlgUpdateQueueInfo( ListBox* pBox, QueueInfo& rInfo )
{
if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
{
const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
if( pInfo )
rInfo = *pInfo;
2000-09-18 16:07:07 +00:00
}
}
// -----------------------------------------------------------------------
static void ImplPrnDlgAddString( XubString& rStr, const XubString& rAddStr )
{
if ( rStr.Len() )
rStr.AppendAscii( "; " );
rStr += rAddStr;
}
// -----------------------------------------------------------------------
static void ImplPrnDlgAddResString( XubString& rStr, USHORT nResId )
{
SvtResId aResId( nResId );
XubString aAddStr( aResId );
ImplPrnDlgAddString( rStr, aAddStr );
}
// -----------------------------------------------------------------------
XubString ImplPrnDlgGetStatusText( const QueueInfo& rInfo )
{
XubString aStr;
ULONG nStatus = rInfo.GetStatus();
// Default-Printer
if ( rInfo.GetPrinterName().Len() &&
(rInfo.GetPrinterName() == Printer::GetDefaultPrinterName()) )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DEFPRINTER );
// Status
if ( nStatus & QUEUE_STATUS_READY )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_READY );
if ( nStatus & QUEUE_STATUS_PAUSED )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAUSED );
if ( nStatus & QUEUE_STATUS_PENDING_DELETION )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PENDING );
if ( nStatus & QUEUE_STATUS_BUSY )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_BUSY );
if ( nStatus & QUEUE_STATUS_INITIALIZING )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_INITIALIZING );
if ( nStatus & QUEUE_STATUS_WAITING )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WAITING );
if ( nStatus & QUEUE_STATUS_WARMING_UP )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_WARMING_UP );
if ( nStatus & QUEUE_STATUS_PROCESSING )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PROCESSING );
if ( nStatus & QUEUE_STATUS_PRINTING )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PRINTING );
if ( nStatus & QUEUE_STATUS_OFFLINE )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OFFLINE );
if ( nStatus & QUEUE_STATUS_ERROR )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_ERROR );
if ( nStatus & QUEUE_STATUS_SERVER_UNKNOWN )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_SERVER_UNKNOWN );
if ( nStatus & QUEUE_STATUS_PAPER_JAM )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_JAM );
if ( nStatus & QUEUE_STATUS_PAPER_OUT )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_OUT );
if ( nStatus & QUEUE_STATUS_MANUAL_FEED )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_MANUAL_FEED );
if ( nStatus & QUEUE_STATUS_PAPER_PROBLEM )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAPER_PROBLEM );
if ( nStatus & QUEUE_STATUS_IO_ACTIVE )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_IO_ACTIVE );
if ( nStatus & QUEUE_STATUS_OUTPUT_BIN_FULL )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUTPUT_BIN_FULL );
if ( nStatus & QUEUE_STATUS_TONER_LOW )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_TONER_LOW );
if ( nStatus & QUEUE_STATUS_NO_TONER )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_NO_TONER );
if ( nStatus & QUEUE_STATUS_PAGE_PUNT )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_PAGE_PUNT );
if ( nStatus & QUEUE_STATUS_USER_INTERVENTION )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_USER_INTERVENTION );
if ( nStatus & QUEUE_STATUS_OUT_OF_MEMORY )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_OUT_OF_MEMORY );
if ( nStatus & QUEUE_STATUS_DOOR_OPEN )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_DOOR_OPEN );
if ( nStatus & QUEUE_STATUS_POWER_SAVE )
ImplPrnDlgAddResString( aStr, STR_SVT_PRNDLG_POWER_SAVE );
// Anzahl Jobs
ULONG nJobs = rInfo.GetJobs();
if ( nJobs && (nJobs != QUEUE_JOBS_DONTKNOW) )
{
XubString aJobStr( SvtResId( STR_SVT_PRNDLG_JOBCOUNT ) );
XubString aJobs( XubString::CreateFromInt32( nJobs ) );
aJobStr.SearchAndReplaceAscii( "%d", aJobs );
ImplPrnDlgAddString( aStr, aJobStr );
}
return aStr;
}
// =======================================================================
PrinterSetupDialog::PrinterSetupDialog( Window* pWindow ) :
ModalDialog ( pWindow, SvtResId( DLG_SVT_PRNDLG_PRNSETUPDLG ) ),
2001-06-12 07:50:43 +00:00
maFlPrinter ( this, SvtResId( FL_PRINTER ) ),
2000-09-18 16:07:07 +00:00
maFtName ( this, SvtResId( FT_NAME ) ),
maLbName ( this, SvtResId( LB_NAMES ) ),
maBtnProperties ( this, SvtResId( BTN_PROPERTIES ) ),
maFtStatus ( this, SvtResId( FT_STATUS ) ),
maFiStatus ( this, SvtResId( FI_STATUS ) ),
maFtType ( this, SvtResId( FT_TYPE ) ),
maFiType ( this, SvtResId( FI_TYPE ) ),
maFtLocation ( this, SvtResId( FT_LOCATION ) ),
maFiLocation ( this, SvtResId( FI_LOCATION ) ),
maFtComment ( this, SvtResId( FT_COMMENT ) ),
maFiComment ( this, SvtResId( FI_COMMENT ) ),
maFlSepButton ( this, SvtResId( FL_SEPBUTTON ) ),
2000-09-18 16:07:07 +00:00
maBtnOK ( this, SvtResId( BTN_OK ) ),
maBtnCancel ( this, SvtResId( BTN_CANCEL ) ),
maBtnHelp ( this, SvtResId( BTN_HELP ) )
2000-09-18 16:07:07 +00:00
{
FreeResource();
mpPrinter = NULL;
mpTempPrinter = NULL;
maStatusTimer.SetTimeout( IMPL_PRINTDLG_STATUS_UPDATE );
maStatusTimer.SetTimeoutHdl( LINK( this, PrinterSetupDialog, ImplStatusHdl ) );
maBtnProperties.SetClickHdl( LINK( this, PrinterSetupDialog, ImplPropertiesHdl ) );
maLbName.SetSelectHdl( LINK( this, PrinterSetupDialog, ImplChangePrinterHdl ) );
}
// -----------------------------------------------------------------------
PrinterSetupDialog::~PrinterSetupDialog()
{
ImplFreePrnDlgListBox( &maLbName, FALSE );
delete mpTempPrinter;
}
// -----------------------------------------------------------------------
void PrinterSetupDialog::ImplSetInfo()
{
const QueueInfo* pInfo = Printer::GetQueueInfo(maLbName.GetSelectEntry(), true);
2000-09-18 16:07:07 +00:00
if ( pInfo )
{
maFiType.SetText( pInfo->GetDriver() );
maFiLocation.SetText( pInfo->GetLocation() );
maFiComment.SetText( pInfo->GetComment() );
maFiStatus.SetText( ImplPrnDlgGetStatusText( *pInfo ) );
}
else
{
XubString aTempStr;
maFiType.SetText( aTempStr );
maFiLocation.SetText( aTempStr );
maFiComment.SetText( aTempStr );
maFiStatus.SetText( aTempStr );
}
}
// -----------------------------------------------------------------------
IMPL_LINK( PrinterSetupDialog, ImplStatusHdl, Timer*, EMPTYARG )
{
QueueInfo aInfo;
ImplPrnDlgUpdateQueueInfo( &maLbName, aInfo );
maFiStatus.SetText( ImplPrnDlgGetStatusText( aInfo ) );
return 0;
}
// -----------------------------------------------------------------------
IMPL_LINK( PrinterSetupDialog, ImplPropertiesHdl, void*, EMPTYARG )
{
if ( !mpTempPrinter )
mpTempPrinter = new Printer( mpPrinter->GetJobSetup() );
mpTempPrinter->Setup( this );
2000-09-18 16:07:07 +00:00
return 0;
}
// -----------------------------------------------------------------------
IMPL_LINK( PrinterSetupDialog, ImplChangePrinterHdl, void*, EMPTYARG )
{
mpTempPrinter = ImplPrnDlgListBoxSelect( &maLbName, &maBtnProperties,
mpPrinter, mpTempPrinter );
ImplSetInfo();
return 0;
}
// -----------------------------------------------------------------------
long PrinterSetupDialog::Notify( NotifyEvent& rNEvt )
{
if ( (rNEvt.GetType() == EVENT_GETFOCUS) && IsReallyVisible() )
ImplStatusHdl( &maStatusTimer );
return ModalDialog::Notify( rNEvt );
}
// -----------------------------------------------------------------------
void PrinterSetupDialog::DataChanged( const DataChangedEvent& rDCEvt )
{
if ( rDCEvt.GetType() == DATACHANGED_PRINTER )
{
mpTempPrinter = ImplPrnDlgUpdatePrinter( mpPrinter, mpTempPrinter );
Printer* pPrn;
if ( mpTempPrinter )
pPrn = mpTempPrinter;
else
pPrn = mpPrinter;
ImplFillPrnDlgListBox( pPrn, &maLbName, &maBtnProperties );
ImplSetInfo();
}
ModalDialog::DataChanged( rDCEvt );
}
// -----------------------------------------------------------------------
short PrinterSetupDialog::Execute()
{
if ( !mpPrinter || mpPrinter->IsPrinting() || mpPrinter->IsJobActive() )
{
DBG_ERRORFILE( "PrinterSetupDialog::Execute() - No Printer or printer is printing" );
return FALSE;
}
Printer::updatePrinters();
2000-09-18 16:07:07 +00:00
ImplFillPrnDlgListBox( mpPrinter, &maLbName, &maBtnProperties );
ImplSetInfo();
maStatusTimer.Start();
// Dialog starten
short nRet = ModalDialog::Execute();
// Wenn Dialog mit OK beendet wurde, dann die Daten updaten
if ( nRet == TRUE )
{
if ( mpTempPrinter )
mpPrinter->SetPrinterProps( mpTempPrinter );
}
maStatusTimer.Stop();
return nRet;
}