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