📄 menuutil.c
字号:
if (!menuInfoPtr->separator2ID) { menuInfoPtr->separator2ID = InsertSeparator(menuInfoPtr->menuBarHandle, menuInfoPtr->menuID, beforeMenuItemID); } beforeMenuItemID = menuInfoPtr->separator2ID; } /* Loop thru menu items in reverse order */ for (i=totalItems;(i>0);i--) { /* Get ith list item */ if (menuItemInfoPtr = ListGetPtrToItem (menuInfoPtr->menuItemInfoList, i)) { /* Remove previous menu item */ if (menuItemInfoPtr->menuItemID) { GetMenuBarAttribute (menuInfoPtr->menuBarHandle, menuItemInfoPtr->menuItemID, ATTR_CHECKED, &checked); DiscardMenuItem (menuInfoPtr->menuBarHandle, menuItemInfoPtr->menuItemID); menuItemInfoPtr->menuItemID = 0; } else checked = menuInfoPtr->checkWhenAdded; /* Create new menu item */ /* Determine the visible name for the menu item */ if (menuInfoPtr->preAppendShortCut) { if (i<10) sprintf(tempName, "__%d %s", i%10, menuItemInfoPtr->menuName); else if (i<36) sprintf(tempName, "__%c %s", (75-i), menuItemInfoPtr->menuName); else strcpy(tempName, menuItemInfoPtr->menuName); } else strcpy(tempName, menuItemInfoPtr->menuName); menuItemInfoPtr->menuItemID = NewMenuItem ( menuInfoPtr->menuBarHandle, menuInfoPtr->menuID, tempName, beforeMenuItemID, 0, InternalMenuCallback, (void *) menuInfoPtr->handle); SetMenuBarAttribute (menuInfoPtr->menuBarHandle, menuItemInfoPtr->menuItemID, ATTR_CHECKED, checked); } else success = 0; /* Setup before menu item id for next item */ beforeMenuItemID = menuItemInfoPtr->menuItemID; } /* Create Upper Separator */ if (menuInfoPtr->separator1ID) { /* Discard Upper Separator */ DiscardMenuItem (menuInfoPtr->menuBarHandle, menuInfoPtr->separator1ID); menuInfoPtr->separator1ID = 0; } if (menuInfoPtr->separator1) { if (!menuInfoPtr->separator1ID) { menuInfoPtr->separator1ID = InsertSeparator(menuInfoPtr->menuBarHandle, menuInfoPtr->menuID, beforeMenuItemID); } beforeMenuItemID = menuInfoPtr->separator1ID; } } else { /* Get rid of separators if they exist */ if (menuInfoPtr->separator1ID) { if (!DiscardMenuItem (menuInfoPtr->menuBarHandle, menuInfoPtr->separator1ID)) menuInfoPtr->separator1ID = 0; } if (menuInfoPtr->separator2ID) { if (!DiscardMenuItem (menuInfoPtr->menuBarHandle, menuInfoPtr->separator2ID)) menuInfoPtr->separator2ID = 0; } } } else success = 0; return success;}/*****************************************************//* UncheckAllCheckedItems() *//* *//* Parameters: *//* pointer to menu info *//* whether to remove the check from the first *//* item found *//* *//* Return: index into list for found item *//* *//* Purpose: Routine to search the menuItemInfo list *//* for the longName passed in *//* *//*****************************************************/static int UncheckAllCheckedItems( menuInfoRec *menuInfoPtr, int doNotUncheckFirstFound){ int i, totalItems, checked = 0; menuItemInfoRec * menuItemInfoPtr = NULL; if (menuInfoPtr->menuItemInfoList) { /* Loop to find handle in list */ totalItems = ListNumItems (menuInfoPtr->menuItemInfoList); for (i=1;(i<=totalItems);i++) { menuItemInfoPtr = ListGetPtrToItem (menuInfoPtr->menuItemInfoList, i); if ((menuItemInfoPtr) && (menuItemInfoPtr->menuItemID)) { if (doNotUncheckFirstFound) { GetMenuBarAttribute (menuInfoPtr->menuBarHandle, menuItemInfoPtr->menuItemID, ATTR_CHECKED, &checked); if (checked) doNotUncheckFirstFound = 0; } else SetMenuBarAttribute (menuInfoPtr->menuBarHandle, menuItemInfoPtr->menuItemID, ATTR_CHECKED, 0); } } } return 0; }/*****************************************************//* RemoveDuplicates() *//* *//* Parameters: *//* menuItemInfoList handle *//* *//* Return: index into list for found item *//* *//* Purpose: Routine to search the menuItemInfo list *//* for the longName passed in *//* *//*****************************************************/static int RemoveDuplicates( menuInfoRec *menuInfoPtr){ int i, j, totalItems; menuItemInfoRec * menuItemInfoPtr1 = NULL; menuItemInfoRec * menuItemInfoPtr2 = NULL; if (menuInfoPtr->menuItemInfoList) { /* Loop to find handle in list */ totalItems = ListNumItems (menuInfoPtr->menuItemInfoList); for (i=1;(i<=totalItems);i++) { menuItemInfoPtr1 = ListGetPtrToItem (menuInfoPtr->menuItemInfoList, i); for (j=i+1;(j<=totalItems);j++) { menuItemInfoPtr2 = ListGetPtrToItem (menuInfoPtr->menuItemInfoList, j); if (!strcmp(menuItemInfoPtr1->menuName, menuItemInfoPtr1->menuName)) { /* Remove item */ RemoveMenuListItem(menuInfoPtr, j); totalItems--; } } } } return 0; }/*****************************************************//* MU_AddItemToMenuList() *//* *//* Parameters: *//* menuList *//* index location to insert *//* menu name to appear in menu *//* callback data to be sent to callback *//* *//* Return: success = 1 *//* *//* Purpose: Routine to Add a name to the menulist. *//* This will also update the menubar *//* *//*****************************************************/int CVIFUNC MU_AddItemToMenuList( menuList handle, int index, char *menuItemName, void *callbackData){ int success = 1, item; menuInfoRec * menuInfoPtr = NULL; menuItemInfoRec * menuItemInfoPtr = NULL; char *shortName = NULL; char *findPtr = NULL; if ((!menuItemName) || (!menuItemName[0]) ) { success = 0; goto Error; } /* Find the menuInfo in list */ if (item = FindMenuInfoInList(sMenuInfoList, handle)) { /* Get menuInfo from list */ menuInfoPtr = ListGetPtrToItem (sMenuInfoList, item); if ((menuInfoPtr) && (menuInfoPtr->menuItemInfoList) ) { /* List found, so create memory for new element */ if (menuItemInfoPtr = calloc(sizeof(menuItemInfoRec), 1)) { if (!menuInfoPtr->allowDuplicates) { /* See if item already exists in list */ if (item = FindMenuItemInfoFromMenuName(menuInfoPtr->menuItemInfoList, menuItemName)) { /* Remove the found item */ RemoveMenuListItem(menuInfoPtr, item); if ((index!=FRONT_OF_LIST) && (index!=END_OF_LIST) && (index>item)) { index--; if (index==0) index = FRONT_OF_LIST; } } } /* Fill in new item */ strncpy(menuItemInfoPtr->menuName, menuItemName, MAX_MENU_ITEM_LENGTH); menuItemInfoPtr->menuName[MAX_MENU_ITEM_LENGTH]=0; menuItemInfoPtr->callbackData = callbackData; menuItemInfoPtr->menuItemID = 0; /* Add new item to the list */ if ((success) && (!ListInsertItem (menuInfoPtr->menuItemInfoList, menuItemInfoPtr, index)) ) success = 0; /* free temporary memory */ if (menuItemInfoPtr) { free (menuItemInfoPtr); menuItemInfoPtr = NULL; } } else success = 0; } else success = 0; } else success = 0; /* Remove all checked items */ if ((menuInfoPtr->oneCheckItem) && (menuInfoPtr->checkWhenAdded)) UncheckAllCheckedItems(menuInfoPtr, 0); /* Update the users's menuBar */ if (success) success = UpdateMenuItems(menuInfoPtr);Error: return success; }/*****************************************************//* PutMenuListInIniFile() *//* *//* Parameters: *//* menuList from CreateMenuList() *//* handle for inifile Instrument driver *//* section name *//* tag name prefix *//* whether to use the menu callback data as *//* the tag name *//* *//* Return: status *//* *//* Purpose: Routine for putting menuList items into *//* an INIFILE handle *//* *//* Example: *//* [Section Name] *//* TagName1="value1" *//* TagName2="value2" *//* TagName3="value3" *//* TagName4="value4" *//* *//*****************************************************/int CVIFUNC MU_PutFileListInIniFile( menuList menuListHandle, IniText iniTextHandle, char *sectionName, char *tagPrefix, int useCallbackDataAsTagName){ int success = 1; int i, totalItems, item; menuInfoRec *menuInfoPtr = NULL; menuItemInfoRec *menuItemInfoPtr = NULL; char *tagName = NULL; /* Find the menuInfo in list */ if (item = FindMenuInfoInList(sMenuInfoList, menuListHandle)) { /* Get menuInfo from list */ menuInfoPtr = ListGetPtrToItem (sMenuInfoList, item); if ((menuInfoPtr) && (menuInfoPtr->menuItemInfoList) ) { /* Get number of items in list */ totalItems = ListNumItems (menuInfoPtr->menuItemInfoList); /* Loop thru menuItem list */ for (i=Min(totalItems, menuInfoPtr->maxItems);i>0;i--) { /* Get ith list item */ if (menuItemInfoPtr = ListGetPtrToItem (menuInfoPtr->menuItemInfoList, i)) { /* Add item to the INIFILE */ if ((useCallbackDataAsTagName) && (menuItemInfoPtr->callbackData)) { if(IniEx_PutRawStringListItem(iniTextHandle, sectionName, tagPrefix, (char *)menuItemInfoPtr->callbackData, menuInfoPtr->maxItems)<0) { success = 0; goto Error; } } else { if(IniEx_PutRawStringListItem(iniTextHandle, sectionName, tagPrefix, menuItemInfoPtr->menuName, menuInfoPtr->maxItems)<0) { success = 0; goto Error; } } } else success = 0; } /* malloc memory for tag name buffer */ if ( (tagName = (char *) malloc(sizeof(tagPrefix)+16))==NULL) { success = 0; goto Error; } tagName[0] = 0; /* Remove Items after maxItems */ i = Min(totalItems,menuInfoPtr->maxItems); while (i) { i++; sprintf(tagName, "%s%d", tagPrefix, i); if (Ini_ItemExists (iniTextHandle, sectionName, tagName)) Ini_RemoveItem (iniTextHandle, sectionName, tagName); else i=0; } if (tagName) { free(tagName); tagName = NULL; } } else success = 0; } else success = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -