예제 #1
0
		protected override void RecalcSize()
		{
            if (!BarFunctions.IsHandleValid(this) || m_SuspendRecalcSize)
				return;
            
            InitDefaultStyles();
            ElementStyle backStyle = GetBackgroundStyle();
            if (m_TitleVisible)
            {
                SimpleElementLayoutInfo li = new SimpleElementLayoutInfo();
                m_TitleElement.Image = m_DialogLauncherButton;
                if (m_DialogLauncherButton != null && m_DialogLauncherVisible)
                {
                    m_TitleElement.ImageAlignment = eSimplePartAlignment.FarCenter;
                }

                li.Element = m_TitleElement;
                li.LayoutStyle = GetTitleStyle();
                li.Font = this.Font;
                li.LeftToRight = (this.RightToLeft != RightToLeft.Yes);
                li.VerticalPartAlignment = false;
                li.Left = this.ClientRectangle.X;
                li.Top = this.ClientRectangle.Y;
                m_TitleElement.FixedWidth = this.ClientRectangle.Width;

                if (backStyle != null)
                {
                    //if (backStyle.PaintLeftBorder)
                    //{
                    //    li.Left += backStyle.BorderLeftWidth;
                    //    m_TitleElement.FixedWidth -= backStyle.BorderLeftWidth;
                    //}

                    if (backStyle.PaintRightBorder)
                        m_TitleElement.FixedWidth -= backStyle.BorderRightWidth;

                    if (backStyle.PaintTopBorder)
                        li.Top += backStyle.BorderTopWidth;
                }

                using (Graphics g = this.CreateGraphics())
                {
                    li.Graphics = g;
                    SimpleElementLayout.LayoutSimpleElement(li);
                    if (m_TitlePosition == eRibbonTitlePosition.Bottom)
                    {
                        li.Top = this.ClientRectangle.Bottom - m_TitleElement.Bounds.Height;
                        if (backStyle != null && backStyle.PaintBottomBorder)
                            li.Top -= backStyle.BorderBottomWidth;
                        SimpleElementLayout.LayoutSimpleElement(li);
                    }
                }
                m_TitleRectangle = m_TitleElement.Bounds;
            }
            else
                m_TitleRectangle = Rectangle.Empty;

            RestoreAutoSizedItems();
            m_FullItemsSize = Size.Empty;

            if (this.Parent is RibbonPanel)
            {
                RibbonControl rc = this.GetRibbonControl();
                if ((rc != null) && !rc.AutoSize)
                {
                    // The height of the RibbonBar is controlled by the height of the panel so whatever height is here we apply to ItemContainer
                    m_ItemContainer.MinimumSize = new Size(0, GetItemContainerMinimumSize().Height);
                }
            }
            else if(this.IsOverflowRibbon && !this.AutoSize)
                m_ItemContainer.MinimumSize = new Size(0, GetItemContainerMinimumSize().Height);
            else
                m_ItemContainer.MinimumSize = Size.Empty;

			base.RecalcSize();

            Size contentSize = this.GetContentBasedSize();
            if (ResizeGallery(contentSize.Width))
            {
                m_LastReducedSize = Size.Empty;
                return;
            }

            if (this.AutoOverflowEnabled && !this.DesignMode)
            {    
                if (contentSize.Width > this.Width)
                {
                    if (m_AutoSizeBagList.Count == 0 && m_AutoSizeItems && this.Width > 1 && !this.OverflowState)
                    {
                        // Try to reduce the size of the Ribbon by manipulating size of the items
                        AutoReduceItemSize(contentSize.Width);
                        base.RecalcSize();
                        Size sa = this.GetContentBasedSize();
                        if (sa.Width > this.Width)
                        {
                            RestoreAutoSizedItems();
                        }
                        else
                        {
                            m_LastReducedSize = sa;
                            m_FullItemsSize = contentSize;
                            contentSize = sa;
                        }
                    }

                    if (!this.OverflowState && contentSize.Width > this.Width)
                    {
                        m_BeforeOverflowSize = contentSize;
                        this.SetupOverflowButton();
                        base.RecalcSize();
                    }
                }
                else if (this.OverflowState)
                {
                    if (m_BeforeOverflowSize.IsEmpty)
                    {
                        this.DisposeOverflowButton();
                        base.RecalcSize();
                        Size newSize = this.GetContentBasedSize();
                        if (newSize.Width > this.Width)
                        {
                            this.SetupOverflowButton();
                            base.RecalcSize();
                        }
                    }
                    else if (m_BeforeOverflowSize.Width <= this.Width)
                    {
                        this.DisposeOverflowButton();
                        base.RecalcSize();
                        contentSize = this.GetContentBasedSize();
                        if (ResizeGallery(contentSize.Width))
                            m_LastReducedSize = Size.Empty;
                    }
                    else if (!m_LastReducedSize.IsEmpty && m_LastReducedSize.Width <= this.Width)
                    {
                        this.DisposeOverflowButton();
                        AutoReduceItemSize(m_LastReducedSize.Width);
                        base.RecalcSize();
                        contentSize = this.GetContentBasedSize();
                        if (ResizeGallery(contentSize.Width))
                            m_LastReducedSize = Size.Empty;
                    }
                }
                else
                    m_LastReducedSize = Size.Empty;
            }
		}
예제 #2
0
		internal static void LayoutSimpleElement(SimpleElementLayoutInfo info)
		{
			Size textSize=Size.Empty;
			Font font=info.Font;
			int height=0;
			if(info.LayoutStyle.Font!=null)
				font=info.LayoutStyle.Font;

			// Calculate Text Width and Height
			if(info.Element.FixedWidth==0)
			{
				if(info.Element.TextVisible)
				{
					string text=info.Element.Text;
					if(text!="")
					{
						textSize=TextDrawing.MeasureString(info.Graphics,text,font);
						//textSize=info.Graphics.MeasureString(text,font);
                        if (info.LayoutStyle != null && !info.LayoutStyle.TextShadowColor.IsEmpty && !info.LayoutStyle.TextShadowOffset.IsEmpty)
                            textSize.Height += info.LayoutStyle.TextShadowOffset.Y;
					}
				}
			}
			else
			{
				int availTextWidth=info.Element.FixedWidth-
					ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle);

				if(info.Element.ImageVisible)
					availTextWidth-=info.Element.ImageLayoutSize.Width;

				if(info.Element.TextVisible)
				{
					int elementHeight=font.Height;
                    if (info.LayoutStyle != null && !info.LayoutStyle.TextShadowColor.IsEmpty && !info.LayoutStyle.TextShadowOffset.IsEmpty)
                        elementHeight += info.LayoutStyle.TextShadowOffset.Y;

					if(info.LayoutStyle.WordWrap)
					{
						elementHeight=info.LayoutStyle.MaximumHeight-info.LayoutStyle.MarginTop-
						              info.LayoutStyle.MarginBottom-info.LayoutStyle.PaddingTop-info.LayoutStyle.PaddingBottom;
						if(availTextWidth>0)
						{
							if(elementHeight>0)
							{
								textSize=TextDrawing.MeasureString(info.Graphics,info.Element.Text,font,new Size(availTextWidth,elementHeight),info.LayoutStyle.TextFormat);
							}
							else
								textSize=TextDrawing.MeasureString(info.Graphics,info.Element.Text,font,availTextWidth,info.LayoutStyle.TextFormat);
						}
					}
					else
						textSize=new Size(availTextWidth,elementHeight);
				}
			}

			if(info.Element.TextVisible && !info.LayoutStyle.TextShadowColor.IsEmpty)
			{
				textSize.Height+=info.LayoutStyle.TextShadowOffset.Y;
			}
			height=textSize.Height;

			if(info.VerticalPartAlignment)
			{
				if(info.Element.ImageVisible && info.Element.ImageLayoutSize.Height>0)
					height+=info.Element.ImageLayoutSize.Height;
			}
			else
			{
				if(info.Element.ImageVisible && info.Element.ImageLayoutSize.Height>height)
					height=info.Element.ImageLayoutSize.Height;
			}

			Rectangle r=new Rectangle(info.Left+ElementStyleLayout.LeftWhiteSpace(info.LayoutStyle),
				info.Top+ElementStyleLayout.TopWhiteSpace(info.LayoutStyle)
				,info.Element.FixedWidth-ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle),height);

			if(r.Width==0)
			{
				if(info.VerticalPartAlignment)
				{
					if(info.Element.TextVisible)
						r.Width=textSize.Width;
					if(info.Element.ImageVisible && info.Element.ImageLayoutSize.Width>r.Width)
						r.Width=(info.Element.ImageLayoutSize.Width+info.Element.ImageTextSpacing);
				}
				else
				{
					if(info.Element.TextVisible)
						r.Width=textSize.Width;
					if(info.Element.ImageVisible && info.Element.ImageLayoutSize.Width>0)
						r.Width+=(info.Element.ImageLayoutSize.Width+info.Element.ImageTextSpacing);
				}
			}

			// Now that we have element bounds store them
			Rectangle rElementBounds=new Rectangle(info.Left,info.Top,info.Element.FixedWidth,r.Height+info.LayoutStyle.MarginTop+info.LayoutStyle.MarginBottom+info.LayoutStyle.PaddingTop+info.LayoutStyle.PaddingBottom);
			if(rElementBounds.Width==0)
				rElementBounds.Width=r.Width+ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle);
			info.Element.Bounds=rElementBounds;

			// Set Position of the image
			if(info.Element.ImageVisible && !info.Element.ImageLayoutSize.IsEmpty)
			{
				eVerticalAlign va=GetImageVerticalAlign(info.Element.ImageAlignment);
				eHorizontalAlign ha=GetImageHorizontalAlign(info.Element.ImageAlignment,info.LeftToRight);
				if(info.VerticalPartAlignment)
					info.Element.ImageBounds=AlignContentVertical(info.Element.ImageLayoutSize, ref r, ha, va, info.Element.ImageTextSpacing);
				else
					info.Element.ImageBounds=AlignContent(info.Element.ImageLayoutSize, ref r, ha, va, info.Element.ImageTextSpacing);
			}
			else
				info.Element.ImageBounds=Rectangle.Empty;

			
			// Set position of the text
			if(!textSize.IsEmpty)
				info.Element.TextBounds=r;
			else
				info.Element.TextBounds=Rectangle.Empty;
            
		}