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 * @typedef IrrecoScrolledWindow
25 * A GtkScrolledWindow with automatic resising to fit client widgets.
28 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
30 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
31 static void irreco_scrolled_window_size_request(GtkWidget
*widget
,
32 GtkRequisition
*requisition
,
33 IrrecoScrolledWindow
*self
);
37 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
38 /* Construction & Destruction */
39 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 G_DEFINE_TYPE(IrrecoScrolledWindow
, irreco_scrolled_window
, GTK_TYPE_SCROLLED_WINDOW
)
43 static void irreco_scrolled_window_finalize(GObject
*object
)
45 G_OBJECT_CLASS(irreco_scrolled_window_parent_class
)->finalize (object
);
48 static void irreco_scrolled_window_class_init(IrrecoScrolledWindowClass
*klass
)
50 GObjectClass
*object_class
= G_OBJECT_CLASS(klass
);
51 object_class
->finalize
= irreco_scrolled_window_finalize
;
54 static void irreco_scrolled_window_init(IrrecoScrolledWindow
*self
)
58 /* Setup scrolled window. */
59 gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(self
), NULL
);
60 gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(self
), NULL
);
61 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self
),
63 GTK_POLICY_AUTOMATIC
);
65 /* Create container for child. We use this container to make sure that
66 possible extra space inside the scrolled_window is not allocated to
68 self
->alignment
= gtk_alignment_new(0, 0, 0, 0);
69 gtk_alignment_set_padding(GTK_ALIGNMENT(self
->alignment
), 0, 0, 0, 0);
70 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(self
),
73 /* Connect signals. */
74 g_signal_connect(G_OBJECT(self
), "size-request",
75 G_CALLBACK(irreco_scrolled_window_size_request
),
81 GtkWidget
* irreco_scrolled_window_new(void)
84 IRRECO_RETURN_PTR(g_object_new(IRRECO_TYPE_SCROLLED_WINDOW
, NULL
));
87 GtkWidget
* irreco_scrolled_window_new_with_autoresize(gint width_min
,
92 IrrecoScrolledWindow
*self
;
95 self
= g_object_new(IRRECO_TYPE_SCROLLED_WINDOW
, NULL
);
96 irreco_scrolled_window_set_autoresize(self
, width_min
, width_max
,
97 height_min
, height_max
);
98 IRRECO_RETURN_PTR(self
);
103 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
105 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
107 void irreco_scrolled_window_set_autoresize(IrrecoScrolledWindow
*self
,
114 if ((self
->width_min
= width_min
) < 0) self
->width_min
= 0;
115 if ((self
->width_max
= width_max
) < 0) self
->width_max
= 0;
116 if ((self
->height_min
= height_min
) < 0) self
->height_min
= 0;
117 if ((self
->height_max
= height_max
) < 0) self
->height_max
= 0;
121 void irreco_scrolled_window_add(IrrecoScrolledWindow
*self
,
125 self
->child
= widget
;
126 gtk_container_add(GTK_CONTAINER(self
->alignment
), widget
);
132 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
133 /* Events and Callbacks */
134 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
136 static void irreco_scrolled_window_size_request(GtkWidget
*widget
,
137 GtkRequisition
*requisition
,
138 IrrecoScrolledWindow
*self
)
140 GtkRequisition child_req
;
141 gint scrollbar_space
= 30;
142 /*GtkAdjustment *adj;*/
145 if (self
->child
== NULL
) IRRECO_RETURN
;
147 gtk_widget_size_request(self
->child
, &child_req
);
148 IRRECO_DEBUG("Child size requisition: w%i h%i\n",
153 if (self
->height_min
> child_req
.height
) {
154 requisition
->height
= self
->height_min
;
156 requisition
->height
= child_req
.height
;
158 if (self
->height_max
> 0
159 && requisition
->height
> self
->height_max
) {
160 requisition
->height
= self
->height_max
;
164 if (self
->width_min
> child_req
.width
) {
165 requisition
->width
= self
->width_min
+ scrollbar_space
;
167 requisition
->width
= child_req
.width
+ scrollbar_space
;
169 if (self
->width_max
> 0
170 && requisition
->width
> self
->width_max
) {
171 requisition
->width
= self
->width_max
;
174 IRRECO_DEBUG("Size requisition: w%i h%i\n",
176 requisition
->height
);