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