1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 31 #undef SC_DLLIMPLEMENTATION 32 33 34 35 #include "global.hxx" 36 #include "document.hxx" 37 #include "attrib.hxx" 38 #include "scresid.hxx" 39 #include "sc.hrc" 40 41 #include "attrdlg.hrc" 42 #include "tabpages.hxx" 43 44 // STATIC DATA ----------------------------------------------------------- 45 46 static sal_uInt16 pProtectionRanges[] = 47 { 48 SID_SCATTR_PROTECTION, 49 SID_SCATTR_PROTECTION, 50 0 51 }; 52 53 //======================================================================== 54 // Zellschutz-Tabpage: 55 //======================================================================== 56 57 ScTabPageProtection::ScTabPageProtection( Window* pParent, 58 const SfxItemSet& rCoreAttrs ) 59 : SfxTabPage ( pParent, 60 ScResId( RID_SCPAGE_PROTECTION ), 61 rCoreAttrs ), 62 // 63 aFlProtect ( this, ScResId( FL_PROTECTION ) ), 64 aBtnHideCell ( this, ScResId( BTN_HIDE_ALL ) ), 65 aBtnProtect ( this, ScResId( BTN_PROTECTED ) ), 66 aBtnHideFormula ( this, ScResId( BTN_HIDE_FORMULAR ) ), 67 aTxtHint ( this, ScResId( FT_HINT ) ), 68 aFlPrint ( this, ScResId( FL_PRINT ) ), 69 aBtnHidePrint ( this, ScResId( BTN_HIDE_PRINT ) ), 70 aTxtHint2 ( this, ScResId( FT_HINT2 ) ) 71 { 72 // diese Page braucht ExchangeSupport 73 SetExchangeSupport(); 74 75 // States werden in Reset gesetzt 76 bTriEnabled = bDontCare = bProtect = bHideForm = bHideCell = bHidePrint = sal_False; 77 78 aBtnProtect.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) ); 79 aBtnHideCell.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) ); 80 aBtnHideFormula.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) ); 81 aBtnHidePrint.SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) ); 82 83 FreeResource(); 84 } 85 86 // ----------------------------------------------------------------------- 87 88 __EXPORT ScTabPageProtection::~ScTabPageProtection() 89 { 90 } 91 92 //------------------------------------------------------------------------ 93 94 sal_uInt16* __EXPORT ScTabPageProtection::GetRanges() 95 { 96 return pProtectionRanges; 97 } 98 99 // ----------------------------------------------------------------------- 100 101 SfxTabPage* __EXPORT ScTabPageProtection::Create( Window* pParent, 102 const SfxItemSet& rAttrSet ) 103 { 104 return ( new ScTabPageProtection( pParent, rAttrSet ) ); 105 } 106 107 //------------------------------------------------------------------------ 108 109 void __EXPORT ScTabPageProtection::Reset( const SfxItemSet& rCoreAttrs ) 110 { 111 // Variablen initialisieren 112 113 sal_uInt16 nWhich = GetWhich( SID_SCATTR_PROTECTION ); 114 const ScProtectionAttr* pProtAttr = NULL; 115 SfxItemState eItemState = rCoreAttrs.GetItemState( nWhich, sal_False, 116 (const SfxPoolItem**)&pProtAttr ); 117 118 // handelt es sich um ein Default-Item? 119 if ( eItemState == SFX_ITEM_DEFAULT ) 120 pProtAttr = (const ScProtectionAttr*)&(rCoreAttrs.Get(nWhich)); 121 // bei SFX_ITEM_DONTCARE auf 0 lassen 122 123 bTriEnabled = ( pProtAttr == NULL ); // TriState, wenn DontCare 124 bDontCare = bTriEnabled; 125 if (bTriEnabled) 126 { 127 // Defaults, die erscheinen wenn ein TriState weggeklickt wird: 128 // (weil alles zusammen ein Attribut ist, kann auch nur alles zusammen 129 // auf DontCare stehen - #38543#) 130 bProtect = sal_True; 131 bHideForm = bHideCell = bHidePrint = sal_False; 132 } 133 else 134 { 135 bProtect = pProtAttr->GetProtection(); 136 bHideCell = pProtAttr->GetHideCell(); 137 bHideForm = pProtAttr->GetHideFormula(); 138 bHidePrint = pProtAttr->GetHidePrint(); 139 } 140 141 // Controls initialisieren 142 143 aBtnProtect .EnableTriState( bTriEnabled ); 144 aBtnHideCell .EnableTriState( bTriEnabled ); 145 aBtnHideFormula .EnableTriState( bTriEnabled ); 146 aBtnHidePrint .EnableTriState( bTriEnabled ); 147 148 UpdateButtons(); 149 } 150 151 // ----------------------------------------------------------------------- 152 153 sal_Bool __EXPORT ScTabPageProtection::FillItemSet( SfxItemSet& rCoreAttrs ) 154 { 155 sal_Bool bAttrsChanged = sal_False; 156 sal_uInt16 nWhich = GetWhich( SID_SCATTR_PROTECTION ); 157 const SfxPoolItem* pOldItem = GetOldItem( rCoreAttrs, SID_SCATTR_PROTECTION ); 158 const SfxItemSet& rOldSet = GetItemSet(); 159 SfxItemState eItemState = rOldSet.GetItemState( nWhich, sal_False ); 160 ScProtectionAttr aProtAttr; 161 162 if ( !bDontCare ) 163 { 164 aProtAttr.SetProtection( bProtect ); 165 aProtAttr.SetHideCell( bHideCell ); 166 aProtAttr.SetHideFormula( bHideForm ); 167 aProtAttr.SetHidePrint( bHidePrint ); 168 169 if ( bTriEnabled ) 170 bAttrsChanged = sal_True; // DontCare -> richtiger Wert 171 else 172 bAttrsChanged = !pOldItem || !( aProtAttr == *(const ScProtectionAttr*)pOldItem ); 173 } 174 175 //-------------------------------------------------- 176 177 if ( bAttrsChanged ) 178 rCoreAttrs.Put( aProtAttr ); 179 else if ( eItemState == SFX_ITEM_DEFAULT ) 180 rCoreAttrs.ClearItem( nWhich ); 181 182 return bAttrsChanged; 183 } 184 185 //------------------------------------------------------------------------ 186 187 int __EXPORT ScTabPageProtection::DeactivatePage( SfxItemSet* pSetP ) 188 { 189 if ( pSetP ) 190 FillItemSet( *pSetP ); 191 192 return LEAVE_PAGE; 193 } 194 195 //------------------------------------------------------------------------ 196 197 IMPL_LINK( ScTabPageProtection, ButtonClickHdl, TriStateBox*, pBox ) 198 { 199 TriState eState = pBox->GetState(); 200 if ( eState == STATE_DONTKNOW ) 201 bDontCare = sal_True; // alles zusammen auf DontCare 202 else 203 { 204 bDontCare = sal_False; // DontCare ueberall aus 205 sal_Bool bOn = ( eState == STATE_CHECK ); // ausgewaehlter Wert 206 207 if ( pBox == &aBtnProtect ) 208 bProtect = bOn; 209 else if ( pBox == &aBtnHideCell ) 210 bHideCell = bOn; 211 else if ( pBox == &aBtnHideFormula ) 212 bHideForm = bOn; 213 else if ( pBox == &aBtnHidePrint ) 214 bHidePrint = bOn; 215 else 216 { 217 DBG_ERRORFILE("falscher Button"); 218 } 219 } 220 221 UpdateButtons(); // TriState und Enable-Logik 222 223 return 0; 224 } 225 226 //------------------------------------------------------------------------ 227 228 void ScTabPageProtection::UpdateButtons() 229 { 230 if ( bDontCare ) 231 { 232 aBtnProtect.SetState( STATE_DONTKNOW ); 233 aBtnHideCell.SetState( STATE_DONTKNOW ); 234 aBtnHideFormula.SetState( STATE_DONTKNOW ); 235 aBtnHidePrint.SetState( STATE_DONTKNOW ); 236 } 237 else 238 { 239 aBtnProtect.SetState( bProtect ? STATE_CHECK : STATE_NOCHECK ); 240 aBtnHideCell.SetState( bHideCell ? STATE_CHECK : STATE_NOCHECK ); 241 aBtnHideFormula.SetState( bHideForm ? STATE_CHECK : STATE_NOCHECK ); 242 aBtnHidePrint.SetState( bHidePrint ? STATE_CHECK : STATE_NOCHECK ); 243 } 244 245 sal_Bool bEnable = ( aBtnHideCell.GetState() != STATE_CHECK ); 246 { 247 aBtnProtect.Enable( bEnable ); 248 aBtnHideFormula.Enable( bEnable ); 249 } 250 } 251