X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/573ac9dc6e94c0256089700d2fafac486c957b5a..327788acc5e4915df4e9e97db7fb08a4c4a00cdd:/src/mac/listbox.cpp diff --git a/src/mac/listbox.cpp b/src/mac/listbox.cpp index 91595e5f38..f4ddc539b3 100644 --- a/src/mac/listbox.cpp +++ b/src/mac/listbox.cpp @@ -26,7 +26,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl) BEGIN_EVENT_TABLE(wxListBox, wxControl) - EVT_SIZE( wxListBox::OnSize ) + EVT_SIZE( wxListBox::OnSize ) + EVT_CHAR( wxListBox::OnChar ) END_EVENT_TABLE() #endif @@ -64,7 +65,6 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect Cell cell, short dataOffset, short dataLength, ListHandle listHandle ) { - FontInfo fontInfo; GrafPtr savePort; GrafPtr grafPtr; RgnHandle savedClipRegion; @@ -195,7 +195,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, #else long result ; - + wxStAppResource resload ; m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , kwxMacListWithVerticalScrollbar , 0 , 0, kControlListBoxProc , (long) this ) ; @@ -246,7 +246,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, wxListBox::~wxListBox() { - Free() ; + FreeData() ; if ( m_macList ) { #if !TARGET_CARBON @@ -257,7 +257,7 @@ wxListBox::~wxListBox() } } -void wxListBox::Free() +void wxListBox::FreeData() { #if wxUSE_OWNER_DRAWN if ( m_windowStyle & wxLB_OWNERDRAW ) @@ -265,6 +265,7 @@ void wxListBox::Free() size_t uiCount = m_aItems.Count(); while ( uiCount-- != 0 ) { delete m_aItems[uiCount]; + m_aItems[uiCount] = NULL; } m_aItems.Clear(); @@ -320,7 +321,7 @@ void wxListBox::Delete(int N) delete GetClientObject(N); } #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN - m_stringArray.Remove( N ) ; + m_stringArray.RemoveAt( N ) ; m_dataArray.RemoveAt( N ) ; m_noItems --; @@ -373,6 +374,7 @@ void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData) size_t ui = m_aItems.Count(); while ( ui-- != 0 ) { delete m_aItems[ui]; + m_aItems[ui] = NULL; } m_aItems.Empty(); @@ -428,6 +430,7 @@ int wxListBox::FindString(const wxString& st) const } if ( s.Left(1) == "*" && s.Length() > 1 ) { + s = st ; s.MakeLower() ; for ( int i = 0 ; i < m_noItems ; ++i ) { @@ -465,7 +468,7 @@ int wxListBox::FindString(const wxString& st) const void wxListBox::Clear() { - Free(); + FreeData(); m_noItems = 0; m_stringArray.Empty() ; m_dataArray.Empty() ; @@ -596,7 +599,7 @@ int wxListBox::GetCount() const void wxListBox::SetupColours() { - SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW)); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); SetForegroundColour(GetParent()->GetForegroundColour()); } @@ -681,10 +684,10 @@ void wxListBox::MacSetSelection( int n , bool select ) Cell cell = { 0 , 0 } ; if ( ! (m_windowStyle & wxLB_MULTIPLE) ) { - if ( LGetSelect( true , &cell , (ListHandle)m_macList ) ) - { - LSetSelect( false , cell , (ListHandle)m_macList ) ; - } + if ( LGetSelect( true , &cell , (ListHandle)m_macList ) ) + { + LSetSelect( false , cell , (ListHandle)m_macList ) ; + } } cell.v = n ; @@ -832,5 +835,62 @@ void wxListBox::MacDoDoubleClick() { wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId); event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event) ; + GetEventHandler()->ProcessEvent(event) ; } + +static long sLastTypeIn = 0 ; + +void wxListBox::OnChar(wxKeyEvent& event) +{ + EventRecord *ev = (EventRecord*) (wxTheApp->MacGetCurrentEvent() ) ; + short keycode ; + short keychar ; + keychar = short(ev->message & charCodeMask); + keycode = short(ev->message & keyCodeMask) >> 8 ; + if ( event.KeyCode() == WXK_SPACE ) + { + wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); + event.SetEventObject( this ); + + wxArrayInt aSelections; + int n, count = GetSelections(aSelections); + if ( count > 0 ) + { + n = aSelections[0]; + if ( HasClientObjectData() ) + event.SetClientObject( GetClientObject(n) ); + else if ( HasClientUntypedData() ) + event.SetClientData( GetClientData(n) ); + event.SetString( GetString(n) ); + } + else + { + n = -1; + } + + event.m_commandInt = n; + + GetEventHandler()->ProcessEvent(event); + } + else if ( event.KeyCode() == WXK_DOWN || event.KeyCode() == WXK_UP ) + { + // default handling + event.Skip() ; +// ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ; + } + else + { + if ( ev->when > m_lastTypeIn + 60 ) + { + m_typeIn = "" ; + } + m_lastTypeIn = ev->when ; + m_typeIn += (char) event.KeyCode() ; + int line = FindString("*"+m_typeIn+"*") ; + if ( line >= 0 ) + { + SetSelection(line) ; + } + } +} +