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