Example #1
0
                /// <summary>
                /// Initializes the components of the tab widget to the values specified by the strings.
                /// </summary>
                /// <param name="ID">The unique id (if any) of this object.</param>
                /// <param name="MaxTabWidth">The maximum (non-zero) width a page tab can be (can be null for unconstrained width)</param>
                /// <param name="Parent">The parent layout (used for adding and validating page/widget ids)</param>
                /// <param name="Children">The XML node list containing the child elements that compose the style of the button (see XML notation docs for further information).</param>
                /// <param name="X">The x positioning of the tab container rect relative to the parent as governed by the horizontal alignment as follows:
                /// <list type="table">
                /// <listheader>
                /// <term>Alignment</term>
                /// <term>X Position</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>x units from parent's left edge</term>
                /// </item>
                /// <item>
                /// <term>Left</term>
                /// <term>x units from parent's left edge</term>
                /// </item>
                /// <item>
                /// <term>Center</term>
                /// <term>x position is ignored</term>
                /// </item>
                /// <item>
                /// <term>Right</term>
                /// <term>x units from parent's right edge</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="Y">The y positioning of the tab container rect relative to the parent as governed by the vertical alignment as follows:
                /// <list type="table">
                /// <listheader>
                /// <term>Alignment</term>
                /// <term>Y Position</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>y units from parent's top edge</term>
                /// </item>
                /// <item>
                /// <term>Top</term>
                /// <term>y units from parent's top edge</term>
                /// </item>
                /// <item>
                /// <term>Center</term>
                /// <term>y position is ignored</term>
                /// </item>
                /// <item>
                /// <term>Bottom</term>
                /// <term>y units from parent's bottom edge</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="W">The width of the tab container rect.</param>
                /// <param name="H">The height of the tab container rect.</param>
                /// <param name="HAlign">The horizontal alignemnt of the tab container rect within the parent rect as specified by the following values:
                /// <list type="table">
                /// <listheader>
                /// <term>String Value</term>
                /// <term>Alignment.Type</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>null</term>
                /// </item>
                /// <item>
                /// <term>left</term>
                /// <term>Alignment.Type.Left</term>
                /// </item>
                /// <item>
                /// <term>center</term>
                /// <term>Alignment.Type.Center</term>
                /// </item>
                /// <item>
                /// <term>right</term>
                /// <term>Alignment.Type.Right</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="VAlign">The horizontal alignemnt of the tab container rect within the parent rect  as specified by the following values:
                /// <list type="table">
                /// <listheader>
                /// <term>String Value</term>
                /// <term>Alignment.Type</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>null</term>
                /// </item>
                /// <item>
                /// <term>top</term>
                /// <term>Alignment.Type.Top</term>
                /// </item>
                /// <item>
                /// <term>center</term>
                /// <term>Alignment.Type.Center</term>
                /// </item>
                /// <item>
                /// <term>bottom</term>
                /// <term>Alignment.Type.Bottom</term>
                /// </item>
                /// </list>
                /// </param>
                /// <remarks>This constructor is used primarily in conjunction with XML-based layouts</remarks>
                public Tab(StyleSheet Styling, string ID, string MaxTabWidth, Layout Parent, XmlNodeList Children, string X, string Y, string W, string H, string HAlign, string VAlign, string Visible) : base(ID, X, Y, W, H, HAlign, VAlign, Visible)
                {
                    maxTabWidth = new Unit(MaxTabWidth);

                    foreach (XmlNode element in Children)
                    {
                        string style = Xml.Att(element.Attributes["style"]);

                        // Tab header for defining tab sizes, backgrounds etc.
                        if (element.Name == "header")
                        {
                            headerHeight = new Unit(Styling.Apply(style, "height", element.Attributes));
                            maxTabWidth  = new Unit(Styling.Apply(style, "maxW", element.Attributes));

                            foreach (XmlNode hChild in element.ChildNodes)
                            {
                                style = Xml.Att(element.Attributes["style"]);

                                switch (hChild.Name)
                                {
                                case "background":

                                    headerBackground = new Image(null,
                                                                 Styling.Apply(style, "src", hChild.Attributes),
                                                                 Styling.Apply(style, "colour", hChild.Attributes),
                                                                 Styling.Apply(style, "scale", hChild.Attributes),
                                                                 "0",
                                                                 "0",
                                                                 "100%",
                                                                 "100%",
                                                                 null,
                                                                 null,
                                                                 null);

                                    break;

                                case "active":

                                    Image imgA = new Image(null,
                                                           Styling.Apply(style, "src", hChild.Attributes),
                                                           Styling.Apply(style, "colour", hChild.Attributes),
                                                           Styling.Apply(style, "scale", hChild.Attributes),
                                                           "0",
                                                           "0",
                                                           "100%",
                                                           "100%",
                                                           null,
                                                           null,
                                                           null);

                                    activeTab = new Button(null,
                                                           null,
                                                           null,
                                                           imgA,
                                                           "0",
                                                           "0",
                                                           "100%",
                                                           "100%",
                                                           null,
                                                           null,
                                                           Xml.Att(element.Attributes["enabled"]),
                                                           null);

                                    activeTab.guiDispatcher.AttachHandler("onClick", this, "tab_Click");

                                    break;

                                case "inactive":

                                    Image imgI = new Image(null,
                                                           Styling.Apply(style, "src", hChild.Attributes),
                                                           Styling.Apply(style, "colour", hChild.Attributes),
                                                           Styling.Apply(style, "scale", hChild.Attributes),
                                                           "0",
                                                           "0",
                                                           "100%",
                                                           "100%",
                                                           null,
                                                           null,
                                                           null);

                                    inactiveTab = new Button(null,
                                                             null,
                                                             null,
                                                             imgI,
                                                             "0",
                                                             "0",
                                                             "100%",
                                                             "100%",
                                                             null,
                                                             null,
                                                             Xml.Att(element.Attributes["enabled"]),
                                                             null);

                                    inactiveTab.guiDispatcher.AttachHandler("onClick", this, "tab_Click");

                                    break;

                                case "text":

                                    tabText = new Text(null,
                                                       "middleCenter",
                                                       null,
                                                       Styling.Apply(style, "colour", element.Attributes),
                                                       Styling.Apply(style, "fontFace", hChild.Attributes),
                                                       Styling.Apply(style, "fontSize", hChild.Attributes));

                                    break;

                                default: throw new Exception(string.Format("Encountered unknown tab child: {0}", element.Name));
                                }
                            }
                        }
                        else if (element.Name == "body")
                        {
                            bodyHeight = new Unit(Styling.Apply(style, "height", element.Attributes));

                            pages = new PageContainer(Xml.Att(element.Attributes["id"]), Xml.Att(element.Attributes["title"]));

                            pages.AddChildren(element.ChildNodes, Parent);

                            pages.ActivatePage(Xml.Att(element.FirstChild.Attributes["id"]));
                        }
                        else
                        {
                            throw new Exception("Unexpected child node in tab widget: " + element.Name);
                        }
                    }

                    if ((headerHeight == null || headerHeight.value == null) && (bodyHeight == null || bodyHeight.value == null))
                    {
                        throw new Exception("Tab must have either header or body element height specified");
                    }
                    if (activeTab == null)
                    {
                        throw new Exception("Tab must have active tab specified");
                    }
                    if (inactiveTab == null)
                    {
                        throw new Exception("Tab must have inactive tab specified");
                    }
                }