From 3a991672550ca9b6f4046ab1232caf8d48d14b23 Mon Sep 17 00:00:00 2001 From: "evan@chromium.org" Date: Sat, 9 Jan 2010 00:52:19 +0000 Subject: linux: set a minimum size for dialogs based on locale resources GTK dialogs size to their contents, but sometimes the title is the longest string available. BUG=28024 Review URL: http://codereview.chromium.org/534006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35855 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/app/resources/locale_settings.grd | 5 +++++ chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc | 6 +++++- .../browser/gtk/create_application_shortcuts_dialog_gtk.cc | 6 +++++- chrome/browser/gtk/import_dialog_gtk.cc | 10 +++++----- chrome/browser/views/create_application_shortcut_view.cc | 1 + chrome/common/gtk_util.cc | 13 +++++++++++++ chrome/common/gtk_util.h | 7 +++++++ 7 files changed, 41 insertions(+), 7 deletions(-) (limited to 'chrome') diff --git a/chrome/app/resources/locale_settings.grd b/chrome/app/resources/locale_settings.grd index a122250..0bbc205 100644 --- a/chrome/app/resources/locale_settings.grd +++ b/chrome/app/resources/locale_settings.grd @@ -663,6 +663,11 @@ 4 + + + + 55 + diff --git a/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc b/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc index 07b911d..b85d86b 100644 --- a/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc +++ b/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc @@ -12,6 +12,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "grit/generated_resources.h" +#include "grit/locale_settings.h" // static void ClearBrowsingDataDialogGtk::Show(GtkWindow* parent, Profile* profile) { @@ -29,6 +30,10 @@ ClearBrowsingDataDialogGtk::ClearBrowsingDataDialogGtk(GtkWindow* parent, GTK_STOCK_CLOSE, GTK_RESPONSE_REJECT, NULL); + gtk_widget_realize(dialog); + gtk_util::SetWindowWidthFromResources(GTK_WINDOW(dialog), + IDS_CLEARDATA_DIALOG_WIDTH_CHARS, + /* resizable */ false); gtk_util::AddButtonToDialog(dialog, l10n_util::GetStringUTF8(IDS_CLEAR_BROWSING_DATA_COMMIT).c_str(), GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); @@ -127,7 +132,6 @@ ClearBrowsingDataDialogGtk::ClearBrowsingDataDialogGtk(GtkWindow* parent, g_signal_connect(dialog, "response", G_CALLBACK(HandleOnResponseDialog), this); - gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); gtk_widget_show_all(dialog); } diff --git a/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc b/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc index 56a5908..61105d3 100644 --- a/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc +++ b/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc @@ -8,6 +8,7 @@ #include "chrome/browser/shell_integration.h" #include "chrome/common/gtk_util.h" #include "grit/generated_resources.h" +#include "grit/locale_settings.h" // static void CreateApplicationShortcutsDialogGtk::Show(GtkWindow* parent, @@ -33,6 +34,10 @@ CreateApplicationShortcutsDialogGtk::CreateApplicationShortcutsDialogGtk( GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); + gtk_widget_realize(dialog); + gtk_util::SetWindowWidthFromResources(GTK_WINDOW(dialog), + IDS_CREATE_SHORTCUTS_DIALOG_WIDTH_CHARS, + /* resizable */ false); gtk_util::AddButtonToDialog(dialog, l10n_util::GetStringUTF8(IDS_CREATE_SHORTCUTS_COMMIT).c_str(), GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); @@ -63,7 +68,6 @@ CreateApplicationShortcutsDialogGtk::CreateApplicationShortcutsDialogGtk( g_signal_connect(dialog, "response", G_CALLBACK(HandleOnResponseDialog), this); - gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); gtk_widget_show_all(dialog); } diff --git a/chrome/browser/gtk/import_dialog_gtk.cc b/chrome/browser/gtk/import_dialog_gtk.cc index 9acd79e..443d453 100644 --- a/chrome/browser/gtk/import_dialog_gtk.cc +++ b/chrome/browser/gtk/import_dialog_gtk.cc @@ -8,6 +8,7 @@ #include "app/resource_bundle.h" #include "chrome/common/gtk_util.h" #include "grit/generated_resources.h" +#include "grit/locale_settings.h" // static void ImportDialogGtk::Show(GtkWindow* parent, Profile* profile) { @@ -35,6 +36,10 @@ ImportDialogGtk::ImportDialogGtk(GtkWindow* parent, Profile* profile) GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); + gtk_widget_realize(dialog_); + gtk_util::SetWindowWidthFromResources(GTK_WINDOW(dialog_), + IDS_IMPORT_DIALOG_WIDTH_CHARS, + /* resizable */ false); importer_host_->set_parent_window(GTK_WINDOW(dialog_)); // Add import button separately as we might need to disable it, if @@ -45,10 +50,6 @@ ImportDialogGtk::ImportDialogGtk(GtkWindow* parent, Profile* profile) GTK_WIDGET_SET_FLAGS(import_button, GTK_CAN_DEFAULT); gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); - // TODO(rahulk): find how to set size properly so that the dialog - // box width is at least enough to display full title. - gtk_widget_set_size_request(dialog_, 300, -1); - GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox; gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); @@ -114,7 +115,6 @@ ImportDialogGtk::ImportDialogGtk(GtkWindow* parent, Profile* profile) g_signal_connect(dialog_, "response", G_CALLBACK(HandleOnResponseDialog), this); - gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); gtk_widget_show_all(dialog_); } diff --git a/chrome/browser/views/create_application_shortcut_view.cc b/chrome/browser/views/create_application_shortcut_view.cc index 37d4b81..63d55c9 100644 --- a/chrome/browser/views/create_application_shortcut_view.cc +++ b/chrome/browser/views/create_application_shortcut_view.cc @@ -312,6 +312,7 @@ void CreateApplicationShortcutView::Init() { } gfx::Size CreateApplicationShortcutView::GetPreferredSize() { + // TODO(evanm): should this use IDS_CREATE_SHORTCUTS_DIALOG_WIDTH_CHARS? static const int kDialogWidth = 360; int height = GetLayoutManager()->GetPreferredHeightForWidth(this, kDialogWidth); diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc index 75a5acf..f63fd69 100644 --- a/chrome/common/gtk_util.cc +++ b/chrome/common/gtk_util.cc @@ -219,6 +219,19 @@ void GetWidgetSizeFromCharacters(GtkWidget* widget, double width_chars, g_object_unref(context); } +void SetWindowWidthFromResources(GtkWindow* window, int resource_id, + bool resizable) { + int width; + gtk_util::GetWidgetSizeFromResources(GTK_WIDGET(window), resource_id, 0, + &width, NULL); + if (resizable) { + gtk_window_set_default_size(window, width, -1); + } else { + gtk_widget_set_size_request(GTK_WIDGET(window), width, -1); + } + gtk_window_set_resizable(window, resizable ? TRUE : FALSE); +} + void RemoveAllChildren(GtkWidget* container) { gtk_container_foreach(GTK_CONTAINER(container), RemoveWidget, container); } diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h index f92c3ad..1e7c636 100644 --- a/chrome/common/gtk_util.h +++ b/chrome/common/gtk_util.h @@ -81,6 +81,13 @@ void GetWidgetSizeFromResources(GtkWidget* widget, int width_chars, void GetWidgetSizeFromCharacters(GtkWidget* widget, double width_chars, double height_lines, int* width, int* height); +// As above, but a convenience method for configuring dialog width. +// |resizable| also controls whether the dialog will be resizable +// (this info is also necessary for getting the width-setting code +// right). +void SetWindowWidthFromResources(GtkWindow* window, int resource_id, + bool resizable); + // Remove all children from this container. void RemoveAllChildren(GtkWidget* container); -- cgit v1.1