예제 #1
0
        public int Add(Object hlControl)
        {
            HitbaseControlData newControl = new HitbaseControlData();

            newControl.ControlName = hlControl.GetType().Name;

            AddProperties(newControl.Properties, hlControl);

            return(Controls.Add(newControl));
        }
예제 #2
0
        public void AddProperties(List <Property> props, Object hlControl)
        {
            HitbaseControlData newControl = new HitbaseControlData();

            newControl.ControlName = hlControl.GetType().Name;

            // Jetzt per Reflection alle Hitbase-Properties auslesen

            PropertyInfo[] propInfo = hlControl.GetType().GetProperties();
            foreach (PropertyInfo prop in propInfo)
            {
                // Handelt es sich um ein Hitbase-Attribut?
                CategoryAttribute[] attribs = (CategoryAttribute[])prop.GetCustomAttributes(typeof(CategoryAttribute), true);

                if (attribs != null && attribs.Length > 0 && attribs[0].Category == "Hitbase")
                {
                    object objValue = prop.GetValue(hlControl, null);

                    if (objValue != null)
                    {
                        if (objValue is System.Drawing.Color)
                        {
                            if (!((System.Drawing.Color)objValue).IsEmpty)
                            {
                                System.Drawing.Color col = ((System.Drawing.Color)objValue);
                                String colValue;

                                if (col.IsNamedColor)
                                {
                                    colValue = col.Name;
                                }
                                else
                                {
                                    colValue = String.Format("#{0:x2}{1:x2}{2:x2}", col.R, col.G, col.B);
                                }

                                props.Add(new Property(prop.Name, colValue));
                            }
                        }
                        else
                        {
                            if (objValue is System.Drawing.Font)
                            {
                                props.Add(new Property(prop.Name, GetStringFromFont((System.Drawing.Font)objValue)));
                            }
                            else
                            {
                                props.Add(new Property(prop.Name, objValue));
                            }
                        }
                    }
                }
            }
        }
        public void SaveDialogToXMLRecursive(HitbaseControlData ctlData, FrameworkElement parent)
        {
            // Von hinten nach vorne laufen, weil sonst die Reihenfolge umgedreht wird.

            /*TODO_WPF!!!!!!!!!!!!!!!!!for (int i = parent.Controls.Count - 1; i >= 0; i--)
             * {
             *  if (parent.Controls[i] is IHitbaseControl)
             *  {
             *      int index = ctlData.Add(((IHitbaseControl)parent.Controls[i]).HitbaseControl);
             *
             *      SaveDialogToXMLRecursive((HitbaseControlData)ctlData.Controls[index], parent.Controls[i]);
             *  }
             * }*/
        }
        public bool ReadDialogFromDialogData(HitbaseControl parent, HitbaseControlData hitbaseControlData)
        {
            //int controlIndex = 0;
            foreach (HitbaseControlData ctl in hitbaseControlData.Controls)
            {
                Object newControl = null;

                if (ctl.ControlName != "MainWindowCDUserControl")
                {
                    switch (ctl.ControlName)
                    {
                    case "HitbaseTextBox": newControl = new HitbaseTextBox(this); break;

                    case "HitbaseLabel": newControl = new HitbaseLabel(this); break;

                    case "HitbaseButton": newControl = new HitbaseButton(this); break;

                    case "HitbaseComboBox": newControl = new HitbaseComboBox(this); break;

                    case "HitbaseCheckBox": newControl = new HitbaseCheckBox(this); break;

                    case "HitbaseRating": newControl = new HitbaseRating(this); break;

                    //TODO_WPF!!!!!!!!!!!!!!!!case "HitbaseTrackList": newControl = new HitbaseTrackList(this); break;
                    //TODO_WPF!!!!!!!!!!!!!!!!case "HitbaseParticipants": newControl = new HitbaseParticipants(this); break;
                    case "HitbaseSeperator": newControl = new HitbaseSeperator(this); break;

                    //TODO_WPF!!!!!!!!!!!!!!!!case "HitbaseCover": newControl = new HitbaseCover(this); break;
                    default:
                        //MessageBox.Show("unknown hitbase Control " + ctl.ControlName, System.Windows.Forms.Application.ProductName, MessageBoxButton.OK, MessageBoxImage.Error);
                        break;
                    }
                }
                else
                {
                    newControl = this;
                }

                if (newControl != null)
                {
                    foreach (HitbaseControlData.Property prop in ctl.Properties)
                    {
                        PropertyInfo property = newControl.GetType().GetProperty(prop.Name);
                        if (property != null)
                        {
                            if (property.PropertyType == typeof(System.Drawing.Color))
                            {
                                string colorString = prop.Value.ToString();
                                if (colorString.StartsWith("#"))
                                {
                                    int R, G, B;
                                    R = Convert.ToInt32(colorString.Substring(1, 2), 16);
                                    G = Convert.ToInt32(colorString.Substring(3, 2), 16);
                                    B = Convert.ToInt32(colorString.Substring(5, 2), 16);

                                    //TODO_WPF!!!!!!!!!!!!!!!!!property.SetValue(newControl, Color.FromArgb(R, G, B), null);
                                }
                                else
                                {
                                    //TODO_WPF!!!!!!!!!!!!!!!!!property.SetValue(newControl, Color.FromName(colorString), null);
                                }
                            }
                            else
                            {
                                if (property.PropertyType == typeof(System.Drawing.Font) && prop.Value != null)
                                {
                                    property.SetValue(newControl, GetFontFromString(prop.Value.ToString()), null);
                                }
                                else
                                {
                                    property.SetValue(newControl, prop.Value, null);
                                }
                            }
                        }
                    }

                    if (newControl is HitbaseControl)
                    {
                        AddHitbaseControl(parent, 0, (HitbaseControl)newControl);

                        ReadDialogFromDialogData((HitbaseControl)newControl, ctl);
                    }
                }
            }

            return(true);
        }