add the gtksuperwin library. this is not part of the build. a=granrose

This commit is contained in:
blizzard%redhat.com 1999-11-12 20:12:02 +00:00
parent a2de456d1b
commit 8964cbc3e9
7 changed files with 930 additions and 0 deletions

View File

@ -0,0 +1,70 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = gtksuperwin
REQUIRES =
CSRCS = \
gdksuperwin.c \
gtkmozarea.c \
gtkmozbox.c
EXTRA_DSO_LDOPTS = \
$(MKSHLIB_FORCE_ALL) \
$(SHARED_LIBRARY_LIBS) \
$(MKSHLIB_UNFORCE_ALL) \
$(NULL)
ifndef MOZ_MONOLITHIC_TOOLKIT
EXTRA_DSO_LDOPTS += $(MOZ_GTK_LDFLAGS)
else
EXTRA_DSO_LDOPTS += $(TK_LIBS)
endif
EXPORTS = gdksuperwin.h \
gtkmozarea.h \
gtkmozbox.h
include $(topsrcdir)/config/rules.mk
ifndef MOZ_MONOLITHIC_TOOLKIT
CFLAGS += $(MOZ_GTK_CFLAGS)
else
CFLAGS += $(TK_CFLAGS)
endif
DEFINES += -D_IMPL_NS_WIDGET -DUSE_XIM
ifeq ($(OS_ARCH), Linux)
DEFINES += -D_BSD_SOURCE
endif
INCLUDES += \
-I$(srcdir) \
$(NULL)
$(LIBRARY) $(SHARED_LIBRARY): $(SHARED_LIBRARY_LIBS) Makefile

View File

@ -0,0 +1,360 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License
* at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Initial Developers of this code under the MPL are Owen Taylor
* <otaylor@redhat.com> and Christopher Blizzard <blizzard@redhat.com>.
* Portions created by the Initial Developers are Copyright (C) 1999
* Owen Taylor and Christopher Blizzard. All Rights Reserved. */
#include "gdksuperwin.h"
static void gdk_superwin_class_init(GdkSuperWinClass *klass);
static void gdk_superwin_init(GdkSuperWin *superwin);
typedef struct _GdkSuperWinTranslate GdkSuperWinTranslate;
struct _GdkSuperWinTranslate
{
unsigned long serial;
gint dx;
gint dy;
};
GtkType
gdk_superwin_get_type(void)
{
static GtkType superwin_type = 0;
if (!superwin_type)
{
static const GtkTypeInfo superwin_info =
{
"GtkSuperWin",
sizeof(GdkSuperWin),
sizeof(GdkSuperWinClass),
(GtkClassInitFunc) gdk_superwin_class_init,
(GtkObjectInitFunc) gdk_superwin_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL
};
superwin_type = gtk_type_unique (gtk_object_get_type(), &superwin_info);
}
return superwin_type;
}
static void
gdk_superwin_class_init(GdkSuperWinClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS(klass);
/* XXX do we need a finalize in here to destroy the
window? */
}
static void
gdk_superwin_init(GdkSuperWin *superwin)
{
}
static GdkFilterReturn gdk_superwin_bin_filter (GdkXEvent *gdk_xevent,
GdkEvent *event,
gpointer data);
static GdkFilterReturn gdk_superwin_shell_filter (GdkXEvent *gdk_xevent,
GdkEvent *event,
gpointer data);
static void gdk_superwin_expose_area (GdkSuperWin *superwin,
gint x,
gint y,
gint width,
gint height);
static gboolean gravity_works;
GdkSuperWin *
gdk_superwin_new (GdkWindow *parent_window,
guint x,
guint y,
guint width,
guint height)
{
GdkWindowAttr attributes;
gint attributes_mask;
Window bin_xwindow;
Display *xdisplay;
XSetWindowAttributes xattr;
unsigned long xattr_mask;
GdkSuperWin *superwin = gtk_type_new(GDK_TYPE_SUPERWIN);
superwin->translate_queue = NULL;
superwin->shell_func = NULL;
superwin->bin_func = NULL;
superwin->func_data = NULL;
superwin->notify = NULL;
/* Create the shell (clipping) window */
attributes.window_type = GDK_WINDOW_CHILD;
attributes.x = x;
attributes.y = y;
attributes.width = width;
attributes.height = height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
attributes_mask = GDK_WA_X | GDK_WA_Y;
superwin->shell_window = gdk_window_new (parent_window,
&attributes, attributes_mask);
/* if we failed to create a window, die a horrible death */
g_assert(superwin->shell_window);
/* Create the bin window for drawing */
attributes.x = 0;
attributes.y = 0;
attributes.event_mask = GDK_EXPOSURE_MASK;
superwin->bin_window = gdk_window_new (superwin->shell_window,
&attributes, attributes_mask);
/* set the backing store for the bin window */
bin_xwindow = GDK_WINDOW_XWINDOW(superwin->bin_window);
xdisplay = GDK_WINDOW_XDISPLAY(superwin->bin_window);
/* XXX should we make this Always? */
xattr.backing_store = WhenMapped;
xattr_mask = CWBackingStore;
/* XChangeWindowAttributes(xdisplay, bin_xwindow, xattr_mask, &xattr); */
gdk_window_show (superwin->bin_window);
gdk_window_add_filter (superwin->shell_window, gdk_superwin_shell_filter, superwin);
gdk_window_add_filter (superwin->bin_window, gdk_superwin_bin_filter, superwin);
gravity_works = gdk_window_set_static_gravities (superwin->bin_window, TRUE);
return superwin;
}
/* XXX this should really be part of the object... */
/* XXX and it should chain up to the object's destructor */
void gdk_superwin_destroy(GdkSuperWin *superwin)
{
gdk_window_remove_filter(superwin->shell_window,
gdk_superwin_shell_filter,
superwin);
gdk_window_remove_filter(superwin->bin_window,
gdk_superwin_bin_filter,
superwin);
gdk_window_destroy(superwin->bin_window);
gdk_window_destroy(superwin->shell_window);
}
void
gdk_superwin_scroll (GdkSuperWin *superwin,
gint dx,
gint dy)
{
GdkSuperWinTranslate *translate;
gint width, height;
gdk_window_get_size (superwin->shell_window, &width, &height);
if (dx > 0 || dy > 0)
{
translate = g_new (GdkSuperWinTranslate, 1);
translate->dx = MAX (0, dx);
translate->dy = MAX (0, dy);
translate->serial = NextRequest (GDK_DISPLAY());
superwin->translate_queue = g_list_append (superwin->translate_queue, translate);
}
gdk_window_move_resize (superwin->bin_window,
MIN (0, -dx), MIN (0, -dy),
width + ABS(dx), height + ABS(dy));
gdk_window_move (superwin->bin_window,
MIN (0, -dx) + dx, MIN (0, -dy) + dy);
if (dx < 0 || dy < 0)
{
translate = g_new (GdkSuperWinTranslate, 1);
translate->dx = MIN (0, dx);
translate->dy = MIN (0, dy);
translate->serial = NextRequest (GDK_DISPLAY());
superwin->translate_queue = g_list_append (superwin->translate_queue, translate);
}
gdk_window_move_resize (superwin->bin_window,
0, 0, width, height);
if (dx < 0)
gdk_superwin_expose_area (superwin,
MAX (width + dx, 0), 0,
MIN (-dx, width), height);
else
gdk_superwin_expose_area (superwin,
0, 0,
MIN (dx, width), height);
if (dy < 0)
gdk_superwin_expose_area (superwin,
MIN (dx, 0), MAX (height + dy, 0),
MIN (width - ABS(dx), 0), MIN (-dy, height));
else
gdk_superwin_expose_area (superwin,
MIN (dx, 0), 0,
MIN (width - ABS(dx), 0), MIN (dy, height));
}
void
gdk_superwin_set_event_funcs (GdkSuperWin *superwin,
GdkSuperWinFunc shell_func,
GdkSuperWinFunc bin_func,
gpointer func_data,
GDestroyNotify notify)
{
if (superwin->notify && superwin->func_data)
superwin->notify (superwin->func_data);
superwin->shell_func = shell_func;
superwin->bin_func = bin_func;
superwin->func_data = func_data;
superwin->notify = notify;
}
void gdk_superwin_resize (GdkSuperWin *superwin,
gint width,
gint height)
{
gdk_window_resize (superwin->bin_window, width, height);
gdk_window_resize (superwin->shell_window, width, height);
}
static void
gdk_superwin_expose_area (GdkSuperWin *superwin,
gint x,
gint y,
gint width,
gint height)
{
}
static GdkFilterReturn
gdk_superwin_bin_filter (GdkXEvent *gdk_xevent,
GdkEvent *event,
gpointer data)
{
XEvent *xevent = (XEvent *)gdk_xevent;
GdkSuperWin *superwin = data;
GdkSuperWinTranslate *translate;
GList *tmp_list;
switch (xevent->xany.type) {
case Expose:
tmp_list = superwin->translate_queue;
while (tmp_list) {
translate = tmp_list->data;
xevent->xexpose.x += translate->dx;
xevent->xexpose.y += translate->dy;
tmp_list = tmp_list->next;
}
if (superwin->bin_func) {
superwin->bin_func (superwin, xevent, superwin->func_data);
}
return GDK_FILTER_REMOVE;
break;
case ConfigureNotify:
gdk_superwin_clear_translate_queue(superwin, xevent->xany.serial);
break;
}
return GDK_FILTER_CONTINUE;
}
static GdkFilterReturn
gdk_superwin_shell_filter (GdkXEvent *gdk_xevent,
GdkEvent *event,
gpointer data)
{
XEvent *xevent = (XEvent *)gdk_xevent;
GdkSuperWin *superwin = data;
if (xevent->type == VisibilityNotify)
{
switch (xevent->xvisibility.state)
{
case VisibilityFullyObscured:
superwin->visibility = GDK_VISIBILITY_FULLY_OBSCURED;
break;
case VisibilityPartiallyObscured:
superwin->visibility = GDK_VISIBILITY_PARTIAL;
break;
case VisibilityUnobscured:
superwin->visibility = GDK_VISIBILITY_UNOBSCURED;
break;
}
return GDK_FILTER_REMOVE;
}
if (superwin->shell_func) {
/* g_print("calling func %p with arg %p in win %p\n",
superwin->event_func, superwin->func_data, superwin); */
superwin->shell_func (superwin, xevent, superwin->func_data);
}
return GDK_FILTER_CONTINUE;
}
void
gdk_superwin_clear_translate_queue(GdkSuperWin *superwin, unsigned long serial)
{
GdkSuperWinTranslate *translate;
GList *tmp_list;
GList *link_to_remove = NULL;
if (superwin->translate_queue) {
tmp_list = superwin->translate_queue;
while (tmp_list) {
translate = tmp_list->data;
if (serial == translate->serial) {
g_free (tmp_list->data);
superwin->translate_queue = g_list_remove_link (superwin->translate_queue, tmp_list);
link_to_remove = tmp_list;
}
tmp_list = tmp_list->next;
if (link_to_remove) {
g_list_free_1(link_to_remove);
link_to_remove = NULL;
}
}
}
}

View File

@ -0,0 +1,92 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License
* at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Initial Developers of this code under the MPL are Owen Taylor
* <otaylor@redhat.com> and Christopher Blizzard <blizzard@redhat.com>.
* Portions created by the Initial Developers are Copyright (C) 1999
* Owen Taylor and Christopher Blizzard. All Rights Reserved. */
#ifndef __GDK_SUPERWIN_H__
#define __GDK_SUPERWIN_H__
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gtk/gtkobject.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct _GdkSuperWin GdkSuperWin;
typedef struct _GdkSuperWinClass GdkSuperWinClass;
#define GDK_TYPE_SUPERWIN (gdk_superwin_get_type())
#define GDK_SUPERWIN(obj) (GTK_CHECK_CAST((obj), GDK_TYPE_SUPERWIN, GdkSuperWin))
#define GDK_SUPERWIN_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GDK_TYPE_SUPERWIN, GdkSuperWinClass))
#define GDK_IS_SUPERWIN(obj) (GTK_CHECK_TYPE((obj), GDK_TYPE_SUPERWIN))
#define GDK_IS_SUPERWIN_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GDK_TYPE_SUPERWIN))
typedef void (*GdkSuperWinFunc) (GdkSuperWin *super_win,
XEvent *event,
gpointer data);
struct _GdkSuperWin
{
GtkObject object;
GdkWindow *shell_window;
GdkWindow *bin_window;
/* Private */
GList *translate_queue;
GdkSuperWinFunc shell_func;
GdkSuperWinFunc bin_func;
gpointer func_data;
GDestroyNotify notify;
GdkVisibilityState visibility;
};
struct _GdkSuperWinClass
{
GtkObjectClass object_class;
};
GtkType gdk_superwin_get_type(void);
GdkSuperWin *gdk_superwin_new (GdkWindow *parent_window,
guint x,
guint y,
guint width,
guint height);
void
gdk_superwin_set_event_funcs (GdkSuperWin *superwin,
GdkSuperWinFunc shell_func,
GdkSuperWinFunc bin_func,
gpointer func_data,
GDestroyNotify notify);
void gdk_superwin_scroll (GdkSuperWin *superwin,
gint dx,
gint dy);
void gdk_superwin_resize (GdkSuperWin *superwin,
gint width,
gint height);
void gdk_superwin_destroy(GdkSuperWin *superwin);
void gdk_superwin_clear_translate_queue(GdkSuperWin *superwin,
unsigned long serial);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _GDK_SUPERWIN_H__ */

View File

@ -0,0 +1,140 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License
* at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Initial Developers of this code under the MPL are Owen Taylor
* <otaylor@redhat.com> and Christopher Blizzard <blizzard@redhat.com>.
* Portions created by the Initial Developers are Copyright (C) 1999
* Owen Taylor and Christopher Blizzard. All Rights Reserved. */
#include "gtkmozarea.h"
#include <X11/Xlib.h>
static void gtk_mozarea_class_init (GtkMozAreaClass *klass);
static void gtk_mozarea_init (GtkMozArea *mozarea);
static void gtk_mozarea_realize (GtkWidget *widget);
static void gtk_mozarea_unrealize (GtkWidget *widget);
static void gtk_mozarea_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
GtkWidgetClass *parent_class = NULL;
GtkType
gtk_mozarea_get_type (void)
{
static GtkType mozarea_type = 0;
if (!mozarea_type)
{
static const GtkTypeInfo mozarea_info =
{
"GtkMozArea",
sizeof (GtkMozArea),
sizeof (GtkMozAreaClass),
(GtkClassInitFunc) gtk_mozarea_class_init,
(GtkObjectInitFunc) gtk_mozarea_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL
};
mozarea_type = gtk_type_unique (GTK_TYPE_WIDGET, &mozarea_info);
}
return mozarea_type;
}
static void
gtk_mozarea_class_init (GtkMozAreaClass *klass)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS (klass);
widget_class->realize = gtk_mozarea_realize;
widget_class->unrealize = gtk_mozarea_unrealize;
widget_class->size_allocate = gtk_mozarea_size_allocate;
parent_class = gtk_type_class(gtk_widget_get_type());
}
static void
gtk_mozarea_init (GtkMozArea *mozarea)
{
mozarea->superwin = NULL;
}
static void
gtk_mozarea_realize (GtkWidget *widget)
{
GtkMozArea *mozarea;
g_return_if_fail (GTK_IS_MOZAREA (widget));
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
mozarea = GTK_MOZAREA (widget);
mozarea->superwin = gdk_superwin_new (gtk_widget_get_parent_window (widget),
widget->allocation.x, widget->allocation.y,
widget->allocation.width, widget->allocation.height);
gdk_window_set_user_data (mozarea->superwin->shell_window, mozarea);
widget->window = mozarea->superwin->shell_window;
widget->style = gtk_style_attach (widget->style, widget->window);
/* make sure that we add a reference to this window.
if we don't then it will be destroyed by both the superwin
destroy method and the widget class destructor */
gdk_window_ref(widget->window);
}
static void
gtk_mozarea_unrealize(GtkWidget *widget)
{
GtkMozArea *mozarea;
g_return_if_fail(GTK_IS_MOZAREA(widget));
GTK_WIDGET_UNSET_FLAGS(widget, GTK_REALIZED);
mozarea = GTK_MOZAREA(widget);
if (mozarea->superwin) {
gdk_superwin_destroy(mozarea->superwin);
mozarea->superwin = NULL;
}
GTK_WIDGET_CLASS(parent_class)->unrealize(widget);
}
static void
gtk_mozarea_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkMozArea *mozarea;
g_return_if_fail (GTK_IS_MOZAREA (widget));
mozarea = GTK_MOZAREA (widget);
if (GTK_WIDGET_REALIZED (widget))
{
gdk_window_move (mozarea->superwin->shell_window,
allocation->x, allocation->y);
gdk_superwin_resize (mozarea->superwin,
allocation->width, allocation->height);
}
}
GtkWidget*
gtk_mozarea_new (GdkWindow *parent_window)
{
return GTK_WIDGET (gtk_type_new (GTK_TYPE_MOZAREA));
}

View File

@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License
* at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Initial Developers of this code under the MPL are Owen Taylor
* <otaylor@redhat.com> and Christopher Blizzard <blizzard@redhat.com>.
* Portions created by the Initial Developers are Copyright (C) 1999
* Owen Taylor and Christopher Blizzard. All Rights Reserved. */
#ifndef __GTK_MOZAREA_H__
#define __GTK_MOZAREA_H__
#include <gtk/gtkwindow.h>
#include "gdksuperwin.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct _GtkMozArea GtkMozArea;
typedef struct _GtkMozAreaClass GtkMozAreaClass;
#define GTK_TYPE_MOZAREA (gtk_mozarea_get_type ())
#define GTK_MOZAREA(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_MOZAREA, GtkMozArea))
#define GTK_MOZAREA_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_MOZAREA, GtkMozAreaClass))
#define GTK_IS_MOZAREA(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_MOZAREA))
#define GTK_IS_MOZAREA_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MOZAREA))
struct _GtkMozArea
{
GtkWidget widget;
GdkSuperWin *superwin;
};
struct _GtkMozAreaClass
{
GtkWindowClass window_class;
};
GtkType gtk_mozarea_get_type (void);
GtkWidget *gtk_mozarea_new ();
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GTK_MOZAREA_H__ */

View File

@ -0,0 +1,154 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License
* at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Initial Developers of this code under the MPL are Owen Taylor
* <otaylor@redhat.com> and Christopher Blizzard <blizzard@redhat.com>.
* Portions created by the Initial Developers are Copyright (C) 1999
* Owen Taylor and Christopher Blizzard. All Rights Reserved. */
#include "gtkmozbox.h"
#include <X11/Xlib.h>
static void gtk_mozbox_class_init (GtkMozBoxClass *klass);
static void gtk_mozbox_init (GtkMozBox *mozbox);
static void gtk_mozbox_realize (GtkWidget *widget);
static GdkFilterReturn gtk_mozbox_filter (GdkXEvent *xevent,
GdkEvent *event,
gpointer data);
GtkType
gtk_mozbox_get_type (void)
{
static GtkType mozbox_type = 0;
if (!mozbox_type)
{
static const GtkTypeInfo mozbox_info =
{
"GtkMozBox",
sizeof (GtkMozBox),
sizeof (GtkMozBoxClass),
(GtkClassInitFunc) gtk_mozbox_class_init,
(GtkObjectInitFunc) gtk_mozbox_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL
};
mozbox_type = gtk_type_unique (GTK_TYPE_WINDOW, &mozbox_info);
}
return mozbox_type;
}
static void
gtk_mozbox_class_init (GtkMozBoxClass *klass)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS (klass);
widget_class->realize = gtk_mozbox_realize;
}
static void
gtk_mozbox_init (GtkMozBox *mozbox)
{
mozbox->parent_window = NULL;
mozbox->x = 0;
mozbox->y = 0;
}
static void
gtk_mozbox_realize (GtkWidget *widget)
{
GdkWindowAttr attributes;
gint attributes_mask;
GtkMozBox *mozbox;
g_return_if_fail (GTK_IS_MOZBOX (widget));
mozbox = GTK_MOZBOX (widget);
/* GtkWindow checks against premature realization here. Just
* don't do it.
*/
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
attributes.window_type = GDK_WINDOW_CHILD;
attributes.x = mozbox->x;
attributes.y = mozbox->y;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = gtk_widget_get_events (widget);
attributes.event_mask |= GDK_EXPOSURE_MASK;
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new (mozbox->parent_window,
&attributes, attributes_mask);
gdk_window_set_user_data (widget->window, mozbox);
widget->style = gtk_style_attach (widget->style, widget->window);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
gdk_window_add_filter (widget->window, gtk_mozbox_filter, mozbox);
}
static GdkFilterReturn
gtk_mozbox_filter (GdkXEvent *xevent,
GdkEvent *event,
gpointer data)
{
XEvent *xev = xevent;
GtkWidget *widget = data;
switch (xev->xany.type)
{
case ConfigureNotify:
event->configure.type = GDK_CONFIGURE;
event->configure.window = widget->window;
event->configure.x = 0;
event->configure.y = 0;
event->configure.width = xev->xconfigure.width;
event->configure.height = xev->xconfigure.height;
return GDK_FILTER_TRANSLATE;
default:
return GDK_FILTER_CONTINUE;
}
}
GtkWidget*
gtk_mozbox_new (GdkWindow *parent_window)
{
GtkMozBox *mozbox;
mozbox = gtk_type_new (GTK_TYPE_MOZBOX);
mozbox->parent_window = parent_window;
return GTK_WIDGET (mozbox);
}
void
gtk_mozbox_set_position (GtkMozBox *mozbox,
gint x,
gint y)
{
mozbox->x = x;
mozbox->y = y;
if (GTK_WIDGET_REALIZED (mozbox))
gdk_window_move (GTK_WIDGET (mozbox)->window, x, y);
}

View File

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License
* at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Initial Developers of this code under the MPL are Owen Taylor
* <otaylor@redhat.com> and Christopher Blizzard <blizzard@redhat.com>.
* Portions created by the Initial Developers are Copyright (C) 1999
* Owen Taylor and Christopher Blizzard. All Rights Reserved. */
#ifndef __GTK_MOZBOX_H__
#define __GTK_MOZBOX_H__
#include <gtk/gtkwindow.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct _GtkMozBox GtkMozBox;
typedef struct _GtkMozBoxClass GtkMozBoxClass;
#define GTK_TYPE_MOZBOX (gtk_mozbox_get_type ())
#define GTK_MOZBOX(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_MOZBOX, GtkMozBox))
#define GTK_MOZBOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_MOZBOX, GtkMozBoxClass))
#define GTK_IS_MOZBOX(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_MOZBOX))
#define GTK_IS_MOZBOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MOZBOX))
struct _GtkMozBox
{
GtkWindow window;
GdkWindow *parent_window;
gint x;
gint y;
};
struct _GtkMozBoxClass
{
GtkWindowClass window_class;
};
GtkType gtk_mozbox_get_type (void);
GtkWidget *gtk_mozbox_new (GdkWindow *parent_window);
void gtk_mozbox_set_position (GtkMozBox *mozbox,
gint x,
gint y);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GTK_MOZBOX_H__ */