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 if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
167 m_noItems
= 0 ; // this will be increased by our append command
172 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
175 verify_noerr( ::CreateDataBrowserControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
, kDataBrowserListView
, (ControlRef
*)&m_macControl
) );
176 browser
= (ControlRef
) m_macControl
;
178 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
179 if ( style
& wxLB_MULTIPLE
)
181 options
+= kDataBrowserAlwaysExtendSelection
+ kDataBrowserCmdTogglesSelection
;
183 else if ( style
& wxLB_EXTENDED
)
189 options
+= kDataBrowserSelectOnlyOne
;
191 verify_noerr(SetDataBrowserSelectionFlags (browser
, options
) );
193 DataBrowserListViewColumnDesc columnDesc
;
194 columnDesc
.headerBtnDesc
.titleOffset
= 0;
195 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
197 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
198 kControlUseFontMask
| kControlUseJustMask
;
200 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlNoContent
;
201 columnDesc
.propertyDesc
.propertyType
= kDataBrowserTextType
;
202 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
203 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
204 columnDesc
.headerBtnDesc
.maximumWidth
= 10000;
206 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
207 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
208 columnDesc
.headerBtnDesc
.titleString
= NULL
; // CFSTR( "" );
210 columnDesc
.propertyDesc
.propertyID
= 1024;
211 columnDesc
.propertyDesc
.propertyType
= kDataBrowserTextType
;
212 columnDesc
.propertyDesc
.propertyFlags
=
213 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
214 kDataBrowserListViewTypeSelectColumn
|
216 kDataBrowserTableViewSelectionColumn
;
219 verify_noerr(::AddDataBrowserListViewColumn(browser
, &columnDesc
, kDataBrowserListViewAppendColumn
) ) ;
220 verify_noerr(::AutoSizeDataBrowserListViewColumns( browser
) ) ;
221 verify_noerr(::SetDataBrowserHasScrollBars( browser
, false , true ) ) ;
222 verify_noerr(::SetDataBrowserTableViewHiliteStyle( browser
, kDataBrowserTableViewFillHilite
) ) ;
223 verify_noerr(::SetDataBrowserListViewHeaderBtnHeight( browser
, 0 ) ) ;
224 DataBrowserCallbacks callbacks
;
226 callbacks
.version
= kDataBrowserLatestCallbacks
;
228 InitDataBrowserCallbacks(&callbacks
);
230 callbacks
.u
.v1
.itemDataCallback
=
231 NewDataBrowserItemDataUPP(ListBoxGetSetItemData
);
233 callbacks
.u
.v1
.itemNotificationCallback
=
234 #if TARGET_API_MAC_OSX
235 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
) ;
237 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
) ;
239 SetDataBrowserCallbacks(browser
, &callbacks
);
241 MacPostControlCreate(pos
,size
) ;
243 for ( int i
= 0 ; i
< n
; i
++ )
245 Append( choices
[i
] ) ;
251 wxListBox::~wxListBox()
253 SetControlReference( (ControlRef
) m_macControl
, NULL
) ;
255 // avoid access during destruction
262 void wxListBox::FreeData()
264 #if wxUSE_OWNER_DRAWN
265 if ( m_windowStyle
& wxLB_OWNERDRAW
)
267 size_t uiCount
= m_aItems
.Count();
268 while ( uiCount
-- != 0 ) {
269 delete m_aItems
[uiCount
];
270 m_aItems
[uiCount
] = NULL
;
276 #endif // wxUSE_OWNER_DRAWN
277 if ( HasClientObjectData() )
279 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
281 delete GetClientObject(n
);
286 void wxListBox::DoSetSize(int x
, int y
,
287 int width
, int height
,
290 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
293 void wxListBox::DoSetFirstItem(int N
)
298 void wxListBox::Delete(int N
)
300 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
301 wxT("invalid index in wxListBox::Delete") );
303 #if wxUSE_OWNER_DRAWN
305 m_aItems
.RemoveAt(N
);
306 #else // !wxUSE_OWNER_DRAWN
307 if ( HasClientObjectData() )
309 delete GetClientObject(N
);
311 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
312 m_stringArray
.RemoveAt( N
) ;
313 m_dataArray
.RemoveAt( N
) ;
319 int wxListBox::DoAppend(const wxString
& item
)
321 int index
= m_noItems
;
322 m_stringArray
.Add( item
) ;
323 m_dataArray
.Add( NULL
);
325 DoSetItemClientData( index
, NULL
) ;
331 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
334 int n
= choices
.GetCount();
336 for( int i
= 0 ; i
< n
; ++i
)
340 #if wxUSE_OWNER_DRAWN
341 wxASSERT_MSG(clientData
[i
] == NULL
,
342 wxT("Can't use client data with owner-drawn listboxes"));
343 #else // !wxUSE_OWNER_DRAWN
344 Append( choices
[i
] , clientData
[i
] ) ;
348 Append( choices
[i
] ) ;
351 #if wxUSE_OWNER_DRAWN
352 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
353 // first delete old items
354 size_t ui
= m_aItems
.Count();
355 while ( ui
-- != 0 ) {
361 // then create new ones
362 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
363 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
364 pNewItem
->SetName(choices
[ui
]);
365 m_aItems
.Add(pNewItem
);
368 #endif // wxUSE_OWNER_DRAWN
371 int wxListBox::FindString(const wxString
& s
) const
374 if ( s
.Right(1) == wxT("*") )
376 wxString search
= s
.Left( s
.Length() - 1 ) ;
377 int len
= search
.Length() ;
379 wxMacStringToPascal( search
, s2
) ;
381 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
383 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
385 if ( EqualString( s1
, s2
, false , false ) )
388 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
392 for ( int i
= 0 ; i
< m_noItems
; ++i
)
394 if ( GetString(i
).Lower().Matches(st
) )
404 wxMacStringToPascal( s
, s2
) ;
406 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
408 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
410 if ( EqualString( s1
, s2
, false , false ) )
417 void wxListBox::Clear()
421 m_stringArray
.Empty() ;
422 m_dataArray
.Empty() ;
426 void wxListBox::SetSelection(int N
, bool select
)
428 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
429 wxT("invalid index in wxListBox::SetSelection") );
430 MacSetSelection( N
, select
) ;
431 GetSelections( m_selectionPreImage
) ;
434 bool wxListBox::IsSelected(int N
) const
436 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
437 wxT("invalid index in wxListBox::Selected") );
439 return MacIsSelected( N
) ;
442 void *wxListBox::DoGetItemClientData(int N
) const
444 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
445 wxT("invalid index in wxListBox::GetClientData"));
447 return (void *)m_dataArray
[N
];
450 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
452 return (wxClientData
*) DoGetItemClientData( N
) ;
455 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
457 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
458 wxT("invalid index in wxListBox::SetClientData") );
460 #if wxUSE_OWNER_DRAWN
461 if ( m_windowStyle
& wxLB_OWNERDRAW
)
463 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
464 // in OnMeasure/OnDraw.
465 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
467 #endif // wxUSE_OWNER_DRAWN
468 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
470 if ( m_dataArray
.GetCount() > (size_t) N
)
472 m_dataArray
[N
] = (char*) Client_data
;
476 m_dataArray
.Add( (char*) Client_data
) ;
480 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
482 DoSetItemClientData(n
, clientData
);
485 // Return number of selections and an array of selected integers
486 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
488 return MacGetSelections( aSelections
) ;
491 // Get single selection, for single choice list items
492 int wxListBox::GetSelection() const
494 return MacGetSelection() ;
497 // Find string for position
498 wxString
wxListBox::GetString(int N
) const
500 return m_stringArray
[N
] ;
503 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
505 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
506 wxT("invalid index in wxListBox::InsertItems") );
508 int nItems
= items
.GetCount();
510 for ( int i
= 0 ; i
< nItems
; i
++ )
512 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
513 m_dataArray
.Insert( NULL
, pos
+ i
) ;
514 MacInsert( pos
+ i
, items
[i
] ) ;
520 void wxListBox::SetString(int N
, const wxString
& s
)
522 m_stringArray
[N
] = s
;
526 wxSize
wxListBox::DoGetBestSize() const
528 int lbWidth
= 100; // some defaults
533 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetTopLevelWindowRef() ) ) ;
537 ::TextFont( m_font
.MacGetFontNum() ) ;
538 ::TextSize( m_font
.MacGetFontSize() ) ;
539 ::TextFace( m_font
.MacGetFontStyle() ) ;
543 ::TextFont( kFontIDMonaco
) ;
548 // Find the widest line
549 for(int i
= 0; i
< GetCount(); i
++) {
550 wxString
str(GetString(i
));
554 ::GetThemeTextDimensions( wxMacCFStringHolder( str
, m_font
.GetEncoding() ) ,
555 kThemeCurrentPortFont
,
562 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
564 lbWidth
= wxMax(lbWidth
, wLine
);
567 // Add room for the scrollbar
568 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
570 // And just a bit more
572 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
575 // don't make the listbox too tall (limit height to around 10 items) but don't
576 // make it too small neither
577 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
580 return wxSize(lbWidth
, lbHeight
);
583 int wxListBox::GetCount() const
588 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
590 wxControl::Refresh( eraseBack
, rect
) ;
591 // MacRedrawControl() ;
594 #if wxUSE_OWNER_DRAWN
596 class wxListBoxItem
: public wxOwnerDrawn
599 wxListBoxItem(const wxString
& str
= "");
602 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
604 // no bitmaps/checkmarks
608 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
610 return new wxListBoxItem();
613 #endif //USE_OWNER_DRAWN
615 // ============================================================================
616 // list box control implementation
617 // ============================================================================
619 void wxListBox::MacDelete( int N
)
621 UInt32 id
= m_idArray
[N
] ;
622 verify_noerr(::RemoveDataBrowserItems((ControlRef
) m_macControl
, kDataBrowserNoItem
, 1 , (UInt32
*) &id
, kDataBrowserItemNoProperty
) ) ;
623 m_idArray
.RemoveAt( N
) ;
626 void wxListBox::MacInsert( int n
, const wxString
& text
)
628 verify_noerr(::AddDataBrowserItems( (ControlRef
) m_macControl
, kDataBrowserNoItem
, 1 , (UInt32
*) &m_nextId
, kDataBrowserItemNoProperty
) ) ;
629 m_idArray
.Insert( m_nextId
, n
) ;
633 void wxListBox::MacAppend( const wxString
& text
)
635 verify_noerr(::AddDataBrowserItems( (ControlRef
) m_macControl
, kDataBrowserNoItem
, 1 , (UInt32
*) &m_nextId
, kDataBrowserItemNoProperty
) ) ;
636 m_idArray
.Add( m_nextId
) ;
640 void wxListBox::MacClear()
642 verify_noerr(::RemoveDataBrowserItems((ControlRef
) m_macControl
, kDataBrowserNoItem
, 0 , NULL
, kDataBrowserItemNoProperty
) ) ;
646 void wxListBox::MacSetSelection( int n
, bool select
)
648 UInt32 id
= m_idArray
[n
] ;
649 if ( ::IsDataBrowserItemSelected( (ControlRef
) m_macControl
, id
) != select
)
651 verify_noerr(::SetDataBrowserSelectedItems((ControlRef
) m_macControl
, 1 , & id
, kDataBrowserItemsToggle
) ) ;
656 bool wxListBox::MacIsSelected( int n
) const
658 return ::IsDataBrowserItemSelected( (ControlRef
) m_macControl
, m_idArray
[n
] ) ;
661 int wxListBox::MacGetSelection() const
663 for ( size_t i
= 0 ; i
< m_idArray
.GetCount() ; ++i
)
665 if ( ::IsDataBrowserItemSelected((ControlRef
) m_macControl
, m_idArray
[i
] ) )
673 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
678 for ( size_t i
= 0 ; i
< m_idArray
.GetCount() ; ++i
)
680 if ( ::IsDataBrowserItemSelected((ControlRef
) m_macControl
, m_idArray
[i
] ) )
682 aSelections
.Add( i
) ;
689 void wxListBox::MacSet( int n
, const wxString
& text
)
691 // as we don't store the strings we only have to issue a redraw
692 UInt32 id
= m_idArray
[n
] ;
693 verify_noerr( ::UpdateDataBrowserItems( (ControlRef
) m_macControl
, kDataBrowserNoItem
, 1 , &id
, kDataBrowserItemNoProperty
, kDataBrowserItemNoProperty
) ) ;
696 void wxListBox::MacScrollTo( int n
)
698 // TODO implement scrolling
701 void wxListBox::OnSize( wxSizeEvent
&event
)
705 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
708 Boolean wasDoubleClick = false ;
711 ::GetControlData( (ControlRef) m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ;
712 if ( !wasDoubleClick )
723 void wxListBox::MacSetRedraw( bool doDraw
)
725 // nothing to do in compositing mode
728 void wxListBox::MacDoClick()
730 wxArrayInt aSelections;
732 size_t count = GetSelections(aSelections);
734 if ( count == m_selectionPreImage.GetCount() )
736 bool hasChanged = false ;
737 for ( size_t i = 0 ; i < count ; ++i )
739 if ( aSelections[i] != m_selectionPreImage[i] )
751 m_selectionPreImage = aSelections;
753 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
754 event.SetEventObject( this );
759 if ( HasClientObjectData() )
760 event.SetClientObject( GetClientObject(n) );
761 else if ( HasClientUntypedData() )
762 event.SetClientData( GetClientData(n) );
763 event.SetString( GetString(n) );
770 event.m_commandInt = n;
772 GetEventHandler()->ProcessEvent(event);
776 void wxListBox::MacDoDoubleClick()
779 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
780 event.SetEventObject( this );
781 GetEventHandler()->ProcessEvent(event) ;
785 void wxListBox::OnChar(wxKeyEvent
& event
)
787 // todo trigger proper events here
791 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
793 wxWindow
* parent
= GetParent() ;
794 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
795 parent
= parent
->GetParent() ;
797 if ( parent
&& parent
->GetDefaultItem() )
799 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
801 if ( def
&& def
->IsEnabled() )
803 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
804 event
.SetEventObject(def
);
811 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
812 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
814 // FIXME: look in ancestors, not just parent.
815 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
818 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
819 new_event
.SetEventObject( win
);
820 win
->GetEventHandler()->ProcessEvent( new_event
);
823 else if ( event
.GetKeyCode() == WXK_TAB
)
825 wxNavigationKeyEvent new_event
;
826 new_event
.SetEventObject( this );
827 new_event
.SetDirection( !event
.ShiftDown() );
828 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
829 new_event
.SetWindowChange( event
.ControlDown() );
830 new_event
.SetCurrentFocus( this );
831 if ( !GetEventHandler()->ProcessEvent( new_event
) )
834 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
836 // perform the default key handling first
837 wxControl::OnKeyDown( event
) ;
839 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
840 event
.SetEventObject( this );
842 wxArrayInt aSelections
;
843 int n
, count
= GetSelections(aSelections
);
847 if ( HasClientObjectData() )
848 event
.SetClientObject( GetClientObject(n
) );
849 else if ( HasClientUntypedData() )
850 event
.SetClientData( GetClientData(n
) );
851 event
.SetString( GetString(n
) );
858 event
.m_commandInt
= n
;
860 GetEventHandler()->ProcessEvent(event
);
864 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
866 m_typeIn
= wxEmptyString
;
868 m_lastTypeIn
= event
.GetTimestamp() ;
869 m_typeIn
+= (char) event
.GetKeyCode() ;
870 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
873 if ( GetSelection() != line
)
876 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
877 event
.SetEventObject( this );
879 if ( HasClientObjectData() )
880 event
.SetClientObject( GetClientObject( line
) );
881 else if ( HasClientUntypedData() )
882 event
.SetClientData( GetClientData(line
) );
883 event
.SetString( GetString(line
) );
885 event
.m_commandInt
= line
;
887 GetEventHandler()->ProcessEvent(event
);
895 // old carbon version
897 const short kwxMacListItemHeight
= 19 ;
901 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect
*drawRect
,
902 Cell cell
, short dataOffset
, short dataLength
,
903 ListHandle listHandle
) ;
906 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect
*d
,
907 Cell cell
, short dataOffset
, short dataLength
,
908 ListHandle listHandle
)
912 Rect
* drawRect
= &r
;
914 list
= (wxListBox
*) GetControlReference( (ControlRef
) GetListRefCon(listHandle
) );
915 if ( list
== NULL
|| list
->GetHandle() == NULL
|| GetControlReference( ( ControlRef
)list
->GetHandle() ) == NULL
)
918 // the bounds passed in are not correct, adjust the right border
921 GetControlBounds( (ControlRef
) list
->GetHandle() , &bounds
) ;
922 r
.right
= r
.left
+ (bounds
.right
- bounds
.left
) - 16 ;
926 RgnHandle savedClipRegion
;
929 SetPort((**listHandle
).port
);
930 grafPtr
= (**listHandle
).port
;
931 // typecast our refCon
933 // Calculate the cell rect.
944 const wxString linetext
= list
->m_stringArray
[cell
.v
] ;
946 // Save the current clip region, and set the clip region to the area we are about
949 savedClipRegion
= NewRgn();
950 GetClip( savedClipRegion
);
952 ClipRect( drawRect
);
953 EraseRect( drawRect
);
955 const wxFont
& font
= list
->GetFont();
958 ::TextFont( font
.MacGetFontNum() ) ;
959 ::TextSize( font
.MacGetFontSize() ) ;
960 ::TextFace( font
.MacGetFontStyle() ) ;
964 ::TextFont( kFontIDMonaco
) ;
970 Rect frame
= { drawRect
->top
, drawRect
->left
+ 4,
971 drawRect
->top
+ kwxMacListItemHeight
, drawRect
->right
+ 10000 } ;
972 CFMutableStringRef mString
= CFStringCreateMutableCopy( NULL
, 0 , wxMacCFStringHolder(linetext
, list
->GetFont().GetEncoding()) ) ;
973 ::TruncateThemeText( mString
, kThemeCurrentPortFont
, kThemeStateActive
, drawRect
->right
- drawRect
->left
, truncEnd
, NULL
) ;
975 ::DrawThemeTextBox( mString
,
976 kThemeCurrentPortFont
,
983 CFRelease( mString
) ;
986 // If the cell is hilited, do the hilite now. Paint the cell contents with the
987 // appropriate QuickDraw transform mode.
990 savedPenMode
= GetPortPenMode( (CGrafPtr
) grafPtr
);
991 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
992 PaintRect( drawRect
);
993 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
996 // Restore the saved clip region.
998 SetClip( savedClipRegion
);
999 DisposeRgn( savedClipRegion
);
1004 // Hilite or unhilite the cell. Paint the cell contents with the
1005 // appropriate QuickDraw transform mode.
1007 GetPort( &grafPtr
);
1008 savedPenMode
= GetPortPenMode( (CGrafPtr
)grafPtr
);
1009 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
1010 PaintRect( drawRect
);
1011 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
1019 extern "C" void MacDrawStringCell(Rect
*cellRect
, Cell lCell
, ListHandle theList
, long refCon
) ;
1020 // resources ldef ids
1021 const short kwxMacListWithVerticalScrollbar
= 128 ;
1022 const short kwxMacListWithVerticalAndHorizontalScrollbar
= 129 ;
1024 // ============================================================================
1025 // list box control implementation
1026 // ============================================================================
1029 wxListBox::wxListBox()
1036 static ListDefUPP macListDefUPP
= NULL
;
1038 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
1041 const wxArrayString
& choices
,
1043 const wxValidator
& validator
,
1044 const wxString
& name
)
1046 wxCArrayString
chs(choices
);
1048 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
1049 style
, validator
, name
);
1052 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
1055 int n
, const wxString choices
[],
1057 const wxValidator
& validator
,
1058 const wxString
& name
)
1060 m_macIsUserPane
= FALSE
;
1062 if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
1065 m_noItems
= 0 ; // this will be increased by our append command
1068 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1070 ListDefSpec listDef
;
1071 listDef
.defType
= kListDefUserProcType
;
1072 if ( macListDefUPP
== NULL
)
1074 macListDefUPP
= NewListDefUPP( wxMacListDefinition
);
1076 listDef
.u
.userProc
= macListDefUPP
;
1082 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1084 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) ) ) ;
1089 CreateListBoxControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
, false, 0, 1, (style
& wxLB_HSCROLL
), true,
1090 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
1092 GetControlData( (ControlRef
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
1093 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
1095 SetControlReference( (ControlRef
) m_macControl
, (long) this);
1098 OptionBits options
= 0;
1099 if ( style
& wxLB_MULTIPLE
)
1101 options
+= lExtendDrag
+ lUseSense
;
1103 else if ( style
& wxLB_EXTENDED
)
1105 // default behaviour
1109 options
= (OptionBits
) lOnlyOne
;
1111 SetListSelectionFlags((ListHandle
)m_macList
, options
);
1113 for ( int i
= 0 ; i
< n
; i
++ )
1115 Append( choices
[i
] ) ;
1118 MacPostControlCreate(pos
,size
) ;
1120 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
1125 wxListBox::~wxListBox()
1127 SetControlReference( (ControlRef
) m_macControl
, NULL
) ;
1129 // avoid access during destruction
1136 void wxListBox::FreeData()
1138 #if wxUSE_OWNER_DRAWN
1139 if ( m_windowStyle
& wxLB_OWNERDRAW
)
1141 size_t uiCount
= m_aItems
.Count();
1142 while ( uiCount
-- != 0 ) {
1143 delete m_aItems
[uiCount
];
1144 m_aItems
[uiCount
] = NULL
;
1150 #endif // wxUSE_OWNER_DRAWN
1151 if ( HasClientObjectData() )
1153 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
1155 delete GetClientObject(n
);
1160 void wxListBox::DoSetSize(int x
, int y
,
1161 int width
, int height
,
1164 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
1167 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1168 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
1172 GetControlBounds( control
, &scrollbounds
) ;
1173 if( scrollbounds
.right
!= bounds
.right
+ 1 )
1175 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
1176 scrollbounds
.top
) ;
1181 void wxListBox::DoSetFirstItem(int N
)
1186 void wxListBox::Delete(int N
)
1188 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
1189 wxT("invalid index in wxListBox::Delete") );
1191 #if wxUSE_OWNER_DRAWN
1193 m_aItems
.RemoveAt(N
);
1194 #else // !wxUSE_OWNER_DRAWN
1195 if ( HasClientObjectData() )
1197 delete GetClientObject(N
);
1199 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
1200 m_stringArray
.RemoveAt( N
) ;
1201 m_dataArray
.RemoveAt( N
) ;
1207 int wxListBox::DoAppend(const wxString
& item
)
1209 int index
= m_noItems
;
1210 m_stringArray
.Add( item
) ;
1211 m_dataArray
.Add( NULL
);
1213 DoSetItemClientData( index
, NULL
) ;
1219 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
1221 MacSetRedraw( false ) ;
1223 int n
= choices
.GetCount();
1225 for( int i
= 0 ; i
< n
; ++i
)
1229 #if wxUSE_OWNER_DRAWN
1230 wxASSERT_MSG(clientData
[i
] == NULL
,
1231 wxT("Can't use client data with owner-drawn listboxes"));
1232 #else // !wxUSE_OWNER_DRAWN
1233 Append( choices
[i
] , clientData
[i
] ) ;
1237 Append( choices
[i
] ) ;
1240 #if wxUSE_OWNER_DRAWN
1241 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
1242 // first delete old items
1243 size_t ui
= m_aItems
.Count();
1244 while ( ui
-- != 0 ) {
1245 delete m_aItems
[ui
];
1246 m_aItems
[ui
] = NULL
;
1250 // then create new ones
1251 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
1252 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
1253 pNewItem
->SetName(choices
[ui
]);
1254 m_aItems
.Add(pNewItem
);
1257 #endif // wxUSE_OWNER_DRAWN
1258 MacSetRedraw( true ) ;
1261 bool wxListBox::HasMultipleSelection() const
1263 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
1266 int wxListBox::FindString(const wxString
& s
) const
1269 if ( s
.Right(1) == wxT("*") )
1271 wxString search
= s
.Left( s
.Length() - 1 ) ;
1272 int len
= search
.Length() ;
1274 wxMacStringToPascal( search
, s2
) ;
1276 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
1278 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
1280 if ( EqualString( s1
, s2
, false , false ) )
1283 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
1287 for ( int i
= 0 ; i
< m_noItems
; ++i
)
1289 if ( GetString(i
).Lower().Matches(st
) )
1299 wxMacStringToPascal( s
, s2
) ;
1301 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
1303 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
1305 if ( EqualString( s1
, s2
, false , false ) )
1312 void wxListBox::Clear()
1316 m_stringArray
.Empty() ;
1317 m_dataArray
.Empty() ;
1321 void wxListBox::SetSelection(int N
, bool select
)
1323 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
1324 wxT("invalid index in wxListBox::SetSelection") );
1325 MacSetSelection( N
, select
) ;
1326 GetSelections( m_selectionPreImage
) ;
1329 bool wxListBox::IsSelected(int N
) const
1331 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
1332 wxT("invalid index in wxListBox::Selected") );
1334 return MacIsSelected( N
) ;
1337 void *wxListBox::DoGetItemClientData(int N
) const
1339 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
1340 wxT("invalid index in wxListBox::GetClientData"));
1342 return (void *)m_dataArray
[N
];
1345 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
1347 return (wxClientData
*) DoGetItemClientData( N
) ;
1350 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
1352 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
1353 wxT("invalid index in wxListBox::SetClientData") );
1355 #if wxUSE_OWNER_DRAWN
1356 if ( m_windowStyle
& wxLB_OWNERDRAW
)
1358 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
1359 // in OnMeasure/OnDraw.
1360 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
1362 #endif // wxUSE_OWNER_DRAWN
1363 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
1365 if ( m_dataArray
.GetCount() > (size_t) N
)
1367 m_dataArray
[N
] = (char*) Client_data
;
1371 m_dataArray
.Add( (char*) Client_data
) ;
1375 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
1377 DoSetItemClientData(n
, clientData
);
1380 // Return number of selections and an array of selected integers
1381 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
1383 return MacGetSelections( aSelections
) ;
1386 // Get single selection, for single choice list items
1387 int wxListBox::GetSelection() const
1389 return MacGetSelection() ;
1392 // Find string for position
1393 wxString
wxListBox::GetString(int N
) const
1395 return m_stringArray
[N
] ;
1398 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
1400 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
1401 wxT("invalid index in wxListBox::InsertItems") );
1403 int nItems
= items
.GetCount();
1405 for ( int i
= 0 ; i
< nItems
; i
++ )
1407 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
1408 m_dataArray
.Insert( NULL
, pos
+ i
) ;
1409 MacInsert( pos
+ i
, items
[i
] ) ;
1412 m_noItems
+= nItems
;
1415 void wxListBox::SetString(int N
, const wxString
& s
)
1417 m_stringArray
[N
] = s
;
1421 wxSize
wxListBox::DoGetBestSize() const
1423 int lbWidth
= 100; // some defaults
1428 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetTopLevelWindowRef() ) ) ;
1432 ::TextFont( m_font
.MacGetFontNum() ) ;
1433 ::TextSize( m_font
.MacGetFontSize() ) ;
1434 ::TextFace( m_font
.MacGetFontStyle() ) ;
1438 ::TextFont( kFontIDMonaco
) ;
1443 // Find the widest line
1444 for(int i
= 0; i
< GetCount(); i
++) {
1445 wxString
str(GetString(i
));
1447 Point bounds
={0,0} ;
1449 ::GetThemeTextDimensions( wxMacCFStringHolder( str
, m_font
.GetEncoding() ) ,
1450 kThemeCurrentPortFont
,
1457 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
1459 lbWidth
= wxMax(lbWidth
, wLine
);
1462 // Add room for the scrollbar
1463 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1465 // And just a bit more
1467 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
1470 // don't make the listbox too tall (limit height to around 10 items) but don't
1471 // make it too small neither
1472 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
1475 return wxSize(lbWidth
, lbHeight
);
1478 int wxListBox::GetCount() const
1483 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
1485 wxControl::Refresh( eraseBack
, rect
) ;
1486 // MacRedrawControl() ;
1489 #if wxUSE_OWNER_DRAWN
1491 class wxListBoxItem
: public wxOwnerDrawn
1494 wxListBoxItem(const wxString
& str
= "");
1497 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
1499 // no bitmaps/checkmarks
1503 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
1505 return new wxListBoxItem();
1508 #endif //USE_OWNER_DRAWN
1510 // ============================================================================
1511 // list box control implementation
1512 // ============================================================================
1515 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
1518 // typecast our refCon
1519 list = (wxListBox*)refCon;
1521 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
1522 const wxString text = list->m_stringArray[lCell.v] ;
1523 ::TextFont( kFontIDMonaco ) ;
1526 DrawText(text, 0 , text.Length());
1530 void wxListBox::MacDelete( int N
)
1532 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
1536 void wxListBox::MacInsert( int n
, const wxString
& text
)
1538 Cell cell
= { 0 , 0 } ;
1540 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
1541 // LSetCell(text, strlen(text), cell, m_macList);
1545 void wxListBox::MacAppend( const wxString
& text
)
1547 Cell cell
= { 0 , 0 } ;
1548 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
1549 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
1550 // LSetCell(text, strlen(text), cell, m_macList);
1554 void wxListBox::MacClear()
1556 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
1560 void wxListBox::MacSetSelection( int n
, bool select
)
1562 Cell cell
= { 0 , 0 } ;
1563 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
1565 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
1567 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
1572 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
1573 LAutoScroll( (ListHandle
)m_macList
) ;
1577 bool wxListBox::MacIsSelected( int n
) const
1579 Cell cell
= { 0 , 0 } ;
1581 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
1584 int wxListBox::MacGetSelection() const
1586 Cell cell
= { 0 , 0 } ;
1587 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
1593 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
1597 aSelections
.Empty();
1599 Cell cell
= { 0 , 0 } ;
1602 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
1604 aSelections
.Add( cell
.v
) ;
1611 void wxListBox::MacSet( int n
, const wxString
& text
)
1613 // our implementation does not store anything in the list
1614 // so we just have to redraw
1615 Cell cell
= { 0 , 0 } ;
1617 // LSetCell(text, strlen(text), cell, m_macList);
1621 void wxListBox::MacScrollTo( int n
)
1623 // TODO implement scrolling
1626 void wxListBox::OnSize( wxSizeEvent
&event
)
1631 GetListCellSize((ListHandle
)m_macList
, &pt
);
1633 pt
= (**(ListHandle
)m_macList
).cellSize
;
1636 GetSize( &w
, &h
) ;
1638 LCellSize( pt
, (ListHandle
)m_macList
) ;
1641 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
1643 Boolean wasDoubleClick
= false ;
1646 ::GetControlData( (ControlRef
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
1647 if ( !wasDoubleClick
)
1653 MacDoDoubleClick() ;
1657 void wxListBox::MacSetRedraw( bool doDraw
)
1659 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
1663 void wxListBox::MacDoClick()
1665 wxArrayInt aSelections
;
1667 size_t count
= GetSelections(aSelections
);
1669 if ( count
== m_selectionPreImage
.GetCount() )
1671 bool hasChanged
= false ;
1672 for ( size_t i
= 0 ; i
< count
; ++i
)
1674 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
1686 m_selectionPreImage
= aSelections
;
1688 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1689 event
.SetEventObject( this );
1694 if ( HasClientObjectData() )
1695 event
.SetClientObject( GetClientObject(n
) );
1696 else if ( HasClientUntypedData() )
1697 event
.SetClientData( GetClientData(n
) );
1698 event
.SetString( GetString(n
) );
1705 event
.m_commandInt
= n
;
1707 GetEventHandler()->ProcessEvent(event
);
1710 void wxListBox::MacDoDoubleClick()
1712 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
1713 event
.SetEventObject( this );
1714 GetEventHandler()->ProcessEvent(event
) ;
1717 void wxListBox::OnChar(wxKeyEvent
& event
)
1719 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
1721 wxWindow
* parent
= GetParent() ;
1722 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
1723 parent
= parent
->GetParent() ;
1725 if ( parent
&& parent
->GetDefaultItem() )
1727 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
1729 if ( def
&& def
->IsEnabled() )
1731 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1732 event
.SetEventObject(def
);
1733 def
->Command(event
);
1739 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1740 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
1742 // FIXME: look in ancestors, not just parent.
1743 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
1746 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1747 new_event
.SetEventObject( win
);
1748 win
->GetEventHandler()->ProcessEvent( new_event
);
1751 else if ( event
.GetKeyCode() == WXK_TAB
)
1753 wxNavigationKeyEvent new_event
;
1754 new_event
.SetEventObject( this );
1755 new_event
.SetDirection( !event
.ShiftDown() );
1756 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1757 new_event
.SetWindowChange( event
.ControlDown() );
1758 new_event
.SetCurrentFocus( this );
1759 if ( !GetEventHandler()->ProcessEvent( new_event
) )
1762 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
1764 // perform the default key handling first
1765 wxControl::OnKeyDown( event
) ;
1767 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1768 event
.SetEventObject( this );
1770 wxArrayInt aSelections
;
1771 int n
, count
= GetSelections(aSelections
);
1775 if ( HasClientObjectData() )
1776 event
.SetClientObject( GetClientObject(n
) );
1777 else if ( HasClientUntypedData() )
1778 event
.SetClientData( GetClientData(n
) );
1779 event
.SetString( GetString(n
) );
1786 event
.m_commandInt
= n
;
1788 GetEventHandler()->ProcessEvent(event
);
1792 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
1794 m_typeIn
= wxEmptyString
;
1796 m_lastTypeIn
= event
.GetTimestamp() ;
1797 m_typeIn
+= (char) event
.GetKeyCode() ;
1798 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
1801 if ( GetSelection() != line
)
1803 SetSelection(line
) ;
1804 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1805 event
.SetEventObject( this );
1807 if ( HasClientObjectData() )
1808 event
.SetClientObject( GetClientObject( line
) );
1809 else if ( HasClientUntypedData() )
1810 event
.SetClientData( GetClientData(line
) );
1811 event
.SetString( GetString(line
) );
1813 event
.m_commandInt
= line
;
1815 GetEventHandler()->ProcessEvent(event
);