]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/menu.mm
Added style metadata for selected controls
[wxWidgets.git] / src / cocoa / menu.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/menu.cpp
3 // Purpose: wxMenu and wxMenuBar implementation
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2002/12/09
7 // RCS-ID: $Id:
8 // Copyright: (c) 2002 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21 #ifndef WX_PRECOMP
22 #include "wx/menu.h"
23 #include "wx/log.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/cocoa/autorelease.h"
27
28 #import <Foundation/NSString.h>
29 #import <AppKit/NSMenu.h>
30
31 #if wxUSE_MENUS
32
33 // ----------------------------------------------------------------------------
34 // globals
35 // ----------------------------------------------------------------------------
36
37 // ============================================================================
38 // wxMenu implementation
39 // ============================================================================
40
41 IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
42
43 bool wxMenu::Create(const wxString& title, long style)
44 {
45 #if 0
46 if(!title)
47 return CocoaCreate("wxMenu");
48 #endif
49 return CocoaCreate(title);
50 }
51
52 wxMenu::~wxMenu()
53 {
54 }
55
56 bool wxMenu::DoAppend(wxMenuItem *item)
57 {
58 wxAutoNSAutoreleasePool pool;
59 if(!wxMenuBase::DoAppend(item))
60 return false;
61 [m_cocoaNSMenu addItem: item->GetNSMenuItem()];
62 return true;
63 }
64
65 bool wxMenu::DoInsert(unsigned long pos, wxMenuItem *item)
66 {
67 wxAutoNSAutoreleasePool pool;
68 if(!wxMenuBase::DoInsert(pos,item))
69 return false;
70 [m_cocoaNSMenu insertItem:item->GetNSMenuItem() atIndex:pos];
71 return true;
72 }
73
74 wxMenuItem* wxMenu::DoRemove(wxMenuItem *item)
75 {
76 wxAutoNSAutoreleasePool pool;
77 wxMenuItem *retitem = wxMenuBase::DoRemove(item);
78 wxASSERT(retitem->GetNSMenuItem());
79 [m_cocoaNSMenu removeItem:retitem->GetNSMenuItem()];
80 return retitem;
81 }
82
83 // ============================================================================
84 // wxMenuBar implementation
85 // ============================================================================
86 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
87
88 bool wxMenuBar::Create(long style)
89 {
90 if(!CocoaCreate("wxMenuBar"))
91 return false;
92 return true;
93 }
94
95 wxMenuBar::~wxMenuBar()
96 {
97 }
98
99 bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
100 {
101 wxAutoNSAutoreleasePool pool;
102 wxLogDebug("append menu=%p, title=%s",menu,title.c_str());
103 if(!wxMenuBarBase::Append(menu,title))
104 return false;
105 wxASSERT(menu);
106 wxASSERT(menu->GetNSMenu());
107 NSString *menuTitle = [[NSString alloc] initWithCString: wxStripMenuCodes(title).c_str()];
108 NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""];
109 [menu->GetNSMenu() setTitle:menuTitle];
110 [newItem setSubmenu:menu->GetNSMenu()];
111
112 [m_cocoaNSMenu addItem:newItem];
113
114 [menuTitle release];
115 [newItem release];
116 return true;
117 }
118
119 bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
120 {
121 wxAutoNSAutoreleasePool pool;
122 wxLogDebug("insert pos=%lu, menu=%p, title=%s",pos,menu,title.c_str());
123 if(!wxMenuBarBase::Insert(pos,menu,title))
124 return false;
125 wxASSERT(menu);
126 wxASSERT(menu->GetNSMenu());
127 NSString *menuTitle = [[NSString alloc] initWithCString: title.c_str()];
128 NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""];
129 [menu->GetNSMenu() setTitle:menuTitle];
130 [newItem setSubmenu:menu->GetNSMenu()];
131
132 [m_cocoaNSMenu insertItem:newItem atIndex:pos];
133
134 [menuTitle release];
135 [newItem release];
136 return true;
137 }
138
139 wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
140 {
141 return NULL;
142 }
143
144 wxMenu *wxMenuBar::Remove(size_t pos)
145 {
146 return NULL;
147 }
148
149
150 void wxMenuBar::EnableTop(size_t pos, bool enable)
151 {
152 }
153
154 bool wxMenuBar::IsEnabledTop(size_t pos) const
155 {
156 return false;
157 }
158
159 void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
160 {
161 }
162
163 wxString wxMenuBar::GetLabelTop(size_t pos) const
164 {
165 return wxEmptyString;
166 }
167
168 void wxMenuBar::Attach(wxFrame *frame)
169 {
170 }
171
172 void wxMenuBar::Detach()
173 {
174 }
175
176 wxSize wxMenuBar::DoGetBestClientSize() const
177 {
178 return wxDefaultSize;
179 }
180
181 #endif // wxUSE_MENUS