]> git.saurik.com Git - wxWidgets.git/blame - src/os2/listbox.cpp
Changed code to get rid of a compiler warning about statement always being FALSE
[wxWidgets.git] / src / os2 / listbox.cpp
CommitLineData
0e320a79
DW
1///////////////////////////////////////////////////////////////////////////////
2// Name: listbox.cpp
3// Purpose: wxListBox
fb9010ed 4// Author: David Webster
0e320a79 5// Modified by:
fb9010ed 6// Created: 10/09/99
0e320a79 7// RCS-ID: $Id$
fb9010ed 8// Copyright: (c) David Webster
0e320a79
DW
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
fb9010ed
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#include "wx/window.h"
16#include "wx/os2/private.h"
0e320a79 17
fb9010ed 18#ifndef WX_PRECOMP
0e320a79
DW
19#include "wx/listbox.h"
20#include "wx/settings.h"
fb9010ed
DW
21#include "wx/brush.h"
22#include "wx/font.h"
23#include "wx/dc.h"
24#include "wx/utils.h"
25#endif
26
27#define INCL_M
28#include <os2.h>
29
0e320a79
DW
30#include "wx/dynarray.h"
31#include "wx/log.h"
32
7e99520b
DW
33#if wxUSE_LISTBOX
34
fb9010ed
DW
35#if wxUSE_OWNER_DRAWN
36 #include "wx/ownerdrw.h"
37#endif
38
0e320a79 39 IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
0e320a79 40
fb9010ed
DW
41// ============================================================================
42// list box item declaration and implementation
43// ============================================================================
44
45#if wxUSE_OWNER_DRAWN
46
47class wxListBoxItem : public wxOwnerDrawn
48{
49public:
50 wxListBoxItem(const wxString& str = "");
51};
52
53wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
54{
55 // no bitmaps/checkmarks
56 SetMarginWidth(0);
57}
58
59wxOwnerDrawn *wxListBox::CreateItem(size_t n)
60{
61 return new wxListBoxItem();
62}
63
64#endif //USE_OWNER_DRAWN
65
0e320a79
DW
66// ============================================================================
67// list box control implementation
68// ============================================================================
69
70// Listbox item
71wxListBox::wxListBox()
72{
dcd307ee
DW
73 m_noItems = 0;
74 m_selected = 0;
0e320a79
DW
75}
76
dcd307ee
DW
77bool wxListBox::Create(wxWindow *parent,
78 wxWindowID id,
0e320a79
DW
79 const wxPoint& pos,
80 const wxSize& size,
81 int n, const wxString choices[],
82 long style,
5d4b632b 83#if wxUSE_VALIDATORS
0e320a79 84 const wxValidator& validator,
5d4b632b 85#endif
0e320a79
DW
86 const wxString& name)
87{
dcd307ee
DW
88 m_noItems = 0;
89 m_hWnd = 0;
90 m_selected = 0;
0e320a79 91
dcd307ee 92 SetName(name);
5d4b632b 93#if wxUSE_VALIDATORS
dcd307ee 94 SetValidator(validator);
5d4b632b 95#endif
0e320a79 96
dcd307ee
DW
97 if (parent)
98 parent->AddChild(this);
0e320a79 99
dcd307ee
DW
100 wxSystemSettings settings;
101 SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_WINDOW));
102 SetForegroundColour(parent->GetForegroundColour());
0e320a79 103
dcd307ee 104 m_windowId = ( id == -1 ) ? (int)NewControlId() : id;
0e320a79 105
dcd307ee
DW
106 int x = pos.x;
107 int y = pos.y;
108 int width = size.x;
109 int height = size.y;
110 m_windowStyle = style;
fb9010ed 111
dcd307ee 112// TODO:
fb9010ed
DW
113/*
114 DWORD wstyle = WS_VISIBLE | WS_VSCROLL | WS_TABSTOP |
115 LBS_NOTIFY | LBS_HASSTRINGS;
116 if (m_windowStyle & wxLB_MULTIPLE)
117 wstyle |= LBS_MULTIPLESEL;
118 else if (m_windowStyle & wxLB_EXTENDED)
119 wstyle |= LBS_EXTENDEDSEL;
120
121 if (m_windowStyle & wxLB_ALWAYS_SB)
dcd307ee 122 wstyle |= LBS_DISABLENOSCROLL;
fb9010ed
DW
123 if (m_windowStyle & wxLB_HSCROLL)
124 wstyle |= WS_HSCROLL;
125 if (m_windowStyle & wxLB_SORT)
126 wstyle |= LBS_SORT;
127
128#if wxUSE_OWNER_DRAWN
129 if ( m_windowStyle & wxLB_OWNERDRAW ) {
130 // we don't support LBS_OWNERDRAWVARIABLE yet
131 wstyle |= LBS_OWNERDRAWFIXED;
132 }
133#endif
134
135 // Without this style, you get unexpected heights, so e.g. constraint layout
136 // doesn't work properly
137 wstyle |= LBS_NOINTEGRALHEIGHT;
138
139 bool want3D;
dcd307ee 140 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
fb9010ed 141
dcd307ee
DW
142 // Even with extended styles, need to combine with WS_BORDER for them to
143 // look right.
fb9010ed
DW
144 if ( want3D || wxStyleHasBorder(m_windowStyle) )
145 {
146 wstyle |= WS_BORDER;
147 }
148
149 m_hWnd = (WXHWND)::CreateWindowEx(exStyle, wxT("LISTBOX"), NULL,
150 wstyle | WS_CHILD,
151 0, 0, 0, 0,
152 (HWND)parent->GetHWND(), (HMENU)m_windowId,
153 wxGetInstance(), NULL);
154
dcd307ee 155 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create listbox") );
fb9010ed
DW
156
157 // Subclass again to catch messages
158 SubclassWin(m_hWnd);
159
160 size_t ui;
161 for (ui = 0; ui < (size_t)n; ui++) {
162 Append(choices[ui]);
163 }
164
165 if ( (m_windowStyle & wxLB_MULTIPLE) == 0 )
166 SendMessage(GetHwnd(), LB_SETCURSEL, 0, 0);
dcd307ee 167*/
fb9010ed
DW
168 SetFont(parent->GetFont());
169
170 SetSize(x, y, width, height);
171
172 Show(TRUE);
0e320a79 173
dcd307ee 174 return TRUE;
0e320a79
DW
175}
176
177wxListBox::~wxListBox()
178{
fb9010ed
DW
179#if wxUSE_OWNER_DRAWN
180 size_t uiCount = m_aItems.Count();
181 while ( uiCount-- != 0 ) {
182 delete m_aItems[uiCount];
183 }
184#endif // wxUSE_OWNER_DRAWN
185}
186
187void wxListBox::SetupColours()
188{
189 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
190 SetForegroundColour(GetParent()->GetForegroundColour());
0e320a79
DW
191}
192
dcd307ee
DW
193// ----------------------------------------------------------------------------
194// implementation of wxListBoxBase methods
195// ----------------------------------------------------------------------------
196
197void wxListBox::DoSetFirstItem(int N)
0e320a79 198{
fb9010ed
DW
199 wxCHECK_RET( N >= 0 && N < m_noItems,
200 wxT("invalid index in wxListBox::SetFirstItem") );
201
dcd307ee 202// SendMessage(GetHwnd(), LB_SETTOPINDEX, (WPARAM)N, (LPARAM)0);
0e320a79
DW
203}
204
205void wxListBox::Delete(int N)
206{
fb9010ed
DW
207 wxCHECK_RET( N >= 0 && N < m_noItems,
208 wxT("invalid index in wxListBox::Delete") );
209
dcd307ee
DW
210#if wxUSE_OWNER_DRAWN
211 delete m_aItems[N];
212 m_aItems.Remove(N);
213#else // !wxUSE_OWNER_DRAWN
214 if ( HasClientObjectData() )
215 {
216 delete GetClientObject(N);
217 }
218#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
219
220// SendMessage(GetHwnd(), LB_DELETESTRING, N, 0);
221 m_noItems--;
222
fb9010ed 223 SetHorizontalExtent("");
0e320a79
DW
224}
225
dcd307ee 226int wxListBox::DoAppend(const wxString& item)
0e320a79 227{
dcd307ee
DW
228// TODO:
229/*
230 int index = ListBox_AddString(GetHwnd(), item);
231 m_noItems++;
fb9010ed
DW
232
233#if wxUSE_OWNER_DRAWN
234 if ( m_windowStyle & wxLB_OWNERDRAW ) {
235 wxOwnerDrawn *pNewItem = CreateItem(index); // dummy argument
236 pNewItem->SetName(item);
237 m_aItems.Add(pNewItem);
dcd307ee 238 ListBox_SetItemData(GetHwnd(), index, pNewItem);
fb9010ed
DW
239 }
240#endif
0e320a79 241
fb9010ed 242 SetHorizontalExtent(item);
dcd307ee
DW
243
244 return index;
245*/
246 return 0;
0e320a79
DW
247}
248
dcd307ee 249void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
0e320a79 250{
dcd307ee
DW
251// TODO:
252/*
253 ShowWindow(GetHwnd(), SW_HIDE);
0e320a79 254
dcd307ee 255 ListBox_ResetContent(GetHwnd());
0e320a79 256
dcd307ee 257 m_noItems = choices.GetCount();
fb9010ed 258 int i;
dcd307ee 259 for (i = 0; i < m_noItems; i++)
fb9010ed 260 {
dcd307ee
DW
261 ListBox_AddString(GetHwnd(), choices[i]);
262 if ( clientData )
263 {
264#if wxUSE_OWNER_DRAWN
265 wxASSERT_MSG(clientData[ui] == NULL,
266 wxT("Can't use client data with owner-drawn listboxes"));
267#else // !wxUSE_OWNER_DRAWN
268 ListBox_SetItemData(GetHwnd(), i, clientData[i]);
269#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
270 }
fb9010ed 271 }
fb9010ed
DW
272
273#if wxUSE_OWNER_DRAWN
274 if ( m_windowStyle & wxLB_OWNERDRAW ) {
275 // first delete old items
276 size_t ui = m_aItems.Count();
277 while ( ui-- != 0 ) {
278 delete m_aItems[ui];
279 }
280 m_aItems.Empty();
281
282 // then create new ones
dcd307ee 283 for ( ui = 0; ui < (size_t)m_noItems; ui++ ) {
fb9010ed
DW
284 wxOwnerDrawn *pNewItem = CreateItem(ui);
285 pNewItem->SetName(choices[ui]);
286 m_aItems.Add(pNewItem);
dcd307ee 287 ListBox_SetItemData(GetHwnd(), ui, pNewItem);
fb9010ed
DW
288 }
289 }
dcd307ee 290#endif // wxUSE_OWNER_DRAWN
0e320a79 291
dcd307ee
DW
292 SetHorizontalExtent();
293
294 ShowWindow(GetHwnd(), SW_SHOW);
295*/
0e320a79
DW
296}
297
298int wxListBox::FindString(const wxString& s) const
299{
dcd307ee
DW
300// TODO:
301/*
302 int pos = ListBox_FindStringExact(GetHwnd(), (WPARAM)-1, s);
303 if (pos == LB_ERR)
304 return wxNOT_FOUND;
305 else
fb9010ed 306 return pos;
dcd307ee
DW
307*/
308 return 0;
0e320a79
DW
309}
310
311void wxListBox::Clear()
312{
fb9010ed
DW
313#if wxUSE_OWNER_DRAWN
314 size_t uiCount = m_aItems.Count();
315 while ( uiCount-- != 0 ) {
316 delete m_aItems[uiCount];
317 }
318
319 m_aItems.Clear();
dcd307ee
DW
320#else // !wxUSE_OWNER_DRAWN
321 if ( HasClientObjectData() )
322 {
323 for ( size_t n = 0; n < (size_t)m_noItems; n++ )
324 {
325 delete GetClientObject(n);
326 }
327 }
328#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
329// TODO:
330/*
331
332 ListBox_ResetContent(GetHwnd());
fb9010ed
DW
333
334 m_noItems = 0;
dcd307ee
DW
335 SetHorizontalExtent();
336*/
0e320a79
DW
337}
338
339void wxListBox::SetSelection(int N, bool select)
340{
fb9010ed
DW
341 wxCHECK_RET( N >= 0 && N < m_noItems,
342 wxT("invalid index in wxListBox::SetSelection") );
dcd307ee
DW
343// TODO:
344/*
fb9010ed 345
dcd307ee 346 if ( HasMultipleSelection() )
fb9010ed 347 {
dcd307ee 348 SendMessage(GetHwnd(), LB_SETSEL, select, N);
fb9010ed
DW
349 }
350 else
351 {
dcd307ee 352 SendMessage(GetHwnd(), LB_SETCURSEL, select ? N : -1, 0);
fb9010ed 353 }
dcd307ee 354*/
0e320a79
DW
355}
356
dcd307ee 357bool wxListBox::IsSelected(int N) const
0e320a79 358{
fb9010ed
DW
359 wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE,
360 wxT("invalid index in wxListBox::Selected") );
361
362// return SendMessage(GetHwnd(), LB_GETSEL, N, 0) == 0 ? FALSE : TRUE;
0e320a79
DW
363 return FALSE;
364}
365
dcd307ee 366wxClientData* wxListBox::DoGetItemClientObject(int n) const
0e320a79 367{
dcd307ee 368 return (wxClientData *)DoGetItemClientData(n);
0e320a79
DW
369}
370
dcd307ee 371void *wxListBox::DoGetItemClientData(int n) const
0e320a79 372{
dcd307ee 373 wxCHECK_MSG( n >= 0 && n < m_noItems, NULL,
fb9010ed
DW
374 wxT("invalid index in wxListBox::GetClientData") );
375
dcd307ee
DW
376// return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA, n, 0);
377 return NULL;
0e320a79
DW
378}
379
dcd307ee 380void wxListBox::DoSetItemClientObject(int n, wxClientData* clientData)
0e320a79 381{
dcd307ee
DW
382 DoSetItemClientData(n, clientData);
383}
384
385void wxListBox::DoSetItemClientData(int n, void *clientData)
386{
387 wxCHECK_RET( n >= 0 && n < m_noItems,
fb9010ed
DW
388 wxT("invalid index in wxListBox::SetClientData") );
389
dcd307ee
DW
390#if wxUSE_OWNER_DRAWN
391 if ( m_windowStyle & wxLB_OWNERDRAW )
392 {
393 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
394 // in OnMeasure/OnDraw.
395 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
396 }
397#endif // wxUSE_OWNER_DRAWN
398
399// TODO:
400/*
401 if ( ListBox_SetItemData(GetHwnd(), n, clientData) == LB_ERR )
402 wxLogDebug(wxT("LB_SETITEMDATA failed"));
403*/
404}
405
406bool wxListBox::HasMultipleSelection() const
407{
408 return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED);
0e320a79
DW
409}
410
411// Return number of selections and an array of selected integers
412int wxListBox::GetSelections(wxArrayInt& aSelections) const
413{
414 aSelections.Empty();
415
dcd307ee
DW
416// TODO:
417/*
418 if ( HasMultipleSelection() )
0e320a79 419 {
dcd307ee 420 int no_sel = ListBox_GetSelCount(GetHwnd());
fb9010ed
DW
421 if (no_sel != 0) {
422 int *selections = new int[no_sel];
dcd307ee
DW
423 int rc = ListBox_GetSelItems(GetHwnd(), no_sel, selections);
424
425 wxCHECK_MSG(rc != LB_ERR, -1, wxT("ListBox_GetSelItems failed"));
fb9010ed
DW
426
427 aSelections.Alloc(no_sel);
428 for ( int n = 0; n < no_sel; n++ )
429 aSelections.Add(selections[n]);
430
431 delete [] selections;
432 }
0e320a79
DW
433
434 return no_sel;
435 }
436 else // single-selection listbox
437 {
dcd307ee 438 aSelections.Add(ListBox_GetCurSel(GetHwnd()));
0e320a79
DW
439
440 return 1;
441 }
dcd307ee
DW
442*/
443 return 0;
0e320a79
DW
444}
445
446// Get single selection, for single choice list items
447int wxListBox::GetSelection() const
448{
dcd307ee 449 wxCHECK_MSG( !HasMultipleSelection(),
fb9010ed
DW
450 -1,
451 wxT("GetSelection() can't be used with multiple-selection "
452 "listboxes, use GetSelections() instead.") );
453
454// return ListBox_GetCurSel(GetHwnd());
dcd307ee 455 return 0;
0e320a79
DW
456}
457
458// Find string for position
459wxString wxListBox::GetString(int N) const
460{
fb9010ed
DW
461 wxCHECK_MSG( N >= 0 && N < m_noItems, "",
462 wxT("invalid index in wxListBox::GetClientData") );
463
dcd307ee
DW
464// TODO:
465/*
466 int len = ListBox_GetTextLen(GetHwnd(), N);
fb9010ed
DW
467
468 // +1 for terminating NUL
469 wxString result;
dcd307ee 470 ListBox_GetText(GetHwnd(), N, result.GetWriteBuf(len + 1));
fb9010ed
DW
471 result.UngetWriteBuf();
472
473 return result;
dcd307ee
DW
474*/
475 return((wxString)"");
0e320a79
DW
476}
477
dcd307ee
DW
478void
479wxListBox::DoInsertItems(const wxArrayString& items, int pos)
480{
481 wxCHECK_RET( pos >= 0 && pos <= m_noItems,
482 wxT("invalid index in wxListBox::InsertItems") );
483
484// TODO:
485/*
486 int nItems = items.GetCount();
487 for ( int i = 0; i < nItems; i++ )
488 ListBox_InsertString(GetHwnd(), i + pos, items[i]);
489 m_noItems += nItems;
490
491 SetHorizontalExtent();
492*/
493}
494
495void wxListBox::SetString(int N, const wxString& s)
496{
497 wxCHECK_RET( N >= 0 && N < m_noItems,
498 wxT("invalid index in wxListBox::SetString") );
499
500 // remember the state of the item
501 bool wasSelected = IsSelected(N);
502
503 void *oldData = NULL;
504 wxClientData *oldObjData = NULL;
505 if ( m_clientDataItemsType == ClientData_Void )
506 oldData = GetClientData(N);
507 else if ( m_clientDataItemsType == ClientData_Object )
508 oldObjData = GetClientObject(N);
509// TODO:
510/*
511
512 // delete and recreate it
513 SendMessage(GetHwnd(), LB_DELETESTRING, N, 0);
514
515 int newN = N;
516 if ( N == m_noItems - 1 )
517 newN = -1;
518
519 ListBox_InsertString(GetHwnd(), newN, s);
520
521 // restore the client data
522 if ( oldData )
523 SetClientData(N, oldData);
524 else if ( oldObjData )
525 SetClientObject(N, oldObjData);
526
527 // we may have lost the selection
528 if ( wasSelected )
529 Select(N);
530
531#if wxUSE_OWNER_DRAWN
532 if ( m_windowStyle & wxLB_OWNERDRAW )
533 // update item's text
534 m_aItems[N]->SetName(s);
535#endif //USE_OWNER_DRAWN
536*/
537}
538
539int wxListBox::GetCount() const
540{
541 return m_noItems;
542}
543
544// ----------------------------------------------------------------------------
545// helpers
546// ----------------------------------------------------------------------------
547
548// Windows-specific code to set the horizontal extent of the listbox, if
fb9010ed
DW
549// necessary. If s is non-NULL, it's used to calculate the horizontal extent.
550// Otherwise, all strings are used.
551void wxListBox::SetHorizontalExtent(const wxString& s)
0e320a79 552{
dcd307ee 553// TODO:
fb9010ed
DW
554/*
555 // Only necessary if we want a horizontal scrollbar
556 if (!(m_windowStyle & wxHSCROLL))
557 return;
558 TEXTMETRIC lpTextMetric;
0e320a79 559
dcd307ee 560 if ( !s.IsEmpty() )
fb9010ed
DW
561 {
562 int existingExtent = (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT, 0, 0L);
563 HDC dc = GetWindowDC(GetHwnd());
564 HFONT oldFont = 0;
565 if (GetFont().Ok() && GetFont().GetResourceHandle())
566 oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle());
567
568 GetTextMetrics(dc, &lpTextMetric);
569 SIZE extentXY;
570 ::GetTextExtentPoint(dc, (LPTSTR) (const wxChar *)s, s.Length(), &extentXY);
571 int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth);
572
573 if (oldFont)
574 ::SelectObject(dc, oldFont);
575
576 ReleaseDC(GetHwnd(), dc);
577 if (extentX > existingExtent)
578 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(extentX), 0L);
fb9010ed
DW
579 }
580 else
581 {
582 int largestExtent = 0;
583 HDC dc = GetWindowDC(GetHwnd());
584 HFONT oldFont = 0;
585 if (GetFont().Ok() && GetFont().GetResourceHandle())
586 oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle());
587
588 GetTextMetrics(dc, &lpTextMetric);
589 int i;
590 for (i = 0; i < m_noItems; i++)
591 {
592 int len = (int)SendMessage(GetHwnd(), LB_GETTEXT, i, (LONG)wxBuffer);
593 wxBuffer[len] = 0;
594 SIZE extentXY;
595 ::GetTextExtentPoint(dc, (LPTSTR)wxBuffer, len, &extentXY);
596 int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth);
597 if (extentX > largestExtent)
598 largestExtent = extentX;
599 }
600 if (oldFont)
601 ::SelectObject(dc, oldFont);
602
603 ReleaseDC(GetHwnd(), dc);
604 SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(largestExtent), 0L);
605 }
606*/
607}
0e320a79 608
e78c4d50 609wxSize wxListBox::DoGetBestSize() const
fb9010ed
DW
610{
611 // find the widest string
612 int wLine;
613 int wListbox = 0;
614 for ( int i = 0; i < m_noItems; i++ )
615 {
616 wxString str(GetString(i));
617 GetTextExtent(str, &wLine, NULL);
618 if ( wLine > wListbox )
619 wListbox = wLine;
620 }
621
622 // give it some reasonable default value if there are no strings in the
623 // list
624 if ( wListbox == 0 )
625 wListbox = 100;
626
627 // the listbox should be slightly larger than the widest string
628 int cx, cy;
e78c4d50 629 wxGetCharSize(GetHWND(), &cx, &cy, (wxFont*)&GetFont());
fb9010ed
DW
630
631 wListbox += 3*cx;
632
633 int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*(wxMax(m_noItems, 7));
634
635 return wxSize(wListbox, hListbox);
636}
637
dcd307ee
DW
638// ----------------------------------------------------------------------------
639// callbacks
640// ----------------------------------------------------------------------------
641
642bool wxListBox::OS2Command(WXUINT param, WXWORD WXUNUSED(id))
0e320a79 643{
dcd307ee
DW
644 /*
645 if (param == LBN_SELCANCEL)
646 {
647 event.extraLong = FALSE;
648 }
649 */
650// TODO:
651/*
652 if (param == LBN_SELCHANGE)
653 {
654 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
655 wxArrayInt aSelections;
656 int count = GetSelections(aSelections);
657 if ( count > 0 )
658 {
659 event.m_commandInt = aSelections[0];
660 event.m_clientData = GetClientData(event.m_commandInt);
661 wxString str(GetString(event.m_commandInt));
662 if (str != wxT(""))
663 {
664 event.m_commandString = str;
665 }
666 }
667 else
668 {
669 event.m_commandInt = -1;
670 event.m_commandString.Empty();
671 }
672
673 event.SetEventObject( this );
674 ProcessCommand(event);
675 return TRUE;
676 }
677 else if (param == LBN_DBLCLK)
0e320a79 678 {
dcd307ee
DW
679 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
680 event.SetEventObject( this );
681 GetEventHandler()->ProcessEvent(event);
682 return TRUE;
0e320a79 683 }
dcd307ee
DW
684*/
685 return FALSE;
0e320a79
DW
686}
687
fb9010ed 688WXHBRUSH wxListBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
dcd307ee 689 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
fb9010ed 690{
dcd307ee 691// TODO:
fb9010ed 692/*
fb9010ed
DW
693 if (GetParent()->GetTransparentBackground())
694 SetBkMode((HDC) pDC, TRANSPARENT);
695 else
696 SetBkMode((HDC) pDC, OPAQUE);
697
698 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
699 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
700
701 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
702
703 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
704 // has a zero usage count.
705 backgroundBrush->RealizeResource();
fb9010ed 706 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
dcd307ee 707*/
e6ebb514 708 return (WXHBRUSH)0;
fb9010ed
DW
709}
710
dcd307ee
DW
711// ----------------------------------------------------------------------------
712// wxCheckListBox support
713// ----------------------------------------------------------------------------
fb9010ed
DW
714
715#if wxUSE_OWNER_DRAWN
716
717// drawing
718// -------
719
720// space beneath/above each row in pixels
721// "standard" checklistbox use 1 here, some might prefer 2. 0 is ugly.
722#define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
723
724// the height is the same for all items
725// TODO should be changed for LBS_OWNERDRAWVARIABLE style listboxes
726
727// NB: can't forward this to wxListBoxItem because LB_SETITEMDATA
728// message is not yet sent when we get here!
729bool wxListBox::OS2OnMeasure(WXMEASUREITEMSTRUCT *item)
730{
dcd307ee
DW
731// TODO:
732/*
fb9010ed
DW
733 // only owner-drawn control should receive this message
734 wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
735
dcd307ee 736 MEASUREITEMSTRUCT *pStruct = (MEASUREITEMSTRUCT *)item;
fb9010ed
DW
737
738 wxDC dc;
dcd307ee 739 dc.SetHDC((WXHDC)CreateIC(wxT("DISPLAY"), NULL, NULL, 0));
fb9010ed
DW
740 dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_ANSI_VAR_FONT));
741
dcd307ee
DW
742 pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE;
743 pStruct->itemWidth = dc.GetCharWidth();
fb9010ed 744
dcd307ee
DW
745 return TRUE;
746*/
fb9010ed
DW
747 return TRUE;
748}
749
750// forward the message to the appropriate item
751bool wxListBox::OS2OnDraw(WXDRAWITEMSTRUCT *item)
752{
dcd307ee
DW
753// TODO:
754/*
fb9010ed
DW
755 // only owner-drawn control should receive this message
756 wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
dcd307ee 757
fb9010ed
DW
758 DRAWITEMSTRUCT *pStruct = (DRAWITEMSTRUCT *)item;
759
760 long data = ListBox_GetItemData(GetHwnd(), pStruct->itemID);
761
762 wxCHECK( data && (data != LB_ERR), FALSE );
763
764 wxListBoxItem *pItem = (wxListBoxItem *)data;
765
766 wxDC dc;
767 dc.SetHDC((WXHDC)pStruct->hDC, FALSE);
768 wxRect rect(wxPoint(pStruct->rcItem.left, pStruct->rcItem.top),
769 wxPoint(pStruct->rcItem.right, pStruct->rcItem.bottom));
770
771 return pItem->OnDrawItem(dc, rect,
772 (wxOwnerDrawn::wxODAction)pStruct->itemAction,
773 (wxOwnerDrawn::wxODStatus)pStruct->itemState);
774*/
dcd307ee 775 return FALSE;
fb9010ed 776}
fb9010ed
DW
777#endif
778 // wxUSE_OWNER_DRAWN
7e99520b
DW
779
780#endif //wxUSE_LISTBOX