wxString wxMenuBar::GetLabelTop(size_t pos) const { wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, wxT("invalid menu index in wxMenuBar::GetLabelTop") ); return wxMenuItem::GetLabelFromText(m_titles[pos]); }
void wxMenuBar::RebuildAccelTable() { // // Merge the accelerators of all menus into one accel table // size_t nAccelCount = 0; size_t i; size_t nCount = GetMenuCount(); wxMenuList::iterator it; for (i = 0, it = m_menus.begin(); i < nCount; i++, it++) { nAccelCount += (*it)->GetAccelCount(); } if (nAccelCount) { wxAcceleratorEntry* pAccelEntries = new wxAcceleratorEntry[nAccelCount]; nAccelCount = 0; for (i = 0, it = m_menus.begin(); i < nCount; i++, it++) { nAccelCount += (*it)->CopyAccels(&pAccelEntries[nAccelCount]); } m_vAccelTable = wxAcceleratorTable( nAccelCount ,pAccelEntries ); delete [] pAccelEntries; } } // end of wxMenuBar::RebuildAccelTable
// Destroy menubar, but keep data structures intact so we can recreate it. bool wxMenuBar::DestroyMenuBar() { if (!m_mainWidget) { SetMenuBarFrame(NULL); return false; } XtUnmanageChild ((Widget) m_mainWidget); XtUnrealizeWidget ((Widget) m_mainWidget); size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) { wxMenu *menu = GetMenu(i); menu->DestroyMenu(true); } XtDestroyWidget((Widget) m_mainWidget); m_mainWidget = (WXWidget) 0; SetMenuBarFrame(NULL); return true; }
void wxMenuBar::RebuildAccelTable() { // merge the accelerators of all menus into one accel table size_t nAccelCount = 0; size_t i, count = GetMenuCount(); wxMenuList::iterator it; for ( i = 0, it = m_menus.begin(); i < count; i++, it++ ) { nAccelCount += (*it)->GetAccelCount(); } if ( nAccelCount ) { wxAcceleratorEntry *accelEntries = new wxAcceleratorEntry[nAccelCount]; nAccelCount = 0; for ( i = 0, it = m_menus.begin(); i < count; i++, it++ ) { nAccelCount += (*it)->CopyAccels(&accelEntries[nAccelCount]); } SetAcceleratorTable(wxAcceleratorTable(nAccelCount, accelEntries)); delete [] accelEntries; } else // No (more) accelerators. { SetAcceleratorTable(wxAcceleratorTable()); } }
int wxMenuBar::MSWPositionForWxMenu(wxMenu *menu, int wxpos) { wxASSERT(menu); wxASSERT(menu->GetHMenu()); wxASSERT(m_hMenu); #if defined(__WXWINCE__) int totalMSWItems = GetMenuCount(); #else int totalMSWItems = GetMenuItemCount((HMENU)m_hMenu); #endif int i; // For old C++ compatibility for(i=wxpos; i<totalMSWItems; i++) { if(GetSubMenu((HMENU)m_hMenu,i)==(HMENU)menu->GetHMenu()) return i; } for(i=0; i<wxpos; i++) { if(GetSubMenu((HMENU)m_hMenu,i)==(HMENU)menu->GetHMenu()) return i; } wxFAIL; return -1; }
int wxMenuBar::ProcessCommand(int ItemID) { if(!IsAttached()) return -1; int MenuNum=(ItemID/1000)-1; int ItemNum=(ItemID-(1000*(MenuNum+1))); // Should never happen, but it doesn't hurt to check anyway. if(MenuNum>GetMenuCount()) return -1; // Get the menu wxMenu *ActiveMenu=GetMenu(MenuNum); // Make sure this is a valid item. if(ItemNum>ActiveMenu->GetMenuItemCount()) return -1; // Get the item wxMenuItem *ActiveItem=ActiveMenu->FindItemByPosition(ItemNum); int ActiveID=ActiveItem->GetId(); return ActiveID; }
// Gets the original label at the top-level of the menubar wxString wxMenuBar::GetMenuLabel(size_t pos) const { wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, wxT("invalid menu index in wxMenuBar::GetMenuLabel") ); return m_titles[pos]; }
bool wxMenuBar::Append(wxMenu *menu, const wxString& title) { WXHMENU submenu = menu ? menu->GetHMenu() : 0; wxCHECK_MSG( submenu, false, wxT("can't append invalid menu to menubar") ); if ( !wxMenuBarBase::Append(menu, title) ) return false; menu->wxMenuBase::SetTitle(title); #if defined(WINCE_WITHOUT_COMMANDBAR) if (IsAttached()) #else if (GetHmenu()) #endif { #if defined(WINCE_WITHOUT_COMMANDBAR) if (!GetToolBar()) return false; TBBUTTON tbButton; memset(&tbButton, 0, sizeof(TBBUTTON)); tbButton.iBitmap = I_IMAGENONE; tbButton.fsState = TBSTATE_ENABLED; tbButton.fsStyle = TBSTYLE_DROPDOWN | TBSTYLE_NO_DROPDOWN_ARROW | TBSTYLE_AUTOSIZE; size_t pos = GetMenuCount(); HMENU hPopupMenu = (HMENU) menu->GetHMenu() ; tbButton.dwData = (DWORD)hPopupMenu; wxString label = wxStripMenuCodes(title); tbButton.iString = (int) label.wx_str(); tbButton.idCommand = NewControlId(); if (!::SendMessage((HWND) GetToolBar()->GetHWND(), TB_INSERTBUTTON, pos, (LPARAM)&tbButton)) { wxLogLastError(wxT("TB_INSERTBUTTON")); return false; } #else if ( !::AppendMenu(GetHmenu(), MF_POPUP | MF_STRING, (UINT_PTR)submenu, title.wx_str()) ) { wxLogLastError(wxT("AppendMenu")); } #endif #if wxUSE_ACCEL if ( menu->HasAccels() ) { // need to rebuild accelerator table RebuildAccelTable(); } #endif // wxUSE_ACCEL if (IsAttached()) Refresh(); } return true; }
void wxMenuBar::RebuildAccelTable() { // // Merge the accelerators of all menus into one accel table // size_t nAccelCount = 0; size_t i; size_t nCount = GetMenuCount(); wxMenuList::iterator it; #if defined(__INTEL_COMPILER) && 1 // VDM auto patch # pragma ivdep # pragma swp # pragma unroll #endif #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (i = 0, it = m_menus.begin(); i < nCount; i++, it++) { nAccelCount += (*it)->GetAccelCount(); } if (nAccelCount) { wxAcceleratorEntry* pAccelEntries = new wxAcceleratorEntry[nAccelCount]; nAccelCount = 0; #if defined(__INTEL_COMPILER) && 1 // VDM auto patch # pragma ivdep # pragma swp # pragma unroll #endif #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (i = 0, it = m_menus.begin(); i < nCount; i++, it++) { nAccelCount += (*it)->CopyAccels(&pAccelEntries[nAccelCount]); } m_vAccelTable = wxAcceleratorTable( nAccelCount ,pAccelEntries ); delete [] pAccelEntries; } } // end of wxMenuBar::RebuildAccelTable
void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) { wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") ); m_titles[pos] = label; if ( !IsAttached() ) { return; } //else: have to modify the existing menu int mswpos = MSWPositionForWxMenu(GetMenu(pos),pos); UINT id; UINT flagsOld = ::GetMenuState((HMENU)m_hMenu, mswpos, MF_BYPOSITION); if ( flagsOld == 0xFFFFFFFF ) { wxLogLastError(wxT("GetMenuState")); return; } if ( flagsOld & MF_POPUP ) { // HIBYTE contains the number of items in the submenu in this case flagsOld &= 0xff; id = (UINT)::GetSubMenu((HMENU)m_hMenu, mswpos); } else { id = pos; } #ifdef __WXWINCE__ MENUITEMINFO info; wxZeroMemory(info); info.cbSize = sizeof(info); info.fMask = MIIM_TYPE; info.fType = MFT_STRING; info.cch = label.Length(); info.dwTypeData = (LPTSTR) label.c_str(); if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, & info) ) { wxLogLastError(wxT("SetMenuItemInfo")); } #else if ( ::ModifyMenu(GetHmenu(), mswpos, MF_BYPOSITION | MF_STRING | flagsOld, id, label) == (int)0xFFFFFFFF ) { wxLogLastError(wxT("ModifyMenu")); } #endif Refresh(); }
bool wxMenuBar::Enable(bool enable) { wxCHECK_MSG( IsAttached(), false, wxT("doesn't work with unattached menubars") ); size_t i; for (i = 0; i < GetMenuCount(); i++) EnableTop(i, enable); return true; }
void wxMenuBarBase::UpdateMenus() { wxMenu* menu; int nCount = GetMenuCount(); for (int n = 0; n < nCount; n++) { menu = GetMenu( n ); if (menu != NULL) menu->UpdateUI( NULL ); } }
int wxMenuBar::MSWGetTopMenuPos(WXHMENU hMenu) const { for ( size_t n = 0 ; n < GetMenuCount(); ++n ) { wxMenu* menu = GetMenu(n)->MSWGetMenu(hMenu); if ( menu ) return n; } return wxNOT_FOUND; }
// Create menubar bool wxMenuBar::CreateMenuBar(wxFrame* parent) { m_parent = parent; // bleach... override it! PreCreation(); m_parent = NULL; if (m_mainWidget) { XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL); /* if (!XtIsManaged((Widget) m_mainWidget)) XtManageChild((Widget) m_mainWidget); */ XtMapWidget((Widget) m_mainWidget); return true; } Widget menuBarW = XmCreateMenuBar ((Widget) parent->GetMainWidget(), wxMOTIF_STR("MenuBar"), NULL, 0); m_mainWidget = (WXWidget) menuBarW; size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) { wxMenu *menu = GetMenu(i); wxString title(m_titles[i]); menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, i, title, true)); if (strcmp (wxStripMenuCodes(title), "Help") == 0) XtVaSetValues ((Widget) menuBarW, XmNmenuHelpWidget, (Widget) menu->GetButtonWidget(), NULL); // tear off menu support #if (XmVersion >= 1002) if ( menu->IsTearOff() ) { XtVaSetValues(GetWidget(menu), XmNtearOffModel, XmTEAR_OFF_ENABLED, NULL); Widget tearOff = XmGetTearOffControl(GetWidget(menu)); wxDoChangeForegroundColour((Widget) tearOff, m_foregroundColour); wxDoChangeBackgroundColour((Widget) tearOff, m_backgroundColour, true); } #endif } PostCreation(); XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL); XtRealizeWidget ((Widget) menuBarW); XtManageChild ((Widget) menuBarW); SetMenuBarFrame(parent); return true; }
bool wxMenuBar::SetFont(const wxFont& font) { m_font = font; ChangeFont(); size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) m_menus.Item(i)->GetData()->SetFont(font); return true; }
void wxMenuBar::EnableTop(size_t pos, bool enable) { wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") ); wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") ); int flag = enable ? MF_ENABLED : MF_GRAYED; EnableMenuItem((HMENU)m_hMenu, MSWPositionForWxMenu(GetMenu(pos),pos), MF_BYPOSITION | flag); Refresh(); }
const wxMenuInfoHelperList& wxMenuBarBase::GetMenuInfos() const { wxMenuInfoHelperList* list = const_cast< wxMenuInfoHelperList* > (& m_menuInfos); WX_CLEAR_LIST( wxMenuInfoHelperList, *list); for (size_t i = 0 ; i < GetMenuCount(); ++i) { wxMenuInfoHelper* info = new wxMenuInfoHelper(); info->Create( GetMenu(i), GetMenuLabel(i)); list->Append(info); } return m_menuInfos; }
wxMenuItem *wxMenuBar::FindItem(int id, wxMenu **itemMenu) const { if ( itemMenu ) *itemMenu = NULL; wxMenuItem *item = NULL; size_t count = GetMenuCount(); for ( size_t i = 0; !item && (i < count); i++ ) item = _wxMenuAt(m_menus, i)->FindItem(id, itemMenu); return item; }
bool wxMenuBar::IsEnabledTop(size_t pos) const { wxCHECK_MSG( pos < GetMenuCount(), false, wxS("invalid menu index") ); WinStruct<MENUITEMINFO> mii; mii.fMask = MIIM_STATE; if ( !::GetMenuItemInfo(GetHmenu(), pos, TRUE, &mii) ) { wxLogLastError(wxS("GetMenuItemInfo(menubar)")); } return !(mii.fState & MFS_GRAYED); }
bool wxMenuBar::SetForegroundColour(const wxColour& col) { m_foregroundColour = col; if (m_mainWidget) wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col); size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) m_menus.Item(i)->GetData()->SetForegroundColour((wxColour&) col); return true; }
const wxMenuInfoList& wxMenuBar::GetMenuInfos() const { wxMenuInfoList* list = const_cast< wxMenuInfoList* >( &m_menuInfos ) ; WX_CLEAR_LIST( wxMenuInfoList , *list ) ; for( size_t i = 0 ; i < GetMenuCount() ; ++i ) { wxMenuInfo* info = new wxMenuInfo() ; info->Create( const_cast<wxMenuBar*>(this)->GetMenu(i) , GetLabelTop(i) ) ; list->Append( info ) ; } return m_menuInfos ; }
// Find the menu menuString, item itemString, and return the item id. // Returns -1 if none found. int wxMenuBar::FindMenuItem(const wxString& menuString, const wxString& itemString) const { const wxString stripped = wxStripMenuCodes(menuString); size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) { if ( wxStripMenuCodes(m_titles[i]) == stripped ) return m_menus.Item(i)->GetData()->FindItem (itemString); } return wxNOT_FOUND; }
void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) { wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") ); m_titles[pos]=wxStripMenuCodes(label); if ( !IsAttached() ) { return; } // Regenerate the menu resource Refresh(); }
// Find the itemString in menuString, and return the item id or wxNOT_FOUND int wxMenuBar::FindMenuItem(const wxString& menuString, const wxString& itemString) const { wxString menuLabel = wxStripMenuCodes(menuString); size_t count = GetMenuCount(); for ( size_t i = 0; i < count; i++ ) { wxString title = wxStripMenuCodes(m_titles[i]); if ( menuLabel == title ) return _wxMenuAt(m_menus, i)->FindItem(itemString); } return wxNOT_FOUND; }
int wxMenuBar::FindMenu(const wxString& title) { wxString menuTitle = wxStripMenuCodes(title); size_t count = GetMenuCount(); for ( size_t i = 0; i < count; i++ ) { wxString title = wxStripMenuCodes(m_titles[i]); if ( menuTitle == title ) return i; } return wxNOT_FOUND; }
wxMenuItem *wxMenuBar::FindItem(int id, wxMenu ** itemMenu) const { if (itemMenu) *itemMenu = NULL; size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) { wxMenuItem *item = m_menus.Item(i)->GetData()->FindItem(id, itemMenu); if (item) return item; } return NULL; }
bool wxMenuBar::SetForegroundColour(const wxColour& col) { if (!wxWindowBase::SetForegroundColour(col)) return false; if (!col.IsOk()) return false; if (m_mainWidget) wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col); size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) m_menus.Item(i)->GetData()->SetForegroundColour((wxColour&) col); return true; }
wxMenuItem *wxMenuBarBase::FindItem(int id, wxMenu **menu) const { if ( menu ) *menu = NULL; wxMenuItem *item = NULL; size_t count = GetMenuCount(), i; wxMenuList::const_iterator it; for ( i = 0, it = m_menus.begin(); !item && (i < count); i++, it++ ) { item = (*it)->FindItem(id, menu); } return item; }
// get the menu with given handle (recursively) wxMenu* wxMenuBar::MSWGetMenu(WXHMENU hMenu) { wxCHECK_MSG( GetHMenu() != hMenu, NULL, wxT("wxMenuBar::MSWGetMenu(): menu handle is wxMenuBar, not wxMenu") ); // query all menus for ( size_t n = 0 ; n < GetMenuCount(); ++n ) { wxMenu* menu = GetMenu(n)->MSWGetMenu(hMenu); if ( menu ) return menu; } // unknown hMenu return NULL; }
void wxMenuBarBase::UpdateMenus( void ) { wxEvtHandler* source; wxMenu* menu; int nCount = GetMenuCount(); for (int n = 0; n < nCount; n++) { menu = GetMenu( n ); if (menu != NULL) { source = menu->GetEventHandler(); if (source != NULL) menu->UpdateUI( source ); } } }