CVSROOT: /sources/gnash Module name: gnash Changes by: Benjamin Wolsey <bwy> 08/02/14 13:27:56
Modified files: . : ChangeLog server/asobj : xml.cpp xml.h gui : gtk.cpp gtksup.h Log message: * gui/gtk{sup.h,.cpp}: set up key event callbacks on the toplevel window after drawing area has been reparented. The new setupWindowEvents() function splits off those functions to save resetting other callbacks unnecessarily. Makes key events work in the fullscreen plugin. * server/asobj/xml.{cpp,h}: fix small leak of xmlChar when the node is empty. Replace reinterpret_cast<>s with nice, safe, null-terminated stringstreams. Comment out some questionable headers. The reinterpret casts to const char* look relatively safe as they are mostly immediately used to construct a std::string. The ignoreWhite implementation did work on the pointer itself, though, and out of pure avoid reinterpret_cast-if-possible dogma I've replaced the others too. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5647&r2=1.5648 http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xml.cpp?cvsroot=gnash&r1=1.69&r2=1.70 http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xml.h?cvsroot=gnash&r1=1.25&r2=1.26 http://cvs.savannah.gnu.org/viewcvs/gnash/gui/gtk.cpp?cvsroot=gnash&r1=1.144&r2=1.145 http://cvs.savannah.gnu.org/viewcvs/gnash/gui/gtksup.h?cvsroot=gnash&r1=1.64&r2=1.65 Patches: Index: ChangeLog =================================================================== RCS file: /sources/gnash/gnash/ChangeLog,v retrieving revision 1.5647 retrieving revision 1.5648 diff -u -b -r1.5647 -r1.5648 --- ChangeLog 14 Feb 2008 12:07:34 -0000 1.5647 +++ ChangeLog 14 Feb 2008 13:27:55 -0000 1.5648 @@ -1,3 +1,14 @@ +2008-02-14 Benjamin Wolsey <[EMAIL PROTECTED]> + + * gui/gtk{sup.h,.cpp}: set up key event callbacks on the toplevel + window after drawing area has been reparented. The new + setupWindowEvents() function splits off those functions to save + resetting other callbacks unnecessarily. Makes key events + work in the fullscreen plugin. + * server/asobj/xml.{cpp,h}: fix small leak of xmlChar when the node + is empty. Replace reinterpret_cast<>s with nice, safe, null-terminated + stringstreams. Comment out some questionable headers. + 2008-02-14 Sandro Santilli <[EMAIL PROTECTED]> * server/sprite_instance.cpp (on_event): reword the onLoad handling so Index: server/asobj/xml.cpp =================================================================== RCS file: /sources/gnash/gnash/server/asobj/xml.cpp,v retrieving revision 1.69 retrieving revision 1.70 diff -u -b -r1.69 -r1.70 --- server/asobj/xml.cpp 8 Feb 2008 11:58:56 -0000 1.69 +++ server/asobj/xml.cpp 14 Feb 2008 13:27:56 -0000 1.70 @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // -/* $Id: xml.cpp,v 1.69 2008/02/08 11:58:56 strk Exp $ */ +/* $Id: xml.cpp,v 1.70 2008/02/14 13:27:56 bwy Exp $ */ #ifdef HAVE_CONFIG_H #include "gnashconfig.h" @@ -46,13 +46,12 @@ #include <libxml/parser.h> #include <libxml/tree.h> #include <libxml/xmlreader.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> +//#include <unistd.h> +//#include <sys/types.h> +//#include <sys/stat.h> #include <string> #include <sstream> #include <vector> -//#include <boost/lexical_cast.hpp> #include <boost/algorithm/string/case_conv.hpp> #include <memory> @@ -245,8 +244,13 @@ { //log_msg(_("extractNode %s has property %s, value is %s"), // node->name, attr->name, attr->children->content); - XMLAttr attrib(reinterpret_cast<const char*>(attr->name), - reinterpret_cast<const char*>(attr->children->content)); + + std::ostringstream name, content; + + name << attr->name; + content << attr->children->content; + + XMLAttr attrib(name.str(), content.str()); //log_msg(_("\tPushing attribute %s for element %s has value %s"), // attr->name, node->name, attr->children->content); @@ -264,8 +268,9 @@ { element.nodeTypeSet(tElement); - std::string name(reinterpret_cast<const char*>(node->name)); - element.nodeNameSet(name); + std::ostringstream name; + name << node->name; + element.nodeNameSet(name.str()); } else if ( node->type == XML_TEXT_NODE ) { @@ -275,19 +280,20 @@ if (ptr == NULL) return false; if (node->content) { - const char* in = reinterpret_cast<const char*>(ptr); + std::ostringstream in; + in << ptr; // XML_PARSE_NOBLANKS seems not to be working, so here's // a custom implementation of it. if ( ignoreWhite() ) { - if ( strspn(in, " \n\t\r") == strlen(in) ) + if ( in.str().find_first_not_of(" \n\t\r") == std::string::npos ) { log_msg("Text node value consists in blanks only, discarding"); + xmlFree(ptr); return false; } } - std::string val(in); - element.nodeValueSet(val); + element.nodeValueSet(in.str()); } xmlFree(ptr); } Index: server/asobj/xml.h =================================================================== RCS file: /sources/gnash/gnash/server/asobj/xml.h,v retrieving revision 1.25 retrieving revision 1.26 diff -u -b -r1.25 -r1.26 --- server/asobj/xml.h 21 Jan 2008 20:55:59 -0000 1.25 +++ server/asobj/xml.h 14 Feb 2008 13:27:56 -0000 1.26 @@ -24,7 +24,7 @@ #include "tu_config.h" -#include "event_id.h" +//#include "event_id.h" #include "action.h" #include "LoadThread.h" #include "xmlattrs.h" Index: gui/gtk.cpp =================================================================== RCS file: /sources/gnash/gnash/gui/gtk.cpp,v retrieving revision 1.144 retrieving revision 1.145 diff -u -b -r1.144 -r1.145 --- gui/gtk.cpp 10 Feb 2008 18:42:28 -0000 1.144 +++ gui/gtk.cpp 14 Feb 2008 13:27:56 -0000 1.145 @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // -/* $Id: gtk.cpp,v 1.144 2008/02/10 18:42:28 bwy Exp $ */ +/* $Id: gtk.cpp,v 1.145 2008/02/14 13:27:56 bwy Exp $ */ #ifdef HAVE_CONFIG_H #include "gnashconfig.h" @@ -118,15 +118,15 @@ } // XXXbjacques: why do we need this? - gtk_container_set_reallocate_redraws(GTK_CONTAINER (_window), TRUE); + //gtk_container_set_reallocate_redraws(GTK_CONTAINER (_window), TRUE); addGnashIcon(GTK_WINDOW(_window)); - _drawing_area = gtk_drawing_area_new(); + _drawingArea = gtk_drawing_area_new(); // IF we don't set this flag we won't be able to grab focus // ( grabFocus() would be a no-op ) - GTK_WIDGET_SET_FLAGS (GTK_WIDGET(_drawing_area), GTK_CAN_FOCUS); + GTK_WIDGET_SET_FLAGS (GTK_WIDGET(_drawingArea), GTK_CAN_FOCUS); createMenu(); @@ -134,14 +134,12 @@ // OpenGL _glue needs to prepare the drawing area for OpenGL rendering before // widgets are realized and before the configure event is fired. // TODO: find a way to make '_glue' use independent from actual renderer in use - _glue->prepDrawingArea(_drawing_area); + gtk_container_set_reallocate_redraws(GTK_CONTAINER (_window), TRUE); #endif - setupEvents(); - // Plugin if (_xid) { - gtk_container_add(GTK_CONTAINER(_window), _drawing_area); + gtk_container_add(GTK_CONTAINER(_window), _drawingArea); } // Stand-alone @@ -156,17 +154,19 @@ createMenuBar(); #endif - gtk_box_pack_start(GTK_BOX(_vbox), _drawing_area, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(_vbox), _drawingArea, TRUE, TRUE, 0); } + setupEvents(); + gtk_widget_realize(_window); - gtk_widget_show(_drawing_area); + gtk_widget_show(_drawingArea); gtk_widget_show(_window); #if defined(RENDERER_CAIRO) || defined(RENDERER_AGG) - // cairo needs the _drawing_area.window to prepare it .. + // cairo needs the _drawingArea.window to prepare it .. // TODO: find a way to make '_glue' use independent from actual renderer in use - _glue->prepDrawingArea(_drawing_area); + _glue->prepDrawingArea(_drawingArea); #endif #ifdef USE_LIRC @@ -258,7 +258,11 @@ // Reparent drawing area from GtkPlug to fullscreen window gtk_widget_realize(_overlay); - gtk_widget_reparent(_drawing_area, _overlay); + gtk_widget_reparent(_drawingArea, _overlay); + + // Apply key event callbacks to the new window. + setupWindowEvents(); + gtk_widget_show(_overlay); } @@ -272,7 +276,7 @@ // It could be a good hack if it were done earlier. // There really doesn't seem to be a proper way of setting the starting size // of a widget but allowing it to be shrunk. - gtk_widget_set_size_request(_drawing_area, -1, -1); + gtk_widget_set_size_request(_drawingArea, -1, -1); gtk_window_fullscreen(GTK_WINDOW(_window)); if (_menubar) { @@ -290,7 +294,10 @@ // Plugin if (_xid) { - gtk_widget_reparent (_drawing_area, _window); + gtk_widget_reparent (_drawingArea, _window); + + // Apply key event callbacks to the plugin instance. + setupWindowEvents(); if (_overlay) { gtk_widget_destroy(_overlay); log_msg (_("Destroyed fullscreen window")); @@ -332,8 +339,8 @@ gdkcursor = gdk_cursor_new(cursortype); } - // The parent of _drawing_area is different for the plugin in fullscreen - gdk_window_set_cursor (gtk_widget_get_parent_window(_drawing_area), + // The parent of _drawingArea is different for the plugin in fullscreen + gdk_window_set_cursor (gtk_widget_get_parent_window(_drawingArea), gdkcursor); if (gdkcursor) { @@ -341,42 +348,50 @@ } } +// private +void +GtkGui::setupWindowEvents() +{ + g_signal_connect(G_OBJECT(gtk_widget_get_toplevel(_drawingArea)), "delete_event", + G_CALLBACK(delete_event), this); + g_signal_connect(G_OBJECT(gtk_widget_get_toplevel(_drawingArea)), "key_press_event", + G_CALLBACK(key_press_event), this); + g_signal_connect(G_OBJECT(gtk_widget_get_toplevel(_drawingArea)), "key_release_event", + G_CALLBACK(key_release_event), this); +} + +// public virtual bool GtkGui::setupEvents() { //GNASH_REPORT_FUNCTION; - g_signal_connect(G_OBJECT(_window), "delete_event", - G_CALLBACK(delete_event), this); - g_signal_connect(G_OBJECT(_window), "key_press_event", - G_CALLBACK(key_press_event), this); - g_signal_connect(G_OBJECT(_window), "key_release_event", - G_CALLBACK(key_release_event), this); + setupWindowEvents(); - gtk_widget_add_events(_drawing_area, GDK_EXPOSURE_MASK + gtk_widget_add_events(_drawingArea, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_POINTER_MOTION_MASK); - g_signal_connect_swapped(G_OBJECT(_drawing_area), + g_signal_connect_swapped(G_OBJECT(_drawingArea), "button_press_event", G_CALLBACK(popup_handler), GTK_OBJECT(_popup_menu)); - g_signal_connect(G_OBJECT(_drawing_area), "button_press_event", + g_signal_connect(G_OBJECT(_drawingArea), "button_press_event", G_CALLBACK(button_press_event), this); - g_signal_connect(G_OBJECT(_drawing_area), "button_release_event", + g_signal_connect(G_OBJECT(_drawingArea), "button_release_event", G_CALLBACK(button_release_event), this); - g_signal_connect(G_OBJECT(_drawing_area), "motion_notify_event", + g_signal_connect(G_OBJECT(_drawingArea), "motion_notify_event", G_CALLBACK(motion_notify_event), this); - g_signal_connect_after(G_OBJECT (_drawing_area), "realize", + g_signal_connect_after(G_OBJECT (_drawingArea), "realize", G_CALLBACK (realize_event), NULL); - g_signal_connect(G_OBJECT (_drawing_area), "configure_event", + g_signal_connect(G_OBJECT (_drawingArea), "configure_event", G_CALLBACK (configure_event), this); - g_signal_connect(G_OBJECT (_drawing_area), "expose_event", + g_signal_connect(G_OBJECT (_drawingArea), "expose_event", G_CALLBACK (expose_event), this); return true; @@ -385,7 +400,7 @@ void GtkGui::grabFocus() { - gtk_widget_grab_focus(GTK_WIDGET(_drawing_area)); + gtk_widget_grab_focus(GTK_WIDGET(_drawingArea)); } void @@ -500,7 +515,7 @@ // Advantage: The window is sized correctly, no matter what other // widgets are visible // Disadvantage: The window cannot be shrinked, which is bad. - gtk_widget_set_size_request(_drawing_area, width, height); + gtk_widget_set_size_request(_drawingArea, width, height); } return ret; @@ -1369,7 +1384,17 @@ // "translator-credits", "translator-credits", "logo", logo_pixbuf, "license", - "This program is free software; you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation; either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software\nFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA", + "This program is free software; you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation; either version 3 of the License, or\n" + "(at your option) any later version.\n\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n" + "You should have received a copy of the GNU General Public License\n" + "along with this program; if not, write to the Free Software\n" + "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA", "website", "http://www.gnu.org/software/gnash/", NULL); } Index: gui/gtksup.h =================================================================== RCS file: /sources/gnash/gnash/gui/gtksup.h,v retrieving revision 1.64 retrieving revision 1.65 diff -u -b -r1.64 -r1.65 --- gui/gtksup.h 31 Jan 2008 11:08:56 -0000 1.64 +++ gui/gtksup.h 14 Feb 2008 13:27:56 -0000 1.65 @@ -58,6 +58,12 @@ void quit(); virtual bool createMenu(); + + /// Set up callbacks for key, mouse and other GTK events. + // + /// Must be called after the drawing area has been added to + /// a top level window, as it calls setupWindowEvents() to + /// add key event callbacks to the top level window. virtual bool setupEvents(); virtual void beforeRendering(); virtual void renderBuffer(); @@ -182,7 +188,7 @@ // A window only for rendering the plugin as fullscreen. GtkWidget *_overlay; - GtkWidget *_drawing_area; + GtkWidget *_drawingArea; GtkMenu *_popup_menu; GtkWidget *_menubar; GtkWidget *_vbox; @@ -192,6 +198,13 @@ // Adds the gnash icon to a window. void addGnashIcon(GtkWindow* window); + /// Add key press events to the toplevel window. + // + /// The plugin fullscreen creates a new top level + /// window, so this function must be called every time + /// the drawing area is reparented. + void setupWindowEvents(); + GdkPixbuf* createPixbuf(const gchar *filename); // Create a tree model for displaying movie info (not yet properly _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit