Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/form/fmpage.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 <svx/fmpage.hxx>
21
#include <com/sun/star/beans/XPropertySet.hpp>
22
23
#include <svx/fmmodel.hxx>
24
25
#include <fmobj.hxx>
26
27
#include <fmpgeimp.hxx>
28
29
#include <svx/svdview.hxx>
30
#include <tools/urlobj.hxx>
31
#include <vcl/help.hxx>
32
#include <vcl/window.hxx>
33
#include <osl/diagnose.h>
34
#include <fmprop.hxx>
35
#include <fmundo.hxx>
36
#include <comphelper/property.hxx>
37
#include <comphelper/types.hxx>
38
39
using namespace ::svxform;
40
using com::sun::star::uno::Reference;
41
using com::sun::star::uno::UNO_QUERY;
42
43
44
FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
45
688k
:   SdrPage(rModel, bMasterPage)
46
688k
    ,m_pImpl( new FmFormPageImpl( *this ) )
47
688k
{
48
688k
}
49
50
void FmFormPage::lateInit(const FmFormPage& rPage)
51
5.28k
{
52
    // call parent
53
5.28k
    SdrPage::lateInit( rPage );
54
55
    // copy local variables (former stuff from copy constructor)
56
5.28k
    m_pImpl->initFrom( rPage.GetImpl() );
57
5.28k
    m_sPageName = rPage.m_sPageName;
58
5.28k
}
59
60
61
FmFormPage::~FmFormPage()
62
687k
{
63
687k
}
64
65
rtl::Reference<SdrPage> FmFormPage::CloneSdrPage(SdrModel& rTargetModel) const
66
0
{
67
0
    FmFormModel& rFmFormModel(static_cast< FmFormModel& >(rTargetModel));
68
0
    rtl::Reference<FmFormPage> pClonedFmFormPage =
69
0
        new FmFormPage(
70
0
            rFmFormModel,
71
0
            IsMasterPage());
72
0
    pClonedFmFormPage->lateInit(*this);
73
0
    return pClonedFmFormPage;
74
0
}
75
76
77
void FmFormPage::InsertObject(SdrObject* pObj, size_t nPos)
78
1.41M
{
79
1.41M
    SdrPage::InsertObject( pObj, nPos );
80
1.41M
    static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Inserted(pObj);
81
1.41M
}
82
83
84
const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
85
734k
{
86
734k
    const SdrPage& rMasterPage( *this );
87
734k
    const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
88
734k
    OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
89
734k
    if ( !pFormPage )
90
0
        pFormPage = this;
91
92
734k
    return pFormPage->m_pImpl->getForms( _bForceCreate );
93
734k
}
94
95
96
bool FmFormPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView,
97
                              const HelpEvent& rEvt )
98
0
{
99
0
    if( pView->IsAction() )
100
0
        return false;
101
102
0
    Point aPos = rEvt.GetMousePosPixel();
103
0
    aPos = pWindow->ScreenToOutputPixel( aPos );
104
0
    aPos = pWindow->PixelToLogic( aPos );
105
106
0
    SdrPageView* pPV = nullptr;
107
0
    SdrObject* pObj = pView->PickObj(aPos, 0, pPV, SdrSearchOptions::DEEP);
108
0
    if (!pObj)
109
0
        return false;
110
111
0
    FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
112
0
    if ( !pFormObject )
113
0
        return false;
114
115
0
    OUString aHelpText;
116
0
    css::uno::Reference< css::beans::XPropertySet >  xSet( pFormObject->GetUnoControlModel(), css::uno::UNO_QUERY );
117
0
    if (xSet.is())
118
0
    {
119
0
        if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
120
0
            aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT));
121
122
0
        if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
123
0
        {
124
0
            OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
125
0
            INetURLObject aUrl(aText);
126
127
            // test if it is a protocol type that I want to display
128
0
            INetProtocol aProtocol = aUrl.GetProtocol();
129
0
            static const INetProtocol s_aQuickHelpSupported[] =
130
0
                {   INetProtocol::Ftp, INetProtocol::Http, INetProtocol::File, INetProtocol::Mailto,
131
0
                    INetProtocol::Https, INetProtocol::Javascript,
132
0
                    INetProtocol::Ldap
133
0
                };
134
0
            for (const INetProtocol& i : s_aQuickHelpSupported)
135
0
                if (i == aProtocol)
136
0
                {
137
0
                    aHelpText = aUrl.GetURLNoPass(INetURLObject::DecodeMechanism::Unambiguous);
138
0
                    break;
139
0
                }
140
0
        }
141
0
    }
142
143
    // display the help
144
0
    tools::Rectangle aItemRect = pObj->GetCurrentBoundRect();
145
0
    aItemRect = pWindow->LogicToPixel( aItemRect );
146
0
    Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
147
0
    aItemRect.SetLeft( aPt.X() );
148
0
    aItemRect.SetTop( aPt.Y() );
149
0
    aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
150
0
    aItemRect.SetRight( aPt.X() );
151
0
    aItemRect.SetBottom( aPt.Y() );
152
0
    if( rEvt.GetMode() == HelpEventMode::BALLOON )
153
0
        Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
154
0
    else
155
0
        Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
156
157
0
    return true;
158
0
}
159
160
161
rtl::Reference<SdrObject> FmFormPage::RemoveObject(size_t nObjNum)
162
473k
{
163
473k
    rtl::Reference<SdrObject> pObj = SdrPage::RemoveObject(nObjNum);
164
473k
    if (pObj)
165
473k
        static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Removed(pObj.get());
166
473k
    return pObj;
167
473k
}
168
169
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */