1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "sfx2/securitypage.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "securitypage.hrc" 34*cdf0e10cSrcweir #include "sfxresid.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <sfx2/sfx.hrc> 37*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc> 38*cdf0e10cSrcweir #include <sfx2/objsh.hxx> 39*cdf0e10cSrcweir #include <sfx2/viewsh.hxx> 40*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 41*cdf0e10cSrcweir #include <sfx2/passwd.hxx> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include <vcl/button.hxx> 44*cdf0e10cSrcweir #include <vcl/edit.hxx> 45*cdf0e10cSrcweir #include <vcl/fixed.hxx> 46*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 47*cdf0e10cSrcweir #include <svl/eitem.hxx> 48*cdf0e10cSrcweir #include <svl/poolitem.hxx> 49*cdf0e10cSrcweir #include <svl/intitem.hxx> 50*cdf0e10cSrcweir #include <svl/PasswordHelper.hxx> 51*cdf0e10cSrcweir #include <svtools/xwindowitem.hxx> 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir using namespace ::com::sun::star; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir namespace 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir enum RedliningMode { RL_NONE, RL_WRITER, RL_CALC }; 62*cdf0e10cSrcweir enum RedlineFunc { RF_ON, RF_PROTECT }; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir /* 65*cdf0e10cSrcweir bool QueryIsEnabled( sal_uInt16 _nSlot ) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir bool bRes = false; 68*cdf0e10cSrcweir SfxViewShell* pViewSh = SfxViewShell::Current(); 69*cdf0e10cSrcweir if (pViewSh) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir const SfxPoolItem* pItem; 72*cdf0e10cSrcweir SfxDispatcher* pDisp = pViewSh->GetDispatcher(); 73*cdf0e10cSrcweir SfxItemState eState = pDisp->QueryState( _nSlot, pItem ); 74*cdf0e10cSrcweir bRes = (eState & SFX_ITEM_DISABLED) == 0; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir return bRes; 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir */ 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir bool QueryState( sal_uInt16 _nSlot, bool& _rValue ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir bool bRet = false; 83*cdf0e10cSrcweir SfxViewShell* pViewSh = SfxViewShell::Current(); 84*cdf0e10cSrcweir if (pViewSh) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir const SfxPoolItem* pItem; 87*cdf0e10cSrcweir SfxDispatcher* pDisp = pViewSh->GetDispatcher(); 88*cdf0e10cSrcweir SfxItemState nState = pDisp->QueryState( _nSlot, pItem ); 89*cdf0e10cSrcweir bRet = SFX_ITEM_AVAILABLE <= nState; 90*cdf0e10cSrcweir if (bRet) 91*cdf0e10cSrcweir _rValue = ( static_cast< const SfxBoolItem* >( pItem ) )->GetValue(); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir return bRet; 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir bool QueryRecordChangesProtectionState( RedliningMode _eMode, bool& _rValue ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir bool bRet = false; 100*cdf0e10cSrcweir if (_eMode != RL_NONE) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir sal_uInt16 nSlot = _eMode == RL_WRITER ? FN_REDLINE_PROTECT : SID_CHG_PROTECT; 103*cdf0e10cSrcweir bRet = QueryState( nSlot, _rValue ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir return bRet; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir bool QueryRecordChangesState( RedliningMode _eMode, bool& _rValue ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir bool bRet = false; 112*cdf0e10cSrcweir if (_eMode != RL_NONE) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir sal_uInt16 nSlot = _eMode == RL_WRITER ? FN_REDLINE_ON : FID_CHG_RECORD; 115*cdf0e10cSrcweir bRet = QueryState( nSlot, _rValue ); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir return bRet; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir static short lcl_GetPassword( 126*cdf0e10cSrcweir Window *pParent, 127*cdf0e10cSrcweir bool bProtect, 128*cdf0e10cSrcweir /*out*/String &rPassword ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir bool bRes = false; 131*cdf0e10cSrcweir SfxPasswordDialog aPasswdDlg( pParent ); 132*cdf0e10cSrcweir const String aTitle( SfxResId( bProtect ? RID_SFX_PROTECT_RECORDS : RID_SFX_UNPROTECT_RECORDS ) ); 133*cdf0e10cSrcweir aPasswdDlg.SetText( aTitle ); 134*cdf0e10cSrcweir aPasswdDlg.SetMinLen( 1 ); 135*cdf0e10cSrcweir if (bProtect) 136*cdf0e10cSrcweir aPasswdDlg.ShowExtras( SHOWEXTRAS_CONFIRM ); 137*cdf0e10cSrcweir if (RET_OK == aPasswdDlg.Execute() && aPasswdDlg.GetPassword().Len() > 0) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir rPassword = aPasswdDlg.GetPassword(); 140*cdf0e10cSrcweir bRes = true; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir return bRes; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir static bool lcl_IsPasswordCorrect( const String &rPassword ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir bool bRes = false; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir SfxObjectShell* pCurDocShell = SfxObjectShell::Current(); 151*cdf0e10cSrcweir uno::Sequence< sal_Int8 > aPasswordHash; 152*cdf0e10cSrcweir pCurDocShell->GetProtectionHash( aPasswordHash ); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // check if supplied password was correct 155*cdf0e10cSrcweir uno::Sequence< sal_Int8 > aNewPasswd( aPasswordHash ); 156*cdf0e10cSrcweir SvPasswordHelper::GetHashPassword( aNewPasswd, rPassword ); 157*cdf0e10cSrcweir if (SvPasswordHelper::CompareHashPassword( aPasswordHash, rPassword )) 158*cdf0e10cSrcweir bRes = true; // password was correct 159*cdf0e10cSrcweir else 160*cdf0e10cSrcweir InfoBox( NULL, String( SfxResId( RID_SFX_INCORRECT_PASSWORD ) ) ).Execute(); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir return bRes; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir struct SfxSecurityPage_Impl 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir SfxSecurityPage & m_rMyTabPage; 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir FixedLine m_aNewPasswordToOpenFL; 174*cdf0e10cSrcweir FixedText m_aNewPasswordToOpenFT; 175*cdf0e10cSrcweir Edit m_aNewPasswordToOpenED; 176*cdf0e10cSrcweir FixedText m_aConfirmPasswordToOpenFT; 177*cdf0e10cSrcweir Edit m_aConfirmPasswordToOpenED; 178*cdf0e10cSrcweir FixedText m_aNewPasswordInfoFT; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir FixedLine m_aNewPasswordToModifyFL; 181*cdf0e10cSrcweir FixedText m_aNewPasswordToModifyFT; 182*cdf0e10cSrcweir Edit m_aNewPasswordToModifyED; 183*cdf0e10cSrcweir FixedText m_aConfirmPasswordToModifyFT; 184*cdf0e10cSrcweir Edit m_aConfirmPasswordToModifyED; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir FixedLine m_aOptionsFL; 187*cdf0e10cSrcweir CheckBox m_aOpenReadonlyCB; 188*cdf0e10cSrcweir CheckBox m_aRecordChangesCB; // for record changes 189*cdf0e10cSrcweir PushButton m_aChangeProtectionPB; // for record changes 190*cdf0e10cSrcweir String m_aProtectSTR; // for record changes 191*cdf0e10cSrcweir String m_aUnProtectSTR; // for record changes 192*cdf0e10cSrcweir RedliningMode m_eRedlingMode; // for record changes 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir bool m_bOrigPasswordIsConfirmed; 195*cdf0e10cSrcweir bool m_bNewPasswordIsValid; 196*cdf0e10cSrcweir String m_aNewPassword; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir String m_aEndRedliningWarning; 199*cdf0e10cSrcweir bool m_bEndRedliningWarningDone; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir DECL_LINK( RecordChangesCBToggleHdl, void* ); 202*cdf0e10cSrcweir DECL_LINK( ChangeProtectionPBHdl, void* ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir SfxSecurityPage_Impl( SfxSecurityPage &rDlg, const SfxItemSet &rItemSet ); 205*cdf0e10cSrcweir ~SfxSecurityPage_Impl(); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir sal_Bool FillItemSet_Impl( SfxItemSet & ); 208*cdf0e10cSrcweir void Reset_Impl( const SfxItemSet & ); 209*cdf0e10cSrcweir }; 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir SfxSecurityPage_Impl::SfxSecurityPage_Impl( SfxSecurityPage &rTabPage, const SfxItemSet & ) : 213*cdf0e10cSrcweir m_rMyTabPage (rTabPage), 214*cdf0e10cSrcweir m_aNewPasswordToOpenFL (&rTabPage, SfxResId( PASSWORD_TO_OPEN_FL ) ), 215*cdf0e10cSrcweir m_aNewPasswordToOpenFT (&rTabPage, SfxResId( PASSWORD_TO_OPEN_FT ) ), 216*cdf0e10cSrcweir m_aNewPasswordToOpenED (&rTabPage, SfxResId( PASSWORD_TO_OPEN_ED ) ), 217*cdf0e10cSrcweir m_aConfirmPasswordToOpenFT (&rTabPage, SfxResId( CONFIRM_PASSWORD_TO_OPEN_FT ) ), 218*cdf0e10cSrcweir m_aConfirmPasswordToOpenED (&rTabPage, SfxResId( CONFIRM_PASSWORD_TO_OPEN_ED ) ), 219*cdf0e10cSrcweir m_aNewPasswordInfoFT (&rTabPage, SfxResId( PASSWORD_INFO_FT ) ), 220*cdf0e10cSrcweir m_aNewPasswordToModifyFL (&rTabPage, SfxResId( PASSWORD_TO_MODIFY_FL ) ), 221*cdf0e10cSrcweir m_aNewPasswordToModifyFT (&rTabPage, SfxResId( PASSWORD_TO_MODIFY_FT ) ), 222*cdf0e10cSrcweir m_aNewPasswordToModifyED (&rTabPage, SfxResId( PASSWORD_TO_MODIFY_ED ) ), 223*cdf0e10cSrcweir m_aConfirmPasswordToModifyFT (&rTabPage, SfxResId( CONFIRM_PASSWORD_TO_MODIFY_FT ) ), 224*cdf0e10cSrcweir m_aConfirmPasswordToModifyED (&rTabPage, SfxResId( CONFIRM_PASSWORD_TO_MODIFY_ED ) ), 225*cdf0e10cSrcweir m_aOptionsFL (&rTabPage, SfxResId( OPTIONS_FL ) ), 226*cdf0e10cSrcweir m_aOpenReadonlyCB (&rTabPage, SfxResId( OPEN_READONLY_CB ) ), 227*cdf0e10cSrcweir m_aRecordChangesCB (&rTabPage, SfxResId( RECORD_CHANGES_CB ) ), 228*cdf0e10cSrcweir m_aChangeProtectionPB (&rTabPage, SfxResId( CHANGE_PROTECTION_PB ) ), 229*cdf0e10cSrcweir m_aProtectSTR ( SfxResId( STR_PROTECT ) ), 230*cdf0e10cSrcweir m_aUnProtectSTR ( SfxResId( STR_UNPROTECT ) ), 231*cdf0e10cSrcweir m_eRedlingMode ( RL_NONE ), 232*cdf0e10cSrcweir m_bOrigPasswordIsConfirmed ( false ), 233*cdf0e10cSrcweir m_bNewPasswordIsValid ( false ), 234*cdf0e10cSrcweir m_aEndRedliningWarning ( SfxResId( STR_END_REDLINING_WARNING ) ), 235*cdf0e10cSrcweir m_bEndRedliningWarningDone ( false ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir m_aChangeProtectionPB.SetText( m_aProtectSTR ); 238*cdf0e10cSrcweir // adjust button width if necessary 239*cdf0e10cSrcweir long nBtnTextWidth = 0; 240*cdf0e10cSrcweir long nTemp = m_aChangeProtectionPB.GetCtrlTextWidth( m_aChangeProtectionPB.GetText() ); 241*cdf0e10cSrcweir if (nTemp > nBtnTextWidth) 242*cdf0e10cSrcweir nBtnTextWidth = nTemp; 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir // force toggle hdl called before visual change of checkbox 245*cdf0e10cSrcweir m_aRecordChangesCB.SetStyle( m_aRecordChangesCB.GetStyle() | WB_EARLYTOGGLE ); 246*cdf0e10cSrcweir m_aRecordChangesCB.SetToggleHdl( LINK( this, SfxSecurityPage_Impl, RecordChangesCBToggleHdl ) ); 247*cdf0e10cSrcweir m_aChangeProtectionPB.SetClickHdl( LINK( this, SfxSecurityPage_Impl, ChangeProtectionPBHdl ) ); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir // #i112277: for the time being (OOO 3.3) the following options should not 251*cdf0e10cSrcweir // be available. In the long run however it is planned to implement the yet 252*cdf0e10cSrcweir // missing functionality. Thus now we hide them and move the remaining ones up. 253*cdf0e10cSrcweir m_aNewPasswordToOpenFL.Hide(); 254*cdf0e10cSrcweir m_aNewPasswordToOpenFT.Hide(); 255*cdf0e10cSrcweir m_aNewPasswordToOpenED.Hide(); 256*cdf0e10cSrcweir m_aConfirmPasswordToOpenFT.Hide(); 257*cdf0e10cSrcweir m_aConfirmPasswordToOpenED.Hide(); 258*cdf0e10cSrcweir m_aNewPasswordInfoFT.Hide(); 259*cdf0e10cSrcweir m_aNewPasswordToModifyFL.Hide(); 260*cdf0e10cSrcweir m_aNewPasswordToModifyFT.Hide(); 261*cdf0e10cSrcweir m_aNewPasswordToModifyED.Hide(); 262*cdf0e10cSrcweir m_aConfirmPasswordToModifyFT.Hide(); 263*cdf0e10cSrcweir m_aConfirmPasswordToModifyED.Hide(); 264*cdf0e10cSrcweir const long nDelta = m_aOptionsFL.GetPosPixel().Y() - m_aNewPasswordToOpenFL.GetPosPixel().Y(); 265*cdf0e10cSrcweir Point aPos; 266*cdf0e10cSrcweir aPos = m_aOptionsFL.GetPosPixel(); 267*cdf0e10cSrcweir aPos.Y() -= nDelta; 268*cdf0e10cSrcweir m_aOptionsFL.SetPosPixel( aPos ); 269*cdf0e10cSrcweir aPos = m_aOpenReadonlyCB.GetPosPixel(); 270*cdf0e10cSrcweir aPos.Y() -= nDelta; 271*cdf0e10cSrcweir m_aOpenReadonlyCB.SetPosPixel( aPos ); 272*cdf0e10cSrcweir aPos = m_aRecordChangesCB.GetPosPixel(); 273*cdf0e10cSrcweir aPos.Y() -= nDelta; 274*cdf0e10cSrcweir m_aRecordChangesCB.SetPosPixel( aPos ); 275*cdf0e10cSrcweir aPos = m_aChangeProtectionPB.GetPosPixel(); 276*cdf0e10cSrcweir aPos.Y() -= nDelta; 277*cdf0e10cSrcweir m_aChangeProtectionPB.SetPosPixel( aPos ); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir SfxSecurityPage_Impl::~SfxSecurityPage_Impl() 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir sal_Bool SfxSecurityPage_Impl::FillItemSet_Impl( SfxItemSet & ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir bool bModified = false; 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir SfxObjectShell* pCurDocShell = SfxObjectShell::Current(); 291*cdf0e10cSrcweir if (pCurDocShell&& !pCurDocShell->IsReadOnly()) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir if (m_eRedlingMode != RL_NONE ) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir const bool bDoRecordChanges = m_aRecordChangesCB.IsChecked(); 296*cdf0e10cSrcweir const bool bDoChangeProtection = m_aChangeProtectionPB.GetText() != m_aProtectSTR; 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir // sanity checks 299*cdf0e10cSrcweir DBG_ASSERT( bDoRecordChanges || !bDoChangeProtection, "no change recording should imply no change protection" ); 300*cdf0e10cSrcweir DBG_ASSERT( bDoChangeProtection || !bDoRecordChanges, "no change protection should imply no change recording" ); 301*cdf0e10cSrcweir DBG_ASSERT( !bDoChangeProtection || m_aNewPassword.Len() > 0, "change protection should imply password length is > 0" ); 302*cdf0e10cSrcweir DBG_ASSERT( bDoChangeProtection || m_aNewPassword.Len() == 0, "no change protection should imply password length is 0" ); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir // change recording 305*cdf0e10cSrcweir if (bDoRecordChanges != pCurDocShell->IsChangeRecording()) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir pCurDocShell->SetChangeRecording( bDoRecordChanges ); 308*cdf0e10cSrcweir bModified = true; 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir // change record protection 312*cdf0e10cSrcweir if (m_bNewPasswordIsValid && 313*cdf0e10cSrcweir bDoChangeProtection != pCurDocShell->HasChangeRecordProtection()) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir DBG_ASSERT( !bDoChangeProtection || bDoRecordChanges, 316*cdf0e10cSrcweir "change protection requires record changes to be active!" ); 317*cdf0e10cSrcweir pCurDocShell->SetProtectionPassword( m_aNewPassword ); 318*cdf0e10cSrcweir bModified = true; 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir // open read-only? 323*cdf0e10cSrcweir const sal_Bool bDoOpenReadonly = m_aOpenReadonlyCB.IsChecked(); 324*cdf0e10cSrcweir if (pCurDocShell->HasSecurityOptOpenReadOnly() && 325*cdf0e10cSrcweir bDoOpenReadonly != pCurDocShell->IsSecurityOptOpenReadOnly()) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir pCurDocShell->SetSecurityOptOpenReadOnly( bDoOpenReadonly ); 328*cdf0e10cSrcweir bModified = true; 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir return bModified; 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir void SfxSecurityPage_Impl::Reset_Impl( const SfxItemSet & ) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir SfxObjectShell* pCurDocShell = SfxObjectShell::Current(); 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir String sNewText = m_aProtectSTR; 341*cdf0e10cSrcweir if (!pCurDocShell) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir // no doc -> hide document settings 344*cdf0e10cSrcweir m_aOpenReadonlyCB.Disable(); 345*cdf0e10cSrcweir m_aRecordChangesCB.Disable(); 346*cdf0e10cSrcweir m_aChangeProtectionPB.Disable(); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir else 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir bool bIsHTMLDoc = false; 351*cdf0e10cSrcweir SfxViewShell* pViewSh = SfxViewShell::Current(); 352*cdf0e10cSrcweir if (pViewSh) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir const SfxPoolItem* pItem; 355*cdf0e10cSrcweir SfxDispatcher* pDisp = pViewSh->GetDispatcher(); 356*cdf0e10cSrcweir if (SFX_ITEM_AVAILABLE <= pDisp->QueryState( SID_HTML_MODE, pItem )) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir sal_uInt16 nMode = static_cast< const SfxUInt16Item* >( pItem )->GetValue(); 359*cdf0e10cSrcweir bIsHTMLDoc = ( ( nMode & HTMLMODE_ON ) != 0 ); 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir sal_Bool bIsReadonly = pCurDocShell->IsReadOnly(); 364*cdf0e10cSrcweir if (pCurDocShell->HasSecurityOptOpenReadOnly() && !bIsHTMLDoc) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir m_aOpenReadonlyCB.Check( pCurDocShell->IsSecurityOptOpenReadOnly() ); 367*cdf0e10cSrcweir m_aOpenReadonlyCB.Enable( !bIsReadonly ); 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir else 370*cdf0e10cSrcweir m_aOpenReadonlyCB.Disable(); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir bool bRecordChanges; 373*cdf0e10cSrcweir if (QueryRecordChangesState( RL_WRITER, bRecordChanges ) && !bIsHTMLDoc) 374*cdf0e10cSrcweir m_eRedlingMode = RL_WRITER; 375*cdf0e10cSrcweir else if (QueryRecordChangesState( RL_CALC, bRecordChanges )) 376*cdf0e10cSrcweir m_eRedlingMode = RL_CALC; 377*cdf0e10cSrcweir else 378*cdf0e10cSrcweir m_eRedlingMode = RL_NONE; 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir if (m_eRedlingMode != RL_NONE) 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir bool bProtection; 383*cdf0e10cSrcweir QueryRecordChangesProtectionState( m_eRedlingMode, bProtection ); 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir m_aChangeProtectionPB.Enable( !bIsReadonly ); 386*cdf0e10cSrcweir // set the right text 387*cdf0e10cSrcweir if (bProtection) 388*cdf0e10cSrcweir sNewText = m_aUnProtectSTR; 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir m_aRecordChangesCB.Check( bRecordChanges ); 391*cdf0e10cSrcweir m_aRecordChangesCB.Enable( /*!bProtection && */!bIsReadonly ); 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir m_bOrigPasswordIsConfirmed = true; // default case if no password is set 394*cdf0e10cSrcweir uno::Sequence< sal_Int8 > aPasswordHash; 395*cdf0e10cSrcweir // check if password is available 396*cdf0e10cSrcweir if (pCurDocShell->GetProtectionHash( aPasswordHash ) && 397*cdf0e10cSrcweir aPasswordHash.getLength() > 0) 398*cdf0e10cSrcweir m_bOrigPasswordIsConfirmed = false; // password found, needs to be confirmed later on 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir else 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir // A Calc document that is shared will have 'm_eRedlingMode == RL_NONE' 403*cdf0e10cSrcweir // In shared documents change recording and protection must be disabled, 404*cdf0e10cSrcweir // similar to documents that do not support change recording at all. 405*cdf0e10cSrcweir m_aRecordChangesCB.Check( sal_False ); 406*cdf0e10cSrcweir m_aRecordChangesCB.Disable(); 407*cdf0e10cSrcweir m_aChangeProtectionPB.Check( sal_False ); 408*cdf0e10cSrcweir m_aChangeProtectionPB.Disable(); 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir m_aChangeProtectionPB.SetText( sNewText ); 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir IMPL_LINK( SfxSecurityPage_Impl, RecordChangesCBToggleHdl, void*, EMPTYARG ) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir // when change recording gets disabled protection must be disabled as well 419*cdf0e10cSrcweir if (!m_aRecordChangesCB.IsChecked()) // the new check state is already present, thus the '!' 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir bool bAlreadyDone = false; 422*cdf0e10cSrcweir if (!m_bEndRedliningWarningDone) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir WarningBox aBox( m_rMyTabPage.GetParent(), WinBits(WB_YES_NO | WB_DEF_NO), 425*cdf0e10cSrcweir m_aEndRedliningWarning ); 426*cdf0e10cSrcweir if (aBox.Execute() != RET_YES) 427*cdf0e10cSrcweir bAlreadyDone = true; 428*cdf0e10cSrcweir else 429*cdf0e10cSrcweir m_bEndRedliningWarningDone = true; 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir const bool bNeedPasssword = !m_bOrigPasswordIsConfirmed 433*cdf0e10cSrcweir && m_aChangeProtectionPB.GetText() != m_aProtectSTR; 434*cdf0e10cSrcweir if (!bAlreadyDone && bNeedPasssword) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir String aPasswordText; 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir // dialog canceled or no password provided 439*cdf0e10cSrcweir if (!lcl_GetPassword( m_rMyTabPage.GetParent(), false, aPasswordText )) 440*cdf0e10cSrcweir bAlreadyDone = true; 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir // ask for password and if dialog is canceled or no password provided return 443*cdf0e10cSrcweir if (lcl_IsPasswordCorrect( aPasswordText )) 444*cdf0e10cSrcweir m_bOrigPasswordIsConfirmed = true; 445*cdf0e10cSrcweir else 446*cdf0e10cSrcweir bAlreadyDone = true; 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir if (bAlreadyDone) 450*cdf0e10cSrcweir m_aRecordChangesCB.Check( true ); // restore original state 451*cdf0e10cSrcweir else 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir // remember required values to change protection and change recording in 454*cdf0e10cSrcweir // FillItemSet_Impl later on if password was correct. 455*cdf0e10cSrcweir m_bNewPasswordIsValid = true; 456*cdf0e10cSrcweir m_aNewPassword = String(); 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir m_aChangeProtectionPB.SetText( m_aProtectSTR ); 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir return 0; 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir IMPL_LINK( SfxSecurityPage_Impl, ChangeProtectionPBHdl, void*, EMPTYARG ) 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir if (m_eRedlingMode == RL_NONE) 469*cdf0e10cSrcweir return 0; 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir // the push button text is always the opposite of the current state. Thus: 472*cdf0e10cSrcweir const bool bCurrentProtection = m_aChangeProtectionPB.GetText() != m_aProtectSTR; 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir // ask user for password (if still necessary) 475*cdf0e10cSrcweir String aPasswordText; 476*cdf0e10cSrcweir bool bNewProtection = !bCurrentProtection; 477*cdf0e10cSrcweir const bool bNeedPassword = bNewProtection || !m_bOrigPasswordIsConfirmed; 478*cdf0e10cSrcweir if (bNeedPassword) 479*cdf0e10cSrcweir { 480*cdf0e10cSrcweir // ask for password and if dialog is canceled or no password provided return 481*cdf0e10cSrcweir if (!lcl_GetPassword( m_rMyTabPage.GetParent(), bNewProtection, aPasswordText )) 482*cdf0e10cSrcweir return 0; 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir // provided password still needs to be checked? 485*cdf0e10cSrcweir if (!bNewProtection && !m_bOrigPasswordIsConfirmed) 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir if (lcl_IsPasswordCorrect( aPasswordText )) 488*cdf0e10cSrcweir m_bOrigPasswordIsConfirmed = true; 489*cdf0e10cSrcweir else 490*cdf0e10cSrcweir return 0; 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir DBG_ASSERT( m_bOrigPasswordIsConfirmed, "ooops... this should not have happened!" ); 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir // remember required values to change protection and change recording in 496*cdf0e10cSrcweir // FillItemSet_Impl later on if password was correct. 497*cdf0e10cSrcweir m_bNewPasswordIsValid = true; 498*cdf0e10cSrcweir m_aNewPassword = bNewProtection? aPasswordText : String(); 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir // // RecordChangesCB is enabled if protection is off 501*cdf0e10cSrcweir // m_aRecordChangesCB.Enable( !bNewProtection ); 502*cdf0e10cSrcweir m_aRecordChangesCB.Check( bNewProtection ); 503*cdf0e10cSrcweir // toggle text of button "Protect" <-> "Unprotect" 504*cdf0e10cSrcweir m_aChangeProtectionPB.SetText( bNewProtection ? m_aUnProtectSTR : m_aProtectSTR ); 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir return 0; 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir SfxTabPage* SfxSecurityPage::Create( Window * pParent, const SfxItemSet & rItemSet ) 514*cdf0e10cSrcweir { 515*cdf0e10cSrcweir return new SfxSecurityPage( pParent, rItemSet ); 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir SfxSecurityPage::SfxSecurityPage( Window* pParent, const SfxItemSet& rItemSet ) : 520*cdf0e10cSrcweir SfxTabPage( pParent, SfxResId( TP_DOCINFOSECURITY ), rItemSet ) 521*cdf0e10cSrcweir { 522*cdf0e10cSrcweir m_pImpl = std::auto_ptr< SfxSecurityPage_Impl >(new SfxSecurityPage_Impl( *this, rItemSet )); 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir FreeResource(); 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir SfxSecurityPage::~SfxSecurityPage() 529*cdf0e10cSrcweir { 530*cdf0e10cSrcweir } 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir sal_Bool SfxSecurityPage::FillItemSet( SfxItemSet & rItemSet ) 534*cdf0e10cSrcweir { 535*cdf0e10cSrcweir bool bModified = false; 536*cdf0e10cSrcweir DBG_ASSERT( m_pImpl.get(), "implementation pointer is 0. Still in c-tor?" ); 537*cdf0e10cSrcweir if (m_pImpl.get() != 0) 538*cdf0e10cSrcweir bModified = m_pImpl->FillItemSet_Impl( rItemSet ); 539*cdf0e10cSrcweir return bModified; 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir void SfxSecurityPage::Reset( const SfxItemSet & rItemSet ) 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir DBG_ASSERT( m_pImpl.get(), "implementation pointer is 0. Still in c-tor?" ); 546*cdf0e10cSrcweir if (m_pImpl.get() != 0) 547*cdf0e10cSrcweir m_pImpl->Reset_Impl( rItemSet ); 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir 554