OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 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 VIEWS_CONTROLS_COMBO_BOX_H_ | |
6 #define VIEWS_CONTROLS_COMBO_BOX_H_ | |
7 | |
8 #include "views/controls/native_control.h" | |
9 | |
10 namespace views { | |
11 //////////////////////////////////////////////////////////////////////////////// | |
12 // | |
13 // ComboBox is a basic non editable combo box. It is initialized from a simple | |
14 // model. | |
15 // | |
16 //////////////////////////////////////////////////////////////////////////////// | |
17 class ComboBox : public NativeControl { | |
18 public: | |
19 class Model { | |
20 public: | |
21 // Return the number of items in the combo box. | |
22 virtual int GetItemCount(ComboBox* source) = 0; | |
23 | |
24 // Return the string that should be used to represent a given item. | |
25 virtual std::wstring GetItemAt(ComboBox* source, int index) = 0; | |
26 }; | |
27 | |
28 class Listener { | |
29 public: | |
30 // This is invoked once the selected item changed. | |
31 virtual void ItemChanged(ComboBox* combo_box, | |
32 int prev_index, | |
33 int new_index) = 0; | |
34 }; | |
35 | |
36 // |model is not owned by the combo box. | |
37 explicit ComboBox(Model* model); | |
38 virtual ~ComboBox(); | |
39 | |
40 // Register |listener| for item change events. | |
41 void SetListener(Listener* listener); | |
42 | |
43 // Overridden from View. | |
44 virtual gfx::Size GetPreferredSize(); | |
45 virtual bool OverrideAccelerator(const Accelerator& accelerator); | |
46 | |
47 // Overridden from NativeControl | |
48 virtual HWND CreateNativeControl(HWND parent_container); | |
49 virtual LRESULT OnCommand(UINT code, int id, HWND source); | |
50 virtual LRESULT OnNotify(int w_param, LPNMHDR l_param); | |
51 | |
52 // Inform the combo box that its model changed. | |
53 void ModelChanged(); | |
54 | |
55 // Set / Get the selected item. | |
56 void SetSelectedItem(int index); | |
57 int GetSelectedItem(); | |
58 | |
59 private: | |
60 // Update a combo box from our model. | |
61 void UpdateComboBoxFromModel(HWND hwnd); | |
62 | |
63 // Our model. | |
64 Model* model_; | |
65 | |
66 // The current selection. | |
67 int selected_item_; | |
68 | |
69 // Item change listener. | |
70 Listener* listener_; | |
71 | |
72 // The min width, in pixels, for the text content. | |
73 int content_width_; | |
74 | |
75 DISALLOW_EVIL_CONSTRUCTORS(ComboBox); | |
76 }; | |
77 | |
78 } // namespace views | |
79 | |
80 #endif // VIEWS_CONTROLS_COMBO_BOX_H_ | |
OLD | NEW |