Beispiel #1
0
                public IEditableUIControl ContainerForControl(Type controlType, PointF mousePos)
                {
                    // this will return the deepest level control that can own controlType as a parent.
                    // Example: contrlType == Paragraph, it's going to return the deepest level Stack Panel or Canvas found.
                    foreach (IUIControl control in ChildControls)
                    {
                        IEditableUIControl editableControl = control as IEditableUIControl;
                        if (editableControl != null)
                        {
                            IEditableUIControl targetControl = editableControl.ContainerForControl(controlType, mousePos);

                            if (targetControl != null)
                            {
                                return(targetControl);
                            }
                        }
                    }

                    return(null);
                }
Beispiel #2
0
                public void HandleCreateControl(Type controlType, PointF mousePos)
                {
                    do
                    {
                        // first, if we're creating a header, we need to make sure there isn't already one
                        if (typeof(EditableHeader) == controlType)
                        {
                            List <IUIControl> headerControls = new List <IUIControl>( );
                            GetControlOfType <EditableHeader>(headerControls);

                            // we found a header, so we're done.
                            if (headerControls.Count > 0)
                            {
                                break;
                            }
                        }

                        // now see if any child wants to create it
                        IUIControl newControl = null;
                        foreach (IUIControl control in ChildControls)
                        {
                            IEditableUIControl editableControl = control as IEditableUIControl;
                            if (editableControl != null)
                            {
                                IEditableUIControl containerControl = editableControl.ContainerForControl(controlType, mousePos);
                                if (containerControl != null)
                                {
                                    newControl = containerControl.HandleCreateControl(controlType, mousePos);
                                    break;
                                }
                            }
                        }

                        // if a child handled it, we're done
                        if (newControl != null)
                        {
                            break;
                        }


                        // it wasn't a header, and a child didn't create it, so we will.
                        float availableWidth = Frame.Width - Padding.Right - Padding.Left;

                        // if the control type is a header, we want to force it to position 0
                        float workingWidth = availableWidth;
                        if (typeof(EditableHeader) == controlType)
                        {
                            mousePos = PointF.Empty;

                            // and if its allowed, use the full width
                            if (mStyle.mFullWidthHeader == true)
                            {
                                workingWidth = Frame.Width;
                            }
                        }

                        newControl = Parser.CreateEditableControl(controlType, new BaseControl.CreateParams(this, workingWidth, DeviceHeight, ref mStyle));
                        ChildControls.Add(newControl);

                        // add it to our renderable canvas
                        newControl.AddToView(MasterView);

                        // default it to where the click occurred
                        newControl.AddOffset((float)mousePos.X, (float)mousePos.Y);

                        // if the newly created control is the lower than all others, update the note height.
                        // This lets us continue to build vertically
                        if (newControl.GetFrame( ).Bottom > Frame.Height)
                        {
                            Frame = new RectangleF(Frame.Left, Frame.Top, Frame.Width, newControl.GetFrame( ).Bottom + Padding.Bottom);
                        }
                    }while(0 != 0);
                }