System.Windows.Forms.ThemeWin32Classic.LayoutTextAboveOrBelowImage C# (CSharp) Method

LayoutTextAboveOrBelowImage() private method

private LayoutTextAboveOrBelowImage ( Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, System textAlign, System imageAlign, bool displayEllipsis, Rectangle &textRect, Rectangle &imageRect ) : void
totalArea System.Drawing.Rectangle
textFirst bool
textSize System.Drawing.Size
imageSize System.Drawing.Size
textAlign System
imageAlign System
displayEllipsis bool
textRect System.Drawing.Rectangle
imageRect System.Drawing.Rectangle
return void
		private void LayoutTextAboveOrBelowImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, System.Drawing.ContentAlignment textAlign, System.Drawing.ContentAlignment imageAlign, bool displayEllipsis, out Rectangle textRect, out Rectangle imageRect)
		{
			int element_spacing = 0;	// Spacing between the Text and the Image
			int total_height = textSize.Height + element_spacing + imageSize.Height;

			if (textFirst)
				element_spacing += 2;

			if (textSize.Width > totalArea.Width)
				textSize.Width = totalArea.Width;
				
			// If the there isn't enough room and we're text first, cut out the image
			if (total_height > totalArea.Height && textFirst) {
				imageSize = Size.Empty;
				total_height = totalArea.Height;
			}

			int excess_height = totalArea.Height - total_height;
			int offset = 0;

			Rectangle final_text_rect;
			Rectangle final_image_rect;

			VerticalAlignment v_text = GetVerticalAlignment (textAlign);
			VerticalAlignment v_image = GetVerticalAlignment (imageAlign);

			if (v_image == VerticalAlignment.Top)
				offset = 0;
			else if (v_image == VerticalAlignment.Bottom && v_text == VerticalAlignment.Bottom)
				offset = excess_height;
			else if (v_image == VerticalAlignment.Center && (v_text == VerticalAlignment.Top || v_text == VerticalAlignment.Center))
				offset += (int)(excess_height / 3);
			else
				offset += (int)(2 * (excess_height / 3));

			if (textFirst) {
				var textHeight = excess_height >= 0 ? totalArea.Height - imageSize.Height - element_spacing: textSize.Height;
				final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, totalArea.Top + offset, textSize.Width, textHeight);
				final_image_rect = new Rectangle (AlignInRectangle (totalArea, imageSize, imageAlign).Left, final_text_rect.Bottom + element_spacing, imageSize.Width, imageSize.Height);
			}
			else {
				final_image_rect = new Rectangle (AlignInRectangle (totalArea, imageSize, imageAlign).Left, totalArea.Top + offset, imageSize.Width, imageSize.Height);
				var textHeight = excess_height >= 0 ? totalArea.Height - final_image_rect.Height : textSize.Height;
				final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, final_image_rect.Bottom + element_spacing, textSize.Width, textHeight);
				
				if (final_text_rect.Bottom > totalArea.Bottom) {
					final_text_rect.Y -= (final_text_rect.Bottom - totalArea.Bottom);
					if (final_text_rect.Y < totalArea.Top)
						final_text_rect.Y = totalArea.Top;
				}
			}

			if (displayEllipsis) {
				// Don't use more space than is available otherwise ellipsis won't show
				if (final_text_rect.Height > totalArea.Bottom)
					final_text_rect.Height = totalArea.Bottom - final_text_rect.Top;
			}

			textRect = final_text_rect;
			imageRect = final_image_rect;
		}
		
ThemeWin32Classic