[14481] | 1 | /* GTK - The GIMP Toolkit |
---|
| 2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
---|
| 3 | * |
---|
| 4 | * This library is free software; you can redistribute it and/or |
---|
| 5 | * modify it under the terms of the GNU Library General Public |
---|
| 6 | * License as published by the Free Software Foundation; either |
---|
| 7 | * version 2 of the License, or (at your option) any later version. |
---|
| 8 | * |
---|
| 9 | * This library is distributed in the hope that it will be useful, |
---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 12 | * Library General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU Library General Public |
---|
| 15 | * License along with this library; if not, write to the |
---|
| 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
| 17 | * Boston, MA 02111-1307, USA. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | /* |
---|
| 21 | * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS |
---|
| 22 | * file for a list of people on the GTK+ Team. See the ChangeLog |
---|
| 23 | * files for a list of changes. These files are distributed with |
---|
| 24 | * GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | #include "gtkbbox.h" |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | static void gtk_button_box_class_init (GtkButtonBoxClass *klass); |
---|
| 31 | static void gtk_button_box_init (GtkButtonBox *box); |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | static gint default_child_min_width = 85; |
---|
| 35 | static gint default_child_min_height = 27; |
---|
| 36 | static gint default_child_ipad_x = 7; |
---|
| 37 | static gint default_child_ipad_y = 0; |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | GtkType |
---|
| 41 | gtk_button_box_get_type (void) |
---|
| 42 | { |
---|
| 43 | static GtkType button_box_type = 0; |
---|
| 44 | |
---|
| 45 | if (!button_box_type) |
---|
| 46 | { |
---|
| 47 | static const GtkTypeInfo button_box_info = |
---|
| 48 | { |
---|
| 49 | "GtkButtonBox", |
---|
| 50 | sizeof (GtkButtonBox), |
---|
| 51 | sizeof (GtkButtonBoxClass), |
---|
| 52 | (GtkClassInitFunc) gtk_button_box_class_init, |
---|
| 53 | (GtkObjectInitFunc) gtk_button_box_init, |
---|
| 54 | /* reserved_1 */ NULL, |
---|
| 55 | /* reserved_2 */ NULL, |
---|
| 56 | (GtkClassInitFunc) NULL, |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | button_box_type = gtk_type_unique (gtk_box_get_type (), &button_box_info); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | return button_box_type; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | static void |
---|
| 66 | gtk_button_box_class_init (GtkButtonBoxClass *class) |
---|
| 67 | { |
---|
| 68 | GtkWidgetClass *widget_class; |
---|
| 69 | |
---|
| 70 | widget_class = (GtkWidgetClass*) class; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | static void |
---|
| 74 | gtk_button_box_init (GtkButtonBox *button_box) |
---|
| 75 | { |
---|
| 76 | button_box->spacing = GTK_BUTTONBOX_DEFAULT; |
---|
| 77 | button_box->child_min_width = GTK_BUTTONBOX_DEFAULT; |
---|
| 78 | button_box->child_min_height = GTK_BUTTONBOX_DEFAULT; |
---|
| 79 | button_box->child_ipad_x = GTK_BUTTONBOX_DEFAULT; |
---|
| 80 | button_box->child_ipad_y = GTK_BUTTONBOX_DEFAULT; |
---|
| 81 | button_box->layout_style = GTK_BUTTONBOX_DEFAULT_STYLE; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | /* set default values for child size and child internal padding */ |
---|
| 86 | /* default spacing is in defined in subclasses */ |
---|
| 87 | |
---|
| 88 | void gtk_button_box_set_child_size_default (gint width, gint height) |
---|
| 89 | { |
---|
| 90 | default_child_min_width = width; |
---|
| 91 | default_child_min_height = height; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | void gtk_button_box_set_child_ipadding_default (gint ipad_x, gint ipad_y) |
---|
| 95 | { |
---|
| 96 | default_child_ipad_x = ipad_x; |
---|
| 97 | default_child_ipad_y = ipad_y; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | /* get default values for child size and child internal padding */ |
---|
| 101 | |
---|
| 102 | void gtk_button_box_get_child_size_default (gint *width, gint *height) |
---|
| 103 | { |
---|
| 104 | *width = default_child_min_width; |
---|
| 105 | *height = default_child_min_height; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | void gtk_button_box_get_child_ipadding_default (gint *ipad_x, gint *ipad_y) |
---|
| 109 | { |
---|
| 110 | *ipad_x = default_child_ipad_x; |
---|
| 111 | *ipad_y = default_child_ipad_y; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /* set per widget values for spacing, child size and child internal padding */ |
---|
| 115 | |
---|
| 116 | void gtk_button_box_set_spacing (GtkButtonBox *widget, gint spacing) |
---|
| 117 | { |
---|
| 118 | widget->spacing = spacing; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | void gtk_button_box_set_child_size (GtkButtonBox *widget, gint width, gint height) |
---|
| 122 | { |
---|
| 123 | widget->child_min_width = width; |
---|
| 124 | widget->child_min_height = height; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | void gtk_button_box_set_child_ipadding (GtkButtonBox *widget, |
---|
| 128 | gint ipad_x, gint ipad_y) |
---|
| 129 | { |
---|
| 130 | widget->child_ipad_x = ipad_x; |
---|
| 131 | widget->child_ipad_y = ipad_y; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | void gtk_button_box_set_layout (GtkButtonBox *widget, |
---|
| 135 | GtkButtonBoxStyle layout_style) |
---|
| 136 | { |
---|
| 137 | g_return_if_fail (layout_style >= GTK_BUTTONBOX_DEFAULT_STYLE && |
---|
| 138 | layout_style <= GTK_BUTTONBOX_END); |
---|
| 139 | |
---|
| 140 | widget->layout_style = layout_style; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | /* get per widget values for spacing, child size and child internal padding */ |
---|
| 145 | |
---|
| 146 | gint gtk_button_box_get_spacing (GtkButtonBox *widget) |
---|
| 147 | { |
---|
| 148 | return widget->spacing; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | void gtk_button_box_get_child_size (GtkButtonBox *widget, |
---|
| 152 | gint *width, gint *height) |
---|
| 153 | { |
---|
| 154 | *width = widget->child_min_width; |
---|
| 155 | *height = widget->child_min_height; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | void gtk_button_box_get_child_ipadding (GtkButtonBox *widget, |
---|
| 159 | gint* ipad_x, gint *ipad_y) |
---|
| 160 | { |
---|
| 161 | *ipad_x = widget->child_ipad_x; |
---|
| 162 | *ipad_y = widget->child_ipad_y; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | GtkButtonBoxStyle gtk_button_box_get_layout (GtkButtonBox *widget) |
---|
| 166 | { |
---|
| 167 | return widget->layout_style; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | /* Ask children how much space they require and round up |
---|
| 173 | to match minimum size and internal padding. |
---|
| 174 | Returns the size each single child should have. */ |
---|
| 175 | void |
---|
| 176 | gtk_button_box_child_requisition (GtkWidget *widget, |
---|
| 177 | int *nvis_children, |
---|
| 178 | int *width, |
---|
| 179 | int *height) |
---|
| 180 | { |
---|
| 181 | GtkButtonBox *bbox; |
---|
| 182 | GtkBoxChild *child; |
---|
| 183 | GList *children; |
---|
| 184 | gint nchildren; |
---|
| 185 | gint needed_width; |
---|
| 186 | gint needed_height; |
---|
| 187 | GtkRequisition child_requisition; |
---|
| 188 | gint ipad_w; |
---|
| 189 | gint ipad_h; |
---|
| 190 | gint width_default; |
---|
| 191 | gint height_default; |
---|
| 192 | gint ipad_x_default; |
---|
| 193 | gint ipad_y_default; |
---|
| 194 | |
---|
| 195 | gint child_min_width; |
---|
| 196 | gint child_min_height; |
---|
| 197 | gint ipad_x; |
---|
| 198 | gint ipad_y; |
---|
| 199 | |
---|
| 200 | g_return_if_fail (widget != NULL); |
---|
| 201 | g_return_if_fail (GTK_IS_BUTTON_BOX (widget)); |
---|
| 202 | |
---|
| 203 | bbox = GTK_BUTTON_BOX (widget); |
---|
| 204 | |
---|
| 205 | gtk_button_box_get_child_size_default (&width_default, &height_default); |
---|
| 206 | gtk_button_box_get_child_ipadding_default (&ipad_x_default, &ipad_y_default); |
---|
| 207 | |
---|
| 208 | child_min_width = bbox->child_min_width != GTK_BUTTONBOX_DEFAULT |
---|
| 209 | ? bbox->child_min_width : width_default; |
---|
| 210 | child_min_height = bbox->child_min_height !=GTK_BUTTONBOX_DEFAULT |
---|
| 211 | ? bbox->child_min_height : height_default; |
---|
| 212 | ipad_x = bbox->child_ipad_x != GTK_BUTTONBOX_DEFAULT |
---|
| 213 | ? bbox->child_ipad_x : ipad_x_default; |
---|
| 214 | ipad_y = bbox->child_ipad_y != GTK_BUTTONBOX_DEFAULT |
---|
| 215 | ? bbox->child_ipad_y : ipad_y_default; |
---|
| 216 | |
---|
| 217 | nchildren = 0; |
---|
| 218 | children = GTK_BOX(bbox)->children; |
---|
| 219 | needed_width = child_min_width; |
---|
| 220 | needed_height = child_min_height; |
---|
| 221 | ipad_w = ipad_x * 2; |
---|
| 222 | ipad_h = ipad_y * 2; |
---|
| 223 | |
---|
| 224 | while (children) |
---|
| 225 | { |
---|
| 226 | child = children->data; |
---|
| 227 | children = children->next; |
---|
| 228 | |
---|
| 229 | if (GTK_WIDGET_VISIBLE (child->widget)) |
---|
| 230 | { |
---|
| 231 | nchildren += 1; |
---|
| 232 | gtk_widget_size_request (child->widget, &child_requisition); |
---|
| 233 | if (child_requisition.width + ipad_w > needed_width) |
---|
| 234 | needed_width = child_requisition.width + ipad_w; |
---|
| 235 | if (child_requisition.height + ipad_h > needed_height) |
---|
| 236 | needed_height = child_requisition.height + ipad_h; |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | *nvis_children = nchildren; |
---|
| 241 | *width = needed_width; |
---|
| 242 | *height = needed_height; |
---|
| 243 | } |
---|