Exemplo n.º 1
0
        private void InitContainer(FieldContainerBase container)
        {
            if (container.Globals.Parent != null)
            {
                container.Globals.DepthDifference = container.Globals.Parent.DepthDifference - 1;
            }
            container.PerformingLoad += new DynamicContainerDelegate(Subblock_OnExpanding);
            if (container.Globals.BlockNode.Attributes["name"] != null)
            {
                container.Name          = container.Globals.BlockNode.Attributes["name"].Value;
                container.ContainerName = StringOps.CapitalizeWords(container.Name);
            }
            container.FooterFont = new System.Drawing.Font("Segoe UI", 8.25F, FontStyle.Bold);
            container.Collapsed  = true;
            XmlNode node          = container.Globals.BlockNode;
            XmlNode shortDescNode = node.SelectSingleNode("shortdesc");
            XmlNode longDescNode  = node.SelectSingleNode("longdesc");
            XmlNode warningNode   = node.SelectSingleNode("warning");

            if (shortDescNode != null)
            {
                container.ShortDescription = shortDescNode.InnerText;
            }
            if (longDescNode != null)
            {
                container.LongDescription = longDescNode.InnerText;
            }
            if (warningNode != null)
            {
                container.Warning = warningNode.InnerText;
            }

            container.ResumeLayout(true);
            //container.LayoutEngine.Layout(container, new LayoutEventArgs(container, "Size"));
        }
Exemplo n.º 2
0
        public void DatabindChildrenToBlock(IBlock block, IFieldControlContainer container)
        {
            #region Old Method

            /*linkedBlock = block;
             *
             * if (block != null)
             * {
             * int index = -1;
             * IFieldControl[] childFields = GetChildFields();
             * foreach (FieldControlBase field in childFields)
             * {
             *  index++;
             *  field.Enabled = true;
             *
             *  try
             *  {
             *    // If the field is not a block, we will need to databind it.
             *    if (!(field is IBlockControl))
             *    {
             *      IField binding = (LocateFieldByName(linkedBlock, field.BoundPropertyName) as IField);
             *      if (binding != null)
             *      {
             *        field.DataBind(binding);
             *        Binding[] bindings = field.GetDataBindings();
             *        foreach (Binding bind in bindings)
             *        {
             *          bind.Parse += bind_Parse;
             *        }
             *      }
             *    }
             *    // If it is a block, we need to recurse on the block so that its children get databound.
             *    else
             *    {
             *      IBlockCollection binding = LocateFieldByName(linkedBlock, field.BoundPropertyName) as IBlockCollection;
             *      if (binding != null)
             *      {
             *        (field as IBlockControl).DataBindCollection(binding);
             *        (field as IBlockControl).Initialize();
             *      }
             *      else
             *        field.Enabled = false;
             *    }
             *  }
             *  catch (Exception ex)
             *  {
             *    Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "There was an error databinding to " + field.BoundPropertyName + ":" + ex.Message, ex);
             *    //MessageBox.Show("There was an error binding \"" + field.BoundPropertyName + ":\" " + ex.Message);
             *  }
             * }
             * }
             * else
             * {
             * foreach (FieldControlBase field in GetChildFields())
             *  field.Enabled = false;
             * }*/
            #endregion

            #region New Method
            if (container is FieldContainerBase)
            {
                container = (container as FieldContainerBase).FieldPanel;
            }
            if (container == null)
            {
                return;
            }
            //(container as Control).Enabled = (block != null);
            if (block == null)
            {
                IFieldControl[] children = container.GetChildFields();
                foreach (FieldControlBase field in children)
                {
                    field.Enabled = false;
                }
                return;
            }

            Control control = container as Control;
            // This is a bug-fix. At some point along the line, databinding was attached to an FieldContainerBase... so to fix it, we relink to the FieldPanel property.
            if (container is FieldContainerBase)
            {
                control = (container as FieldContainerBase).FieldPanel;
            }

            for (int x = 0; x < control.Controls.Count; x++)
            {
                Control curControl = control.Controls[x];
                curControl.Visible = true;

                // Determine whether or not the field is a FieldControlBase or not.
                FieldControlBase field = (curControl is FieldControlBase) ? curControl as FieldControlBase : null;

                #region the current control is a field
                if (field != null)
                {
                    field.Enabled = true;
                    #region If the field is not a block, we will need to databind it.
                    if (!(field is IBlockControl))
                    {
                        IField binding = (LocateFieldByName(block, field.BoundPropertyName) as IField);
                        if (binding != null)
                        {
                            field.DataBind(binding);
                            Binding[] bindings = field.GetDataBindings();
                            foreach (Binding bind in bindings)
                            {
                                bind.Parse += bind_Parse;
                            }
                        }
                        else
                        {
                            field.Enabled = false;
                        }
                    }
                    #endregion
                    else // This shouldn't happen, EVER!
                    {
                        Interfaces.Output.Write(Interfaces.OutputTypes.Information, "DatabindChildrenToBlock came across an IBlockControl.");
                    }
                }
                #endregion
                #region the current control is a block container.
                else if (curControl is Prometheus.Controls.BlockContainer)
                {
                    Prometheus.Controls.BlockContainer blockContainer = curControl as Prometheus.Controls.BlockContainer;
                    blockContainer.Enabled = true;
                    IBlock nextBlock = null;
                    BlockContainerPanel nextContainer = null;

                    #region get the next container
                    // We're getting all of the controls of type FieldContainerPanel, though there should only be one.

                    /*Control[] fieldContainerPanels = GetChildControlsByType(blockContainer, typeof(BlockContainerPanel));
                     * if (fieldContainerPanels.Length > 0)
                     * {
                     * nextContainer = fieldContainerPanels[0] as BlockContainerPanel;
                     * }
                     * else
                     * {
                     * // This is a warning because the rest of the tag will work properly and execution can continue as normal.
                     * Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "During databinding, the block \"" + blockContainer.BoundPropertyName + "\" did not have a field container panel!");
                     * continue;
                     * }*/
                    if (blockContainer.FieldPanel != null)
                    {
                        nextContainer = blockContainer.FieldPanel;
                    }

                    #endregion

                    #region get the next block

                    /*Control[] blocks = GetChildControlsByType(blockContainer, typeof(IBlockControl));
                     * if (blocks.Length > 0)
                     * {
                     * IBlockControl blockControl = blocks[0] as IBlockControl;
                     * blockControl.Container = nextContainer as IFieldControlContainer;
                     * IBlockCollection binding = LocateFieldByName(block, (blockControl as IBoundPropertyCapable).BoundPropertyName) as IBlockCollection;
                     * if (binding != null)
                     * {
                     *  blockControl.DataBindCollection(binding);
                     *  blockControl.Initialize();
                     * }
                     * }
                     * else
                     * {
                     * Interfaces.Output.Write(Interfaces.OutputTypes.Warning, "During databinding, the block \"" + blockContainer.BoundPropertyName + "\" did not have an IBlockControl!");
                     * continue;
                     * }*/
                    if (blockContainer.Block != null)
                    {
                        IBlockControl blockControl = blockContainer.Block;
                        if (blockContainer.FieldPanel == null)
                        {
                            blockControl.Container = blockContainer;
                        }
                        else
                        {
                            blockControl.Container = blockContainer.FieldPanel;
                        }
                        IBlockCollection binding = LocateFieldByName(block, (blockControl as IBoundPropertyCapable).BoundPropertyName) as IBlockCollection;
                        if (binding != null)
                        {
                            blockControl.DataBindCollection(binding);
                            blockControl.Initialize();
                        }
                        if (blockControl.SelectedBlockIndex > -1)
                        {
                            nextBlock = blockControl.BlockCollection.GetBlock(blockControl.SelectedBlockIndex);
                        }
                    }
                    #endregion

                    if ((nextBlock != null) && (nextContainer != null))
                    {
                        DatabindChildrenToBlock(nextBlock, nextContainer);
                    }
                }
                else if (curControl is FieldContainerBase)
                {
                    FieldContainerBase fieldContainer = curControl as FieldContainerBase;
                    fieldContainer.Enabled = true;

                    DatabindChildrenToBlock(block, fieldContainer.FieldPanel);
                }
                #endregion
            }
            #endregion
        }
Exemplo n.º 3
0
        public override bool Layout(object container, LayoutEventArgs layoutEventArgs)
        {
            bool dirty = false;

            if (container is FieldContainerPanel)
            {
                FieldContainerPanel panel = container as FieldContainerPanel;
                int minimumWidth          = (BlockWidth + (panel.DepthDifference * (panel.Margin.Left * 2))) - 1;

                if (panel.Width < minimumWidth)
                {
                    panel.Width = minimumWidth;
                    dirty       = true;
                }
                //panel.SuspendLayout();

                bool controlFound = (layoutEventArgs.AffectedControl == panel);

                int maxWidth = 0;

                System.Drawing.Point lastLocation = new Point();
                lastLocation = new System.Drawing.Point(panel.Margin.Left, panel.Margin.Top);

                bool inGroup    = false;
                int  groupCount = 0; // to prevent spacing of groups that don't have enough controls.
                for (int x = 0; x < panel.Controls.Count; x++)
                {
                    if (!controlFound)
                    {
                        if (panel.Controls[x] == layoutEventArgs.AffectedControl)
                        {
                            controlFound = true;
                        }
                    }

                    Point newLocation = lastLocation;

                    // List's go from top to bottom, thus, we don't need to do any layout until we get to the control that's changed.
                    if (controlFound)
                    {
                        if (panel.DrawBorder)
                        {
                            // if the current control is a field container...
                            if (panel.Controls[x] is IFieldControl)
                            {
                                newLocation = new Point(lastLocation.X + panel.Margin.Left, lastLocation.Y + panel.Padding.Top);
                                inGroup     = true;
                                groupCount++;
                            }
                            else
                            {
                                if ((inGroup) && (groupCount >= MinimumGroupCount))
                                {
                                    // put in some extra padding between groups.
                                    newLocation = new System.Drawing.Point(lastLocation.X, lastLocation.Y + 1);
                                }
                                else
                                {
                                    newLocation = new System.Drawing.Point(lastLocation.X, lastLocation.Y);
                                }
                                inGroup    = false;
                                groupCount = 0;
                            }
                        }

                        if (panel.Controls[x].Location != newLocation)
                        {
                            panel.Controls[x].Location = newLocation;
                            dirty = true;
                        }

                        if (panel.Controls[x] is FieldContainerBase)
                        {
                            FieldContainerBase tempContainer = panel.Controls[x] as FieldContainerBase;
                            bool isSuspended       = tempContainer.LayoutSuspended;
                            int  newContainerWidth = 0;
                            if (tempContainer.FieldPanel != null)
                            {
                                if (tempContainer.FieldPanel.DepthDifference > -1)
                                {
                                    newContainerWidth = (BlockWidth + (tempContainer.FieldPanel.DepthDifference * (tempContainer.Location.X * 2))) - 1;
                                }
                            }
                            else
                            if (tempContainer.Globals.DepthDifference > -1)
                            {
                                newContainerWidth = (BlockWidth + (tempContainer.Globals.DepthDifference * (tempContainer.Location.X * 2))) - 1;
                            }
                            if (newContainerWidth != 0)
                            {
                                if (newContainerWidth != tempContainer.Width)
                                {
                                    tempContainer.Width = newContainerWidth;
                                    dirty = true;
                                }
                            }
                            if (tempContainer.Block != null)
                            {
                                (tempContainer.Block as Control).Width = tempContainer.Width - 2;
                            }
                        }
                        else if (panel.Controls[x] is IFieldControl)
                        {
                            // Center the controls for Nick. This may need to be replaced if we ever desire the use of margins.
                            panel.Controls[x].Width = panel.Width - (panel.Controls[x].Location.X * 2);
                        }
                    }


                    lastLocation = new System.Drawing.Point(panel.Margin.Left, panel.Controls[x].Location.Y + panel.Controls[x].Height + panel.Padding.Top);

                    if (panel.Controls[x] is BlockContainerPanel)
                    {
                        if (panel.Controls[x].Width > maxWidth)
                        {
                            maxWidth = panel.Controls[x].Width;
                        }
                    }
                    else
                    if (panel.Controls[x].Location.X + panel.Controls[x].Width + panel.Padding.Right > maxWidth)
                    {
                        maxWidth = panel.Controls[x].Location.X + panel.Controls[x].Width + panel.Padding.Right;
                    }
                }

                #region Autosize the panel.
                if (panel.AutoSize == true)
                {
                    AutoSizePanel(ref dirty, panel, ref maxWidth, ref lastLocation);
                }
                #endregion

                if (!(panel.Parent is BlockContainer))
                {
                    if (panel.Width < minimumWidth)
                    {
                        panel.Width = minimumWidth + 1;
                        dirty       = true;
                    }
                }
                // Group controls...
                if (panel.DrawBorder)
                {
                    groups = GroupControls(typeof(IFieldControl), panel.Controls);
                }
                else
                {
                    groups = null;
                }

                //panel.Location = new Point(0, panel.Location.Y);

                //if (dirty)
//          panel.Invalidate(false);

                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        public override bool Layout(object container, LayoutEventArgs layoutEventArgs)
        {
            if (!(container is FieldContainerBase))
            {
                return(true);
            }
            FieldContainerBase @this = (FieldContainerBase)container;

            using (Graphics g = @this.CreateGraphics())
            {
                if (@this.Width < FieldListLayout.BlockWidth)
                {
                    @this.Width = FieldListLayout.BlockWidth + (@this.Globals.DepthDifference * (@this.Margin.Left * 2)) - 1;
                }

                // Calculate the header line height.
                SizeF s = MeasureCaptionString("A", @this.Font, 800, g);
                @this.LayoutValues.headerCaptionLineHeight = (int)s.Height;

                // Calculate the base header height.
                SizeF headerTextSize = MeasureCaptionString(@this.ContainerName, @this.Font, @this.Width, g);
                @this.LayoutValues.headerBaseHeight = (int)headerTextSize.Height + (@this.LayoutValues.padding * 2);

                //bool noDescription = String.IsNullOrEmpty(@this.LongDescription) && string.IsNullOrEmpty(@this.ShortDescription);
                string descriptionText = "";
                // Calculate the MoreInfo text height.
                if ((!String.IsNullOrEmpty(@this.LongDescription)) && (@this.ShowingLongDescription))
                {
                    SizeF moreInfoTextSize = MeasureCaptionString(@this.LongDescription, @this.LongDescriptionFont, @this.Width - (@this.LayoutValues.padding * 2) - (@this.LayoutValues.moreInfoPadding * 2), g);
                    @this.LayoutValues.moreInfoTextHeight = (int)moreInfoTextSize.Height; //+ @this.LayoutValues.moreInfoPadding + @this.LayoutValues.padding * 2;
                    descriptionText = @this.LongDescription;
                    @this.LayoutValues.headerBaseHeight += @this.LayoutValues.moreInfoTextHeight + (@this.LayoutValues.padding);
                }
                else if (!String.IsNullOrEmpty(@this.ShortDescription))
                {
                    SizeF moreInfoTextSize = MeasureCaptionString(@this.ShortDescription, @this.ShortDescriptionFont, @this.Width - (@this.LayoutValues.padding * 2) - (@this.LayoutValues.moreInfoPadding * 2), g);
                    @this.LayoutValues.moreInfoTextHeight = (int)moreInfoTextSize.Height; //+ //@this.LayoutValues.moreInfoPadding + @this.LayoutValues.padding * 2;
                    descriptionText = @this.ShortDescription;
                    @this.LayoutValues.headerBaseHeight += @this.LayoutValues.moreInfoTextHeight + (@this.LayoutValues.padding);
                }
                else
                {
                    @this.LayoutValues.moreInfoTextHeight = 0;
                }

                // Calculate full caption height.
                int fullCaptionHeight   = @this.LayoutValues.headerBaseHeight + 1;
                int descriptionLocation = (int)headerTextSize.Height + 5;
                //fullCaptionHeight += @this.LayoutValues.moreInfoTextHeight;
                Control lblMoreInfo = null;
                DevComponents.DotNetBar.LabelX lblWarning     = null;
                DevComponents.DotNetBar.LabelX lblDescription = null;
                Control btnCollapse = null;
                for (int x = 0; x < @this.Controls.Count; x++)
                {
                    if (@this.Controls[x].Name == "lblMoreInfo")
                    {
                        // Calculate MoreInfo link position and text.
//            @this.Controls[x].Text = moreInfoLinkTet(@this);
                        int linkPadding = ((@this.LayoutValues.headerCaptionLineHeight + @this.LayoutValues.padding * 2) - @this.Controls[x].Height) / 2 + 1;
                        @this.Controls[x].Location = new Point((int)headerTextSize.Width + @this.LayoutValues.padding, linkPadding);
                        lblMoreInfo         = @this.Controls[x];
                        lblMoreInfo.Visible = !String.IsNullOrEmpty(@this.LongDescription);
                        lblMoreInfo.Margin  = new Padding(0, 0, 0, 0);
                    }
                    else if (@this.Controls[x].Name == "btnCollapse")
                    {
                        btnCollapse = @this.Controls[x];
                        // Calculate the ToggleButton position.
                        int toggleButtonPadding = ((@this.LayoutValues.headerCaptionLineHeight + @this.LayoutValues.padding * 2) - @this.Controls[x].Height) / 2;
                        @this.Controls[x].Location = new Point((@this.Width - @this.Controls[x].Width) - toggleButtonPadding, toggleButtonPadding);
                        if (btnCollapse.Location.Y + btnCollapse.Height + @this.LayoutValues.padding > descriptionLocation)
                        {
                            descriptionLocation = btnCollapse.Location.Y + btnCollapse.Height + @this.LayoutValues.padding;
                        }
                    }
                    else if (@this.Controls[x].Name == "lblWarning")
                    {
                        lblWarning = (DevComponents.DotNetBar.LabelX)@this.Controls[x];
                    }
                    else if (@this.Controls[x].Name == "lblDescription")
                    {
                        lblDescription = (DevComponents.DotNetBar.LabelX)@this.Controls[x];
                    }
                }

                SizeF warningTextSize = new SizeF(0f, 0f);
                if (!String.IsNullOrEmpty(@this.Warning))
                {
                    warningTextSize = MeasureCaptionString(@this.Warning, @this.WarningFont, (@this.Width - lblWarning.Location.X + 1), g);
                    @this.LayoutValues.headerBaseHeight += (int)warningTextSize.Height + @this.LayoutValues.padding;
                }

                // Calculate the warning label position, taking into account its size.
                int warningLabelX = (int)headerTextSize.Width + 10;
                if (warningTextSize.Height > @this.LayoutValues.headerCaptionLineHeight) // we'll see how well this goes... :x
                {
                    if (lblMoreInfo != null)
                    {
                        lblMoreInfo.Location = new Point(@this.LayoutValues.padding, (int)headerTextSize.Height + (@this.LayoutValues.padding * 2));
                        if (descriptionLocation < lblMoreInfo.Location.Y + lblMoreInfo.Height + 5)
                        {
                            descriptionLocation = lblMoreInfo.Location.Y + lblMoreInfo.Height + 5;
                        }
                    }
                }
                else if (lblMoreInfo != null)
                {
                    if (lblMoreInfo.Visible)
                    {
                        if (warningLabelX < lblMoreInfo.Location.X + lblMoreInfo.Width + 5)
                        {
                            warningLabelX = lblMoreInfo.Location.X + lblMoreInfo.Width + 5;
                        }
                    }
                }

                // setup the warning label
                if ((lblWarning != null) && (!String.IsNullOrEmpty(@this.Warning)))
                {
                    lblWarning.Location = new Point(warningLabelX, @this.LayoutValues.padding);
                    //lblWarning.Width = (btnCollapse.Location.X - lblWarning.Location.X) - 5;
                    lblWarning.Height      = (int)warningTextSize.Height + 2;
                    lblWarning.MinimumSize = new Size((btnCollapse.Location.X - lblWarning.Location.X) - 5, 0);
                    lblWarning.MaximumSize = new Size(lblWarning.MinimumSize.Width, 0);

                    lblWarning.Visible = true;
                    if (lblWarning.Location.Y + lblWarning.Height + (@this.LayoutValues.padding) > fullCaptionHeight)
                    {
                        fullCaptionHeight = lblWarning.Location.Y + lblWarning.Height + (@this.LayoutValues.padding * 2);
                    }
                    if (lblWarning.Location.Y + lblWarning.Height + 5 > descriptionLocation)
                    {
                        descriptionLocation = lblWarning.Location.Y + lblWarning.Height + 5;
                    }
                }
                // Setup the description label
                if ((lblDescription != null) && (!String.IsNullOrEmpty(descriptionText)))
                {
                    int locationY = descriptionLocation;

                    lblDescription.Location    = new Point(@this.LayoutValues.padding, locationY);
                    lblDescription.MaximumSize = new Size(@this.Width - lblDescription.Location.X - @this.LayoutValues.padding, 0);
                    lblDescription.Height      = @this.LayoutValues.moreInfoTextHeight + 2;
                    lblDescription.WordWrap    = true;
                    lblDescription.Visible     = true;
                    lblDescription.BringToFront();
                    //lblDescription.Text = descriptionText;
                }

                #region figure out the header size
                System.Collections.Generic.List <int> lowestPoints = new System.Collections.Generic.List <int>();
                lowestPoints.Add((int)headerTextSize.Height + (@this.LayoutValues.padding * 2));
                if (lblMoreInfo != null)
                {
                    lowestPoints.Add(lblMoreInfo.Location.Y + lblMoreInfo.Height + lblMoreInfo.Location.Y);
                }
                if (!String.IsNullOrEmpty(descriptionText))
                {
                    lowestPoints.Add(lblDescription.Location.Y + lblDescription.Height + @this.LayoutValues.padding);
                }
                if (lblWarning != null)
                {
                    if (!String.IsNullOrEmpty(@this.Warning))
                    {
                        lowestPoints.Add(lblWarning.Location.Y + lblWarning.Height + @this.LayoutValues.padding);
                    }
                }
                int lowestPoint = lowestPoints[0];
                for (int x = 1; x < lowestPoints.Count; x++)
                {
                    if (lowestPoints[x] > lowestPoint)
                    {
                        lowestPoint = lowestPoints[x];
                    }
                }

                @this.LayoutValues.headerBaseHeight = lowestPoint;
                fullCaptionHeight = lowestPoint;
                #endregion

                //fullCaptionHeight += @this.LayoutValues.padding;
                //@this.LayoutValues.headerBaseHeight = fullCaptionHeight - 1;

                @this.Location = new Point(4, @this.Location.Y);

                if (@this.Block != null)
                {
                    (@this.Block as Control).Location = new Point(1, fullCaptionHeight);
                    (@this.Block as Control).BringToFront();
                    @this.LayoutValues.blockControlHeight = (@this.Block as Control).Height + 2;
                }
                else
                {
                    @this.LayoutValues.blockControlHeight = 0;
                }

                // Calculate the size of the control.
                if (@this.Collapsed)
                {
                    @this.Height = fullCaptionHeight + @this.LayoutValues.footerHeight;
                }
                else
                {
                    int height = fullCaptionHeight + @this.LayoutValues.blockControlHeight + @this.LayoutValues.footerHeight;
                    if (@this.FieldPanel != null)
                    {
                        @this.LayoutValues.controlAreaHeight = @this.FieldPanel.Height + 1;
                        @this.FieldPanel.Location            = new Point(0, fullCaptionHeight + @this.LayoutValues.blockControlHeight + 2);
                    }
                    height      += @this.LayoutValues.controlAreaHeight + 1;
                    @this.Height = height;
                }

                @this.LayoutValues.fullCaptionHeight = fullCaptionHeight;
                // Redraw the control.
                //lblWarning.PerformLayout();
            }
            @this.Invalidate();
            return(true);
        }