Example #1
0
        private static void AllocateShortTextSpace(ViewLayoutContext context,
                                                   Graphics g,
                                                   StandardContentMemento memento,
                                                   IPaletteContent paletteContent,
                                                   IContentValues contentValues,
                                                   PaletteState state,
                                                   Rectangle displayRect,
                                                   RightToLeft rtl,
                                                   int spacingGap,
                                                   ref Size[,] allocation,
                                                   bool composition,
                                                   bool glowing)
        {
            // By default, we cannot draw the text
            memento.DrawShortText = false;

            // Get the defined text for display
            string shortText = contentValues.GetShortText();

            // Is there any text to be drawn?
            if ((shortText != null) && (shortText.Length > 0))
            {
                // If the text is not allowed to span multiple lines
                if (paletteContent.GetContentShortTextMultiLine(state) == InheritBool.False)
                {
                    // Replace any carriage returns and newlines with just spaces
                    shortText = shortText.Replace("\r\n", " ");
                    shortText = shortText.Replace("\n", " ");
                    shortText = shortText.Replace("\r", " ");
                }

                // Convert from alignment enums to integers
                int alignHIndex = RightToLeftIndex(rtl, paletteContent.GetContentShortTextH(state));
                int alignVIndex = (int)paletteContent.GetContentShortTextV(state);

                // Cache the rendering hint used
                memento.ShortTextHint = CommonHelper.PaletteTextHintToRenderingHint(paletteContent.GetContentShortTextHint(state));
                memento.ShortTextTrimming = paletteContent.GetContentShortTextTrim(state);

                bool fontChanged = false;
                Font textFont = paletteContent.GetContentShortTextFont(state);

                // Get the appropriate font to use in the caption area
                if (paletteContent.GetContentStyle() == PaletteContentStyle.HeaderForm)
                {
                    Font captionFont = ContentFontForButtonForm(context, textFont);
                    fontChanged = (captionFont != textFont);
                    textFont = captionFont;
                }

                // Get a pixel accurate measure of text drawing space needed
                memento.ShortTextMemento = AccurateText.MeasureString(g,
                                                                      rtl,
                                                                      shortText,
                                                                      textFont,
                                                                      memento.ShortTextTrimming,
                                                                      paletteContent.GetContentShortTextMultiLineH(state),
                                                                      paletteContent.GetContentShortTextPrefix(state),
                                                                      memento.ShortTextHint,
                                                                      composition,
                                                                      glowing,
                                                                      fontChanged);

                // Space required for short text starts with the text width itself
                Size requiredSpace = memento.ShortTextMemento.Size;

                // Find the space available given our required alignment
                if (AllocateAlignmentSpace(alignHIndex, alignVIndex,
                                           allocation, displayRect,
                                           spacingGap, memento.ShortTextTrimming,
                                           ref requiredSpace))
                {
                    // Allocate the actual space used up
                    // Cache the actual draw size of the text
                    memento.ShortTextRect.Size = requiredSpace;

                    // Mark the memento to draw the short text
                    memento.DrawShortText = true;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Get the preferred size for drawing the content.
        /// </summary>
        /// <param name="context">Layout context.</param>
        /// <param name="palette">Content palette details.</param>
        /// <param name="values">Content values.</param>
        /// <param name="orientation">Visual orientation of the content.</param>
        /// <param name="state">State associated with rendering.</param>
        /// <param name="composition">Should draw on a composition element.</param>
        /// <param name="glowing">If composition, should glowing be drawn.</param>
        /// <returns>Preferred size.</returns>
        public override Size GetContentPreferredSize(ViewLayoutContext context,
													 IPaletteContent palette,
													 IContentValues values,
													 VisualOrientation orientation,
                                                     PaletteState state,
                                                     bool composition,
                                                     bool glowing)
        {
            Debug.Assert(context != null);
            Debug.Assert(palette != null);
            Debug.Assert(values != null);

            // Validate parameter references
            if (context == null) throw new ArgumentNullException("context");
            if (palette == null) throw new ArgumentNullException("palette");

            Debug.Assert(context.Control != null);
            Debug.Assert(!context.Control.IsDisposed);

            // Provide a maximum sized rectangle for placing content into, in
            // order to work out how much of the space is actually allocated
            Rectangle displayRect = new Rectangle(Point.Empty, new Size(int.MaxValue, int.MaxValue));

            // Track the allocated space in each grid position
            Size[,] allocation = new Size[3, 3] { { Size.Empty, Size.Empty, Size.Empty },
                                                  { Size.Empty, Size.Empty, Size.Empty },
                                                  { Size.Empty, Size.Empty, Size.Empty } };

            // Create a memento for storing calculations
            using (StandardContentMemento memento = new StandardContentMemento())
            {
                // Cache the size of a spacing gap
                int spacingGap = palette.GetContentAdjacentGap(state);

                // Is the content intended for a vertical drawing orientation?
                bool vertical = (orientation == VisualOrientation.Left) ||
                                (orientation == VisualOrientation.Right);

                // Drawing vertical means we can ignore right to left, otherwise get value from control
                RightToLeft rtl = (vertical ? RightToLeft.No : context.Control.RightToLeft);

                // Allocate space for each required content in turn
                AllocateImageSpace(memento, palette, values, state, displayRect, rtl, ref allocation);
                AllocateShortTextSpace(context, context.Graphics, memento, palette, values, state, displayRect, rtl, spacingGap, ref allocation, composition, glowing);
                AllocateLongTextSpace(context, context.Graphics, memento, palette, values, state, displayRect, rtl, spacingGap, ref allocation, composition, glowing);

                // Add up total allocated for rows and columns
                int allocatedWidth = AllocatedTotalWidth(allocation, -1, -1, spacingGap);
                int allocatedHeight = AllocatedTotalHeight(allocation);

                // Grab the padding for the content
                Padding borderPadding = palette.GetContentPadding(state);

                // For the form level buttons we have to calculate the correct padding based on caption area
                PaletteContentStyle contentStyle = palette.GetContentStyle();
                if ((contentStyle == PaletteContentStyle.ButtonForm) ||
                    (contentStyle == PaletteContentStyle.ButtonFormClose))
                    borderPadding = ContentPaddingForButtonForm(borderPadding, context, allocatedHeight);

                // The preferred size needed depends on the orientation.
                switch (orientation)
                {
                    case VisualOrientation.Top:
                    case VisualOrientation.Bottom:
                        // Preferred size is the allocated space for the content plus the border padding
                        return new Size(allocatedWidth + borderPadding.Horizontal,
                                        allocatedHeight + borderPadding.Vertical);
                    case VisualOrientation.Left:
                    case VisualOrientation.Right:
                        // Preferred size is the allocated space for the content plus the border padding
                        return new Size(allocatedHeight + borderPadding.Vertical,
                                        allocatedWidth + borderPadding.Horizontal);
                    default:
                        // Should never happen!
                        Debug.Assert(false);
                        return Size.Empty;
                }
            }
        }
Example #3
0
 /// <summary>
 /// Gets the style appropriate for this content.
 /// </summary>
 /// <returns>Content style.</returns>
 public override PaletteContentStyle GetContentStyle()
 {
     return(_inherit.GetContentStyle());
 }
Example #4
0
 /// <summary>
 /// Gets the style appropriate for this content.
 /// </summary>
 /// <returns>Content style.</returns>
 public override PaletteContentStyle GetContentStyle() => Apply?_primary.GetContentStyle() : _backup.GetContentStyle();
 /// <summary>
 /// Gets the style appropriate for this content.
 /// </summary>
 /// <returns>Content style.</returns>
 public virtual PaletteContentStyle GetContentStyle() =>
 Apply?_primaryContent.GetContentStyle() : _backupContent.GetContentStyle();
Example #6
0
 /// <summary>
 /// Gets the style appropriate for this content.
 /// </summary>
 /// <returns>Content style.</returns>
 public override PaletteContentStyle GetContentStyle() => _inherit.GetContentStyle();