Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / textdrw.cxx
blob881468c5d7173c3599e0680a004742648edf164c
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 <config_features.h>
22 #include <svx/svdview.hxx>
23 #include <tools/urlobj.hxx>
24 #include <svx/svdobjkind.hxx>
25 #include <svx/svdouno.hxx>
26 #include <com/sun/star/form/FormButtonType.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <osl/diagnose.h>
30 #include <view.hxx>
31 #include <wrtsh.hxx>
32 #include <edtwin.hxx>
33 #include <swundo.hxx>
34 #include <basesh.hxx>
36 #include <docsh.hxx>
37 #include <sfx2/docfile.hxx>
38 #include <svl/urihelper.hxx>
39 #include <avmedia/mediawindow.hxx>
41 using namespace ::com::sun::star;
43 void SwBaseShell::InsertURLButton(const OUString& rURL, const OUString& rTarget, const OUString& rText)
45 SwWrtShell& rSh = GetShell();
47 if (!rSh.HasDrawView())
48 rSh.MakeDrawView();
49 SdrView *pSdrView = rSh.GetDrawView();
51 // OBJ_FM_BUTTON
52 pSdrView->SetDesignMode();
53 pSdrView->SetCurrentObj(SdrObjKind::FormButton);
54 pSdrView->SetEditMode(false);
56 Point aStartPos(rSh.GetCharRect().Pos() + Point(0, 1));
58 rSh.StartAction();
59 rSh.StartUndo( SwUndoId::UI_INSERT_URLBTN );
60 if (rSh.BeginCreate(SdrObjKind::FormButton, SdrInventor::FmForm, aStartPos))
62 pSdrView->SetOrtho(false);
63 Size aSz(GetView().GetEditWin().PixelToLogic(Size(140, 20)));
64 Point aEndPos(aSz.Width(), aSz.Height());
66 rSh.MoveCreate(aStartPos + aEndPos);
67 rSh.EndCreate(SdrCreateCmd::ForceEnd);
69 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
70 if (rMarkList.GetMark(0))
72 SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
73 OSL_ENSURE( pUnoCtrl, "not an SdrUnoObj" );
74 if (!pUnoCtrl)
75 return;
77 uno::Reference< awt::XControlModel > xControlModel = pUnoCtrl->GetUnoControlModel();
79 OSL_ENSURE( xControlModel.is(), "UNO-Control without Model" );
80 if (!xControlModel.is())
81 return;
83 uno::Reference< beans::XPropertySet > xPropSet(xControlModel, uno::UNO_QUERY);
85 uno::Any aTmp;
87 aTmp <<= rText;
88 xPropSet->setPropertyValue( "Label", aTmp );
90 SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
91 INetURLObject aAbs;
92 if( pMedium )
93 aAbs = pMedium->GetURLObject();
95 aTmp <<= URIHelper::SmartRel2Abs(aAbs, rURL);
96 xPropSet->setPropertyValue( "TargetURL", aTmp );
98 if( !rTarget.isEmpty() )
100 aTmp <<= rTarget;
101 xPropSet->setPropertyValue( "TargetFrame", aTmp );
104 aTmp <<= form::FormButtonType_URL;
105 xPropSet->setPropertyValue( "ButtonType", aTmp );
107 #if HAVE_FEATURE_AVMEDIA
108 if ( ::avmedia::MediaWindow::isMediaURL( rURL, ""/*TODO?*/ ) )
110 // #105638# OJ
111 aTmp <<= true;
112 xPropSet->setPropertyValue("DispatchURLInternal", aTmp );
114 #endif
117 if (rSh.IsObjSelected())
119 rSh.UnSelectFrame();
122 rSh.EndUndo( SwUndoId::UI_INSERT_URLBTN );
123 rSh.EndAction();
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */