]>
git.saurik.com Git - wxWidgets.git/blob - src/common/menucmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/menucmn.cpp
3 // Purpose: wxMenu and wxMenuBar methods common to all ports
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "menubase.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 #include "wx/listimpl.cpp"
40 WX_DEFINE_LIST(wxMenuList
);
42 // ============================================================================
44 // ============================================================================
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 wxMenuBarBase::wxMenuBarBase()
52 // we own the menus when we get them
53 m_menus
.DeleteContents(TRUE
);
56 wxMenuBarBase::~wxMenuBarBase()
58 // nothing to do, the list will delete the menus because of the call to
59 // DeleteContents() above
62 // ----------------------------------------------------------------------------
63 // wxMenuBar item access: the base class versions manage m_menus list, the
64 // derived class should reflect the changes in the real menubar
65 // ----------------------------------------------------------------------------
67 wxMenu
*wxMenuBarBase::GetMenu(size_t pos
) const
69 wxMenuList::Node
*node
= m_menus
.Item(pos
);
70 wxCHECK_MSG( node
, NULL
, wxT("bad index in wxMenuBar::GetMenu()") );
72 return node
->GetData();
75 bool wxMenuBarBase::Append(wxMenu
*menu
, const wxString
& WXUNUSED(title
))
77 wxCHECK_MSG( menu
, FALSE
, wxT("can't append NULL menu") );
84 bool wxMenuBarBase::Insert(size_t pos
, wxMenu
*menu
,
85 const wxString
& WXUNUSED(title
))
87 wxCHECK_MSG( menu
, FALSE
, wxT("can't insert NULL menu") );
89 wxMenuList::Node
*node
= m_menus
.Item(pos
);
90 wxCHECK_MSG( node
, FALSE
, wxT("bad index in wxMenuBar::Insert()") );
92 m_menus
.Insert(node
, menu
);
97 wxMenu
*wxMenuBarBase::Replace(size_t pos
, wxMenu
*menu
,
98 const wxString
& WXUNUSED(title
))
100 wxCHECK_MSG( menu
, NULL
, wxT("can't insert NULL menu") );
102 wxMenuList::Node
*node
= m_menus
.Item(pos
);
103 wxCHECK_MSG( node
, NULL
, wxT("bad index in wxMenuBar::Replace()") );
105 wxMenu
*menuOld
= node
->GetData();
111 wxMenu
*wxMenuBarBase::Remove(size_t pos
)
113 wxMenuList::Node
*node
= m_menus
.Item(pos
);
114 wxCHECK_MSG( node
, NULL
, wxT("bad index in wxMenuBar::Remove()") );
116 node
= m_menus
.DetachNode(node
);
117 wxCHECK( node
, NULL
); // unexpected
118 wxMenu
*menu
= node
->GetData();
125 // ---------------------------------------------------------------------------
126 // wxMenuBar functions forwarded to wxMenuItem
127 // ---------------------------------------------------------------------------
129 void wxMenuBarBase::Enable(int id
, bool enable
)
131 wxMenuItem
*item
= FindItem(id
);
133 wxCHECK_RET( item
, wxT("attempt to enable an item which doesn't exist") );
135 item
->Enable(enable
);
138 void wxMenuBarBase::Check(int id
, bool check
)
140 wxMenuItem
*item
= FindItem(id
);
142 wxCHECK_RET( item
, wxT("attempt to check an item which doesn't exist") );
143 wxCHECK_RET( item
->IsCheckable(), wxT("attempt to check an uncheckable item") );
148 bool wxMenuBarBase::IsChecked(int id
) const
150 wxMenuItem
*item
= FindItem(id
);
152 wxCHECK_MSG( item
, FALSE
, wxT("wxMenuBar::IsChecked(): no such item") );
154 return item
->IsChecked();
157 bool wxMenuBarBase::IsEnabled(int id
) const
159 wxMenuItem
*item
= FindItem(id
);
161 wxCHECK_MSG( item
, FALSE
, wxT("wxMenuBar::IsEnabled(): no such item") );
163 return item
->IsEnabled();
166 void wxMenuBarBase::SetLabel(int id
, const wxString
& label
)
168 wxMenuItem
*item
= FindItem(id
);
170 wxCHECK_RET( item
, wxT("wxMenuBar::SetLabel(): no such item") );
172 item
->SetText(label
);
175 wxString
wxMenuBarBase::GetLabel(int id
) const
177 wxMenuItem
*item
= FindItem(id
);
179 wxCHECK_MSG( item
, wxEmptyString
,
180 wxT("wxMenuBar::GetLabel(): no such item") );
182 return item
->GetText();
185 void wxMenuBarBase::SetHelpString(int id
, const wxString
& helpString
)
187 wxMenuItem
*item
= FindItem(id
);
189 wxCHECK_RET( item
, wxT("wxMenuBar::SetHelpString(): no such item") );
191 item
->SetHelp(helpString
);
194 wxString
wxMenuBarBase::GetHelpString(int id
) const
196 wxMenuItem
*item
= FindItem(id
);
198 wxCHECK_MSG( item
, wxEmptyString
,
199 wxT("wxMenuBar::GetHelpString(): no such item") );
201 return item
->GetHelp();