/// <summary> /// Get matching menu entries from menus of all ctls opened. /// </summary> /// <param name = "entryName">name to be matched</param> /// <param name = "currentPulldownMenu">current pulldown menu</param> private ArrayList GetMatchingMenuValues(Int64 contextID, String entryName, MgMenu currentPulldownMenu) { entryName = entryName.Trim(); ArrayList menuEntryList = new ArrayList(); // Go through all ctls to get matching menus int ctlIdx = 0; TaskBase mainProg = (TaskBase)Manager.MGDataTable.GetMainProgByCtlIdx(contextID, ctlIdx); while (mainProg != null) { ApplicationMenus menus = getApplicationMenus(mainProg); if (menus != null) { ArrayList tempMenuEntryList = menus.GetMatchingMenuValues(entryName, currentPulldownMenu); if (tempMenuEntryList != null) { menuEntryList.AddRange(tempMenuEntryList); } } ctlIdx++; mainProg = (TaskBase)Manager.MGDataTable.GetMainProgByCtlIdx(contextID, ctlIdx); } return(menuEntryList); }
public TaskDefinitionId TaskCalledByMenu(int menuId, TaskBase mainProg) { //fixed bug#:431559, the menu need to be take from menuCtlIndex main program. ApplicationMenus applicationMenus = getApplicationMenus(mainProg); MenuEntryProgram menuEntry = applicationMenus.menuByUid(menuId) as MenuEntryProgram; TaskDefinitionId taskDefinitionId = new TaskDefinitionId(menuEntry.CtlIndex, menuEntry.ProgramIsn, 0, true); return(taskDefinitionId); }
/// <summary> /// destroy and rebuild menus for the passed file. /// </summary> public void destroyAndRebuild(String menusFileName) { ApplicationMenus appMenus = (ApplicationMenus)_applicationMenusMap[menusFileName]; if (appMenus != null) { // remove previous object - no longer needed _applicationMenusMap.Remove(menusFileName); appMenus.destroyAndRebuild(); } }
/// <summary> /// get Menu's index. /// </summary> /// <param name = "mainProg">main prog</param> /// <param name = "entryName">menuentry name</param> /// <param name = "isPublic"></param> public int GetMenuIdx(TaskBase mainProg, String entryName, bool isPublic) { int index = 0; ApplicationMenus menus = getApplicationMenus(mainProg); if (menus != null) { index = menus.menuIdxByName(entryName, isPublic); } return(index); }
/// <summary> /// Create an open task command from a menu command /// </summary> /// <param name="command"></param> /// <returns></returns> internal LocalRunTimeCommandBase CreateMenuExecuteOperationCommand(MenuCommand command) { // Get the relevant menu entry // QCR #283731. Use MenuComp on command for the relevant Ctl. Task mainProg = MGDataCollection.Instance.GetMainProgByCtlIdx(command.MenuComp); ApplicationMenus applicationMenus = Manager.MenuManager.getApplicationMenus(mainProg); MenuEntryProgram menuEntry = applicationMenus.menuByUid(command.MenuUid) as MenuEntryProgram; TaskDefinitionId taskDefinitionId = new TaskDefinitionId(menuEntry.CtlIndex, menuEntry.ProgramIsn, 0, true); ArgumentsList argList = GetCommandArgumentList(command, menuEntry, mainProg); return(new LocalRunTimeCommandOpenTask(taskDefinitionId) { ArgList = argList, CallingTaskTag = command.TaskTag, PathParentTaskTag = command.TaskTag }); }
/// <summary> /// This method initializes an application’s menus object, from the passed menusFileName /// (loads the menus xml file to matching data structures). /// </summary> /// <param name="mainProg"></param> /// <returns></returns> public ApplicationMenus getApplicationMenus(TaskBase mainProg) { if (mainProg == null) { return(null); } // build the menus file URL from the name and the rights hash code String menusKey = mainProg.getMenusFileURL(); ApplicationMenus appMenus = null; if (menusKey != null) { appMenus = (ApplicationMenus)_applicationMenusMap[menusKey]; if (appMenus == null) { try { byte[] menusFileContent = mainProg.getMenusContent(); // build the application menus appMenus = new ApplicationMenus(menusFileContent); // set the indexes of the menu entries relative to their immediate parents. // also set the CtlIdx of the application that contains the menu on the MgMenu, int CtlIdx = mainProg.getCtlIdx(); IEnumerator iMgMenu = appMenus.iterator(); while (iMgMenu.MoveNext()) { MgMenu mgmenu = (MgMenu)iMgMenu.Current; mgmenu.setIndexes(true); mgmenu.CtlIdx = CtlIdx; } _applicationMenusMap[menusKey] = appMenus; } catch (Exception ex) { Events.WriteExceptionToLog(ex); } } } return(appMenus); }
/// <summary> /// The menu texts needs to be refreshed due to a change in the language. /// </summary> private void RefreshMenusText() { int ctlIdx = 0; Task mainProg = (Task)MGDataCollection.Instance.GetMainProgByCtlIdx(ctlIdx); while (mainProg != null) { ApplicationMenus menus = Manager.MenuManager.getApplicationMenus(mainProg); // call refreshMenuesTextMls for each application menu of components, starting with the main. if (menus != null) { menus.refreshMenuesTextMls(); } ctlIdx = mainProg.getCtlIdx(); mainProg = (Task)mainProg.getMGData().getNextMainProg(ctlIdx); } }
/// <summary> /// The menu texts needs to be refreshed due to a change in the language. /// </summary> /// <param name = "contextID">The context on which menues will be refreshed.</param> public void RefreshMenusText(Int64 contextID) { // Go through all ctls in the context. Each ctl has its own application menu. int ctlIdx = 0; TaskBase mainProg = (TaskBase)Manager.MGDataTable.GetMainProgByCtlIdx(contextID, ctlIdx); while (mainProg != null) { ApplicationMenus menus = getApplicationMenus(mainProg); // call refreshMenuesTextMls for each application menu of components, starting with the main. if (menus != null) { menus.refreshMenuesTextMls(); } ctlIdx++; mainProg = (TaskBase)Manager.MGDataTable.GetMainProgByCtlIdx(contextID, ctlIdx); } }
/// <summary> /// gets menu path. /// </summary> /// <param name = "mainProg"></param> /// <param name = "menuUid"></param> public String GetMenuPath(TaskBase mainProg, int menuUid) { String tmpMenuPath = ""; String MenuPath = ""; // Read all menus present inside Menu repository ApplicationMenus menus = getApplicationMenus(mainProg); if (menus != null && menuUid != 0) { MenuEntry menuEntry = menus.menuByUid(menuUid); if (menuEntry != null) { tmpMenuPath = BuildProgramMenuPath(menuEntry); MenuPath = tmpMenuPath.Substring(0, tmpMenuPath.Length - 1); } } return(MenuPath); }
/// <summary> /// show/hide menu entry identified by entryName. /// </summary> /// <param name = "task"></param> /// <param name = "entryName">menuentry name</param> /// <param name = "show">show/hide value</param> public bool MenuShowByName(TaskBase task, String entryName, bool show) { bool pulldownMenuModified = false; MgMenu pulldownMenu = GetPulldownMenu(task); // Get matching menus from all ctls ArrayList menuEntryList = GetMatchingMenuValues(task.ContextID, entryName, pulldownMenu); if (menuEntryList != null) { IEnumerator iMatchingEnt = menuEntryList.GetEnumerator(); while (iMatchingEnt.MoveNext()) { var menuValue = (MenuValue)iMatchingEnt.Current; var mnuEnt = menuValue.InnerMenuEntry; if (menuValue.IsPulldown) { pulldownMenuModified = true; } mnuEnt.setVisible(show, false, menuValue.IsPulldown, task, null); } } // If the menu is being shown, then refresh 'enable' state of internal event menus if (show && pulldownMenuModified) { int ctlIdx = 0; TaskBase mainProg = (TaskBase)Manager.MGDataTable.GetMainProgByCtlIdx(task.ContextID, ctlIdx); ApplicationMenus menus = getApplicationMenus(mainProg); MgFormBase formOrg = (MgFormBase)task.getTopMostForm(); MgFormBase form = (MgFormBase)formOrg.getTopMostFrameForm(); // fixed bug#:773382, when there is no SDI\MDI need to get the org form (for the context menu) form = (form ?? formOrg); menus.refreshInternalEventMenus(form); } return(true); }
/// <summary> /// This method returns a specific menu object, which matches the passed menu index. It checks if the wanted /// menu already exists. If it does not, it calls the CreateMenu method for this entry. The matching MgMenu /// object is returned. This method will be called from the Property::RefreshDisplay. It will provide the /// Property mechanism with a matching MenuEntry to the specified menu identification. /// </summary> /// <param name="mainProg"></param> /// <param name="menuIndex"></param> /// <param name="menuStyle">type of the menu: MENU_TYPE_PULLDOWN, MENU_TYPE_CONTEXT</param> /// <param name="form"></param> /// <param name="createIfNotExist">This will decide if menu is to be created or not.</param> /// <returns></returns> public MgMenu getMenu(TaskBase mainProg, int menuIndex, MenuStyle menuStyle, MgFormBase form, bool createIfNotExist) { MgMenu retMenu = null; if (mainProg.menusAttached()) { ApplicationMenus appMenus = getApplicationMenus(mainProg); if (appMenus != null) { retMenu = appMenus.getMgMenu(menuIndex); if (createIfNotExist && retMenu != null && !retMenu.menuIsInstantiated(form, menuStyle)) { // this menu does not have a matching java object for this shell – we need to create it // Context menus are created & destroyed on the fly. For context menu, if no visible menu entry // is found at 1st level, then don't create it. Because, if no visible menu entry is found , // no popup is displayed, So menu gets instantiated but it is not destroyed as we don't get CLOSING message. if (menuStyle == MenuStyle.MENU_STYLE_CONTEXT) { if (retMenu.isAnyMenuEntryVisible()) { retMenu.createMenu(form, menuStyle); } else { retMenu = null; } } else { retMenu.createMenu(form, menuStyle); } } } } return(retMenu); }
/// <summary> /// Remove menu identified by menuIdx, in current pulldown menu at menuPath specified. /// </summary> /// <param name = "mainProg"></param> /// <param name = "menuIdx"></param> /// <param name = "menuPath"></param> public bool MenuRemove(TaskBase mainProg, TaskBase task, int menuIdx, String menuPath) { Boolean success = false; // Read all menus present inside Menu repository ApplicationMenus menus = getApplicationMenus(mainProg); int index = menuIdx; // index of the menu inside Menu repository MgMenu delMenu = menus.getMgMenu(index); // menu structure to delete MgFormBase topMostFrameForm = (MgFormBase)task.getForm() == null ? null : (MgFormBase)task.getForm().getTopMostFrameForm(); MgMenu pulldownMenu = GetPulldownMenu(task); if (delMenu == null || pulldownMenu == null) { success = false; } else { // If path, from where the menu to be deleted is Null and 1.menu to be deleted is pulldown menu. The delete pulldown menu // menu to be deleted is not pulldown menu, search the whole menu. if (String.IsNullOrEmpty(menuPath)) { success = true; if (delMenu == pulldownMenu) //remove all entries from pulldown menu { // Set PulldownMenuIdx to 0. this will reset the menu. int saveMenuIdx = topMostFrameForm.getPulldownMenuNumber(); topMostFrameForm.setPulldownMenuNumber(0, true); topMostFrameForm.setPulldownMenuNumber(saveMenuIdx, false); } else { SearchAndRemoveMenuEntries(0, delMenu, pulldownMenu, topMostFrameForm); } } // Function will fail if consecutive "\\" are found in the menu path else if (menuPath.IndexOf("\\\\") >= 0) { success = false; } // Valid Menu Path else { int idx = 0; Object menuPos = null; menuPath = menuPath.TrimEnd(' '); success = FindMenuPath(pulldownMenu, menuPath, ref menuPos, ref idx); if (success) { SearchAndRemoveMenuEntries(idx, delMenu, menuPos, topMostFrameForm); } } } if (success) { if (pulldownMenu != null) { pulldownMenu.refreshInternalEventMenus(topMostFrameForm); } } return(success); }
/// <summary> /// Add menu identified by menuIdx, in current pulldown menu at menuPath specified. /// </summary> /// <param name = "mainProg">main prog</param> /// <param name = "menuIdx">menu to be added</param> /// <param name = "menuPath">menu path</param> public bool MenuAdd(TaskBase mainProg, TaskBase task, int menuIdx, String menuPath) { Boolean success = false; // Read all menus present inside Menu repository ApplicationMenus menus = getApplicationMenus(mainProg); int index = menuIdx; // index of the menu inside Menu repository MgMenu addMenu = menus.getMgMenu(index); // menu structure to add MgMenu pulldownMenu = GetPulldownMenu(task); MgFormBase topMostFrameForm = (MgFormBase)task.getForm() == null ? null : (MgFormBase)task.getForm().getTopMostFrameForm(); if (addMenu == null) { success = false; } // Add Menu to Current Pulldown Menu, only if the menu to add is not Current Pulldown Menu else if (pulldownMenu != null && topMostFrameForm.getPulldownMenuNumber() > 0 && index != topMostFrameForm.getPulldownMenuNumber()) { // if new menu is to be added, make a new menu by clone instead of using the same reference var clonedMenu = (MgMenu)addMenu.Clone(); MgMenu root = topMostFrameForm.getPulldownMenu(); bool includeInMenu = topMostFrameForm.isUsedAsPulldownMenu(root); bool includeInContext = topMostFrameForm.isUsedAsContextMenu(root); // If path, where the menu is to be added, is Null, then add the menu at the end of Current Pulldown Menu. if (String.IsNullOrEmpty(menuPath)) { // If menu is not instantiated, it means old menu is deleted, so assign new menu as pulldown menu. if (pulldownMenu.getInstantiatedMenu(topMostFrameForm, MenuStyle.MENU_STYLE_PULLDOWN) == null) { topMostFrameForm.setPulldownMenuNumber(index, true); success = true; } else if (!String.IsNullOrEmpty(clonedMenu.getName())) { IEnumerator iAddMenu = clonedMenu.iterator(); MenuEntry newMenuEntry; // Iterate through all menu entries inside Menu structure to be added, and add it to the current // Pulldown Menu Structure while (iAddMenu.MoveNext()) { newMenuEntry = (MenuEntry)iAddMenu.Current; root.addSubMenu(newMenuEntry); newMenuEntry.setParentRootMgMenu(root); // set orgindex as -1, so that resetIndexes() will recalculate orgIndex newMenuEntry.setIndex(-1); #if PocketPC // Add menu entry to the Pulldown Menu if menu entry is visible SetAddedMenuVisible(newMenuEntry, includeInMenu, task); #else // Add menu entry object to the Pulldown Menu for newly added menu entries. newMenuEntry.CreateNewlyAddedMenus(root, topMostFrameForm); #endif } success = true; } } // Function will fail if consecutive "\\" are found in the menu path else if (menuPath.IndexOf("\\\\") >= 0) { success = false; } // Valid Menu Path else { if (!String.IsNullOrEmpty(clonedMenu.getName())) { int idx = 0; Object menuPos = null; menuPath = menuPath.TrimEnd(' '); success = FindMenuPath(root, menuPath, ref menuPos, ref idx); if (success) { IEnumerator iAddMenu = clonedMenu.iterator(); MenuEntry newMenuEntry; int i = 0; // if menu to be added to root menu i.e Current Pulldown Menu if (menuPos.GetType() == typeof(MgMenu)) { while (iAddMenu.MoveNext()) { newMenuEntry = (MenuEntry)iAddMenu.Current; root.addMenu(newMenuEntry, idx + i); newMenuEntry.setParentRootMgMenu(root); // set orgindex as -1, so that resetIndexes() will recalculate orgIndex newMenuEntry.setIndex(-1); #if PocketPC // Add menu entry to the Pulldown Menu if menu entry is visible SetAddedMenuVisible(newMenuEntry, includeInMenu, task); #else // Add menu entry object to the Pulldown Menu for newly added menu entries. newMenuEntry.CreateNewlyAddedMenus(root, topMostFrameForm); #endif i++; } } else // if menu to be added to any menu entry { while (iAddMenu.MoveNext()) { newMenuEntry = (MenuEntry)iAddMenu.Current; // set the root parent menu newMenuEntry.setParentRootMgMenu(((MenuEntry)menuPos).getParentMgMenu()); // set immediate parent of the menu entry newMenuEntry.ParentMenuEntry = ((MenuEntry)menuPos).ParentMenuEntry; // set orgindex as -1, so that resetIndexes() will recalculate orgIndex newMenuEntry.setIndex(-1); ((MenuEntryMenu)menuPos).addSubMenu(newMenuEntry, idx + i); #if PocketPC // Add menu entry to the Pulldown Menu if menu entry is visible SetAddedMenuVisible(newMenuEntry, includeInMenu, task); #else // Add menu entry object to the Pulldown Menu for newly added menu entries. newMenuEntry.CreateNewlyAddedMenus(((MenuEntry)menuPos).getInstantiatedMenu(topMostFrameForm, MenuStyle.MENU_STYLE_PULLDOWN), topMostFrameForm); #endif i++; } } } } } } else { //If no pulldown menu is attached, menu to be added should be assigned as pulldown menu. if (topMostFrameForm != null) { if (topMostFrameForm.getPulldownMenuNumber() == 0) { topMostFrameForm.setPulldownMenuNumber(menuIdx, true); } else { topMostFrameForm.getProp(PropInterface.PROP_TYPE_PULLDOWN_MENU).RefreshDisplay(true, Int32.MinValue, false); } success = true; } } if (success) { if (menus != null) { menus.refreshInternalEventMenus(topMostFrameForm); } } return(success); }
/// <summary> /// close the task, if the wide is open, then close is before close the task /// </summary> /// <param name = "form"> </param> /// <param name="mainPrgTask"></param> public static void Abort(MgFormBase form, TaskBase mainPrgTask) { ApplicationMenus menus = MenuManager.getApplicationMenus(mainPrgTask); MgFormBase topMostForm = form.getTopMostForm(); if (topMostForm.wideIsOpen()) { topMostForm.closeWide(); } // Context menu will not automatically dispose when form is dispose. we need to dispose it menually. if (menus != null) { menus.disposeFormContexts(form); } // remove the instantiatedToolbar as this is not removed from Dispose handler. MgMenu mgMenu = form.getPulldownMenu(); if (mgMenu != null) { mgMenu.removeInstantiatedToolbar(form); } if (form.getSubFormCtrl() == null) { // if the closing form is 'opened as a modal' then decrement the modal count on its frame window. if (form.isDialog()) { MgFormBase topMostFrameForm = form.getTopMostFrameForm(); if (topMostFrameForm != null) { topMostFrameForm.UpdateModalFormsCount(form, false); } } #if !PocketPC // If the form was added into WindowMenu then remove it from list before closing it. if (form.IsValidWindowTypeForWidowList) { Property prop = form.GetComputedProperty(PropInterface.PROP_TYPE_SHOW_IN_WINDOW_MENU); if (prop != null && prop.GetComputedValueBoolean()) { MenuManager.WindowList.Remove(form); } } #endif Commands.addAsync(CommandType.CLOSE_FORM, form); // QCR# 307199/302197: When a task closes, its form is closed, where it activates topmost form of // ParentForm. If Print Preview is activated, this is not required. Instead Print Preview form // should be activated. if (!PrintPreviewFocusManager.GetInstance().ShouldPrintPreviewBeFocused) { /* QCR #939802. This bug is since 1.9 after the check-in of version 41 of GuiCommandsQueue.cs */ /* From that version onwards, we started to set the owner of the Floating window. */ /* Now, when we close a form, the .Net Framework activates the form which spawned this form. */ /* But in this special case of the QCR, while closing the 3rd form, framework activated the */ /* 1st form instead of the 2nd. */ /* So, when pressing Esc, the 1st form got closed (and of course, because of this all forms got */ /* closed. */ /* The solution is to explicitly activate the parent form when a form is closed. */ // If interactive offline task calls, non interactive non offline task, after closing the parent task // focus is not switched back to caller task, but it is set on MDI Frame. To avoid this, activate parent // form only if called task's form is opened. MgFormBase formToBeActivated = form.ParentForm; if (form.FormToBoActivatedOnClosingCurrentForm != null) { formToBeActivated = form.FormToBoActivatedOnClosingCurrentForm; } if (formToBeActivated != null && form.getTask() != null && !form.getTask().IsParallel && //not for parallel !MgFormBase.isMDIChild(form.ConcreteWindowType) && //not for mdi children Defect 128265 form.Opened) { Commands.addAsync(CommandType.ACTIVATE_FORM, formToBeActivated.getTopMostForm()); if (form.ConcreteWindowType == WindowType.ChildWindow) { TaskBase task = formToBeActivated.getTask(); MgControlBase mgControl = task.getLastParkedCtrl(); if (mgControl != null) { Commands.addAsync(CommandType.SET_FOCUS, mgControl, mgControl.getDisplayLine(false), true); } } } } } else { // Defect 115062. For frames remove controls also from frame control. if (form.getContainerCtrl() != null) { Commands.addAsync(CommandType.REMOVE_SUBFORM_CONTROLS, form.getContainerCtrl()); } Commands.addAsync(CommandType.REMOVE_SUBFORM_CONTROLS, form.getSubFormCtrl()); } Commands.beginInvoke(); Thread.Sleep(10); }