diff --git a/mozilla/modules/plugin/samples/simple/npsimple.cpp b/mozilla/modules/plugin/samples/simple/npsimple.cpp index 6a94dd0a671..8e746aaa05d 100644 --- a/mozilla/modules/plugin/samples/simple/npsimple.cpp +++ b/mozilla/modules/plugin/samples/simple/npsimple.cpp @@ -60,9 +60,6 @@ * UNIX includes *----------------------------------------------------------------------------*/ #ifdef XP_UNIX -//#include -//#include -//#include #include #include #include @@ -70,6 +67,12 @@ #include #endif /* XP_UNIX */ +#ifdef XP_UNIX + +gboolean draw (GtkWidget *widget, GdkEventExpose *event, gpointer data); + +#endif + /******************************************************************************* * SECTION 2 - Instance Structs @@ -105,6 +108,7 @@ typedef struct _PlatformInstance Window window; GtkWidget *moz_box; GdkSuperWin *superwin; + GtkWidget *label; Display * display; uint32 x, y; uint32 width, height; @@ -311,6 +315,10 @@ public: void SetMode(nsPluginMode mode) { fMode = mode; } +#ifdef XP_UNIX + NS_IMETHOD Repaint(void); +#endif + #if defined(XP_PC) && !defined(XP_OS2) static LRESULT CALLBACK PluginWindowProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); @@ -713,6 +721,13 @@ SimplePluginInstance::SimplePluginInstance(void) static const char text[] = "Hello World!"; fText = (char*) nsMemory::Clone(text, sizeof(text)); + +#ifdef XP_UNIX + fPlatform.moz_box = nsnull; + fPlatform.superwin = nsnull; + fPlatform.label = nsnull; +#endif + } SimplePluginInstance::~SimplePluginInstance(void) @@ -918,6 +933,11 @@ NS_IMETHODIMP SimplePluginInstance::SetText(const char * aText) } #endif +#ifdef XP_UNIX + // force a redraw + Repaint(); +#endif + } return NS_OK; @@ -1161,18 +1181,33 @@ SimplePluginInstance::PlatformSetWindow(nsPluginWindow* window) #ifdef NS_DEBUG printf("SimplePluginInstance::PlatformSetWindow\n"); #endif + if (window == NULL || window->window == NULL) return NS_ERROR_NULL_POINTER; - + if ( fPlatform.superwin == (GdkSuperWin *)window->window ) + return NS_OK; + fPlatform.superwin = (GdkSuperWin *)window->window; + + // a little cleanup + if (fPlatform.label) + gtk_widget_destroy(fPlatform.label); + if (fPlatform.moz_box) + gtk_widget_destroy(fPlatform.moz_box); + + // create a containing mozbox and a label to put in it fPlatform.moz_box = gtk_mozbox_new(fPlatform.superwin->bin_window); + fPlatform.label = gtk_label_new(fText); + gtk_container_add(GTK_CONTAINER(fPlatform.moz_box), fPlatform.label); - GtkWidget *button; + // grow the label to fit the entire mozbox + gtk_widget_set_usize(fPlatform.label, window->width, window->height); - button = gtk_button_new_with_label("Hello World"); - gtk_container_add(GTK_CONTAINER(fPlatform.moz_box), button); + // connect to expose events + gtk_signal_connect (GTK_OBJECT(fPlatform.label), "expose_event", + GTK_SIGNAL_FUNC(draw), this); - gtk_widget_show(button); + gtk_widget_show(fPlatform.label); gtk_widget_show(fPlatform.moz_box); return NS_OK; @@ -1191,6 +1226,34 @@ SimplePluginInstance::PlatformHandleEvent(nsPluginEvent* event) return 0; } +NS_IMETHODIMP +SimplePluginInstance::Repaint(void) +{ +#ifdef DEBUG + printf("SimplePluginInstance::Repaint()\n"); +#endif + + if ( !fPlatform.moz_box || !fPlatform.label ) + return NS_ERROR_FAILURE; + + // Set the label text + gtk_label_set_text(GTK_LABEL(fPlatform.label), fText); + + // show the new label + gtk_widget_show(fPlatform.label); + gtk_widget_show(fPlatform.moz_box); + + return NS_OK; +} + +gboolean draw (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + SimplePluginInstance * pthis = (SimplePluginInstance *)data; + + pthis->Repaint(); + return TRUE; +} + /*------------------------------------------------------------------------------ * Windows Implementations *----------------------------------------------------------------------------*/ diff --git a/mozilla/modules/plugin/test/npsimple.cpp b/mozilla/modules/plugin/test/npsimple.cpp index 6a94dd0a671..8e746aaa05d 100644 --- a/mozilla/modules/plugin/test/npsimple.cpp +++ b/mozilla/modules/plugin/test/npsimple.cpp @@ -60,9 +60,6 @@ * UNIX includes *----------------------------------------------------------------------------*/ #ifdef XP_UNIX -//#include -//#include -//#include #include #include #include @@ -70,6 +67,12 @@ #include #endif /* XP_UNIX */ +#ifdef XP_UNIX + +gboolean draw (GtkWidget *widget, GdkEventExpose *event, gpointer data); + +#endif + /******************************************************************************* * SECTION 2 - Instance Structs @@ -105,6 +108,7 @@ typedef struct _PlatformInstance Window window; GtkWidget *moz_box; GdkSuperWin *superwin; + GtkWidget *label; Display * display; uint32 x, y; uint32 width, height; @@ -311,6 +315,10 @@ public: void SetMode(nsPluginMode mode) { fMode = mode; } +#ifdef XP_UNIX + NS_IMETHOD Repaint(void); +#endif + #if defined(XP_PC) && !defined(XP_OS2) static LRESULT CALLBACK PluginWindowProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); @@ -713,6 +721,13 @@ SimplePluginInstance::SimplePluginInstance(void) static const char text[] = "Hello World!"; fText = (char*) nsMemory::Clone(text, sizeof(text)); + +#ifdef XP_UNIX + fPlatform.moz_box = nsnull; + fPlatform.superwin = nsnull; + fPlatform.label = nsnull; +#endif + } SimplePluginInstance::~SimplePluginInstance(void) @@ -918,6 +933,11 @@ NS_IMETHODIMP SimplePluginInstance::SetText(const char * aText) } #endif +#ifdef XP_UNIX + // force a redraw + Repaint(); +#endif + } return NS_OK; @@ -1161,18 +1181,33 @@ SimplePluginInstance::PlatformSetWindow(nsPluginWindow* window) #ifdef NS_DEBUG printf("SimplePluginInstance::PlatformSetWindow\n"); #endif + if (window == NULL || window->window == NULL) return NS_ERROR_NULL_POINTER; - + if ( fPlatform.superwin == (GdkSuperWin *)window->window ) + return NS_OK; + fPlatform.superwin = (GdkSuperWin *)window->window; + + // a little cleanup + if (fPlatform.label) + gtk_widget_destroy(fPlatform.label); + if (fPlatform.moz_box) + gtk_widget_destroy(fPlatform.moz_box); + + // create a containing mozbox and a label to put in it fPlatform.moz_box = gtk_mozbox_new(fPlatform.superwin->bin_window); + fPlatform.label = gtk_label_new(fText); + gtk_container_add(GTK_CONTAINER(fPlatform.moz_box), fPlatform.label); - GtkWidget *button; + // grow the label to fit the entire mozbox + gtk_widget_set_usize(fPlatform.label, window->width, window->height); - button = gtk_button_new_with_label("Hello World"); - gtk_container_add(GTK_CONTAINER(fPlatform.moz_box), button); + // connect to expose events + gtk_signal_connect (GTK_OBJECT(fPlatform.label), "expose_event", + GTK_SIGNAL_FUNC(draw), this); - gtk_widget_show(button); + gtk_widget_show(fPlatform.label); gtk_widget_show(fPlatform.moz_box); return NS_OK; @@ -1191,6 +1226,34 @@ SimplePluginInstance::PlatformHandleEvent(nsPluginEvent* event) return 0; } +NS_IMETHODIMP +SimplePluginInstance::Repaint(void) +{ +#ifdef DEBUG + printf("SimplePluginInstance::Repaint()\n"); +#endif + + if ( !fPlatform.moz_box || !fPlatform.label ) + return NS_ERROR_FAILURE; + + // Set the label text + gtk_label_set_text(GTK_LABEL(fPlatform.label), fText); + + // show the new label + gtk_widget_show(fPlatform.label); + gtk_widget_show(fPlatform.moz_box); + + return NS_OK; +} + +gboolean draw (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + SimplePluginInstance * pthis = (SimplePluginInstance *)data; + + pthis->Repaint(); + return TRUE; +} + /*------------------------------------------------------------------------------ * Windows Implementations *----------------------------------------------------------------------------*/