示例#1
0
        /// <summary>
        ///   read form-state of the form, and applies them
        /// </summary>
        /// <param name = "mgform"></param>
        internal void Apply(MgFormBase mgform)
        {
            try
            {
                // When opening the MDI form, use the details of the previous MDI form, if available.
                //This details have preference over the current form's persistent state.
                if (mgform.getTask().isMainProg() && mdiFormDetails != null)
                {
                    ApplyFormBounds(mgform, mdiFormDetails.rect.Left, mdiFormDetails.rect.Top, mdiFormDetails.rect.Width, mdiFormDetails.rect.Height, mdiFormDetails.windowState);
                    return;
                }

                XmlElement formNode = GetNode(mgform);
                if (formNode == null)
                {
                    return;
                }

                Int32 oldPersistentFormStateVersion = 0;
                Int32.TryParse(formNode.GetAttribute(TAG_Version), out oldPersistentFormStateVersion);

                if (oldPersistentFormStateVersion != mgform.getProp(PropInterface.PROP_TYPE_PERSISTENT_FORM_STATE_VERSION).GetComputedValueInteger())
                {
                    return;
                }

                // QCR # 734135, check if form has no data to apply. All child elements are control tags.
                List <XmlElement> childNodes = XmlServices.getMatchingChildrens(formNode, STR_CONTROL, null, null);
                if (formNode.ChildNodes.Count == childNodes.Count)
                {
                    return;
                }

                XmlElement framesetsNode = null;
                XmlElement tableNode = null;
                int        left = 0, top = 0, width = 0, height = 0;
                int        startupStyle = 0;

                // traverse through all child node of form node and get the saved propVal and apply
                foreach (XmlElement currEle in formNode.ChildNodes)
                {
                    if (currEle.Name == STR_STARTUP_STYLE)
                    {
                        startupStyle = int.Parse(currEle.GetAttribute(TAG_VALUE));
                    }
                    else if (currEle.Name == STR_LEFT)
                    {
                        left = int.Parse(currEle.GetAttribute(TAG_VALUE)); // read val
                    }
                    else if (currEle.Name == STR_TOP)
                    {
                        top = int.Parse(currEle.GetAttribute(TAG_VALUE)); // read val
                    }
                    else if (currEle.Name == STR_WIDTH)
                    {
                        width = int.Parse(currEle.GetAttribute(TAG_VALUE)); // read val
                    }
                    else if (currEle.Name == STR_HEIGHT)
                    {
                        height = int.Parse(currEle.GetAttribute(TAG_VALUE)); // read val
                    }
                    else if (currEle.Name == STR_FRAMESETS)
                    {
                        framesetsNode = currEle;
                    }
                    else if (currEle.Name == STR_TABLECOLS)
                    {
                        tableNode = currEle;
                    }
                }

                // donot apply form coordinates for nested forms
                if (!mgform.isSubForm() && !mgform.IsChildWindow)
                {
                    //If the left-top corner is beyond the screen boundaries, ignore it.
                    if (!mgform.IsMDIChild)
                    {
                        MgRectangle rect = new MgRectangle();
                        Commands.getDesktopBounds(rect, null);

                        if (left >= rect.width)
                        {
                            left = GuiConstants.DEFAULT_VALUE_INT;
                        }
                        if (top >= rect.height)
                        {
                            top = GuiConstants.DEFAULT_VALUE_INT;
                        }
                    }

                    ApplyFormBounds(mgform, left, top, width, height, startupStyle);
                }

                // apply framesets
                if (framesetsNode != null)
                {
                    ApplyFramesetsProp(framesetsNode, mgform);
                }

                // apply table
                if (tableNode != null)
                {
                    ApplyTableProp(tableNode, mgform);
                }

                // #924756 - do not apply top left width height if the property has an expression attached
                if (startupStyle != Styles.WINDOW_STATE_MAXIMIZE && !mgform.IsChildWindow)
                {
                    mgform.RefreshPropertyByExpression(PropInterface.PROP_TYPE_LEFT);
                    mgform.RefreshPropertyByExpression(PropInterface.PROP_TYPE_TOP);
                    mgform.RefreshPropertyByExpression(PropInterface.PROP_TYPE_WIDTH);
                    mgform.RefreshPropertyByExpression(PropInterface.PROP_TYPE_HEIGHT);
                }
            }
            catch (Exception exception)
            {
                Events.WriteExceptionToLog(exception);
            }
        }