]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/listbox.cpp
Silence warning about truncation since the comment says it ok
[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 standard wxWidgets colors for Listbox items and highlighting
196 //
197 wxColour vColour;
198
199 vColour.Set(wxString(wxT("WHITE")));
200
201 LONG lColor = (LONG)vColour.GetPixel();
202
203 ::WinSetPresParam( m_hWnd
204 ,PP_HILITEFOREGROUNDCOLOR
205 ,sizeof(LONG)
206 ,(PVOID)&lColor
207 );
208 vColour.Set(wxString(wxT("NAVY")));
209 lColor = (LONG)vColour.GetPixel();
210 ::WinSetPresParam( m_hWnd
211 ,PP_HILITEBACKGROUNDCOLOR
212 ,sizeof(LONG)
213 ,(PVOID)&lColor
214 );
215
216 SetSize( nX
217 ,nY
218 ,nWidth
219 ,nHeight
220 );
221 delete pTextFont;
222 return true;
223} // end of wxListBox::Create
224
225wxListBox::~wxListBox()
226{
227#if wxUSE_OWNER_DRAWN
228 size_t lUiCount = m_aItems.Count();
229
230 while (lUiCount-- != 0)
231 {
232 delete m_aItems[lUiCount];
233 }
234#endif // wxUSE_OWNER_DRAWN
235} // end of wxListBox::~wxListBox
236
237void wxListBox::SetupColours()
238{
239 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
240 SetForegroundColour(GetParent()->GetForegroundColour());
241} // end of wxListBox::SetupColours
242
243// ----------------------------------------------------------------------------
244// implementation of wxListBoxBase methods
245// ----------------------------------------------------------------------------
246
247void wxListBox::DoSetFirstItem(
248 int N
249)
250{
251 wxCHECK_RET( N >= 0 && N < m_nNumItems,
252 wxT("invalid index in wxListBox::SetFirstItem") );
253
254 ::WinSendMsg(GetHwnd(), LM_SETTOPINDEX, MPFROMLONG(N), (MPARAM)0);
255} // end of wxListBox::DoSetFirstItem
256
257void wxListBox::Delete(
258 int N
259)
260{
261 wxCHECK_RET( N >= 0 && N < m_nNumItems,
262 wxT("invalid index in wxListBox::Delete") );
263
264#if wxUSE_OWNER_DRAWN
265 delete m_aItems[N];
266 m_aItems.RemoveAt(N);
267#else // !wxUSE_OWNER_DRAWN
268 if (HasClientObjectData())
269 {
270 delete GetClientObject(N);
271 }
272#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
273
274 ::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)N, (MPARAM)0);
275 m_nNumItems--;
276} // end of wxListBox::DoSetFirstItem
277
278int wxListBox::DoAppend(
279 const wxString& rsItem
280)
281{
282 long lIndex = 0;
283 LONG lIndexType = 0;
284
285 if (m_windowStyle & wxLB_SORT)
286 lIndexType = LIT_SORTASCENDING;
287 else
288 lIndexType = LIT_END;
289 lIndex = (long)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)rsItem.c_str());
290 m_nNumItems++;
291
292#if wxUSE_OWNER_DRAWN
293 if (m_windowStyle & wxLB_OWNERDRAW)
294 {
295 wxOwnerDrawn* pNewItem = CreateItem(lIndex); // dummy argument
296 wxScreenDC vDc;
297
298
299 pNewItem->SetName(rsItem);
300 m_aItems.Insert(pNewItem, lIndex);
301 ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)lIndex, MPFROMP(pNewItem));
302 pNewItem->SetFont(GetFont());
303 }
304#endif
305 return (int)lIndex;
306} // end of wxListBox::DoAppend
307
308void wxListBox::DoSetItems(
309 const wxArrayString& raChoices
310, void** ppClientData
311)
312{
313 BOOL bHideAndShow = IsShown();
314 int i;
315 LONG lIndexType = 0;
316
317 if (bHideAndShow)
318 {
319 ::WinShowWindow(GetHwnd(), FALSE);
320 }
321 ::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
322 m_nNumItems = raChoices.GetCount();
323 for (i = 0; i < m_nNumItems; i++)
324 {
325
326 if (m_windowStyle & wxLB_SORT)
327 lIndexType = LIT_SORTASCENDING;
328 else
329 lIndexType = LIT_END;
330 ::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)raChoices[i].c_str());
331
332 if (ppClientData)
333 {
334#if wxUSE_OWNER_DRAWN
335 wxASSERT_MSG(ppClientData[i] == NULL,
336 wxT("Can't use client data with owner-drawn listboxes"));
337#else // !wxUSE_OWNER_DRAWN
338 ::WinSendMsg(WinUtil_GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(lCount), MPFROMP(ppClientData[i]));
339#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
340 }
341 }
342
343#if wxUSE_OWNER_DRAWN
344 if ( m_windowStyle & wxLB_OWNERDRAW )
345 {
346 //
347 // First delete old items
348 //
349 WX_CLEAR_ARRAY(m_aItems);
350
351 //
352 // Then create new ones
353 //
354 for (size_t ui = 0; ui < (size_t)m_nNumItems; ui++)
355 {
356 wxOwnerDrawn* pNewItem = CreateItem(ui);
357
358 pNewItem->SetName(raChoices[ui]);
359 m_aItems.Add(pNewItem);
360 ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(ui), MPFROMP(pNewItem));
361 }
362 }
363#endif // wxUSE_OWNER_DRAWN
364 ::WinShowWindow(GetHwnd(), TRUE);
365} // end of wxListBox::DoSetItems
366
367void wxListBox::Clear()
368{
369#if wxUSE_OWNER_DRAWN
370 size_t lUiCount = m_aItems.Count();
371
372 while (lUiCount-- != 0)
373 {
374 delete m_aItems[lUiCount];
375 }
376
377 m_aItems.Clear();
378#else // !wxUSE_OWNER_DRAWN
379 if (HasClientObjectData())
380 {
381 for (size_t n = 0; n < (size_t)m_lNumItems; n++)
382 {
383 delete GetClientObject(n);
384 }
385 }
386#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
387 ::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
388
389 m_nNumItems = 0;
390} // end of wxListBox::Clear
391
392void wxListBox::DoSetSelection(
393 int N
394, bool bSelect
395)
396{
397 wxCHECK_RET( N >= 0 && N < m_nNumItems,
398 wxT("invalid index in wxListBox::SetSelection") );
399 ::WinSendMsg( GetHwnd()
400 ,LM_SELECTITEM
401 ,MPFROMLONG(N)
402 ,(MPARAM)bSelect
403 );
404 if(m_windowStyle & wxLB_OWNERDRAW)
405 Refresh();
406} // end of wxListBox::SetSelection
407
408bool wxListBox::IsSelected(
409 int N
410) const
411{
412 wxCHECK_MSG( N >= 0 && N < m_nNumItems, false,
413 wxT("invalid index in wxListBox::Selected") );
414
415 LONG lItem;
416
417 if (GetWindowStyleFlag() & wxLB_EXTENDED)
418 {
419 if (N == 0)
420 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0));
421 else
422 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)(N - 1), (MPARAM)0));
423 }
424 else
425 {
426 lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0));
427 }
428 return (lItem == (LONG)N && lItem != LIT_NONE);
429} // end of wxListBox::IsSelected
430
431wxClientData* wxListBox::DoGetItemClientObject(
432 int n
433) const
434{
435 return (wxClientData *)DoGetItemClientData(n);
436}
437
438void* wxListBox::DoGetItemClientData(
439 int n
440) const
441{
442 wxCHECK_MSG( n >= 0 && n < m_nNumItems, NULL,
443 wxT("invalid index in wxListBox::GetClientData") );
444
445 return((void *)::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE, MPFROMLONG(n), (MPARAM)0));
446} // end of wxListBox::DoGetItemClientData
447
448void wxListBox::DoSetItemClientObject(
449 int n
450, wxClientData* pClientData
451)
452{
453 DoSetItemClientData( n
454 ,pClientData
455 );
456} // end of wxListBox::DoSetItemClientObject
457
458void wxListBox::DoSetItemClientData(
459 int n
460, void* pClientData
461)
462{
463 wxCHECK_RET( n >= 0 && n < m_nNumItems,
464 wxT("invalid index in wxListBox::SetClientData") );
465
466#if wxUSE_OWNER_DRAWN
467 if ( m_windowStyle & wxLB_OWNERDRAW )
468 {
469 //
470 // Client data must be pointer to wxOwnerDrawn, otherwise we would crash
471 // in OnMeasure/OnDraw.
472 //
473 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
474 }
475#endif // wxUSE_OWNER_DRAWN
476
477 ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(n), MPFROMP(pClientData));
478} // end of wxListBox::DoSetItemClientData
479
480bool wxListBox::HasMultipleSelection() const
481{
482 return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED);
483} // end of wxListBox::HasMultipleSelection
484
485int wxListBox::GetSelections( wxArrayInt& raSelections ) const
486{
487 int nCount = 0;
488 LONG lItem;
489
490
491 raSelections.Empty();
492 if (HasMultipleSelection())
493 {
494 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
495 ,LM_QUERYSELECTION
496 ,(MPARAM)LIT_FIRST
497 ,(MPARAM)0
498 )
499 );
500 if (lItem != LIT_NONE)
501 {
502 nCount++;
503 while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
504 ,LM_QUERYSELECTION
505 ,(MPARAM)lItem
506 ,(MPARAM)0
507 )
508 )) != LIT_NONE)
509 {
510 nCount++;
511 }
512 raSelections.Alloc(nCount);
513 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
514 ,LM_QUERYSELECTION
515 ,(MPARAM)LIT_FIRST
516 ,(MPARAM)0
517 )
518 );
519
520 raSelections.Add((int)lItem);
521 while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
522 ,LM_QUERYSELECTION
523 ,(MPARAM)lItem
524 ,(MPARAM)0
525 )
526 )) != LIT_NONE)
527 {
528 raSelections.Add((int)lItem);
529 }
530 return nCount;
531 }
532 }
533 else // single-selection listbox
534 {
535 lItem = LONGFROMMR(::WinSendMsg( GetHwnd()
536 ,LM_QUERYSELECTION
537 ,(MPARAM)LIT_FIRST
538 ,(MPARAM)0
539 )
540 );
541 raSelections.Add((int)lItem);
542 return 1;
543 }
544 return 0;
545} // end of wxListBox::GetSelections
546
547int wxListBox::GetSelection() const
548{
549 wxCHECK_MSG( !HasMultipleSelection(),
550 -1,
551 wxT("GetSelection() can't be used with multiple-selection "
552 "listboxes, use GetSelections() instead.") );
553
554 return(LONGFROMMR(::WinSendMsg( GetHwnd()
555 ,LM_QUERYSELECTION
556 ,(MPARAM)LIT_FIRST
557 ,(MPARAM)0
558 )
559 ));
560} // end of wxListBox::GetSelection
561
562wxString wxListBox::GetString(
563 int N
564) const
565{
566 LONG lLen = 0;
567 wxChar* zBuf;
568 wxString sResult;
569
570 wxCHECK_MSG( N >= 0 && N < m_nNumItems, wxEmptyString,
571 wxT("invalid index in wxListBox::GetClientData") );
572
573 lLen = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)N, (MPARAM)0));
574 zBuf = new wxChar[lLen + 1];
575 ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT, MPFROM2SHORT((SHORT)N, (SHORT)lLen), (MPARAM)zBuf);
576 zBuf[lLen] = '\0';
577 sResult = zBuf;
578 delete [] zBuf;
579 return sResult;
580} // end of wxListBox::GetString
581
582void wxListBox::DoInsertItems(
583 const wxArrayString& asItems
584, int nPos
585)
586{
587 wxCHECK_RET( nPos >= 0 && nPos <= m_nNumItems,
588 wxT("invalid index in wxListBox::InsertItems") );
589
590 int nItems = asItems.GetCount();
591
592 for (int i = 0; i < nItems; i++)
593 {
594 int nIndex = (int)::WinSendMsg( GetHwnd()
595 ,LM_INSERTITEM
596 ,MPFROMLONG((LONG)(i + nPos))
597 ,(MPARAM)asItems[i].c_str()
598 );
599
600 wxOwnerDrawn* pNewItem = CreateItem(nIndex);
601
602 pNewItem->SetName(asItems[i]);
603 pNewItem->SetFont(GetFont());
604 m_aItems.Insert(pNewItem, nIndex);
605 ::WinSendMsg( GetHwnd()
606 ,LM_SETITEMHANDLE
607 ,(MPARAM)((LONG)nIndex)
608 ,MPFROMP(pNewItem)
609 );
610 m_nNumItems += nItems;
611 }
612} // end of wxListBox::DoInsertItems
613
614void wxListBox::SetString(
615 int N
616, const wxString& rsString
617)
618{
619 wxCHECK_RET( N >= 0 && N < m_nNumItems,
620 wxT("invalid index in wxListBox::SetString") );
621
622 //
623 // Remember the state of the item
624 //
625 bool bWasSelected = IsSelected(N);
626 void* pOldData = NULL;
627 wxClientData* pOldObjData = NULL;
628
629 if (m_clientDataItemsType == wxClientData_Void)
630 pOldData = GetClientData(N);
631 else if (m_clientDataItemsType == wxClientData_Object)
632 pOldObjData = GetClientObject(N);
633
634 //
635 // Delete and recreate it
636 //
637 ::WinSendMsg( GetHwnd()
638 ,LM_DELETEITEM
639 ,(MPARAM)N
640 ,(MPARAM)0
641 );
642
643 int nNewN = N;
644
645 if (N == m_nNumItems - 1)
646 nNewN = -1;
647
648 ::WinSendMsg( GetHwnd()
649 ,LM_INSERTITEM
650 ,(MPARAM)nNewN
651 ,(MPARAM)rsString.c_str()
652 );
653
654 //
655 // Restore the client data
656 //
657 if (pOldData)
658 SetClientData( N
659 ,pOldData
660 );
661 else if (pOldObjData)
662 SetClientObject( N
663 ,pOldObjData
664 );
665
666 //
667 // We may have lost the selection
668 //
669 if (bWasSelected)
670 Select(N);
671
672#if wxUSE_OWNER_DRAWN
673 if (m_windowStyle & wxLB_OWNERDRAW)
674 //
675 // Update item's text
676 //
677 m_aItems[N]->SetName(rsString);
678#endif //USE_OWNER_DRAWN
679} // end of wxListBox::SetString
680
681int wxListBox::GetCount() const
682{
683 return m_nNumItems;
684}
685
686// ----------------------------------------------------------------------------
687// helpers
688// ----------------------------------------------------------------------------
689
690wxSize wxListBox::DoGetBestSize() const
691{
692 //
693 // Find the widest string
694 //
695 int nLine;
696 int nListbox = 0;
697 int nCx;
698 int nCy;
699 wxFont vFont = (wxFont)GetFont();
700
701 for (int i = 0; i < m_nNumItems; i++)
702 {
703 wxString vStr(GetString(i));
704
705 GetTextExtent( vStr
706 ,&nLine
707 ,NULL
708 );
709 if (nLine > nListbox)
710 nListbox = nLine;
711 }
712
713 //
714 // Give it some reasonable default value if there are no strings in the
715 // list.
716 //
717 if (nListbox == 0)
718 nListbox = 100;
719
720 //
721 // The listbox should be slightly larger than the widest string
722 //
723 wxGetCharSize( GetHWND()
724 ,&nCx
725 ,&nCy
726 ,&vFont
727 );
728 nListbox += 3 * nCx;
729
730 int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy) * (wxMax(m_nNumItems, 7));
731
732 return wxSize( nListbox
733 ,hListbox
734 );
735} // end of wxListBox::DoGetBestSize
736
737// ----------------------------------------------------------------------------
738// callbacks
739// ----------------------------------------------------------------------------
740
741bool wxListBox::OS2Command(
742 WXUINT uParam
743, WXWORD WXUNUSED(wId))
744{
745 wxEventType eEvtType;
746
747 if (uParam == LN_SELECT)
748 {
749 eEvtType = wxEVT_COMMAND_LISTBOX_SELECTED;
750 }
751 else if (uParam == LN_ENTER)
752 {
753 eEvtType = wxEVT_COMMAND_LISTBOX_DOUBLECLICKED;
754 }
755 else
756 {
757 //
758 // Some event we're not interested in
759 //
760 return false;
761 }
762 wxCommandEvent vEvent( eEvtType
763 ,m_windowId
764 );
765
766 vEvent.SetEventObject(this);
767
768 wxArrayInt aSelections;
769 int n;
770 int nCount = GetSelections(aSelections);
771
772 if (nCount > 0)
773 {
774 n = aSelections[0];
775 if (HasClientObjectData())
776 vEvent.SetClientObject(GetClientObject(n));
777 else if ( HasClientUntypedData() )
778 vEvent.SetClientData(GetClientData(n));
779 vEvent.SetString(GetString(n));
780 }
781 else
782 {
783 n = -1;
784 }
785 vEvent.SetInt(n);
786 return GetEventHandler()->ProcessEvent(vEvent);
787} // end of wxListBox::OS2Command
788
789// ----------------------------------------------------------------------------
790// wxCheckListBox support
791// ----------------------------------------------------------------------------
792
793#if wxUSE_OWNER_DRAWN
794
795//
796// Drawing
797// -------
798//
799#define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
800
801long wxListBox::OS2OnMeasure(
802 WXMEASUREITEMSTRUCT* pItem
803)
804{
805 if (!pItem)
806 pItem = (WXMEASUREITEMSTRUCT*)new OWNERITEM;
807
808 POWNERITEM pMeasureStruct = (POWNERITEM)pItem;
809 wxScreenDC vDc;
810
811 //
812 // Only owner-drawn control should receive this message
813 //
814 wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
815
816 vDc.SetFont(GetFont());
817
818 wxCoord vHeight;
819 wxCoord vWidth;
820
821 GetSize( &vWidth
822 ,NULL
823 );
824
825 pMeasureStruct->rclItem.xRight = (USHORT)vWidth;
826 pMeasureStruct->rclItem.xLeft = 0;
827 pMeasureStruct->rclItem.yTop = 0;
828 pMeasureStruct->rclItem.yBottom = 0;
829
830 vHeight = (wxCoord)(vDc.GetCharHeight() * 2.5);
831 pMeasureStruct->rclItem.yTop = (USHORT)vHeight;
832
833 return long(MRFROM2SHORT((USHORT)vHeight, (USHORT)vWidth));
834} // end of wxListBox::OS2OnMeasure
835
836bool wxListBox::OS2OnDraw (
837 WXDRAWITEMSTRUCT* pItem
838)
839{
840 POWNERITEM pDrawStruct = (POWNERITEM)pItem;
841 LONG lItemID = pDrawStruct->idItem;
842 int eAction = 0;
843 int eStatus = 0;
844
845 //
846 // Only owner-drawn control should receive this message
847 //
848 wxCHECK(((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false);
849
850
851 //
852 // The item may be -1 for an empty listbox
853 //
854 if (lItemID == -1L)
855 return false;
856
857 wxListBoxItem* pData = (wxListBoxItem*)PVOIDFROMMR( ::WinSendMsg( GetHwnd()
858 ,LM_QUERYITEMHANDLE
859 ,MPFROMLONG(pDrawStruct->idItem)
860 ,(MPARAM)0
861 )
862 );
863
864 wxCHECK(pData, false );
865
866 wxDC vDc;
867 wxPoint pt1( pDrawStruct->rclItem.xLeft, pDrawStruct->rclItem.yTop );
868 wxPoint pt2( pDrawStruct->rclItem.xRight, pDrawStruct->rclItem.yBottom );
869 wxRect vRect( pt1, pt2 );
870
871 vDc.SetHPS(pDrawStruct->hps);
872
873 if (pDrawStruct->fsAttribute == pDrawStruct->fsAttributeOld)
874 {
875 //
876 // Entire Item needs to be redrawn (either it has reappeared from
877 // behind another window or is being displayed for the first time
878 //
879 eAction = wxOwnerDrawn::wxODDrawAll;
880
881 if (pDrawStruct->fsAttribute & MIA_HILITED)
882 {
883 //
884 // If it is currently selected we let the system handle it
885 //
886 eStatus |= wxOwnerDrawn::wxODSelected;
887 }
888 if (pDrawStruct->fsAttribute & MIA_CHECKED)
889 {
890 //
891 // If it is currently checked we draw our own
892 //
893 eStatus |= wxOwnerDrawn::wxODChecked;
894 pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_CHECKED;
895 }
896 if (pDrawStruct->fsAttribute & MIA_DISABLED)
897 {
898 //
899 // If it is currently disabled we let the system handle it
900 //
901 eStatus |= wxOwnerDrawn::wxODDisabled;
902 }
903 //
904 // Don't really care about framed (indicationg focus) or NoDismiss
905 //
906 }
907 else
908 {
909 if (pDrawStruct->fsAttribute & MIA_HILITED)
910 {
911 eAction = wxOwnerDrawn::wxODDrawAll;
912 eStatus |= wxOwnerDrawn::wxODSelected;
913 //
914 // Keep the system from trying to highlight with its bogus colors
915 //
916 pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_HILITED;
917 }
918 else if (!(pDrawStruct->fsAttribute & MIA_HILITED))
919 {
920 eAction = wxOwnerDrawn::wxODDrawAll;
921 eStatus = 0;
922 //
923 // Keep the system from trying to highlight with its bogus colors
924 //
925 pDrawStruct->fsAttribute = pDrawStruct->fsAttributeOld &= ~MIA_HILITED;
926 }
927 else
928 {
929 //
930 // For now we don't care about anything else
931 // just ignore the entire message!
932 //
933 return true;
934 }
935 }
936 return pData->OnDrawItem( vDc
937 ,vRect
938 ,(wxOwnerDrawn::wxODAction)eAction
939 ,(wxOwnerDrawn::wxODStatus)eStatus
940 );
941} // end of wxListBox::OS2OnDraw
942
943#endif // ndef for wxUSE_OWNER_DRAWN
944
945#endif // ndef for wxUSE_LISTBOX