Commit f6dd44e5 authored by Cheng Sun's avatar Cheng Sun Committed by Jean-Baptiste Kempf

VlcPluginGtk: Add functionality to show/hide toolbar

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 32b6c34f
......@@ -283,8 +283,11 @@ public:
virtual bool destroy_windows() = 0;
virtual void toggle_fullscreen() = 0;
virtual void set_fullscreen(bool) = 0;
virtual bool get_fullscreen() = 0;
virtual void set_fullscreen(int) = 0;
virtual int get_fullscreen() = 0;
virtual void set_toolbar_visible(bool) = 0;
virtual bool get_toolbar_visible() = 0;
virtual void update_controls() = 0;
virtual void popup_menu() = 0;
......
......@@ -38,7 +38,8 @@ VlcPluginGtk::VlcPluginGtk(NPP instance, NPuint16_t mode) :
video_container(NULL),
toolbar(NULL),
fullscreen_win(NULL),
is_fullscreen(false)
is_fullscreen(false),
is_toolbar_visible(false)
{
memset(&video_xwindow, 0, sizeof(Window));
}
......@@ -65,7 +66,7 @@ void VlcPluginGtk::toggle_fullscreen()
set_fullscreen(!get_fullscreen());
}
void VlcPluginGtk::set_fullscreen(int yes)
void VlcPluginGtk::do_set_fullscreen(bool yes)
{
/* we have to reparent windows */
/* note that the xid of video_container changes after reparenting */
......@@ -76,12 +77,18 @@ void VlcPluginGtk::set_fullscreen(int yes)
XReparentWindow(display, video_xwindow,
gdk_x11_get_default_root_xwindow(), 0,0);
if (yes) {
gtk_widget_reparent(GTK_WIDGET(parent_vbox), GTK_WIDGET(fullscreen_win));
gtk_widget_show(fullscreen_win);
g_object_ref(G_OBJECT(parent_vbox));
gtk_container_remove(GTK_CONTAINER(parent), parent_vbox);
gtk_container_add(GTK_CONTAINER(fullscreen_win), parent_vbox);
g_object_unref(G_OBJECT(parent_vbox));
gtk_widget_show_all(fullscreen_win);
gtk_window_fullscreen(GTK_WINDOW(fullscreen_win));
} else {
gtk_widget_hide(fullscreen_win);
gtk_widget_reparent(GTK_WIDGET(parent_vbox), GTK_WIDGET(parent));
g_object_ref(G_OBJECT(parent_vbox));
gtk_container_remove(GTK_CONTAINER(fullscreen_win), parent_vbox);
gtk_container_add(GTK_CONTAINER(parent), parent_vbox);
g_object_unref(G_OBJECT(parent_vbox));
gtk_widget_show_all(GTK_WIDGET(parent));
}
XReparentWindow(display, video_xwindow, get_xid(video_container), 0,0);
......@@ -94,21 +101,44 @@ void VlcPluginGtk::set_fullscreen(int yes)
is_fullscreen = yes;
}
void VlcPluginGtk::set_fullscreen(int yes)
{
if (yes == is_fullscreen) return;
if (yes) {
gtk_widget_show(fullscreen_win);
} else {
gtk_widget_hide(fullscreen_win);
}
}
int VlcPluginGtk::get_fullscreen()
{
return is_fullscreen;
}
void VlcPluginGtk::show_toolbar()
void VlcPluginGtk::set_toolbar_visible(bool yes)
{
if (yes == is_toolbar_visible) return;
if (yes) {
gtk_box_pack_start(GTK_BOX(parent_vbox), toolbar, false, false, 0);
gtk_widget_show_all(toolbar);
}
update_controls();
g_object_unref(G_OBJECT(toolbar));
void VlcPluginGtk::hide_toolbar()
{
gtk_container_resize_children(GTK_CONTAINER(parent));
gtk_container_resize_children(GTK_CONTAINER(parent_vbox));
} else {
g_object_ref(G_OBJECT(toolbar));
gtk_widget_hide(toolbar);
gtk_container_remove(GTK_CONTAINER(parent_vbox), toolbar);
}
is_toolbar_visible = yes;
}
bool VlcPluginGtk::get_toolbar_visible()
{
return is_toolbar_visible;
}
void VlcPluginGtk::resize_video_xwindow(GdkRectangle *rect)
......@@ -149,6 +179,10 @@ static void menu_handler(GtkMenuItem *menuitem, gpointer user_data)
{
VlcPluginGtk *plugin = (VlcPluginGtk *) user_data;
const gchar *stock_id = gtk_menu_item_get_label(GTK_MENU_ITEM(menuitem));
if (!strcmp(stock_id, VLCPLUGINGTK_MENU_TOOLBAR)) {
plugin->set_toolbar_visible(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem)));
return;
}
for (int i = 0; i < sizeof(tool_actions)/sizeof(tool_actions_t); ++i) {
if (!strcmp(stock_id, tool_actions[i].stock_id)) {
plugin->control_handler(tool_actions[i].clicked);
......@@ -181,7 +215,12 @@ void VlcPluginGtk::popup_menu()
GTK_STOCK_FULLSCREEN, NULL);
g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(menu_handler), this);
gtk_menu_shell_append(GTK_MENU_SHELL(popupmenu), menuitem);
/* toolbar */
menuitem = gtk_check_menu_item_new_with_label(
VLCPLUGINGTK_MENU_TOOLBAR);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), get_toolbar_visible());
g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(menu_handler), this);
gtk_menu_shell_append(GTK_MENU_SHELL(popupmenu), menuitem);
/* show menu */
gtk_widget_show_all(popupmenu);
......@@ -232,11 +271,12 @@ static bool vol_slider_handler(GtkRange *range, GtkScrollType scroll, gdouble va
static void fullscreen_win_visibility_handler(GtkWidget *widget, gpointer user_data)
{
VlcPluginGtk *plugin = (VlcPluginGtk *) user_data;
plugin->set_fullscreen(gtk_widget_get_visible(widget));
plugin->do_set_fullscreen(gtk_widget_get_visible(widget));
}
void VlcPluginGtk::update_controls()
{
if (get_toolbar_visible()) {
GtkToolItem *toolbutton;
/* play/pause button */
......@@ -263,6 +303,7 @@ void VlcPluginGtk::update_controls()
}
gtk_widget_show_all(toolbar);
}
}
bool VlcPluginGtk::create_windows()
......@@ -290,6 +331,7 @@ bool VlcPluginGtk::create_windows()
/* fullscreen top-level */
fullscreen_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_modify_bg(video_container, GTK_STATE_NORMAL, &color_black);
gtk_window_set_decorated(GTK_WINDOW(fullscreen_win), false);
g_signal_connect(G_OBJECT(fullscreen_win), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), this);
g_signal_connect(G_OBJECT(fullscreen_win), "show", G_CALLBACK(fullscreen_win_visibility_handler), this);
......@@ -315,6 +357,7 @@ bool VlcPluginGtk::create_windows()
/*** TOOLBAR ***/
toolbar = gtk_toolbar_new();
g_object_ref(G_OBJECT(toolbar));
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);
GtkToolItem *toolitem;
/* play/pause */
......@@ -346,9 +389,6 @@ bool VlcPluginGtk::create_windows()
gtk_tool_item_set_expand(toolitem, false);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1);
update_controls();
show_toolbar();
return true;
}
......
......@@ -29,24 +29,25 @@
#include <gtk/gtk.h>
#include <X11/Xlib.h>
#define VLCPLUGINGTK_MENU_TOOLBAR "Show toolbar"
class VlcPluginGtk : public VlcPluginBase
{
public:
VlcPluginGtk(NPP, NPuint16_t);
virtual ~VlcPluginGtk();
int setSize(unsigned width, unsigned height);
void toggle_fullscreen();
void set_fullscreen( int );
int get_fullscreen();
bool create_windows();
bool resize_windows();
bool destroy_windows();
void show_toolbar();
void hide_toolbar();
void toggle_fullscreen();
void set_fullscreen(int);
int get_fullscreen();
void do_set_fullscreen(bool);
void set_toolbar_visible(bool);
bool get_toolbar_visible();
void update_controls();
void popup_menu();
......@@ -62,7 +63,7 @@ private:
gulong video_container_size_handler_id;
Window video_xwindow;
bool is_fullscreen;
bool is_fullscreen, is_toolbar_visible;
};
#endif /* __VLCPLUGIN_GTK_H__ */
......@@ -47,10 +47,10 @@ public:
bool resize_windows();
bool destroy_windows();
void show_toolbar() {/* STUB */};
void hide_toolbar() {/* STUB */};
void update_controls() {/* STUB */};
void popup_menu() {/* STUB */};
void set_toolbar_visible(bool) { /* STUB */ }
bool get_toolbar_visible() { return false; }
void update_controls() {/* STUB */}
void popup_menu() {/* STUB */}
private:
void set_player_window();
......
......@@ -81,14 +81,15 @@ int VlcPluginWin::get_fullscreen()
return _WindowsManager.IsFullScreen();
}
void VlcPluginWin::show_toolbar()
void VlcPluginWin::set_toolbar_visible(bool)
{
/* TODO */
}
void VlcPluginWin::hide_toolbar()
bool VlcPluginWin::get_toolbar_visible()
{
/* TODO */
return false;
}
void VlcPluginWin::update_controls()
......
......@@ -52,6 +52,9 @@ public:
void show_toolbar();
void hide_toolbar();
void set_toolbar_visible(bool);
bool get_toolbar_visible();
void update_controls();
void popup_menu(){};
......
......@@ -47,10 +47,10 @@ public:
bool resize_windows();
bool destroy_windows();
void show_toolbar() {/* STUB */};
void hide_toolbar() {/* STUB */};
void update_controls() {/* STUB */};
void popup_menu() {/* STUB */};
void set_toolbar_visible(bool) { /* STUB */ }
bool get_toolbar_visible() { return false; }
void update_controls() {/* STUB */}
void popup_menu() {/* STUB */}
Display *getDisplay();
private:
......
......@@ -370,7 +370,7 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
/* now display toolbar if asked through parameters */
if( p_plugin->b_toolbar )
{
p_plugin->show_toolbar();
p_plugin->set_toolbar_visible(true);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment