OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/gtk/create_application_shortcuts_dialog_gtk.h" | 5 #include "chrome/browser/gtk/create_application_shortcuts_dialog_gtk.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 void CreateApplicationShortcutsDialogGtk::CreateDialogBox(GtkWindow* parent) { | 80 void CreateApplicationShortcutsDialogGtk::CreateDialogBox(GtkWindow* parent) { |
81 // Build the dialog. | 81 // Build the dialog. |
82 create_dialog_ = gtk_dialog_new_with_buttons( | 82 create_dialog_ = gtk_dialog_new_with_buttons( |
83 l10n_util::GetStringUTF8(IDS_CREATE_SHORTCUTS_TITLE).c_str(), | 83 l10n_util::GetStringUTF8(IDS_CREATE_SHORTCUTS_TITLE).c_str(), |
84 parent, | 84 parent, |
85 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), | 85 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), |
86 GTK_STOCK_CANCEL, | 86 GTK_STOCK_CANCEL, |
87 GTK_RESPONSE_REJECT, | 87 GTK_RESPONSE_REJECT, |
88 NULL); | 88 NULL); |
89 gtk_widget_realize(create_dialog_); | 89 gtk_widget_realize(create_dialog_); |
90 gtk_util::SetWindowSizeFromResources(GTK_WINDOW(create_dialog_), | 90 gtk_window_set_resizable(GTK_WINDOW(create_dialog_), false); |
91 IDS_CREATE_SHORTCUTS_DIALOG_WIDTH_CHARS, | |
92 -1, // height | |
93 false); // resizable | |
94 gtk_util::AddButtonToDialog(create_dialog_, | 91 gtk_util::AddButtonToDialog(create_dialog_, |
95 l10n_util::GetStringUTF8(IDS_CREATE_SHORTCUTS_COMMIT).c_str(), | 92 l10n_util::GetStringUTF8(IDS_CREATE_SHORTCUTS_COMMIT).c_str(), |
96 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); | 93 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); |
97 | 94 |
98 GtkWidget* content_area = GTK_DIALOG(create_dialog_)->vbox; | 95 GtkWidget* content_area = GTK_DIALOG(create_dialog_)->vbox; |
99 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); | 96 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); |
100 | 97 |
101 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); | 98 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
102 gtk_container_add(GTK_CONTAINER(content_area), vbox); | 99 gtk_container_add(GTK_CONTAINER(content_area), vbox); |
103 | 100 |
104 // Create a box containing basic information about the new shortcut: an image | 101 // Create a box containing basic information about the new shortcut: an image |
105 // on the left, and a description on the right. | 102 // on the left, and a description on the right. |
106 GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); | 103 GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); |
107 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | 104 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
108 gtk_container_set_border_width(GTK_CONTAINER(hbox), | 105 gtk_container_set_border_width(GTK_CONTAINER(hbox), |
109 gtk_util::kControlSpacing); | 106 gtk_util::kControlSpacing); |
110 | 107 |
111 // Put the icon preview in place. | 108 // Put the icon preview in place. |
112 GtkWidget* favicon_image = gtk_image_new_from_pixbuf(favicon_pixbuf_); | 109 GtkWidget* favicon_image = gtk_image_new_from_pixbuf(favicon_pixbuf_); |
113 gtk_box_pack_start(GTK_BOX(hbox), favicon_image, FALSE, FALSE, 0); | 110 gtk_box_pack_start(GTK_BOX(hbox), favicon_image, FALSE, FALSE, 0); |
114 | 111 |
115 // Create the label with application shortcut description. | 112 // Create the label with application shortcut description. |
116 GtkWidget* description_label = gtk_label_new(NULL); | 113 GtkWidget* description_label = gtk_label_new(NULL); |
117 gtk_box_pack_start(GTK_BOX(hbox), description_label, FALSE, FALSE, 0); | 114 gtk_box_pack_start(GTK_BOX(hbox), description_label, FALSE, FALSE, 0); |
118 gtk_label_set_line_wrap(GTK_LABEL(description_label), TRUE); | 115 gtk_label_set_line_wrap(GTK_LABEL(description_label), TRUE); |
119 gtk_widget_realize(description_label); | 116 gtk_widget_realize(description_label); |
120 int label_height; | 117 |
121 gtk_util::GetWidgetSizeFromCharacters(description_label, -1, | 118 // Set the size request on the label so it knows where to line wrap. The width |
122 kDescriptionLabelHeightLines, NULL, | 119 // is the desired size of the dialog less the space reserved for padding and |
123 &label_height); | 120 // the image. |
124 gtk_widget_set_size_request(description_label, -1, label_height); | 121 int label_width, label_height; |
| 122 gtk_util::GetWidgetSizeFromResources( |
| 123 description_label, |
| 124 IDS_CREATE_SHORTCUTS_DIALOG_WIDTH_CHARS, -1, &label_width, NULL); |
| 125 label_width -= gtk_util::kControlSpacing * 3 + |
| 126 gdk_pixbuf_get_width(favicon_pixbuf_); |
| 127 gtk_util::GetWidgetSizeFromCharacters( |
| 128 description_label, -1, kDescriptionLabelHeightLines, NULL, &label_height); |
| 129 gtk_widget_set_size_request(description_label, label_width, label_height); |
125 gtk_misc_set_alignment(GTK_MISC(description_label), 0, 0.5); | 130 gtk_misc_set_alignment(GTK_MISC(description_label), 0, 0.5); |
126 std::string description(UTF16ToUTF8(shortcut_info_.description)); | 131 std::string description(UTF16ToUTF8(shortcut_info_.description)); |
127 std::string title(UTF16ToUTF8(shortcut_info_.title)); | 132 std::string title(UTF16ToUTF8(shortcut_info_.title)); |
128 gtk_label_set_text(GTK_LABEL(description_label), | 133 gtk_label_set_text(GTK_LABEL(description_label), |
129 (description.empty() ? title : description).c_str()); | 134 (description.empty() ? title : description).c_str()); |
130 | 135 |
131 // Label on top of the checkboxes. | 136 // Label on top of the checkboxes. |
132 GtkWidget* checkboxes_label = gtk_label_new( | 137 GtkWidget* checkboxes_label = gtk_label_new( |
133 l10n_util::GetStringUTF8(IDS_CREATE_SHORTCUTS_LABEL).c_str()); | 138 l10n_util::GetStringUTF8(IDS_CREATE_SHORTCUTS_LABEL).c_str()); |
134 gtk_misc_set_alignment(GTK_MISC(checkboxes_label), 0, 0); | 139 gtk_misc_set_alignment(GTK_MISC(checkboxes_label), 0, 0); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 SkBitmap* image, ExtensionResource resource, int index) { | 321 SkBitmap* image, ExtensionResource resource, int index) { |
317 if (image->isNull()) { | 322 if (image->isNull()) { |
318 NOTREACHED() << "Corrupt image in profile?"; | 323 NOTREACHED() << "Corrupt image in profile?"; |
319 return; | 324 return; |
320 } | 325 } |
321 shortcut_info_.favicon = *image; | 326 shortcut_info_.favicon = *image; |
322 | 327 |
323 CreateIconPixBuf(*image); | 328 CreateIconPixBuf(*image); |
324 CreateDialogBox(parent_); | 329 CreateDialogBox(parent_); |
325 } | 330 } |
OLD | NEW |