1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 * Copyright (C) 2013 Red Hat, Inc.
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.";
19 #include "polari-fixed-size-frame.h"
21 struct _PolariFixedSizeFramePrivate {
36 static GParamSpec *props[LAST_PROP];
39 polari_fixed_size_frame_buildable_init (GtkBuildableIface *iface);
41 G_DEFINE_TYPE_WITH_CODE (PolariFixedSizeFrame, polari_fixed_size_frame,
43 G_ADD_PRIVATE (PolariFixedSizeFrame)
44 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
45 polari_fixed_size_frame_buildable_init))
48 polari_fixed_size_frame_buildable_init (GtkBuildableIface *iface)
53 queue_redraw (PolariFixedSizeFrame *self)
55 GtkWidget *child = gtk_bin_get_child (GTK_BIN (self));
58 gtk_widget_queue_resize (child);
60 gtk_widget_queue_draw (GTK_WIDGET (self));
64 polari_fixed_size_frame_set_width (PolariFixedSizeFrame *self,
67 if (self->priv->width != width)
69 self->priv->width = width;
70 g_object_notify_by_pspec (G_OBJECT (self), props[PROP_WIDTH]);
77 polari_fixed_size_frame_set_height (PolariFixedSizeFrame *self,
80 if (self->priv->height != height)
82 self->priv->height = height;
83 g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HEIGHT]);
90 polari_fixed_size_frame_set_property (GObject *object,
95 PolariFixedSizeFrame *self = POLARI_FIXED_SIZE_FRAME (object);
100 polari_fixed_size_frame_set_width(self, g_value_get_int (value));
103 polari_fixed_size_frame_set_height(self, g_value_get_int (value));
106 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
111 polari_fixed_size_frame_get_property (GObject *object,
116 PolariFixedSizeFrame *self = POLARI_FIXED_SIZE_FRAME (object);
121 g_value_set_int (value, self->priv->width);
124 g_value_set_int (value, self->priv->height);
127 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
132 polari_fixed_size_frame_get_preferred_width (GtkWidget *widget,
136 PolariFixedSizeFrame *self = POLARI_FIXED_SIZE_FRAME (widget);
138 if (self->priv->width == -1)
140 GTK_WIDGET_CLASS (polari_fixed_size_frame_parent_class)->get_preferred_width (widget, minimum_size, natural_size);
144 *minimum_size = *natural_size = self->priv->width;
149 polari_fixed_size_frame_get_preferred_height (GtkWidget *widget,
153 PolariFixedSizeFrame *self = POLARI_FIXED_SIZE_FRAME (widget);
155 if (self->priv->height == -1)
157 GTK_WIDGET_CLASS (polari_fixed_size_frame_parent_class)->get_preferred_height (widget, minimum_size, natural_size);
161 *minimum_size = *natural_size = self->priv->height;
166 polari_fixed_size_frame_class_init (PolariFixedSizeFrameClass *klass)
168 GObjectClass *object_class = G_OBJECT_CLASS (klass);
169 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
170 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
172 object_class->get_property = polari_fixed_size_frame_get_property;
173 object_class->set_property = polari_fixed_size_frame_set_property;
174 widget_class->get_preferred_width =
175 polari_fixed_size_frame_get_preferred_width;
176 widget_class->get_preferred_height =
177 polari_fixed_size_frame_get_preferred_height;
178 gtk_container_class_handle_border_width (container_class);
181 g_param_spec_int ("width",
183 "Fixed width of the widget, or -1 to use the child's "
191 g_param_spec_int ("height",
193 "Fixed height of the widget, or -1 to use the child's "
200 g_object_class_install_properties (object_class, LAST_PROP, props);
204 polari_fixed_size_frame_init (PolariFixedSizeFrame *self)
206 self->priv = polari_fixed_size_frame_get_instance_private (self),
207 self->priv->width = -1;
208 self->priv->height = -1;