Back to index

lightning-sunbird  0.9+nobinonly
mozdrawingarea.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* vim:expandtab:shiftwidth=4:tabstop=4:
00003  */
00004 /* ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is mozilla.org code.
00018  *
00019  * The Initial Developer of the Original Code is Christopher Blizzard
00020  * <blizzard@mozilla.org>.  Portions created by the Initial Developer
00021  * are Copyright (C) 2001 the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "mozdrawingarea.h"
00040 
00041 /* init methods */
00042 static void moz_drawingarea_class_init          (MozDrawingareaClass *klass);
00043 static void moz_drawingarea_init                (MozDrawingarea *drawingarea);
00044 
00045 /* static methods */
00046 static void moz_drawingarea_create_windows      (MozDrawingarea *drawingarea,
00047                                                  GdkWindow *parent,
00048                                                  GtkWidget *widget);
00049 
00050 static void moz_drawingarea_finalize            (GObject *object);
00051 
00052 static GObjectClass *parent_class = NULL;
00053 
00054 GtkType
00055 moz_drawingarea_get_type(void)
00056 {
00057     static GtkType moz_drawingarea_type = 0;
00058 
00059    if (!moz_drawingarea_type) {
00060        static GTypeInfo moz_drawingarea_info = {
00061            sizeof(MozDrawingareaClass), /* class size */
00062            NULL, /* base_init */
00063            NULL, /* base_finalize */
00064            (GClassInitFunc) moz_drawingarea_class_init, /* class_init */
00065            NULL, /* class_destroy */
00066            NULL, /* class_data */
00067            sizeof(MozDrawingarea), /* instance_size */
00068            0, /* n_preallocs */
00069            (GInstanceInitFunc) moz_drawingarea_init, /* instance_init */
00070            NULL, /* value_table */
00071        };
00072        moz_drawingarea_type =
00073            g_type_register_static (G_TYPE_OBJECT,
00074                                    "MozDrawingarea",
00075                                    &moz_drawingarea_info, 0);
00076    }
00077 
00078    return moz_drawingarea_type;
00079 }
00080 
00081 MozDrawingarea *
00082 moz_drawingarea_new (MozDrawingarea *parent, MozContainer *widget_parent)
00083 {
00084     MozDrawingarea *drawingarea;
00085 
00086     drawingarea = g_object_new(MOZ_DRAWINGAREA_TYPE, NULL);
00087 
00088     drawingarea->parent = parent;
00089 
00090     if (!parent)
00091         moz_drawingarea_create_windows(drawingarea,
00092                                        GTK_WIDGET(widget_parent)->window,
00093                                        GTK_WIDGET(widget_parent));
00094     else
00095         moz_drawingarea_create_windows(drawingarea,
00096                                        parent->inner_window, 
00097                                        GTK_WIDGET(widget_parent));
00098 
00099     return drawingarea;
00100 }
00101 
00102 void
00103 moz_drawingarea_class_init (MozDrawingareaClass *klass)
00104 {
00105     GObjectClass *object_class = G_OBJECT_CLASS (klass);
00106 
00107     object_class->finalize = moz_drawingarea_finalize;
00108 
00109     parent_class = g_type_class_peek_parent(klass);
00110 }
00111 
00112 void
00113 moz_drawingarea_init (MozDrawingarea *drawingarea)
00114 {
00115 
00116 }
00117 
00118 void
00119 moz_drawingarea_reparent (MozDrawingarea *drawingarea, GdkWindow *aNewParent)
00120 {
00121     gdk_window_reparent(drawingarea->clip_window,
00122                         aNewParent, 0, 0);
00123 }
00124 
00125 void
00126 moz_drawingarea_create_windows (MozDrawingarea *drawingarea, GdkWindow *parent,
00127                                 GtkWidget *widget)
00128 {
00129     GdkWindowAttr attributes;
00130     gint          attributes_mask = 0;
00131 
00132     /* create the clipping window */
00133     attributes.event_mask = 0;
00134     attributes.x = 0;
00135     attributes.y = 0;
00136     attributes.width = 1;
00137     attributes.height = 1;
00138     attributes.wclass = GDK_INPUT_OUTPUT;
00139     attributes.visual = gtk_widget_get_visual (widget);
00140     attributes.colormap = gtk_widget_get_colormap (widget);
00141     attributes.window_type = GDK_WINDOW_CHILD;
00142 
00143     attributes_mask |= GDK_WA_VISUAL | GDK_WA_COLORMAP |
00144         GDK_WA_X | GDK_WA_Y;
00145 
00146     drawingarea->clip_window = gdk_window_new (parent, &attributes,
00147                                                attributes_mask);
00148     gdk_window_set_user_data(drawingarea->clip_window, widget);
00149 
00150     /* set the default pixmap to None so that you don't end up with the
00151        gtk default which is BlackPixel. */
00152     gdk_window_set_back_pixmap(drawingarea->clip_window, NULL, FALSE);
00153 
00154     attributes.event_mask = (GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK |
00155                              GDK_VISIBILITY_NOTIFY_MASK |
00156                              GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
00157                              GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
00158                              GDK_POINTER_MOTION_MASK);
00159     /* create the inner window */
00160     drawingarea->inner_window = gdk_window_new (drawingarea->clip_window,
00161                                                 &attributes, attributes_mask);
00162     gdk_window_set_user_data(drawingarea->inner_window, widget);
00163 
00164     /* set the default pixmap to None so that you don't end up with the
00165        gtk default which is BlackPixel. */
00166     gdk_window_set_back_pixmap(drawingarea->inner_window, NULL, FALSE);
00167 }
00168 
00169 void
00170 moz_drawingarea_finalize (GObject *object)
00171 {
00172     MozDrawingarea *drawingarea;
00173 
00174     g_return_if_fail(IS_MOZ_DRAWINGAREA(object));
00175 
00176     drawingarea = MOZ_DRAWINGAREA(object);
00177 
00178     gdk_window_set_user_data(drawingarea->inner_window, NULL);
00179     gdk_window_destroy(drawingarea->inner_window);
00180     gdk_window_set_user_data(drawingarea->clip_window, NULL);
00181     gdk_window_destroy(drawingarea->clip_window);
00182 
00183     (* parent_class->finalize) (object);
00184 }
00185 
00186 void
00187 moz_drawingarea_move (MozDrawingarea *drawingarea,
00188                       gint x, gint y)
00189 {
00190     gdk_window_move(drawingarea->clip_window, x, y);
00191 }
00192 
00193 void
00194 moz_drawingarea_resize (MozDrawingarea *drawingarea,
00195                         gint width, gint height)
00196 {
00197     gdk_window_resize(drawingarea->clip_window, width, height);
00198     gdk_window_resize(drawingarea->inner_window, width, height);
00199 }
00200 
00201 void
00202 moz_drawingarea_move_resize (MozDrawingarea *drawingarea,
00203                              gint x, gint y, gint width, gint height)
00204 {
00205     gdk_window_resize(drawingarea->inner_window, width, height);
00206     gdk_window_move_resize(drawingarea->clip_window, x, y, width, height);
00207 }
00208 
00209 void
00210 moz_drawingarea_set_visibility (MozDrawingarea *drawingarea,
00211                                 gboolean visibility)
00212 {
00213     if (visibility) {
00214         gdk_window_show_unraised(drawingarea->inner_window);
00215         gdk_window_show_unraised(drawingarea->clip_window);
00216     }
00217     else    {
00218         gdk_window_hide(drawingarea->clip_window);
00219         gdk_window_hide(drawingarea->inner_window);
00220     }
00221 }
00222 
00223 void
00224 moz_drawingarea_scroll (MozDrawingarea *drawingarea,
00225                         gint x, gint y)
00226 {
00227     gdk_window_scroll(drawingarea->inner_window, x, y);
00228 }