Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: chrome/browser/gtk/dialogs_gtk.cc

Issue 149548: Make GTK file dialog box modal for parent window, instead of for the entire... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/browser_window_gtk.cc ('k') | chrome/browser/gtk/info_bubble_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
30 // This acts as a modal dialog. Ideally we want to only act modally for the 30 // This acts as a modal dialog.
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 { 31 class SelectFileDialogImpl : public SelectFileDialog {
36 public: 32 public:
37 explicit SelectFileDialogImpl(Listener* listener); 33 explicit SelectFileDialogImpl(Listener* listener);
38 virtual ~SelectFileDialogImpl(); 34 virtual ~SelectFileDialogImpl();
39 35
40 // BaseShellDialog implementation. 36 // BaseShellDialog implementation.
41 virtual bool IsRunning(gfx::NativeWindow parent_window) const; 37 virtual bool IsRunning(gfx::NativeWindow parent_window) const;
42 virtual void ListenerDestroyed(); 38 virtual void ListenerDestroyed();
43 39
44 // SelectFileDialog implementation. 40 // SelectFileDialog implementation.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 default: 197 default:
202 NOTIMPLEMENTED() << "Dialog type " << type << " not implemented."; 198 NOTIMPLEMENTED() << "Dialog type " << type << " not implemented.";
203 return; 199 return;
204 } 200 }
205 201
206 preview_ = gtk_image_new(); 202 preview_ = gtk_image_new();
207 g_signal_connect(dialog, "update-preview", G_CALLBACK(OnUpdatePreview), this); 203 g_signal_connect(dialog, "update-preview", G_CALLBACK(OnUpdatePreview), this);
208 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_); 204 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview_);
209 205
210 params_map_[dialog] = params; 206 params_map_[dialog] = params;
207
208 // Set window-to-parent modality by adding the dialog to the same window
209 // group as the parent, and calling gtk_grab_add(...)
Evan Martin 2009/07/20 22:49:17 This comment is no longer correct.
210 gtk_window_group_add_window(gtk_window_get_group(owning_window),
211 GTK_WINDOW(dialog));
211 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); 212 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
213
212 gtk_widget_show_all(dialog); 214 gtk_widget_show_all(dialog);
213 } 215 }
214 216
215 void SelectFileDialogImpl::AddFilters(GtkFileChooser* chooser) { 217 void SelectFileDialogImpl::AddFilters(GtkFileChooser* chooser) {
216 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { 218 for (size_t i = 0; i < file_types_.extensions.size(); ++i) {
217 GtkFileFilter* filter = NULL; 219 GtkFileFilter* filter = NULL;
218 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) { 220 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 221 // TODO(estade): it's probably preferable to use mime types, but we are
220 // passed extensions, so it's much easier to use globs. 222 // passed extensions, so it's much easier to use globs.
221 if (!file_types_.extensions[i][j].empty()) { 223 if (!file_types_.extensions[i][j].empty()) {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 // This will preserve the image's aspect ratio. 440 // This will preserve the image's aspect ratio.
439 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth, 441 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth,
440 kPreviewHeight, NULL); 442 kPreviewHeight, NULL);
441 g_free(filename); 443 g_free(filename);
442 if (pixbuf) { 444 if (pixbuf) {
443 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->preview_), pixbuf); 445 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->preview_), pixbuf);
444 g_object_unref(pixbuf); 446 g_object_unref(pixbuf);
445 } 447 }
446 gtk_file_chooser_set_preview_widget_active(chooser, pixbuf ? TRUE : FALSE); 448 gtk_file_chooser_set_preview_widget_active(chooser, pixbuf ? TRUE : FALSE);
447 } 449 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/browser_window_gtk.cc ('k') | chrome/browser/gtk/info_bubble_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698