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
29
30 #include "global.hxx"
31 #include "document.hxx"
32 #include "attrib.hxx"
33 #include "scresid.hxx"
34 #include "sc.hrc"
35
36 #include "attrdlg.hrc"
37 #include "tabpages.hxx"
38
39 // STATIC DATA -----------------------------------------------------------
40
41 static sal_uInt16 pProtectionRanges[] =
42 {
43 SID_SCATTR_PROTECTION,
44 SID_SCATTR_PROTECTION,
45 0
46 };
47
48 //========================================================================
49 // Zellschutz-Tabpage:
50 //========================================================================
51
ScTabPageProtection(Window * pParent,const SfxItemSet & rCoreAttrs)52 ScTabPageProtection::ScTabPageProtection( Window* pParent,
53 const SfxItemSet& rCoreAttrs )
54 : SfxTabPage ( pParent,
55 ScResId( RID_SCPAGE_PROTECTION ),
56 rCoreAttrs ),
57 //
58 aFlProtect ( this, ScResId( FL_PROTECTION ) ),
59 aBtnHideCell ( this, ScResId( BTN_HIDE_ALL ) ),
60 aBtnProtect ( this, ScResId( BTN_PROTECTED ) ),
61 aBtnHideFormula ( this, ScResId( BTN_HIDE_FORMULAR ) ),
62 aTxtHint ( this, ScResId( FT_HINT ) ),
63 aFlPrint ( this, ScResId( FL_PRINT ) ),
64 aBtnHidePrint ( this, ScResId( BTN_HIDE_PRINT ) ),
65 aTxtHint2 ( this, ScResId( FT_HINT2 ) )
66 {
67 // diese Page braucht ExchangeSupport
68 SetExchangeSupport();
69
70 // States werden in Reset gesetzt
71 bTriEnabled = bDontCare = bProtect = bHideForm = bHideCell = bHidePrint = sal_False;
72
73 aBtnProtect.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
74 aBtnHideCell.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
75 aBtnHideFormula.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
76 aBtnHidePrint.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
77
78 FreeResource();
79 }
80
81 // -----------------------------------------------------------------------
82
~ScTabPageProtection()83 __EXPORT ScTabPageProtection::~ScTabPageProtection()
84 {
85 }
86
87 //------------------------------------------------------------------------
88
GetRanges()89 sal_uInt16* __EXPORT ScTabPageProtection::GetRanges()
90 {
91 return pProtectionRanges;
92 }
93
94 // -----------------------------------------------------------------------
95
Create(Window * pParent,const SfxItemSet & rAttrSet)96 SfxTabPage* __EXPORT ScTabPageProtection::Create( Window* pParent,
97 const SfxItemSet& rAttrSet )
98 {
99 return ( new ScTabPageProtection( pParent, rAttrSet ) );
100 }
101
102 //------------------------------------------------------------------------
103
Reset(const SfxItemSet & rCoreAttrs)104 void __EXPORT ScTabPageProtection::Reset( const SfxItemSet& rCoreAttrs )
105 {
106 // Variablen initialisieren
107
108 sal_uInt16 nWhich = GetWhich( SID_SCATTR_PROTECTION );
109 const ScProtectionAttr* pProtAttr = NULL;
110 SfxItemState eItemState = rCoreAttrs.GetItemState( nWhich, sal_False,
111 (const SfxPoolItem**)&pProtAttr );
112
113 // handelt es sich um ein Default-Item?
114 if ( eItemState == SFX_ITEM_DEFAULT )
115 pProtAttr = (const ScProtectionAttr*)&(rCoreAttrs.Get(nWhich));
116 // bei SFX_ITEM_DONTCARE auf 0 lassen
117
118 bTriEnabled = ( pProtAttr == NULL ); // TriState, wenn DontCare
119 bDontCare = bTriEnabled;
120 if (bTriEnabled)
121 {
122 // Defaults, die erscheinen wenn ein TriState weggeklickt wird:
123 // (weil alles zusammen ein Attribut ist, kann auch nur alles zusammen
124 // auf DontCare stehen - #38543#)
125 bProtect = sal_True;
126 bHideForm = bHideCell = bHidePrint = sal_False;
127 }
128 else
129 {
130 bProtect = pProtAttr->GetProtection();
131 bHideCell = pProtAttr->GetHideCell();
132 bHideForm = pProtAttr->GetHideFormula();
133 bHidePrint = pProtAttr->GetHidePrint();
134 }
135
136 // Controls initialisieren
137
138 aBtnProtect .EnableTriState( bTriEnabled );
139 aBtnHideCell .EnableTriState( bTriEnabled );
140 aBtnHideFormula .EnableTriState( bTriEnabled );
141 aBtnHidePrint .EnableTriState( bTriEnabled );
142
143 UpdateButtons();
144 }
145
146 // -----------------------------------------------------------------------
147
FillItemSet(SfxItemSet & rCoreAttrs)148 sal_Bool __EXPORT ScTabPageProtection::FillItemSet( SfxItemSet& rCoreAttrs )
149 {
150 sal_Bool bAttrsChanged = sal_False;
151 sal_uInt16 nWhich = GetWhich( SID_SCATTR_PROTECTION );
152 const SfxPoolItem* pOldItem = GetOldItem( rCoreAttrs, SID_SCATTR_PROTECTION );
153 const SfxItemSet& rOldSet = GetItemSet();
154 SfxItemState eItemState = rOldSet.GetItemState( nWhich, sal_False );
155 ScProtectionAttr aProtAttr;
156
157 if ( !bDontCare )
158 {
159 aProtAttr.SetProtection( bProtect );
160 aProtAttr.SetHideCell( bHideCell );
161 aProtAttr.SetHideFormula( bHideForm );
162 aProtAttr.SetHidePrint( bHidePrint );
163
164 if ( bTriEnabled )
165 bAttrsChanged = sal_True; // DontCare -> richtiger Wert
166 else
167 bAttrsChanged = !pOldItem || !( aProtAttr == *(const ScProtectionAttr*)pOldItem );
168 }
169
170 //--------------------------------------------------
171
172 if ( bAttrsChanged )
173 rCoreAttrs.Put( aProtAttr );
174 else if ( eItemState == SFX_ITEM_DEFAULT )
175 rCoreAttrs.ClearItem( nWhich );
176
177 return bAttrsChanged;
178 }
179
180 //------------------------------------------------------------------------
181
DeactivatePage(SfxItemSet * pSetP)182 int __EXPORT ScTabPageProtection::DeactivatePage( SfxItemSet* pSetP )
183 {
184 if ( pSetP )
185 FillItemSet( *pSetP );
186
187 return LEAVE_PAGE;
188 }
189
190 //------------------------------------------------------------------------
191
IMPL_LINK(ScTabPageProtection,ButtonClickHdl,TriStateBox *,pBox)192 IMPL_LINK( ScTabPageProtection, ButtonClickHdl, TriStateBox*, pBox )
193 {
194 TriState eState = pBox->GetState();
195 if ( eState == STATE_DONTKNOW )
196 bDontCare = sal_True; // alles zusammen auf DontCare
197 else
198 {
199 bDontCare = sal_False; // DontCare ueberall aus
200 sal_Bool bOn = ( eState == STATE_CHECK ); // ausgewaehlter Wert
201
202 if ( pBox == &aBtnProtect )
203 bProtect = bOn;
204 else if ( pBox == &aBtnHideCell )
205 bHideCell = bOn;
206 else if ( pBox == &aBtnHideFormula )
207 bHideForm = bOn;
208 else if ( pBox == &aBtnHidePrint )
209 bHidePrint = bOn;
210 else
211 {
212 DBG_ERRORFILE("falscher Button");
213 }
214 }
215
216 UpdateButtons(); // TriState und Enable-Logik
217
218 return 0;
219 }
220
221 //------------------------------------------------------------------------
222
UpdateButtons()223 void ScTabPageProtection::UpdateButtons()
224 {
225 if ( bDontCare )
226 {
227 aBtnProtect.SetState( STATE_DONTKNOW );
228 aBtnHideCell.SetState( STATE_DONTKNOW );
229 aBtnHideFormula.SetState( STATE_DONTKNOW );
230 aBtnHidePrint.SetState( STATE_DONTKNOW );
231 }
232 else
233 {
234 aBtnProtect.SetState( bProtect ? STATE_CHECK : STATE_NOCHECK );
235 aBtnHideCell.SetState( bHideCell ? STATE_CHECK : STATE_NOCHECK );
236 aBtnHideFormula.SetState( bHideForm ? STATE_CHECK : STATE_NOCHECK );
237 aBtnHidePrint.SetState( bHidePrint ? STATE_CHECK : STATE_NOCHECK );
238 }
239
240 sal_Bool bEnable = ( aBtnHideCell.GetState() != STATE_CHECK );
241 {
242 aBtnProtect.Enable( bEnable );
243 aBtnHideFormula.Enable( bEnable );
244 }
245 }
246