]> git.saurik.com Git - wxWidgets.git/blame - src/os2/choice.cpp
Implementing some more controls and an MDI child frame fix for wxFrame.
[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 22
0e320a79 23IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
0e320a79 24
37f214d5
DW
25bool wxChoice::Create(wxWindow *parent,
26 wxWindowID id,
27 const wxPoint& pos,
28 const wxSize& size,
29 int n, const wxString choices[],
30 long style,
5d4b632b 31#if wxUSE_VALIDATORS
37f214d5 32 const wxValidator& validator,
5d4b632b 33#endif
37f214d5 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
dcd307ee
DW
131void 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
0e320a79
DW
141wxString wxChoice::GetString(int n) const
142{
37f214d5
DW
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;
0e320a79
DW
156}
157
37f214d5
DW
158// ----------------------------------------------------------------------------
159// client data
160// ----------------------------------------------------------------------------
161
dcd307ee 162void wxChoice::DoSetItemClientData( int n, void* clientData )
0e320a79 163{
37f214d5
DW
164 // TODO:
165 /*
166 if ( SendMessage(GetHwnd(), CB_SETITEMDATA, n, (LPARAM)clientData) == CB_ERR )
167 {
168 wxLogLastError(wxT("CB_SETITEMDATA"));
169 }
170 */
0e320a79
DW
171}
172
dcd307ee 173void* wxChoice::DoGetItemClientData( int n ) const
0e320a79 174{
37f214d5
DW
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;
0e320a79
DW
189}
190
dcd307ee 191void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData )
0e320a79 192{
e6ebb514 193 DoSetItemClientData(n, clientData);
0e320a79
DW
194}
195
dcd307ee 196wxClientData* wxChoice::DoGetItemClientObject( int n ) const
0e320a79 197{
e6ebb514 198 return (wxClientData *)DoGetItemClientData(n);
37f214d5
DW
199}
200
201// ----------------------------------------------------------------------------
202// wxOS2 specific helpers
203// ----------------------------------------------------------------------------
204
205void wxChoice::DoSetSize(int x, int y,
206 int width, int height,
207 int sizeFlags)
208{
209 // Ignore height parameter because height doesn't mean 'initially
210 // displayed' height, it refers to the drop-down menu as well. The
211 // wxWindows interpretation is different; also, getting the size returns
212 // the _displayed_ size (NOT the drop down menu size) so
213 // setting-getting-setting size would not work.
214 wxControl::DoSetSize(x, y, width, -1, sizeFlags);
215}
216
e78c4d50 217wxSize wxChoice::DoGetBestSize() const
37f214d5
DW
218{
219 // find the widest string
220 int wLine;
221 int wChoice = 0;
222 int nItems = GetCount();
223 for ( int i = 0; i < nItems; i++ )
224 {
225 wxString str(GetString(i));
226 GetTextExtent(str, &wLine, NULL);
227 if ( wLine > wChoice )
228 wChoice = wLine;
229 }
230
231 // give it some reasonable default value if there are no strings in the
232 // list
233 if ( wChoice == 0 )
234 wChoice = 100;
235
236 // the combobox should be larger than the widest string
237 int cx, cy;
e78c4d50 238 wxGetCharSize(GetHWND(), &cx, &cy, (wxFont*)&GetFont());
37f214d5
DW
239
240 wChoice += 5*cx;
241
242 // Choice drop-down list depends on number of items (limited to 10)
243 size_t nStrings = nItems == 0 ? 10 : wxMin(10, nItems) + 1;
244 int hChoice = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*nStrings;
245
246 return wxSize(wChoice, hChoice);
247}
248
a885d89a 249MRESULT wxChoice::OS2WindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
37f214d5
DW
250{
251 // TODO:
252 /*
253 if ( nMsg == WM_LBUTTONUP )
254 {
255 int x = (int)LOWORD(lParam);
256 int y = (int)HIWORD(lParam);
257
258 // Ok, this is truly weird, but if a panel with a wxChoice loses the
259 // focus, then you get a *fake* WM_LBUTTONUP message with x = 65535 and
260 // y = 65535. Filter out this nonsense.
261 //
262 // VZ: I'd like to know how to reproduce this please...
263 if ( x == 65535 && y == 65535 )
264 return 0;
265 }
266 */
a885d89a 267 return wxWindow::OS2WindowProc(nMsg, wParam, lParam);
37f214d5
DW
268}
269
270bool wxChoice::OS2Command(WXUINT param, WXWORD WXUNUSED(id))
271{
272 // TODO:
273 /*
274 if ( param != CBN_SELCHANGE)
275 {
276 // "selection changed" is the only event we're after
277 return FALSE;
278 }
279 */
280 wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId);
281 event.SetInt(GetSelection());
282 event.SetEventObject(this);
283// TODO: event.SetString(GetStringSelection());
284 ProcessCommand(event);
285
286 return TRUE;
0e320a79
DW
287}
288