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