Blame gtk/gtkinvisible.c

Packit Service fb6fa5
/* GTK - The GIMP Toolkit
Packit Service fb6fa5
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is free software; you can redistribute it and/or
Packit Service fb6fa5
 * modify it under the terms of the GNU Lesser General Public
Packit Service fb6fa5
 * License as published by the Free Software Foundation; either
Packit Service fb6fa5
 * version 2 of the License, or (at your option) any later version.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is distributed in the hope that it will be useful,
Packit Service fb6fa5
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fb6fa5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service fb6fa5
 * Lesser General Public License for more details.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * You should have received a copy of the GNU Lesser General Public
Packit Service fb6fa5
 * License along with this library; if not, write to the
Packit Service fb6fa5
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service fb6fa5
 * Boston, MA 02111-1307, USA.
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
/*
Packit Service fb6fa5
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
Packit Service fb6fa5
 * file for a list of people on the GTK+ Team.  See the ChangeLog
Packit Service fb6fa5
 * files for a list of changes.  These files are distributed with
Packit Service fb6fa5
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
#include "config.h"
Packit Service fb6fa5
#include <gdk/gdk.h>
Packit Service fb6fa5
#include "gtkinvisible.h"
Packit Service fb6fa5
#include "gtkprivate.h"
Packit Service fb6fa5
#include "gtkintl.h"
Packit Service fb6fa5
#include "gtkalias.h"
Packit Service fb6fa5
Packit Service fb6fa5
enum {
Packit Service fb6fa5
  PROP_0,
Packit Service fb6fa5
  PROP_SCREEN,
Packit Service fb6fa5
  LAST_ARG
Packit Service fb6fa5
};
Packit Service fb6fa5
Packit Service fb6fa5
static void gtk_invisible_destroy       (GtkObject         *object);
Packit Service fb6fa5
static void gtk_invisible_realize       (GtkWidget         *widget);
Packit Service fb6fa5
static void gtk_invisible_style_set     (GtkWidget         *widget,
Packit Service fb6fa5
					 GtkStyle          *previous_style);
Packit Service fb6fa5
static void gtk_invisible_show          (GtkWidget         *widget);
Packit Service fb6fa5
static void gtk_invisible_size_allocate (GtkWidget         *widget,
Packit Service fb6fa5
					 GtkAllocation     *allocation);
Packit Service fb6fa5
static void gtk_invisible_set_property  (GObject           *object,
Packit Service fb6fa5
					 guint              prop_id,
Packit Service fb6fa5
					 const GValue      *value,
Packit Service fb6fa5
					 GParamSpec        *pspec);
Packit Service fb6fa5
static void gtk_invisible_get_property  (GObject           *object,
Packit Service fb6fa5
					 guint              prop_id,
Packit Service fb6fa5
					 GValue		   *value,
Packit Service fb6fa5
					 GParamSpec        *pspec);
Packit Service fb6fa5
Packit Service fb6fa5
static GObject *gtk_invisible_constructor (GType                  type,
Packit Service fb6fa5
					   guint                  n_construct_properties,
Packit Service fb6fa5
					   GObjectConstructParam *construct_params);
Packit Service fb6fa5
Packit Service fb6fa5
G_DEFINE_TYPE (GtkInvisible, gtk_invisible, GTK_TYPE_WIDGET)
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_invisible_class_init (GtkInvisibleClass *class)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GObjectClass	 *gobject_class;
Packit Service fb6fa5
  GtkObjectClass *object_class;
Packit Service fb6fa5
  GtkWidgetClass *widget_class;
Packit Service fb6fa5
Packit Service fb6fa5
  widget_class = (GtkWidgetClass*) class;
Packit Service fb6fa5
  object_class = (GtkObjectClass*) class;
Packit Service fb6fa5
  gobject_class = (GObjectClass*) class;
Packit Service fb6fa5
Packit Service fb6fa5
  widget_class->realize = gtk_invisible_realize;
Packit Service fb6fa5
  widget_class->style_set = gtk_invisible_style_set;
Packit Service fb6fa5
  widget_class->show = gtk_invisible_show;
Packit Service fb6fa5
  widget_class->size_allocate = gtk_invisible_size_allocate;
Packit Service fb6fa5
Packit Service fb6fa5
  object_class->destroy = gtk_invisible_destroy;
Packit Service fb6fa5
  gobject_class->set_property = gtk_invisible_set_property;
Packit Service fb6fa5
  gobject_class->get_property = gtk_invisible_get_property;
Packit Service fb6fa5
  gobject_class->constructor = gtk_invisible_constructor;
Packit Service fb6fa5
Packit Service fb6fa5
  g_object_class_install_property (gobject_class,
Packit Service fb6fa5
				   PROP_SCREEN,
Packit Service fb6fa5
				   g_param_spec_object ("screen",
Packit Service fb6fa5
 							P_("Screen"),
Packit Service fb6fa5
 							P_("The screen where this window will be displayed"),
Packit Service fb6fa5
							GDK_TYPE_SCREEN,
Packit Service fb6fa5
 							GTK_PARAM_READWRITE));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_invisible_init (GtkInvisible *invisible)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GdkColormap *colormap;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_widget_set_has_window (GTK_WIDGET (invisible), TRUE);
Packit Service fb6fa5
  _gtk_widget_set_is_toplevel (GTK_WIDGET (invisible), TRUE);
Packit Service fb6fa5
Packit Service fb6fa5
  g_object_ref_sink (invisible);
Packit Service fb6fa5
Packit Service fb6fa5
  invisible->has_user_ref_count = TRUE;
Packit Service fb6fa5
  invisible->screen = gdk_screen_get_default ();
Packit Service fb6fa5
  
Packit Service fb6fa5
  colormap = _gtk_widget_peek_colormap ();
Packit Service fb6fa5
  if (colormap)
Packit Service fb6fa5
    gtk_widget_set_colormap (GTK_WIDGET (invisible), colormap);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_invisible_destroy (GtkObject *object)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkInvisible *invisible = GTK_INVISIBLE (object);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (invisible->has_user_ref_count)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      invisible->has_user_ref_count = FALSE;
Packit Service fb6fa5
      g_object_unref (invisible);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  GTK_OBJECT_CLASS (gtk_invisible_parent_class)->destroy (object);  
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_invisible_new_for_screen:
Packit Service fb6fa5
 * @screen: a #GdkScreen which identifies on which
Packit Service fb6fa5
 *	    the new #GtkInvisible will be created.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Creates a new #GtkInvisible object for a specified screen
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: a newly created #GtkInvisible object
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.2
Packit Service fb6fa5
 **/
Packit Service fb6fa5
GtkWidget* 
Packit Service fb6fa5
gtk_invisible_new_for_screen (GdkScreen *screen)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_invisible_new:
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Creates a new #GtkInvisible.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Return value: a new #GtkInvisible.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
GtkWidget*
Packit Service fb6fa5
gtk_invisible_new (void)
Packit Service fb6fa5
{
Packit Service fb6fa5
  return g_object_new (GTK_TYPE_INVISIBLE, NULL);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_invisible_set_screen:
Packit Service fb6fa5
 * @invisible: a #GtkInvisible.
Packit Service fb6fa5
 * @screen: a #GdkScreen.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.2
Packit Service fb6fa5
 **/ 
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_invisible_set_screen (GtkInvisible *invisible,
Packit Service fb6fa5
			  GdkScreen    *screen)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkWidget *widget;
Packit Service fb6fa5
  GdkScreen *previous_screen;
Packit Service fb6fa5
  gboolean was_realized;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_INVISIBLE (invisible));
Packit Service fb6fa5
  g_return_if_fail (GDK_IS_SCREEN (screen));
Packit Service fb6fa5
Packit Service fb6fa5
  if (screen == invisible->screen)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
Packit Service fb6fa5
  widget = GTK_WIDGET (invisible);
Packit Service fb6fa5
Packit Service fb6fa5
  previous_screen = invisible->screen;
Packit Service fb6fa5
  was_realized = gtk_widget_get_realized (widget);
Packit Service fb6fa5
Packit Service fb6fa5
  if (was_realized)
Packit Service fb6fa5
    gtk_widget_unrealize (widget);
Packit Service fb6fa5
  
Packit Service fb6fa5
  invisible->screen = screen;
Packit Service fb6fa5
  if (screen != previous_screen)
Packit Service fb6fa5
    _gtk_widget_propagate_screen_changed (widget, previous_screen);
Packit Service fb6fa5
  g_object_notify (G_OBJECT (invisible), "screen");
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (was_realized)
Packit Service fb6fa5
    gtk_widget_realize (widget);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_invisible_get_screen:
Packit Service fb6fa5
 * @invisible: a #GtkInvisible.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Returns the #GdkScreen object associated with @invisible
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: (transfer none): the associated #GdkScreen.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.2
Packit Service fb6fa5
 **/
Packit Service fb6fa5
GdkScreen *
Packit Service fb6fa5
gtk_invisible_get_screen (GtkInvisible *invisible)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return invisible->screen;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_invisible_realize (GtkWidget *widget)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GdkWindow *parent;
Packit Service fb6fa5
  GdkWindowAttr attributes;
Packit Service fb6fa5
  gint attributes_mask;
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_set_realized (widget, TRUE);
Packit Service fb6fa5
Packit Service fb6fa5
  parent = gtk_widget_get_parent_window (widget);
Packit Service fb6fa5
  if (parent == NULL)
Packit Service fb6fa5
    parent = gtk_widget_get_root_window (widget);
Packit Service fb6fa5
Packit Service fb6fa5
  attributes.x = -100;
Packit Service fb6fa5
  attributes.y = -100;
Packit Service fb6fa5
  attributes.width = 10;
Packit Service fb6fa5
  attributes.height = 10;
Packit Service fb6fa5
  attributes.window_type = GDK_WINDOW_TEMP;
Packit Service fb6fa5
  attributes.wclass = GDK_INPUT_ONLY;
Packit Service fb6fa5
  attributes.override_redirect = TRUE;
Packit Service fb6fa5
  attributes.event_mask = gtk_widget_get_events (widget);
Packit Service fb6fa5
Packit Service fb6fa5
  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
Packit Service fb6fa5
Packit Service fb6fa5
  widget->window = gdk_window_new (parent, &attributes, attributes_mask);
Packit Service fb6fa5
					      
Packit Service fb6fa5
  gdk_window_set_user_data (widget->window, widget);
Packit Service fb6fa5
  
Packit Service fb6fa5
  widget->style = gtk_style_attach (widget->style, widget->window);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_invisible_style_set (GtkWidget *widget,
Packit Service fb6fa5
			 GtkStyle  *previous_style)
Packit Service fb6fa5
{
Packit Service fb6fa5
  /* Don't chain up to parent implementation */
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_invisible_show (GtkWidget *widget)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
Packit Service fb6fa5
  gtk_widget_map (widget);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_invisible_size_allocate (GtkWidget     *widget,
Packit Service fb6fa5
			    GtkAllocation *allocation)
Packit Service fb6fa5
{
Packit Service fb6fa5
  widget->allocation = *allocation;
Packit Service fb6fa5
} 
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
static void 
Packit Service fb6fa5
gtk_invisible_set_property  (GObject      *object,
Packit Service fb6fa5
			     guint         prop_id,
Packit Service fb6fa5
			     const GValue *value,
Packit Service fb6fa5
			     GParamSpec   *pspec)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkInvisible *invisible = GTK_INVISIBLE (object);
Packit Service fb6fa5
  
Packit Service fb6fa5
  switch (prop_id)
Packit Service fb6fa5
    {
Packit Service fb6fa5
    case PROP_SCREEN:
Packit Service fb6fa5
      gtk_invisible_set_screen (invisible, g_value_get_object (value));
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    default:
Packit Service fb6fa5
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void 
Packit Service fb6fa5
gtk_invisible_get_property  (GObject      *object,
Packit Service fb6fa5
			     guint         prop_id,
Packit Service fb6fa5
			     GValue	  *value,
Packit Service fb6fa5
			     GParamSpec   *pspec)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkInvisible *invisible = GTK_INVISIBLE (object);
Packit Service fb6fa5
Packit Service fb6fa5
  switch (prop_id)
Packit Service fb6fa5
    {
Packit Service fb6fa5
    case PROP_SCREEN:
Packit Service fb6fa5
      g_value_set_object (value, invisible->screen);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    default:
Packit Service fb6fa5
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* We use a constructor here so that we can realize the invisible on
Packit Service fb6fa5
 * the correct screen after the "screen" property has been set
Packit Service fb6fa5
 */
Packit Service fb6fa5
static GObject*
Packit Service fb6fa5
gtk_invisible_constructor (GType                  type,
Packit Service fb6fa5
			   guint                  n_construct_properties,
Packit Service fb6fa5
			   GObjectConstructParam *construct_params)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GObject *object;
Packit Service fb6fa5
Packit Service fb6fa5
  object = G_OBJECT_CLASS (gtk_invisible_parent_class)->constructor (type,
Packit Service fb6fa5
                                                                     n_construct_properties,
Packit Service fb6fa5
                                                                     construct_params);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_realize (GTK_WIDGET (object));
Packit Service fb6fa5
Packit Service fb6fa5
  return object;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
#define __GTK_INVISIBLE_C__
Packit Service fb6fa5
#include "gtkaliasdef.c"