summaryrefslogtreecommitdiff
path: root/src/combobox.cpp
blob: f16b6197e8b837e965ed8aa323c28ef6def201be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//  w32dlib - Win32 Control Helpers
//
//  Copyright (C) 2005  Ian Cowburn (ianc@noddybox.demon.co.uk)
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//  -------------------------------------------------------------------------
//
#include "w32dlib/window.h"
#include "w32dlib/combobox.h"

namespace W32DLib
{

// ------------------------------------------------------------
//
ComboBox::ComboBox(Dialog *parent, int resource_id) :
				Control(parent,resource_id)
{
}


// ------------------------------------------------------------
//
ComboBox::~ComboBox()
{
}


// ------------------------------------------------------------
//
void ComboBox::OnSelection(Window *owner, W32DLibCallback callback)
{
    Control::AddCallback(WM_COMMAND,CBN_SELCHANGE,owner,callback);
}


// ------------------------------------------------------------
//
void ComboBox::OnDoubleClick(Window *owner, W32DLibCallback callback)
{
    Control::AddCallback(WM_COMMAND,CBN_DBLCLK,owner,callback);
}


// ------------------------------------------------------------
//
void ComboBox::OnTextChanged(Window *owner, W32DLibCallback callback)
{
    Control::AddCallback(WM_COMMAND,CBN_EDITCHANGE,owner,callback);
}


// ------------------------------------------------------------
//
void ComboBox::Reset()
{
    SendMsg(CB_RESETCONTENT,0,0);
}


// ------------------------------------------------------------
//
void ComboBox::MaxLen(int count)
{
    SendMsg(CB_LIMITTEXT,count,0);
}


// ------------------------------------------------------------
//
int ComboBox::Count()
{
    return SendMsg(CB_GETCOUNT,0,0);
}


// ------------------------------------------------------------
//
int  ComboBox::AddString(const char *text)
{
    return SendMsg(CB_ADDSTRING,0,reinterpret_cast<LPARAM>(text));
}


// ------------------------------------------------------------
//
int  ComboBox::AddString(const std::string& text)
{
    return AddString(text.c_str());
}


// ------------------------------------------------------------
//
int  ComboBox::AddString(const char *text, int index)
{
    return SendMsg(CB_INSERTSTRING,index,reinterpret_cast<LPARAM>(text));
}


// ------------------------------------------------------------
//
int  ComboBox::AddString(const std::string& text, int index)
{
    return AddString(text.c_str(),index);
}


// ------------------------------------------------------------
//
int ComboBox::RemoveString(int index)
{
    return SendMsg(CB_DELETESTRING,index,0);
}


// ------------------------------------------------------------
//
std::string ComboBox::GetString(int index)
{
    std::string result;
    LRESULT len=SendMsg(CB_GETLBTEXTLEN,index,0);

    if (len!=CB_ERR)
    {
    	char *text=new char[len+1];

	SendMsg(CB_GETLBTEXT,index,reinterpret_cast<LPARAM>(text));

	result=text;

	delete[] text;
    }

    return result;
}


// ------------------------------------------------------------
//
int ComboBox::TopRowIndex()
{
    return SendMsg(CB_GETTOPINDEX,0,0);
}


// ------------------------------------------------------------
//
void ComboBox::TopRowIndex(int index)
{
    SendMsg(CB_SETTOPINDEX,index,0);
}


// ------------------------------------------------------------
//
int ComboBox::SelectedIndex()
{
    return SendMsg(CB_GETCURSEL,0,0);
}


// ------------------------------------------------------------
//
void ComboBox::SelectedIndex(int index)
{
    SendMsg(CB_SETCURSEL,index,0);
}


};	// namespace W32DLib

// END OF FILE