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 <svx/svdview.hxx>
21 #include <tools/urlobj.hxx>
22 #include <svx/fmglob.hxx>
23 #include <svx/svdouno.hxx>
24 #include <com/sun/star/form/FormButtonType.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <poolfmt.hrc>
36 #include <sfx2/docfile.hxx>
37 #include <svl/urihelper.hxx>
38 #include <avmedia/mediawindow.hxx>
42 using namespace ::com::sun::star
;
44 void SwBaseShell::InsertURLButton(const String
& rURL
, const String
& rTarget
, const String
& rTxt
)
46 SwWrtShell
& rSh
= GetShell();
48 if (!rSh
.HasDrawView())
50 SdrView
*pSdrView
= rSh
.GetDrawView();
53 pSdrView
->SetDesignMode(sal_True
);
54 pSdrView
->SetCurrentObj(OBJ_FM_BUTTON
);
55 pSdrView
->SetEditMode(sal_False
);
57 Point
aStartPos(rSh
.GetCharRect().Pos() + Point(0, 1));
60 rSh
.StartUndo( UNDO_UI_INSERT_URLBTN
);
61 if (rSh
.BeginCreate(OBJ_FM_BUTTON
, FmFormInventor
, aStartPos
))
63 pSdrView
->SetOrtho(sal_False
);
64 Size
aSz(GetView().GetEditWin().PixelToLogic(Size(140, 20)));
65 Point
aEndPos(aSz
.Width(), aSz
.Height());
67 rSh
.MoveCreate(aStartPos
+ aEndPos
);
68 rSh
.EndCreate(SDRCREATE_FORCEEND
);
70 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
71 if (rMarkList
.GetMark(0))
73 SdrUnoObj
* pUnoCtrl
= PTR_CAST(SdrUnoObj
, rMarkList
.GetMark(0)->GetMarkedSdrObj());
74 uno::Reference
< awt::XControlModel
> xControlModel
= pUnoCtrl
->GetUnoControlModel();
76 OSL_ENSURE( xControlModel
.is(), "UNO-Control without Model" );
77 if( !xControlModel
.is() )
80 uno::Reference
< beans::XPropertySet
> xPropSet(xControlModel
, uno::UNO_QUERY
);
85 aTmp
<<= OUString(rTxt
);
86 xPropSet
->setPropertyValue( "Label", aTmp
);
88 SfxMedium
* pMedium
= rSh
.GetView().GetDocShell()->GetMedium();
91 aAbs
= pMedium
->GetURLObject();
93 aTmp
<<= OUString(URIHelper::SmartRel2Abs(aAbs
, rURL
));
94 xPropSet
->setPropertyValue( "TargetURL", aTmp
);
98 aTmp
<<= OUString(rTarget
);
99 xPropSet
->setPropertyValue( "TargetFrame", aTmp
);
103 form::FormButtonType eButtonType
= form::FormButtonType_URL
;
104 aTmp
.setValue( &eButtonType
, ::getCppuType((const form::FormButtonType
*)0));
105 xPropSet
->setPropertyValue( "ButtonType", aTmp
);
107 if ( ::avmedia::MediaWindow::isMediaURL( rURL
) )
111 xPropSet
->setPropertyValue( OUString( "DispatchURLInternal" ), aTmp
);
115 if (rSh
.IsObjSelected())
120 rSh
.EndUndo( UNDO_UI_INSERT_URLBTN
);
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */