1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include "sdrmediawindow.hxx"
32 #include <svtools/transfer.hxx>
33 
34 #include <svx/sdr/contact/viewobjectcontactofsdrmediaobj.hxx>
35 #include <vcl/window.hxx>
36 
37 namespace sdr {	namespace contact {
38 
39 // ------------------
40 // - SdrMediaWindow -
41 // ------------------
42 
43 SdrMediaWindow::SdrMediaWindow( Window* pParent, ViewObjectContactOfSdrMediaObj& rViewObjContact ) :
44 	::avmedia::MediaWindow( pParent, false ),
45 	mrViewObjectContactOfSdrMediaObj( rViewObjContact )
46 {
47 }
48 
49 // ------------------------------------------------------------------------------
50 
51 SdrMediaWindow::~SdrMediaWindow()
52 {
53 }
54 
55 // ------------------------------------------------------------------------------
56 
57 void SdrMediaWindow::MouseMove( const MouseEvent& rMEvt )
58 {
59 	Window* pWindow = mrViewObjectContactOfSdrMediaObj.getWindow();
60 
61 	if( pWindow && getWindow() )
62 	{
63 		const MouseEvent aTransformedEvent( pWindow->ScreenToOutputPixel( getWindow()->OutputToScreenPixel( rMEvt.GetPosPixel() ) ),
64 									  		rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() );
65 
66 		pWindow->MouseMove( aTransformedEvent );
67 		setPointer( pWindow->GetPointer() );
68 	}
69 }
70 
71 // ------------------------------------------------------------------------------
72 
73 void SdrMediaWindow::MouseButtonDown( const MouseEvent& rMEvt )
74 {
75 	Window* pWindow = mrViewObjectContactOfSdrMediaObj.getWindow();
76 
77 	if( pWindow && getWindow() )
78 	{
79 		const MouseEvent aTransformedEvent( pWindow->ScreenToOutputPixel( getWindow()->OutputToScreenPixel( rMEvt.GetPosPixel() ) ),
80 									  		rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() );
81 
82 		pWindow->MouseButtonDown( aTransformedEvent );
83 	}
84 }
85 
86 // ------------------------------------------------------------------------------
87 
88 void SdrMediaWindow::MouseButtonUp( const MouseEvent& rMEvt )
89 {
90 	Window* pWindow = mrViewObjectContactOfSdrMediaObj.getWindow();
91 
92 	if( pWindow && getWindow() )
93 	{
94 		const MouseEvent aTransformedEvent( pWindow->ScreenToOutputPixel( getWindow()->OutputToScreenPixel( rMEvt.GetPosPixel() ) ),
95 									  		rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() );
96 
97 		pWindow->MouseButtonUp( aTransformedEvent );
98 	}
99 }
100 
101 // ------------------------------------------------------------------------------
102 
103 void SdrMediaWindow::KeyInput( const KeyEvent& rKEvt )
104 {
105 	Window* pWindow = mrViewObjectContactOfSdrMediaObj.getWindow();
106 
107 	if( pWindow )
108 		pWindow->KeyInput( rKEvt );
109 }
110 
111 // ------------------------------------------------------------------------------
112 
113 void SdrMediaWindow::KeyUp( const KeyEvent& rKEvt )
114 {
115 	Window* pWindow = mrViewObjectContactOfSdrMediaObj.getWindow();
116 
117 	if( pWindow )
118 		pWindow->KeyUp( rKEvt );
119 }
120 
121 // ------------------------------------------------------------------------------
122 
123 void SdrMediaWindow::Command( const CommandEvent& rCEvt )
124 {
125 	Window* pWindow = mrViewObjectContactOfSdrMediaObj.getWindow();
126 
127 	if( pWindow && getWindow() )
128 	{
129 		const CommandEvent aTransformedEvent( pWindow->ScreenToOutputPixel( getWindow()->OutputToScreenPixel( rCEvt.GetMousePosPixel() ) ),
130 									  		  rCEvt.GetCommand(), rCEvt.IsMouseEvent(), rCEvt.GetData() );
131 
132 		pWindow->Command( aTransformedEvent );
133 	}
134 }
135 
136 // ------------------------------------------------------------------------------
137 
138 sal_Int8 SdrMediaWindow::AcceptDrop( const AcceptDropEvent& rEvt )
139 {
140 	Window* 	pWindow = mrViewObjectContactOfSdrMediaObj.getWindow();
141 	sal_Int8	nRet = DND_ACTION_NONE;
142 
143 	if( pWindow )
144 	{
145 		DropTargetHelper* pDropTargetHelper = dynamic_cast< DropTargetHelper* >( pWindow );
146 
147 		if( pDropTargetHelper )
148 		{
149 			nRet = pDropTargetHelper->AcceptDrop( rEvt );
150 		}
151 	}
152 
153 	return( nRet );
154 }
155 
156 // ------------------------------------------------------------------------------
157 
158 sal_Int8 SdrMediaWindow::ExecuteDrop( const ExecuteDropEvent& rEvt )
159 {
160 	Window* 	pWindow = mrViewObjectContactOfSdrMediaObj.getWindow();
161 	sal_Int8	nRet = DND_ACTION_NONE;
162 
163 	if( pWindow )
164 	{
165 		DropTargetHelper* pDropTargetHelper = dynamic_cast< DropTargetHelper* >( pWindow );
166 
167 		if( pDropTargetHelper )
168 		{
169 			nRet = pDropTargetHelper->ExecuteDrop( rEvt );
170 		}
171 	}
172 
173 	return( nRet );
174 }
175 
176 // ------------------------------------------------------------------------------
177 
178 void SdrMediaWindow::StartDrag( sal_Int8 nAction, const Point& rPosPixel )
179 {
180 	Window* pWindow = mrViewObjectContactOfSdrMediaObj.getWindow();
181 
182 	if( pWindow )
183 	{
184 		DragSourceHelper* pDragSourceHelper = dynamic_cast< DragSourceHelper* >( pWindow );
185 
186 		if( pDragSourceHelper )
187 		{
188 			pDragSourceHelper->StartDrag( nAction, rPosPixel );
189 		}
190 	}
191 }
192 
193 } }
194