| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/options/language_pinyin_config_view.h" | |
| 6 | |
| 7 #include "app/l10n_util.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 10 #include "chrome/browser/chromeos/cros/input_method_library.h" | |
| 11 #include "chrome/browser/chromeos/options/language_config_util.h" | |
| 12 #include "chrome/browser/chromeos/preferences.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/common/notification_type.h" | |
| 15 #include "grit/generated_resources.h" | |
| 16 #include "grit/locale_settings.h" | |
| 17 #include "views/controls/button/checkbox.h" | |
| 18 #include "views/controls/label.h" | |
| 19 #include "views/grid_layout.h" | |
| 20 #include "views/standard_layout.h" | |
| 21 #include "views/window/window.h" | |
| 22 | |
| 23 namespace chromeos { | |
| 24 | |
| 25 LanguagePinyinConfigView::LanguagePinyinConfigView(Profile* profile) | |
| 26 : OptionsPageView(profile), contents_(NULL) { | |
| 27 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { | |
| 28 pinyin_boolean_prefs_[i].Init( | |
| 29 language_prefs::kPinyinBooleanPrefs[i].pref_name, profile->GetPrefs(), | |
| 30 this); | |
| 31 pinyin_boolean_checkboxes_[i] = NULL; | |
| 32 } | |
| 33 | |
| 34 double_pinyin_schema_.multiple_choice_pref.Init( | |
| 35 language_prefs::kPinyinDoublePinyinSchema.pref_name, | |
| 36 profile->GetPrefs(), this); | |
| 37 double_pinyin_schema_.combobox_model = | |
| 38 new LanguageComboboxModel<int>( | |
| 39 &language_prefs::kPinyinDoublePinyinSchema); | |
| 40 double_pinyin_schema_.combobox = NULL; | |
| 41 } | |
| 42 | |
| 43 LanguagePinyinConfigView::~LanguagePinyinConfigView() { | |
| 44 } | |
| 45 | |
| 46 void LanguagePinyinConfigView::ButtonPressed( | |
| 47 views::Button* sender, const views::Event& event) { | |
| 48 views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); | |
| 49 const int pref_id = checkbox->tag(); | |
| 50 DCHECK(pref_id >= 0 && pref_id < static_cast<int>( | |
| 51 language_prefs::kNumPinyinBooleanPrefs)); | |
| 52 pinyin_boolean_prefs_[pref_id].SetValue(checkbox->checked()); | |
| 53 } | |
| 54 | |
| 55 void LanguagePinyinConfigView::ItemChanged( | |
| 56 views::Combobox* sender, int prev_index, int new_index) { | |
| 57 if (double_pinyin_schema_.combobox == sender) { | |
| 58 const int config_value = | |
| 59 double_pinyin_schema_.combobox_model->GetConfigValueAt(new_index); | |
| 60 VLOG(1) << "Changing Pinyin pref to " << config_value; | |
| 61 // Update the Chrome pref. | |
| 62 double_pinyin_schema_.multiple_choice_pref.SetValue(config_value); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 void LanguagePinyinConfigView::Layout() { | |
| 67 // Not sure why but this is needed to show contents in the dialog. | |
| 68 contents_->SetBounds(0, 0, width(), height()); | |
| 69 } | |
| 70 | |
| 71 int LanguagePinyinConfigView::GetDialogButtons() const { | |
| 72 return MessageBoxFlags::DIALOGBUTTON_OK; | |
| 73 } | |
| 74 | |
| 75 std::wstring LanguagePinyinConfigView::GetDialogButtonLabel( | |
| 76 MessageBoxFlags::DialogButton button) const { | |
| 77 if (button == MessageBoxFlags::DIALOGBUTTON_OK) { | |
| 78 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_OK)); | |
| 79 } | |
| 80 return L""; | |
| 81 } | |
| 82 | |
| 83 std::wstring LanguagePinyinConfigView::GetWindowTitle() const { | |
| 84 return UTF16ToWide(l10n_util::GetStringUTF16( | |
| 85 IDS_OPTIONS_SETTINGS_LANGUAGES_PINYIN_SETTINGS_TITLE)); | |
| 86 } | |
| 87 | |
| 88 gfx::Size LanguagePinyinConfigView::GetPreferredSize() { | |
| 89 // TODO(satorux): Create our own localized content size once the UI is done. | |
| 90 return gfx::Size(views::Window::GetLocalizedContentsSize( | |
| 91 IDS_LANGUAGES_INPUT_DIALOG_WIDTH_CHARS, | |
| 92 IDS_LANGUAGES_INPUT_DIALOG_HEIGHT_LINES)); | |
| 93 } | |
| 94 | |
| 95 void LanguagePinyinConfigView::InitControlLayout() { | |
| 96 using views::ColumnSet; | |
| 97 using views::GridLayout; | |
| 98 | |
| 99 contents_ = new views::View; | |
| 100 AddChildView(contents_); | |
| 101 | |
| 102 GridLayout* layout = new GridLayout(contents_); | |
| 103 layout->SetInsets(kPanelVertMargin, kPanelHorizMargin, | |
| 104 kPanelVertMargin, kPanelHorizMargin); | |
| 105 contents_->SetLayoutManager(layout); | |
| 106 | |
| 107 const int kColumnSetId = 0; | |
| 108 ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); | |
| 109 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | |
| 110 GridLayout::USE_PREF, 0, 0); | |
| 111 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | |
| 112 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | |
| 113 GridLayout::USE_PREF, 0, 0); | |
| 114 | |
| 115 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { | |
| 116 pinyin_boolean_checkboxes_[i] = new views::Checkbox( | |
| 117 UTF16ToWide(l10n_util::GetStringUTF16( | |
| 118 language_prefs::kPinyinBooleanPrefs[i].message_id))); | |
| 119 pinyin_boolean_checkboxes_[i]->set_listener(this); | |
| 120 pinyin_boolean_checkboxes_[i]->set_tag(i); | |
| 121 } | |
| 122 double_pinyin_schema_.combobox = | |
| 123 new LanguageCombobox(double_pinyin_schema_.combobox_model); | |
| 124 double_pinyin_schema_.combobox->set_listener(this); | |
| 125 | |
| 126 NotifyPrefChanged(); | |
| 127 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { | |
| 128 layout->StartRow(0, kColumnSetId); | |
| 129 layout->AddView(pinyin_boolean_checkboxes_[i]); | |
| 130 } | |
| 131 layout->StartRow(0, kColumnSetId); | |
| 132 layout->AddView( | |
| 133 new views::Label(double_pinyin_schema_.combobox_model->GetLabel())); | |
| 134 layout->AddView(double_pinyin_schema_.combobox); | |
| 135 } | |
| 136 | |
| 137 void LanguagePinyinConfigView::Observe(NotificationType type, | |
| 138 const NotificationSource& source, | |
| 139 const NotificationDetails& details) { | |
| 140 if (type == NotificationType::PREF_CHANGED) { | |
| 141 NotifyPrefChanged(); | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 void LanguagePinyinConfigView::NotifyPrefChanged() { | |
| 146 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) { | |
| 147 const bool checked = pinyin_boolean_prefs_[i].GetValue(); | |
| 148 pinyin_boolean_checkboxes_[i]->SetChecked(checked); | |
| 149 } | |
| 150 const int value = double_pinyin_schema_.multiple_choice_pref.GetValue(); | |
| 151 for (int i = 0; i < double_pinyin_schema_.combobox_model->num_items(); ++i) { | |
| 152 if (double_pinyin_schema_.combobox_model->GetConfigValueAt(i) == value) { | |
| 153 double_pinyin_schema_.combobox->SetSelectedItem(i); | |
| 154 break; | |
| 155 } | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 } // namespace chromeos | |
| OLD | NEW |