Added original works and stubs to CVS repository
[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 #import <Foundation/NSString.h>
27 #import <AppKit/NSMenu.h>
28
29 #if wxUSE_MENUS
30
31 // ----------------------------------------------------------------------------
32 // globals
33 // ----------------------------------------------------------------------------
34
35 // ============================================================================
36 // wxMenu implementation
37 // ============================================================================
38
39 IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
40
41 bool wxMenu::Create(const wxString& title, long style)
42 {
43 #if 0
44     if(!title)
45         return CocoaCreate("wxMenu");
46 #endif
47     return CocoaCreate(title);
48 }
49
50 wxMenu::~wxMenu()
51 {
52 }
53
54 bool wxMenu::DoAppend(wxMenuItem *item)
55 {
56     if(!wxMenuBase::DoAppend(item))
57         return false;
58     [m_cocoaNSMenu addItem: item->GetNSMenuItem()];
59     return true;
60 }
61
62 bool wxMenu::DoInsert(unsigned long pos, wxMenuItem *item)
63 {
64     if(!wxMenuBase::DoInsert(pos,item))
65         return false;
66     [m_cocoaNSMenu insertItem:item->GetNSMenuItem() atIndex:pos];
67     return true;
68 }
69
70 wxMenuItem* wxMenu::DoRemove(wxMenuItem *item)
71 {
72     wxMenuItem *retitem = wxMenuBase::DoRemove(item);
73     wxASSERT(retitem->GetNSMenuItem());
74     [m_cocoaNSMenu removeItem:retitem->GetNSMenuItem()];
75     return retitem;
76 }
77
78 // ============================================================================
79 // wxMenuBar implementation
80 // ============================================================================
81 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
82
83 bool wxMenuBar::Create(long style)
84 {
85     if(!CocoaCreate("wxMenuBar"))
86         return false;
87     return true;
88 }
89
90 wxMenuBar::~wxMenuBar()
91 {
92 }
93
94 bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
95 {
96     wxLogDebug("append menu=%p, title=%s",menu,title.c_str());
97     if(!wxMenuBarBase::Append(menu,title))
98         return false;
99     wxASSERT(menu);
100     wxASSERT(menu->GetNSMenu());
101     NSString *menuTitle = [[NSString alloc] initWithCString: wxStripMenuCodes(title).c_str()];
102     NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""];
103     [menu->GetNSMenu() setTitle:menuTitle];
104     [newItem setSubmenu:menu->GetNSMenu()];
105
106     [m_cocoaNSMenu addItem:newItem];
107
108     [menuTitle release];
109     [newItem release];
110     return true;
111 }
112
113 bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
114 {
115     wxLogDebug("insert pos=%lu, menu=%p, title=%s",pos,menu,title.c_str());
116     if(!wxMenuBarBase::Insert(pos,menu,title))
117         return false;
118     wxASSERT(menu);
119     wxASSERT(menu->GetNSMenu());
120     NSString *menuTitle = [[NSString alloc] initWithCString: title.c_str()];
121     NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:NULL keyEquivalent:@""];
122     [menu->GetNSMenu() setTitle:menuTitle];
123     [newItem setSubmenu:menu->GetNSMenu()];
124
125     [m_cocoaNSMenu insertItem:newItem atIndex:pos];
126
127     [menuTitle release];
128     [newItem release];
129     return true;
130 }
131
132 wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
133 {
134     return NULL;
135 }
136
137 wxMenu *wxMenuBar::Remove(size_t pos)
138 {
139     return NULL;
140 }
141
142
143 void wxMenuBar::EnableTop(size_t pos, bool enable)
144 {
145 }
146
147 bool wxMenuBar::IsEnabledTop(size_t pos) const
148 {
149     return false;
150 }
151
152 void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
153 {
154 }
155
156 wxString wxMenuBar::GetLabelTop(size_t pos) const
157 {
158     return wxEmptyString;
159 }
160
161 void wxMenuBar::Attach(wxFrame *frame)
162 {
163 }
164
165 void wxMenuBar::Detach()
166 {
167 }
168
169 wxSize wxMenuBar::DoGetBestClientSize() const
170 {
171     return wxDefaultSize;
172 }
173
174 #endif // wxUSE_MENUS