Blame plugins/gtk+/glade-gtk-fixed-layout.c

Packit 1e8aac
/*
Packit 1e8aac
 * glade-gtk-fixed-layout.c - GladeWidgetAdaptor for GtkFixed and GtkLayout
Packit 1e8aac
 *
Packit 1e8aac
 * Copyright (C) 2013 Tristan Van Berkom
Packit 1e8aac
 *
Packit 1e8aac
 * Authors:
Packit 1e8aac
 *      Tristan Van Berkom <tristan.van.berkom@gmail.com>
Packit 1e8aac
 *
Packit 1e8aac
 * This library is free software; you can redistribute it and/or modify it
Packit 1e8aac
 * under the terms of the GNU Lesser General Public License as
Packit 1e8aac
 * published by the Free Software Foundation; either version 2.1 of
Packit 1e8aac
 * the License, or (at your option) any later version.
Packit 1e8aac
 *
Packit 1e8aac
 * This library is distributed in the hope that it will be useful, but
Packit 1e8aac
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 1e8aac
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 1e8aac
 * Lesser General Public License for more details.
Packit 1e8aac
 *
Packit 1e8aac
 * You should have received a copy of the GNU Lesser General Public 
Packit 1e8aac
 * License along with this program; if not, write to the Free Software
Packit 1e8aac
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit 1e8aac
 */
Packit 1e8aac
Packit 1e8aac
#include <config.h>
Packit 1e8aac
#include <glib/gi18n-lib.h>
Packit 1e8aac
#include <gladeui/glade.h>
Packit 1e8aac
Packit 1e8aac
#include "glade-layout-editor.h"
Packit 1e8aac
Packit 1e8aac
GladeEditable *
Packit 1e8aac
glade_gtk_layout_create_editable (GladeWidgetAdaptor * adaptor,
Packit 1e8aac
				  GladeEditorPageType type)
Packit 1e8aac
{
Packit 1e8aac
  if (type == GLADE_PAGE_GENERAL)
Packit 1e8aac
    {
Packit 1e8aac
      return (GladeEditable *)glade_layout_editor_new ();
Packit 1e8aac
    }
Packit 1e8aac
Packit 1e8aac
  return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type);
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
static void
Packit 1e8aac
glade_gtk_fixed_layout_sync_size_requests (GtkWidget * widget)
Packit 1e8aac
{
Packit 1e8aac
  GList *children, *l;
Packit 1e8aac
Packit 1e8aac
  if ((children = gtk_container_get_children (GTK_CONTAINER (widget))) != NULL)
Packit 1e8aac
    {
Packit 1e8aac
      for (l = children; l; l = l->next)
Packit 1e8aac
        {
Packit 1e8aac
          GtkWidget *child = l->data;
Packit 1e8aac
          GladeWidget *gchild = glade_widget_get_from_gobject (child);
Packit 1e8aac
          gint width = -1, height = -1;
Packit 1e8aac
Packit 1e8aac
          if (!gchild)
Packit 1e8aac
            continue;
Packit 1e8aac
Packit 1e8aac
          glade_widget_property_get (gchild, "width-request", &width);
Packit 1e8aac
          glade_widget_property_get (gchild, "height-request", &height);
Packit 1e8aac
Packit 1e8aac
          gtk_widget_set_size_request (child, width, height);
Packit 1e8aac
Packit 1e8aac
        }
Packit 1e8aac
      g_list_free (children);
Packit 1e8aac
    }
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
static cairo_pattern_t *
Packit 1e8aac
get_fixed_layout_pattern (void)
Packit 1e8aac
{
Packit 1e8aac
  static cairo_pattern_t *static_pattern = NULL;
Packit 1e8aac
Packit 1e8aac
  if (!static_pattern)
Packit 1e8aac
    {
Packit 1e8aac
      gchar *path = g_build_filename (glade_app_get_pixmaps_dir (), "fixed-bg.png", NULL);
Packit 1e8aac
      cairo_surface_t *surface = 
Packit 1e8aac
	cairo_image_surface_create_from_png (path);
Packit 1e8aac
Packit 1e8aac
      if (surface)
Packit 1e8aac
	{
Packit 1e8aac
	  static_pattern = cairo_pattern_create_for_surface (surface);
Packit 1e8aac
	  cairo_pattern_set_extend (static_pattern, CAIRO_EXTEND_REPEAT);
Packit 1e8aac
	}
Packit 1e8aac
      else 
Packit 1e8aac
	g_warning ("Failed to create surface for %s\n", path);
Packit 1e8aac
Packit 1e8aac
      g_free (path);
Packit 1e8aac
    }
Packit 1e8aac
  return static_pattern;
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
static void
Packit 1e8aac
glade_gtk_fixed_layout_draw (GtkWidget *widget, cairo_t *cr)
Packit 1e8aac
{
Packit 1e8aac
  GtkAllocation allocation;
Packit 1e8aac
Packit 1e8aac
  gtk_widget_get_allocation (widget, &allocation);
Packit 1e8aac
Packit 1e8aac
  cairo_save (cr);
Packit 1e8aac
Packit 1e8aac
  cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
Packit 1e8aac
  cairo_set_source (cr, get_fixed_layout_pattern ());
Packit 1e8aac
  cairo_fill (cr);
Packit 1e8aac
Packit 1e8aac
  cairo_restore (cr);
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
void
Packit 1e8aac
glade_gtk_fixed_layout_post_create (GladeWidgetAdaptor * adaptor,
Packit 1e8aac
                                    GObject * object, GladeCreateReason reason)
Packit 1e8aac
{
Packit 1e8aac
  /* Set a minimun size so you can actually see it if you added to a box */
Packit 1e8aac
  gtk_widget_set_size_request (GTK_WIDGET (object), 32, 32);
Packit 1e8aac
Packit 1e8aac
  gtk_widget_set_has_window (GTK_WIDGET (object), TRUE);
Packit 1e8aac
  
Packit 1e8aac
  /* Sync up size request at project load time */
Packit 1e8aac
  if (reason == GLADE_CREATE_LOAD)
Packit 1e8aac
    g_signal_connect_after (object, "realize",
Packit 1e8aac
                            G_CALLBACK
Packit 1e8aac
                            (glade_gtk_fixed_layout_sync_size_requests), NULL);
Packit 1e8aac
Packit 1e8aac
  g_signal_connect (object, "draw",
Packit 1e8aac
		    G_CALLBACK (glade_gtk_fixed_layout_draw), NULL);
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
void
Packit 1e8aac
glade_gtk_fixed_layout_add_child (GladeWidgetAdaptor * adaptor,
Packit 1e8aac
                                  GObject * object, GObject * child)
Packit 1e8aac
{
Packit 1e8aac
  g_return_if_fail (GTK_IS_CONTAINER (object));
Packit 1e8aac
  g_return_if_fail (GTK_IS_WIDGET (child));
Packit 1e8aac
Packit 1e8aac
  gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child));
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
void
Packit 1e8aac
glade_gtk_fixed_layout_remove_child (GladeWidgetAdaptor * adaptor,
Packit 1e8aac
                                     GObject * object, GObject * child)
Packit 1e8aac
{
Packit 1e8aac
  g_return_if_fail (GTK_IS_CONTAINER (object));
Packit 1e8aac
  g_return_if_fail (GTK_IS_WIDGET (child));
Packit 1e8aac
Packit 1e8aac
  gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
Packit 1e8aac
}