remove IRRECO_PAUSE
[irreco.git] / irreco / src / core / irreco_scrolled_window.c
blobc0685752dc4cd31f65e43f38e1425801a16ddcea
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "irreco_scrolled_window.h"
22 /**
23 * @addtogroup IrrecoScrolledWindow
24 * @ingroup Irreco
26 * A GtkScrolledWindow with automatic resising to fit client widgets.
28 * @{
31 /**
32 * @file
33 * Source file of @ref IrrecoScrolledWindow.
37 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
38 /* Prototypes */
39 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 static void irreco_scrolled_window_size_request(GtkWidget *widget,
41 GtkRequisition *requisition,
42 IrrecoScrolledWindow *self);
46 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
47 /* Construction & Destruction */
48 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
50 /**
51 * @name Construction & Destruction
52 * @{
55 G_DEFINE_TYPE(IrrecoScrolledWindow, irreco_scrolled_window, GTK_TYPE_SCROLLED_WINDOW)
57 static void irreco_scrolled_window_finalize(GObject *object)
59 G_OBJECT_CLASS(irreco_scrolled_window_parent_class)->finalize (object);
62 static void irreco_scrolled_window_class_init(IrrecoScrolledWindowClass *klass)
64 GObjectClass *object_class = G_OBJECT_CLASS(klass);
65 object_class->finalize = irreco_scrolled_window_finalize;
68 static void irreco_scrolled_window_init(IrrecoScrolledWindow *self)
70 IRRECO_ENTER
72 /* Setup scrolled window. */
73 gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(self), NULL);
74 gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(self), NULL);
75 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self),
76 GTK_POLICY_AUTOMATIC,
77 GTK_POLICY_AUTOMATIC);
79 /* Create container for child. We use this container to make sure that
80 possible extra space inside the scrolled_window is not allocated to
81 the child widget. */
82 self->alignment = gtk_alignment_new(0, 0, 0, 0);
83 gtk_alignment_set_padding(GTK_ALIGNMENT(self->alignment), 0, 0, 0, 0);
84 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(self),
85 self->alignment);
87 /* Connect signals. */
88 g_signal_connect(G_OBJECT(self), "size-request",
89 G_CALLBACK(irreco_scrolled_window_size_request),
90 self);
92 IRRECO_RETURN
95 GtkWidget* irreco_scrolled_window_new(void)
97 IRRECO_ENTER
98 IRRECO_RETURN_PTR(g_object_new(IRRECO_TYPE_SCROLLED_WINDOW, NULL));
101 GtkWidget* irreco_scrolled_window_new_with_autoresize(gint width_min,
102 gint width_max,
103 gint height_min,
104 gint height_max)
106 IrrecoScrolledWindow *self;
107 IRRECO_ENTER
109 self = g_object_new(IRRECO_TYPE_SCROLLED_WINDOW, NULL);
110 irreco_scrolled_window_set_autoresize(self, width_min, width_max,
111 height_min, height_max);
112 IRRECO_RETURN_PTR(self);
115 /** @} */
119 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
120 /* Functions */
121 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
124 * @name Public Functions
125 * @{
128 void irreco_scrolled_window_set_autoresize(IrrecoScrolledWindow *self,
129 gint width_min,
130 gint width_max,
131 gint height_min,
132 gint height_max)
134 IRRECO_ENTER
135 if ((self->width_min = width_min) < 0) self->width_min = 0;
136 if ((self->width_max = width_max) < 0) self->width_max = 0;
137 if ((self->height_min = height_min) < 0) self->height_min = 0;
138 if ((self->height_max = height_max) < 0) self->height_max = 0;
139 IRRECO_RETURN
142 void irreco_scrolled_window_add(IrrecoScrolledWindow *self,
143 GtkWidget *widget)
145 IRRECO_ENTER
146 self->child = widget;
147 gtk_container_add(GTK_CONTAINER(self->alignment), widget);
148 IRRECO_RETURN
151 /** @} */
155 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
156 /* Events and Callbacks */
157 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
160 * @name Events and Callbacks
161 * @{
164 static void irreco_scrolled_window_size_request(GtkWidget *widget,
165 GtkRequisition *requisition,
166 IrrecoScrolledWindow *self)
168 GtkRequisition child_req;
169 gint scrollbar_space = 30;
170 /*GtkAdjustment *adj;*/
171 IRRECO_ENTER
173 if (self->child == NULL) IRRECO_RETURN;
175 gtk_widget_size_request(self->child, &child_req);
176 IRRECO_DEBUG("Child size requisition: w%i h%i\n",
177 child_req.width,
178 child_req.height);
180 /* Height */
181 if (self->height_min > child_req.height) {
182 requisition->height = self->height_min;
183 } else {
184 requisition->height = child_req.height;
186 if (self->height_max > 0
187 && requisition->height > self->height_max) {
188 requisition->height = self->height_max;
191 /* Width */
192 if (self->width_min > child_req.width) {
193 requisition->width = self->width_min + scrollbar_space;
194 } else {
195 requisition->width = child_req.width + scrollbar_space;
197 if (self->width_max > 0
198 && requisition->width > self->width_max) {
199 requisition->width = self->width_max;
202 IRRECO_DEBUG("Size requisition: w%i h%i\n",
203 requisition->width,
204 requisition->height);
206 IRRECO_RETURN
209 /** @} */
210 /** @} */