[Libreoffice-commits] core.git: include/svx officecfg/registry sc/inc sc/sdi sc/source sc/uiconfig

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Wed Mar 7 07:27:19 UTC 2018


 include/svx/svdobj.hxx                                               |    3 
 include/svx/svdograf.hxx                                             |    2 
 include/svx/svdomedia.hxx                                            |    2 
 officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu |    5 +
 sc/inc/globstr.hrc                                                   |    1 
 sc/inc/sc.hrc                                                        |    1 
 sc/sdi/drawsh.sdi                                                    |    1 
 sc/sdi/scalc.sdi                                                     |   18 +++
 sc/source/ui/drawfunc/drawsh2.cxx                                    |    8 +
 sc/source/ui/drawfunc/drawsh5.cxx                                    |    4 
 sc/source/ui/inc/drawview.hxx                                        |    1 
 sc/source/ui/view/drawvie4.cxx                                       |   46 ++++++++++
 sc/uiconfig/scalc/menubar/menubar.xml                                |    1 
 sc/uiconfig/scalc/popupmenu/chart.xml                                |    1 
 sc/uiconfig/scalc/popupmenu/draw.xml                                 |    1 
 sc/uiconfig/scalc/popupmenu/form.xml                                 |    1 
 sc/uiconfig/scalc/popupmenu/graphic.xml                              |    1 
 sc/uiconfig/scalc/popupmenu/media.xml                                |    1 
 sc/uiconfig/scalc/popupmenu/oleobject.xml                            |    1 
 19 files changed, 99 insertions(+)

New commits:
commit 073b4eadd2a9a00b915c664df90b15d5b2d709c0
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Thu Mar 1 12:17:46 2018 +0100

    tdf#116108 Add option to fit images into their cell
    
    Change-Id: I2e9a4f567049f11985e4bf914c2fa5bd1f181823
    Reviewed-on: https://gerrit.libreoffice.org/50569
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx
index 2f9542659cb0..3e97a472084f 100644
--- a/include/svx/svdobj.hxx
+++ b/include/svx/svdobj.hxx
@@ -733,6 +733,9 @@ public:
     void SetMarkProtect(bool bProt);
     bool IsMarkProtect() const { return bMarkProt;}
 
+    /// Whether the aspect ratio should be kept by default when resizing.
+    virtual bool shouldKeepAspectRatio() const { return false; }
+
     // application specific data
     sal_uInt16 GetUserDataCount() const;
     SdrObjUserData* GetUserData(sal_uInt16 nNum) const;
diff --git a/include/svx/svdograf.hxx b/include/svx/svdograf.hxx
index f31ed858e575..abea8f1b222e 100644
--- a/include/svx/svdograf.hxx
+++ b/include/svx/svdograf.hxx
@@ -211,6 +211,8 @@ public:
     bool IsMirrored() const { return bMirrored;}
     void SetMirrored( bool _bMirrored );
 
+    virtual bool shouldKeepAspectRatio() const override { return true; }
+
     // Access to GrafAnimationAllowed flag
     void SetGrafAnimationAllowed(bool bNew);
 
diff --git a/include/svx/svdomedia.hxx b/include/svx/svdomedia.hxx
index f0bf09300aff..43356da4e302 100644
--- a/include/svx/svdomedia.hxx
+++ b/include/svx/svdomedia.hxx
@@ -69,6 +69,8 @@ public:
                                     GetInputStream();
         void                        SetInputStream(css::uno::Reference<css::io::XInputStream> const&);
 
+        virtual bool shouldKeepAspectRatio() const override { return true; }
+
 private:
 
         void                mediaPropertiesChanged( const ::avmedia::MediaItem& rNewState );
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index af2f0c643cc5..22f09405bf64 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -2181,6 +2181,11 @@
           <value xml:lang="en-US">~Original Size</value>
         </prop>
       </node>
+      <node oor:name=".uno:FitCellSize" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">~Fit to Cell Size</value>
+        </prop>
+      </node>
       <node oor:name=".uno:GridMenu" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">Gr~id and Helplines</value>
diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 89f3150fa8d0..d08ec69ed2a5 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -93,6 +93,7 @@
 #define STR_UNDO_DETREFRESH                     NC_("STR_UNDO_DETREFRESH", "Refresh Traces")
 #define STR_UNDO_CHARTDATA                      NC_("STR_UNDO_CHARTDATA", "Modify chart data range")
 #define STR_UNDO_ORIGINALSIZE                   NC_("STR_UNDO_ORIGINALSIZE", "Original Size")
+#define STR_UNDO_FITCELLSIZE                    NC_("STR_UNDO_FITCELLSIZE", "Fit to Cell Size")
 #define STR_UNDO_UPDATELINK                     NC_("STR_UNDO_UPDATELINK", "Update Link")
 #define STR_UNDO_REMOVELINK                     NC_("STR_UNDO_REMOVELINK", "Unlink")
 #define STR_UNDO_INSERTAREALINK                 NC_("STR_UNDO_INSERTAREALINK", "Insert Link")
diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index 64ee13afc73c..5f1ae5ef385b 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -409,6 +409,7 @@
 #define SID_ANCHOR_CELL_RESIZE  (DRAW_BAR_START+26)
 #define SID_ANCHOR_TOGGLE       (DRAW_BAR_START+27)
 #define SID_ORIGINALSIZE        (DRAW_BAR_START+28)
+#define SID_FITCELLSIZE         (DRAW_BAR_START+29)
 
 #define DRAW_BAR_END            (DRAW_BAR_START+50)
 
diff --git a/sc/sdi/drawsh.sdi b/sc/sdi/drawsh.sdi
index feaa7ba0280c..038489e3e065 100644
--- a/sc/sdi/drawsh.sdi
+++ b/sc/sdi/drawsh.sdi
@@ -179,6 +179,7 @@ interface TableDraw
     SID_ATTR_SIZE           [ StateMethod = GetDrawAttrState; Export = FALSE; ]
     SID_TABLE_CELL          [ StateMethod = GetDrawAttrState; Export = FALSE; ]
     SID_ORIGINALSIZE        [ ExecMethod = ExecDrawFunc; StateMethod = GetDrawFuncState; Export = FALSE; ]
+    SID_FITCELLSIZE         [ ExecMethod = ExecDrawFunc; StateMethod = GetDrawFuncState; Export = FALSE; ]
     SID_HYPERLINK_SETLINK   [ ExecMethod = ExecuteHLink; Export = FALSE; ]
     SID_HYPERLINK_GETLINK   [ StateMethod = GetHLinkState; Export = FALSE; ]
     SID_ENABLE_HYPHENATION  [ ExecMethod = ExecDrawFunc; StateMethod = GetDrawFuncState; Export = FALSE; ]
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index 8ef6851af217..57c13e0d237c 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -3924,6 +3924,24 @@ SfxVoidItem OriginalSize SID_ORIGINALSIZE
 ]
 
 
+SfxVoidItem FitCellSize SID_FITCELLSIZE
+()
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    ToolBoxConfig = TRUE,
+    GroupId = SfxGroupId::Format;
+]
+
+
 SfxBoolItem NormalViewMode FID_NORMALVIEWMODE
 
 [
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: */
diff --git a/sc/uiconfig/scalc/menubar/menubar.xml b/sc/uiconfig/scalc/menubar/menubar.xml
index b40e1bd484dc..b9a909c2976b 100644
--- a/sc/uiconfig/scalc/menubar/menubar.xml
+++ b/sc/uiconfig/scalc/menubar/menubar.xml
@@ -430,6 +430,7 @@
                 <menu:menupopup>
                     <menu:menuitem menu:id=".uno:Crop"/>
                     <menu:menuitem menu:id=".uno:OriginalSize"/>
+                    <menu:menuitem menu:id=".uno:FitCellSize"/>
                     <menu:menuseparator/>
                     <menu:menuitem menu:id=".uno:ExternalEdit"/>
                     <menu:menuitem menu:id=".uno:ChangePicture"/>
diff --git a/sc/uiconfig/scalc/popupmenu/chart.xml b/sc/uiconfig/scalc/popupmenu/chart.xml
index d2581d879551..e7ddbc87a272 100644
--- a/sc/uiconfig/scalc/popupmenu/chart.xml
+++ b/sc/uiconfig/scalc/popupmenu/chart.xml
@@ -17,6 +17,7 @@
   <menu:menuitem menu:id=".uno:TextAttributes"/>
   <menu:menuitem menu:id=".uno:TransformDialog"/>
   <menu:menuitem menu:id=".uno:OriginalSize"/>
+  <menu:menuitem menu:id=".uno:FitCellSize"/>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
   <menu:menuitem menu:id=".uno:RenameObject"/>
diff --git a/sc/uiconfig/scalc/popupmenu/draw.xml b/sc/uiconfig/scalc/popupmenu/draw.xml
index daeb44d65036..c09726f593d9 100644
--- a/sc/uiconfig/scalc/popupmenu/draw.xml
+++ b/sc/uiconfig/scalc/popupmenu/draw.xml
@@ -16,6 +16,7 @@
   <menu:menuitem menu:id=".uno:FormatArea"/>
   <menu:menuitem menu:id=".uno:TextAttributes"/>
   <menu:menuitem menu:id=".uno:TransformDialog"/>
+  <menu:menuitem menu:id=".uno:FitCellSize"/>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
   <menu:menuitem menu:id=".uno:RenameObject"/>
diff --git a/sc/uiconfig/scalc/popupmenu/form.xml b/sc/uiconfig/scalc/popupmenu/form.xml
index 2efbc4d9e16c..72fc473f1443 100644
--- a/sc/uiconfig/scalc/popupmenu/form.xml
+++ b/sc/uiconfig/scalc/popupmenu/form.xml
@@ -13,6 +13,7 @@
   <menu:menuitem menu:id=".uno:Paste"/>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:TransformDialog"/>
+  <menu:menuitem menu:id=".uno:FitCellSize"/>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
   <menu:menuitem menu:id=".uno:RenameObject"/>
diff --git a/sc/uiconfig/scalc/popupmenu/graphic.xml b/sc/uiconfig/scalc/popupmenu/graphic.xml
index ab60b0ce44f7..6185490898eb 100644
--- a/sc/uiconfig/scalc/popupmenu/graphic.xml
+++ b/sc/uiconfig/scalc/popupmenu/graphic.xml
@@ -17,6 +17,7 @@
   <menu:menuitem menu:id=".uno:TextAttributes"/>
   <menu:menuitem menu:id=".uno:TransformDialog"/>
   <menu:menuitem menu:id=".uno:OriginalSize"/>
+  <menu:menuitem menu:id=".uno:FitCellSize"/>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
   <menu:menuitem menu:id=".uno:RenameObject"/>
diff --git a/sc/uiconfig/scalc/popupmenu/media.xml b/sc/uiconfig/scalc/popupmenu/media.xml
index 242ac43d498d..f6d8c5082426 100644
--- a/sc/uiconfig/scalc/popupmenu/media.xml
+++ b/sc/uiconfig/scalc/popupmenu/media.xml
@@ -13,6 +13,7 @@
   <menu:menuitem menu:id=".uno:Paste"/>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:TransformDialog"/>
+  <menu:menuitem menu:id=".uno:FitCellSize"/>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
   <menu:menuitem menu:id=".uno:RenameObject"/>
diff --git a/sc/uiconfig/scalc/popupmenu/oleobject.xml b/sc/uiconfig/scalc/popupmenu/oleobject.xml
index cc1c3e208646..f2e746590bce 100644
--- a/sc/uiconfig/scalc/popupmenu/oleobject.xml
+++ b/sc/uiconfig/scalc/popupmenu/oleobject.xml
@@ -17,6 +17,7 @@
   <menu:menuitem menu:id=".uno:TextAttributes"/>
   <menu:menuitem menu:id=".uno:TransformDialog"/>
   <menu:menuitem menu:id=".uno:OriginalSize"/>
+  <menu:menuitem menu:id=".uno:FitCellSize"/>
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
   <menu:menuitem menu:id=".uno:RenameObject"/>


More information about the Libreoffice-commits mailing list