Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sd/source/ui/func/fuexecuteinteraction.cxx
Line
Count
Source (jump to first uncovered line)
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 <fuexecuteinteraction.hxx>
21
22
#include <app.hrc>
23
#include <config_features.h>
24
#include <avmedia/mediawindow.hxx>
25
#include <basic/sbstar.hxx>
26
#include <sfx2/app.hxx>
27
#include <sfx2/bindings.hxx>
28
#include <sfx2/dispatch.hxx>
29
#include <sfx2/docfile.hxx>
30
#include <sfx2/sfxsids.hrc>
31
#include <sfx2/viewfrm.hxx>
32
#include <svl/intitem.hxx>
33
#include <svl/stritem.hxx>
34
#include <svl/urihelper.hxx>
35
#include <tools/urlobj.hxx>
36
#include <o3tl/string_view.hxx>
37
38
#include <DrawViewShell.hxx>
39
#include <GraphicDocShell.hxx>
40
#include <ViewShell.hxx>
41
#include <anminfo.hxx>
42
#include <drawdoc.hxx>
43
#include <drawview.hxx>
44
#include <pgjump.hxx>
45
46
#include <com/sun/star/media/XPlayer.hpp>
47
48
using namespace css;
49
50
namespace sd
51
{
52
FuExecuteInteraction::FuExecuteInteraction(ViewShell& rViewSh, ::sd::Window* pWin,
53
                                           ::sd::View* pView, SdDrawDocument& rDoc,
54
                                           SfxRequest& rReq)
55
0
    : FuPoor(rViewSh, pWin, pView, rDoc, rReq)
56
0
{
57
0
}
58
59
rtl::Reference<FuPoor> FuExecuteInteraction::Create(ViewShell& rViewSh, ::sd::Window* pWin,
60
                                                    ::sd::View* pView, SdDrawDocument& rDoc,
61
                                                    SfxRequest& rReq)
62
0
{
63
0
    rtl::Reference<FuPoor> xFunc(new FuExecuteInteraction(rViewSh, pWin, pView, rDoc, rReq));
64
0
    xFunc->DoExecute(rReq);
65
0
    return xFunc;
66
0
}
67
68
void FuExecuteInteraction::DoExecute(SfxRequest&)
69
0
{
70
0
    const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
71
72
0
    if (rMarkList.GetMarkCount() != 1)
73
0
        return;
74
75
0
    SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
76
77
0
    if (dynamic_cast<const GraphicDocShell*>(mpDocSh) != nullptr
78
0
        || dynamic_cast<const DrawView*>(mpView) == nullptr)
79
0
        return;
80
81
0
    assert(mpDocSh);
82
83
0
    SdAnimationInfo* pInfo = SdDrawDocument::GetAnimationInfo(pObj);
84
0
    if (!pInfo)
85
0
        return;
86
87
0
    switch (pInfo->meClickAction)
88
0
    {
89
0
        case presentation::ClickAction_BOOKMARK:
90
0
        {
91
            // Jump to Bookmark (Page or Object)
92
0
            SfxStringItem aItem(SID_NAVIGATOR_OBJECT, pInfo->GetBookmark());
93
0
            mrViewShell.GetViewFrame()->GetDispatcher()->ExecuteList(
94
0
                SID_NAVIGATOR_OBJECT, SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
95
0
        }
96
0
        break;
97
98
0
        case presentation::ClickAction_DOCUMENT:
99
0
        {
100
0
            OUString sBookmark(pInfo->GetBookmark());
101
            // Jump to document
102
0
            if (!sBookmark.isEmpty())
103
0
            {
104
0
                SfxStringItem aReferer(SID_REFERER, mpDocSh->GetMedium()->GetName());
105
0
                SfxStringItem aStrItem(SID_FILE_NAME, sBookmark);
106
0
                SfxViewFrame* pFrame = mrViewShell.GetViewFrame();
107
0
                SfxFrameItem aFrameItem(SID_DOCFRAME, pFrame);
108
0
                SfxBoolItem aBrowseItem(SID_BROWSE, true);
109
0
                pFrame->GetDispatcher()->ExecuteList(
110
0
                    SID_OPENDOC, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
111
0
                    { &aStrItem, &aFrameItem, &aBrowseItem, &aReferer });
112
0
            }
113
0
        }
114
0
        break;
115
116
0
        case presentation::ClickAction_PREVPAGE:
117
0
        {
118
            // Jump to the previous page
119
0
            SfxUInt16Item aItem(SID_NAVIGATOR_PAGE, PAGE_PREVIOUS);
120
0
            mrViewShell.GetViewFrame()->GetDispatcher()->ExecuteList(
121
0
                SID_NAVIGATOR_PAGE, SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
122
0
        }
123
0
        break;
124
125
0
        case presentation::ClickAction_NEXTPAGE:
126
0
        {
127
            // Jump to the next page
128
0
            SfxUInt16Item aItem(SID_NAVIGATOR_PAGE, PAGE_NEXT);
129
0
            mrViewShell.GetViewFrame()->GetDispatcher()->ExecuteList(
130
0
                SID_NAVIGATOR_PAGE, SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
131
0
        }
132
0
        break;
133
134
0
        case presentation::ClickAction_FIRSTPAGE:
135
0
        {
136
            // Jump to the first page
137
0
            SfxUInt16Item aItem(SID_NAVIGATOR_PAGE, PAGE_FIRST);
138
0
            mrViewShell.GetViewFrame()->GetDispatcher()->ExecuteList(
139
0
                SID_NAVIGATOR_PAGE, SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
140
0
        }
141
0
        break;
142
143
0
        case presentation::ClickAction_LASTPAGE:
144
0
        {
145
            // Jump to the last page
146
0
            SfxUInt16Item aItem(SID_NAVIGATOR_PAGE, PAGE_LAST);
147
0
            mrViewShell.GetViewFrame()->GetDispatcher()->ExecuteList(
148
0
                SID_NAVIGATOR_PAGE, SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
149
0
        }
150
0
        break;
151
152
0
        case presentation::ClickAction_SOUND:
153
0
        {
154
0
#if HAVE_FEATURE_AVMEDIA
155
0
            try
156
0
            {
157
0
                mxPlayer.set(
158
0
                    avmedia::MediaWindow::createPlayer(pInfo->GetBookmark(), u""_ustr /*TODO?*/),
159
0
                    uno::UNO_SET_THROW);
160
0
                mxPlayer->start();
161
0
            }
162
0
            catch (uno::Exception&)
163
0
            {
164
0
            }
165
0
#endif
166
0
        }
167
0
        break;
168
169
0
        case presentation::ClickAction_VERB:
170
0
        {
171
            // Assign verb
172
0
            mpView->UnmarkAll();
173
0
            mpView->MarkObj(pObj, mpView->GetSdrPageView());
174
0
            DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(&mrViewShell);
175
0
            pDrViewSh->DoVerb(static_cast<sal_Int16>(pInfo->mnVerb));
176
0
        }
177
0
        break;
178
179
0
        case presentation::ClickAction_PROGRAM:
180
0
        {
181
0
            OUString aBaseURL = GetDocSh()->GetMedium()->GetBaseURL();
182
0
            INetURLObject aURL(::URIHelper::SmartRel2Abs(
183
0
                INetURLObject(aBaseURL), pInfo->GetBookmark(), URIHelper::GetMaybeFileHdl(), true,
184
0
                false, INetURLObject::EncodeMechanism::WasEncoded,
185
0
                INetURLObject::DecodeMechanism::Unambiguous));
186
187
0
            if (INetProtocol::File == aURL.GetProtocol())
188
0
            {
189
0
                if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
190
0
                {
191
0
                    SfxStringItem aUrl(SID_FILE_NAME,
192
0
                                       aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE));
193
0
                    SfxBoolItem aBrowsing(SID_BROWSE, true);
194
195
0
                    pViewFrm->GetDispatcher()->ExecuteList(
196
0
                        SID_OPENDOC, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
197
0
                        { &aUrl, &aBrowsing });
198
0
                }
199
0
            }
200
0
        }
201
0
        break;
202
203
#if HAVE_FEATURE_SCRIPTING
204
        case presentation::ClickAction_MACRO:
205
        {
206
            // Execute macro
207
            OUString aMacro = pInfo->GetBookmark();
208
209
            if (SfxApplication::IsXScriptURL(aMacro))
210
            {
211
                uno::Any aRet;
212
                uno::Sequence<sal_Int16> aOutArgsIndex;
213
                uno::Sequence<uno::Any> aParams;
214
                uno::Sequence<uno::Any> aOutArgs;
215
216
                mpDocSh->CallXScript(aMacro, aParams, aRet, aOutArgsIndex, aOutArgs);
217
            }
218
            else
219
            {
220
                // aMacro has got following format:
221
                // "Macroname.Modulname.Libname.Documentname" or
222
                // "Macroname.Modulname.Libname.Applicationname"
223
                sal_Int32 nIdx{ 0 };
224
                const std::u16string_view aMacroName = o3tl::getToken(aMacro, 0, '.', nIdx);
225
                const std::u16string_view aModulName = o3tl::getToken(aMacro, 0, '.', nIdx);
226
227
                // Currently the "Call" method only resolves modulename+macroname
228
                mpDocSh->GetBasic()->Call(OUString::Concat(aModulName) + "." + aMacroName);
229
            }
230
        }
231
        break;
232
#endif
233
234
0
        default:
235
0
            break;
236
0
    }
237
0
}
238
239
} // end of namespace sd
240
241
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */