OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
6 #include <map> | 6 #include <map> |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/thread.h" | 13 #include "base/thread.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/shell_dialogs.h" | 17 #include "chrome/browser/shell_dialogs.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 | 19 |
20 // The size of the preview we display for selected image files. We set height | 20 // The size of the preview we display for selected image files. We set height |
21 // larger than width because generally there is more free space vertically | 21 // larger than width because generally there is more free space vertically |
22 // than horiztonally (setting the preview image will alway expand the width of | 22 // than horiztonally (setting the preview image will alway expand the width of |
23 // the dialog, but usually not the height). The image's aspect ratio will always | 23 // the dialog, but usually not the height). The image's aspect ratio will always |
24 // be preserved. | 24 // be preserved. |
25 static const int kPreviewWidth = 256; | 25 static const int kPreviewWidth = 256; |
26 static const int kPreviewHeight = 512; | 26 static const int kPreviewHeight = 512; |
27 | 27 |
28 // Implementation of SelectFileDialog that shows a Gtk common dialog for | 28 // Implementation of SelectFileDialog that shows a Gtk common dialog for |
29 // choosing a file or folder. | 29 // choosing a file or folder. This acts as a modal dialog. |
30 // This acts as a modal dialog. Ideally we want to only act modally for the | |
31 // parent window and allow other toplevel chrome windows to still function while | |
32 // the dialog is showing, but we need the GtkWindowGroup or something similar to | |
33 // get that, and that API is only available in more recent versions of GTK. | |
34 // TODO(port): fix modality: crbug.com/8727 | |
35 class SelectFileDialogImpl : public SelectFileDialog { | 30 class SelectFileDialogImpl : public SelectFileDialog { |
36 public: | 31 public: |
37 explicit SelectFileDialogImpl(Listener* listener); | 32 explicit SelectFileDialogImpl(Listener* listener); |
38 virtual ~SelectFileDialogImpl(); | 33 virtual ~SelectFileDialogImpl(); |
39 | 34 |
40 // BaseShellDialog implementation. | 35 // BaseShellDialog implementation. |
41 virtual bool IsRunning(gfx::NativeWindow parent_window) const; | 36 virtual bool IsRunning(gfx::NativeWindow parent_window) const; |
42 virtual void ListenerDestroyed(); | 37 virtual void ListenerDestroyed(); |
43 | 38 |
44 // SelectFileDialog implementation. | 39 // SelectFileDialog implementation. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 default: | 196 default: |
202 NOTIMPLEMENTED() << "Dialog type " << type << " not implemented."; | 197 NOTIMPLEMENTED() << "Dialog type " << type << " not implemented."; |
203 return; | 198 return; |
204 } | 199 } |
205 | 200 |
206 preview_ = gtk_image_new(); | 201 preview_ = gtk_image_new(); |
207 g_signal_connect(dialog, "update-preview", G_CALLBACK(OnUpdatePreview), this); | 202 g_signal_connect(dialog, "update-preview", G_CALLBACK(OnUpdatePreview), this); |
208 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); | 203 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); |
209 | 204 |
210 params_map_[dialog] = params; | 205 params_map_[dialog] = params; |
| 206 |
| 207 // Set window-to-parent modality by adding the dialog to the same window |
| 208 // group as the parent. |
| 209 gtk_window_group_add_window(gtk_window_get_group(owning_window), |
| 210 GTK_WINDOW(dialog)); |
211 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); | 211 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); |
| 212 |
212 gtk_widget_show_all(dialog); | 213 gtk_widget_show_all(dialog); |
213 } | 214 } |
214 | 215 |
215 void SelectFileDialogImpl::AddFilters(GtkFileChooser* chooser) { | 216 void SelectFileDialogImpl::AddFilters(GtkFileChooser* chooser) { |
216 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { | 217 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { |
217 GtkFileFilter* filter = NULL; | 218 GtkFileFilter* filter = NULL; |
218 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) { | 219 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) { |
219 // TODO(estade): it's probably preferable to use mime types, but we are | 220 // TODO(estade): it's probably preferable to use mime types, but we are |
220 // passed extensions, so it's much easier to use globs. | 221 // passed extensions, so it's much easier to use globs. |
221 if (!file_types_.extensions[i][j].empty()) { | 222 if (!file_types_.extensions[i][j].empty()) { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 // This will preserve the image's aspect ratio. | 439 // This will preserve the image's aspect ratio. |
439 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth, | 440 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth, |
440 kPreviewHeight, NULL); | 441 kPreviewHeight, NULL); |
441 g_free(filename); | 442 g_free(filename); |
442 if (pixbuf) { | 443 if (pixbuf) { |
443 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->preview_), pixbuf); | 444 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->preview_), pixbuf); |
444 g_object_unref(pixbuf); | 445 g_object_unref(pixbuf); |
445 } | 446 } |
446 gtk_file_chooser_set_preview_widget_active(chooser, pixbuf ? TRUE : FALSE); | 447 gtk_file_chooser_set_preview_widget_active(chooser, pixbuf ? TRUE : FALSE); |
447 } | 448 } |
OLD | NEW |