예제 #1
0
    //...
    void Parent_AddChildControl()
    {
        ChildControl child = new ChildControl();

        child.MouseEnter += child_MouseEnter;
        UiElementX.Children.Add(child);
    }
예제 #2
0
    // Use this for initialization
    void Start()
    {
        // Set Timers
        mainTimer = levelTime;
        lastTimer = levelTime;
        legTimer  = legTime;

        children = new List <ChildControl>();


        // Create Child Data - Child ref, Start Position, End Position, and a recording of input.
        for (int i = 0; i < startPoints.Length; i++)
        {
            ChildControl c = GameObject.Instantiate(childPref).GetComponent <ChildControl>();
            c.transform.position = startPoints[i].transform.position;
            bool ghost;
            if (i == 0)
            {
                ghost = false;
            }
            else
            {
                ghost = true;
            }

            c.Init(ghost, startPoints[i].transform.position, desks[i].GetComponent <DeskControl>());
            children.Add(c);
        }
    }
예제 #3
0
        public void Adding_Child_Should_Call_PropertyChanged_If_Parent_Value_Changed()
        {
            bool   called   = false;
            string oldValue = null;
            string newValue = null;

            ParentControl parent = new ParentControl();

            parent.Test = "bar";

            ChildControl child = new ChildControl();

            propertyChangedCallback = (s, o, n) =>
            {
                called   = s == child;
                oldValue = o;
                newValue = n;
            };

            parent.Children.Add(child);

            Assert.IsTrue(called);
            Assert.AreEqual(oldValue, "foo");
            Assert.AreEqual(newValue, "bar");
        }
        public void Test_ControlWithDataIsValid()
        {
            Control ctrl = new Control();

            ctrl.family    = "AC";
            ctrl.number    = "AC-1";
            ctrl.title     = "ACCESS CONTROL";
            ctrl.priority  = "P1";
            ctrl.lowimpact = true;
            ctrl.id        = Guid.NewGuid();
            ChildControl cc = new ChildControl();

            cc.number      = "AC-1.2.3.4.5(6)";
            cc.description = "My description is here";
            ctrl.childControls.Add(cc);

            // test things out
            Assert.True(ctrl != null);
            Assert.True(!string.IsNullOrEmpty(ctrl.family));
            Assert.True(!string.IsNullOrEmpty(ctrl.number));
            Assert.True(!string.IsNullOrEmpty(ctrl.title));
            Assert.True(!string.IsNullOrEmpty(ctrl.priority));
            Assert.True(ctrl.lowimpact);
            Assert.False(ctrl.moderateimpact);
            Assert.False(ctrl.highimpact);
            Assert.True(ctrl.childControls.Count == 1);
            Assert.True(ctrl.childControls[0].id != Guid.Empty);
        }
예제 #5
0
        public override void LoadSettingsFromStorage()
        {
            // Read setting but set to null if it doesn't exist
            Func <string, string, T?> readProp <T>(Func <string, string, T> readFn) where T : struct
            {
                return((string collection, string prop) =>
                {
                    try
                    {
                        return readFn("Rewrap\\" + collection, prop);
                    }
                    catch
                    {
                        return null;
                    }
                });
            }

            var readInt  = readProp(Store.GetInt32);
            var readBool = readProp(Store.GetBoolean);

            Store.CreateCollection("Rewrap\\*");
            GlobalOptions = new GlobalOptionsGroup()
            {
                WrappingColumn        = readInt("*", "wrappingColumn"),
                WholeComment          = Store.GetBoolean("Rewrap\\*", "wholeComment", true),
                DoubleSentenceSpacing = Store.GetBoolean("Rewrap\\*", "doubleSentenceSpacing", false),
                Reformat = Store.GetBoolean("Rewrap\\*", "reformat", false),
            };

            (int?, OptionsGroup) readGroup(string name)
            {
                return(
                    readInt(name, "index"),
                    new OptionsGroup(name.Split(',').Select(s => s.Trim()))
                {
                    WrappingColumn = readInt(name, "wrappingColumn"),
                    WholeComment = readBool(name, "wholeComment"),
                    DoubleSentenceSpacing = readBool(name, "doubleSentenceSpacing"),
                    Reformat = readBool(name, "reformat"),
                }
                    );
            }

            OptionsGroups =
                Store.GetSubCollectionNames("Rewrap")
                .Where(name => name != "*")
                .Select(readGroup)
                .OrderBy(indexAndGroup => indexAndGroup.Item1)
                .Select(indexAndGroup => indexAndGroup.Item2)
                .ToList();


            if (ChildControl != null)
            {
                ChildControl.SetOptions(GlobalOptions, OptionsGroups);
            }
        }
        public void Measure_Should_Call_Child_Measure()
        {
            ContentControl target = new ContentControl();
            ChildControl   child  = new ChildControl();

            child.RecordInputs = true;
            target.Content     = child;
            target.Measure(new Size(12, 23));

            Assert.AreEqual(new Size(12, 23), child.MeasureInput);
        }
        public void Measure_Should_Call_Child_Measure()
        {
            ContentControl target = new ContentControl();
            ChildControl child = new ChildControl();

            child.RecordInputs = true;
            target.Content = child;           
            target.Measure(new Size(12, 23));

            Assert.AreEqual(new Size(12, 23), child.MeasureInput);
        }
        public void Visual_Bounds_Should_Be_Correct_For_Stretch_Alignment()
        {
            ContentControl target = new ContentControl();
            ChildControl   child  = new ChildControl();

            child.MeasureOutput = new Size(12, 23);
            target.Content      = child;
            target.Arrange(new Rect(new Point(34, 45), new Size(56, 67)));

            Assert.AreEqual(new Vector(), child.VisualOffset);
            Assert.AreEqual(new Size(56, 67), child.RenderSize);
        }
        public void Full_Size_Should_Be_Passed_To_Child_ArrangeOverride_For_Stretch_Alignment()
        {
            ContentControl target = new ContentControl();
            ChildControl   child  = new ChildControl();

            child.RecordInputs  = true;
            child.MeasureOutput = new Size(12, 23);
            target.Content      = child;
            target.Arrange(new Rect(new Point(34, 45), new Size(56, 67)));

            Assert.AreEqual(new Size(56, 67), child.ArrangeInput);
        }
        public void Full_Size_Should_Be_Passed_To_Child_ArrangeOverride_For_Stretch_Alignment()
        {
            ContentControl target = new ContentControl();
            ChildControl child = new ChildControl();

            child.RecordInputs = true;
            child.MeasureOutput = new Size(12, 23);
            target.Content = child;
            target.Arrange(new Rect(new Point(34, 45), new Size(56, 67)));

            Assert.AreEqual(new Size(56, 67), child.ArrangeInput);
        }
예제 #11
0
        public void Test_ChildControlWithDataIsValid()
        {
            ChildControl ctrl = new ChildControl();

            ctrl.description = "AU-9";
            ctrl.number      = "AU-9";

            // test things out
            Assert.True(ctrl != null);
            Assert.True(!string.IsNullOrEmpty(ctrl.description));
            Assert.True(!string.IsNullOrEmpty(ctrl.number));
            Assert.True(ctrl.id != Guid.Empty);
        }
        public void Measure_Width_Should_Be_Passed_To_Child_ArrangeOverride_For_Right_Alignment()
        {
            ContentControl target = new ContentControl();
            ChildControl child = new ChildControl();

            child.RecordInputs = true;
            child.HorizontalAlignment = HorizontalAlignment.Right;
            child.MeasureOutput = new Size(12, 23);
            target.Content = child;
            target.Arrange(new Rect(new Point(34, 45), new Size(56, 67)));

            Assert.AreEqual(new Size(12, 67), child.ArrangeInput);
        }
        public void Measure_Height_Should_Be_Passed_To_Child_ArrangeOverride_For_Bottom_Alignment()
        {
            ContentControl target = new ContentControl();
            ChildControl   child  = new ChildControl();

            child.RecordInputs      = true;
            child.VerticalAlignment = VerticalAlignment.Bottom;
            child.MeasureOutput     = new Size(12, 23);
            target.Content          = child;
            target.Arrange(new Rect(new Point(34, 45), new Size(56, 67)));

            Assert.AreEqual(new Size(56, 23), child.ArrangeInput);
        }
        public void Measure_Width_Should_Be_Passed_To_Child_ArrangeOverride_For_Right_Alignment()
        {
            ContentControl target = new ContentControl();
            ChildControl   child  = new ChildControl();

            child.RecordInputs        = true;
            child.HorizontalAlignment = HorizontalAlignment.Right;
            child.MeasureOutput       = new Size(12, 23);
            target.Content            = child;
            target.Arrange(new Rect(new Point(34, 45), new Size(56, 67)));

            Assert.AreEqual(new Size(12, 67), child.ArrangeInput);
        }
예제 #15
0
        public override void SaveSettingsToStorage()
        {
            if (ChildControl != null)
            {
                (GlobalOptions, OptionsGroups) = ChildControl.GetOptions();
            }

            // Create methods that write the settings only if they're not null
            Action <string, string, T?> writeProp <T>(Action <string, string, T> writeFn) where T : struct
            {
                return((string collection, string prop, T? value) =>
                {
                    if (value.HasValue)
                    {
                        writeFn(collection, prop, value.Value);
                    }
                });
            }

            var writeInt  = writeProp <int>(Store.SetInt32);
            var writeBool = writeProp <bool>(Store.SetBoolean);

            Store.DeleteCollection("Rewrap");

            // Save global options
            var globalCollection = "Rewrap\\*";

            Store.CreateCollection(globalCollection);
            writeInt(globalCollection, "wrappingColumn", GlobalOptions.WrappingColumn);
            Store.SetBoolean(globalCollection, "wholeComment", GlobalOptions.WholeComment);
            Store.SetBoolean(globalCollection, "doubleSentenceSpacing", GlobalOptions.DoubleSentenceSpacing);
            Store.SetBoolean(globalCollection, "reformat", GlobalOptions.Reformat);

            // Save language-specific options
            for (var i = 0; i < OptionsGroups.Count; i++)
            {
                var group      = OptionsGroups[i];
                var collection = "Rewrap\\" + String.Join(",", group.Languages);
                Store.CreateCollection(collection);
                Store.SetInt32(collection, "index", i);
                writeInt(collection, "wrappingColumn", group.WrappingColumn);
                writeBool(collection, "wholeComment", group.WholeComment);
                writeBool(collection, "doubleSentenceSpacing", group.DoubleSentenceSpacing);
                writeBool(collection, "reformat", group.Reformat);
            }
        }
예제 #16
0
        public void Child_Should_Be_Measured_With_Width_And_Height_If_SizeToContent_Is_Manual()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var child  = new ChildControl();
                var target = new Window
                {
                    Width         = 100,
                    Height        = 50,
                    SizeToContent = SizeToContent.Manual,
                    Content       = child
                };

                target.Show();

                Assert.Equal(new Size(100, 50), child.MeasureSize);
            }
        }
예제 #17
0
        public void Child_Should_Be_Measured_With_Infinity_If_SizeToContent_Is_WidthAndHeight()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var child  = new ChildControl();
                var target = new Window
                {
                    Width         = 100,
                    Height        = 50,
                    SizeToContent = SizeToContent.WidthAndHeight,
                    Content       = child
                };

                target.Show();

                Assert.Equal(Size.Infinity, child.MeasureSize);
            }
        }
예제 #18
0
        public void Child_Should_Be_Measured_With_ClientSize_If_SizeToContent_Is_Manual_And_No_Width_Height_Specified()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var windowImpl = MockWindowingPlatform.CreateWindowMock();
                windowImpl.Setup(x => x.ClientSize).Returns(new Size(550, 450));

                var child  = new ChildControl();
                var target = new Window(windowImpl.Object)
                {
                    SizeToContent = SizeToContent.Manual,
                    Content       = child
                };

                target.Show();

                Assert.Equal(new Size(550, 450), child.MeasureSize);
            }
        }
예제 #19
0
        /// <summary>
        /// 鼠标弹起事件
        /// 主要用于点击进度条改变值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EasyTrackBar_MouseUp(object sender, MouseEventArgs e)
        {
            //Console.WriteLine("点中:" + _clickChildControl);
            var ctrl = sender as Control;

            if (ctrl != null && MouseButtons.Left == e.Button)
            {
                if (_clickChildControl == ChildControl.Progress)
                {
                    Point point = new Point(e.X, e.Y);
                    updateBarLocation(point);
                }
                else
                {
                    _clickChildControl = ChildControl.None;
                    Invalidate();
                }
            }
        }
예제 #20
0
            public void MaxWidth_And_MaxHeight_Should_Be_Respected_With_SizeToContent_WidthAndHeight()
            {
                using (UnitTestApplication.Start(TestServices.StyledWindow))
                {
                    var child = new ChildControl();

                    var target = new Window()
                    {
                        SizeToContent = SizeToContent.WidthAndHeight,
                        MaxWidth      = 300,
                        MaxHeight     = 700,
                        Content       = child,
                    };

                    Show(target);

                    Assert.Equal(new[] { new Size(300, 700) }, child.MeasureSizes);
                }
            }
예제 #21
0
 Form RecursivelyGetFormControl(Control ParentControl)
 {
     try
     {
         foreach (Control ChildControl in ParentControl.Controls)
         {
             if (ChildControl.GetType() == typeof(Form))
             {
                 return(ChildControl as Form);
             }
             Control MinedControl = RecursivelyGetFormControl(ChildControl);
             if (MinedControl != null)
             {
                 return(MinedControl as Form);
             }
         }
     }
     catch { }
     return(null);
 }
        public void Adding_Child_Should_Not_Call_PropertyChanged_If_Parent_Value_Unchanged()
        {
            bool called = false;
            string oldValue = null;
            string newValue = null;

            ParentControl parent = new ParentControl();

            ChildControl child = new ChildControl();

            propertyChangedCallback = (s, o, n) =>
            {
                called = s == child;
                oldValue = o;
                newValue = n;
            };

            parent.Children.Add(child);

            Assert.IsFalse(called);
        }
예제 #23
0
        /// <summary>
        /// 鼠标按下事件
        /// 用于判断点中的子控件和计算鼠标偏移值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EasyTrackBar_MouseDown(object sender, MouseEventArgs e)
        {
            var ctrl = sender as Control;

            if (ctrl != null)
            {
                _offsetPoint = new Point(e.X - _nowPoint.X, e.Y - _nowPoint.Y);

                //判断点中了哪个控件
                foreach (KeyValuePair <ChildControl, RectangleF> c in _childControls)
                {
                    RectangleF r = c.Value;
                    if ((r.X <= e.X && e.X <= r.X + r.Width) && (r.Y <= e.Y && e.Y <= r.Y + r.Height))
                    {
                        _clickChildControl = c.Key;
                        break;
                    }
                }
                Invalidate();
            }
        }
예제 #24
0
        public void Adding_Child_Should_Not_Call_PropertyChanged_If_Parent_Value_Unchanged()
        {
            bool   called   = false;
            string oldValue = null;
            string newValue = null;

            ParentControl parent = new ParentControl();

            ChildControl child = new ChildControl();

            propertyChangedCallback = (s, o, n) =>
            {
                called   = s == child;
                oldValue = o;
                newValue = n;
            };

            parent.Children.Add(child);

            Assert.IsFalse(called);
        }
예제 #25
0
            public void Child_Should_Be_Measured_With_MaxAutoSizeHint_If_SizeToContent_Is_WidthAndHeight()
            {
                using (UnitTestApplication.Start(TestServices.StyledWindow))
                {
                    var windowImpl = MockWindowingPlatform.CreateWindowMock();
                    windowImpl.Setup(x => x.MaxAutoSizeHint).Returns(new Size(1200, 1000));

                    var child  = new ChildControl();
                    var target = new Window(windowImpl.Object)
                    {
                        Width         = 100,
                        Height        = 50,
                        SizeToContent = SizeToContent.WidthAndHeight,
                        Content       = child
                    };

                    target.Show();

                    Assert.Equal(1, child.MeasureSizes.Count);
                    Assert.Equal(new Size(1200, 1000), child.MeasureSizes[0]);
                }
            }
        public void Test_ControlWithDataIsValid()
        {
            ChildControl cc = new ChildControl();

            cc.description = "My Child Description";
            cc.number      = "AC-1.1";

            Control cs = new Control();

            cs.family   = "AC";
            cs.number   = "AC-1";
            cs.title    = "My Title";
            cs.priority = "P1";
            cs.childControls.Add(cc);
            cs.supplementalGuidance = "My supplemental guidance.";
            Assert.True(cs != null);
            Assert.True(cs.id != null);
            Assert.True(cs.childControls.Count == 1);
            Assert.True(cs.childControls[0].id != null);
            Assert.False(cs.lowimpact);
            Assert.False(cs.moderateimpact);
            Assert.False(cs.highimpact);
        }
        public void Setting_Parent_Value_Should_Call_PropertyChanged_If_Child_Value_Unset()
        {
            bool called = false;
            string oldValue = null;
            string newValue = null;

            ParentControl parent = new ParentControl();
            ChildControl child = new ChildControl();
            parent.Children.Add(child);

            propertyChangedCallback = (s, o, n) =>
            {
                called = s == child;
                oldValue = o;
                newValue = n;
            };

            parent.Test = "bar";

            Assert.IsTrue(called);
            Assert.AreEqual(oldValue, "foo");
            Assert.AreEqual(newValue, "bar");
        }
예제 #28
0
 // Use this for initialization
 void Start()
 {
     oldman = GameObject.Find("Oldman").GetComponent <OldmanControl>();
     child  = GameObject.Find("Children").GetComponent <ChildControl>();
 }
        public void Visual_Bounds_Should_Be_Correct_For_CenterCenter_Alignment()
        {
            ContentControl target = new ContentControl();
            ChildControl child = new ChildControl();

            child.HorizontalAlignment = HorizontalAlignment.Center;
            child.VerticalAlignment = VerticalAlignment.Center;
            child.MeasureOutput = new Size(12, 23);
            target.Content = child;
            target.Arrange(new Rect(new Point(34, 45), new Size(56, 67)));

            Assert.AreEqual(new Vector(22, 22), child.VisualOffset);
            Assert.AreEqual(new Size(12, 23), child.RenderSize);
        }
예제 #30
0
        /// <summary>
        /// Load the included XML file of all NIST controls into a list to parse.
        /// This feeds a function below to load the records into a database in memory.
        /// </summary>
        /// <returns>The list of controls from the XML file</returns>
        public static List <Control> LoadControls()
        {
            List <Control> controls = new List <Control>();
            Control        c;
            ChildControl   cc;
            XmlDocument    xmlDoc = new XmlDocument();
            XmlNodeList    statementList;
            // get the file path for the NIST control listing inside this area
            var ccipath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/800-53-controls.xml";

            if (File.Exists(ccipath))
            {
                xmlDoc.LoadXml(File.ReadAllText(ccipath));
                XmlNodeList itemList = xmlDoc.GetElementsByTagName("controls:control");
                foreach (XmlElement child in itemList)
                {
                    c = new Control();
                    foreach (XmlElement controlData in child.ChildNodes)
                    {
                        if (controlData.Name == "family")
                        {
                            c.family = controlData.InnerText;
                        }
                        else if (controlData.Name == "number")
                        {
                            c.number = controlData.InnerText;
                        }
                        else if (controlData.Name == "title")
                        {
                            c.title = controlData.InnerText;
                        }
                        else if (controlData.Name == "priority")
                        {
                            c.priority = controlData.InnerText;
                        }
                        else if (controlData.Name == "baseline-impact")
                        {
                            if (controlData.InnerText == "LOW")
                            {
                                c.lowimpact = true;
                            }
                            else if (controlData.InnerText == "MODERATE")
                            {
                                c.moderateimpact = true;
                            }
                            else if (controlData.InnerText == "HIGH")
                            {
                                c.highimpact = true;
                            }
                        }
                        else if (controlData.Name == "statement")
                        {
                            // get the subparts of this control
                            statementList = controlData.GetElementsByTagName("statement");
                            foreach (XmlElement statementChild in statementList)
                            {
                                cc = new ChildControl();
                                // get all the sub controls listed
                                foreach (XmlElement statementData in statementChild.ChildNodes)
                                {
                                    if (statementData.Name == "number")
                                    {
                                        cc.number = statementData.InnerText;
                                    }
                                    else if (statementData.Name == "description")
                                    {
                                        cc.description = statementData.InnerText;
                                    }
                                }
                                // for this section, whatever the parent has you have
                                cc.lowimpact      = c.lowimpact;
                                cc.moderateimpact = c.moderateimpact;
                                cc.highimpact     = c.highimpact;
                                // add to the listing of child controls
                                c.childControls.Add(cc);
                            }
                        }
                        else if (controlData.Name == "control-enhancements")
                        {
                            // get the subparts of this control enhancement section
                            statementList = controlData.GetElementsByTagName("control-enhancement");
                            foreach (XmlElement statementChild in statementList)
                            {
                                cc = new ChildControl();
                                // get all the sub controls listed
                                foreach (XmlElement statementData in statementChild.ChildNodes)
                                {
                                    if (statementData.Name == "number")
                                    {
                                        cc.number = statementData.InnerText;
                                    }
                                    else if (statementData.Name == "description")
                                    {
                                        cc.description = statementData.InnerText;
                                    }
                                    else if (statementData.Name == "statement")
                                    {
                                        if (statementData.ChildNodes.Count > 0)
                                        {
                                            cc.description = statementData.ChildNodes[0].FirstChild.InnerText;
                                        }
                                    }
                                    else if (statementData.Name == "baseline-impact")
                                    {
                                        // the control enhancements have their own low/moderate/high setting
                                        if (statementData.InnerText == "LOW")
                                        {
                                            cc.lowimpact = true;
                                        }
                                        else if (statementData.InnerText == "MODERATE")
                                        {
                                            cc.moderateimpact = true;
                                        }
                                        else if (statementData.InnerText == "HIGH")
                                        {
                                            cc.highimpact = true;
                                        }
                                    }
                                }
                                c.childControls.Add(cc);
                            }
                        }
                        else if (controlData.Name == "supplemental-guidance")
                        {
                            // get the description
                            if (controlData.ChildNodes.Count > 0)
                            {
                                c.supplementalGuidance = controlData.ChildNodes[0].FirstChild.InnerText.Replace("\r", "").Replace("\n", "");
                            }
                        }
                    }
                    controls.Add(c); // add to the main control
                }
            }
            return(controls); // send back and have them cycle through it
        }
예제 #31
0
 /// <summary>
 /// 更新空间坐标尺寸信息
 /// </summary>
 /// <param name="cc"></param>
 /// <param name="r"></param>
 private void updateChildControl(ChildControl cc, RectangleF r)
 {
     _childControls[cc] = r;
 }
예제 #32
0
 public MainControl()
 {
     childControl = new ChildControl();
     childControl.VisibilityChanged += yourControl_VisibilityChanged;
 }
        public void Measure_Height_Should_Be_Passed_To_Child_ArrangeOverride_For_Bottom_Alignment()
        {
            ContentControl target = new ContentControl();
            ChildControl child = new ChildControl();

            child.RecordInputs = true;
            child.VerticalAlignment = VerticalAlignment.Bottom;
            child.MeasureOutput = new Size(12, 23);
            target.Content = child;
            target.Arrange(new Rect(new Point(34, 45), new Size(56, 67)));

            Assert.AreEqual(new Size(56, 23), child.ArrangeInput);
        }
예제 #34
0
        public void Test_NewChildControlIsValid()
        {
            ChildControl ctrl = new ChildControl();

            Assert.True(ctrl != null);
        }