1 /*****************************************************************************
2 * vout_window.cpp
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
5 * $Id: d683e6a974b03e4b5244d7efc2ccaf1881d24f46 $
6 *
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
23
24 #include "vout_window.hpp"
25 #include "vout_manager.hpp"
26 #include "vlcproc.hpp"
27 #include "theme.hpp"
28 #include "os_factory.hpp"
29 #include "os_graphics.hpp"
30 #include "os_window.hpp"
31 #include "../events/evt_key.hpp"
32 #include "../events/evt_motion.hpp"
33 #include "../events/evt_mouse.hpp"
34
35 #include <vlc_actions.h>
36
37
VoutWindow(intf_thread_t * pIntf,vout_window_t * pWnd,int width,int height,GenericWindow * pParent)38 VoutWindow::VoutWindow( intf_thread_t *pIntf, vout_window_t* pWnd,
39 int width, int height, GenericWindow* pParent ) :
40 GenericWindow( pIntf, 0, 0, false, false, pParent,
41 GenericWindow::VoutWindow ),
42 m_pWnd( pWnd ), original_width( width ), original_height( height ),
43 m_pCtrlVideo( NULL ), m_pParentWindow( pParent )
44 {
45 if( m_pWnd )
46 {
47 vlc_object_hold( m_pWnd );
48
49 #ifdef X11_SKINS
50 m_pWnd->handle.xid = getOSHandle();
51 m_pWnd->display.x11 = NULL;
52 #else
53 m_pWnd->handle.hwnd = getOSHandle();
54 #endif
55 }
56 }
57
58
~VoutWindow()59 VoutWindow::~VoutWindow()
60 {
61 if( m_pWnd )
62 {
63 vlc_object_release( m_pWnd );
64 }
65 }
66
67
setCtrlVideo(CtrlVideo * pCtrlVideo)68 void VoutWindow::setCtrlVideo( CtrlVideo* pCtrlVideo )
69 {
70 if( pCtrlVideo )
71 {
72 hide();
73 const Position *pPos = pCtrlVideo->getPosition();
74 int x = pPos->getLeft();
75 int y = pPos->getTop();
76 int w = pPos->getWidth();
77 int h = pPos->getHeight();
78
79 setParent( pCtrlVideo->getWindow(), x, y, w, h );
80 m_pParentWindow = pCtrlVideo->getWindow();
81
82 resize( w, h );
83 show();
84 }
85 else
86 {
87 hide();
88 int w = VoutManager::instance( getIntf() )->getVoutMainWindow()->getWidth();
89 int h = VoutManager::instance( getIntf() )->getVoutMainWindow()->getHeight();
90
91 setParent( VoutManager::instance( getIntf() )->getVoutMainWindow(),
92 0, 0, w, h );
93 m_pParentWindow =
94 VoutManager::instance( getIntf() )->getVoutMainWindow();
95
96 resize( w, h );
97 show();
98 }
99
100 m_pCtrlVideo = pCtrlVideo;
101 }
102
103
resize(int width,int height)104 void VoutWindow::resize( int width, int height )
105 {
106 GenericWindow::resize( width, height );
107
108 if( m_pWnd )
109 vout_window_ReportSize( m_pWnd, width, height );
110 }
111
112
processEvent(EvtKey & rEvtKey)113 void VoutWindow::processEvent( EvtKey &rEvtKey )
114 {
115 // Only do the action when the key is down
116 if( rEvtKey.getKeyState() == EvtKey::kDown )
117 getIntf()->p_sys->p_dialogs->sendKey( rEvtKey.getModKey() );
118 }
119
120
processEvent(EvtMotion & rEvtMotion)121 void VoutWindow::processEvent( EvtMotion &rEvtMotion )
122 {
123 int x = rEvtMotion.getXPos() - m_pParentWindow->getLeft() - getLeft();
124 int y = rEvtMotion.getYPos() - m_pParentWindow->getTop() - getTop();
125 vout_window_ReportMouseMoved( m_pWnd, x, y );
126 }
127
128
processEvent(EvtMouse & rEvtMouse)129 void VoutWindow::processEvent( EvtMouse &rEvtMouse )
130 {
131 int button = -1;
132 if( rEvtMouse.getButton() == EvtMouse::kLeft )
133 button = 0;
134 else if( rEvtMouse.getButton() == EvtMouse::kMiddle )
135 button = 1;
136 else if( rEvtMouse.getButton() == EvtMouse::kRight )
137 button = 2;
138
139 if( rEvtMouse.getAction() == EvtMouse::kDown )
140 vout_window_ReportMousePressed( m_pWnd, button );
141 else if( rEvtMouse.getAction() == EvtMouse::kUp )
142 vout_window_ReportMouseReleased( m_pWnd, button );
143 else if( rEvtMouse.getAction() == EvtMouse::kDblClick )
144 vout_window_ReportMouseDoubleClick( m_pWnd, button );
145 }
146