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