]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/menu.mm
Remove wxBitmapHandler code
[wxWidgets.git] / src / cocoa / menu.mm
CommitLineData
fb896a32
DE
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
7fc77f30
DE
26#include "wx/cocoa/autorelease.h"
27
fb896a32
DE
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
41IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
42
43bool 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
52wxMenu::~wxMenu()
53{
54}
55
56bool wxMenu::DoAppend(wxMenuItem *item)
57{
7fc77f30 58 wxAutoNSAutoreleasePool pool;
fb896a32
DE
59 if(!wxMenuBase::DoAppend(item))
60 return false;
61 [m_cocoaNSMenu addItem: item->GetNSMenuItem()];
62 return true;
63}
64
65bool wxMenu::DoInsert(unsigned long pos, wxMenuItem *item)
66{
7fc77f30 67 wxAutoNSAutoreleasePool pool;
fb896a32
DE
68 if(!wxMenuBase::DoInsert(pos,item))
69 return false;
70 [m_cocoaNSMenu insertItem:item->GetNSMenuItem() atIndex:pos];
71 return true;
72}
73
74wxMenuItem* wxMenu::DoRemove(wxMenuItem *item)
75{
7fc77f30 76 wxAutoNSAutoreleasePool pool;
fb896a32
DE
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// ============================================================================
86IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
87
88bool wxMenuBar::Create(long style)
89{
90 if(!CocoaCreate("wxMenuBar"))
91 return false;
92 return true;
93}
94
95wxMenuBar::~wxMenuBar()
96{
97}
98
99bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
100{
7fc77f30 101 wxAutoNSAutoreleasePool pool;
fb896a32
DE
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
119bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
120{
7fc77f30 121 wxAutoNSAutoreleasePool pool;
fb896a32
DE
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
139wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
140{
141 return NULL;
142}
143
144wxMenu *wxMenuBar::Remove(size_t pos)
145{
146 return NULL;
147}
148
149
150void wxMenuBar::EnableTop(size_t pos, bool enable)
151{
152}
153
154bool wxMenuBar::IsEnabledTop(size_t pos) const
155{
156 return false;
157}
158
159void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
160{
161}
162
163wxString wxMenuBar::GetLabelTop(size_t pos) const
164{
165 return wxEmptyString;
166}
167
168void wxMenuBar::Attach(wxFrame *frame)
169{
170}
171
172void wxMenuBar::Detach()
173{
174}
175
176wxSize wxMenuBar::DoGetBestClientSize() const
177{
178 return wxDefaultSize;
179}
180
181#endif // wxUSE_MENUS