diff options
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/drawfunc/drawsh2.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/drawfunc/drawsh5.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/inc/drawview.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/view/drawvie4.cxx | 46 |
4 files changed, 59 insertions, 0 deletions
diff --git a/sc/source/ui/drawfunc/drawsh2.cxx b/sc/source/ui/drawfunc/drawsh2.cxx index 9f2f0f2975e3..83d5d51ade9c 100644 --- a/sc/source/ui/drawfunc/drawsh2.cxx +++ b/sc/source/ui/drawfunc/drawsh2.cxx @@ -208,6 +208,8 @@ void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet ) // disable functions rSet.DisableItem( SID_DRAW_HLINK_EDIT ); rSet.DisableItem( SID_DRAW_HLINK_DELETE ); rSet.DisableItem( SID_OPEN_HYPERLINK ); + // Fit to cell only works with a single graphic + rSet.DisableItem( SID_FITCELLSIZE ); } else if ( nMarkCount == 1 ) { @@ -244,6 +246,11 @@ void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet ) // disable functions rSet.DisableItem( SID_ANCHOR_TOGGLE ); } } + + // Fit to cell is only available for cell anchored graphics obviously + if (pView->GetAnchorType() != SCA_CELL && + pView->GetAnchorType() != SCA_CELL_RESIZE) + rSet.DisableItem( SID_FITCELLSIZE ); } if ( !bCanRename ) { @@ -267,6 +274,7 @@ void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet ) // disable functions // other rSet.DisableItem( SID_ANCHOR_TOGGLE ); rSet.DisableItem( SID_ORIGINALSIZE ); + rSet.DisableItem( SID_FITCELLSIZE ); rSet.DisableItem( SID_ATTR_TRANSFORM ); } diff --git a/sc/source/ui/drawfunc/drawsh5.cxx b/sc/source/ui/drawfunc/drawsh5.cxx index 892895bb27fd..971f1aa73782 100644 --- a/sc/source/ui/drawfunc/drawsh5.cxx +++ b/sc/source/ui/drawfunc/drawsh5.cxx @@ -458,6 +458,10 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq ) pView->SetMarkedOriginalSize(); break; + case SID_FITCELLSIZE: + pView->FitToCellSize(); + break; + case SID_ENABLE_HYPHENATION: { const SfxBoolItem* pItem = rReq.GetArg<SfxBoolItem>(SID_ENABLE_HYPHENATION); diff --git a/sc/source/ui/inc/drawview.hxx b/sc/source/ui/inc/drawview.hxx index 7a1066db82a3..9574cdb63900 100644 --- a/sc/source/ui/inc/drawview.hxx +++ b/sc/source/ui/inc/drawview.hxx @@ -108,6 +108,7 @@ public: void UpdateUserViewOptions(); void SetMarkedOriginalSize(); + void FitToCellSize(); bool SelectObject( const OUString& rName ); bool HasMarkedControl() const; diff --git a/sc/source/ui/view/drawvie4.cxx b/sc/source/ui/view/drawvie4.cxx index 72f06667ce34..bee41f56eee0 100644 --- a/sc/source/ui/view/drawvie4.cxx +++ b/sc/source/ui/view/drawvie4.cxx @@ -40,6 +40,7 @@ #include <globstr.hrc> #include <chartarr.hxx> #include <gridwin.hxx> +#include <userdat.hxx> #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> #include <com/sun/star/embed/Aspects.hpp> @@ -530,4 +531,49 @@ void ScDrawView::SetMarkedOriginalSize() delete pUndoGroup; } +void ScDrawView::FitToCellSize() +{ + const SdrMarkList& rMarkList = GetMarkedObjectList(); + + if (rMarkList.GetMarkCount() != 1) + { + SAL_WARN("sc.ui", "Fit to cell only works with one graphic!"); + return; + } + + SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); + + ScAnchorType aAnchorType = ScDrawLayer::GetAnchorType(*pObj); + if (aAnchorType != SCA_CELL && aAnchorType != SCA_CELL_RESIZE) + { + SAL_WARN("sc.ui", "Fit to cell only works with cell anchored graphics!"); + return; + } + + SdrUndoGroup* pUndoGroup = new SdrUndoGroup(*GetModel()); + ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pObj); + tools::Rectangle aGraphicRect = pObj->GetSnapRect(); + tools::Rectangle aCellRect = ScDrawLayer::GetCellRect( *pDoc, pObjData->maStart, true); + + // For graphic objects, we want to keep the aspect ratio + if (pObj->shouldKeepAspectRatio()) + { + double fScaleX = static_cast<double>(aCellRect.GetWidth()) / static_cast<double>(aGraphicRect.GetWidth()); + double fScaleY = static_cast<double>(aCellRect.GetHeight()) / static_cast<double>(aGraphicRect.GetHeight()); + double fScaleMin = std::min(fScaleX, fScaleY); + + aCellRect.setWidth(static_cast<double>(aGraphicRect.GetWidth()) * fScaleMin); + aCellRect.setHeight(static_cast<double>(aGraphicRect.GetHeight()) * fScaleMin); + } + + pUndoGroup->AddAction( new SdrUndoGeoObj( *pObj ) ); + + pObj->SetSnapRect(aCellRect); + + pUndoGroup->SetComment(ScGlobal::GetRscString( STR_UNDO_FITCELLSIZE )); + ScDocShell* pDocSh = pViewData->GetDocShell(); + pDocSh->GetUndoManager()->AddUndoAction(pUndoGroup); + +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |