xref: /trunk/main/sc/source/ui/optdlg/tpprint.cxx (revision b77af630)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scui.hxx"
26 
27 #undef SC_DLLIMPLEMENTATION
28 
29 #include <svl/eitem.hxx>
30 
31 #include "tpprint.hxx"
32 #include "printopt.hxx"
33 #include "scmod.hxx"
34 #include "scresid.hxx"
35 #include "sc.hrc"
36 #include "optdlg.hrc"
37 
38 // -----------------------------------------------------------------------
39 
40 static sal_uInt16 pPrintOptRanges[] =
41 {
42 	SID_SCPRINTOPTIONS,
43 	SID_SCPRINTOPTIONS,
44 	0
45 };
46 
47 // -----------------------------------------------------------------------
48 
49 ScTpPrintOptions::ScTpPrintOptions( Window*			  pParent,
50 									const SfxItemSet& rCoreAttrs )
51 	:	SfxTabPage		( pParent,
52 						  ScResId( RID_SCPAGE_PRINT ),
53 						  rCoreAttrs ),
54 		aPagesFL	     ( this, ScResId( FL_PAGES ) ),
55 		aSkipEmptyPagesCB( this, ScResId( BTN_SKIPEMPTYPAGES ) ),
56 		aSheetsFL		 ( this, ScResId( FL_SHEETS ) ),
57 		aSelectedSheetsCB( this, ScResId( BTN_SELECTEDSHEETS ) )
58 {
59 	FreeResource();
60 }
61 
62 ScTpPrintOptions::~ScTpPrintOptions()
63 {
64 }
65 
66 sal_uInt16* ScTpPrintOptions::GetRanges()
67 {
68 	return pPrintOptRanges;
69 }
70 
71 SfxTabPage* ScTpPrintOptions::Create( Window* pParent, const SfxItemSet& rAttrSet )
72 {
73 	return new ScTpPrintOptions( pParent, rAttrSet );
74 }
75 
76 int ScTpPrintOptions::DeactivatePage( SfxItemSet* pSetP )
77 {
78     if ( pSetP )
79         FillItemSet( *pSetP );
80 
81 	return LEAVE_PAGE;
82 }
83 
84 // -----------------------------------------------------------------------
85 
86 void ScTpPrintOptions::Reset( const SfxItemSet& rCoreSet )
87 {
88 	ScPrintOptions aOptions;
89 
90 	const SfxPoolItem* pItem;
91 	if(SFX_ITEM_SET == rCoreSet.GetItemState(SID_SCPRINTOPTIONS, sal_False , &pItem))
92 		aOptions = ((const ScTpPrintItem*)pItem)->GetPrintOptions();
93 	else
94 	{
95 		// when called from print dialog and no options set, use configuration
96 		aOptions = SC_MOD()->GetPrintOptions();
97 	}
98 
99     if ( SFX_ITEM_SET == rCoreSet.GetItemState( SID_PRINT_SELECTEDSHEET, sal_False , &pItem ) )
100     {
101         sal_Bool bChecked = ( (const SfxBoolItem*)pItem )->GetValue();
102         aSelectedSheetsCB.Check( bChecked );
103     }
104     else
105     {
106         aSelectedSheetsCB.Check( !aOptions.GetAllSheets() );
107     }
108 
109 	aSkipEmptyPagesCB.Check( aOptions.GetSkipEmpty() );
110 	aSkipEmptyPagesCB.SaveValue();
111 	aSelectedSheetsCB.SaveValue();
112 }
113 
114 // -----------------------------------------------------------------------
115 
116 sal_Bool ScTpPrintOptions::FillItemSet( SfxItemSet& rCoreAttrs )
117 {
118     rCoreAttrs.ClearItem( SID_PRINT_SELECTEDSHEET );
119 
120     bool bSkipEmptyChanged = ( aSkipEmptyPagesCB.GetSavedValue() != aSkipEmptyPagesCB.IsChecked() );
121     bool bSelectedSheetsChanged = ( aSelectedSheetsCB.GetSavedValue() != aSelectedSheetsCB.IsChecked() );
122 
123     if ( bSkipEmptyChanged || bSelectedSheetsChanged )
124     {
125         ScPrintOptions aOpt;
126         aOpt.SetSkipEmpty( aSkipEmptyPagesCB.IsChecked() );
127         aOpt.SetAllSheets( !aSelectedSheetsCB.IsChecked() );
128         rCoreAttrs.Put( ScTpPrintItem( SID_SCPRINTOPTIONS, aOpt ) );
129         if ( bSelectedSheetsChanged )
130         {
131             rCoreAttrs.Put( SfxBoolItem( SID_PRINT_SELECTEDSHEET, aSelectedSheetsCB.IsChecked() ) );
132         }
133         return sal_True;
134     }
135     else
136     {
137         return sal_False;
138     }
139 }
140 
141