]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/choice.mm
The alignment controls are now left-aligned if the floating controls are not shown.
[wxWidgets.git] / src / osx / cocoa / choice.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/choice.mm
3 // Purpose: wxChoice
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #if wxUSE_CHOICE
14
15 #include "wx/choice.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/menu.h"
19 #include "wx/dcclient.h"
20 #endif
21
22 #include "wx/osx/private.h"
23
24 @interface wxNSPopUpButton : NSPopUpButton
25 {
26 }
27
28 @end
29
30 @implementation wxNSPopUpButton
31
32 + (void)initialize
33 {
34 static BOOL initialized = NO;
35 if (!initialized)
36 {
37 initialized = YES;
38 wxOSXCocoaClassAddWXMethods( self );
39 }
40 }
41
42 - (int) intValue
43 {
44 return [self indexOfSelectedItem];
45 }
46
47 - (void) setIntValue: (int) v
48 {
49 [self selectItemAtIndex:v];
50 }
51
52 @end
53
54 @interface NSView(PossibleSizeMethods)
55 - (NSControlSize)controlSize;
56 @end
57
58 class wxChoiceCocoaImpl : public wxWidgetCocoaImpl
59 {
60 public:
61 wxChoiceCocoaImpl(wxWindowMac *wxpeer, wxNSPopUpButton *v)
62 : wxWidgetCocoaImpl(wxpeer, v)
63 {
64 }
65
66 void GetLayoutInset(int &left , int &top , int &right, int &bottom) const
67 {
68 left = top = right = bottom = 0;
69 NSControlSize size = NSRegularControlSize;
70 if ( [m_osxView respondsToSelector:@selector(controlSize)] )
71 size = [m_osxView controlSize];
72 else if ([m_osxView respondsToSelector:@selector(cell)])
73 {
74 id cell = [(id)m_osxView cell];
75 if ([cell respondsToSelector:@selector(controlSize)])
76 size = [cell controlSize];
77 }
78
79 switch( size )
80 {
81 case NSRegularControlSize:
82 left = right = 3;
83 top = 2;
84 bottom = 4;
85 break;
86 case NSSmallControlSize:
87 left = right = 3;
88 top = 1;
89 bottom = 4;
90 break;
91 case NSMiniControlSize:
92 left = 1;
93 right = 2;
94 top = 0;
95 bottom = 0;
96 break;
97 }
98 }
99 };
100
101 wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer,
102 wxWindowMac* WXUNUSED(parent),
103 wxWindowID WXUNUSED(id),
104 wxMenu* menu,
105 const wxPoint& pos,
106 const wxSize& size,
107 long WXUNUSED(style),
108 long WXUNUSED(extraStyle))
109 {
110 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
111 wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO];
112 [v setMenu: menu->GetHMenu()];
113 [v setAutoenablesItems:NO];
114 wxWidgetCocoaImpl* c = new wxChoiceCocoaImpl( wxpeer, v );
115 return c;
116 }
117
118 #endif // wxUSE_CHOICE