Beispiel #1
0
                public void HandleChildDeleted(IEditableUIControl childControl)
                {
                    // if any of our children are deleted, we want to delete ourselves completely.
                    // First, remove the child that was just deleted, and then delete all other controls and ourself
                    foreach (IUIControl child in ChildControls)
                    {
                        if (child.Equals(childControl) == true)
                        {
                            ChildControls.Remove(child);
                            break;
                        }
                    }

                    HandleDelete(true);

                    //// if we still have children
                    //if( ChildControls.Count > 0 )
                    //{
                    //    // update our layout
                    //    SetPosition( Frame.Left, Frame.Top );
                    //}
                    //else
                    //{
                    //    // otherwise, delete ourselves and tell our parent
                    //    HandleDelete( true );
                    //}
                }
Beispiel #2
0
                public void HandleDelete(bool notifyParent)
                {
                    // first, delete all our child controls
                    int i = 0;

                    for (i = ChildControls.Count - 1; i >= 0; i--)
                    {
                        // since we DO support child controls that are containers, call HandleDelete on all our children
                        IEditableUIControl editableControl = ChildControls[i] as IEditableUIControl;
                        if (editableControl != null)
                        {
                            // let them know not to inform their parent, since that's us.
                            editableControl.HandleDelete(false);
                        }
                        else
                        {
                            // if it's not editable, we need to remove it ourselves
                            ChildControls[i].RemoveFromView(ParentEditingCanvas);
                        }

                        ChildControls.Remove(ChildControls[i]);
                    }

                    // clean ourselves up
                    RemoveFromView(ParentEditingCanvas);

                    // notify our parent if we need to
                    if (notifyParent)
                    {
                        ParentNote.HandleChildDeleted(this);
                    }
                }
Beispiel #3
0
                public IEditableUIControl HandleMouseHover(PointF mousePos)
                {
                    IEditableUIControl consumingControl = null;

                    // otherwise, see if we're hovering over the paragraph, and if we are, highlight it
                    RectangleF frame = GetFrame( );

                    frame.Inflate(CornerExtensionSize, CornerExtensionSize);

                    // are we hovering over this control?
                    bool mouseHovering = frame.Contains(mousePos);

                    if (mouseHovering == true)
                    {
                        // take us as the consumer
                        consumingControl = this;

                        // alter the hover appearance
                        TextView.BackgroundColor = 0xFFFFFF77;
                    }
                    // we're NOT hovering
                    else
                    {
                        // so revert the color and turn the Hovering flag off
                        TextView.BackgroundColor = OrigBackgroundColor;
                    }

                    return(consumingControl);
                }
Beispiel #4
0
                public IEditableUIControl HandleMouseDoubleClick(PointF point)
                {
                    // for double click, we need to give all our child controls a chance to consume

                    // see if any of our child controls contain the point
                    foreach (IUIControl control in ChildControls)
                    {
                        // if this control is editable
                        IEditableUIControl editableControl = control as IEditableUIControl;
                        if (editableControl != null)
                        {
                            // if it (or a child) consumes, return that
                            IEditableUIControl consumingControl = editableControl.HandleMouseDoubleClick(point);
                            if (consumingControl != null)
                            {
                                return(consumingControl);
                            }
                        }
                    }

                    // create a grabbable corner outside of the paragraph words
                    RectangleF frame = GetFrame( );

                    frame.Inflate(CornerExtensionSize, CornerExtensionSize);

                    if (frame.Contains(point))
                    {
                        // notify the caller we're consuming, and turn on edit mode
                        EditMode_Begin( );
                        return(this);
                    }

                    return(null);
                }
Beispiel #5
0
                public IEditableUIControl HandleControlSnappingX(IEditableUIControl sourceControl, PointF currPos, PointF snapRange)
                {
                    // given a currPos (which is the position the control WILL move to, not the current position of the control),
                    // find controls that fall within snapRange, and "snap" horizontally to the one closest
                    IEditableUIControl nearbyControl = null;
                    float minDeltaX = snapRange.X;

                    int i;

                    for (i = 0; i < ChildControls.Count; i++)
                    {
                        // make sure it's an editable control that isn't ourself
                        IEditableUIControl editableControl = ChildControls[i] as IEditableUIControl;
                        if (editableControl != null && editableControl != sourceControl)
                        {
                            // get the distance
                            float deltaX = Math.Abs(currPos.X - editableControl.GetPosition( ).X);
                            float deltaY = Math.Abs(currPos.Y - editableControl.GetPosition( ).Y);

                            // if we're within range, take it
                            if (deltaX < minDeltaX && deltaY < snapRange.Y)
                            {
                                nearbyControl = editableControl;
                                minDeltaX     = deltaX;
                            }
                        }
                    }

                    return(nearbyControl);
                }
Beispiel #6
0
                public EditableRevealBox(CreateParams parentParams, string text) : base(parentParams, text)
                {
                    ParentControl = parentParams.Parent as IEditableUIControl;

                    ParentEditingCanvas = null;

                    OrigBackgroundColor = PlatformLabel.BackgroundColor;
                }
Beispiel #7
0
                // This constructor is called when explicit Note Text is being declared.
                // This means the XML has "<NoteText>Something</NoteText>. Its used when
                // the user wants to alter a particular piece of text within a paragraph.
                public EditableNoteText(CreateParams parentParams, XmlReader reader) : base(parentParams, reader)
                {
                    ParentControl = parentParams.Parent as IEditableUIControl;

                    ParentEditingCanvas = null;

                    OrigBackgroundColor = PlatformLabel.BackgroundColor;
                }
Beispiel #8
0
                public string Export(RectangleF parentPadding, float currYPos)
                {
                    // start by setting our position to our global position, and then we'll translate.
                    float controlLeftPos = Frame.Left;
                    float controlTopPos  = Frame.Top;

                    // for vertical, it's relative to the control above it, so just make it relative to that
                    IUIControl logicalParent = ParentNote.GetLogicalVerticalParent(this);

                    if (logicalParent != null)
                    {
                        controlTopPos -= logicalParent.GetFrame( ).Bottom;
                    }
                    else
                    {
                        controlTopPos -= currYPos;
                    }

                    // for horizontal, it just needs to remove padding, since it'll be re-applied on load
                    controlLeftPos -= parentPadding.Left;

                    string xml = "<P ";

                    string attributes = "";

                    controlLeftPos /= (ParentSize.Width - parentPadding.Left - parentPadding.Right);
                    attributes     += string.Format("Left=\"{0:#0.00}%\"", controlLeftPos * 100);


                    attributes += string.Format(" Top=\"{0}\"", controlTopPos);

                    if (string.IsNullOrWhiteSpace(ActiveUrl) == false)
                    {
                        attributes += string.Format(" Url=\"{0}\"", HttpUtility.HtmlEncode(ActiveUrl));
                    }

                    xml += attributes + ">";

                    foreach (IUIControl child in ChildControls)
                    {
                        IEditableUIControl editableChild = child as IEditableUIControl;
                        if (editableChild != null)
                        {
                            // children of paragraphs cannot set their own position, so pass 0
                            xml += editableChild.Export(new RectangleF( ), 0);
                        }
                    }

                    xml += "</P>";

                    return(xml);
                }
Beispiel #9
0
                public void HandleChildDeleted(IEditableUIControl childControl)
                {
                    // this allows direct children of ours to notify us they were deleted
                    // (example: a user deletes the last word of text in a paragraph - the paragraph deletes itself, but Note must remove it from its ChildControls list.)

                    foreach (IUIControl child in ChildControls)
                    {
                        if (child.Equals(childControl) == true)
                        {
                            ChildControls.Remove(child);
                            break;
                        }
                    }
                }
Beispiel #10
0
                public IEditableUIControl HandleMouseDoubleClick(PointF position)
                {
                    // let each child add itself and its children
                    foreach (IUIControl control in ChildControls)
                    {
                        IEditableUIControl editableControl = control as IEditableUIControl;
                        if (editableControl != null)
                        {
                            IEditableUIControl targetControl = editableControl.HandleMouseDoubleClick(position);

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

                    return(null);
                }
Beispiel #11
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 #12
0
                public IEditableUIControl ControlAtPosition(PointF position)
                {
                    IEditableUIControl consumingControl = null;

                    // create a position outside the canvas. As soon as we find an item we're hovering over,
                    // we'll send the rest of the controls this position to force them to discontinue their hover state
                    PointF oobPos = new PointF(-100, -100);

                    // let each child add itself and its children
                    int i;

                    for (i = 0; i < ChildControls.Count; i++)
                    {
                        IEditableUIControl editableControl = ChildControls[i] as IEditableUIControl;
                        if (editableControl != null)
                        {
                            consumingControl = editableControl.HandleMouseHover(position);
                            if (consumingControl != null)
                            {
                                break;
                            }
                        }
                    }

                    // now let the remainig children turn off
                    i++;
                    for ( ; i < ChildControls.Count; i++)
                    {
                        IEditableUIControl editableControl = ChildControls[i] as IEditableUIControl;
                        if (editableControl != null)
                        {
                            editableControl.HandleMouseHover(oobPos);
                        }
                    }

                    // and return the control consuming this hover
                    return(consumingControl);
                }
Beispiel #13
0
                public string Export( )
                {
                    string xmlExport = "<Note " + sDefaultNoteAttribs + ">";

                    // first, sort all controls by Y. That way, if something was created and then moved UP, it won't
                    // have a negative value
                    ChildControls.Sort(delegate(IUIControl a, IUIControl b)
                    {
                        if (a.GetFrame( ).Top < b.GetFrame( ).Top)
                        {
                            return(-1);
                        }
                        return(1);
                    });

                    foreach (IUIControl child in ChildControls)
                    {
                        IEditableUIControl editableChild = child as IEditableUIControl;
                        xmlExport += editableChild.Export(new RectangleF(Padding.Left, Padding.Top, 0, 0), 0);
                    }

                    xmlExport += "</Note>";
                    return(xmlExport);
                }
Beispiel #14
0
                public void HandleChildStyleChanged(EditStyling.Style style, IEditableUIControl childControl)
                {
                    switch (style)
                    {
                    case EditStyling.Style.RevealBox:
                    {
                        // first, find the target in our list
                        int targetIndex = 0;
                        foreach (IUIControl child in ChildControls)
                        {
                            // when we find it
                            if (child.Equals(childControl) == true)
                            {
                                // take its index, and remove it from the renderer and our list of children
                                targetIndex = ChildControls.IndexOf(child);

                                child.RemoveFromView(ParentEditingCanvas);
                                ChildControls.RemoveAt(targetIndex);
                                break;
                            }
                        }

                        // if we received RevealBox, we're either upgrading a NoteText to BE a RevealBox,
                        // or downgrading a RevealBox to be a normal NoteText.
                        EditableNoteText editableNoteText = childControl as EditableNoteText;
                        if (editableNoteText != null)
                        {
                            // create a new revealBox, but force the text to uppper-case and add the bold font (since this is typically what the Mobile App does)
                            Style controlStyle = childControl.GetControlStyle( );
                            controlStyle.mFont       = new FontParams( );
                            controlStyle.mFont.mName = sDefaultBoldFontName;

                            RevealBox newRevealBox = Parser.CreateRevealBox(new CreateParams(this, Frame.Width, Frame.Height, ref controlStyle), editableNoteText.GetText( ).ToUpper( ).Trim( ));
                            newRevealBox.AddToView(ParentEditingCanvas);

                            // add the new revealBox into the same spot as what it's replacing
                            ChildControls.Insert(targetIndex, newRevealBox);

                            // make sure we add a space after the reveal box, as that's required.
                            NoteText textLabel = Parser.CreateNoteText(new CreateParams(this, Frame.Width, Frame.Height, ref mStyle), " ");
                            textLabel.AddToView(ParentEditingCanvas);
                            ChildControls.Insert(targetIndex + 1, textLabel);
                        }

                        EditableRevealBox editableRevealBox = childControl as EditableRevealBox;
                        if (editableRevealBox != null)
                        {
                            // create a new revealBox that has the styling and text of the noteText it's replacing.
                            Style    controlStyle = childControl.GetControlStyle( );
                            NoteText newNoteText  = Parser.CreateNoteText(new CreateParams(this, Frame.Width, Frame.Height, ref controlStyle), editableRevealBox.GetText( ).Trim( ));
                            newNoteText.AddToView(ParentEditingCanvas);

                            // add the new revealBox into the same spot as what it's replacing
                            ChildControls.Insert(targetIndex, newNoteText);
                        }

                        break;
                    }
                    }

                    // for now, lets just redo our layout.
                    SetPosition(Frame.Left, Frame.Top);
                }
Beispiel #15
0
 public void HandleChildDeleted(IEditableUIControl childControl)
 {
     // this control doesn't support children
 }
Beispiel #16
0
 public void HandleChildStyleChanged(EditStyling.Style style, IEditableUIControl childControl)
 {
     // for now, lets just redo our layout.
     SetPosition(TextView.Frame.Left, TextView.Frame.Top);
 }
Beispiel #17
0
 public void HandleChildStyleChanged(EditStyling.Style style, IEditableUIControl childControl)
 {
     // nothing this will need to do, since this control can't have children
 }
Beispiel #18
0
 public void HandleDeleteControl(IEditableUIControl control)
 {
     // notify the control to delete itself. if this results in a
     // direct child of ours being deleted, we'll receive a HandleChildDeleted call
     control.HandleDelete(true);
 }
Beispiel #19
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);
                }
Beispiel #20
0
                public void SetStyleValue(EditStyling.Style style, object value)
                {
                    switch (style)
                    {
                    case EditStyling.Style.BoldParagraph:
                    {
                        // force all children to bold
                        foreach (IUIControl child in ChildControls)
                        {
                            IEditableUIControl editableChild = child as IEditableUIControl;
                            if (editableChild != null)
                            {
                                editableChild.SetStyleValue(EditStyling.Style.FontName, EditableParagraph.sDefaultBoldFontName);
                            }
                        }
                        break;
                    }

                    case EditStyling.Style.BoldItalicizeParagraph:
                    {
                        // force all children to bold
                        foreach (IUIControl child in ChildControls)
                        {
                            IEditableUIControl editableChild = child as IEditableUIControl;
                            if (editableChild != null)
                            {
                                editableChild.SetStyleValue(EditStyling.Style.FontName, EditableParagraph.sDefaultBoldItalicFontName);
                            }
                        }
                        break;
                    }

                    case EditStyling.Style.ItalicizeParagraph:
                    {
                        // force all children to bold
                        foreach (IUIControl child in ChildControls)
                        {
                            IEditableUIControl editableChild = child as IEditableUIControl;
                            if (editableChild != null)
                            {
                                editableChild.SetStyleValue(EditStyling.Style.FontName, EditableParagraph.sDefaultItalicFontName);
                            }
                        }
                        break;
                    }

                    case EditStyling.Style.BulletParagraph:
                    {
                        // create a noteText with the bullet, and then insert it
                        XmlTextReader reader = new XmlTextReader(new StringReader("<NT>" + sBulletChar + "</NT>"));
                        reader.Read( );

                        IUIControl bulletText = Parser.TryParseControl(new CreateParams(this, ParentSize.Width, ParentSize.Height, ref mStyle), reader);

                        ChildControls.Insert(0, bulletText);

                        SetPosition(Frame.Left, Frame.Top);

                        bulletText.AddToView(ParentEditingCanvas);

                        break;
                    }

                    case EditStyling.Style.UnderlineParagraph:
                    {
                        // to underline the whole thing, we need to make it one big NoteText.
                        // we'll gather all the text, convert it to a single NoteText with Underlined Attribute,
                        // remove the existing children, and replace them with the new single underlined one.

                        // get the full text. we can use the build HTML stream code to do this.
                        string htmlStream = string.Empty;
                        string textStream = string.Empty;
                        BuildHTMLContent(ref htmlStream, ref textStream, new List <IUIControl>( ));

                        // if the last character is a URL glyph, remove it
                        textStream = textStream.Trim(new char[] { ' ', PrivateNoteConfig.CitationUrl_Icon[0] });

                        XmlTextReader reader = new XmlTextReader(new StringReader("<NT Underlined=\"True\">" + textStream + "</NT>"));
                        reader.Read( );

                        IUIControl noteText = Parser.TryParseControl(new CreateParams(this, ParentSize.Width, ParentSize.Height, ref mStyle), reader);

                        foreach (IUIControl control in ChildControls)
                        {
                            control.RemoveFromView(ParentEditingCanvas);
                        }
                        ChildControls.Clear( );


                        ChildControls.Add(noteText);

                        SetPosition(Frame.Left, Frame.Top);

                        noteText.AddToView(ParentEditingCanvas);

                        break;
                    }
                    }
                }
Beispiel #21
0
                public IEditableUIControl HandleMouseHover(PointF mousePos)
                {
                    IEditableUIControl consumingControl = null;
                    bool hoveringChildControl           = false;

                    // create a position outside the canvas. As soon as we find an item we're hovering over,
                    // we'll send the rest of the controls this position to force them to discontinue their hover state
                    PointF oobPos = new PointF(-100, -100);

                    // see if any of our child controls contain the point
                    int i;

                    for (i = 0; i < ChildControls.Count; i++)
                    {
                        IEditableUIControl editControl = ChildControls[i] as IEditableUIControl;
                        if (editControl != null)
                        {
                            // if we're hovering over any control, flag it, but don't stop checking
                            consumingControl = editControl.HandleMouseHover(mousePos);
                            if (consumingControl != null)
                            {
                                hoveringChildControl = true;
                                break;
                            }
                        }
                    }

                    // now let the remainig children turn off
                    i++;
                    for ( ; i < ChildControls.Count; i++)
                    {
                        IEditableUIControl editableControl = ChildControls[i] as IEditableUIControl;
                        if (editableControl != null)
                        {
                            editableControl.HandleMouseHover(oobPos);
                        }
                    }


                    // JHM 5-8-17 - Only show hover for the children. Don't highlight the paragraph. It's pointless and distracting
                    // if we're over a child
                    if (hoveringChildControl == true)
                    {
                        return(consumingControl);
                    }

                    return(null);

                    // if we're over a child
                    //if( hoveringChildControl == true )
                    //{
                    //    // restore the color
                    //    BorderView.BackgroundColor = OrigBackgroundColor;
                    //}
                    //else
                    //{
                    //    // otherwise, see if we're hovering over the paragraph, and if we are, highlight it
                    //    RectangleF frame = GetFrame( );
                    //    frame.Inflate( CornerExtensionSize, CornerExtensionSize );

                    //    // are we hovering over this control?
                    //    bool mouseHovering = frame.Contains( mousePos );
                    //    if( mouseHovering == true )
                    //    {
                    //        // take us as the consumer
                    //        consumingControl = this;

                    //        // set the hover appearance
                    //        BorderView.BackgroundColor = 0xFFFFFF77;
                    //    }
                    //    // we're NOT hovering
                    //    else
                    //    {
                    //        // so revert the color
                    //        BorderView.BackgroundColor = OrigBackgroundColor;
                    //    }
                    //}

                    //return consumingControl;
                }