diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-09 10:58:25 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-03-09 14:18:28 +0100 |
commit | 76e2cede5a415df8d3e7a874f56be7a0b5953e12 (patch) | |
tree | e7eafef3b01fad3fd36f1dc97484d9f414102941 /sfx2 | |
parent | 644ace4143fe2576bfd71c8ab3da9d666d6523bb (diff) |
Move copy/paste classification check from sw to sfx2
So that it's easy to unit test it and other apps can use it as well in
the future.
Change-Id: I38d601924b7fbb17615ff6e9c031a71b40777c4c
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/view/classificationhelper.cxx | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx index ab913b537d3f..6950048fae82 100644 --- a/sfx2/source/view/classificationhelper.cxx +++ b/sfx2/source/view/classificationhelper.cxx @@ -426,6 +426,35 @@ bool SfxClassificationHelper::IsClassified(SfxObjectShell& rObjectShell) return false; } +SfxClassificationCheckPasteResult SfxClassificationHelper::CheckPaste(SfxObjectShell& rSource, SfxObjectShell& rDestination) +{ + bool bSourceClassified = SfxClassificationHelper::IsClassified(rSource); + if (!bSourceClassified) + // No classification on the source side. Return early, regardless the + // state of the destination side. + return SfxClassificationCheckPasteResult::None; + + bool bDestinationClassified = SfxClassificationHelper::IsClassified(rDestination); + if (bSourceClassified && !bDestinationClassified) + { + // Paste from a classified document to a non-classified one -> deny. + return SfxClassificationCheckPasteResult::TargetDocNotClassified; + } + + // Remaining case: paste between two classified documents. + SfxClassificationHelper aSource(rSource); + SfxClassificationHelper aDestination(rDestination); + if (aSource.GetImpactScale() != aDestination.GetImpactScale()) + // It's possible to compare them if they have the same scale. + return SfxClassificationCheckPasteResult::None; + + if (aSource.GetImpactLevel() > aDestination.GetImpactLevel()) + // Paste from a doc that has higher classification -> deny. + return SfxClassificationCheckPasteResult::DocClassificationTooLow; + + return SfxClassificationCheckPasteResult::None; +} + SfxClassificationHelper::SfxClassificationHelper(SfxObjectShell& rObjectShell) : m_pImpl(o3tl::make_unique<Impl>(rObjectShell)) { |