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