static const int idMenuTitle = -2;
// ----------------------------------------------------------------------------
-// macros
+// private functions
// ----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
-IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxWindow)
+// make the given menu item default
+static void SetDefaultMenuItem(HMENU hmenu, UINT id)
+{
+ MENUITEMINFO mii;
+ wxZeroMemory(mii);
+ mii.cbSize = sizeof(MENUITEMINFO);
+ mii.fMask = MIIM_STATE;
+ mii.fState = MFS_DEFAULT;
+
+ if ( !::SetMenuItemInfo(hmenu, id, FALSE, &mii) )
+ {
+ wxLogLastError(wxT("SetMenuItemInfo"));
+ }
+}
// ============================================================================
// implementation
// ============================================================================
+IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
+IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxWindow)
+
// ---------------------------------------------------------------------------
// wxMenu construction, adding and removing menu items
// ---------------------------------------------------------------------------
void wxMenu::Init()
{
m_doBreak = FALSE;
+ m_startRadioGroup = -1;
// create the menu
m_hMenu = (WXHMENU)CreatePopupMenu();
m_doBreak = TRUE;
}
+void wxMenu::Attach(wxMenuBarBase *menubar)
+{
+ wxMenuBase::Attach(menubar);
+
+ EndRadioGroup();
+}
+
#if wxUSE_ACCEL
int wxMenu::FindAccel(int id) const
return FALSE;
}
- else
- {
- // if we just appended the title, highlight it
+
+ // if we just appended the title, highlight it
#ifdef __WIN32__
- if ( (int)id == idMenuTitle )
+ if ( (int)id == idMenuTitle )
+ {
+ // visually select the menu title
+ SetDefaultMenuItem(GetHmenu(), id);
+ }
+#endif // __WIN32__
+
+ // if we're already attached to the menubar, we must update it
+ if ( IsAttached() && m_menuBar->IsAttached() )
+ {
+ m_menuBar->Refresh();
+ }
+
+ return TRUE;
+}
+
+void wxMenu::EndRadioGroup()
+{
+ // we're not inside a radio group any longer
+ m_startRadioGroup = -1;
+}
+
+bool wxMenu::DoAppend(wxMenuItem *item)
+{
+ wxCHECK_MSG( item, FALSE, _T("NULL item in wxMenu::DoAppend") );
+
+ bool check = FALSE;
+
+ if ( item->GetKind() == wxITEM_RADIO )
+ {
+ int count = GetMenuItemCount();
+
+ if ( m_startRadioGroup == -1 )
+ {
+ // start a new radio group
+ m_startRadioGroup = count;
+
+ // for now it has just one element
+ item->SetAsRadioGroupStart();
+ item->SetRadioGroupEnd(m_startRadioGroup);
+
+ // ensure that we have a checked item in the radio group
+ check = TRUE;
+ }
+ else // extend the current radio group
{
- // visually select the menu title
- MENUITEMINFO mii;
- mii.cbSize = sizeof(mii);
- mii.fMask = MIIM_STATE;
- mii.fState = MFS_DEFAULT;
+ // we need to update its end item
+ item->SetRadioGroupStart(m_startRadioGroup);
+ wxMenuItemList::Node *node = GetMenuItems().Item(m_startRadioGroup);
- if ( !SetMenuItemInfo(GetHmenu(), (unsigned)id, FALSE, &mii) )
+ if ( node )
+ {
+ node->GetData()->SetRadioGroupEnd(count);
+ }
+ else
{
- wxLogLastError(wxT("SetMenuItemInfo"));
+ wxFAIL_MSG( _T("where is the radio group start item?") );
}
}
-#endif // __WIN32__
+ }
+ else // not a radio item
+ {
+ EndRadioGroup();
+ }
- // if we're already attached to the menubar, we must update it
- if ( IsAttached() && m_menuBar->IsAttached() )
- {
- m_menuBar->Refresh();
- }
+ if ( !wxMenuBase::DoAppend(item) || !DoInsertOrAppend(item) )
+ {
+ return FALSE;
+ }
- return TRUE;
+ if ( check )
+ {
+ // check the item initially
+ item->Check(TRUE);
}
-}
-bool wxMenu::DoAppend(wxMenuItem *item)
-{
- return wxMenuBase::DoAppend(item) && DoInsertOrAppend(item);
+ return TRUE;
}
bool wxMenu::DoInsert(size_t pos, wxMenuItem *item)
// put the title string in bold face
if ( !m_title.IsEmpty() )
{
- MENUITEMINFO mii;
- mii.cbSize = sizeof(mii);
- mii.fMask = MIIM_STATE;
- mii.fState = MFS_DEFAULT;
-
- if ( !SetMenuItemInfo(hMenu, (unsigned)idMenuTitle, FALSE, &mii) )
- {
- wxLogLastError(wxT("SetMenuItemInfo"));
- }
+ SetDefaultMenuItem(GetHmenu(), (UINT)idMenuTitle);
}
#endif // Win32
}
if ( !wxMenuBarBase::Append(menu, title) )
return FALSE;
- // Already done in Append above
- //menu->Attach(this);
-
m_titles.Add(title);
if ( IsAttached() )
wxLogLastError(wxT("RemoveMenu"));
}
- menu->Detach();
-
#if wxUSE_ACCEL
if ( menu->HasAccels() )
{
{
wxMenuBarBase::Attach(frame);
- m_menuBarFrame = frame;
-
#if wxUSE_ACCEL
RebuildAccelTable();
#endif // wxUSE_ACCEL