gadget: Add GtkCssCustomGadget
The thing you use when you want to custom-do everything.
This commit is contained in:
		
				
					committed by
					
						
						Matthias Clasen
					
				
			
			
				
	
			
			
			
						parent
						
							6eafe00d8f
						
					
				
				
					commit
					e09eb4fc9f
				
			@ -386,7 +386,8 @@ gtk_private_h_sources =		\
 | 
				
			|||||||
	gtkcssbordervalueprivate.h	\
 | 
						gtkcssbordervalueprivate.h	\
 | 
				
			||||||
	gtkcsscolorvalueprivate.h	\
 | 
						gtkcsscolorvalueprivate.h	\
 | 
				
			||||||
	gtkcsscornervalueprivate.h	\
 | 
						gtkcsscornervalueprivate.h	\
 | 
				
			||||||
	gtkcsscustompropertyprivate.h \
 | 
						gtkcsscustomgadgetprivate.h	\
 | 
				
			||||||
 | 
						gtkcsscustompropertyprivate.h 	\
 | 
				
			||||||
	gtkcsseasevalueprivate.h	\
 | 
						gtkcsseasevalueprivate.h	\
 | 
				
			||||||
	gtkcssenginevalueprivate.h	\
 | 
						gtkcssenginevalueprivate.h	\
 | 
				
			||||||
	gtkcssenumvalueprivate.h	\
 | 
						gtkcssenumvalueprivate.h	\
 | 
				
			||||||
@ -640,6 +641,7 @@ gtk_base_c_sources = 		\
 | 
				
			|||||||
	gtkcssbordervalue.c	\
 | 
						gtkcssbordervalue.c	\
 | 
				
			||||||
	gtkcsscolorvalue.c	\
 | 
						gtkcsscolorvalue.c	\
 | 
				
			||||||
	gtkcsscornervalue.c	\
 | 
						gtkcsscornervalue.c	\
 | 
				
			||||||
 | 
						gtkcsscustomgadget.c	\
 | 
				
			||||||
	gtkcsscustomproperty.c	\
 | 
						gtkcsscustomproperty.c	\
 | 
				
			||||||
	gtkcsseasevalue.c	\
 | 
						gtkcsseasevalue.c	\
 | 
				
			||||||
	gtkcssenumvalue.c	\
 | 
						gtkcssenumvalue.c	\
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										180
									
								
								gtk/gtkcsscustomgadget.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										180
									
								
								gtk/gtkcsscustomgadget.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,180 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright © 2015 Red Hat Inc.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This library is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					 * modify it under the terms of the GNU Lesser General Public
 | 
				
			||||||
 | 
					 * License as published by the Free Software Foundation; either
 | 
				
			||||||
 | 
					 * version 2.1 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
 | 
				
			||||||
 | 
					 * Lesser General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Lesser General Public
 | 
				
			||||||
 | 
					 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Authors: Benjamin Otte <otte@gnome.org>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "gtkcsscustomgadgetprivate.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "gtkcssnodeprivate.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct _GtkCssCustomGadgetPrivate GtkCssCustomGadgetPrivate;
 | 
				
			||||||
 | 
					struct _GtkCssCustomGadgetPrivate {
 | 
				
			||||||
 | 
					  GtkCssPreferredSizeFunc          preferred_size_func;
 | 
				
			||||||
 | 
					  GtkCssAllocateFunc               allocate_func;
 | 
				
			||||||
 | 
					  GtkCssDrawFunc                   draw_func;
 | 
				
			||||||
 | 
					  gpointer                         data;
 | 
				
			||||||
 | 
					  GDestroyNotify                   destroy_func;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					G_DEFINE_TYPE_WITH_CODE (GtkCssCustomGadget, gtk_css_custom_gadget, GTK_TYPE_CSS_GADGET,
 | 
				
			||||||
 | 
					                         G_ADD_PRIVATE (GtkCssCustomGadget))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					gtk_css_custom_gadget_get_preferred_size (GtkCssGadget   *gadget,
 | 
				
			||||||
 | 
					                                          GtkOrientation  orientation,
 | 
				
			||||||
 | 
					                                          gint            for_size,
 | 
				
			||||||
 | 
					                                          gint           *minimum,
 | 
				
			||||||
 | 
					                                          gint           *natural,
 | 
				
			||||||
 | 
					                                          gint           *minimum_baseline,
 | 
				
			||||||
 | 
					                                          gint           *natural_baseline)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GtkCssCustomGadgetPrivate *priv = gtk_css_custom_gadget_get_instance_private (GTK_CSS_CUSTOM_GADGET (gadget));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (priv->preferred_size_func)
 | 
				
			||||||
 | 
					    return priv->preferred_size_func (gadget, orientation, for_size, 
 | 
				
			||||||
 | 
					                                      minimum, natural,
 | 
				
			||||||
 | 
					                                      minimum_baseline, natural_baseline,
 | 
				
			||||||
 | 
					                                      priv->data);
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    return GTK_CSS_GADGET_CLASS (gtk_css_custom_gadget_parent_class)->get_preferred_size (gadget, orientation, for_size, 
 | 
				
			||||||
 | 
					                                                                                          minimum, natural,
 | 
				
			||||||
 | 
					                                                                                          minimum_baseline, natural_baseline);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					gtk_css_custom_gadget_allocate (GtkCssGadget        *gadget,
 | 
				
			||||||
 | 
					                                const GtkAllocation *allocation,
 | 
				
			||||||
 | 
					                                int                  baseline,
 | 
				
			||||||
 | 
					                                GtkAllocation       *out_clip)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GtkCssCustomGadgetPrivate *priv = gtk_css_custom_gadget_get_instance_private (GTK_CSS_CUSTOM_GADGET (gadget));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (priv->allocate_func)
 | 
				
			||||||
 | 
					    return priv->allocate_func (gadget, allocation, baseline, out_clip, priv->data);
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    return GTK_CSS_GADGET_CLASS (gtk_css_custom_gadget_parent_class)->allocate (gadget, allocation, baseline, out_clip);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static gboolean
 | 
				
			||||||
 | 
					gtk_css_custom_gadget_draw (GtkCssGadget *gadget,
 | 
				
			||||||
 | 
					                            cairo_t      *cr,
 | 
				
			||||||
 | 
					                            int           x,
 | 
				
			||||||
 | 
					                            int           y,
 | 
				
			||||||
 | 
					                            int           width,
 | 
				
			||||||
 | 
					                            int           height)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GtkCssCustomGadgetPrivate *priv = gtk_css_custom_gadget_get_instance_private (GTK_CSS_CUSTOM_GADGET (gadget));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (priv->draw_func)
 | 
				
			||||||
 | 
					    return priv->draw_func (gadget, cr, x, y, width, height, priv->data);
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    return GTK_CSS_GADGET_CLASS (gtk_css_custom_gadget_parent_class)->draw (gadget, cr, x, y, width, height);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					gtk_css_custom_gadget_finalize (GObject *object)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GtkCssCustomGadgetPrivate *priv = gtk_css_custom_gadget_get_instance_private (GTK_CSS_CUSTOM_GADGET (object));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (priv->destroy_func)
 | 
				
			||||||
 | 
					    priv->destroy_func (priv->data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  G_OBJECT_CLASS (gtk_css_custom_gadget_parent_class)->finalize (object);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					gtk_css_custom_gadget_class_init (GtkCssCustomGadgetClass *klass)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GtkCssGadgetClass *gadget_class = GTK_CSS_GADGET_CLASS (klass);
 | 
				
			||||||
 | 
					  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  object_class->finalize = gtk_css_custom_gadget_finalize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  gadget_class->get_preferred_size = gtk_css_custom_gadget_get_preferred_size;
 | 
				
			||||||
 | 
					  gadget_class->allocate = gtk_css_custom_gadget_allocate;
 | 
				
			||||||
 | 
					  gadget_class->draw = gtk_css_custom_gadget_draw;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					gtk_css_custom_gadget_init (GtkCssCustomGadget *custom_gadget)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GtkCssGadget *
 | 
				
			||||||
 | 
					gtk_css_custom_gadget_new_for_node (GtkCssNode                 *node,
 | 
				
			||||||
 | 
					                                    GtkWidget                  *owner,
 | 
				
			||||||
 | 
					                                    GtkCssPreferredSizeFunc     preferred_size_func,
 | 
				
			||||||
 | 
					                                    GtkCssAllocateFunc          allocate_func,
 | 
				
			||||||
 | 
					                                    GtkCssDrawFunc              draw_func,
 | 
				
			||||||
 | 
					                                    gpointer                    data,
 | 
				
			||||||
 | 
					                                    GDestroyNotify              destroy_func)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GtkCssCustomGadgetPrivate *priv;
 | 
				
			||||||
 | 
					  GtkCssGadget *result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  result = g_object_new (GTK_TYPE_CSS_CUSTOM_GADGET,
 | 
				
			||||||
 | 
					                         "node", node,
 | 
				
			||||||
 | 
					                         "owner", owner,
 | 
				
			||||||
 | 
					                         NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  priv = gtk_css_custom_gadget_get_instance_private (GTK_CSS_CUSTOM_GADGET (result));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  priv->preferred_size_func = preferred_size_func;
 | 
				
			||||||
 | 
					  priv->allocate_func = allocate_func;
 | 
				
			||||||
 | 
					  priv->draw_func = draw_func;
 | 
				
			||||||
 | 
					  priv->data = data;
 | 
				
			||||||
 | 
					  priv->destroy_func = destroy_func;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return result;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GtkCssGadget *
 | 
				
			||||||
 | 
					gtk_css_custom_gadget_new (const char                 *name,
 | 
				
			||||||
 | 
					                           GtkWidget                  *owner,
 | 
				
			||||||
 | 
					                           GtkCssGadget               *parent,
 | 
				
			||||||
 | 
					                           GtkCssGadget               *next_sibling,
 | 
				
			||||||
 | 
					                           GtkCssPreferredSizeFunc     preferred_size_func,
 | 
				
			||||||
 | 
					                           GtkCssAllocateFunc          allocate_func,
 | 
				
			||||||
 | 
					                           GtkCssDrawFunc              draw_func,
 | 
				
			||||||
 | 
					                           gpointer                    data,
 | 
				
			||||||
 | 
					                           GDestroyNotify              destroy_func)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GtkCssNode *node;
 | 
				
			||||||
 | 
					  GtkCssGadget *result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  node = gtk_css_node_new ();
 | 
				
			||||||
 | 
					  gtk_css_node_set_name (node, g_intern_string (name));
 | 
				
			||||||
 | 
					  if (parent)
 | 
				
			||||||
 | 
					    gtk_css_node_insert_before (gtk_css_gadget_get_node (parent),
 | 
				
			||||||
 | 
					                                node,
 | 
				
			||||||
 | 
					                                next_sibling ? gtk_css_gadget_get_node (next_sibling) : NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  result = gtk_css_custom_gadget_new_for_node (node,
 | 
				
			||||||
 | 
					                                               owner,
 | 
				
			||||||
 | 
					                                               preferred_size_func,
 | 
				
			||||||
 | 
					                                               allocate_func,
 | 
				
			||||||
 | 
					                                               draw_func,
 | 
				
			||||||
 | 
					                                               data,
 | 
				
			||||||
 | 
					                                               destroy_func);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_object_unref (node);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return result;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										88
									
								
								gtk/gtkcsscustomgadgetprivate.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								gtk/gtkcsscustomgadgetprivate.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,88 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright © 2015 Red Hat Inc.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This library is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					 * modify it under the terms of the GNU Lesser General Public
 | 
				
			||||||
 | 
					 * License as published by the Free Software Foundation; either
 | 
				
			||||||
 | 
					 * version 2.1 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
 | 
				
			||||||
 | 
					 * Lesser General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Lesser General Public
 | 
				
			||||||
 | 
					 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Authors: Benjamin Otte <otte@gnome.org>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __GTK_CSS_CUSTOM_GADGET_PRIVATE_H__
 | 
				
			||||||
 | 
					#define __GTK_CSS_CUSTOM_GADGET_PRIVATE_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "gtk/gtkcssgadgetprivate.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					G_BEGIN_DECLS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define GTK_TYPE_CSS_CUSTOM_GADGET           (gtk_css_custom_gadget_get_type ())
 | 
				
			||||||
 | 
					#define GTK_CSS_CUSTOM_GADGET(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_CUSTOM_GADGET, GtkCssCustomGadget))
 | 
				
			||||||
 | 
					#define GTK_CSS_CUSTOM_GADGET_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_CUSTOM_GADGET, GtkCssCustomGadgetClass))
 | 
				
			||||||
 | 
					#define GTK_IS_CSS_CUSTOM_GADGET(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_CUSTOM_GADGET))
 | 
				
			||||||
 | 
					#define GTK_IS_CSS_CUSTOM_GADGET_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_CUSTOM_GADGET))
 | 
				
			||||||
 | 
					#define GTK_CSS_CUSTOM_GADGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_CUSTOM_GADGET, GtkCssCustomGadgetClass))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct _GtkCssCustomGadget           GtkCssCustomGadget;
 | 
				
			||||||
 | 
					typedef struct _GtkCssCustomGadgetClass      GtkCssCustomGadgetClass;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef void    (* GtkCssPreferredSizeFunc)             (GtkCssGadget           *gadget,
 | 
				
			||||||
 | 
					                                                         GtkOrientation          orientation,
 | 
				
			||||||
 | 
					                                                         gint                    for_size,
 | 
				
			||||||
 | 
					                                                         gint                   *minimum,
 | 
				
			||||||
 | 
					                                                         gint                   *natural,
 | 
				
			||||||
 | 
					                                                         gint                   *minimum_baseline,
 | 
				
			||||||
 | 
					                                                         gint                   *natural_baseline,
 | 
				
			||||||
 | 
					                                                         gpointer                data);
 | 
				
			||||||
 | 
					typedef void    (* GtkCssAllocateFunc)                  (GtkCssGadget           *gadget,
 | 
				
			||||||
 | 
					                                                         const GtkAllocation    *allocation,
 | 
				
			||||||
 | 
					                                                         int                     baseline,
 | 
				
			||||||
 | 
					                                                         GtkAllocation          *out_clip,
 | 
				
			||||||
 | 
					                                                         gpointer                data);
 | 
				
			||||||
 | 
					typedef gboolean (* GtkCssDrawFunc)                     (GtkCssGadget           *gadget,
 | 
				
			||||||
 | 
					                                                         cairo_t                *cr,
 | 
				
			||||||
 | 
					                                                         int                     x,
 | 
				
			||||||
 | 
					                                                         int                     y,
 | 
				
			||||||
 | 
					                                                         int                     width,
 | 
				
			||||||
 | 
					                                                         int                     height,
 | 
				
			||||||
 | 
					                                                         gpointer                data);
 | 
				
			||||||
 | 
					struct _GtkCssCustomGadget
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GtkCssGadget parent;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct _GtkCssCustomGadgetClass
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  GtkCssGadgetClass  parent_class;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GType           gtk_css_custom_gadget_get_type                 (void) G_GNUC_CONST;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GtkCssGadget *  gtk_css_custom_gadget_new                      (const char                      *name,
 | 
				
			||||||
 | 
					                                                                GtkWidget                       *owner,
 | 
				
			||||||
 | 
					                                                                GtkCssGadget                    *parent,
 | 
				
			||||||
 | 
					                                                                GtkCssGadget                    *next_sibling,
 | 
				
			||||||
 | 
					                                                                GtkCssPreferredSizeFunc          get_preferred_size_func,
 | 
				
			||||||
 | 
					                                                                GtkCssAllocateFunc               allocate_func,
 | 
				
			||||||
 | 
					                                                                GtkCssDrawFunc                   draw_func,
 | 
				
			||||||
 | 
					                                                                gpointer                         data,
 | 
				
			||||||
 | 
					                                                                GDestroyNotify                   destroy_func);
 | 
				
			||||||
 | 
					GtkCssGadget *  gtk_css_custom_gadget_new_for_node             (GtkCssNode                      *node,
 | 
				
			||||||
 | 
					                                                                GtkWidget                       *owner,
 | 
				
			||||||
 | 
					                                                                GtkCssPreferredSizeFunc          preferred_size_func,
 | 
				
			||||||
 | 
					                                                                GtkCssAllocateFunc               allocate_func,
 | 
				
			||||||
 | 
					                                                                GtkCssDrawFunc                   draw_func,
 | 
				
			||||||
 | 
					                                                                gpointer                         data,
 | 
				
			||||||
 | 
					                                                                GDestroyNotify                   destroy_func);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					G_END_DECLS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* __GTK_CSS_CUSTOM_GADGET_PRIVATE_H__ */
 | 
				
			||||||
		Reference in New Issue
	
	Block a user