/src/libreoffice/svx/source/sdr/contact/viewcontactofsdrmediaobj.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 | | |
21 | | #include <sdr/contact/viewcontactofsdrmediaobj.hxx> |
22 | | #include <svx/svdomedia.hxx> |
23 | | #include <sdr/contact/viewobjectcontactofsdrmediaobj.hxx> |
24 | | #include <drawinglayer/primitive2d/mediaprimitive2d.hxx> |
25 | | #include <vcl/canvastools.hxx> |
26 | | |
27 | | namespace sdr::contact { |
28 | | |
29 | | ViewContactOfSdrMediaObj::ViewContactOfSdrMediaObj( SdrMediaObj& rMediaObj ) : |
30 | 0 | ViewContactOfSdrObj( rMediaObj ) |
31 | 0 | { |
32 | 0 | } |
33 | | |
34 | | ViewContactOfSdrMediaObj::~ViewContactOfSdrMediaObj() |
35 | 0 | { |
36 | 0 | } |
37 | | |
38 | | ViewObjectContact& ViewContactOfSdrMediaObj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact) |
39 | 0 | { |
40 | 0 | return *( new ViewObjectContactOfSdrMediaObj( rObjectContact, *this, static_cast< SdrMediaObj& >( GetSdrObject() ).getMediaProperties() ) ); |
41 | 0 | } |
42 | | |
43 | | Size ViewContactOfSdrMediaObj::getPreferredSize() const |
44 | 0 | { |
45 | | // #i71805# Since we may have a whole bunch of VOCs here, make a loop |
46 | | // return first useful size -> the size from the first which is visualized as a window |
47 | 0 | const sal_uInt32 nCount(getViewObjectContactCount()); |
48 | |
|
49 | 0 | for(sal_uInt32 a(0); a < nCount; a++) |
50 | 0 | { |
51 | 0 | ViewObjectContact* pCandidate = getViewObjectContact(a); |
52 | 0 | Size aSize(pCandidate ? static_cast< ViewObjectContactOfSdrMediaObj* >(pCandidate)->getPreferredSize() : Size()); |
53 | |
|
54 | 0 | if(0 != aSize.getWidth() || 0 != aSize.getHeight()) |
55 | 0 | { |
56 | 0 | return aSize; |
57 | 0 | } |
58 | 0 | } |
59 | | |
60 | 0 | return Size(); |
61 | 0 | } |
62 | | |
63 | | void ViewContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem& rItem ) const |
64 | 0 | { |
65 | | // #i71805# Since we may have a whole bunch of VOCs here, make a loop |
66 | 0 | const sal_uInt32 nCount(getViewObjectContactCount()); |
67 | |
|
68 | 0 | for(sal_uInt32 a(0); a < nCount; a++) |
69 | 0 | { |
70 | 0 | ViewObjectContact* pCandidate = getViewObjectContact(a); |
71 | |
|
72 | 0 | if(pCandidate) |
73 | 0 | { |
74 | 0 | static_cast< ViewObjectContactOfSdrMediaObj* >(pCandidate)->updateMediaItem(rItem); |
75 | 0 | } |
76 | 0 | } |
77 | 0 | } |
78 | | |
79 | | void ViewContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem& rItem ) |
80 | 0 | { |
81 | 0 | const sal_uInt32 nCount(getViewObjectContactCount()); |
82 | |
|
83 | 0 | for(sal_uInt32 a(0); a < nCount; a++) |
84 | 0 | { |
85 | 0 | ViewObjectContact* pCandidate = getViewObjectContact(a); |
86 | |
|
87 | 0 | if(pCandidate) |
88 | 0 | { |
89 | 0 | static_cast< ViewObjectContactOfSdrMediaObj* >(pCandidate)->executeMediaItem(rItem); |
90 | 0 | } |
91 | 0 | } |
92 | 0 | } |
93 | | |
94 | | void ViewContactOfSdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewState ) |
95 | 0 | { |
96 | 0 | static_cast< SdrMediaObj& >(GetSdrObject()).mediaPropertiesChanged(rNewState); |
97 | 0 | } |
98 | | |
99 | | void ViewContactOfSdrMediaObj::createViewIndependentPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const |
100 | 0 | { |
101 | | // create range using the model data directly. This is in SdrTextObj::aRect which i will access using |
102 | | // GetGeoRect() to not trigger any calculations. It's the unrotated geometry which is okay for MediaObjects ATM. |
103 | 0 | const tools::Rectangle aRectangle(GetSdrMediaObj().GetGeoRect()); |
104 | 0 | const basegfx::B2DRange aRange = vcl::unotools::b2DRectangleFromRectangle(aRectangle); |
105 | | |
106 | | // create object transform |
107 | 0 | basegfx::B2DHomMatrix aTransform; |
108 | 0 | aTransform.set(0, 0, aRange.getWidth()); |
109 | 0 | aTransform.set(1, 1, aRange.getHeight()); |
110 | 0 | aTransform.set(0, 2, aRange.getMinX()); |
111 | 0 | aTransform.set(1, 2, aRange.getMinY()); |
112 | | |
113 | | // create media primitive. Always create primitives to allow the |
114 | | // decomposition of MediaPrimitive2D to create needed invisible elements for HitTest |
115 | | // and/or BoundRect |
116 | 0 | const basegfx::BColor aBackgroundColor(67.0 / 255.0, 67.0 / 255.0, 67.0 / 255.0); |
117 | 0 | const OUString& rURL(GetSdrMediaObj().getURL()); |
118 | 0 | const sal_uInt32 nPixelBorder(4); |
119 | 0 | const drawinglayer::primitive2d::Primitive2DReference xRetval( |
120 | 0 | new drawinglayer::primitive2d::MediaPrimitive2D( |
121 | 0 | aTransform, rURL, aBackgroundColor, nPixelBorder, |
122 | 0 | GetSdrMediaObj().getSnapshot())); |
123 | |
|
124 | 0 | rVisitor.visit(xRetval); |
125 | 0 | } |
126 | | |
127 | | } |
128 | | |
129 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |