1 ///////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "listbox.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 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
29 BEGIN_EVENT_TABLE(wxListBox
, wxControl
)
30 #if !TARGET_API_MAC_OSX
31 EVT_SIZE( wxListBox::OnSize
)
32 EVT_CHAR( wxListBox::OnChar
)
37 #include "wx/mac/uma.h"
39 #if TARGET_API_MAC_OSX
41 // new databrowserbased version
44 wxListBox::wxListBox()
51 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
54 const wxArrayString
& choices
,
56 const wxValidator
& validator
,
59 wxCArrayString
chs(choices
);
61 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
62 style
, validator
, name
);
65 #if TARGET_API_MAC_OSX
66 static pascal void DataBrowserItemNotificationProc(ControlRef browser
, DataBrowserItemID itemID
,
67 DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
)
69 static pascal void DataBrowserItemNotificationProc(ControlRef browser
, DataBrowserItemID itemID
,
70 DataBrowserItemNotification message
)
73 long ref
= GetControlReference( browser
) ;
76 wxListBox
* list
= wxDynamicCast( ref
, wxListBox
) ;
77 for ( size_t i
= 0 ; i
< list
->m_idArray
.GetCount() ; ++i
)
78 if ( list
->m_idArray
[i
] == (long) itemID
)
80 bool trigger
= false ;
82 wxEVT_COMMAND_LISTBOX_SELECTED
, list
->GetId() );
85 case kDataBrowserItemDeselected
:
86 if ( list
->HasMultipleSelection() )
89 case kDataBrowserItemSelected
:
92 case kDataBrowserItemDoubleClicked
:
93 event
.SetEventType(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
) ;
101 event
.SetEventObject( list
);
102 if ( list
->HasClientObjectData() )
103 event
.SetClientObject( list
->GetClientObject(i
) );
104 else if ( list
->HasClientUntypedData() )
105 event
.SetClientData( list
->GetClientData(i
) );
106 event
.SetString( list
->GetString(i
) );
108 event
.SetExtraLong( list
->HasMultipleSelection() ? message
== kDataBrowserItemSelected
: TRUE
);
109 list
->GetEventHandler()->ProcessEvent(event
) ;
117 static pascal OSStatus
ListBoxGetSetItemData(ControlRef browser
,
118 DataBrowserItemID itemID
, DataBrowserPropertyID property
,
119 DataBrowserItemDataRef itemData
, Boolean changeValue
)
121 OSStatus err
= errDataBrowserPropertyNotSupported
;
130 long ref
= GetControlReference( browser
) ;
133 wxListBox
* list
= wxDynamicCast( ref
, wxListBox
) ;
134 for ( size_t i
= 0 ; i
< list
->m_idArray
.GetCount() ; ++i
)
135 if ( list
->m_idArray
[i
] == (long) itemID
)
137 wxMacCFStringHolder
cf( list
->GetString(i
) , list
->GetFont().GetEncoding() ) ;
138 verify_noerr( ::SetDataBrowserItemDataText( itemData
, cf
) ) ;
154 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
157 int n
, const wxString choices
[],
159 const wxValidator
& validator
,
160 const wxString
& name
)
162 m_macIsUserPane
= FALSE
;
164 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
165 _T("only one of listbox selection modes can be specified") );
167 if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
170 m_noItems
= 0 ; // this will be increased by our append command
175 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
178 verify_noerr( ::CreateDataBrowserControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
, kDataBrowserListView
, (ControlRef
*)&m_macControl
) );
179 browser
= (ControlRef
) m_macControl
;
181 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
182 if ( style
& wxLB_MULTIPLE
)
184 options
+= kDataBrowserAlwaysExtendSelection
+ kDataBrowserCmdTogglesSelection
;
186 else if ( style
& wxLB_EXTENDED
)
192 options
+= kDataBrowserSelectOnlyOne
;
194 verify_noerr(SetDataBrowserSelectionFlags (browser
, options
) );
196 DataBrowserListViewColumnDesc columnDesc
;
197 columnDesc
.headerBtnDesc
.titleOffset
= 0;
198 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
200 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
201 kControlUseFontMask
| kControlUseJustMask
;
203 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlNoContent
;
204 columnDesc
.propertyDesc
.propertyType
= kDataBrowserTextType
;
205 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
206 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
207 columnDesc
.headerBtnDesc
.maximumWidth
= 10000;
209 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
210 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
211 columnDesc
.headerBtnDesc
.titleString
= NULL
; // CFSTR( "" );
213 columnDesc
.propertyDesc
.propertyID
= 1024;
214 columnDesc
.propertyDesc
.propertyType
= kDataBrowserTextType
;
215 columnDesc
.propertyDesc
.propertyFlags
=
216 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
217 kDataBrowserListViewTypeSelectColumn
|
219 kDataBrowserTableViewSelectionColumn
;
222 verify_noerr(::AddDataBrowserListViewColumn(browser
, &columnDesc
, kDataBrowserListViewAppendColumn
) ) ;
223 verify_noerr(::AutoSizeDataBrowserListViewColumns( browser
) ) ;
224 verify_noerr(::SetDataBrowserHasScrollBars( browser
, false , true ) ) ;
225 verify_noerr(::SetDataBrowserTableViewHiliteStyle( browser
, kDataBrowserTableViewFillHilite
) ) ;
226 verify_noerr(::SetDataBrowserListViewHeaderBtnHeight( browser
, 0 ) ) ;
227 DataBrowserCallbacks callbacks
;
229 callbacks
.version
= kDataBrowserLatestCallbacks
;
231 InitDataBrowserCallbacks(&callbacks
);
233 callbacks
.u
.v1
.itemDataCallback
=
234 NewDataBrowserItemDataUPP(ListBoxGetSetItemData
);
236 callbacks
.u
.v1
.itemNotificationCallback
=
237 #if TARGET_API_MAC_OSX
238 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
) ;
240 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
) ;
242 SetDataBrowserCallbacks(browser
, &callbacks
);
244 MacPostControlCreate(pos
,size
) ;
246 for ( int i
= 0 ; i
< n
; i
++ )
248 Append( choices
[i
] ) ;
254 wxListBox::~wxListBox()
256 SetControlReference( (ControlRef
) m_macControl
, NULL
) ;
258 // avoid access during destruction
265 void wxListBox::FreeData()
267 #if wxUSE_OWNER_DRAWN
268 if ( m_windowStyle
& wxLB_OWNERDRAW
)
270 size_t uiCount
= m_aItems
.Count();
271 while ( uiCount
-- != 0 ) {
272 delete m_aItems
[uiCount
];
273 m_aItems
[uiCount
] = NULL
;
279 #endif // wxUSE_OWNER_DRAWN
280 if ( HasClientObjectData() )
282 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
284 delete GetClientObject(n
);
289 void wxListBox::DoSetSize(int x
, int y
,
290 int width
, int height
,
293 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
296 void wxListBox::DoSetFirstItem(int N
)
301 void wxListBox::Delete(int N
)
303 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
304 wxT("invalid index in wxListBox::Delete") );
306 #if wxUSE_OWNER_DRAWN
308 m_aItems
.RemoveAt(N
);
309 #else // !wxUSE_OWNER_DRAWN
310 if ( HasClientObjectData() )
312 delete GetClientObject(N
);
314 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
315 m_stringArray
.RemoveAt( N
) ;
316 m_dataArray
.RemoveAt( N
) ;
322 int wxListBox::DoAppend(const wxString
& item
)
324 int index
= m_noItems
;
325 m_stringArray
.Add( item
) ;
326 m_dataArray
.Add( NULL
);
328 DoSetItemClientData( index
, NULL
) ;
334 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
337 int n
= choices
.GetCount();
339 for( int i
= 0 ; i
< n
; ++i
)
343 #if wxUSE_OWNER_DRAWN
344 wxASSERT_MSG(clientData
[i
] == NULL
,
345 wxT("Can't use client data with owner-drawn listboxes"));
346 #else // !wxUSE_OWNER_DRAWN
347 Append( choices
[i
] , clientData
[i
] ) ;
351 Append( choices
[i
] ) ;
354 #if wxUSE_OWNER_DRAWN
355 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
356 // first delete old items
357 size_t ui
= m_aItems
.Count();
358 while ( ui
-- != 0 ) {
364 // then create new ones
365 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
366 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
367 pNewItem
->SetName(choices
[ui
]);
368 m_aItems
.Add(pNewItem
);
371 #endif // wxUSE_OWNER_DRAWN
374 int wxListBox::FindString(const wxString
& s
) const
377 if ( s
.Right(1) == wxT("*") )
379 wxString search
= s
.Left( s
.Length() - 1 ) ;
380 int len
= search
.Length() ;
382 wxMacStringToPascal( search
, s2
) ;
384 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
386 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
388 if ( EqualString( s1
, s2
, false , false ) )
391 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
395 for ( int i
= 0 ; i
< m_noItems
; ++i
)
397 if ( GetString(i
).Lower().Matches(st
) )
407 wxMacStringToPascal( s
, s2
) ;
409 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
411 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
413 if ( EqualString( s1
, s2
, false , false ) )
420 void wxListBox::Clear()
424 m_stringArray
.Empty() ;
425 m_dataArray
.Empty() ;
429 void wxListBox::SetSelection(int N
, bool select
)
431 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
432 wxT("invalid index in wxListBox::SetSelection") );
433 MacSetSelection( N
, select
) ;
434 GetSelections( m_selectionPreImage
) ;
437 bool wxListBox::IsSelected(int N
) const
439 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
440 wxT("invalid index in wxListBox::Selected") );
442 return MacIsSelected( N
) ;
445 void *wxListBox::DoGetItemClientData(int N
) const
447 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
448 wxT("invalid index in wxListBox::GetClientData"));
450 return (void *)m_dataArray
[N
];
453 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
455 return (wxClientData
*) DoGetItemClientData( N
) ;
458 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
460 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
461 wxT("invalid index in wxListBox::SetClientData") );
463 #if wxUSE_OWNER_DRAWN
464 if ( m_windowStyle
& wxLB_OWNERDRAW
)
466 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
467 // in OnMeasure/OnDraw.
468 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
470 #endif // wxUSE_OWNER_DRAWN
471 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
473 if ( m_dataArray
.GetCount() > (size_t) N
)
475 m_dataArray
[N
] = (char*) Client_data
;
479 m_dataArray
.Add( (char*) Client_data
) ;
483 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
485 DoSetItemClientData(n
, clientData
);
488 // Return number of selections and an array of selected integers
489 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
491 return MacGetSelections( aSelections
) ;
494 // Get single selection, for single choice list items
495 int wxListBox::GetSelection() const
497 return MacGetSelection() ;
500 // Find string for position
501 wxString
wxListBox::GetString(int N
) const
503 return m_stringArray
[N
] ;
506 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
508 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
509 wxT("invalid index in wxListBox::InsertItems") );
511 int nItems
= items
.GetCount();
513 for ( int i
= 0 ; i
< nItems
; i
++ )
515 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
516 m_dataArray
.Insert( NULL
, pos
+ i
) ;
517 MacInsert( pos
+ i
, items
[i
] ) ;
523 void wxListBox::SetString(int N
, const wxString
& s
)
525 m_stringArray
[N
] = s
;
529 wxSize
wxListBox::DoGetBestSize() const
531 int lbWidth
= 100; // some defaults
536 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetTopLevelWindowRef() ) ) ;
540 ::TextFont( m_font
.MacGetFontNum() ) ;
541 ::TextSize( m_font
.MacGetFontSize() ) ;
542 ::TextFace( m_font
.MacGetFontStyle() ) ;
546 ::TextFont( kFontIDMonaco
) ;
551 // Find the widest line
552 for(int i
= 0; i
< GetCount(); i
++) {
553 wxString
str(GetString(i
));
557 ::GetThemeTextDimensions( wxMacCFStringHolder( str
, m_font
.GetEncoding() ) ,
558 kThemeCurrentPortFont
,
565 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
567 lbWidth
= wxMax(lbWidth
, wLine
);
570 // Add room for the scrollbar
571 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
573 // And just a bit more
575 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
578 // don't make the listbox too tall (limit height to around 10 items) but don't
579 // make it too small neither
580 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
583 return wxSize(lbWidth
, lbHeight
);
586 int wxListBox::GetCount() const
591 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
593 wxControl::Refresh( eraseBack
, rect
) ;
594 // MacRedrawControl() ;
597 #if wxUSE_OWNER_DRAWN
599 class wxListBoxItem
: public wxOwnerDrawn
602 wxListBoxItem(const wxString
& str
= "");
605 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
607 // no bitmaps/checkmarks
611 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
613 return new wxListBoxItem();
616 #endif //USE_OWNER_DRAWN
618 // ============================================================================
619 // list box control implementation
620 // ============================================================================
622 void wxListBox::MacDelete( int N
)
624 UInt32 id
= m_idArray
[N
] ;
625 verify_noerr(::RemoveDataBrowserItems((ControlRef
) m_macControl
, kDataBrowserNoItem
, 1 , (UInt32
*) &id
, kDataBrowserItemNoProperty
) ) ;
626 m_idArray
.RemoveAt( N
) ;
629 void wxListBox::MacInsert( int n
, const wxString
& text
)
631 verify_noerr(::AddDataBrowserItems( (ControlRef
) m_macControl
, kDataBrowserNoItem
, 1 , (UInt32
*) &m_nextId
, kDataBrowserItemNoProperty
) ) ;
632 m_idArray
.Insert( m_nextId
, n
) ;
636 void wxListBox::MacAppend( const wxString
& text
)
638 verify_noerr(::AddDataBrowserItems( (ControlRef
) m_macControl
, kDataBrowserNoItem
, 1 , (UInt32
*) &m_nextId
, kDataBrowserItemNoProperty
) ) ;
639 m_idArray
.Add( m_nextId
) ;
643 void wxListBox::MacClear()
645 verify_noerr(::RemoveDataBrowserItems((ControlRef
) m_macControl
, kDataBrowserNoItem
, 0 , NULL
, kDataBrowserItemNoProperty
) ) ;
649 void wxListBox::MacSetSelection( int n
, bool select
)
651 UInt32 id
= m_idArray
[n
] ;
652 if ( !(GetWindowStyle() & (wxLB_MULTIPLE
|wxLB_EXTENDED
) ) )
654 int n
= MacGetSelection() ;
657 UInt32 idOld
= m_idArray
[n
] ;
658 SetDataBrowserSelectedItems((ControlRef
) m_macControl
, 1 , & idOld
, kDataBrowserItemsRemove
) ;
661 if ( ::IsDataBrowserItemSelected( (ControlRef
) m_macControl
, id
) != select
)
663 verify_noerr(::SetDataBrowserSelectedItems((ControlRef
) m_macControl
, 1 , & id
, kDataBrowserItemsToggle
) ) ;
668 bool wxListBox::MacIsSelected( int n
) const
670 return ::IsDataBrowserItemSelected( (ControlRef
) m_macControl
, m_idArray
[n
] ) ;
673 int wxListBox::MacGetSelection() const
675 for ( size_t i
= 0 ; i
< m_idArray
.GetCount() ; ++i
)
677 if ( ::IsDataBrowserItemSelected((ControlRef
) m_macControl
, m_idArray
[i
] ) )
685 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
690 for ( size_t i
= 0 ; i
< m_idArray
.GetCount() ; ++i
)
692 if ( ::IsDataBrowserItemSelected((ControlRef
) m_macControl
, m_idArray
[i
] ) )
694 aSelections
.Add( i
) ;
701 void wxListBox::MacSet( int n
, const wxString
& text
)
703 // as we don't store the strings we only have to issue a redraw
704 UInt32 id
= m_idArray
[n
] ;
705 verify_noerr( ::UpdateDataBrowserItems( (ControlRef
) m_macControl
, kDataBrowserNoItem
, 1 , &id
, kDataBrowserItemNoProperty
, kDataBrowserItemNoProperty
) ) ;
708 void wxListBox::MacScrollTo( int n
)
710 // TODO implement scrolling
713 void wxListBox::OnSize( wxSizeEvent
&event
)
717 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
720 Boolean wasDoubleClick = false ;
723 ::GetControlData( (ControlRef) m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ;
724 if ( !wasDoubleClick )
735 void wxListBox::MacSetRedraw( bool doDraw
)
737 // nothing to do in compositing mode
740 void wxListBox::MacDoClick()
742 wxArrayInt aSelections;
744 size_t count = GetSelections(aSelections);
746 if ( count == m_selectionPreImage.GetCount() )
748 bool hasChanged = false ;
749 for ( size_t i = 0 ; i < count ; ++i )
751 if ( aSelections[i] != m_selectionPreImage[i] )
763 m_selectionPreImage = aSelections;
765 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
766 event.SetEventObject( this );
771 if ( HasClientObjectData() )
772 event.SetClientObject( GetClientObject(n) );
773 else if ( HasClientUntypedData() )
774 event.SetClientData( GetClientData(n) );
775 event.SetString( GetString(n) );
782 event.m_commandInt = n;
784 GetEventHandler()->ProcessEvent(event);
788 void wxListBox::MacDoDoubleClick()
791 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
792 event.SetEventObject( this );
793 GetEventHandler()->ProcessEvent(event) ;
797 void wxListBox::OnChar(wxKeyEvent
& event
)
799 // todo trigger proper events here
803 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
805 wxWindow
* parent
= GetParent() ;
806 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
807 parent
= parent
->GetParent() ;
809 if ( parent
&& parent
->GetDefaultItem() )
811 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
813 if ( def
&& def
->IsEnabled() )
815 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
816 event
.SetEventObject(def
);
823 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
824 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
826 // FIXME: look in ancestors, not just parent.
827 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
830 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
831 new_event
.SetEventObject( win
);
832 win
->GetEventHandler()->ProcessEvent( new_event
);
835 else if ( event
.GetKeyCode() == WXK_TAB
)
837 wxNavigationKeyEvent new_event
;
838 new_event
.SetEventObject( this );
839 new_event
.SetDirection( !event
.ShiftDown() );
840 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
841 new_event
.SetWindowChange( event
.ControlDown() );
842 new_event
.SetCurrentFocus( this );
843 if ( !GetEventHandler()->ProcessEvent( new_event
) )
846 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
848 // perform the default key handling first
849 wxControl::OnKeyDown( event
) ;
851 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
852 event
.SetEventObject( this );
854 wxArrayInt aSelections
;
855 int n
, count
= GetSelections(aSelections
);
859 if ( HasClientObjectData() )
860 event
.SetClientObject( GetClientObject(n
) );
861 else if ( HasClientUntypedData() )
862 event
.SetClientData( GetClientData(n
) );
863 event
.SetString( GetString(n
) );
870 event
.m_commandInt
= n
;
872 GetEventHandler()->ProcessEvent(event
);
876 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
878 m_typeIn
= wxEmptyString
;
880 m_lastTypeIn
= event
.GetTimestamp() ;
881 m_typeIn
+= (char) event
.GetKeyCode() ;
882 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
885 if ( GetSelection() != line
)
888 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
889 event
.SetEventObject( this );
891 if ( HasClientObjectData() )
892 event
.SetClientObject( GetClientObject( line
) );
893 else if ( HasClientUntypedData() )
894 event
.SetClientData( GetClientData(line
) );
895 event
.SetString( GetString(line
) );
897 event
.m_commandInt
= line
;
899 GetEventHandler()->ProcessEvent(event
);
907 // old carbon version
909 const short kwxMacListItemHeight
= 19 ;
913 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect
*drawRect
,
914 Cell cell
, short dataOffset
, short dataLength
,
915 ListHandle listHandle
) ;
918 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect
*d
,
919 Cell cell
, short dataOffset
, short dataLength
,
920 ListHandle listHandle
)
924 Rect
* drawRect
= &r
;
926 list
= (wxListBox
*) GetControlReference( (ControlRef
) GetListRefCon(listHandle
) );
927 if ( list
== NULL
|| list
->GetHandle() == NULL
|| GetControlReference( ( ControlRef
)list
->GetHandle() ) == NULL
)
930 // the bounds passed in are not correct, adjust the right border
933 GetControlBounds( (ControlRef
) list
->GetHandle() , &bounds
) ;
934 r
.right
= r
.left
+ (bounds
.right
- bounds
.left
) - 16 ;
938 RgnHandle savedClipRegion
;
941 SetPort((**listHandle
).port
);
942 grafPtr
= (**listHandle
).port
;
943 // typecast our refCon
945 // Calculate the cell rect.
956 const wxString linetext
= list
->m_stringArray
[cell
.v
] ;
958 // Save the current clip region, and set the clip region to the area we are about
961 savedClipRegion
= NewRgn();
962 GetClip( savedClipRegion
);
964 ClipRect( drawRect
);
965 EraseRect( drawRect
);
967 const wxFont
& font
= list
->GetFont();
970 ::TextFont( font
.MacGetFontNum() ) ;
971 ::TextSize( font
.MacGetFontSize() ) ;
972 ::TextFace( font
.MacGetFontStyle() ) ;
976 ::TextFont( kFontIDMonaco
) ;
982 Rect frame
= { drawRect
->top
, drawRect
->left
+ 4,
983 drawRect
->top
+ kwxMacListItemHeight
, drawRect
->right
+ 10000 } ;
984 CFMutableStringRef mString
= CFStringCreateMutableCopy( NULL
, 0 , wxMacCFStringHolder(linetext
, list
->GetFont().GetEncoding()) ) ;
985 ::TruncateThemeText( mString
, kThemeCurrentPortFont
, kThemeStateActive
, drawRect
->right
- drawRect
->left
, truncEnd
, NULL
) ;
987 ::DrawThemeTextBox( mString
,
988 kThemeCurrentPortFont
,
995 CFRelease( mString
) ;
998 // If the cell is hilited, do the hilite now. Paint the cell contents with the
999 // appropriate QuickDraw transform mode.
1002 savedPenMode
= GetPortPenMode( (CGrafPtr
) grafPtr
);
1003 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
1004 PaintRect( drawRect
);
1005 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
1008 // Restore the saved clip region.
1010 SetClip( savedClipRegion
);
1011 DisposeRgn( savedClipRegion
);
1016 // Hilite or unhilite the cell. Paint the cell contents with the
1017 // appropriate QuickDraw transform mode.
1019 GetPort( &grafPtr
);
1020 savedPenMode
= GetPortPenMode( (CGrafPtr
)grafPtr
);
1021 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
1022 PaintRect( drawRect
);
1023 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
1031 extern "C" void MacDrawStringCell(Rect
*cellRect
, Cell lCell
, ListHandle theList
, long refCon
) ;
1032 // resources ldef ids
1033 const short kwxMacListWithVerticalScrollbar
= 128 ;
1034 const short kwxMacListWithVerticalAndHorizontalScrollbar
= 129 ;
1036 // ============================================================================
1037 // list box control implementation
1038 // ============================================================================
1041 wxListBox::wxListBox()
1048 static ListDefUPP macListDefUPP
= NULL
;
1050 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
1053 const wxArrayString
& choices
,
1055 const wxValidator
& validator
,
1056 const wxString
& name
)
1058 wxCArrayString
chs(choices
);
1060 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
1061 style
, validator
, name
);
1064 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
1067 int n
, const wxString choices
[],
1069 const wxValidator
& validator
,
1070 const wxString
& name
)
1072 m_macIsUserPane
= FALSE
;
1074 if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
1077 m_noItems
= 0 ; // this will be increased by our append command
1080 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1082 ListDefSpec listDef
;
1083 listDef
.defType
= kListDefUserProcType
;
1084 if ( macListDefUPP
== NULL
)
1086 macListDefUPP
= NewListDefUPP( wxMacListDefinition
);
1088 listDef
.u
.userProc
= macListDefUPP
;
1094 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1096 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) ) ) ;
1101 CreateListBoxControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
, false, 0, 1, (style
& wxLB_HSCROLL
), true,
1102 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
1104 GetControlData( (ControlRef
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
1105 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
1107 SetControlReference( (ControlRef
) m_macControl
, (long) this);
1110 OptionBits options
= 0;
1111 if ( style
& wxLB_MULTIPLE
)
1113 options
+= lExtendDrag
+ lUseSense
;
1115 else if ( style
& wxLB_EXTENDED
)
1117 // default behaviour
1121 options
= (OptionBits
) lOnlyOne
;
1123 SetListSelectionFlags((ListHandle
)m_macList
, options
);
1125 for ( int i
= 0 ; i
< n
; i
++ )
1127 Append( choices
[i
] ) ;
1130 MacPostControlCreate(pos
,size
) ;
1132 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
1137 wxListBox::~wxListBox()
1139 SetControlReference( (ControlRef
) m_macControl
, NULL
) ;
1141 // avoid access during destruction
1148 void wxListBox::FreeData()
1150 #if wxUSE_OWNER_DRAWN
1151 if ( m_windowStyle
& wxLB_OWNERDRAW
)
1153 size_t uiCount
= m_aItems
.Count();
1154 while ( uiCount
-- != 0 ) {
1155 delete m_aItems
[uiCount
];
1156 m_aItems
[uiCount
] = NULL
;
1162 #endif // wxUSE_OWNER_DRAWN
1163 if ( HasClientObjectData() )
1165 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
1167 delete GetClientObject(n
);
1172 void wxListBox::DoSetSize(int x
, int y
,
1173 int width
, int height
,
1176 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
1179 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1180 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
1184 GetControlBounds( control
, &scrollbounds
) ;
1185 if( scrollbounds
.right
!= bounds
.right
+ 1 )
1187 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
1188 scrollbounds
.top
) ;
1193 void wxListBox::DoSetFirstItem(int N
)
1198 void wxListBox::Delete(int N
)
1200 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
1201 wxT("invalid index in wxListBox::Delete") );
1203 #if wxUSE_OWNER_DRAWN
1205 m_aItems
.RemoveAt(N
);
1206 #else // !wxUSE_OWNER_DRAWN
1207 if ( HasClientObjectData() )
1209 delete GetClientObject(N
);
1211 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
1212 m_stringArray
.RemoveAt( N
) ;
1213 m_dataArray
.RemoveAt( N
) ;
1219 int wxListBox::DoAppend(const wxString
& item
)
1221 int index
= m_noItems
;
1222 m_stringArray
.Add( item
) ;
1223 m_dataArray
.Add( NULL
);
1225 DoSetItemClientData( index
, NULL
) ;
1231 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
1233 MacSetRedraw( false ) ;
1235 int n
= choices
.GetCount();
1237 for( int i
= 0 ; i
< n
; ++i
)
1241 #if wxUSE_OWNER_DRAWN
1242 wxASSERT_MSG(clientData
[i
] == NULL
,
1243 wxT("Can't use client data with owner-drawn listboxes"));
1244 #else // !wxUSE_OWNER_DRAWN
1245 Append( choices
[i
] , clientData
[i
] ) ;
1249 Append( choices
[i
] ) ;
1252 #if wxUSE_OWNER_DRAWN
1253 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
1254 // first delete old items
1255 size_t ui
= m_aItems
.Count();
1256 while ( ui
-- != 0 ) {
1257 delete m_aItems
[ui
];
1258 m_aItems
[ui
] = NULL
;
1262 // then create new ones
1263 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
1264 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
1265 pNewItem
->SetName(choices
[ui
]);
1266 m_aItems
.Add(pNewItem
);
1269 #endif // wxUSE_OWNER_DRAWN
1270 MacSetRedraw( true ) ;
1273 int wxListBox::FindString(const wxString
& s
) const
1276 if ( s
.Right(1) == wxT("*") )
1278 wxString search
= s
.Left( s
.Length() - 1 ) ;
1279 int len
= search
.Length() ;
1281 wxMacStringToPascal( search
, s2
) ;
1283 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
1285 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
1287 if ( EqualString( s1
, s2
, false , false ) )
1290 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
1294 for ( int i
= 0 ; i
< m_noItems
; ++i
)
1296 if ( GetString(i
).Lower().Matches(st
) )
1306 wxMacStringToPascal( s
, s2
) ;
1308 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
1310 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
1312 if ( EqualString( s1
, s2
, false , false ) )
1319 void wxListBox::Clear()
1323 m_stringArray
.Empty() ;
1324 m_dataArray
.Empty() ;
1328 void wxListBox::SetSelection(int N
, bool select
)
1330 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
1331 wxT("invalid index in wxListBox::SetSelection") );
1332 MacSetSelection( N
, select
) ;
1333 GetSelections( m_selectionPreImage
) ;
1336 bool wxListBox::IsSelected(int N
) const
1338 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
1339 wxT("invalid index in wxListBox::Selected") );
1341 return MacIsSelected( N
) ;
1344 void *wxListBox::DoGetItemClientData(int N
) const
1346 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
1347 wxT("invalid index in wxListBox::GetClientData"));
1349 return (void *)m_dataArray
[N
];
1352 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
1354 return (wxClientData
*) DoGetItemClientData( N
) ;
1357 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
1359 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
1360 wxT("invalid index in wxListBox::SetClientData") );
1362 #if wxUSE_OWNER_DRAWN
1363 if ( m_windowStyle
& wxLB_OWNERDRAW
)
1365 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
1366 // in OnMeasure/OnDraw.
1367 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
1369 #endif // wxUSE_OWNER_DRAWN
1370 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
1372 if ( m_dataArray
.GetCount() > (size_t) N
)
1374 m_dataArray
[N
] = (char*) Client_data
;
1378 m_dataArray
.Add( (char*) Client_data
) ;
1382 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
1384 DoSetItemClientData(n
, clientData
);
1387 // Return number of selections and an array of selected integers
1388 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
1390 return MacGetSelections( aSelections
) ;
1393 // Get single selection, for single choice list items
1394 int wxListBox::GetSelection() const
1396 return MacGetSelection() ;
1399 // Find string for position
1400 wxString
wxListBox::GetString(int N
) const
1402 return m_stringArray
[N
] ;
1405 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
1407 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
1408 wxT("invalid index in wxListBox::InsertItems") );
1410 int nItems
= items
.GetCount();
1412 for ( int i
= 0 ; i
< nItems
; i
++ )
1414 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
1415 m_dataArray
.Insert( NULL
, pos
+ i
) ;
1416 MacInsert( pos
+ i
, items
[i
] ) ;
1419 m_noItems
+= nItems
;
1422 void wxListBox::SetString(int N
, const wxString
& s
)
1424 m_stringArray
[N
] = s
;
1428 wxSize
wxListBox::DoGetBestSize() const
1430 int lbWidth
= 100; // some defaults
1435 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetTopLevelWindowRef() ) ) ;
1439 ::TextFont( m_font
.MacGetFontNum() ) ;
1440 ::TextSize( m_font
.MacGetFontSize() ) ;
1441 ::TextFace( m_font
.MacGetFontStyle() ) ;
1445 ::TextFont( kFontIDMonaco
) ;
1450 // Find the widest line
1451 for(int i
= 0; i
< GetCount(); i
++) {
1452 wxString
str(GetString(i
));
1454 Point bounds
={0,0} ;
1456 ::GetThemeTextDimensions( wxMacCFStringHolder( str
, m_font
.GetEncoding() ) ,
1457 kThemeCurrentPortFont
,
1464 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
1466 lbWidth
= wxMax(lbWidth
, wLine
);
1469 // Add room for the scrollbar
1470 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1472 // And just a bit more
1474 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
1477 // don't make the listbox too tall (limit height to around 10 items) but don't
1478 // make it too small neither
1479 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
1482 return wxSize(lbWidth
, lbHeight
);
1485 int wxListBox::GetCount() const
1490 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
1492 wxControl::Refresh( eraseBack
, rect
) ;
1493 // MacRedrawControl() ;
1496 #if wxUSE_OWNER_DRAWN
1498 class wxListBoxItem
: public wxOwnerDrawn
1501 wxListBoxItem(const wxString
& str
= "");
1504 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
1506 // no bitmaps/checkmarks
1510 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
1512 return new wxListBoxItem();
1515 #endif //USE_OWNER_DRAWN
1517 // ============================================================================
1518 // list box control implementation
1519 // ============================================================================
1522 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
1525 // typecast our refCon
1526 list = (wxListBox*)refCon;
1528 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
1529 const wxString text = list->m_stringArray[lCell.v] ;
1530 ::TextFont( kFontIDMonaco ) ;
1533 DrawText(text, 0 , text.Length());
1537 void wxListBox::MacDelete( int N
)
1539 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
1543 void wxListBox::MacInsert( int n
, const wxString
& text
)
1545 Cell cell
= { 0 , 0 } ;
1547 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
1548 // LSetCell(text, strlen(text), cell, m_macList);
1552 void wxListBox::MacAppend( const wxString
& text
)
1554 Cell cell
= { 0 , 0 } ;
1555 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
1556 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
1557 // LSetCell(text, strlen(text), cell, m_macList);
1561 void wxListBox::MacClear()
1563 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
1567 void wxListBox::MacSetSelection( int n
, bool select
)
1569 Cell cell
= { 0 , 0 } ;
1570 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
1572 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
1574 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
1579 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
1580 LAutoScroll( (ListHandle
)m_macList
) ;
1584 bool wxListBox::MacIsSelected( int n
) const
1586 Cell cell
= { 0 , 0 } ;
1588 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
1591 int wxListBox::MacGetSelection() const
1593 Cell cell
= { 0 , 0 } ;
1594 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
1600 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
1604 aSelections
.Empty();
1606 Cell cell
= { 0 , 0 } ;
1609 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
1611 aSelections
.Add( cell
.v
) ;
1618 void wxListBox::MacSet( int n
, const wxString
& text
)
1620 // our implementation does not store anything in the list
1621 // so we just have to redraw
1622 Cell cell
= { 0 , 0 } ;
1624 // LSetCell(text, strlen(text), cell, m_macList);
1628 void wxListBox::MacScrollTo( int n
)
1630 // TODO implement scrolling
1633 void wxListBox::OnSize( wxSizeEvent
&event
)
1638 GetListCellSize((ListHandle
)m_macList
, &pt
);
1640 pt
= (**(ListHandle
)m_macList
).cellSize
;
1643 GetSize( &w
, &h
) ;
1645 LCellSize( pt
, (ListHandle
)m_macList
) ;
1648 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
1650 Boolean wasDoubleClick
= false ;
1653 ::GetControlData( (ControlRef
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
1654 if ( !wasDoubleClick
)
1660 MacDoDoubleClick() ;
1664 void wxListBox::MacSetRedraw( bool doDraw
)
1666 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
1670 void wxListBox::MacDoClick()
1672 wxArrayInt aSelections
;
1674 size_t count
= GetSelections(aSelections
);
1676 if ( count
== m_selectionPreImage
.GetCount() )
1678 bool hasChanged
= false ;
1679 for ( size_t i
= 0 ; i
< count
; ++i
)
1681 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
1693 m_selectionPreImage
= aSelections
;
1695 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1696 event
.SetEventObject( this );
1701 if ( HasClientObjectData() )
1702 event
.SetClientObject( GetClientObject(n
) );
1703 else if ( HasClientUntypedData() )
1704 event
.SetClientData( GetClientData(n
) );
1705 event
.SetString( GetString(n
) );
1712 event
.m_commandInt
= n
;
1714 GetEventHandler()->ProcessEvent(event
);
1717 void wxListBox::MacDoDoubleClick()
1719 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
1720 event
.SetEventObject( this );
1721 GetEventHandler()->ProcessEvent(event
) ;
1724 void wxListBox::OnChar(wxKeyEvent
& event
)
1726 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
1728 wxWindow
* parent
= GetParent() ;
1729 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
1730 parent
= parent
->GetParent() ;
1732 if ( parent
&& parent
->GetDefaultItem() )
1734 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
1736 if ( def
&& def
->IsEnabled() )
1738 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1739 event
.SetEventObject(def
);
1740 def
->Command(event
);
1746 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1747 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
1749 // FIXME: look in ancestors, not just parent.
1750 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
1753 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1754 new_event
.SetEventObject( win
);
1755 win
->GetEventHandler()->ProcessEvent( new_event
);
1758 else if ( event
.GetKeyCode() == WXK_TAB
)
1760 wxNavigationKeyEvent new_event
;
1761 new_event
.SetEventObject( this );
1762 new_event
.SetDirection( !event
.ShiftDown() );
1763 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1764 new_event
.SetWindowChange( event
.ControlDown() );
1765 new_event
.SetCurrentFocus( this );
1766 if ( !GetEventHandler()->ProcessEvent( new_event
) )
1769 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
1771 // perform the default key handling first
1772 wxControl::OnKeyDown( event
) ;
1774 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1775 event
.SetEventObject( this );
1777 wxArrayInt aSelections
;
1778 int n
, count
= GetSelections(aSelections
);
1782 if ( HasClientObjectData() )
1783 event
.SetClientObject( GetClientObject(n
) );
1784 else if ( HasClientUntypedData() )
1785 event
.SetClientData( GetClientData(n
) );
1786 event
.SetString( GetString(n
) );
1793 event
.m_commandInt
= n
;
1795 GetEventHandler()->ProcessEvent(event
);
1799 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
1801 m_typeIn
= wxEmptyString
;
1803 m_lastTypeIn
= event
.GetTimestamp() ;
1804 m_typeIn
+= (char) event
.GetKeyCode() ;
1805 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
1808 if ( GetSelection() != line
)
1810 SetSelection(line
) ;
1811 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1812 event
.SetEventObject( this );
1814 if ( HasClientObjectData() )
1815 event
.SetClientObject( GetClientObject( line
) );
1816 else if ( HasClientUntypedData() )
1817 event
.SetClientData( GetClientData(line
) );
1818 event
.SetString( GetString(line
) );
1820 event
.m_commandInt
= line
;
1822 GetEventHandler()->ProcessEvent(event
);