tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / sd / source / ui / func / futransf.cxx
bloba50cfaf3648a0474705fefa4b41a16f6112409b1
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 <svx/svxids.hrc>
23 #include <sfx2/request.hxx>
25 #include <strings.hrc>
26 #include <ViewShell.hxx>
27 #include <View.hxx>
28 #include <sdresid.hxx>
29 #include <drawdoc.hxx>
30 #include <svx/svxdlg.hxx>
31 #include <comphelper/lok.hxx>
33 #include <memory>
35 using namespace sd;
37 FuTransform::FuTransform(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
38 SdDrawDocument* pDoc, SfxRequest& rReq)
39 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
43 rtl::Reference<FuPoor> FuTransform::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
45 rtl::Reference<FuPoor> xFunc( new FuTransform( pViewSh, pWin, pView, pDoc, rReq ) );
46 xFunc->DoExecute(rReq);
47 return xFunc;
50 namespace {
52 void setUndo(::sd::View* pView, const SfxItemSet* pArgs, bool addPageMargin)
54 // Undo
55 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
56 OUString aString = rMarkList.GetMarkDescription() +
57 " " + SdResId(STR_TRANSFORM);
58 pView->BegUndo(aString);
59 pView->SetGeoAttrToMarked(*pArgs, addPageMargin);
60 pView->SetAttributes(*pArgs);
61 pView->EndUndo();
66 void FuTransform::DoExecute( SfxRequest& rReq )
68 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
69 if (rMarkList.GetMarkCount() == 0)
70 return;
72 const SfxItemSet* pArgs = rReq.GetArgs();
74 if (pArgs)
76 // If this comes from LOK, that means the shape is moved by mouse
77 // only then pArgs is pre-set.
78 setUndo(mpView, pArgs, comphelper::LibreOfficeKit::isActive());
79 return;
82 // --------- itemset for size and position --------
83 SfxItemSet aSet( mpView->GetGeoAttrFromMarked() );
84 VclPtr<SfxAbstractTabDialog> pDlg;
86 bool bWelded = false;
87 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
88 if( rMarkList.GetMarkCount() == 1 &&
89 pObj->GetObjInventor() == SdrInventor::Default &&
90 pObj->GetObjIdentifier() == SdrObjKind::Caption )
92 // --------- itemset for caption --------
93 SfxItemSet aNewAttr( mpDoc->GetPool() );
94 mpView->GetAttributes( aNewAttr );
96 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
97 pDlg.reset(pFact->CreateCaptionDialog(mpViewShell->GetFrameWeld(), mpView));
99 const WhichRangesContainer aRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
100 SfxItemSet aCombSet( *aNewAttr.GetPool(), aRange );
101 aCombSet.Put( aNewAttr );
102 aCombSet.Put( aSet );
103 pDlg->SetInputSet( &aCombSet );
105 else
107 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
108 pDlg.reset(pFact->CreateSvxTransformTabDialog(mpViewShell->GetFrameWeld(), &aSet, mpView));
109 bWelded = true;
112 assert(pDlg && "there must be a dialog at this point");
114 auto xRequest = std::make_shared<SfxRequest>(rReq);
115 rReq.Ignore(); // the 'old' request is not relevant any more
117 pDlg->StartExecuteAsync([bWelded, pDlg, xRequest=std::move(xRequest), this](sal_Int32 nResult){
118 if (nResult == RET_OK)
120 xRequest->Done(*(pDlg->GetOutputItemSet()));
121 // Page margin is already calculated at this point.
122 setUndo(mpView, xRequest->GetArgs(), false);
125 // deferred until the dialog ends
126 mpViewShell->Invalidate(SID_RULER_OBJECT);
127 mpViewShell->Cancel();
128 if (bWelded)
129 pDlg->disposeOnce();
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */