LibreOffice Module sc (master) 1
tabvwshg.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <config_features.h>
21
22#include <tools/urlobj.hxx>
23#include <svx/svdobjkind.hxx>
24#include <svx/svdouno.hxx>
25#include <sfx2/objsh.hxx>
26#include <sfx2/docfile.hxx>
27#include <osl/diagnose.h>
28
29#include <com/sun/star/form/FormButtonType.hpp>
30#include <com/sun/star/beans/XPropertySet.hpp>
31#include <com/sun/star/awt/XControlModel.hpp>
32
33using namespace com::sun::star;
34
35#include <tabvwsh.hxx>
36#include <document.hxx>
37#include <drawview.hxx>
38#include <globstr.hrc>
39#include <gridwin.hxx>
41
42void ScTabViewShell::InsertURLButton( const OUString& rName, const OUString& rURL,
43 const OUString& rTarget,
44 const Point* pInsPos )
45{
46 // protected sheet ?
47
48 ScViewData& rViewData = GetViewData();
49 ScDocument& rDoc = rViewData.GetDocument();
50 SCTAB nTab = rViewData.GetTabNo();
51 if ( rDoc.IsTabProtected(nTab) )
52 {
53 ErrorMessage(STR_PROTECTIONERR);
54 return;
55 }
56
58
59 ScTabView* pView = rViewData.GetView();
60 ScDrawView* pDrView = pView->GetScDrawView();
61 SdrModel& rModel = pDrView->GetModel();
62
64 rModel,
65 SdrInventor::FmForm,
66 SdrObjKind::FormButton);
67
68 SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( pObj.get() );
69 OSL_ENSURE( pUnoCtrl, "no SdrUnoObj");
70 if( !pUnoCtrl )
71 return;
72
73 uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
74 OSL_ENSURE( xControlModel.is(), "UNO control without model" );
75 if( !xControlModel.is() )
76 return;
77
78 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
79
80 xPropSet->setPropertyValue("Label", uno::Any(rName) );
81
82 OUString aTmp = INetURLObject::GetAbsURL( rDoc.GetDocumentShell()->GetMedium()->GetBaseURL(), rURL );
83 xPropSet->setPropertyValue("TargetURL", uno::Any(aTmp) );
84
85 if( !rTarget.isEmpty() )
86 {
87 xPropSet->setPropertyValue("TargetFrame", uno::Any(rTarget) );
88 }
89
90 xPropSet->setPropertyValue("ButtonType", uno::Any(form::FormButtonType_URL) );
91
92#if HAVE_FEATURE_AVMEDIA
93 if ( ::avmedia::MediaWindow::isMediaURL( rURL, ""/*TODO?*/ ) )
94 {
95 xPropSet->setPropertyValue("DispatchURLInternal", uno::Any(true) );
96 }
97#endif
98
99 Point aPos;
100 if (pInsPos)
101 aPos = *pInsPos;
102 else
103 aPos = GetInsertPos();
104
105 // Size as in 3.1:
106 Size aSize = GetActiveWin()->PixelToLogic(Size(140, 20));
107
108 if ( rDoc.IsNegativePage(nTab) )
109 aPos.AdjustX( -(aSize.Width()) );
110
111 pObj->SetLogicRect(tools::Rectangle(aPos, aSize));
112
113 // for the old VC-Button the position/size had to be set explicitly once more
114 // that seems not to be needed with UnoControls
115
116 // do not mark when Ole
117 pDrView->InsertObjectSafe( pObj.get(), *pDrView->GetSdrPageView() );
118}
119
120/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OUString GetAbsURL(std::u16string_view rTheBaseURIRef, OUString const &rTheRelURIRef, EncodeMechanism eEncodeMechanism=EncodeMechanism::WasEncoded, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
tools::Long AdjustX(tools::Long nHorzMove)
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1905
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:982
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1083
bool InsertObjectSafe(SdrObject *pObj, SdrPageView &rPV)
Definition: drawview.cxx:797
void InsertURLButton(const OUString &rName, const OUString &rURL, const OUString &rTarget, const Point *pInsPos)
Definition: tabvwshg.cxx:42
void ErrorMessage(TranslateId pGlobStrId)
Definition: tabview2.cxx:1553
void MakeDrawLayer()
Definition: tabview2.cxx:1529
Point GetInsertPos() const
Definition: tabview.cxx:1737
ScViewData & GetViewData()
Definition: tabview.hxx:344
ScGridWindow * GetActiveWin()
Definition: tabview.cxx:878
ScDrawView * GetScDrawView()
Definition: tabview.hxx:352
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
ScDBFunc * GetView() const
Definition: viewdata.cxx:864
static rtl::Reference< SdrObject > MakeNewObject(SdrModel &rSdrModel, SdrInventor nInventor, SdrObjKind nObjIdentifier, const tools::Rectangle *pSnapRect=nullptr)
SdrPageView * GetSdrPageView() const
SdrModel & GetModel() const
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
OUString GetBaseURL(bool bForSaving=false)
SfxMedium * GetMedium() const
constexpr tools::Long Width() const
static bool isMediaURL(std::u16string_view rURL, const OUString &rReferer, bool bDeep=false, rtl::Reference< PlayerListener > xPreferredPixelSizeListener=nullptr)
Point PixelToLogic(const Point &rDevicePt) const
FilterGroup & rTarget
sal_Int16 SCTAB
Definition: types.hxx:22