diff options
author | Armin Le Grand <alg@apache.org> | 2014-02-07 01:26:23 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-02-07 12:24:46 +0000 |
commit | 5c75cd95178e3d57e53fee64a9d64023c6d18acf (patch) | |
tree | 0b8608bbb949b1f07e62c82a188ba5d96da861e3 /sw/source/ui/shells | |
parent | coverity#708818 Unused pointer value (diff) | |
download | core-5c75cd95178e3d57e53fee64a9d64023c6d18acf.tar.gz core-5c75cd95178e3d57e53fee64a9d64023c6d18acf.zip |
Resolves: #i123922# Refactored D&D and insert picture from file...
in all apps for all object types to work the same
(cherry picked from commit 080a23dfb836bac49d9496fa1460b9dda9138f65)
Conflicts:
sc/source/ui/drawfunc/fuins1.cxx
sc/source/ui/inc/drawview.hxx
sc/source/ui/inc/viewfunc.hxx
sc/source/ui/view/drawview.cxx
sc/source/ui/view/viewfun3.cxx
sc/source/ui/view/viewfun7.cxx
sd/source/ui/func/fuinsert.cxx
sd/source/ui/view/sdview4.cxx
sw/source/core/frmedt/fecopy.cxx
sw/source/ui/dochdl/swdtflvr.cxx
sw/source/ui/inc/view.hxx
sw/source/ui/inc/wrtsh.hxx
sw/source/ui/shells/drawsh.cxx
sw/source/ui/uiview/view2.cxx
sw/source/ui/wrtsh/wrtsh1.cxx
Change-Id: I7f77d8c0812278ad434fe1c503a03d9747ea0b00
Diffstat (limited to 'sw/source/ui/shells')
-rw-r--r-- | sw/source/ui/shells/drawsh.cxx | 142 | ||||
-rw-r--r-- | sw/source/ui/shells/grfsh.cxx | 7 |
2 files changed, 149 insertions, 0 deletions
diff --git a/sw/source/ui/shells/drawsh.cxx b/sw/source/ui/shells/drawsh.cxx index 16a1f98eac84..84f394af081b 100644 --- a/sw/source/ui/shells/drawsh.cxx +++ b/sw/source/ui/shells/drawsh.cxx @@ -22,6 +22,7 @@ #include <svx/svdotext.hxx> #include <svl/whiter.hxx> #include <svx/fontwork.hxx> +#include <sfx2/docfile.hxx> #include <sfx2/request.hxx> #include <sfx2/bindings.hxx> #include <sfx2/objface.hxx> @@ -34,6 +35,8 @@ #include <wview.hxx> #include <swmodule.hxx> #include <swwait.hxx> +#include <doc.hxx> +#include <docsh.hxx> #include <docstat.hxx> #include <IDocumentStatistics.hxx> #include <tools/diagnose_ex.h> @@ -44,6 +47,12 @@ #include <svx/svdoashp.hxx> #include <svx/xtable.hxx> #include <sfx2/sidebar/EnumContext.hxx> +#include <svx/svdoashp.hxx> +#include <svx/svdoole2.hxx> +#include <sfx2/opengrf.hxx> +#include <svx/svdograf.hxx> +#include <svx/svdundo.hxx> +#include <svx/xbtmpit.hxx> #include "swundo.hxx" #include "wrtsh.hxx" @@ -74,6 +83,112 @@ SFX_IMPL_INTERFACE(SwDrawShell, SwDrawBaseShell, SW_RES(STR_SHELLNAME_DRAW)) TYPEINIT1(SwDrawShell,SwDrawBaseShell) +// #i123922# check as the name implies +SdrObject* SwDrawShell::IsSingleFillableNonOLESelected() +{ + SwWrtShell &rSh = GetShell(); + SdrView* pSdrView = rSh.GetDrawView(); + + if(!pSdrView) + { + return 0; + } + + if(1 != pSdrView->GetMarkedObjectCount()) + { + return 0; + } + + SdrObject* pPickObj = pSdrView->GetMarkedObjectByIndex(0); + + if(!pPickObj) + { + return 0; + } + + if(!pPickObj->IsClosedObj()) + { + return 0; + } + + if(dynamic_cast< SdrOle2Obj* >(pPickObj)) + { + return 0; + } + + return pPickObj; +} + +// #i123922# insert given graphic data dependent of the object type in focus +void SwDrawShell::InsertPictureFromFile(SdrObject& rObject) +{ + SwWrtShell &rSh = GetShell(); + SdrView* pSdrView = rSh.GetDrawView(); + + if(pSdrView) + { + SvxOpenGraphicDialog aDlg(SW_RESSTR(STR_INSERT_GRAPHIC)); + + if(GRFILTER_OK == aDlg.Execute()) + { + Graphic aGraphic; + int nError(aDlg.GetGraphic(aGraphic)); + + if(GRFILTER_OK == nError) + { + const bool bAsLink(aDlg.IsAsLink()); + SdrObject* pResult = &rObject; + + rSh.StartUndo(UNDO_PASTE_CLIPBOARD); + + if(dynamic_cast< SdrGrafObj* >(&rObject)) + { + SdrGrafObj* pNewGrafObj = (SdrGrafObj*)rObject.Clone(); + + pNewGrafObj->SetGraphic(aGraphic); + + // #i123922# for handling MasterObject and virtual ones correctly, SW + // wants us to call ReplaceObject at the page, but that also + // triggers the same assertion (I tried it), so stay at the view method + pSdrView->ReplaceObjectAtView(&rObject, *pSdrView->GetSdrPageView(), pNewGrafObj); + + OUString aReferer; + SwDocShell *pDocShell = rSh.GetDoc()->GetDocShell(); + if (pDocShell->HasName()) { + aReferer = pDocShell->GetMedium()->GetName(); + } + + // set in all cases - the Clone() will have copied an existing link (!) + pNewGrafObj->SetGraphicLink( + bAsLink ? aDlg.GetPath() : OUString(), + aReferer, + bAsLink ? aDlg.GetCurrentFilter() : OUString()); + + pResult = pNewGrafObj; + } + else // if(rObject.IsClosedObj() && !dynamic_cast< SdrOle2Obj* >(&rObject)) + { + pSdrView->AddUndo(new SdrUndoAttrObj(rObject)); + + SfxItemSet aSet(pSdrView->GetModel()->GetItemPool(), XATTR_FILLSTYLE, XATTR_FILLBITMAP); + + aSet.Put(XFillStyleItem(XFILL_BITMAP)); + aSet.Put(XFillBitmapItem(OUString(), aGraphic)); + rObject.SetMergedItemSetAndBroadcast(aSet); + } + + rSh.EndUndo( UNDO_END ); + + if(pResult) + { + // we are done; mark the modified/new object + pSdrView->MarkObj(pResult, pSdrView->GetSdrPageView()); + } + } + } + } +} + void SwDrawShell::Execute(SfxRequest &rReq) { SwWrtShell &rSh = GetShell(); @@ -265,6 +380,20 @@ void SwDrawShell::Execute(SfxRequest &rReq) rReq.Ignore (); break; + case SID_INSERT_GRAPHIC: + { + // #i123922# check if we can do something + SdrObject* pObj = IsSingleFillableNonOLESelected(); + + if(pObj) + { + // ...and if yes, do something + InsertPictureFromFile(*pObj); + } + + break; + } + default: OSL_ENSURE(!this, "wrong dispatcher"); return; @@ -357,6 +486,19 @@ void SwDrawShell::GetState(SfxItemSet& rSet) } } break; + + case SID_INSERT_GRAPHIC: + { + // #i123922# check if we can do something + SdrObject* pObj = IsSingleFillableNonOLESelected(); + + if(!pObj) + { + rSet.DisableItem(nWhich); + } + + break; + } } nWhich = aIter.NextWhich(); } diff --git a/sw/source/ui/shells/grfsh.cxx b/sw/source/ui/shells/grfsh.cxx index 6e6c75714276..0ad28795b5b8 100644 --- a/sw/source/ui/shells/grfsh.cxx +++ b/sw/source/ui/shells/grfsh.cxx @@ -186,6 +186,13 @@ void SwGrfShell::Execute(SfxRequest &rReq) break; case SID_INSERT_GRAPHIC: + { + // #i123922# implement slot independent from the two below to + // bring up the insert graphic dialog and associated actions + SwView& rLclView = GetView(); + rReq.SetReturnValue(SfxBoolItem(nSlot, rLclView.InsertGraphicDlg( rReq ))); + break; + } case FN_FORMAT_GRAFIC_DLG: case FN_DRAW_WRAP_DLG: { |