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