]> git.saurik.com Git - wxWidgets.git/blob - src/os2/choice.cpp
Added m_callback init.
[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 #if wxUSE_VALIDATORS
34 # if defined(__VISAGECPP__)
35 const wxValidator* validator,
36 # else
37 const wxValidator& validator,
38 # endif
39 #endif
40 const wxString& name)
41 {
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") );
57
58 if ( !OS2CreateControl(wxT("COMBOBOX"), msStyle) )
59 return FALSE;
60
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);
67
68 return TRUE;
69 }
70
71 // ----------------------------------------------------------------------------
72 // adding/deleting items to/from the list
73 // ----------------------------------------------------------------------------
74
75 int wxChoice::DoAppend(const wxString& item)
76 {
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
86 }
87
88 void wxChoice::Delete(int n)
89 {
90 wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") );
91
92 // TODO: SendMessage(GetHwnd(), CB_DELETESTRING, n, 0);
93 }
94
95 void wxChoice::Clear()
96 {
97 // TODO: SendMessage(GetHwnd(), CB_RESETCONTENT, 0, 0);
98 }
99
100 // ----------------------------------------------------------------------------
101 // selection
102 // ----------------------------------------------------------------------------
103
104 int wxChoice::GetSelection() const
105 {
106 // TODO: return (int)SendMessage(GetHwnd(), CB_GETCURSEL, 0, 0);
107 return 0;
108 }
109
110 void wxChoice::SetSelection(int n)
111 {
112 // TODO: SendMessage(GetHwnd(), CB_SETCURSEL, n, 0);
113 }
114
115 // ----------------------------------------------------------------------------
116 // string list functions
117 // ----------------------------------------------------------------------------
118
119 int wxChoice::GetCount() const
120 {
121 // TODO: return (int)SendMessage(GetHwnd(), CB_GETCOUNT, 0, 0);
122 return 0;
123 }
124
125 int wxChoice::FindString(const wxString& s) const
126 {
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 */
134 return 0;
135 }
136
137 void 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
147 wxString wxChoice::GetString(int n) const
148 {
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;
162 }
163
164 // ----------------------------------------------------------------------------
165 // client data
166 // ----------------------------------------------------------------------------
167
168 void wxChoice::DoSetItemClientData( int n, void* clientData )
169 {
170 // TODO:
171 /*
172 if ( SendMessage(GetHwnd(), CB_SETITEMDATA, n, (LPARAM)clientData) == CB_ERR )
173 {
174 wxLogLastError(wxT("CB_SETITEMDATA"));
175 }
176 */
177 }
178
179 void* wxChoice::DoGetItemClientData( int n ) const
180 {
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;
195 }
196
197 void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData )
198 {
199 DoSetItemClientData(n, clientData);
200 }
201
202 wxClientData* wxChoice::DoGetItemClientObject( int n ) const
203 {
204 return (wxClientData *)DoGetItemClientData(n);
205 }
206
207 // ----------------------------------------------------------------------------
208 // wxOS2 specific helpers
209 // ----------------------------------------------------------------------------
210
211 void 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
223 wxSize 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
255 MRESULT 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
276 bool 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;
293 }
294