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