| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ | 5 #ifndef UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ |
| 6 #define UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ | 6 #define UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "ui/gfx/native_widget_types.h" | 11 #include "ui/gfx/native_widget_types.h" |
| 12 #include "ui/views/controls/combobox/native_combobox_wrapper.h" | 12 #include "ui/views/controls/combobox/native_combobox_wrapper.h" |
| 13 #include "ui/views/view.h" | 13 #include "ui/views/view.h" |
| 14 | 14 |
| 15 namespace gfx { | 15 namespace gfx { |
| 16 class Font; | 16 class Font; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 class ComboboxModel; | 20 class ComboboxModel; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace views { | 23 namespace views { |
| 24 | 24 |
| 25 class ComboboxListener; | 25 class ComboboxListener; |
| 26 | 26 |
| 27 // A non-editable combo-box (aka a drop-down list) | 27 // A non-editable combobox (aka a drop-down list). |
| 28 class VIEWS_EXPORT Combobox : public View { | 28 class VIEWS_EXPORT Combobox : public View { |
| 29 public: | 29 public: |
| 30 // The combobox's class name. | 30 // The combobox's class name. |
| 31 static const char kViewClassName[]; | 31 static const char kViewClassName[]; |
| 32 | 32 |
| 33 // |model| is not owned by the combo box. | 33 // |model| is not owned by the combobox. |
| 34 explicit Combobox(ui::ComboboxModel* model); | 34 explicit Combobox(ui::ComboboxModel* model); |
| 35 virtual ~Combobox(); | 35 virtual ~Combobox(); |
| 36 | 36 |
| 37 static const gfx::Font& GetFont(); | 37 static const gfx::Font& GetFont(); |
| 38 | 38 |
| 39 // Register |listener| for item change events. | 39 // Sets the listener which will be called when a selection has been made. |
| 40 void set_listener(ComboboxListener* listener) { | 40 void set_listener(ComboboxListener* listener) { |
| 41 listener_ = listener; | 41 listener_ = listener; |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Inform the combo box that its model changed. | 44 // Informs the combobox that its model changed. |
| 45 void ModelChanged(); | 45 void ModelChanged(); |
| 46 | 46 |
| 47 // Gets/Sets the selected item. | 47 // Gets/Sets the selected index. |
| 48 int selected_item() const { return selected_item_; } | 48 int selected_index() const { return selected_index_; } |
| 49 void SetSelectedItem(int index); | 49 void SetSelectedIndex(int index); |
| 50 | 50 |
| 51 // Called when the combo box's selection is changed by the user. | 51 // Called when the combobox's selection is changed by the user. |
| 52 void SelectionChanged(); | 52 void SelectionChanged(); |
| 53 | 53 |
| 54 // Accessor for |model_|. | |
| 55 ui::ComboboxModel* model() const { return model_; } | 54 ui::ComboboxModel* model() const { return model_; } |
| 56 | 55 |
| 57 // Set the accessible name of the combo box. | 56 // Set the accessible name of the combobox. |
| 58 void SetAccessibleName(const string16& name); | 57 void SetAccessibleName(const string16& name); |
| 59 | 58 |
| 60 // Provided only for testing: | 59 // Provided only for testing: |
| 61 gfx::NativeView GetTestingHandle() const { | 60 gfx::NativeView GetTestingHandle() const { |
| 62 return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL; | 61 return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL; |
| 63 } | 62 } |
| 64 NativeComboboxWrapper* GetNativeWrapperForTesting() const { | 63 NativeComboboxWrapper* GetNativeWrapperForTesting() const { |
| 65 return native_wrapper_; | 64 return native_wrapper_; |
| 66 } | 65 } |
| 67 | 66 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 81 // Overridden from View: | 80 // Overridden from View: |
| 82 virtual void ViewHierarchyChanged(bool is_add, | 81 virtual void ViewHierarchyChanged(bool is_add, |
| 83 View* parent, | 82 View* parent, |
| 84 View* child) OVERRIDE; | 83 View* child) OVERRIDE; |
| 85 virtual std::string GetClassName() const OVERRIDE; | 84 virtual std::string GetClassName() const OVERRIDE; |
| 86 | 85 |
| 87 // The object that actually implements the native combobox. | 86 // The object that actually implements the native combobox. |
| 88 NativeComboboxWrapper* native_wrapper_; | 87 NativeComboboxWrapper* native_wrapper_; |
| 89 | 88 |
| 90 private: | 89 private: |
| 91 // Our model. | 90 // Our model. Not owned. |
| 92 ui::ComboboxModel* model_; | 91 ui::ComboboxModel* model_; |
| 93 | 92 |
| 94 // The combobox's listener. Notified when the selected item change. | 93 // Our listener. Not owned. Notified when the selected index change. |
| 95 ComboboxListener* listener_; | 94 ComboboxListener* listener_; |
| 96 | 95 |
| 97 // The current selection. | 96 // The current selected index. |
| 98 int selected_item_; | 97 int selected_index_; |
| 99 | 98 |
| 100 // The accessible name of the text field. | 99 // The accessible name of this combobox. |
| 101 string16 accessible_name_; | 100 string16 accessible_name_; |
| 102 | 101 |
| 103 DISALLOW_COPY_AND_ASSIGN(Combobox); | 102 DISALLOW_COPY_AND_ASSIGN(Combobox); |
| 104 }; | 103 }; |
| 105 | 104 |
| 106 } // namespace views | 105 } // namespace views |
| 107 | 106 |
| 108 #endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ | 107 #endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ |
| OLD | NEW |