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