1 /*****************************************************************************
2 * video.cpp : wxWidgets plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004, 2003 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include "interface.hpp"
34 static void *GetWindow( intf_thread_t *p_intf, vout_thread_t *,
35 int *pi_x_hint, int *pi_y_hint,
36 unsigned int *pi_width_hint,
37 unsigned int *pi_height_hint );
39 static void ReleaseWindow( intf_thread_t *p_intf, void *p_window );
41 static int ControlWindow( intf_thread_t *p_intf, void *p_window,
42 int i_query, va_list args );
44 /* IDs for the controls and the menu commands */
47 UpdateSize_Event = wxID_HIGHEST + 1,
53 DEFINE_LOCAL_EVENT_TYPE( wxEVT_VLC_VIDEO );
55 BEGIN_EVENT_TABLE(VideoWindow, wxWindow)
56 EVT_CUSTOM( wxEVT_SIZE, UpdateSize_Event, VideoWindow::UpdateSize )
57 EVT_CUSTOM( wxEVT_SIZE, UpdateHide_Event, VideoWindow::UpdateHide )
58 EVT_COMMAND( SetStayOnTop_Event, wxEVT_VLC_VIDEO,
59 VideoWindow::OnControlEvent )
60 EVT_TIMER( ID_HIDE_TIMER, VideoWindow::OnHideTimer )
63 /*****************************************************************************
65 *****************************************************************************/
66 wxWindow *CreateVideoWindow( intf_thread_t *p_intf, wxWindow *p_parent )
68 return new VideoWindow( p_intf, p_parent );
71 void UpdateVideoWindow( intf_thread_t *p_intf, wxWindow *p_window )
73 #if (wxCHECK_VERSION(2,5,0))
74 if( p_window && mdate() - ((VideoWindow *)p_window)->i_creation_date < 2000000 )
75 return; /* Hack to prevent saving coordinates if window is not yet
76 * properly created. Yuck :( */
78 if( p_window && p_intf->p_sys->p_video_sizer && p_window->IsShown() )
79 p_intf->p_sys->p_video_sizer->SetMinSize( p_window->GetSize() );
83 /*****************************************************************************
85 *****************************************************************************/
86 VideoWindow::VideoWindow( intf_thread_t *_p_intf, wxWindow *_p_parent ):
87 wxWindow( _p_parent, -1 )
93 vlc_mutex_init( p_intf, &lock );
95 b_auto_size = config_GetInt( p_intf, "wx-autosize" );
99 m_hide_timer.SetOwner( this, ID_HIDE_TIMER );
101 p_intf->pf_request_window = ::GetWindow;
102 p_intf->pf_release_window = ::ReleaseWindow;
103 p_intf->pf_control_window = ::ControlWindow;
105 p_intf->p_sys->p_video_window = this;
107 wxSize child_size = wxSize(0,0);
110 WindowSettings *ws = p_intf->p_sys->p_window_settings;
111 wxPoint p; bool b_shown;
113 // Maybe this size should be an option
114 child_size = wxSize( wxSystemSettings::GetMetric(wxSYS_SCREEN_X) / 2,
115 wxSystemSettings::GetMetric(wxSYS_SCREEN_Y) / 2 );
117 ws->GetSettings( WindowSettings::ID_VIDEO, b_shown, p, child_size );
118 SetSize( child_size );
121 p_child_window = new wxWindow( this, -1, wxDefaultPosition, child_size );
125 SetBackgroundColour( *wxBLACK );
126 p_child_window->SetBackgroundColour( *wxBLACK );
129 p_child_window->Show();
133 p_intf->p_sys->p_video_sizer = new wxBoxSizer( wxHORIZONTAL );
134 #if (wxCHECK_VERSION(2,5,3))
135 p_intf->p_sys->p_video_sizer->Add( this, 1, wxEXPAND|wxFIXED_MINSIZE );
137 p_intf->p_sys->p_video_sizer->Add( this, 1, wxEXPAND );
140 ReleaseWindow( NULL );
143 VideoWindow::~VideoWindow()
145 vlc_mutex_lock( &lock );
148 if( !p_intf->psz_switch_intf )
150 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
151 vout_Control( p_vout, VOUT_REPARENT );
155 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
156 vout_Control( p_vout, VOUT_CLOSE );
160 p_intf->pf_request_window = NULL;
161 p_intf->pf_release_window = NULL;
162 p_intf->pf_control_window = NULL;
163 vlc_mutex_unlock( &lock );
167 WindowSettings *ws = p_intf->p_sys->p_window_settings;
168 ws->SetSettings( WindowSettings::ID_VIDEO, true,
169 GetPosition(), GetSize() );
172 vlc_mutex_destroy( &lock );
175 /*****************************************************************************
177 *****************************************************************************/
178 static void *GetWindow( intf_thread_t *p_intf, vout_thread_t *p_vout,
179 int *pi_x_hint, int *pi_y_hint,
180 unsigned int *pi_width_hint,
181 unsigned int *pi_height_hint )
183 return p_intf->p_sys->p_video_window->GetWindow( p_vout,
184 pi_x_hint, pi_y_hint,
189 /* Part of the hack to get the X11 window handle from the GtkWidget */
193 int gdk_x11_drawable_get_xid( void * );
195 void *gtk_widget_get_parent_window( void * );
199 void *VideoWindow::GetWindow( vout_thread_t *_p_vout,
200 int *pi_x_hint, int *pi_y_hint,
201 unsigned int *pi_width_hint,
202 unsigned int *pi_height_hint )
204 #if defined(__WXGTK__) || defined(WIN32)
205 vlc_mutex_lock( &lock );
209 vlc_mutex_unlock( &lock );
210 msg_Dbg( p_intf, "Video window already in use" );
216 wxSizeEvent event( wxSize(*pi_width_hint, *pi_height_hint),
218 AddPendingEvent( event );
219 vlc_mutex_unlock( &lock );
222 GtkWidget *p_widget = p_child_window->GetHandle();
225 return (void *)gdk_x11_drawable_get_xid(
226 gtk_widget_get_parent_window( p_widget ) );
227 #elif defined(__WXGTK__)
228 return (void *)*(int *)( (char *)gtk_widget_get_parent_window( p_widget )
229 + 2 * sizeof(void *) );
233 return (void*)GetHandle();
237 #else // defined(__WXGTK__) || defined(WIN32)
243 static void ReleaseWindow( intf_thread_t *p_intf, void *p_window )
245 return p_intf->p_sys->p_video_window->ReleaseWindow( p_window );
248 void VideoWindow::ReleaseWindow( void *p_window )
250 vlc_mutex_lock( &lock );
252 vlc_mutex_unlock( &lock );
254 if( !b_auto_size ) return;
256 #if defined(__WXGTK__) || defined(WIN32)
257 wxSizeEvent event( wxSize(0, 0), UpdateHide_Event );
258 AddPendingEvent( event );
262 void VideoWindow::UpdateSize( wxEvent &_event )
266 if( !b_auto_size ) return;
268 wxSizeEvent * event = (wxSizeEvent*)(&_event);
271 p_intf->p_sys->p_video_sizer->Show( this, TRUE );
272 p_intf->p_sys->p_video_sizer->Layout();
276 p_intf->p_sys->p_video_sizer->SetMinSize( event->GetSize() );
278 i_creation_date = mdate();
279 wxCommandEvent intf_event( wxEVT_INTF, 0 );
280 p_parent->AddPendingEvent( intf_event );
283 void VideoWindow::UpdateHide( wxEvent &_event )
285 if( b_auto_size ) m_hide_timer.Start( 200, wxTIMER_ONE_SHOT );
288 void VideoWindow::OnHideTimer( wxTimerEvent& WXUNUSED(event))
292 p_intf->p_sys->p_video_sizer->Show( this, FALSE );
294 p_intf->p_sys->p_video_sizer->Layout();
297 p_intf->p_sys->p_video_sizer->SetMinSize( wxSize(0,0) );
299 wxCommandEvent intf_event( wxEVT_INTF, 0 );
300 p_parent->AddPendingEvent( intf_event );
303 void VideoWindow::OnControlEvent( wxCommandEvent &event )
305 switch( event.GetId() )
307 case SetStayOnTop_Event:
308 wxCommandEvent intf_event( wxEVT_INTF, 1 );
309 intf_event.SetInt( event.GetInt() );
310 p_parent->AddPendingEvent( intf_event );
315 static int ControlWindow( intf_thread_t *p_intf, void *p_window,
316 int i_query, va_list args )
318 return p_intf->p_sys->p_video_window->ControlWindow( p_window, i_query,
322 int VideoWindow::ControlWindow( void *p_window, int i_query, va_list args )
324 int i_ret = VLC_EGENERIC;
326 vlc_mutex_lock( &lock );
332 if( !b_auto_size ) break;
334 /* Update dimensions */
335 wxSizeEvent event( wxSize( p_vout->i_window_width,
336 p_vout->i_window_height ),
340 AddPendingEvent( event );
346 case VOUT_SET_STAY_ON_TOP:
348 int i_arg = va_arg( args, int );
349 wxCommandEvent event( wxEVT_VLC_VIDEO, SetStayOnTop_Event );
350 event.SetInt( i_arg );
351 AddPendingEvent( event );
358 msg_Dbg( p_intf, "control query not supported" );
362 vlc_mutex_unlock( &lock );