Implemented wxMenuBar::Insert and wxMenu::Insert.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35767 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -62,7 +62,7 @@ public:
|
|||||||
void HidePopup();
|
void HidePopup();
|
||||||
|
|
||||||
WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu,
|
WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu,
|
||||||
const wxString& title = wxEmptyString,
|
size_t index, const wxString& title = wxEmptyString,
|
||||||
bool isPulldown = false);
|
bool isPulldown = false);
|
||||||
|
|
||||||
// For popups, need to destroy, then recreate menu for a different (or
|
// For popups, need to destroy, then recreate menu for a different (or
|
||||||
|
@@ -44,7 +44,8 @@ public:
|
|||||||
virtual const wxBitmap& GetBitmap() const { return m_bitmap; }
|
virtual const wxBitmap& GetBitmap() const { return m_bitmap; }
|
||||||
|
|
||||||
// implementation from now on
|
// implementation from now on
|
||||||
void CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMenu);
|
void CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMenu,
|
||||||
|
size_t index);
|
||||||
void DestroyItem(bool full);
|
void DestroyItem(bool full);
|
||||||
|
|
||||||
WXWidget GetButtonWidget() const { return m_buttonWidget; }
|
WXWidget GetButtonWidget() const { return m_buttonWidget; }
|
||||||
|
@@ -114,18 +114,7 @@ void wxMenu::Break()
|
|||||||
// function appends a new item or submenu to the menu
|
// function appends a new item or submenu to the menu
|
||||||
wxMenuItem* wxMenu::DoAppend(wxMenuItem *pItem)
|
wxMenuItem* wxMenu::DoAppend(wxMenuItem *pItem)
|
||||||
{
|
{
|
||||||
if (m_menuWidget)
|
return DoInsert(GetMenuItemCount(), pItem);
|
||||||
{
|
|
||||||
// this is a dynamic Append
|
|
||||||
pItem->CreateItem(m_menuWidget, GetMenuBar(), m_topLevelMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( pItem->IsSubMenu() )
|
|
||||||
{
|
|
||||||
pItem->GetSubMenu()->m_topLevelMenu = m_topLevelMenu;
|
|
||||||
}
|
|
||||||
|
|
||||||
return wxMenuBase::DoAppend(pItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
|
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
|
||||||
@@ -137,12 +126,22 @@ wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
|
|||||||
|
|
||||||
wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
|
wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
|
||||||
{
|
{
|
||||||
if ( wxMenuBase::DoInsert(pos, item) )
|
if (m_menuWidget)
|
||||||
return item;
|
{
|
||||||
|
// this is a dynamic Append
|
||||||
|
#ifndef XmNpositionIndex
|
||||||
|
wxCHECK_MSG( pos == GetMenuItemCount(), -1, wxT("insert not implemented"));
|
||||||
|
#endif
|
||||||
|
item->CreateItem(m_menuWidget, GetMenuBar(), m_topLevelMenu, pos);
|
||||||
|
}
|
||||||
|
|
||||||
wxFAIL_MSG(wxT("DoInsert not implemented; or error in wxMenuBase::DoInsert"));
|
if ( item->IsSubMenu() )
|
||||||
|
{
|
||||||
|
item->GetSubMenu()->m_topLevelMenu = m_topLevelMenu;
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return pos == GetMenuItemCount() ? wxMenuBase::DoAppend(item) :
|
||||||
|
wxMenuBase::DoInsert(pos, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMenu::SetTitle(const wxString& label)
|
void wxMenu::SetTitle(const wxString& label)
|
||||||
@@ -267,30 +266,27 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const
|
|||||||
|
|
||||||
bool wxMenuBar::Append(wxMenu * menu, const wxString& title)
|
bool wxMenuBar::Append(wxMenu * menu, const wxString& title)
|
||||||
{
|
{
|
||||||
|
return Insert(GetMenuCount(), menu, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( pos <= GetMenuCount(), false, wxT("invalid position") );
|
||||||
wxCHECK_MSG( menu, false, wxT("invalid menu") );
|
wxCHECK_MSG( menu, false, wxT("invalid menu") );
|
||||||
wxCHECK_MSG( !menu->GetParent() && !menu->GetButtonWidget(), false,
|
wxCHECK_MSG( !menu->GetParent() && !menu->GetButtonWidget(), false,
|
||||||
wxT("menu already appended") );
|
wxT("menu already appended") );
|
||||||
|
|
||||||
if ( m_menuBarFrame )
|
if ( m_menuBarFrame )
|
||||||
{
|
{
|
||||||
WXWidget w = menu->CreateMenu(this, GetMainWidget(), menu, title, true);
|
WXWidget w = menu->CreateMenu(this, GetMainWidget(), menu,
|
||||||
|
pos, title, true);
|
||||||
wxCHECK_MSG( w, false, wxT("failed to create menu") );
|
wxCHECK_MSG( w, false, wxT("failed to create menu") );
|
||||||
menu->SetButtonWidget(w);
|
menu->SetButtonWidget(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_titles.Add(title);
|
m_titles.Insert(title, pos);
|
||||||
|
|
||||||
return wxMenuBarBase::Append(menu, title);
|
return wxMenuBarBase::Insert(pos, menu, title);
|
||||||
}
|
|
||||||
|
|
||||||
bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
|
|
||||||
{
|
|
||||||
if ( !wxMenuBarBase::Insert(pos, menu, title) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
wxFAIL_MSG(wxT("TODO"));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
|
wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
|
||||||
@@ -373,7 +369,7 @@ bool wxMenuBar::CreateMenuBar(wxFrame* parent)
|
|||||||
{
|
{
|
||||||
wxMenu *menu = GetMenu(i);
|
wxMenu *menu = GetMenu(i);
|
||||||
wxString title(m_titles[i]);
|
wxString title(m_titles[i]);
|
||||||
menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, title, true));
|
menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, i, title, true));
|
||||||
|
|
||||||
if (strcmp (wxStripMenuCodes(title), "Help") == 0)
|
if (strcmp (wxStripMenuCodes(title), "Help") == 0)
|
||||||
XtVaSetValues ((Widget) menuBarW, XmNmenuHelpWidget, (Widget) menu->GetButtonWidget(), NULL);
|
XtVaSetValues ((Widget) menuBarW, XmNmenuHelpWidget, (Widget) menu->GetButtonWidget(), NULL);
|
||||||
@@ -469,7 +465,7 @@ void wxMenu::DestroyWidgetAndDetach()
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topMenu, const wxString& title, bool pullDown)
|
WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topMenu, size_t index, const wxString& title, bool pullDown)
|
||||||
{
|
{
|
||||||
Widget menu = (Widget) 0;
|
Widget menu = (Widget) 0;
|
||||||
Widget buttonWidget = (Widget) 0;
|
Widget buttonWidget = (Widget) 0;
|
||||||
@@ -512,13 +508,14 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM
|
|||||||
|
|
||||||
m_topLevelMenu = topMenu;
|
m_topLevelMenu = topMenu;
|
||||||
|
|
||||||
|
size_t i = 0;
|
||||||
for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
|
for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
|
||||||
node;
|
node;
|
||||||
node = node->GetNext() )
|
node = node->GetNext(), ++i )
|
||||||
{
|
{
|
||||||
wxMenuItem *item = node->GetData();
|
wxMenuItem *item = node->GetData();
|
||||||
|
|
||||||
item->CreateItem(menu, menuBar, topMenu);
|
item->CreateItem(menu, menuBar, topMenu, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetBackgroundColour(m_backgroundColour);
|
SetBackgroundColour(m_backgroundColour);
|
||||||
|
@@ -158,7 +158,8 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
|
|||||||
// Motif-specific
|
// Motif-specific
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxMenuItem::CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMenu)
|
void wxMenuItem::CreateItem (WXWidget menu, wxMenuBar * menuBar,
|
||||||
|
wxMenu * topMenu, size_t index)
|
||||||
{
|
{
|
||||||
m_menuBar = menuBar;
|
m_menuBar = menuBar;
|
||||||
m_topMenu = topMenu;
|
m_topMenu = topMenu;
|
||||||
@@ -177,12 +178,18 @@ void wxMenuItem::CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMen
|
|||||||
{
|
{
|
||||||
m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (strName,
|
m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (strName,
|
||||||
xmToggleButtonGadgetClass, (Widget) menu,
|
xmToggleButtonGadgetClass, (Widget) menu,
|
||||||
|
#ifdef XmNpositionIndex
|
||||||
|
XmNpositionIndex, index,
|
||||||
|
#endif
|
||||||
NULL);
|
NULL);
|
||||||
XtVaSetValues ((Widget) m_buttonWidget, XmNset, (Boolean) IsChecked(), NULL);
|
XtVaSetValues ((Widget) m_buttonWidget, XmNset, (Boolean) IsChecked(), NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (strName,
|
m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (strName,
|
||||||
xmPushButtonGadgetClass, (Widget) menu,
|
xmPushButtonGadgetClass, (Widget) menu,
|
||||||
|
#ifdef XmNpositionIndex
|
||||||
|
XmNpositionIndex, index,
|
||||||
|
#endif
|
||||||
NULL);
|
NULL);
|
||||||
char mnem = wxFindMnemonic (m_text);
|
char mnem = wxFindMnemonic (m_text);
|
||||||
if (mnem != 0)
|
if (mnem != 0)
|
||||||
@@ -225,11 +232,15 @@ void wxMenuItem::CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMen
|
|||||||
else if (GetId() == wxID_SEPARATOR)
|
else if (GetId() == wxID_SEPARATOR)
|
||||||
{
|
{
|
||||||
m_buttonWidget = (WXWidget) XtVaCreateManagedWidget ("separator",
|
m_buttonWidget = (WXWidget) XtVaCreateManagedWidget ("separator",
|
||||||
xmSeparatorGadgetClass, (Widget) menu, NULL);
|
xmSeparatorGadgetClass, (Widget) menu,
|
||||||
|
#ifndef XmNpositionIndex
|
||||||
|
XmNpositionIndex, index,
|
||||||
|
#endif
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
else if (m_subMenu)
|
else if (m_subMenu)
|
||||||
{
|
{
|
||||||
m_buttonWidget = m_subMenu->CreateMenu (menuBar, menu, topMenu, m_text, true);
|
m_buttonWidget = m_subMenu->CreateMenu (menuBar, menu, topMenu, index, m_text, true);
|
||||||
m_subMenu->SetButtonWidget(m_buttonWidget);
|
m_subMenu->SetButtonWidget(m_buttonWidget);
|
||||||
XtAddCallback ((Widget) m_buttonWidget,
|
XtAddCallback ((Widget) m_buttonWidget,
|
||||||
XmNcascadingCallback,
|
XmNcascadingCallback,
|
||||||
|
@@ -1089,7 +1089,7 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
menu->SetId(1); /* Mark as popped-up */
|
menu->SetId(1); /* Mark as popped-up */
|
||||||
menu->CreateMenu(NULL, widget, menu);
|
menu->CreateMenu(NULL, widget, menu, 0);
|
||||||
menu->SetInvokingWindow(this);
|
menu->SetInvokingWindow(this);
|
||||||
|
|
||||||
menu->UpdateUI();
|
menu->UpdateUI();
|
||||||
|
Reference in New Issue
Block a user