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