]>
Commit | Line | Data |
---|---|---|
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 | |
7 | // RCS-ID: $Id: choice.cpp 54129 2008-06-11 19:30:52Z 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 | { | |
27 | wxWidgetImpl* impl; | |
28 | } | |
29 | ||
30 | - (void)setImplementation: (wxWidgetImpl *) theImplementation; | |
31 | - (wxWidgetImpl*) implementation; | |
32 | - (BOOL) isFlipped; | |
33 | - (void) clickedAction: (id) sender; | |
34 | ||
35 | @end | |
36 | ||
37 | @implementation wxNSPopUpButton | |
38 | ||
39 | - (id)initWithFrame:(NSRect)frame pullsDown:(BOOL) pd | |
40 | { | |
41 | [super initWithFrame:frame pullsDown:pd]; | |
42 | impl = NULL; | |
43 | [self setTarget: self]; | |
44 | [self setAction: @selector(clickedAction:)]; | |
45 | return self; | |
46 | } | |
47 | ||
48 | - (void) clickedAction: (id) sender | |
49 | { | |
50 | if ( impl ) | |
51 | { | |
52 | wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); | |
53 | if ( wxpeer ) | |
54 | wxpeer->HandleClicked(0); | |
55 | } | |
56 | } | |
57 | ||
58 | - (void)setImplementation: (wxWidgetImpl *) theImplementation | |
59 | { | |
60 | impl = theImplementation; | |
61 | } | |
62 | ||
63 | - (wxWidgetImpl*) implementation | |
64 | { | |
65 | return impl; | |
66 | } | |
67 | ||
68 | - (BOOL) isFlipped | |
69 | { | |
70 | return YES; | |
71 | } | |
72 | ||
73 | - (int) intValue | |
74 | { | |
75 | return [self indexOfSelectedItem]; | |
76 | } | |
77 | ||
78 | - (void) setIntValue: (int) v | |
79 | { | |
80 | [self selectItemAtIndex:v]; | |
81 | } | |
82 | ||
83 | @end | |
84 | ||
85 | wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer, | |
86 | wxWindowMac* parent, | |
87 | wxWindowID id, | |
88 | wxMenu* menu, | |
89 | const wxPoint& pos, | |
90 | const wxSize& size, | |
91 | long style, | |
92 | long extraStylew) | |
93 | { | |
94 | NSView* sv = (wxpeer->GetParent()->GetHandle() ); | |
95 | ||
96 | NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; | |
97 | wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO]; | |
98 | [sv addSubview:v]; | |
99 | [v setMenu: menu->GetHMenu()]; | |
100 | wxWidgetCocoaImpl* c = new wxWidgetCocoaImpl( wxpeer, v ); | |
101 | [v setImplementation:c]; | |
102 | return c; | |
103 | } | |
104 | ||
105 | #endif // wxUSE_CHOICE |