Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/view/tabvwshg.cxx
Line
Count
Source
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/docfile.hxx>
26
#include <osl/diagnose.h>
27
28
#include <com/sun/star/form/FormButtonType.hpp>
29
#include <com/sun/star/beans/XPropertySet.hpp>
30
#include <com/sun/star/awt/XControlModel.hpp>
31
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>
38
39
using namespace com::sun::star;
40
41
void ScTabViewShell::InsertURLButton( const OUString& rName, const OUString& rURL,
42
                                        const OUString& rTarget,
43
                                        const Point* pInsPos )
44
0
{
45
    // protected sheet ?
46
47
0
    ScViewData& rViewData = GetViewData();
48
0
    ScDocument& rDoc = rViewData.GetDocument();
49
0
    SCTAB nTab = rViewData.CurrentTabForData();
50
0
    if ( rDoc.IsTabProtected(nTab) )
51
0
    {
52
0
        ErrorMessage(STR_PROTECTIONERR);
53
0
        return;
54
0
    }
55
56
0
    MakeDrawLayer();
57
58
0
    ScTabView*  pView   = rViewData.GetView();
59
0
    ScDrawView* pDrView = pView->GetScDrawView();
60
0
    SdrModel& rModel = pDrView->GetModel();
61
62
0
    rtl::Reference<SdrObject> pObj = SdrObjFactory::MakeNewObject(
63
0
        rModel,
64
0
        SdrInventor::FmForm,
65
0
        SdrObjKind::FormButton);
66
67
0
    SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( pObj.get() );
68
0
    OSL_ENSURE( pUnoCtrl, "no SdrUnoObj");
69
0
    if( !pUnoCtrl )
70
0
        return;
71
72
0
    uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
73
0
    OSL_ENSURE( xControlModel.is(), "UNO control without model" );
74
0
    if( !xControlModel.is() )
75
0
        return;
76
77
0
    uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
78
79
0
    xPropSet->setPropertyValue(u"Label"_ustr, uno::Any(rName) );
80
81
0
    OUString aTmp = INetURLObject::GetAbsURL( rDoc.GetDocumentShell()->GetMedium()->GetBaseURL(), rURL );
82
0
    xPropSet->setPropertyValue(u"TargetURL"_ustr, uno::Any(aTmp) );
83
84
0
    if( !rTarget.isEmpty() )
85
0
    {
86
0
        xPropSet->setPropertyValue(u"TargetFrame"_ustr, uno::Any(rTarget) );
87
0
    }
88
89
0
    xPropSet->setPropertyValue(u"ButtonType"_ustr, uno::Any(form::FormButtonType_URL) );
90
91
0
#if HAVE_FEATURE_AVMEDIA
92
0
    if ( ::avmedia::MediaWindow::isMediaURL( rURL, u""_ustr/*TODO?*/ ) )
93
0
    {
94
0
        xPropSet->setPropertyValue(u"DispatchURLInternal"_ustr, uno::Any(true) );
95
0
    }
96
0
#endif
97
98
0
    Point aPos;
99
0
    if (pInsPos)
100
0
        aPos = *pInsPos;
101
0
    else
102
0
        aPos = GetInsertPos();
103
104
    // Size as in 3.1:
105
0
    Size aSize = GetActiveWin()->PixelToLogic(Size(140, 20));
106
107
0
    if ( rDoc.IsNegativePage(nTab) )
108
0
        aPos.AdjustX( -(aSize.Width()) );
109
110
0
    pObj->SetLogicRect(tools::Rectangle(aPos, aSize));
111
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
114
115
    // do not mark when Ole
116
0
    pDrView->InsertObjectSafe( pObj.get(), *pDrView->GetSdrPageView() );
117
0
}
118
119
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */