]>
Commit | Line | Data |
---|---|---|
4ddfa282 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/cocoa/combobox.mm | |
3 | // Purpose: wxChoice | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id: combobox.mm 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 | ||
c84030e0 | 14 | #if wxUSE_COMBOBOX |
4ddfa282 SC |
15 | |
16 | #include "wx/combobox.h" | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/menu.h" | |
20 | #include "wx/dcclient.h" | |
21 | #endif | |
22 | ||
c84030e0 | 23 | #include "wx/osx/cocoa/private/textimpl.h" |
4ddfa282 SC |
24 | |
25 | // work in progress | |
26 | ||
27 | @interface wxNSComboBox : NSComboBox | |
28 | { | |
29 | } | |
30 | ||
31 | @end | |
32 | ||
33 | @implementation wxNSComboBox | |
34 | ||
35 | + (void)initialize | |
36 | { | |
37 | static BOOL initialized = NO; | |
38 | if (!initialized) | |
39 | { | |
40 | initialized = YES; | |
41 | wxOSXCocoaClassAddWXMethods( self ); | |
42 | } | |
43 | } | |
44 | ||
c84030e0 | 45 | - (void)controlTextDidChange:(NSNotification *)aNotification |
4ddfa282 | 46 | { |
c84030e0 KO |
47 | wxUnusedVar(aNotification); |
48 | wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); | |
49 | if ( impl ) | |
50 | { | |
51 | wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); | |
52 | if ( wxpeer ) { | |
53 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId()); | |
54 | event.SetEventObject( wxpeer ); | |
55 | event.SetString( static_cast<wxComboBox*>(wxpeer)->GetValue() ); | |
56 | wxpeer->HandleWindowEvent( event ); | |
57 | } | |
58 | } | |
4ddfa282 SC |
59 | } |
60 | ||
c84030e0 | 61 | - (void)comboBoxSelectionDidChange:(NSNotification *)notification |
4ddfa282 | 62 | { |
c84030e0 KO |
63 | wxUnusedVar(notification); |
64 | wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); | |
65 | if ( impl ) | |
66 | { | |
67 | wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer(); | |
68 | if ( wxpeer ) { | |
69 | wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, wxpeer->GetId()); | |
70 | event.SetEventObject( wxpeer ); | |
71 | event.SetInt( static_cast<wxComboBox*>(wxpeer)->GetSelection() ); | |
72 | // For some reason, wxComboBox::GetValue will not return the newly selected item | |
73 | // while we're inside this callback, so use AddPendingEvent to make sure | |
74 | // GetValue() returns the right value. | |
75 | wxpeer->GetEventHandler()->AddPendingEvent( event ); | |
76 | } | |
77 | } | |
4ddfa282 | 78 | } |
4ddfa282 SC |
79 | @end |
80 | ||
c84030e0 KO |
81 | wxNSComboBoxControl::wxNSComboBoxControl( wxWindow *wxPeer, WXWidget w ) : wxNSTextFieldControl(wxPeer, w) |
82 | { | |
83 | m_comboBox = (NSComboBox*)w; | |
84 | } | |
85 | ||
86 | wxNSComboBoxControl::~wxNSComboBoxControl() | |
87 | { | |
88 | } | |
89 | ||
90 | int wxNSComboBoxControl::GetSelectedItem() const | |
91 | { | |
92 | return [m_comboBox indexOfSelectedItem]; | |
93 | } | |
94 | ||
95 | void wxNSComboBoxControl::SetSelectedItem(int item) | |
96 | { | |
97 | [m_comboBox selectItemAtIndex: item]; | |
98 | } | |
99 | ||
100 | int wxNSComboBoxControl::GetNumberOfItems() const | |
101 | { | |
102 | return [m_comboBox numberOfItems]; | |
103 | } | |
104 | ||
105 | void wxNSComboBoxControl::InsertItem(int pos, const wxString& item) | |
106 | { | |
107 | [m_comboBox insertItemWithObjectValue:wxCFStringRef( item , m_wxPeer->GetFont().GetEncoding() ).AsNSString() atIndex:pos]; | |
108 | } | |
109 | ||
110 | void wxNSComboBoxControl::RemoveItem(int pos) | |
111 | { | |
112 | [m_comboBox removeItemAtIndex:pos]; | |
113 | } | |
114 | ||
115 | void wxNSComboBoxControl::Clear() | |
116 | { | |
117 | [m_comboBox removeAllItems]; | |
118 | } | |
119 | ||
120 | wxString wxNSComboBoxControl::GetStringAtIndex(int pos) const | |
121 | { | |
122 | return wxCFStringRef::AsString([m_comboBox itemObjectValueAtIndex:pos], m_wxPeer->GetFont().GetEncoding()); | |
123 | } | |
124 | ||
125 | int wxNSComboBoxControl::FindString(const wxString& text) const | |
126 | { | |
127 | return [m_comboBox indexOfItemWithObjectValue:wxCFStringRef( text , m_wxPeer->GetFont().GetEncoding() ).AsNSString()]; | |
128 | } | |
129 | ||
4ddfa282 SC |
130 | wxWidgetImplType* wxWidgetImpl::CreateComboBox( wxWindowMac* wxpeer, |
131 | wxWindowMac* WXUNUSED(parent), | |
132 | wxWindowID WXUNUSED(id), | |
133 | wxMenu* menu, | |
134 | const wxPoint& pos, | |
135 | const wxSize& size, | |
136 | long WXUNUSED(style), | |
137 | long WXUNUSED(extraStyle)) | |
138 | { | |
139 | NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; | |
f941a30b | 140 | wxNSComboBox* v = [[wxNSComboBox alloc] initWithFrame:r]; |
c84030e0 | 141 | wxNSComboBoxControl* c = new wxNSComboBoxControl( wxpeer, v ); |
4ddfa282 SC |
142 | return c; |
143 | } | |
144 | ||
c84030e0 | 145 | #endif // wxUSE_COMBOBOX |