xref: /aoo42x/main/sc/source/ui/attrdlg/tabpages.cxx (revision a479921a)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b77af630Sdamjan #include "precompiled_scui.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "global.hxx"
31cdf0e10cSrcweir #include "document.hxx"
32cdf0e10cSrcweir #include "attrib.hxx"
33cdf0e10cSrcweir #include "scresid.hxx"
34cdf0e10cSrcweir #include "sc.hrc"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "attrdlg.hrc"
37cdf0e10cSrcweir #include "tabpages.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
40cdf0e10cSrcweir 
41cdf0e10cSrcweir static sal_uInt16 pProtectionRanges[] =
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 	SID_SCATTR_PROTECTION,
44cdf0e10cSrcweir 	SID_SCATTR_PROTECTION,
45cdf0e10cSrcweir 	0
46cdf0e10cSrcweir };
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //========================================================================
49cdf0e10cSrcweir // Zellschutz-Tabpage:
50cdf0e10cSrcweir //========================================================================
51cdf0e10cSrcweir 
ScTabPageProtection(Window * pParent,const SfxItemSet & rCoreAttrs)52cdf0e10cSrcweir ScTabPageProtection::ScTabPageProtection( Window*			pParent,
53cdf0e10cSrcweir 										  const SfxItemSet& rCoreAttrs )
54cdf0e10cSrcweir 	:	SfxTabPage			( pParent,
55cdf0e10cSrcweir 							  ScResId( RID_SCPAGE_PROTECTION ),
56cdf0e10cSrcweir 							  rCoreAttrs ),
57cdf0e10cSrcweir 		//
58cdf0e10cSrcweir         aFlProtect          ( this, ScResId( FL_PROTECTION      ) ),
59cdf0e10cSrcweir 		aBtnHideCell		( this, ScResId( BTN_HIDE_ALL 		) ),
60cdf0e10cSrcweir 		aBtnProtect 		( this, ScResId( BTN_PROTECTED		) ),
61cdf0e10cSrcweir 		aBtnHideFormula 	( this, ScResId( BTN_HIDE_FORMULAR	) ),
62cdf0e10cSrcweir 		aTxtHint			( this, ScResId( FT_HINT			) ),
63cdf0e10cSrcweir         aFlPrint            ( this, ScResId( FL_PRINT           ) ),
64cdf0e10cSrcweir 		aBtnHidePrint		( this, ScResId( BTN_HIDE_PRINT		) ),
65cdf0e10cSrcweir         aTxtHint2           ( this, ScResId( FT_HINT2           ) )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	// diese Page braucht ExchangeSupport
68cdf0e10cSrcweir 	SetExchangeSupport();
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	//	States werden in Reset gesetzt
71cdf0e10cSrcweir 	bTriEnabled = bDontCare = bProtect = bHideForm = bHideCell = bHidePrint = sal_False;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	aBtnProtect.SetClickHdl(	 LINK( this, ScTabPageProtection, ButtonClickHdl ) );
74cdf0e10cSrcweir 	aBtnHideCell.SetClickHdl(	 LINK( this, ScTabPageProtection, ButtonClickHdl ) );
75cdf0e10cSrcweir 	aBtnHideFormula.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
76cdf0e10cSrcweir 	aBtnHidePrint.SetClickHdl(	 LINK( this, ScTabPageProtection, ButtonClickHdl ) );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	FreeResource();
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // -----------------------------------------------------------------------
82cdf0e10cSrcweir 
~ScTabPageProtection()83cdf0e10cSrcweir __EXPORT ScTabPageProtection::~ScTabPageProtection()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir //------------------------------------------------------------------------
88cdf0e10cSrcweir 
GetRanges()89cdf0e10cSrcweir sal_uInt16* __EXPORT ScTabPageProtection::GetRanges()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	return pProtectionRanges;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir // -----------------------------------------------------------------------
95cdf0e10cSrcweir 
Create(Window * pParent,const SfxItemSet & rAttrSet)96cdf0e10cSrcweir SfxTabPage* __EXPORT ScTabPageProtection::Create( Window*			pParent,
97cdf0e10cSrcweir 												  const SfxItemSet&	rAttrSet )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	return ( new ScTabPageProtection( pParent, rAttrSet ) );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir //------------------------------------------------------------------------
103cdf0e10cSrcweir 
Reset(const SfxItemSet & rCoreAttrs)104cdf0e10cSrcweir void __EXPORT ScTabPageProtection::Reset( const SfxItemSet& rCoreAttrs )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir 	//	Variablen initialisieren
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	sal_uInt16 nWhich = GetWhich( SID_SCATTR_PROTECTION );
109cdf0e10cSrcweir 	const ScProtectionAttr* pProtAttr = NULL;
110cdf0e10cSrcweir 	SfxItemState eItemState = rCoreAttrs.GetItemState( nWhich, sal_False,
111cdf0e10cSrcweir 										  (const SfxPoolItem**)&pProtAttr );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	// handelt es sich um ein Default-Item?
114cdf0e10cSrcweir 	if ( eItemState == SFX_ITEM_DEFAULT )
115cdf0e10cSrcweir 		pProtAttr = (const ScProtectionAttr*)&(rCoreAttrs.Get(nWhich));
116cdf0e10cSrcweir 	// bei SFX_ITEM_DONTCARE auf 0 lassen
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	bTriEnabled = ( pProtAttr == NULL );				// TriState, wenn DontCare
119cdf0e10cSrcweir 	bDontCare = bTriEnabled;
120cdf0e10cSrcweir 	if (bTriEnabled)
121cdf0e10cSrcweir 	{
122cdf0e10cSrcweir 		//	Defaults, die erscheinen wenn ein TriState weggeklickt wird:
123cdf0e10cSrcweir 		//	(weil alles zusammen ein Attribut ist, kann auch nur alles zusammen
124cdf0e10cSrcweir 		//	auf DontCare stehen - #38543#)
125cdf0e10cSrcweir 		bProtect = sal_True;
126cdf0e10cSrcweir 		bHideForm = bHideCell = bHidePrint = sal_False;
127cdf0e10cSrcweir 	}
128cdf0e10cSrcweir 	else
129cdf0e10cSrcweir 	{
130cdf0e10cSrcweir 		bProtect = pProtAttr->GetProtection();
131cdf0e10cSrcweir 		bHideCell = pProtAttr->GetHideCell();
132cdf0e10cSrcweir 		bHideForm = pProtAttr->GetHideFormula();
133cdf0e10cSrcweir 		bHidePrint = pProtAttr->GetHidePrint();
134cdf0e10cSrcweir 	}
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	//	Controls initialisieren
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	aBtnProtect		.EnableTriState( bTriEnabled );
139cdf0e10cSrcweir 	aBtnHideCell	.EnableTriState( bTriEnabled );
140cdf0e10cSrcweir 	aBtnHideFormula	.EnableTriState( bTriEnabled );
141cdf0e10cSrcweir 	aBtnHidePrint	.EnableTriState( bTriEnabled );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	UpdateButtons();
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir // -----------------------------------------------------------------------
147cdf0e10cSrcweir 
FillItemSet(SfxItemSet & rCoreAttrs)148cdf0e10cSrcweir sal_Bool __EXPORT ScTabPageProtection::FillItemSet( SfxItemSet& rCoreAttrs )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	sal_Bool 				bAttrsChanged	= sal_False;
151cdf0e10cSrcweir 	sal_uInt16				nWhich			= GetWhich( SID_SCATTR_PROTECTION );
152cdf0e10cSrcweir 	const SfxPoolItem*	pOldItem		= GetOldItem( rCoreAttrs, SID_SCATTR_PROTECTION );
153cdf0e10cSrcweir 	const SfxItemSet&	rOldSet			= GetItemSet();
154cdf0e10cSrcweir 	SfxItemState		eItemState		= rOldSet.GetItemState( nWhich, sal_False );
155cdf0e10cSrcweir 	ScProtectionAttr	aProtAttr;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	if ( !bDontCare )
158cdf0e10cSrcweir 	{
159cdf0e10cSrcweir 		aProtAttr.SetProtection( bProtect );
160cdf0e10cSrcweir 		aProtAttr.SetHideCell( bHideCell );
161cdf0e10cSrcweir 		aProtAttr.SetHideFormula( bHideForm );
162cdf0e10cSrcweir 		aProtAttr.SetHidePrint( bHidePrint );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		if ( bTriEnabled )
165cdf0e10cSrcweir 			bAttrsChanged = sal_True;					// DontCare -> richtiger Wert
166cdf0e10cSrcweir 		else
167cdf0e10cSrcweir 			bAttrsChanged = !pOldItem || !( aProtAttr == *(const ScProtectionAttr*)pOldItem );
168cdf0e10cSrcweir 	}
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	//--------------------------------------------------
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	if ( bAttrsChanged )
173cdf0e10cSrcweir 		rCoreAttrs.Put( aProtAttr );
174cdf0e10cSrcweir 	else if ( eItemState == SFX_ITEM_DEFAULT )
175cdf0e10cSrcweir 		rCoreAttrs.ClearItem( nWhich );
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	return bAttrsChanged;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir //------------------------------------------------------------------------
181cdf0e10cSrcweir 
DeactivatePage(SfxItemSet * pSetP)182cdf0e10cSrcweir int __EXPORT ScTabPageProtection::DeactivatePage( SfxItemSet* pSetP )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     if ( pSetP )
185cdf0e10cSrcweir         FillItemSet( *pSetP );
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 	return LEAVE_PAGE;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir //------------------------------------------------------------------------
191cdf0e10cSrcweir 
IMPL_LINK(ScTabPageProtection,ButtonClickHdl,TriStateBox *,pBox)192cdf0e10cSrcweir IMPL_LINK( ScTabPageProtection, ButtonClickHdl, TriStateBox*, pBox )
193cdf0e10cSrcweir {
194cdf0e10cSrcweir 	TriState eState = pBox->GetState();
195cdf0e10cSrcweir 	if ( eState == STATE_DONTKNOW )
196cdf0e10cSrcweir 		bDontCare = sal_True;							// alles zusammen auf DontCare
197cdf0e10cSrcweir 	else
198cdf0e10cSrcweir 	{
199cdf0e10cSrcweir 		bDontCare = sal_False;							// DontCare ueberall aus
200cdf0e10cSrcweir 		sal_Bool bOn = ( eState == STATE_CHECK );		// ausgewaehlter Wert
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 		if ( pBox == &aBtnProtect )
203cdf0e10cSrcweir 			bProtect = bOn;
204cdf0e10cSrcweir 		else if ( pBox == &aBtnHideCell )
205cdf0e10cSrcweir 			bHideCell = bOn;
206cdf0e10cSrcweir 		else if ( pBox == &aBtnHideFormula )
207cdf0e10cSrcweir 			bHideForm = bOn;
208cdf0e10cSrcweir 		else if ( pBox == &aBtnHidePrint )
209cdf0e10cSrcweir 			bHidePrint = bOn;
210cdf0e10cSrcweir 		else
211cdf0e10cSrcweir 		{
212cdf0e10cSrcweir 			DBG_ERRORFILE("falscher Button");
213cdf0e10cSrcweir 		}
214cdf0e10cSrcweir 	}
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	UpdateButtons();		// TriState und Enable-Logik
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 	return 0;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir //------------------------------------------------------------------------
222cdf0e10cSrcweir 
UpdateButtons()223cdf0e10cSrcweir void ScTabPageProtection::UpdateButtons()
224cdf0e10cSrcweir {
225cdf0e10cSrcweir 	if ( bDontCare )
226cdf0e10cSrcweir 	{
227cdf0e10cSrcweir 		aBtnProtect.SetState( STATE_DONTKNOW );
228cdf0e10cSrcweir 		aBtnHideCell.SetState( STATE_DONTKNOW );
229cdf0e10cSrcweir 		aBtnHideFormula.SetState( STATE_DONTKNOW );
230cdf0e10cSrcweir 		aBtnHidePrint.SetState( STATE_DONTKNOW );
231cdf0e10cSrcweir 	}
232cdf0e10cSrcweir 	else
233cdf0e10cSrcweir 	{
234cdf0e10cSrcweir 		aBtnProtect.SetState( bProtect ? STATE_CHECK : STATE_NOCHECK );
235cdf0e10cSrcweir 		aBtnHideCell.SetState( bHideCell ? STATE_CHECK : STATE_NOCHECK );
236cdf0e10cSrcweir 		aBtnHideFormula.SetState( bHideForm ? STATE_CHECK : STATE_NOCHECK );
237cdf0e10cSrcweir 		aBtnHidePrint.SetState( bHidePrint ? STATE_CHECK : STATE_NOCHECK );
238cdf0e10cSrcweir 	}
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 	sal_Bool bEnable = ( aBtnHideCell.GetState() != STATE_CHECK );
241cdf0e10cSrcweir 	{
242cdf0e10cSrcweir 		aBtnProtect.Enable( bEnable );
243cdf0e10cSrcweir 		aBtnHideFormula.Enable( bEnable );
244cdf0e10cSrcweir 	}
245cdf0e10cSrcweir }
246