]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/menuitem.mm
Removed obsolete ODBC classes.
[wxWidgets.git] / src / cocoa / menuitem.mm
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: menuitem.cpp
3 // Purpose: wxMenuItem implementation
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2002/12/15
7 // RCS-ID: $Id:
8 // Copyright: 2002 David Elliott
9 // Licence: wxWindows licence
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/menuitem.h"
24 #include "wx/utils.h"
25 #include "wx/frame.h"
26 #endif
27
28 #include "wx/cocoa/ObjcPose.h"
29
30 #import <AppKit/NSMenuItem.h>
31 #import <AppKit/NSMenu.h>
32 #import <Foundation/NSString.h>
33
34 #if wxUSE_MENUS
35
36 // ----------------------------------------------------------------------------
37 // globals
38 // ----------------------------------------------------------------------------
39 wxMenuItemCocoaHash wxMenuItemCocoa::sm_cocoaHash;
40
41 // ----------------------------------------------------------------------------
42 // functions prototypes
43 // ----------------------------------------------------------------------------
44
45 // ============================================================================
46 // @class wxPoserNSMenuItem
47 // ============================================================================
48 @interface wxPoserNSMenuItem : NSMenuItem
49 {
50 }
51
52 @end // wxPoserNSMenuItem
53
54 WX_IMPLEMENT_POSER(wxPoserNSMenuItem);
55 @implementation wxPoserNSMenuItem : NSMenuItem
56
57 @end // wxPoseRNSMenuItem
58
59 // ============================================================================
60 // wxMenuItemCocoa implementation
61 // ============================================================================
62 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
63
64 // ----------------------------------------------------------------------------
65 // wxMenuItemBase
66 // ----------------------------------------------------------------------------
67
68 wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
69 int itemid,
70 const wxString& name,
71 const wxString& help,
72 wxItemKind kind,
73 wxMenu *subMenu)
74 {
75 return new wxMenuItem(parentMenu, itemid, name, help, kind, subMenu);
76 }
77
78 /* static */
79 wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
80 {
81 return wxStripMenuCodes(text);
82 }
83
84 // ----------------------------------------------------------------------------
85 // ctor & dtor
86 // ----------------------------------------------------------------------------
87 wxMenuItemCocoa::wxMenuItemCocoa(wxMenu *pParentMenu,
88 int itemid,
89 const wxString& strName,
90 const wxString& strHelp,
91 wxItemKind kind,
92 wxMenu *pSubMenu)
93 : wxMenuItemBase(pParentMenu, itemid, strName, strHelp, kind, pSubMenu)
94 {
95 NSString *menuTitle = [[NSString alloc] initWithCString: wxStripMenuCodes(strName).c_str()];
96 m_cocoaNSMenuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(wxMenuItemAction:) keyEquivalent:@""];
97 sm_cocoaHash.insert(wxMenuItemCocoaHash::value_type(m_cocoaNSMenuItem,this));
98 if(pSubMenu)
99 {
100 wxASSERT(pSubMenu->GetNSMenu());
101 [pSubMenu->GetNSMenu() setTitle:menuTitle];
102 [m_cocoaNSMenuItem setSubmenu:pSubMenu->GetNSMenu()];
103 }
104 [menuTitle release];
105 }
106
107 wxMenuItem::~wxMenuItem()
108 {
109 sm_cocoaHash.erase(m_cocoaNSMenuItem);
110 [m_cocoaNSMenuItem release];
111 }
112
113 // ----------------------------------------------------------------------------
114 // misc
115 // ----------------------------------------------------------------------------
116
117 // change item state
118 // -----------------
119
120 void wxMenuItem::Enable(bool bDoEnable)
121 {
122 wxMenuItemBase::Enable(bDoEnable);
123 }
124
125 void wxMenuItem::Check(bool bDoCheck)
126 {
127 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
128 wxMenuItemBase::Check(bDoCheck);
129 }
130
131 void wxMenuItem::SetText(const wxString& label)
132 {
133 wxMenuItemBase::SetText(label);
134 }
135
136 void wxMenuItem::SetCheckable(bool checkable)
137 {
138 wxMenuItemBase::SetCheckable(checkable);
139 }
140
141 #endif // wxUSE_MENUS