fpicker/source/aqua/ControlHelper.hxx                                |    1 
 fpicker/source/aqua/ControlHelper.mm                                 |    9 
 fpicker/source/aqua/SalAquaFilePicker.mm                             |    3 
 fpicker/source/aqua/resourceprovider.mm                              |    1 
 fpicker/source/office/OfficeControlAccess.cxx                        |    4 
 fpicker/source/office/OfficeFilePicker.cxx                           |    4 
 fpicker/source/office/OfficeFilePicker.src                           |    5 
 fpicker/source/office/fpdialogbase.hxx                               |    3 
 fpicker/source/office/iodlg.cxx                                      |   20 +
 fpicker/source/office/iodlgimp.cxx                                   |    2 
 fpicker/source/office/iodlgimp.hxx                                   |    3 
 fpicker/source/win32/filepicker/VistaFilePicker.cxx                  |    9 
 fpicker/source/win32/filepicker/VistaFilePickerImpl.cxx              |   15 +
 fpicker/source/win32/filepicker/VistaFilePickerImpl.hxx              |    1 
 fpicker/source/win32/misc/resourceprovider.cxx                       |    1 
 include/sfx2/opengrf.hxx                                             |    6 
 include/svtools/helpid.hrc                                           |    1 
 include/svx/svdobj.hxx                                               |    3 
 include/svx/svdograf.hxx                                             |    2 
 include/svx/svdomedia.hxx                                            |    3 
 include/vcl/fpicker.hrc                                              |    1 
 offapi/com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.idl      |    3 
 offapi/com/sun/star/ui/dialogs/TemplateDescription.idl               |   11 
 officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu    |   17 +
 officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu |    5 
 sc/CppunitTest_sc_anchor_test.mk                                     |  106 
+++++++++
 sc/Module_sc.mk                                                      |    1 
 sc/inc/drwlayer.hxx                                                  |    4 
 sc/inc/global.hxx                                                    |    5 
 sc/inc/globstr.hrc                                                   |    1 
 sc/inc/sc.hrc                                                        |   10 
 sc/inc/userdat.hxx                                                   |    1 
 sc/qa/extras/anchor.cxx                                              |  115 
++++++++++
 sc/qa/extras/sccondformats.cxx                                       |    2 
 sc/qa/unit/data/ods/3AnchorTypes.ods                                 |binary
 sc/qa/unit/subsequent_export-test.cxx                                |    7 
 sc/qa/unit/ucalc.cxx                                                 |   12 -
 sc/qa/unit/ucalc_sort.cxx                                            |    2 
 sc/sdi/drawsh.sdi                                                    |    4 
 sc/sdi/scalc.sdi                                                     |   38 +++
 sc/source/core/data/drwlayer.cxx                                     |   40 ++-
 sc/source/core/data/userdat.cxx                                      |    3 
 sc/source/filter/excel/xiescher.cxx                                  |    2 
 sc/source/filter/inc/drawingbase.hxx                                 |    3 
 sc/source/filter/oox/drawingbase.cxx                                 |    2 
 sc/source/filter/oox/drawingfragment.cxx                             |    3 
 sc/source/filter/xcl97/xcl97rec.cxx                                  |   10 
 sc/source/filter/xml/XMLExportIterator.hxx                           |    1 
 sc/source/filter/xml/XMLTableShapeImportHelper.cxx                   |    3 
 sc/source/filter/xml/xmlexprt.cxx                                    |    6 
 sc/source/ui/drawfunc/drawsh2.cxx                                    |   26 +-
 sc/source/ui/drawfunc/drawsh5.cxx                                    |   21 +
 sc/source/ui/drawfunc/fuins1.cxx                                     |   59 
++++-
 sc/source/ui/inc/drawview.hxx                                        |    3 
 sc/source/ui/src/globstr.src                                         |    4 
 sc/source/ui/src/scstring.src                                        |   15 +
 sc/source/ui/view/drawvie3.cxx                                       |   18 +
 sc/source/ui/view/drawvie4.cxx                                       |   46 
++++
 sc/source/ui/view/viewfun7.cxx                                       |    5 
 sc/uiconfig/scalc/menubar/menubar.xml                                |    1 
 sc/uiconfig/scalc/popupmenu/anchor.xml                               |    3 
 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 
 sfx2/source/appl/opengrf.cxx                                         |   21 +
 sfx2/source/dialog/filedlghelper.cxx                                 |   22 +
 vcl/inc/svids.hrc                                                    |    1 
 vcl/source/src/fpicker.src                                           |    5 
 vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx                             |   11 
 vcl/unx/gtk/fpicker/SalGtkFilePicker.hxx                             |    1 
 vcl/unx/gtk/fpicker/resourceprovider.cxx                             |    1 
 vcl/unx/gtk3_kde5/gtk3_kde5_filepicker.cxx                           |   12 +
 vcl/unx/kde4/KDE4FilePicker.cxx                                      |   12 +
 76 files changed, 743 insertions(+), 64 deletions(-)

New commits:
commit 9ec9420a4bce6b68eb8b201e128f0979d9e0e448
Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
Date:   Thu Mar 1 12:17:46 2018 +0100

    tdf#116108 Add option to fit images into their cell
    
    Reviewed-on: https://gerrit.libreoffice.org/50569
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
    (cherry picked from commit 073b4eadd2a9a00b915c664df90b15d5b2d709c0)
    
    Change-Id: I2e9a4f567049f11985e4bf914c2fa5bd1f181823

diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx
index 390afe887459..efc3bb220c66 100644
--- a/include/svx/svdobj.hxx
+++ b/include/svx/svdobj.hxx
@@ -877,6 +877,9 @@ public:
     // #i25616#
     bool DoesSupportTextIndentingOnLineWidthChange() const { return 
mbSupportTextIndentingOnLineWidthChange;}
 
+    /// 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 123ba1dc69bd..e1687b4a2e22 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 9ea8d917d521..f2aacb0db8de 100644
--- a/include/svx/svdomedia.hxx
+++ b/include/svx/svdomedia.hxx
@@ -70,8 +70,9 @@ public:
                                     GetInputStream();
         void                        
SetInputStream(css::uno::Reference<css::io::XInputStream> const&);
 
-protected:
+        virtual bool shouldKeepAspectRatio() const override { return true; }
 
+protected:
         void                mediaPropertiesChanged( const 
::avmedia::MediaItem& rNewState );
         virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() 
override;
 
diff --git 
a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index c077a8e12f01..e06248614b37 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -2015,6 +2015,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 81e44932d49b..7a6827a1147d 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -349,6 +349,7 @@
 
 #define STR_UNDO_CHARTDATA          261
 #define STR_UNDO_ORIGINALSIZE       262
+#define STR_UNDO_FITCELLSIZE        263
 
 #define STR_LINKERROR               263
 #define STR_LINKERRORFILE           264
diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index b8dac1516dc7..141286fd8d9f 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -451,6 +451,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 3a12ef500174..d6c0f4ca0352 100644
--- a/sc/sdi/drawsh.sdi
+++ b/sc/sdi/drawsh.sdi
@@ -187,6 +187,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 5b97aaa8c5ff..ea282dca7347 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -4064,6 +4064,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 = GID_FORMAT;
+]
+
+
 SfxBoolItem NormalViewMode FID_NORMALVIEWMODE
 
 [
diff --git a/sc/source/ui/drawfunc/drawsh2.cxx 
b/sc/source/ui/drawfunc/drawsh2.cxx
index d754869834fa..ec02c32d923b 100644
--- a/sc/source/ui/drawfunc/drawsh2.cxx
+++ b/sc/source/ui/drawfunc/drawsh2.cxx
@@ -209,6 +209,8 @@ void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet )      
// Funktionen disabl
         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 )
     {
@@ -245,6 +247,11 @@ void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet )     
 // Funktionen disabl
                 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 )
     {
@@ -268,6 +275,7 @@ void ScDrawShell::GetDrawFuncState( SfxItemSet& rSet )      
// Funktionen disabl
             //  sonstiges
         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 04238223015e..49a266b065d5 100644
--- a/sc/source/ui/drawfunc/drawsh5.cxx
+++ b/sc/source/ui/drawfunc/drawsh5.cxx
@@ -467,6 +467,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 ce72f79370cf..045ea6241e7d 100644
--- a/sc/source/ui/inc/drawview.hxx
+++ b/sc/source/ui/inc/drawview.hxx
@@ -109,6 +109,7 @@ public:
     void            UpdateUserViewOptions();
 
     void            SetMarkedOriginalSize();
+    void            FitToCellSize();
 
     bool            SelectObject( const OUString& rName );
     bool            HasMarkedControl() const;
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index c74373f662b3..5260ab699673 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -273,6 +273,10 @@ Resource RID_GLOBSTR
     {
         Text [ en-US ] = "Original Size" ;
     };
+    String STR_UNDO_FITCELLSIZE
+    {
+        Text [ en-US ] = "Fit to Cell Size" ;
+    };
     String STR_UNDO_UPDATELINK
     {
         Text [ en-US ] = "Update Link" ;
diff --git a/sc/source/ui/view/drawvie4.cxx b/sc/source/ui/view/drawvie4.cxx
index dbc8ef80fd00..5d4463da5771 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>
@@ -542,4 +543,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);
+    Rectangle aGraphicRect = pObj->GetSnapRect();
+    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 54676dd8c5d9..f5b9529222df 100644
--- a/sc/uiconfig/scalc/menubar/menubar.xml
+++ b/sc/uiconfig/scalc/menubar/menubar.xml
@@ -348,6 +348,7 @@
             <menu:menu menu:id=".uno:FormatImageMenu">
                 <menu:menupopup>
                     <menu:menuitem menu:id=".uno:Crop"/>
+                    <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"/>
commit 93317f9668030b8ff1fe3eddc13c32f731d28e93
Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
Date:   Mon Feb 12 15:32:15 2018 +0100

    tdf#114552 Add unit test for ODF Import of anchor types
    
    Contains parts from dc306db9b51e6f009803f7ba633674dc2840ac08
    
    Reviewed-on: https://gerrit.libreoffice.org/49602
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
    (cherry picked from commit 782d504649ccb2dbe1a55d7abdf5c532b62f5c39)
    
    Change-Id: I7b6e013de5b37c8da0adf5be8e66472e76d81375

diff --git a/sc/CppunitTest_sc_anchor_test.mk b/sc/CppunitTest_sc_anchor_test.mk
new file mode 100644
index 000000000000..2f9719e48fd6
--- /dev/null
+++ b/sc/CppunitTest_sc_anchor_test.mk
@@ -0,0 +1,106 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sc_anchor_test))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sc_anchor_test, \
+       sc/qa/extras/anchor \
+))
+
+$(eval $(call gb_CppunitTest_use_external,sc_anchor_test,boost_headers))
+
+$(eval $(call gb_CppunitTest_use_libraries,sc_anchor_test, \
+       basegfx \
+       comphelper \
+       cppu \
+       cppuhelper \
+       drawinglayer \
+       editeng \
+       for \
+       forui \
+       i18nlangtag \
+       msfilter \
+       oox \
+       sal \
+       salhelper \
+       sax \
+       sb \
+       sc \
+       scqahelper \
+       sfx \
+       sot \
+       subsequenttest \
+       svl \
+       svt \
+       svx \
+       svxcore \
+       test \
+       tk \
+       tl \
+       ucbhelper \
+       unotest \
+       utl \
+       vbahelper \
+       vcl \
+       xo \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sc_anchor_test,\
+       -I$(SRCDIR)/sc/source/ui/inc \
+       -I$(SRCDIR)/sc/inc \
+       $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,sc_anchor_test))
+
+$(eval $(call gb_CppunitTest_use_ure,sc_anchor_test))
+$(eval $(call gb_CppunitTest_use_vcl,sc_anchor_test))
+
+$(eval $(call gb_CppunitTest_use_components,sc_anchor_test,\
+       basic/util/sb \
+       comphelper/util/comphelp \
+       configmgr/source/configmgr \
+       dbaccess/util/dba \
+       filter/source/config/cache/filterconfig1 \
+       filter/source/storagefilterdetect/storagefd \
+       forms/util/frm \
+       framework/util/fwk \
+       i18npool/util/i18npool \
+       linguistic/source/lng \
+       oox/util/oox \
+       package/source/xstor/xstor \
+       package/util/package2 \
+       sax/source/expatwrap/expwrap \
+       scripting/source/basprov/basprov \
+       scripting/util/scriptframe \
+       sc/util/sc \
+       sc/util/scd \
+       sc/util/scfilt \
+       $(call gb_Helper_optional,SCRIPTING, \
+               sc/util/vbaobj) \
+       sfx2/util/sfx \
+       sot/util/sot \
+       svl/source/fsstor/fsstorage \
+       toolkit/util/tk \
+       ucb/source/core/ucb1 \
+       ucb/source/ucp/file/ucpfile1 \
+       ucb/source/ucp/tdoc/ucptdoc1 \
+       unotools/util/utl \
+       unoxml/source/rdf/unordf \
+       unoxml/source/service/unoxml \
+       uui/util/uui \
+       xmloff/util/xo \
+       svtools/util/svt \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sc_anchor_test))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk
index d8561753f376..1e4ef9f7d4b6 100644
--- a/sc/Module_sc.mk
+++ b/sc/Module_sc.mk
@@ -75,6 +75,7 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sc,\
        JunitTest_sc_unoapi_5 \
        JunitTest_sc_unoapi_6 \
        JunitTest_sc_unoapi_7 \
+       CppunitTest_sc_anchor_test \
        CppunitTest_sc_annotationshapeobj \
        CppunitTest_sc_outlineobj \
        CppunitTest_sc_styleloaderobj \
diff --git a/sc/qa/extras/anchor.cxx b/sc/qa/extras/anchor.cxx
new file mode 100644
index 000000000000..fb50fab9243a
--- /dev/null
+++ b/sc/qa/extras/anchor.cxx
@@ -0,0 +1,115 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/calc_unoapi_test.hxx>
+#include <svx/svdograf.hxx>
+#include <svx/svdpage.hxx>
+#include <sfx2/dispatch.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/sheet/XSpreadsheet.hpp>
+#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
+#include <com/sun/star/text/XText.hpp>
+#include <unonames.hxx>
+
+#include <tabvwsh.hxx>
+#include <docsh.hxx>
+#include <svx/svdocirc.hxx>
+#include <scitems.hxx>
+
+#include <sc.hrc>
+
+using namespace css;
+
+namespace sc_apitest {
+
+class ScAnchorTest : public CalcUnoApiTest
+{
+public:
+    ScAnchorTest();
+
+    virtual void tearDown() override;
+
+    void testODFAnchorTypes();
+
+    CPPUNIT_TEST_SUITE(ScAnchorTest);
+
+    CPPUNIT_TEST(testODFAnchorTypes);
+    CPPUNIT_TEST_SUITE_END();
+private:
+
+    uno::Reference< lang::XComponent > mxComponent;
+};
+
+ScAnchorTest::ScAnchorTest()
+    : CalcUnoApiTest("sc/qa/unit/data/ods")
+{
+}
+
+void ScAnchorTest::testODFAnchorTypes()
+{
+    OUString aFileURL;
+    createFileURL("3AnchorTypes.ods", aFileURL);
+    // open the document with graphic included
+    uno::Reference< css::lang::XComponent > xComponent = 
loadFromDesktop(aFileURL);
+    CPPUNIT_ASSERT(xComponent.is());
+
+    // Get the document model
+    SfxObjectShell* pFoundShell = 
SfxObjectShell::GetShellFromComponent(xComponent);
+    CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
+
+    ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
+    CPPUNIT_ASSERT(pDocSh);
+
+    // Check whether graphic imported well
+    ScDocument& rDoc = pDocSh->GetDocument();
+    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
+    CPPUNIT_ASSERT(pDrawLayer);
+
+    const SdrPage *pPage = pDrawLayer->GetPage(0);
+    CPPUNIT_ASSERT(pPage);
+
+    // Check 1st object: Page anchored
+    SdrGrafObj* pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(0));
+    CPPUNIT_ASSERT(pObject);
+    ScAnchorType anchorType = ScDrawLayer::GetAnchorType(*pObject);
+    CPPUNIT_ASSERT_EQUAL(SCA_PAGE, anchorType);
+
+    // Check 2nd object: Cell anchored, resize with cell
+    pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(1));
+    CPPUNIT_ASSERT(pObject);
+    anchorType = ScDrawLayer::GetAnchorType(*pObject);
+    CPPUNIT_ASSERT_EQUAL(SCA_CELL_RESIZE, anchorType);
+
+     // Check 3rd object: Cell anchored
+    pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(2));
+    CPPUNIT_ASSERT(pObject);
+    anchorType = ScDrawLayer::GetAnchorType(*pObject);
+    CPPUNIT_ASSERT_EQUAL(SCA_CELL, anchorType);
+
+    pDocSh->DoClose();
+}
+
+void ScAnchorTest::tearDown()
+{
+    if (mxComponent.is())
+    {
+        closeDocument(mxComponent);
+    }
+
+    CalcUnoApiTest::tearDown();
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ScAnchorTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/unit/data/ods/3AnchorTypes.ods 
b/sc/qa/unit/data/ods/3AnchorTypes.ods
new file mode 100644
index 000000000000..a68c36271595
Binary files /dev/null and b/sc/qa/unit/data/ods/3AnchorTypes.ods differ
commit 8019cae7ab8f32e042918a8b0c82d97fac627b09
Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
Date:   Fri Feb 9 12:52:52 2018 +0100

    tdf#114552 Add a third anchor type for calc graphics
    
    This allows to have two cell anchored types:
    * Only cell anchored (moves with the cell when sorting etc)
    * Cell anchored, also resizes with the cell
    
    Beforehand, all cell anchored images would resize with the cell,
    which was often not what users expected.
    
    The new default (when inserting images) is now that inserted images
    are only anchored to the cell, but don't resize with the cell.
    
    This makes use of the ODF elements table:end-cell-address, table:end-x, 
table:end-y.
    When images should resize with the cell, the end address is written
    (it has always been written earlier, so documents would still import 
correctly).
    If not, they are omitted.
    
    Also implements xlsx import & export
    
    Reviewed-on: https://gerrit.libreoffice.org/49490
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
    (cherry picked from commit acf0bad4e2b8c3c43aaaee8312c8a61d3552fcc2)
    
    Change-Id: I5f96242f88943ed77a0fd12b7f39b444e1380df7

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index 03d07c356312..20ff4c237431 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -1894,6 +1894,9 @@
         <prop oor:name="ContextLabel" oor:type="xs:string">
           <value xml:lang="en-US">To P~age</value>
         </prop>
+        <prop oor:name="TooltipLabel" oor:type="xs:string">
+          <value xml:lang="en-US">Anchor to p~age</value>
+        </prop>
       </node>
       <node oor:name=".uno:SetAnchorToCell" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
@@ -1902,6 +1905,20 @@
         <prop oor:name="ContextLabel" oor:type="xs:string">
           <value xml:lang="en-US">To ~Cell</value>
         </prop>
+        <prop oor:name="TooltipLabel" oor:type="xs:string">
+          <value xml:lang="en-US">Anchor to ~cell (move with cell)</value>
+        </prop>
+      </node>
+      <node oor:name=".uno:SetAnchorToCellResize" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Anchor: To Cell (~resize with cell)</value>
+        </prop>
+        <prop oor:name="ContextLabel" oor:type="xs:string">
+          <value xml:lang="en-US">To Cell (~resize with cell)</value>
+        </prop>
+        <prop oor:name="TooltipLabel" oor:type="xs:string">
+          <value xml:lang="en-US">Anchor to cell (move and ~resize with 
cell)</value>
+        </prop>
       </node>
       <node oor:name=".uno:SendMailDocAsMS" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
diff --git a/sc/inc/drwlayer.hxx b/sc/inc/drwlayer.hxx
index 8be1d5422b3e..df1ebbe8edb1 100644
--- a/sc/inc/drwlayer.hxx
+++ b/sc/inc/drwlayer.hxx
@@ -80,6 +80,7 @@ class ScUndoAnchorData : public SdrUndoObj
 {
 private:
     bool                    mbWasCellAnchored;
+    bool                    mbWasResizeWithCell;
     ScDocument*             mpDoc;
     SCTAB                   mnTab;
 public:
@@ -174,12 +175,13 @@ public:
     void            EnsureGraphicNames();
 
     static bool IsCellAnchored( const SdrObject& rObj );
+    static bool IsResizeWithCell( const SdrObject& rObj );
     static void             SetPageAnchored( SdrObject& );
     static void             SetCellAnchored( SdrObject&, const ScDrawObjData 
&rAnchor );
     static void             SetVisualCellAnchored( SdrObject&, const 
ScDrawObjData &rAnchor );
     // Updates rAnchor based on position of rObj
     static void             GetCellAnchorFromPosition( SdrObject &rObj, 
ScDrawObjData &rAnchor, const ScDocument &rDoc, SCTAB nTab, bool bUseLogicRect 
= true, bool bHiddenAsZero = true );
-    static void             SetCellAnchoredFromPosition( SdrObject &rObj, 
const ScDocument &rDoc, SCTAB nTab );
+    static void             SetCellAnchoredFromPosition( SdrObject &rObj, 
const ScDocument &rDoc, SCTAB nTab, bool bResizeWithCell );
     static void             UpdateCellAnchorFromPositionEnd( SdrObject &rObj, 
ScDrawObjData &rAnchor, const ScDocument &rDoc, SCTAB nTab, bool bUseLogicRect 
= true );
     static ScAnchorType     GetAnchorType( const SdrObject& );
     std::map<SCROW, std::vector<SdrObject*>> GetObjectsAnchoredToRange(SCTAB 
nTab, SCCOL nCol, SCROW nStartRow, SCROW nEndRow) const;
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index 9c1bb5e377d9..29df0e988905 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -355,8 +355,9 @@ enum ScVObjMode                     // output modes of 
objects on a page
 
 enum ScAnchorType                   // anchor of a character object
 {
-    SCA_CELL,
-    SCA_PAGE,
+    SCA_CELL,                       // anchor to cell, move with cell
+    SCA_CELL_RESIZE,                // anchor to cell, move and resize with 
cell
+    SCA_PAGE,                       // anchor to page, independent of any cells
     SCA_DONTKNOW                    // for multi selection
 };
 
diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index 0b5277ed46fd..b8dac1516dc7 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -448,8 +448,9 @@
 #define DRAW_BAR_START          (RID_INPUTBAR_END)
 #define SID_ANCHOR_PAGE         (DRAW_BAR_START+24)
 #define SID_ANCHOR_CELL         (DRAW_BAR_START+25)
-#define SID_ANCHOR_TOGGLE       (DRAW_BAR_START+26)
-#define SID_ORIGINALSIZE        (DRAW_BAR_START+27)
+#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 DRAW_BAR_END            (DRAW_BAR_START+50)
 
@@ -906,6 +907,7 @@
 
 #define STR_ANCHOR_TO_CELL       (STR_START + 223)
 #define STR_ANCHOR_TO_PAGE       (STR_START + 224)
+#define STR_ANCHOR_TO_CELL_RESIZE (STR_START + 225)
 
 // navigator - in the same order as SC_CONTENT_...
 #define SCSTR_CONTENT_ROOT      (STR_START + 250)
diff --git a/sc/inc/userdat.hxx b/sc/inc/userdat.hxx
index bed2070d7ea4..3edf6fe3677d 100644
--- a/sc/inc/userdat.hxx
+++ b/sc/inc/userdat.hxx
@@ -52,6 +52,7 @@ public:
     Point               maEndOffset;
     Type                meType;
     Rectangle           maLastRect;
+    bool                mbResizeWithCell = false;
 
     explicit            ScDrawObjData();
 
diff --git a/sc/qa/extras/sccondformats.cxx b/sc/qa/extras/sccondformats.cxx
index 9f1f8c7b7d8e..f5ac2e428760 100644
--- a/sc/qa/extras/sccondformats.cxx
+++ b/sc/qa/extras/sccondformats.cxx
@@ -159,7 +159,7 @@ void ScConditionalFormatTest::testUndoAnchor()
     CPPUNIT_ASSERT(pDrawView->AreObjectsMarked() );
 
     // Set Cell Anchor
-    ScDrawLayer::SetCellAnchoredFromPosition(*pObject, rDoc, 0);
+    ScDrawLayer::SetCellAnchoredFromPosition(*pObject, rDoc, 0, false);
     // Check state
     ScAnchorType oldType = ScDrawLayer::GetAnchorType(*pObject);
     CPPUNIT_ASSERT(oldType == SCA_CELL );
diff --git a/sc/qa/unit/subsequent_export-test.cxx 
b/sc/qa/unit/subsequent_export-test.cxx
index 0941a0b0adb0..5638017e2de4 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -3399,7 +3399,8 @@ void ScExportTest::testMoveCellAnchoredShapes()
 
     // Check cell anchor state
     ScAnchorType oldType = ScDrawLayer::GetAnchorType(*pObj);
-    CPPUNIT_ASSERT_MESSAGE( "Failed to get anchor type", oldType == SCA_CELL );
+    CPPUNIT_ASSERT_MESSAGE( "Failed to get anchor type", oldType == 
SCA_CELL_RESIZE );
+
 
     // Get anchor data
     ScDrawObjData* pData = ScDrawLayer::GetObjData(pObj);
@@ -3461,7 +3462,7 @@ void ScExportTest::testMoveCellAnchoredShapes()
 
     // Check cell anchor state
     oldType = ScDrawLayer::GetAnchorType(*pObj);
-    CPPUNIT_ASSERT_MESSAGE( "Failed to get anchor type", oldType == SCA_CELL );
+    CPPUNIT_ASSERT_MESSAGE( "Failed to get anchor type", oldType == 
SCA_CELL_RESIZE );
 
     // Get anchor data
     pData = ScDrawLayer::GetObjData(pObj);
@@ -3522,7 +3523,7 @@ void ScExportTest::testMoveCellAnchoredShapes()
 
     // Check cell anchor state
     oldType = ScDrawLayer::GetAnchorType(*pObj);
-    CPPUNIT_ASSERT_MESSAGE( "Failed to get anchor type", oldType == SCA_CELL );
+    CPPUNIT_ASSERT_MESSAGE( "Failed to get anchor type", oldType == 
SCA_CELL_RESIZE );
 
     // Get anchor data
     pData = ScDrawLayer::GetObjData(pObj);
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 5a38c92fabfc..3c2f6c723fb8 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -2577,7 +2577,7 @@ void Test::testGraphicsInGroup()
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Should not change when page anchored",
                                static_cast<const Rectangle &>(aOrigRect), 
rNewRect);
 
-        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0);
+        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, true);
         CPPUNIT_ASSERT_EQUAL_MESSAGE("That shouldn't change size or 
positioning",
                                static_cast<const Rectangle &>(aOrigRect), 
rNewRect);
 
@@ -2602,7 +2602,7 @@ void Test::testGraphicsInGroup()
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Position and size of the circle 
shouldn't change when inserted into the page.",
                                static_cast<const Rectangle &>(aOrigRect), 
rNewRect);
 
-        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0);
+        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, false);
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Size changed when cell anchored. Not 
good.",
                                static_cast<const Rectangle &>(aOrigRect), 
rNewRect);
 
@@ -2635,7 +2635,7 @@ void Test::testGraphicsInGroup()
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Size differ.",
                                static_cast<const Rectangle &>(aOrigRect), 
rNewRect);
 
-        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0);
+        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, false);
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Size changed when cell-anchored. Not 
good.",
                                static_cast<const Rectangle &>(aOrigRect), 
rNewRect);
 
@@ -2671,7 +2671,7 @@ void Test::testGraphicsOnSheetMove()
     Rectangle aObjRect(2,2,100,100);
     SdrObject* pObj = new SdrRectObj(aObjRect);
     pPage->InsertObject(pObj);
-    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0);
+    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, false);
 
     CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be one object on the 1st 
sheet.", static_cast<size_t>(1), pPage->GetObjCount());
 
@@ -5120,7 +5120,7 @@ void Test::testAnchoredRotatedShape()
         double nCos=cos(nAngle*nPi180);
         pObj->Rotate(aRef1,nAngle,nSin,nCos);
 
-        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0);
+        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, true);
 
         Rectangle aSnap = pObj->GetSnapRect();
         CPPUNIT_ASSERT_EQUAL( true, testEqualsWithTolerance( 
aRotRect.GetHeight(), aSnap.GetHeight(), TOLERANCE ) );
@@ -5889,7 +5889,7 @@ void Test::testUndoDataAnchor()
     Rectangle aObjRect(2,1000,100,1100);
     SdrObject* pObj = new SdrRectObj(aObjRect);
     pPage->InsertObject(pObj);
-    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0);
+    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, false);
 
     // Get anchor data
     ScDrawObjData* pData = ScDrawLayer::GetObjData(pObj);
diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx
index beb2502c180f..c6487b0117c9 100644
--- a/sc/qa/unit/ucalc_sort.cxx
+++ b/sc/qa/unit/ucalc_sort.cxx
@@ -1949,7 +1949,7 @@ void Test::testSortImages()
     CPPUNIT_ASSERT(pPage);
     pPage->InsertObject(pObj);
     // Anchor to cell
-    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0);
+    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, false);
     // Move to cell B2
     ScAddress aCellPos(1, 1, 0);
     pDrawLayer->MoveObject(pObj, aCellPos);
diff --git a/sc/sdi/drawsh.sdi b/sc/sdi/drawsh.sdi
index 0aa9964237ae..3a12ef500174 100644
--- a/sc/sdi/drawsh.sdi
+++ b/sc/sdi/drawsh.sdi
@@ -169,7 +169,8 @@ interface TableDraw
     SID_ANCHOR_PAGE         [ ExecMethod = ExecDrawFunc; StateMethod = 
GetState; Export = FALSE; ]
     SID_ANCHOR_TOGGLE       [ ExecMethod = ExecDrawFunc; StateMethod = 
GetDrawFuncState; Export = FALSE; ]
     SID_ANCHOR_CELL         [ ExecMethod = ExecDrawFunc; StateMethod = 
GetState; Export = FALSE; ]
-     // ---- FontWork:
+    SID_ANCHOR_CELL_RESIZE  [ ExecMethod = ExecDrawFunc; StateMethod = 
GetState; Export = FALSE; ]
+    // FontWork:
     SID_FONTWORK            [ ExecMethod = ExecDrawFunc; StateMethod = 
GetState; Export = FALSE; ]
     SID_FORMTEXT_STYLE      [ ExecMethod = ExecFormText; StateMethod = 
GetFormTextState; Export = FALSE; ]
     SID_FORMTEXT_ADJUST     [ ExecMethod = ExecFormText; StateMethod = 
GetFormTextState; Export = FALSE; ]
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index 407de11e1b1c..5b97aaa8c5ff 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -4808,7 +4808,25 @@ SfxBoolItem SetAnchorToCell SID_ANCHOR_CELL
 ]
 
 
-SfxBoolItem SetAnchorToPage SID_ANCHOR_PAGE
+SfxVoidItem SetAnchorToCellResize SID_ANCHOR_CELL_RESIZE
+()
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+
+    AccelConfig = FALSE,
+    MenuConfig = FALSE,
+    ToolBoxConfig = FALSE,
+    GroupId = GID_FORMAT;
+]
+
+
+SfxVoidItem SetAnchorToPage SID_ANCHOR_PAGE
 ()
 [
     AutoUpdate = FALSE,
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index 14daf6a83ea6..4ac593948eac 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -151,6 +151,7 @@ ScUndoAnchorData::ScUndoAnchorData( SdrObject* pObjP, 
ScDocument* pDoc, SCTAB nT
     mnTab( nTab )
 {
     mbWasCellAnchored = ScDrawLayer::IsCellAnchored( *pObjP );
+    mbWasResizeWithCell = ScDrawLayer::IsResizeWithCell( *pObjP );
 }
 
 ScUndoAnchorData::~ScUndoAnchorData()
@@ -167,7 +168,7 @@ void ScUndoAnchorData::Undo()
     }
 
     if (mbWasCellAnchored)
-        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *mpDoc, mnTab);
+        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *mpDoc, mnTab, 
mbWasResizeWithCell);
     else
         ScDrawLayer::SetPageAnchored( *pObj );
 }
@@ -177,7 +178,7 @@ void ScUndoAnchorData::Redo()
     if (mbWasCellAnchored)
         ScDrawLayer::SetPageAnchored( *pObj );
     else
-        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *mpDoc, mnTab);
+        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *mpDoc, mnTab, 
mbWasResizeWithCell);
 
     // Trigger Object Change
     if (pObj->IsInserted() && pObj->GetPage() && pObj->GetModel())
@@ -827,14 +828,15 @@ void ScDrawLayer::RecalcPos( SdrObject* pObj, 
ScDrawObjData& rData, bool bNegati
     }
     else
     {
-        bool bCanResize = bValid2 && !pObj->IsResizeProtect();
+        bool bCanResize = bValid2 && !pObj->IsResizeProtect() && 
rData.mbResizeWithCell;
 
         //First time positioning, must be able to at least move it
         ScDrawObjData& rNoRotatedAnchor = *GetNonRotatedObjData( pObj, true );
         if (rData.maLastRect.IsEmpty())
         {
             // Every shape it is saved with an negative offset relative to cell
-            if (ScDrawLayer::GetAnchorType(*pObj) == SCA_CELL)
+            ScAnchorType aAnchorType = ScDrawLayer::GetAnchorType(*pObj);
+            if (aAnchorType == SCA_CELL || aAnchorType == SCA_CELL_RESIZE)
             {
                 double fRotate(0.0);
                 double fShearX(0.0);
@@ -1881,6 +1883,7 @@ void ScDrawLayer::SetVisualCellAnchored( SdrObject &rObj, 
const ScDrawObjData &r
     pAnchor->maEnd = rAnchor.maEnd;
     pAnchor->maStartOffset = rAnchor.maStartOffset;
     pAnchor->maEndOffset = rAnchor.maEndOffset;
+    pAnchor->mbResizeWithCell = rAnchor.mbResizeWithCell;
 }
 
 void ScDrawLayer::SetCellAnchored( SdrObject &rObj, const ScDrawObjData 
&rAnchor )
@@ -1890,19 +1893,23 @@ void ScDrawLayer::SetCellAnchored( SdrObject &rObj, 
const ScDrawObjData &rAnchor
     pAnchor->maEnd = rAnchor.maEnd;
     pAnchor->maStartOffset = rAnchor.maStartOffset;
     pAnchor->maEndOffset = rAnchor.maEndOffset;
+    pAnchor->mbResizeWithCell = rAnchor.mbResizeWithCell;
 }
 
-void ScDrawLayer::SetCellAnchoredFromPosition( SdrObject &rObj, const 
ScDocument &rDoc, SCTAB nTab )
+void ScDrawLayer::SetCellAnchoredFromPosition( SdrObject &rObj, const 
ScDocument &rDoc, SCTAB nTab,
+                                               bool bResizeWithCell )
 {
     ScDrawObjData aAnchor;
     // set anchor in terms of the visual ( SnapRect )
     // object ( e.g. for when object is rotated )
     GetCellAnchorFromPosition( rObj, aAnchor, rDoc, nTab, false );
+    aAnchor.mbResizeWithCell = bResizeWithCell;
     SetCellAnchored( rObj, aAnchor );
     // - keep also an anchor in terms of the Logic ( untransformed ) object
     // because thats what we stored ( and still do ) to xml
     ScDrawObjData aVisAnchor;
     GetCellAnchorFromPosition( rObj, aVisAnchor, rDoc, nTab );
+    aVisAnchor.mbResizeWithCell = bResizeWithCell;
     SetVisualCellAnchored( rObj, aVisAnchor );
     // absolutely necessary to set flag that in order to prevent 
ScDrawLayer::RecalcPos
     // doing an initialisation hack
@@ -1964,6 +1971,17 @@ bool ScDrawLayer::IsCellAnchored( const SdrObject& rObj )
     return GetFirstUserDataOfType(&rObj, SC_UD_OBJDATA) != nullptr;
 }
 
+bool ScDrawLayer::IsResizeWithCell( const SdrObject& rObj )
+{
+    // Cell anchored object always has a user data, to store the anchor cell
+    // info. If it doesn't then it's page-anchored.
+    ScDrawObjData* pDrawObjData = GetObjData(const_cast<SdrObject*>(&rObj));
+    if (!pDrawObjData)
+        return false;
+
+    return pDrawObjData->mbResizeWithCell;
+}
+
 void ScDrawLayer::SetPageAnchored( SdrObject &rObj )
 {
     DeleteFirstUserDataOfType(&rObj, SC_UD_OBJDATA);
@@ -1974,7 +1992,17 @@ ScAnchorType ScDrawLayer::GetAnchorType( const SdrObject 
&rObj )
 {
     //If this object has a cell anchor associated with it
     //then its cell-anchored, otherwise its page-anchored
-    return ScDrawLayer::GetObjData(const_cast<SdrObject*>(&rObj)) ? SCA_CELL : 
SCA_PAGE;
+    const ScDrawObjData* pObjData = 
ScDrawLayer::GetObjData(const_cast<SdrObject*>(&rObj));
+
+    // When there is no cell anchor, it is page anchored.
+    if (!pObjData)
+        return SCA_PAGE;
+
+    // It's cell-anchored, check if the object resizes with the cell
+    if (pObjData->mbResizeWithCell)
+        return SCA_CELL_RESIZE;
+
+    return SCA_CELL;
 }
 
 std::map<SCROW, std::vector<SdrObject*>>
diff --git a/sc/source/core/data/userdat.cxx b/sc/source/core/data/userdat.cxx
index f06d2201facc..401bf3e06281 100644
--- a/sc/source/core/data/userdat.cxx
+++ b/sc/source/core/data/userdat.cxx
@@ -53,7 +53,8 @@ ScDrawObjData::ScDrawObjData() :
     SdrObjUserData( SC_DRAWLAYER, SC_UD_OBJDATA ),
     maStart( ScAddress::INITIALIZE_INVALID ),
     maEnd( ScAddress::INITIALIZE_INVALID ),
-    meType( DrawingObject )
+    meType( DrawingObject ),
+    mbResizeWithCell( false )
 {
 }
 
diff --git a/sc/source/filter/excel/xiescher.cxx 
b/sc/source/filter/excel/xiescher.cxx
index 1236eeacd639..4bc9b4a3e609 100644
--- a/sc/source/filter/excel/xiescher.cxx
+++ b/sc/source/filter/excel/xiescher.cxx
@@ -3604,7 +3604,7 @@ SdrObject* XclImpDffConverter::FinalizeObj(DffObjData& 
rDffObjData, SdrObject* p
     {
         // cell anchoring
         if ( !rDffObjData.bPageAnchor )
-            ScDrawLayer::SetCellAnchoredFromPosition( *xSdrObj,  GetDoc(), 
xDrawObj->GetTab() );
+            ScDrawLayer::SetCellAnchoredFromPosition( *xSdrObj,  GetDoc(), 
xDrawObj->GetTab(), false );
     }
 
     return xSdrObj.release();
diff --git a/sc/source/filter/inc/drawingbase.hxx 
b/sc/source/filter/inc/drawingbase.hxx
index 16e258f7a911..dfc10b76c86c 100644
--- a/sc/source/filter/inc/drawingbase.hxx
+++ b/sc/source/filter/inc/drawingbase.hxx
@@ -73,8 +73,11 @@ public:
     {
         ANCHOR_INVALID,         /// Anchor type is unknown.
         ANCHOR_ABSOLUTE,        /// Absolute anchor (top-left corner and size 
in absolute units).
+                                /// Matches our "Page" anchor -> 
ScAnchorType::SCA_PAGE
         ANCHOR_ONECELL,         /// One-cell anchor (top-left corner at cell, 
size in absolute units).
+                                /// Matches our "Cell" anchor -> 
ScAnchorType::SCA_CELL
         ANCHOR_TWOCELL,         /// Two-cell anchor (top-left and bottom-right 
corner at cell).
+                                /// Matches our "Cell (resize with cell)" 
anchor -> ScAnchorType::SCA_CELL_RESIZE
         ANCHOR_VML
     };
     explicit            ShapeAnchor( const WorksheetHelper& rHelper );
diff --git a/sc/source/filter/oox/drawingbase.cxx 
b/sc/source/filter/oox/drawingbase.cxx
index eae05aac6241..7b7ba6f2b8bd 100644
--- a/sc/source/filter/oox/drawingbase.cxx
+++ b/sc/source/filter/oox/drawingbase.cxx
@@ -93,6 +93,8 @@ void ShapeAnchor::importAnchor( sal_Int32 nElement, const 
AttributeList& rAttrib
                     meEditAs = ANCHOR_ABSOLUTE;
                 else if ( sEditAs.equalsIgnoreAsciiCase("oneCell") )
                     meEditAs = ANCHOR_ONECELL;
+                else if (sEditAs.equalsIgnoreAsciiCase("twoCell") )
+                    meEditAs = ANCHOR_TWOCELL;
             }
         }
         break;
diff --git a/sc/source/filter/oox/drawingfragment.cxx 
b/sc/source/filter/oox/drawingfragment.cxx
index 7c220930ad13..608b3bc02382 100644
--- a/sc/source/filter/oox/drawingfragment.cxx
+++ b/sc/source/filter/oox/drawingfragment.cxx
@@ -295,7 +295,8 @@ void DrawingFragment::onEndElement()
                         SdrObject* pObj = SdrObject::getSdrObjectFromXShape( 
mxShape->getXShape() );
                         if ( pObj )
                         {
-                             ScDrawLayer::SetCellAnchoredFromPosition( *pObj, 
getScDocument(), static_cast<SCTAB>( getSheetIndex() ) );
+                            bool bResizeWithCell = mxAnchor->getEditAs() == 
ShapeAnchor::ANCHOR_TWOCELL;
+                            ScDrawLayer::SetCellAnchoredFromPosition( *pObj, 
getScDocument(), static_cast<SCTAB>( getSheetIndex() ), bResizeWithCell );
                         }
                     }
                 }
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx 
b/sc/source/filter/xcl97/xcl97rec.cxx
index 0860a8c16c03..02df8f21ce6a 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -1037,11 +1037,15 @@ GetEditAs( XclObjAny& rObj )
 {
     if( const SdrObject* pShape = EscherEx::GetSdrObject( rObj.GetShape() ) )
     {
-        // OOXTODO: returning "twoCell"
         switch( ScDrawLayer::GetAnchorType( *pShape ) )
         {
-            case SCA_CELL:  return "oneCell";
-            default:        break;
+            case SCA_CELL:
+                return "oneCell";
+            case SCA_CELL_RESIZE:
+                return "twoCell";
+            default:
+            case SCA_PAGE:
+                break; // absolute
         }
     }
     return "absolute";
diff --git a/sc/source/filter/xml/XMLExportIterator.hxx 
b/sc/source/filter/xml/XMLExportIterator.hxx
index 2419616c43ba..88d80c3569e3 100644
--- a/sc/source/filter/xml/XMLExportIterator.hxx
+++ b/sc/source/filter/xml/XMLExportIterator.hxx
@@ -64,6 +64,7 @@ struct ScMyShape
     ScAddress   aEndAddress;
     sal_Int32       nEndX;
     sal_Int32       nEndY;
+    bool            bResizeWithCell;
     css::uno::Reference<css::drawing::XShape> xShape;
 
     bool operator<(const ScMyShape& aShape) const;
diff --git a/sc/source/filter/xml/XMLTableShapeImportHelper.cxx 
b/sc/source/filter/xml/XMLTableShapeImportHelper.cxx
index 553c36fae9c2..7013cd6eb5b0 100644
--- a/sc/source/filter/xml/XMLTableShapeImportHelper.cxx
+++ b/sc/source/filter/xml/XMLTableShapeImportHelper.cxx
@@ -92,6 +92,7 @@ void XMLTableShapeImportHelper::finishShape(
             aAnchor.maStart = ScAddress(aStartCell.Column, aStartCell.Row, 
aStartCell.Sheet);
             awt::Point aStartPoint(rShape->getPosition());
             aAnchor.maStartOffset = Point(aStartPoint.X, aStartPoint.Y);
+            aAnchor.mbResizeWithCell = false;
 
             sal_Int32 nEndX(-1);
             sal_Int32 nEndY(-1);
@@ -115,6 +116,8 @@ void XMLTableShapeImportHelper::finishShape(
                         sal_Int32 nOffset(0);
                         ScRangeStringConverter::GetAddressFromString(aEndCell, 
rValue, static_cast<ScXMLImport&>(mrImporter).GetDocument(), 
::formula::FormulaGrammar::CONV_OOO, nOffset);
                         aAnchor.maEnd = ScAddress(aEndCell.Column, 
aEndCell.Row, aEndCell.Sheet);
+                        // When the cell end address is set, we let the shape 
resize with the cell
+                        aAnchor.mbResizeWithCell = true;
                     }
                     else if (IsXMLToken(aLocalName, XML_END_X))
                     {
diff --git a/sc/source/filter/xml/xmlexprt.cxx 
b/sc/source/filter/xml/xmlexprt.cxx
index 2d87d33a6b28..8411d106d3e2 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -572,6 +572,7 @@ void ScXMLExport::CollectSharedData(SCTAB& nTableCount, 
sal_Int32& nShapesCount)
                 aMyShape.nEndX = pAnchor->maEndOffset.X();
                 aMyShape.nEndY = pAnchor->maEndOffset.Y();
                 aMyShape.xShape = xShape;
+                aMyShape.bResizeWithCell = 
ScDrawLayer::IsResizeWithCell(*pSdrObj);
                 pSharedData->AddNewShape(aMyShape);
                 pSharedData->SetLastColumn(nTable, pAnchor->maStart.Col());
                 pSharedData->SetLastRow(nTable, pAnchor->maStart.Row());
@@ -3499,7 +3500,10 @@ void ScXMLExport::WriteShapes(const ScMyCell& rMyCell)
             {
                 if (bNegativePage)
                     aPoint.X = 2 * aItr->xShape->getPosition().X + 
aItr->xShape->getSize().Width - aPoint.X;
-                if ( aItr->xShape->getShapeType() != 
"com.sun.star.drawing.CaptionShape" )
+
+                // We only write the end address if we want the shape to 
resize with the cell
+                if ( aItr->bResizeWithCell &&
+                    aItr->xShape->getShapeType() != 
"com.sun.star.drawing.CaptionShape" )
                 {
                     OUString sEndAddress;
                     ScRangeStringConverter::GetStringFromAddress(sEndAddress, 
aItr->aEndAddress, pDoc, FormulaGrammar::CONV_OOO);
diff --git a/sc/source/ui/drawfunc/drawsh2.cxx 
b/sc/source/ui/drawfunc/drawsh2.cxx
index 6ee0f37ae564..d754869834fa 100644
--- a/sc/source/ui/drawfunc/drawsh2.cxx
+++ b/sc/source/ui/drawfunc/drawsh2.cxx
@@ -102,6 +102,7 @@ void ScDrawShell::GetState( SfxItemSet& rSet )          // 
Zustaende / Toggles
             bDisableAnchor = true;
             rSet.DisableItem( SID_ANCHOR_PAGE );
             rSet.DisableItem( SID_ANCHOR_CELL );
+            rSet.DisableItem( SID_ANCHOR_CELL_RESIZE );
         }
     }
 
@@ -112,16 +113,25 @@ void ScDrawShell::GetState( SfxItemSet& rSet )          
// Zustaende / Toggles
         case SCA_PAGE:
             rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, true ) );
             rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, false ) );
+            rSet.Put( SfxBoolItem( SID_ANCHOR_CELL_RESIZE, false ) );
         break;
 
         case SCA_CELL:
-        rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, false ) );
-        rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, true ) );
+            rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, false ) );
+            rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, true ) );
+            rSet.Put( SfxBoolItem( SID_ANCHOR_CELL_RESIZE, false ) );
+        break;
+
+        case SCA_CELL_RESIZE:
+            rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, false ) );
+            rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, false ) );
+            rSet.Put( SfxBoolItem( SID_ANCHOR_CELL_RESIZE, true ) );
         break;
 
         default:
-        rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, false ) );
-        rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, false ) );
+            rSet.Put( SfxBoolItem( SID_ANCHOR_PAGE, false ) );
+            rSet.Put( SfxBoolItem( SID_ANCHOR_CELL, false ) );
+            rSet.Put( SfxBoolItem( SID_ANCHOR_CELL_RESIZE, false ) );
         break;
         }
     }
diff --git a/sc/source/ui/drawfunc/drawsh5.cxx 
b/sc/source/ui/drawfunc/drawsh5.cxx
index 28a9084a66c2..04238223015e 100644
--- a/sc/source/ui/drawfunc/drawsh5.cxx
+++ b/sc/source/ui/drawfunc/drawsh5.cxx
@@ -360,28 +360,41 @@ void ScDrawShell::ExecDrawFunc( SfxRequest& rReq )
             pView->SetPageAnchored();
             rBindings.Invalidate( SID_ANCHOR_PAGE );
             rBindings.Invalidate( SID_ANCHOR_CELL );
+            rBindings.Invalidate( SID_ANCHOR_CELL_RESIZE );
             break;
 
         case SID_ANCHOR_CELL:
-            pView->SetCellAnchored();
+            pView->SetCellAnchored(false);
             rBindings.Invalidate( SID_ANCHOR_PAGE );
             rBindings.Invalidate( SID_ANCHOR_CELL );
+            rBindings.Invalidate( SID_ANCHOR_CELL_RESIZE );
             break;
 
+        case SID_ANCHOR_CELL_RESIZE:
+            pView->SetCellAnchored(true);
+            rBindings.Invalidate( SID_ANCHOR_PAGE );
+            rBindings.Invalidate( SID_ANCHOR_CELL );
+            rBindings.Invalidate( SID_ANCHOR_CELL_RESIZE );
+            break;
+
+        // TODO: This toggle should probably be converted to a dropdown,
+        //       since we now have three states, not two.
         case SID_ANCHOR_TOGGLE:
             {
                 switch( pView->GetAnchorType() )
                 {
                     case SCA_CELL:
+                    case SCA_CELL_RESIZE:
                     pView->SetPageAnchored();
                     break;
                     default:
-                    pView->SetCellAnchored();
+                    pView->SetCellAnchored(false);
                     break;
                 }
             }
             rBindings.Invalidate( SID_ANCHOR_PAGE );
             rBindings.Invalidate( SID_ANCHOR_CELL );
+            rBindings.Invalidate( SID_ANCHOR_CELL_RESIZE );
             break;
 
         case SID_OBJECT_ROTATE:
diff --git a/sc/source/ui/drawfunc/fuins1.cxx b/sc/source/ui/drawfunc/fuins1.cxx
index d10230addbf3..373429a62770 100644
--- a/sc/source/ui/drawfunc/fuins1.cxx
+++ b/sc/source/ui/drawfunc/fuins1.cxx
@@ -96,7 +96,7 @@ void ScLimitSizeOnDrawPage( Size& rSize, Point& rPos, const 
Size& rPage )
 
 static void lcl_InsertGraphic( const Graphic& rGraphic,
                         const OUString& rFileName, const OUString& 
rFilterName, bool bAsLink, bool bApi,
-                        ScTabViewShell* pViewSh, vcl::Window* pWindow, 
SdrView* pView, bool bAnchorToCell=true )
+                        ScTabViewShell* pViewSh, vcl::Window* pWindow, 
SdrView* pView, ScAnchorType aAnchorType = SCA_CELL )
 {
     ScDrawView* pDrawView = pViewSh->GetScDrawView();
 
@@ -168,8 +168,9 @@ static void lcl_InsertGraphic( const Graphic& rGraphic,
     OUString aName = pLayer->GetNewGraphicName();                 // "Graphics"
     pObj->SetName(aName);
 
-    if (bAnchorToCell)
-        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, 
*(rData.GetDocument()), rData.GetTabNo());
+    if (aAnchorType == SCA_CELL || aAnchorType == SCA_CELL_RESIZE)
+        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, 
*(rData.GetDocument()), rData.GetTabNo(),
+                                                 aAnchorType == 
SCA_CELL_RESIZE);
 
     //  don't select if from (dispatch) API, to allow subsequent cell 
operations
     SdrInsertFlags nInsOptions = bApi ? SdrInsertFlags::DONTMARK : 
SdrInsertFlags::NONE;
@@ -271,6 +272,7 @@ FuInsertGraphic::FuInsertGraphic( ScTabViewShell*   pViewSh,
         sal_Int16 nSelect = 0;
         Sequence<OUString> aListBoxEntries {
             ScResId(STR_ANCHOR_TO_CELL),
+            ScResId(STR_ANCHOR_TO_CELL_RESIZE),
             ScResId(STR_ANCHOR_TO_PAGE)
         };
         try
@@ -313,9 +315,18 @@ FuInsertGraphic::FuInsertGraphic( ScTabViewShell*   
pViewSh,
                     ui::dialogs::ListboxControlActions::GET_SELECTED_ITEM );
                 OUString sAnchor;
                 aAnchorValue >>= sAnchor;
-                bool bAnchorToCell = sAnchor == ScResId(STR_ANCHOR_TO_CELL);
 
-                lcl_InsertGraphic( aGraphic, aFileName, aFilterName, bAsLink, 
false, pViewSh, pWindow, pView, bAnchorToCell );
+                ScAnchorType aAnchorType;
+                if (sAnchor == ScResId(STR_ANCHOR_TO_CELL))
+                    aAnchorType = SCA_CELL;
+                else if (sAnchor == ScResId(STR_ANCHOR_TO_CELL_RESIZE))
+                    aAnchorType = SCA_CELL_RESIZE;
+                else if (sAnchor == ScResId(STR_ANCHOR_TO_PAGE))
+                    aAnchorType = SCA_PAGE;
+                else
+                    aAnchorType = SCA_DONTKNOW;
+
+                lcl_InsertGraphic( aGraphic, aFileName, aFilterName, bAsLink, 
false, pViewSh, pWindow, pView, aAnchorType );
 
                 //  append items for recording
                 rReq.AppendItem( SfxStringItem( SID_INSERT_GRAPHIC, aFileName 
) );
diff --git a/sc/source/ui/inc/drawview.hxx b/sc/source/ui/inc/drawview.hxx
index 99280f31eeb6..ce72f79370cf 100644
--- a/sc/source/ui/inc/drawview.hxx
+++ b/sc/source/ui/inc/drawview.hxx
@@ -101,7 +101,7 @@ public:
     void            CalcNormScale( Fraction& rFractX, Fraction& rFractY ) 
const;
 
     void            SetPageAnchored();
-    void            SetCellAnchored();
+    void            SetCellAnchored(bool bResizeWithCell);
     ScAnchorType    GetAnchorType() const;
 
     void            UpdateIMap( SdrObject* pObj );
diff --git a/sc/source/ui/src/scstring.src b/sc/source/ui/src/scstring.src
index d47e14d9081a..092362472ede 100644
--- a/sc/source/ui/src/scstring.src
+++ b/sc/source/ui/src/scstring.src
@@ -921,6 +921,11 @@ String STR_ANCHOR_TO_CELL
     Text [ en-US ] = "To cell" ;
 };
 
+String STR_ANCHOR_TO_CELL_RESIZE
+{
+    Text [ en-US ] = "To cell (resize with cell)" ;
+};
+
 String STR_ANCHOR_TO_PAGE
 {
     Text [ en-US ] = "To page" ;
diff --git a/sc/source/ui/view/drawvie3.cxx b/sc/source/ui/view/drawvie3.cxx
index 85228549b314..8ac6455e26b7 100644
--- a/sc/source/ui/view/drawvie3.cxx
+++ b/sc/source/ui/view/drawvie3.cxx
@@ -80,7 +80,7 @@ void ScDrawView::SetPageAnchored()
     }
 }
 
-void ScDrawView::SetCellAnchored()
+void ScDrawView::SetCellAnchored(bool bResizeWithCell)
 {
     if (!pDoc)
         return;
@@ -95,7 +95,7 @@ void ScDrawView::SetCellAnchored()
         {
             SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
             AddUndo (new ScUndoAnchorData( pObj, pDoc, nTab ));
-            ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *pDoc, nTab);
+            ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *pDoc, nTab, 
bResizeWithCell);
         }
         EndUndo();
 
@@ -111,6 +111,7 @@ ScAnchorType ScDrawView::GetAnchorType() const
 {
     bool bPage = false;
     bool bCell = false;
+    bool bCellResize = false;
     if( AreObjectsMarked() )
     {
         const SdrMarkList* pMark = &GetMarkedObjectList();
@@ -118,16 +119,21 @@ ScAnchorType ScDrawView::GetAnchorType() const
         for( size_t i=0; i<nCount; ++i )
         {
             const SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
-            if( ScDrawLayer::GetAnchorType( *pObj ) == SCA_CELL )
+            const ScAnchorType aAnchorType = ScDrawLayer::GetAnchorType( *pObj 
);
+            if( aAnchorType == SCA_CELL )
                 bCell =true;
+            else if (aAnchorType == SCA_CELL_RESIZE)
+                bCellResize = true;
             else
                 bPage = true;
         }
     }
-    if( bPage && !bCell )
+    if( bPage && !bCell && !bCellResize )
         return SCA_PAGE;
-    if( !bPage && bCell )
+    if( !bPage && bCell && !bCellResize )
         return SCA_CELL;
+    if( !bPage && !bCell && bCellResize )
+        return SCA_CELL_RESIZE;
     return SCA_DONTKNOW;
 }
 
@@ -162,7 +168,7 @@ void adjustAnchoredPosition(const SdrHint& rHint, const 
ScDocument& rDoc, SCTAB
         // anchored on all selected sheets.
         return;
 
-    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, 
pAnchor->maStart.Tab());
+    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, 
pAnchor->maStart.Tab(), pAnchor->mbResizeWithCell);
 }
 
 }
diff --git a/sc/source/ui/view/viewfun7.cxx b/sc/source/ui/view/viewfun7.cxx
index da2bdba0d113..30fbce62d371 100644
--- a/sc/source/ui/view/viewfun7.cxx
+++ b/sc/source/ui/view/viewfun7.cxx
@@ -173,7 +173,7 @@ void ScViewFunc::PasteDraw( const Point& rLogicPos, 
SdrModel* pModel,
                     pScDrawView->AddUndo(new SdrUndoInsertObj( *pNeuObj ));
 
                     if (ScDrawLayer::IsCellAnchored(*pNeuObj))
-                        ScDrawLayer::SetCellAnchoredFromPosition(*pNeuObj, 
*GetViewData().GetDocument(), nTab);
+                        ScDrawLayer::SetCellAnchoredFromPosition(*pNeuObj, 
*GetViewData().GetDocument(), nTab, ScDrawLayer::IsResizeWithCell(*pNeuObj));
                 }
             }
 
@@ -240,7 +240,8 @@ void ScViewFunc::PasteDraw( const Point& rLogicPos, 
SdrModel* pModel,
                     pObject->NbcSetLayer(SC_LAYER_CONTROLS);
 
                 if (ScDrawLayer::IsCellAnchored(*pObject))
-                    ScDrawLayer::SetCellAnchoredFromPosition(*pObject, 
*GetViewData().GetDocument(), nTab);
+                    ScDrawLayer::SetCellAnchoredFromPosition(*pObject, 
*GetViewData().GetDocument(), nTab,
+                                                             
ScDrawLayer::IsResizeWithCell(*pObject));
 
                 pObject = aIter.Next();
             }
diff --git a/sc/uiconfig/scalc/popupmenu/anchor.xml 
b/sc/uiconfig/scalc/popupmenu/anchor.xml
index c269bef3ad16..6268cd0b9ae8 100644
--- a/sc/uiconfig/scalc/popupmenu/anchor.xml
+++ b/sc/uiconfig/scalc/popupmenu/anchor.xml
@@ -8,6 +8,7 @@
  *
 -->
 <menu:menupopup xmlns:menu="http://openoffice.org/2001/menu";>
-  <menu:menuitem menu:id=".uno:SetAnchorToPage" menu:style="radio"/>
   <menu:menuitem menu:id=".uno:SetAnchorToCell" menu:style="radio"/>
+  <menu:menuitem menu:id=".uno:SetAnchorToCellResize" menu:style="radio"/>
+  <menu:menuitem menu:id=".uno:SetAnchorToPage" menu:style="radio"/>
 </menu:menupopup>
commit 2f5c5aa139268e040a511823288d9edc3c3e29c8
Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
Date:   Tue Feb 6 17:48:51 2018 +0100

    tdf#86739 Option to set image anchor type in image insert dialog
    
    This adds the selectbox to (hopefully) all filepickers:
    - LO native
    - GTK/GTK3
    - KDE4
    - KDE5
    - Windows
    - macOS
    
    Reviewed-on: https://gerrit.libreoffice.org/49311
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
    (cherry picked from commit 38774ce79b4b24628c3a73f387489bf2498363f1)
    
    Change-Id: I01bd42b1ca18e0f691b879647a6cb1b62177d3ce

diff --git a/fpicker/source/aqua/ControlHelper.hxx 
b/fpicker/source/aqua/ControlHelper.hxx
index c564c18a4100..db18a950b226 100644
--- a/fpicker/source/aqua/ControlHelper.hxx
+++ b/fpicker/source/aqua/ControlHelper.hxx
@@ -82,6 +82,7 @@ public:
         VERSION,
         TEMPLATE,
         IMAGE_TEMPLATE,
+        IMAGE_ANCHOR,
         LIST_LAST
     };
 
diff --git a/fpicker/source/aqua/ControlHelper.mm 
b/fpicker/source/aqua/ControlHelper.mm
index 5727cdf35cdf..f0b396d549ec 100644
--- a/fpicker/source/aqua/ControlHelper.mm
+++ b/fpicker/source/aqua/ControlHelper.mm
@@ -205,6 +205,11 @@ void ControlHelper::initialize( sal_Int16 nTemplateId )
             m_bToggleVisibility[PREVIEW] = true;
             m_bListVisibility[IMAGE_TEMPLATE] = true;
             break;
+        case FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR:
+            m_bToggleVisibility[LINK] = true;
+            m_bToggleVisibility[PREVIEW] = true;
+            m_bListVisibility[IMAGE_ANCHOR] = true;
+            break;
         case FILEOPEN_READONLY_VERSION:
             m_bToggleVisibility[READONLY] = true;
             m_bListVisibility[VERSION] = true;
@@ -536,6 +541,7 @@ void ControlHelper::createControls()
                 MAP_LIST_(VERSION);
                 MAP_LIST_(TEMPLATE);
                 MAP_LIST_(IMAGE_TEMPLATE);
+                MAP_LIST_(IMAGE_ANCHOR);
             }
 
             m_aActiveControls.push_back(m_pListControls[i]);
@@ -609,6 +615,7 @@ int ControlHelper::getControlElementName(const Class 
aClazz, const int nControlI
             LIST_ELEMENT( VERSION );
             LIST_ELEMENT( TEMPLATE );
             LIST_ELEMENT( IMAGE_TEMPLATE );
+            LIST_ELEMENT( IMAGE_ANCHOR );
         }
     }
 
@@ -727,9 +734,11 @@ case ExtendedFilePickerElementIds::LISTBOX_##elem##_LABEL: 
\
             MAP_LIST( VERSION );
             MAP_LIST( TEMPLATE );
             MAP_LIST( IMAGE_TEMPLATE );
+            MAP_LIST( IMAGE_ANCHOR );
             MAP_LIST_LABEL( VERSION );
             MAP_LIST_LABEL( TEMPLATE );
             MAP_LIST_LABEL( IMAGE_TEMPLATE );
+            MAP_LIST_LABEL( IMAGE_ANCHOR );
         default:
             SAL_INFO("fpicker.aqua","Handle unknown control " << nControlId);
             break;
diff --git a/fpicker/source/aqua/SalAquaFilePicker.mm 
b/fpicker/source/aqua/SalAquaFilePicker.mm
index 78ec4f8cf640..fbb52c078477 100644
--- a/fpicker/source/aqua/SalAquaFilePicker.mm
+++ b/fpicker/source/aqua/SalAquaFilePicker.mm
@@ -471,6 +471,9 @@ throw( uno::Exception, uno::RuntimeException )
         case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
             m_nDialogType = NAVIGATIONSERVICES_OPEN;
             break;
+        case FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR:
+            m_nDialogType = NAVIGATIONSERVICES_OPEN;
+            break;
         case FILEOPEN_PLAY:
             m_nDialogType = NAVIGATIONSERVICES_OPEN;
             break;
diff --git a/fpicker/source/aqua/resourceprovider.mm 
b/fpicker/source/aqua/resourceprovider.mm
index e687809f768b..051077358d23 100644
--- a/fpicker/source/aqua/resourceprovider.mm
+++ b/fpicker/source/aqua/resourceprovider.mm
@@ -67,6 +67,7 @@ Entry CtrlIdToResIdTable[] = {
     { LISTBOX_VERSION_LABEL,                    STR_SVT_FILEPICKER_VERSION },
     { LISTBOX_TEMPLATE_LABEL,                   STR_SVT_FILEPICKER_TEMPLATES },
     { LISTBOX_IMAGE_TEMPLATE_LABEL,             
STR_SVT_FILEPICKER_IMAGE_TEMPLATE },
+    { LISTBOX_IMAGE_ANCHOR_LABEL,               
STR_SVT_FILEPICKER_IMAGE_ANCHOR },
     { CHECKBOX_SELECTION,                       STR_SVT_FILEPICKER_SELECTION },
     { FOLDERPICKER_TITLE,                       
STR_SVT_FOLDERPICKER_DEFAULT_TITLE },
     { FOLDER_PICKER_DEF_DESCRIPTION,            
STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION },
diff --git a/fpicker/source/office/OfficeControlAccess.cxx 
b/fpicker/source/office/OfficeControlAccess.cxx
index c373cc93dca9..4458dd487af9 100644
--- a/fpicker/source/office/OfficeControlAccess.cxx
+++ b/fpicker/source/office/OfficeControlAccess.cxx
@@ -88,6 +88,8 @@ namespace svt
             { "FilterListLabel",        LISTBOX_FILTER_LABEL,           
PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
             { "FilterOptionsBox",       CHECKBOX_FILTEROPTIONS,         
PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX     },
             { "HelpButton",             PUSHBUTTON_HELP,                
PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
+            { "ImageAnchorList",        LISTBOX_IMAGE_ANCHOR,           
PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX      },
+            { "ImageAnchorListLabel",   LISTBOX_IMAGE_ANCHOR_LABEL,     
PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
             { "ImageTemplateList",      LISTBOX_IMAGE_TEMPLATE,         
PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX      },
             { "ImageTemplateListLabel", LISTBOX_IMAGE_TEMPLATE_LABEL,   
PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
             { "LevelUpButton",          TOOLBOXBUTOON_LEVEL_UP,         
PROPERTY_FLAGS_COMMON                               },
@@ -377,6 +379,7 @@ namespace svt
                     case LISTBOX_VERSION:
                     case LISTBOX_TEMPLATE:
                     case LISTBOX_IMAGE_TEMPLATE:
+                    case LISTBOX_IMAGE_ANCHOR:
                         if ( ControlActions::SET_SELECT_ITEM == 
_nControlAction )
                         {
                             nPropertyId = PROPERTY_FLAG_SELECTEDITEMINDEX;
@@ -437,6 +440,7 @@ namespace svt
                     case LISTBOX_VERSION:
                     case LISTBOX_TEMPLATE:
                     case LISTBOX_IMAGE_TEMPLATE:
+                    case LISTBOX_IMAGE_ANCHOR:
                         switch ( _nControlAction )
                         {
                             case ControlActions::GET_SELECTED_ITEM:
diff --git a/fpicker/source/office/OfficeFilePicker.cxx 
b/fpicker/source/office/OfficeFilePicker.cxx
index 728dd4f5ca75..ef6d6e1caac2 100644
--- a/fpicker/source/office/OfficeFilePicker.cxx
+++ b/fpicker/source/office/OfficeFilePicker.cxx
@@ -277,6 +277,10 @@ PickerFlags SvtFilePicker::getPickerFlags()
     {
         nBits = PickerFlags::Open | PickerFlags::InsertAsLink | 
PickerFlags::ShowPreview;
     }
+    else if ( m_nServiceType == 
TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR )
+    {
+        nBits = PickerFlags::Open | PickerFlags::InsertAsLink | 
PickerFlags::ShowPreview | PickerFlags::ImageAnchor;
+    }
     if ( m_bMultiSelection && ( nBits & PickerFlags::Open ) )
         nBits |= PickerFlags::MultiSelection;
 
diff --git a/fpicker/source/office/OfficeFilePicker.src 
b/fpicker/source/office/OfficeFilePicker.src
index 4f6fe4b764b9..3c676dd5ce7a 100644
--- a/fpicker/source/office/OfficeFilePicker.src
+++ b/fpicker/source/office/OfficeFilePicker.src
@@ -64,6 +64,11 @@ String STR_SVT_FILEPICKER_TEMPLATES
     Text [ en-US ] = "S~tyles:" ;
 };
 
+String STR_SVT_FILEPICKER_IMAGE_ANCHOR
+{
+    Text [ en-US ] = "A~nchor:" ;
+};
+
 String STR_SVT_FILEPICKER_IMAGE_TEMPLATE
 {
     Text [ en-US ] = "Style:";
diff --git a/fpicker/source/office/fpdialogbase.hxx 
b/fpicker/source/office/fpdialogbase.hxx
index b27006cce13d..6fa20138a49c 100644
--- a/fpicker/source/office/fpdialogbase.hxx
+++ b/fpicker/source/office/fpdialogbase.hxx
@@ -52,9 +52,10 @@ enum class PickerFlags {
     Password          = 0x001000,
     ReadOnly          = 0x002000,
     MultiSelection    = 0x004000,
+    ImageAnchor       = 0x008000,
 };
 namespace o3tl {
-    template<> struct typed_flags<PickerFlags> : is_typed_flags<PickerFlags, 
0x007fff> {};
+    template<> struct typed_flags<PickerFlags> : is_typed_flags<PickerFlags, 
0x00ffff> {};
 }
 
 #define FILEDIALOG_FILTER_ALL   "*.*"
diff --git a/fpicker/source/office/iodlg.cxx b/fpicker/source/office/iodlg.cxx
index 6f816159a8a8..fde29f8fce74 100644
--- a/fpicker/source/office/iodlg.cxx
+++ b/fpicker/source/office/iodlg.cxx
@@ -561,6 +561,8 @@ void SvtFileDialog::Init_Impl
     get(_pImp->_pLbTemplates, "shared");
     get(_pImp->_pFtImageTemplates, "shared_label");
     get(_pImp->_pLbImageTemplates, "shared");
+    get(_pImp->_pFtImageAnchor, "shared_label");
+    get(_pImp->_pLbImageAnchor, "shared");
 
     _pImp->_pLbImageTemplates->setMaxWidthChars(40);
     _pImp->_pLbFilter->setMaxWidthChars(40);
@@ -2389,6 +2391,12 @@ Control* SvtFileDialog::getControl( sal_Int16 
_nControlId, bool _bLabelControl )
                     :   static_cast< Control* >( _pImp->_pLbImageTemplates );
             break;
 
+        case LISTBOX_IMAGE_ANCHOR:
+            pReturn =   _bLabelControl
+                    ?   static_cast< Control* >( _pImp->_pFtImageAnchor )
+                    :   static_cast< Control* >( _pImp->_pLbImageAnchor );
+            break;
+
         case LISTBOX_VERSION_LABEL:
             pReturn = _pImp->_pFtFileVersion;
             break;
@@ -2401,6 +2409,10 @@ Control* SvtFileDialog::getControl( sal_Int16 
_nControlId, bool _bLabelControl )
             pReturn = _pImp->_pFtImageTemplates;
             break;
 
+        case LISTBOX_IMAGE_ANCHOR_LABEL:
+            pReturn = _pImp->_pFtImageAnchor;
+            break;
+
         case PUSHBUTTON_OK:
             pReturn = _pImp->_pBtnFileOpen;
             break;
@@ -2540,6 +2552,14 @@ void SvtFileDialog::AddControls_Impl( )
         _pImp->_pLbImageTemplates->SetHelpId( HID_FILEOPEN_IMAGE_TEMPLATE );
         _pImp->_pLbImageTemplates->Show();
     }
+    else if ( _nPickerFlags & PickerFlags::ImageAnchor )
+    {
+        _pImp->_pFtImageAnchor->SetText( SvtResId( 
STR_SVT_FILEPICKER_IMAGE_ANCHOR ) );
+        _pImp->_pFtImageAnchor->Show();
+
+        _pImp->_pLbImageAnchor->SetHelpId( HID_FILEOPEN_IMAGE_ANCHOR );
+        _pImp->_pLbImageAnchor->Show();
+    }
 
     _pImp->_pPlaces = VclPtr<PlacesListBox>::Create(_pContainer, this, 
SVT_RESSTR(STR_PLACES_TITLE), WB_BORDER);
     _pImp->_pPlaces->SetHelpId("SVT_HID_FILESAVE_PLACES_LISTBOX");
diff --git a/fpicker/source/office/iodlgimp.cxx 
b/fpicker/source/office/iodlgimp.cxx
index 7aaa3d05bd2e..282d889b0dc6 100644
--- a/fpicker/source/office/iodlgimp.cxx
+++ b/fpicker/source/office/iodlgimp.cxx
@@ -215,6 +215,8 @@ SvtExpFileDlg_Impl::SvtExpFileDlg_Impl()   :
     _pLbTemplates       ( nullptr ),
     _pFtImageTemplates  ( nullptr ),
     _pLbImageTemplates  ( nullptr ),
+    _pFtImageAnchor     ( nullptr ),
+    _pLbImageAnchor     ( nullptr ),
     _pFtFileType        ( nullptr ),
     _pLbFilter          ( nullptr ),
     _pBtnFileOpen       ( nullptr ),
diff --git a/fpicker/source/office/iodlgimp.hxx 
b/fpicker/source/office/iodlgimp.hxx
index 1726a394a542..6f57050de215 100644
--- a/fpicker/source/office/iodlgimp.hxx
+++ b/fpicker/source/office/iodlgimp.hxx
@@ -137,6 +137,9 @@ public:
     VclPtr<FixedText>                      _pFtImageTemplates;
     VclPtr<ListBox>                        _pLbImageTemplates;
 
+    VclPtr<FixedText>                      _pFtImageAnchor;
+    VclPtr<ListBox>                        _pLbImageAnchor;
+
     VclPtr<FixedText>                      _pFtFileType;
     VclPtr<ListBox>                        _pLbFilter;
     VclPtr<PushButton>                     _pBtnFileOpen;
diff --git a/fpicker/source/win32/filepicker/VistaFilePicker.cxx 
b/fpicker/source/win32/filepicker/VistaFilePicker.cxx
index 238dad83d44d..d92686094cc4 100644
--- a/fpicker/source/win32/filepicker/VistaFilePicker.cxx
+++ b/fpicker/source/win32/filepicker/VistaFilePicker.cxx
@@ -510,6 +510,15 @@ void SAL_CALL VistaFilePicker::initialize(const 
css::uno::Sequence< css::uno::An
         }
         break;
 
+        case 
css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR :
+        {
+            bFileOpenDialog  = true;
+            nFeatures        |= FEATURE_LINK;
+            nFeatures        |= FEATURE_PREVIEW;
+            nFeatures        |= FEATURE_IMAGEANCHOR;
+        }
+        break;
+
         case css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY :
         {
             bFileOpenDialog  = sal_True;
diff --git a/fpicker/source/win32/filepicker/VistaFilePickerImpl.cxx 
b/fpicker/source/win32/filepicker/VistaFilePickerImpl.cxx
index abb186d62b9d..a668c8f11f67 100644
--- a/fpicker/source/win32/filepicker/VistaFilePickerImpl.cxx
+++ b/fpicker/source/win32/filepicker/VistaFilePickerImpl.cxx
@@ -95,6 +95,7 @@ static const GUID CLIENTID_FILESAVE_PASSWORD        = 
{0xC12D4F4C, 0x4D41, 0x4D4
 static const GUID CLIENTID_FILESAVE_SELECTION       = {0x5B2482B3, 0x0358, 
0x4E09, 0xAA, 0x64, 0x2B, 0x76, 0xB2, 0xA0, 0xDD, 0xFE};
 static const GUID CLIENTID_FILESAVE_TEMPLATE        = {0x9996D877, 0x20D5, 
0x424B, 0x9C, 0x2E, 0xD3, 0xB6, 0x31, 0xEC, 0xF7, 0xCE};
 static const GUID CLIENTID_FILEOPEN_LINK_TEMPLATE   = {0x32237796, 0x1509, 
0x49D1, 0xBB, 0x7E, 0x63, 0xAD, 0x36, 0xAE, 0x86, 0x8C};
+static const GUID CLIENTID_FILEOPEN_LINK_ANCHOR     = {0xBE3188CB, 0x399A, 
0x45AE, 0x8F, 0x78, 0x75, 0x17, 0xAF, 0x26, 0x81, 0xEA};
 static const GUID CLIENTID_FILEOPEN_PLAY            = {0x32CFB147, 0xF5AE, 
0x4F90, 0xA1, 0xF1, 0x81, 0x20, 0x72, 0xBB, 0x2F, 0xC5};
 static const GUID CLIENTID_FILEOPEN_LINK            = {0x39AC4BAE, 0x7D2D, 
0x46BC, 0xBE, 0x2E, 0xF8, 0x8C, 0xB5, 0x65, 0x5E, 0x6A};
 
@@ -508,6 +509,7 @@ static const ::sal_Int32 GROUP_VERSION         =   1;
 static const ::sal_Int32 GROUP_TEMPLATE        =   2;
 static const ::sal_Int32 GROUP_IMAGETEMPLATE   =   3;
 static const ::sal_Int32 GROUP_CHECKBOXES      =   4;
+static const ::sal_Int32 GROUP_IMAGEANCHOR     =   5;
 
 
 static void setLabelToControl(CResourceProvider& rResourceProvider, 
TFileDialogCustomize iCustom, sal_uInt16 nControlId)
@@ -550,6 +552,10 @@ void 
VistaFilePickerImpl::impl_sta_enableFeatures(::sal_Int32 nFeatures, ::sal_I
             aGUID = CLIENTID_FILEOPEN_LINK_TEMPLATE;
             break;
 
+        case 
css::ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR :
+            aGUID = CLIENTID_FILEOPEN_LINK_ANCHOR;
+            break;
+
         case css::ui::dialogs::TemplateDescription::FILEOPEN_PLAY :
             aGUID = CLIENTID_FILEOPEN_PLAY;
             break;
@@ -587,6 +593,14 @@ void 
VistaFilePickerImpl::impl_sta_enableFeatures(::sal_Int32 nFeatures, ::sal_I
         iCustom->MakeProminent    (GROUP_IMAGETEMPLATE);
     }
 
+    if ((nFeatures & FEATURE_IMAGEANCHOR) == FEATURE_IMAGEANCHOR)
+    {
+        iCustom->StartVisualGroup (GROUP_IMAGEANCHOR, 
o3tl::toW(FpsResId(STR_SVT_FILEPICKER_IMAGE_ANCHOR).replaceFirst("~","").getStr()));
+        iCustom->AddComboBox      
(css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_ANCHOR);
+        iCustom->EndVisualGroup   ();
+        iCustom->MakeProminent    (GROUP_IMAGEANCHOR);
+    }
+
     iCustom->StartVisualGroup (GROUP_CHECKBOXES, L"");
 
     sal_uInt16 nControlId(0);
@@ -1083,6 +1097,7 @@ void VistaFilePickerImpl::impl_sta_SetControlValue(const 
RequestRef& rRequest)
         case css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_VERSION :
         case css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_TEMPLATE :
         case 
css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE :
+        case 
css::ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_ANCHOR :
             {
                 HRESULT hResult;
                 switch (nAction)
diff --git a/fpicker/source/win32/filepicker/VistaFilePickerImpl.hxx 
b/fpicker/source/win32/filepicker/VistaFilePickerImpl.hxx
index c457e290064d..436aca0651c1 100644
--- a/fpicker/source/win32/filepicker/VistaFilePickerImpl.hxx
+++ b/fpicker/source/win32/filepicker/VistaFilePickerImpl.hxx
@@ -70,6 +70,7 @@ static const ::sal_Int32 FEATURE_IMAGETEMPLATE  =  128;
 static const ::sal_Int32 FEATURE_PLAY           =  256;
 static const ::sal_Int32 FEATURE_READONLY       =  512;
 static const ::sal_Int32 FEATURE_VERSION        = 1024;
+static const ::sal_Int32 FEATURE_IMAGEANCHOR    = 2048;
 
 static const OUString PROP_PICKER_LISTENER("picker_listener"   ); // 
[XFilePickerListenert]
 static const OUString PROP_DIALOG_SHOW_RESULT("dialog_show_result" ); // 
[sal_Bool] true=OK, false=CANCEL
diff --git a/fpicker/source/win32/misc/resourceprovider.cxx 
b/fpicker/source/win32/misc/resourceprovider.cxx
index 55abde0239e6..5b3f6bf3388f 100644
--- a/fpicker/source/win32/misc/resourceprovider.cxx
+++ b/fpicker/source/win32/misc/resourceprovider.cxx
@@ -61,6 +61,7 @@ _Entry CtrlIdToResIdTable[] = {
     { LISTBOX_VERSION_LABEL,                    STR_SVT_FILEPICKER_VERSION },
     { LISTBOX_TEMPLATE_LABEL,                   STR_SVT_FILEPICKER_TEMPLATES },
     { LISTBOX_IMAGE_TEMPLATE_LABEL,             
STR_SVT_FILEPICKER_IMAGE_TEMPLATE },
+    { LISTBOX_IMAGE_ANCHOR_LABEL,               
STR_SVT_FILEPICKER_IMAGE_ANCHOR },
     { CHECKBOX_SELECTION,                       STR_SVT_FILEPICKER_SELECTION },
     { FOLDERPICKER_TITLE,                       
STR_SVT_FOLDERPICKER_DEFAULT_TITLE },
     { FOLDER_PICKER_DEF_DESCRIPTION,            
STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION }
diff --git a/include/sfx2/opengrf.hxx b/include/sfx2/opengrf.hxx
index bde7adbdfd19..1cee648be920 100644
--- a/include/sfx2/opengrf.hxx
+++ b/include/sfx2/opengrf.hxx
@@ -23,12 +23,16 @@
 #include <vcl/graphicfilter.hxx>
 #include <sfx2/dllapi.h>
 
+#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
+#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
+
 struct  SvxOpenGrf_Impl;
 
 class SFX2_DLLPUBLIC SvxOpenGraphicDialog
 {
 public:
     SvxOpenGraphicDialog    ( const OUString& rTitle );
+    SvxOpenGraphicDialog(const OUString& rTitle, sal_Int16 nDialogType);
     ~SvxOpenGraphicDialog   ();
 
     short                   Execute();
@@ -45,6 +49,8 @@ public:
 
     OUString                GetCurrentFilter() const;
     void                    SetCurrentFilter(const OUString&);
+
+    css::uno::Reference<css::ui::dialogs::XFilePickerControlAccess> 
GetFilePickerControlAccess();
 private:
     SvxOpenGraphicDialog    (const SvxOpenGraphicDialog&) = delete;
     SvxOpenGraphicDialog& operator = ( const SvxOpenGraphicDialog & ) = delete;
diff --git a/include/svtools/helpid.hrc b/include/svtools/helpid.hrc
index ecc3fbf45d3c..558e333d46bc 100644
--- a/include/svtools/helpid.hrc
+++ b/include/svtools/helpid.hrc
@@ -48,6 +48,7 @@
 #define HID_FILEOPEN_READONLY                                  
"SVT_HID_FILEOPEN_READONLY"
 #define HID_FILEOPEN_VERSION                                   
"SVT_HID_FILEOPEN_VERSION"
 #define HID_FILEOPEN_IMAGE_TEMPLATE                            
"SVT_HID_FILEOPEN_IMAGE_TEMPLATE"
+#define HID_FILEOPEN_IMAGE_ANCHOR                              
"SVT_HID_FILEOPEN_IMAGE_ANCHOR"
 
 #define HID_WIZARD_NEXT                                        
"SVT_HID_WIZARD_NEXT"
 #define HID_WIZARD_PREVIOUS                                    
"SVT_HID_WIZARD_PREVIOUS"
diff --git a/include/vcl/fpicker.hrc b/include/vcl/fpicker.hrc
index 29c446ddbd36..1b8d3a305218 100644
--- a/include/vcl/fpicker.hrc
+++ b/include/vcl/fpicker.hrc
@@ -29,6 +29,7 @@
 #define STR_SVT_ALREADYEXISTOVERWRITE               
(STR_SVT_FILEPICKER_START+14)
 #define STR_SVT_DELETESERVICE                       
(STR_SVT_FILEPICKER_START+15)
 #define STR_SVT_ROOTLABEL                           
(STR_SVT_FILEPICKER_START+16)
+#define STR_SVT_FILEPICKER_IMAGE_ANCHOR             
(STR_SVT_FILEPICKER_START+17)
 
 #endif
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/offapi/com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.idl 
b/offapi/com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.idl
index b641af2e32b6..a5bdc38b4039 100644
--- a/offapi/com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.idl
+++ b/offapi/com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.idl
@@ -94,6 +94,9 @@ published constants ExtendedFilePickerElementIds
     /**
     */
     const short LISTBOX_FILTER_SELECTOR = 210;
+
+    const short LISTBOX_IMAGE_ANCHOR   = 212;
+    const short LISTBOX_IMAGE_ANCHOR_LABEL = 213;
 };
 
 
diff --git a/offapi/com/sun/star/ui/dialogs/TemplateDescription.idl 
b/offapi/com/sun/star/ui/dialogs/TemplateDescription.idl
index 76aaec12abc2..735bfc0a58b1 100644
--- a/offapi/com/sun/star/ui/dialogs/TemplateDescription.idl
+++ b/offapi/com/sun/star/ui/dialogs/TemplateDescription.idl
@@ -114,6 +114,17 @@ published constants TemplateDescription
     */
     const short FILESAVE_AUTOEXTENSION                         = 10;
 
+    /** A FileOpen dialog with additional controls.
+        <ul>
+            <li>A checkbox "Insert as link"
+            <li>A checkbox "Show Preview"
+            <li>A listbox  "Image Anchor" for choosing how to anchor the image 
in Calc.</li>
+            <li>A window for displaying a file preview</li>
+        </ul>
+
+        @since LibreOffice 6.1
+    */
+    const short FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR             = 13;
 };
 
 
diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index 126ebb12e456..0b5277ed46fd 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -904,6 +904,9 @@
 #define SCSTR_UNDO_PAGE_ANCHOR   (STR_START + 221)
 #define SCSTR_UNDO_CELL_ANCHOR   (STR_START + 222)
 
+#define STR_ANCHOR_TO_CELL       (STR_START + 223)
+#define STR_ANCHOR_TO_PAGE       (STR_START + 224)
+
 // navigator - in the same order as SC_CONTENT_...
 #define SCSTR_CONTENT_ROOT      (STR_START + 250)
 #define SCSTR_CONTENT_TABLE     (STR_START + 251)
diff --git a/sc/source/ui/drawfunc/fuins1.cxx b/sc/source/ui/drawfunc/fuins1.cxx
index 4d09c96af759..d10230addbf3 100644
--- a/sc/source/ui/drawfunc/fuins1.cxx
+++ b/sc/source/ui/drawfunc/fuins1.cxx
@@ -41,7 +41,13 @@
 #include "sc.hrc"
 #include "globstr.hrc"
 
-using namespace ::com::sun::star;
+#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
+#include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
+#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
+
+using namespace css;
+using namespace css::uno;
 
 void ScLimitSizeOnDrawPage( Size& rSize, Point& rPos, const Size& rPage )
 {
@@ -90,7 +96,7 @@ void ScLimitSizeOnDrawPage( Size& rSize, Point& rPos, const 
Size& rPage )
 
 static void lcl_InsertGraphic( const Graphic& rGraphic,
                         const OUString& rFileName, const OUString& 
rFilterName, bool bAsLink, bool bApi,
-                        ScTabViewShell* pViewSh, vcl::Window* pWindow, 
SdrView* pView )
+                        ScTabViewShell* pViewSh, vcl::Window* pWindow, 
SdrView* pView, bool bAnchorToCell=true )
 {
     ScDrawView* pDrawView = pViewSh->GetScDrawView();
 
@@ -162,8 +168,8 @@ static void lcl_InsertGraphic( const Graphic& rGraphic,
     OUString aName = pLayer->GetNewGraphicName();                 // "Graphics"
     pObj->SetName(aName);
 
-    // Anchor images to cell by default, tdf#86739
-    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *(rData.GetDocument()), 
rData.GetTabNo());
+    if (bAnchorToCell)
+        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, 
*(rData.GetDocument()), rData.GetTabNo());
 
     //  don't select if from (dispatch) API, to allow subsequent cell 
operations
     SdrInsertFlags nInsOptions = bApi ? SdrInsertFlags::DONTMARK : 
SdrInsertFlags::NONE;
@@ -258,7 +264,30 @@ FuInsertGraphic::FuInsertGraphic( ScTabViewShell*   
pViewSh,
     }
     else
     {
-        SvxOpenGraphicDialog aDlg(ScResId(STR_INSERTGRAPHIC));
+        SvxOpenGraphicDialog aDlg(ScResId(STR_INSERTGRAPHIC), 
ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR);
+
+
+        Reference<ui::dialogs::XFilePickerControlAccess> xCtrlAcc = 
aDlg.GetFilePickerControlAccess();
+        sal_Int16 nSelect = 0;
+        Sequence<OUString> aListBoxEntries {
+            ScResId(STR_ANCHOR_TO_CELL),
+            ScResId(STR_ANCHOR_TO_PAGE)
+        };
+        try
+        {
+            Any aTemplates(&aListBoxEntries, 
cppu::UnoType<decltype(aListBoxEntries)>::get());
+
+            
xCtrlAcc->setValue(ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_ANCHOR,
+                ui::dialogs::ListboxControlActions::ADD_ITEMS, aTemplates);
+
+            Any aSelectPos(&nSelect, cppu::UnoType<decltype(nSelect)>::get());
+            
xCtrlAcc->setValue(ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_ANCHOR,
+                ui::dialogs::ListboxControlActions::SET_SELECT_ITEM, 
aSelectPos);
+        }
+        catch (const Exception&)
+        {
+            SAL_WARN("sc", "control access failed");
+        }
 
         if( aDlg.Execute() == GRFILTER_OK )
         {
@@ -278,7 +307,15 @@ FuInsertGraphic::FuInsertGraphic( ScTabViewShell*   
pViewSh,
                         bAsLink = false; // don't store as link
                 }
 
-                lcl_InsertGraphic( aGraphic, aFileName, aFilterName, bAsLink, 
false, pViewSh, pWindow, pView );
+                // Anchor to cell or to page?
+                Any aAnchorValue = xCtrlAcc->getValue(
+                    
ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_ANCHOR,
+                    ui::dialogs::ListboxControlActions::GET_SELECTED_ITEM );
+                OUString sAnchor;
+                aAnchorValue >>= sAnchor;
+                bool bAnchorToCell = sAnchor == ScResId(STR_ANCHOR_TO_CELL);
+
+                lcl_InsertGraphic( aGraphic, aFileName, aFilterName, bAsLink, 
false, pViewSh, pWindow, pView, bAnchorToCell );
 
                 //  append items for recording
                 rReq.AppendItem( SfxStringItem( SID_INSERT_GRAPHIC, aFileName 
) );
diff --git a/sc/source/ui/src/scstring.src b/sc/source/ui/src/scstring.src
index 82e5e62b222d..d47e14d9081a 100644
--- a/sc/source/ui/src/scstring.src
+++ b/sc/source/ui/src/scstring.src
@@ -916,4 +916,14 @@ String SCSTR_UNDO_CELL_ANCHOR
     Text [ en-US ] = "Cell Anchor" ;
 };
 
+String STR_ANCHOR_TO_CELL
+{
+    Text [ en-US ] = "To cell" ;
+};
+
+String STR_ANCHOR_TO_PAGE
+{
+    Text [ en-US ] = "To page" ;
+};
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/appl/opengrf.cxx b/sfx2/source/appl/opengrf.cxx
index a41e6131618f..237fa7cb7fb9 100644
--- a/sfx2/source/appl/opengrf.cxx
+++ b/sfx2/source/appl/opengrf.cxx
@@ -74,16 +74,15 @@ sal_uInt16  SvxOpenGrfErr2ResId(    short   err     )
 
 struct SvxOpenGrf_Impl
 {
-    SvxOpenGrf_Impl         ();
+    SvxOpenGrf_Impl(sal_Int16 nDialogType);
 
     sfx2::FileDialogHelper                  aFileDlg;
     uno::Reference < XFilePickerControlAccess > xCtrlAcc;
 };
 
 
-SvxOpenGrf_Impl::SvxOpenGrf_Impl()
-    : aFileDlg(ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW,
-            FileDialogFlags::Graphic)
+SvxOpenGrf_Impl::SvxOpenGrf_Impl(sal_Int16 nDialogType)
+    : aFileDlg(nDialogType, FileDialogFlags::Graphic)
 {
     uno::Reference < XFilePicker2 > xFP = aFileDlg.GetFilePicker();
     xCtrlAcc.set(xFP, UNO_QUERY);
@@ -91,7 +90,13 @@ SvxOpenGrf_Impl::SvxOpenGrf_Impl()
 
 
 SvxOpenGraphicDialog::SvxOpenGraphicDialog( const OUString& rTitle ) :
-    mpImpl( new SvxOpenGrf_Impl )
+    mpImpl( new 
SvxOpenGrf_Impl(ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW) )
+{
+    mpImpl->aFileDlg.SetTitle(rTitle);
+}
+
+SvxOpenGraphicDialog::SvxOpenGraphicDialog(const OUString& rTitle, sal_Int16 
nDialogType)
+    : mpImpl(new SvxOpenGrf_Impl(nDialogType))
 {
     mpImpl->aFileDlg.SetTitle(rTitle);
 }
@@ -269,4 +274,10 @@ void SvxOpenGraphicDialog::SetCurrentFilter(const 
OUString& rStr)
     mpImpl->aFileDlg.SetCurrentFilter(rStr);
 }
 
+
+Reference<ui::dialogs::XFilePickerControlAccess> 
SvxOpenGraphicDialog::GetFilePickerControlAccess()
+{
+    return mpImpl->xCtrlAcc;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/dialog/filedlghelper.cxx 
b/sfx2/source/dialog/filedlghelper.cxx
index cfe68f4f936d..b52d7d5a5058 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -260,6 +260,11 @@ OUString FileDialogHelper_Impl::handleHelpRequested( const 
FilePickerEvent& aEve
             sHelpId = HID_FILEOPEN_IMAGE_TEMPLATE;
             break;
 
+        case ExtendedFilePickerElementIds::LISTBOX_IMAGE_ANCHOR_LABEL :
+        case ExtendedFilePickerElementIds::LISTBOX_IMAGE_ANCHOR :
+            sHelpId = HID_FILEOPEN_IMAGE_ANCHOR;
+            break;
+
         case ExtendedFilePickerElementIds::CHECKBOX_SELECTION :
             sHelpId = HID_FILESAVE_SELECTION;
             break;
@@ -825,6 +830,7 @@ static open_or_save_t lcl_OpenOrSave(sal_Int16 const 
nDialogType)
     {
         case FILEOPEN_SIMPLE:
         case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
+        case FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR:
         case FILEOPEN_PLAY:
         case FILEOPEN_READONLY_VERSION:
         case FILEOPEN_LINK_PREVIEW:
@@ -986,10 +992,11 @@ FileDialogHelper_Impl::FileDialogHelper_Impl(
             case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
                 nTemplateDescription = 
TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE;
                 mbHasPreview = true;
+                break;
 
-                // aPreviewTimer
-                maPreviewIdle.SetPriority( TaskPriority::LOWEST );
-                maPreviewIdle.SetInvokeHandler( LINK( this, 
FileDialogHelper_Impl, TimeOutHdl_Impl ) );
+            case FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR:
+                nTemplateDescription = 
TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR;
+                mbHasPreview = true;
                 break;
 
             case FILEOPEN_PLAY:
@@ -1004,9 +1011,6 @@ FileDialogHelper_Impl::FileDialogHelper_Impl(
             case FILEOPEN_LINK_PREVIEW:
                 nTemplateDescription = 
TemplateDescription::FILEOPEN_LINK_PREVIEW;
                 mbHasPreview = true;
-                // aPreviewTimer
-                maPreviewIdle.SetPriority( TaskPriority::LOWEST );
-                maPreviewIdle.SetInvokeHandler( LINK( this, 
FileDialogHelper_Impl, TimeOutHdl_Impl ) );
                 break;
 
             case FILESAVE_AUTOEXTENSION:
@@ -1020,6 +1024,12 @@ FileDialogHelper_Impl::FileDialogHelper_Impl(
                 break;
         }
 
+        if (mbHasPreview)
+        {
+            maPreviewIdle.SetPriority( TaskPriority::LOWEST );
+            maPreviewIdle.SetInvokeHandler( LINK( this, FileDialogHelper_Impl, 
TimeOutHdl_Impl ) );
+        }
+
         Sequence < Any > aInitArguments( !mpPreferredParentWindow ? 3 : 4 );
 
         // This is a hack. We currently know that the internal file picker 
implementation
diff --git a/vcl/inc/svids.hrc b/vcl/inc/svids.hrc
index dcbd8dd6ce61..ce3d3a79f76f 100644
--- a/vcl/inc/svids.hrc
+++ b/vcl/inc/svids.hrc
@@ -152,6 +152,7 @@
 #define STR_FPICKER_OPEN                            10316
 #define STR_FPICKER_SAVE                            10317
 #define STR_FPICKER_TYPE                            10318
+#define STR_FPICKER_IMAGE_ANCHOR                    10319
 
 #define SV_ACCESSERROR_NO_FONTS                     10510
 
diff --git a/vcl/source/src/fpicker.src b/vcl/source/src/fpicker.src
index 73e404c9e6c0..5fcf178ff3fd 100644
--- a/vcl/source/src/fpicker.src
+++ b/vcl/source/src/fpicker.src
@@ -69,6 +69,11 @@ String STR_FPICKER_IMAGE_TEMPLATE
     Text [ en-US ] = "Frame Style: ";
 };
 
+String STR_FPICKER_IMAGE_ANCHOR
+{
+    Text [ en-US ] = "A~nchor: ";
+};
+
 String STR_FPICKER_SELECTION
 {
     Text [ en-US ] = "~Selection" ;
diff --git a/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx 
b/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx
index 5156a7a9b642..5733f192082e 100644
--- a/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx
+++ b/vcl/unx/gtk/fpicker/SalGtkFilePicker.cxx
@@ -199,6 +199,7 @@ SalGtkFilePicker::SalGtkFilePicker( const uno::Reference< 
uno::XComponentContext
             LABEL_LIST( VERSION );
             LABEL_LIST( TEMPLATE );
             LABEL_LIST( IMAGE_TEMPLATE );
+            LABEL_LIST( IMAGE_ANCHOR );
             default:
                 OSL_TRACE("Handle unknown control %d", i);
                 break;
@@ -1103,9 +1104,11 @@ GtkWidget *SalGtkFilePicker::getWidget( sal_Int16 
nControlId, GType *pType )
         MAP_LIST( VERSION );
         MAP_LIST( TEMPLATE );
         MAP_LIST( IMAGE_TEMPLATE );
+        MAP_LIST( IMAGE_ANCHOR );
         MAP_LIST_LABEL( VERSION );
         MAP_LIST_LABEL( TEMPLATE );
         MAP_LIST_LABEL( IMAGE_TEMPLATE );
+        MAP_LIST_LABEL( IMAGE_ANCHOR );
     default:
         OSL_TRACE("Handle unknown control %d", nControlId);
         break;
@@ -1663,6 +1666,14 @@ void SAL_CALL SalGtkFilePicker::initialize( const 
uno::Sequence<uno::Any>& aArgu
             mbListVisibility[IMAGE_TEMPLATE] = true;
             // TODO
                 break;
+        case FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR:
+            eAction = GTK_FILE_CHOOSER_ACTION_OPEN;
+            first_button_text = GTK_STOCK_OPEN;
+            mbToggleVisibility[LINK] = true;
+            mbToggleVisibility[PREVIEW] = true;
+            mbListVisibility[IMAGE_ANCHOR] = true;
+            // TODO
+                break;
         case FILEOPEN_PLAY:
             eAction = GTK_FILE_CHOOSER_ACTION_OPEN;
             first_button_text = GTK_STOCK_OPEN;
diff --git a/vcl/unx/gtk/fpicker/SalGtkFilePicker.hxx 
b/vcl/unx/gtk/fpicker/SalGtkFilePicker.hxx
index 49190eafedb7..a61344b140d3 100644
--- a/vcl/unx/gtk/fpicker/SalGtkFilePicker.hxx
+++ b/vcl/unx/gtk/fpicker/SalGtkFilePicker.hxx
@@ -212,6 +212,7 @@ class SalGtkFilePicker : public SalGtkPicker, public 
SalGtkFilePicker_Base
             VERSION,
             TEMPLATE,
             IMAGE_TEMPLATE,
+            IMAGE_ANCHOR,
             LIST_LAST
               };
 
diff --git a/vcl/unx/gtk/fpicker/resourceprovider.cxx 
b/vcl/unx/gtk/fpicker/resourceprovider.cxx
index c6b09452df91..f6a5be79c3b8 100644
--- a/vcl/unx/gtk/fpicker/resourceprovider.cxx
+++ b/vcl/unx/gtk/fpicker/resourceprovider.cxx
@@ -47,6 +47,7 @@ static const struct
     { LISTBOX_VERSION_LABEL,                    STR_FPICKER_VERSION },
     { LISTBOX_TEMPLATE_LABEL,                   STR_FPICKER_TEMPLATES },
     { LISTBOX_IMAGE_TEMPLATE_LABEL,             STR_FPICKER_IMAGE_TEMPLATE },
+    { LISTBOX_IMAGE_ANCHOR_LABEL,               STR_FPICKER_IMAGE_ANCHOR },
     { CHECKBOX_SELECTION,                       STR_FPICKER_SELECTION },
     { FOLDERPICKER_TITLE,                       
STR_FPICKER_FOLDER_DEFAULT_TITLE },
     { FOLDER_PICKER_DEF_DESCRIPTION,            
STR_FPICKER_FOLDER_DEFAULT_DESCRIPTION },
diff --git a/vcl/unx/gtk3_kde5/gtk3_kde5_filepicker.cxx 
b/vcl/unx/gtk3_kde5/gtk3_kde5_filepicker.cxx
index c23a35716779..66dab2918aae 100644
--- a/vcl/unx/gtk3_kde5/gtk3_kde5_filepicker.cxx
+++ b/vcl/unx/gtk3_kde5/gtk3_kde5_filepicker.cxx
@@ -253,9 +253,13 @@ void Gtk3KDE5FilePicker::addCustomControl(sal_Int16 
controlId)
         case LISTBOX_IMAGE_TEMPLATE:
             resId = STR_FPICKER_IMAGE_TEMPLATE;
             break;
+        case LISTBOX_IMAGE_ANCHOR:
+            resId = STR_FPICKER_IMAGE_ANCHOR;
+            break;
         case LISTBOX_VERSION_LABEL:
         case LISTBOX_TEMPLATE_LABEL:
         case LISTBOX_IMAGE_TEMPLATE_LABEL:
+        case LISTBOX_IMAGE_ANCHOR_LABEL:
         case LISTBOX_FILTER_SELECTOR:
             break;
     }
@@ -282,9 +286,11 @@ void Gtk3KDE5FilePicker::addCustomControl(sal_Int16 
controlId)
         case LISTBOX_VERSION:
         case LISTBOX_TEMPLATE:
         case LISTBOX_IMAGE_TEMPLATE:
+        case LISTBOX_IMAGE_ANCHOR:
         case LISTBOX_VERSION_LABEL:
         case LISTBOX_TEMPLATE_LABEL:
         case LISTBOX_IMAGE_TEMPLATE_LABEL:
+        case LISTBOX_IMAGE_ANCHOR_LABEL:
         case LISTBOX_FILTER_SELECTOR:
             break;
     }
@@ -358,6 +364,12 @@ void SAL_CALL Gtk3KDE5FilePicker::initialize(const 
uno::Sequence<uno::Any>& args
             addCustomControl(LISTBOX_IMAGE_TEMPLATE);
             break;
 
+        case FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR:
+            addCustomControl(CHECKBOX_LINK);
+            addCustomControl(CHECKBOX_PREVIEW);
+            addCustomControl(LISTBOX_IMAGE_ANCHOR);
+            break;
+
         case FILEOPEN_PLAY:
             addCustomControl(PUSHBUTTON_PLAY);
             break;
diff --git a/vcl/unx/kde4/KDE4FilePicker.cxx b/vcl/unx/kde4/KDE4FilePicker.cxx
index 229aa020bb98..5456344d3f5e 100644
--- a/vcl/unx/kde4/KDE4FilePicker.cxx
+++ b/vcl/unx/kde4/KDE4FilePicker.cxx
@@ -585,9 +585,13 @@ void KDE4FilePicker::addCustomControl(sal_Int16 controlId)
         case LISTBOX_IMAGE_TEMPLATE:
             resId = STR_FPICKER_IMAGE_TEMPLATE;
             break;
+        case LISTBOX_IMAGE_ANCHOR:
+            resId = STR_FPICKER_IMAGE_ANCHOR;
+            break;
         case LISTBOX_VERSION_LABEL:
         case LISTBOX_TEMPLATE_LABEL:
         case LISTBOX_IMAGE_TEMPLATE_LABEL:
+        case LISTBOX_IMAGE_ANCHOR_LABEL:
         case LISTBOX_FILTER_SELECTOR:
             break;
     }
@@ -615,9 +619,11 @@ void KDE4FilePicker::addCustomControl(sal_Int16 controlId)
         case LISTBOX_VERSION:
         case LISTBOX_TEMPLATE:
         case LISTBOX_IMAGE_TEMPLATE:
+        case LISTBOX_IMAGE_ANCHOR:
         case LISTBOX_VERSION_LABEL:
         case LISTBOX_TEMPLATE_LABEL:
         case LISTBOX_IMAGE_TEMPLATE_LABEL:
+        case LISTBOX_IMAGE_ANCHOR_LABEL:
         case LISTBOX_FILTER_SELECTOR:
             break;
     }
@@ -711,6 +717,12 @@ void SAL_CALL KDE4FilePicker::initialize( const 
uno::Sequence<uno::Any> &args )
             addCustomControl( LISTBOX_IMAGE_TEMPLATE );
             break;
 
+        case FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR:
+            addCustomControl( CHECKBOX_LINK );
+            addCustomControl( CHECKBOX_PREVIEW );
+            addCustomControl( LISTBOX_IMAGE_ANCHOR );
+            break;
+
         case FILEOPEN_PLAY:
             addCustomControl( PUSHBUTTON_PLAY );
             break;
commit 559b60c7f2c236667bdc3f9dae67e25cb2a4bcc5
Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
Date:   Thu Dec 14 21:14:09 2017 +0100

    tdf#86739 Anchor inserted images to cell by default
    
    As Calc is all about cells, many users expect images
    to be also anchored to cells, not the page.
    
    This is in preparation for tdf#98931 where we also want
    to keep images attached to their cell when users sort
    the cells.
    
    Change-Id: I5ba19f2524504ec018990c60098900d99e0db1c9
    Reviewed-on: https://gerrit.libreoffice.org/46488
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de>
    (cherry picked from commit 3e9bea4dcb6b780a3ef720858bb5dca92b065a39)

diff --git a/sc/source/ui/drawfunc/fuins1.cxx b/sc/source/ui/drawfunc/fuins1.cxx
index c7fd4c96c8ae..4d09c96af759 100644
--- a/sc/source/ui/drawfunc/fuins1.cxx
+++ b/sc/source/ui/drawfunc/fuins1.cxx
@@ -162,6 +162,9 @@ static void lcl_InsertGraphic( const Graphic& rGraphic,
     OUString aName = pLayer->GetNewGraphicName();                 // "Graphics"
     pObj->SetName(aName);
 
+    // Anchor images to cell by default, tdf#86739

... etc. - the rest is truncated
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to