/src/libreoffice/svx/source/sdr/contact/viewobjectcontactofsdrmediaobj.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 | | |
22 | | #include <sdr/contact/viewobjectcontactofsdrmediaobj.hxx> |
23 | | #include <sdr/contact/viewcontactofsdrmediaobj.hxx> |
24 | | #include <svx/sdr/contact/objectcontact.hxx> |
25 | | #include <vcl/outdev.hxx> |
26 | | #include <vcl/window.hxx> |
27 | | #include <avmedia/mediaitem.hxx> |
28 | | #include "sdrmediawindow.hxx" |
29 | | |
30 | | namespace sdr::contact { |
31 | | |
32 | | ViewObjectContactOfSdrMediaObj::ViewObjectContactOfSdrMediaObj( ObjectContact& rObjectContact, |
33 | | ViewContact& rViewContact, |
34 | | const ::avmedia::MediaItem& rMediaItem ) : |
35 | 0 | ViewObjectContactOfSdrObj( rObjectContact, rViewContact ) |
36 | 0 | { |
37 | 0 | #if HAVE_FEATURE_AVMEDIA |
38 | 0 | vcl::Window* pWindow = getWindow(); |
39 | |
|
40 | 0 | if( pWindow ) |
41 | 0 | { |
42 | 0 | mpMediaWindow.reset( new SdrMediaWindow( pWindow, *this ) ); |
43 | 0 | mpMediaWindow->hide(); |
44 | 0 | executeMediaItem( rMediaItem ); |
45 | 0 | } |
46 | | #else |
47 | | (void) rMediaItem; |
48 | | #endif |
49 | 0 | } |
50 | | |
51 | | ViewObjectContactOfSdrMediaObj::~ViewObjectContactOfSdrMediaObj() |
52 | 0 | { |
53 | 0 | } |
54 | | |
55 | | |
56 | | vcl::Window* ViewObjectContactOfSdrMediaObj::getWindow() const |
57 | 0 | { |
58 | 0 | vcl::Window* pRetval = nullptr; |
59 | |
|
60 | 0 | const OutputDevice* oPageOutputDev = getPageViewOutputDevice(); |
61 | 0 | if( oPageOutputDev ) |
62 | 0 | { |
63 | 0 | if(OUTDEV_WINDOW == oPageOutputDev->GetOutDevType()) |
64 | 0 | { |
65 | 0 | pRetval = oPageOutputDev->GetOwnerWindow(); |
66 | 0 | } |
67 | 0 | } |
68 | |
|
69 | 0 | return pRetval; |
70 | 0 | } |
71 | | |
72 | | |
73 | | Size ViewObjectContactOfSdrMediaObj::getPreferredSize() const |
74 | 0 | { |
75 | 0 | Size aRet; |
76 | |
|
77 | 0 | #if HAVE_FEATURE_AVMEDIA |
78 | 0 | if( mpMediaWindow ) |
79 | 0 | aRet = mpMediaWindow->getPreferredSize(); |
80 | | #else |
81 | | aRet = Size(0,0); |
82 | | #endif |
83 | |
|
84 | 0 | return aRet; |
85 | 0 | } |
86 | | |
87 | | void ViewObjectContactOfSdrMediaObj::ActionChanged() |
88 | 0 | { |
89 | 0 | ViewObjectContactOfSdrObj::ActionChanged(); |
90 | 0 | updateMediaWindow(false); |
91 | 0 | } |
92 | | |
93 | | void ViewObjectContactOfSdrMediaObj::updateMediaWindow(bool bShow) const |
94 | 0 | { |
95 | 0 | #if HAVE_FEATURE_AVMEDIA |
96 | 0 | if (!mpMediaWindow || (!bShow && !mpMediaWindow->isVisible())) |
97 | 0 | return; |
98 | | |
99 | 0 | basegfx::B2DRange aViewRange(getObjectRange()); |
100 | 0 | aViewRange.transform(GetObjectContact().getViewInformation2D().getViewTransformation()); |
101 | |
|
102 | 0 | const tools::Rectangle aViewRectangle( |
103 | 0 | static_cast<sal_Int32>(floor(aViewRange.getMinX())), static_cast<sal_Int32>(floor(aViewRange.getMinY())), |
104 | 0 | static_cast<sal_Int32>(ceil(aViewRange.getMaxX())), static_cast<sal_Int32>(ceil(aViewRange.getMaxY()))); |
105 | | |
106 | | // mpMediaWindow contains a SalObject window and gtk won't accept |
107 | | // the size until after the SalObject widget is shown but if we |
108 | | // show it before setting a size then vcl will detect that the |
109 | | // vcl::Window has no size and make it invisible instead. If we |
110 | | // call setPosSize twice with the same size before and after show |
111 | | // then the second attempt is a no-op as vcl caches the size. |
112 | | |
113 | | // so call it initially with a size arbitrarily 1 pixel wider than |
114 | | // we want so we have an initial size to make vcl happy |
115 | 0 | tools::Rectangle aInitialRect(aViewRectangle); |
116 | 0 | aInitialRect.AdjustRight(1); |
117 | 0 | mpMediaWindow->setPosSize(aInitialRect); |
118 | | |
119 | | // then make it visible |
120 | 0 | mpMediaWindow->show(); |
121 | | |
122 | | // set the final desired size which is different to let vcl send it |
123 | | // through to gtk which will now accept it as the underlying |
124 | | // m_pSocket of GtkSalObject::SetPosSize is now visible |
125 | 0 | mpMediaWindow->setPosSize(aViewRectangle); |
126 | | #else |
127 | | (void) bShow; |
128 | | #endif |
129 | 0 | } |
130 | | |
131 | | void ViewObjectContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem& rItem ) const |
132 | 0 | { |
133 | 0 | #if HAVE_FEATURE_AVMEDIA |
134 | 0 | if( !mpMediaWindow ) |
135 | 0 | return; |
136 | | |
137 | 0 | mpMediaWindow->updateMediaItem( rItem ); |
138 | | |
139 | | // show/hide is now dependent of play state |
140 | 0 | if(avmedia::MediaState::Stop == rItem.getState()) |
141 | 0 | { |
142 | 0 | mpMediaWindow->hide(); |
143 | 0 | } |
144 | 0 | else |
145 | 0 | { |
146 | 0 | updateMediaWindow(true); |
147 | 0 | } |
148 | | #else |
149 | | (void) rItem; |
150 | | #endif |
151 | 0 | } |
152 | | |
153 | | |
154 | | void ViewObjectContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem& rItem ) |
155 | 0 | { |
156 | 0 | #if HAVE_FEATURE_AVMEDIA |
157 | 0 | if( mpMediaWindow ) |
158 | 0 | { |
159 | 0 | ::avmedia::MediaItem aUpdatedItem; |
160 | |
|
161 | 0 | mpMediaWindow->executeMediaItem( rItem ); |
162 | | |
163 | | // query new properties after trying to set the new properties |
164 | 0 | updateMediaItem( aUpdatedItem ); |
165 | 0 | static_cast< ViewContactOfSdrMediaObj& >( GetViewContact() ).mediaPropertiesChanged( aUpdatedItem ); |
166 | 0 | } |
167 | | #else |
168 | | (void) rItem; |
169 | | #endif |
170 | 0 | } |
171 | | |
172 | | |
173 | | } // end of namespace sdr::contact |
174 | | |
175 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |