no message
[wxWidgets.git] / src / os2 / choice.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: choice.cpp
3 // Purpose: wxChoice
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/13/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/choice.h"
17 #include "wx/utils.h"
18 #include "wx/log.h"
19 #endif
20
21 #include "wx/os2/private.h"
22
23 #if !USE_SHARED_LIBRARY
24 IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
25 #endif
26
27 bool wxChoice::Create(wxWindow *parent,
28 wxWindowID id,
29 const wxPoint& pos,
30 const wxSize& size,
31 int n, const wxString choices[],
32 long style,
33 const wxValidator& validator,
34 const wxString& name)
35 {
36 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
37 return FALSE;
38 // TODO:
39 /*
40 long msStyle = WS_CHILD | CBS_DROPDOWNLIST | WS_TABSTOP | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
41 if ( style & wxCB_SORT )
42 msStyle |= CBS_SORT;
43
44 // the experience shows that wxChoice vs. wxComboBox distinction confuses
45 // quite a few people - try to help them
46 wxASSERT_MSG( !(style & wxCB_DROPDOWN) &&
47 !(style & wxCB_READONLY) &&
48 !(style & wxCB_SIMPLE),
49 wxT("this style flag is ignored by wxChoice, you "
50 "probably want to use a wxComboBox") );
51
52 if ( !OS2CreateControl(wxT("COMBOBOX"), msStyle) )
53 return FALSE;
54
55 for ( int i = 0; i < n; i++ )
56 {
57 Append(choices[i]);
58 }
59 */
60 SetSize(pos.x, pos.y, size.x, size.y);
61
62 return TRUE;
63 }
64
65 // ----------------------------------------------------------------------------
66 // adding/deleting items to/from the list
67 // ----------------------------------------------------------------------------
68
69 int wxChoice::DoAppend(const wxString& item)
70 {
71 // TODO:
72 /*
73 int n = (int)SendMessage(GetHwnd(), CB_ADDSTRING, 0, (LONG)item.c_str());
74 if ( n == CB_ERR )
75 {
76 wxLogLastError("SendMessage(CB_ADDSTRING)");
77 }
78 */
79 return 0; //n
80 }
81
82 void wxChoice::Delete(int n)
83 {
84 wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") );
85
86 // TODO: SendMessage(GetHwnd(), CB_DELETESTRING, n, 0);
87 }
88
89 void wxChoice::Clear()
90 {
91 // TODO: SendMessage(GetHwnd(), CB_RESETCONTENT, 0, 0);
92 }
93
94 // ----------------------------------------------------------------------------
95 // selection
96 // ----------------------------------------------------------------------------
97
98 int wxChoice::GetSelection() const
99 {
100 // TODO: return (int)SendMessage(GetHwnd(), CB_GETCURSEL, 0, 0);
101 return 0;
102 }
103
104 void wxChoice::SetSelection(int n)
105 {
106 // TODO: SendMessage(GetHwnd(), CB_SETCURSEL, n, 0);
107 }
108
109 // ----------------------------------------------------------------------------
110 // string list functions
111 // ----------------------------------------------------------------------------
112
113 int wxChoice::GetCount() const
114 {
115 // TODO: return (int)SendMessage(GetHwnd(), CB_GETCOUNT, 0, 0);
116 return 0;
117 }
118
119 int wxChoice::FindString(const wxString& s) const
120 {
121 // TODO:
122 /*
123 int pos = (int)SendMessage(GetHwnd(), CB_FINDSTRINGEXACT,
124 (WPARAM)-1, (LPARAM)s.c_str());
125
126 return pos == LB_ERR ? wxNOT_FOUND : pos;
127 */
128 return 0;
129 }
130
131 void wxChoice::SetString(int n, const wxString& s)
132 {
133 wxFAIL_MSG(wxT("not implemented"));
134
135 #if 0 // should do this, but no Insert() so far
136 Delete(n);
137 Insert(n + 1, s);
138 #endif
139 }
140
141 wxString wxChoice::GetString(int n) const
142 {
143 size_t len = 0; // TODO: (size_t)::SendMessage(GetHwnd(), CB_GETLBTEXTLEN, n, 0);
144 wxString str = "";
145 // TODO:
146 /*
147 if (len) {
148 if ( ::SendMessage(GetHwnd(), CB_GETLBTEXT, n,
149 (LPARAM)str.GetWriteBuf(len)) == CB_ERR ) {
150 wxLogLastError("SendMessage(CB_GETLBTEXT)");
151 }
152 str.UngetWriteBuf();
153 }
154 */
155 return str;
156 }
157
158 // ----------------------------------------------------------------------------
159 // client data
160 // ----------------------------------------------------------------------------
161
162 void wxChoice::DoSetItemClientData( int n, void* clientData )
163 {
164 // TODO:
165 /*
166 if ( SendMessage(GetHwnd(), CB_SETITEMDATA, n, (LPARAM)clientData) == CB_ERR )
167 {
168 wxLogLastError(wxT("CB_SETITEMDATA"));
169 }
170 */
171 }
172
173 void* wxChoice::DoGetItemClientData( int n ) const
174 {
175 // TODO:
176 /*
177 LPARAM rc = SendMessage(GetHwnd(), CB_GETITEMDATA, n, 0);
178 if ( rc == CB_ERR )
179 {
180 wxLogLastError(wxT("CB_GETITEMDATA"));
181
182 // unfortunately, there is no way to return an error code to the user
183 rc = (LPARAM) NULL;
184 }
185
186 return (void *)rc;
187 */
188 return NULL;
189 }
190
191 void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData )
192 {
193 DoSetClientData(n, clientData);
194 }
195
196 wxClientData* wxChoice::DoGetItemClientObject( int n ) const
197 {
198 // TODO: return (wxClientData *)DoGetClientData(n);
199 return NULL;
200 }
201
202 // ----------------------------------------------------------------------------
203 // wxOS2 specific helpers
204 // ----------------------------------------------------------------------------
205
206 void wxChoice::DoSetSize(int x, int y,
207 int width, int height,
208 int sizeFlags)
209 {
210 // Ignore height parameter because height doesn't mean 'initially
211 // displayed' height, it refers to the drop-down menu as well. The
212 // wxWindows interpretation is different; also, getting the size returns
213 // the _displayed_ size (NOT the drop down menu size) so
214 // setting-getting-setting size would not work.
215 wxControl::DoSetSize(x, y, width, -1, sizeFlags);
216 }
217
218 wxSize wxChoice::DoGetBestSize()
219 {
220 // find the widest string
221 int wLine;
222 int wChoice = 0;
223 int nItems = GetCount();
224 for ( int i = 0; i < nItems; i++ )
225 {
226 wxString str(GetString(i));
227 GetTextExtent(str, &wLine, NULL);
228 if ( wLine > wChoice )
229 wChoice = wLine;
230 }
231
232 // give it some reasonable default value if there are no strings in the
233 // list
234 if ( wChoice == 0 )
235 wChoice = 100;
236
237 // the combobox should be larger than the widest string
238 int cx, cy;
239 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
240
241 wChoice += 5*cx;
242
243 // Choice drop-down list depends on number of items (limited to 10)
244 size_t nStrings = nItems == 0 ? 10 : wxMin(10, nItems) + 1;
245 int hChoice = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*nStrings;
246
247 return wxSize(wChoice, hChoice);
248 }
249
250 MRESULT wxChoice::OS2WindowProc(HWND hwnd, WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
251 {
252 // TODO:
253 /*
254 if ( nMsg == WM_LBUTTONUP )
255 {
256 int x = (int)LOWORD(lParam);
257 int y = (int)HIWORD(lParam);
258
259 // Ok, this is truly weird, but if a panel with a wxChoice loses the
260 // focus, then you get a *fake* WM_LBUTTONUP message with x = 65535 and
261 // y = 65535. Filter out this nonsense.
262 //
263 // VZ: I'd like to know how to reproduce this please...
264 if ( x == 65535 && y == 65535 )
265 return 0;
266 }
267 */
268 return wxWindow::OS2WindowProc(hwnd, nMsg, wParam, lParam);
269 }
270
271 bool wxChoice::OS2Command(WXUINT param, WXWORD WXUNUSED(id))
272 {
273 // TODO:
274 /*
275 if ( param != CBN_SELCHANGE)
276 {
277 // "selection changed" is the only event we're after
278 return FALSE;
279 }
280 */
281 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId);
282 event.SetInt(GetSelection());
283 event.SetEventObject(this);
284 // TODO: event.SetString(GetStringSelection());
285 ProcessCommand(event);
286
287 return TRUE;
288 }
289