]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/choice.mm
fixing osx_cocoa, there's a reason m_peer is private in the base class
[wxWidgets.git] / src / osx / cocoa / choice.mm
index 01ba759f82cd7f044f1d6185fe697f9b5a343333..0d70d6610d6762802077d061b04937031eb38e7e 100644 (file)
@@ -4,7 +4,7 @@
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     1998-01-01
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     1998-01-01
-// RCS-ID:      $Id: choice.cpp 54129 2008-06-11 19:30:52Z SC $
+// RCS-ID:      $Id$
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 @interface wxNSPopUpButton : NSPopUpButton
 {
 
 @interface wxNSPopUpButton : NSPopUpButton
 {
-    WXCOCOAIMPL_COMMON_MEMBERS
 }
 
 }
 
-WXCOCOAIMPL_COMMON_INTERFACE
-
-- (void) clickedAction: (id) sender;
-
 @end
 
 @implementation wxNSPopUpButton
 
 @end
 
 @implementation wxNSPopUpButton
 
-- (id)initWithFrame:(NSRect)frame pullsDown:(BOOL) pd
++ (void)initialize
 {
 {
-    [super initWithFrame:frame pullsDown:pd];
-    impl = NULL;
-    [self setTarget: self];
-    [self setAction: @selector(clickedAction:)];
-    return self;
-}
-
-- (void) clickedAction: (id) sender
-{
-    if ( impl )
+    static BOOL initialized = NO;
+    if (!initialized)
     {
     {
-        wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
-        if ( wxpeer )
-            wxpeer->HandleClicked(0);
+        initialized = YES;
+        wxOSXCocoaClassAddWXMethods( self );
     }
 }
 
     }
 }
 
-WXCOCOAIMPL_COMMON_IMPLEMENTATION
-
 - (int) intValue
 {
    return [self indexOfSelectedItem];
 - (int) intValue
 {
    return [self indexOfSelectedItem];
@@ -68,20 +52,67 @@ WXCOCOAIMPL_COMMON_IMPLEMENTATION
 
 @end
 
 
 @end
 
-wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer, 
-                                    wxWindowMac* parent, 
-                                    wxWindowID id, 
+@interface NSView(PossibleSizeMethods)
+- (NSControlSize)controlSize;
+@end
+
+class wxChoiceCocoaImpl : public wxWidgetCocoaImpl
+{
+public:
+    wxChoiceCocoaImpl(wxWindowMac *wxpeer, wxNSPopUpButton *v)
+    : wxWidgetCocoaImpl(wxpeer, v)
+    {
+    }
+    
+    void GetLayoutInset(int &left , int &top , int &right, int &bottom) const
+    {
+        left = top = right = bottom = 0;
+        NSControlSize size = NSRegularControlSize;
+        if ( [m_osxView respondsToSelector:@selector(controlSize)] )
+            size = [m_osxView controlSize];
+        else if ([m_osxView respondsToSelector:@selector(cell)])
+        {
+            id cell = [(id)m_osxView cell];
+            if ([cell respondsToSelector:@selector(controlSize)])
+                size = [cell controlSize];
+        }
+        
+        switch( size )
+        {
+            case NSRegularControlSize:
+                left = right = 3;
+                top = 2;
+                bottom = 4;
+                break;
+            case NSSmallControlSize:
+                left = right = 3;
+                top = 1;
+                bottom = 4;
+                break;
+            case NSMiniControlSize:
+                left = 1;
+                right = 2;
+                top = 0;
+                bottom = 0;
+                break;
+        }
+    }
+};
+
+wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer,
+                                    wxWindowMac* WXUNUSED(parent),
+                                    wxWindowID WXUNUSED(id),
                                     wxMenu* menu,
                                     wxMenu* menu,
-                                    const wxPoint& pos, 
+                                    const wxPoint& pos,
                                     const wxSize& size,
                                     const wxSize& size,
-                                    long style, 
-                                    long extraStylew)
+                                    long WXUNUSED(style),
+                                    long WXUNUSED(extraStyle))
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO];
     [v setMenu: menu->GetHMenu()];
 {
     NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
     wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO];
     [v setMenu: menu->GetHMenu()];
-    wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v );
-    [v setImplementation:c];
+    [v setAutoenablesItems:NO];
+    wxWidgetCocoaImpl* c = new wxChoiceCocoaImpl( wxpeer, v );
     return c;
 }
 
     return c;
 }