/src/libreoffice/sw/source/uibase/shells/grfshex.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 | | #include <wrtsh.hxx> |
22 | | #include <view.hxx> |
23 | | #include <textsh.hxx> |
24 | | #include <drawdoc.hxx> |
25 | | #include <doc.hxx> |
26 | | #include <IDocumentDrawModelAccess.hxx> |
27 | | #include <docsh.hxx> |
28 | | #include <avmedia/mediawindow.hxx> |
29 | | #include <editeng/sizeitem.hxx> |
30 | | #include <sfx2/request.hxx> |
31 | | #include <sfx2/viewfrm.hxx> |
32 | | #include <svl/stritem.hxx> |
33 | | #include <svx/svdomedia.hxx> |
34 | | #include <com/sun/star/frame/XDispatchProvider.hpp> |
35 | | #include <com/sun/star/media/XPlayer.hpp> |
36 | | |
37 | | using namespace ::com::sun::star; |
38 | | using namespace ::com::sun::star::uno; |
39 | | |
40 | | bool SwTextShell::InsertMediaDlg( SfxRequest const & rReq ) |
41 | 0 | { |
42 | 0 | bool bRet = false; |
43 | |
|
44 | | #if !HAVE_FEATURE_AVMEDIA |
45 | | (void) rReq; |
46 | | #else |
47 | 0 | OUString aURL; |
48 | 0 | const SfxItemSet* pReqArgs = rReq.GetArgs(); |
49 | 0 | vcl::Window& rWindow = GetView().GetViewFrame().GetWindow(); |
50 | 0 | bool bAPI = false; |
51 | |
|
52 | 0 | const SvxSizeItem* pSizeItem = rReq.GetArg<SvxSizeItem>(FN_PARAM_1); |
53 | 0 | const SfxBoolItem* pLinkItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_2); |
54 | 0 | const bool bSizeUnknown = !pSizeItem; |
55 | |
|
56 | 0 | if( pReqArgs ) |
57 | 0 | { |
58 | 0 | const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>( &pReqArgs->Get( rReq.GetSlot() ) ); |
59 | 0 | if( pStringItem ) |
60 | 0 | { |
61 | 0 | aURL = pStringItem->GetValue(); |
62 | 0 | bAPI = !aURL.isEmpty(); |
63 | 0 | } |
64 | 0 | } |
65 | |
|
66 | 0 | bool bLink(pLinkItem ? pLinkItem->GetValue() : true); |
67 | |
|
68 | 0 | if (bAPI || ::avmedia::MediaWindow::executeMediaURLDialog(rWindow.GetFrameWeld(), aURL, & bLink)) |
69 | 0 | { |
70 | 0 | Size aPrefSize; |
71 | |
|
72 | 0 | if (!bSizeUnknown) |
73 | 0 | aPrefSize = pSizeItem->GetSize(); |
74 | 0 | else |
75 | 0 | { |
76 | 0 | rWindow.EnterWait(); |
77 | |
|
78 | 0 | css::uno::Reference<css::frame::XDispatchProvider> xDispatchProvider(GetView().GetViewFrame().GetFrame().GetFrameInterface(), css::uno::UNO_QUERY); |
79 | |
|
80 | 0 | rtl::Reference<avmedia::PlayerListener> xPlayerListener(new avmedia::PlayerListener( |
81 | 0 | [xDispatchProvider=std::move(xDispatchProvider), aURL, bLink](const css::uno::Reference<css::media::XPlayer>& rPlayer){ |
82 | 0 | css::awt::Size aSize = rPlayer->getPreferredPlayerWindowSize(); |
83 | 0 | avmedia::MediaWindow::dispatchInsertAVMedia(xDispatchProvider, aSize, aURL, bLink); |
84 | 0 | })); |
85 | |
|
86 | 0 | const bool bIsMediaURL = ::avmedia::MediaWindow::isMediaURL(aURL, u""_ustr, true, xPlayerListener); |
87 | |
|
88 | 0 | rWindow.LeaveWait(); |
89 | |
|
90 | 0 | if (!bIsMediaURL) |
91 | 0 | { |
92 | 0 | if( !bAPI ) |
93 | 0 | ::avmedia::MediaWindow::executeFormatErrorBox(rWindow.GetFrameWeld()); |
94 | |
|
95 | 0 | return bRet; |
96 | 0 | } |
97 | | |
98 | 0 | return true; |
99 | 0 | } |
100 | | |
101 | 0 | rWindow.EnterWait(); |
102 | |
|
103 | 0 | SwWrtShell& rSh = GetShell(); |
104 | |
|
105 | 0 | if( !rSh.HasDrawView() ) |
106 | 0 | rSh.MakeDrawView(); |
107 | |
|
108 | 0 | Size aDocSz( rSh.GetDocSize() ); |
109 | 0 | const SwRect& rVisArea = rSh.VisArea(); |
110 | 0 | Point aPos( rVisArea.Center() ); |
111 | 0 | Size aSize; |
112 | |
|
113 | 0 | if( rVisArea.Width() > aDocSz.Width()) |
114 | 0 | aPos.setX( aDocSz.Width() / 2 + rVisArea.Left() ); |
115 | |
|
116 | 0 | if(rVisArea.Height() > aDocSz.Height()) |
117 | 0 | aPos.setY( aDocSz.Height() / 2 + rVisArea.Top() ); |
118 | |
|
119 | 0 | if( aPrefSize.Width() && aPrefSize.Height() ) |
120 | 0 | aSize = rWindow.PixelToLogic(aPrefSize, MapMode(MapUnit::MapTwip)); |
121 | 0 | else |
122 | 0 | aSize = Size( 2835, 2835 ); |
123 | |
|
124 | 0 | OUString realURL; |
125 | 0 | if (bLink) |
126 | 0 | { |
127 | 0 | realURL = aURL; |
128 | 0 | } |
129 | 0 | else |
130 | 0 | { |
131 | 0 | if (SwDocShell* pShell = rSh.GetDoc()->GetDocShell()) |
132 | 0 | { |
133 | 0 | uno::Reference<frame::XModel> const xModel( |
134 | 0 | pShell->GetModel()); |
135 | 0 | bRet = ::avmedia::EmbedMedia(xModel, aURL, realURL); |
136 | 0 | if (!bRet) { return bRet; } |
137 | 0 | } |
138 | 0 | } |
139 | | |
140 | 0 | rtl::Reference<SdrMediaObj> pObj = new SdrMediaObj( |
141 | 0 | *rSh.GetDoc()->getIDocumentDrawModelAccess().GetDrawModel(), |
142 | 0 | tools::Rectangle(aPos, aSize)); |
143 | |
|
144 | 0 | pObj->setURL( realURL, u""_ustr ); |
145 | 0 | rSh.EnterStdMode(); |
146 | 0 | rSh.SwFEShell::InsertDrawObj( *pObj, aPos ); |
147 | 0 | bRet = true; |
148 | |
|
149 | 0 | rWindow.LeaveWait(); |
150 | 0 | } |
151 | 0 | #endif |
152 | | |
153 | 0 | return bRet; |
154 | 0 | } |
155 | | |
156 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |