]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkalignment.c
filechooserbutton: Do not propagate state from the dialog unless it is active
[~andy/gtk] / gtk / gtkalignment.c
index 44adfa107fc430c92212d940660eeaba048ad3a3..ddd627ce86695a64dc262cfbc7bb0ec8809ad5a8 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
  * Of course, if the scale settings are both set to 1, the alignment settings
  * have no effect.
  *
+ * <note>
+ * <para>
  * Note that the desired effect can in most cases be achieved by using the
  * #GtkWidget:halign, #GtkWidget:valign and #GtkWidget:margin properties
- * on the child widget.
+ * on the child widget, so #GtkAlignment should not be used in new code.
+ * </para>
+ * </note>
  */
 
 #include "config.h"
@@ -98,6 +100,14 @@ static void gtk_alignment_get_preferred_width          (GtkWidget           *wid
 static void gtk_alignment_get_preferred_height         (GtkWidget           *widget,
                                                         gint                *minimum_size,
                                                         gint                *natural_size);
+static void gtk_alignment_get_preferred_width_for_height (GtkWidget           *widget,
+                                                         gint                 for_size,
+                                                         gint                *minimum_size,
+                                                         gint                *natural_size);
+static void gtk_alignment_get_preferred_height_for_width (GtkWidget           *widget,
+                                                         gint                 for_size,
+                                                         gint                *minimum_size,
+                                                         gint                *natural_size);
 
 G_DEFINE_TYPE (GtkAlignment, gtk_alignment, GTK_TYPE_BIN)
 
@@ -116,6 +126,8 @@ gtk_alignment_class_init (GtkAlignmentClass *class)
   widget_class->size_allocate        = gtk_alignment_size_allocate;
   widget_class->get_preferred_width  = gtk_alignment_get_preferred_width;
   widget_class->get_preferred_height = gtk_alignment_get_preferred_height;
+  widget_class->get_preferred_width_for_height = gtk_alignment_get_preferred_width_for_height;
+  widget_class->get_preferred_height_for_width = gtk_alignment_get_preferred_height_for_width;
 
   g_object_class_install_property (gobject_class,
                                    PROP_XALIGN,
@@ -567,6 +579,7 @@ gtk_alignment_size_allocate (GtkWidget     *widget,
 static void
 gtk_alignment_get_preferred_size (GtkWidget      *widget,
                                   GtkOrientation  orientation,
+                                 gint            for_size,
                                   gint           *minimum_size,
                                   gint           *natural_size)
 {
@@ -585,12 +598,44 @@ gtk_alignment_get_preferred_size (GtkWidget      *widget,
       if (orientation == GTK_ORIENTATION_HORIZONTAL)
        {
          minimum += (priv->padding_left + priv->padding_right);
-         gtk_widget_get_preferred_width (child, &child_min, &child_nat);
+
+         if (for_size < 0)
+           gtk_widget_get_preferred_width (child, &child_min, &child_nat);
+         else
+           {
+             gint min_height;
+
+             gtk_widget_get_preferred_height (child, &min_height, NULL);
+
+             for_size -= (priv->padding_top + priv->padding_bottom);
+
+             if (for_size > min_height)
+               for_size = (min_height * (1.0 - priv->yscale) +
+                           for_size * priv->yscale);
+
+             gtk_widget_get_preferred_width_for_height (child, for_size, &child_min, &child_nat);
+           }
        }
       else
        {
          minimum += (priv->padding_top + priv->padding_bottom);
-         gtk_widget_get_preferred_height (child, &child_min, &child_nat);
+
+         if (for_size < 0)
+           gtk_widget_get_preferred_height (child, &child_min, &child_nat);
+         else
+           {
+             gint min_width;
+
+             gtk_widget_get_preferred_width (child, &min_width, NULL);
+
+             for_size -= (priv->padding_left + priv->padding_right);
+
+             if (for_size > min_width)
+               for_size = (min_width * (1.0 - priv->xscale) +
+                           for_size * priv->xscale);
+
+             gtk_widget_get_preferred_height_for_width (child, for_size, &child_min, &child_nat);
+           }
        }
 
       natural = minimum;
@@ -611,7 +656,7 @@ gtk_alignment_get_preferred_width (GtkWidget      *widget,
                                    gint           *minimum_size,
                                    gint           *natural_size)
 {
-  gtk_alignment_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
+  gtk_alignment_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, -1, minimum_size, natural_size);
 }
 
 static void
@@ -619,7 +664,26 @@ gtk_alignment_get_preferred_height (GtkWidget      *widget,
                                     gint           *minimum_size,
                                     gint           *natural_size)
 {
-  gtk_alignment_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
+  gtk_alignment_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, -1, minimum_size, natural_size);
+}
+
+
+static void 
+gtk_alignment_get_preferred_width_for_height (GtkWidget           *widget,
+                                             gint                 for_size,
+                                             gint                *minimum_size,
+                                             gint                *natural_size)
+{
+  gtk_alignment_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, for_size, minimum_size, natural_size);
+}
+
+static void
+gtk_alignment_get_preferred_height_for_width (GtkWidget           *widget,
+                                             gint                 for_size,
+                                             gint                *minimum_size,
+                                             gint                *natural_size)
+{
+  gtk_alignment_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, for_size, minimum_size, natural_size);
 }
 
 /**
@@ -687,10 +751,14 @@ gtk_alignment_set_padding (GtkAlignment    *alignment,
 /**
  * gtk_alignment_get_padding:
  * @alignment: a #GtkAlignment
- * @padding_top: (allow-none): location to store the padding for the top of the widget, or %NULL
- * @padding_bottom: (allow-none): location to store the padding for the bottom of the widget, or %NULL
- * @padding_left: (allow-none): location to store the padding for the left of the widget, or %NULL
- * @padding_right: (allow-none): location to store the padding for the right of the widget, or %NULL
+ * @padding_top: (out) (allow-none): location to store the padding for
+ *     the top of the widget, or %NULL
+ * @padding_bottom: (out) (allow-none): location to store the padding
+ *     for the bottom of the widget, or %NULL
+ * @padding_left: (out) (allow-none): location to store the padding
+ *     for the left of the widget, or %NULL
+ * @padding_right: (out) (allow-none): location to store the padding
+ *     for the right of the widget, or %NULL
  *
  * Gets the padding on the different sides of the widget.
  * See gtk_alignment_set_padding ().