Update ooo320-m1
[ooovba.git] / sc / source / ui / attrdlg / tabpages.cxx
blob4b48a1ecbc90af013d8fcbc97e48d7eb193663c3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabpages.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 #include "global.hxx"
39 #include "document.hxx"
40 #include "attrib.hxx"
41 #include "scresid.hxx"
42 #include "sc.hrc"
44 #include "attrdlg.hrc"
45 #include "tabpages.hxx"
47 // STATIC DATA -----------------------------------------------------------
49 static USHORT pProtectionRanges[] =
51 SID_SCATTR_PROTECTION,
52 SID_SCATTR_PROTECTION,
56 //========================================================================
57 // Zellschutz-Tabpage:
58 //========================================================================
60 ScTabPageProtection::ScTabPageProtection( Window* pParent,
61 const SfxItemSet& rCoreAttrs )
62 : SfxTabPage ( pParent,
63 ScResId( RID_SCPAGE_PROTECTION ),
64 rCoreAttrs ),
66 aFlProtect ( this, ScResId( FL_PROTECTION ) ),
67 aBtnHideCell ( this, ScResId( BTN_HIDE_ALL ) ),
68 aBtnProtect ( this, ScResId( BTN_PROTECTED ) ),
69 aBtnHideFormula ( this, ScResId( BTN_HIDE_FORMULAR ) ),
70 aTxtHint ( this, ScResId( FT_HINT ) ),
71 aFlPrint ( this, ScResId( FL_PRINT ) ),
72 aBtnHidePrint ( this, ScResId( BTN_HIDE_PRINT ) ),
73 aTxtHint2 ( this, ScResId( FT_HINT2 ) )
75 // diese Page braucht ExchangeSupport
76 SetExchangeSupport();
78 // States werden in Reset gesetzt
79 bTriEnabled = bDontCare = bProtect = bHideForm = bHideCell = bHidePrint = FALSE;
81 aBtnProtect.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
82 aBtnHideCell.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
83 aBtnHideFormula.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
84 aBtnHidePrint.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
86 FreeResource();
89 // -----------------------------------------------------------------------
91 __EXPORT ScTabPageProtection::~ScTabPageProtection()
95 //------------------------------------------------------------------------
97 USHORT* __EXPORT ScTabPageProtection::GetRanges()
99 return pProtectionRanges;
102 // -----------------------------------------------------------------------
104 SfxTabPage* __EXPORT ScTabPageProtection::Create( Window* pParent,
105 const SfxItemSet& rAttrSet )
107 return ( new ScTabPageProtection( pParent, rAttrSet ) );
110 //------------------------------------------------------------------------
112 void __EXPORT ScTabPageProtection::Reset( const SfxItemSet& rCoreAttrs )
114 // Variablen initialisieren
116 USHORT nWhich = GetWhich( SID_SCATTR_PROTECTION );
117 const ScProtectionAttr* pProtAttr = NULL;
118 SfxItemState eItemState = rCoreAttrs.GetItemState( nWhich, FALSE,
119 (const SfxPoolItem**)&pProtAttr );
121 // handelt es sich um ein Default-Item?
122 if ( eItemState == SFX_ITEM_DEFAULT )
123 pProtAttr = (const ScProtectionAttr*)&(rCoreAttrs.Get(nWhich));
124 // bei SFX_ITEM_DONTCARE auf 0 lassen
126 bTriEnabled = ( pProtAttr == NULL ); // TriState, wenn DontCare
127 bDontCare = bTriEnabled;
128 if (bTriEnabled)
130 // Defaults, die erscheinen wenn ein TriState weggeklickt wird:
131 // (weil alles zusammen ein Attribut ist, kann auch nur alles zusammen
132 // auf DontCare stehen - #38543#)
133 bProtect = TRUE;
134 bHideForm = bHideCell = bHidePrint = FALSE;
136 else
138 bProtect = pProtAttr->GetProtection();
139 bHideCell = pProtAttr->GetHideCell();
140 bHideForm = pProtAttr->GetHideFormula();
141 bHidePrint = pProtAttr->GetHidePrint();
144 // Controls initialisieren
146 aBtnProtect .EnableTriState( bTriEnabled );
147 aBtnHideCell .EnableTriState( bTriEnabled );
148 aBtnHideFormula .EnableTriState( bTriEnabled );
149 aBtnHidePrint .EnableTriState( bTriEnabled );
151 UpdateButtons();
154 // -----------------------------------------------------------------------
156 BOOL __EXPORT ScTabPageProtection::FillItemSet( SfxItemSet& rCoreAttrs )
158 BOOL bAttrsChanged = FALSE;
159 USHORT nWhich = GetWhich( SID_SCATTR_PROTECTION );
160 const SfxPoolItem* pOldItem = GetOldItem( rCoreAttrs, SID_SCATTR_PROTECTION );
161 const SfxItemSet& rOldSet = GetItemSet();
162 SfxItemState eItemState = rOldSet.GetItemState( nWhich, FALSE );
163 ScProtectionAttr aProtAttr;
165 if ( !bDontCare )
167 aProtAttr.SetProtection( bProtect );
168 aProtAttr.SetHideCell( bHideCell );
169 aProtAttr.SetHideFormula( bHideForm );
170 aProtAttr.SetHidePrint( bHidePrint );
172 if ( bTriEnabled )
173 bAttrsChanged = TRUE; // DontCare -> richtiger Wert
174 else
175 bAttrsChanged = !pOldItem || !( aProtAttr == *(const ScProtectionAttr*)pOldItem );
178 //--------------------------------------------------
180 if ( bAttrsChanged )
181 rCoreAttrs.Put( aProtAttr );
182 else if ( eItemState == SFX_ITEM_DEFAULT )
183 rCoreAttrs.ClearItem( nWhich );
185 return bAttrsChanged;
188 //------------------------------------------------------------------------
190 int __EXPORT ScTabPageProtection::DeactivatePage( SfxItemSet* pSetP )
192 if ( pSetP )
193 FillItemSet( *pSetP );
195 return LEAVE_PAGE;
198 //------------------------------------------------------------------------
200 IMPL_LINK( ScTabPageProtection, ButtonClickHdl, TriStateBox*, pBox )
202 TriState eState = pBox->GetState();
203 if ( eState == STATE_DONTKNOW )
204 bDontCare = TRUE; // alles zusammen auf DontCare
205 else
207 bDontCare = FALSE; // DontCare ueberall aus
208 BOOL bOn = ( eState == STATE_CHECK ); // ausgewaehlter Wert
210 if ( pBox == &aBtnProtect )
211 bProtect = bOn;
212 else if ( pBox == &aBtnHideCell )
213 bHideCell = bOn;
214 else if ( pBox == &aBtnHideFormula )
215 bHideForm = bOn;
216 else if ( pBox == &aBtnHidePrint )
217 bHidePrint = bOn;
218 else
220 DBG_ERRORFILE("falscher Button");
224 UpdateButtons(); // TriState und Enable-Logik
226 return 0;
229 //------------------------------------------------------------------------
231 void ScTabPageProtection::UpdateButtons()
233 if ( bDontCare )
235 aBtnProtect.SetState( STATE_DONTKNOW );
236 aBtnHideCell.SetState( STATE_DONTKNOW );
237 aBtnHideFormula.SetState( STATE_DONTKNOW );
238 aBtnHidePrint.SetState( STATE_DONTKNOW );
240 else
242 aBtnProtect.SetState( bProtect ? STATE_CHECK : STATE_NOCHECK );
243 aBtnHideCell.SetState( bHideCell ? STATE_CHECK : STATE_NOCHECK );
244 aBtnHideFormula.SetState( bHideForm ? STATE_CHECK : STATE_NOCHECK );
245 aBtnHidePrint.SetState( bHidePrint ? STATE_CHECK : STATE_NOCHECK );
248 BOOL bEnable = ( aBtnHideCell.GetState() != STATE_CHECK );
250 aBtnProtect.Enable( bEnable );
251 aBtnHideFormula.Enable( bEnable );