summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-11 00:21:57 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-11 00:21:57 +0000
commit54211c3efb9d4a9b47f3369bdc9f95827e39465e (patch)
tree1dc9c9f18e3b7a369651ab082c2fee9b323621d9
parentb2b462c79bd4365c76ec90dd74f15ea4e8252638 (diff)
downloadchromium_src-54211c3efb9d4a9b47f3369bdc9f95827e39465e.zip
chromium_src-54211c3efb9d4a9b47f3369bdc9f95827e39465e.tar.gz
chromium_src-54211c3efb9d4a9b47f3369bdc9f95827e39465e.tar.bz2
Add helper for creating table of labeled controls.
BUG=none Review URL: http://codereview.chromium.org/118489 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18120 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/bookmark_bubble_gtk.cc26
-rw-r--r--chrome/browser/gtk/bookmark_editor_gtk.cc33
-rw-r--r--chrome/common/gtk_util.cc26
-rw-r--r--chrome/common/gtk_util.h8
4 files changed, 49 insertions, 44 deletions
diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.cc b/chrome/browser/gtk/bookmark_bubble_gtk.cc
index adf0874..b875f4f 100644
--- a/chrome/browser/gtk/bookmark_bubble_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bubble_gtk.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/gtk/info_bubble_gtk.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
+#include "chrome/common/gtk_util.h"
#include "grit/generated_resources.h"
namespace {
@@ -119,10 +120,6 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel,
IDS_BOOMARK_BUBBLE_PAGE_BOOKMARK).c_str());
GtkWidget* remove_button = gtk_chrome_link_button_new(
l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_REMOVE_BOOKMARK).c_str());
- GtkWidget* name_label = gtk_label_new(
- l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_TITLE_TEXT).c_str());
- GtkWidget* folder_label = gtk_label_new(
- l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_FOLDER_TEXT).c_str());
GtkWidget* edit_button = gtk_button_new_with_label(
l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_OPTIONS).c_str());
GtkWidget* close_button = gtk_button_new_with_label(
@@ -154,21 +151,12 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel,
// We use a table to allow the labels to line up with each other, along
// with the entry and folder combo lining up.
- GtkWidget* table = gtk_table_new(2, 2, FALSE);
- gtk_table_set_row_spacings(GTK_TABLE(table), 5);
- gtk_table_set_col_spacings(GTK_TABLE(table), 10);
- gtk_table_attach_defaults(GTK_TABLE(table),
- name_label,
- 0, 1, 0, 1);
- gtk_table_attach_defaults(GTK_TABLE(table),
- name_entry_,
- 1, 2, 0, 1);
- gtk_table_attach_defaults(GTK_TABLE(table),
- folder_label,
- 0, 1, 1, 2);
- gtk_table_attach_defaults(GTK_TABLE(table),
- folder_combo_,
- 1, 2, 1, 2);
+ GtkWidget* table = gtk_util::CreateLabeledControlsGroup(
+ l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_TITLE_TEXT).c_str(),
+ name_entry_,
+ l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_FOLDER_TEXT).c_str(),
+ folder_combo_,
+ NULL);
GtkWidget* bottom = gtk_hbox_new(FALSE, 0);
// We want the buttons on the right, so just use an expanding label to fill
diff --git a/chrome/browser/gtk/bookmark_editor_gtk.cc b/chrome/browser/gtk/bookmark_editor_gtk.cc
index d667d86..05d1ec2 100644
--- a/chrome/browser/gtk/bookmark_editor_gtk.cc
+++ b/chrome/browser/gtk/bookmark_editor_gtk.cc
@@ -127,43 +127,26 @@ void BookmarkEditorGtk::Init(GtkWindow* parent_window) {
GtkWidget* vbox = gtk_vbox_new(FALSE, 12);
- GtkWidget* table = gtk_table_new(2, 2, FALSE);
- gtk_table_set_col_spacing(GTK_TABLE(table), 0, gtk_util::kLabelSpacing);
- gtk_table_set_row_spacings(GTK_TABLE(table), gtk_util::kControlSpacing);
-
- GtkWidget* label = gtk_label_new(
- l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NAME_LABEL).c_str());
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
- gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(label),
- 0, 1, 0, 1,
- (GtkAttachOptions)(GTK_FILL),
- (GtkAttachOptions)(GTK_FILL),
- 0, 0);
name_entry_ = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(name_entry_),
node_ ? WideToUTF8(node_->GetTitle()).c_str() : "");
g_signal_connect(G_OBJECT(name_entry_), "changed",
G_CALLBACK(OnEntryChanged), this);
gtk_entry_set_activates_default(GTK_ENTRY(name_entry_), TRUE);
- gtk_table_attach_defaults(GTK_TABLE(table), GTK_WIDGET(name_entry_),
- 1, 2, 0, 1);
-
- label = gtk_label_new(
- l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_URL_LABEL).c_str());
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
- gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(label),
- 0, 1, 1, 2,
- (GtkAttachOptions)(GTK_FILL),
- (GtkAttachOptions)(GTK_FILL),
- 0, 0);
+
url_entry_ = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(url_entry_),
node_ ? node_->GetURL().spec().c_str() : "");
g_signal_connect(G_OBJECT(url_entry_), "changed",
G_CALLBACK(OnEntryChanged), this);
gtk_entry_set_activates_default(GTK_ENTRY(url_entry_), TRUE);
- gtk_table_attach_defaults(GTK_TABLE(table), GTK_WIDGET(url_entry_),
- 1, 2, 1, 2);
+
+ GtkWidget* table = gtk_util::CreateLabeledControlsGroup(
+ l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NAME_LABEL).c_str(),
+ name_entry_,
+ l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_URL_LABEL).c_str(),
+ url_entry_,
+ NULL);
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc
index 95fe87b..b280a6b 100644
--- a/chrome/common/gtk_util.cc
+++ b/chrome/common/gtk_util.cc
@@ -4,6 +4,7 @@
#include "chrome/common/gtk_util.h"
+#include <cstdarg>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
@@ -37,6 +38,31 @@ WindowOpenDisposition DispositionFromEventFlags(guint event_flags) {
namespace gtk_util {
+GtkWidget* CreateLabeledControlsGroup(const char* text, ...) {
+ va_list ap;
+ va_start(ap, text);
+ GtkWidget* table = gtk_table_new(0, 2, FALSE);
+ gtk_table_set_col_spacing(GTK_TABLE(table), 0, kLabelSpacing);
+ gtk_table_set_row_spacings(GTK_TABLE(table), kControlSpacing);
+
+ for (guint row = 0; text; ++row) {
+ gtk_table_resize(GTK_TABLE(table), row + 1, 2);
+ GtkWidget* control = va_arg(ap, GtkWidget*);
+ GtkWidget* label = gtk_label_new(text);
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+ gtk_table_attach(GTK_TABLE(table), label,
+ 0, 1, row, row + 1,
+ GTK_FILL, GTK_FILL,
+ 0, 0);
+ gtk_table_attach_defaults(GTK_TABLE(table), control,
+ 1, 2, row, row + 1);
+ text = va_arg(ap, const char*);
+ }
+ va_end(ap);
+
+ return table;
+}
+
GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color,
int top, int bottom, int left, int right) {
// Use a GtkEventBox to get the background painted. However, we can't just
diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h
index 52629d3..92ea54e 100644
--- a/chrome/common/gtk_util.h
+++ b/chrome/common/gtk_util.h
@@ -44,6 +44,14 @@ const int kContentAreaBorder = 12;
// Spacing between groups of controls.
const int kContentAreaSpacing = 18;
+// Create a table of labeled controls, using proper spacing and alignment.
+// Arguments should be pairs of const char*, GtkWidget*, concluding with a NULL.
+// For example:
+// controls = CreateLabeledControlsGroup("Name:", title_entry_,
+// "Folder:", folder_combobox_,
+// NULL);
+GtkWidget* CreateLabeledControlsGroup(const char* text, ...);
+
// Create a GtkBin with |child| as its child widget. This bin will paint a
// border of color |color| with the sizes specified in pixels.
GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color,