gtk: Add GtkStylablePicture

This interface allows adding styling information to GdkPicture
subclasses that can be used by widgets to draw them.
This commit is contained in:
Benjamin Otte 2011-02-05 15:16:01 +01:00
parent e56f013698
commit 9668dcba7d
4 changed files with 144 additions and 0 deletions

View File

@ -296,6 +296,7 @@ gtk_public_h_sources = \
gtkstatusbar.h \
gtkstatusicon.h \
gtkstock.h \
gtkstylablepicture.h \
gtkstylecontext.h \
gtkstyleproperties.h \
gtkstyleprovider.h \
@ -622,6 +623,7 @@ gtk_base_c_sources = \
gtkstatusbar.c \
gtkstatusicon.c \
gtkstock.c \
gtkstylablepicture.c \
gtkstylecontext.c \
gtkstyleproperties.c \
gtkstyleprovider.c \

View File

@ -179,6 +179,7 @@
#include <gtk/gtkstatusbar.h>
#include <gtk/gtkstatusicon.h>
#include <gtk/gtkstock.h>
#include <gtk/gtkstylablepicture.h>
#include <gtk/gtkstylecontext.h>
#include <gtk/gtkstyleproperties.h>
#include <gtk/gtkstyleprovider.h>

78
gtk/gtkstylablepicture.c Normal file
View File

@ -0,0 +1,78 @@
/* gtktreesortable.c
* Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "gtkstylablepicture.h"
#include "gtkintl.h"
/**
* SECTION:gtkstylablepicture
* @Short_description: Pictures that can be styled when attached to widgets
* @Title: GtkStylablePicture
* @See_also:#GdkPicture, #GtkWidget
*
* #GtkStylablePicture is an interface to be implemented by pictures that can be
* styled according to a #GtkWidget's #GtkStyleContext.
*/
G_DEFINE_INTERFACE (GtkStylablePicture, gtk_stylable_picture, GDK_TYPE_PICTURE)
static void
gtk_stylable_picture_default_init (GtkStylablePictureInterface *iface)
{
}
GdkPicture *
gtk_widget_style_picture (GtkWidget *widget,
GdkPicture *picture)
{
GtkStylablePictureInterface *iface;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (GDK_IS_PICTURE (picture), NULL);
if (!GTK_IS_STYLABLE_PICTURE (picture))
return g_object_ref (picture);
iface = GTK_STYLABLE_PICTURE_GET_IFACE (picture);
if (iface->attach == NULL)
return g_object_ref (picture);
return (* iface->attach) (picture, widget);
}
GdkPicture *
gtk_picture_get_unstyled (GdkPicture *styled)
{
GtkStylablePictureInterface *iface;
g_return_val_if_fail (GDK_IS_PICTURE (styled), NULL);
if (!GTK_IS_STYLABLE_PICTURE (styled))
return styled;
iface = GTK_STYLABLE_PICTURE_GET_IFACE (styled);
if (iface->get_unstyled == NULL)
return styled;
return iface->get_unstyled (styled);
}

63
gtk/gtkstylablepicture.h Normal file
View File

@ -0,0 +1,63 @@
/* gtktreesortable.h
* Copyright (C) 2001 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#ifndef __GTK_STYLABLE_PICTURE_H__
#define __GTK_STYLABLE_PICTURE_H__
#include <gdk/gdk.h>
#include <gtk/gtkwidget.h>
G_BEGIN_DECLS
#define GTK_TYPE_STYLABLE_PICTURE (gtk_stylable_picture_get_type ())
#define GTK_STYLABLE_PICTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_STYLABLE_PICTURE, GtkStylablePicture))
#define GTK_STYLABLE_PICTURE_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GTK_TYPE_STYLABLE_PICTURE, GtkStylablePictureInterface))
#define GTK_IS_STYLABLE_PICTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_STYLABLE_PICTURE))
#define GTK_STYLABLE_PICTURE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_STYLABLE_PICTURE, GtkStylablePictureInterface))
typedef struct _GtkStylablePicture GtkStylablePicture; /* Dummy typedef */
typedef struct _GtkStylablePictureInterface GtkStylablePictureInterface;
struct _GtkStylablePictureInterface
{
GTypeInterface g_iface;
/* virtual table */
GdkPicture * (* attach) (GdkPicture *picture,
GtkWidget *widget);
GdkPicture * (* get_unstyled) (GdkPicture *picture);
};
GType gtk_stylable_picture_get_type (void) G_GNUC_CONST;
GdkPicture * gtk_widget_style_picture (GtkWidget *widget,
GdkPicture *picture);
GdkPicture * gtk_picture_get_unstyled (GdkPicture *styled);
G_END_DECLS
#endif /* __GTK_STYLABLE_PICTURE_H__ */