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"
23 * @addtogroup IrrecoScrolledWindow
26 * A GtkScrolledWindow with automatic resising to fit client widgets.
33 * Source file of @ref IrrecoScrolledWindow.
37 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
39 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 static void irreco_scrolled_window_size_request(GtkWidget
*widget
,
41 GtkRequisition
*requisition
,
42 IrrecoScrolledWindow
*self
);
46 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
47 /* Construction & Destruction */
48 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
51 * @name Construction & Destruction
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
)
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
),
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
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
),
87 /* Connect signals. */
88 g_signal_connect(G_OBJECT(self
), "size-request",
89 G_CALLBACK(irreco_scrolled_window_size_request
),
95 GtkWidget
* irreco_scrolled_window_new(void)
98 IRRECO_RETURN_PTR(g_object_new(IRRECO_TYPE_SCROLLED_WINDOW
, NULL
));
101 GtkWidget
* irreco_scrolled_window_new_with_autoresize(gint width_min
,
106 IrrecoScrolledWindow
*self
;
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
);
119 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
121 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
124 * @name Public Functions
128 void irreco_scrolled_window_set_autoresize(IrrecoScrolledWindow
*self
,
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;
142 void irreco_scrolled_window_add(IrrecoScrolledWindow
*self
,
146 self
->child
= widget
;
147 gtk_container_add(GTK_CONTAINER(self
->alignment
), widget
);
155 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
156 /* Events and Callbacks */
157 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
160 * @name Events and Callbacks
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;*/
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",
181 if (self
->height_min
> child_req
.height
) {
182 requisition
->height
= self
->height_min
;
184 requisition
->height
= child_req
.height
;
186 if (self
->height_max
> 0
187 && requisition
->height
> self
->height_max
) {
188 requisition
->height
= self
->height_max
;
192 if (self
->width_min
> child_req
.width
) {
193 requisition
->width
= self
->width_min
+ scrollbar_space
;
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",
204 requisition
->height
);