1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include <tools/gen.hxx>
24 #include <com/sun/star/awt/Size.hpp>
25 #include <com/sun/star/uno/Reference.hxx>
26 #include <com/sun/star/media/XPlayerListener.hpp>
27 #include <cppuhelper/compbase.hxx>
28 #include <cppuhelper/basemutex.hxx>
29 #include <vcl/vclptr.hxx>
30 #include <avmedia/avmediadllapi.h>
32 #define AVMEDIA_FRAMEGRABBER_DEFAULTFRAME -1.0
34 namespace com::sun::star::frame
{ class XDispatchProvider
; }
35 namespace com::sun::star::graphic
{ class XGraphic
; }
36 namespace com::sun::star::media
{
38 class XPlayerNotifier
;
41 namespace vcl
{ class Window
; }
42 namespace weld
{ class Window
; }
46 struct AcceptDropEvent
;
47 struct ExecuteDropEvent
;
48 enum class PointerStyle
;
52 typedef ::std::vector
< ::std::pair
< OUString
, OUString
> > FilterNameVector
;
56 namespace priv
{ class MediaWindowImpl
; }
58 typedef cppu::WeakComponentImplHelper
<css::media::XPlayerListener
> PlayerListener_BASE
;
60 class AVMEDIA_DLLPUBLIC PlayerListener final
: public cppu::BaseMutex
, public PlayerListener_BASE
63 css::uno::Reference
<css::media::XPlayerNotifier
> m_xNotifier
;
64 std::function
<void(const css::uno::Reference
<css::media::XPlayer
>&)> m_aFn
;
66 using WeakComponentImplHelperBase::disposing
;
68 PlayerListener(std::function
<void(const css::uno::Reference
<css::media::XPlayer
>&)> fn
);
69 virtual void SAL_CALL
dispose() override
;
70 virtual ~PlayerListener() override
;
72 virtual void SAL_CALL
preferredPlayerWindowSizeAvailable(const css::lang::EventObject
& rSource
) override
;
73 virtual void SAL_CALL
disposing(const css::lang::EventObject
& rSource
) override
;
75 void startListening(const css::uno::Reference
<css::media::XPlayerNotifier
>& rNotifier
);
78 void callPlayerWindowSizeAvailable(const css::uno::Reference
<css::media::XPlayer
>& rPlayer
) { m_aFn(rPlayer
); }
81 class AVMEDIA_DLLPUBLIC MediaWindow
84 MediaWindow( vcl::Window
* parent
, bool bInternalMediaControl
);
85 virtual ~MediaWindow();
87 void setURL( const OUString
& rURL
, const OUString
& rReferer
);
88 const OUString
& getURL() const;
91 Size
getPreferredSize() const;
93 vcl::Window
* getWindow() const;
95 void setPosSize( const tools::Rectangle
& rNewRect
);
97 void setPointer( PointerStyle aPointer
);
101 void updateMediaItem( MediaItem
& rItem
) const;
102 void executeMediaItem( const MediaItem
& rItem
);
106 bool isVisible() const;
110 virtual void MouseMove( const MouseEvent
& rMEvt
);
111 virtual void MouseButtonDown( const MouseEvent
& rMEvt
);
112 virtual void MouseButtonUp( const MouseEvent
& rMEvt
);
114 virtual void KeyInput( const KeyEvent
& rKEvt
);
115 virtual void KeyUp( const KeyEvent
& rKEvt
);
117 virtual void Command( const CommandEvent
& rCEvt
);
119 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
);
120 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
);
122 virtual void StartDrag( sal_Int8 nAction
, const Point
& rPosPixel
);
126 static FilterNameVector
getMediaFilters();
127 /// @param o_pbLink if not 0, this is an "insert" dialog: display link
128 /// checkbox and store its state in *o_pbLink
129 static bool executeMediaURLDialog(weld::Window
* pParent
, OUString
& rURL
, bool *const o_pbLink
);
130 static void executeFormatErrorBox(weld::Window
* pParent
);
131 static bool isMediaURL(std::u16string_view rURL
, const OUString
& rReferer
, bool bDeep
= false,
132 rtl::Reference
<PlayerListener
> xPreferredPixelSizeListener
= nullptr);
134 static css::uno::Reference
< css::media::XPlayer
> createPlayer( const OUString
& rURL
, const OUString
& rReferer
, const OUString
* pMimeType
= nullptr );
136 static css::uno::Reference
<css::graphic::XGraphic
>
137 grabFrame(const css::uno::Reference
<css::media::XPlayer
>& rPlayer
,
138 const css::uno::Reference
<css::graphic::XGraphic
>& rGraphic
= nullptr);
140 static css::uno::Reference
< css::graphic::XGraphic
> grabFrame(const OUString
& rURL
, const OUString
& rReferer
,
141 const OUString
& sMimeType
, rtl::Reference
<PlayerListener
> xPreferredPixelSizeListener
);
143 static void dispatchInsertAVMedia(const css::uno::Reference
<css::frame::XDispatchProvider
>&,
144 const css::awt::Size
& rSize
, const OUString
& rURL
, bool bLink
);
147 MediaWindow(const MediaWindow
&) = delete;
148 MediaWindow
& operator =( const MediaWindow
& ) = delete;
150 VclPtr
<priv::MediaWindowImpl
> mpImpl
;
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */