diff options
-rwxr-xr-x[-rw-r--r--] | sc/source/ui/docshell/docsh.cxx | 95 | ||||
-rwxr-xr-x[-rw-r--r--] | sc/source/ui/docshell/docsh4.cxx | 46 | ||||
-rwxr-xr-x[-rw-r--r--] | sc/source/ui/inc/docsh.hxx | 12 |
3 files changed, 129 insertions, 24 deletions
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 10a0b9c175dc..ac240c32e5c5 100644..100755 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -49,6 +49,7 @@ #include <svtools/ctrltool.hxx> #include <svtools/sfxecode.hxx> #include <svl/zforlist.hxx> +#include <svl/PasswordHelper.hxx> #include <sfx2/app.hxx> #include <sfx2/bindings.hxx> #include <sfx2/dinfdlg.hxx> @@ -2652,3 +2653,97 @@ sal_Bool ScDocShell::AcceptStateUpdate() const return sal_False; } //-->Added by PengYunQuan for Validity Cell Range Picker + + +bool ScDocShell::IsChangeRecording() const +{ + ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack(); + return pChangeTrack != NULL; +} + + +bool ScDocShell::HasChangeRecordProtection() const +{ + bool bRes = false; + ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack(); + if (pChangeTrack) + bRes = pChangeTrack->IsProtected(); + return bRes; +} + + +void ScDocShell::SetChangeRecording( bool bActivate ) +{ + bool bOldChangeRecording = IsChangeRecording(); + + if (bActivate) + { + aDocument.StartChangeTracking(); + ScChangeViewSettings aChangeViewSet; + aChangeViewSet.SetShowChanges(TRUE); + aDocument.SetChangeViewSettings(aChangeViewSet); + } + else + { + aDocument.EndChangeTracking(); + PostPaintGridAll(); + } + + if (bOldChangeRecording != IsChangeRecording()) + { + UpdateAcceptChangesDialog(); + // Slots invalidieren + SfxBindings* pBindings = GetViewBindings(); + if (pBindings) + pBindings->InvalidateAll(FALSE); + } +} + + +bool ScDocShell::SetProtectionPassword( const String &rNewPassword ) +{ + bool bRes = false; + ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack(); + if (pChangeTrack) + { + sal_Bool bProtected = pChangeTrack->IsProtected(); + + if (rNewPassword.Len()) + { + // when password protection is applied change tracking must always be active + SetChangeRecording( true ); + + ::com::sun::star::uno::Sequence< sal_Int8 > aProtectionHash; + SvPasswordHelper::GetHashPassword( aProtectionHash, rNewPassword ); + pChangeTrack->SetProtection( aProtectionHash ); + } + else + { + pChangeTrack->SetProtection( ::com::sun::star::uno::Sequence< sal_Int8 >() ); + } + bRes = true; + + if ( bProtected != pChangeTrack->IsProtected() ) + { + UpdateAcceptChangesDialog(); + SetDocumentModified(); + } + } + + return bRes; +} + + +bool ScDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash ) +{ + bool bRes = false; + ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack(); + if (pChangeTrack && pChangeTrack->IsProtected()) + { + rPasswordHash = pChangeTrack->GetProtection(); + bRes = true; + } + return bRes; +} + + diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index 157b98497e83..1fe5cc7a74ba 100644..100755 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -66,6 +66,7 @@ using namespace ::com::sun::star; #include <svx/svditer.hxx> #include <svx/svdpage.hxx> #include <svx/fmshell.hxx> +#include <svtools/xwindowitem.hxx> #include <sfx2/passwd.hxx> #include <sfx2/filedlghelper.hxx> #include <sfx2/docinsert.hxx> @@ -623,8 +624,8 @@ void ScDocShell::Execute( SfxRequest& rReq ) // getting real parent window when called from Security-Options TP Window* pParent = NULL; const SfxPoolItem* pParentItem; - if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_PARENTWINDOW, FALSE, &pParentItem ) ) - pParent = ( Window* ) ( ( const OfaPtrItem* ) pParentItem )->GetValue(); + if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_XWINDOW, FALSE, &pParentItem ) ) + pParent = ( ( const XWindowItem* ) pParentItem )->GetWindowPtr(); // desired state ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack(); @@ -664,17 +665,7 @@ void ScDocShell::Execute( SfxRequest& rReq ) if ( bDo ) { - // update "accept changes" dialog - //! notify all views - SfxViewFrame* pViewFrm = SfxViewFrame::Current(); - if ( pViewFrm && pViewFrm->HasChildWindow(FID_CHG_ACCEPT) ) - { - SfxChildWindow* pChild = pViewFrm->GetChildWindow(FID_CHG_ACCEPT); - if (pChild) - { - ((ScAcceptChgDlgWrapper*)pChild)->ReInitDlg(); - } - } + UpdateAcceptChangesDialog(); // Slots invalidieren if (pBindings) @@ -693,8 +684,8 @@ void ScDocShell::Execute( SfxRequest& rReq ) { Window* pParent = NULL; const SfxPoolItem* pParentItem; - if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_PARENTWINDOW, FALSE, &pParentItem ) ) - pParent = ( Window* ) ( ( const OfaPtrItem* ) pParentItem )->GetValue(); + if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_XWINDOW, FALSE, &pParentItem ) ) + pParent = ( ( const XWindowItem* ) pParentItem )->GetWindowPtr(); if ( ExecuteChangeProtectionDialog( pParent ) ) { rReq.Done(); @@ -1164,6 +1155,21 @@ void ScDocShell::Execute( SfxRequest& rReq ) //------------------------------------------------------------------ +void UpdateAcceptChangesDialog() +{ + // update "accept changes" dialog + //! notify all views + SfxViewFrame* pViewFrm = SfxViewFrame::Current(); + if ( pViewFrm && pViewFrm->HasChildWindow( FID_CHG_ACCEPT ) ) + { + SfxChildWindow* pChild = pViewFrm->GetChildWindow( FID_CHG_ACCEPT ); + if ( pChild ) + ((ScAcceptChgDlgWrapper*)pChild)->ReInitDlg(); + } +} + +//------------------------------------------------------------------ + BOOL ScDocShell::ExecuteChangeProtectionDialog( Window* _pParent, BOOL bJustQueryIfProtected ) { BOOL bDone = FALSE; @@ -1217,15 +1223,7 @@ BOOL ScDocShell::ExecuteChangeProtectionDialog( Window* _pParent, BOOL bJustQuer } if ( bProtected != pChangeTrack->IsProtected() ) { - // update "accept changes" dialog - //! notify all views - SfxViewFrame* pViewFrm = SfxViewFrame::Current(); - if ( pViewFrm && pViewFrm->HasChildWindow( FID_CHG_ACCEPT ) ) - { - SfxChildWindow* pChild = pViewFrm->GetChildWindow( FID_CHG_ACCEPT ); - if ( pChild ) - ((ScAcceptChgDlgWrapper*)pChild)->ReInitDlg(); - } + UpdateAcceptChangesDialog(); bDone = TRUE; } } diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx index 09d34c661995..e4c02458ec6e 100644..100755 --- a/sc/source/ui/inc/docsh.hxx +++ b/sc/source/ui/inc/docsh.hxx @@ -418,8 +418,20 @@ public: sal_Bool AcceptStateUpdate() const; //-->Added by PengYunQuan for Validity Cell Range Picker ScSheetSaveData* GetSheetSaveData(); + + // passwword protection for Calc (derived from SfxObjectShell) + // see also: FID_CHG_RECORD, SID_CHG_PROTECT + virtual bool IsChangeRecording() const; + virtual bool HasChangeRecordProtection() const; + virtual void SetChangeRecording( bool bActivate ); + virtual bool SetProtectionPassword( const String &rPassword ); + virtual bool GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash ); }; + +void UpdateAcceptChangesDialog(); + + SO2_DECL_REF(ScDocShell) SO2_IMPL_REF(ScDocShell) |