1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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())
49 SdrView
*pSdrView
= rSh
.GetDrawView();
52 pSdrView
->SetDesignMode();
53 pSdrView
->SetCurrentObj(SdrObjKind::FormButton
);
54 pSdrView
->SetEditMode(false);
56 Point
aStartPos(rSh
.GetCharRect().Pos() + Point(0, 1));
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" );
77 uno::Reference
< awt::XControlModel
> xControlModel
= pUnoCtrl
->GetUnoControlModel();
79 OSL_ENSURE( xControlModel
.is(), "UNO-Control without Model" );
80 if (!xControlModel
.is())
83 uno::Reference
< beans::XPropertySet
> xPropSet(xControlModel
, uno::UNO_QUERY
);
88 xPropSet
->setPropertyValue( "Label", aTmp
);
90 SfxMedium
* pMedium
= rSh
.GetView().GetDocShell()->GetMedium();
93 aAbs
= pMedium
->GetURLObject();
95 aTmp
<<= URIHelper::SmartRel2Abs(aAbs
, rURL
);
96 xPropSet
->setPropertyValue( "TargetURL", aTmp
);
98 if( !rTarget
.isEmpty() )
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?*/ ) )
112 xPropSet
->setPropertyValue("DispatchURLInternal", aTmp
);
117 if (rSh
.IsObjSelected())
122 rSh
.EndUndo( SwUndoId::UI_INSERT_URLBTN
);
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */