Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / futransf.cxx
blob28babc122354b5d7412af7fd0e9a9796f7ebcdd2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <futransf.hxx>
22 #include <comphelper/scopeguard.hxx>
23 #include <svx/dialogs.hrc>
24 #include <sfx2/request.hxx>
26 #include <strings.hrc>
27 #include <ViewShell.hxx>
28 #include <View.hxx>
29 #include <Window.hxx>
30 #include <sdresid.hxx>
31 #include <drawdoc.hxx>
32 #include <svx/svxdlg.hxx>
34 #include <memory>
36 using namespace sd;
38 FuTransform::FuTransform(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
39 SdDrawDocument* pDoc, SfxRequest& rReq)
40 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
44 rtl::Reference<FuPoor> FuTransform::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
46 rtl::Reference<FuPoor> xFunc( new FuTransform( pViewSh, pWin, pView, pDoc, rReq ) );
47 xFunc->DoExecute(rReq);
48 return xFunc;
51 namespace {
53 void setUndo(::sd::View* pView, const SfxItemSet* pArgs)
55 // Undo
56 OUString aString(pView->GetDescriptionOfMarkedObjects());
57 aString += " " + SdResId(STR_TRANSFORM);
58 pView->BegUndo(aString);
60 pView->SetGeoAttrToMarked(*pArgs);
61 pView->SetAttributes(*pArgs);
62 pView->EndUndo();
67 void FuTransform::DoExecute( SfxRequest& rReq )
69 if (!mpView->AreObjectsMarked())
70 return;
72 const SfxItemSet* pArgs = rReq.GetArgs();
74 if (pArgs)
76 setUndo(mpView, pArgs);
77 return;
80 // --------- itemset for size and position --------
81 SfxItemSet aSet( mpView->GetGeoAttrFromMarked() );
82 VclPtr<SfxAbstractTabDialog> pDlg;
84 bool bWelded = false;
85 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
86 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
87 if( rMarkList.GetMarkCount() == 1 &&
88 pObj->GetObjInventor() == SdrInventor::Default &&
89 pObj->GetObjIdentifier() == OBJ_CAPTION )
91 // --------- itemset for caption --------
92 SfxItemSet aNewAttr( mpDoc->GetPool() );
93 mpView->GetAttributes( aNewAttr );
95 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
96 if (!pFact)
97 return;
99 pDlg.reset(pFact->CreateCaptionDialog(mpViewShell->GetActiveWindow(), mpView));
101 const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
102 SfxItemSet aCombSet( *aNewAttr.GetPool(), pRange );
103 aCombSet.Put( aNewAttr );
104 aCombSet.Put( aSet );
105 pDlg->SetInputSet( &aCombSet );
107 else
109 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
110 if (!pFact)
111 return;
113 pDlg.reset(pFact->CreateSvxTransformTabDialog(mpViewShell->GetFrameWeld(), &aSet, mpView));
114 bWelded = true;
117 if (!pDlg)
118 return;
120 std::shared_ptr<SfxRequest> pRequest(new SfxRequest(rReq));
121 rReq.Ignore(); // the 'old' request is not relevant any more
123 pDlg->StartExecuteAsync([=](sal_Int32 nResult){
124 if (nResult == RET_OK)
126 pRequest->Done(*(pDlg->GetOutputItemSet()));
127 setUndo(mpView, pRequest->GetArgs());
130 // deferred until the dialog ends
131 mpViewShell->Invalidate(SID_RULER_OBJECT);
132 mpViewShell->Cancel();
133 if (bWelded)
134 pDlg->disposeOnce();
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */