]> git.saurik.com Git - wxWidgets.git/blame - src/os2/listbox.cpp
Provide stand-in IDropTargetHelper definition to fix VC6 build.
[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 266 LONG lIndexType = 0;
a236aa20 267 bool incrementPos = false;
49dc8caa 268
a236aa20 269 if (IsSorted())
9923c37d 270 lIndexType = LIT_SORTASCENDING;
a236aa20 271 else if (pos == GetCount())
9923c37d 272 lIndexType = LIT_END;
a236aa20 273 else
49dc8caa 274 {
a236aa20
VZ
275 lIndexType = (LONG)pos;
276 incrementPos = true;
fb9010ed 277 }
0e320a79 278
a236aa20 279 int n = wxNOT_FOUND;
0e320a79 280
a236aa20
VZ
281 unsigned int count = items.GetCount();
282 for (unsigned int i = 0; i < count; i++)
fb9010ed 283 {
a236aa20
VZ
284 n = (int)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)items[i].wx_str());
285 if (n < 0)
dcd307ee 286 {
9a83f860 287 wxLogLastError(wxT("WinSendMsg(LM_INSERTITEM)"));
a236aa20
VZ
288 n = wxNOT_FOUND;
289 break;
dcd307ee 290 }
a236aa20 291 ++m_nNumItems;
fb9010ed
DW
292
293#if wxUSE_OWNER_DRAWN
a236aa20 294 if (HasFlag(wxLB_OWNERDRAW))
49dc8caa 295 {
98fbab9e 296 wxOwnerDrawn* pNewItem = CreateItem(n); // dummy argument
a236aa20 297 pNewItem->SetFont(GetFont());
98fbab9e 298 m_aItems.Insert(pNewItem, n);
fb9010ed 299 }
a236aa20
VZ
300#endif
301 AssignNewItemClientData(n, clientData, i, type);
302
303 if (incrementPos)
304 ++lIndexType;
fb9010ed 305 }
0e320a79 306
a236aa20
VZ
307 return n;
308} // end of wxListBox::DoInsertAppendItemsWithData
309
310void wxListBox::DoClear()
0e320a79 311{
fb9010ed 312#if wxUSE_OWNER_DRAWN
98fbab9e 313 if ( m_windowStyle & wxLB_OWNERDRAW )
49dc8caa 314 {
98fbab9e 315 WX_CLEAR_ARRAY(m_aItems);
fb9010ed 316 }
a236aa20 317#endif // wxUSE_OWNER_DRAWN
49dc8caa 318 ::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
dcd307ee 319
49dc8caa
DW
320 m_nNumItems = 0;
321} // end of wxListBox::Clear
fb9010ed 322
8228b893 323void wxListBox::DoSetSelection( int N, bool bSelect)
0e320a79 324{
8228b893 325 wxCHECK_RET( IsValid(N),
fb9010ed 326 wxT("invalid index in wxListBox::SetSelection") );
49dc8caa
DW
327 ::WinSendMsg( GetHwnd()
328 ,LM_SELECTITEM
329 ,MPFROMLONG(N)
330 ,(MPARAM)bSelect
331 );
1de4baa3
DW
332 if(m_windowStyle & wxLB_OWNERDRAW)
333 Refresh();
49dc8caa
DW
334} // end of wxListBox::SetSelection
335
8228b893 336bool wxListBox::IsSelected( int N ) const
49dc8caa 337{
8228b893 338 wxCHECK_MSG( IsValid(N), false,
fb9010ed
DW
339 wxT("invalid index in wxListBox::Selected") );
340
49dc8caa 341 LONG lItem;
0e320a79 342
70a2c656
DW
343 if (GetWindowStyleFlag() & wxLB_EXTENDED)
344 {
345 if (N == 0)
346 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0));
347 else
348 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)(N - 1), (MPARAM)0));
349 }
350 else
351 {
352 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0));
353 }
354 return (lItem == (LONG)N && lItem != LIT_NONE);
49dc8caa
DW
355} // end of wxListBox::IsSelected
356
aa61d352 357void* wxListBox::DoGetItemClientData(unsigned int n) const
0e320a79 358{
8228b893 359 wxCHECK_MSG( IsValid(n), NULL,
fb9010ed
DW
360 wxT("invalid index in wxListBox::GetClientData") );
361
49dc8caa
DW
362 return((void *)::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE, MPFROMLONG(n), (MPARAM)0));
363} // end of wxListBox::DoGetItemClientData
0e320a79 364
aa61d352 365void wxListBox::DoSetItemClientData(unsigned int n, void* pClientData)
dcd307ee 366{
8228b893 367 wxCHECK_RET( IsValid(n),
fb9010ed
DW
368 wxT("invalid index in wxListBox::SetClientData") );
369
49dc8caa
DW
370 ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(n), MPFROMP(pClientData));
371} // end of wxListBox::DoSetItemClientData
dcd307ee
DW
372
373bool wxListBox::HasMultipleSelection() const
374{
375 return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED);
49dc8caa 376} // end of wxListBox::HasMultipleSelection
0e320a79 377
6670f564 378int wxListBox::GetSelections( wxArrayInt& raSelections ) const
0e320a79 379{
8228b893
WS
380 int nCount = 0;
381 LONG lItem;
0e320a79 382
fb9010ed 383
49dc8caa
DW
384 raSelections.Empty();
385 if (HasMultipleSelection())
386 {
387 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
388 ,LM_QUERYSELECTION
389 ,(MPARAM)LIT_FIRST
390 ,(MPARAM)0
391 )
392 );
393 if (lItem != LIT_NONE)
394 {
395 nCount++;
396 while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
397 ,LM_QUERYSELECTION
398 ,(MPARAM)lItem
399 ,(MPARAM)0
400 )
401 )) != LIT_NONE)
402 {
403 nCount++;
404 }
405 raSelections.Alloc(nCount);
406 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
407 ,LM_QUERYSELECTION
408 ,(MPARAM)LIT_FIRST
409 ,(MPARAM)0
410 )
411 );
412
413 raSelections.Add((int)lItem);
414 while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
415 ,LM_QUERYSELECTION
416 ,(MPARAM)lItem
417 ,(MPARAM)0
418 )
419 )) != LIT_NONE)
420 {
421 raSelections.Add((int)lItem);
422 }
423 return nCount;
fb9010ed 424 }
0e320a79
DW
425 }
426 else // single-selection listbox
427 {
49dc8caa
DW
428 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
429 ,LM_QUERYSELECTION
430 ,(MPARAM)LIT_FIRST
431 ,(MPARAM)0
432 )
433 );
434 raSelections.Add((int)lItem);
0e320a79
DW
435 return 1;
436 }
dcd307ee 437 return 0;
49dc8caa 438} // end of wxListBox::GetSelections
0e320a79 439
0e320a79
DW
440int wxListBox::GetSelection() const
441{
dcd307ee 442 wxCHECK_MSG( !HasMultipleSelection(),
fb9010ed
DW
443 -1,
444 wxT("GetSelection() can't be used with multiple-selection "
445 "listboxes, use GetSelections() instead.") );
446
49dc8caa
DW
447 return(LONGFROMMR(::WinSendMsg( GetHwnd()
448 ,LM_QUERYSELECTION
449 ,(MPARAM)LIT_FIRST
450 ,(MPARAM)0
451 )
452 ));
453} // end of wxListBox::GetSelection
0e320a79 454
aa61d352 455wxString wxListBox::GetString(unsigned int n) const
0e320a79 456{
8228b893
WS
457 LONG lLen = 0;
458 wxChar* zBuf;
459 wxString sResult;
fb9010ed 460
aa61d352 461 wxCHECK_MSG( IsValid(n), wxEmptyString,
49dc8caa 462 wxT("invalid index in wxListBox::GetClientData") );
0e320a79 463
aa61d352 464 lLen = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)n, (MPARAM)0));
0fba44b4 465 zBuf = new wxChar[lLen + 1];
aa61d352 466 ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT, MPFROM2SHORT((SHORT)n, (SHORT)lLen), (MPARAM)zBuf);
49dc8caa
DW
467 zBuf[lLen] = '\0';
468 sResult = zBuf;
469 delete [] zBuf;
470 return sResult;
471} // end of wxListBox::GetString
472
aa61d352 473void wxListBox::SetString(unsigned int n, const wxString& rsString)
dcd307ee 474{
aa61d352 475 wxCHECK_RET( IsValid(n),
dcd307ee
DW
476 wxT("invalid index in wxListBox::SetString") );
477
49dc8caa
DW
478 //
479 // Remember the state of the item
480 //
aa61d352 481 bool bWasSelected = IsSelected(n);
8228b893
WS
482 void* pOldData = NULL;
483 wxClientData* pOldObjData = NULL;
49dc8caa 484
6d8eb95b 485 if ( HasClientUntypedData() )
aa61d352 486 pOldData = GetClientData(n);
6d8eb95b 487 else if ( HasClientObjectData() )
aa61d352 488 pOldObjData = GetClientObject(n);
49dc8caa
DW
489
490 //
491 // Delete and recreate it
492 //
493 ::WinSendMsg( GetHwnd()
494 ,LM_DELETEITEM
aa61d352 495 ,(MPARAM)n
49dc8caa
DW
496 ,(MPARAM)0
497 );
498
aa61d352 499 int nNewN = n;
49dc8caa 500
020e385d 501 if (n == (m_nNumItems - 1))
49dc8caa
DW
502 nNewN = -1;
503
504 ::WinSendMsg( GetHwnd()
505 ,LM_INSERTITEM
506 ,(MPARAM)nNewN
404aba09 507 ,(MPARAM)rsString.wx_str()
49dc8caa
DW
508 );
509
510 //
511 // Restore the client data
512 //
513 if (pOldData)
aa61d352 514 SetClientData(n, pOldData);
49dc8caa 515 else if (pOldObjData)
aa61d352 516 SetClientObject(n, pOldObjData);
49dc8caa
DW
517
518 //
519 // We may have lost the selection
520 //
521 if (bWasSelected)
aa61d352 522 Select(n);
49dc8caa 523} // end of wxListBox::SetString
dcd307ee 524
aa61d352 525unsigned int wxListBox::GetCount() const
dcd307ee 526{
49dc8caa 527 return m_nNumItems;
dcd307ee
DW
528}
529
530// ----------------------------------------------------------------------------
531// helpers
532// ----------------------------------------------------------------------------
533
e78c4d50 534wxSize wxListBox::DoGetBestSize() const
fb9010ed 535{
49dc8caa
DW
536 //
537 // Find the widest string
538 //
8228b893
WS
539 int nLine;
540 int nListbox = 0;
541 int nCx;
542 int nCy;
543 wxFont vFont = (wxFont)GetFont();
49dc8caa 544
aa61d352 545 for (unsigned int i = 0; i < m_nNumItems; i++)
fb9010ed 546 {
8228b893 547 wxString vStr(GetString(i));
49dc8caa 548
8228b893 549 GetTextExtent( vStr, &nLine, NULL );
49dc8caa
DW
550 if (nLine > nListbox)
551 nListbox = nLine;
fb9010ed
DW
552 }
553
49dc8caa
DW
554 //
555 // Give it some reasonable default value if there are no strings in the
556 // list.
557 //
558 if (nListbox == 0)
559 nListbox = 100;
560
561 //
562 // The listbox should be slightly larger than the widest string
563 //
564 wxGetCharSize( GetHWND()
565 ,&nCx
566 ,&nCy
0d598bae 567 ,&vFont
49dc8caa
DW
568 );
569 nListbox += 3 * nCx;
570
8228b893 571 int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy) * (wxMax(m_nNumItems, 7));
49dc8caa
DW
572
573 return wxSize( nListbox
574 ,hListbox
575 );
576} // end of wxListBox::DoGetBestSize
fb9010ed 577
dcd307ee
DW
578// ----------------------------------------------------------------------------
579// callbacks
580// ----------------------------------------------------------------------------
581
49dc8caa
DW
582bool wxListBox::OS2Command(
583 WXUINT uParam
584, WXWORD WXUNUSED(wId))
0e320a79 585{
49dc8caa 586 wxEventType eEvtType;
dcd307ee 587
49dc8caa
DW
588 if (uParam == LN_SELECT)
589 {
590 eEvtType = wxEVT_COMMAND_LISTBOX_SELECTED;
dcd307ee 591 }
d6701f32 592 else if (uParam == LN_ENTER)
0e320a79 593 {
49dc8caa 594 eEvtType = wxEVT_COMMAND_LISTBOX_DOUBLECLICKED;
0e320a79 595 }
fb9010ed 596 else
49dc8caa
DW
597 {
598 //
599 // Some event we're not interested in
600 //
ec157c8f 601 return false;
49dc8caa
DW
602 }
603 wxCommandEvent vEvent( eEvtType
604 ,m_windowId
605 );
fb9010ed 606
49dc8caa 607 vEvent.SetEventObject(this);
fb9010ed 608
8228b893
WS
609 wxArrayInt aSelections;
610 int n;
611 int nCount = GetSelections(aSelections);
fb9010ed 612
49dc8caa
DW
613 if (nCount > 0)
614 {
615 n = aSelections[0];
616 if (HasClientObjectData())
617 vEvent.SetClientObject(GetClientObject(n));
618 else if ( HasClientUntypedData() )
619 vEvent.SetClientData(GetClientData(n));
620 vEvent.SetString(GetString(n));
621 }
622 else
623 {
624 n = -1;
625 }
687706f5 626 vEvent.SetInt(n);
937013e0 627 return HandleWindowEvent(vEvent);
49dc8caa 628} // end of wxListBox::OS2Command
fb9010ed 629
dcd307ee
DW
630// ----------------------------------------------------------------------------
631// wxCheckListBox support
632// ----------------------------------------------------------------------------
fb9010ed
DW
633
634#if wxUSE_OWNER_DRAWN
635
49dc8caa
DW
636//
637// Drawing
fb9010ed 638// -------
49dc8caa 639//
fb9010ed
DW
640#define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
641
8228b893 642long wxListBox::OS2OnMeasure(WXMEASUREITEMSTRUCT* pItem)
fb9010ed 643{
1de4baa3
DW
644 if (!pItem)
645 pItem = (WXMEASUREITEMSTRUCT*)new OWNERITEM;
646
647 POWNERITEM pMeasureStruct = (POWNERITEM)pItem;
648 wxScreenDC vDc;
649
49dc8caa 650 //
1de4baa3 651 // Only owner-drawn control should receive this message
49dc8caa 652 //
1de4baa3
DW
653 wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
654
655 vDc.SetFont(GetFont());
656
657 wxCoord vHeight;
f5ea767e
DW
658 wxCoord vWidth;
659
660 GetSize( &vWidth
661 ,NULL
662 );
1de4baa3 663
f5ea767e 664 pMeasureStruct->rclItem.xRight = (USHORT)vWidth;
1de4baa3
DW
665 pMeasureStruct->rclItem.xLeft = 0;
666 pMeasureStruct->rclItem.yTop = 0;
667 pMeasureStruct->rclItem.yBottom = 0;
668
9923c37d 669 vHeight = (wxCoord)(vDc.GetCharHeight() * 2.5);
f5ea767e 670 pMeasureStruct->rclItem.yTop = (USHORT)vHeight;
1de4baa3 671
f5ea767e 672 return long(MRFROM2SHORT((USHORT)vHeight, (USHORT)vWidth));
1de4baa3 673} // end of wxListBox::OS2OnMeasure
fb9010ed 674
1de4baa3
DW
675bool wxListBox::OS2OnDraw (
676 WXDRAWITEMSTRUCT* pItem
677)
fb9010ed 678{
1de4baa3 679 POWNERITEM pDrawStruct = (POWNERITEM)pItem;
1de4baa3
DW
680 int eAction = 0;
681 int eStatus = 0;
682
49dc8caa 683 //
1de4baa3 684 // Only owner-drawn control should receive this message
49dc8caa 685 //
ec157c8f 686 wxCHECK(((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false);
1de4baa3
DW
687
688
689 //
690 // The item may be -1 for an empty listbox
691 //
e4de7a77 692 if (pDrawStruct->idItem == -1L)
ec157c8f 693 return false;
1de4baa3 694
e4de7a77 695 wxListBoxItem* pData = (wxListBoxItem*)m_aItems[pDrawStruct->idItem];
1de4baa3 696
38400bb4
SN
697 wxClientDC vDc(this);
698 wxPMDCImpl *impl = (wxPMDCImpl*) vDc.GetImpl();
6670f564
WS
699 wxPoint pt1( pDrawStruct->rclItem.xLeft, pDrawStruct->rclItem.yTop );
700 wxPoint pt2( pDrawStruct->rclItem.xRight, pDrawStruct->rclItem.yBottom );
701 wxRect vRect( pt1, pt2 );
1de4baa3 702
38400bb4 703 impl->SetHPS(pDrawStruct->hps);
1de4baa3
DW
704
705 if (pDrawStruct->fsAttribute == pDrawStruct->fsAttributeOld)
706 {
707 //
708 // Entire Item needs to be redrawn (either it has reappeared from
709 // behind another window or is being displayed for the first time
710 //
711 eAction = wxOwnerDrawn::wxODDrawAll;
712
713 if (pDrawStruct->fsAttribute & MIA_HILITED)
714 {
715 //
716 // If it is currently selected we let the system handle it
717 //
718 eStatus |= wxOwnerDrawn::wxODSelected;
719 }
720 if (pDrawStruct->fsAttribute & MIA_CHECKED)
721 {
722 //
723 // If it is currently checked we draw our own
724 //
725 eStatus |= wxOwnerDrawn::wxODChecked;
726 pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_CHECKED;
727 }
728 if (pDrawStruct->fsAttribute & MIA_DISABLED)
729 {
730 //
731 // If it is currently disabled we let the system handle it
732 //
733 eStatus |= wxOwnerDrawn::wxODDisabled;
734 }
735 //
736 // Don't really care about framed (indicationg focus) or NoDismiss
737 //
738 }
739 else
740 {
741 if (pDrawStruct->fsAttribute & MIA_HILITED)
742 {
743 eAction = wxOwnerDrawn::wxODDrawAll;
744 eStatus |= wxOwnerDrawn::wxODSelected;
745 //
746 // Keep the system from trying to highlight with its bogus colors
747 //
748 pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_HILITED;
749 }
750 else if (!(pDrawStruct->fsAttribute & MIA_HILITED))
751 {
752 eAction = wxOwnerDrawn::wxODDrawAll;
753 eStatus = 0;
754 //
755 // Keep the system from trying to highlight with its bogus colors
756 //
757 pDrawStruct->fsAttribute = pDrawStruct->fsAttributeOld &= ~MIA_HILITED;
758 }
759 else
760 {
761 //
762 // For now we don't care about anything else
763 // just ignore the entire message!
764 //
ec157c8f 765 return true;
1de4baa3
DW
766 }
767 }
768 return pData->OnDrawItem( vDc
769 ,vRect
770 ,(wxOwnerDrawn::wxODAction)eAction
98fbab9e 771 ,(wxOwnerDrawn::wxODStatus)(eStatus | wxOwnerDrawn::wxODHidePrefix)
1de4baa3
DW
772 );
773} // end of wxListBox::OS2OnDraw
774
49dc8caa
DW
775#endif // ndef for wxUSE_OWNER_DRAWN
776
8228b893 777#endif // wxUSE_LISTBOX