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