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 #ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_UTIL_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_UTIL_H_ | |
7 #pragma once | |
8 | |
9 #include "base/string16.h" | |
10 #include "chrome/browser/chromeos/language_preferences.h" | |
11 #include "ui/base/models/combobox_model.h" | |
12 #include "views/controls/combobox/combobox.h" | |
13 | |
14 namespace chromeos { | |
15 | |
16 // The combobox model for Language input method prefs. | |
17 template <typename DataType> | |
18 class LanguageComboboxModel : public ui::ComboboxModel { | |
19 public: | |
20 explicit LanguageComboboxModel( | |
21 const language_prefs::LanguageMultipleChoicePreference<DataType>* | |
22 pref_data) | |
23 : pref_data_(pref_data), num_items_(0) { | |
24 // Check how many items are defined in the |pref_data->values_and_ids| | |
25 // array. | |
26 for (size_t i = 0; | |
27 i < language_prefs::LanguageMultipleChoicePreference<DataType>:: | |
28 kMaxItems; ++i) { | |
29 if ((pref_data_->values_and_ids)[i].item_message_id == 0) { | |
30 break; | |
31 } | |
32 ++num_items_; | |
33 } | |
34 } | |
35 | |
36 // Implements ui::ComboboxModel interface. | |
37 virtual int GetItemCount() { | |
38 return num_items_; | |
39 } | |
40 | |
41 // Implements ui::ComboboxModel interface. | |
42 virtual string16 GetItemAt(int index) { | |
43 if (index < 0 || index >= num_items_) { | |
44 LOG(ERROR) << "Index is out of bounds: " << index; | |
45 return string16(); | |
46 } | |
47 const int message_id = (pref_data_->values_and_ids)[index].item_message_id; | |
48 return l10n_util::GetStringUTF16(message_id); | |
49 } | |
50 | |
51 // Gets a label for the combobox like "Input mode". This function is NOT part | |
52 // of the ComboboxModel interface. | |
53 std::wstring GetLabel() const { | |
54 return UTF16ToWide(l10n_util::GetStringUTF16(pref_data_->label_message_id)); | |
55 } | |
56 | |
57 // Gets a config value for the ibus configuration daemon (e.g. "KUTEN_TOUTEN", | |
58 // "KUTEN_PERIOD", ..) for an item at zero-origin |index|. This function is | |
59 // NOT part of the ComboboxModel interface. | |
60 DataType GetConfigValueAt(int index) const { | |
61 if (index < 0 || index >= num_items_) { | |
62 LOG(ERROR) << "Index is out of bounds: " << index; | |
63 return (pref_data_->values_and_ids)[0].ibus_config_value; | |
64 } | |
65 return (pref_data_->values_and_ids)[index].ibus_config_value; | |
66 } | |
67 | |
68 int num_items() { | |
69 return num_items_; | |
70 } | |
71 | |
72 private: | |
73 const language_prefs::LanguageMultipleChoicePreference<DataType>* pref_data_; | |
74 int num_items_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(LanguageComboboxModel); | |
77 }; | |
78 | |
79 // The combobox for the dialog which has minimum width. | |
80 class LanguageCombobox : public views::Combobox { | |
81 public: | |
82 explicit LanguageCombobox(ui::ComboboxModel* model) : Combobox(model) { | |
83 } | |
84 | |
85 virtual gfx::Size GetPreferredSize() { | |
86 gfx::Size size = Combobox::GetPreferredSize(); | |
87 if (size.width() < kMinComboboxWidth) { | |
88 size.set_width(kMinComboboxWidth); | |
89 } | |
90 return size; | |
91 } | |
92 | |
93 private: | |
94 static const int kMinComboboxWidth = 250; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(LanguageCombobox); | |
97 }; | |
98 | |
99 } // namespace chromeos | |
100 | |
101 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_UTIL_H_ | |
OLD | NEW |