first step for Insert->Chart From File

This needs some tweaks but it looks like we are already able to choose
the chart and import it. There are some more tweaks needed to handle
internal vs. external data provider, errors, other components, ...

Change-Id: Ib3e7f8bbf7b7f49b071d85120930624e2add91a7
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index bad0084..b03d7d4 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -380,6 +380,11 @@
                    <value xml:lang="en-US">Ch~art...</value>
                </prop>
            </node>
            <node oor:name=".uno:InsertObjectChartFromFile" oor:op="replace">
                <prop oor:name="Label" oor:type="xs:string">
                    <value xml:lang="en-US">Load Chart From File</value>
                </prop>
            </node>
            <node oor:name=".uno:StarChartDialog" oor:op="replace">
                <prop oor:name="Label" oor:type="xs:string">
                    <value xml:lang="en-US">Ch~art...</value>
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index be30696..74b99f1 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -2131,6 +2131,11 @@
                    <value>1</value>
                </prop>
            </node>
            <node oor:name=".uno:InsertObjectChartFromFile" oor:op="replace">
                <prop oor:name="Label" oor:type="xs:string">
                    <value xml:lang="en-US">Chart from File</value>
                </prop>
            </node>
            <node oor:name=".uno:DefaultBullet" oor:op="replace">
                <prop oor:name="Label" oor:type="xs:string">
                    <value xml:lang="en-US">Bullets On/Off</value>
diff --git a/sc/sdi/tabvwsh.sdi b/sc/sdi/tabvwsh.sdi
index 05459a0..7bbdfca 100644
--- a/sc/sdi/tabvwsh.sdi
+++ b/sc/sdi/tabvwsh.sdi
@@ -113,6 +113,7 @@ interface BaseSelection
    SID_FM_CREATE_CONTROL   [ ExecMethod = ExecDraw ; ]
    SID_LINKS               [ ExecMethod = ExecDrawIns; StateMethod = GetDrawInsState; ]
    SID_DRAW_CHART          [ ExecMethod = ExecDraw; StateMethod = GetDrawState; ]
    SID_INSERT_DIAGRAM_FROM_FILE [ ExecMethod = ExecDrawIns; StateMethod = GetDrawState; ]
    SID_FM_CREATE_FIELDCONTROL [ ExecMethod = ExecDrawIns ; ]

    // } Einfuegen von Objekten
diff --git a/sc/source/ui/drawfunc/fuins2.cxx b/sc/source/ui/drawfunc/fuins2.cxx
index 30cdc7d..f5a8aeb 100644
--- a/sc/source/ui/drawfunc/fuins2.cxx
+++ b/sc/source/ui/drawfunc/fuins2.cxx
@@ -61,6 +61,9 @@
#include <com/sun/star/chart/ChartDataRowSource.hpp>
#include <cppuhelper/bootstrap.hxx>

#include <com/sun/star/embed/XEmbeddedObjectCreator.hpp>
#include <com/sun/star/embed/EmbeddedObjectCreator.hpp>

using namespace ::com::sun::star;
// BM/IHA --

@@ -776,5 +779,57 @@ void FuInsertChart::Deactivate()
    FuPoor::Deactivate();
}

FuInsertChartFromFile::FuInsertChartFromFile( ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
           SdrModel* pDoc, SfxRequest& rReq, const OUString& rURL):
    FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
{
    uno::Reference< io::XInputStream > xStorage = comphelper::OStorageHelper::GetInputStreamFromURL(
            rURL, comphelper::getProcessComponentContext());

    comphelper::EmbeddedObjectContainer& rObjContainer =
        pViewShell->GetObjectShell()->GetEmbeddedObjectContainer();

    OUString aName;
    uno::Reference< embed::XEmbeddedObject > xObj = rObjContainer.InsertEmbeddedObject( xStorage, aName );

    uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver;
    uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
    if( xCompSupp.is())
        xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );

    const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
    awt::Size aSz = xObj->getVisualAreaSize( nAspect );
    Size aSize( aSz.Width, aSz.Height );

    MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
    ScRange aPositionRange = pViewSh->GetViewData()->GetCurPos();
    Point aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange );
    Rectangle aRect (aStart, aSize);
    SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect);

    pSkipPaintObj = pObj;

    SdrPageView* pPV = pView->GetSdrPageView();

    // use the page instead of the view to insert, so no undo action is created yet
    SdrPage* pInsPage = pPV->GetPage();
    pInsPage->InsertObject( pObj );
    pView->UnmarkAllObj();
    pView->MarkObj( pObj, pPV );

    pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW );

}

void FuInsertChartFromFile::Activate()
{
    FuPoor::Activate();
}

void FuInsertChartFromFile::Deactivate()
{
    FuPoor::Deactivate();
}


/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/fuinsert.hxx b/sc/source/ui/inc/fuinsert.hxx
index a4eb584..26e2a89 100644
--- a/sc/source/ui/inc/fuinsert.hxx
+++ b/sc/source/ui/inc/fuinsert.hxx
@@ -58,7 +58,7 @@ class FuInsertChartFromFile : public FuPoor
{
 public:
    FuInsertChartFromFile( ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pView,
           SdrModel* pDoc, SfxRequest& rReq);
           SdrModel* pDoc, SfxRequest& rReq, const OUString& rURL);

    virtual void Activate();
    virtual void Deactivate();
diff --git a/sc/source/ui/view/tabvwshb.cxx b/sc/source/ui/view/tabvwshb.cxx
index 2765f71..b1fc8d3 100644
--- a/sc/source/ui/view/tabvwshb.cxx
+++ b/sc/source/ui/view/tabvwshb.cxx
@@ -59,6 +59,9 @@
#include "drawview.hxx"
#include "ChartRangeSelectionListener.hxx"

#include <tools/urlobj.hxx>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>

using namespace com::sun::star;

// STATIC DATA -----------------------------------------------------------
@@ -301,6 +304,19 @@ void ScTabViewShell::ExecDrawIns(SfxRequest& rReq)
            FuInsertOLE(this, pWin, pView, pDrModel, rReq);
            break;

        case SID_INSERT_DIAGRAM_FROM_FILE:
            {
                sfx2::FileDialogHelper aDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
                        0, OUString("com.sun.star.chart2.ChartDocument"));
                if(aDlg.Execute() == ERRCODE_NONE )
                {
                    INetURLObject aURLObj( aDlg.GetPath() );
                    OUString aURL = aURLObj.GetURLNoPass();
                    FuInsertChartFromFile(this, pWin, pView, pDrModel, rReq, aURL);
                }
            }
            break;

        case SID_OBJECTRESIZE:
            {
                //          Der Server moechte die Clientgrosse verandern
diff --git a/sc/uiconfig/scalc/menubar/menubar.xml b/sc/uiconfig/scalc/menubar/menubar.xml
index 0544210..de494d5 100644
--- a/sc/uiconfig/scalc/menubar/menubar.xml
+++ b/sc/uiconfig/scalc/menubar/menubar.xml
@@ -214,9 +214,10 @@
                    <menu:menuitem menu:id=".uno:InsertSound"/>
                    <menu:menuitem menu:id=".uno:InsertVideo"/>
                    <menu:menuitem menu:id=".uno:InsertObjectStarMath"/>
                    <menu:menuitem menu:id=".uno:InsertObjectChart"/>
                    <menu:menuitem menu:id=".uno:InsertObjectChartFromFile"/>
                </menu:menupopup>
            </menu:menu>
            <menu:menuitem menu:id=".uno:InsertObjectChart"/>
            <menu:menuitem menu:id=".uno:InsertObjectFloatingFrame"/>
        </menu:menupopup>
    </menu:menu>
diff --git a/svx/inc/svx/svxids.hrc b/svx/inc/svx/svxids.hrc
index 43411c8..e92b3da 100644
--- a/svx/inc/svx/svxids.hrc
+++ b/svx/inc/svx/svxids.hrc
@@ -333,6 +333,7 @@
#define SID_OBJECT_ALIGN_UP                             ( SID_SVX_START + 134 )
#define SID_OBJECT_ALIGN_MIDDLE                         ( SID_SVX_START + 135 )
#define SID_OBJECT_ALIGN_DOWN                           ( SID_SVX_START + 136 )
#define SID_INSERT_DIAGRAM_FROM_FILE                    ( SID_SVX_START + 139 )
#define SID_INSERT_DIAGRAM                              ( SID_SVX_START + 140 )
#define SID_DRAW_CHART                                      SID_INSERT_DIAGRAM
#define SID_INSERT_TABLE                                ( SID_SVX_START + 141 )
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index a0b4f85..c432a52 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -6449,6 +6449,31 @@ SfxVoidItem InsertObjectChart SID_INSERT_DIAGRAM
]

//--------------------------------------------------------------------------
SfxVoidItem InsertObjectChartFromFile SID_INSERT_DIAGRAM_FROM_FILE
()
[
    /* flags: */
    AutoUpdate = FALSE,
    Cachable = Cachable,
    FastCall = FALSE,
    HasCoreId = FALSE,
    HasDialog = FALSE,
    ReadOnlyDoc = FALSE,
    Toggle = FALSE,
    Container = FALSE,
    RecordAbsolute = FALSE,
    RecordPerSet;
    Asynchron;

    /* config: */
    AccelConfig = TRUE,
    MenuConfig = TRUE,
    StatusBarConfig = FALSE,
    ToolBoxConfig = TRUE,
    GroupId = GID_INSERT;
]

//--------------------------------------------------------------------------
SfxVoidItem InsertPlugin SID_INSERT_PLUGIN
(SfxStringItem ClassLocation FN_PARAM_2,
 SfxStringItem Commands FN_PARAM_3)