/// <summary> /// Initialize a new instance of the PaletteRibbonGeneral class. /// </summary> /// <param name="inherit">Source for inheriting general values.</param> /// <param name="needPaint">Delegate for notifying paint requests.</param> public PaletteRibbonGeneral(IPaletteRibbonGeneral inherit, NeedPaintHandler needPaint) { Debug.Assert(inherit != null); // Remember inheritance _inherit = inherit; // Store the provided paint notification delegate NeedPaint = needPaint; // Set default values _contextTextAlign = PaletteRelativeAlign.Inherit; _contextTextColor = Color.Empty; _contextTextFont = null; _disabledDarkColor = Color.Empty; _disabledLightColor = Color.Empty; _dialogDarkColor = Color.Empty; _dialogLightColor = Color.Empty; _dropArrowLightColor = Color.Empty; _dropArrowDarkColor = Color.Empty; _groupSeparatorDark = Color.Empty; _groupSeparatorLight = Color.Empty; _minimizeBarDarkColor = Color.Empty; _minimizeBarLightColor = Color.Empty; _ribbonShape = PaletteRibbonShape.Inherit; _tabSeparatorColor = Color.Empty; _tabSeparatorContextColor = Color.Empty; _textFont = null; _textHint = PaletteTextHint.Inherit; _qatButtonDarkColor = Color.Empty; _qatButtonLightColor = Color.Empty; }
/// <summary> /// Initialize a new instance of the PaletteDataGridViewContentStates class. /// </summary> /// <param name="inherit">Source for inheriting defaulted values.</param> /// <param name="needPaint">Delegate for notifying paint requests.</param> public PaletteDataGridViewContentStates(IPaletteContent inherit, NeedPaintHandler needPaint) { Debug.Assert(inherit != null); // Remember inheritance _inherit = inherit; // Store the provided paint notification delegate NeedPaint = needPaint; // Default the initial values _draw = InheritBool.Inherit; _hint = PaletteTextHint.Inherit; _trim = PaletteTextTrim.Inherit; _color1 = Color.Empty; _color2 = Color.Empty; _colorStyle = PaletteColorStyle.Inherit; _colorAlign = PaletteRectangleAlign.Inherit; _colorAngle = -1; _imageStyle = PaletteImageStyle.Inherit; _imageAlign = PaletteRectangleAlign.Inherit; _multiLine = InheritBool.Inherit; _multiLineH = PaletteRelativeAlign.Inherit; }
/// <summary> /// Initialize a new instance of the PaletteDataGridViewContentCommon class. /// </summary> /// <param name="inherit">Source for inheriting defaulted values.</param> /// <param name="needPaint">Delegate for notifying paint requests.</param> public PaletteDataGridViewContentCommon(IPaletteContent inherit, NeedPaintHandler needPaint) : base(inherit, needPaint) { // Default the initial values _padding = CommonHelper.InheritPadding; _textH = PaletteRelativeAlign.Inherit; _textV = PaletteRelativeAlign.Inherit; }
/// <summary> /// Gets the vertical relative alignment of the long text. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>RelativeAlignment value.</returns> public virtual PaletteRelativeAlign GetContentLongTextMultiLineH(PaletteState state) { if (Apply) { PaletteRelativeAlign ret = _primaryContent.GetContentLongTextMultiLineH(Override ? OverrideState : state); if (ret == PaletteRelativeAlign.Inherit) { ret = _backupContent.GetContentLongTextMultiLineH(state); } return(ret); } else { return(_backupContent.GetContentLongTextMultiLineH(state)); } }
/// <summary> /// Gets the vertical relative alignment of the long text. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>RelativeAlignment value.</returns> public override PaletteRelativeAlign GetContentLongTextMultiLineH(PaletteState state) { if (_apply) { PaletteRelativeAlign ret = _primary.GetContentLongTextMultiLineH(_override ? _state : state); if (ret == PaletteRelativeAlign.Inherit) { ret = _backup.GetContentLongTextMultiLineH(state); } return(ret); } else { return(_backup.GetContentLongTextMultiLineH(state)); } }
/// <summary> /// Gets the vertical relative alignment of the short text. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>RelativeAlignment value.</returns> public virtual PaletteRelativeAlign GetContentShortTextV(PaletteState state) { if (_apply) { PaletteRelativeAlign ret = _primaryContent.GetContentShortTextV(_override ? _state : state); if (ret == PaletteRelativeAlign.Inherit) { ret = _backupContent.GetContentShortTextV(state); } return(ret); } else { return(_backupContent.GetContentShortTextV(state)); } }
/// <summary> /// Gets the vertical relative alignment of the long text. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>RelativeAlignment value.</returns> public override PaletteRelativeAlign GetContentLongTextV(PaletteState state) { if (Apply) { PaletteRelativeAlign ret = _primary.GetContentLongTextV(Override ? OverrideState : state); if (ret == PaletteRelativeAlign.Inherit) { ret = _backup.GetContentLongTextV(state); } return(ret); } else { return(_backup.GetContentLongTextV(state)); } }
/// <summary> /// Initialize a new instance of the ViewDrawRibbonGalleryButton class. /// </summary> /// <param name="palette">Reference to inherited palette.</param> /// <param name="alignment">Button alignment within gallery.</param> /// <param name="button">Button content to display.</param> /// <param name="images">Button images.</param> /// <param name="needPaint">Paint event delegate.</param> public ViewDrawRibbonGalleryButton(IPalette palette, PaletteRelativeAlign alignment, PaletteRibbonGalleryButton button, GalleryImages images, NeedPaintHandler needPaint) { _palette = palette; _alignment = alignment; _button = button; _images = images; _needPaint = needPaint; _paletteBack = new PaletteBackToPalette(palette, PaletteBackStyle.ButtonGallery); _paletteBorder = new PaletteBorderToPalette(palette, PaletteBorderStyle.ButtonGallery); _paletteContent = new PaletteContentToPalette(palette, PaletteContentStyle.ButtonGallery); _controller = new GalleryButtonController(this, needPaint, (alignment != PaletteRelativeAlign.Far)); _controller.Click += OnButtonClick; MouseController = _controller; }
/// <summary> /// Initialize a new instance of the ViewDrawRibbonGalleryButton class. /// </summary> /// <param name="palette">Reference to inherited palette.</param> /// <param name="alignment">Button alignment within gallery.</param> /// <param name="button">Button content to display.</param> /// <param name="images">Button images.</param> /// <param name="needPaint">Paint event delegate.</param> public ViewDrawRibbonGalleryButton(IPalette palette, PaletteRelativeAlign alignment, PaletteRibbonGalleryButton button, GalleryImages images, NeedPaintHandler needPaint) { _palette = palette; _alignment = alignment; _button = button; _images = images; _needPaint = needPaint; _paletteBack = new PaletteBackToPalette(palette, PaletteBackStyle.ButtonGallery); _paletteBorder = new PaletteBorderToPalette(palette, PaletteBorderStyle.ButtonGallery); _paletteContent = new PaletteContentToPalette(palette, PaletteContentStyle.ButtonGallery); _controller = new GalleryButtonController(this, needPaint, (alignment != PaletteRelativeAlign.Far)); _controller.Click += new MouseEventHandler(OnButtonClick); MouseController = _controller; }
/// <summary> /// Initialize a new instance of the InternalStorage structure. /// </summary> public InternalStorage() { // Set to default values ContentTextHint = PaletteTextHint.Inherit; ContentTextTrim = PaletteTextTrim.Inherit; ContentTextPrefix = PaletteTextHotkeyPrefix.Inherit; ContentTextH = PaletteRelativeAlign.Inherit; ContentTextV = PaletteRelativeAlign.Inherit; ContentTextMultiLineH = PaletteRelativeAlign.Inherit; ContentTextMultiLine = InheritBool.Inherit; ContentTextColor1 = Color.Empty; ContentTextColor2 = Color.Empty; ContentTextColorStyle = PaletteColorStyle.Inherit; ContentTextColorAlign = PaletteRectangleAlign.Inherit; ContentTextColorAngle = -1; ContentTextImageStyle = PaletteImageStyle.Inherit; ContentTextImageAlign = PaletteRectangleAlign.Inherit; }
/// <summary> /// Pixel accurate measure of the specified string when drawn with the specified Font object. /// </summary> /// <param name="g">Graphics instance used to measure text.</param> /// <param name="rtl">Right to left setting for control.</param> /// <param name="text">String to measure.</param> /// <param name="font">Font object that defines the text format of the string.</param> /// <param name="trim">How to trim excess text.</param> /// <param name="align">How to align multi-line text.</param> /// <param name="prefix">How to process prefix characters.</param> /// <param name="hint">Rendering hint.</param> /// <param name="composition">Should draw on a composition element.</param> /// <param name="glowing">When on composition draw with glowing.</param> /// <param name="disposeFont">Dispose of font when finished with it.</param> /// <exception cref="ArgumentNullException"></exception> /// <returns>A memento used to draw the text.</returns> public static AccurateTextMemento MeasureString(Graphics g, RightToLeft rtl, string text, Font font, PaletteTextTrim trim, PaletteRelativeAlign align, PaletteTextHotkeyPrefix prefix, TextRenderingHint hint, bool composition, bool glowing, bool disposeFont) { Debug.Assert(g != null); Debug.Assert(text != null); Debug.Assert(font != null); if (g == null) { throw new ArgumentNullException(nameof(g)); } if (text == null) { throw new ArgumentNullException(nameof(text)); } if (font == null) { throw new ArgumentNullException(nameof(font)); } // An empty string cannot be drawn, so uses the empty memento if (text.Length == 0) { return(AccurateTextMemento.Empty); } // Create the format object used when measuring and drawing StringFormat format = new StringFormat { FormatFlags = StringFormatFlags.NoClip }; // Ensure that text reflects reversed RTL setting if (rtl == RightToLeft.Yes) { format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } // How do we position text horizontally? switch (align) { case PaletteRelativeAlign.Near: format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Far : StringAlignment.Near; break; case PaletteRelativeAlign.Center: format.Alignment = StringAlignment.Center; break; case PaletteRelativeAlign.Far: format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Near : StringAlignment.Far; break; default: // Should never happen! Debug.Assert(false); break; } // Do we need to trim text that is too big? switch (trim) { case PaletteTextTrim.Character: format.Trimming = StringTrimming.Character; break; case PaletteTextTrim.EllipsisCharacter: format.Trimming = StringTrimming.EllipsisCharacter; break; case PaletteTextTrim.EllipsisPath: format.Trimming = StringTrimming.EllipsisPath; break; case PaletteTextTrim.EllipsisWord: format.Trimming = StringTrimming.EllipsisWord; break; case PaletteTextTrim.Word: format.Trimming = StringTrimming.Word; break; case PaletteTextTrim.Hide: format.Trimming = StringTrimming.None; break; default: // Should never happen! Debug.Assert(false); break; } // Setup the correct prefix processing switch (prefix) { case PaletteTextHotkeyPrefix.None: format.HotkeyPrefix = HotkeyPrefix.None; break; case PaletteTextHotkeyPrefix.Hide: format.HotkeyPrefix = HotkeyPrefix.Hide; break; case PaletteTextHotkeyPrefix.Show: format.HotkeyPrefix = HotkeyPrefix.Show; break; default: // Should never happen! Debug.Assert(false); break; } // Replace tab characters with a fixed four spaces text = text.Replace("\t", " "); // Perform actual measure of the text using (GraphicsTextHint graphicsHint = new GraphicsTextHint(g, hint)) { SizeF textSize = Size.Empty; try { textSize = g.MeasureString(text, font, int.MaxValue, format); if (composition && glowing) //Seb { textSize.Width += GLOW_EXTRA_WIDTH; } } catch { // ignored } // Return a memento with drawing details return(new AccurateTextMemento(text, font, textSize, format, hint, disposeFont)); } }
private static int RightToLeftIndex(RightToLeft rtl, PaletteRelativeAlign align) { switch (align) { case PaletteRelativeAlign.Near: return (rtl == RightToLeft.Yes ? 2 : 0); case PaletteRelativeAlign.Center: return 1; case PaletteRelativeAlign.Far: return (rtl == RightToLeft.Yes ? 0 : 2); default: // Should never happen! Debug.Assert(false); throw new ArgumentOutOfRangeException("align"); } }
private static Point PositionCellContent(RightToLeft rtl, PaletteRelativeAlign drawH, PaletteRelativeAlign drawV, Size contentSize, int spacingGap, ref Rectangle cellRect) { Point location = Point.Empty; // If drawing from right to left... if (rtl == RightToLeft.Yes) { // Then invert the near and far positioning if (drawH == PaletteRelativeAlign.Near) drawH = PaletteRelativeAlign.Far; else if (drawH == PaletteRelativeAlign.Far) drawH = PaletteRelativeAlign.Near; } switch (drawH) { case PaletteRelativeAlign.Near: location.X = cellRect.Left; cellRect.X += (contentSize.Width + spacingGap); cellRect.Width -= (contentSize.Width + spacingGap); break; case PaletteRelativeAlign.Center: int halfHorz = (cellRect.Width - contentSize.Width) / 2; location.X = cellRect.Left + halfHorz; break; case PaletteRelativeAlign.Far: location.X = cellRect.Right - contentSize.Width; cellRect.Width -= (contentSize.Width + spacingGap); break; } switch (drawV) { case PaletteRelativeAlign.Near: location.Y = cellRect.Top; break; case PaletteRelativeAlign.Center: int halfVert = (cellRect.Height - contentSize.Height) / 2; location.Y = cellRect.Top + halfVert; break; case PaletteRelativeAlign.Far: location.Y = cellRect.Bottom - contentSize.Height; break; } return location; }
private static void PositionAlignContent(StandardContentMemento memento, IPaletteContent paletteContent, PaletteState state, RightToLeft rtl, PaletteRelativeAlign alignH, PaletteRelativeAlign alignV, int cellX, int cellY, int cellWidth, int cellHeight, int spacingGap) { // Create client rectangle covering cell size Rectangle cellRect = new Rectangle(cellX, cellY, cellWidth, cellHeight); PaletteRelativeAlign drawHImage = paletteContent.GetContentImageH(state); PaletteRelativeAlign drawVImage = paletteContent.GetContentImageV(state); PaletteRelativeAlign drawHShort = paletteContent.GetContentShortTextH(state); PaletteRelativeAlign drawVShort = paletteContent.GetContentShortTextV(state); PaletteRelativeAlign drawHLong = paletteContent.GetContentLongTextH(state); PaletteRelativeAlign drawVLong = paletteContent.GetContentLongTextV(state); PaletteRelativeAlign posHImage = drawHImage; PaletteRelativeAlign posHShort = drawHShort; PaletteRelativeAlign posHLong = drawHLong; // If positioning in the center, then need extra processing if (alignH == PaletteRelativeAlign.Center) { // Find number of content and width of those in this cell int totalWidth = 0; int totalItems = 0; if (memento.DrawImage && (drawHImage == alignH) && (drawVImage == alignV)) { totalWidth += memento.ImageRect.Width; totalItems++; } if (memento.DrawShortText && (drawHShort == alignH) && (drawVShort == alignV)) { totalWidth += memento.ShortTextRect.Width; totalItems++; } if (memento.DrawLongText && (drawHLong == alignH) && (drawVLong == alignV)) { totalWidth += memento.LongTextRect.Width; totalItems++; } // If more than one item is to be positioned if (totalItems > 1) { // Add on required number of spacing gaps totalWidth += (totalItems - 1) * spacingGap; // Then center the space for the content int halfWidth = (cellRect.Width - totalWidth) / 2; cellRect.Width -= (halfWidth * 2); cellRect.X += halfWidth; // Ensure all content are placed near, so they fit exactly posHImage = posHShort = posHLong = PaletteRelativeAlign.Near; } } // Do we need to position the image? if (memento.DrawImage && (drawHImage == alignH) && (drawVImage == alignV)) memento.ImageRect.Location = PositionCellContent(rtl, posHImage, drawVImage, memento.ImageRect.Size, spacingGap, ref cellRect); // Do we need to position the short text? if (memento.DrawShortText && (drawHShort == alignH) && (drawVShort == alignV)) memento.ShortTextRect.Location = PositionCellContent(rtl, posHShort, drawVShort, memento.ShortTextRect.Size, spacingGap, ref cellRect); // Do we need to position the long text? if (memento.DrawLongText && (drawHLong == alignH) && (drawVLong == alignV)) memento.LongTextRect.Location = PositionCellContent(rtl, posHLong, drawVLong, memento.LongTextRect.Size, spacingGap, ref cellRect); }
/// <summary> /// Pixel accurate measure of the specified string when drawn with the specified Font object. /// </summary> /// <param name="g">Graphics instance used to measure text.</param> /// <param name="rtl">Right to left setting for control.</param> /// <param name="text">String to measure.</param> /// <param name="font">Font object that defines the text format of the string.</param> /// <param name="trim">How to trim excess text.</param> /// <param name="align">How to align multine text.</param> /// <param name="prefix">How to process prefix characters.</param> /// <param name="hint">Rendering hint.</param> /// <param name="composition">Should draw on a composition element.</param> /// <param name="disposeFont">Dispose of font when finished with it.</param> /// <returns>A memento used to draw the text.</returns> public static AccurateTextMemento MeasureString(Graphics g, RightToLeft rtl, string text, Font font, PaletteTextTrim trim, PaletteRelativeAlign align, PaletteTextHotkeyPrefix prefix, TextRenderingHint hint, bool composition, bool disposeFont) { Debug.Assert(g != null); Debug.Assert(text != null); Debug.Assert(font != null); if (g == null) throw new ArgumentNullException("g"); if (text == null) throw new ArgumentNullException("text"); if (font == null) throw new ArgumentNullException("font"); // An empty string cannot be drawn, so uses the empty memento if (text.Length == 0) return AccurateTextMemento.Empty; // Create the format object used when measuring and drawing StringFormat format = new StringFormat(); format.FormatFlags = StringFormatFlags.NoClip; // Ensure that text reflects reversed RTL setting if (rtl == RightToLeft.Yes) format.FormatFlags = StringFormatFlags.DirectionRightToLeft; // How do we position text horizontally? switch (align) { case PaletteRelativeAlign.Near: format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Far : StringAlignment.Near; break; case PaletteRelativeAlign.Center: format.Alignment = StringAlignment.Center; break; case PaletteRelativeAlign.Far: format.Alignment = (rtl == RightToLeft.Yes) ? StringAlignment.Near : StringAlignment.Far; break; default: // Should never happen! Debug.Assert(false); break; } // Do we need to trim text that is too big? switch (trim) { case PaletteTextTrim.Character: format.Trimming = StringTrimming.Character; break; case PaletteTextTrim.EllipsisCharacter: format.Trimming = StringTrimming.EllipsisCharacter; break; case PaletteTextTrim.EllipsisPath: format.Trimming = StringTrimming.EllipsisPath; break; case PaletteTextTrim.EllipsisWord: format.Trimming = StringTrimming.EllipsisWord; break; case PaletteTextTrim.Word: format.Trimming = StringTrimming.Word; break; case PaletteTextTrim.Hide: format.Trimming = StringTrimming.None; break; default: // Should never happen! Debug.Assert(false); break; } // Setup the correct prefix processing switch (prefix) { case PaletteTextHotkeyPrefix.None: format.HotkeyPrefix = HotkeyPrefix.None; break; case PaletteTextHotkeyPrefix.Hide: format.HotkeyPrefix = HotkeyPrefix.Hide; break; case PaletteTextHotkeyPrefix.Show: format.HotkeyPrefix = HotkeyPrefix.Show; break; default: // Should never happen! Debug.Assert(false); break; } // Replace tab characters with a fixed four spaces text = text.Replace("\t", " "); // Perform actual measure of the text using (GraphicsTextHint graphicsHint = new GraphicsTextHint(g, hint)) { SizeF textSize = Size.Empty; try { textSize = g.MeasureString(text, font, int.MaxValue, format); if (composition) textSize.Width += GLOW_EXTRA_WIDTH; } catch {} // Return a memento with drawing details return new AccurateTextMemento(text, font, textSize, format, hint, disposeFont); } }
/// <summary> /// Reset the ContextTextAlign to the default value. /// </summary> public void ResetContextTextAlign() { ContextTextAlign = PaletteRelativeAlign.Inherit; }
/// <summary> /// Populate values from the base palette. /// </summary> /// <param name="state">Palette state to use when populating.</param> public override void PopulateFromBase(PaletteState state) { base.PopulateFromBase(state); Font = GetContentShortTextFont(state); TextH = GetContentShortTextH(state); TextV = GetContentShortTextV(state); Padding = GetContentPadding(state); }
/// <summary> /// Initialize a new instance of the InternalStorage structure. /// </summary> public InternalStorage() { // Set to default values ContentImageH = PaletteRelativeAlign.Inherit; ContentImageV = PaletteRelativeAlign.Inherit; ContentEffect = PaletteImageEffect.Inherit; ContentImageColorMap = Color.Empty; ContentImageColorTo = Color.Empty; }