예제 #1
0
파일: Manager.cs 프로젝트: rinavin/RCJS
        /// <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);
        }