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); }
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; } } }