]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_callbacks.c
-Unification of gnome/gtk intefaces: now all the file are in plugin/gtk.
[vlc] / plugins / gtk / gtk_callbacks.c
1 /*****************************************************************************
2  * gtk_callbacks.c : Callbacks for the Gtk+ plugin.
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: gtk_callbacks.c,v 1.20 2001/05/23 23:08:20 stef Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Stéphane Borel <stef@via.ecp.fr>
9  *      
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program 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 General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include "defs.h"
29 #include <sys/types.h>                                              /* off_t */
30 #include <stdlib.h>
31
32 #include <gtk/gtk.h>
33
34 #include <string.h>
35
36 #include "config.h"
37 #include "common.h"
38 #include "threads.h"
39 #include "mtime.h"
40
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
43
44 #include "interface.h"
45 #include "intf_playlist.h"
46 #include "intf_msg.h"
47
48 #include "video.h"
49 #include "video_output.h"
50
51 #include "gtk_callbacks.h"
52 #include "gtk_interface.h"
53 #include "gtk_support.h"
54 #include "intf_gtk.h"
55
56 #include "main.h"
57
58 /*****************************************************************************
59  * Callbacks
60  *****************************************************************************/
61
62 /*
63  * Main interface callbacks
64  */
65
66 gboolean GtkExit( GtkWidget       *widget,
67                   GdkEventButton  *event,
68                   gpointer         user_data )
69 {
70     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
71
72     vlc_mutex_lock( &p_intf->change_lock );
73     p_intf->b_die = 1;
74     vlc_mutex_unlock( &p_intf->change_lock );
75
76     return TRUE;
77 }
78
79 gboolean GtkWindowDelete( GtkWidget       *widget,
80                           GdkEvent        *event,
81                           gpointer         user_data )
82 {
83     GtkExit( GTK_WIDGET( widget ), NULL, user_data );
84
85     return TRUE;
86 }
87
88
89 gboolean GtkWindowToggle( GtkWidget       *widget,
90                           GdkEventButton  *event,
91                           gpointer         user_data )
92 {
93     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
94     
95     if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_window) )
96     {
97         gtk_widget_hide( p_intf->p_sys->p_window);
98
99     } 
100     else 
101     {
102         gtk_widget_show( p_intf->p_sys->p_window );
103     }
104
105     return TRUE;
106 }
107
108 gboolean GtkFullscreen( GtkWidget       *widget,
109                         GdkEventButton  *event,
110                         gpointer         user_data)
111 {
112     if( p_vout_bank->i_count )
113     {
114         vlc_mutex_lock( &p_vout_bank->pp_vout[0]->change_lock );
115
116         p_vout_bank->pp_vout[0]->i_changes |= VOUT_FULLSCREEN_CHANGE;
117
118         vlc_mutex_unlock( &p_vout_bank->pp_vout[0]->change_lock );
119
120         return TRUE;
121     }
122     else
123     {
124         return FALSE;
125     }
126 }
127
128 void GtkWindowDrag( GtkWidget       *widget,
129                     GdkDragContext  *drag_context,
130                     gint             x,
131                     gint             y,
132                     GtkSelectionData *data,
133                     guint            info,
134                     guint            time,
135                     gpointer         user_data)
136 {
137     intf_thread_t * p_intf =  GetIntf( GTK_WIDGET(widget), "intf_window" );
138     int end = p_main->p_playlist->i_size;
139     GtkDropDataReceived( p_intf, data, info, PLAYLIST_END );
140
141     if( p_intf->p_input != NULL )
142     {
143        /* FIXME: temporary hack */
144        p_intf->p_input->b_eof = 1;
145     }
146      
147     intf_PlaylistJumpto( p_main->p_playlist, end-1 );
148 }
149
150
151 /****************************************************************************
152  * Slider management
153  ****************************************************************************/
154
155 gboolean GtkSliderRelease( GtkWidget       *widget,
156                            GdkEventButton  *event,
157                            gpointer         user_data )
158 {
159     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
160
161     vlc_mutex_lock( &p_intf->change_lock );
162     p_intf->p_sys->b_slider_free = 1;
163     vlc_mutex_unlock( &p_intf->change_lock );
164
165     return FALSE;
166 }
167
168
169 gboolean GtkSliderPress( GtkWidget       *widget,
170                          GdkEventButton  *event,
171                          gpointer         user_data)
172 {
173     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), "intf_window" );
174
175     vlc_mutex_lock( &p_intf->change_lock );
176     p_intf->p_sys->b_slider_free = 0;
177     vlc_mutex_unlock( &p_intf->change_lock );
178
179     return FALSE;
180 }
181
182
183 /****************************************************************************
184  * DVD specific items
185  ****************************************************************************/
186
187 void GtkTitlePrev( GtkButton * button, gpointer user_data )
188 {
189     intf_thread_t * p_intf;
190     input_area_t *  p_area;
191     int             i_id;
192
193     p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
194     i_id = p_intf->p_input->stream.p_selected_area->i_id - 1;
195
196     /* Disallow area 0 since it is used for video_ts.vob */
197     if( i_id > 0 )
198     {
199         p_area = p_intf->p_input->stream.pp_areas[i_id];
200         input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
201
202         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
203
204         p_intf->p_sys->b_title_update = 1;
205         GtkSetupMenus( p_intf );
206     }
207 }
208
209
210 void GtkTitleNext( GtkButton * button, gpointer user_data )
211 {
212     intf_thread_t * p_intf;
213     input_area_t *  p_area;
214     int             i_id;
215
216     p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
217     i_id = p_intf->p_input->stream.p_selected_area->i_id + 1;
218
219     if( i_id < p_intf->p_input->stream.i_area_nb )
220     {
221         p_area = p_intf->p_input->stream.pp_areas[i_id];   
222         input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
223
224         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
225
226         p_intf->p_sys->b_title_update = 1;
227         GtkSetupMenus( p_intf );
228     }
229
230 }
231
232
233 void GtkChapterPrev( GtkButton * button, gpointer user_data )
234 {
235     intf_thread_t * p_intf;
236     input_area_t *  p_area;
237
238     p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
239     p_area = p_intf->p_input->stream.p_selected_area;
240
241     if( p_area->i_part > 0 )
242     {
243         p_area->i_part--;
244         input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
245
246         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
247
248         p_intf->p_sys->b_chapter_update = 1;
249         GtkSetupMenus( p_intf );
250     }
251 }
252
253
254 void GtkChapterNext( GtkButton * button, gpointer user_data )
255 {
256     intf_thread_t * p_intf;
257     input_area_t *  p_area;
258
259     p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
260     p_area = p_intf->p_input->stream.p_selected_area;
261
262     if( p_area->i_part < p_area->i_part_nb )
263     {
264         p_area->i_part++;
265         input_ChangeArea( p_intf->p_input, (input_area_t*)p_area );
266
267         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
268
269         p_intf->p_sys->b_chapter_update = 1;
270         GtkSetupMenus( p_intf );
271     }
272 }
273
274 /****************************************************************************
275  * About box
276  ****************************************************************************/
277
278 gboolean GtkAboutShow( GtkWidget       *widget,
279                        GdkEventButton  *event,
280                        gpointer         user_data)
281 {
282     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
283
284     if( !GTK_IS_WIDGET( p_intf->p_sys->p_about ) )
285     {
286         p_intf->p_sys->p_about = create_intf_about();
287         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_about ),
288                              "p_intf", p_intf );
289     }
290     gtk_widget_show( p_intf->p_sys->p_about );
291     gdk_window_raise( p_intf->p_sys->p_about->window );
292
293     return TRUE;
294 }
295
296 void GtkAboutOk( GtkButton * button, gpointer user_data)
297 {
298     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(button), (char*)user_data );
299
300     gtk_widget_hide( p_intf->p_sys->p_about );
301 }
302
303
304 /****************************************************************************
305  * Jump box
306  ****************************************************************************/
307
308 gboolean GtkJumpShow( GtkWidget       *widget,
309                       GdkEventButton  *event,
310                       gpointer         user_data)
311 {
312     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
313
314     if( !GTK_IS_WIDGET( p_intf->p_sys->p_jump ) )
315     {
316         p_intf->p_sys->p_jump = create_intf_jump();
317         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_jump ),
318                              "p_intf", p_intf );
319     }
320
321     gtk_widget_show( p_intf->p_sys->p_jump );
322     gdk_window_raise( p_intf->p_sys->p_jump->window );
323
324     return FALSE;
325 }
326
327
328 void GtkJumpOk( GtkButton       *button,
329                 gpointer         user_data)
330 {
331     intf_thread_t * p_intf;
332     off_t           i_seek;
333     off_t           i_size;
334     int             i_hours;
335     int             i_minutes;
336     int             i_seconds;
337
338     p_intf = GetIntf( GTK_WIDGET( button ), (char*)user_data );
339
340 #define GET_VALUE( name )                                                   \
341     gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( gtk_object_get_data( \
342         GTK_OBJECT( p_intf->p_sys->p_jump ), name ) ) )
343
344     i_hours   = GET_VALUE( "jump_hour_spinbutton" );
345     i_minutes = GET_VALUE( "jump_minute_spinbutton" );
346     i_seconds = GET_VALUE( "jump_second_spinbutton" );
347
348 #undef GET_VALUE
349
350     i_seconds += 60 *i_minutes + 3600* i_hours;
351
352     vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
353     i_seek = i_seconds * 50 * p_intf->p_input->stream.i_mux_rate;
354     i_size = p_intf->p_input->stream.p_selected_area->i_size;
355     vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
356
357     if( i_seek < i_size )
358     {
359         input_Seek( p_intf->p_input, i_seek );
360     }
361     p_main->p_playlist->b_stopped = 0;
362     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
363 }
364
365
366 void GtkJumpCancel( GtkButton       *button,
367                     gpointer         user_data)
368 {
369     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
370 }
371
372
373 /****************************************************************************
374  * Callbacks for menuitems
375  ****************************************************************************/
376 void GtkExitActivate( GtkMenuItem * menuitem, gpointer user_data )
377 {
378     GtkExit( GTK_WIDGET( menuitem ), NULL, user_data );
379 }
380
381
382 void GtkFullscreenActivate( GtkMenuItem * menuitem, gpointer user_data )
383 {
384     GtkFullscreen( GTK_WIDGET( menuitem ), NULL, user_data );
385 }
386
387
388 void GtkWindowToggleActivate( GtkMenuItem * menuitem, gpointer user_data )
389 {
390     GtkWindowToggle( GTK_WIDGET( menuitem ), NULL, user_data );
391 }
392
393
394 void GtkAboutActivate( GtkMenuItem * menuitem, gpointer user_data )
395 {
396     GtkAboutShow( GTK_WIDGET( menuitem ), NULL, user_data );
397 }
398
399
400 void GtkJumpActivate( GtkMenuItem * menuitem, gpointer user_data )
401 {
402     GtkJumpShow( GTK_WIDGET( menuitem ), NULL, user_data );
403 }