From: Stefan Csomor <csomor@advancedconcepts.ch>
Date: Sat, 11 May 2002 06:54:50 +0000 (+0000)
Subject: key handling
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ecaf6c1897ba205c2800f8954249c49b3f6eb937

key handling


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15506 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---

diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp
index 9a10e64d29..557d05f213 100644
--- a/src/mac/carbon/listbox.cpp
+++ b/src/mac/carbon/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
 
@@ -319,7 +320,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 --;
     
@@ -427,6 +428,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 )
             {
@@ -831,5 +833,60 @@ 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 )
+	{
+	  ::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) ;
+	  }
+	}
+}
+
diff --git a/src/mac/listbox.cpp b/src/mac/listbox.cpp
index 9a10e64d29..557d05f213 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
 
@@ -319,7 +320,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 --;
     
@@ -427,6 +428,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 )
             {
@@ -831,5 +833,60 @@ 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 )
+	{
+	  ::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) ;
+	  }
+	}
+}
+