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 <tools/urlobj.hxx>
23 #include <svx/svdobjkind.hxx>
24 #include <svx/svdouno.hxx>
25 #include <sfx2/docfile.hxx>
26 #include <osl/diagnose.h>
28 #include <com/sun/star/form/FormButtonType.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/awt/XControlModel.hpp>
32 #include <tabvwsh.hxx>
33 #include <document.hxx>
34 #include <drawview.hxx>
35 #include <globstr.hrc>
36 #include <gridwin.hxx>
37 #include <avmedia/mediawindow.hxx>
39 using namespace com::sun::star
;
41 void ScTabViewShell::InsertURLButton( const OUString
& rName
, const OUString
& rURL
,
42 const OUString
& rTarget
,
43 const Point
* pInsPos
)
47 ScViewData
& rViewData
= GetViewData();
48 ScDocument
& rDoc
= rViewData
.GetDocument();
49 SCTAB nTab
= rViewData
.GetTabNo();
50 if ( rDoc
.IsTabProtected(nTab
) )
52 ErrorMessage(STR_PROTECTIONERR
);
58 ScTabView
* pView
= rViewData
.GetView();
59 ScDrawView
* pDrView
= pView
->GetScDrawView();
60 SdrModel
& rModel
= pDrView
->GetModel();
62 rtl::Reference
<SdrObject
> pObj
= SdrObjFactory::MakeNewObject(
65 SdrObjKind::FormButton
);
67 SdrUnoObj
* pUnoCtrl
= dynamic_cast<SdrUnoObj
*>( pObj
.get() );
68 OSL_ENSURE( pUnoCtrl
, "no SdrUnoObj");
72 uno::Reference
<awt::XControlModel
> xControlModel
= pUnoCtrl
->GetUnoControlModel();
73 OSL_ENSURE( xControlModel
.is(), "UNO control without model" );
74 if( !xControlModel
.is() )
77 uno::Reference
< beans::XPropertySet
> xPropSet( xControlModel
, uno::UNO_QUERY
);
79 xPropSet
->setPropertyValue(u
"Label"_ustr
, uno::Any(rName
) );
81 OUString aTmp
= INetURLObject::GetAbsURL( rDoc
.GetDocumentShell()->GetMedium()->GetBaseURL(), rURL
);
82 xPropSet
->setPropertyValue(u
"TargetURL"_ustr
, uno::Any(aTmp
) );
84 if( !rTarget
.isEmpty() )
86 xPropSet
->setPropertyValue(u
"TargetFrame"_ustr
, uno::Any(rTarget
) );
89 xPropSet
->setPropertyValue(u
"ButtonType"_ustr
, uno::Any(form::FormButtonType_URL
) );
91 #if HAVE_FEATURE_AVMEDIA
92 if ( ::avmedia::MediaWindow::isMediaURL( rURL
, u
""_ustr
/*TODO?*/ ) )
94 xPropSet
->setPropertyValue(u
"DispatchURLInternal"_ustr
, uno::Any(true) );
102 aPos
= GetInsertPos();
105 Size aSize
= GetActiveWin()->PixelToLogic(Size(140, 20));
107 if ( rDoc
.IsNegativePage(nTab
) )
108 aPos
.AdjustX( -(aSize
.Width()) );
110 pObj
->SetLogicRect(tools::Rectangle(aPos
, aSize
));
112 // for the old VC-Button the position/size had to be set explicitly once more
113 // that seems not to be needed with UnoControls
115 // do not mark when Ole
116 pDrView
->InsertObjectSafe( pObj
.get(), *pDrView
->GetSdrPageView() );
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */