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" 
  17 #include "wx/listbox.h" 
  18 #include "wx/button.h" 
  19 #include "wx/settings.h" 
  20 #include "wx/toplevel.h" 
  21 #include "wx/dynarray.h" 
  26 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
) 
  28 BEGIN_EVENT_TABLE(wxListBox
, wxControl
) 
  29     EVT_SIZE( wxListBox::OnSize 
) 
  30     EVT_CHAR( wxListBox::OnChar 
) 
  33 #include "wx/mac/uma.h" 
  35 #if PRAGMA_STRUCT_ALIGN 
  36     #pragma options align=mac68k 
  37 #elif PRAGMA_STRUCT_PACKPUSH 
  39 #elif PRAGMA_STRUCT_PACK 
  44     unsigned short instruction
; 
  46 } ldefRec
, *ldefPtr
, **ldefHandle
; 
  48 #if PRAGMA_STRUCT_ALIGN 
  49     #pragma options align=reset 
  50 #elif PRAGMA_STRUCT_PACKPUSH 
  52 #elif PRAGMA_STRUCT_PACK 
  57 const short kwxMacListItemHeight 
= 19 ; 
  59 const short kwxMacListItemHeight 
= 14 ; 
  64 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect 
*drawRect
, 
  65                                      Cell cell
, short dataOffset
, short dataLength
, 
  66                                      ListHandle listHandle 
) ; 
  69 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect 
*drawRect
, 
  70                                      Cell cell
, short dataOffset
, short dataLength
, 
  71                                      ListHandle listHandle 
) 
  74     list 
= (wxListBox
*) GetControlReference( (ControlHandle
) GetListRefCon(listHandle
) ); 
  80     RgnHandle savedClipRegion
; 
  83     SetPort((**listHandle
).port
); 
  84     grafPtr 
= (**listHandle
).port 
; 
  85     // typecast our refCon 
  87     //  Calculate the cell rect. 
  98             const wxString linetext 
= list
->m_stringArray
[cell
.v
] ; 
 100             //  Save the current clip region, and set the clip region to the area we are about 
 103             savedClipRegion 
= NewRgn(); 
 104             GetClip( savedClipRegion 
); 
 106             ClipRect( drawRect 
); 
 107             EraseRect( drawRect 
); 
 109             const wxFont
& font 
= list
->GetFont(); 
 112                 ::TextFont( font
.GetMacFontNum() ) ; 
 113                 ::TextSize( font
.GetMacFontSize() ) ; 
 114                 ::TextFace( font
.GetMacFontStyle() ) ; 
 118                 ::TextFont( kFontIDMonaco 
) ; 
 125                 Rect frame 
= { drawRect
->top
, drawRect
->left 
+ 4, 
 126                                drawRect
->top 
+ kwxMacListItemHeight
, drawRect
->right 
+ 10000 } ; 
 127                 CFMutableStringRef mString 
= CFStringCreateMutableCopy( NULL 
, 0 , wxMacCFStringHolder(linetext 
, list
->GetFont().GetEncoding()) ) ; 
 128                 ::TruncateThemeText( mString 
, kThemeCurrentPortFont
, kThemeStateActive
, drawRect
->right 
- drawRect
->left 
, truncEnd 
, NULL 
) ; 
 129                 ::DrawThemeTextBox( mString
, 
 130                                     kThemeCurrentPortFont
, 
 136                                     CFRelease( mString 
) ; 
 140                 wxCharBuffer text 
= linetext
.mb_str( wxConvLocal
) ; 
 141                 MoveTo(drawRect
->left 
+ 4 , drawRect
->top 
+ 10 ); 
 142                 DrawText(text
, 0 , strlen(text
) ); 
 145             //  If the cell is hilited, do the hilite now. Paint the cell contents with the 
 146             //  appropriate QuickDraw transform mode. 
 149                 savedPenMode 
= GetPortPenMode( (CGrafPtr
) grafPtr 
); 
 150                 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode 
); 
 151                 PaintRect( drawRect 
); 
 152                 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode 
); 
 155             //  Restore the saved clip region. 
 157             SetClip( savedClipRegion 
); 
 158             DisposeRgn( savedClipRegion 
); 
 163         //  Hilite or unhilite the cell. Paint the cell contents with the 
 164         //  appropriate QuickDraw transform mode. 
 167         savedPenMode 
= GetPortPenMode( (CGrafPtr
)grafPtr 
); 
 168         SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode 
); 
 169         PaintRect( drawRect 
); 
 170         SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode 
); 
 178 extern "C" void MacDrawStringCell(Rect 
*cellRect
, Cell lCell
, ListHandle theList
, long refCon
) ; 
 179 // resources ldef ids 
 180 const short kwxMacListWithVerticalScrollbar 
= 128 ; 
 181 const short kwxMacListWithVerticalAndHorizontalScrollbar 
= 129 ; 
 183 // ============================================================================ 
 184 // list box control implementation 
 185 // ============================================================================ 
 188 wxListBox::wxListBox() 
 195 static ListDefUPP macListDefUPP 
= NULL 
; 
 197 bool wxListBox::Create(wxWindow 
*parent
, wxWindowID id
, 
 200                        const wxArrayString
& choices
, 
 202                        const wxValidator
& validator
, 
 203                        const wxString
& name
) 
 205     wxCArrayString 
chs(choices
); 
 207     return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(), 
 208                   style
, validator
, name
); 
 211 bool wxListBox::Create(wxWindow 
*parent
, wxWindowID id
, 
 214                        int n
, const wxString choices
[], 
 216                        const wxValidator
& validator
, 
 217                        const wxString
& name
) 
 219     if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style 
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) ) 
 222     m_noItems 
= 0 ; // this will be increased by our append command 
 228     MacPreControlCreate( parent 
, id 
,  wxEmptyString 
, pos 
, size 
,style
, validator 
, name 
, &bounds 
, title 
) ; 
 231     listDef
.defType 
= kListDefUserProcType
; 
 232     if ( macListDefUPP 
== NULL 
) 
 234         macListDefUPP 
= NewListDefUPP( wxMacListDefinition 
); 
 236     listDef
.u
.userProc 
= macListDefUPP 
; 
 242     GetThemeFont(kThemeViewsFont 
, GetApplicationScript() , fontName 
, &fontSize 
, &fontStyle 
) ; 
 244     GetFontName( kFontIDMonaco 
, fontName 
) ; 
 248     SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL 
, false , wxMacMakeStringFromPascal( fontName 
) ) ) ; 
 253     CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, (style 
& wxLB_HSCROLL
), true, 
 254                           kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef 
*)&m_macControl 
); 
 256     GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
, 
 257                    sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
); 
 259     SetControlReference( (ControlHandle
) m_macControl
, (long) this); 
 260     SetControlVisibility( (ControlHandle
) m_macControl
, false, false); 
 265     wxStAppResource resload 
; 
 266     m_macControl 
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds 
, title 
, false , 
 267                   (style 
& wxLB_HSCROLL
) ? kwxMacListWithVerticalAndHorizontalScrollbar 
: kwxMacListWithVerticalScrollbar 
, 
 268                   0 , 0, kControlListBoxProc 
, (long) this ) ; 
 269     ::GetControlData( (ControlHandle
) m_macControl 
, kControlNoPart 
, kControlListBoxListHandleTag 
, 
 270                sizeof( ListHandle 
) , (char*) &m_macList  
, &result 
) ; 
 272     HLock( (Handle
) m_macList 
) ; 
 274     ldef 
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ; 
 275     if (  (**(ListHandle
)m_macList
).listDefProc 
!= NULL 
) 
 277       (**ldef
).instruction 
= 0x4EF9;  /* JMP instruction */ 
 278       (**ldef
).function 
= (void(*)()) listDef
.u
.userProc
; 
 279       (**(ListHandle
)m_macList
).listDefProc 
= (Handle
) ldef 
; 
 282     Point pt 
= (**(ListHandle
)m_macList
).cellSize 
; 
 283     pt
.v 
= kwxMacListItemHeight 
; 
 284     LCellSize( pt 
, (ListHandle
)m_macList 
) ; 
 285     LAddColumn( 1 , 0 , (ListHandle
)m_macList 
) ; 
 287     OptionBits  options 
= 0; 
 288     if ( style 
& wxLB_MULTIPLE 
) 
 290         options 
+= lExtendDrag 
+ lUseSense  
; 
 292     else if ( style 
& wxLB_EXTENDED 
) 
 298         options 
= (OptionBits
) lOnlyOne 
; 
 300     SetListSelectionFlags((ListHandle
)m_macList
, options
); 
 302     for ( int i 
= 0 ; i 
< n 
; i
++ ) 
 304         Append( choices
[i
] ) ; 
 307     MacPostControlCreate() ; 
 309     LSetDrawingMode( true , (ListHandle
)m_macList 
) ; 
 314 wxListBox::~wxListBox() 
 317     // avoid access during destruction 
 318     SetControlReference( (ControlHandle
) m_macControl 
, NULL 
) ; 
 322         DisposeHandle( (**(ListHandle
)m_macList
).listDefProc 
) ; 
 323         (**(ListHandle
)m_macList
).listDefProc 
= NULL 
; 
 329 void wxListBox::FreeData() 
 331 #if wxUSE_OWNER_DRAWN 
 332     if ( m_windowStyle 
& wxLB_OWNERDRAW 
) 
 334         size_t uiCount 
= m_aItems
.Count(); 
 335         while ( uiCount
-- != 0 ) { 
 336             delete m_aItems
[uiCount
]; 
 337             m_aItems
[uiCount
] = NULL
; 
 343 #endif // wxUSE_OWNER_DRAWN 
 344     if ( HasClientObjectData() ) 
 346         for ( unsigned int n 
= 0; n 
< m_noItems
; n
++ ) 
 348             delete GetClientObject(n
); 
 353 void  wxListBox::DoSetSize(int x
, int y
, 
 354             int width
, int height
, 
 357     wxControl::DoSetSize( x 
, y 
, width 
, height 
, sizeFlags 
) ; 
 360     GetControlBounds( (ControlHandle
) m_macControl 
, &bounds 
) ; 
 361     ControlRef control 
= GetListVerticalScrollBar( (ListHandle
)m_macList 
) ; 
 365         GetControlBounds( control 
, &scrollbounds 
) ; 
 366         if( scrollbounds
.right 
!= bounds
.right 
+ 1 ) 
 368             UMAMoveControl( control 
, bounds
.right 
- (scrollbounds
.right 
- scrollbounds
.left
) + 1 , 
 374 void wxListBox::DoSetFirstItem(int N
) 
 379 void wxListBox::Delete(unsigned int n
) 
 381     wxCHECK_RET( IsValid(n
), 
 382                  wxT("invalid index in wxListBox::Delete") ); 
 384 #if wxUSE_OWNER_DRAWN 
 386     m_aItems
.RemoveAt(n
); 
 387 #else // !wxUSE_OWNER_DRAWN 
 388     if ( HasClientObjectData() ) 
 390         delete GetClientObject(n
); 
 392 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN 
 393     m_stringArray
.RemoveAt(n
) ; 
 394     m_dataArray
.RemoveAt(n
) ; 
 400 int wxListBox::DoAppend(const wxString
& item
) 
 402     InvalidateBestSize(); 
 404     unsigned int index 
= m_noItems 
; 
 405     m_stringArray
.Add( item 
) ; 
 406     m_dataArray
.Add( NULL 
); 
 408     DoSetItemClientData( index 
, NULL 
) ; 
 414 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
) 
 416     MacSetRedraw( false ) ; 
 418     int n 
= choices
.GetCount(); 
 420     for( int i 
= 0 ; i 
< n 
; ++i 
) 
 424 #if wxUSE_OWNER_DRAWN 
 425             wxASSERT_MSG(clientData
[i
] == NULL
, 
 426                 wxT("Can't use client data with owner-drawn listboxes")); 
 427 #else // !wxUSE_OWNER_DRAWN 
 428             Append( choices
[i
] , clientData
[i
] ) ; 
 432             Append( choices
[i
] ) ; 
 435 #if wxUSE_OWNER_DRAWN 
 436     if ( m_windowStyle 
& wxLB_OWNERDRAW 
) { 
 437         // first delete old items 
 438         unsigned int ui 
= m_aItems
.Count(); 
 439         while ( ui
-- != 0 ) { 
 445         // then create new ones 
 446         for ( ui 
= 0; ui 
< m_noItems
; ui
++ ) { 
 447             wxOwnerDrawn 
*pNewItem 
= CreateItem(ui
); 
 448             pNewItem
->SetName(choices
[ui
]); 
 449             m_aItems
.Add(pNewItem
); 
 452 #endif // wxUSE_OWNER_DRAWN 
 453     MacSetRedraw( true ) ; 
 456 bool wxListBox::HasMultipleSelection() const 
 458     return (m_windowStyle 
& wxLB_MULTIPLE
) || (m_windowStyle 
& wxLB_EXTENDED
); 
 461 int wxListBox::FindString(const wxString
& s
, bool bCase
) const 
 463     if ( s
.Right(1) == wxT("*") ) 
 465         wxString search 
= s
.Left( s
.length() - 1 ) ; 
 466         int len 
= search
.length() ; 
 468         wxMacStringToPascal( search 
, s2 
) ; 
 470         for ( unsigned int i 
= 0 ; i 
< m_noItems 
; ++ i 
) 
 472             wxMacStringToPascal( m_stringArray
[i
].Left( len 
) , s1 
) ; 
 474             if ( EqualString( s1 
, s2 
, bCase 
, false ) ) 
 477         if ( s
.Left(1) == wxT("*") && s
.length() > 1 ) 
 481             for ( unsigned int i 
= 0 ; i 
< m_noItems 
; ++i 
) 
 483                 if (GetString(i
).Lower().Matches(st
)) 
 493         wxMacStringToPascal( s 
, s2 
) ; 
 495         for ( unsigned int i 
= 0 ; i 
< m_noItems 
; ++ i 
) 
 497             wxMacStringToPascal( m_stringArray
[i
] , s1 
) ; 
 499             if ( EqualString( s1 
, s2 
, bCase 
, false ) ) 
 507 void wxListBox::Clear() 
 511     m_stringArray
.Empty() ; 
 512     m_dataArray
.Empty() ; 
 516 void wxListBox::DoSetSelection(int N
, bool select
) 
 518     wxCHECK_RET( IsValid(N
), 
 519         wxT("invalid index in wxListBox::SetSelection") ); 
 520     MacSetSelection( N 
, select 
) ; 
 521     GetSelections( m_selectionPreImage 
) ; 
 524 bool wxListBox::IsSelected(int N
) const 
 526     wxCHECK_MSG( IsValid(N
), false, 
 527         wxT("invalid index in wxListBox::Selected") ); 
 529     return MacIsSelected( N 
) ; 
 532 void *wxListBox::DoGetItemClientData(unsigned int n
) const 
 534     wxCHECK_MSG( IsValid(n
), NULL
, 
 535         wxT("invalid index in wxListBox::GetClientData")); 
 537     return (void *)m_dataArray
[n
]; 
 540 wxClientData 
*wxListBox::DoGetItemClientObject(unsigned int n
) const 
 542     return (wxClientData 
*) DoGetItemClientData( n 
) ; 
 545 void wxListBox::DoSetItemClientData(unsigned int n
, void *Client_data
) 
 547     wxCHECK_RET( IsValid(n
), 
 548         wxT("invalid index in wxListBox::SetClientData") ); 
 550 #if wxUSE_OWNER_DRAWN 
 551     if ( m_windowStyle 
& wxLB_OWNERDRAW 
) 
 553         // client data must be pointer to wxOwnerDrawn, otherwise we would crash 
 554         // in OnMeasure/OnDraw. 
 555         wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes")); 
 557 #endif // wxUSE_OWNER_DRAWN 
 558     wxASSERT_MSG( m_dataArray
.GetCount() >= (unsigned int) n 
, wxT("invalid client_data array") ) ; 
 560     if ( m_dataArray
.GetCount() > (size_t) n 
) 
 562         m_dataArray
[n
] = (char*) Client_data 
; 
 566         m_dataArray
.Add( (char*) Client_data 
) ; 
 570 void wxListBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
) 
 572     DoSetItemClientData(n
, clientData
); 
 575 // Return number of selections and an array of selected integers 
 576 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const 
 578     return MacGetSelections( aSelections 
) ; 
 581 // Get single selection, for single choice list items 
 582 int wxListBox::GetSelection() const 
 584     return MacGetSelection() ; 
 587 // Find string for position 
 588 wxString 
wxListBox::GetString(unsigned int n
) const 
 590     return m_stringArray
[n
]  ; 
 593 void wxListBox::DoInsertItems(const wxArrayString
& items
, unsigned int pos
) 
 595     wxCHECK_RET( IsValidInsert(pos
), 
 596         wxT("invalid index in wxListBox::InsertItems") ); 
 598     InvalidateBestSize(); 
 600     unsigned int nItems 
= items
.GetCount(); 
 602     for ( unsigned int i 
= 0 ; i 
< nItems 
; i
++ ) 
 604         m_stringArray
.Insert( items
[i
] , pos 
+ i 
) ; 
 605         m_dataArray
.Insert( NULL 
, pos 
+ i 
) ; 
 606         MacInsert( pos 
+ i 
, items
[i
] ) ; 
 612 void wxListBox::SetString(unsigned int n
, const wxString
& s
) 
 614     m_stringArray
[n
] = s
; 
 618 wxSize 
wxListBox::DoGetBestSize() const 
 620     int lbWidth 
= 100;  // some defaults 
 625         wxMacPortStateHelper 
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ; 
 629             ::TextFont( m_font
.GetMacFontNum() ) ; 
 630             ::TextSize( m_font
.GetMacFontSize() ) ; 
 631             ::TextFace( m_font
.GetMacFontStyle() ) ; 
 635             ::TextFont( kFontIDMonaco 
) ; 
 640         // Find the widest line 
 641         for(unsigned int i 
= 0; i 
< GetCount(); i
++) { 
 642             wxString 
str(GetString(i
)); 
 646             ::GetThemeTextDimensions( wxMacCFStringHolder( str 
, m_font
.GetEncoding() ) , 
 647                 kThemeCurrentPortFont
, 
 654             wLine 
= ::TextWidth( str
.c_str() , 0 , str
.length() ) ; 
 656             lbWidth 
= wxMax(lbWidth
, wLine
); 
 659         // Add room for the scrollbar 
 660         lbWidth 
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
); 
 662         // And just a bit more 
 664         int cx 
= ::TextWidth( "X" , 0 , 1 ) ; 
 667         // don't make the listbox too tall (limit height to around 10 items) but don't 
 668         // make it too small neither 
 669         lbHeight 
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10); 
 671     return wxSize(lbWidth
, lbHeight
); 
 674 unsigned int wxListBox::GetCount() const 
 679 void wxListBox::SetupColours() 
 681     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
)); 
 682     SetForegroundColour(GetParent()->GetForegroundColour()); 
 685 void wxListBox::Refresh(bool eraseBack
, const wxRect 
*rect
) 
 687     wxControl::Refresh( eraseBack 
, rect 
) ; 
 688     //    MacRedrawControl() ; 
 691 #if wxUSE_OWNER_DRAWN 
 693 class wxListBoxItem 
: public wxOwnerDrawn
 
 696     wxListBoxItem(const wxString
& str 
= wxEmptyString
); 
 699 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, false) 
 701     // no bitmaps/checkmarks 
 705 wxOwnerDrawn 
*wxListBox::CreateItem(size_t n
) 
 707     return new wxListBoxItem(); 
 710 #endif  //USE_OWNER_DRAWN 
 712 // ============================================================================ 
 713 // list box control implementation 
 714 // ============================================================================ 
 717 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) 
 720 // typecast our refCon 
 721 list = (wxListBox*)refCon; 
 723   MoveTo(cellRect->left + 4 , cellRect->top + 10 ); 
 724   const wxString text = list->m_stringArray[lCell.v] ; 
 725   ::TextFont( kFontIDMonaco ) ; 
 728   DrawText(text, 0 , text.length()); 
 732 void wxListBox::MacDelete( int N 
) 
 734     LDelRow( 1 , N 
, (ListHandle
)m_macList
) ; 
 738 void wxListBox::MacInsert( int n 
, const wxString
& text
) 
 740     Cell cell 
= { 0 , 0 } ; 
 742     LAddRow( 1 , cell
.v 
, (ListHandle
)m_macList 
) ; 
 743     //    LSetCell(text, strlen(text), cell, m_macList); 
 747 void wxListBox::MacAppend( const wxString
& text
) 
 749     Cell cell 
= { 0 , 0 } ; 
 750     cell
.v 
= (**(ListHandle
)m_macList
).dataBounds
.bottom 
; 
 751     LAddRow( 1 , cell
.v 
, (ListHandle
)m_macList 
) ; 
 752     //   LSetCell(text, strlen(text), cell, m_macList); 
 756 void wxListBox::MacClear() 
 758     LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom 
, 0 ,(ListHandle
) m_macList 
) ; 
 762 void wxListBox::MacSetSelection( int n 
, bool select 
) 
 764     Cell cell 
= { 0 , 0 } ; 
 765     if ( ! (m_windowStyle 
& wxLB_MULTIPLE
) ) 
 767         if ( LGetSelect( true , &cell 
, (ListHandle
)m_macList 
) ) 
 769             LSetSelect( false , cell 
, (ListHandle
)m_macList 
) ; 
 774     LSetSelect( select 
, cell 
, (ListHandle
)m_macList 
) ; 
 775     LAutoScroll( (ListHandle
)m_macList 
) ; 
 779 bool wxListBox::MacIsSelected( int n 
) const 
 781     Cell cell 
= { 0 , 0 } ; 
 783     return LGetSelect( false , &cell 
, (ListHandle
)m_macList 
) ; 
 786 void wxListBox::MacDestroy() 
 788     //    DisposeExtLDEFInfo( m_macList ) ; 
 791 int wxListBox::MacGetSelection() const 
 793     Cell cell 
= { 0 , 0 } ; 
 794     if ( LGetSelect( true , &cell 
, (ListHandle
)m_macList 
) ) 
 800 int wxListBox::MacGetSelections( wxArrayInt
& aSelections 
) const 
 806     Cell cell 
= { 0 , 0 } ; 
 809     while ( LGetSelect( true , &cell 
,(ListHandle
) m_macList 
) ) 
 811         aSelections
.Add( cell
.v 
) ; 
 818 void wxListBox::MacSet( int n 
, const wxString
& text 
) 
 820     // our implementation does not store anything in the list 
 821     // so we just have to redraw 
 822     Cell cell 
= { 0 , 0 } ; 
 824     //  LSetCell(text, strlen(text), cell, m_macList); 
 828 void wxListBox::MacScrollTo( int n 
) 
 830     // TODO implement scrolling 
 833 void wxListBox::OnSize( wxSizeEvent 
&event
) 
 838     GetListCellSize((ListHandle
)m_macList
, &pt
); 
 840     pt 
= (**(ListHandle
)m_macList
).cellSize 
; 
 842     pt
.h 
=  m_width 
- 15  ; 
 843     LCellSize( pt 
, (ListHandle
)m_macList 
) ; 
 846 void wxListBox::MacHandleControlClick( WXWidget control 
, wxInt16 controlpart 
, bool WXUNUSED(mouseStillDown
)) 
 848     Boolean wasDoubleClick 
= false ; 
 851     ::GetControlData( (ControlHandle
) m_macControl 
, kControlNoPart 
, kControlListBoxDoubleClickTag 
, sizeof( wasDoubleClick 
) , (char*) &wasDoubleClick  
, &result 
) ; 
 852     if ( !wasDoubleClick 
) 
 862 void wxListBox::MacSetRedraw( bool doDraw 
) 
 864     LSetDrawingMode( doDraw 
, (ListHandle
)m_macList 
) ; 
 867 void wxListBox::MacDoClick() 
 869     wxArrayInt aSelections
; 
 871     size_t count 
= GetSelections(aSelections
); 
 873     if ( count 
== m_selectionPreImage
.GetCount() ) 
 875         bool hasChanged 
= false ; 
 876         for ( size_t i 
= 0 ; i 
< count 
; ++i 
) 
 878             if ( aSelections
[i
] != m_selectionPreImage
[i
] ) 
 890     m_selectionPreImage 
= aSelections
; 
 892     wxCommandEvent 
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
); 
 893     event
.SetEventObject( this ); 
 898         if ( HasClientObjectData() ) 
 899             event
.SetClientObject( GetClientObject(n
) ); 
 900         else if ( HasClientUntypedData() ) 
 901             event
.SetClientData( GetClientData(n
) ); 
 902         event
.SetString(GetString(n
)); 
 911     GetEventHandler()->ProcessEvent(event
); 
 914 void wxListBox::MacDoDoubleClick() 
 916     wxCommandEvent 
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
); 
 917     event
.SetEventObject( this ); 
 918     GetEventHandler()->ProcessEvent(event
) ; 
 921 void wxListBox::OnChar(wxKeyEvent
& event
) 
 923     if ( event
.GetKeyCode() == WXK_RETURN 
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
) 
 925         wxWindow
* parent 
= GetParent() ; 
 926         while( parent  
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL 
) 
 927             parent 
= parent
->GetParent() ; 
 929         if ( parent 
&& parent
->GetDefaultItem() ) 
 931             wxButton 
*def 
= wxDynamicCast(parent
->GetDefaultItem(), 
 933             if ( def 
&& def
->IsEnabled() ) 
 935                 wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() ); 
 936                 event
.SetEventObject(def
); 
 943     /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */ 
 944     else if (event
.GetKeyCode() == WXK_ESCAPE 
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) ) 
 946         // FIXME: look in ancestors, not just parent. 
 947         wxWindow
* win 
= GetParent()->FindWindow( wxID_CANCEL 
) ; 
 950             wxCommandEvent 
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
); 
 951             new_event
.SetEventObject( win 
); 
 952             win
->GetEventHandler()->ProcessEvent( new_event 
); 
 955     else if ( event
.GetKeyCode() == WXK_TAB 
) 
 957         wxNavigationKeyEvent new_event
; 
 958         new_event
.SetEventObject( this ); 
 959         new_event
.SetDirection( !event
.ShiftDown() ); 
 960         /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ 
 961         new_event
.SetWindowChange( event
.ControlDown() ); 
 962         new_event
.SetCurrentFocus( this ); 
 963         if ( !GetEventHandler()->ProcessEvent( new_event 
) ) 
 966     else if ( event
.GetKeyCode() == WXK_DOWN 
|| event
.GetKeyCode() == WXK_UP 
) 
 968         // perform the default key handling first 
 969         wxControl::OnKeyDown( event 
) ; 
 971         wxCommandEvent 
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
); 
 972         event
.SetEventObject( this ); 
 974         wxArrayInt aSelections
; 
 975         int n
, count 
= GetSelections(aSelections
); 
 979             if ( HasClientObjectData() ) 
 980                 event
.SetClientObject( GetClientObject(n
) ); 
 981             else if ( HasClientUntypedData() ) 
 982                 event
.SetClientData( GetClientData(n
) ); 
 983             event
.SetString(GetString(n
)); 
 992         GetEventHandler()->ProcessEvent(event
); 
 996         if ( event
.GetTimestamp() > m_lastTypeIn 
+ 60 ) 
 998             m_typeIn 
= wxEmptyString 
; 
1000         m_lastTypeIn 
= event
.GetTimestamp() ; 
1001         m_typeIn 
+= (char) event
.GetKeyCode() ; 
1002         int line 
= FindString(wxT("*")+m_typeIn
+wxT("*")) ; 
1005             if ( GetSelection() != line 
) 
1007                 SetSelection(line
) ; 
1008                 wxCommandEvent 
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
); 
1009                 event
.SetEventObject( this ); 
1011                 if ( HasClientObjectData() ) 
1012                     event
.SetClientObject( GetClientObject( line 
) ); 
1013                 else if ( HasClientUntypedData() ) 
1014                     event
.SetClientData( GetClientData(line
) ); 
1015                 event
.SetString(GetString(line
)); 
1019                 GetEventHandler()->ProcessEvent(event
); 
1025 #endif // wxUSE_LISTBOX