android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / func / fuexecuteinteraction.cxx
blob6dacef089d5609dab112b3258565ca4942903832
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <fuexecuteinteraction.hxx>
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>
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>
46 #include <com/sun/star/media/XPlayer.hpp>
48 using namespace css;
50 namespace sd
52 FuExecuteInteraction::FuExecuteInteraction(ViewShell* pViewSh, ::sd::Window* pWin,
53 ::sd::View* pView, SdDrawDocument* pDoc,
54 SfxRequest& rReq)
55 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
59 rtl::Reference<FuPoor> FuExecuteInteraction::Create(ViewShell* pViewSh, ::sd::Window* pWin,
60 ::sd::View* pView, SdDrawDocument* pDoc,
61 SfxRequest& rReq)
63 rtl::Reference<FuPoor> xFunc(new FuExecuteInteraction(pViewSh, pWin, pView, pDoc, rReq));
64 xFunc->DoExecute(rReq);
65 return xFunc;
68 void FuExecuteInteraction::DoExecute(SfxRequest&)
70 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
72 if (rMarkList.GetMarkCount() != 1)
73 return;
75 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
77 if (dynamic_cast<const GraphicDocShell*>(mpDocSh) != nullptr
78 || dynamic_cast<const DrawView*>(mpView) == nullptr)
79 return;
81 SdAnimationInfo* pInfo = SdDrawDocument::GetAnimationInfo(pObj);
82 if (!pInfo)
83 return;
85 switch (pInfo->meClickAction)
87 case presentation::ClickAction_BOOKMARK:
89 // Jump to Bookmark (Page or Object)
90 SfxStringItem aItem(SID_NAVIGATOR_OBJECT, pInfo->GetBookmark());
91 mpViewShell->GetViewFrame()->GetDispatcher()->ExecuteList(
92 SID_NAVIGATOR_OBJECT, SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
94 break;
96 case presentation::ClickAction_DOCUMENT:
98 OUString sBookmark(pInfo->GetBookmark());
99 // Jump to document
100 if (!sBookmark.isEmpty())
102 SfxStringItem aReferer(SID_REFERER, mpDocSh->GetMedium()->GetName());
103 SfxStringItem aStrItem(SID_FILE_NAME, sBookmark);
104 SfxViewFrame* pFrame = mpViewShell->GetViewFrame();
105 SfxFrameItem aFrameItem(SID_DOCFRAME, pFrame);
106 SfxBoolItem aBrowseItem(SID_BROWSE, true);
107 pFrame->GetDispatcher()->ExecuteList(
108 SID_OPENDOC, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
109 { &aStrItem, &aFrameItem, &aBrowseItem, &aReferer });
112 break;
114 case presentation::ClickAction_PREVPAGE:
116 // Jump to the previous page
117 SfxUInt16Item aItem(SID_NAVIGATOR_PAGE, PAGE_PREVIOUS);
118 mpViewShell->GetViewFrame()->GetDispatcher()->ExecuteList(
119 SID_NAVIGATOR_PAGE, SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
121 break;
123 case presentation::ClickAction_NEXTPAGE:
125 // Jump to the next page
126 SfxUInt16Item aItem(SID_NAVIGATOR_PAGE, PAGE_NEXT);
127 mpViewShell->GetViewFrame()->GetDispatcher()->ExecuteList(
128 SID_NAVIGATOR_PAGE, SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
130 break;
132 case presentation::ClickAction_FIRSTPAGE:
134 // Jump to the first page
135 SfxUInt16Item aItem(SID_NAVIGATOR_PAGE, PAGE_FIRST);
136 mpViewShell->GetViewFrame()->GetDispatcher()->ExecuteList(
137 SID_NAVIGATOR_PAGE, SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
139 break;
141 case presentation::ClickAction_LASTPAGE:
143 // Jump to the last page
144 SfxUInt16Item aItem(SID_NAVIGATOR_PAGE, PAGE_LAST);
145 mpViewShell->GetViewFrame()->GetDispatcher()->ExecuteList(
146 SID_NAVIGATOR_PAGE, SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
148 break;
150 case presentation::ClickAction_SOUND:
152 #if HAVE_FEATURE_AVMEDIA
155 mxPlayer.set(avmedia::MediaWindow::createPlayer(pInfo->GetBookmark(), "" /*TODO?*/),
156 uno::UNO_SET_THROW);
157 mxPlayer->start();
159 catch (uno::Exception&)
162 #endif
164 break;
166 case presentation::ClickAction_VERB:
168 // Assign verb
169 mpView->UnmarkAll();
170 mpView->MarkObj(pObj, mpView->GetSdrPageView());
171 DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(mpViewShell);
172 pDrViewSh->DoVerb(static_cast<sal_Int16>(pInfo->mnVerb));
174 break;
176 case presentation::ClickAction_PROGRAM:
178 OUString aBaseURL = GetDocSh()->GetMedium()->GetBaseURL();
179 INetURLObject aURL(::URIHelper::SmartRel2Abs(
180 INetURLObject(aBaseURL), pInfo->GetBookmark(), URIHelper::GetMaybeFileHdl(), true,
181 false, INetURLObject::EncodeMechanism::WasEncoded,
182 INetURLObject::DecodeMechanism::Unambiguous));
184 if (INetProtocol::File == aURL.GetProtocol())
186 if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
188 SfxStringItem aUrl(SID_FILE_NAME,
189 aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE));
190 SfxBoolItem aBrowsing(SID_BROWSE, true);
192 pViewFrm->GetDispatcher()->ExecuteList(
193 SID_OPENDOC, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
194 { &aUrl, &aBrowsing });
198 break;
200 #if HAVE_FEATURE_SCRIPTING
201 case presentation::ClickAction_MACRO:
203 // Execute macro
204 OUString aMacro = pInfo->GetBookmark();
206 if (SfxApplication::IsXScriptURL(aMacro))
208 uno::Any aRet;
209 uno::Sequence<sal_Int16> aOutArgsIndex;
210 uno::Sequence<uno::Any> aParams;
211 uno::Sequence<uno::Any> aOutArgs;
213 mpDocSh->CallXScript(aMacro, aParams, aRet, aOutArgsIndex, aOutArgs);
215 else
217 // aMacro has got following format:
218 // "Macroname.Modulname.Libname.Documentname" or
219 // "Macroname.Modulname.Libname.Applicationname"
220 sal_Int32 nIdx{ 0 };
221 const std::u16string_view aMacroName = o3tl::getToken(aMacro, 0, '.', nIdx);
222 const std::u16string_view aModulName = o3tl::getToken(aMacro, 0, '.', nIdx);
224 // Currently the "Call" method only resolves modulename+macroname
225 mpDocSh->GetBasic()->Call(OUString::Concat(aModulName) + "." + aMacroName);
228 break;
229 #endif
231 default:
232 break;
236 } // end of namespace sd
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */