gnome-shell-3.6.3.1/src/st/st-border-image.c

No issues found

  1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
  2 /*
  3  * st-border-image.c: store information about an image with borders
  4  *
  5  * Copyright 2009, 2010 Red Hat, Inc.
  6  *
  7  * This program is free software; you can redistribute it and/or modify
  8  * it under the terms of the GNU Lesser General Public License as
  9  * published by the Free Software Foundation, either version 2.1 of
 10  * the License, or (at your option) any later version.
 11  *
 12  * This program is distributed in the hope it will be useful, but WITHOUT ANY
 13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 14  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 15  * more details.
 16  *
 17  * You should have received a copy of the GNU Lesser General Public License
 18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
 19  */
 20 
 21 #include <config.h>
 22 
 23 #include <string.h>
 24 
 25 #include "st-border-image.h"
 26 
 27 struct _StBorderImage {
 28   GObject parent;
 29 
 30   char *filename;
 31   int border_top;
 32   int border_right;
 33   int border_bottom;
 34   int border_left;
 35 };
 36 
 37 struct _StBorderImageClass {
 38   GObjectClass parent_class;
 39 
 40 };
 41 
 42 G_DEFINE_TYPE (StBorderImage, st_border_image, G_TYPE_OBJECT)
 43 
 44 static void
 45 st_border_image_finalize (GObject *object)
 46 {
 47   StBorderImage *image = ST_BORDER_IMAGE (object);
 48 
 49   g_free (image->filename);
 50 
 51   G_OBJECT_CLASS (st_border_image_parent_class)->finalize (object);
 52 }
 53 
 54 static void
 55 st_border_image_class_init (StBorderImageClass *klass)
 56 {
 57   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 58 
 59   object_class->finalize = st_border_image_finalize;
 60 }
 61 
 62 static void
 63 st_border_image_init (StBorderImage *image)
 64 {
 65 }
 66 
 67 StBorderImage *
 68 st_border_image_new (const char *filename,
 69                        int         border_top,
 70                        int         border_right,
 71                        int         border_bottom,
 72                        int         border_left)
 73 {
 74   StBorderImage *image;
 75 
 76   image = g_object_new (ST_TYPE_BORDER_IMAGE, NULL);
 77 
 78   image->filename = g_strdup (filename);
 79   image->border_top = border_top;
 80   image->border_right = border_right;
 81   image->border_bottom = border_bottom;
 82   image->border_left = border_left;
 83 
 84   return image;
 85 }
 86 
 87 const char *
 88 st_border_image_get_filename (StBorderImage *image)
 89 {
 90   g_return_val_if_fail (ST_IS_BORDER_IMAGE (image), NULL);
 91 
 92   return image->filename;
 93 }
 94 
 95 void
 96 st_border_image_get_borders (StBorderImage *image,
 97                              int           *border_top,
 98                              int           *border_right,
 99                              int           *border_bottom,
100                              int           *border_left)
101 {
102   g_return_if_fail (ST_IS_BORDER_IMAGE (image));
103 
104   if (border_top)
105     *border_top = image->border_top;
106   if (border_right)
107     *border_right = image->border_right;
108   if (border_bottom)
109     *border_bottom = image->border_bottom;
110   if (border_left)
111     *border_left = image->border_left;
112 }
113 
114 /**
115  * st_border_image_equal:
116  * @image: a #StBorder_Image
117  * @other: a different #StBorder_Image
118  *
119  * Check if two border_image objects are identical.
120  *
121  * Return value: %TRUE if the two border image objects are identical
122  */
123 gboolean
124 st_border_image_equal (StBorderImage *image,
125                        StBorderImage *other)
126 {
127   g_return_val_if_fail (ST_IS_BORDER_IMAGE (image), FALSE);
128   g_return_val_if_fail (ST_IS_BORDER_IMAGE (other), FALSE);
129 
130   return (image->border_top == other->border_top &&
131           image->border_right == other->border_right &&
132           image->border_bottom == other->border_bottom &&
133           image->border_left == other->border_left &&
134           strcmp (image->filename, other->filename) == 0);
135 }