LCOV - code coverage report
Current view: top level - sfx2/source/dialog - securitypage.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 203 0.0 %
Date: 2012-08-25 Functions: 0 19 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 482 0.0 %

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

Generated by: LCOV version 1.10