fix bug 85701; problems using plugins [@ gtk_xtbin_init] topcrash; r=pavlov;sr=blizzard

This commit is contained in:
serge%netscape.com 2001-09-28 01:51:06 +00:00
Родитель 64fb1452bf
Коммит 8b5e04ccf2
2 изменённых файлов: 73 добавлений и 52 удалений

Просмотреть файл

@ -853,7 +853,8 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
ws = (NPSetWindowCallbackStruct *)window->ws_info; ws = (NPSetWindowCallbackStruct *)window->ws_info;
GdkWindow *win = gdk_window_lookup((XID)window->window); GdkWindow *win = gdk_window_lookup((XID)window->window);
if (win) if (!win)
return NS_ERROR_FAILURE;
{ {
#ifdef NS_DEBUG #ifdef NS_DEBUG
printf("About to create new xtbin of %i X %i from %p...\n", printf("About to create new xtbin of %i X %i from %p...\n",
@ -881,6 +882,10 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
if (!mXtBin) { if (!mXtBin) {
mXtBin = gtk_xtbin_new(win, 0); mXtBin = gtk_xtbin_new(win, 0);
// Check to see if creating mXtBin failed for some reason.
// if it did, we can't go any further.
if (!mXtBin)
return NS_ERROR_FAILURE;
} }
gtk_widget_set_usize(mXtBin, window->width, window->height); gtk_widget_set_usize(mXtBin, window->width, window->height);
@ -904,6 +909,9 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
XFlush(ws->display); XFlush(ws->display);
} // !window->ws_info } // !window->ws_info
if (!mXtBin)
return NS_ERROR_FAILURE;
// And now point the NPWindow structures window // And now point the NPWindow structures window
// to the actual X window // to the actual X window
window->window = (nsPluginPort *)GTK_XTBIN(mXtBin)->xtwindow; window->window = (nsPluginPort *)GTK_XTBIN(mXtBin)->xtwindow;

Просмотреть файл

@ -173,58 +173,12 @@ gtk_xtbin_class_init (GtkXtBinClass *klass)
static void static void
gtk_xtbin_init (GtkXtBin *xtbin) gtk_xtbin_init (GtkXtBin *xtbin)
{ {
static Display *xtdisplay = NULL; xtbin->xtdisplay = NULL;
xtbin->xtwidget = NULL; xtbin->xtwidget = NULL;
xtbin->parent_window = NULL; xtbin->parent_window = NULL;
xtbin->xtwindow = 0; xtbin->xtwindow = 0;
xtbin->x = 0; xtbin->x = 0;
xtbin->y = 0; xtbin->y = 0;
/* Initialize the Xt toolkit */
if (xt_is_initialized == 0) {
char *mArgv[1];
int mArgc = 0;
XtAppContext app_context;
int cnumber;
#ifdef DEBUG_XTBIN
printf("starting up Xt stuff\n");
#endif
/*
* Initialize Xt stuff
*/
XtToolkitInitialize();
app_context = XtCreateApplicationContext();
if (fallback)
XtAppSetFallbackResources(app_context, fallback);
xtdisplay = XtOpenDisplay(app_context, NULL, NULL,
"Wrapper", NULL, 0, &mArgc, mArgv);
/*
* hook Xt event loop into the glib event loop.
*/
/* the assumption is that gtk_init has already been called */
g_source_add (GDK_PRIORITY_EVENTS, TRUE,
&xt_event_funcs, NULL, xtdisplay, NULL);
#ifdef VMS
cnumber = XConnectionNumber(xtdisplay);
#else
cnumber = ConnectionNumber(xtdisplay);
#endif
xt_event_poll_fd.fd = cnumber;
xt_event_poll_fd.events = G_IO_IN;
xt_event_poll_fd.revents = 0; /* hmm... is this correct? */
g_main_add_poll (&xt_event_poll_fd, G_PRIORITY_DEFAULT);
}
xt_is_initialized++; /* bump up our count here */
xtbin->xtdisplay = xtdisplay;
} }
static void static void
@ -239,13 +193,11 @@ gtk_xtbin_realize (GtkWidget *widget)
Window win; Window win;
Widget embeded; Widget embeded;
g_return_if_fail (GTK_IS_XTBIN (widget)); g_return_if_fail (GTK_IS_XTBIN (widget));
gdk_flush(); gdk_flush();
xtbin = GTK_XTBIN (widget); xtbin = GTK_XTBIN (widget);
if (widget->allocation.x == -1 && if (widget->allocation.x == -1 &&
widget->allocation.y == -1 && widget->allocation.y == -1 &&
widget->allocation.width == 1 && widget->allocation.width == 1 &&
@ -370,11 +322,72 @@ gtk_xtbin_realize (GtkWidget *widget)
GtkWidget* GtkWidget*
gtk_xtbin_new (GdkWindow *parent_window, String * f) gtk_xtbin_new (GdkWindow *parent_window, String * f)
{ {
GtkXtBin *xtbin; static Display *xtdisplay = NULL;
GtkXtBin *xtbin;
assert(parent_window != NULL); assert(parent_window != NULL);
xtbin = gtk_type_new (GTK_TYPE_XTBIN); xtbin = gtk_type_new (GTK_TYPE_XTBIN);
if (!xtbin)
return (GtkWidget*)NULL;
/* Initialize the Xt toolkit */
if (xt_is_initialized == 0) {
char *mArgv[1];
int mArgc = 0;
XtAppContext app_context;
int cnumber;
#ifdef DEBUG_XTBIN
printf("starting up Xt stuff\n");
#endif
/*
* Initialize Xt stuff
*/
XtToolkitInitialize();
app_context = XtCreateApplicationContext();
if (fallback)
XtAppSetFallbackResources(app_context, fallback);
xtdisplay = XtOpenDisplay(app_context, NULL, NULL,
"Wrapper", NULL, 0, &mArgc, mArgv);
if (!xtdisplay) {
/* If XtOpenDisplay failed, we can't go any further.
* Bail out.
*/
#ifdef DEBUG_XTBIN
printf("gtk_xtbin_init: XtOpenDisplay() returned NULL.\n");
#endif
gtk_type_free (GTK_TYPE_XTBIN, xtbin);
return (GtkWidget *)NULL;
}
/*
* hook Xt event loop into the glib event loop.
*/
/* the assumption is that gtk_init has already been called */
g_source_add (GDK_PRIORITY_EVENTS, TRUE,
&xt_event_funcs, NULL, xtdisplay, (GDestroyNotify)NULL);
#ifdef VMS
cnumber = XConnectionNumber(xtdisplay);
#else
cnumber = ConnectionNumber(xtdisplay);
#endif
xt_event_poll_fd.fd = cnumber;
xt_event_poll_fd.events = G_IO_IN;
xt_event_poll_fd.revents = 0; /* hmm... is this correct? */
g_main_add_poll (&xt_event_poll_fd, G_PRIORITY_DEFAULT);
xt_is_initialized++; /* bump up our count here */
}
xtbin->xtdisplay = xtdisplay;
xtbin->parent_window = parent_window; xtbin->parent_window = parent_window;
if (f) if (f)
fallback = f; fallback = f;