Files
libreoffice/vcl/source/window/printdlg.cxx

1961 lines
73 KiB
C++
Raw Normal View History

/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: printdlg.cxx,v $
* $Revision: 1.1.2.7 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org 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 version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include "precompiled_vcl.hxx"
#include "vcl/print.hxx"
#include "vcl/prndlg.hxx"
#include "vcl/dialog.hxx"
#include "vcl/button.hxx"
#include "vcl/svdata.hxx"
#include "vcl/svids.hrc"
#include "vcl/wall.hxx"
#include "vcl/jobset.h"
2009-03-18 14:46:10 +00:00
#include "vcl/status.hxx"
2009-03-18 16:16:06 +00:00
#include "vcl/decoview.hxx"
2009-05-22 10:06:06 +00:00
#include "vcl/arrange.hxx"
2009-06-02 11:37:36 +00:00
#include "vcl/configsettings.hxx"
#include "vcl/help.hxx"
#include "vcl/decoview.hxx"
2009-06-10 12:10:29 +00:00
#include "unotools/localedatawrapper.hxx"
#include "rtl/ustrbuf.hxx"
#include "com/sun/star/awt/Size.hpp"
using namespace vcl;
using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::beans;
2009-04-27 09:47:17 +00:00
#define HELPID_PREFIX ".HelpId:vcl:PrintDialog"
#define SMHID2( a, b ) SetSmartHelpId( SmartId( String( RTL_CONSTASCII_USTRINGPARAM( HELPID_PREFIX ":" a ":" b ) ) ) )
#define SMHID1( a ) SetSmartHelpId( SmartId( String( RTL_CONSTASCII_USTRINGPARAM( HELPID_PREFIX ":" a ) ) ) )
2009-04-24 15:39:41 +00:00
PrintDialog::PrintPreviewWindow::PrintPreviewWindow( Window* i_pParent, const ResId& i_rId )
2009-07-24 13:15:45 +00:00
: Window( i_pParent, i_rId )
, maOrigSize( 10, 10 )
, maPageVDev( *this )
{
2009-07-24 13:15:45 +00:00
SetPaintTransparent( TRUE );
SetBackground();
maPageVDev.SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
}
PrintDialog::PrintPreviewWindow::~PrintPreviewWindow()
{
}
2009-07-24 13:15:45 +00:00
void PrintDialog::PrintPreviewWindow::Resize()
{
2009-07-24 13:15:45 +00:00
Size aNewSize( GetSizePixel() );
Size aScaledSize;
double fScale = 1.0;
if( maOrigSize.Width() > maOrigSize.Height() )
{
aScaledSize = Size( aNewSize.Width(), aNewSize.Width() * maOrigSize.Height() / maOrigSize.Width() );
if( aScaledSize.Height() > aNewSize.Height() )
fScale = double(aNewSize.Height())/double(aScaledSize.Height());
}
else
{
aScaledSize = Size( aNewSize.Height() * maOrigSize.Width() / maOrigSize.Height(), aNewSize.Height() );
if( aScaledSize.Width() > aNewSize.Width() )
fScale = double(aNewSize.Width())/double(aScaledSize.Width());
}
aScaledSize.Width() = long(aScaledSize.Width()*fScale);
aScaledSize.Height() = long(aScaledSize.Height()*fScale);
maPageVDev.SetOutputSizePixel( aScaledSize, FALSE );
}
2009-07-25 01:56:38 +00:00
void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& )
2009-07-24 13:15:45 +00:00
{
GDIMetaFile aMtf( maMtf );
2009-07-24 13:15:45 +00:00
Size aPreviewSize = maPageVDev.GetOutputSizePixel();
Size aSize( GetSizePixel() );
Point aOffset( (aSize.Width() - aPreviewSize.Width()) / 2,
(aSize.Height() - aPreviewSize.Height()) / 2 );
const Size aLogicSize( maPageVDev.PixelToLogic( aPreviewSize, MapMode( MAP_100TH_MM ) ) );
double fScale = double(aLogicSize.Width())/double(maOrigSize.Width());
maPageVDev.Erase();
maPageVDev.Push();
maPageVDev.SetMapMode( MAP_100TH_MM );
aMtf.WindStart();
2009-07-24 13:15:45 +00:00
aMtf.Scale( fScale, fScale );
aMtf.WindStart();
2009-07-24 13:15:45 +00:00
aMtf.Play( &maPageVDev, Point( 0, 0 ), aLogicSize );
maPageVDev.Pop();
SetMapMode( MAP_PIXEL );
maPageVDev.SetMapMode( MAP_PIXEL );
DrawOutDev( aOffset, aPreviewSize, Point( 0, 0 ), aPreviewSize, maPageVDev );
}
void PrintDialog::PrintPreviewWindow::Command( const CommandEvent& rEvt )
{
if( rEvt.GetCommand() == COMMAND_WHEEL )
{
const CommandWheelData* pWheelData = rEvt.GetWheelData();
PrintDialog* pDlg = dynamic_cast<PrintDialog*>(GetParent());
if( pDlg )
{
if( pWheelData->GetDelta() > 0 )
pDlg->previewForward();
else if( pWheelData->GetDelta() < 0 )
pDlg->previewBackward();
/*
else
huh ?
*/
}
}
}
2009-07-24 13:15:45 +00:00
void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPreview, const Size& i_rOrigSize )
{
maMtf = i_rNewPreview;
2009-07-24 13:15:45 +00:00
maOrigSize = i_rOrigSize;
2009-07-27 17:10:15 +00:00
Resize();
Invalidate();
}
PrintDialog::NUpTabPage::NUpTabPage( Window* i_pParent, const ResId& rResId )
: TabPage( i_pParent, rResId )
2009-07-27 17:10:15 +00:00
, maNupLine( this, VclResId( SV_PRINT_PRT_NUP_LAYOUT_FL ) )
, maNupPagesTxt( this, VclResId( SV_PRINT_PRT_NUP_PAGES_TXT ) )
, maNupPagesBox( this, VclResId( SV_PRINT_PRT_NUP_PAGES_BOX ) )
, maNupNumPagesTxt( this, VclResId( SV_PRINT_PRT_NUP_NUM_PAGES_TXT ) )
, maNupColEdt( this, VclResId( SV_PRINT_PRT_NUP_COLS_EDT ) )
, maNupTimesTxt( this, VclResId( SV_PRINT_PRT_NUP_TIMES_TXT ) )
2009-03-28 08:52:14 +00:00
, maNupRowsEdt( this, VclResId( SV_PRINT_PRT_NUP_ROWS_EDT ) )
2009-07-27 17:10:15 +00:00
, maPageMarginTxt( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_PAGES_TXT ) )
, maPageMarginEdt( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_PAGES_EDT ) )
, maSheetMarginTxt( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_SHEET_TXT ) )
, maSheetMarginEdt( this, VclResId( SV_PRINT_PRT_NUP_MARGINS_SHEET_EDT ) )
, maNupOrientationTxt( this, VclResId( SV_PRINT_PRT_NUP_ORIENTATION_TXT ) )
, maNupOrientationBox( this, VclResId( SV_PRINT_PRT_NUP_ORIENTATION_BOX ) )
, maNupOrderTxt( this, VclResId( SV_PRINT_PRT_NUP_ORDER_TXT ) )
, maNupOrderBox( this, VclResId( SV_PRINT_PRT_NUP_ORDER_BOX ) )
2009-06-09 18:58:38 +00:00
, maBorderCB( this, VclResId( SV_PRINT_PRT_NUP_BORDER_CB ) )
{
FreeResource();
2009-06-10 12:10:29 +00:00
// setup field units for metric fields
2009-07-27 17:10:15 +00:00
const LocaleDataWrapper& rLocWrap( maPageMarginEdt.GetLocaleDataWrapper() );
2009-06-10 12:10:29 +00:00
FieldUnit eUnit = FUNIT_MM;
USHORT nDigits = 0;
if( rLocWrap.getMeasurementSystemEnum() == MEASURE_US )
{
eUnit = FUNIT_INCH;
nDigits = 2;
}
// set units
2009-07-27 17:10:15 +00:00
maPageMarginEdt.SetUnit( eUnit );
maSheetMarginEdt.SetUnit( eUnit );
2009-06-10 12:10:29 +00:00
// set precision
2009-07-27 17:10:15 +00:00
maPageMarginEdt.SetDecimalDigits( nDigits );
maSheetMarginEdt.SetDecimalDigits( nDigits );
maNupLine.SMHID2("NUpPage", "Layout");
maNupPagesTxt.SMHID2( "NUpPage", "PagesPerSheet" );
maNupPagesBox.SMHID2( "NUpPage", "PagesPerSheetBox" );
maNupNumPagesTxt.SMHID2( "NUpPage", "Columns" );
maNupColEdt.SMHID2( "NUpPage", "ColumnsBox" );
maNupTimesTxt.SMHID2( "NUpPage", "Rows" );
maNupRowsEdt.SMHID2( "NUpPage", "RowsBox" );
maPageMarginTxt.SMHID2( "NUpPage", "PageMargin" );
maPageMarginEdt.SMHID2( "NUpPage", "PageMarginBox" );
maSheetMarginTxt.SMHID2( "NUpPage", "SheetMargin" );
maSheetMarginEdt.SMHID2( "NUpPage", "SheetMarginBox" );
maNupOrientationTxt.SMHID2( "NUpPage", "Orientation" );
maNupOrientationBox.SMHID2( "NUpPage", "OrientationBox" );
maNupOrderTxt.SMHID2( "NUpPage", "Order" );
maNupOrderBox.SMHID2( "NUpPage", "OrderBox" );
maBorderCB.SMHID2( "NUpPage", "BorderBox" );
setupLayout();
}
PrintDialog::NUpTabPage::~NUpTabPage()
{
}
2009-07-27 17:10:15 +00:00
void PrintDialog::NUpTabPage::setupLayout()
2009-06-18 18:26:15 +00:00
{
Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) );
2009-07-27 17:10:15 +00:00
maLayout.setParentWindow( this );
maLayout.setOuterBorder( aBorder.Width() );
maLayout.addWindow( &maNupLine );
boost::shared_ptr< vcl::RowOrColumn > xRow( new vcl::RowOrColumn( &maLayout, false ) );
maLayout.addChild( xRow );
xRow->addWindow( &maNupPagesTxt );
xRow->addWindow( &maNupPagesBox );
boost::shared_ptr< vcl::Indenter > xIndent( new vcl::Indenter( &maLayout ) );
maLayout.addChild( xIndent );
2009-07-27 18:42:13 +00:00
// remember advanced controls to show/hide
mxAdvancedControls = xIndent;
2009-07-27 17:10:15 +00:00
boost::shared_ptr< vcl::RowOrColumn > xCol( new vcl::RowOrColumn( xIndent.get() ) );
xIndent->setChild( xCol );
xRow.reset( new vcl::RowOrColumn( xCol.get(), false ) );
xCol->addChild( xRow );
xRow->addWindow( &maNupNumPagesTxt );
xRow->addWindow( &maNupColEdt );
xRow->addWindow( &maNupTimesTxt );
xRow->addWindow( &maNupRowsEdt );
xRow.reset( new vcl::RowOrColumn( xCol.get(), false ) );
xCol->addChild( xRow );
xRow->addWindow( &maPageMarginTxt );
xRow->addWindow( &maPageMarginEdt );
xRow.reset( new vcl::RowOrColumn( xCol.get(), false ) );
xCol->addChild( xRow );
xRow->addWindow( &maSheetMarginTxt );
xRow->addWindow( &maSheetMarginEdt );
xRow.reset( new vcl::RowOrColumn( xCol.get(), false ) );
xCol->addChild( xRow );
xRow->addWindow( &maNupOrientationTxt );
xRow->addWindow( &maNupOrientationBox );
xRow.reset( new vcl::RowOrColumn( &maLayout, false ) );
maLayout.addChild( xRow );
xRow->addWindow( &maNupOrderTxt );
xRow->addWindow( &maNupOrderBox );
maLayout.addWindow( &maBorderCB );
2009-07-27 18:42:13 +00:00
// initially advanced controls are not show, rows=columns=1
mxAdvancedControls->show( false, false );
2009-07-27 17:10:15 +00:00
}
void PrintDialog::NUpTabPage::Resize()
{
maLayout.setManagedArea( Rectangle( Point( 0, 0 ), GetOutputSizePixel() ) );
2009-06-18 18:26:15 +00:00
}
void PrintDialog::NUpTabPage::initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& i_rMPS )
2009-06-09 18:58:38 +00:00
{
2009-07-27 17:10:15 +00:00
maSheetMarginEdt.SetValue( maSheetMarginEdt.Normalize( i_rMPS.nLeftMargin ), FUNIT_100TH_MM );
maPageMarginEdt.SetValue( maPageMarginEdt.Normalize( i_rMPS.nHorizontalSpacing ), FUNIT_100TH_MM );
2009-06-09 18:58:38 +00:00
maBorderCB.Check( i_rMPS.bDrawBorder );
maNupRowsEdt.SetValue( i_rMPS.nRows );
maNupColEdt.SetValue( i_rMPS.nColumns );
}
void PrintDialog::NUpTabPage::readFromSettings()
2009-06-02 11:37:36 +00:00
{
}
void PrintDialog::NUpTabPage::storeToSettings()
2009-06-02 11:37:36 +00:00
{
}
PrintDialog::JobTabPage::JobTabPage( Window* i_pParent, const ResId& rResId )
: TabPage( i_pParent, rResId )
2009-07-22 17:16:34 +00:00
, maPrinterFL( this, VclResId( SV_PRINT_PRINTERS_FL ) )
, maPrinters( this, VclResId( SV_PRINT_PRINTERS ) )
2009-07-27 18:42:13 +00:00
, maDetailsBtn( this, VclResId( SV_PRINT_DETAILS_BTN ) )
, maDetailsTxt( this, VclResId( SV_PRINT_DETAILS_TXT ) )
2009-07-22 17:16:34 +00:00
, maStatusLabel( this, VclResId( SV_PRINT_STATUS_TXT ) )
, maStatusTxt( this, 0 )
, maLocationLabel( this, VclResId( SV_PRINT_LOCATION_TXT ) )
, maLocationTxt( this, 0 )
, maCommentLabel( this, VclResId( SV_PRINT_COMMENT_TXT ) )
, maCommentTxt( this, 0 )
, maSetupButton( this, VclResId( SV_PRINT_PRT_SETUP ) )
, maCopies( this, VclResId( SV_PRINT_COPIES ) )
2009-07-22 17:16:34 +00:00
, maCopySpacer( this, WB_VERT )
, maCopyCount( this, VclResId( SV_PRINT_COPYCOUNT ) )
, maCopyCountField( this, VclResId( SV_PRINT_COPYCOUNT_FIELD ) )
, maCollateBox( this, VclResId( SV_PRINT_COLLATE ) )
, maCollateImage( this, VclResId( SV_PRINT_COLLATE_IMAGE ) )
, maCollateImg( VclResId( SV_PRINT_COLLATE_IMG ) )
, maCollateHCImg( VclResId( SV_PRINT_COLLATE_HC_IMG ) )
, maNoCollateImg( VclResId( SV_PRINT_NOCOLLATE_IMG ) )
, maNoCollateHCImg( VclResId( SV_PRINT_NOCOLLATE_HC_IMG ) )
, mnCollateUIMode( 0 )
{
FreeResource();
2009-07-22 17:16:34 +00:00
maPrinterFL.SMHID2( "JobPage", "Printer" );
2009-04-27 09:47:17 +00:00
maPrinters.SMHID2( "JobPage", "PrinterList" );
2009-07-22 17:16:34 +00:00
maStatusLabel.SMHID2( "JobPage", "StatusLabel" );
maStatusTxt.SMHID2( "JobPage", "StatusText" );
maLocationLabel.SMHID2( "JobPage", "LocationLabel" );
maLocationTxt.SMHID2( "JobPage", "LocationText" );
maCommentLabel.SMHID2( "JobPage", "CommentLabel" );
maCommentTxt.SMHID2( "JobPage", "CommentText" );
maSetupButton.SMHID2( "JobPage", "Setup" );
2009-04-27 09:47:17 +00:00
maCopies.SMHID2( "JobPage", "CopiesLine" );
2009-07-22 17:16:34 +00:00
maCopySpacer.SMHID2( "JobPage", "CopySpacer" );
2009-04-27 09:47:17 +00:00
maCopyCount.SMHID2( "JobPage", "CopiesText" );
maCopyCountField.SMHID2( "JobPage", "Copies" );
maCollateBox.SMHID2( "JobPage", "Collate" );
maCollateImage.SMHID2( "JobPage", "CollateImage" );
2009-07-22 17:16:34 +00:00
maCopySpacer.Show();
maStatusTxt.Show();
maCommentTxt.Show();
maLocationTxt.Show();
setupLayout();
}
PrintDialog::JobTabPage::~JobTabPage()
{
}
2009-07-22 17:16:34 +00:00
void PrintDialog::JobTabPage::setupLayout()
{
// HACK: this is not a dropdown box, but the dropdown line count
// sets the results of GetOptimalSize in a normal ListBox
maPrinters.SetDropDownLineCount( 4 );
Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) );
maLayout.setParentWindow( this );
maLayout.setOuterBorder( aBorder.Width() );
// add printer fixed line
maLayout.addWindow( &maPrinterFL );
// add print LB
maLayout.addWindow( &maPrinters );
2009-07-27 18:42:13 +00:00
// create a row for details button/text and properties button
boost::shared_ptr< vcl::RowOrColumn > xDetRow( new vcl::RowOrColumn( &maLayout, false ) );
maLayout.addChild( xDetRow );
xDetRow->addWindow( &maDetailsBtn );
xDetRow->addWindow( &maDetailsTxt );
xDetRow->addChild( new vcl::Spacer( xDetRow.get(), 2 ) );
xDetRow->addWindow( &maSetupButton );
// create an indent for details
boost::shared_ptr< vcl::Indenter > xIndent( new vcl::Indenter( &maLayout ) );
maLayout.addChild( xIndent );
// remember details controls
mxDetails = xIndent;
// create a column for the details
boost::shared_ptr< vcl::RowOrColumn > xDetCol( new vcl::RowOrColumn( xIndent.get() ) );
xIndent->setChild( xDetCol );
2009-07-22 17:16:34 +00:00
// create a row for stati and properties button
2009-07-27 18:42:13 +00:00
boost::shared_ptr< vcl::RowOrColumn > xStateRow( new vcl::RowOrColumn( xDetCol.get(), false ) );
xDetCol->addChild( xStateRow );
2009-07-22 17:16:34 +00:00
boost::shared_ptr< vcl::RowOrColumn > xLabelCol( new vcl::RowOrColumn( xStateRow.get(), true, aBorder.Height() ) );
xStateRow->addChild( xLabelCol );
xLabelCol->addWindow( &maStatusLabel );
xLabelCol->addWindow( &maLocationLabel );
xLabelCol->addWindow( &maCommentLabel );
boost::shared_ptr< vcl::RowOrColumn > xStatusCol( new vcl::RowOrColumn( xStateRow.get(), true, aBorder.Height() ) );
xStateRow->addChild( xStatusCol );
xStatusCol->addWindow( &maStatusTxt );
xStatusCol->addWindow( &maLocationTxt );
xStatusCol->addWindow( &maCommentTxt );
// add print range and copies columns
maLayout.addWindow( &maCopies );
boost::shared_ptr< vcl::RowOrColumn > xRangeRow( new vcl::RowOrColumn( &maLayout, false, aBorder.Width() ) );
maLayout.addChild( xRangeRow );
// create print range and add to range row
mxPrintRange.reset( new vcl::RowOrColumn( xRangeRow.get() ) );
xRangeRow->addChild( mxPrintRange );
xRangeRow->addWindow( &maCopySpacer );
boost::shared_ptr< vcl::RowOrColumn > xCopyCollateCol( new vcl::RowOrColumn( xRangeRow.get() ) );
xRangeRow->addChild( xCopyCollateCol );
// add copies row to copy/collate column
boost::shared_ptr< vcl::RowOrColumn > xCopiesRow( new vcl::RowOrColumn( xCopyCollateCol.get(), false, 0 ) );
xCopyCollateCol->addChild( xCopiesRow );
xCopiesRow->addWindow( &maCopyCount );
xCopiesRow->addWindow( &maCopyCountField );
boost::shared_ptr< vcl::RowOrColumn > xCollateRow( new vcl::RowOrColumn( xCopyCollateCol.get(), false, 0 ) );
xCopyCollateCol->addChild( xCollateRow );
xCollateRow->addWindow( &maCollateBox );
xCollateRow->addWindow( &maCollateImage );
2009-07-27 18:42:13 +00:00
maDetailsBtn.SetSymbol( SYMBOL_SPIN_DOWN );
maDetailsBtn.SetSmallSymbol();
maDetailsBtn.SetStyle( maDetailsBtn.GetStyle() | (WB_SMALLSTYLE | WB_BEVELBUTTON) );
mxDetails->show( false, false );
2009-07-22 17:16:34 +00:00
}
2009-06-02 11:37:36 +00:00
void PrintDialog::JobTabPage::readFromSettings()
{
SettingsConfigItem* pItem = SettingsConfigItem::get();
rtl::OUString aValue;
2009-06-09 18:58:38 +00:00
#if 0
// do not actually make copy count persistent
// the assumption is that this would lead to a lot of unwanted copies
aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CopyCount" ) ) );
2009-06-02 11:37:36 +00:00
sal_Int32 nVal = aValue.toInt32();
maCopyCountField.SetValue( sal_Int64(nVal > 1 ? nVal : 1) );
2009-06-09 18:58:38 +00:00
#endif
2009-06-02 11:37:36 +00:00
aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CollateBox" ) ) );
if( aValue.equalsIgnoreAsciiCaseAscii( "alwaysoff" ) )
{
mnCollateUIMode = 1;
maCollateBox.Check( FALSE );
maCollateBox.Enable( FALSE );
}
else
{
mnCollateUIMode = 0;
aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ) );
maCollateBox.Check( aValue.equalsIgnoreAsciiCaseAscii( "true" ) );
}
2009-06-02 11:37:36 +00:00
}
void PrintDialog::JobTabPage::storeToSettings()
{
SettingsConfigItem* pItem = SettingsConfigItem::get();
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CopyCount" ) ),
2009-06-02 11:37:36 +00:00
maCopyCountField.GetText() );
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
2009-06-02 11:37:36 +00:00
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ),
rtl::OUString::createFromAscii( maCollateBox.IsChecked() ? "true" : "false" ) );
}
2009-07-22 17:16:34 +00:00
void PrintDialog::JobTabPage::Resize()
{
maLayout.setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
}
PrintDialog::OutputOptPage::OutputOptPage( Window* i_pParent, const ResId& i_rResId )
: TabPage( i_pParent, i_rResId )
, maOptionsLine( this, VclResId( SV_PRINT_OPT_PRINT_FL ) )
, maToFileBox( this, VclResId( SV_PRINT_OPT_TOFILE ) )
, maCollateSingleJobsBox( this, VclResId( SV_PRINT_OPT_SINGLEJOBS ) )
, maReverseOrderBox( this, VclResId( SV_PRINT_OPT_REVERSE ) )
{
2009-07-24 13:15:45 +00:00
FreeResource();
2009-07-22 17:16:34 +00:00
maOptionsLine.SMHID2( "OptPage", "Options" );
maToFileBox.SMHID2( "OptPage", "ToFile" );
maCollateSingleJobsBox.SMHID2( "OptPage", "SingleJobs" );
maReverseOrderBox.SMHID2( "OptPage", "Reverse" );
2009-07-23 17:22:34 +00:00
setupLayout();
2009-07-22 17:16:34 +00:00
}
PrintDialog::OutputOptPage::~OutputOptPage()
{
}
2009-07-23 17:22:34 +00:00
void PrintDialog::OutputOptPage::setupLayout()
{
Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) );
maLayout.setParentWindow( this );
maLayout.setOuterBorder( aBorder.Width() );
maLayout.addWindow( &maOptionsLine );
boost::shared_ptr<vcl::Indenter> xIndent( new vcl::Indenter( &maLayout, aBorder.Width() ) );
maLayout.addChild( xIndent );
boost::shared_ptr<vcl::RowOrColumn> xCol( new vcl::RowOrColumn( xIndent.get(), aBorder.Height() ) );
xIndent->setChild( xCol );
2009-07-28 19:01:04 +00:00
mxOptGroup = xCol;
2009-07-23 17:22:34 +00:00
xCol->addWindow( &maToFileBox );
xCol->addWindow( &maCollateSingleJobsBox );
xCol->addWindow( &maReverseOrderBox );
}
2009-07-22 17:16:34 +00:00
void PrintDialog::OutputOptPage::readFromSettings()
{
SettingsConfigItem* pItem = SettingsConfigItem::get();
rtl::OUString aValue;
aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ToFile" ) ) );
maToFileBox.Check( aValue.equalsIgnoreAsciiCaseAscii( "true" ) );
}
void PrintDialog::OutputOptPage::storeToSettings()
{
SettingsConfigItem* pItem = SettingsConfigItem::get();
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ToFile" ) ),
rtl::OUString::createFromAscii( maToFileBox.IsChecked() ? "true" : "false" ) );
}
2009-07-23 17:22:34 +00:00
void PrintDialog::OutputOptPage::Resize()
{
maLayout.setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
}
2009-07-22 17:16:34 +00:00
PrintDialog::PrintDialog( Window* i_pParent, const boost::shared_ptr<PrinterController>& i_rController )
: ModalDialog( i_pParent, VclResId( SV_DLG_PRINT ) )
, maOKButton( this, VclResId( SV_PRINT_OK ) )
, maCancelButton( this, VclResId( SV_PRINT_CANCEL ) )
, maPreviewWindow( this, VclResId( SV_PRINT_PAGE_PREVIEW ) )
, maPageEdit( this, VclResId( SV_PRINT_PAGE_EDIT ) )
, maNumPagesText( this, VclResId( SV_PRINT_PAGE_TXT ) )
, maForwardBtn( this, VclResId( SV_PRINT_PAGE_FORWARD ) )
, maBackwardBtn( this, VclResId( SV_PRINT_PAGE_BACKWARD ) )
, maTabCtrl( this, VclResId( SV_PRINT_TABCTRL ) )
, maNUpPage( &maTabCtrl, VclResId( SV_PRINT_TAB_NUP ) )
, maJobPage( &maTabCtrl, VclResId( SV_PRINT_TAB_JOB ) )
2009-07-22 17:16:34 +00:00
, maOptionsPage( &maTabCtrl, VclResId( SV_PRINT_TAB_OPT ) )
, maButtonLine( this, VclResId( SV_PRINT_BUTTONLINE ) )
, maPController( i_rController )
2009-03-26 18:00:43 +00:00
, maNoPageStr( String( VclResId( SV_PRINT_NOPAGES ) ) )
, mnCurPage( 0 )
, mnCachedPages( 0 )
2009-07-24 13:15:45 +00:00
, maPrintToFileText( String( VclResId( SV_PRINT_TOFILE_TXT ) ) )
{
FreeResource();
2009-07-24 13:15:45 +00:00
// save printbutton text, gets exchanged occasionally with print to file
maPrintText = maOKButton.GetText();
// setup preview controls
maForwardBtn.SetStyle( maForwardBtn.GetStyle() | WB_BEVELBUTTON );
maBackwardBtn.SetStyle( maBackwardBtn.GetStyle() | WB_BEVELBUTTON );
2009-07-23 17:22:34 +00:00
// insert the job (general) tab page first
maTabCtrl.InsertPage( SV_PRINT_TAB_JOB, maJobPage.GetText() );
maTabCtrl.SetTabPage( SV_PRINT_TAB_JOB, &maJobPage );
// set symbols on forward and backward button
maBackwardBtn.SetSymbol( SYMBOL_PREV );
maForwardBtn.SetSymbol( SYMBOL_NEXT );
maBackwardBtn.ImplSetSmallSymbol( TRUE );
maForwardBtn.ImplSetSmallSymbol( TRUE );
maPageStr = maNumPagesText.GetText();
2009-07-24 13:15:45 +00:00
// get the first page
2009-06-10 17:21:10 +00:00
preparePreview( true, true );
// fill printer listbox
const std::vector< rtl::OUString >& rQueues( Printer::GetPrinterQueues() );
for( std::vector< rtl::OUString >::const_iterator it = rQueues.begin();
it != rQueues.end(); ++it )
{
maJobPage.maPrinters.InsertEntry( *it );
}
// select current printer
if( maJobPage.maPrinters.GetEntryPos( maPController->getPrinter()->GetName() ) != LISTBOX_ENTRY_NOTFOUND )
{
maJobPage.maPrinters.SelectEntry( maPController->getPrinter()->GetName() );
}
else
{
2009-06-02 11:37:36 +00:00
// fall back to last printer
SettingsConfigItem* pItem = SettingsConfigItem::get();
String aValue( pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPrinter" ) ) ) );
if( maJobPage.maPrinters.GetEntryPos( aValue ) != LISTBOX_ENTRY_NOTFOUND )
2009-06-02 11:37:36 +00:00
{
maJobPage.maPrinters.SelectEntry( aValue );
maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aValue ) ) );
2009-06-02 11:37:36 +00:00
}
else
{
// fall back to default printer
maJobPage.maPrinters.SelectEntry( Printer::GetDefaultPrinterName() );
maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( Printer::GetDefaultPrinterName() ) ) );
2009-06-02 11:37:36 +00:00
}
}
// update the text fields for the printer
updatePrinterText();
// set a select handler
maJobPage.maPrinters.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
2009-03-28 08:52:14 +00:00
// setup sizes for N-Up
Size aNupSize( maPController->getPrinter()->PixelToLogic(
maPController->getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
if( maPController->getPrinter()->GetOrientation() == ORIENTATION_LANDSCAPE )
2009-03-28 08:52:14 +00:00
{
maNupLandscapeSize = aNupSize;
maNupPortraitSize = Size( aNupSize.Height(), aNupSize.Width() );
}
else
{
maNupPortraitSize = aNupSize;
maNupLandscapeSize = Size( aNupSize.Height(), aNupSize.Width() );
}
maNUpPage.initFromMultiPageSetup( maPController->getMultipage() );
2009-06-09 18:58:38 +00:00
2009-03-28 08:52:14 +00:00
// setup click handler on the various buttons
2009-06-02 11:37:36 +00:00
maOKButton.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
#if OSL_DEBUG_LEVEL > 1
maCancelButton.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
#endif
maForwardBtn.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
maBackwardBtn.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
2009-07-16 11:37:53 +00:00
maJobPage.maCollateBox.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
maJobPage.maSetupButton.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
2009-07-27 18:42:13 +00:00
maJobPage.maDetailsBtn.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
2009-06-09 18:58:38 +00:00
maNUpPage.maBorderCB.SetClickHdl( LINK( this, PrintDialog, ClickHdl ) );
2009-07-24 13:15:45 +00:00
maOptionsPage.maToFileBox.SetToggleHdl( LINK( this, PrintDialog, ClickHdl ) );
// setup modify hdl
maPageEdit.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
maJobPage.maCopyCountField.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
maNUpPage.maNupRowsEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
maNUpPage.maNupColEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
2009-07-27 17:10:15 +00:00
maNUpPage.maPageMarginEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
maNUpPage.maSheetMarginEdt.SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) );
// setup select hdl
maNUpPage.maNupPagesBox.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
maNUpPage.maNupOrientationBox.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
maNUpPage.maNupOrderBox.SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) );
2009-07-24 13:15:45 +00:00
// setup the layout
setupLayout();
// setup optional UI options set by application
setupOptionalUI();
// set change handler for UI options
maPController->setOptionChangeHdl( LINK( this, PrintDialog, UIOptionsChanged ) );
2009-03-17 12:27:26 +00:00
// set min size pixel to current size
SetMinOutputSizePixel( GetOutputSizePixel() );
2009-06-02 11:37:36 +00:00
// restore settings from last run
readFromSettings();
// setup dependencies
checkControlDependencies();
2009-04-27 09:47:17 +00:00
// set HelpIDs
maOKButton.SMHID1( "OK" );
maCancelButton.SMHID1( "Cancel" );
maPreviewWindow.SMHID1( "Preview" );
maNumPagesText.SMHID1( "NumPagesText" );
maPageEdit.SMHID1( "PageEdit" );
maForwardBtn.SMHID1( "ForwardBtn" );
maBackwardBtn.SMHID1( "BackwardBtn" );
2009-04-27 09:47:17 +00:00
maTabCtrl.SMHID1( "TabPages" );
2009-07-22 17:16:34 +00:00
2009-07-23 17:22:34 +00:00
// append further tab pages
maTabCtrl.InsertPage( SV_PRINT_TAB_NUP, maNUpPage.GetText() );
maTabCtrl.SetTabPage( SV_PRINT_TAB_NUP, &maNUpPage );
2009-07-22 17:16:34 +00:00
maTabCtrl.InsertPage( SV_PRINT_TAB_OPT, maOptionsPage.GetText() );
maTabCtrl.SetTabPage( SV_PRINT_TAB_OPT, &maOptionsPage );
}
PrintDialog::~PrintDialog()
{
while( ! maControls.empty() )
{
delete maControls.front();
maControls.pop_front();
}
}
2009-07-24 13:15:45 +00:00
void PrintDialog::setupLayout()
{
Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) );
maLayout.setParentWindow( this );
maLayout.setOuterBorder( aBorder.Width() );
boost::shared_ptr< vcl::RowOrColumn > xPreviewAndTab( new vcl::RowOrColumn( &maLayout, false ) );
maLayout.addChild( xPreviewAndTab, 5 );
// setup column for preview and sub controls
boost::shared_ptr< vcl::RowOrColumn > xPreview( new vcl::RowOrColumn( xPreviewAndTab.get() ) );
xPreviewAndTab->addChild( xPreview, 5 );
xPreview->addWindow( &maPreviewWindow, 5 );
// get a row for the preview controls
boost::shared_ptr< vcl::RowOrColumn > xPreviewCtrls( new vcl::RowOrColumn( xPreview.get(), false ) );
xPreview->addChild( xPreviewCtrls );
xPreviewCtrls->addWindow( &maPageEdit );
xPreviewCtrls->addWindow( &maNumPagesText );
boost::shared_ptr< vcl::Spacer > xSpacer( new vcl::Spacer( xPreviewCtrls.get(), 2 ) );
xPreviewCtrls->addChild( xSpacer );
xPreviewCtrls->addWindow( &maBackwardBtn );
xPreviewCtrls->addWindow( &maForwardBtn );
// continue with the tab ctrl
xPreviewAndTab->addWindow( &maTabCtrl );
// add the button line
maLayout.addWindow( &maButtonLine );
// add the row for the buttons
boost::shared_ptr< vcl::RowOrColumn > xButtons( new vcl::RowOrColumn( &maLayout, false ) );
maLayout.addChild( xButtons );
// insert a spacer, buttons are right aligned
xSpacer.reset( new vcl::Spacer( xButtons.get(), 2 ) );
xButtons->addChild( xSpacer );
Size aMinSize( maCancelButton.GetSizePixel() );
xButtons->setMinimumSize( xButtons->addWindow( &maOKButton ), aMinSize );
xButtons->setMinimumSize( xButtons->addWindow( &maCancelButton ), aMinSize );
}
2009-06-02 11:37:36 +00:00
void PrintDialog::readFromSettings()
{
maJobPage.readFromSettings();
maNUpPage.readFromSettings();
2009-07-22 17:16:34 +00:00
maOptionsPage.readFromSettings();
2009-06-02 11:37:36 +00:00
// read last selected tab page; if it exists, actiavte it
SettingsConfigItem* pItem = SettingsConfigItem::get();
rtl::OUString aValue = pItem->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPage" ) ) );
USHORT nCount = maTabCtrl.GetPageCount();
for( USHORT i = 0; i < nCount; i++ )
{
USHORT nPageId = maTabCtrl.GetPageId( i );
if( aValue.equals( maTabCtrl.GetPageText( nPageId ) ) )
{
maTabCtrl.SelectTabPage( nPageId );
break;
}
}
2009-07-24 13:15:45 +00:00
maOKButton.SetText( maOptionsPage.maToFileBox.IsChecked() ? maPrintToFileText : maPrintText );
2009-06-02 11:37:36 +00:00
}
void PrintDialog::storeToSettings()
{
maJobPage.storeToSettings();
maNUpPage.storeToSettings();
2009-07-22 17:16:34 +00:00
maOptionsPage.storeToSettings();
2009-06-02 11:37:36 +00:00
// store last selected printer
SettingsConfigItem* pItem = SettingsConfigItem::get();
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPrinter" ) ),
maJobPage.maPrinters.GetSelectEntry() );
pItem->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintDialog" ) ),
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LastPage" ) ),
maTabCtrl.GetPageText( maTabCtrl.GetCurPageId() ) );
pItem->Commit();
}
bool PrintDialog::isPrintToFile()
{
2009-07-22 17:16:34 +00:00
return maOptionsPage.maToFileBox.IsChecked();
}
int PrintDialog::getCopyCount()
{
2008-11-06 15:54:09 +00:00
return static_cast<int>(maJobPage.maCopyCountField.GetValue());
}
bool PrintDialog::isCollate()
{
return maJobPage.maCopyCountField.GetValue() > 1 ? maJobPage.maCollateBox.IsChecked() : FALSE;
}
2009-04-27 09:47:17 +00:00
static void setSmartId( Window* i_pWindow, const char* i_pType, sal_Int32 i_nId = -1, const rtl::OUString& i_rPropName = rtl::OUString() )
{
rtl::OUStringBuffer aBuf( 256 );
aBuf.appendAscii( HELPID_PREFIX );
if( i_rPropName.getLength() )
{
aBuf.append( sal_Unicode( ':' ) );
aBuf.append( i_rPropName );
}
if( i_pType )
{
aBuf.append( sal_Unicode( ':' ) );
aBuf.appendAscii( i_pType );
}
if( i_nId >= 0 )
{
aBuf.append( sal_Unicode( ':' ) );
aBuf.append( i_nId );
}
i_pWindow->SetSmartHelpId( SmartId( aBuf.makeStringAndClear() ) );
}
2009-04-27 16:11:03 +00:00
static void setHelpText( Window* i_pWindow, const Sequence< rtl::OUString >& i_rHelpTexts, sal_Int32 i_nIndex )
{
if( i_nIndex >= 0 && i_nIndex < i_rHelpTexts.getLength() )
i_pWindow->SetHelpText( i_rHelpTexts.getConstArray()[i_nIndex] );
}
void PrintDialog::setupOptionalUI()
{
2009-07-23 17:22:34 +00:00
Size aBorder( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) );
2009-05-22 10:06:06 +00:00
std::vector<vcl::RowOrColumn*> aDynamicColumns;
vcl::RowOrColumn* pCurColumn = 0;
Window* pCurParent = 0, *pDynamicPageParent = 0;
2009-05-22 10:06:06 +00:00
USHORT nOptPageId = 9, nCurSubGroup = 0;
2009-07-23 17:22:34 +00:00
bool bOnStaticPage = false;
2009-07-28 19:01:04 +00:00
bool bSubgroupOnStaticPage = false;
2009-05-27 17:40:24 +00:00
std::multimap< rtl::OUString, vcl::RowOrColumn* > aPropertyToDependencyRowMap;
const Sequence< PropertyValue >& rOptions( maPController->getUIOptions() );
for( int i = 0; i < rOptions.getLength(); i++ )
{
Sequence< beans::PropertyValue > aOptProp;
rOptions[i].Value >>= aOptProp;
// extract ui element
bool bEnabled = true;
rtl::OUString aCtrlType;
rtl::OUString aText;
rtl::OUString aPropertyName;
Sequence< rtl::OUString > aChoices;
2009-04-27 16:11:03 +00:00
Sequence< rtl::OUString > aHelpTexts;
2009-03-16 17:48:45 +00:00
sal_Int64 nMinValue = 0, nMaxValue = 0;
2009-04-27 16:11:03 +00:00
sal_Int32 nCurHelpText = 0;
2009-07-22 17:16:34 +00:00
rtl::OUString aGroupingHint;
2009-05-27 17:40:24 +00:00
rtl::OUString aDependsOnName;
sal_Int32 nDependsOnValue = 0;
sal_Bool bUseDependencyRow = sal_False;
for( int n = 0; n < aOptProp.getLength(); n++ )
{
const beans::PropertyValue& rEntry( aOptProp[ n ] );
if( rEntry.Name.equalsAscii( "Text" ) )
{
rEntry.Value >>= aText;
}
else if( rEntry.Name.equalsAscii( "ControlType" ) )
{
rEntry.Value >>= aCtrlType;
}
else if( rEntry.Name.equalsAscii( "Choices" ) )
{
rEntry.Value >>= aChoices;
}
else if( rEntry.Name.equalsAscii( "Property" ) )
{
PropertyValue aVal;
rEntry.Value >>= aVal;
aPropertyName = aVal.Name;
}
else if( rEntry.Name.equalsAscii( "Enabled" ) )
{
sal_Bool bValue = sal_True;
rEntry.Value >>= bValue;
bEnabled = bValue;
}
2009-07-22 17:16:34 +00:00
else if( rEntry.Name.equalsAscii( "GroupingHint" ) )
{
2009-07-22 17:16:34 +00:00
rEntry.Value >>= aGroupingHint;
}
else if( rEntry.Name.equalsAscii( "DependsOnName" ) )
{
2009-05-27 17:40:24 +00:00
rEntry.Value >>= aDependsOnName;
}
else if( rEntry.Name.equalsAscii( "DependsOnEntry" ) )
{
rEntry.Value >>= nDependsOnValue;
}
else if( rEntry.Name.equalsAscii( "AttachToDependency" ) )
{
rEntry.Value >>= bUseDependencyRow;
}
2009-03-16 17:48:45 +00:00
else if( rEntry.Name.equalsAscii( "MinValue" ) )
{
rEntry.Value >>= nMinValue;
}
else if( rEntry.Name.equalsAscii( "MaxValue" ) )
{
rEntry.Value >>= nMaxValue;
}
2009-04-27 16:11:03 +00:00
else if( rEntry.Name.equalsAscii( "HelpText" ) )
{
if( ! (rEntry.Value >>= aHelpTexts) )
{
rtl::OUString aHelpText;
if( (rEntry.Value >>= aHelpText) )
{
aHelpTexts.realloc( 1 );
*aHelpTexts.getArray() = aHelpText;
}
}
}
}
2009-07-28 19:01:04 +00:00
// is it necessary to switch between static and dynamic pages ?
bool bSwitchPage = false;
if( aGroupingHint.getLength() )
bSwitchPage = true;
else if( aCtrlType.equalsAscii( "Subgroup" ) || (bOnStaticPage && ! bSubgroupOnStaticPage ) )
bSwitchPage = true;
if( bSwitchPage )
{
// restore to dynamic
pCurParent = pDynamicPageParent;
pCurColumn = aDynamicColumns.empty() ? NULL : aDynamicColumns.back();
bOnStaticPage = false;
bSubgroupOnStaticPage = false;
if( aGroupingHint.equalsAscii( "PrintRange" ) )
{
pCurColumn = maJobPage.mxPrintRange.get();
pCurParent = &maJobPage; // set job page as current parent
bOnStaticPage = true;
}
else if( aGroupingHint.equalsAscii( "OptionsPage" ) )
{
pCurColumn = &maOptionsPage.maLayout;
pCurParent = &maOptionsPage; // set options page as current parent
bOnStaticPage = true;
}
else if( aGroupingHint.equalsAscii( "OptionsPageOptGroup" ) )
{
pCurColumn = maOptionsPage.mxOptGroup.get();
pCurParent = &maOptionsPage; // set options page as current parent
bOnStaticPage = true;
}
else if( aGroupingHint.equalsAscii( "LayoutPage" ) )
{
pCurColumn = &maNUpPage.maLayout;
pCurParent = &maNUpPage; // set layout page as current parent
bOnStaticPage = true;
}
else if( aGroupingHint.getLength() )
{
pCurColumn = &maJobPage.maLayout;
pCurParent = &maJobPage; // set job page as current parent
bOnStaticPage = true;
}
}
2009-05-27 18:53:40 +00:00
if( aCtrlType.equalsAscii( "Group" ) ||
2009-07-23 17:22:34 +00:00
( ! pCurParent && ! (bOnStaticPage || aGroupingHint.getLength() ) ) )
2009-05-27 17:40:24 +00:00
{
// add new tab page
TabPage* pNewGroup = new TabPage( &maTabCtrl );
maControls.push_front( pNewGroup );
2009-07-23 17:22:34 +00:00
pDynamicPageParent = pCurParent = pNewGroup;
2009-05-27 17:40:24 +00:00
pNewGroup->SetText( aText );
maTabCtrl.InsertPage( ++nOptPageId, aText );
maTabCtrl.SetTabPage( nOptPageId, pNewGroup );
// set help id
setSmartId( pNewGroup, "TabPage", nOptPageId );
// set help text
setHelpText( pNewGroup, aHelpTexts, 0 );
// reset subgroup counter
nCurSubGroup = 0;
2009-07-23 17:22:34 +00:00
aDynamicColumns.push_back( new vcl::RowOrColumn( NULL, true, aBorder.Width() ) );
2009-05-27 17:40:24 +00:00
pCurColumn = aDynamicColumns.back();
pCurColumn->setParentWindow( pNewGroup );
2009-07-23 17:22:34 +00:00
pCurColumn->setOuterBorder( aBorder.Width() );
2009-07-28 19:01:04 +00:00
bSubgroupOnStaticPage = false;
bOnStaticPage = false;
2009-05-27 17:40:24 +00:00
}
2009-07-22 17:16:34 +00:00
else if( aCtrlType.equalsAscii( "Subgroup" ) && (pCurParent || aGroupingHint.getLength() ) )
{
2009-07-28 19:01:04 +00:00
bSubgroupOnStaticPage = (aGroupingHint.getLength() != 0);
2009-05-27 17:40:24 +00:00
// create group FixedLine
2009-07-22 17:16:34 +00:00
if( ! aGroupingHint.equalsAscii( "PrintRange" ) ||
! pCurColumn->countElements() == 0
)
{
FixedLine* pNewSub = new FixedLine( pCurParent );
maControls.push_front( pNewSub );
pNewSub->SetText( aText );
pNewSub->Show();
2009-07-22 17:16:34 +00:00
// set help id
setSmartId( pNewSub, "FixedLine", sal_Int32( nCurSubGroup++ ) );
// set help text
setHelpText( pNewSub, aHelpTexts, 0 );
// add group to current column
pCurColumn->addWindow( pNewSub );
}
2009-07-23 17:22:34 +00:00
// add an indent to the current column
vcl::Indenter* pIndent = new vcl::Indenter( pCurColumn, aBorder.Width() );
pCurColumn->addChild( pIndent );
// and create a column inside the indent
pCurColumn = new vcl::RowOrColumn( pIndent );
pIndent->setChild( pCurColumn );
2009-05-27 17:40:24 +00:00
}
else
{
vcl::RowOrColumn* pSaveCurColumn = pCurColumn;
if( bUseDependencyRow && aDependsOnName.getLength() )
2008-11-05 15:52:15 +00:00
{
2009-05-27 17:40:24 +00:00
// find the correct dependency row (if any)
std::pair< std::multimap< rtl::OUString, vcl::RowOrColumn* >::iterator,
std::multimap< rtl::OUString, vcl::RowOrColumn* >::iterator > aDepRange;
aDepRange = aPropertyToDependencyRowMap.equal_range( aDependsOnName );
if( aDepRange.first != aDepRange.second )
{
2009-05-27 17:40:24 +00:00
while( nDependsOnValue && aDepRange.first != aDepRange.second )
{
2009-05-27 17:40:24 +00:00
nDependsOnValue--;
++aDepRange.first;
}
2009-05-27 17:40:24 +00:00
if( aDepRange.first != aPropertyToDependencyRowMap.end() )
{
2009-05-27 17:40:24 +00:00
pCurColumn = aDepRange.first->second;
}
}
2008-11-05 15:52:15 +00:00
}
2009-05-27 17:40:24 +00:00
if( aCtrlType.equalsAscii( "Bool" ) && pCurParent )
{
// add a check box
CheckBox* pNewBox = new CheckBox( pCurParent );
maControls.push_front( pNewBox );
pNewBox->SetText( aText );
pNewBox->Show();
2009-05-22 10:06:06 +00:00
sal_Bool bVal = sal_False;
PropertyValue* pVal = maPController->getValue( aPropertyName );
if( pVal )
pVal->Value >>= bVal;
pNewBox->Check( bVal );
pNewBox->Enable( maPController->isUIOptionEnabled( aPropertyName ) && pVal != NULL );
pNewBox->SetToggleHdl( LINK( this, PrintDialog, UIOption_CheckHdl ) );
maPropertyToWindowMap.insert( std::pair< rtl::OUString, Window* >( aPropertyName, pNewBox ) );
maControlToPropertyMap[pNewBox] = aPropertyName;
2009-04-27 09:47:17 +00:00
// set help id
setSmartId( pNewBox, "CheckBox", -1, aPropertyName );
2009-04-27 16:11:03 +00:00
// set help text
setHelpText( pNewBox, aHelpTexts, 0 );
2009-05-22 10:06:06 +00:00
2009-05-27 17:40:24 +00:00
vcl::RowOrColumn* pDependencyRow = new vcl::RowOrColumn( pCurColumn, false );
pCurColumn->addChild( pDependencyRow );
aPropertyToDependencyRowMap.insert( std::pair< rtl::OUString, vcl::RowOrColumn* >( aPropertyName, pDependencyRow ) );
2009-05-22 10:06:06 +00:00
// add checkbox to current column
2009-05-27 17:40:24 +00:00
pDependencyRow->addWindow( pNewBox );
}
else if( aCtrlType.equalsAscii( "Radio" ) && pCurParent )
{
2009-05-22 10:06:06 +00:00
vcl::RowOrColumn* pRadioColumn = pCurColumn;
if( aText.getLength() )
{
// add a FixedText:
FixedText* pHeading = new FixedText( pCurParent );
maControls.push_front( pHeading );
pHeading->SetText( aText );
pHeading->Show();
2009-04-27 09:47:17 +00:00
// set help id
setSmartId( pHeading, "FixedText", -1, aPropertyName );
2009-04-27 16:11:03 +00:00
// set help text
setHelpText( pHeading, aHelpTexts, nCurHelpText++ );
2009-05-22 10:06:06 +00:00
// add fixed text to current column
pCurColumn->addWindow( pHeading );
// add an indent to the current column
vcl::Indenter* pIndent = new vcl::Indenter( pCurColumn, 15 );
pCurColumn->addChild( pIndent );
// and create a column inside the indent
pRadioColumn = new vcl::RowOrColumn( pIndent );
pIndent->setChild( pRadioColumn );
}
// iterate options
sal_Int32 nSelectVal = 0;
PropertyValue* pVal = maPController->getValue( aPropertyName );
if( pVal && pVal->Value.hasValue() )
pVal->Value >>= nSelectVal;
for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
{
2009-05-27 17:40:24 +00:00
vcl::RowOrColumn* pDependencyRow = new vcl::RowOrColumn( pCurColumn, false );
pRadioColumn->addChild( pDependencyRow );
aPropertyToDependencyRowMap.insert( std::pair< rtl::OUString, vcl::RowOrColumn* >( aPropertyName, pDependencyRow ) );
RadioButton* pBtn = new RadioButton( pCurParent, m == 0 ? WB_GROUP : 0 );
maControls.push_front( pBtn );
pBtn->SetText( aChoices[m] );
pBtn->Check( m == nSelectVal );
pBtn->Enable( maPController->isUIOptionEnabled( aPropertyName ) );
pBtn->SetToggleHdl( LINK( this, PrintDialog, UIOption_RadioHdl ) );
pBtn->Show();
maPropertyToWindowMap.insert( std::pair< rtl::OUString, Window* >( aPropertyName, pBtn ) );
maControlToPropertyMap[pBtn] = aPropertyName;
maControlToNumValMap[pBtn] = m;
2009-04-27 09:47:17 +00:00
// set help id
setSmartId( pBtn, "RadioButton", m, aPropertyName );
2009-04-27 16:11:03 +00:00
// set help text
setHelpText( pBtn, aHelpTexts, nCurHelpText++ );
2009-05-22 10:06:06 +00:00
// add the radio button to the column
2009-05-27 17:40:24 +00:00
pDependencyRow->addWindow( pBtn );
}
}
2009-05-22 10:19:01 +00:00
else if( ( aCtrlType.equalsAscii( "List" ) ||
aCtrlType.equalsAscii( "Range" ) ||
aCtrlType.equalsAscii( "Edit" )
) && pCurParent )
{
2009-05-27 17:40:24 +00:00
// create a row in the current column
vcl::RowOrColumn* pFieldColumn = new vcl::RowOrColumn( pCurColumn, false );
pCurColumn->addChild( pFieldColumn );
aPropertyToDependencyRowMap.insert( std::pair< rtl::OUString, vcl::RowOrColumn* >( aPropertyName, pFieldColumn ) );
2009-05-22 10:19:01 +00:00
if( aText.getLength() )
{
2009-05-22 10:19:01 +00:00
// add a FixedText:
FixedText* pHeading = new FixedText( pCurParent, WB_VCENTER );
maControls.push_front( pHeading );
pHeading->SetText( aText );
pHeading->Show();
2009-04-27 09:47:17 +00:00
2009-05-22 10:19:01 +00:00
// set help id
setSmartId( pHeading, "FixedText", -1, aPropertyName );
2009-05-22 10:06:06 +00:00
2009-05-22 10:19:01 +00:00
// add to row
pFieldColumn->addWindow( pHeading );
}
2009-03-16 17:48:45 +00:00
2009-05-22 10:19:01 +00:00
if( aCtrlType.equalsAscii( "List" ) )
2009-03-16 17:48:45 +00:00
{
2009-05-22 10:19:01 +00:00
ListBox* pList = new ListBox( pCurParent, WB_DROPDOWN | WB_BORDER );
maControls.push_front( pList );
2009-03-16 17:48:45 +00:00
2009-05-22 10:19:01 +00:00
// iterate options
for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
{
pList->InsertEntry( aChoices[m] );
}
sal_Int32 nSelectVal = 0;
PropertyValue* pVal = maPController->getValue( aPropertyName );
2009-05-22 10:19:01 +00:00
if( pVal && pVal->Value.hasValue() )
pVal->Value >>= nSelectVal;
pList->SelectEntryPos( static_cast<USHORT>(nSelectVal) );
pList->Enable( maPController->isUIOptionEnabled( aPropertyName ) );
2009-05-22 10:19:01 +00:00
pList->SetSelectHdl( LINK( this, PrintDialog, UIOption_SelectHdl ) );
2009-05-25 15:12:27 +00:00
pList->SetDropDownLineCount( static_cast<USHORT>(aChoices.getLength()) );
2009-05-22 10:19:01 +00:00
pList->Show();
2009-03-16 17:48:45 +00:00
2009-05-22 10:19:01 +00:00
// set help id
setSmartId( pList, "ListBox", -1, aPropertyName );
// set help text
setHelpText( pList, aHelpTexts, 0 );
2009-04-27 09:47:17 +00:00
2009-05-22 10:19:01 +00:00
maPropertyToWindowMap.insert( std::pair< rtl::OUString, Window* >( aPropertyName, pList ) );
maControlToPropertyMap[pList] = aPropertyName;
2009-03-16 17:48:45 +00:00
2009-05-22 10:19:01 +00:00
// finish the pair
pFieldColumn->addWindow( pList );
}
else if( aCtrlType.equalsAscii( "Range" ) )
{
2009-05-22 10:19:01 +00:00
NumericField* pField = new NumericField( pCurParent, WB_BORDER | WB_SPIN );
maControls.push_front( pField );
2009-05-22 10:06:06 +00:00
2009-05-22 10:19:01 +00:00
// set min/max and current value
if( nMinValue != nMaxValue )
{
pField->SetMin( nMinValue );
pField->SetMax( nMaxValue );
}
sal_Int64 nCurVal = 0;
PropertyValue* pVal = maPController->getValue( aPropertyName );
2009-05-22 10:19:01 +00:00
if( pVal && pVal->Value.hasValue() )
pVal->Value >>= nCurVal;
pField->SetValue( nCurVal );
pField->Enable( maPController->isUIOptionEnabled( aPropertyName ) );
2009-05-22 10:19:01 +00:00
pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
pField->Show();
// set help id
2009-05-22 10:19:01 +00:00
setSmartId( pField, "NumericField", -1, aPropertyName );
// set help text
setHelpText( pField, aHelpTexts, 0 );
2009-05-22 10:19:01 +00:00
maPropertyToWindowMap.insert( std::pair< rtl::OUString, Window* >( aPropertyName, pField ) );
maControlToPropertyMap[pField] = aPropertyName;
2009-05-22 10:19:01 +00:00
// add to row
pFieldColumn->addWindow( pField );
}
else if( aCtrlType.equalsAscii( "Edit" ) )
{
Edit* pField = new Edit( pCurParent, WB_BORDER );
maControls.push_front( pField );
rtl::OUString aCurVal;
PropertyValue* pVal = maPController->getValue( aPropertyName );
2009-05-22 10:19:01 +00:00
if( pVal && pVal->Value.hasValue() )
pVal->Value >>= aCurVal;
pField->SetText( aCurVal );
pField->Enable( maPController->isUIOptionEnabled( aPropertyName ) );
2009-05-22 10:19:01 +00:00
pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) );
pField->Show();
2009-05-22 10:19:01 +00:00
// set help id
setSmartId( pField, "Edit", -1, aPropertyName );
// set help text
setHelpText( pField, aHelpTexts, 0 );
2009-05-22 10:19:01 +00:00
maPropertyToWindowMap.insert( std::pair< rtl::OUString, Window* >( aPropertyName, pField ) );
maControlToPropertyMap[pField] = aPropertyName;
2009-05-22 10:19:01 +00:00
// add to row
2009-05-27 17:40:24 +00:00
pFieldColumn->addWindow( pField, 2 );
2009-05-22 10:19:01 +00:00
}
}
2009-05-27 17:40:24 +00:00
else
{
DBG_ERROR( "Unsupported UI option" );
}
pCurColumn = pSaveCurColumn;
}
}
2009-03-26 18:54:45 +00:00
2009-07-28 19:01:04 +00:00
// print range empty (currently math only) -> hide print range and spacer line
if( maJobPage.mxPrintRange->countElements() == 0 )
{
maJobPage.mxPrintRange->show( false, false );
maJobPage.maCopySpacer.Show( FALSE );
}
2009-05-22 10:06:06 +00:00
// calculate job page
2009-07-22 17:16:34 +00:00
Size aMaxSize = maJobPage.maLayout.getOptimalSize( WINDOWSIZE_PREFERRED );
2009-05-22 10:06:06 +00:00
Size aMaxPageSize;
for( std::vector< vcl::RowOrColumn* >::iterator it = aDynamicColumns.begin();
it != aDynamicColumns.end(); ++it )
{
Size aPageSize( (*it)->getOptimalSize( WINDOWSIZE_PREFERRED ) );
if( aPageSize.Width() > aMaxPageSize.Width() )
aMaxPageSize.Width() = aPageSize.Width();
if( aPageSize.Height() > aMaxPageSize.Height() )
aMaxPageSize.Height() = aPageSize.Height();
}
if( aMaxPageSize.Width() > aMaxSize.Width() )
aMaxSize.Width() = aMaxPageSize.Width();
if( aMaxPageSize.Height() > aMaxSize.Height() )
aMaxSize.Height() = aMaxPageSize.Height();
2009-03-26 18:54:45 +00:00
// resize dialog if necessary
2009-05-22 10:06:06 +00:00
Size aTabSize = maTabCtrl.GetTabPageSizePixel();
2009-07-24 13:15:45 +00:00
maTabCtrl.SetMinimumSizePixel( maTabCtrl.GetSizePixel() );
2009-05-22 10:06:06 +00:00
if( aMaxSize.Height() > aTabSize.Height() || aMaxSize.Width() > aTabSize.Width() )
2009-03-26 18:54:45 +00:00
{
Size aCurSize( GetSizePixel() );
2009-05-22 10:06:06 +00:00
if( aMaxSize.Height() > aTabSize.Height() )
aCurSize.Height() += aMaxSize.Height() - aTabSize.Height();
if( aMaxSize.Width() > aTabSize.Width() )
{
aCurSize.Width() += aMaxSize.Width() - aTabSize.Width();
// and the tab ctrl needs more space, too
aTabSize.Width() = aMaxSize.Width();
maTabCtrl.SetSizePixel( aTabSize );
2009-07-24 13:15:45 +00:00
maTabCtrl.SetMinimumSizePixel( maTabCtrl.GetSizePixel() );
2009-05-22 10:06:06 +00:00
}
2009-03-26 18:54:45 +00:00
SetSizePixel( aCurSize );
}
2009-05-22 10:06:06 +00:00
// and finally arrange controls
aTabSize = maTabCtrl.GetTabPageSizePixel();
for( std::vector< vcl::RowOrColumn* >::iterator it = aDynamicColumns.begin();
it != aDynamicColumns.end(); ++it )
{
(*it)->setManagedArea( Rectangle( Point(), aMaxPageSize ) );
delete *it;
*it = NULL;
}
}
void PrintDialog::checkControlDependencies()
{
if( maJobPage.maCopyCountField.GetValue() > 1 )
maJobPage.maCollateBox.Enable( maJobPage.mnCollateUIMode == 0 );
else
maJobPage.maCollateBox.Enable( FALSE );
Image aImg( maJobPage.maCollateBox.IsChecked() ? maJobPage.maCollateImg : maJobPage.maNoCollateImg );
if( GetSettings().GetStyleSettings().GetFieldColor().IsDark() )
aImg = maJobPage.maCollateBox.IsChecked() ? maJobPage.maCollateHCImg : maJobPage.maNoCollateHCImg;
// adjust size of image
maJobPage.maCollateImage.SetSizePixel( aImg.GetSizePixel() );
maJobPage.maCollateImage.SetImage( aImg );
// enable setup button only for printers that can be setup
bool bHaveSetup = maPController->getPrinter()->HasSupport( SUPPORT_SETUPDIALOG );
maJobPage.maSetupButton.Enable( bHaveSetup );
if( bHaveSetup )
{
if( ! maJobPage.maSetupButton.IsVisible() )
{
Point aPrinterPos( maJobPage.maPrinters.GetPosPixel() );
Point aSetupPos( maJobPage.maSetupButton.GetPosPixel() );
Size aPrinterSize( maJobPage.maPrinters.GetSizePixel() );
aPrinterSize.Width() = aSetupPos.X() - aPrinterPos.X() - LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ).Width();
maJobPage.maPrinters.SetSizePixel( aPrinterSize );
maJobPage.maSetupButton.Show();
2009-07-27 18:42:13 +00:00
maLayout.resize();
}
}
else
{
if( maJobPage.maSetupButton.IsVisible() )
{
Point aPrinterPos( maJobPage.maPrinters.GetPosPixel() );
Point aSetupPos( maJobPage.maSetupButton.GetPosPixel() );
Size aPrinterSize( maJobPage.maPrinters.GetSizePixel() );
Size aSetupSize( maJobPage.maSetupButton.GetSizePixel() );
aPrinterSize.Width() = aSetupPos.X() + aSetupSize.Width() - aPrinterPos.X();
maJobPage.maPrinters.SetSizePixel( aPrinterSize );
maJobPage.maSetupButton.Hide();
2009-07-27 18:42:13 +00:00
maLayout.resize();
}
}
}
void PrintDialog::checkOptionalControlDependencies()
{
for( std::map< Window*, rtl::OUString >::iterator it = maControlToPropertyMap.begin();
it != maControlToPropertyMap.end(); ++it )
{
bool bShouldbeEnabled = maPController->isUIOptionEnabled( it->second );
bool bIsEnabled = it->first->IsEnabled();
// Enable does not do a change check first, so can be less cheap than expected
if( bShouldbeEnabled != bIsEnabled )
it->first->Enable( bShouldbeEnabled );
}
}
static rtl::OUString searchAndReplace( const rtl::OUString& i_rOrig, const char* i_pRepl, sal_Int32 i_nReplLen, const rtl::OUString& i_rRepl )
{
sal_Int32 nPos = i_rOrig.indexOfAsciiL( i_pRepl, i_nReplLen );
if( nPos != -1 )
{
rtl::OUStringBuffer aBuf( i_rOrig.getLength() );
aBuf.append( i_rOrig.getStr(), nPos );
aBuf.append( i_rRepl );
if( nPos + i_nReplLen < i_rOrig.getLength() )
aBuf.append( i_rOrig.getStr() + nPos + i_nReplLen );
return aBuf.makeStringAndClear();
}
return i_rOrig;
}
void PrintDialog::updatePrinterText()
{
const QueueInfo* pInfo = Printer::GetQueueInfo( maJobPage.maPrinters.GetSelectEntry(), true );
if( pInfo )
{
2009-07-22 17:16:34 +00:00
maJobPage.maLocationTxt.SetText( pInfo->GetLocation() );
maJobPage.maCommentTxt.SetText( pInfo->GetComment() );
// FIXME: status text
maJobPage.maStatusTxt.SetText( String() );
}
else
{
maJobPage.maLocationTxt.SetText( String() );
maJobPage.maCommentTxt.SetText( String() );
maJobPage.maStatusTxt.SetText( String() );
}
}
2009-06-03 19:22:35 +00:00
void PrintDialog::setPreviewText( sal_Int32 )
{
2009-03-26 18:00:43 +00:00
if( mnCachedPages != 0 )
{
rtl::OUString aNewText( searchAndReplace( maPageStr, "%n", 2, rtl::OUString::valueOf( mnCachedPages ) ) );
maNumPagesText.SetText( aNewText );
2009-03-26 18:00:43 +00:00
}
else
maNumPagesText.SetText( maNoPageStr );
}
2009-06-10 17:21:10 +00:00
void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache )
{
// page range may have changed depending on options
sal_Int32 nPages = maPController->getFilteredPageCount();
mnCachedPages = nPages;
if( mnCurPage >= nPages )
mnCurPage = nPages-1;
2009-03-26 18:00:43 +00:00
if( mnCurPage < 0 )
mnCurPage = 0;
setPreviewText( mnCurPage );
maPageEdit.SetMin( 1 );
maPageEdit.SetMax( nPages );
boost::shared_ptr<Printer> aPrt( maPController->getPrinter() );
if( i_bNewPage )
{
const MapMode aMapMode( MAP_100TH_MM );
GDIMetaFile aMtf;
2009-05-05 17:16:25 +00:00
if( nPages > 0 )
maCurPageSize = maPController->getFilteredPageFile( mnCurPage, aMtf, i_bMayUseCache );
2009-07-24 13:15:45 +00:00
else
maCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
2009-07-24 13:15:45 +00:00
maPreviewWindow.setPreview( aMtf, maCurPageSize );
}
}
2009-07-27 17:10:15 +00:00
Size PrintDialog::getJobPageSize()
{
if( maFirstPageSize.Width() == 0 && maFirstPageSize.Height() == 0)
{
maFirstPageSize = maNupPortraitSize;
GDIMetaFile aMtf;
if( maPController->getPageCount() > 0 )
maFirstPageSize = maPController->getPageFile( 0, aMtf, true );
}
return maFirstPageSize;
}
2009-03-28 08:52:14 +00:00
void PrintDialog::updateNup()
{
2009-07-27 17:10:15 +00:00
int nRows = int(maNUpPage.maNupRowsEdt.GetValue());
int nCols = int(maNUpPage.maNupColEdt.GetValue());
long nPageMargin = long(maNUpPage.maPageMarginEdt.Denormalize(maNUpPage.maPageMarginEdt.GetValue( FUNIT_100TH_MM )));
long nSheetMargin = long(maNUpPage.maSheetMarginEdt.Denormalize(maNUpPage.maSheetMarginEdt.GetValue( FUNIT_100TH_MM )));
2009-03-28 08:52:14 +00:00
PrinterController::MultiPageSetup aMPS;
2009-06-09 18:58:38 +00:00
aMPS.nRows = nRows;
aMPS.nColumns = nCols;
2009-07-27 17:10:15 +00:00
aMPS.nRepeat = 1;
aMPS.nLeftMargin =
aMPS.nTopMargin =
aMPS.nRightMargin =
aMPS.nBottomMargin = nSheetMargin;
2009-06-09 18:58:38 +00:00
2009-07-27 17:10:15 +00:00
aMPS.nHorizontalSpacing =
aMPS.nVerticalSpacing = nPageMargin;
2009-06-09 18:58:38 +00:00
aMPS.bDrawBorder = maNUpPage.maBorderCB.IsChecked();
2009-07-27 17:10:15 +00:00
int nOrientationMode = int(maNUpPage.maNupOrientationBox.GetEntryData(
maNUpPage.maNupOrientationBox.GetSelectEntryPos() ));
if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE )
{
aMPS.aPaperSize = maNupLandscapeSize;
}
else if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT )
{
aMPS.aPaperSize = maNupPortraitSize;
}
else // automatic mode
{
// get size of first real page to see if it is portrait or landscape
// we assume same page sizes for all the pages for this
Size aPageSize = getJobPageSize();
Size aMultiSize( aPageSize.Width() * nCols, aPageSize.Height() * nRows );
if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape
aMPS.aPaperSize = maNupLandscapeSize;
else
aMPS.aPaperSize = maNupPortraitSize;
}
maPController->setMultipage( aMPS );
2009-03-28 08:52:14 +00:00
2009-06-10 17:21:10 +00:00
preparePreview( true, true );
2009-03-28 08:52:14 +00:00
}
IMPL_LINK( PrintDialog, SelectHdl, ListBox*, pBox )
{
if( pBox == &maJobPage.maPrinters )
{
String aNewPrinter( pBox->GetSelectEntry() );
// set new printer
maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aNewPrinter ) ) );
// update text fields
updatePrinterText();
}
2009-07-27 17:10:15 +00:00
else if( pBox == &maNUpPage.maNupOrientationBox )
{
updateNup();
}
else if( pBox == &maNUpPage.maNupPagesBox )
{
long nPages = long(maNUpPage.maNupPagesBox.GetEntryData(maNUpPage.maNupPagesBox.GetSelectEntryPos()));
int nRows = int(maNUpPage.maNupRowsEdt.GetValue());
int nCols = int(maNUpPage.maNupColEdt.GetValue());
long nPageMargin = long(maNUpPage.maPageMarginEdt.Denormalize(maNUpPage.maPageMarginEdt.GetValue( FUNIT_100TH_MM )));
long nSheetMargin = long(maNUpPage.maSheetMarginEdt.Denormalize(maNUpPage.maSheetMarginEdt.GetValue( FUNIT_100TH_MM )));
2009-07-27 17:10:15 +00:00
bool bCustom = false;
if( nPages == 1 )
{
2009-07-27 17:10:15 +00:00
nRows = nCols = 1;
nSheetMargin = 0;
}
2009-07-27 17:10:15 +00:00
else if( nPages == 2 || nPages == 4 || nPages == 6 || nPages == 9 || nPages == 16 )
{
Size aJobPageSize( getJobPageSize() );
bool bPortrait = aJobPageSize.Width() < aJobPageSize.Height();
if( nPages == 2 )
{
if( bPortrait )
nRows = 1, nCols = 2;
else
nRows = 2, nCols = 1;
}
else if( nPages == 4 )
nRows = nCols = 2;
else if( nPages == 6 )
{
if( bPortrait )
nRows = 2, nCols = 3;
else
nRows = 3, nCols = 2;
}
else if( nPages == 9 )
nRows = nCols = 3;
else if( nPages == 16 )
nRows = nCols = 4;
nPageMargin = 500;
nSheetMargin = 500;
2009-07-27 17:10:15 +00:00
}
else
bCustom = true;
maNUpPage.maNupRowsEdt.SetValue( nRows );
maNUpPage.maNupColEdt.SetValue( nCols );
maNUpPage.maPageMarginEdt.SetValue( maNUpPage.maPageMarginEdt.Normalize( nPageMargin ), FUNIT_100TH_MM );
maNUpPage.maSheetMarginEdt.SetValue( maNUpPage.maSheetMarginEdt.Normalize( nSheetMargin ), FUNIT_100TH_MM );
2009-07-27 17:10:15 +00:00
updateNup();
2009-07-27 18:42:13 +00:00
maNUpPage.mxAdvancedControls->show( bCustom );
2009-07-27 17:10:15 +00:00
}
return 0;
}
IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton )
{
2009-06-02 11:37:36 +00:00
if( pButton == &maOKButton || pButton == &maCancelButton )
{
2009-06-02 11:37:36 +00:00
storeToSettings();
EndDialog( pButton == &maOKButton );
}
else if( pButton == &maForwardBtn )
{
previewForward();
}
else if( pButton == &maBackwardBtn )
{
previewBackward();
}
2009-07-24 13:15:45 +00:00
else if( pButton == &maOptionsPage.maToFileBox )
{
maOKButton.SetText( maOptionsPage.maToFileBox.IsChecked() ? maPrintToFileText : maPrintText );
maLayout.resize();
}
2009-07-27 18:42:13 +00:00
else if( pButton == &maJobPage.maDetailsBtn )
{
bool bShow = ! maJobPage.maStatusTxt.IsVisible();
maJobPage.maDetailsBtn.SetSymbol( bShow ? SYMBOL_SPIN_UP : SYMBOL_SPIN_DOWN );
maJobPage.mxDetails->show( bShow );
}
2009-07-16 11:37:53 +00:00
else if( pButton == &maJobPage.maCollateBox )
{
maPController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ),
makeAny( sal_Bool(isCollate()) ) );
2009-07-22 17:16:34 +00:00
checkControlDependencies();
2009-07-16 11:37:53 +00:00
}
2009-06-02 11:37:36 +00:00
else
{
if( pButton == &maJobPage.maSetupButton )
2009-06-02 11:37:36 +00:00
{
maPController->getPrinter()->Setup( this );
2009-06-02 11:37:36 +00:00
}
checkControlDependencies();
2009-07-27 17:10:15 +00:00
if( pButton == &maNUpPage.maBorderCB )
2009-06-02 11:37:36 +00:00
updateNup();
}
return 0;
}
2009-03-26 18:00:43 +00:00
IMPL_LINK( PrintDialog, ModifyHdl, Edit*, pEdit )
{
checkControlDependencies();
2009-07-27 17:10:15 +00:00
if( pEdit == &maNUpPage.maNupRowsEdt || pEdit == &maNUpPage.maNupColEdt ||
pEdit == &maNUpPage.maSheetMarginEdt || pEdit == &maNUpPage.maPageMarginEdt
2009-06-09 18:58:38 +00:00
)
2009-03-28 08:52:14 +00:00
{
updateNup();
}
else if( pEdit == &maPageEdit )
{
mnCurPage = sal_Int32( maPageEdit.GetValue() - 1 );
2009-06-10 17:21:10 +00:00
preparePreview( true, true );
}
else if( pEdit == &maJobPage.maCopyCountField )
{
maPController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CopyCount" ) ),
makeAny( sal_Int32(maJobPage.maCopyCountField.GetValue()) ) );
2009-07-16 11:37:53 +00:00
maPController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ),
makeAny( sal_Bool(isCollate()) ) );
}
return 0;
}
2009-03-18 14:52:24 +00:00
IMPL_LINK( PrintDialog, UIOptionsChanged, void*, EMPTYARG )
{
checkOptionalControlDependencies();
return 0;
}
PropertyValue* PrintDialog::getValueForWindow( Window* i_pWindow ) const
{
PropertyValue* pVal = NULL;
std::map< Window*, rtl::OUString >::const_iterator it = maControlToPropertyMap.find( i_pWindow );
if( it != maControlToPropertyMap.end() )
{
pVal = maPController->getValue( it->second );
DBG_ASSERT( pVal, "property value not found" );
}
else
{
DBG_ERROR( "changed control not in property map" );
}
return pVal;
}
IMPL_LINK( PrintDialog, UIOption_CheckHdl, CheckBox*, i_pBox )
{
PropertyValue* pVal = getValueForWindow( i_pBox );
if( pVal )
{
sal_Bool bVal = i_pBox->IsChecked();
pVal->Value <<= bVal;
checkOptionalControlDependencies();
// update preview and page settings
preparePreview();
}
return 0;
}
IMPL_LINK( PrintDialog, UIOption_RadioHdl, RadioButton*, i_pBtn )
{
// this handler gets called for all radiobuttons that get unchecked, too
// however we only want one notificaction for the new value (that is for
// the button that gets checked)
if( i_pBtn->IsChecked() )
{
PropertyValue* pVal = getValueForWindow( i_pBtn );
std::map< Window*, sal_Int32 >::const_iterator it = maControlToNumValMap.find( i_pBtn );
if( pVal && it != maControlToNumValMap.end() )
{
sal_Int32 nVal = it->second;
pVal->Value <<= nVal;
checkOptionalControlDependencies();
// update preview and page settings
preparePreview();
}
}
return 0;
}
IMPL_LINK( PrintDialog, UIOption_SelectHdl, ListBox*, i_pBox )
{
PropertyValue* pVal = getValueForWindow( i_pBox );
if( pVal )
{
sal_Int32 nVal( i_pBox->GetSelectEntryPos() );
pVal->Value <<= nVal;
checkOptionalControlDependencies();
// update preview and page settings
preparePreview();
}
return 0;
}
2009-03-16 17:48:45 +00:00
IMPL_LINK( PrintDialog, UIOption_ModifyHdl, Edit*, i_pBox )
{
PropertyValue* pVal = getValueForWindow( i_pBox );
if( pVal )
{
NumericField* pNum = dynamic_cast<NumericField*>(i_pBox);
MetricField* pMetric = dynamic_cast<MetricField*>(i_pBox);
if( pNum )
{
sal_Int64 nVal = pNum->GetValue();
pVal->Value <<= nVal;
}
else if( pMetric )
{
sal_Int64 nVal = pMetric->GetValue();
pVal->Value <<= nVal;
}
else
{
rtl::OUString aVal( i_pBox->GetText() );
pVal->Value <<= aVal;
}
checkOptionalControlDependencies();
// update preview and page settings
preparePreview();
}
return 0;
}
void PrintDialog::Command( const CommandEvent& rEvt )
{
if( rEvt.GetCommand() == COMMAND_WHEEL )
{
const CommandWheelData* pWheelData = rEvt.GetWheelData();
if( pWheelData->GetDelta() > 0 )
previewForward();
else if( pWheelData->GetDelta() < 0 )
previewBackward();
/*
else
huh ?
*/
}
}
2009-03-17 12:27:26 +00:00
void PrintDialog::Resize()
{
2009-07-24 13:15:45 +00:00
#if 0
2009-03-17 12:27:26 +00:00
Size aPixDiff( LogicToPixel( Size( 5, 5 ), MapMode( MAP_APPFONT ) ) );
Size aWindowSize( GetOutputSizePixel() );
// position buttons from lower end, right to left
Size aBtnSize( maCancelButton.GetSizePixel() );
Rectangle aBtnRect( Point( aWindowSize.Width() - aPixDiff.Width() - aBtnSize.Width(),
aWindowSize.Height() - aPixDiff.Height() - aBtnSize.Height() ),
aBtnSize );
maCancelButton.SetPosSizePixel( aBtnRect.TopLeft(), aBtnRect.GetSize() );
aBtnSize = maOKButton.GetSizePixel();
aBtnRect = Rectangle( Point( aBtnRect.Left() - aPixDiff.Width() - aBtnSize.Width(),
aWindowSize.Height() - aPixDiff.Height() - aBtnSize.Height() ),
aBtnSize );
maOKButton.SetPosSizePixel( aBtnRect.TopLeft(), aBtnRect.GetSize() );
aBtnSize = maButtonLine.GetSizePixel();
// position fixed line above buttons
aBtnRect = Rectangle( Point( 0, aBtnRect.Top() - aPixDiff.Width() - aBtnSize.Height()/2 ),
Size( aWindowSize.Width(), aBtnSize.Height() ) );
maButtonLine.SetPosSizePixel( aBtnRect.TopLeft(), aBtnRect.GetSize() );
// position tab control on upper right
aBtnSize = maTabCtrl.GetSizePixel();
aBtnRect = Rectangle( Point( aWindowSize.Width() - aPixDiff.Width() - aBtnSize.Width(),
aPixDiff.Height() ),
Size( aBtnSize.Width(), maButtonLine.GetPosPixel().Y() - 2*aPixDiff.Height() ) );
maTabCtrl.SetPosSizePixel( aBtnRect.TopLeft(), aBtnRect.GetSize() );
// set size for preview
long nMaxX = maTabCtrl.GetPosPixel().X() - 2*aPixDiff.Width();
long nMaxY = maButtonLine.GetPosPixel().Y()
- 4 * aPixDiff.Height()
- maForwardBtn.GetSizePixel().Height();
2009-03-17 12:27:26 +00:00
long nPreviewLength = std::min( nMaxX, nMaxY );
maPreviewSpace = Rectangle( Point( aPixDiff.Width(), 2 * aPixDiff.Height() ),
2009-03-17 12:27:26 +00:00
Size( nPreviewLength, nPreviewLength ) );
// position text and slider below preview, aligned
Size aPrefSize( maPreviewCtrlRow.getOptimalSize( WINDOWSIZE_PREFERRED ) );
aPrefSize.Width() = nPreviewLength - 2* aPixDiff.Width();
Point aCtrlPos( 2*aPixDiff.Width(), 3*aPixDiff.Height() + nPreviewLength );
maPreviewCtrlRow.setManagedArea( Rectangle( aCtrlPos, aPrefSize ) );
2009-06-10 12:18:55 +00:00
maPreviewBackground.Left() = aPixDiff.Width() - 2;
maPreviewBackground.Top() = aPixDiff.Height() - 2;
maPreviewBackground.Right() = aPixDiff.Width() + nPreviewLength + 2;
maPreviewBackground.Bottom() = maPreviewCtrlRow.getManagedArea().Bottom() + aPixDiff.Height();
2009-07-24 13:15:45 +00:00
#else
maLayout.setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
#endif
// and do the preview; however the metafile does not need to be gotten anew
preparePreview( false );
// do an invalidate for the benefit of the grouping elements
Invalidate();
2009-03-17 12:27:26 +00:00
}
2009-03-18 14:46:10 +00:00
void PrintDialog::previewForward()
{
maPageEdit.Up();
}
void PrintDialog::previewBackward()
{
maPageEdit.Down();
}
2009-03-18 14:46:10 +00:00
// -----------------------------------------------------------------------------
//
// PrintProgressDialog
//
// -----------------------------------------------------------------------------
PrintProgressDialog::PrintProgressDialog( Window* i_pParent, int i_nMax ) :
ModelessDialog( i_pParent, VclResId( SV_DLG_PRINT_PROGRESS ) ),
maText( this, VclResId( SV_PRINT_PROGRESS_TEXT ) ),
maButton( this, VclResId( SV_PRINT_PROGRESS_CANCEL ) ),
mbCanceled( false ),
mnCur( 0 ),
2009-03-18 16:16:06 +00:00
mnMax( i_nMax ),
mnProgressHeight( 15 ),
mbNativeProgress( false )
2009-03-18 14:46:10 +00:00
{
FreeResource();
2009-05-05 17:16:25 +00:00
if( mnMax < 1 )
mnMax = 1;
2009-03-18 14:46:10 +00:00
maStr = maText.GetText();
maButton.SetClickHdl( LINK( this, PrintProgressDialog, ClickHdl ) );
}
PrintProgressDialog::~PrintProgressDialog()
{
}
IMPL_LINK( PrintProgressDialog, ClickHdl, Button*, pButton )
{
if( pButton == &maButton )
mbCanceled = true;
return 0;
}
void PrintProgressDialog::implCalcProgressRect()
{
if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
{
ImplControlValue aValue;
2009-03-18 16:16:06 +00:00
Region aControlRegion( Rectangle( Point(), Size( 100, mnProgressHeight ) ) );
2009-03-18 14:46:10 +00:00
Region aNativeControlRegion, aNativeContentRegion;
if( GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
CTRL_STATE_ENABLED, aValue, rtl::OUString(),
aNativeControlRegion, aNativeContentRegion ) )
{
2009-03-18 16:16:06 +00:00
mnProgressHeight = aNativeControlRegion.GetBoundRect().GetHeight();
2009-03-18 14:46:10 +00:00
}
2009-03-18 16:16:06 +00:00
mbNativeProgress = true;
2009-03-18 14:46:10 +00:00
}
maProgressRect = Rectangle( Point( 10, maText.GetPosPixel().Y() + maText.GetSizePixel().Height() + 8 ),
2009-03-18 16:16:06 +00:00
Size( GetSizePixel().Width() - 20, mnProgressHeight ) );
2009-03-18 14:46:10 +00:00
}
void PrintProgressDialog::setProgress( int i_nCurrent, int i_nMax )
{
2009-03-18 16:16:06 +00:00
if( maProgressRect.IsEmpty() )
implCalcProgressRect();
2009-03-18 14:46:10 +00:00
mnCur = i_nCurrent;
if( i_nMax != -1 )
mnMax = i_nMax;
2009-05-05 17:16:25 +00:00
if( mnMax < 1 )
mnMax = 1;
rtl::OUString aNewText( searchAndReplace( maStr, "%p", 2, rtl::OUString::valueOf( mnCur ) ) );
aNewText = searchAndReplace( aNewText, "%n", 2, rtl::OUString::valueOf( mnMax ) );
2009-03-18 14:46:10 +00:00
maText.SetText( aNewText );
// update progress
2009-03-18 18:04:53 +00:00
Invalidate( maProgressRect, INVALIDATE_UPDATE );
2009-03-18 14:46:10 +00:00
}
void PrintProgressDialog::tick()
{
if( mnCur < mnMax )
setProgress( ++mnCur );
}
2009-03-18 14:52:24 +00:00
void PrintProgressDialog::Paint( const Rectangle& )
2009-03-18 14:46:10 +00:00
{
2009-05-05 17:16:25 +00:00
if( maProgressRect.IsEmpty() )
implCalcProgressRect();
2009-03-18 16:16:06 +00:00
Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
Color aPrgsColor = rStyleSettings.GetHighlightColor();
if ( aPrgsColor == rStyleSettings.GetFaceColor() )
aPrgsColor = rStyleSettings.GetDarkShadowColor();
SetLineColor();
SetFillColor( aPrgsColor );
2009-03-18 18:05:51 +00:00
const long nOffset = 3;
2009-03-18 16:16:06 +00:00
const long nWidth = 3*mnProgressHeight/2;
const long nFullWidth = nWidth + nOffset;
const long nMaxCount = maProgressRect.GetWidth() / nFullWidth;
2009-03-18 14:46:10 +00:00
DrawProgress( this, maProgressRect.TopLeft(),
2009-03-18 16:16:06 +00:00
nOffset,
nWidth,
mnProgressHeight,
2009-03-18 14:46:10 +00:00
static_cast<USHORT>(0),
2009-03-18 16:16:06 +00:00
static_cast<USHORT>(10000*mnCur/mnMax),
static_cast<USHORT>(10000/nMaxCount),
2009-03-18 14:46:10 +00:00
maProgressRect
);
2009-03-18 16:16:06 +00:00
Pop();
2009-03-18 14:46:10 +00:00
2009-03-18 16:16:06 +00:00
if( ! mbNativeProgress )
{
DecorationView aDecoView( this );
Rectangle aFrameRect( maProgressRect );
aFrameRect.Left() -= nOffset;
aFrameRect.Right() += nOffset;
aFrameRect.Top() -= nOffset;
aFrameRect.Bottom() += nOffset;
aDecoView.DrawFrame( aFrameRect );
}
2009-03-18 14:46:10 +00:00
}