]> git.saurik.com Git - wxWidgets.git/commitdiff
common event code
authorStefan Csomor <csomor@advancedconcepts.ch>
Tue, 13 Jan 2009 18:19:42 +0000 (18:19 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Tue, 13 Jan 2009 18:19:42 +0000 (18:19 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58077 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/carbon/listbox.h
src/osx/carbon/listbox.cpp
src/osx/cocoa/listbox.mm
src/osx/listbox_osx.cpp

index e2fc661e1c4520ce60d2a034a28aa55597b93aa3..bf01a78fecd5de48c6ec094cd02b9f3d277dda27 100644 (file)
@@ -122,6 +122,7 @@ public:
     
     bool MacGetBlockEvents() const { return m_blockEvents; }
 
+    virtual void HandleLineEvent( unsigned int n, bool doubleClick );
 protected:
     // callback for derived classes which may have to insert additional data
     // at a certain line - which cannot be predetermined for sorted list data
index 23f6443ba019112b2bbdd348a25b5fe72cec1c52..148167afc03a93d5f598d0e5a144bea3ebe7368e 100644 (file)
@@ -250,16 +250,7 @@ void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl *owner ,
     if (message == kDataBrowserItemDoubleClicked)
     {
         unsigned int n = owner->GetLineFromItem( this );
-        wxCommandEvent event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, list->GetId() );
-        event.SetEventObject( list );
-        if ( list->HasClientObjectData() )
-            event.SetClientObject( list->GetClientObject(n) );
-        else if ( list->HasClientUntypedData() )
-            event.SetClientData( list->GetClientData(n) );
-        event.SetString( list->GetString(n) );
-        event.SetInt( n );
-        event.SetExtraLong( 1 );
-        list->HandleWindowEvent(event);
+        list->HandleLineEvent( n, true );
         return;
     }
 }
@@ -374,15 +365,7 @@ void wxMacDataBrowserListControl::ItemNotification(
         int sel = list->GetSelection();
         if ((sel < 0) || (sel > (int) list->GetCount()))  // OS X can select an item below the last item (why?)
            return;
-        event.SetEventObject( list );
-        if ( list->HasClientObjectData() )
-            event.SetClientObject( list->GetClientObject( sel ) );
-        else if ( list->HasClientUntypedData() )
-            event.SetClientData( list->GetClientData( sel ) );
-        event.SetString( list->GetString( sel ) );
-        event.SetInt( sel );
-        event.SetExtraLong( 1 );
-        list->HandleWindowEvent(event);
+        list->HandleLineEvent( sel, false );
         return;
     }
     
index 5297c16508d2b24a21fadc1cc278e0bbdeb172e8..94d57afad60cbb0105b5d1855f121242bb4f60a0 100644 (file)
@@ -59,6 +59,8 @@ class wxListWidgetCocoaImpl;
 
 - (void)setImplementation: (wxListWidgetCocoaImpl *) theImplementation;
 - (wxListWidgetCocoaImpl*) implementation;
+- (void)clickedAction: (id) sender;
+- (void)doubleClickedAction: (id) sender;
 
 @end
 
@@ -282,6 +284,47 @@ protected:
     return impl;
 }
 
+- (id) init
+{
+    [super init];
+    impl = NULL;
+    [self setTarget: self];
+    [self setAction: @selector(clickedAction:)];
+    [self setDoubleAction: @selector(doubleClickedAction:)];
+    return self;
+}
+
+- (void) clickedAction: (id) sender
+{
+    if ( impl )
+    {
+        wxListBox *list = static_cast<wxListBox*> ( impl->GetWXPeer());
+        wxCHECK_RET( list != NULL , wxT("Listbox expected"));
+
+        wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() );
+
+        int sel = [self clickedRow];
+        if ((sel < 0) || (sel > (int) list->GetCount()))  // OS X can select an item below the last item (why?)
+           return;
+           
+        list->HandleLineEvent( sel, false );
+    }
+}
+
+- (void) doubleClickedAction: (id) sender
+{
+    if ( impl )
+    {
+        wxListBox *list = static_cast<wxListBox*> ( impl->GetWXPeer());
+        wxCHECK_RET( list != NULL , wxT("Listbox expected"));
+
+        int sel = [self clickedRow];
+        if ((sel < 0) || (sel > (int) list->GetCount()))  // OS X can select an item below the last item (why?)
+           return;
+
+        list->HandleLineEvent( sel, true );
+    }
+}
 
 @end
 
@@ -428,17 +471,27 @@ void wxListWidgetCocoaImpl::ListSetSelection( unsigned int n, bool select, bool
 
 int wxListWidgetCocoaImpl::ListGetSelection() const 
 {
-    return 0;
+    return [m_tableView selectedRow];
 }
 
 int wxListWidgetCocoaImpl::ListGetSelections( wxArrayInt& aSelections ) const 
 {
-    return 0;
+    aSelections.Empty();
+
+    int count = ListGetCount();
+
+    for ( int i = 0; i < count; ++i)
+    {
+        if ([m_tableView isRowSelected:count])
+        aSelections.Add(i);
+    }
+
+    return aSelections.Count();
 }
 
 bool wxListWidgetCocoaImpl::ListIsSelected( unsigned int n ) const 
 {
-    return false;
+    return [m_tableView isRowSelected:n];
 }
 
 // display
index e138470caee91944ed8a8da4bc066ee755c9e393..3b74cc851e2a05ddfcd64275d7d11763e6c86803 100644 (file)
@@ -370,4 +370,23 @@ void wxListBox::SetString(unsigned int n, const wxString& s)
     GetListPeer()->UpdateLine(n);
 }
 
+//
+// common event handling
+//
+
+void wxListBox::HandleLineEvent( unsigned int n, bool doubleClick )
+{
+    wxCommandEvent event( doubleClick ? wxEVT_COMMAND_LISTBOX_DOUBLECLICKED : 
+        wxEVT_COMMAND_LISTBOX_SELECTED, GetId() );
+    event.SetEventObject( this );
+    if ( HasClientObjectData() )
+        event.SetClientObject( GetClientObject(n) );
+    else if ( HasClientUntypedData() )
+        event.SetClientData( GetClientData(n) );
+    event.SetString( GetString(n) );
+    event.SetInt( n );
+    event.SetExtraLong( 1 );
+    HandleWindowEvent(event);
+}
+
 #endif // wxUSE_LISTBOX