diff --git a/gfx/src/gtk/nsDeviceContextGTK.cpp b/gfx/src/gtk/nsDeviceContextGTK.cpp index 26645d64818c..c77ca4d43d31 100644 --- a/gfx/src/gtk/nsDeviceContextGTK.cpp +++ b/gfx/src/gtk/nsDeviceContextGTK.cpp @@ -150,6 +150,9 @@ NS_IMETHODIMP nsDeviceContextGTK::CreateRenderingContext(nsIRenderingContext *&a nsIRenderingContext *pContext; nsresult rv; nsDrawingSurfaceGTK *surf; + GtkWidget *w; + + w = (GtkWidget*)mWidget; // to call init for this, we need to have a valid nsDrawingSurfaceGTK created pContext = new nsRenderingContextGTK(); @@ -161,15 +164,25 @@ NS_IMETHODIMP nsDeviceContextGTK::CreateRenderingContext(nsIRenderingContext *&a // create the nsDrawingSurfaceGTK surf = new nsDrawingSurfaceGTK(); - if (nsnull != surf) + if (surf && w) { + GdkDrawable *gwin = nsnull; GdkDrawable *win = nsnull; // FIXME - if (GTK_IS_LAYOUT((GtkWidget*)mWidget)) - win = (GdkDrawable*)gdk_window_ref(GTK_LAYOUT((GtkWidget*)mWidget)->bin_window); + if (GTK_IS_LAYOUT(w)) + gwin = (GdkDrawable*)GTK_LAYOUT(w)->bin_window; else - win = (GdkDrawable*)gdk_window_ref(((GtkWidget*)mWidget)->window); + gwin = (GdkDrawable*)(w)->window; + // window might not be realized... ugh + if (gwin) + gdk_window_ref(gwin); + else + win = gdk_pixmap_new(nsnull, + w->allocation.width, + w->allocation.height, + gdk_rgb_get_visual()->depth); + GdkGC *gc = gdk_gc_new(win); // init the nsDrawingSurfaceGTK diff --git a/gfx/src/gtk/nsRenderingContextGTK.cpp b/gfx/src/gtk/nsRenderingContextGTK.cpp index 723f420369c7..6511ce60a1ad 100644 --- a/gfx/src/gtk/nsRenderingContextGTK.cpp +++ b/gfx/src/gtk/nsRenderingContextGTK.cpp @@ -107,7 +107,19 @@ NS_IMETHODIMP nsRenderingContextGTK::Init(nsIDeviceContext* aContext, // we want to ref the window here so that we can unref in the drawing surface. // otherwise, we can not unref and that causes windows that are created in the // drawing surface not to be freed. - GdkDrawable *win = (GdkDrawable*)gdk_window_ref((GdkWindow *)aWindow->GetNativeData(NS_NATIVE_WINDOW)); + GdkDrawable *win = (GdkDrawable*)aWindow->GetNativeData(NS_NATIVE_WINDOW); + if (win) + gdk_window_ref((GdkWindow*)win); + else + { + GtkWidget *w = aWindow->GetNativeData(NS_NATIVE_WIDGET); + + win = gdk_pixmap_new(nsnull, + w->allocation.width, + w->allocation.height, + gdk_rgb_get_visual()->depth); + } + #else GdkDrawable *win = (GdkDrawable *)aWindow->GetNativeData(NS_NATIVE_WINDOW); #endif