| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/gtk/options/options_layout_gtk.h" | |
| 6 | |
| 7 #include "chrome/browser/gtk/gtk_util.h" | |
| 8 | |
| 9 // If the height of screen is equal or shorter than this, we will use | |
| 10 // a more compact option layout. | |
| 11 const int kCompactScreenHeight = 600; | |
| 12 | |
| 13 // Default option layout builder follows GNOME HIG, which uses header and | |
| 14 // spacing to group options. | |
| 15 class DefaultOptionsLayoutBuilderGtk : public OptionsLayoutBuilderGtk { | |
| 16 public: | |
| 17 explicit DefaultOptionsLayoutBuilderGtk(); | |
| 18 | |
| 19 void AddOptionGroup(const std::string& title, GtkWidget* content, | |
| 20 bool expandable); | |
| 21 void AddWidget(GtkWidget* content, bool expandable); | |
| 22 private: | |
| 23 DISALLOW_COPY_AND_ASSIGN(DefaultOptionsLayoutBuilderGtk); | |
| 24 }; | |
| 25 | |
| 26 DefaultOptionsLayoutBuilderGtk::DefaultOptionsLayoutBuilderGtk() { | |
| 27 page_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing); | |
| 28 gtk_container_set_border_width(GTK_CONTAINER(page_), | |
| 29 gtk_util::kContentAreaBorder); | |
| 30 } | |
| 31 | |
| 32 void DefaultOptionsLayoutBuilderGtk::AddOptionGroup(const std::string& title, | |
| 33 GtkWidget* content, | |
| 34 bool expandable) { | |
| 35 GtkWidget* title_label = gtk_util::CreateBoldLabel(title); | |
| 36 | |
| 37 GtkWidget* group = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); | |
| 38 gtk_box_pack_start(GTK_BOX(group), title_label, FALSE, FALSE, 0); | |
| 39 gtk_container_add(GTK_CONTAINER(group), gtk_util::IndentWidget(content)); | |
| 40 | |
| 41 AddWidget(group, expandable); | |
| 42 } | |
| 43 | |
| 44 void DefaultOptionsLayoutBuilderGtk::AddWidget(GtkWidget* content, | |
| 45 bool expandable) { | |
| 46 gtk_box_pack_start(GTK_BOX(page_), content, expandable, expandable, 0); | |
| 47 } | |
| 48 | |
| 49 // Compact layout builder uses table to layout label and content horizontally. | |
| 50 class CompactOptionsLayoutBuilderGtk : public OptionsLayoutBuilderGtk { | |
| 51 public: | |
| 52 explicit CompactOptionsLayoutBuilderGtk(); | |
| 53 | |
| 54 void AddOptionGroup(const std::string& title, GtkWidget* content, | |
| 55 bool expandable); | |
| 56 void AddWidget(GtkWidget* content, bool expandable); | |
| 57 private: | |
| 58 GtkWidget *table_; | |
| 59 guint row_; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(CompactOptionsLayoutBuilderGtk); | |
| 62 }; | |
| 63 | |
| 64 CompactOptionsLayoutBuilderGtk::CompactOptionsLayoutBuilderGtk() { | |
| 65 row_ = 0; | |
| 66 table_ = NULL; | |
| 67 | |
| 68 page_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing); | |
| 69 gtk_container_set_border_width(GTK_CONTAINER(page_), | |
| 70 gtk_util::kContentAreaBorder); | |
| 71 } | |
| 72 | |
| 73 void CompactOptionsLayoutBuilderGtk::AddOptionGroup(const std::string& title, | |
| 74 GtkWidget* content, | |
| 75 bool expandable) { | |
| 76 if (!table_) { | |
| 77 // Create a new table to contain option groups | |
| 78 table_ = gtk_table_new(0, 2, FALSE); | |
| 79 gtk_table_set_col_spacing(GTK_TABLE(table_), 0, gtk_util::kLabelSpacing); | |
| 80 gtk_table_set_row_spacings(GTK_TABLE(table_), | |
| 81 gtk_util::kContentAreaSpacing); | |
| 82 | |
| 83 gtk_container_set_border_width(GTK_CONTAINER(table_), | |
| 84 gtk_util::kContentAreaBorder); | |
| 85 gtk_box_pack_start(GTK_BOX(page_), table_, TRUE, TRUE, 0); | |
| 86 } | |
| 87 | |
| 88 GtkWidget* title_label = gtk_util::CreateBoldLabel(title); | |
| 89 | |
| 90 gtk_table_resize(GTK_TABLE(table_), row_ + 1, 2); | |
| 91 gtk_misc_set_alignment(GTK_MISC(title_label), 1, 0); | |
| 92 | |
| 93 gtk_table_attach(GTK_TABLE(table_), title_label, | |
| 94 0, 1, row_, row_ + 1, | |
| 95 GTK_FILL, GTK_FILL, | |
| 96 0, 0); | |
| 97 gtk_table_attach(GTK_TABLE(table_), content, | |
| 98 1, 2, row_, row_ + 1, | |
| 99 expandable ? | |
| 100 GTK_FILL : GtkAttachOptions(GTK_FILL | GTK_EXPAND), | |
| 101 GTK_FILL, | |
| 102 0, 0); | |
| 103 row_++; | |
| 104 } | |
| 105 | |
| 106 void CompactOptionsLayoutBuilderGtk::AddWidget(GtkWidget* content, | |
| 107 bool expandable) { | |
| 108 gtk_box_pack_start(GTK_BOX(page_), content, expandable, expandable, 0); | |
| 109 | |
| 110 // Let AddOptionGroup create a new table and append after this widget | |
| 111 table_ = NULL; | |
| 112 } | |
| 113 | |
| 114 OptionsLayoutBuilderGtk* OptionsLayoutBuilderGtk::Create() { | |
| 115 return new DefaultOptionsLayoutBuilderGtk(); | |
| 116 } | |
| 117 | |
| 118 OptionsLayoutBuilderGtk* | |
| 119 OptionsLayoutBuilderGtk::CreateOptionallyCompactLayout() { | |
| 120 gint screen_height = gdk_screen_get_height(gdk_screen_get_default()); | |
| 121 if (screen_height <= kCompactScreenHeight) | |
| 122 return new CompactOptionsLayoutBuilderGtk(); | |
| 123 else | |
| 124 return new DefaultOptionsLayoutBuilderGtk(); | |
| 125 } | |
| OLD | NEW |