1 ////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // Nestopia - NES/Famicom emulator written in C++
4 //
5 // Copyright (C) 2003-2008 Martin Freij
6 //
7 // This file is part of Nestopia.
8 //
9 // Nestopia is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Nestopia is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Nestopia; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 //
23 ////////////////////////////////////////////////////////////////////////////////////////
24 
25 #ifndef NST_CTRL_COMBOBOX_H
26 #define NST_CTRL_COMBOBOX_H
27 
28 #pragma once
29 
30 #include "NstCtrlStandard.hpp"
31 
32 namespace Nestopia
33 {
34 	namespace Window
35 	{
36 		namespace Control
37 		{
38 			class ComboBox : public Generic
39 			{
40 			public:
41 
42 				typedef ULONG_PTR Value;
43 
44 			private:
45 
46 				class Item : public ImplicitBool<Item>
47 				{
48 					class DataProxy
49 					{
50 						const Item& item;
51 
52 					public:
53 
DataProxy(const Item & i)54 						DataProxy(const Item& i)
55 						: item(i) {}
56 
57 						operator Value () const;
58 						void operator = (const Value) const;
59 					};
60 
61 					const Window::Generic control;
62 					const int index;
63 
64 				public:
65 
Item(Window::Generic w,int i)66 					Item(Window::Generic w,int i)
67 					: control(w), index(i) {}
68 
69 					void Erase() const;
70 					void Select() const;
71 
GetIndex() const72 					int GetIndex() const
73 					{
74 						return index;
75 					}
76 
operator !() const77 					bool operator ! () const
78 					{
79 						return index < 0;
80 					}
81 
Data() const82 					DataProxy Data() const
83 					{
84 						return *this;
85 					}
86 				};
87 
88 			public:
89 
ComboBox(HWND hWnd=NULL)90 				ComboBox(HWND hWnd=NULL)
91 				: Generic( hWnd ) {}
92 
ComboBox(HWND hWnd,uint id)93 				ComboBox(HWND hWnd,uint id)
94 				: Generic( hWnd, id ) {}
95 
96 				void Reserve(uint,uint) const;
97 				Item Add(wcstring) const;
98 				void Clear() const;
99 				Item Selection() const;
100 				uint Size() const;
101 
operator [](uint i) const102 				Item operator [] (uint i) const
103 				{
104 					return Item( control, i );
105 				}
106 
Back() const107 				Item Back() const
108 				{
109 					return Item( control, Size() - 1 );
110 				}
111 
112 				template<typename T>
Add(T * list,uint count) const113 				void Add(T* list,uint count) const
114 				{
115 					for (uint i=0; i < count; ++i)
116 						Add( list[i] );
117 				}
118 			};
119 		}
120 	}
121 }
122 
123 #endif
124