public MainMenu(MenuItem[] items) : base(items)
 {
     this.rightToLeft = System.Windows.Forms.RightToLeft.Inherit;
 }
Exemple #2
0
        void parseXML(string filePath)
        {
            XDocument xDoc = XDocument.Load(filePath);

            List <XElement> element = xDoc.Elements("locale").ToList();

            if (element != null)
            {
                lManager.Enter(Sender.MANAGER, Level.DEBUG, "<locale/> found for locale:{0}", key);

                Locale locale = new Locale();

                if (!element[0].HasAttributes)
                {
                    lManager.Enter(Sender.MANAGER, Level.ERROR, "<locale/> element does not have expected attributes!");
                    return;
                }

                locale.Name = element[0].FirstAttribute.Value;

                List <XElement> childNodes = element[0].Elements().ToList();
                locale.DisplayName = childNodes[0].Value;
                locale.Encoding    = Convert.ToInt32(childNodes[1].Value);

                FontConfig globalFont = new FontConfig();
                System.Windows.Forms.RightToLeft rightToLeft = System.Windows.Forms.RightToLeft.No;

                if (childNodes.Count == 4) // Global font is likely defined
                {
                    if (childNodes[2].Name == "font")
                    {
                        List <XElement> fontElements = childNodes[2].Elements().ToList();

                        globalFont.Style = (System.Drawing.FontStyle)Enum.Parse(typeof(System.Drawing.FontStyle), fontElements[0].Value);
                        globalFont.Size  = Convert.ToDouble(fontElements[1].Value, CultureInfo.InvariantCulture);

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "Global <font/> is defined.\nFamily:{0}\nStyle:{1}\nSize:{2}", globalFont.Name,
                                       globalFont.Style.ToString(),
                                       globalFont.Size);
                    }
                }
                else if (childNodes.Count == 5) // Global right to left is likely defined
                {
                    if (childNodes[3].Name == "rightToLeft")
                    {
                        rightToLeft = (System.Windows.Forms.RightToLeft)Enum.Parse(typeof(System.Windows.Forms.RightToLeft), childNodes[3].Value);

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "Global <rightToLeft/> defined.");
                    }
                }

                // Get the <control/> nodes in the <controls/> elemenent
                childNodes = childNodes[childNodes.Count - 1].Elements().ToList();

                lManager.Enter(Sender.MANAGER, Level.DEBUG, "{0} <control/> nodes found.", childNodes.Count);

                List <ControlConfig> controls = new List <ControlConfig>();
                for (int c = 0; c < childNodes.Count; c++)
                {
                    ControlConfig control = new ControlConfig();

                    if (childNodes[c].HasAttributes)
                    {
                        List <XAttribute> attributes = childNodes[c].Attributes().ToList();
                        if (attributes.Count >= 1)
                        {
                            control.Name = attributes[0].Value;
                        }

                        if (attributes.Count >= 2)
                        {
                            control.Comment = attributes[1].Value;
                        }

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "<control/> {0} has expected attributes.", control.Name);
                    }
                    else
                    {
                        string msg = string.Format("<control/> at index: {0} does not have attributes! Ignoring!", c);
                        lManager.Enter(Sender.MANAGER, Level.WARNING, msg);
                        System.Windows.Forms.MessageBox.Show(msg, "XML Exception", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                    }

                    FontConfig controlFont = null;

                    List <XElement> fontElements = childNodes[c].Elements("font").ToList();
                    if (fontElements.Count > 0)
                    {
                        controlFont      = new FontConfig();
                        controlFont.Name = fontElements[0].FirstAttribute.Value;

                        fontElements      = fontElements[0].Elements().ToList();
                        controlFont.Style = (System.Drawing.FontStyle)Enum.Parse(typeof(System.Drawing.FontStyle), fontElements[0].Value);
                        controlFont.Size  = Convert.ToDouble(fontElements[1].Value, CultureInfo.InvariantCulture);

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "<font/> detected.\nFamily:{0}\nStyle:{2}\nSize:{1}", controlFont.Name,
                                       controlFont.Style.ToString(),
                                       controlFont.Size);
                    }
                    else
                    {
                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "No <font/> detected for control: {0}", control.Name);
                    }

                    control.Font = (controlFont != null) ? controlFont : globalFont;

                    List <XElement> locationElements = childNodes[c].Elements("location").ToList();
                    if (locationElements.Count == 1)
                    {
                        string[] location = childNodes[c].Elements("location").ToList()[0].Value.Split(',');
                        control.Location = new System.Drawing.Point(int.Parse(location[0]), int.Parse(location[1]));

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "<location/> detected.\nx:{0}\ny:{1}", control.Location.X,
                                       control.Location.Y);
                    }
                    else
                    {
                        control.Location = new System.Drawing.Point(0, 0);
                    }

                    List <XElement> sizeElements = childNodes[c].Elements("size").ToList();
                    if (sizeElements.Count == 1)
                    {
                        string[] size = childNodes[c].Elements("size").ToList()[0].Value.Split(',');
                        control.Size = new System.Drawing.Size(int.Parse(size[0]), int.Parse(size[1]));

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "<size/> detected. \nheight:{0}\nwidth:{1}", control.Size.Height,
                                       control.Size.Width);
                    }
                    else
                    {
                        control.Size = new System.Drawing.Size(0, 0);
                    }

                    TextConfig text = new TextConfig();
                    text.Alignment = System.Drawing.ContentAlignment.MiddleLeft;

                    List <XElement> textElements = childNodes[c].Elements("text").ToList();

                    if (textElements.Count > 0)
                    {
                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "<text/> element detected!");

                        if (textElements[0].HasAttributes)
                        {
                            List <XAttribute> attributes = textElements[0].Attributes().ToList();

                            XAttribute attribute = attributes.Find(a => a.Name == "align");
                            if (attribute != null)
                            {
                                text.Alignment = (System.Drawing.ContentAlignment)Enum.Parse(typeof(System.Drawing.ContentAlignment), attribute.Value);
                            }

                            attribute = attributes.Find(a => a.Name == "rightToLeft");
                            if (attribute != null)
                            {
                                text.RightToLeft = (System.Windows.Forms.RightToLeft)Enum.Parse(typeof(System.Windows.Forms.RightToLeft), attribute.Value);
                            }
                        }

                        text.Text = textElements[0].Value;
                    }
                    else
                    {
                        text.Text = string.Empty;
                    }

                    control.Text = text;

                    if (control.Populated)
                    {
                        controls.Add(control);
                    }
                }

                locale.Controls = controls;

                if (locale.Populated)
                {
                    locales.Add(locale);
                }

                lManager.Enter(Sender.MANAGER, Level.DEBUG, string.Format("{0} controls configurations loaded from locale: {1} from\n\t- {2}", locale.Controls.Count, locale.Name, filePath));
            }
        }
 public MainMenu() : base(null)
 {
     this.rightToLeft = System.Windows.Forms.RightToLeft.Inherit;
 }
 public ContextMenu(MenuItem[] menuItems) : base(menuItems)
 {
     this.rightToLeft = System.Windows.Forms.RightToLeft.Inherit;
 }
Exemple #5
0
 public ContextMenu(MenuItem[] menuItems) : base(menuItems)
 {
     this.rightToLeft = System.Windows.Forms.RightToLeft.Inherit;
 }
Exemple #6
0
 public ContextMenu() : base(null)
 {
     this.rightToLeft = System.Windows.Forms.RightToLeft.Inherit;
 }
Exemple #7
0
 public MainMenu(MenuItem[] items) : base(items)
 {
     this.rightToLeft = System.Windows.Forms.RightToLeft.Inherit;
 }