summaryrefslogtreecommitdiff
path: root/gtk/gtkfilechooserdialog.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@ximian.com>2004-02-14 01:23:58 +0000
committerFederico Mena Quintero <federico@src.gnome.org>2004-02-14 01:23:58 +0000
commitfff49996990feece0debb661bddb861f03fa639c (patch)
tree6ba3ee633ad980edca675cf4883ecca1eae72e2c /gtk/gtkfilechooserdialog.c
parentcf6d6a1a6e7e4cb798a9bfe58afaab156c78bef8 (diff)
downloadgtk+-fff49996990feece0debb661bddb861f03fa639c.tar.gz
Fix #129020.
2004-02-13 Federico Mena Quintero <federico@ximian.com> Fix #129020. * gtk/gtkfilechooserdialog.c (set_default_size): New function, sets a reasonable default size for the window. (gtk_file_chooser_dialog_realize): New function, call set_default_size(). (gtk_file_chooser_dialog_style_set): Likewise. (gtk_file_chooser_dialog_screen_changed): Likewise. * tests/testfilechooser.c (main): Don't set a default size for the dialog.
Diffstat (limited to 'gtk/gtkfilechooserdialog.c')
-rw-r--r--gtk/gtkfilechooserdialog.c108
1 files changed, 100 insertions, 8 deletions
diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index 2067f076e2..157768571e 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -26,10 +26,13 @@
#include <stdarg.h>
+#define NUM_LINES 40
+#define NUM_CHARS 50
+
struct _GtkFileChooserDialogPrivate
{
GtkWidget *widget;
-
+
GtkFileSystem *file_system;
};
@@ -50,6 +53,12 @@ static void gtk_file_chooser_dialog_get_property (GObject *obj
GValue *value,
GParamSpec *pspec);
+static void gtk_file_chooser_dialog_realize (GtkWidget *widget);
+static void gtk_file_chooser_dialog_style_set (GtkWidget *widget,
+ GtkStyle *previous_style);
+static void gtk_file_chooser_dialog_screen_changed (GtkWidget *widget,
+ GdkScreen *previous_screen);
+
static GObjectClass *parent_class;
GType
@@ -71,7 +80,7 @@ gtk_file_chooser_dialog_get_type (void)
0, /* n_preallocs */
(GInstanceInitFunc) gtk_file_chooser_dialog_init,
};
-
+
static const GInterfaceInfo file_chooser_info =
{
(GInterfaceInitFunc) _gtk_file_chooser_delegate_iface_init, /* interface_init */
@@ -93,6 +102,7 @@ static void
gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
parent_class = g_type_class_peek_parent (class);
@@ -100,6 +110,10 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
gobject_class->set_property = gtk_file_chooser_dialog_set_property;
gobject_class->get_property = gtk_file_chooser_dialog_get_property;
+ widget_class->realize = gtk_file_chooser_dialog_realize;
+ widget_class->style_set = gtk_file_chooser_dialog_style_set;
+ widget_class->screen_changed = gtk_file_chooser_dialog_screen_changed;
+
_gtk_file_chooser_install_properties (gobject_class);
g_type_class_add_private (class, sizeof (GtkFileChooserDialogPrivate));
@@ -131,7 +145,7 @@ gtk_file_chooser_dialog_constructor (GType type,
{
GtkFileChooserDialogPrivate *priv;
GObject *object;
-
+
object = parent_class->constructor (type,
n_construct_properties,
construct_params);
@@ -165,7 +179,7 @@ gtk_file_chooser_dialog_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
-
+
{
GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (object);
@@ -197,10 +211,88 @@ gtk_file_chooser_dialog_get_property (GObject *object,
GParamSpec *pspec)
{
GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (object);
-
+
g_object_get_property (G_OBJECT (priv->widget), pspec->name, value);
}
+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);
+}
+
+static void
+gtk_file_chooser_dialog_realize (GtkWidget *widget)
+{
+ GTK_WIDGET_CLASS (parent_class)->realize (widget);
+ set_default_size (GTK_FILE_CHOOSER_DIALOG (widget));
+}
+
+static void
+gtk_file_chooser_dialog_style_set (GtkWidget *widget,
+ GtkStyle *previous_style)
+{
+ if (GTK_WIDGET_CLASS (parent_class)->style_set)
+ GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
+
+ if (GTK_WIDGET_REALIZED (widget))
+ set_default_size (GTK_FILE_CHOOSER_DIALOG (widget));
+}
+
+static void
+gtk_file_chooser_dialog_screen_changed (GtkWidget *widget,
+ GdkScreen *previous_screen)
+{
+ if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
+ GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, previous_screen);
+
+ if (GTK_WIDGET_REALIZED (widget))
+ set_default_size (GTK_FILE_CHOOSER_DIALOG (widget));
+}
+
/**
* gtk_file_chooser_dialog_new:
* @title: Title of the dialog, or %NULL
@@ -208,10 +300,10 @@ gtk_file_chooser_dialog_get_property (GObject *object,
* @action: Open or save mode for the dialog
* @first_button_text: stock ID or text to go in the first button, or %NULL
* @Varargs: response ID for the first button, then additional (button, id) pairs, ending with %NULL
- *
+ *
* Creates a new #GtkFileChooserDialog. This function is analogous to
* gtk_dialog_new_with_buttons().
- *
+ *
* Return value: a new #GtkFileChooserDialog
*
* Since: 2.4
@@ -227,7 +319,7 @@ gtk_file_chooser_dialog_new (const gchar *title,
va_list varargs;
const char *button_text = first_button_text;
gint response_id;
-
+
result = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
"title", title,
"action", action,