Some documenting thingies.
[irreco.git] / irreco / trunk / src / core / irreco_scrolled_window.c
blob3bbc2af8a9f1d50a407a670ce666ae3445c6d099
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
4 *
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.
9 *
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 * @typedef IrrecoScrolledWindow
25 * A GtkScrolledWindow with automatic resising to fit client widgets.
28 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
29 /* Prototypes */
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)
56 IRRECO_ENTER
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),
62 GTK_POLICY_AUTOMATIC,
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
67 the child widget. */
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),
71 self->alignment);
73 /* Connect signals. */
74 g_signal_connect(G_OBJECT(self), "size-request",
75 G_CALLBACK(irreco_scrolled_window_size_request),
76 self);
78 IRRECO_RETURN
81 GtkWidget* irreco_scrolled_window_new(void)
83 IRRECO_ENTER
84 IRRECO_RETURN_PTR(g_object_new(IRRECO_TYPE_SCROLLED_WINDOW, NULL));
87 GtkWidget* irreco_scrolled_window_new_with_autoresize(gint width_min,
88 gint width_max,
89 gint height_min,
90 gint height_max)
92 IrrecoScrolledWindow *self;
93 IRRECO_ENTER
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 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
104 /* Functions */
105 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
107 void irreco_scrolled_window_set_autoresize(IrrecoScrolledWindow *self,
108 gint width_min,
109 gint width_max,
110 gint height_min,
111 gint height_max)
113 IRRECO_ENTER
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;
118 IRRECO_RETURN
121 void irreco_scrolled_window_add(IrrecoScrolledWindow *self,
122 GtkWidget *widget)
124 IRRECO_ENTER
125 self->child = widget;
126 gtk_container_add(GTK_CONTAINER(self->alignment), widget);
127 IRRECO_RETURN
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;*/
143 IRRECO_ENTER
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",
149 child_req.width,
150 child_req.height);
152 /* Height */
153 if (self->height_min > child_req.height) {
154 requisition->height = self->height_min;
155 } else {
156 requisition->height = child_req.height;
158 if (self->height_max > 0
159 && requisition->height > self->height_max) {
160 requisition->height = self->height_max;
163 /* Width */
164 if (self->width_min > child_req.width) {
165 requisition->width = self->width_min + scrollbar_space;
166 } else {
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",
175 requisition->width,
176 requisition->height);
178 IRRECO_RETURN