]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/listbox.mm
Set default attributes after a SetSelection
[wxWidgets.git] / src / cocoa / listbox.mm
index 08603883be013dda4e254806ef2d073b06f14911..0d24e92f68a8ef4f7a0572bde66807b1fc1fb9a9 100644 (file)
 
 #include "wx/cocoa/string.h"
 #include "wx/cocoa/autorelease.h"
+#include "wx/cocoa/ObjcRef.h"
+#include "wx/cocoa/private/scrollview.h"
 #include "wx/cocoa/NSTableDataSource.h"
 
 #import <Foundation/NSArray.h>
 #import <Foundation/NSEnumerator.h>
 #import <AppKit/NSTableView.h>
 #import <AppKit/NSTableColumn.h>
+#import <AppKit/NSScrollView.h>
 
-IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
+IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControlWithItems)
 BEGIN_EVENT_TABLE(wxListBox, wxListBoxBase)
 END_EVENT_TABLE()
 WX_IMPLEMENT_COCOA_OWNER(wxListBox,NSTableView,NSControl,NSView)
@@ -83,7 +86,7 @@ The listbox contents are sorted in alphabetical order.
         return false;
 
     // Provide the data
-    m_cocoaItems = [[NSMutableArray arrayWithCapacity:n] retain];
+    m_cocoaItems = wxGCSafeRetain([NSMutableArray arrayWithCapacity:n]);
     for(int i=0; i < n; i++)
     {
         [m_cocoaItems addObject: wxNSStringWithWxString(choices[i])];
@@ -115,6 +118,15 @@ The listbox contents are sorted in alphabetical order.
     CocoaCreateNSScrollView();
     SetInitialFrameRect(pos,size);
 
+    [m_wxCocoaScrollView->GetNSScrollView() setHasVerticalScroller:YES];
+    // Pre-10.3: Always show vertical scroller, never show horizontal scroller
+    // Post-10.3: Show scrollers dynamically (turn them both on, set auto-hide)
+    if([m_wxCocoaScrollView->GetNSScrollView() respondsToSelector:@selector(setAutohidesScrollers:)])
+    {
+        [m_wxCocoaScrollView->GetNSScrollView() setHasHorizontalScroller:YES];
+        [m_wxCocoaScrollView->GetNSScrollView() setAutohidesScrollers:YES];
+    }
+
     // Set up extended/multiple selection flags
     if ((style & wxLB_EXTENDED) || (style & wxLB_MULTIPLE))
         //diff is that mult requires shift down for multi selection
@@ -129,7 +141,8 @@ wxListBox::~wxListBox()
 {
     [GetNSTableView() setDataSource: nil];
     [m_cocoaDataSource release];
-    [m_cocoaItems release];
+    wxGCSafeRelease(m_cocoaItems);
+    m_cocoaItems = nil;
     DisassociateNSTableView(GetNSTableView());
 }