зеркало из https://github.com/mozilla/pjs.git
Checkpointing changes. Not part of the build. Some more methods flushed out including widget creation and moving and resizing.
This commit is contained in:
Родитель
a20e5d37dd
Коммит
45557ed47f
|
@ -0,0 +1,294 @@
|
|||
#include "mozcontainer.h"
|
||||
#include <gtk/gtkprivate.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* init methods */
|
||||
static void moz_container_class_init (MozContainerClass *klass);
|
||||
static void moz_container_init (MozContainer *container);
|
||||
|
||||
/* widget class methods */
|
||||
static void moz_container_map (GtkWidget *widget);
|
||||
static void moz_container_unmap (GtkWidget *widget);
|
||||
static void moz_container_realize (GtkWidget *widget);
|
||||
static void moz_container_size_request (GtkWidget *widget,
|
||||
GtkRequisition *requisition);
|
||||
static void moz_container_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation);
|
||||
|
||||
/* container class methods */
|
||||
static void moz_container_add (GtkContainer *container,
|
||||
GtkWidget *widget);
|
||||
static void moz_container_remove (GtkContainer *container,
|
||||
GtkWidget *widget);
|
||||
static void moz_container_forall (GtkContainer *container,
|
||||
gboolean include_internals,
|
||||
GtkCallback callback,
|
||||
gpointer callback_data);
|
||||
|
||||
static GtkContainerClass *parent_class = NULL;
|
||||
|
||||
GtkType
|
||||
moz_container_get_type(void)
|
||||
{
|
||||
static GtkType moz_container_type = 0;
|
||||
|
||||
if (!moz_container_type)
|
||||
{
|
||||
static GTypeInfo moz_container_info = {
|
||||
sizeof(MozContainerClass), /* class_size */
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) moz_container_class_init, /* class_init */
|
||||
NULL, /* class_destroy */
|
||||
NULL, /* class_data */
|
||||
sizeof(MozContainer), /* instance_size */
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) moz_container_init, /* instance_init */
|
||||
NULL, /* value_table */
|
||||
};
|
||||
|
||||
moz_container_type = g_type_register_static (GTK_TYPE_CONTAINER,
|
||||
"MozContainer",
|
||||
&moz_container_info, 0);
|
||||
}
|
||||
|
||||
return moz_container_type;
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
moz_container_new (void)
|
||||
{
|
||||
MozContainer *container;
|
||||
|
||||
container = gtk_type_new (MOZ_CONTAINER_TYPE);
|
||||
|
||||
return GTK_WIDGET(container);
|
||||
}
|
||||
|
||||
void
|
||||
moz_container_class_init (MozContainerClass *klass)
|
||||
{
|
||||
/*GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); */
|
||||
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
widget_class->map = moz_container_map;
|
||||
widget_class->unmap = moz_container_unmap;
|
||||
widget_class->realize = moz_container_realize;
|
||||
widget_class->size_request = moz_container_size_request;
|
||||
widget_class->size_allocate = moz_container_size_allocate;
|
||||
|
||||
container_class->add = moz_container_add;
|
||||
container_class->remove = moz_container_remove;
|
||||
container_class->forall = moz_container_forall;
|
||||
}
|
||||
|
||||
void
|
||||
moz_container_init (MozContainer *container)
|
||||
{
|
||||
container->container.resize_mode = GTK_RESIZE_IMMEDIATE;
|
||||
gtk_widget_set_redraw_on_allocate(GTK_WIDGET(container),
|
||||
FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
moz_container_map (GtkWidget *widget)
|
||||
{
|
||||
MozContainer *container;
|
||||
GList *tmp_list;
|
||||
GtkWidget *tmp_child;
|
||||
|
||||
g_return_if_fail (IS_MOZ_CONTAINER(widget));
|
||||
container = MOZ_CONTAINER (widget);
|
||||
|
||||
GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
|
||||
|
||||
tmp_list = container->children;
|
||||
while (tmp_list)
|
||||
{
|
||||
tmp_child = GTK_WIDGET(tmp_list->data);
|
||||
|
||||
if (GTK_WIDGET_VISIBLE(tmp_child))
|
||||
{
|
||||
if (!GTK_WIDGET_MAPPED(tmp_child))
|
||||
gtk_widget_map(tmp_child);
|
||||
}
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
gdk_window_show (widget->window);
|
||||
}
|
||||
|
||||
void
|
||||
moz_container_unmap (GtkWidget *widget)
|
||||
{
|
||||
MozContainer *container;
|
||||
|
||||
g_return_if_fail (IS_MOZ_CONTAINER (widget));
|
||||
container = MOZ_CONTAINER (widget);
|
||||
|
||||
GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
|
||||
|
||||
gdk_window_hide (widget->window);
|
||||
}
|
||||
|
||||
void
|
||||
moz_container_realize (GtkWidget *widget)
|
||||
{
|
||||
GdkWindowAttr attributes;
|
||||
gint attributes_mask = 0;
|
||||
MozContainer *container;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(widget));
|
||||
|
||||
container = MOZ_CONTAINER(widget);
|
||||
|
||||
GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
|
||||
|
||||
/* create the shell window */
|
||||
|
||||
attributes.event_mask = gtk_widget_get_events (widget);
|
||||
attributes.event_mask |= (GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK);
|
||||
attributes.x = widget->allocation.x;
|
||||
attributes.y = widget->allocation.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.window_type = GDK_WINDOW_CHILD;
|
||||
|
||||
attributes_mask |= GDK_WA_VISUAL | GDK_WA_COLORMAP |
|
||||
GDK_WA_X | GDK_WA_Y;
|
||||
|
||||
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
|
||||
&attributes, attributes_mask);
|
||||
printf("widget->window is %p\n", widget->window);
|
||||
gdk_window_set_user_data (widget->window, container);
|
||||
|
||||
widget->style = gtk_style_attach (widget->style, widget->window);
|
||||
|
||||
/* set the back pixmap to None so that you don't end up with the gtk
|
||||
default which is BlackPixel */
|
||||
gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
moz_container_size_request (GtkWidget *widget,
|
||||
GtkRequisition *requisition)
|
||||
{
|
||||
/* always request our current size */
|
||||
requisition->width = widget->allocation.width;
|
||||
requisition->height = widget->allocation.height;
|
||||
}
|
||||
|
||||
void
|
||||
moz_container_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation)
|
||||
{
|
||||
MozContainer *container;
|
||||
GList *tmp_list;
|
||||
GtkAllocation tmp_allocation;
|
||||
GtkRequisition tmp_requisition;
|
||||
|
||||
g_return_if_fail (IS_MOZ_CONTAINER (widget));
|
||||
|
||||
printf("moz_container_size_allocate %p %d %d %d %d\n",
|
||||
widget,
|
||||
allocation->x,
|
||||
allocation->y,
|
||||
allocation->width,
|
||||
allocation->height);
|
||||
|
||||
/* short circuit if you can */
|
||||
if (widget->allocation.x == allocation->x &&
|
||||
widget->allocation.y == allocation->y &&
|
||||
widget->allocation.width == allocation->width &&
|
||||
widget->allocation.height == allocation->height) {
|
||||
return;
|
||||
}
|
||||
|
||||
container = MOZ_CONTAINER (widget);
|
||||
|
||||
widget->allocation = *allocation;
|
||||
|
||||
tmp_list = container->children;
|
||||
while (tmp_list)
|
||||
{
|
||||
gtk_widget_size_request (GTK_WIDGET(tmp_list->data), &tmp_requisition);
|
||||
tmp_allocation.x = 0;
|
||||
tmp_allocation.y = 0;
|
||||
tmp_allocation.width = tmp_requisition.width;
|
||||
tmp_allocation.height = tmp_requisition.height;
|
||||
gtk_widget_size_allocate (GTK_WIDGET(tmp_list->data), &tmp_allocation);
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_REALIZED (widget))
|
||||
{
|
||||
gdk_window_move_resize(widget->window,
|
||||
widget->allocation.x,
|
||||
widget->allocation.y,
|
||||
widget->allocation.width,
|
||||
widget->allocation.height);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
moz_container_add (GtkContainer *container, GtkWidget *widget)
|
||||
{
|
||||
MozContainer *moz_container;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(container));
|
||||
|
||||
moz_container = MOZ_CONTAINER(container);
|
||||
|
||||
moz_container->children = g_list_append(moz_container->children, widget);
|
||||
|
||||
gtk_widget_set_parent (widget, GTK_WIDGET(moz_container));
|
||||
}
|
||||
|
||||
void
|
||||
moz_container_remove (GtkContainer *container, GtkWidget *widget)
|
||||
{
|
||||
GList *tmp_list;
|
||||
|
||||
MozContainer *moz_container;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(container));
|
||||
|
||||
moz_container = MOZ_CONTAINER(container);
|
||||
|
||||
tmp_list = g_list_find(moz_container->children, widget);
|
||||
if (tmp_list)
|
||||
{
|
||||
gtk_widget_unparent (widget);
|
||||
moz_container->children = g_list_remove_link (moz_container->children,
|
||||
tmp_list);
|
||||
g_list_free_1 (tmp_list);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
moz_container_forall (GtkContainer *container, gboolean include_internals,
|
||||
GtkCallback callback, gpointer callback_data)
|
||||
{
|
||||
MozContainer *moz_container;
|
||||
GList *tmp_list;
|
||||
|
||||
g_return_if_fail (IS_MOZ_CONTAINER(container));
|
||||
g_return_if_fail (callback != NULL);
|
||||
|
||||
moz_container = MOZ_CONTAINER(container);
|
||||
|
||||
tmp_list = moz_container->children;
|
||||
while (tmp_list)
|
||||
{
|
||||
(* callback) (GTK_WIDGET(tmp_list->data), callback_data);
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef __MOZ_CONTAINER_H__
|
||||
#define __MOZ_CONTAINER_H__
|
||||
|
||||
#include <gtk/gtkcontainer.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define MOZ_CONTAINER_TYPE (moz_container_get_type())
|
||||
#define MOZ_CONTAINER(obj) (GTK_CHECK_CAST ((obj), MOZ_CONTAINER_TYPE, MozContainer))
|
||||
#define MOZ_CONTAINER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), MOZ_CONTAINER_TYPE, MozContainerClass))
|
||||
#define IS_MOZ_CONTAINER(obj) (GTK_CHECK_TYPE ((obj), MOZ_CONTAINER_TYPE))
|
||||
#define IS_MOZ_CONTAINER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), MOZ_CONTAINER_TYPE))
|
||||
#define MOZ_CONAINTER_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), MOZ_CONTAINER_TYPE, MozContainerClass))
|
||||
|
||||
typedef struct _MozContainer MozContainer;
|
||||
typedef struct _MozContainerClass MozContainerClass;
|
||||
|
||||
struct _MozContainer
|
||||
{
|
||||
GtkContainer container;
|
||||
GList *children;
|
||||
};
|
||||
|
||||
struct _MozContainerClass
|
||||
{
|
||||
GtkContainerClass parent_class;
|
||||
};
|
||||
|
||||
GtkType moz_container_get_type (void);
|
||||
GtkWidget *moz_container_new (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __MOZ_CONTAINER_H__ */
|
|
@ -0,0 +1,150 @@
|
|||
#include "mozdrawingarea.h"
|
||||
|
||||
/* init methods */
|
||||
static void moz_drawingarea_class_init (MozDrawingareaClass *klass);
|
||||
static void moz_drawingarea_init (MozDrawingarea *drawingarea);
|
||||
|
||||
/* static methods */
|
||||
static void moz_drawingarea_create_windows (MozDrawingarea *drawingarea,
|
||||
GdkWindow *parent, GtkWidget *widget);
|
||||
|
||||
static GObjectClass *parent_class = NULL;
|
||||
|
||||
GtkType
|
||||
moz_drawingarea_get_type(void)
|
||||
{
|
||||
static GtkType moz_drawingarea_type = 0;
|
||||
|
||||
if (!moz_drawingarea_type)
|
||||
{
|
||||
static GTypeInfo moz_drawingarea_info = {
|
||||
sizeof(MozDrawingareaClass), /* class size */
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) moz_drawingarea_class_init, /* class_init */
|
||||
NULL, /* class_destroy */
|
||||
NULL, /* class_data */
|
||||
sizeof(MozDrawingarea), /* instance_size */
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) moz_drawingarea_init, /* instance_init */
|
||||
NULL, /* value_table */
|
||||
};
|
||||
|
||||
moz_drawingarea_type = g_type_register_static (G_TYPE_OBJECT,
|
||||
"MozDrawingarea",
|
||||
&moz_drawingarea_info, 0);
|
||||
}
|
||||
|
||||
return moz_drawingarea_type;
|
||||
}
|
||||
|
||||
MozDrawingarea *
|
||||
moz_drawingarea_new (MozDrawingarea *parent, MozContainer *widget_parent)
|
||||
{
|
||||
MozDrawingarea *drawingarea;
|
||||
|
||||
drawingarea = g_object_new(MOZ_DRAWINGAREA_TYPE, NULL);
|
||||
|
||||
drawingarea->parent = parent;
|
||||
|
||||
if (!parent)
|
||||
moz_drawingarea_create_windows(drawingarea,
|
||||
GTK_WIDGET(widget_parent)->window,
|
||||
GTK_WIDGET(widget_parent));
|
||||
else
|
||||
moz_drawingarea_create_windows(drawingarea,
|
||||
parent->inner_window,
|
||||
GTK_WIDGET(widget_parent));
|
||||
|
||||
return drawingarea;
|
||||
}
|
||||
|
||||
void
|
||||
moz_drawingarea_class_init (MozDrawingareaClass *klass)
|
||||
{
|
||||
parent_class = g_type_class_peek_parent(klass);
|
||||
}
|
||||
|
||||
void
|
||||
moz_drawingarea_init (MozDrawingarea *drawingarea)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
moz_drawingarea_create_windows (MozDrawingarea *drawingarea, GdkWindow *parent,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
GdkWindowAttr attributes;
|
||||
gint attributes_mask = 0;
|
||||
|
||||
/* create the clipping window */
|
||||
attributes.event_mask = (GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK);
|
||||
attributes.x = 0;
|
||||
attributes.y = 0;
|
||||
attributes.width = 1;
|
||||
attributes.height = 1;
|
||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
||||
attributes.visual = gtk_widget_get_visual (widget);
|
||||
attributes.colormap = gtk_widget_get_colormap (widget);
|
||||
attributes.window_type = GDK_WINDOW_CHILD;
|
||||
|
||||
attributes_mask |= GDK_WA_VISUAL | GDK_WA_COLORMAP |
|
||||
GDK_WA_X | GDK_WA_Y;
|
||||
|
||||
drawingarea->clip_window = gdk_window_new (parent, &attributes,
|
||||
attributes_mask);
|
||||
gdk_window_set_user_data(drawingarea->clip_window, widget);
|
||||
|
||||
/* set the default pixmap to None so that you don't end up with the
|
||||
gtk default which is BlackPixel. */
|
||||
gdk_window_set_back_pixmap(drawingarea->clip_window, NULL, FALSE);
|
||||
|
||||
/* create the inner window */
|
||||
drawingarea->inner_window = gdk_window_new (drawingarea->clip_window,
|
||||
&attributes, attributes_mask);
|
||||
gdk_window_set_user_data(drawingarea->inner_window, widget);
|
||||
|
||||
/* set the default pixmap to None so that you don't end up with the
|
||||
gtk default which is BlackPixel. */
|
||||
gdk_window_set_back_pixmap(drawingarea->inner_window, NULL, FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
moz_drawingarea_move (MozDrawingarea *drawingarea,
|
||||
gint x, gint y)
|
||||
{
|
||||
gdk_window_move(drawingarea->clip_window, x, y);
|
||||
}
|
||||
|
||||
void
|
||||
moz_drawingarea_resize (MozDrawingarea *drawingarea,
|
||||
gint width, gint height)
|
||||
{
|
||||
gdk_window_resize(drawingarea->clip_window, width, height);
|
||||
gdk_window_resize(drawingarea->inner_window, width, height);
|
||||
}
|
||||
|
||||
void
|
||||
moz_drawingarea_move_resize (MozDrawingarea *drawingarea,
|
||||
gint x, gint y, gint width, gint height)
|
||||
{
|
||||
gdk_window_resize(drawingarea->inner_window, width, height);
|
||||
gdk_window_move_resize(drawingarea->clip_window, x, y, width, height);
|
||||
}
|
||||
|
||||
void
|
||||
moz_drawingarea_set_visibility (MozDrawingarea *drawingarea,
|
||||
gboolean visibility)
|
||||
{
|
||||
if (visibility)
|
||||
{
|
||||
gdk_window_show(drawingarea->inner_window);
|
||||
gdk_window_show(drawingarea->clip_window);
|
||||
}
|
||||
else
|
||||
{
|
||||
gdk_window_hide(drawingarea->clip_window);
|
||||
gdk_window_hide(drawingarea->inner_window);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
#ifndef __MOZ_DRAWINGAREA_H__
|
||||
#define __MOZ_DRAWINGAREA_H__
|
||||
|
||||
#include <gdk/gdkwindow.h>
|
||||
#include "mozcontainer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define MOZ_DRAWINGAREA_TYPE (moz_drawingarea_get_type())
|
||||
#define MOZ_DRAWINGAREA(obj) (GTK_CHECK_CAST((obj), MOZ_DRAWINGAREA_TYPE, MozDrawingarea))
|
||||
#define MOZ_DRAWINGAREA_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), MOZ_DRAWINGAREA_TYPE, MozDrawingareaClass))
|
||||
#define IS_MOZ_DRAWINGAREA(obj) (GTK_CHECK_TYPE((obj), MOZ_DRAWINGAREA_TYPE))
|
||||
#define IS_MOZ_DRAWINGAREA_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), MOZ_DRAWINGAREA_TYPE))
|
||||
#define MOZ_DRAWINGAREA_GET_CLASS(obj) (GTK_CHECK_GET_CLASS((obj), MOZ_DRAWINGAREA_TYPE, MozDrawingareaClass))
|
||||
|
||||
typedef struct _MozDrawingarea MozDrawingarea;
|
||||
typedef struct _MozDrawingareaClass MozDrawingareaClass;
|
||||
|
||||
struct _MozDrawingarea
|
||||
{
|
||||
GObject parent_instance;
|
||||
GdkWindow *clip_window;
|
||||
GdkWindow *inner_window;
|
||||
MozDrawingarea *parent;
|
||||
};
|
||||
|
||||
struct _MozDrawingareaClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
GtkType moz_drawingarea_get_type (void);
|
||||
MozDrawingarea *moz_drawingarea_new (MozDrawingarea *parent,
|
||||
MozContainer *widget_parent);
|
||||
void moz_drawingarea_move (MozDrawingarea *drawingarea,
|
||||
gint x, gint y);
|
||||
void moz_drawingarea_resize (MozDrawingarea *drawingarea,
|
||||
gint width, gint height);
|
||||
void moz_drawingarea_move_resize (MozDrawingarea *drawingarea,
|
||||
gint x, gint y,
|
||||
gint width, gint height);
|
||||
void moz_drawingarea_set_visibility (MozDrawingarea *drawingarea,
|
||||
gboolean visibility);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __MOZ_DRAWINGAREA_H__ */
|
|
@ -21,8 +21,14 @@
|
|||
|
||||
#include "nsWindow.h"
|
||||
|
||||
#include <gtk/gtkwindow.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
nsWindow::nsWindow()
|
||||
{
|
||||
mContainer = nsnull;
|
||||
mDrawingarea = nsnull;
|
||||
mIsTopLevel = PR_FALSE;
|
||||
}
|
||||
|
||||
nsWindow::~nsWindow()
|
||||
|
@ -38,7 +44,8 @@ nsWindow::Create(nsIWidget *aParent,
|
|||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return CommonCreate(aParent, nsnull, aRect, aHandleEventFunction,
|
||||
aContext, aAppShell, aToolkit, aInitData);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -50,7 +57,8 @@ nsWindow::Create(nsNativeWidget aParent,
|
|||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return CommonCreate(nsnull, aParent, aRect, aHandleEventFunction,
|
||||
aContext, aAppShell, aToolkit, aInitData);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -62,13 +70,25 @@ nsWindow::Destroy(void)
|
|||
nsIWidget*
|
||||
nsWindow::GetParent(void)
|
||||
{
|
||||
return nsnull;
|
||||
nsIWidget *retval;
|
||||
retval = mParent;
|
||||
NS_IF_ADDREF(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWindow::Show(PRBool aState)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
if (mIsTopLevel) {
|
||||
moz_drawingarea_set_visibility(mDrawingarea, aState);
|
||||
gtk_widget_show(GTK_WIDGET(mContainer));
|
||||
gtk_widget_show(mShell);
|
||||
}
|
||||
else {
|
||||
moz_drawingarea_set_visibility(mDrawingarea, aState);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -94,7 +114,19 @@ NS_IMETHODIMP
|
|||
nsWindow::Move(PRInt32 aX,
|
||||
PRInt32 aY)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
if ((aX == mBounds.x) && (aY == mBounds.y) && !mIsTopLevel)
|
||||
return NS_OK;
|
||||
|
||||
mBounds.x = aX;
|
||||
mBounds.y = aY;
|
||||
|
||||
// XXX do we need to handle the popup crud here?
|
||||
if (mIsTopLevel)
|
||||
gtk_widget_set_uposition(mShell, aX, aY);
|
||||
else
|
||||
moz_drawingarea_move(mDrawingarea, aX, aY);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -102,7 +134,17 @@ nsWindow::Resize(PRInt32 aWidth,
|
|||
PRInt32 aHeight,
|
||||
PRBool aRepaint)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
mBounds.width = aWidth;
|
||||
mBounds.height = aHeight;
|
||||
|
||||
if (mIsTopLevel) {
|
||||
gtk_window_set_default_size(GTK_WINDOW(mShell), aWidth, aHeight);
|
||||
gtk_widget_set_size_request(GTK_WIDGET(mContainer), aWidth, aHeight);
|
||||
}
|
||||
|
||||
moz_drawingarea_resize (mDrawingarea, aWidth, aHeight);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -110,9 +152,23 @@ nsWindow::Resize(PRInt32 aX,
|
|||
PRInt32 aY,
|
||||
PRInt32 aWidth,
|
||||
PRInt32 aHeight,
|
||||
PRBool aRepaint)
|
||||
PRBool aRepaint)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
mBounds.x = aX;
|
||||
mBounds.y = aY;
|
||||
mBounds.width = aWidth;
|
||||
mBounds.height = aHeight;
|
||||
|
||||
if (mIsTopLevel) {
|
||||
gtk_window_set_default_size(GTK_WINDOW(mShell), aWidth, aHeight);
|
||||
gtk_widget_set_uposition(mShell, aX, aY);
|
||||
gtk_widget_set_size_request(GTK_WIDGET(mContainer), aWidth, aHeight);
|
||||
moz_drawingarea_resize(mDrawingarea, aWidth, aHeight);
|
||||
}
|
||||
else {
|
||||
moz_drawingarea_move_resize(mDrawingarea, aX, aY, aWidth, aHeight);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -234,7 +290,33 @@ nsWindow::ScrollRect(nsRect &aSrcRect,
|
|||
void*
|
||||
nsWindow::GetNativeData(PRUint32 aDataType)
|
||||
{
|
||||
return nsnull;
|
||||
switch (aDataType) {
|
||||
case NS_NATIVE_WINDOW:
|
||||
return mDrawingarea->inner_window;
|
||||
break;
|
||||
|
||||
case NS_NATIVE_WIDGET:
|
||||
return mDrawingarea;
|
||||
break;
|
||||
|
||||
case NS_NATIVE_PLUGIN_PORT:
|
||||
NS_WARNING("nsWindow::GetNativeData plugin port not supported yet\n");
|
||||
return nsnull;
|
||||
break;
|
||||
|
||||
case NS_NATIVE_DISPLAY:
|
||||
return GDK_DISPLAY();
|
||||
break;
|
||||
|
||||
case NS_NATIVE_GRAPHIC:
|
||||
NS_WARNING("nsWindow::GetNativeData native graphic not support yet\n");
|
||||
return nsnull;
|
||||
break;
|
||||
|
||||
default:
|
||||
NS_WARNING("nsWindow::GetNativeData called with bad value\n");
|
||||
return nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -358,3 +440,115 @@ nsWindow::GetAttention()
|
|||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsWindow::CommonCreate(nsIWidget *aParent,
|
||||
nsNativeWidget aNativeParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
// only set the base parent if we're going to be a dialog or a
|
||||
// toplevel
|
||||
nsIWidget *baseParent = aInitData &&
|
||||
(aInitData->mWindowType == eWindowType_dialog ||
|
||||
aInitData->mWindowType == eWindowType_toplevel) ?
|
||||
nsnull : aParent;
|
||||
|
||||
// initialize all the common bits of this class
|
||||
BaseCreate(baseParent, aRect, aHandleEventFunction, aContext,
|
||||
aAppShell, aToolkit, aInitData);
|
||||
|
||||
// save a ref to our parent
|
||||
mParent = aParent;
|
||||
|
||||
// save our bounds
|
||||
mBounds = aRect;
|
||||
|
||||
// figure out our parent window
|
||||
MozDrawingarea *parentArea = nsnull;
|
||||
MozContainer *parentContainer = nsnull;
|
||||
GtkWindow *topLevelParent = nsnull;
|
||||
if (aParent || aNativeParent) {
|
||||
// get the drawing area and the container from the parent
|
||||
if (aParent)
|
||||
parentArea = MOZ_DRAWINGAREA(aParent->GetNativeData(NS_NATIVE_WINDOW));
|
||||
else
|
||||
parentArea = MOZ_DRAWINGAREA(aNativeParent);
|
||||
|
||||
NS_ASSERTION(parentArea, "no drawingarea for parent widget!\n");
|
||||
if (!parentArea)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// get the user data for the widget - it should be a container
|
||||
gpointer user_data = nsnull;
|
||||
gdk_window_get_user_data(parentArea->inner_window, &user_data);
|
||||
NS_ASSERTION(user_data, "no user data for parentArea\n");
|
||||
if (!user_data)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// XXX support generic containers here for embedding!
|
||||
parentContainer = MOZ_CONTAINER(user_data);
|
||||
NS_ASSERTION(parentContainer, "owning widget is not a mozcontainer!\n");
|
||||
if (!parentContainer)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// get the toplevel window just in case someone needs to use it
|
||||
// for setting transients or whatever.
|
||||
topLevelParent =
|
||||
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(parentContainer)));
|
||||
}
|
||||
|
||||
// ok, create our windows
|
||||
switch (mWindowType) {
|
||||
case eWindowType_dialog:
|
||||
case eWindowType_popup:
|
||||
case eWindowType_toplevel:
|
||||
{
|
||||
mIsTopLevel = PR_TRUE;
|
||||
if (mWindowType == eWindowType_dialog) {
|
||||
mShell = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_type_hint(GTK_WINDOW(mShell),
|
||||
GDK_WINDOW_TYPE_HINT_DIALOG);
|
||||
gtk_window_set_transient_for(GTK_WINDOW(mShell), topLevelParent);
|
||||
}
|
||||
else if (mWindowType == eWindowType_popup) {
|
||||
mShell = gtk_window_new(GTK_WINDOW_POPUP);
|
||||
gtk_window_set_transient_for(GTK_WINDOW(mShell), topLevelParent);
|
||||
}
|
||||
else { // must be eWindowType_toplevel
|
||||
mShell = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
}
|
||||
|
||||
// create our container
|
||||
mContainer = MOZ_CONTAINER(moz_container_new());
|
||||
gtk_container_add(GTK_CONTAINER(mShell), GTK_WIDGET(mContainer));
|
||||
gtk_widget_realize(GTK_WIDGET(mContainer));
|
||||
|
||||
// and the drawing area
|
||||
mDrawingarea = moz_drawingarea_new(nsnull, mContainer);
|
||||
}
|
||||
break;
|
||||
case eWindowType_child:
|
||||
{
|
||||
mDrawingarea = moz_drawingarea_new(parentArea, parentContainer);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// label the drawing area with this object so we can find our way
|
||||
// home
|
||||
g_object_set_data(G_OBJECT(mDrawingarea->clip_window), "nsWindow",
|
||||
this);
|
||||
g_object_set_data(G_OBJECT(mDrawingarea->inner_window), "nsWindow",
|
||||
this);
|
||||
g_object_set_data(G_OBJECT(mContainer), "nsWindow",
|
||||
this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
#include <nsBaseWidget.h>
|
||||
|
||||
#include "mozcontainer.h"
|
||||
#include "mozdrawingarea.h"
|
||||
|
||||
class nsWindow : public nsBaseWidget {
|
||||
public:
|
||||
nsWindow();
|
||||
|
@ -113,4 +116,23 @@ class nsWindow : public nsBaseWidget {
|
|||
void *aEvent,
|
||||
PRBool *aForWindow);
|
||||
NS_IMETHOD GetAttention();
|
||||
|
||||
private:
|
||||
|
||||
nsresult CommonCreate(nsIWidget *aParent,
|
||||
nsNativeWidget aNativeParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData);
|
||||
|
||||
GtkWidget *mShell;
|
||||
MozContainer *mContainer;
|
||||
MozDrawingarea *mDrawingarea;
|
||||
|
||||
PRPackedBool mIsTopLevel;
|
||||
|
||||
nsCOMPtr<nsIWidget> mParent;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче