public HitbaseControl AddControlFromStream(int parentControlID, int controlIndex, byte[] objectStream, bool keepControlID)
        {
            BinaryFormatter bf  = new BinaryFormatter();
            MemoryStream    mem = new MemoryStream(objectStream);

            HitbaseControl parentCtl = FindHitbaseControlFromID(parentControlID);
            HitbaseControl ctl       = (HitbaseControl)bf.Deserialize(mem);

            PropertyInfo[] propInfo = ctl.GetType().GetProperties();

            HitbaseControl newControl = Activator.CreateInstance(ctl.GetType(), this) as HitbaseControl;

            foreach (PropertyInfo pi in propInfo)
            {
                if (pi.CanWrite)
                {
                    pi.SetValue(newControl, pi.GetValue(ctl, null), null);
                }
            }

            if (keepControlID)
            {
                PropertyInfo piControlID = ctl.GetType().GetProperty("ControlID");
                newControl.SetControlID((int)piControlID.GetValue(ctl, null));
            }

            AddHitbaseControl(parentCtl, controlIndex, newControl);

            mem.Close();

            return(newControl);
        }
Пример #2
0
        /// <summary>
        /// Fügt einen neuen Eintrag in die Undo-Liste ein, wenn ein neues Control angelegt wird.
        /// </summary>
        /// <param name="ctl"></param>
        public void AddNew(HitbaseControl ctl)
        {
            if (!initialized)
            {
                return;
            }

            if (currentUndoStep == null)
            {
                throw new Exception("BeginUndoStep must be called first.");
            }

            UndoEntry entry = new UndoEntry();

            entry.undoAction = UndoAction.New;
            entry.controlID  = ctl.ControlID;
            if (ctl.Parent == null)
            {
                entry.parentControlID = 0;      // Hat keinen Parent
            }
            else
            {
                entry.parentControlID = ctl.Parent.ControlID;
            }
            currentUndoStep.undoEntry.Push(entry);
        }
        /// <summary>
        /// Fügt das angegebene neue Hitbase-Control hinzu.
        /// </summary>
        /// <param name="parent">Das Parent, oder null, wenn das neue Control im Hauptframe hinzugefügt werden soll.</param>
        /// <param name="newControl">Das hinzuzufügende Control.</param>
        public void AddHitbaseControl(HitbaseControl parent, int controlIndex, HitbaseControl newControl)
        {
            if (parent == null)
            {
                this.Canvas.Children.Add(newControl.GetControl());
                if (controlIndex >= 0)
                {
                    newControl.SetChildIndexToControl(this, controlIndex);
                }
            }
            else
            {
                parent.Add(newControl);
                if (controlIndex >= 0)
                {
                    parent.SetChildIndex(newControl, controlIndex);
                }
            }

            newControl.ControlCreated();

            /*TODO_WPF!!!!!!!!!!!!!!!undoEngine.BeginUndoStep(StringTable.New);
             * undoEngine.AddNew(newControl);
             * undoEngine.EndUndoStep();*/
        }
        private void DeleteAllChildHitbaseControls(HitbaseControl parent)
        {
            List <Control> delControls = new List <Control>();

            foreach (Control ctl in parent.Controls)
            {
                if (ctl is IHitbaseControl)
                {
                    delControls.Add(ctl);
                    DeleteAllChildHitbaseControls(((IHitbaseControl)ctl).HitbaseControl);
                }
            }

            // Jetzt die Controls löschen
            foreach (Control ctl in delControls)
            {
                if (!(parent is IHitbaseControl))
                {
                    DeleteHitbaseControl(null, ((IHitbaseControl)ctl).HitbaseControl);
                }
                else
                {
                    DeleteHitbaseControl(((IHitbaseControl)parent).HitbaseControl, ((IHitbaseControl)ctl).HitbaseControl);
                }
            }
        }
        /// <summary>
        /// Liefert alle Child-Controls dess angegebenen Controls zurück, die vom angegebenen Type sind.
        /// </summary>
        /// <param name="hitbaseControlType"></param>
        /// <returns></returns>
        public List <HitbaseControl> GetAllControlsOfType(HitbaseControl parent, Type hitbaseControlType)
        {
            List <HitbaseControl> controls = new List <HitbaseControl>();

            GetAllControlsOfTypeRecursive(controls, parent, hitbaseControlType);

            return(controls);
        }
        /// <summary>
        /// Lösche das angegebene Control mit allen Child Controls.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="ctl"></param>
        public void DeleteHitbaseControlWithChilds(HitbaseControl parent, HitbaseControl ctl)
        {
            //TODO_WPF!!!!!!!!!!!!!!undoEngine.BeginUndoStep(StringTable.Delete);

            DeleteAllChildHitbaseControls(ctl);

            DeleteHitbaseControl(parent, ctl);

            //TODO_WPF!!!!!!!!!!!!!!!undoEngine.EndUndoStep();
        }
        public void ChangeProperty(HitbaseControl ctl, string property, object value)
        {
            //TODO_WPF!!!!!!!!!!!!!undoEngine.BeginUndoStep(StringTable.PropertyChanged);
            PropertyInfo propInfo = ctl.GetType().GetProperty(property);

            //TODO_WPF!!!!!!!!!!!!!undoEngine.AddPropertyChange(ctl.ControlID, property, propInfo.GetValue(ctl, null));

            propInfo.SetValue(ctl, value, null);

            //TODO_WPF!!!!!!!!!!!!!undoEngine.EndUndoStep();
        }
 public void GetAllControlsOfTypeRecursive(List <HitbaseControl> controls, HitbaseControl parent, Type hitbaseControlType)
 {
     foreach (HitbaseControl ctl in parent.Children)
     {
         if (ctl == null)
         {
             continue;
         }
         if (ctl.GetType() == hitbaseControlType || ctl.GetType().IsSubclassOf(hitbaseControlType))
         {
             controls.Add(ctl);
         }
         GetAllControlsOfTypeRecursive(controls, ctl, hitbaseControlType);
     }
 }
Пример #9
0
        /// <summary>
        /// Führt einen einzelnen Undo-Step aus.
        /// </summary>
        /// <param name="step"></param>
        private void DoUndoStep(UndoStep step)
        {
            while (step.undoEntry.Count > 0)
            {
                UndoEntry entry = step.undoEntry.Pop();

                switch (entry.undoAction)
                {
                case UndoAction.ChangeProperty:
                {
                    // Property-Änderung rückgängig machen.
                    HitbaseControl hlControl = mainWindowControl.FindHitbaseControlFromID(entry.controlID);

                    mainWindowControl.ChangeProperty(hlControl, entry.property, entry.value);

                    break;
                }

                case UndoAction.Delete:
                {
                    // Löschen eines Objektes rückgängig machen.
                    HitbaseControl newControl = mainWindowControl.AddControlFromStream(entry.parentControlID, entry.controlIndex, entry.serializedObject, true);
                    newControl.SetTabIndex(entry.tabIndex);
                    break;
                }

                case UndoAction.New:
                {
                    HitbaseControl ctl = mainWindowControl.FindHitbaseControlFromID(entry.controlID);
                    HitbaseControl parent;

                    if (entry.parentControlID != 0)
                    {
                        parent = mainWindowControl.FindHitbaseControlFromID(entry.controlID);
                    }
                    else
                    {
                        parent = null;
                    }

                    mainWindowControl.DeleteHitbaseControlWithChilds(parent, ctl);
                    break;
                }
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Lösche das angegebene Control mit allen Child Controls.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="ctl"></param>
        private void DeleteHitbaseControl(HitbaseControl parent, HitbaseControl ctl)
        {
            /*TODO_WPF!!!!!!!!!!!!!!!!!!!!!!!!!!if (thePropertyGrid != null && thePropertyGrid.SelectedObject == ctl)
             * {
             *  thePropertyGrid.SelectedObject = null;
             * }
             *
             * undoEngine.BeginUndoStep(StringTable.Delete);
             * undoEngine.AddDelete(ctl);*/

            if (parent == null)
            {
                ctl.RemoveFromControl(this);
            }
            else
            {
                parent.RemoveChild(ctl);
            }

            //TODO_WPF!!!!!!!!!!!!!!!!!!undoEngine.EndUndoStep();
        }
Пример #11
0
        /// <summary>
        /// Fügt einen neuen Eintrag in die Undo-Liste ein, wenn ein Control gelöscht wird.
        /// </summary>
        /// <param name="ctl"></param>
        public void AddDelete(HitbaseControl ctl)
        {
            if (!initialized)
            {
                return;
            }

            if (currentUndoStep == null)
            {
                throw new Exception("BeginUndoStep must be called first.");
            }

            UndoEntry entry = new UndoEntry();

            entry.undoAction = UndoAction.Delete;
            entry.controlID  = ctl.ControlID;

            BinaryFormatter bf  = new BinaryFormatter();
            MemoryStream    mem = new MemoryStream();

            bf.Serialize(mem, ctl);
            entry.serializedObject = mem.ToArray();
            mem.Close();

            if (ctl.Parent == null)
            {
                entry.parentControlID = 0;
            }
            else
            {
                entry.parentControlID = ctl.Parent.ControlID;
                entry.controlIndex    = ctl.Parent.GetChildIndex(ctl);
                entry.tabIndex        = ctl.GetTabIndex();
            }

            currentUndoStep.undoEntry.Push(entry);
        }
Пример #12
0
 public MyButton(HitbaseControl ctl)
 {
     hitbaseControl = ctl;
 }
Пример #13
0
 public MyComboBox(HitbaseControl ctl)
 {
     hitbaseControl = ctl;
 }
Пример #14
0
 /// <summary>
 /// Liefert alle Child-Controls des angegebenen Controls zurück.
 /// </summary>
 /// <returns></returns>
 public List <HitbaseControl> GetAllControls(HitbaseControl parent)
 {
     return(GetAllControlsOfType(parent, typeof(HitbaseControl)));
 }
Пример #15
0
        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);
        }
Пример #16
0
 public MyCheckBox(HitbaseControl ctl)
 {
     hitbaseControl = ctl;
 }