diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 00:43:55 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 00:43:55 +0000 |
commit | c7f9141a21e096ae7715bde8db2cc5d1b2175ed6 (patch) | |
tree | 50aeb0c171d568508453229120354c3e385ed977 /chrome | |
parent | 7e43da7c595c0ab9c7089477bb52bbf6ab421c81 (diff) | |
download | chromium_src-c7f9141a21e096ae7715bde8db2cc5d1b2175ed6.zip chromium_src-c7f9141a21e096ae7715bde8db2cc5d1b2175ed6.tar.gz chromium_src-c7f9141a21e096ae7715bde8db2cc5d1b2175ed6.tar.bz2 |
GTK: Preview images in file chooser.
BUG=http://crbug.com/15500
TEST=select an image in a file chooser
Review URL: http://codereview.chromium.org/151100
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19874 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/dialogs_gtk.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/chrome/browser/gtk/dialogs_gtk.cc b/chrome/browser/gtk/dialogs_gtk.cc index 637d203..62de9ce6 100644 --- a/chrome/browser/gtk/dialogs_gtk.cc +++ b/chrome/browser/gtk/dialogs_gtk.cc @@ -17,6 +17,14 @@ #include "chrome/browser/shell_dialogs.h" #include "grit/generated_resources.h" +// The size of the preview we display for selected image files. We set height +// larger than width because generally there is more free space vertically +// than horiztonally (setting the preview image will alway expand the width of +// the dialog, but usually not the height). The image's aspect ratio will always +// be preserved. +static const int kPreviewWidth = 256; +static const int kPreviewHeight = 512; + // Implementation of SelectFileDialog that shows a Gtk common dialog for // choosing a file or folder. // This acts as a modal dialog. Ideally we want to only act modally for the @@ -88,6 +96,10 @@ class SelectFileDialogImpl : public SelectFileDialog { static void OnSelectMultiFileDialogResponse( GtkWidget* dialog, gint response_id, SelectFileDialogImpl* dialog_impl); + // Callback for when we update the preview for the selection. + static void OnUpdatePreview(GtkFileChooser* chooser, + SelectFileDialogImpl* dialog); + // The listener to be notified of selection completion. Listener* listener_; @@ -112,6 +124,9 @@ class SelectFileDialogImpl : public SelectFileDialog { static FilePath* last_saved_path_; static FilePath* last_opened_path_; + // The GtkImage widget for showing previews of selected images. + GtkWidget* preview_; + DISALLOW_COPY_AND_ASSIGN(SelectFileDialogImpl); }; @@ -188,6 +203,10 @@ void SelectFileDialogImpl::SelectFile( return; } + preview_ = gtk_image_new(); + g_signal_connect(dialog, "update-preview", G_CALLBACK(OnUpdatePreview), this); + gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); + params_map_[dialog] = params; gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_widget_show_all(dialog); @@ -409,3 +428,20 @@ void SelectFileDialogImpl::OnSelectMultiFileDialogResponse( g_slist_free(filenames); dialog_impl->MultiFilesSelected(dialog, filenames_fp); } + +// static +void SelectFileDialogImpl::OnUpdatePreview(GtkFileChooser* chooser, + SelectFileDialogImpl* dialog) { + gchar* filename = gtk_file_chooser_get_preview_filename(chooser); + if (!filename) + return; + // This will preserve the image's aspect ratio. + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth, + kPreviewHeight, NULL); + g_free(filename); + if (pixbuf) { + gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->preview_), pixbuf); + g_object_unref(pixbuf); + } + gtk_file_chooser_set_preview_widget_active(chooser, pixbuf ? TRUE : FALSE); +} |