public static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (backgroundImageLayout == ImageLayout.Tile)
     {
         using (TextureBrush brush = new TextureBrush(backgroundImage, WrapMode.Tile))
         {
             if (scrollOffset != Point.Empty)
             {
                 Matrix transform = brush.Transform;
                 transform.Translate((float) scrollOffset.X, (float) scrollOffset.Y);
                 brush.Transform = transform;
             }
             g.FillRectangle(brush, clipRect);
             return;
         }
     }
     Rectangle rect = CalculateBackgroundImageRectangle(bounds, backgroundImage, backgroundImageLayout);
     if ((rightToLeft == RightToLeft.Yes) && (backgroundImageLayout == ImageLayout.None))
     {
         rect.X += clipRect.Width - rect.Width;
     }
     using (SolidBrush brush2 = new SolidBrush(backColor))
     {
         g.FillRectangle(brush2, clipRect);
     }
     if (!clipRect.Contains(rect))
     {
         if ((backgroundImageLayout == ImageLayout.Stretch) || (backgroundImageLayout == ImageLayout.Zoom))
         {
             rect.Intersect(clipRect);
             g.DrawImage(backgroundImage, rect);
         }
         else if (backgroundImageLayout == ImageLayout.None)
         {
             rect.Offset(clipRect.Location);
             Rectangle destRect = rect;
             destRect.Intersect(clipRect);
             Rectangle rectangle3 = new Rectangle(Point.Empty, destRect.Size);
             g.DrawImage(backgroundImage, destRect, rectangle3.X, rectangle3.Y, rectangle3.Width, rectangle3.Height, GraphicsUnit.Pixel);
         }
         else
         {
             Rectangle rectangle4 = rect;
             rectangle4.Intersect(clipRect);
             Rectangle rectangle5 = new Rectangle(new Point(rectangle4.X - rect.X, rectangle4.Y - rect.Y), rectangle4.Size);
             g.DrawImage(backgroundImage, rectangle4, rectangle5.X, rectangle5.Y, rectangle5.Width, rectangle5.Height, GraphicsUnit.Pixel);
         }
     }
     else
     {
         ImageAttributes imageAttr = new ImageAttributes();
         imageAttr.SetWrapMode(WrapMode.TileFlipXY);
         g.DrawImage(backgroundImage, rect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAttr);
         imageAttr.Dispose();
     }
 }
 internal static LayoutOptions CommonLayout(Rectangle clientRectangle, Padding padding, bool isDefault, Font font, string text, bool enabled, ContentAlignment textAlign, RightToLeft rtl)
 {
     return new LayoutOptions { 
         client = LayoutUtils.DeflateRect(clientRectangle, padding), padding = padding, growBorderBy1PxWhenDefault = true, isDefault = isDefault, borderSize = 2, paddingSize = 0, maxFocus = true, focusOddEvenFixup = false, font = font, text = text, imageSize = Size.Empty, checkSize = 0, checkPaddingSize = 0, checkAlign = ContentAlignment.TopLeft, imageAlign = ContentAlignment.MiddleCenter, textAlign = textAlign, 
         hintTextUp = false, shadowedText = !enabled, layoutRTL = RightToLeft.Yes == rtl, textImageRelation = TextImageRelation.Overlay, useCompatibleTextRendering = false
      };
 }
		/// <summary>
		/// </summary>
		public Rectangle GetContentRectangle(
			Rectangle clientRectangle
			, Rectangle arrowRectangle
			, RightToLeft rightToLeft
			)
		{
			Rectangle contentRectangle;

			if (rightToLeft == RightToLeft.Yes)
			{
				contentRectangle = Rectangle.FromLTRB(
					arrowRectangle.Right
					, clientRectangle.Top
					, clientRectangle.Right
					, clientRectangle.Bottom
				);
			}
			else
			{
				contentRectangle = Rectangle.FromLTRB(
					clientRectangle.Left
					, clientRectangle.Top
					, arrowRectangle.Left
					, clientRectangle.Bottom
				);
			}

			return Rectangle.Inflate(contentRectangle, -6, -6);
		}
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new instance of TextEditBase class.
        /// </summary>
        public TextEditBase()
        {
            TextBox = new TextBox();
            Width = 120;
            Height = 20;

            rtl = RightToLeft.Yes;
            base.BackColor = SystemColors.Window;
            TextBox.RightToLeft = rtl;
            TextBox.BorderStyle = BorderStyle.None;
            TextBox.AutoSize = false;

            TextBox.MouseEnter += TextBox_MouseEnter;
            TextBox.MouseLeave += TextBox_MouseLeave;
            TextBox.GotFocus += TextBox_GotFocus;
            TextBox.LostFocus += TextBox_LostFocus;
            TextBox.SizeChanged += TextBox_SizeChanged;
            TextBox.TextChanged += TextBox_TextChanged;
            TextBox.MouseUp += InvokeMouseUp;
            TextBox.MouseDown += InvokeMouseDown;
            TextBox.MouseEnter += InvokeMouseEnter;
            TextBox.MouseHover += InvokeMouseHover;
            TextBox.MouseLeave += InvokeMouseLeave;
            TextBox.MouseMove += InvokeMouseMove;
            TextBox.KeyDown += InvokeKeyDown;
            TextBox.KeyPress += InvokeKeyPress;
            TextBox.KeyUp += InvokeKeyUp;
            TextBox.Click += InvokeClick;
            TextBox.DoubleClick += InvokeDoubleClick;

            ThemeChanged += OnThemeChanged;
            Controls.Add(TextBox);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initialize a new instance of the ViewLayoutViewport class.
        /// </summary>
        /// <param name="paletteMetrics">Palette source for metrics.</param>
        /// <param name="metricPadding">Metric used to get view padding.</param>
        /// <param name="metricOvers">Metric used to get overposition.</param>
        /// <param name="orientation">Orientation for the viewport children.</param>
        /// <param name="alignment">Alignment of the children within the viewport.</param>
        /// <param name="animateChange">Animate changes in the viewport.</param>
        public ViewLayoutViewport(IPaletteMetric paletteMetrics,
                                  PaletteMetricPadding metricPadding,
                                  PaletteMetricInt metricOvers,
                                  VisualOrientation orientation,
                                  RelativePositionAlign alignment,
                                  bool animateChange)
        {
            // Remember the source information
            _paletteMetrics = paletteMetrics;
            _metricPadding = metricPadding;
            _metricOvers = metricOvers;
            _orientation = orientation;
            _alignment = alignment;
            _animateChange = animateChange;

            // Default other state
            _offset = Point.Empty;
            _extent = Size.Empty;
            _rightToLeft = RightToLeft.No;
            _rightToLeftLayout = false;
            _fillSpace = false;
            _counterAlignment = RelativePositionAlign.Far;

            // Create a timer for animation effect
            _animationTimer = new Timer();
            _animationTimer.Interval = _animationInterval;
            _animationTimer.Tick += new EventHandler(OnAnimationTick);
        }
		/*
		 * DropDownButtonBounds
		 */

		/// <summary>
		/// </summary>
		/// <param name="clientRectangle"></param>
		/// <param name="rightToLeft"></param>
		/// <returns></returns>
		public static Rectangle DropDownButtonBounds(Rectangle clientRectangle, RightToLeft rightToLeft)
		{
			Rectangle buttonBounds = Rectangle.Empty;

			if (rightToLeft == RightToLeft.No)
			{
				buttonBounds = new Rectangle(
					clientRectangle.Right - SystemInformation.VerticalScrollBarWidth,
					clientRectangle.Top,
					SystemInformation.VerticalScrollBarWidth,
					clientRectangle.Height
				);
			}
			else
			{
				buttonBounds = new Rectangle(
					clientRectangle.Left,
					clientRectangle.Top,
					SystemInformation.VerticalScrollBarWidth,
					clientRectangle.Height
				);
			}

			return buttonBounds;
		}
		/// <summary>
		/// </summary>
		public Rectangle GetArrowRectangle(Rectangle clientRectangle, RightToLeft rightToLeft)
		{
			Point arrowLocation = new Point(clientRectangle.Left, clientRectangle.Top);
			Size arrowSize = new Size(28, clientRectangle.Height);

			if (rightToLeft == RightToLeft.No)
			{
				arrowLocation.X = clientRectangle.Right - arrowSize.Width;
			}

			return Rectangle.Inflate(new Rectangle(arrowLocation, arrowSize), -3, -6);
		}
Exemplo n.º 8
0
        /// <summary>
        /// Set default values of Language
        /// </summary>
        public Language()
        {
            _langCode = "en";
            _langName = "English";
            _author = "Dương Diệu Pháp";
            _description = "English";
            _minVersion = "3.5.0.0";
            _fileName = "";
            _isRightToLeftLayout = RightToLeft.No;

            _Items = new LanguageItem<string, string>();
            InitDefaultLanguageDictionary();
        }
 internal static ButtonBaseAdapter.LayoutOptions PaintPopupLayout(Graphics g, bool show3D, int checkSize, Rectangle clientRectangle, Padding padding, bool isDefault, Font font, string text, bool enabled, ContentAlignment textAlign, RightToLeft rtl)
 {
     ButtonBaseAdapter.LayoutOptions options = ButtonBaseAdapter.CommonLayout(clientRectangle, padding, isDefault, font, text, enabled, textAlign, rtl);
     options.shadowedText = false;
     if (show3D)
     {
         options.checkSize = (int) ((checkSize * CheckableControlBaseAdapter.GetDpiScaleRatio(g)) + 1f);
         return options;
     }
     options.checkSize = (int) (checkSize * CheckableControlBaseAdapter.GetDpiScaleRatio(g));
     options.checkPaddingSize = 1;
     return options;
 }
		/// <summary>
		/// </summary>
		public Rectangle GetGridPanelBounds(Rectangle clientRectangle, RightToLeft rightToLeft)
		{
			if (rightToLeft == RightToLeft.Yes)
			{
				return new Rectangle(
					clientRectangle.Left
					, clientRectangle.Top + 1
					, clientRectangle.Width - 1
					, clientRectangle.Height - 1
				);
			}

			return new Rectangle(
				clientRectangle.Left + 1
				, clientRectangle.Top + 1
				, clientRectangle.Width - 1
				, clientRectangle.Height - 1
			);
		}
        /// <summary>
        /// Perform a layout of the elements.
        /// </summary>
        /// <param name="context">Layout context.</param>
        public override void Layout(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Validate incoming reference
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Cache the right to left setting at layout time
            _rightToLeft       = context.Control.RightToLeft;
            _rightToLeftLayout = CommonHelper.GetRightToLeftLayout(context.Control);

            // We take on all the available display area
            ClientRectangle = context.DisplayRectangle;

            // Available space for positioning starts with entire client area
            Rectangle positionRectangle = ClientRectangle;

            // Do we have a metric source for additional padding?
            if (_paletteMetrics != null)
            {
                // Get the padding to be applied
                Padding outerPadding = _paletteMetrics.GetMetricPadding(State, _metricPadding);

                // Reduce space for children by the padding area
                positionRectangle = ApplyPadding(positionRectangle, outerPadding);
            }

            // Do we need to fill any remainder space?
            if (FillSpace)
            {
                // Ensure the extent reflects the maximum size we want, the whole area
                if (_extent.Width < positionRectangle.Width)
                {
                    _extent.Width = positionRectangle.Width;
                }

                if (_extent.Height < positionRectangle.Height)
                {
                    _extent.Height = positionRectangle.Height;
                }
            }

            // Find the limits allowed for the offset given current extent and display rect
            _limit = new Point(Math.Min(positionRectangle.Width - _extent.Width, 0),
                               Math.Min(positionRectangle.Height - _extent.Height, 0));

            // Enforce the offset back to the limits
            if (_offset.X < _limit.X)
            {
                _offset.X = _limit.X;
            }

            if (_offset.Y < _limit.Y)
            {
                _offset.Y = _limit.Y;
            }

            // Calculate the offset given the current alignment and counter alignment
            int childOffsetX;
            int childOffsetY;

            // Find the final child offset
            if (Horizontal)
            {
                childOffsetX = CalculateAlignedOffset(AlignmentRTL, positionRectangle.X, positionRectangle.Width, _offset.X, _extent.Width, _limit.X);
                childOffsetY = CalculateAlignedOffset(CounterAlignmentRTL, positionRectangle.Y, positionRectangle.Height, _offset.Y, _extent.Height, _limit.Y);
            }
            else
            {
                childOffsetX = CalculateAlignedOffset(CounterAlignmentRTL, positionRectangle.X, positionRectangle.Width, _offset.X, _extent.Width, _limit.X);
                childOffsetY = CalculateAlignedOffset(AlignmentRTL, positionRectangle.Y, positionRectangle.Height, _offset.Y, _extent.Height, _limit.Y);
            }

            Point childOffset = new Point(childOffsetX, childOffsetY);

            // Ask each child to layout in turn
            foreach (ViewBase child in this)
            {
                // Only layout visible children
                if (child.Visible)
                {
                    // Give the child the available positioning size
                    context.DisplayRectangle = positionRectangle;

                    // Ask the child how much space they would like
                    Size childSize = child.GetPreferredSize(context);

                    // Do we need to fill any remainder space?
                    if (FillSpace)
                    {
                        // Ensure the child reflect the size we want, the whole area
                        if (childSize.Width < positionRectangle.Width)
                        {
                            childSize.Width = positionRectangle.Width;
                        }

                        if (childSize.Height < positionRectangle.Height)
                        {
                            childSize.Height = positionRectangle.Height;
                        }
                    }

                    // Give the child all the space it requires
                    context.DisplayRectangle = new Rectangle(childOffset, childSize);

                    // Let the child layout using the provided space
                    child.Layout(context);
                }
            }

            // Put back the original display value now we have finished
            context.DisplayRectangle = ClientRectangle;
        }
        public void VScrollBarLastLineButtonAccessibleObject_FragmentNavigate_ReturnsExpected_LastPageButtonIsHidden(RightToLeft rightToLeft, int minimum, int maximum, int value)
        {
            using VScrollBar scrollBar = GetVScrollBar(createControl: true, rightToLeft, minimum, maximum, value);
            var scrollBarAccessibleObject = (ScrollBar.ScrollBarAccessibleObject)scrollBar.AccessibilityObject;
            ScrollBarLastLineButtonAccessibleObject accessibleObject = GetLastLineButton(scrollBar);

            Assert.Equal(scrollBarAccessibleObject, accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.Parent));
            Assert.Equal(scrollBarAccessibleObject.ThumbAccessibleObject, accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.PreviousSibling));
            Assert.Null(accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.NextSibling));
            Assert.Null(accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.FirstChild));
            Assert.Null(accessibleObject.FragmentNavigate(UiaCore.NavigateDirection.LastChild));
            Assert.True(scrollBar.IsHandleCreated);
        }
        public void VScrollBarLastLineButtonAccessibleObject_InvokePattern_Supported(bool createControl, RightToLeft rightToLeft, int minimum, int maximum, int value)
        {
            using VScrollBar scrollBar = GetVScrollBar(createControl, rightToLeft, minimum, maximum, value);
            ScrollBarLastLineButtonAccessibleObject accessibleObject = GetLastLineButton(scrollBar);

            Assert.Equal(createControl, accessibleObject.IsPatternSupported(UiaCore.UIA.InvokePatternId));
            Assert.Equal(createControl, scrollBar.IsHandleCreated);
        }
Exemplo n.º 14
0
      /// <summary>
      ///  Constructeur
      /// </summary>
      /// <param name="comboBox">référence sur la combo à peindre</param>
      /// <param name="smallButton">si true, dessiner un petit bouton pour le drop-down</param>
      public FlatComboAdapter( ComboBox comboBox, bool smallButton ) {
        this.comboBox = comboBox;

        clientRect = comboBox.ClientRectangle;
        origRightToLeft = comboBox.RightToLeft;

        int dropDownButtonWidth = System.Windows.Forms.SystemInformation.HorizontalScrollBarArrowWidth;
        outerBorder = new Rectangle( clientRect.Location, new Size( clientRect.Width - 1, clientRect.Height - 1 ) );
        innerBorder = new Rectangle( outerBorder.X + 1, outerBorder.Y + 1, outerBorder.Width - dropDownButtonWidth - 2, outerBorder.Height - 2 );
        innerInnerBorder = new Rectangle( innerBorder.X + 1, innerBorder.Y + 1, innerBorder.Width - 2, innerBorder.Height - 2 );
        dropDownRect = new Rectangle( innerBorder.Right + 1, innerBorder.Y, dropDownButtonWidth, innerBorder.Height + 1 );

        // fill in several pixels of the dropdown rect with white so that it looks like the combo button is thinner.
        if ( smallButton ) {
          whiteFillRect = dropDownRect;
          whiteFillRect.Width = WhiteFillRectWidth;
          dropDownRect.X += WhiteFillRectWidth;
          dropDownRect.Width -= WhiteFillRectWidth;
        }

        if ( origRightToLeft == RightToLeft.Yes ) {
          innerBorder.X = clientRect.Width - innerBorder.Right;
          innerInnerBorder.X = clientRect.Width - innerInnerBorder.Right;
          dropDownRect.X = clientRect.Width - dropDownRect.Right;
          whiteFillRect.X = clientRect.Width - whiteFillRect.Right + 1;  // since we're filling, we need to move over to the next px.
        }
      }
Exemplo n.º 15
0
        public void HScrollBarFirstLineButtonAccessibleObject_Description_ReturnNull_HandleIsCreated(RightToLeft rightToLeft, int minimum, int maximum, int value)
        {
            using HScrollBar scrollBar = GetHScrollBar(createControl: true, rightToLeft, minimum, maximum, value);
            ScrollBarFirstLineButtonAccessibleObject accessibleObject = GetFirstLineButton(scrollBar);

            Assert.NotNull(accessibleObject.Description);
            Assert.True(scrollBar.IsHandleCreated);
        }
Exemplo n.º 16
0
        public void TrackBarFirstButtonAccessibleObject_Invoke_DoesNotWork_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum);
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);

            Assert.Equal(value, trackBar.Value);

            accessibleObject.Invoke();

            Assert.Equal(value, trackBar.Value);
            Assert.False(trackBar.IsHandleCreated);
        }
Exemplo n.º 17
0
        public void TrackBarFirstButtonAccessibleObject_InvokePattern_DoesNotSupport(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum);
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);

            Assert.True(accessibleObject.IsPatternSupported(Interop.UiaCore.UIA.InvokePatternId));
            Assert.Equal(createControl, trackBar.IsHandleCreated);
        }
Exemplo n.º 18
0
        public void TrackBarFirstButtonAccessibleObject_FragmentNavigate_ReturnsNull_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum);
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);

            Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent));
            Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling));
            Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling));
            Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild));
            Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild));
            Assert.False(trackBar.IsHandleCreated);
        }
Exemplo n.º 19
0
        public void TrackBarFirstButtonAccessibleObject_Invoke_Decrease_WorkCorrectly(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value: 5, 0, 10);
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);

            Assert.Equal(5, trackBar.Value);

            accessibleObject.Invoke();

            Assert.Equal(2, trackBar.Value);

            accessibleObject.Invoke();

            Assert.Equal(0, trackBar.Value);

            accessibleObject.Invoke();

            Assert.Equal(0, trackBar.Value);
            Assert.True(trackBar.IsHandleCreated);
        }
Exemplo n.º 20
0
        public void TrackBarFirstButtonAccessibleObject_FragmentNavigate_ReturnsExpected_IfFirstButtonIsDisplayed(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum);
            var trackBarAccessibleObject = (TrackBar.TrackBarAccessibleObject)trackBar.AccessibilityObject;

            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = trackBarAccessibleObject.FirstButtonAccessibleObject;

            Assert.Equal(trackBarAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.Parent));
            Assert.Equal(trackBarAccessibleObject.ThumbAccessibleObject, accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling));
            Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.PreviousSibling));
            Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild));
            Assert.Null(accessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.LastChild));
            Assert.True(trackBar.IsHandleCreated);
        }
Exemplo n.º 21
0
        public void TrackBarFirstButtonAccessibleObject_State_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum);
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);
            AccessibleStates expectedState = accessibleObject.IsDisplayed || !trackBar.IsHandleCreated
                                             ? AccessibleStates.None
                                             : AccessibleStates.Invisible;

            Assert.Equal(expectedState, accessibleObject.State);
            Assert.Equal(createControl, trackBar.IsHandleCreated);
        }
Exemplo n.º 22
0
        public void TrackBarFirstButtonAccessibleObject_Role_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum);
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);
            AccessibleRole accessibleRole = createControl ? AccessibleRole.PushButton : AccessibleRole.None;

            Assert.Equal(accessibleRole, accessibleObject.Role);
            Assert.Equal(createControl, trackBar.IsHandleCreated);
        }
Exemplo n.º 23
0
 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");
     }
 }
Exemplo n.º 24
0
        public void TrackBarFirstButtonAccessibleObject_GetPropertyValue_IsEnabledProperty_ReturnsFalse_OwnerDisabled(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum);
            trackBar.Enabled        = false;
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);

            Assert.False((bool)accessibleObject.GetPropertyValue(UiaCore.UIA.IsEnabledPropertyId));
            Assert.Equal(createControl, trackBar.IsHandleCreated);
        }
Exemplo n.º 25
0
             public FlatComboAdapter(ComboBox comboBox, bool smallButton) {

                 if (!isScalingInitialized) {
                     if (DpiHelper.IsScalingRequired) {
                         Offset2X = DpiHelper.LogicalToDeviceUnitsX(OFFSET_2PIXELS);
                         Offset2Y = DpiHelper.LogicalToDeviceUnitsY(OFFSET_2PIXELS);
                     }
                     isScalingInitialized = true;
                 }

                 clientRect = comboBox.ClientRectangle;
                 int dropDownButtonWidth = System.Windows.Forms.SystemInformation.HorizontalScrollBarArrowWidth;
                 outerBorder = new Rectangle(clientRect.Location, new Size(clientRect.Width - 1, clientRect.Height - 1));
                 innerBorder = new Rectangle(outerBorder.X + 1, outerBorder.Y + 1, outerBorder.Width - dropDownButtonWidth - 2, outerBorder.Height - 2);
                 innerInnerBorder = new Rectangle(innerBorder.X + 1, innerBorder.Y + 1, innerBorder.Width - 2, innerBorder.Height - 2);
                 dropDownRect = new Rectangle(innerBorder.Right + 1, innerBorder.Y, dropDownButtonWidth, innerBorder.Height+1);
 
 
                 // fill in several pixels of the dropdown rect with white so that it looks like the combo button is thinner.
                 if (smallButton) {
                      whiteFillRect = dropDownRect;
                      whiteFillRect.Width = WhiteFillRectWidth;
                      dropDownRect.X += WhiteFillRectWidth;
                      dropDownRect.Width -= WhiteFillRectWidth;
                 }

                 origRightToLeft = comboBox.RightToLeft;
                                     
 
                  if (origRightToLeft == RightToLeft.Yes) {
                      innerBorder.X =      clientRect.Width - innerBorder.Right;
                      innerInnerBorder.X = clientRect.Width - innerInnerBorder.Right;
                      dropDownRect.X =     clientRect.Width - dropDownRect.Right;
                      whiteFillRect.X  =   clientRect.Width - whiteFillRect.Right + 1;  // since we're filling, we need to move over to the next px.
                  }                     
 
             }
Exemplo n.º 26
0
        public void TrackBarFirstButtonAccessibleObject_Bounds_ReturnsEmptyRectangle_IfHandleIsNotCreated(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: false, value, minimum, maximum);
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);

            Assert.Equal(Rectangle.Empty, accessibleObject.Bounds);
            Assert.False(trackBar.IsHandleCreated);
        }
Exemplo n.º 27
0
     private ToolStripDropDownDirection RTLTranslateDropDownDirection(ToolStripDropDownDirection dropDownDirection, RightToLeft rightToLeft) {
         switch (dropDownDirection) {
             case ToolStripDropDownDirection.AboveLeft:
                  return ToolStripDropDownDirection.AboveRight;
              case ToolStripDropDownDirection.AboveRight:
                  return ToolStripDropDownDirection.AboveLeft;
              case ToolStripDropDownDirection.BelowRight:
                  return ToolStripDropDownDirection.BelowLeft;
              case ToolStripDropDownDirection.BelowLeft:
                  return ToolStripDropDownDirection.BelowRight;
              case ToolStripDropDownDirection.Right:
                  return ToolStripDropDownDirection.Left;
              case ToolStripDropDownDirection.Left:
                  return ToolStripDropDownDirection.Right;
           }
           Debug.Fail("Why are we here");
           
           // dont expect it to come to this but just in case here are the real defaults.
           if (IsOnDropDown) {
                return (rightToLeft == RightToLeft.Yes) ? ToolStripDropDownDirection.Left : ToolStripDropDownDirection.Right;
           }
           else {
               return (rightToLeft == RightToLeft.Yes) ? ToolStripDropDownDirection.BelowLeft : ToolStripDropDownDirection.BelowRight;
           }
 
 
     }
Exemplo n.º 28
0
        public void TrackBarFirstButtonAccessibleObject_IsDisplayed_ReturnsFalse_OwnerInvisible(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl: true, value, minimum, maximum);
            trackBar.Visible        = false;
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);

            Assert.False(accessibleObject.IsDisplayed);
            Assert.True(trackBar.IsHandleCreated);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Draws the text and image objects at the specified location. 
        /// </summary>
        /// <param name="graphics">The Graphics to draw on.</param>
        /// <param name="captionRectangle">The drawing rectangle on a panel's caption.</param>
        /// <param name="iSpacing">The spacing on a panel's caption</param>
        /// <param name="imageRectangle">The rectangle of an image displayed on a panel's caption.</param>
        /// <param name="image">The image that is displayed on a panel's caption.</param>
        /// <param name="rightToLeft">A value indicating whether control's elements are aligned to support locales using right-to-left fonts.</param>
        /// <param name="bDrawBackground">A value indicating whether the background of the images is displayed</param>
        /// <param name="bIsClosable">A value indicating whether the xpanderpanel is closable</param>
        /// <param name="bShowCloseIcon">A value indicating whether the close image is displayed</param>
        /// <param name="imageClosePanel">The close image that is displayed on a panel's caption.</param>
        /// <param name="foreColorCloseIcon">The foreground color of the close image that is displayed on a panel's caption.</param>
        /// <param name="rectangleImageClosePanel">The rectangle of the close image that is displayed on a panel's caption.</param>
        /// <param name="bShowExpandIcon">A value indicating whether the expand image is displayed</param>
        /// <param name="imageExandPanel">The expand image that is displayed on a panel's caption.</param>
        /// <param name="foreColorExpandIcon">The foreground color of the expand image displayed by this caption.</param>
        /// <param name="rectangleImageExandPanel">the rectangle of the expand image displayed by this caption.</param>
        /// <param name="fontCaption">The font of the text displayed on a panel's caption.</param>
        /// <param name="captionForeColor">The foreground color of the text displayed on a panel's caption.</param>
        /// <param name="strCaptionText">The text which is associated with this caption.</param>
        protected static void DrawImagesAndText(
            Graphics graphics,
            Rectangle captionRectangle,
            int iSpacing,
            Rectangle imageRectangle,
            Image image,
            RightToLeft rightToLeft,
            bool bDrawBackground,
            bool bIsClosable,
            bool bShowCloseIcon,
            Image imageClosePanel,
            Color foreColorCloseIcon,
            ref Rectangle rectangleImageClosePanel,
            bool bShowExpandIcon,
            Image imageExandPanel,
            Color foreColorExpandIcon,
            ref Rectangle rectangleImageExandPanel,
            Font fontCaption,
            Color captionForeColor,
            string strCaptionText)
        {
            //DrawImages
            int iTextPositionX1 = iSpacing;
            int iTextPositionX2 = captionRectangle.Right - iSpacing;

            imageRectangle.Y = (captionRectangle.Height - imageRectangle.Height) / 2;

            if (rightToLeft == RightToLeft.No)
            {
                if (image != null)
                {
                    DrawImage(graphics, image, imageRectangle);
                    iTextPositionX1 += imageRectangle.Width + iSpacing;
                    iTextPositionX2 -= iTextPositionX1;
                }
            }
            else
            {
                if ((bShowCloseIcon == true) && (imageClosePanel != null))
                {
                    rectangleImageClosePanel = imageRectangle;
                    rectangleImageClosePanel.X = imageRectangle.X;
                    if (bIsClosable == true)
                    {
                        DrawChevron(graphics, imageClosePanel, rectangleImageClosePanel, foreColorCloseIcon, bDrawBackground, imageRectangle.Y);
                    }
                    iTextPositionX1 = rectangleImageClosePanel.X + rectangleImageClosePanel.Width;
                }
                if ((bShowExpandIcon == true) && (imageExandPanel != null))
                {
                    rectangleImageExandPanel = imageRectangle;
                    rectangleImageExandPanel.X = imageRectangle.X;
                    if ((bShowCloseIcon == true) && (imageClosePanel != null))
                    {
                        rectangleImageExandPanel.X = iTextPositionX1 + (iSpacing / 2);
                    }
                    DrawChevron(graphics, imageExandPanel, rectangleImageExandPanel, foreColorExpandIcon, bDrawBackground, imageRectangle.Y);
                    iTextPositionX1 = rectangleImageExandPanel.X + rectangleImageExandPanel.Width;
                }
            }
            //
            // Draw Caption text
            //
            Rectangle textRectangle = captionRectangle;
            textRectangle.X = iTextPositionX1;
            textRectangle.Width -= iTextPositionX1 + iSpacing;
            if (rightToLeft == RightToLeft.No)
            {
                if ((bShowCloseIcon == true) && (imageClosePanel != null))
                {
                    rectangleImageClosePanel = imageRectangle;
                    rectangleImageClosePanel.X = captionRectangle.Right - iSpacing - imageRectangle.Width;
                    if (bIsClosable == true)
                    {
                        DrawChevron(graphics, imageClosePanel, rectangleImageClosePanel, foreColorCloseIcon, bDrawBackground, imageRectangle.Y);
                    }
                    iTextPositionX2 = rectangleImageClosePanel.X;
                }
                if ((bShowExpandIcon == true) && (imageExandPanel != null))
                {
                    rectangleImageExandPanel = imageRectangle;
                    rectangleImageExandPanel.X = captionRectangle.Right - iSpacing - imageRectangle.Width;
                    if ((bShowCloseIcon == true) && (imageClosePanel != null))
                    {
                        rectangleImageExandPanel.X = iTextPositionX2 - (iSpacing / 2) - imageRectangle.Width;
                    }
                    DrawChevron(graphics, imageExandPanel, rectangleImageExandPanel, foreColorExpandIcon, bDrawBackground, imageRectangle.Y);
                    iTextPositionX2 = rectangleImageExandPanel.X;
                }
                if ((bShowCloseIcon == true)
                    && (imageClosePanel != null)
                    && (bShowExpandIcon == true)
                    && (imageExandPanel != null))
                {
                    iTextPositionX2 -= iSpacing;
                }
            }
            else
            {
                if (image != null)
                {
                    Rectangle imageRectangleRight = imageRectangle;
                    imageRectangleRight.X = iTextPositionX2 - imageRectangle.Width;
                    DrawImage(graphics, image, imageRectangleRight);
                    iTextPositionX2 = imageRectangleRight.X - iSpacing;
                }
            }
            textRectangle.Width = iTextPositionX2 - iTextPositionX1;
            DrawString(graphics, textRectangle, fontCaption, captionForeColor, strCaptionText, rightToLeft, StringAlignment.Near);
        }
Exemplo n.º 30
0
        public void HScrollBarFirstLineButtonAccessibleObject_Name_ReturnNull_HandleIsNotCreated(RightToLeft rightToLeft, int minimum, int maximum, int value)
        {
            using HScrollBar scrollBar = GetHScrollBar(createControl: false, rightToLeft, minimum, maximum, value);
            ScrollBarFirstLineButtonAccessibleObject accessibleObject = GetFirstLineButton(scrollBar);

            Assert.Null(accessibleObject.Name);
            Assert.False(scrollBar.IsHandleCreated);
        }
        public void VScrollBarLastLineButtonAccessibleObject_Role_ReturnNone_HandleIsNotCreated(RightToLeft rightToLeft, int minimum, int maximum, int value)
        {
            using VScrollBar scrollBar = GetVScrollBar(createControl: false, rightToLeft, minimum, maximum, value);
            ScrollBarLastLineButtonAccessibleObject accessibleObject = GetLastLineButton(scrollBar);

            Assert.Equal(AccessibleRole.None, accessibleObject.Role);
            Assert.False(scrollBar.IsHandleCreated);
        }
Exemplo n.º 32
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);
            }
        }
        public void VScrollBarLastLineButtonAccessibleObject_GetChild_ReturnNull(bool createControl, RightToLeft rightToLeft, int minimum, int maximum, int value)
        {
            using VScrollBar scrollBar = GetVScrollBar(createControl, rightToLeft, minimum, maximum, value);
            ScrollBarLastLineButtonAccessibleObject accessibleObject = GetLastLineButton(scrollBar);

            Assert.Null(accessibleObject.GetChild(-1));
            Assert.Null(accessibleObject.GetChild(0));
            Assert.Null(accessibleObject.GetChild(1));
            Assert.Equal(createControl, scrollBar.IsHandleCreated);
        }
Exemplo n.º 34
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;
                }
            }
        }
Exemplo n.º 35
0
        public void HScrollBarFirstLineButtonAccessibleObject_IsDisplayed_ReturnsFalse_OwnerInvisible(bool createControl, RightToLeft rightToLeft, int minimum, int maximum, int value)
        {
            using HScrollBar scrollBar = GetHScrollBar(createControl, rightToLeft, minimum, maximum, value);
            scrollBar.Visible          = false;
            ScrollBarFirstLineButtonAccessibleObject accessibleObject = GetFirstLineButton(scrollBar);

            Assert.False(accessibleObject.IsDisplayed);
            Assert.Equal(createControl, scrollBar.IsHandleCreated);
        }
Exemplo n.º 36
0
        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);
        }
Exemplo n.º 37
0
        public void TrackBarFirstButtonAccessibleObject_DefaultAction_ReturnActionPress(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum);
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);

            Assert.Equal(SR.AccessibleActionPress, accessibleObject.DefaultAction);
            Assert.Equal(createControl, trackBar.IsHandleCreated);
        }
Exemplo n.º 38
0
        [SuppressMessage("Microsoft.Performance", "CA1801:AvoidUnusedParameters")]  // removed graphics, may have to put it back
        internal static LayoutOptions PaintPopupLayout(Graphics g, bool show3D, int checkSize, Rectangle clientRectangle, Padding padding,
                                                       bool isDefault, Font font, string text, bool enabled, ContentAlignment textAlign, RightToLeft rtl,
                                                       Control control = null)
        {
            LayoutOptions layout = CommonLayout(clientRectangle, padding, isDefault, font, text, enabled, textAlign, rtl);

            layout.shadowedText = false;
            if (show3D)
            {
                layout.checkSize = (int)(checkSize * GetDpiScaleRatio(g, control) + 1);
            }
            else
            {
                layout.checkSize        = (int)(checkSize * GetDpiScaleRatio(g, control));
                layout.checkPaddingSize = 1;
            }
            return(layout);
        }
Exemplo n.º 39
0
        /// <summary>
        /// Pixel accurate drawing of the requested text memento information.
        /// </summary>
        /// <param name="g">Graphics object used for drawing.</param>
        /// <param name="brush">Brush for drawing text with.</param>
        /// <param name="rect">Rectangle to draw text inside.</param>
        /// <param name="rtl">Right to left setting for control.</param>
        /// <param name="orientation">Orientation for drawing text.</param>
        /// <param name="memento">Memento containing text context.</param>
        /// <param name="state">State of the source element.</param>
        /// <param name="composition">Should draw on a composition element.</param>
        /// <returns>True if draw succeeded; False is draw produced an error.</returns>
        public static bool DrawString(Graphics g,
                                      Brush brush,
                                      Rectangle rect,
                                      RightToLeft rtl,
                                      VisualOrientation orientation,
                                      bool composition,
                                      PaletteState state,
                                      AccurateTextMemento memento)
        {
            Debug.Assert(g != null);
            Debug.Assert(memento != null);

            // Cannot draw with a null graphics instance
            if (g == null)
                throw new ArgumentNullException("g");

            // Cannot draw with a null memento instance
            if (memento == null)
                throw new ArgumentNullException("memento");

            bool ret = true;

            // Is there a valid place to be drawn into
            if ((rect.Width > 0) && (rect.Height > 0))
            {
                // Does the memento contain something to draw?
                if (!memento.IsEmpty)
                {
                    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 = rect.X * 2 + rect.Width;
                            translateY = rect.Y * 2 + rect.Height;
                            rotation = 180f;
                            break;
                        case VisualOrientation.Left:
                            // Invert the dimensions of the rectangle for drawing upwards
                            rect = new Rectangle(rect.X, rect.Y, rect.Height, rect.Width);

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

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

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

                    if (rotation != 0f)
                        g.RotateTransform(rotation);

                    try
                    {
                        if (composition)
                            DrawCompositionGlowingText(g, memento.Text, memento.Font, rect, state,
                                                       SystemColors.ActiveCaptionText, true);
                        else
                            g.DrawString(memento.Text, memento.Font, brush, rect, memento.Format);
                    }
                    catch
                    {
                        // Ignore any error from the DrawString, usually because the display settings
                        // have changed causing Fonts to be invalid. Our controls will notice the change
                        // and refresh the fonts but sometimes the draw happens before the fonts are
                        // regenerated. Just ignore message and everything will sort itself out. Trust me!
                        ret = false;
                    }
                    finally
                    {
                        // Remove the applied transforms
                        if (rotation != 0f)
                            g.RotateTransform(-rotation);

                        if ((translateX != 0) || (translateY != 0))
                            g.TranslateTransform(-translateX, -translateY);
                    }
                }
            }

            return ret;
        }
Exemplo n.º 40
0
        public void TrackBarFirstButtonAccessibleObject_Help_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum);
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);

            Assert.Null(accessibleObject.Help);
            Assert.Equal(createControl, trackBar.IsHandleCreated);
        }
Exemplo n.º 41
0
        private static void AllocateImageSpace(StandardContentMemento memento,
                                               IPaletteContent paletteContent,
                                               IContentValues contentValues,
                                               PaletteState state,
                                               Rectangle displayRect,
                                               RightToLeft rtl,
                                               ref Size[,] allocation)
        {
            // By default, we cannot draw the image
            memento.DrawImage = false;

            // Get the image details
            memento.Image = contentValues.GetImage(state);
            memento.ImageTransparentColor = contentValues.GetImageTransparentColor(state);

            // Is there any image to be drawn?
            if (memento.Image != null)
            {
                try
                {
                    // Cache the size of the image
                    memento.ImageRect.Size = memento.Image.Size;

                    // Check for enough space to show all of the image
                    if ((displayRect.Width >= memento.ImageRect.Width) &&
                        (displayRect.Height >= memento.ImageRect.Height))
                    {
                        // Convert from alignment enums to integers
                        int alignHIndex = RightToLeftIndex(rtl, paletteContent.GetContentImageH(state));
                        int alignVIndex = (int)paletteContent.GetContentImageV(state);

                        // Bump the allocated space in the destination grid cell
                        allocation[alignHIndex, alignVIndex].Width += memento.ImageRect.Width;
                        allocation[alignHIndex, alignVIndex].Height += memento.ImageRect.Height;

                        // Yes, we do want to draw the image/icon
                        memento.DrawImage = true;
                    }
                }
                catch
                {
                    // Image is not valid, so do not use it!
                    memento.Image = null;
                    memento.DrawImage = false;
                }
            }
        }
Exemplo n.º 42
0
        public void TrackBarFirstButtonAccessibleObject_Name_ReturnDescreaseName(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum);
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);

            Assert.Equal(SR.TrackBarLargeDecreaseButtonName, accessibleObject.Name);
            Assert.Equal(createControl, trackBar.IsHandleCreated);
        }
Exemplo n.º 43
0
        private static GraphicsPath CreateTabBorderBackPath(RightToLeft rtl,
                                                            PaletteState state,
                                                            bool forBorder,
                                                            Rectangle rect,
                                                            int borderWidth,
                                                            TabBorderStyle tabBorderStyle,
                                                            VisualOrientation orientation,
                                                            bool smoothing)
        {
            GraphicsPath borderPath = new GraphicsPath();

            // A zero size rectangle cannot be drawn, so return a null path
            if ((rect.Width > 0) && (rect.Height > 0))
            {
                // Shrink the rect by half the width of the pen, because the pen will
                // draw half the distance overlapping each side of the centre anyway.
                int halfBorderWidth = borderWidth / 2;

                // Adjust rectangle for all except the bottom edges
                rect.Width -= (halfBorderWidth * 2);
                rect.Height -= halfBorderWidth;
                rect.X += halfBorderWidth;
                rect.Y += halfBorderWidth;

                // Populate the graphics path for the border style
                CreateTabBorderPath((rtl == RightToLeft.Yes), state, forBorder,
                                    borderPath, rect, tabBorderStyle, orientation);
            }

            return borderPath;
        }
Exemplo n.º 44
0
        /// <summary>
        /// Pixel accurate drawing of the requested text memento information.
        /// </summary>
        /// <param name="g">Graphics object used for drawing.</param>
        /// <param name="brush">Brush for drawing text with.</param>
        /// <param name="rect">Rectangle to draw text inside.</param>
        /// <param name="rtl">Right to left setting for control.</param>
        /// <param name="orientation">Orientation for drawing text.</param>
        /// <param name="memento">Memento containing text context.</param>
        /// <param name="state">State of the source element.</param>
        /// <param name="composition">Should draw on a composition element.</param>
        /// <param name="glowing">When on composition draw with glowing.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns>True if draw succeeded; False is draw produced an error.</returns>
        public static bool DrawString(Graphics g,
                                      Brush brush,
                                      Rectangle rect,
                                      RightToLeft rtl,
                                      VisualOrientation orientation,
                                      bool composition,
                                      bool glowing,
                                      PaletteState state,
                                      AccurateTextMemento memento)
        {
            Debug.Assert(g != null);
            Debug.Assert(memento != null);

            // Cannot draw with a null graphics instance
            if (g == null)
            {
                throw new ArgumentNullException(nameof(g));
            }

            // Cannot draw with a null memento instance
            if (memento == null)
            {
                throw new ArgumentNullException(nameof(memento));
            }

            bool ret = true;

            // Is there a valid place to be drawn into
            if ((rect.Width > 0) && (rect.Height > 0))
            {
                // Does the memento contain something to draw?
                if (!memento.IsEmpty)
                {
                    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 = (rect.X * 2) + rect.Width;
                        translateY = (rect.Y * 2) + rect.Height;
                        rotation   = 180f;
                        break;

                    case VisualOrientation.Left:
                        // Invert the dimensions of the rectangle for drawing upwards
                        rect = new Rectangle(rect.X, rect.Y, rect.Height, rect.Width);

                        // Translate back from a quarter left turn to the original place
                        translateX = rect.X - rect.Y - 1;
                        translateY = rect.X + rect.Y + rect.Width;
                        rotation   = 270;
                        break;

                    case VisualOrientation.Right:
                        // Invert the dimensions of the rectangle for drawing upwards
                        rect = new Rectangle(rect.X, rect.Y, rect.Height, rect.Width);

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

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

                    if (rotation != 0f)
                    {
                        g.RotateTransform(rotation);
                    }

                    try
                    {
                        if (Application.RenderWithVisualStyles && composition && glowing)
                        {
                            //DrawCompositionGlowingText(g, memento.Text, memento.Font, rect, state,
                            //                           SystemColors.ActiveCaptionText, true);
                            if (Environment.OSVersion.Version.Major >= 10 &&
                                Environment.OSVersion.Version.Build >= 10586)
                            {
                                DrawCompositionGlowingText(g, memento.Text, memento.Font, rect, state,
                                                           (state == PaletteState.Disabled)
                                        ? Color.FromArgb(170, 170, 170)
                                        : ContrastColor(AccentColorService.GetColorByTypeName("ImmersiveSystemAccent")),
                                                           true);
                            }
                            else
                            {
                                DrawCompositionGlowingText(g, memento.Text, memento.Font, rect, state,
                                                           SystemColors.ActiveCaptionText, true);
                            }
                        }
                        else if (Application.RenderWithVisualStyles && composition)
                        {
                            //Check if correct in all cases
                            SolidBrush tmpBrush = brush as SolidBrush;
                            Color      tmpColor = tmpBrush?.Color ?? SystemColors.ActiveCaptionText;

                            DrawCompositionText(g, memento.Text, memento.Font, rect, state,
                                                tmpColor, true, memento.Format);
                        }
                        else
                        {
                            g.DrawString(memento.Text, memento.Font, brush, rect, memento.Format);
                        }
                    }
                    catch
                    {
                        // Ignore any error from the DrawString, usually because the display settings
                        // have changed causing Fonts to be invalid. Our controls will notice the change
                        // and refresh the fonts but sometimes the draw happens before the fonts are
                        // regenerated. Just ignore message and everything will sort itself out. Trust me!
                        ret = false;
                    }
                    finally
                    {
                        // Remove the applied transforms
                        if (rotation != 0f)
                        {
                            g.RotateTransform(-rotation);
                        }

                        if ((translateX != 0) || (translateY != 0))
                        {
                            g.TranslateTransform(-translateX, -translateY);
                        }
                    }
                }
            }

            return(ret);
        }
Exemplo n.º 45
0
        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;
        }
Exemplo n.º 46
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));
            }
        }
		/*
		 * RTLContentAlignment
		 */

		/// <summary>
		/// Converts the specified <see cref="ContentAlignment"/> to its right-to-left representation.
		/// </summary>
		/// <returns>
		/// The specified <see cref="ContentAlignment"/> is converted only if right-to-left layout is specified;
		/// otherwise, it is left as is.
		/// </returns>
		public static ContentAlignment RTLContentAlignment(ContentAlignment contentAlignment, RightToLeft rightToLeft)
		{
			if (rightToLeft == RightToLeft.Yes)
			{
				switch (contentAlignment)
				{
					case ContentAlignment.BottomLeft: return ContentAlignment.BottomRight;
					case ContentAlignment.BottomRight: return ContentAlignment.BottomLeft;
					case ContentAlignment.MiddleLeft: return ContentAlignment.MiddleRight;
					case ContentAlignment.MiddleRight: return ContentAlignment.MiddleLeft;
					case ContentAlignment.TopLeft: return ContentAlignment.TopRight;
					case ContentAlignment.TopRight: return ContentAlignment.TopLeft;
					default: return contentAlignment;
				}
			}

			return contentAlignment;
		}
Exemplo n.º 48
0
        public static void DrawBackgroundImage(
            Graphics g,
            Image backgroundImage,
            Color backColor,
            ImageLayout backgroundImageLayout,
            Rectangle bounds,
            Rectangle clipRect,
            Point scrollOffset,
            RightToLeft rightToLeft)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            if (backgroundImageLayout == ImageLayout.Tile)
            {
                using (TextureBrush brush = new TextureBrush(backgroundImage, WrapMode.Tile))
                {
                    if (scrollOffset != Point.Empty)
                    {
                        Matrix transform = brush.Transform;
                        transform.Translate((float)scrollOffset.X, (float)scrollOffset.Y);
                        brush.Transform = transform;
                    }
                    g.FillRectangle(brush, clipRect);
                    return;
                }
            }
            Rectangle rect = CalculateBackgroundImageRectangle(
                bounds,
                backgroundImage,
                backgroundImageLayout);

            if ((rightToLeft == RightToLeft.Yes) &&
                (backgroundImageLayout == ImageLayout.None))
            {
                rect.X += clipRect.Width - rect.Width;
            }
            using (SolidBrush brush2 = new SolidBrush(backColor))
            {
                g.FillRectangle(brush2, clipRect);
            }
            if (!clipRect.Contains(rect))
            {
                if ((backgroundImageLayout == ImageLayout.Stretch) ||
                    (backgroundImageLayout == ImageLayout.Zoom))
                {
                    rect.Intersect(clipRect);
                    g.DrawImage(backgroundImage, rect);
                }
                else if (backgroundImageLayout == ImageLayout.None)
                {
                    rect.Offset(clipRect.Location);
                    Rectangle destRect = rect;
                    destRect.Intersect(clipRect);
                    Rectangle rectangle3 = new Rectangle(Point.Empty, destRect.Size);
                    g.DrawImage(
                        backgroundImage,
                        destRect,
                        rectangle3.X,
                        rectangle3.Y,
                        rectangle3.Width,
                        rectangle3.Height,
                        GraphicsUnit.Pixel);
                }
                else
                {
                    Rectangle rectangle4 = rect;
                    rectangle4.Intersect(clipRect);
                    Rectangle rectangle5 = new Rectangle(
                        new Point(rectangle4.X - rect.X, rectangle4.Y - rect.Y),
                        rectangle4.Size);
                    g.DrawImage(
                        backgroundImage,
                        rectangle4,
                        rectangle5.X,
                        rectangle5.Y,
                        rectangle5.Width,
                        rectangle5.Height,
                        GraphicsUnit.Pixel);
                }
            }
            else
            {
                ImageAttributes imageAttr = new ImageAttributes();
                imageAttr.SetWrapMode(WrapMode.TileFlipXY);
                g.DrawImage(
                    backgroundImage,
                    rect,
                    0,
                    0,
                    backgroundImage.Width,
                    backgroundImage.Height,
                    GraphicsUnit.Pixel,
                    imageAttr);
                imageAttr.Dispose();
            }
        }
Exemplo n.º 49
0
		/// <summary>
		/// Initializes a new instance of the <see cref="NuGenBoundsParams"/> class.
		/// </summary>
		public NuGenBoundsParams(
			Rectangle bounds
			, ContentAlignment imageAlign
			, Rectangle imageBounds
			, RightToLeft rightToLeft
			)
		{
			_bounds = bounds;
			_imageAlign = imageAlign;
			_imageBounds = imageBounds;
			_rightToLeft = rightToLeft;
		}
Exemplo n.º 50
0
        private void SavePropertiesXml(string xmlPath)
        {
            var xmlDocument = new XmlDocument();

            var xmlDeclaration = xmlDocument.CreateXmlDeclaration(@"1.0", @"utf-8", null);

            xmlDocument.InsertBefore(xmlDeclaration, xmlDocument.DocumentElement);

            var xmlNode = xmlDocument.AppendChild(xmlDocument.CreateElement(@"localization"));

            xmlNode = xmlNode.AppendChild(xmlDocument.CreateElement(@"locale"));

            xmlNode.AppendChild(xmlDocument.CreateNode(XmlNodeType.Element, @"name", @"")).InnerText         = Name;
            xmlNode.AppendChild(xmlDocument.CreateNode(XmlNodeType.Element, @"rtl", @"")).InnerText          = RightToLeft.ToString().ToLower();
            xmlNode.AppendChild(xmlDocument.CreateNode(XmlNodeType.Element, @"parentLocale", @"")).InnerText = ParentLocale;

            xmlDocument.Save(xmlPath);
        }
Exemplo n.º 51
0
		protected ToolStripItem (string text, Image image, EventHandler onClick, string name)
		{
			this.alignment = ToolStripItemAlignment.Left;
			this.anchor = AnchorStyles.Left | AnchorStyles.Top;
			this.auto_size = true;
			this.auto_tool_tip = this.DefaultAutoToolTip;
			this.available = true;
			this.back_color = Color.Empty;
			this.background_image_layout = ImageLayout.Tile;
			this.can_select = true;
			this.display_style = this.DefaultDisplayStyle;
			this.dock = DockStyle.None;
			this.enabled = true;
			this.fore_color = Color.Empty;
			this.image = image;
			this.image_align = ContentAlignment.MiddleCenter;
			this.image_index = -1;
			this.image_key = string.Empty;
			this.image_scaling = ToolStripItemImageScaling.SizeToFit;
			this.image_transparent_color = Color.Empty;
			this.margin = this.DefaultMargin;
			this.merge_action = MergeAction.Append;
			this.merge_index = -1;
			this.name = name;
			this.overflow = ToolStripItemOverflow.AsNeeded;
			this.padding = this.DefaultPadding;
			this.placement = ToolStripItemPlacement.None;
			this.right_to_left = RightToLeft.Inherit;
			this.bounds.Size = this.DefaultSize;
			this.text = text;
			this.text_align = ContentAlignment.MiddleCenter;
			this.text_direction = DefaultTextDirection;
			this.text_image_relation = TextImageRelation.ImageBeforeText;
			this.visible = true;

			this.Click += onClick;
			OnLayout (new LayoutEventArgs (null, string.Empty));
		}
Exemplo n.º 52
0
		public virtual void ResetRightToLeft () { this.right_to_left = RightToLeft.Inherit; }
Exemplo n.º 53
0
        internal static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            if (backgroundImageLayout == ImageLayout.Tile)
            {
                var imageWidth  = backgroundImage.Width;
                var imageHeight = backgroundImage.Height;

                // TODO: better to use shader.
                for (int y = 0; y < bounds.Height; y += imageHeight)
                {
                    for (int x = 0; x < bounds.Width; x += imageWidth)
                    {
                        g.DrawImage(backgroundImage, x, y, imageWidth, imageHeight);
                    }
                }
            }
            else
            {
                var imageRectangle = CalculateBackgroundImageRectangle(bounds, backgroundImage, backgroundImageLayout);
                if (rightToLeft == RightToLeft.Yes && backgroundImageLayout == ImageLayout.None)
                {
                    imageRectangle.X += clipRect.Width - imageRectangle.Width;
                }

                g.uwfFillRectangle(backColor, clipRect);

                if (clipRect.Contains(imageRectangle) == false)
                {
                    switch (backgroundImageLayout)
                    {
                    case ImageLayout.Stretch:
                    case ImageLayout.Zoom:
                        imageRectangle.Intersect(clipRect);
                        g.DrawImage(backgroundImage, imageRectangle);
                        break;

                    default:
                    {
                        imageRectangle.Offset(clipRect.Location);
                        var imageRect = imageRectangle;
                        imageRect.Intersect(clipRect);
                        g.DrawImage(backgroundImage, imageRect);
                    }
                    break;
                    }
                }
                else
                {
                    g.DrawImage(backgroundImage, imageRectangle);
                }
            }
        }
Exemplo n.º 54
0
        private static void DrawVerticalImagesAndText(
            Graphics graphics,
			Rectangle captionRectangle,
			Rectangle panelRectangle,
            Rectangle imageRectangle,
			DockStyle dockStyle,
			Image image,
			RightToLeft rightToLeft,
            bool bDrawBackground,
            Image imageExandPanel,
            Color foreColorExpandPanel,
            ref Rectangle rectangleImageExandPanel,
			Font captionFont,
			Color collapsedCaptionForeColor,
			string strCaptionText)
        {
            imageRectangle.Y = (captionRectangle.Height - imageRectangle.Height) / 2;

            if (imageExandPanel != null)
            {
                rectangleImageExandPanel = imageRectangle;
                rectangleImageExandPanel.X = (panelRectangle.Width - imageRectangle.Width) / 2;
                DrawChevron(graphics, imageExandPanel, rectangleImageExandPanel, foreColorExpandPanel, bDrawBackground, imageRectangle.Y);
            }

            int iTextPositionY1 = CaptionSpacing;
            int iTextPositionY2 = panelRectangle.Height - CaptionSpacing;

            if (image != null)
            {
                imageRectangle.Y = iTextPositionY2 - imageRectangle.Height;
                imageRectangle.X = (panelRectangle.Width - imageRectangle.Width) / 2;
                DrawImage(graphics, image, imageRectangle);
                iTextPositionY1 += imageRectangle.Height + CaptionSpacing;
            }

            iTextPositionY2 -= captionRectangle.Height + iTextPositionY1;

            Rectangle textRectangle = new Rectangle(
                iTextPositionY1,
                panelRectangle.Y,
                iTextPositionY2,
                captionRectangle.Height);

            using (SolidBrush textBrush = new SolidBrush(collapsedCaptionForeColor))
            {
                if (dockStyle == DockStyle.Left)
                {
                    graphics.TranslateTransform(0, panelRectangle.Height);
                    graphics.RotateTransform(-90);

                    DrawString(
                        graphics,
                        textRectangle,
                        captionFont,
                        collapsedCaptionForeColor,
                        strCaptionText,
                        rightToLeft,
                        StringAlignment.Center);

                    graphics.ResetTransform();
                }
                if (dockStyle == DockStyle.Right)
                {
                    graphics.TranslateTransform(panelRectangle.Width, 0);
                    graphics.RotateTransform(90);

                    DrawString(
                        graphics,
                        textRectangle,
                        captionFont,
                        collapsedCaptionForeColor,
                        strCaptionText,
                        rightToLeft,
                        StringAlignment.Center);

                    graphics.ResetTransform();
                }
            }
        }
Exemplo n.º 55
0
        /// <summary>
        /// Draws the specified text string on the specified caption surface; within the specified bounds; and in the specified font, color. 
        /// </summary>
        /// <param name="graphics">The Graphics to draw on.</param>
        /// <param name="layoutRectangle">Rectangle structure that specifies the location of the drawn text.</param>
        /// <param name="font">Font that defines the text format of the string.</param>
        /// <param name="fontColor">The color of the string</param>
        /// <param name="strText">String to draw.</param>
        /// <param name="rightToLeft">Gets or sets a value indicating whether control's elements are aligned to support locales using right-to-left fonts.</param>
        /// <param name="stringAlignment">The alignment of a text string relative to its layout rectangle.</param>
        protected static void DrawString(
            Graphics graphics,
            Rectangle layoutRectangle,
            Font font,
            Color fontColor,
            string strText,
            RightToLeft rightToLeft,
            StringAlignment stringAlignment)
        {
            if (graphics == null)
            {
                throw new ArgumentException(
                    string.Format(
                    System.Globalization.CultureInfo.CurrentUICulture,
                    Resources.IDS_ArgumentException,
                    typeof(Graphics).Name));
            }

            using (SolidBrush stringBrush = new SolidBrush(fontColor))
            {
                using (StringFormat stringFormat = new StringFormat())
                {
                    if (rightToLeft == RightToLeft.Yes)
                    {
                        stringFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.DirectionRightToLeft;
                    }
                    else
                    {
                        stringFormat.FormatFlags = StringFormatFlags.NoWrap;
                    }
                    stringFormat.Trimming = StringTrimming.EllipsisCharacter;
                    stringFormat.LineAlignment = StringAlignment.Center;
                    stringFormat.Alignment = stringAlignment;
                    graphics.DrawString(strText, font, stringBrush, layoutRectangle, stringFormat);
                }
            }
        }
Exemplo n.º 56
0
        /// <summary>
        /// Draws the background image.
        /// </summary>
        /// <param name="g">The g.</param>
        /// <param name="backgroundImage">The background image.</param>
        /// <param name="backColor">Color of the back.</param>
        /// <param name="backgroundImageLayout">The background image layout.</param>
        /// <param name="bounds">The bounds.</param>
        /// <param name="clipRect">The clip rect.</param>
        /// <param name="scrollOffset">The scroll offset.</param>
        /// <param name="rightToLeft">The right to left.</param>
        /// <exception cref="ArgumentNullException">g</exception>
        public static void DrawBackgroundImage(this System.Drawing.Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft)
        {
            if (g == null)
            {
                throw new ArgumentNullException(nameof(g));
            }
            if (backgroundImageLayout == ImageLayout.Tile)
            {
                using (TextureBrush textureBrush = new TextureBrush(backgroundImage, WrapMode.Tile))
                {
                    if (scrollOffset != Point.Empty)
                    {
                        Matrix transform = textureBrush.Transform;
                        transform.Translate((float)scrollOffset.X, (float)scrollOffset.Y);
                        textureBrush.Transform = transform;
                    }
                    g.FillRectangle(textureBrush, clipRect);
                    return;
                }
            }
            Rectangle rectangle = CalculateBackgroundImageRectangle(bounds, backgroundImage, backgroundImageLayout);

            if (rightToLeft == RightToLeft.Yes && backgroundImageLayout == ImageLayout.None)
            {
                rectangle.X += clipRect.Width - rectangle.Width;
            }
            using (SolidBrush solidBrush = new SolidBrush(backColor))
            {
                g.FillRectangle(solidBrush, clipRect);
            }
            if (!clipRect.Contains(rectangle))
            {
                if (backgroundImageLayout == ImageLayout.Stretch || backgroundImageLayout == ImageLayout.Zoom)
                {
                    rectangle.Intersect(clipRect);
                    g.DrawImage(backgroundImage, rectangle);
                    return;
                }
                if (backgroundImageLayout == ImageLayout.None)
                {
                    rectangle.Offset(clipRect.Location);
                    Rectangle destRect = rectangle;
                    destRect.Intersect(clipRect);
                    Rectangle rectangle2 = new Rectangle(Point.Empty, destRect.Size);
                    g.DrawImage(backgroundImage, destRect, rectangle2.X, rectangle2.Y, rectangle2.Width, rectangle2.Height, GraphicsUnit.Pixel);
                    return;
                }
                Rectangle destRect2 = rectangle;
                destRect2.Intersect(clipRect);
                Rectangle rectangle3 = new Rectangle(new Point(destRect2.X - rectangle.X, destRect2.Y - rectangle.Y), destRect2.Size);
                g.DrawImage(backgroundImage, destRect2, rectangle3.X, rectangle3.Y, rectangle3.Width, rectangle3.Height, GraphicsUnit.Pixel);
                return;
            }
            else
            {
                ImageAttributes imageAttributes = new ImageAttributes();
                imageAttributes.SetWrapMode(WrapMode.TileFlipXY);
                g.DrawImage(backgroundImage, rectangle, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAttributes);
                imageAttributes.Dispose();
            }
        }
Exemplo n.º 57
0
        /// <summary>
        /// Draws the text and image objects at the specified location. 
        /// </summary>
        /// <param name="graphics">The Graphics to draw on.</param>
        /// <param name="captionRectangle">The drawing rectangle on a panel's caption.</param>
        /// <param name="iSpacing">The spacing on a panel's caption</param>
        /// <param name="imageRectangle">The rectangle of an image displayed on a panel's caption.</param>
        /// <param name="image">The image that is displayed on a panel's caption.</param>
        /// <param name="rightToLeft">A value indicating whether control's elements are aligned to support locales using right-to-left fonts.</param>
        /// <param name="fontCaption">The font of the text displayed on a panel's caption.</param>
        /// <param name="captionForeColor">The foreground color of the text displayed on a panel's caption.</param>
        /// <param name="strCaptionText">The text which is associated with this caption.</param>
        protected static void DrawImagesAndText(
			Graphics graphics,
			Rectangle captionRectangle,
			int iSpacing,
			Rectangle imageRectangle,
			Image image,
			RightToLeft rightToLeft,
			Font fontCaption,
			Color captionForeColor,
			string strCaptionText)
        {
            //DrawImages
            int iTextPositionX1 = iSpacing;
            int iTextPositionX2 = captionRectangle.Right - iSpacing;

            imageRectangle.Y = (captionRectangle.Height - imageRectangle.Height) / 2;

            if (rightToLeft == RightToLeft.No)
            {
                if (image != null)
                {
                    DrawImage(graphics, image, imageRectangle);
                    iTextPositionX1 += imageRectangle.Width + iSpacing;
                }
            }
            //
            // Draw Caption text
            //
            Rectangle textRectangle = captionRectangle;
            textRectangle.X = iTextPositionX1;
            textRectangle.Width -= iTextPositionX1 + iSpacing;
            if (rightToLeft == RightToLeft.Yes)
            {
                if (image != null)
                {
                    Rectangle imageRectangleRight = imageRectangle;
                    imageRectangleRight.X = iTextPositionX2 - imageRectangle.Width;
                    DrawImage(graphics, image, imageRectangleRight);
                    iTextPositionX2 = imageRectangleRight.X - iSpacing;
                }
            }
            textRectangle.Width = iTextPositionX2 - iTextPositionX1;
            DrawString(graphics, textRectangle, fontCaption, captionForeColor, strCaptionText, rightToLeft, StringAlignment.Near);
        }
 public static void Set_RightToLeft(this UpgradeHelpers.BasicViewModels.TextBoxViewModel _TextBox, RightToLeft RightToLeft)
 {
     throw new NotImplementedException("This is an automatic generated code, please implement the requested logic.");
 }
Exemplo n.º 59
0
        /// <summary>
        /// Draws the text and image objects at the specified location.
        /// </summary>
        /// <param name="graphics">The Graphics to draw on.</param>
        /// <param name="panelStyle">The style of the panel.</param>
        /// <param name="dockStyle">Specifies the position and manner in which a control is docked.</param>
        /// <param name="iSpacing">The spacing on a panel's caption</param>
        /// <param name="captionRectangle">The rectangle of the panel's caption bar.</param>
        /// <param name="panelRectangle">The rectangle that represents the client area of the panel.</param>
        /// <param name="imageRectangle">The rectangle of an image displayed on a panel's caption.</param>
        /// <param name="image">The image that is displayed on a panel's caption.</param>
        /// <param name="rightToLeft">A value indicating whether control's elements are aligned to support locales using right-to-left fonts.</param>
        /// <param name="bShowCloseIcon">A value indicating whether the close image is displayed</param>
        /// <param name="imageClosePanel">The close image that is displayed on a panel's caption.</param>
        /// <param name="foreColorCloseIcon">The foreground color of the close image that is displayed on a panel's caption.</param>
        /// <param name="rectangleImageClosePanel">The rectangle of the close image that is displayed on a panel's caption.</param>
        /// <param name="bShowExpandIcon">A value indicating whether the expand image is displayed</param>
        /// <param name="bIsExpanded">A value indicating whether the panel is expanded or collapsed</param>
        /// <param name="imageExandPanel">The expand image that is displayed on a panel's caption.</param>
        /// <param name="foreColorExpandPanel">The foreground color of the expand image displayed by this caption.</param>
        /// <param name="rectangleImageExandPanel"></param>
        /// <param name="fontCaption">The font of the text displayed on a panel's caption.</param>
        /// <param name="captionForeColor">The foreground color of the text displayed on a panel's caption.</param>
        /// <param name="collapsedForeColor"></param>
        /// <param name="strCaptionText">The text which is associated with this caption.</param>
        protected static void DrawImagesAndText(
            Graphics graphics, 
            PanelStyle panelStyle,
			DockStyle dockStyle,
            int iSpacing,
            Rectangle captionRectangle,
			Rectangle panelRectangle,
            Rectangle imageRectangle,
			Image image,
			RightToLeft rightToLeft,
            bool bShowCloseIcon,
            Image imageClosePanel,
            Color foreColorCloseIcon,
            ref Rectangle rectangleImageClosePanel,
            bool bShowExpandIcon,
            bool bIsExpanded, 
            Image imageExandPanel, 
            Color foreColorExpandPanel, 
            ref Rectangle rectangleImageExandPanel,
			Font fontCaption,
            Color captionForeColor, 
            Color collapsedForeColor,
			string strCaptionText)
        {
            bool bDrawBackground = false;
            if (panelStyle == PanelStyle.Aqua)
            {
                bDrawBackground = true;
            }

            switch (dockStyle)
            {
                case DockStyle.Left:
                case DockStyle.Right:
                    if (bIsExpanded == true)
                    {
                        DrawImagesAndText(
                        graphics,
                        captionRectangle,
                        iSpacing,
                        imageRectangle,
                        image,
                        rightToLeft,
                        bDrawBackground,
                        true,
                        bShowCloseIcon,
                        imageClosePanel,
                        foreColorCloseIcon,
                        ref rectangleImageClosePanel,
                        bShowExpandIcon,
                        imageExandPanel,
                        foreColorExpandPanel,
                        ref rectangleImageExandPanel,
                        fontCaption,
                        captionForeColor,
                        strCaptionText);
                    }
                    else
                    {
                        rectangleImageClosePanel = Rectangle.Empty;
                        DrawVerticalImagesAndText(
                            graphics,
                            captionRectangle,
                            panelRectangle,
                            imageRectangle,
                            dockStyle,
                            image,
                            rightToLeft,
                            bDrawBackground,
                            imageExandPanel,
                            foreColorExpandPanel,
                            ref rectangleImageExandPanel,
                            fontCaption,
                            collapsedForeColor,
                            strCaptionText);
                    }
                    break;
                case DockStyle.Top:
                case DockStyle.Bottom:
                    DrawImagesAndText(
                        graphics,
                        captionRectangle,
                        iSpacing,
                        imageRectangle,
                        image,
                        rightToLeft,
                        bDrawBackground,
                        true,
                        bShowCloseIcon,
                        imageClosePanel,
                        foreColorCloseIcon,
                        ref rectangleImageClosePanel,
                        bShowExpandIcon,
                        imageExandPanel,
                        foreColorExpandPanel,
                        ref rectangleImageExandPanel,
                        fontCaption,
                        captionForeColor,
                        strCaptionText);
                    break;
            }
        }
        public void VScrollBarLastLineButtonAccessibleObject_State_ReturnExpected(bool createControl, RightToLeft rightToLeft, int minimum, int maximum, int value)
        {
            using VScrollBar scrollBar = GetVScrollBar(createControl, rightToLeft, minimum, maximum, value);
            ScrollBarLastLineButtonAccessibleObject accessibleObject = GetLastLineButton(scrollBar);

            Assert.Equal(AccessibleStates.None, accessibleObject.State);
            Assert.Equal(createControl, scrollBar.IsHandleCreated);
        }