1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/classic/listbox.cpp 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  16 #include "wx/listbox.h" 
  19     #include "wx/dynarray.h" 
  23     #include "wx/button.h" 
  24     #include "wx/settings.h" 
  27 #include "wx/toplevel.h" 
  29 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
) 
  31 BEGIN_EVENT_TABLE(wxListBox
, wxControl
) 
  32     EVT_SIZE( wxListBox::OnSize 
) 
  33     EVT_CHAR( wxListBox::OnChar 
) 
  36 #include "wx/mac/uma.h" 
  38 #if PRAGMA_STRUCT_ALIGN 
  39     #pragma options align=mac68k 
  40 #elif PRAGMA_STRUCT_PACKPUSH 
  42 #elif PRAGMA_STRUCT_PACK 
  47     unsigned short instruction
; 
  49 } ldefRec
, *ldefPtr
, **ldefHandle
; 
  51 #if PRAGMA_STRUCT_ALIGN 
  52     #pragma options align=reset 
  53 #elif PRAGMA_STRUCT_PACKPUSH 
  55 #elif PRAGMA_STRUCT_PACK 
  60 const short kwxMacListItemHeight 
= 19 ; 
  62 const short kwxMacListItemHeight 
= 14 ; 
  67 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect 
*drawRect
, 
  68                                      Cell cell
, short dataOffset
, short dataLength
, 
  69                                      ListHandle listHandle 
) ; 
  72 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect 
*drawRect
, 
  73                                      Cell cell
, short dataOffset
, short dataLength
, 
  74                                      ListHandle listHandle 
) 
  77     list 
= (wxListBox
*) GetControlReference( (ControlHandle
) GetListRefCon(listHandle
) ); 
  83     RgnHandle savedClipRegion
; 
  86     SetPort((**listHandle
).port
); 
  87     grafPtr 
= (**listHandle
).port 
; 
  88     // typecast our refCon 
  90     //  Calculate the cell rect. 
 101             const wxString linetext 
= list
->m_stringArray
[cell
.v
] ; 
 103             //  Save the current clip region, and set the clip region to the area we are about 
 106             savedClipRegion 
= NewRgn(); 
 107             GetClip( savedClipRegion 
); 
 109             ClipRect( drawRect 
); 
 110             EraseRect( drawRect 
); 
 112             const wxFont
& font 
= list
->GetFont(); 
 115                 ::TextFont( font
.GetMacFontNum() ) ; 
 116                 ::TextSize( font
.GetMacFontSize() ) ; 
 117                 ::TextFace( font
.GetMacFontStyle() ) ; 
 121                 ::TextFont( kFontIDMonaco 
) ; 
 128                 Rect frame 
= { drawRect
->top
, drawRect
->left 
+ 4, 
 129                                drawRect
->top 
+ kwxMacListItemHeight
, drawRect
->right 
+ 10000 } ; 
 130                 CFMutableStringRef mString 
= CFStringCreateMutableCopy( NULL 
, 0 , wxMacCFStringHolder(linetext 
, list
->GetFont().GetEncoding()) ) ; 
 131                 ::TruncateThemeText( mString 
, kThemeCurrentPortFont
, kThemeStateActive
, drawRect
->right 
- drawRect
->left 
, truncEnd 
, NULL 
) ; 
 132                 ::DrawThemeTextBox( mString
, 
 133                                     kThemeCurrentPortFont
, 
 139                                     CFRelease( mString 
) ; 
 143                 wxCharBuffer text 
= linetext
.mb_str( wxConvLocal
) ; 
 144                 MoveTo(drawRect
->left 
+ 4 , drawRect
->top 
+ 10 ); 
 145                 DrawText(text
, 0 , strlen(text
) ); 
 148             //  If the cell is hilited, do the hilite now. Paint the cell contents with the 
 149             //  appropriate QuickDraw transform mode. 
 152                 savedPenMode 
= GetPortPenMode( (CGrafPtr
) grafPtr 
); 
 153                 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode 
); 
 154                 PaintRect( drawRect 
); 
 155                 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode 
); 
 158             //  Restore the saved clip region. 
 160             SetClip( savedClipRegion 
); 
 161             DisposeRgn( savedClipRegion 
); 
 166         //  Hilite or unhilite the cell. Paint the cell contents with the 
 167         //  appropriate QuickDraw transform mode. 
 170         savedPenMode 
= GetPortPenMode( (CGrafPtr
)grafPtr 
); 
 171         SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode 
); 
 172         PaintRect( drawRect 
); 
 173         SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode 
); 
 181 extern "C" void MacDrawStringCell(Rect 
*cellRect
, Cell lCell
, ListHandle theList
, long refCon
) ; 
 182 // resources ldef ids 
 183 const short kwxMacListWithVerticalScrollbar 
= 128 ; 
 184 const short kwxMacListWithVerticalAndHorizontalScrollbar 
= 129 ; 
 186 // ============================================================================ 
 187 // list box control implementation 
 188 // ============================================================================ 
 191 wxListBox::wxListBox() 
 198 static ListDefUPP macListDefUPP 
= NULL 
; 
 200 bool wxListBox::Create(wxWindow 
*parent
, wxWindowID id
, 
 203                        const wxArrayString
& choices
, 
 205                        const wxValidator
& validator
, 
 206                        const wxString
& name
) 
 208     wxCArrayString 
chs(choices
); 
 210     return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(), 
 211                   style
, validator
, name
); 
 214 bool wxListBox::Create(wxWindow 
*parent
, wxWindowID id
, 
 217                        int n
, const wxString choices
[], 
 219                        const wxValidator
& validator
, 
 220                        const wxString
& name
) 
 222     if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style 
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) ) 
 225     m_noItems 
= 0 ; // this will be increased by our append command 
 231     MacPreControlCreate( parent 
, id 
,  wxEmptyString 
, pos 
, size 
,style
, validator 
, name 
, &bounds 
, title 
) ; 
 234     listDef
.defType 
= kListDefUserProcType
; 
 235     if ( macListDefUPP 
== NULL 
) 
 237         macListDefUPP 
= NewListDefUPP( wxMacListDefinition 
); 
 239     listDef
.u
.userProc 
= macListDefUPP 
; 
 245     GetThemeFont(kThemeViewsFont 
, GetApplicationScript() , fontName 
, &fontSize 
, &fontStyle 
) ; 
 247     GetFontName( kFontIDMonaco 
, fontName 
) ; 
 251     SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL 
, false , wxMacMakeStringFromPascal( fontName 
) ) ) ; 
 256     CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, (style 
& wxLB_HSCROLL
), true, 
 257                           kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef 
*)&m_macControl 
); 
 259     GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
, 
 260                    sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
); 
 262     SetControlReference( (ControlHandle
) m_macControl
, (long) this); 
 263     SetControlVisibility( (ControlHandle
) m_macControl
, false, false); 
 268     wxStAppResource resload 
; 
 269     m_macControl 
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds 
, title 
, false , 
 270                   (style 
& wxLB_HSCROLL
) ? kwxMacListWithVerticalAndHorizontalScrollbar 
: kwxMacListWithVerticalScrollbar 
, 
 271                   0 , 0, kControlListBoxProc 
, (long) this ) ; 
 272     ::GetControlData( (ControlHandle
) m_macControl 
, kControlNoPart 
, kControlListBoxListHandleTag 
, 
 273                sizeof( ListHandle 
) , (char*) &m_macList  
, &result 
) ; 
 275     HLock( (Handle
) m_macList 
) ; 
 277     ldef 
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ; 
 278     if (  (**(ListHandle
)m_macList
).listDefProc 
!= NULL 
) 
 280       (**ldef
).instruction 
= 0x4EF9;  /* JMP instruction */ 
 281       (**ldef
).function 
= (void(*)()) listDef
.u
.userProc
; 
 282       (**(ListHandle
)m_macList
).listDefProc 
= (Handle
) ldef 
; 
 285     Point pt 
= (**(ListHandle
)m_macList
).cellSize 
; 
 286     pt
.v 
= kwxMacListItemHeight 
; 
 287     LCellSize( pt 
, (ListHandle
)m_macList 
) ; 
 288     LAddColumn( 1 , 0 , (ListHandle
)m_macList 
) ; 
 290     OptionBits  options 
= 0; 
 291     if ( style 
& wxLB_MULTIPLE 
) 
 293         options 
+= lExtendDrag 
+ lUseSense  
; 
 295     else if ( style 
& wxLB_EXTENDED 
) 
 301         options 
= (OptionBits
) lOnlyOne 
; 
 303     SetListSelectionFlags((ListHandle
)m_macList
, options
); 
 305     for ( int i 
= 0 ; i 
< n 
; i
++ ) 
 307         Append( choices
[i
] ) ; 
 310     MacPostControlCreate() ; 
 312     LSetDrawingMode( true , (ListHandle
)m_macList 
) ; 
 317 wxListBox::~wxListBox() 
 320     // avoid access during destruction 
 321     SetControlReference( (ControlHandle
) m_macControl 
, NULL 
) ; 
 325         DisposeHandle( (**(ListHandle
)m_macList
).listDefProc 
) ; 
 326         (**(ListHandle
)m_macList
).listDefProc 
= NULL 
; 
 332 void wxListBox::FreeData() 
 334 #if wxUSE_OWNER_DRAWN 
 335     if ( m_windowStyle 
& wxLB_OWNERDRAW 
) 
 337         size_t uiCount 
= m_aItems
.Count(); 
 338         while ( uiCount
-- != 0 ) { 
 339             delete m_aItems
[uiCount
]; 
 340             m_aItems
[uiCount
] = NULL
; 
 346 #endif // wxUSE_OWNER_DRAWN 
 347     if ( HasClientObjectData() ) 
 349         for ( unsigned int n 
= 0; n 
< m_noItems
; n
++ ) 
 351             delete GetClientObject(n
); 
 356 void  wxListBox::DoSetSize(int x
, int y
, 
 357             int width
, int height
, 
 360     wxControl::DoSetSize( x 
, y 
, width 
, height 
, sizeFlags 
) ; 
 363     GetControlBounds( (ControlHandle
) m_macControl 
, &bounds 
) ; 
 364     ControlRef control 
= GetListVerticalScrollBar( (ListHandle
)m_macList 
) ; 
 368         GetControlBounds( control 
, &scrollbounds 
) ; 
 369         if( scrollbounds
.right 
!= bounds
.right 
+ 1 ) 
 371             UMAMoveControl( control 
, bounds
.right 
- (scrollbounds
.right 
- scrollbounds
.left
) + 1 , 
 377 void wxListBox::DoSetFirstItem(int N
) 
 382 void wxListBox::Delete(unsigned int n
) 
 384     wxCHECK_RET( IsValid(n
), 
 385                  wxT("invalid index in wxListBox::Delete") ); 
 387 #if wxUSE_OWNER_DRAWN 
 389     m_aItems
.RemoveAt(n
); 
 390 #else // !wxUSE_OWNER_DRAWN 
 391     if ( HasClientObjectData() ) 
 393         delete GetClientObject(n
); 
 395 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN 
 396     m_stringArray
.RemoveAt(n
) ; 
 397     m_dataArray
.RemoveAt(n
) ; 
 403 int wxListBox::DoAppend(const wxString
& item
) 
 405     InvalidateBestSize(); 
 407     unsigned int index 
= m_noItems 
; 
 408     m_stringArray
.Add( item 
) ; 
 409     m_dataArray
.Add( NULL 
); 
 411     DoSetItemClientData( index 
, NULL 
) ; 
 417 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
) 
 419     MacSetRedraw( false ) ; 
 421     int n 
= choices
.GetCount(); 
 423     for( int i 
= 0 ; i 
< n 
; ++i 
) 
 427 #if wxUSE_OWNER_DRAWN 
 428             wxASSERT_MSG(clientData
[i
] == NULL
, 
 429                 wxT("Can't use client data with owner-drawn listboxes")); 
 430 #else // !wxUSE_OWNER_DRAWN 
 431             Append( choices
[i
] , clientData
[i
] ) ; 
 435             Append( choices
[i
] ) ; 
 438 #if wxUSE_OWNER_DRAWN 
 439     if ( m_windowStyle 
& wxLB_OWNERDRAW 
) { 
 440         // first delete old items 
 441         unsigned int ui 
= m_aItems
.Count(); 
 442         while ( ui
-- != 0 ) { 
 448         // then create new ones 
 449         for ( ui 
= 0; ui 
< m_noItems
; ui
++ ) { 
 450             wxOwnerDrawn 
*pNewItem 
= CreateItem(ui
); 
 451             pNewItem
->SetName(choices
[ui
]); 
 452             m_aItems
.Add(pNewItem
); 
 455 #endif // wxUSE_OWNER_DRAWN 
 456     MacSetRedraw( true ) ; 
 459 bool wxListBox::HasMultipleSelection() const 
 461     return (m_windowStyle 
& wxLB_MULTIPLE
) || (m_windowStyle 
& wxLB_EXTENDED
); 
 464 int wxListBox::FindString(const wxString
& s
, bool bCase
) const 
 466     if ( s
.Right(1) == wxT("*") ) 
 468         wxString search 
= s
.Left( s
.length() - 1 ) ; 
 469         int len 
= search
.length() ; 
 471         wxMacStringToPascal( search 
, s2 
) ; 
 473         for ( unsigned int i 
= 0 ; i 
< m_noItems 
; ++ i 
) 
 475             wxMacStringToPascal( m_stringArray
[i
].Left( len 
) , s1 
) ; 
 477             if ( EqualString( s1 
, s2 
, bCase 
, false ) ) 
 480         if ( s
.Left(1) == wxT("*") && s
.length() > 1 ) 
 484             for ( unsigned int i 
= 0 ; i 
< m_noItems 
; ++i 
) 
 486                 if (GetString(i
).Lower().Matches(st
)) 
 496         wxMacStringToPascal( s 
, s2 
) ; 
 498         for ( unsigned int i 
= 0 ; i 
< m_noItems 
; ++ i 
) 
 500             wxMacStringToPascal( m_stringArray
[i
] , s1 
) ; 
 502             if ( EqualString( s1 
, s2 
, bCase 
, false ) ) 
 510 void wxListBox::Clear() 
 514     m_stringArray
.Empty() ; 
 515     m_dataArray
.Empty() ; 
 519 void wxListBox::DoSetSelection(int N
, bool select
) 
 521     wxCHECK_RET( IsValid(N
), 
 522         wxT("invalid index in wxListBox::SetSelection") ); 
 523     MacSetSelection( N 
, select 
) ; 
 524     GetSelections( m_selectionPreImage 
) ; 
 527 bool wxListBox::IsSelected(int N
) const 
 529     wxCHECK_MSG( IsValid(N
), false, 
 530         wxT("invalid index in wxListBox::Selected") ); 
 532     return MacIsSelected( N 
) ; 
 535 void *wxListBox::DoGetItemClientData(unsigned int n
) const 
 537     wxCHECK_MSG( IsValid(n
), NULL
, 
 538         wxT("invalid index in wxListBox::GetClientData")); 
 540     return (void *)m_dataArray
[n
]; 
 543 wxClientData 
*wxListBox::DoGetItemClientObject(unsigned int n
) const 
 545     return (wxClientData 
*) DoGetItemClientData( n 
) ; 
 548 void wxListBox::DoSetItemClientData(unsigned int n
, void *Client_data
) 
 550     wxCHECK_RET( IsValid(n
), 
 551         wxT("invalid index in wxListBox::SetClientData") ); 
 553 #if wxUSE_OWNER_DRAWN 
 554     if ( m_windowStyle 
& wxLB_OWNERDRAW 
) 
 556         // client data must be pointer to wxOwnerDrawn, otherwise we would crash 
 557         // in OnMeasure/OnDraw. 
 558         wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes")); 
 560 #endif // wxUSE_OWNER_DRAWN 
 561     wxASSERT_MSG( m_dataArray
.GetCount() >= (unsigned int) n 
, wxT("invalid client_data array") ) ; 
 563     if ( m_dataArray
.GetCount() > (size_t) n 
) 
 565         m_dataArray
[n
] = (char*) Client_data 
; 
 569         m_dataArray
.Add( (char*) Client_data 
) ; 
 573 void wxListBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
) 
 575     DoSetItemClientData(n
, clientData
); 
 578 // Return number of selections and an array of selected integers 
 579 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const 
 581     return MacGetSelections( aSelections 
) ; 
 584 // Get single selection, for single choice list items 
 585 int wxListBox::GetSelection() const 
 587     return MacGetSelection() ; 
 590 // Find string for position 
 591 wxString 
wxListBox::GetString(unsigned int n
) const 
 593     return m_stringArray
[n
]  ; 
 596 void wxListBox::DoInsertItems(const wxArrayString
& items
, unsigned int pos
) 
 598     wxCHECK_RET( IsValidInsert(pos
), 
 599         wxT("invalid index in wxListBox::InsertItems") ); 
 601     InvalidateBestSize(); 
 603     unsigned int nItems 
= items
.GetCount(); 
 605     for ( unsigned int i 
= 0 ; i 
< nItems 
; i
++ ) 
 607         m_stringArray
.Insert( items
[i
] , pos 
+ i 
) ; 
 608         m_dataArray
.Insert( NULL 
, pos 
+ i 
) ; 
 609         MacInsert( pos 
+ i 
, items
[i
] ) ; 
 615 void wxListBox::SetString(unsigned int n
, const wxString
& s
) 
 617     m_stringArray
[n
] = s
; 
 621 wxSize 
wxListBox::DoGetBestSize() const 
 623     int lbWidth 
= 100;  // some defaults 
 628         wxMacPortStateHelper 
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ; 
 632             ::TextFont( m_font
.GetMacFontNum() ) ; 
 633             ::TextSize( m_font
.GetMacFontSize() ) ; 
 634             ::TextFace( m_font
.GetMacFontStyle() ) ; 
 638             ::TextFont( kFontIDMonaco 
) ; 
 643         // Find the widest line 
 644         for(unsigned int i 
= 0; i 
< GetCount(); i
++) { 
 645             wxString 
str(GetString(i
)); 
 649             ::GetThemeTextDimensions( wxMacCFStringHolder( str 
, m_font
.GetEncoding() ) , 
 650                 kThemeCurrentPortFont
, 
 657             wLine 
= ::TextWidth( str
.c_str() , 0 , str
.length() ) ; 
 659             lbWidth 
= wxMax(lbWidth
, wLine
); 
 662         // Add room for the scrollbar 
 663         lbWidth 
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
); 
 665         // And just a bit more 
 667         int cx 
= ::TextWidth( "X" , 0 , 1 ) ; 
 670         // don't make the listbox too tall (limit height to around 10 items) but don't 
 671         // make it too small neither 
 672         lbHeight 
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10); 
 674     return wxSize(lbWidth
, lbHeight
); 
 677 unsigned int wxListBox::GetCount() const 
 682 void wxListBox::SetupColours() 
 684     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
)); 
 685     SetForegroundColour(GetParent()->GetForegroundColour()); 
 688 void wxListBox::Refresh(bool eraseBack
, const wxRect 
*rect
) 
 690     wxControl::Refresh( eraseBack 
, rect 
) ; 
 691     //    MacRedrawControl() ; 
 694 #if wxUSE_OWNER_DRAWN 
 696 class wxListBoxItem 
: public wxOwnerDrawn
 
 699     wxListBoxItem(const wxString
& str 
= wxEmptyString
); 
 702 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, false) 
 704     // no bitmaps/checkmarks 
 708 wxOwnerDrawn 
*wxListBox::CreateItem(size_t n
) 
 710     return new wxListBoxItem(); 
 713 #endif  //USE_OWNER_DRAWN 
 715 // ============================================================================ 
 716 // list box control implementation 
 717 // ============================================================================ 
 720 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) 
 723 // typecast our refCon 
 724 list = (wxListBox*)refCon; 
 726   MoveTo(cellRect->left + 4 , cellRect->top + 10 ); 
 727   const wxString text = list->m_stringArray[lCell.v] ; 
 728   ::TextFont( kFontIDMonaco ) ; 
 731   DrawText(text, 0 , text.length()); 
 735 void wxListBox::MacDelete( int N 
) 
 737     LDelRow( 1 , N 
, (ListHandle
)m_macList
) ; 
 741 void wxListBox::MacInsert( int n 
, const wxString
& text
) 
 743     Cell cell 
= { 0 , 0 } ; 
 745     LAddRow( 1 , cell
.v 
, (ListHandle
)m_macList 
) ; 
 746     //    LSetCell(text, strlen(text), cell, m_macList); 
 750 void wxListBox::MacAppend( const wxString
& text
) 
 752     Cell cell 
= { 0 , 0 } ; 
 753     cell
.v 
= (**(ListHandle
)m_macList
).dataBounds
.bottom 
; 
 754     LAddRow( 1 , cell
.v 
, (ListHandle
)m_macList 
) ; 
 755     //   LSetCell(text, strlen(text), cell, m_macList); 
 759 void wxListBox::MacClear() 
 761     LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom 
, 0 ,(ListHandle
) m_macList 
) ; 
 765 void wxListBox::MacSetSelection( int n 
, bool select 
) 
 767     Cell cell 
= { 0 , 0 } ; 
 768     if ( ! (m_windowStyle 
& wxLB_MULTIPLE
) ) 
 770         if ( LGetSelect( true , &cell 
, (ListHandle
)m_macList 
) ) 
 772             LSetSelect( false , cell 
, (ListHandle
)m_macList 
) ; 
 777     LSetSelect( select 
, cell 
, (ListHandle
)m_macList 
) ; 
 778     LAutoScroll( (ListHandle
)m_macList 
) ; 
 782 bool wxListBox::MacIsSelected( int n 
) const 
 784     Cell cell 
= { 0 , 0 } ; 
 786     return LGetSelect( false , &cell 
, (ListHandle
)m_macList 
) ; 
 789 void wxListBox::MacDestroy() 
 791     //    DisposeExtLDEFInfo( m_macList ) ; 
 794 int wxListBox::MacGetSelection() const 
 796     Cell cell 
= { 0 , 0 } ; 
 797     if ( LGetSelect( true , &cell 
, (ListHandle
)m_macList 
) ) 
 803 int wxListBox::MacGetSelections( wxArrayInt
& aSelections 
) const 
 809     Cell cell 
= { 0 , 0 } ; 
 812     while ( LGetSelect( true , &cell 
,(ListHandle
) m_macList 
) ) 
 814         aSelections
.Add( cell
.v 
) ; 
 821 void wxListBox::MacSet( int n 
, const wxString
& text 
) 
 823     // our implementation does not store anything in the list 
 824     // so we just have to redraw 
 825     Cell cell 
= { 0 , 0 } ; 
 827     //  LSetCell(text, strlen(text), cell, m_macList); 
 831 void wxListBox::MacScrollTo( int n 
) 
 833     // TODO implement scrolling 
 836 void wxListBox::OnSize( wxSizeEvent 
&event
) 
 841     GetListCellSize((ListHandle
)m_macList
, &pt
); 
 843     pt 
= (**(ListHandle
)m_macList
).cellSize 
; 
 845     pt
.h 
=  m_width 
- 15  ; 
 846     LCellSize( pt 
, (ListHandle
)m_macList 
) ; 
 849 void wxListBox::MacHandleControlClick( WXWidget control 
, wxInt16 controlpart 
, bool WXUNUSED(mouseStillDown
)) 
 851     Boolean wasDoubleClick 
= false ; 
 854     ::GetControlData( (ControlHandle
) m_macControl 
, kControlNoPart 
, kControlListBoxDoubleClickTag 
, sizeof( wasDoubleClick 
) , (char*) &wasDoubleClick  
, &result 
) ; 
 855     if ( !wasDoubleClick 
) 
 865 void wxListBox::MacSetRedraw( bool doDraw 
) 
 867     LSetDrawingMode( doDraw 
, (ListHandle
)m_macList 
) ; 
 870 void wxListBox::MacDoClick() 
 872     wxArrayInt aSelections
; 
 874     size_t count 
= GetSelections(aSelections
); 
 876     if ( count 
== m_selectionPreImage
.GetCount() ) 
 878         bool hasChanged 
= false ; 
 879         for ( size_t i 
= 0 ; i 
< count 
; ++i 
) 
 881             if ( aSelections
[i
] != m_selectionPreImage
[i
] ) 
 893     m_selectionPreImage 
= aSelections
; 
 895     wxCommandEvent 
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
); 
 896     event
.SetEventObject( this ); 
 901         if ( HasClientObjectData() ) 
 902             event
.SetClientObject( GetClientObject(n
) ); 
 903         else if ( HasClientUntypedData() ) 
 904             event
.SetClientData( GetClientData(n
) ); 
 905         event
.SetString(GetString(n
)); 
 914     GetEventHandler()->ProcessEvent(event
); 
 917 void wxListBox::MacDoDoubleClick() 
 919     wxCommandEvent 
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
); 
 920     event
.SetEventObject( this ); 
 921     GetEventHandler()->ProcessEvent(event
) ; 
 924 void wxListBox::OnChar(wxKeyEvent
& event
) 
 926     if ( event
.GetKeyCode() == WXK_RETURN 
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
) 
 928         wxWindow
* parent 
= GetParent() ; 
 929         while( parent  
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL 
) 
 930             parent 
= parent
->GetParent() ; 
 932         if ( parent 
&& parent
->GetDefaultItem() ) 
 934             wxButton 
*def 
= wxDynamicCast(parent
->GetDefaultItem(), 
 936             if ( def 
&& def
->IsEnabled() ) 
 938                 wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() ); 
 939                 event
.SetEventObject(def
); 
 946     /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */ 
 947     else if (event
.GetKeyCode() == WXK_ESCAPE 
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) ) 
 949         // FIXME: look in ancestors, not just parent. 
 950         wxWindow
* win 
= GetParent()->FindWindow( wxID_CANCEL 
) ; 
 953             wxCommandEvent 
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
); 
 954             new_event
.SetEventObject( win 
); 
 955             win
->GetEventHandler()->ProcessEvent( new_event 
); 
 958     else if ( event
.GetKeyCode() == WXK_TAB 
) 
 960         wxNavigationKeyEvent new_event
; 
 961         new_event
.SetEventObject( this ); 
 962         new_event
.SetDirection( !event
.ShiftDown() ); 
 963         /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ 
 964         new_event
.SetWindowChange( event
.ControlDown() ); 
 965         new_event
.SetCurrentFocus( this ); 
 966         if ( !GetEventHandler()->ProcessEvent( new_event 
) ) 
 969     else if ( event
.GetKeyCode() == WXK_DOWN 
|| event
.GetKeyCode() == WXK_UP 
) 
 971         // perform the default key handling first 
 972         wxControl::OnKeyDown( event 
) ; 
 974         wxCommandEvent 
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
); 
 975         event
.SetEventObject( this ); 
 977         wxArrayInt aSelections
; 
 978         int n
, count 
= GetSelections(aSelections
); 
 982             if ( HasClientObjectData() ) 
 983                 event
.SetClientObject( GetClientObject(n
) ); 
 984             else if ( HasClientUntypedData() ) 
 985                 event
.SetClientData( GetClientData(n
) ); 
 986             event
.SetString(GetString(n
)); 
 995         GetEventHandler()->ProcessEvent(event
); 
 999         if ( event
.GetTimestamp() > m_lastTypeIn 
+ 60 ) 
1001             m_typeIn 
= wxEmptyString 
; 
1003         m_lastTypeIn 
= event
.GetTimestamp() ; 
1004         m_typeIn 
+= (char) event
.GetKeyCode() ; 
1005         int line 
= FindString(wxT("*")+m_typeIn
+wxT("*")) ; 
1008             if ( GetSelection() != line 
) 
1010                 SetSelection(line
) ; 
1011                 wxCommandEvent 
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
); 
1012                 event
.SetEventObject( this ); 
1014                 if ( HasClientObjectData() ) 
1015                     event
.SetClientObject( GetClientObject( line 
) ); 
1016                 else if ( HasClientUntypedData() ) 
1017                     event
.SetClientData( GetClientData(line
) ); 
1018                 event
.SetString(GetString(line
)); 
1022                 GetEventHandler()->ProcessEvent(event
); 
1028 #endif // wxUSE_LISTBOX