Encapsulates common context for view layout and render operations.
Inheritance: GlobalId, IDisposable
示例#1
0
        /// <summary>
        /// Helper routine to draw an image taking into account various properties.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="image">Image to be drawn.</param>
        /// <param name="remapTransparent">Color that should become transparent.</param>
        /// <param name="imageRect">Destination rectangle.</param>
        /// <param name="orientation">Visual orientation.</param>
        /// <param name="effect">Drawing effect.</param>
        /// <param name="remapColor">Image color to remap.</param>
        /// <param name="remapNew">New color for remap.</param>
        protected static void DrawImageHelper(ViewContext context,
									          Image image,
                                              Color remapTransparent,
									          Rectangle imageRect,
									          VisualOrientation orientation,
									          PaletteImageEffect effect,
                                              Color remapColor,
                                              Color remapNew)
        {
            Debug.Assert(context != null);

            // Prevent problems with multiple threads using the same palette images
            // by only allowing a single thread to draw the provided image at a time
            lock (_threadLock)
            {
                // Validate reference parameter
                if (context == null) throw new ArgumentNullException("context");

                // Use image attributes class to modify image drawing for effects
                ImageAttributes attribs = new ImageAttributes();

                switch (effect)
                {
                    case PaletteImageEffect.Disabled:
                        attribs.SetColorMatrix(CommonHelper.MatrixDisabled);
                        break;
                    case PaletteImageEffect.GrayScale:
                        attribs.SetColorMatrix(_matrixGrayScale, ColorMatrixFlag.SkipGrays);
                        break;
                    case PaletteImageEffect.GrayScaleRed:
                        attribs.SetColorMatrix(_matrixGrayScaleRed, ColorMatrixFlag.SkipGrays);
                        break;
                    case PaletteImageEffect.GrayScaleGreen:
                        attribs.SetColorMatrix(_matrixGrayScaleGreen, ColorMatrixFlag.SkipGrays);
                        break;
                    case PaletteImageEffect.GrayScaleBlue:
                        attribs.SetColorMatrix(_matrixGrayScaleBlue, ColorMatrixFlag.SkipGrays);
                        break;
                    case PaletteImageEffect.Light:
                        attribs.SetColorMatrix(_matrixLight);
                        break;
                    case PaletteImageEffect.LightLight:
                        attribs.SetColorMatrix(_matrixLightLight);
                        break;
                    case PaletteImageEffect.Dark:
                        attribs.SetColorMatrix(_matrixDark);
                        break;
                    case PaletteImageEffect.DarkDark:
                        attribs.SetColorMatrix(_matrixDarkDark);
                        break;
                    case PaletteImageEffect.Inherit:
                        // Should never happen!
                        Debug.Assert(false);
                        break;
                }

                // Do we need to remap a colors in the bitmap?
                if ((remapTransparent != Color.Empty) ||
                    ((remapColor != Color.Empty) && (remapNew != Color.Empty)))
                {
                    List<ColorMap> colorMaps = new List<ColorMap>();

                    // Create remapping for the transparent color
                    if (remapTransparent != Color.Empty)
                    {
                        ColorMap remap = new ColorMap();
                        remap.OldColor = remapTransparent;
                        remap.NewColor = Color.Transparent;
                        colorMaps.Add(remap);
                    }

                    // Create remapping from source to target colors
                    if ((remapColor != Color.Empty) && (remapNew != Color.Empty))
                    {
                        ColorMap remap = new ColorMap();
                        remap.OldColor = remapColor;
                        remap.NewColor = remapNew;
                        colorMaps.Add(remap);
                    }

                    attribs.SetRemapTable(colorMaps.ToArray(), ColorAdjustType.Bitmap);
                }

                int translateX = 0;
                int translateY = 0;
                float rotation = 0f;

                // Perform any transformations needed for orientation
                switch (orientation)
                {
                    case VisualOrientation.Bottom:
                        // Translate to opposite side of origin, so the rotate can
                        // then bring it back to original position but mirror image
                        translateX = imageRect.X * 2 + imageRect.Width;
                        translateY = imageRect.Y * 2 + imageRect.Height;
                        rotation = 180f;
                        break;
                    case VisualOrientation.Left:
                        // Invert the dimensions of the rectangle for drawing upwards
                        imageRect = new Rectangle(imageRect.X, imageRect.Y, imageRect.Height, imageRect.Width);

                        // Translate back from a quarter left turn to the original place
                        translateX = imageRect.X - imageRect.Y;
                        translateY = imageRect.X + imageRect.Y + imageRect.Width;
                        rotation = -90f;
                        break;
                    case VisualOrientation.Right:
                        // Invert the dimensions of the rectangle for drawing upwards
                        imageRect = new Rectangle(imageRect.X, imageRect.Y, imageRect.Height, imageRect.Width);

                        // Translate back from a quarter right turn to the original place
                        translateX = imageRect.X + imageRect.Y + imageRect.Height;
                        translateY = -(imageRect.X - imageRect.Y);
                        rotation = 90f;
                        break;
                }

                // Apply the transforms if we have any to apply
                if ((translateX != 0) || (translateY != 0))
                    context.Graphics.TranslateTransform(translateX, translateY);

                if (rotation != 0f)
                    context.Graphics.RotateTransform(rotation);

                try
                {
                    // Finally, just draw the image and let the transforms do the rest
                    context.Graphics.DrawImage(image, imageRect, 0, 0, imageRect.Width, imageRect.Height, GraphicsUnit.Pixel, attribs);
                }
                catch (ArgumentException)
                {
                }
                finally
                {
                    if (rotation != 0f)
                        context.Graphics.RotateTransform(-rotation);

                    // Remove the applied transforms
                    if ((translateX != 0) | (translateY != 0))
                        context.Graphics.TranslateTransform(-translateX, -translateY);
                }
            }
        }
示例#2
0
 /// <summary>
 /// Evaluate the need for drawing transparent areas.
 /// </summary>
 /// <param name="context">Evaluation context.</param>
 /// <returns>True if transparent areas exist; otherwise false.</returns>
 public override bool EvalTransparentPaint(ViewContext context)
 {
     return _child.EvalTransparentPaint(context);
 }
示例#3
0
        /// <summary>
        /// Helper routine to draw an image taking into account various properties.
        /// </summary>
        /// <param name="context">Rendering context.</param>
        /// <param name="icon">Icon to be drawn.</param>
        /// <param name="iconRect">Destination rectangle.</param>
        /// <param name="orientation">Visual orientation.</param>
        protected static void DrawIconHelper(ViewContext context,
								             Icon icon,
								             Rectangle iconRect,
								             VisualOrientation orientation)
        {
            Debug.Assert(context != null);

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

            try
            {
                // Finally, just draw the icon and let the transforms do the rest
                context.Graphics.DrawIcon(icon, iconRect);
            }
            finally
            {
            }
        }
        /// <summary>
        /// Gets the short text drawing rectangle.
        /// </summary>
        /// <returns>Rectangle of short text drawing.</returns>
        public Rectangle ShortTextRect(ViewContext context)
        {
            Debug.Assert(context != null);

            // Validate incoming reference
            if (context == null) throw new ArgumentNullException("context");

            Rectangle textRect = Rectangle.Empty;

            // If we have some content to investigate
            if (_paletteContent.GetContentDraw(State) == InheritBool.True)
                textRect = context.Renderer.RenderStandardContent.GetContentShortTextRectangle(_memento);

            return textRect;
        }
示例#5
0
        /// <summary>
        /// Evaluate the need for drawing transparent areas.
        /// </summary>
        /// <param name="context">Evaluation context.</param>
        /// <returns>True if transparent areas exist; otherwise false.</returns>
        public override bool EvalTransparentPaint(ViewContext context)
        {
            Debug.Assert(context != null);

            // Ask the renderer to evaluate the given palette
            return context.Renderer.EvalTransparentPaint(_paletteBack, State);
        }
 /// <summary>
 /// Evaluate the need for drawing transparent areas.
 /// </summary>
 /// <param name="context">Evaluation context.</param>
 /// <returns>True if transparent areas exist; otherwise false.</returns>
 public override bool EvalTransparentPaint(ViewContext context)
 {
     return true;
 }
        /// <summary>
        /// Get a value indicating if the content image is being displayed.
        /// </summary>
        /// <param name="context">ViewLayoutContext context.</param>
        public bool IsImageDisplayed(ViewContext context)
        {
            Debug.Assert(context != null);

            // Validate incoming reference
            if (context == null) throw new ArgumentNullException("context");

            bool isDisplayed = false;

            // If we have some content to investigate
            if (_paletteContent.GetContentDraw(State) == InheritBool.True)
                isDisplayed = context.Renderer.RenderStandardContent.GetContentImageDisplayed(_memento);

            return isDisplayed;
        }
示例#8
0
        /// <summary>
        /// Evaluate the need for drawing transparent areas.
        /// </summary>
        /// <param name="context">Evaluation context.</param>
        /// <returns>True if transparent areas exist; otherwise false.</returns>
        public override bool EvalTransparentPaint(ViewContext context)
        {
            Debug.Assert(context != null);

            // Ensure that child elements have correct palette state
            CheckPaletteState(context);

            // Ask the renderer to evaluate the given palette
            return _drawCanvas.EvalTransparentPaint(context);
        }
示例#9
0
        /// <summary>
        /// Check that the palette and state are correct.
        /// </summary>
        /// <param name="context">Reference to the view context.</param>
        protected virtual void CheckPaletteState(ViewContext context)
        {
            // Default to using this element calculated state
            PaletteState buttonState = State;

            // If the actual control is not enabled, force to disabled state
            if (!IsFixed && !context.Control.Enabled)
                buttonState = PaletteState.Disabled;

            // Apply the checked state if not fixed
            if (!IsFixed && Checked)
            {
                // Is the checked button allowed to become unchecked
                if (AllowUncheck)
                {
                    // Show feedback on tracking and presssed
                    switch (buttonState)
                    {
                        case PaletteState.Normal:
                            buttonState = PaletteState.CheckedNormal;
                            break;
                        case PaletteState.Tracking:
                            buttonState = PaletteState.CheckedTracking;
                            break;
                        case PaletteState.Pressed:
                            buttonState = PaletteState.CheckedPressed;
                            break;
                    }
                }
                else
                {
                    // Always use the normal state as user cannot uncheck the button
                    buttonState = PaletteState.CheckedNormal;
                }
            }

            // If the child elements are not in correct state
            if (_forcePaletteUpdate || (_drawCanvas.ElementState != buttonState))
            {
                // No longer need to force the palettes to be updated
                _forcePaletteUpdate = false;

                // Switch the child elements over to correct state
                _drawCanvas.ElementState = buttonState;
                _drawContent.ElementState = buttonState;
                _drawSplitBorder.ElementState = buttonState;
                _drawDropDownButton.ElementState = buttonState;

                // Push the correct palettes into them
                switch (buttonState)
                {
                    case PaletteState.Disabled:
                        _paletteCurrent = _paletteDisabled;
                        break;
                    case PaletteState.Normal:
                        _paletteCurrent = _paletteNormal;
                        break;
                    case PaletteState.CheckedNormal:
                        _paletteCurrent = _paletteCheckedNormal;
                        break;
                    case PaletteState.Pressed:
                        _paletteCurrent = _palettePressed;
                        break;
                    case PaletteState.CheckedPressed:
                        _paletteCurrent = _paletteCheckedPressed;
                        break;
                    case PaletteState.Tracking:
                        _paletteCurrent = _paletteTracking;
                        break;
                    case PaletteState.CheckedTracking:
                        _paletteCurrent = _paletteCheckedTracking;
                        break;
                    default:
                        // Should never happen!
                        Debug.Assert(false);
                        break;
                }

                // Update with the correct palettes
                _drawCanvas.SetPalettes(_paletteCurrent.PaletteBack, _paletteCurrent.PaletteBorder);
                _drawContent.SetPalette(_paletteCurrent.PaletteContent);
                _edgeRedirect.SetPalette(_paletteCurrent.PaletteBorder);
            }
        }
示例#10
0
        /// <summary>
        /// Perform a layout of the view.
        /// </summary>
        /// <param name="renderer">Renderer provider.</param>
        /// <returns>True if it contains transparent painting.</returns>
        public bool EvalTransparentPaint(IRenderer renderer)
        {
            Debug.Assert(renderer != null);
            Debug.Assert(Root != null);

            // Validate incoming reference
            if (renderer == null) throw new ArgumentNullException("renderer");

            // Create a layout context for calculating size and positioning
            using (ViewContext context = new ViewContext(this,
                                                         _control,
                                                         _alignControl,
                                                          renderer))
            {
                // Ask the view to perform operation
                return Root.EvalTransparentPaint(context);
            }
        }
        /// <summary>
        /// Check that the palette and state are correct.
        /// </summary>
        /// <param name="context">Reference to the view context.</param>
        protected override void CheckPaletteState(ViewContext context)
        {
            PaletteState state = ElementState;

            // If the drop down calendar is showing then always draw button as pressed
            if (_dateTimePicker.IsDropped)
                state = PaletteState.Pressed;
            else
            {
                // If the button is in a normal state (not being tracked or pressed)
                if ((ElementState == PaletteState.Normal) ||
                    (ElementState == PaletteState.CheckedNormal))
                {
                    // If the control is active then use the checked normal appearance, otherwise not active and so use the normal appearance
                    if (_dateTimePicker.IsActive || (_dateTimePicker.IsFixedActive && (_dateTimePicker.InputControlStyle == InputControlStyle.Standalone)))
                        state = PaletteState.CheckedNormal;
                    else
                        state = PaletteState.Normal;
                }
            }

            ElementState = state;
            foreach (ViewBase child in this)
                child.ElementState = state;
        }
示例#12
0
        /// <summary>
        /// Evaluate the need for drawing transparent areas.
        /// </summary>
        /// <param name="context">Evaluation context.</param>
        /// <returns>True if transparent areas exist; otherwise false.</returns>
        public override bool EvalTransparentPaint(ViewContext context)
        {
            Debug.Assert(context != null);

            // Check each child in turn for transparent areas
            foreach (ViewBase child in this)
            {
                // Only investigate visible children
                if (child.Visible)
                {
                    // Any child that returns 'true' completes the process
                    if (child.EvalTransparentPaint(context))
                        return true;
                }
            }

            // Nothing found
            return false;
        }
示例#13
0
        /// <summary>
        /// Evaluate the need for drawing transparent areas.
        /// </summary>
        /// <param name="context">Evaluation context.</param>
        /// <returns>True if transparent areas exist; otherwise false.</returns>
        public override bool EvalTransparentPaint(ViewContext context)
        {
            Debug.Assert(context != null);

            // Check with the base canvas first
            if (base.EvalTransparentPaint(context))
                return true;

            // If drawing the other elements over the top of the border
            // then we need to check each element as any of them could
            // have an impact on the transparent drawing.
            if (!DrawBorderLast)
            {
                // Check each child that is docked against an edge
                foreach (ViewBase child in this.Reverse())
                {
                    // Only position visible children
                    if (child.Visible)
                    {
                        switch(GetDock(child))
                        {
                            case ViewDockStyle.Top:
                            case ViewDockStyle.Bottom:
                            case ViewDockStyle.Left:
                            case ViewDockStyle.Right:
                                if (child.EvalTransparentPaint(context))
                                    return true;
                                break;
                        }
                    }
                }
            }

            // Could not find anything that needs transparent painting
            return false;
        }
示例#14
0
        private void CheckPaletteState(ViewContext context)
        {
            // Default to using this element calculated state
            PaletteState buttonState = State;

            // If the actual control is not enabled, force to disabled state
            if (!IsFixed && !context.Control.Enabled)
                buttonState = PaletteState.Disabled;
            else if (buttonState == PaletteState.Disabled)
                buttonState = PaletteState.Normal;

            if (!IsFixed)
            {
                if (Checked)
                {
                    switch (buttonState)
                    {
                        case PaletteState.Normal:
                        case PaletteState.CheckedNormal:
                            buttonState = PaletteState.CheckedNormal;
                            break;
                        case PaletteState.Tracking:
                        case PaletteState.CheckedTracking:
                            buttonState = PaletteState.CheckedTracking;
                            break;
                        case PaletteState.Pressed:
                        case PaletteState.CheckedPressed:
                            buttonState = PaletteState.CheckedPressed;
                            break;
                    }
                }
                else
                {
                    switch (buttonState)
                    {
                        case PaletteState.Normal:
                        case PaletteState.CheckedNormal:
                            buttonState = PaletteState.Normal;
                            break;
                        case PaletteState.Tracking:
                        case PaletteState.CheckedTracking:
                            buttonState = PaletteState.Tracking;
                            break;
                        case PaletteState.Pressed:
                        case PaletteState.CheckedPressed:
                            buttonState = PaletteState.Pressed;
                            break;
                    }
                }
            }

            // Set the correct palette based on state
            switch (buttonState)
            {
                case PaletteState.Disabled:
                    _currentText = Navigator.StateDisabled.RibbonTab.TabDraw;
                    _currentBack = Navigator.StateDisabled.RibbonTab.TabDraw;
                    _currentContent = Navigator.StateDisabled.RibbonTab.Content;
                    break;
                case PaletteState.Normal:
                    _currentText = _overrideStateNormal;
                    _currentBack = _overrideStateNormal;
                    _currentContent = _overrideStateNormal;
                    break;
                case PaletteState.Tracking:
                    _currentText = _overrideStateTracking;
                    _currentBack = _overrideStateTracking;
                    _currentContent = _overrideStateTracking;
                    break;
                case PaletteState.Pressed:
                    _currentText = _overrideStatePressed;
                    _currentBack = _overrideStatePressed;
                    _currentContent = _overrideStatePressed;
                    break;
                case PaletteState.CheckedNormal:
                case PaletteState.CheckedTracking:
                case PaletteState.CheckedPressed:
                    _currentText = _overrideStateSelected;
                    _currentBack = _overrideStateSelected;
                    _currentContent = _overrideStateSelected;
                    break;
                default:
                    // Should never happen!
                    Debug.Assert(false);
                    break;
            }

            // Switch the child elements over to correct state
            ElementState = buttonState;
            this[0][0].ElementState = buttonState;

            // Update content palette with the current ribbon text palette
            _contentProvider.PaletteRibbonText = _currentText;
            _contentProvider.PaletteContent = _currentContent;
        }
示例#15
0
        private void CheckPaletteState(ViewContext context)
        {
            // Should control be enabled or disabled
            bool enabled = IsFixed || context.Control.Enabled;

            // Ensure we and child and in correct enabled state
            Enabled = enabled;

            // Better check we have a child!
            if (Count > 0)
                this[0].Enabled = enabled;

            // If disabled...
            if (!enabled)
            {
                //...must always be using the normal overrides
                _paletteContextCurrent.SetInherit(_overrideStateNormal);
            }
            else
            {
                // Default to using this element calculated state
                PaletteState buttonState = State;

                // Update the checked state
                Checked = (_ribbon.SelectedTab == RibbonTab);

                // Is this tab a context tab?
                bool contextTab = !string.IsNullOrEmpty(RibbonTab.ContextName);

                // Apply the checked state if not fixed
                if (!IsFixed)
                {
                    if (Checked)
                    {
                        switch (buttonState)
                        {
                            case PaletteState.Normal:
                            case PaletteState.CheckedNormal:
                            case PaletteState.ContextCheckedNormal:
                                if (contextTab)
                                    buttonState = PaletteState.ContextCheckedNormal;
                                else
                                    buttonState = PaletteState.CheckedNormal;
                                break;
                            case PaletteState.Tracking:
                            case PaletteState.CheckedTracking:
                            case PaletteState.ContextCheckedTracking:
                                if (contextTab)
                                    buttonState = PaletteState.ContextCheckedTracking;
                                else
                                    buttonState = PaletteState.CheckedTracking;
                                break;
                        }
                    }
                    else
                    {
                        switch (buttonState)
                        {
                            case PaletteState.CheckedNormal:
                            case PaletteState.ContextCheckedNormal:
                                buttonState = PaletteState.Normal;
                                break;
                            case PaletteState.Tracking:
                            case PaletteState.CheckedTracking:
                            case PaletteState.ContextCheckedTracking:
                                if (contextTab)
                                    buttonState = PaletteState.ContextTracking;
                                else
                                    buttonState = PaletteState.Tracking;
                                break;
                        }
                    }
                }

                // Set the correct palette based on state
                switch (buttonState)
                {
                    case PaletteState.Disabled:
                    case PaletteState.Normal:
                        _overrideCurrent = _overrideStateNormal;
                        break;
                    case PaletteState.Tracking:
                        _overrideCurrent = _overrideStateTracking;
                        break;
                    case PaletteState.CheckedNormal:
                        _overrideCurrent = _overrideStateCheckedNormal;
                        break;
                    case PaletteState.CheckedTracking:
                        _overrideCurrent = _overrideStateCheckedTracking;
                        break;
                    case PaletteState.ContextTracking:
                        _overrideCurrent = _overrideStateContextTracking;
                        break;
                    case PaletteState.ContextCheckedNormal:
                        _overrideCurrent = _overrideStateContextCheckedNormal;
                        break;
                    case PaletteState.ContextCheckedTracking:
                        _overrideCurrent = _overrideStateContextCheckedTracking;
                        break;
                    default:
                        // Should never happen!
                        Debug.Assert(false);
                        break;
                }

                // Switch the child elements over to correct state
                ElementState = buttonState;

                // Better check we have a child!
                if (Count > 0)
                    this[0].ElementState = buttonState;

                // Update the actual source palette
                _paletteContextCurrent.SetInherit(_overrideCurrent);
            }
        }
示例#16
0
 /// <summary>
 /// Evaluate the need for drawing transparent areas.
 /// </summary>
 /// <param name="context">Evaluation context.</param>
 /// <returns>True if transparent areas exist; otherwise false.</returns>
 public override bool EvalTransparentPaint(ViewContext context)
 {
     Debug.Assert(context != null);
     return false;
 }