]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/choice.mm
Workaround for #15404: wxRichTextCtrl: caret does not disappear when focus is lost...
[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
dbeddfb9
SC
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{
dbeddfb9
SC
26}
27
dbeddfb9
SC
28@end
29
30@implementation wxNSPopUpButton
31
4dd9fdf8 32+ (void)initialize
dbeddfb9 33{
4dd9fdf8 34 static BOOL initialized = NO;
03647350 35 if (!initialized)
dbeddfb9 36 {
4dd9fdf8
SC
37 initialized = YES;
38 wxOSXCocoaClassAddWXMethods( self );
dbeddfb9
SC
39 }
40}
41
dbeddfb9
SC
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
026e7dcb
SC
54@interface NSView(PossibleSizeMethods)
55- (NSControlSize)controlSize;
56@end
57
58class wxChoiceCocoaImpl : public wxWidgetCocoaImpl
59{
60public:
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
03647350
VZ
101wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer,
102 wxWindowMac* WXUNUSED(parent),
103 wxWindowID WXUNUSED(id),
dbeddfb9 104 wxMenu* menu,
03647350 105 const wxPoint& pos,
dbeddfb9 106 const wxSize& size,
03647350 107 long WXUNUSED(style),
d8207702 108 long WXUNUSED(extraStyle))
dbeddfb9 109{
dbeddfb9
SC
110 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
111 wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO];
dbeddfb9 112 [v setMenu: menu->GetHMenu()];
cc3fcdff 113 [v setAutoenablesItems:NO];
026e7dcb 114 wxWidgetCocoaImpl* c = new wxChoiceCocoaImpl( wxpeer, v );
dbeddfb9
SC
115 return c;
116}
117
118#endif // wxUSE_CHOICE