Index: gtkfilechooserdialog.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilechooserdialog.c,v
retrieving revision 1.24
diff -u -p -u -r1.24 gtkfilechooserdialog.c
--- gtkfilechooserdialog.c	8 Mar 2004 22:21:47 -0000	1.24
+++ gtkfilechooserdialog.c	9 Mar 2004 18:08:09 -0000
@@ -184,6 +184,29 @@ file_chooser_widget_update_hints (GtkFil
 }
 
 static void
+clamp_to_screen (GtkWidget *widget,
+		 gint      *width,
+		 gint      *height)
+{
+  GdkScreen *screen;
+  int monitor_num;
+  GdkRectangle monitor;
+
+  g_return_if_fail (GTK_WIDGET_REALIZED (widget));
+  
+  screen = gtk_widget_get_screen (widget);
+  monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
+
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+  if (width)
+    *width = MIN (*width, (monitor.width * 3) / 4);
+
+  if (height)
+    *height = MIN (*height, (monitor.height * 3) / 4);
+}
+
+static void
 file_chooser_widget_default_realized_size_changed (GtkWidget            *widget,
 						   GtkFileChooserDialog *dialog)
 {
@@ -261,12 +284,15 @@ file_chooser_widget_default_realized_siz
   priv->resize_horizontally = resize_horizontally;
   priv->resize_vertically = resize_vertically;
 
-  /* FIXME: We should make sure that we arent' bigger than the current screen */
   if (dx != 0 || dy != 0)
     {
+      int new_width = dx + cur_width;
+      int new_height = dy + cur_height;
+
+      clamp_to_screen (GTK_WIDGET (dialog), &new_width, &new_height);
+	
       gtk_window_resize (GTK_WINDOW (dialog),
-			 cur_width + dx,
-			 cur_height + dy);
+			 new_width, new_height);
     }
 
   /* Only store the size if we can resize in that direction. */
@@ -275,40 +301,16 @@ file_chooser_widget_default_realized_siz
 }
 
 static void
-file_chooser_widget_default_unrealized_size_changed (GtkWidget            *widget,
-						     GtkFileChooserDialog *dialog)
-{
-  GtkFileChooserDialogPrivate *priv;
-  GtkRequisition req;
-  gint width, height;
-
-  priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
-  gtk_widget_size_request (GTK_WIDGET (dialog), &req);
-
-  _gtk_file_chooser_embed_get_resizable_hints (GTK_FILE_CHOOSER_EMBED (priv->widget),
-					       &(priv->resize_horizontally),
-					       &(priv->resize_vertically));
-  _gtk_file_chooser_embed_get_default_size (GTK_FILE_CHOOSER_EMBED (priv->widget),
-					    &(priv->default_width), &(priv->default_height));
-  
-  /* Determine how much space the rest of the dialog uses compared to priv->widget */
-  width = priv->default_width + GTK_WIDGET (dialog)->requisition.width - priv->widget->requisition.width;
-  height = priv->default_height + GTK_WIDGET (dialog)->requisition.height - priv->widget->requisition.height;
-
-  gtk_window_set_default_size (GTK_WINDOW (dialog), width, height);
-  file_chooser_widget_update_hints (dialog);
-}
-
-static void
 file_chooser_widget_default_size_changed (GtkWidget            *widget,
 					  GtkFileChooserDialog *dialog)
 {
-  if (GTK_WIDGET_REALIZED (dialog))
-    file_chooser_widget_default_realized_size_changed (widget, dialog);
-  else
-    file_chooser_widget_default_unrealized_size_changed (widget, dialog);
-}
+  /* Realize the widget so we can base the size on dialog's screen
+   */
+  gtk_widget_realize (dialog);
   
+  file_chooser_widget_default_realized_size_changed (widget, dialog);
+}
+
 static GObject*
 gtk_file_chooser_dialog_constructor (GType                  type,
 				     guint                  n_construct_properties,
@@ -381,57 +383,6 @@ gtk_file_chooser_dialog_get_property (GO
   g_object_get_property (G_OBJECT (priv->widget), pspec->name, value);
 }
 
-#if 0
-static void
-set_default_size (GtkFileChooserDialog *dialog)
-{
-  GtkWidget *widget;
-  GtkWindow *window;
-  int default_width, default_height;
-  int width, height;
-  int font_size;
-  GdkScreen *screen;
-  int monitor_num;
-  GtkRequisition req;
-  GdkRectangle monitor;
-
-  widget = GTK_WIDGET (dialog);
-  window = GTK_WINDOW (dialog);
-
-  /* Size based on characters */
-
-  font_size = pango_font_description_get_size (widget->style->font_desc);
-  font_size = PANGO_PIXELS (font_size);
-
-  width = font_size * NUM_CHARS;
-  height = font_size * NUM_LINES;
-
-  /* Use at least the requisition size... */
-
-  gtk_widget_size_request (widget, &req);
-  width = MAX (width, req.width);
-  height = MAX (height, req.height);
-
-  /* ... but no larger than the monitor */
-
-  screen = gtk_widget_get_screen (widget);
-  monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
-
-  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
-
-  width = MIN (width, monitor.width * 3 / 4);
-  height = MIN (height, monitor.height * 3 / 4);
-
-  /* Set size */
-
-  gtk_window_get_default_size (window, &default_width, &default_height);
-
-  gtk_window_set_default_size (window,
-			       (default_width == -1) ? width : default_width,
-			       (default_height == -1) ? height : default_height);
-}
-#endif
-
 static void
 gtk_file_chooser_dialog_style_set (GtkWidget *widget,
 				   GtkStyle  *previous_style)
