Files
libreoffice/sc/source/core/tool/printopt.cxx

224 lines
6.0 KiB
C++
Raw Normal View History

2000-09-18 23:16:46 +00:00
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 23:16:46 +00:00
*
* $RCSfile: printopt.cxx,v $
2000-09-18 23:16:46 +00:00
*
* $Revision: 1.6 $
2000-09-18 23:16:46 +00:00
*
* last change: $Author: rt $ $Date: 2007-07-06 12:36:22 $
2000-09-18 23:16:46 +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 23:16:46 +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 23:16:46 +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 23:16:46 +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 23:16:46 +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 23:16:46 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sc.hxx"
2000-09-18 23:16:46 +00:00
2001-05-29 18:46:58 +00:00
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Sequence.hxx>
2000-09-18 23:16:46 +00:00
#include "printopt.hxx"
2001-05-29 18:46:58 +00:00
#include "miscuno.hxx"
2000-09-18 23:16:46 +00:00
2001-05-29 18:46:58 +00:00
using namespace utl;
using namespace rtl;
using namespace com::sun::star::uno;
2000-09-18 23:16:46 +00:00
2001-05-29 18:46:58 +00:00
// -----------------------------------------------------------------------
2000-09-18 23:16:46 +00:00
TYPEINIT1(ScTpPrintItem, SfxPoolItem);
2001-05-29 18:46:58 +00:00
// -----------------------------------------------------------------------
2000-09-18 23:16:46 +00:00
ScPrintOptions::ScPrintOptions()
{
SetDefaults();
}
2001-05-29 18:46:58 +00:00
ScPrintOptions::ScPrintOptions( const ScPrintOptions& rCpy ) :
bSkipEmpty( rCpy.bSkipEmpty ),
bAllSheets( rCpy.bAllSheets )
2000-09-18 23:16:46 +00:00
{
}
2001-05-29 18:46:58 +00:00
ScPrintOptions::~ScPrintOptions()
2000-09-18 23:16:46 +00:00
{
}
2001-05-29 18:46:58 +00:00
void ScPrintOptions::SetDefaults()
2000-09-18 23:16:46 +00:00
{
bSkipEmpty = TRUE;
bAllSheets = FALSE;
2000-09-18 23:16:46 +00:00
}
2001-05-29 18:46:58 +00:00
const ScPrintOptions& ScPrintOptions::operator=( const ScPrintOptions& rCpy )
2000-09-18 23:16:46 +00:00
{
2001-05-29 18:46:58 +00:00
bSkipEmpty = rCpy.bSkipEmpty;
bAllSheets = rCpy.bAllSheets;
return *this;
2000-09-18 23:16:46 +00:00
}
2001-05-29 18:46:58 +00:00
inline int ScPrintOptions::operator==( const ScPrintOptions& rOpt ) const
{
return bSkipEmpty == rOpt.bSkipEmpty
&& bAllSheets == rOpt.bAllSheets;
}
2000-09-18 23:16:46 +00:00
2001-05-29 18:46:58 +00:00
inline int ScPrintOptions::operator!=( const ScPrintOptions& rOpt ) const
2000-09-18 23:16:46 +00:00
{
2001-05-29 18:46:58 +00:00
return !(operator==(rOpt));
2000-09-18 23:16:46 +00:00
}
2001-05-29 18:46:58 +00:00
// -----------------------------------------------------------------------
2000-09-18 23:16:46 +00:00
ScTpPrintItem::ScTpPrintItem( USHORT nWhichP ) : SfxPoolItem( nWhichP )
2000-09-18 23:16:46 +00:00
{
}
ScTpPrintItem::ScTpPrintItem( USHORT nWhichP, const ScPrintOptions& rOpt ) :
SfxPoolItem ( nWhichP ),
2001-05-29 18:46:58 +00:00
theOptions ( rOpt )
2000-09-18 23:16:46 +00:00
{
}
2001-05-29 18:46:58 +00:00
ScTpPrintItem::ScTpPrintItem( const ScTpPrintItem& rItem ) :
SfxPoolItem ( rItem ),
theOptions ( rItem.theOptions )
2000-09-18 23:16:46 +00:00
{
}
2001-05-29 18:46:58 +00:00
ScTpPrintItem::~ScTpPrintItem()
2000-09-18 23:16:46 +00:00
{
}
2001-05-29 18:46:58 +00:00
String ScTpPrintItem::GetValueText() const
2000-09-18 23:16:46 +00:00
{
2001-05-29 18:46:58 +00:00
return String::CreateFromAscii( "ScTpPrintItem" );
2000-09-18 23:16:46 +00:00
}
2001-05-29 18:46:58 +00:00
int ScTpPrintItem::operator==( const SfxPoolItem& rItem ) const
2000-09-18 23:16:46 +00:00
{
DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
const ScTpPrintItem& rPItem = (const ScTpPrintItem&)rItem;
return ( theOptions == rPItem.theOptions );
}
2001-05-29 18:46:58 +00:00
SfxPoolItem* ScTpPrintItem::Clone( SfxItemPool * ) const
2000-09-18 23:16:46 +00:00
{
return new ScTpPrintItem( *this );
}
2001-05-29 18:46:58 +00:00
// -----------------------------------------------------------------------
2000-09-18 23:16:46 +00:00
2001-05-29 18:46:58 +00:00
#define CFGPATH_PRINT "Office.Calc/Print"
2000-09-18 23:16:46 +00:00
2001-05-29 18:46:58 +00:00
#define SCPRINTOPT_EMPTYPAGES 0
#define SCPRINTOPT_ALLSHEETS 1
#define SCPRINTOPT_COUNT 2
2000-09-18 23:16:46 +00:00
2001-05-29 18:46:58 +00:00
Sequence<OUString> ScPrintCfg::GetPropertyNames()
2000-09-18 23:16:46 +00:00
{
2001-05-29 18:46:58 +00:00
static const char* aPropNames[] =
{
"Page/EmptyPages", // SCPRINTOPT_EMPTYPAGES
"Other/AllSheets" // SCPRINTOPT_ALLSHEETS
};
Sequence<OUString> aNames(SCPRINTOPT_COUNT);
OUString* pNames = aNames.getArray();
for(int i = 0; i < SCPRINTOPT_COUNT; i++)
pNames[i] = OUString::createFromAscii(aPropNames[i]);
2000-09-18 23:16:46 +00:00
2001-05-29 18:46:58 +00:00
return aNames;
}
2000-09-18 23:16:46 +00:00
2001-05-29 18:46:58 +00:00
ScPrintCfg::ScPrintCfg() :
ConfigItem( OUString::createFromAscii( CFGPATH_PRINT ) )
{
Sequence<OUString> aNames = GetPropertyNames();
Sequence<Any> aValues = GetProperties(aNames);
// EnableNotification(aNames);
const Any* pValues = aValues.getConstArray();
DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed")
if(aValues.getLength() == aNames.getLength())
{
for(int nProp = 0; nProp < aNames.getLength(); nProp++)
{
DBG_ASSERT(pValues[nProp].hasValue(), "property value missing")
if(pValues[nProp].hasValue())
{
switch(nProp)
{
case SCPRINTOPT_EMPTYPAGES:
// reversed
SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
break;
case SCPRINTOPT_ALLSHEETS:
SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
break;
}
}
}
}
2000-09-18 23:16:46 +00:00
}
2001-05-29 18:46:58 +00:00
void ScPrintCfg::Commit()
2000-09-18 23:16:46 +00:00
{
2001-05-29 18:46:58 +00:00
Sequence<OUString> aNames = GetPropertyNames();
Sequence<Any> aValues(aNames.getLength());
Any* pValues = aValues.getArray();
2000-09-18 23:16:46 +00:00
2001-05-29 18:46:58 +00:00
for(int nProp = 0; nProp < aNames.getLength(); nProp++)
{
switch(nProp)
{
case SCPRINTOPT_EMPTYPAGES:
// reversed
ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], !GetSkipEmpty() );
break;
case SCPRINTOPT_ALLSHEETS:
ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetAllSheets() );
break;
}
}
PutProperties(aNames, aValues);
2000-09-18 23:16:46 +00:00
}
2001-05-29 18:46:58 +00:00
void ScPrintCfg::SetOptions( const ScPrintOptions& rNew )
2000-09-18 23:16:46 +00:00
{
2001-05-29 18:46:58 +00:00
*(ScPrintOptions*)this = rNew;
SetModified();
2000-09-18 23:16:46 +00:00
}
2001-05-29 18:46:58 +00:00
void ScPrintCfg::OptionsChanged()
2000-09-18 23:16:46 +00:00
{
2001-05-29 18:46:58 +00:00
SetModified();
2000-09-18 23:16:46 +00:00
}