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
28 #include <svl/eitem.hxx>
29
30 #include "tpprint.hxx"
31 #include "printopt.hxx"
32 #include "scmod.hxx"
33 #include "scresid.hxx"
34 #include "sc.hrc"
35 #include "optdlg.hrc"
36
37 // -----------------------------------------------------------------------
38
39 static sal_uInt16 pPrintOptRanges[] =
40 {
41 SID_SCPRINTOPTIONS,
42 SID_SCPRINTOPTIONS,
43 0
44 };
45
46 // -----------------------------------------------------------------------
47
ScTpPrintOptions(Window * pParent,const SfxItemSet & rCoreAttrs)48 ScTpPrintOptions::ScTpPrintOptions( Window* pParent,
49 const SfxItemSet& rCoreAttrs )
50 : SfxTabPage ( pParent,
51 ScResId( RID_SCPAGE_PRINT ),
52 rCoreAttrs ),
53 aPagesFL ( this, ScResId( FL_PAGES ) ),
54 aSkipEmptyPagesCB( this, ScResId( BTN_SKIPEMPTYPAGES ) ),
55 aSheetsFL ( this, ScResId( FL_SHEETS ) ),
56 aSelectedSheetsCB( this, ScResId( BTN_SELECTEDSHEETS ) )
57 {
58 FreeResource();
59 }
60
~ScTpPrintOptions()61 ScTpPrintOptions::~ScTpPrintOptions()
62 {
63 }
64
GetRanges()65 sal_uInt16* ScTpPrintOptions::GetRanges()
66 {
67 return pPrintOptRanges;
68 }
69
Create(Window * pParent,const SfxItemSet & rAttrSet)70 SfxTabPage* ScTpPrintOptions::Create( Window* pParent, const SfxItemSet& rAttrSet )
71 {
72 return new ScTpPrintOptions( pParent, rAttrSet );
73 }
74
DeactivatePage(SfxItemSet * pSetP)75 int ScTpPrintOptions::DeactivatePage( SfxItemSet* pSetP )
76 {
77 if ( pSetP )
78 FillItemSet( *pSetP );
79
80 return LEAVE_PAGE;
81 }
82
83 // -----------------------------------------------------------------------
84
Reset(const SfxItemSet & rCoreSet)85 void ScTpPrintOptions::Reset( const SfxItemSet& rCoreSet )
86 {
87 ScPrintOptions aOptions;
88
89 const SfxPoolItem* pItem;
90 if(SFX_ITEM_SET == rCoreSet.GetItemState(SID_SCPRINTOPTIONS, sal_False , &pItem))
91 aOptions = ((const ScTpPrintItem*)pItem)->GetPrintOptions();
92 else
93 {
94 // when called from print dialog and no options set, use configuration
95 aOptions = SC_MOD()->GetPrintOptions();
96 }
97
98 if ( SFX_ITEM_SET == rCoreSet.GetItemState( SID_PRINT_SELECTEDSHEET, sal_False , &pItem ) )
99 {
100 sal_Bool bChecked = ( (const SfxBoolItem*)pItem )->GetValue();
101 aSelectedSheetsCB.Check( bChecked );
102 }
103 else
104 {
105 aSelectedSheetsCB.Check( !aOptions.GetAllSheets() );
106 }
107
108 aSkipEmptyPagesCB.Check( aOptions.GetSkipEmpty() );
109 aSkipEmptyPagesCB.SaveValue();
110 aSelectedSheetsCB.SaveValue();
111 }
112
113 // -----------------------------------------------------------------------
114
FillItemSet(SfxItemSet & rCoreAttrs)115 sal_Bool ScTpPrintOptions::FillItemSet( SfxItemSet& rCoreAttrs )
116 {
117 rCoreAttrs.ClearItem( SID_PRINT_SELECTEDSHEET );
118
119 bool bSkipEmptyChanged = ( aSkipEmptyPagesCB.GetSavedValue() != aSkipEmptyPagesCB.IsChecked() );
120 bool bSelectedSheetsChanged = ( aSelectedSheetsCB.GetSavedValue() != aSelectedSheetsCB.IsChecked() );
121
122 if ( bSkipEmptyChanged || bSelectedSheetsChanged )
123 {
124 ScPrintOptions aOpt;
125 aOpt.SetSkipEmpty( aSkipEmptyPagesCB.IsChecked() );
126 aOpt.SetAllSheets( !aSelectedSheetsCB.IsChecked() );
127 rCoreAttrs.Put( ScTpPrintItem( SID_SCPRINTOPTIONS, aOpt ) );
128 if ( bSelectedSheetsChanged )
129 {
130 rCoreAttrs.Put( SfxBoolItem( SID_PRINT_SELECTEDSHEET, aSelectedSheetsCB.IsChecked() ) );
131 }
132 return sal_True;
133 }
134 else
135 {
136 return sal_False;
137 }
138 }
139
140