]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/listbox.cpp
intel fixes
[wxWidgets.git] / src / os2 / listbox.cpp
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/os2/listbox.cpp
3// Purpose: wxListBox
4// Author: David Webster
5// Modified by:
6// Created: 10/09/99
7// RCS-ID: $Id$
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
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"
17
18#ifndef WX_PRECOMP
19#include "wx/listbox.h"
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"
27#endif
28
29#define INCL_M
30#include <os2.h>
31
32#include "wx/dynarray.h"
33#include "wx/log.h"
34
35#if wxUSE_LISTBOX
36
37#if wxUSE_OWNER_DRAWN
38 #include "wx/ownerdrw.h"
39#endif
40
41 IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
42
43// ============================================================================
44// list box item declaration and implementation
45// ============================================================================
46
47#if wxUSE_OWNER_DRAWN
48
49class wxListBoxItem : public wxOwnerDrawn
50{
51public:
52 wxListBoxItem(const wxString& rsStr = wxEmptyString);
53};
54
55wxListBoxItem::wxListBoxItem(
56 const wxString& rsStr
57)
58: wxOwnerDrawn( rsStr
59 ,false
60 )
61{
62 //
63 // No bitmaps/checkmarks
64 //
65 SetMarginWidth(0);
66} // end of wxListBoxItem::wxListBoxItem
67
68wxOwnerDrawn* wxListBox::CreateItem( size_t WXUNUSED(n) )
69{
70 return new wxListBoxItem();
71} // end of wxListBox::CreateItem
72
73#endif //USE_OWNER_DRAWN
74
75// ============================================================================
76// list box control implementation
77// ============================================================================
78
79// Listbox item
80wxListBox::wxListBox()
81{
82 m_nNumItems = 0;
83 m_nSelected = 0;
84} // end of wxListBox::wxListBox
85
86bool wxListBox::Create(
87 wxWindow* pParent
88, wxWindowID vId
89, const wxPoint& rPos
90, const wxSize& rSize
91, const wxArrayString& asChoices
92, long lStyle
93, const wxValidator& rValidator
94, const wxString& rsName
95)
96{
97 wxCArrayString chs(asChoices);
98
99 return Create(pParent, vId, rPos, rSize, chs.GetCount(), chs.GetStrings(),
100 lStyle, rValidator, rsName);
101}
102
103bool wxListBox::Create(
104 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
113)
114{
115 m_nNumItems = 0;
116 m_hWnd = 0;
117 m_nSelected = 0;
118
119 SetName(rsName);
120#if wxUSE_VALIDATORS
121 SetValidator(rValidator);
122#endif
123
124 if (pParent)
125 pParent->AddChild(this);
126
127 wxSystemSettings vSettings;
128
129 SetBackgroundColour(vSettings.GetColour(wxSYS_COLOUR_WINDOW));
130 SetForegroundColour(pParent->GetForegroundColour());
131
132 m_windowId = (vId == -1) ? (int)NewControlId() : vId;
133
134 int nX = rPos.x;
135 int nY = rPos.y;
136 int nWidth = rSize.x;
137 int nHeight = rSize.y;
138
139 m_windowStyle = lStyle;
140
141 lStyle = WS_VISIBLE;
142
143 if (m_windowStyle & wxCLIP_SIBLINGS )
144 lStyle |= WS_CLIPSIBLINGS;
145 if (m_windowStyle & wxLB_MULTIPLE)
146 lStyle |= LS_MULTIPLESEL;
147 else if (m_windowStyle & wxLB_EXTENDED)
148 lStyle |= LS_EXTENDEDSEL;
149 if (m_windowStyle & wxLB_HSCROLL)
150 lStyle |= LS_HORZSCROLL;
151 if (m_windowStyle & wxLB_OWNERDRAW)
152 lStyle |= LS_OWNERDRAW;
153
154 //
155 // Without this style, you get unexpected heights, so e.g. constraint layout
156 // doesn't work properly
157 //
158 lStyle |= LS_NOADJUSTPOS;
159
160 m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent) // Parent
161 ,WC_LISTBOX // Default Listbox class
162 ,"LISTBOX" // Control's name
163 ,lStyle // Initial Style
164 ,0, 0, 0, 0 // Position and size
165 ,GetWinHwnd(pParent) // Owner
166 ,HWND_TOP // Z-Order
167 ,(HMENU)m_windowId // Id
168 ,NULL // Control Data
169 ,NULL // Presentation Parameters
170 );
171 if (m_hWnd == 0)
172 {
173 return false;
174 }
175
176 //
177 // Subclass again for purposes of dialog editing mode
178 //
179 SubclassWin(m_hWnd);
180
181 LONG lUi;
182
183 for (lUi = 0; lUi < (LONG)n; lUi++)
184 {
185 Append(asChoices[lUi]);
186 }
187 wxFont* pTextFont = new wxFont( 10
188 ,wxMODERN
189 ,wxNORMAL
190 ,wxNORMAL
191 );
192 SetFont(*pTextFont);
193
194 //
195 // Set OS/2 system colours for Listbox items and highlighting
196 //
197 wxColour vColour;
198
199 vColour = wxSystemSettingsNative::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
200
201 LONG lColor = (LONG)vColour.GetPixel();
202
203 ::WinSetPresParam( m_hWnd
204 ,PP_HILITEFOREGROUNDCOLOR
205 ,sizeof(LONG)
206 ,(PVOID)&lColor
207 );
208 vColour = wxSystemSettingsNative::GetColour(wxSYS_COLOUR_HIGHLIGHT);
209 lColor = (LONG)vColour.GetPixel();
210 ::WinSetPresParam( m_hWnd
211 ,PP_HILITEBACKGROUNDCOLOR
212 ,sizeof(LONG)
213 ,(PVOID)&lColor
214 );
215
216 SetXComp(0);
217 SetYComp(0);
218 SetSize( nX
219 ,nY
220 ,nWidth
221 ,nHeight
222 );
223 delete pTextFont;
224 return true;
225} // end of wxListBox::Create
226
227wxListBox::~wxListBox()
228{
229#if wxUSE_OWNER_DRAWN
230 size_t lUiCount = m_aItems.Count();
231
232 while (lUiCount-- != 0)
233 {
234 delete m_aItems[lUiCount];
235 }
236#endif // wxUSE_OWNER_DRAWN
237} // end of wxListBox::~wxListBox
238
239void wxListBox::SetupColours()
240{
241 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
242 SetForegroundColour(GetParent()->GetForegroundColour());
243} // end of wxListBox::SetupColours
244
245// ----------------------------------------------------------------------------
246// implementation of wxListBoxBase methods
247// ----------------------------------------------------------------------------
248
249void wxListBox::DoSetFirstItem(
250 int N
251)
252{
253 wxCHECK_RET( N >= 0 && N < m_nNumItems,
254 wxT("invalid index in wxListBox::SetFirstItem") );
255
256 ::WinSendMsg(GetHwnd(), LM_SETTOPINDEX, MPFROMLONG(N), (MPARAM)0);
257} // end of wxListBox::DoSetFirstItem
258
259void wxListBox::Delete(
260 int N
261)
262{
263 wxCHECK_RET( N >= 0 && N < m_nNumItems,
264 wxT("invalid index in wxListBox::Delete") );
265
266#if wxUSE_OWNER_DRAWN
267 delete m_aItems[N];
268 m_aItems.RemoveAt(N);
269#else // !wxUSE_OWNER_DRAWN
270 if (HasClientObjectData())
271 {
272 delete GetClientObject(N);
273 }
274#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
275
276 ::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)N, (MPARAM)0);
277 m_nNumItems--;
278} // end of wxListBox::DoSetFirstItem
279
280int wxListBox::DoAppend(
281 const wxString& rsItem
282)
283{
284 long lIndex = 0;
285 LONG lIndexType = 0;
286
287 if (m_windowStyle & wxLB_SORT)
288 lIndexType = LIT_SORTASCENDING;
289 else
290 lIndexType = LIT_END;
291 lIndex = (long)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)rsItem.c_str());
292 m_nNumItems++;
293
294#if wxUSE_OWNER_DRAWN
295 if (m_windowStyle & wxLB_OWNERDRAW)
296 {
297 wxOwnerDrawn* pNewItem = CreateItem(lIndex); // dummy argument
298 wxScreenDC vDc;
299
300
301 pNewItem->SetName(rsItem);
302 m_aItems.Insert(pNewItem, lIndex);
303 ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)lIndex, MPFROMP(pNewItem));
304 pNewItem->SetFont(GetFont());
305 }
306#endif
307 return (int)lIndex;
308} // end of wxListBox::DoAppend
309
310void wxListBox::DoSetItems(
311 const wxArrayString& raChoices
312, void** ppClientData
313)
314{
315 BOOL bHideAndShow = IsShown();
316 int i;
317 LONG lIndexType = 0;
318
319 if (bHideAndShow)
320 {
321 ::WinShowWindow(GetHwnd(), FALSE);
322 }
323 ::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
324 m_nNumItems = raChoices.GetCount();
325 for (i = 0; i < m_nNumItems; i++)
326 {
327
328 if (m_windowStyle & wxLB_SORT)
329 lIndexType = LIT_SORTASCENDING;
330 else
331 lIndexType = LIT_END;
332 ::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)raChoices[i].c_str());
333
334 if (ppClientData)
335 {
336#if wxUSE_OWNER_DRAWN
337 wxASSERT_MSG(ppClientData[i] == NULL,
338 wxT("Can't use client data with owner-drawn listboxes"));
339#else // !wxUSE_OWNER_DRAWN
340 ::WinSendMsg(WinUtil_GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(lCount), MPFROMP(ppClientData[i]));
341#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
342 }
343 }
344
345#if wxUSE_OWNER_DRAWN
346 if ( m_windowStyle & wxLB_OWNERDRAW )
347 {
348 //
349 // First delete old items
350 //
351 WX_CLEAR_ARRAY(m_aItems);
352
353 //
354 // Then create new ones
355 //
356 for (size_t ui = 0; ui < (size_t)m_nNumItems; ui++)
357 {
358 wxOwnerDrawn* pNewItem = CreateItem(ui);
359
360 pNewItem->SetName(raChoices[ui]);
361 m_aItems.Add(pNewItem);
362 ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(ui), MPFROMP(pNewItem));
363 }
364 }
365#endif // wxUSE_OWNER_DRAWN
366 ::WinShowWindow(GetHwnd(), TRUE);
367} // end of wxListBox::DoSetItems
368
369void wxListBox::Clear()
370{
371#if wxUSE_OWNER_DRAWN
372 size_t lUiCount = m_aItems.Count();
373
374 while (lUiCount-- != 0)
375 {
376 delete m_aItems[lUiCount];
377 }
378
379 m_aItems.Clear();
380#else // !wxUSE_OWNER_DRAWN
381 if (HasClientObjectData())
382 {
383 for (size_t n = 0; n < (size_t)m_lNumItems; n++)
384 {
385 delete GetClientObject(n);
386 }
387 }
388#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
389 ::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
390
391 m_nNumItems = 0;
392} // end of wxListBox::Clear
393
394void wxListBox::DoSetSelection(
395 int N
396, bool bSelect
397)
398{
399 wxCHECK_RET( N >= 0 && N < m_nNumItems,
400 wxT("invalid index in wxListBox::SetSelection") );
401 ::WinSendMsg( GetHwnd()
402 ,LM_SELECTITEM
403 ,MPFROMLONG(N)
404 ,(MPARAM)bSelect
405 );
406 if(m_windowStyle & wxLB_OWNERDRAW)
407 Refresh();
408} // end of wxListBox::SetSelection
409
410bool wxListBox::IsSelected(
411 int N
412) const
413{
414 wxCHECK_MSG( N >= 0 && N < m_nNumItems, false,
415 wxT("invalid index in wxListBox::Selected") );
416
417 LONG lItem;
418
419 if (GetWindowStyleFlag() & wxLB_EXTENDED)
420 {
421 if (N == 0)
422 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0));
423 else
424 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)(N - 1), (MPARAM)0));
425 }
426 else
427 {
428 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0));
429 }
430 return (lItem == (LONG)N && lItem != LIT_NONE);
431} // end of wxListBox::IsSelected
432
433wxClientData* wxListBox::DoGetItemClientObject(
434 int n
435) const
436{
437 return (wxClientData *)DoGetItemClientData(n);
438}
439
440void* wxListBox::DoGetItemClientData(
441 int n
442) const
443{
444 wxCHECK_MSG( n >= 0 && n < m_nNumItems, NULL,
445 wxT("invalid index in wxListBox::GetClientData") );
446
447 return((void *)::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE, MPFROMLONG(n), (MPARAM)0));
448} // end of wxListBox::DoGetItemClientData
449
450void wxListBox::DoSetItemClientObject(
451 int n
452, wxClientData* pClientData
453)
454{
455 DoSetItemClientData( n
456 ,pClientData
457 );
458} // end of wxListBox::DoSetItemClientObject
459
460void wxListBox::DoSetItemClientData(
461 int n
462, void* pClientData
463)
464{
465 wxCHECK_RET( n >= 0 && n < m_nNumItems,
466 wxT("invalid index in wxListBox::SetClientData") );
467
468#if wxUSE_OWNER_DRAWN
469 if ( m_windowStyle & wxLB_OWNERDRAW )
470 {
471 //
472 // Client data must be pointer to wxOwnerDrawn, otherwise we would crash
473 // in OnMeasure/OnDraw.
474 //
475 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
476 }
477#endif // wxUSE_OWNER_DRAWN
478
479 ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(n), MPFROMP(pClientData));
480} // end of wxListBox::DoSetItemClientData
481
482bool wxListBox::HasMultipleSelection() const
483{
484 return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED);
485} // end of wxListBox::HasMultipleSelection
486
487int wxListBox::GetSelections( wxArrayInt& raSelections ) const
488{
489 int nCount = 0;
490 LONG lItem;
491
492
493 raSelections.Empty();
494 if (HasMultipleSelection())
495 {
496 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
497 ,LM_QUERYSELECTION
498 ,(MPARAM)LIT_FIRST
499 ,(MPARAM)0
500 )
501 );
502 if (lItem != LIT_NONE)
503 {
504 nCount++;
505 while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
506 ,LM_QUERYSELECTION
507 ,(MPARAM)lItem
508 ,(MPARAM)0
509 )
510 )) != LIT_NONE)
511 {
512 nCount++;
513 }
514 raSelections.Alloc(nCount);
515 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
516 ,LM_QUERYSELECTION
517 ,(MPARAM)LIT_FIRST
518 ,(MPARAM)0
519 )
520 );
521
522 raSelections.Add((int)lItem);
523 while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
524 ,LM_QUERYSELECTION
525 ,(MPARAM)lItem
526 ,(MPARAM)0
527 )
528 )) != LIT_NONE)
529 {
530 raSelections.Add((int)lItem);
531 }
532 return nCount;
533 }
534 }
535 else // single-selection listbox
536 {
537 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
538 ,LM_QUERYSELECTION
539 ,(MPARAM)LIT_FIRST
540 ,(MPARAM)0
541 )
542 );
543 raSelections.Add((int)lItem);
544 return 1;
545 }
546 return 0;
547} // end of wxListBox::GetSelections
548
549int wxListBox::GetSelection() const
550{
551 wxCHECK_MSG( !HasMultipleSelection(),
552 -1,
553 wxT("GetSelection() can't be used with multiple-selection "
554 "listboxes, use GetSelections() instead.") );
555
556 return(LONGFROMMR(::WinSendMsg( GetHwnd()
557 ,LM_QUERYSELECTION
558 ,(MPARAM)LIT_FIRST
559 ,(MPARAM)0
560 )
561 ));
562} // end of wxListBox::GetSelection
563
564wxString wxListBox::GetString(
565 int N
566) const
567{
568 LONG lLen = 0;
569 wxChar* zBuf;
570 wxString sResult;
571
572 wxCHECK_MSG( N >= 0 && N < m_nNumItems, wxEmptyString,
573 wxT("invalid index in wxListBox::GetClientData") );
574
575 lLen = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)N, (MPARAM)0));
576 zBuf = new wxChar[lLen + 1];
577 ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT, MPFROM2SHORT((SHORT)N, (SHORT)lLen), (MPARAM)zBuf);
578 zBuf[lLen] = '\0';
579 sResult = zBuf;
580 delete [] zBuf;
581 return sResult;
582} // end of wxListBox::GetString
583
584void wxListBox::DoInsertItems(
585 const wxArrayString& asItems
586, int nPos
587)
588{
589 wxCHECK_RET( nPos >= 0 && nPos <= m_nNumItems,
590 wxT("invalid index in wxListBox::InsertItems") );
591
592 int nItems = asItems.GetCount();
593
594 for (int i = 0; i < nItems; i++)
595 {
596 int nIndex = (int)::WinSendMsg( GetHwnd()
597 ,LM_INSERTITEM
598 ,MPFROMLONG((LONG)(i + nPos))
599 ,(MPARAM)asItems[i].c_str()
600 );
601
602 wxOwnerDrawn* pNewItem = CreateItem(nIndex);
603
604 pNewItem->SetName(asItems[i]);
605 pNewItem->SetFont(GetFont());
606 m_aItems.Insert(pNewItem, nIndex);
607 ::WinSendMsg( GetHwnd()
608 ,LM_SETITEMHANDLE
609 ,(MPARAM)((LONG)nIndex)
610 ,MPFROMP(pNewItem)
611 );
612 m_nNumItems += nItems;
613 }
614} // end of wxListBox::DoInsertItems
615
616void wxListBox::SetString(
617 int N
618, const wxString& rsString
619)
620{
621 wxCHECK_RET( N >= 0 && N < m_nNumItems,
622 wxT("invalid index in wxListBox::SetString") );
623
624 //
625 // Remember the state of the item
626 //
627 bool bWasSelected = IsSelected(N);
628 void* pOldData = NULL;
629 wxClientData* pOldObjData = NULL;
630
631 if (m_clientDataItemsType == wxClientData_Void)
632 pOldData = GetClientData(N);
633 else if (m_clientDataItemsType == wxClientData_Object)
634 pOldObjData = GetClientObject(N);
635
636 //
637 // Delete and recreate it
638 //
639 ::WinSendMsg( GetHwnd()
640 ,LM_DELETEITEM
641 ,(MPARAM)N
642 ,(MPARAM)0
643 );
644
645 int nNewN = N;
646
647 if (N == m_nNumItems - 1)
648 nNewN = -1;
649
650 ::WinSendMsg( GetHwnd()
651 ,LM_INSERTITEM
652 ,(MPARAM)nNewN
653 ,(MPARAM)rsString.c_str()
654 );
655
656 //
657 // Restore the client data
658 //
659 if (pOldData)
660 SetClientData( N
661 ,pOldData
662 );
663 else if (pOldObjData)
664 SetClientObject( N
665 ,pOldObjData
666 );
667
668 //
669 // We may have lost the selection
670 //
671 if (bWasSelected)
672 Select(N);
673
674#if wxUSE_OWNER_DRAWN
675 if (m_windowStyle & wxLB_OWNERDRAW)
676 //
677 // Update item's text
678 //
679 m_aItems[N]->SetName(rsString);
680#endif //USE_OWNER_DRAWN
681} // end of wxListBox::SetString
682
683int wxListBox::GetCount() const
684{
685 return m_nNumItems;
686}
687
688// ----------------------------------------------------------------------------
689// helpers
690// ----------------------------------------------------------------------------
691
692wxSize wxListBox::DoGetBestSize() const
693{
694 //
695 // Find the widest string
696 //
697 int nLine;
698 int nListbox = 0;
699 int nCx;
700 int nCy;
701 wxFont vFont = (wxFont)GetFont();
702
703 for (int i = 0; i < m_nNumItems; i++)
704 {
705 wxString vStr(GetString(i));
706
707 GetTextExtent( vStr
708 ,&nLine
709 ,NULL
710 );
711 if (nLine > nListbox)
712 nListbox = nLine;
713 }
714
715 //
716 // Give it some reasonable default value if there are no strings in the
717 // list.
718 //
719 if (nListbox == 0)
720 nListbox = 100;
721
722 //
723 // The listbox should be slightly larger than the widest string
724 //
725 wxGetCharSize( GetHWND()
726 ,&nCx
727 ,&nCy
728 ,&vFont
729 );
730 nListbox += 3 * nCx;
731
732 int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy) * (wxMax(m_nNumItems, 7));
733
734 return wxSize( nListbox
735 ,hListbox
736 );
737} // end of wxListBox::DoGetBestSize
738
739// ----------------------------------------------------------------------------
740// callbacks
741// ----------------------------------------------------------------------------
742
743bool wxListBox::OS2Command(
744 WXUINT uParam
745, WXWORD WXUNUSED(wId))
746{
747 wxEventType eEvtType;
748
749 if (uParam == LN_SELECT)
750 {
751 eEvtType = wxEVT_COMMAND_LISTBOX_SELECTED;
752 }
753 else if (uParam == LN_ENTER)
754 {
755 eEvtType = wxEVT_COMMAND_LISTBOX_DOUBLECLICKED;
756 }
757 else
758 {
759 //
760 // Some event we're not interested in
761 //
762 return false;
763 }
764 wxCommandEvent vEvent( eEvtType
765 ,m_windowId
766 );
767
768 vEvent.SetEventObject(this);
769
770 wxArrayInt aSelections;
771 int n;
772 int nCount = GetSelections(aSelections);
773
774 if (nCount > 0)
775 {
776 n = aSelections[0];
777 if (HasClientObjectData())
778 vEvent.SetClientObject(GetClientObject(n));
779 else if ( HasClientUntypedData() )
780 vEvent.SetClientData(GetClientData(n));
781 vEvent.SetString(GetString(n));
782 }
783 else
784 {
785 n = -1;
786 }
787 vEvent.SetInt(n);
788 return GetEventHandler()->ProcessEvent(vEvent);
789} // end of wxListBox::OS2Command
790
791// ----------------------------------------------------------------------------
792// wxCheckListBox support
793// ----------------------------------------------------------------------------
794
795#if wxUSE_OWNER_DRAWN
796
797//
798// Drawing
799// -------
800//
801#define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
802
803long wxListBox::OS2OnMeasure(
804 WXMEASUREITEMSTRUCT* pItem
805)
806{
807 if (!pItem)
808 pItem = (WXMEASUREITEMSTRUCT*)new OWNERITEM;
809
810 POWNERITEM pMeasureStruct = (POWNERITEM)pItem;
811 wxScreenDC vDc;
812
813 //
814 // Only owner-drawn control should receive this message
815 //
816 wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
817
818 vDc.SetFont(GetFont());
819
820 wxCoord vHeight;
821 wxCoord vWidth;
822
823 GetSize( &vWidth
824 ,NULL
825 );
826
827 pMeasureStruct->rclItem.xRight = (USHORT)vWidth;
828 pMeasureStruct->rclItem.xLeft = 0;
829 pMeasureStruct->rclItem.yTop = 0;
830 pMeasureStruct->rclItem.yBottom = 0;
831
832 vHeight = (wxCoord)(vDc.GetCharHeight() * 2.5);
833 pMeasureStruct->rclItem.yTop = (USHORT)vHeight;
834
835 return long(MRFROM2SHORT((USHORT)vHeight, (USHORT)vWidth));
836} // end of wxListBox::OS2OnMeasure
837
838bool wxListBox::OS2OnDraw (
839 WXDRAWITEMSTRUCT* pItem
840)
841{
842 POWNERITEM pDrawStruct = (POWNERITEM)pItem;
843 LONG lItemID = pDrawStruct->idItem;
844 int eAction = 0;
845 int eStatus = 0;
846
847 //
848 // Only owner-drawn control should receive this message
849 //
850 wxCHECK(((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false);
851
852
853 //
854 // The item may be -1 for an empty listbox
855 //
856 if (lItemID == -1L)
857 return false;
858
859 wxListBoxItem* pData = (wxListBoxItem*)PVOIDFROMMR( ::WinSendMsg( GetHwnd()
860 ,LM_QUERYITEMHANDLE
861 ,MPFROMLONG(pDrawStruct->idItem)
862 ,(MPARAM)0
863 )
864 );
865
866 wxCHECK(pData, false );
867
868 wxDC vDc;
869 wxPoint pt1( pDrawStruct->rclItem.xLeft, pDrawStruct->rclItem.yTop );
870 wxPoint pt2( pDrawStruct->rclItem.xRight, pDrawStruct->rclItem.yBottom );
871 wxRect vRect( pt1, pt2 );
872
873 vDc.SetHPS(pDrawStruct->hps);
874
875 if (pDrawStruct->fsAttribute == pDrawStruct->fsAttributeOld)
876 {
877 //
878 // Entire Item needs to be redrawn (either it has reappeared from
879 // behind another window or is being displayed for the first time
880 //
881 eAction = wxOwnerDrawn::wxODDrawAll;
882
883 if (pDrawStruct->fsAttribute & MIA_HILITED)
884 {
885 //
886 // If it is currently selected we let the system handle it
887 //
888 eStatus |= wxOwnerDrawn::wxODSelected;
889 }
890 if (pDrawStruct->fsAttribute & MIA_CHECKED)
891 {
892 //
893 // If it is currently checked we draw our own
894 //
895 eStatus |= wxOwnerDrawn::wxODChecked;
896 pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_CHECKED;
897 }
898 if (pDrawStruct->fsAttribute & MIA_DISABLED)
899 {
900 //
901 // If it is currently disabled we let the system handle it
902 //
903 eStatus |= wxOwnerDrawn::wxODDisabled;
904 }
905 //
906 // Don't really care about framed (indicationg focus) or NoDismiss
907 //
908 }
909 else
910 {
911 if (pDrawStruct->fsAttribute & MIA_HILITED)
912 {
913 eAction = wxOwnerDrawn::wxODDrawAll;
914 eStatus |= wxOwnerDrawn::wxODSelected;
915 //
916 // Keep the system from trying to highlight with its bogus colors
917 //
918 pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_HILITED;
919 }
920 else if (!(pDrawStruct->fsAttribute & MIA_HILITED))
921 {
922 eAction = wxOwnerDrawn::wxODDrawAll;
923 eStatus = 0;
924 //
925 // Keep the system from trying to highlight with its bogus colors
926 //
927 pDrawStruct->fsAttribute = pDrawStruct->fsAttributeOld &= ~MIA_HILITED;
928 }
929 else
930 {
931 //
932 // For now we don't care about anything else
933 // just ignore the entire message!
934 //
935 return true;
936 }
937 }
938 return pData->OnDrawItem( vDc
939 ,vRect
940 ,(wxOwnerDrawn::wxODAction)eAction
941 ,(wxOwnerDrawn::wxODStatus)eStatus
942 );
943} // end of wxListBox::OS2OnDraw
944
945#endif // ndef for wxUSE_OWNER_DRAWN
946
947#endif // ndef for wxUSE_LISTBOX