//__________________________________________________________________ void _HYPlatformPullDown::_SetMenuItem (_String& newItem, long index) { _DeleteMenuItem (index); _AddMenuItem (newItem,index); if (index==selection) { cbSelection = -1; _RefreshComboBox(); } }
BMenuItem* PackageView::_AddDestinationMenuItem(BString baseName, size_t size, const char* path) const { BString name = _NamePlusSizeString(baseName, size, B_TRANSLATE("%name% (%size% free)")); BMessage* message = new BMessage(P_MSG_PATH_CHANGED); message->AddString("path", path); return _AddMenuItem(name, message, fDestination); }
BMenuItem* PackageView::_AddInstallTypeMenuItem(BString baseName, size_t size, int32 index) const { BString name = _NamePlusSizeString(baseName, size, B_TRANSLATE("%name% (%size%)")); BMessage* message = new BMessage(P_MSG_INSTALL_TYPE_CHANGED); message->AddInt32("index", index); return _AddMenuItem(name, message, fInstallTypes); }
/** * @brief The function opens a popup menu at the given position. It returns * immediately after creation. On the first call it creates the menu. * @param hParent: pointer to the handle of the parent * @param pMenuItems: pointer to menu items * @param NumItems: number of menu items * @param x: x position of the popup * @param y: y position of the popup * @retval None */ static void _OpenPopup(WM_HWIN hParent, MENU_ITEM * pMenuItems, int NumItems, int x, int y) { static MENU_Handle hMenu; if (!hMenu) { int i; /* Create the popup window only one time */ hMenu = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); MENU_SetBkColor(hMenu, MENU_CI_SELECTED, GUI_LIGHTBLUE); for (i = 0; i < NumItems; i++) { _AddMenuItem(hMenu, 0, pMenuItems[i].sText, pMenuItems[i].Id, pMenuItems[i].Flags); } } MENU_Popup(hMenu, hParent, x, y, 0, 0, 0); }
/** * @brief Opens a popup menu at the given position. * @note It returns immediately after creation. * On the first call it creates the menu * @param hParent: pointer to the handle of the parent * @param pMenuItems: pointer to menu items * @param NumItems: number of menu items * @param x: x position of the popup * @param y: y position of the popup * @retval None */ static void _OpenPopup(WM_HWIN hParent, MENU_ITEM * pMenuItems, int NumItems, int x, int y) { static MENU_Handle hMenu; if (!hMenu) { int i; /* Create the popup window only one time */ hMenu = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); MENU_SetBkColor(hMenu, MENU_CI_SELECTED, GUI_LIGHTBLUE); for (i = 0; i < NumItems; i++) { _AddMenuItem(hMenu, 0, pMenuItems[i].sText, pMenuItems[i].Id, pMenuItems[i].Flags); } } /* Open the popup menu. After opening the menu the function returns immediately. * After selecting menu item or after touching the display outside the menu the * popup menu will be closed, but not deleted. */ MENU_Popup(hMenu, hParent, x, y, 0, 0, 0); }
status_t PackageView::_InstallTypeChanged(int32 index) { if (index < 0) return B_ERROR; // Clear the choice list for (int32 i = fDestination->CountItems() - 1; i >= 0; i--) { BMenuItem* item = fDestination->RemoveItem(i); delete item; } fCurrentType = index; pkg_profile* profile = fInfo.GetProfile(index); if (profile == NULL) return B_ERROR; BString typeDescription = profile->description; if (typeDescription.IsEmpty()) typeDescription = profile->name; fInstallTypeDescriptionView->SetText(typeDescription.String()); BPath path; BVolume volume; if (profile->path_type == P_INSTALL_PATH) { BMenuItem* item = NULL; if (find_directory(B_SYSTEM_NONPACKAGED_DIRECTORY, &path) == B_OK) { dev_t device = dev_for_path(path.Path()); if (volume.SetTo(device) == B_OK && !volume.IsReadOnly() && path.Append("apps") == B_OK) { item = _AddDestinationMenuItem(path.Path(), volume.FreeBytes(), path.Path()); } } if (item != NULL) { item->SetMarked(true); fCurrentPath.SetTo(path.Path()); fDestination->AddSeparatorItem(); } _AddMenuItem(B_TRANSLATE("Other" B_UTF8_ELLIPSIS), new BMessage(P_MSG_OPEN_PANEL), fDestination); fDestField->SetEnabled(true); } else if (profile->path_type == P_USER_PATH) { bool defaultPathSet = false; BVolumeRoster roster; while (roster.GetNextVolume(&volume) != B_BAD_VALUE) { BDirectory mountPoint; if (volume.IsReadOnly() || !volume.IsPersistent() || volume.GetRootDirectory(&mountPoint) != B_OK) { continue; } if (path.SetTo(&mountPoint, NULL) != B_OK) continue; char volumeName[B_FILE_NAME_LENGTH]; volume.GetName(volumeName); BMenuItem* item = _AddDestinationMenuItem(volumeName, volume.FreeBytes(), path.Path()); // The first volume becomes the default element if (!defaultPathSet) { item->SetMarked(true); fCurrentPath.SetTo(path.Path()); defaultPathSet = true; } } fDestField->SetEnabled(true); } else fDestField->SetEnabled(false); return B_OK; }
void _HYPullDown::AddMenuItem (_String newItem, long loc) { menuSelections.InsertElement (&newItem,loc,true); _AddMenuItem (newItem,loc); }
/********************************************************************* * * CreateWindow */ WM_HWIN PrintWinCreate(void) { WM_HWIN hWin; hWin = WM_CreateWindow(0, 0, 800, 480,WM_CF_SHOW, _cbDialog, 0); hPrintMenu = MENU_CreateEx(0,0,0,0,WM_UNATTACHED,WM_CF_SHOW,MENU_CF_VERTICAL,ID_PrintMenu); //主菜单 PrintHintText = TEXT_CreateAsChild(40,440,800,40,hWin,ID_PrintText,WM_CF_SHOW,"",TEXT_CF_LEFT); TEXT_SetFont(PrintHintText,&GUI_Font24); //WIDGET_SetEffect(hMenu,&WIDGET_Effect_3D1L); hFre = MENU_CreateEx(0,0,0,0,WM_UNATTACHED,WM_CF_SHOW,MENU_CF_VERTICAL,ID_Print_Frequency); //频率分类 hSite = MENU_CreateEx(0,0,0,0,WM_UNATTACHED,WM_CF_SHOW,MENU_CF_VERTICAL,ID_Print_Site); //站点分类 hInfo = MENU_CreateEx(0,0,0,0,WM_UNATTACHED,WM_CF_SHOW,MENU_CF_VERTICAL,ID_Print_Info); //信息分类 hSiteSet = MENU_CreateEx(0,0,100,0,WM_UNATTACHED,WM_CF_SHOW,MENU_CF_VERTICAL,ID_Print_Site_SiteSet); //站点打印设置 hInfoSet = MENU_CreateEx(0,0,100,0,WM_UNATTACHED,WM_CF_SHOW,MENU_CF_VERTICAL,ID_Print_Info_InfoSet); //信息打印设置 //菜单回调 WM_SetCallback(hPrintMenu,&MenuCall); WM_SetCallback(hFre,&MenuCall); WM_SetCallback(hSite,&MenuCall); WM_SetCallback(hInfo,&MenuCall); WM_SetCallback(hSiteSet,&MenuCall); WM_SetCallback(hInfoSet,&MenuCall); //左右间距 MENU_SetBorderSize(hPrintMenu,MENU_BI_LEFT,20); MENU_SetBorderSize(hPrintMenu,MENU_BI_RIGHT,20); MENU_SetBorderSize(hFre,MENU_BI_LEFT,20); MENU_SetBorderSize(hFre,MENU_BI_RIGHT,20); MENU_SetBorderSize(hSite,MENU_BI_LEFT,20); MENU_SetBorderSize(hSite,MENU_BI_RIGHT,20); MENU_SetBorderSize(hInfo,MENU_BI_LEFT,20); MENU_SetBorderSize(hInfo,MENU_BI_RIGHT,20); MENU_SetBorderSize(hSiteSet,MENU_BI_LEFT,10); MENU_SetBorderSize(hSiteSet,MENU_BI_RIGHT,10); MENU_SetBorderSize(hInfoSet,MENU_BI_LEFT,10); MENU_SetBorderSize(hInfoSet,MENU_BI_RIGHT,10); //添加菜单项 _AddMenuItem(hPrintMenu, 0, "所有储存信息", ID_Print_All , 0); _AddMenuItem(hPrintMenu, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hPrintMenu, 0, "正在显示的信息", ID_Print_Showing , 0); _AddMenuItem(hPrintMenu, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hPrintMenu, hFre, "按频率分类打印", ID_Print_Frequency , 0); _AddMenuItem(hPrintMenu, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hPrintMenu, hSite, "按站点分类打印", ID_Print_Site , 0); _AddMenuItem(hPrintMenu, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hPrintMenu, hInfo, "按信息分类打印", ID_Print_Info , 0); _AddMenuItem(hFre, 0, "国际频道(518KHz)", ID_Print_Fre_Int , 0); _AddMenuItem(hFre, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hFre, 0, "本地频道I(490KHz)", ID_Print_Fre_Loc1 , 0); _AddMenuItem(hFre, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hFre, 0, "本地频道II(4209.5KHz)", ID_Print_Fre_Loc2 , 0); _AddMenuItem(hFre, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hFre, 0, "中文频道(486KHz)", ID_Print_Fre_Chs , 0); _AddMenuItem(hSite, 0, "打印", ID_Print_Site_Prt , 0); _AddMenuItem(hSite, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hSite, hSiteSet, "站点设置", ID_Print_Site_SiteSet , 0); _AddMenuItem(hSiteSet, 0, "A打印", ID_Print_Site_SiteSet_Prt_0 , 0); _AddMenuItem(hSiteSet, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hSiteSet, 0, "B打印", ID_Print_Site_SiteSet_Prt_1 , 0); _AddMenuItem(hSiteSet, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hSiteSet, 0, "C打印", ID_Print_Site_SiteSet_Prt_2 , 0); _AddMenuItem(hSiteSet, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hSiteSet, 0, "D打印", ID_Print_Site_SiteSet_Prt_3 , 0); _AddMenuItem(hSiteSet, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hSiteSet, 0, "E打印", ID_Print_Site_SiteSet_Prt_4 , 0); _AddMenuItem(hInfo, 0, "打印", ID_Print_Info_Prt , 0); _AddMenuItem(hInfo, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hInfo, hInfoSet, "信息设置", ID_Print_Info_InfoSet , 0); _AddMenuItem(hInfoSet, 0, "A打印", ID_Print_Info_InfoSet_Prt_0 , 0); _AddMenuItem(hInfoSet, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hInfoSet, 0, "B打印", ID_Print_Info_InfoSet_Prt_1 , 0); _AddMenuItem(hInfoSet, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hInfoSet, 0, "C打印", ID_Print_Info_InfoSet_Prt_2 , 0); _AddMenuItem(hInfoSet, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hInfoSet, 0, "D打印", ID_Print_Info_InfoSet_Prt_3, 0); _AddMenuItem(hInfoSet, 0, 0, 0, MENU_IF_SEPARATOR); //分割线 _AddMenuItem(hInfoSet, 0, "E打印", ID_Print_Info_InfoSet_Prt_4 , 0); MENU_Attach (hPrintMenu,hWin,0,60,0,0,0); WM_SetFocus(hPrintMenu); // MENU_SetSel(hMenu, 0); return hWin; }
/********************************************************************* * * _CreateMenu */ static WM_HWIN _CreateMenu(WM_HWIN hParent) { MENU_Handle hMenu, hMenuFile, hMenuEdit, hMenuHelp, hMenuRecent; // Create main menu hMenu = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_HORIZONTAL, ID_MENU); // Create sub menus hMenuFile = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); hMenuEdit = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); hMenuHelp = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); hMenuRecent = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); // Add menu items to menu 'Recent' _AddMenuItem(hMenuRecent, 0, "File 0", ID_MENU_RECENT_0, 0); _AddMenuItem(hMenuRecent, 0, "File 1", ID_MENU_RECENT_1, 0); _AddMenuItem(hMenuRecent, 0, "File 2", ID_MENU_RECENT_2, 0); _AddMenuItem(hMenuRecent, 0, "File 3", ID_MENU_RECENT_3, 0); // Add menu items to menu 'File' _AddMenuItem(hMenuFile, 0, "New", ID_MENU_FILE_NEW, 0); _AddMenuItem(hMenuFile, 0, "Open", ID_MENU_FILE_OPEN, 0); _AddMenuItem(hMenuFile, 0, "Close", ID_MENU_FILE_CLOSE, 0); _AddMenuItem(hMenuFile, 0, 0, 0, MENU_IF_SEPARATOR); _AddMenuItem(hMenuFile, hMenuRecent, "Files...", ID_MENU_FILE_RECENT, 0); _AddMenuItem(hMenuFile, 0, 0, 0, MENU_IF_SEPARATOR); _AddMenuItem(hMenuFile, 0, "Exit", ID_MENU_FILE_EXIT, 0); // Add menu items to menu 'Edit' _AddMenuItem(hMenuEdit, 0, "Undo", ID_MENU_EDIT_UNDO, 0); _AddMenuItem(hMenuEdit, 0, "Redo", ID_MENU_EDIT_REDO, 0); _AddMenuItem(hMenuEdit, 0, 0, 0, MENU_IF_SEPARATOR); _AddMenuItem(hMenuEdit, 0, "Copy", ID_MENU_EDIT_COPY, 0); _AddMenuItem(hMenuEdit, 0, "Paste", ID_MENU_EDIT_PASTE, 0); _AddMenuItem(hMenuEdit, 0, "Delete", ID_MENU_EDIT_DELETE, 0); // Add menu items to menu 'Help' _AddMenuItem(hMenuHelp, 0, "About", ID_MENU_HELP_ABOUT, 0); // Add menu items to main menu _AddMenuItem(hMenu, hMenuFile, "File", 0, 0); _AddMenuItem(hMenu, hMenuEdit, "Edit", 0, 0); _AddMenuItem(hMenu, hMenuHelp, "Help", 0, 0); // Attach menu to parent window MENU_Attach(hMenu, hParent, 0, 0, WM_GetWindowSizeX(hParent), 0, 0); return hMenu; }