xref: /aoo41x/main/sc/source/ui/optdlg/tpprint.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #undef SC_DLLIMPLEMENTATION
32 
33 #include <svl/eitem.hxx>
34 
35 #include "tpprint.hxx"
36 #include "printopt.hxx"
37 #include "scmod.hxx"
38 #include "scresid.hxx"
39 #include "sc.hrc"
40 #include "optdlg.hrc"
41 
42 // -----------------------------------------------------------------------
43 
44 static sal_uInt16 pPrintOptRanges[] =
45 {
46 	SID_SCPRINTOPTIONS,
47 	SID_SCPRINTOPTIONS,
48 	0
49 };
50 
51 // -----------------------------------------------------------------------
52 
53 ScTpPrintOptions::ScTpPrintOptions( Window*			  pParent,
54 									const SfxItemSet& rCoreAttrs )
55 	:	SfxTabPage		( pParent,
56 						  ScResId( RID_SCPAGE_PRINT ),
57 						  rCoreAttrs ),
58 		aPagesFL	     ( this, ScResId( FL_PAGES ) ),
59 		aSkipEmptyPagesCB( this, ScResId( BTN_SKIPEMPTYPAGES ) ),
60 		aSheetsFL		 ( this, ScResId( FL_SHEETS ) ),
61 		aSelectedSheetsCB( this, ScResId( BTN_SELECTEDSHEETS ) )
62 {
63 	FreeResource();
64 }
65 
66 ScTpPrintOptions::~ScTpPrintOptions()
67 {
68 }
69 
70 sal_uInt16* ScTpPrintOptions::GetRanges()
71 {
72 	return pPrintOptRanges;
73 }
74 
75 SfxTabPage* ScTpPrintOptions::Create( Window* pParent, const SfxItemSet& rAttrSet )
76 {
77 	return new ScTpPrintOptions( pParent, rAttrSet );
78 }
79 
80 int ScTpPrintOptions::DeactivatePage( SfxItemSet* pSetP )
81 {
82     if ( pSetP )
83         FillItemSet( *pSetP );
84 
85 	return LEAVE_PAGE;
86 }
87 
88 // -----------------------------------------------------------------------
89 
90 void ScTpPrintOptions::Reset( const SfxItemSet& rCoreSet )
91 {
92 	ScPrintOptions aOptions;
93 
94 	const SfxPoolItem* pItem;
95 	if(SFX_ITEM_SET == rCoreSet.GetItemState(SID_SCPRINTOPTIONS, sal_False , &pItem))
96 		aOptions = ((const ScTpPrintItem*)pItem)->GetPrintOptions();
97 	else
98 	{
99 		// when called from print dialog and no options set, use configuration
100 		aOptions = SC_MOD()->GetPrintOptions();
101 	}
102 
103     if ( SFX_ITEM_SET == rCoreSet.GetItemState( SID_PRINT_SELECTEDSHEET, sal_False , &pItem ) )
104     {
105         sal_Bool bChecked = ( (const SfxBoolItem*)pItem )->GetValue();
106         aSelectedSheetsCB.Check( bChecked );
107     }
108     else
109     {
110         aSelectedSheetsCB.Check( !aOptions.GetAllSheets() );
111     }
112 
113 	aSkipEmptyPagesCB.Check( aOptions.GetSkipEmpty() );
114 	aSkipEmptyPagesCB.SaveValue();
115 	aSelectedSheetsCB.SaveValue();
116 }
117 
118 // -----------------------------------------------------------------------
119 
120 sal_Bool ScTpPrintOptions::FillItemSet( SfxItemSet& rCoreAttrs )
121 {
122     rCoreAttrs.ClearItem( SID_PRINT_SELECTEDSHEET );
123 
124     bool bSkipEmptyChanged = ( aSkipEmptyPagesCB.GetSavedValue() != aSkipEmptyPagesCB.IsChecked() );
125     bool bSelectedSheetsChanged = ( aSelectedSheetsCB.GetSavedValue() != aSelectedSheetsCB.IsChecked() );
126 
127     if ( bSkipEmptyChanged || bSelectedSheetsChanged )
128     {
129         ScPrintOptions aOpt;
130         aOpt.SetSkipEmpty( aSkipEmptyPagesCB.IsChecked() );
131         aOpt.SetAllSheets( !aSelectedSheetsCB.IsChecked() );
132         rCoreAttrs.Put( ScTpPrintItem( SID_SCPRINTOPTIONS, aOpt ) );
133         if ( bSelectedSheetsChanged )
134         {
135             rCoreAttrs.Put( SfxBoolItem( SID_PRINT_SELECTEDSHEET, aSelectedSheetsCB.IsChecked() ) );
136         }
137         return sal_True;
138     }
139     else
140     {
141         return sal_False;
142     }
143 }
144 
145