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