]> git.saurik.com Git - wxWidgets.git/blame - src/os2/choice.cpp
Further DnD changes. Untested.
[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,
33 const wxValidator& validator,
34 const wxString& name)
0e320a79 35{
37f214d5
DW
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") );
0e320a79 51
37f214d5
DW
52 if ( !OS2CreateControl(wxT("COMBOBOX"), msStyle) )
53 return FALSE;
0e320a79 54
37f214d5
DW
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);
0e320a79 61
37f214d5 62 return TRUE;
0e320a79
DW
63}
64
37f214d5
DW
65// ----------------------------------------------------------------------------
66// adding/deleting items to/from the list
67// ----------------------------------------------------------------------------
68
69int wxChoice::DoAppend(const wxString& item)
0e320a79 70{
37f214d5
DW
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
0e320a79
DW
80}
81
82void wxChoice::Delete(int n)
83{
37f214d5
DW
84 wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") );
85
86// TODO: SendMessage(GetHwnd(), CB_DELETESTRING, n, 0);
0e320a79
DW
87}
88
89void wxChoice::Clear()
90{
37f214d5 91 // TODO: SendMessage(GetHwnd(), CB_RESETCONTENT, 0, 0);
0e320a79
DW
92}
93
37f214d5
DW
94// ----------------------------------------------------------------------------
95// selection
96// ----------------------------------------------------------------------------
97
0e320a79
DW
98int wxChoice::GetSelection() const
99{
37f214d5 100 // TODO: return (int)SendMessage(GetHwnd(), CB_GETCURSEL, 0, 0);
0e320a79
DW
101 return 0;
102}
103
104void wxChoice::SetSelection(int n)
105{
37f214d5
DW
106 // TODO: SendMessage(GetHwnd(), CB_SETCURSEL, n, 0);
107}
108
109// ----------------------------------------------------------------------------
110// string list functions
111// ----------------------------------------------------------------------------
112
113int wxChoice::GetCount() const
114{
115 // TODO: return (int)SendMessage(GetHwnd(), CB_GETCOUNT, 0, 0);
116 return 0;
0e320a79
DW
117}
118
119int wxChoice::FindString(const wxString& s) const
120{
37f214d5
DW
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 */
0e320a79
DW
128 return 0;
129}
130
131wxString wxChoice::GetString(int n) const
132{
37f214d5
DW
133 size_t len = 0; // TODO: (size_t)::SendMessage(GetHwnd(), CB_GETLBTEXTLEN, n, 0);
134 wxString str = "";
135 // TODO:
136 /*
137 if (len) {
138 if ( ::SendMessage(GetHwnd(), CB_GETLBTEXT, n,
139 (LPARAM)str.GetWriteBuf(len)) == CB_ERR ) {
140 wxLogLastError("SendMessage(CB_GETLBTEXT)");
141 }
142 str.UngetWriteBuf();
143 }
144 */
145 return str;
0e320a79
DW
146}
147
37f214d5
DW
148// ----------------------------------------------------------------------------
149// client data
150// ----------------------------------------------------------------------------
151
152void wxChoice::DoSetClientData( int n, void* clientData )
0e320a79 153{
37f214d5
DW
154 // TODO:
155 /*
156 if ( SendMessage(GetHwnd(), CB_SETITEMDATA, n, (LPARAM)clientData) == CB_ERR )
157 {
158 wxLogLastError(wxT("CB_SETITEMDATA"));
159 }
160 */
0e320a79
DW
161}
162
37f214d5 163void* wxChoice::DoGetClientData( int n ) const
0e320a79 164{
37f214d5
DW
165 // TODO:
166 /*
167 LPARAM rc = SendMessage(GetHwnd(), CB_GETITEMDATA, n, 0);
168 if ( rc == CB_ERR )
169 {
170 wxLogLastError(wxT("CB_GETITEMDATA"));
171
172 // unfortunately, there is no way to return an error code to the user
173 rc = (LPARAM) NULL;
174 }
175
176 return (void *)rc;
177 */
178 return NULL;
0e320a79
DW
179}
180
37f214d5 181void wxChoice::DoSetClientObject( int n, wxClientData* clientData )
0e320a79 182{
37f214d5 183 DoSetClientData(n, clientData);
0e320a79
DW
184}
185
37f214d5 186wxClientData* wxChoice::DoGetClientObject( int n ) const
0e320a79 187{
37f214d5
DW
188 // TODO: return (wxClientData *)DoGetClientData(n);
189 return NULL;
190}
191
192// ----------------------------------------------------------------------------
193// wxOS2 specific helpers
194// ----------------------------------------------------------------------------
195
196void wxChoice::DoSetSize(int x, int y,
197 int width, int height,
198 int sizeFlags)
199{
200 // Ignore height parameter because height doesn't mean 'initially
201 // displayed' height, it refers to the drop-down menu as well. The
202 // wxWindows interpretation is different; also, getting the size returns
203 // the _displayed_ size (NOT the drop down menu size) so
204 // setting-getting-setting size would not work.
205 wxControl::DoSetSize(x, y, width, -1, sizeFlags);
206}
207
208wxSize wxChoice::DoGetBestSize()
209{
210 // find the widest string
211 int wLine;
212 int wChoice = 0;
213 int nItems = GetCount();
214 for ( int i = 0; i < nItems; i++ )
215 {
216 wxString str(GetString(i));
217 GetTextExtent(str, &wLine, NULL);
218 if ( wLine > wChoice )
219 wChoice = wLine;
220 }
221
222 // give it some reasonable default value if there are no strings in the
223 // list
224 if ( wChoice == 0 )
225 wChoice = 100;
226
227 // the combobox should be larger than the widest string
228 int cx, cy;
229 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
230
231 wChoice += 5*cx;
232
233 // Choice drop-down list depends on number of items (limited to 10)
234 size_t nStrings = nItems == 0 ? 10 : wxMin(10, nItems) + 1;
235 int hChoice = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*nStrings;
236
237 return wxSize(wChoice, hChoice);
238}
239
240MRESULT wxChoice::OS2WindowProc(HWND hwnd, WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
241{
242 // TODO:
243 /*
244 if ( nMsg == WM_LBUTTONUP )
245 {
246 int x = (int)LOWORD(lParam);
247 int y = (int)HIWORD(lParam);
248
249 // Ok, this is truly weird, but if a panel with a wxChoice loses the
250 // focus, then you get a *fake* WM_LBUTTONUP message with x = 65535 and
251 // y = 65535. Filter out this nonsense.
252 //
253 // VZ: I'd like to know how to reproduce this please...
254 if ( x == 65535 && y == 65535 )
255 return 0;
256 }
257 */
258 return wxWindow::OS2WindowProc(hwnd, nMsg, wParam, lParam);
259}
260
261bool wxChoice::OS2Command(WXUINT param, WXWORD WXUNUSED(id))
262{
263 // TODO:
264 /*
265 if ( param != CBN_SELCHANGE)
266 {
267 // "selection changed" is the only event we're after
268 return FALSE;
269 }
270 */
271 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId);
272 event.SetInt(GetSelection());
273 event.SetEventObject(this);
274// TODO: event.SetString(GetStringSelection());
275 ProcessCommand(event);
276
277 return TRUE;
0e320a79
DW
278}
279