コード例 #1
0
        /// <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;
        }
コード例 #2
0
 /// <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>
        /// Gets the text trimming to use for long text.
        /// </summary>
        /// <param name="state">Palette value should be applicable to this state.</param>
        /// <returns>PaletteTextTrim value.</returns>
        public virtual PaletteTextTrim GetContentLongTextTrim(PaletteState state)
        {
            if (Apply)
            {
                PaletteTextTrim ret = _primaryContent.GetContentLongTextTrim(Override ? OverrideState : state);

                if (ret == PaletteTextTrim.Inherit)
                {
                    ret = _backupContent.GetContentLongTextTrim(state);
                }

                return(ret);
            }
            else
            {
                return(_backupContent.GetContentLongTextTrim(state));
            }
        }
コード例 #4
0
        /// <summary>
        /// Gets the text trimming to use for long text.
        /// </summary>
        /// <param name="state">Palette value should be applicable to this state.</param>
        /// <returns>PaletteTextTrim value.</returns>
        public override PaletteTextTrim GetContentLongTextTrim(PaletteState state)
        {
            if (_apply)
            {
                PaletteTextTrim ret = _primary.GetContentLongTextTrim(_override ? _state : state);

                if (ret == PaletteTextTrim.Inherit)
                {
                    ret = _backup.GetContentLongTextTrim(state);
                }

                return(ret);
            }
            else
            {
                return(_backup.GetContentLongTextTrim(state));
            }
        }
コード例 #5
0
        /// <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));
            }
        }
コード例 #6
0
ファイル: RenderStandard.cs プロジェクト: Cocotteseb/Krypton
        private static bool AllocateAlignmentSpace(int alignHIndex,
                                                   int alignVIndex,
                                                   Size[,] allocation,
                                                   Rectangle displayRect,
                                                   int spacingGap,
                                                   PaletteTextTrim trim,
                                                   ref Size requiredSize)
        {
            // Cache the current target value
            Size cacheSize = allocation[alignHIndex, alignVIndex];

            // Track the width needed to show the item
            bool applyGap = false;
            int allocateWidth = requiredSize.Width;

            // If there is already something in the cell
            if (allocation[alignHIndex, alignVIndex].Width > 0)
            {
                // Then add the spacing gap to the required size width
                allocateWidth += spacingGap;
                applyGap = true;
            }

            // Find the current allocated total width
            int totalWidth = AllocatedTotalWidth(allocation, alignHIndex, alignVIndex, spacingGap);

            // How much space is available for allocation?
            int freeSpace = displayRect.Width - totalWidth;

            // If not enough room then we failed
            if (freeSpace < allocateWidth)
            {
                // Should we try and trim the text into the space?
                if (trim != PaletteTextTrim.Hide)
                {
                    // If there is some room available after taking
                    // into account the need for a spacing gap
                    if ((allocateWidth == requiredSize.Width) ||
                        ((allocateWidth > requiredSize.Width) && applyGap))
                    {
                        // Allocate just the available space
                        allocateWidth = freeSpace;

                        // Reduce the reported size back to the caller
                        if (applyGap)
                            requiredSize.Width = allocateWidth - spacingGap;
                        else
                            requiredSize.Width = allocateWidth;
                    }
                    else
                        return false;
                }
                else
                    return false;
            }

            // There is enough space for all the content, so add into the cell width
            allocation[alignHIndex, alignVIndex].Width += allocateWidth;

            // If the required height is greater than the current cell height
            if (requiredSize.Height > allocation[alignHIndex, alignVIndex].Height)
            {
                // Then use the required height instead
                allocation[alignHIndex, alignVIndex].Height = requiredSize.Height;
            }

            // Find the allocated total height as a result
            int totalHeight = AllocatedTotalHeight(allocation);

            // If not enough height then we failed
            if (totalHeight > displayRect.Height)
            {
                // Restore the original cell
                allocation[alignHIndex, alignVIndex] = cacheSize;
                return false;
            }

            return true;
        }
コード例 #7
0
ファイル: RenderStandard.cs プロジェクト: Cocotteseb/Krypton
 /// <summary>
 /// Inititialize a new instance of the StandardContentMemento class.
 /// </summary>
 public StandardContentMemento()
 {
     LongTextTrimming = PaletteTextTrim.EllipsisCharacter;
     ShortTextTrimming = PaletteTextTrim.EllipsisCharacter;
     Orientation = VisualOrientation.Top;
 }
コード例 #8
0
        /// <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);
            }
        }
コード例 #9
0
 /// <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;
 }