1 ///////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "listbox.h"
16 #include "wx/wxprec.h"
21 #include "wx/listbox.h"
22 #include "wx/button.h"
23 #include "wx/settings.h"
24 #include "wx/toplevel.h"
25 #include "wx/dynarray.h"
30 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
32 BEGIN_EVENT_TABLE(wxListBox
, wxControl
)
34 // EVT_SIZE( wxListBox::OnSize )
35 EVT_CHAR( wxListBox::OnChar
)
39 #include "wx/mac/uma.h"
41 const short kTextColumnId
= 1024 ;
43 // new databrowserbased version
44 // because of the limited insert
45 // functionality of DataBrowser,
46 // we just introduce id s corresponding
49 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
50 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
51 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
53 #if TARGET_API_MAC_OSX
54 static pascal void DataBrowserItemNotificationProc(ControlRef browser
, DataBrowserItemID itemID
,
55 DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
)
57 static pascal void DataBrowserItemNotificationProc(ControlRef browser
, DataBrowserItemID itemID
,
58 DataBrowserItemNotification message
)
61 long ref
= GetControlReference( browser
) ;
64 wxListBox
* list
= wxDynamicCast( (wxObject
*) ref
, wxListBox
) ;
66 if (i
>= 0 && i
< list
->GetCount() )
68 bool trigger
= false ;
70 wxEVT_COMMAND_LISTBOX_SELECTED
, list
->GetId() );
73 case kDataBrowserItemDeselected
:
74 if ( list
->HasMultipleSelection() )
75 trigger
= !list
->MacIsSelectionSuppressed() ;
77 case kDataBrowserItemSelected
:
78 trigger
= !list
->MacIsSelectionSuppressed() ;
80 case kDataBrowserItemDoubleClicked
:
81 event
.SetEventType(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
) ;
89 event
.SetEventObject( list
);
90 if ( list
->HasClientObjectData() )
91 event
.SetClientObject( list
->GetClientObject(i
) );
92 else if ( list
->HasClientUntypedData() )
93 event
.SetClientData( list
->GetClientData(i
) );
94 event
.SetString( list
->GetString(i
) );
96 event
.SetExtraLong( list
->HasMultipleSelection() ? message
== kDataBrowserItemSelected
: TRUE
);
97 wxPostEvent( list
->GetEventHandler() , event
) ;
98 // direct notification is not always having the listbox GetSelection() having in synch with event
99 // list->GetEventHandler()->ProcessEvent(event) ;
105 static pascal OSStatus
ListBoxGetSetItemData(ControlRef browser
,
106 DataBrowserItemID itemID
, DataBrowserPropertyID property
,
107 DataBrowserItemDataRef itemData
, Boolean changeValue
)
109 OSStatus err
= errDataBrowserPropertyNotSupported
;
118 long ref
= GetControlReference( browser
) ;
121 wxListBox
* list
= wxDynamicCast( (wxObject
*) ref
, wxListBox
) ;
123 if (i
>= 0 && i
< list
->GetCount() )
125 wxMacCFStringHolder
cf( list
->GetString(i
) , list
->GetFont().GetEncoding() ) ;
126 verify_noerr( ::SetDataBrowserItemDataText( itemData
, cf
) ) ;
142 static pascal void ListBoxDrawProc( ControlRef browser
, DataBrowserItemID item
, DataBrowserPropertyID property
,
143 DataBrowserItemState itemState
, const Rect
*itemRect
, SInt16 depth
, Boolean isColorDevice
)
146 CFStringRef cfString
;
149 cfString
= CFStringCreateWithFormat( NULL
, NULL
, CFSTR("Row %d"), item
);
151 ThemeDrawingState themeState
;
152 GetThemeDrawingState( &themeState
) ;
154 if ( itemState
== kDataBrowserItemIsSelected
) // In this sample we handle the "selected" state, all others fall through to our "active" state
156 Gestalt( gestaltSystemVersion
, &systemVersion
);
157 if ( (systemVersion
>= 0x00001030) && (IsControlActive( browser
) == false) ) // Panther DB starts using kThemeBrushSecondaryHighlightColor for inactive browser hilighting
158 SetThemePen( kThemeBrushSecondaryHighlightColor
, 32, true );
160 SetThemePen( kThemeBrushPrimaryHighlightColor
, 32, true );
162 PaintRect( itemRect
); // First paint the hilite rect, then the text on top
163 SetThemeDrawingState( themeState
, false ) ;
165 DrawThemeTextBox( cfString
, kThemeApplicationFont
, kThemeStateActive
, true, itemRect
, teFlushDefault
, NULL
);
166 if ( cfString
!= NULL
)
167 CFRelease( cfString
);
168 SetThemeDrawingState( themeState
, true ) ;
172 wxListBox::wxListBox()
177 m_suppressSelection
= false ;
180 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
183 const wxArrayString
& choices
,
185 const wxValidator
& validator
,
186 const wxString
& name
)
188 wxCArrayString
chs(choices
);
190 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
191 style
, validator
, name
);
194 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
197 int n
, const wxString choices
[],
199 const wxValidator
& validator
,
200 const wxString
& name
)
202 m_macIsUserPane
= FALSE
;
204 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
205 _T("only one of listbox selection modes can be specified") );
207 if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
210 m_noItems
= 0 ; // this will be increased by our append command
213 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
215 m_peer
= new wxMacControl(this) ;
216 verify_noerr( ::CreateDataBrowserControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
, kDataBrowserListView
, m_peer
->GetControlRefAddr() ) );
218 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
219 if ( style
& wxLB_MULTIPLE
)
221 options
+= kDataBrowserAlwaysExtendSelection
+ kDataBrowserCmdTogglesSelection
;
223 else if ( style
& wxLB_EXTENDED
)
229 options
+= kDataBrowserSelectOnlyOne
;
231 verify_noerr(m_peer
->SetSelectionFlags( options
) );
233 if ( gDataBrowserItemDataUPP
== NULL
) gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(ListBoxGetSetItemData
) ;
234 if ( gDataBrowserItemNotificationUPP
== NULL
)
236 gDataBrowserItemNotificationUPP
=
237 #if TARGET_API_MAC_OSX
238 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
) ;
240 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
) ;
243 if ( gDataBrowserDrawItemUPP
== NULL
) gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(ListBoxDrawProc
) ;
245 DataBrowserCallbacks callbacks
;
246 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
) ;
248 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
249 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
250 m_peer
->SetCallbacks( &callbacks
);
252 DataBrowserCustomCallbacks customCallbacks
;
253 InitializeDataBrowserCustomCallbacks( &customCallbacks
, kDataBrowserLatestCustomCallbacks
) ;
255 customCallbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
257 SetDataBrowserCustomCallbacks( m_peer
->GetControlRef() , &customCallbacks
) ;
259 DataBrowserListViewColumnDesc columnDesc
;
260 columnDesc
.headerBtnDesc
.titleOffset
= 0;
261 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
263 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
264 kControlUseFontMask
| kControlUseJustMask
;
266 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlNoContent
;
267 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
268 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
269 columnDesc
.headerBtnDesc
.maximumWidth
= 10000;
271 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
272 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
273 columnDesc
.headerBtnDesc
.titleString
= NULL
; // CFSTR( "" );
275 columnDesc
.propertyDesc
.propertyID
= kTextColumnId
;
276 columnDesc
.propertyDesc
.propertyType
= kDataBrowserTextType
; // kDataBrowserCustomType;
277 columnDesc
.propertyDesc
.propertyFlags
=
278 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
279 kDataBrowserListViewTypeSelectColumn
|
281 kDataBrowserTableViewSelectionColumn
;
283 verify_noerr(m_peer
->AddListViewColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) ) ;
284 verify_noerr(m_peer
->AutoSizeListViewColumns() ) ;
285 verify_noerr(m_peer
->SetHasScrollBars(false , true ) ) ;
286 verify_noerr(m_peer
->SetTableViewHiliteStyle(kDataBrowserTableViewFillHilite
) ) ;
287 verify_noerr(m_peer
->SetListViewHeaderBtnHeight( 0 ) ) ;
290 // shouldn't be necessary anymore under 10.2
291 m_peer
->SetData( kControlNoPart
, kControlDataBrowserIncludesFrameAndFocusTag
, (Boolean
) false ) ;
292 m_peer
->SetNeedsFocusRect( true ) ;
295 MacPostControlCreate(pos
,size
) ;
297 for ( int i
= 0 ; i
< n
; i
++ )
299 Append( choices
[i
] ) ;
302 SetBestSize(size
); // Needed because it is a wxControlWithItems
307 wxListBox::~wxListBox()
309 m_peer
->SetReference( 0 ) ;
311 // avoid access during destruction
318 void wxListBox::FreeData()
320 #if wxUSE_OWNER_DRAWN
321 if ( m_windowStyle
& wxLB_OWNERDRAW
)
323 size_t uiCount
= m_aItems
.Count();
324 while ( uiCount
-- != 0 ) {
325 delete m_aItems
[uiCount
];
326 m_aItems
[uiCount
] = NULL
;
332 #endif // wxUSE_OWNER_DRAWN
333 if ( HasClientObjectData() )
335 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
337 delete GetClientObject(n
);
342 void wxListBox::DoSetSize(int x
, int y
,
343 int width
, int height
,
346 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
349 void wxListBox::DoSetFirstItem(int N
)
354 void wxListBox::Delete(int N
)
356 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
357 wxT("invalid index in wxListBox::Delete") );
359 #if wxUSE_OWNER_DRAWN
361 m_aItems
.RemoveAt(N
);
362 #else // !wxUSE_OWNER_DRAWN
363 if ( HasClientObjectData() )
365 delete GetClientObject(N
);
367 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
368 m_stringArray
.RemoveAt( N
) ;
369 m_dataArray
.RemoveAt( N
) ;
375 int wxListBox::DoAppend(const wxString
& item
)
377 InvalidateBestSize();
379 int index
= m_noItems
;
380 m_stringArray
.Add( item
) ;
381 m_dataArray
.Add( NULL
);
383 DoSetItemClientData( index
, NULL
) ;
389 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
392 int n
= choices
.GetCount();
394 for( int i
= 0 ; i
< n
; ++i
)
398 #if wxUSE_OWNER_DRAWN
399 wxASSERT_MSG(clientData
[i
] == NULL
,
400 wxT("Can't use client data with owner-drawn listboxes"));
401 #else // !wxUSE_OWNER_DRAWN
402 Append( choices
[i
] , clientData
[i
] ) ;
406 Append( choices
[i
] ) ;
409 #if wxUSE_OWNER_DRAWN
410 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
411 // first delete old items
412 size_t ui
= m_aItems
.Count();
413 while ( ui
-- != 0 ) {
419 // then create new ones
420 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
421 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
422 pNewItem
->SetName(choices
[ui
]);
423 m_aItems
.Add(pNewItem
);
426 #endif // wxUSE_OWNER_DRAWN
429 int wxListBox::FindString(const wxString
& s
) const
432 if ( s
.Right(1) == wxT("*") )
434 wxString search
= s
.Left( s
.Length() - 1 ) ;
435 int len
= search
.Length() ;
437 wxMacStringToPascal( search
, s2
) ;
439 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
441 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
443 if ( EqualString( s1
, s2
, false , false ) )
446 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
450 for ( int i
= 0 ; i
< m_noItems
; ++i
)
452 if ( GetString(i
).Lower().Matches(st
) )
462 wxMacStringToPascal( s
, s2
) ;
464 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
466 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
468 if ( EqualString( s1
, s2
, false , false ) )
475 void wxListBox::Clear()
479 m_stringArray
.Empty() ;
480 m_dataArray
.Empty() ;
484 void wxListBox::DoSetSelection(int N
, bool select
)
486 wxCHECK_RET( N
== wxNOT_FOUND
|| (N
>= 0 && N
< m_noItems
) ,
487 wxT("invalid index in wxListBox::SetSelection") );
489 if ( N
== wxNOT_FOUND
)
492 MacSetSelection( N
, select
) ;
495 bool wxListBox::IsSelected(int N
) const
497 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
498 wxT("invalid index in wxListBox::Selected") );
500 return MacIsSelected( N
) ;
503 void *wxListBox::DoGetItemClientData(int N
) const
505 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
506 wxT("invalid index in wxListBox::GetClientData"));
508 return (void *)m_dataArray
[N
];
511 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
513 return (wxClientData
*) DoGetItemClientData( N
) ;
516 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
518 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
519 wxT("invalid index in wxListBox::SetClientData") );
521 #if wxUSE_OWNER_DRAWN
522 if ( m_windowStyle
& wxLB_OWNERDRAW
)
524 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
525 // in OnMeasure/OnDraw.
526 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
528 #endif // wxUSE_OWNER_DRAWN
529 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
531 if ( m_dataArray
.GetCount() > (size_t) N
)
533 m_dataArray
[N
] = (char*) Client_data
;
537 m_dataArray
.Add( (char*) Client_data
) ;
541 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
543 DoSetItemClientData(n
, clientData
);
546 // Return number of selections and an array of selected integers
547 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
549 return MacGetSelections( aSelections
) ;
552 // Get single selection, for single choice list items
553 int wxListBox::GetSelection() const
555 return MacGetSelection() ;
558 // Find string for position
559 wxString
wxListBox::GetString(int N
) const
561 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, wxEmptyString
,
562 wxT("invalid index in wxListBox::GetString") );
564 return m_stringArray
[N
] ;
567 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
569 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
570 wxT("invalid index in wxListBox::InsertItems") );
572 InvalidateBestSize();
574 int nItems
= items
.GetCount();
576 for ( int i
= 0 ; i
< nItems
; i
++ )
578 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
579 m_dataArray
.Insert( NULL
, pos
+ i
) ;
581 MacInsert( pos
+ i
, items
[i
] ) ;
585 void wxListBox::SetString(int N
, const wxString
& s
)
587 m_stringArray
[N
] = s
;
591 wxSize
wxListBox::DoGetBestSize() const
593 int lbWidth
= 100; // some defaults
598 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetTopLevelWindowRef() ) ) ;
602 ::TextFont( m_font
.MacGetFontNum() ) ;
603 ::TextSize( m_font
.MacGetFontSize() ) ;
604 ::TextFace( m_font
.MacGetFontStyle() ) ;
608 ::TextFont( kFontIDMonaco
) ;
613 // Find the widest line
614 for(int i
= 0; i
< GetCount(); i
++) {
615 wxString
str(GetString(i
));
619 ::GetThemeTextDimensions( wxMacCFStringHolder( str
, m_font
.GetEncoding() ) ,
620 kThemeCurrentPortFont
,
627 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
629 lbWidth
= wxMax(lbWidth
, wLine
);
632 // Add room for the scrollbar
633 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
635 // And just a bit more
637 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
640 // don't make the listbox too tall (limit height to around 10 items) but don't
641 // make it too small neither
642 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
645 return wxSize(lbWidth
, lbHeight
);
648 int wxListBox::GetCount() const
653 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
655 wxControl::Refresh( eraseBack
, rect
) ;
658 #if wxUSE_OWNER_DRAWN
660 class wxListBoxItem
: public wxOwnerDrawn
663 wxListBoxItem(const wxString
& str
= "");
666 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
668 // no bitmaps/checkmarks
672 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
674 return new wxListBoxItem();
677 #endif //USE_OWNER_DRAWN
680 // Some custom controls depend on this
681 /* static */ wxVisualAttributes
682 wxListBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
684 wxVisualAttributes attr
;
685 attr
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
686 attr
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
);
687 attr
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
691 // ============================================================================
692 // list box control implementation
693 // ============================================================================
695 void wxListBox::MacDelete( int n
)
697 wxArrayInt selectionBefore
;
698 MacGetSelections( selectionBefore
) ;
700 UInt32 id
= m_noItems
+1 ;
701 verify_noerr( m_peer
->RemoveItems( kDataBrowserNoItem
, 1 , (UInt32
*) &id
, kDataBrowserItemNoProperty
) ) ;
702 for ( size_t i
= 0 ; i
< selectionBefore
.GetCount() ; ++i
)
704 int current
= selectionBefore
[i
] ;
707 // selection was deleted
708 MacSetSelection( current
, false ) ;
710 else if ( current
> n
)
712 // something behind the deleted item was selected -> move up
713 MacSetSelection( current
- 1 , true ) ;
714 MacSetSelection( current
, false ) ;
718 verify_noerr( m_peer
->UpdateItems( kDataBrowserNoItem
, 1 , (UInt32
*) kDataBrowserNoItem
, kDataBrowserItemNoProperty
, kDataBrowserItemNoProperty
) ) ;
721 void wxListBox::MacInsert( int n
, const wxString
& text
)
723 wxArrayInt selectionBefore
;
724 MacGetSelections( selectionBefore
) ;
726 UInt32 id
= m_noItems
; // this has already been increased
727 verify_noerr( m_peer
->AddItems( kDataBrowserNoItem
, 1 , (UInt32
*) &id
, kDataBrowserItemNoProperty
) ) ;
729 for ( int i
= selectionBefore
.GetCount()-1 ; i
>= 0 ; --i
)
731 int current
= selectionBefore
[i
] ;
734 MacSetSelection( current
+ 1 , true ) ;
735 MacSetSelection( current
, false ) ;
740 verify_noerr( m_peer
->UpdateItems( kDataBrowserNoItem
, 1 , (UInt32
*) kDataBrowserNoItem
, kDataBrowserItemNoProperty
, kDataBrowserItemNoProperty
) ) ;
743 void wxListBox::MacAppend( const wxString
& text
)
745 UInt32 id
= m_noItems
; // this has already been increased
746 verify_noerr( m_peer
->AddItems( kDataBrowserNoItem
, 1 , (UInt32
*) &id
, kDataBrowserItemNoProperty
) ) ;
747 // no need to deal with selections nor refreshed, as we have appended
750 void wxListBox::MacClear()
752 verify_noerr( m_peer
->RemoveItems( kDataBrowserNoItem
, 0 , NULL
, kDataBrowserItemNoProperty
) ) ;
755 void wxListBox::MacDeselectAll()
757 bool former
= MacSuppressSelection( true ) ;
758 verify_noerr(m_peer
->SetSelectedItems( 0 , NULL
, kDataBrowserItemsRemove
) ) ;
759 MacSuppressSelection( former
) ;
762 void wxListBox::MacSetSelection( int n
, bool select
)
764 bool former
= MacSuppressSelection( true ) ;
767 if ( m_peer
->IsItemSelected( id
) != select
)
770 verify_noerr(m_peer
->SetSelectedItems( 1 , & id
, HasMultipleSelection() ? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
) ) ;
772 verify_noerr(m_peer
->SetSelectedItems( 1 , & id
, kDataBrowserItemsRemove
) ) ;
775 MacSuppressSelection( former
) ;
778 bool wxListBox::MacSuppressSelection( bool suppress
)
780 bool former
= m_suppressSelection
;
781 m_suppressSelection
= suppress
;
785 bool wxListBox::MacIsSelected( int n
) const
787 return m_peer
->IsItemSelected( n
+ 1 ) ;
790 int wxListBox::MacGetSelection() const
792 for ( int i
= 0 ; i
< GetCount() ; ++i
)
794 if ( m_peer
->IsItemSelected( i
+ 1 ) )
802 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
808 UInt32 first
, last
;
809 m_peer
->GetSelectionAnchor( &first
, &last
) ;
810 if ( first
!= kDataBrowserNoItem
)
812 for ( size_t i
= first
; i
<= last
; ++i
)
814 if ( m_peer
->IsItemSelected( i
) )
816 aSelections
.Add( i
- 1 ) ;
824 void wxListBox::MacSet( int n
, const wxString
& text
)
826 // as we don't store the strings we only have to issue a redraw
828 verify_noerr( m_peer
->UpdateItems( kDataBrowserNoItem
, 1 , &id
, kDataBrowserItemNoProperty
, kDataBrowserItemNoProperty
) ) ;
831 void wxListBox::MacScrollTo( int n
)
834 verify_noerr( m_peer
->RevealItem( id
, kTextColumnId
, kDataBrowserRevealWithoutSelecting
) ) ;
837 #if !TARGET_API_MAC_OSX
839 void wxListBox::OnChar(wxKeyEvent
& event
)
841 // todo trigger proper events here
845 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
847 wxWindow
* parent
= GetParent() ;
848 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
849 parent
= parent
->GetParent() ;
851 if ( parent
&& parent
->GetDefaultItem() )
853 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
855 if ( def
&& def
->IsEnabled() )
857 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
858 event
.SetEventObject(def
);
865 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
866 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
868 // FIXME: look in ancestors, not just parent.
869 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
872 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
873 new_event
.SetEventObject( win
);
874 win
->GetEventHandler()->ProcessEvent( new_event
);
877 else if ( event
.GetKeyCode() == WXK_TAB
)
879 wxNavigationKeyEvent new_event
;
880 new_event
.SetEventObject( this );
881 new_event
.SetDirection( !event
.ShiftDown() );
882 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
883 new_event
.SetWindowChange( event
.ControlDown() );
884 new_event
.SetCurrentFocus( this );
885 if ( !GetEventHandler()->ProcessEvent( new_event
) )
888 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
890 // perform the default key handling first
891 wxControl::OnKeyDown( event
) ;
893 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
894 event
.SetEventObject( this );
896 wxArrayInt aSelections
;
897 int n
, count
= GetSelections(aSelections
);
901 if ( HasClientObjectData() )
902 event
.SetClientObject( GetClientObject(n
) );
903 else if ( HasClientUntypedData() )
904 event
.SetClientData( GetClientData(n
) );
905 event
.SetString( GetString(n
) );
914 GetEventHandler()->ProcessEvent(event
);
918 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
920 m_typeIn
= wxEmptyString
;
922 m_lastTypeIn
= event
.GetTimestamp() ;
923 m_typeIn
+= (char) event
.GetKeyCode() ;
924 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
927 if ( GetSelection() != line
)
930 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
931 event
.SetEventObject( this );
933 if ( HasClientObjectData() )
934 event
.SetClientObject( GetClientObject( line
) );
935 else if ( HasClientUntypedData() )
936 event
.SetClientData( GetClientData(line
) );
937 event
.SetString( GetString(line
) );
941 GetEventHandler()->ProcessEvent(event
);
947 #endif // !TARGET_API_MAC_OSX