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
|
//
// mxToolKit (c) 1999 by Mete Ciragan
//
// file: mxListBox.cpp
// implementation: Win32 API
// last modified: Mar 18 1999, Mete Ciragan
// copyright: The programs and associated files contained in this
// distribution were developed by Mete Ciragan. The programs
// are not in the public domain, but they are freely
// distributable without licensing fees. These programs are
// provided without guarantee or warrantee expressed or
// implied.
//
#include "mxtk/mxListBox.h"
#include <windows.h>
class mxListBox_i
{
public:
int dummy;
};
mxListBox::mxListBox (mxWindow *parent, int x, int y, int w, int h, int id, int style)
: mxWidget (parent, x, y, w, h)
{
if (!parent)
return;
DWORD dwStyle = WS_VISIBLE | WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_HSCROLL;
HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle ();
if (style == MultiSelection)
dwStyle |= LBS_MULTIPLESEL | LBS_EXTENDEDSEL;
void *handle = (void *) CreateWindowEx (WS_EX_CLIENTEDGE, "LISTBOX", "", WS_VISIBLE | WS_CHILD | LBS_NOTIFY | WS_VSCROLL,
x, y, w, h, hwndParent,
(HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL);
SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0));
SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this);
setHandle (handle);
setType (MX_LISTBOX);
setParent (parent);
setId (id);
}
mxListBox::~mxListBox ()
{
removeAll ();
}
void
mxListBox::add (const char *item)
{
SendMessage ((HWND) getHandle (), LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) item);
}
void
mxListBox::select (int index)
{
SendMessage ((HWND) getHandle (), LB_SETCURSEL, (WPARAM) index, 0L);
}
void
mxListBox::deselect (int index)
{
SendMessage ((HWND) getHandle (), LB_SETSEL, (WPARAM) FALSE, (LPARAM) (UINT) index);
}
void
mxListBox::remove (int index)
{
SendMessage ((HWND) getHandle (), LB_DELETESTRING, (WPARAM) index, 0L);
}
void
mxListBox::removeAll ()
{
SendMessage ((HWND) getHandle (), LB_RESETCONTENT, 0, 0L);
}
void
mxListBox::setItemText (int index, const char *item)
{
//SendMessage ((HWND) getHandle (), LB_SETTEXT, (WPARAM) index, (LPARAM) (LPCTSTR) item);
}
void
mxListBox::setItemData (int index, void *data)
{
SendMessage ((HWND) getHandle (), LB_SETITEMDATA, (WPARAM) index, (LPARAM) data);
}
int
mxListBox::getItemCount () const
{
return (int) SendMessage ((HWND) getHandle (), LB_GETCOUNT, 0, 0L);
}
int
mxListBox::getSelectedIndex () const
{
return (int) SendMessage ((HWND) getHandle (), LB_GETCURSEL, 0, 0L);
}
bool
mxListBox::isSelected (int index) const
{
return (bool) (SendMessage ((HWND) getHandle (), LB_GETSEL, (WPARAM) index, 0L) > 0);
}
const char*
mxListBox::getItemText (int index) const
{
static char text[256];
SendMessage ((HWND) getHandle (), LB_GETTEXT, (WPARAM) index, (LPARAM) (LPCTSTR) text);
return text;
}
void*
mxListBox::getItemData (int index) const
{
return (void *) SendMessage ((HWND) getHandle (), LB_GETITEMDATA, (WPARAM) index, 0L);
}
|