Re: how to draw gtk widget(like buttons) in the firefox npapi plugin under linux?

"spark.bao" <[email protected]> Mon, 18 Nov 2013 06:46:11 -0800 (PST)
Newsgroups gmane.comp.mozilla.devel.plugins
Message-ID <[email protected]>
I almost despair after several days research, but today I finally successfully resovle it. I now can draw a gtk button in the plugin.

The keypoint is that you must write following codes in the NPP_GetValue() funciton:
        case NPPVpluginNeedsXEmbed:
            *((bool *)value) = true;
            return NPERR_NO_ERROR;
Notice: these codes can't be wrote in NP_GetValue() function, it's no useful.
This is the mistake that I did before.

This is the only document I can find in the internet:
https://developer.mozilla.org/zh-CN/docs/XEmbed_Extension_for_Mozilla_Plugins

And a simple sample about XEmbed:
http://multimedia.cx/diamondx/

在 2013年11月16日星期六UTC+8下午4时12分27秒,spark.bao写道:
> some supplement:
> 
> 
> 
> webp-npapi demo is a windowless plugin and don't has buttons while npapi-vlc demo is a window plugin defalut and has some buttons.
> 
> 
> 
> 在 2013年11月16日星期六UTC+8上午10时14分59秒,spark.bao写道:
> 
> > Hello everybody,
> 
> > 
> 
> > 
> 
> > 
> 
> > I has known how to write a simple npapi plugin. But now I am in troubles to draw some buttons in the plugin.
> 
> > 
> 
> > 
> 
> > 
> 
> > I download a simple sample named webp-npapi (http://code.google.com/p/webp-npapi-linux/) and modify it, it now can work well in my firefox.
> 
> > 
> 
> > 
> 
> > 
> 
> > I also download a complex sample named npapi-vlc (http://git.videolan.org/?p=npapi-vlc.git;a=summary) and has read it.
> 
> > 
> 
> > 
> 
> > 
> 
> > I want to draw some buttons in my own plugin, so I imitate the codes of npapi-vlc to modify webp-npapi. I change the type of webp-npapi from windowless to window by comment the following codes in constructor of CPlugin class:
> 
> > 
> 
> > (http://code.google.com/p/webp-npapi-linux/source/browse/trunk/CPlugin.cpp)
> 
> > 
> 
> > 
> 
> > 
> 
> > /*
> 
> > 
> 
> > 	// Make sure we can render this plugin
> 
> > 
> 
> > 	NPBool browserSupportsWindowless = false;
> 
> > 
> 
> > 	s_pBrowserFunctions->getvalue(instance, NPNVSupportsWindowless, &browserSupportsWindowless);
> 
> > 
> 
> > 	if( !browserSupportsWindowless )
> 
> > 
> 
> > 		throw std::runtime_error("Windowless mode not supported by the browser");
> 
> > 
> 
> > 	s_pBrowserFunctions->setvalue(instance, NPPVpluginWindowBool, (void*) false);
> 
> > 
> 
> > */
> 
> > 
> 
> > 
> 
> > 
> 
> > then I start draw a button in CPlugin::setWindow() function:
> 
> > 
> 
> > 
> 
> > 
> 
> > NPError CPlugin::setWindow(const NPWindow * const window)
> 
> > 
> 
> > {
> 
> > 
> 
> > 	#ifdef WEBPNPAPI_DEBUG
> 
> > 
> 
> > 	printf("CPlugin::setWindow() - Window set\n");
> 
> > 
> 
> > 	#endif
> 
> > 
> 
> > 	
> 
> > 
> 
> > 	m_window = *window;
> 
> > 
> 
> > 
> 
> > 
> 
> >         //I add these codes to draw a button
> 
> > 
> 
> > 	printf("test start\n");
> 
> > 
> 
> > 	GdkColor color_bg;
> 
> > 
> 
> > 	gdk_color_parse("#AAAAAA", &color_bg);
> 
> > 
> 
> > 
> 
> > 
> 
> > 	Window socket = (Window)m_window.window;
> 
> > 
> 
> > 	GtkWidget *parent = gtk_plug_new(socket);
> 
> > 
> 
> > 	gtk_widget_modify_bg(parent, GTK_STATE_NORMAL, &color_bg);
> 
> > 
> 
> > 	GtkWidget *button = gtk_button_new_with_label("hello");
> 
> > 
> 
> > 	gtk_container_add(GTK_CONTAINER(parent), button);
> 
> > 
> 
> > 	gtk_widget_show_all(parent);
> 
> > 
> 
> > 	printf("test end\n");
> 
> > 
> 
> > 
> 
> > 
> 
> > 	GtkRequisition req;
> 
> > 
> 
> > 	req.width = m_window.width;
> 
> > 
> 
> > 	req.height = m_window.height;
> 
> > 
> 
> > 	gtk_widget_size_request(parent, &req);
> 
> > 
> 
> > 
> 
> > 
> 
> > 	return NPERR_NO_ERROR;
> 
> > 
> 
> > }
> 
> > 
> 
> > 
> 
> > 
> 
> > But, It doesn't show anything in the webpage...
> 
> > 
> 
> > 
> 
> > 
> 
> > So I really want to know what is the most important things you must notice when you want to draw some gtk widget in your plugin?
> 
> > 
> 
> > 
> 
> > 
> 
> > thx!



在 2013年11月16日星期六UTC+8下午4时12分27秒,spark.bao写道:
> some supplement:
> 
> 
> 
> webp-npapi demo is a windowless plugin and don't has buttons while npapi-vlc demo is a window plugin defalut and has some buttons.
> 
> 
> 
> 在 2013年11月16日星期六UTC+8上午10时14分59秒,spark.bao写道:
> 
> > Hello everybody,
> 
> > 
> 
> > 
> 
> > 
> 
> > I has known how to write a simple npapi plugin. But now I am in troubles to draw some buttons in the plugin.
> 
> > 
> 
> > 
> 
> > 
> 
> > I download a simple sample named webp-npapi (http://code.google.com/p/webp-npapi-linux/) and modify it, it now can work well in my firefox.
> 
> > 
> 
> > 
> 
> > 
> 
> > I also download a complex sample named npapi-vlc (http://git.videolan.org/?p=npapi-vlc.git;a=summary) and has read it.
> 
> > 
> 
> > 
> 
> > 
> 
> > I want to draw some buttons in my own plugin, so I imitate the codes of npapi-vlc to modify webp-npapi. I change the type of webp-npapi from windowless to window by comment the following codes in constructor of CPlugin class:
> 
> > 
> 
> > (http://code.google.com/p/webp-npapi-linux/source/browse/trunk/CPlugin.cpp)
> 
> > 
> 
> > 
> 
> > 
> 
> > /*
> 
> > 
> 
> > 	// Make sure we can render this plugin
> 
> > 
> 
> > 	NPBool browserSupportsWindowless = false;
> 
> > 
> 
> > 	s_pBrowserFunctions->getvalue(instance, NPNVSupportsWindowless, &browserSupportsWindowless);
> 
> > 
> 
> > 	if( !browserSupportsWindowless )
> 
> > 
> 
> > 		throw std::runtime_error("Windowless mode not supported by the browser");
> 
> > 
> 
> > 	s_pBrowserFunctions->setvalue(instance, NPPVpluginWindowBool, (void*) false);
> 
> > 
> 
> > */
> 
> > 
> 
> > 
> 
> > 
> 
> > then I start draw a button in CPlugin::setWindow() function:
> 
> > 
> 
> > 
> 
> > 
> 
> > NPError CPlugin::setWindow(const NPWindow * const window)
> 
> > 
> 
> > {
> 
> > 
> 
> > 	#ifdef WEBPNPAPI_DEBUG
> 
> > 
> 
> > 	printf("CPlugin::setWindow() - Window set\n");
> 
> > 
> 
> > 	#endif
> 
> > 
> 
> > 	
> 
> > 
> 
> > 	m_window = *window;
> 
> > 
> 
> > 
> 
> > 
> 
> >         //I add these codes to draw a button
> 
> > 
> 
> > 	printf("test start\n");
> 
> > 
> 
> > 	GdkColor color_bg;
> 
> > 
> 
> > 	gdk_color_parse("#AAAAAA", &color_bg);
> 
> > 
> 
> > 
> 
> > 
> 
> > 	Window socket = (Window)m_window.window;
> 
> > 
> 
> > 	GtkWidget *parent = gtk_plug_new(socket);
> 
> > 
> 
> > 	gtk_widget_modify_bg(parent, GTK_STATE_NORMAL, &color_bg);
> 
> > 
> 
> > 	GtkWidget *button = gtk_button_new_with_label("hello");
> 
> > 
> 
> > 	gtk_container_add(GTK_CONTAINER(parent), button);
> 
> > 
> 
> > 	gtk_widget_show_all(parent);
> 
> > 
> 
> > 	printf("test end\n");
> 
> > 
> 
> > 
> 
> > 
> 
> > 	GtkRequisition req;
> 
> > 
> 
> > 	req.width = m_window.width;
> 
> > 
> 
> > 	req.height = m_window.height;
> 
> > 
> 
> > 	gtk_widget_size_request(parent, &req);
> 
> > 
> 
> > 
> 
> > 
> 
> > 	return NPERR_NO_ERROR;
> 
> > 
> 
> > }
> 
> > 
> 
> > 
> 
> > 
> 
> > But, It doesn't show anything in the webpage...
> 
> > 
> 
> > 
> 
> > 
> 
> > So I really want to know what is the most important things you must notice when you want to draw some gtk widget in your plugin?
> 
> > 
> 
> > 
> 
> > 
> 
> > thx!



在 2013年11月16日星期六UTC+8下午4时12分27秒,spark.bao写道:
> some supplement:
> 
> 
> 
> webp-npapi demo is a windowless plugin and don't has buttons while npapi-vlc demo is a window plugin defalut and has some buttons.
> 
> 
> 
> 在 2013年11月16日星期六UTC+8上午10时14分59秒,spark.bao写道:
> 
> > Hello everybody,
> 
> > 
> 
> > 
> 
> > 
> 
> > I has known how to write a simple npapi plugin. But now I am in troubles to draw some buttons in the plugin.
> 
> > 
> 
> > 
> 
> > 
> 
> > I download a simple sample named webp-npapi (http://code.google.com/p/webp-npapi-linux/) and modify it, it now can work well in my firefox.
> 
> > 
> 
> > 
> 
> > 
> 
> > I also download a complex sample named npapi-vlc (http://git.videolan.org/?p=npapi-vlc.git;a=summary) and has read it.
> 
> > 
> 
> > 
> 
> > 
> 
> > I want to draw some buttons in my own plugin, so I imitate the codes of npapi-vlc to modify webp-npapi. I change the type of webp-npapi from windowless to window by comment the following codes in constructor of CPlugin class:
> 
> > 
> 
> > (http://code.google.com/p/webp-npapi-linux/source/browse/trunk/CPlugin.cpp)
> 
> > 
> 
> > 
> 
> > 
> 
> > /*
> 
> > 
> 
> > 	// Make sure we can render this plugin
> 
> > 
> 
> > 	NPBool browserSupportsWindowless = false;
> 
> > 
> 
> > 	s_pBrowserFunctions->getvalue(instance, NPNVSupportsWindowless, &browserSupportsWindowless);
> 
> > 
> 
> > 	if( !browserSupportsWindowless )
> 
> > 
> 
> > 		throw std::runtime_error("Windowless mode not supported by the browser");
> 
> > 
> 
> > 	s_pBrowserFunctions->setvalue(instance, NPPVpluginWindowBool, (void*) false);
> 
> > 
> 
> > */
> 
> > 
> 
> > 
> 
> > 
> 
> > then I start draw a button in CPlugin::setWindow() function:
> 
> > 
> 
> > 
> 
> > 
> 
> > NPError CPlugin::setWindow(const NPWindow * const window)
> 
> > 
> 
> > {
> 
> > 
> 
> > 	#ifdef WEBPNPAPI_DEBUG
> 
> > 
> 
> > 	printf("CPlugin::setWindow() - Window set\n");
> 
> > 
> 
> > 	#endif
> 
> > 
> 
> > 	
> 
> > 
> 
> > 	m_window = *window;
> 
> > 
> 
> > 
> 
> > 
> 
> >         //I add these codes to draw a button
> 
> > 
> 
> > 	printf("test start\n");
> 
> > 
> 
> > 	GdkColor color_bg;
> 
> > 
> 
> > 	gdk_color_parse("#AAAAAA", &color_bg);
> 
> > 
> 
> > 
> 
> > 
> 
> > 	Window socket = (Window)m_window.window;
> 
> > 
> 
> > 	GtkWidget *parent = gtk_plug_new(socket);
> 
> > 
> 
> > 	gtk_widget_modify_bg(parent, GTK_STATE_NORMAL, &color_bg);
> 
> > 
> 
> > 	GtkWidget *button = gtk_button_new_with_label("hello");
> 
> > 
> 
> > 	gtk_container_add(GTK_CONTAINER(parent), button);
> 
> > 
> 
> > 	gtk_widget_show_all(parent);
> 
> > 
> 
> > 	printf("test end\n");
> 
> > 
> 
> > 
> 
> > 
> 
> > 	GtkRequisition req;
> 
> > 
> 
> > 	req.width = m_window.width;
> 
> > 
> 
> > 	req.height = m_window.height;
> 
> > 
> 
> > 	gtk_widget_size_request(parent, &req);
> 
> > 
> 
> > 
> 
> > 
> 
> > 	return NPERR_NO_ERROR;
> 
> > 
> 
> > }
> 
> > 
> 
> > 
> 
> > 
> 
> > But, It doesn't show anything in the webpage...
> 
> > 
> 
> > 
> 
> > 
> 
> > So I really want to know what is the most important things you must notice when you want to draw some gtk widget in your plugin?
> 
> > 
> 
> > 
> 
> > 
> 
> > thx!
_______________________________________________
dev-tech-plugins mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-plugins