예제 #1
0
 internal void InvokeMeasureTabItem(MeasureTabItemEventArgs e)
 {
     if (MeasureTabItem != null)
         MeasureTabItem(this, e);
 }
예제 #2
0
		/// <summary>
		/// Resizes the content block and sets it's Bounds property to reflect new size.
		/// </summary>
		/// <param name="block">Content block to resize.</param>
        public override void Layout(IBlock block, Size availableSize)
		{
			if(this.Graphics==null)
				throw(new InvalidOperationException("Graphics property must be set to valid instance of Graphics object."));

			TabItem tab=block as TabItem;
			if(!tab.Visible)
				return;

			int width=0;
			int height=0;
            bool isVertical = (tab.Parent != null && (tab.Parent.TabAlignment == eTabStripAlignment.Left || tab.Parent.TabAlignment == eTabStripAlignment.Right) && !m_HorizontalText);

			eTabStripStyle style=tab.Parent.Style;
			eTextFormat strFormat=eTextFormat.Default;

			Image tabImage=tab.GetImage();
			if(tab.Icon!=null)
			{
				width+=tab.IconSize.Width;
                if (style != eTabStripStyle.OneNote && style != eTabStripStyle.Office2007Document)
					width+=m_ImagePadding;
				height=tab.IconSize.Height+m_PaddingHeight;
			}
			else if(tabImage!=null)
			{
				width+=tabImage.Width;
                if (style != eTabStripStyle.OneNote && style != eTabStripStyle.Office2007Document)
					width+=m_ImagePadding;
				height=tabImage.Height+m_PaddingHeight;
			}

			if((!tab.Parent.DisplaySelectedTextOnly || tab==tab.Parent.SelectedTab))
			{
                string text = tab.Text;
                if (text == "")
                    text = "M";
				Font font=tab.Parent.Font;
                if (tab.Parent.SelectedTabFont != null && (tab == tab.Parent.SelectedTab || 
                    tab.Parent.CloseButtonOnTabsAlwaysDisplayed && tab.Parent.CloseButtonPosition == eTabCloseButtonPosition.Right || 
                    ((tab.Parent.TabAlignment == eTabStripAlignment.Left || tab.Parent.TabAlignment == eTabStripAlignment.Right) && m_HorizontalText)))
					font=tab.Parent.SelectedTabFont;
                Size textSize = Size.Empty;
                if(isVertical)
                    textSize = TextDrawing.MeasureStringLegacy(this.Graphics, text, font, Size.Empty, strFormat);
                else
				    textSize=TextDrawing.MeasureString(this.Graphics,text,font,0,strFormat);
				width+=textSize.Width;
				if(style!=eTabStripStyle.OneNote)
					width+=m_TextPadding;
				if(textSize.Height>height)
					height=(int)(textSize.Height+m_PaddingHeight);
			}

            if (m_CloseButtonOnTabs && tab.CloseButtonVisible)
                width += m_CloseButtonSize.Width + m_CloseButtonSpacing * 2;

			width+=m_PaddingWidth;
			if(tab.IsSelected)
				width+=m_SelectedPaddingWidth;

            if (m_FixedTabSize.Width > 0)
                width = m_FixedTabSize.Width;
            if (m_FixedTabSize.Height > 0)
                height = m_FixedTabSize.Height;

            if (style == eTabStripStyle.OneNote || style == eTabStripStyle.Office2007Document)
                width += (int)(height * .5)-4;

            Rectangle bounds = new Rectangle(0, 0, width, height);

            if (isVertical)
                bounds = new Rectangle(0, 0, height, width);

            if (m_TabStrip != null && m_TabStrip.HasMeasureTabItem)
            {
                MeasureTabItemEventArgs mea = new MeasureTabItemEventArgs(tab, bounds.Size);
                m_TabStrip.InvokeMeasureTabItem(mea);
                bounds.Size = mea.Size;
            }

            block.Bounds = bounds;
		}
예제 #3
0
		private void RecalcSizeLegacy(Graphics g, Rectangle dispRect)
		{
			int iMaxWidth=dispRect.Width;
			int iWidth=0;
			int iDisplayed=0;
			int firstVisible = -1;
			eTextFormat strFormat=eTextFormat.Default;

			if(m_Alignment==eTabStripAlignment.Left || m_Alignment==eTabStripAlignment.Right)
				iMaxWidth=dispRect.Height;

			int iHeight=this.GetTabHeight(g);
			m_TabHeight=iHeight;

			int x=dispRect.X;
			int y=dispRect.Y;
			if(m_Alignment==eTabStripAlignment.Top)
			{
				y=dispRect.Bottom-iHeight;
			}
			else if(m_Alignment==eTabStripAlignment.Left)
			{
				x=dispRect.Right-iHeight;
			}

			if(m_Alignment==eTabStripAlignment.Left || m_Alignment==eTabStripAlignment.Right)
				y-=m_ScrollOffset;
			else
				x-=m_ScrollOffset;

			int initalX=x, initalY=y;
			bool bMultiLine=false;

			if(this.HasNavigationBox)
			{
				iMaxWidth-=m_TabSystemBox.DefaultWidth;
				iMaxWidth-=4;
			}
			ArrayList linePositions=new ArrayList();
			foreach(TabItem tab in m_Tabs)
			{
				int iItemWidth=4;
				if(!tab.Visible)
					continue;

				if(firstVisible<0)
					firstVisible = m_Tabs.IndexOf(tab);

				iDisplayed++;

                if (m_FixedTabSize.Width == 0)
                {
                    Image tabImage = tab.GetImage();
                    if (tab.Icon != null)
                    {
                        iItemWidth += tab.IconSize.Width;
                        if (m_Style != eTabStripStyle.OneNote || this.IsThemed)
                            iItemWidth += 4;
                    }
                    else if (tabImage != null)
                    {
                        iItemWidth += tabImage.Width;
                        if (m_Style != eTabStripStyle.OneNote || this.IsThemed)
                            iItemWidth += 4;
                    }

                    if (m_Style == eTabStripStyle.OneNote && !this.IsThemed)
                        iItemWidth += ((iHeight - 6) * 1);
                    else if (m_Style == eTabStripStyle.VS2005Document && !this.IsThemed)
                        iItemWidth += 4;
                    if (tab.Text != "" && (!m_DisplaySelectedTextOnly || tab == m_SelectedTab))
                    {
                        Font font = this.Font;
                        if (m_SelectedTabFont != null && (tab == m_SelectedTab || m_CloseButtonPosition == eTabCloseButtonPosition.Right && m_CloseButtonOnTabsAlwaysDisplayed))
                            font = m_SelectedTabFont;
                        Size textSize = Size.Empty;
                        if (this.IsVertical)
                            textSize = TextDrawing.MeasureStringLegacy(g, tab.Text, font, Size.Empty, strFormat);
                        else
                            textSize = TextDrawing.MeasureString(g, tab.Text, font, 0, strFormat);
                        iItemWidth += textSize.Width;
                        if ((m_Style != eTabStripStyle.OneNote && m_Style != eTabStripStyle.VS2005Document || this.IsThemed) || m_Alignment == eTabStripAlignment.Top || m_Alignment == eTabStripAlignment.Bottom)
                            iItemWidth += 4; // 2 pixels of padding...
						if(this.IsThemed)
							iItemWidth+=10;
                    }

                    if (m_CloseButtonOnTabs && tab.CloseButtonVisible && m_Style != eTabStripStyle.OneNote)
                        iItemWidth += m_CloseButtonSize.Width;
                }
                else
                    iItemWidth = m_FixedTabSize.Width;

				// Multi-line tab support
				if(this.IsMultiLine && iWidth+iItemWidth>iMaxWidth && iDisplayed>1)
				{
					bMultiLine=true;
					switch(m_Alignment)
					{
						case eTabStripAlignment.Left:
						case eTabStripAlignment.Right:
						{
							if(linePositions.Count==0)
								linePositions.Add(x);
							x+=(iHeight+m_MultiLineSpacing);
							y=initalY;
							linePositions.Add(x);
							break;
						}
						case eTabStripAlignment.Top:
						case eTabStripAlignment.Bottom:
						{
							if(linePositions.Count==0)
								linePositions.Add(y);
							y+=(iHeight+m_MultiLineSpacing);
							x=initalX;
							linePositions.Add(y);
							break;
						}
					}
					m_TabHeight+=(iHeight+m_MultiLineSpacing);
					iWidth=0;
				}

				if(m_Alignment==eTabStripAlignment.Left || m_Alignment==eTabStripAlignment.Right)
				{
					tab._DisplayRectangle=new Rectangle(x,y,iHeight,iItemWidth);
				}
				else
				{
					tab._DisplayRectangle=new Rectangle(x,y,iItemWidth,iHeight);
				}

                if (MeasureTabItem != null)
                {
                    MeasureTabItemEventArgs mea = new MeasureTabItemEventArgs(tab, tab.DisplayRectangle.Size);
                    MeasureTabItem(this, mea);
                    tab._DisplayRectangle = new Rectangle(tab._DisplayRectangle.Location, mea.Size);
                    if (m_Alignment == eTabStripAlignment.Left || m_Alignment == eTabStripAlignment.Right)
                        iItemWidth = mea.Size.Height;
                    else
                        iItemWidth = mea.Size.Width;
                }

                if(m_Alignment==eTabStripAlignment.Left || m_Alignment==eTabStripAlignment.Right)
                    y += iItemWidth;
                else
                    x += iItemWidth;

				iWidth+=iItemWidth;
			}

			if(bMultiLine)
			{
				if(m_Alignment==eTabStripAlignment.Top)
				{
					int offset=initalY-y;
					foreach(TabItem tab in m_Tabs)
						tab._DisplayRectangle=new Rectangle(tab.DisplayRectangle.X,tab.DisplayRectangle.Y+offset,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
					for(int i=0;i<linePositions.Count;i++)
						linePositions[i]=(int)linePositions[i]+offset;
				}
				else if(m_Alignment==eTabStripAlignment.Left)
				{
					int offset=initalX-x;
					foreach(TabItem tab in m_Tabs)
						tab._DisplayRectangle=new Rectangle(tab.DisplayRectangle.X+offset,tab.DisplayRectangle.Y,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
					for(int i=0;i<linePositions.Count;i++)
						linePositions[i]=(int)linePositions[i]+offset;
				}
				// Rearrange tabs so line with the selected tab is always at the edge
				switch(m_Alignment)
				{
					case eTabStripAlignment.Left:
					{
						// Selected tab must be in last line
						if(m_SelectedTab.DisplayRectangle.X!=(int)linePositions[linePositions.Count-1])
						{
							int switchPos=m_SelectedTab.DisplayRectangle.X;
							int selectedPos=(int)linePositions[linePositions.Count-1];
							foreach(TabItem tab in m_Tabs)
							{
								if(tab.DisplayRectangle.X==selectedPos)
									tab._DisplayRectangle=new Rectangle(switchPos,tab.DisplayRectangle.Y,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
								else if(tab.DisplayRectangle.X==switchPos)
									tab._DisplayRectangle=new Rectangle(selectedPos,tab.DisplayRectangle.Y,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
							}
						}
						break;
					}
					case eTabStripAlignment.Right:
					{
						// Selected tab must be in last line
						if(m_SelectedTab.DisplayRectangle.X!=(int)linePositions[0])
						{
							int switchPos=m_SelectedTab.DisplayRectangle.X;
							int selectedPos=(int)linePositions[0];
							foreach(TabItem tab in m_Tabs)
							{
								if(tab.DisplayRectangle.X==selectedPos)
									tab._DisplayRectangle=new Rectangle(switchPos,tab.DisplayRectangle.Y,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
								else if(tab.DisplayRectangle.X==switchPos)
									tab._DisplayRectangle=new Rectangle(selectedPos,tab.DisplayRectangle.Y,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
							}
						}
						break;
					}
					case eTabStripAlignment.Top:
					{
						// Selected tab must be in last line
						if(m_SelectedTab.DisplayRectangle.Y!=(int)linePositions[linePositions.Count-1])
						{
							int switchPos=m_SelectedTab.DisplayRectangle.Y;
							int selectedPos=(int)linePositions[linePositions.Count-1];
							foreach(TabItem tab in m_Tabs)
							{
								if(tab.DisplayRectangle.Y==selectedPos)
									tab._DisplayRectangle=new Rectangle(tab.DisplayRectangle.X,switchPos,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
								else if(tab.DisplayRectangle.Y==switchPos)
									tab._DisplayRectangle=new Rectangle(tab.DisplayRectangle.X,selectedPos,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
							}
						}
						break;
					}
					case eTabStripAlignment.Bottom:
					{
						// Selected tab must be in first line
						if(m_SelectedTab.DisplayRectangle.Y!=(int)linePositions[0])
						{
							int switchPos=m_SelectedTab.DisplayRectangle.Y;
							int selectedPos=(int)linePositions[0];
							foreach(TabItem tab in m_Tabs)
							{
								if(tab.DisplayRectangle.Y==selectedPos)
									tab._DisplayRectangle=new Rectangle(tab.DisplayRectangle.X,switchPos,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
								else if(tab.DisplayRectangle.Y==switchPos)
									tab._DisplayRectangle=new Rectangle(tab.DisplayRectangle.X,selectedPos,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
							}
						}
						break;
					}
				}
			}
			
			if(this.HasNavigationBox)
			{
				if(m_ScrollOffset!=0)
					m_TabSystemBox.BackEnabled=true;
				else
					m_TabSystemBox.BackEnabled=false;

				if(iWidth-m_ScrollOffset>iMaxWidth)
					m_TabSystemBox.ForwardEnabled=true;
				else
					m_TabSystemBox.ForwardEnabled=false;

				if(m_AutoHideSystemBox && !this.IsMultiLine)
				{
					if(iWidth>iMaxWidth)
						m_TabSystemBox.Visible=true;
					else
						m_TabSystemBox.Visible=false;
				}
				else
					m_TabSystemBox.Visible=true;

				Rectangle rSysBox=Rectangle.Empty;
				switch(m_Alignment)
				{
					case eTabStripAlignment.Left:
					{
						rSysBox=new Rectangle((firstVisible<0?dispRect.X:m_Tabs[firstVisible].DisplayRectangle.X),this.ClientRectangle.Bottom-m_TabSystemBox.DefaultWidth-3,(firstVisible<0?dispRect.Width:m_Tabs[firstVisible].DisplayRectangle.Width),m_TabSystemBox.DefaultWidth);
						if(m_Style==eTabStripStyle.VS2005 && !this.IsThemed) rSysBox.X--;
						break;
					}
					case eTabStripAlignment.Right:
					{
						rSysBox=new Rectangle(dispRect.X,this.ClientRectangle.Bottom-m_TabSystemBox.DefaultWidth-3,(firstVisible<0?dispRect.Width:m_Tabs[firstVisible].DisplayRectangle.Width),m_TabSystemBox.DefaultWidth);
						if(m_Style==eTabStripStyle.VS2005 && !this.IsThemed) rSysBox.X++;
						break;
					}
					case eTabStripAlignment.Top:
					{
                        if(this.IsRightToLeft)
                            rSysBox = new Rectangle(this.ClientRectangle.Left, (firstVisible<0 ? dispRect.Y : m_Tabs[firstVisible].DisplayRectangle.Y), m_TabSystemBox.DefaultWidth, (firstVisible<0 ? dispRect.Height : m_Tabs[firstVisible].DisplayRectangle.Height));
                        else
						    rSysBox=new Rectangle(this.ClientRectangle.Right-m_TabSystemBox.DefaultWidth-3,(firstVisible<0?dispRect.Y:m_Tabs[firstVisible].DisplayRectangle.Y),m_TabSystemBox.DefaultWidth,(firstVisible<0?dispRect.Height:m_Tabs[firstVisible].DisplayRectangle.Height));
						if(m_Style==eTabStripStyle.VS2005 && !this.IsThemed) rSysBox.Y--;
						break;
					}
					default:
					{
                        if (this.IsRightToLeft)
                            rSysBox = new Rectangle(this.ClientRectangle.Left, dispRect.Y, m_TabSystemBox.DefaultWidth + 2, (firstVisible<0 ? dispRect.Height : m_Tabs[firstVisible].DisplayRectangle.Height));
                        else
						    rSysBox=new Rectangle(this.ClientRectangle.Right-m_TabSystemBox.DefaultWidth-2,dispRect.Y,m_TabSystemBox.DefaultWidth+2,(firstVisible<0?dispRect.Height:m_Tabs[firstVisible].DisplayRectangle.Height));
						if(m_Style==eTabStripStyle.VS2005 && !this.IsThemed) rSysBox.Y++;
						break;
					}
				}
				
				m_TabSystemBox.DisplayRectangle=rSysBox;
			}

			if(iWidth>iMaxWidth && m_TabLayoutType==eTabLayoutType.FitContainer && !this.IsMultiLine)
			{
				if(iDisplayed>0)
				{
					if(m_Alignment==eTabStripAlignment.Left || m_Alignment==eTabStripAlignment.Right)
					{
						x=dispRect.X;
						y=dispRect.Y;
						if(m_Alignment==eTabStripAlignment.Left)
							x=dispRect.Right-iHeight;
						int iItemWidth=iMaxWidth/iDisplayed;
						int iOverageCount=0;
						foreach(TabItem tab in m_Tabs)
						{
							if(!tab.Visible)
								continue;
							if(tab.DisplayRectangle.Height>iItemWidth)
								iOverageCount++;
							else
							{
								iMaxWidth-=tab.DisplayRectangle.Height;
								iWidth-=tab.DisplayRectangle.Height;
							}
						}
						//int iDiff=(iWidth-iMaxWidth)/iOverageCount;
						float fDiff=(float)iMaxWidth/(float)iWidth;
						foreach(TabItem tab in m_Tabs)
						{
							if(!tab.Visible)
								continue;
							if(tab.DisplayRectangle.Height>iItemWidth)
							{
								if(iOverageCount==iDisplayed)
									tab._DisplayRectangle=new Rectangle(x,y,tab.DisplayRectangle.Width,iItemWidth);
								else
									tab._DisplayRectangle=new Rectangle(x,y,tab.DisplayRectangle.Width,(int)(tab.DisplayRectangle.Height*fDiff));
							}
							else
								tab._DisplayRectangle=new Rectangle(x,y,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
							y+=tab.DisplayRectangle.Height;
						}
					}
					else
					{
						x=dispRect.X;
						int iItemWidth=iMaxWidth/iDisplayed;
						int iOverageCount=0;
						foreach(TabItem tab in m_Tabs)
						{
							if(!tab.Visible)
								continue;
							if(tab.DisplayRectangle.Width>iItemWidth)
								iOverageCount++;
							else
							{
								iMaxWidth-=tab.DisplayRectangle.Width;
								iWidth-=tab.DisplayRectangle.Width;
							}
						}
						//int iDiff=(iWidth-iMaxWidth)/iOverageCount;
						float fDiff=(float)iMaxWidth/(float)iWidth;
						foreach(TabItem tab in m_Tabs)
						{
							if(!tab.Visible)
								continue;
							if(tab.DisplayRectangle.Width>iItemWidth)
							{
								if(iOverageCount==iDisplayed)
									tab._DisplayRectangle=new Rectangle(x,y,iItemWidth,tab.DisplayRectangle.Height);
								else
									tab._DisplayRectangle=new Rectangle(x,y,(int)(tab.DisplayRectangle.Width*fDiff),tab.DisplayRectangle.Height);
							}
							else
								tab._DisplayRectangle=new Rectangle(x,y,tab.DisplayRectangle.Width,tab.DisplayRectangle.Height);
							x+=tab.DisplayRectangle.Width;
						}
					}
				}
			}
            else if (this.IsRightToLeft && m_TabLayoutType != eTabLayoutType.FitContainer &&
                (m_Alignment == eTabStripAlignment.Top || m_Alignment == eTabStripAlignment.Bottom))
            {
                if (iWidth > iMaxWidth)
                {
                    for (int i = m_Tabs.Count - 1; i >= 0; i--)
                    {
                        if (m_Tabs[i].Visible)
                        {
                            x = m_Tabs[i].DisplayRectangle.Right;
                            break;
                        }
                    }
                    if (m_TabSystemBox.Visible)
                        x += m_TabSystemBox.DisplayRectangle.Right;
                }
                else
                    x = dispRect.Right;
                foreach (TabItem tab in m_Tabs)
                {
                    if (tab.Visible)
                    {
                        x -= tab.DisplayRectangle.Width;
                        tab._DisplayRectangle = new Rectangle(x, tab.DisplayRectangle.Y, tab.DisplayRectangle.Width, tab.DisplayRectangle.Height);
                    }
                }
            }
		}