]> git.saurik.com Git - wxWidgets.git/blame - src/os2/listbox.cpp
Restore code for closing inherited file descriptors in the child.
[wxWidgets.git] / src / os2 / listbox.cpp
CommitLineData
0e320a79 1///////////////////////////////////////////////////////////////////////////////
11e62fe6 2// Name: src/os2/listbox.cpp
0e320a79 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
65571936 9// Licence: wxWindows licence
0e320a79
DW
10///////////////////////////////////////////////////////////////////////////////
11
fb9010ed
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
8228b893
WS
15#if wxUSE_LISTBOX
16
e4db172a
WS
17#include "wx/listbox.h"
18
fb9010ed 19#ifndef WX_PRECOMP
ad9835c9 20 #include "wx/dynarray.h"
ad9835c9
WS
21 #include "wx/settings.h"
22 #include "wx/brush.h"
23 #include "wx/font.h"
24 #include "wx/dc.h"
25 #include "wx/dcscreen.h"
26 #include "wx/utils.h"
27 #include "wx/scrolwin.h"
e4db172a 28 #include "wx/log.h"
cdccdfab 29 #include "wx/window.h"
fb9010ed
DW
30#endif
31
38400bb4 32#include "wx/os2/dcclient.h"
ad9835c9
WS
33#include "wx/os2/private.h"
34
fb9010ed
DW
35#define INCL_M
36#include <os2.h>
37
fb9010ed
DW
38#if wxUSE_OWNER_DRAWN
39 #include "wx/ownerdrw.h"
40#endif
41
b1294ada 42IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControlWithItems)
0e320a79 43
fb9010ed
DW
44// ============================================================================
45// list box item declaration and implementation
46// ============================================================================
47
48#if wxUSE_OWNER_DRAWN
49
50class wxListBoxItem : public wxOwnerDrawn
51{
52public:
98fbab9e
VZ
53 wxListBoxItem(wxListBox *parent)
54 { m_parent = parent; }
fb9010ed 55
98fbab9e
VZ
56 wxListBox *GetParent() const
57 { return m_parent; }
58
59 int GetIndex() const
60 { return m_parent->GetItemIndex(const_cast<wxListBoxItem*>(this)); }
61
62 wxString GetName() const
63 { return m_parent->GetString(GetIndex()); }
64
65private:
66 wxListBox *m_parent;
67};
fb9010ed 68
6670f564 69wxOwnerDrawn* wxListBox::CreateItem( size_t WXUNUSED(n) )
fb9010ed 70{
98fbab9e 71 return new wxListBoxItem(this);
49dc8caa 72} // end of wxListBox::CreateItem
fb9010ed
DW
73
74#endif //USE_OWNER_DRAWN
75
0e320a79
DW
76// ============================================================================
77// list box control implementation
78// ============================================================================
79
80// Listbox item
81wxListBox::wxListBox()
82{
49dc8caa
DW
83 m_nNumItems = 0;
84 m_nSelected = 0;
85} // end of wxListBox::wxListBox
86
584ad2a3
MB
87bool wxListBox::Create(
88 wxWindow* pParent
89, wxWindowID vId
90, const wxPoint& rPos
91, const wxSize& rSize
92, const wxArrayString& asChoices
93, long lStyle
94, const wxValidator& rValidator
95, const wxString& rsName
96)
97{
98 wxCArrayString chs(asChoices);
99
100 return Create(pParent, vId, rPos, rSize, chs.GetCount(), chs.GetStrings(),
101 lStyle, rValidator, rsName);
102}
103
8228b893
WS
104bool wxListBox::Create( wxWindow* pParent,
105 wxWindowID vId,
106 const wxPoint& rPos,
107 const wxSize& rSize,
108 int n,
109 const wxString asChoices[],
110 long lStyle,
111 const wxValidator& rValidator,
112 const wxString& rsName )
0e320a79 113{
49dc8caa
DW
114 m_nNumItems = 0;
115 m_hWnd = 0;
116 m_nSelected = 0;
0e320a79 117
49dc8caa 118 SetName(rsName);
5d4b632b 119#if wxUSE_VALIDATORS
49dc8caa 120 SetValidator(rValidator);
5d4b632b 121#endif
0e320a79 122
49dc8caa
DW
123 if (pParent)
124 pParent->AddChild(this);
125
126 wxSystemSettings vSettings;
127
ec157c8f 128 SetBackgroundColour(vSettings.GetColour(wxSYS_COLOUR_WINDOW));
49dc8caa 129 SetForegroundColour(pParent->GetForegroundColour());
0e320a79 130
49dc8caa 131 m_windowId = (vId == -1) ? (int)NewControlId() : vId;
0e320a79 132
49dc8caa
DW
133 int nX = rPos.x;
134 int nY = rPos.y;
135 int nWidth = rSize.x;
136 int nHeight = rSize.y;
0e320a79 137
49dc8caa 138 m_windowStyle = lStyle;
fb9010ed 139
49dc8caa
DW
140 lStyle = WS_VISIBLE;
141
142 if (m_windowStyle & wxCLIP_SIBLINGS )
143 lStyle |= WS_CLIPSIBLINGS;
fb9010ed 144 if (m_windowStyle & wxLB_MULTIPLE)
49dc8caa 145 lStyle |= LS_MULTIPLESEL;
fb9010ed 146 else if (m_windowStyle & wxLB_EXTENDED)
49dc8caa 147 lStyle |= LS_EXTENDEDSEL;
fb9010ed 148 if (m_windowStyle & wxLB_HSCROLL)
49dc8caa
DW
149 lStyle |= LS_HORZSCROLL;
150 if (m_windowStyle & wxLB_OWNERDRAW)
151 lStyle |= LS_OWNERDRAW;
fb9010ed 152
49dc8caa 153 //
fb9010ed
DW
154 // Without this style, you get unexpected heights, so e.g. constraint layout
155 // doesn't work properly
49dc8caa
DW
156 //
157 lStyle |= LS_NOADJUSTPOS;
158
159 m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent) // Parent
160 ,WC_LISTBOX // Default Listbox class
161 ,"LISTBOX" // Control's name
162 ,lStyle // Initial Style
163 ,0, 0, 0, 0 // Position and size
164 ,GetWinHwnd(pParent) // Owner
165 ,HWND_TOP // Z-Order
166 ,(HMENU)m_windowId // Id
167 ,NULL // Control Data
168 ,NULL // Presentation Parameters
169 );
170 if (m_hWnd == 0)
fb9010ed 171 {
ec157c8f 172 return false;
fb9010ed
DW
173 }
174
49dc8caa
DW
175 //
176 // Subclass again for purposes of dialog editing mode
177 //
fb9010ed
DW
178 SubclassWin(m_hWnd);
179
49dc8caa 180 LONG lUi;
0e320a79 181
49dc8caa
DW
182 for (lUi = 0; lUi < (LONG)n; lUi++)
183 {
184 Append(asChoices[lUi]);
185 }
b3260bce
DW
186 wxFont* pTextFont = new wxFont( 10
187 ,wxMODERN
188 ,wxNORMAL
189 ,wxNORMAL
190 );
191 SetFont(*pTextFont);
e58dab20 192
5d44b24e 193 //
ad4e3f7b 194 // Set OS/2 system colours for Listbox items and highlighting
5d44b24e
DW
195 //
196 wxColour vColour;
197
ad4e3f7b 198 vColour = wxSystemSettingsNative::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
5d44b24e
DW
199
200 LONG lColor = (LONG)vColour.GetPixel();
201
202 ::WinSetPresParam( m_hWnd
203 ,PP_HILITEFOREGROUNDCOLOR
204 ,sizeof(LONG)
205 ,(PVOID)&lColor
206 );
ad4e3f7b 207 vColour = wxSystemSettingsNative::GetColour(wxSYS_COLOUR_HIGHLIGHT);
5d44b24e
DW
208 lColor = (LONG)vColour.GetPixel();
209 ::WinSetPresParam( m_hWnd
210 ,PP_HILITEBACKGROUNDCOLOR
211 ,sizeof(LONG)
212 ,(PVOID)&lColor
213 );
214
ad4e3f7b
SN
215 SetXComp(0);
216 SetYComp(0);
49dc8caa
DW
217 SetSize( nX
218 ,nY
219 ,nWidth
220 ,nHeight
221 );
b3260bce 222 delete pTextFont;
ec157c8f 223 return true;
49dc8caa 224} // end of wxListBox::Create
0e320a79
DW
225
226wxListBox::~wxListBox()
227{
98fbab9e 228 Clear();
49dc8caa 229} // end of wxListBox::~wxListBox
fb9010ed
DW
230
231void wxListBox::SetupColours()
232{
a756f210 233 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
fb9010ed 234 SetForegroundColour(GetParent()->GetForegroundColour());
49dc8caa 235} // end of wxListBox::SetupColours
0e320a79 236
dcd307ee
DW
237// ----------------------------------------------------------------------------
238// implementation of wxListBoxBase methods
239// ----------------------------------------------------------------------------
240
8228b893 241void wxListBox::DoSetFirstItem(int N)
0e320a79 242{
8228b893 243 wxCHECK_RET( IsValid(N),
fb9010ed
DW
244 wxT("invalid index in wxListBox::SetFirstItem") );
245
49dc8caa
DW
246 ::WinSendMsg(GetHwnd(), LM_SETTOPINDEX, MPFROMLONG(N), (MPARAM)0);
247} // end of wxListBox::DoSetFirstItem
0e320a79 248
a236aa20 249void wxListBox::DoDeleteOneItem(unsigned int n)
0e320a79 250{
aa61d352 251 wxCHECK_RET( IsValid(n),
fb9010ed
DW
252 wxT("invalid index in wxListBox::Delete") );
253
dcd307ee 254#if wxUSE_OWNER_DRAWN
aa61d352
VZ
255 delete m_aItems[n];
256 m_aItems.RemoveAt(n);
98fbab9e 257#endif // wxUSE_OWNER_DRAWN
dcd307ee 258
aa61d352 259 ::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)n, (MPARAM)0);
49dc8caa
DW
260 m_nNumItems--;
261} // end of wxListBox::DoSetFirstItem
0e320a79 262
a236aa20
VZ
263int wxListBox::DoInsertItems(const wxArrayStringsAdapter & items,
264 unsigned int pos,
265 void **clientData,
266 wxClientDataType type)
0e320a79 267{
8228b893
WS
268 long lIndex = 0;
269 LONG lIndexType = 0;
a236aa20 270 bool incrementPos = false;
49dc8caa 271
a236aa20 272 if (IsSorted())
9923c37d 273 lIndexType = LIT_SORTASCENDING;
a236aa20 274 else if (pos == GetCount())
9923c37d 275 lIndexType = LIT_END;
a236aa20 276 else
49dc8caa 277 {
a236aa20
VZ
278 lIndexType = (LONG)pos;
279 incrementPos = true;
fb9010ed 280 }
0e320a79 281
a236aa20 282 int n = wxNOT_FOUND;
0e320a79 283
a236aa20
VZ
284 unsigned int count = items.GetCount();
285 for (unsigned int i = 0; i < count; i++)
fb9010ed 286 {
a236aa20
VZ
287 n = (int)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)items[i].wx_str());
288 if (n < 0)
dcd307ee 289 {
9a83f860 290 wxLogLastError(wxT("WinSendMsg(LM_INSERTITEM)"));
a236aa20
VZ
291 n = wxNOT_FOUND;
292 break;
dcd307ee 293 }
a236aa20 294 ++m_nNumItems;
fb9010ed
DW
295
296#if wxUSE_OWNER_DRAWN
a236aa20 297 if (HasFlag(wxLB_OWNERDRAW))
49dc8caa 298 {
98fbab9e 299 wxOwnerDrawn* pNewItem = CreateItem(n); // dummy argument
a236aa20 300 pNewItem->SetFont(GetFont());
98fbab9e 301 m_aItems.Insert(pNewItem, n);
fb9010ed 302 }
a236aa20
VZ
303#endif
304 AssignNewItemClientData(n, clientData, i, type);
305
306 if (incrementPos)
307 ++lIndexType;
fb9010ed 308 }
0e320a79 309
a236aa20
VZ
310 return n;
311} // end of wxListBox::DoInsertAppendItemsWithData
312
313void wxListBox::DoClear()
0e320a79 314{
fb9010ed 315#if wxUSE_OWNER_DRAWN
98fbab9e 316 if ( m_windowStyle & wxLB_OWNERDRAW )
49dc8caa 317 {
98fbab9e 318 WX_CLEAR_ARRAY(m_aItems);
fb9010ed 319 }
a236aa20 320#endif // wxUSE_OWNER_DRAWN
49dc8caa 321 ::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
dcd307ee 322
49dc8caa
DW
323 m_nNumItems = 0;
324} // end of wxListBox::Clear
fb9010ed 325
8228b893 326void wxListBox::DoSetSelection( int N, bool bSelect)
0e320a79 327{
8228b893 328 wxCHECK_RET( IsValid(N),
fb9010ed 329 wxT("invalid index in wxListBox::SetSelection") );
49dc8caa
DW
330 ::WinSendMsg( GetHwnd()
331 ,LM_SELECTITEM
332 ,MPFROMLONG(N)
333 ,(MPARAM)bSelect
334 );
1de4baa3
DW
335 if(m_windowStyle & wxLB_OWNERDRAW)
336 Refresh();
49dc8caa
DW
337} // end of wxListBox::SetSelection
338
8228b893 339bool wxListBox::IsSelected( int N ) const
49dc8caa 340{
8228b893 341 wxCHECK_MSG( IsValid(N), false,
fb9010ed
DW
342 wxT("invalid index in wxListBox::Selected") );
343
49dc8caa 344 LONG lItem;
0e320a79 345
70a2c656
DW
346 if (GetWindowStyleFlag() & wxLB_EXTENDED)
347 {
348 if (N == 0)
349 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0));
350 else
351 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)(N - 1), (MPARAM)0));
352 }
353 else
354 {
355 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0));
356 }
357 return (lItem == (LONG)N && lItem != LIT_NONE);
49dc8caa
DW
358} // end of wxListBox::IsSelected
359
aa61d352 360void* wxListBox::DoGetItemClientData(unsigned int n) const
0e320a79 361{
8228b893 362 wxCHECK_MSG( IsValid(n), NULL,
fb9010ed
DW
363 wxT("invalid index in wxListBox::GetClientData") );
364
49dc8caa
DW
365 return((void *)::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE, MPFROMLONG(n), (MPARAM)0));
366} // end of wxListBox::DoGetItemClientData
0e320a79 367
aa61d352 368void wxListBox::DoSetItemClientData(unsigned int n, void* pClientData)
dcd307ee 369{
8228b893 370 wxCHECK_RET( IsValid(n),
fb9010ed
DW
371 wxT("invalid index in wxListBox::SetClientData") );
372
49dc8caa
DW
373 ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(n), MPFROMP(pClientData));
374} // end of wxListBox::DoSetItemClientData
dcd307ee
DW
375
376bool wxListBox::HasMultipleSelection() const
377{
378 return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED);
49dc8caa 379} // end of wxListBox::HasMultipleSelection
0e320a79 380
6670f564 381int wxListBox::GetSelections( wxArrayInt& raSelections ) const
0e320a79 382{
8228b893
WS
383 int nCount = 0;
384 LONG lItem;
0e320a79 385
fb9010ed 386
49dc8caa
DW
387 raSelections.Empty();
388 if (HasMultipleSelection())
389 {
390 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
391 ,LM_QUERYSELECTION
392 ,(MPARAM)LIT_FIRST
393 ,(MPARAM)0
394 )
395 );
396 if (lItem != LIT_NONE)
397 {
398 nCount++;
399 while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
400 ,LM_QUERYSELECTION
401 ,(MPARAM)lItem
402 ,(MPARAM)0
403 )
404 )) != LIT_NONE)
405 {
406 nCount++;
407 }
408 raSelections.Alloc(nCount);
409 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
410 ,LM_QUERYSELECTION
411 ,(MPARAM)LIT_FIRST
412 ,(MPARAM)0
413 )
414 );
415
416 raSelections.Add((int)lItem);
417 while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
418 ,LM_QUERYSELECTION
419 ,(MPARAM)lItem
420 ,(MPARAM)0
421 )
422 )) != LIT_NONE)
423 {
424 raSelections.Add((int)lItem);
425 }
426 return nCount;
fb9010ed 427 }
0e320a79
DW
428 }
429 else // single-selection listbox
430 {
49dc8caa
DW
431 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
432 ,LM_QUERYSELECTION
433 ,(MPARAM)LIT_FIRST
434 ,(MPARAM)0
435 )
436 );
437 raSelections.Add((int)lItem);
0e320a79
DW
438 return 1;
439 }
dcd307ee 440 return 0;
49dc8caa 441} // end of wxListBox::GetSelections
0e320a79 442
0e320a79
DW
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
49dc8caa
DW
450 return(LONGFROMMR(::WinSendMsg( GetHwnd()
451 ,LM_QUERYSELECTION
452 ,(MPARAM)LIT_FIRST
453 ,(MPARAM)0
454 )
455 ));
456} // end of wxListBox::GetSelection
0e320a79 457
aa61d352 458wxString wxListBox::GetString(unsigned int n) const
0e320a79 459{
8228b893
WS
460 LONG lLen = 0;
461 wxChar* zBuf;
462 wxString sResult;
fb9010ed 463
aa61d352 464 wxCHECK_MSG( IsValid(n), wxEmptyString,
49dc8caa 465 wxT("invalid index in wxListBox::GetClientData") );
0e320a79 466
aa61d352 467 lLen = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)n, (MPARAM)0));
0fba44b4 468 zBuf = new wxChar[lLen + 1];
aa61d352 469 ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT, MPFROM2SHORT((SHORT)n, (SHORT)lLen), (MPARAM)zBuf);
49dc8caa
DW
470 zBuf[lLen] = '\0';
471 sResult = zBuf;
472 delete [] zBuf;
473 return sResult;
474} // end of wxListBox::GetString
475
aa61d352 476void wxListBox::SetString(unsigned int n, const wxString& rsString)
dcd307ee 477{
aa61d352 478 wxCHECK_RET( IsValid(n),
dcd307ee
DW
479 wxT("invalid index in wxListBox::SetString") );
480
49dc8caa
DW
481 //
482 // Remember the state of the item
483 //
aa61d352 484 bool bWasSelected = IsSelected(n);
8228b893
WS
485 void* pOldData = NULL;
486 wxClientData* pOldObjData = NULL;
49dc8caa 487
6d8eb95b 488 if ( HasClientUntypedData() )
aa61d352 489 pOldData = GetClientData(n);
6d8eb95b 490 else if ( HasClientObjectData() )
aa61d352 491 pOldObjData = GetClientObject(n);
49dc8caa
DW
492
493 //
494 // Delete and recreate it
495 //
496 ::WinSendMsg( GetHwnd()
497 ,LM_DELETEITEM
aa61d352 498 ,(MPARAM)n
49dc8caa
DW
499 ,(MPARAM)0
500 );
501
aa61d352 502 int nNewN = n;
49dc8caa 503
020e385d 504 if (n == (m_nNumItems - 1))
49dc8caa
DW
505 nNewN = -1;
506
507 ::WinSendMsg( GetHwnd()
508 ,LM_INSERTITEM
509 ,(MPARAM)nNewN
404aba09 510 ,(MPARAM)rsString.wx_str()
49dc8caa
DW
511 );
512
513 //
514 // Restore the client data
515 //
516 if (pOldData)
aa61d352 517 SetClientData(n, pOldData);
49dc8caa 518 else if (pOldObjData)
aa61d352 519 SetClientObject(n, pOldObjData);
49dc8caa
DW
520
521 //
522 // We may have lost the selection
523 //
524 if (bWasSelected)
aa61d352 525 Select(n);
49dc8caa 526} // end of wxListBox::SetString
dcd307ee 527
aa61d352 528unsigned int wxListBox::GetCount() const
dcd307ee 529{
49dc8caa 530 return m_nNumItems;
dcd307ee
DW
531}
532
533// ----------------------------------------------------------------------------
534// helpers
535// ----------------------------------------------------------------------------
536
e78c4d50 537wxSize wxListBox::DoGetBestSize() const
fb9010ed 538{
49dc8caa
DW
539 //
540 // Find the widest string
541 //
8228b893
WS
542 int nLine;
543 int nListbox = 0;
544 int nCx;
545 int nCy;
546 wxFont vFont = (wxFont)GetFont();
49dc8caa 547
aa61d352 548 for (unsigned int i = 0; i < m_nNumItems; i++)
fb9010ed 549 {
8228b893 550 wxString vStr(GetString(i));
49dc8caa 551
8228b893 552 GetTextExtent( vStr, &nLine, NULL );
49dc8caa
DW
553 if (nLine > nListbox)
554 nListbox = nLine;
fb9010ed
DW
555 }
556
49dc8caa
DW
557 //
558 // Give it some reasonable default value if there are no strings in the
559 // list.
560 //
561 if (nListbox == 0)
562 nListbox = 100;
563
564 //
565 // The listbox should be slightly larger than the widest string
566 //
567 wxGetCharSize( GetHWND()
568 ,&nCx
569 ,&nCy
0d598bae 570 ,&vFont
49dc8caa
DW
571 );
572 nListbox += 3 * nCx;
573
8228b893 574 int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy) * (wxMax(m_nNumItems, 7));
49dc8caa
DW
575
576 return wxSize( nListbox
577 ,hListbox
578 );
579} // end of wxListBox::DoGetBestSize
fb9010ed 580
dcd307ee
DW
581// ----------------------------------------------------------------------------
582// callbacks
583// ----------------------------------------------------------------------------
584
49dc8caa
DW
585bool wxListBox::OS2Command(
586 WXUINT uParam
587, WXWORD WXUNUSED(wId))
0e320a79 588{
49dc8caa 589 wxEventType eEvtType;
dcd307ee 590
49dc8caa
DW
591 if (uParam == LN_SELECT)
592 {
593 eEvtType = wxEVT_COMMAND_LISTBOX_SELECTED;
dcd307ee 594 }
d6701f32 595 else if (uParam == LN_ENTER)
0e320a79 596 {
49dc8caa 597 eEvtType = wxEVT_COMMAND_LISTBOX_DOUBLECLICKED;
0e320a79 598 }
fb9010ed 599 else
49dc8caa
DW
600 {
601 //
602 // Some event we're not interested in
603 //
ec157c8f 604 return false;
49dc8caa
DW
605 }
606 wxCommandEvent vEvent( eEvtType
607 ,m_windowId
608 );
fb9010ed 609
49dc8caa 610 vEvent.SetEventObject(this);
fb9010ed 611
8228b893
WS
612 wxArrayInt aSelections;
613 int n;
614 int nCount = GetSelections(aSelections);
fb9010ed 615
49dc8caa
DW
616 if (nCount > 0)
617 {
618 n = aSelections[0];
619 if (HasClientObjectData())
620 vEvent.SetClientObject(GetClientObject(n));
621 else if ( HasClientUntypedData() )
622 vEvent.SetClientData(GetClientData(n));
623 vEvent.SetString(GetString(n));
624 }
625 else
626 {
627 n = -1;
628 }
687706f5 629 vEvent.SetInt(n);
937013e0 630 return HandleWindowEvent(vEvent);
49dc8caa 631} // end of wxListBox::OS2Command
fb9010ed 632
dcd307ee
DW
633// ----------------------------------------------------------------------------
634// wxCheckListBox support
635// ----------------------------------------------------------------------------
fb9010ed
DW
636
637#if wxUSE_OWNER_DRAWN
638
49dc8caa
DW
639//
640// Drawing
fb9010ed 641// -------
49dc8caa 642//
fb9010ed
DW
643#define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
644
8228b893 645long wxListBox::OS2OnMeasure(WXMEASUREITEMSTRUCT* pItem)
fb9010ed 646{
1de4baa3
DW
647 if (!pItem)
648 pItem = (WXMEASUREITEMSTRUCT*)new OWNERITEM;
649
650 POWNERITEM pMeasureStruct = (POWNERITEM)pItem;
651 wxScreenDC vDc;
652
49dc8caa 653 //
1de4baa3 654 // Only owner-drawn control should receive this message
49dc8caa 655 //
1de4baa3
DW
656 wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
657
658 vDc.SetFont(GetFont());
659
660 wxCoord vHeight;
f5ea767e
DW
661 wxCoord vWidth;
662
663 GetSize( &vWidth
664 ,NULL
665 );
1de4baa3 666
f5ea767e 667 pMeasureStruct->rclItem.xRight = (USHORT)vWidth;
1de4baa3
DW
668 pMeasureStruct->rclItem.xLeft = 0;
669 pMeasureStruct->rclItem.yTop = 0;
670 pMeasureStruct->rclItem.yBottom = 0;
671
9923c37d 672 vHeight = (wxCoord)(vDc.GetCharHeight() * 2.5);
f5ea767e 673 pMeasureStruct->rclItem.yTop = (USHORT)vHeight;
1de4baa3 674
f5ea767e 675 return long(MRFROM2SHORT((USHORT)vHeight, (USHORT)vWidth));
1de4baa3 676} // end of wxListBox::OS2OnMeasure
fb9010ed 677
1de4baa3
DW
678bool wxListBox::OS2OnDraw (
679 WXDRAWITEMSTRUCT* pItem
680)
fb9010ed 681{
1de4baa3 682 POWNERITEM pDrawStruct = (POWNERITEM)pItem;
1de4baa3
DW
683 int eAction = 0;
684 int eStatus = 0;
685
49dc8caa 686 //
1de4baa3 687 // Only owner-drawn control should receive this message
49dc8caa 688 //
ec157c8f 689 wxCHECK(((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false);
1de4baa3
DW
690
691
692 //
693 // The item may be -1 for an empty listbox
694 //
e4de7a77 695 if (pDrawStruct->idItem == -1L)
ec157c8f 696 return false;
1de4baa3 697
e4de7a77 698 wxListBoxItem* pData = (wxListBoxItem*)m_aItems[pDrawStruct->idItem];
1de4baa3 699
38400bb4
SN
700 wxClientDC vDc(this);
701 wxPMDCImpl *impl = (wxPMDCImpl*) vDc.GetImpl();
6670f564
WS
702 wxPoint pt1( pDrawStruct->rclItem.xLeft, pDrawStruct->rclItem.yTop );
703 wxPoint pt2( pDrawStruct->rclItem.xRight, pDrawStruct->rclItem.yBottom );
704 wxRect vRect( pt1, pt2 );
1de4baa3 705
38400bb4 706 impl->SetHPS(pDrawStruct->hps);
1de4baa3
DW
707
708 if (pDrawStruct->fsAttribute == pDrawStruct->fsAttributeOld)
709 {
710 //
711 // Entire Item needs to be redrawn (either it has reappeared from
712 // behind another window or is being displayed for the first time
713 //
714 eAction = wxOwnerDrawn::wxODDrawAll;
715
716 if (pDrawStruct->fsAttribute & MIA_HILITED)
717 {
718 //
719 // If it is currently selected we let the system handle it
720 //
721 eStatus |= wxOwnerDrawn::wxODSelected;
722 }
723 if (pDrawStruct->fsAttribute & MIA_CHECKED)
724 {
725 //
726 // If it is currently checked we draw our own
727 //
728 eStatus |= wxOwnerDrawn::wxODChecked;
729 pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_CHECKED;
730 }
731 if (pDrawStruct->fsAttribute & MIA_DISABLED)
732 {
733 //
734 // If it is currently disabled we let the system handle it
735 //
736 eStatus |= wxOwnerDrawn::wxODDisabled;
737 }
738 //
739 // Don't really care about framed (indicationg focus) or NoDismiss
740 //
741 }
742 else
743 {
744 if (pDrawStruct->fsAttribute & MIA_HILITED)
745 {
746 eAction = wxOwnerDrawn::wxODDrawAll;
747 eStatus |= wxOwnerDrawn::wxODSelected;
748 //
749 // Keep the system from trying to highlight with its bogus colors
750 //
751 pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_HILITED;
752 }
753 else if (!(pDrawStruct->fsAttribute & MIA_HILITED))
754 {
755 eAction = wxOwnerDrawn::wxODDrawAll;
756 eStatus = 0;
757 //
758 // Keep the system from trying to highlight with its bogus colors
759 //
760 pDrawStruct->fsAttribute = pDrawStruct->fsAttributeOld &= ~MIA_HILITED;
761 }
762 else
763 {
764 //
765 // For now we don't care about anything else
766 // just ignore the entire message!
767 //
ec157c8f 768 return true;
1de4baa3
DW
769 }
770 }
771 return pData->OnDrawItem( vDc
772 ,vRect
773 ,(wxOwnerDrawn::wxODAction)eAction
98fbab9e 774 ,(wxOwnerDrawn::wxODStatus)(eStatus | wxOwnerDrawn::wxODHidePrefix)
1de4baa3
DW
775 );
776} // end of wxListBox::OS2OnDraw
777
49dc8caa
DW
778#endif // ndef for wxUSE_OWNER_DRAWN
779
8228b893 780#endif // wxUSE_LISTBOX