X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FManaged.Windows.Forms%2FSystem.Windows.Forms%2FThemeWin32Classic.cs;h=be62bc6f707b27af3395c2baf0e9c0f28a2116de;hb=709859812961d35f19da03bf1374a8fc2aece615;hp=8cbd1e086333f90e8510f4ff801a85d67f6d923e;hpb=c05af49a8523d672b768e0e7974a1d82084fe3ae;p=mono.git diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs index 8cbd1e08633..be62bc6f707 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs @@ -35,6 +35,7 @@ using System.Drawing.Imaging; using System.Drawing.Printing; using System.Drawing.Text; using System.Text; +using System.Windows.Forms.Theming; namespace System.Windows.Forms { @@ -59,15 +60,14 @@ namespace System.Windows.Forms const int SEPARATOR_MIN_WIDTH = 20; const int SM_CXBORDER = 1; const int SM_CYBORDER = 1; - const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tab - const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items + const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tab + const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items #region Principal Theme Methods public ThemeWin32Classic () { defaultWindowBackColor = this.ColorWindow; defaultWindowForeColor = this.ColorControlText; - default_font = new Font (FontFamily.GenericSansSerif, 8f); window_border_font = new Font(FontFamily.GenericSansSerif, 8.25f, FontStyle.Bold); /* Menu string formats */ @@ -84,7 +84,6 @@ namespace System.Windows.Forms string_format_menu_menubar_text.LineAlignment = StringAlignment.Center; string_format_menu_menubar_text.Alignment = StringAlignment.Center; string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show; - always_draw_hotkeys = false; } public override void ResetDefaults() { @@ -124,6 +123,13 @@ namespace System.Windows.Forms } #endregion // Internal Methods + #region Control + public override Font GetLinkFont (Control control) + { + return new Font (control.Font.FontFamily, control.Font.Size, control.Font.Style | FontStyle.Underline, control.Font.Unit); + } + #endregion // Control + #region OwnerDraw Support public override void DrawOwnerDrawBackground (DrawItemEventArgs e) { @@ -142,19 +148,436 @@ namespace System.Windows.Forms } #endregion // OwnerDraw Support - #region ButtonBase - public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) { - - // Fill the button with the correct color - bool is_ColorControl = button.BackColor.ToArgb () == ColorControl.ToArgb () ? true : false; - dc.FillRectangle (is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle); + #region Button + #region Standard Button Style + public override void DrawButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle) + { + // Draw Button Background + DrawButtonBackground (g, b, clipRectangle); + + // If we have an image, draw it + if (imageBounds.Size != Size.Empty) + DrawButtonImage (g, b, imageBounds); + + // If we're focused, draw a focus rectangle + if (b.Focused && b.Enabled) + DrawButtonFocus (g, b); + + // If we have text, draw it + if (textBounds != Rectangle.Empty) + DrawButtonText (g, b, textBounds); + } + + public virtual void DrawButtonBackground (Graphics g, Button button, Rectangle clipArea) + { + if (button.Pressed) + ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor); + else if (button.InternalSelected) + ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor); + else if (button.Entered) + ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor); + else if (!button.Enabled) + ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor); + else + ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor); + } + + public virtual void DrawButtonFocus (Graphics g, Button button) + { + ControlPaint.DrawFocusRectangle (g, Rectangle.Inflate (button.ClientRectangle, -4, -4)); + } + + public virtual void DrawButtonImage (Graphics g, Button button, Rectangle imageBounds) + { + if (button.Enabled) + g.DrawImage (button.Image, imageBounds); + else + CPDrawImageDisabled (g, button.Image, imageBounds.Left, imageBounds.Top, ColorControl); + } + + public virtual void DrawButtonText (Graphics g, Button button, Rectangle textBounds) + { + if (button.Enabled) + TextRenderer.DrawTextInternal (g, button.Text, button.Font, textBounds, button.ForeColor, button.TextFormatFlags, button.UseCompatibleTextRendering); + else + DrawStringDisabled20 (g, button.Text, button.Font, textBounds, button.BackColor, button.TextFormatFlags, button.UseCompatibleTextRendering); + } + #endregion + + #region FlatStyle Button Style + public override void DrawFlatButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle) + { + // Draw Button Background + DrawFlatButtonBackground (g, b, clipRectangle); + + // If we have an image, draw it + if (imageBounds.Size != Size.Empty) + DrawFlatButtonImage (g, b, imageBounds); + + // If we're focused, draw a focus rectangle + if (b.Focused && b.Enabled) + DrawFlatButtonFocus (g, b); + + // If we have text, draw it + if (textBounds != Rectangle.Empty) + DrawFlatButtonText (g, b, textBounds); + } + + public virtual void DrawFlatButtonBackground (Graphics g, Button button, Rectangle clipArea) + { + if (button.Pressed) + ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor, button.FlatAppearance); + else if (button.InternalSelected) + ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor, button.FlatAppearance); + else if (button.Entered) + ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor, button.FlatAppearance); + else if (!button.Enabled) + ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor, button.FlatAppearance); + else + ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor, button.FlatAppearance); + } + + public virtual void DrawFlatButtonFocus (Graphics g, Button button) + { + if (!button.Pressed) { + Color focus_color = ControlPaint.Light(button.BackColor); + g.DrawRectangle (ResPool.GetPen (focus_color), new Rectangle (button.ClientRectangle.Left + 4, button.ClientRectangle.Top + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9)); + } + } + + public virtual void DrawFlatButtonImage (Graphics g, Button button, Rectangle imageBounds) + { + // No changes from Standard for image for this theme + DrawButtonImage (g, button, imageBounds); + } + + public virtual void DrawFlatButtonText (Graphics g, Button button, Rectangle textBounds) + { + // No changes from Standard for image for this theme + DrawButtonText (g, button, textBounds); + } + #endregion + + #region Popup Button Style + public override void DrawPopupButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle) + { + // Draw Button Background + DrawPopupButtonBackground (g, b, clipRectangle); + + // If we have an image, draw it + if (imageBounds.Size != Size.Empty) + DrawPopupButtonImage (g, b, imageBounds); + + // If we're focused, draw a focus rectangle + if (b.Focused && b.Enabled) + DrawPopupButtonFocus (g, b); + + // If we have text, draw it + if (textBounds != Rectangle.Empty) + DrawPopupButtonText (g, b, textBounds); + } + + public virtual void DrawPopupButtonBackground (Graphics g, Button button, Rectangle clipArea) + { + if (button.Pressed) + ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor); + else if (button.Entered) + ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor); + else if (button.InternalSelected) + ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor); + else if (!button.Enabled) + ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor); + else + ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor); + } + + public virtual void DrawPopupButtonFocus (Graphics g, Button button) + { + // No changes from Standard for image for this theme + DrawButtonFocus (g, button); + } + + public virtual void DrawPopupButtonImage (Graphics g, Button button, Rectangle imageBounds) + { + // No changes from Standard for image for this theme + DrawButtonImage (g, button, imageBounds); + } + + public virtual void DrawPopupButtonText (Graphics g, Button button, Rectangle textBounds) + { + // No changes from Standard for image for this theme + DrawButtonText (g, button, textBounds); + } + #endregion + + #region Button Layout Calculations + public override void CalculateButtonTextAndImageLayout (Button button, out Rectangle textRectangle, out Rectangle imageRectangle) + { + Image image = button.Image; + string text = button.Text; + Rectangle content_rect = button.ClientRectangle; + Size text_size = TextRenderer.MeasureTextInternal (text, button.Font, content_rect.Size, button.TextFormatFlags, button.UseCompatibleTextRendering); + Size image_size = image == null ? Size.Empty : image.Size; + + textRectangle = Rectangle.Empty; + imageRectangle = Rectangle.Empty; + + switch (button.TextImageRelation) { + case TextImageRelation.Overlay: + // Overlay is easy, text always goes here + textRectangle = Rectangle.Inflate (content_rect, -4, -4); + + if (button.Pressed) + textRectangle.Offset (1, 1); + + // Image is dependent on ImageAlign + if (image == null) + return; + + int image_x = 0; + int image_y = 0; + int image_height = image.Height; + int image_width = image.Width; + + switch (button.ImageAlign) { + case System.Drawing.ContentAlignment.TopLeft: + image_x = 5; + image_y = 5; + break; + case System.Drawing.ContentAlignment.TopCenter: + image_x = (content_rect.Width - image_width) / 2; + image_y = 5; + break; + case System.Drawing.ContentAlignment.TopRight: + image_x = content_rect.Width - image_width - 5; + image_y = 5; + break; + case System.Drawing.ContentAlignment.MiddleLeft: + image_x = 5; + image_y = (content_rect.Height - image_height) / 2; + break; + case System.Drawing.ContentAlignment.MiddleCenter: + image_x = (content_rect.Width - image_width) / 2; + image_y = (content_rect.Height - image_height) / 2; + break; + case System.Drawing.ContentAlignment.MiddleRight: + image_x = content_rect.Width - image_width - 4; + image_y = (content_rect.Height - image_height) / 2; + break; + case System.Drawing.ContentAlignment.BottomLeft: + image_x = 5; + image_y = content_rect.Height - image_height - 4; + break; + case System.Drawing.ContentAlignment.BottomCenter: + image_x = (content_rect.Width - image_width) / 2; + image_y = content_rect.Height - image_height - 4; + break; + case System.Drawing.ContentAlignment.BottomRight: + image_x = content_rect.Width - image_width - 4; + image_y = content_rect.Height - image_height - 4; + break; + default: + image_x = 5; + image_y = 5; + break; + } + + imageRectangle = new Rectangle (image_x, image_y, image_width, image_height); + break; + case TextImageRelation.ImageAboveText: + content_rect.Inflate (-4, -4); + LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle); + break; + case TextImageRelation.TextAboveImage: + content_rect.Inflate (-4, -4); + LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle); + break; + case TextImageRelation.ImageBeforeText: + content_rect.Inflate (-4, -4); + LayoutTextBeforeOrAfterImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle); + break; + case TextImageRelation.TextBeforeImage: + content_rect.Inflate (-4, -4); + LayoutTextBeforeOrAfterImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle); + break; + } + } + + private void LayoutTextBeforeOrAfterImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, System.Drawing.ContentAlignment textAlign, System.Drawing.ContentAlignment imageAlign, out Rectangle textRect, out Rectangle imageRect) + { + int element_spacing = 0; // Spacing between the Text and the Image + int total_width = textSize.Width + element_spacing + imageSize.Width; - // First, draw the image - if (button.FlatStyle != FlatStyle.System && ((button.image != null) || (button.image_list != null))) - ButtonBase_DrawImage(button, dc); + if (!textFirst) + element_spacing += 2; + + // If the text is too big, chop it down to the size we have available to it + if (total_width > totalArea.Width) { + textSize.Width = totalArea.Width - element_spacing - imageSize.Width; + total_width = totalArea.Width; + } + int excess_width = totalArea.Width - total_width; + int offset = 0; + + Rectangle final_text_rect; + Rectangle final_image_rect; + + HorizontalAlignment h_text = GetHorizontalAlignment (textAlign); + HorizontalAlignment h_image = GetHorizontalAlignment (imageAlign); + + if (h_image == HorizontalAlignment.Left) + offset = 0; + else if (h_image == HorizontalAlignment.Right && h_text == HorizontalAlignment.Right) + offset = excess_width; + else if (h_image == HorizontalAlignment.Center && (h_text == HorizontalAlignment.Left || h_text == HorizontalAlignment.Center)) + offset += (int)(excess_width / 3); + else + offset += (int)(2 * (excess_width / 3)); + + if (textFirst) { + final_text_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height); + final_image_rect = new Rectangle (final_text_rect.Right + element_spacing, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height); + } + else { + final_image_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height); + final_text_rect = new Rectangle (final_image_rect.Right + element_spacing, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height); + } + + textRect = final_text_rect; + imageRect = final_image_rect; + } + + private void LayoutTextAboveOrBelowImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, System.Drawing.ContentAlignment textAlign, System.Drawing.ContentAlignment imageAlign, 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) { + final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, totalArea.Top + offset, textSize.Width, textSize.Height); + 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); + final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, final_image_rect.Bottom + element_spacing, textSize.Width, textSize.Height); + + if (final_text_rect.Bottom > totalArea.Bottom) + final_text_rect.Y = totalArea.Top; + } + + textRect = final_text_rect; + imageRect = final_image_rect; + } + + private HorizontalAlignment GetHorizontalAlignment (System.Drawing.ContentAlignment align) + { + switch (align) { + case System.Drawing.ContentAlignment.BottomLeft: + case System.Drawing.ContentAlignment.MiddleLeft: + case System.Drawing.ContentAlignment.TopLeft: + return HorizontalAlignment.Left; + case System.Drawing.ContentAlignment.BottomCenter: + case System.Drawing.ContentAlignment.MiddleCenter: + case System.Drawing.ContentAlignment.TopCenter: + return HorizontalAlignment.Center; + case System.Drawing.ContentAlignment.BottomRight: + case System.Drawing.ContentAlignment.MiddleRight: + case System.Drawing.ContentAlignment.TopRight: + return HorizontalAlignment.Right; + } + + return HorizontalAlignment.Left; + } + + private enum VerticalAlignment + { + Top = 0, + Center = 1, + Bottom = 2 + } + + private VerticalAlignment GetVerticalAlignment (System.Drawing.ContentAlignment align) + { + switch (align) { + case System.Drawing.ContentAlignment.TopLeft: + case System.Drawing.ContentAlignment.TopCenter: + case System.Drawing.ContentAlignment.TopRight: + return VerticalAlignment.Top; + case System.Drawing.ContentAlignment.MiddleLeft: + case System.Drawing.ContentAlignment.MiddleCenter: + case System.Drawing.ContentAlignment.MiddleRight: + return VerticalAlignment.Center; + case System.Drawing.ContentAlignment.BottomLeft: + case System.Drawing.ContentAlignment.BottomCenter: + case System.Drawing.ContentAlignment.BottomRight: + return VerticalAlignment.Bottom; + } + + return VerticalAlignment.Top; + } + + internal Rectangle AlignInRectangle (Rectangle outer, Size inner, System.Drawing.ContentAlignment align) + { + int x = 0; + int y = 0; + + if (align == System.Drawing.ContentAlignment.BottomLeft || align == System.Drawing.ContentAlignment.MiddleLeft || align == System.Drawing.ContentAlignment.TopLeft) + x = outer.X; + else if (align == System.Drawing.ContentAlignment.BottomCenter || align == System.Drawing.ContentAlignment.MiddleCenter || align == System.Drawing.ContentAlignment.TopCenter) + x = Math.Max (outer.X + ((outer.Width - inner.Width) / 2), outer.Left); + else if (align == System.Drawing.ContentAlignment.BottomRight || align == System.Drawing.ContentAlignment.MiddleRight || align == System.Drawing.ContentAlignment.TopRight) + x = outer.Right - inner.Width; + if (align == System.Drawing.ContentAlignment.TopCenter || align == System.Drawing.ContentAlignment.TopLeft || align == System.Drawing.ContentAlignment.TopRight) + y = outer.Y; + else if (align == System.Drawing.ContentAlignment.MiddleCenter || align == System.Drawing.ContentAlignment.MiddleLeft || align == System.Drawing.ContentAlignment.MiddleRight) + y = outer.Y + (outer.Height - inner.Height) / 2; + else if (align == System.Drawing.ContentAlignment.BottomCenter || align == System.Drawing.ContentAlignment.BottomRight || align == System.Drawing.ContentAlignment.BottomLeft) + y = outer.Bottom - inner.Height; + + return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height)); + } + #endregion + #endregion + + #region ButtonBase + public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) + { // Draw the button: Draw border, etc. ButtonBase_DrawButton(button, dc); + + // Draw the image + if (button.FlatStyle != FlatStyle.System && ((button.image != null) || (button.image_list != null))) + ButtonBase_DrawImage(button, dc); // Draw the focus rectangle if ((button.Focused || button.paint_as_acceptbutton) && button.Enabled) @@ -278,7 +701,7 @@ namespace System.Windows.Forms int height = button.ClientSize.Height; if (button.ImageIndex != -1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null - i = button.image_list.Images[button.image_index]; + i = button.image_list.Images[button.ImageIndex]; } else { i = button.image; } @@ -286,7 +709,7 @@ namespace System.Windows.Forms image_width = i.Width; image_height = i.Height; - switch (button.image_alignment) { + switch (button.ImageAlign) { case ContentAlignment.TopLeft: { image_x = 5; image_y = 5; @@ -348,12 +771,14 @@ namespace System.Windows.Forms } } - if (button.Enabled) { - dc.DrawImage(i, image_x, image_y, image_width, image_height); - } - else { - CPDrawImageDisabled(dc, i, image_x, image_y, ColorControl); - } + dc.SetClip (new Rectangle(3, 3, width - 5, height - 5)); + + if (button.Enabled) + dc.DrawImage (i, image_x, image_y, image_width, image_height); + else + CPDrawImageDisabled (dc, i, image_x, image_y, ColorControl); + + dc.ResetClip (); } protected virtual void ButtonBase_DrawFocus(ButtonBase button, Graphics dc) @@ -420,9 +845,12 @@ namespace System.Windows.Forms checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size); text_format = new StringFormat(); - text_format.Alignment=StringAlignment.Near; - text_format.LineAlignment=StringAlignment.Center; - text_format.HotkeyPrefix = HotkeyPrefix.Show; + text_format.Alignment = StringAlignment.Near; + text_format.LineAlignment = StringAlignment.Center; + if (checkbox.ShowKeyboardCuesInternal) + text_format.HotkeyPrefix = HotkeyPrefix.Show; + else + text_format.HotkeyPrefix = HotkeyPrefix.Hide; /* Calculate the position of text and checkbox rectangle */ if (checkbox.appearance!=Appearance.Button) { @@ -826,6 +1254,58 @@ namespace System.Windows.Forms string_format.Dispose (); } + + public override void DrawFlatStyleComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) + { + Point[] arrow = new Point[3]; + Point P1; + Point P2; + Point P3; + int centerX; + int centerY; + int shiftX; + int shiftY; + Rectangle rect; + + rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2); + centerX=rect.Left+rect.Width/2; + centerY=rect.Top+rect.Height/2; + shiftX=Math.Max(1, rect.Width/8); + shiftY=Math.Max(1, rect.Height/8); + + if ((state & ButtonState.Pushed)!=0) { + shiftX++; + shiftY++; + } + + rect.Y-=shiftY; + centerY-=shiftY; + P1=new Point(rect.Left + 1, centerY); + P2=new Point(rect.Right - 1, centerY); + P3=new Point(centerX, rect.Bottom - 1); + + arrow[0]=P1; + arrow[1]=P2; + arrow[2]=P3; + + /* Draw the arrow */ + if ((state & ButtonState.Inactive)!=0) { + /* Move away from the shadow */ + arrow[0].X += 1; arrow[0].Y += 1; + arrow[1].X += 1; arrow[1].Y += 1; + arrow[2].X += 1; arrow[2].Y += 1; + + graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding); + + arrow[0]=P1; + arrow[1]=P2; + arrow[2]=P3; + + graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding); + } else { + graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding); + } + } #endregion ComboBox #region Datagrid @@ -900,10 +1380,10 @@ namespace System.Windows.Forms public override void DataGridPaintColumnHeaders (Graphics g, Rectangle clip, DataGrid grid) { - Rectangle columns_area = grid.columnhdrs_area; + Rectangle columns_area = grid.column_headers_area; if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { // Paint corner shared between row and column header - Rectangle rect_bloc = grid.columnhdrs_area; + Rectangle rect_bloc = grid.column_headers_area; rect_bloc.Width = grid.RowHeaderWidth; if (clip.IntersectsWith (rect_bloc)) { if (grid.VisibleColumnCount > 0) @@ -917,11 +1397,11 @@ namespace System.Windows.Forms } // Set unused area - Rectangle columnhdrs_area_complete = columns_area; - columnhdrs_area_complete.Width = grid.columnhdrs_maxwidth; + Rectangle column_headers_area_complete = columns_area; + column_headers_area_complete.Width = grid.column_headers_max_width; if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { - columnhdrs_area_complete.Width -= grid.RowHeaderWidth; + column_headers_area_complete.Width -= grid.RowHeaderWidth; } // Set column painting @@ -956,7 +1436,7 @@ namespace System.Windows.Forms g.Clip = prev_clip; - Rectangle not_usedarea = columnhdrs_area_complete; + Rectangle not_usedarea = column_headers_area_complete; not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width; not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height; g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea); @@ -971,7 +1451,7 @@ namespace System.Windows.Forms rect_row.Width = grid.ParentRowsArea.Width; rect_row.Height = (grid.CaptionFont.Height + 3); - object[] parentRows = grid.dataSourceStack.ToArray(); + object[] parentRows = grid.data_source_stack.ToArray(); Region current_clip; Region prev_clip = g.Clip; @@ -1410,6 +1890,7 @@ namespace System.Windows.Forms button_bounds.Inflate (-2,-2); if (!dtp.ShowUpDown) { ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal; + dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), dtp.drop_down_arrow_rect); this.CPDrawComboButton ( dc, dtp.drop_down_arrow_rect, @@ -1620,33 +2101,85 @@ namespace System.Windows.Forms #endregion // Label #region LinkLabel - public override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label) + + private Color LinkLabelGetPieceColor (LinkLabel label, LinkLabel.Piece piece, int i) + { + if (!label.Enabled) + return label.DisabledLinkColor; + + if (piece.link == null) + return label.ForeColor; + + if (!piece.link.Enabled) + return label.DisabledLinkColor; + + if (piece.link.Active) + return label.ActiveLinkColor; + + if ((label.LinkVisited && i == 0) || piece.link.Visited) + return label.VisitedLinkColor; + + return label.LinkColor; + } + + public override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label) { dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle); if (label.pieces == null) return; - for (int i = 0; i < label.pieces.Length; i ++) { - RectangleF clipf = new RectangleF (clip_rectangle.X, clip_rectangle.Y, - clip_rectangle.Width, clip_rectangle.Height); - RectangleF rectf = label.pieces[i].region.GetBounds (dc); + // Paint all text as disabled. + if (!label.Enabled) { + dc.SetClip (clip_rectangle); + CPDrawStringDisabled (dc, label.Text, label.Font, label.BackColor, label.ClientRectangle, label.string_format); + return; + } + + Font font, link_font = GetLinkFont (label); + + Region text_region = new Region (new Rectangle()); - if (!clipf.IntersectsWith (rectf)) + // Draw links. + for (int i = 0; i < label.pieces.Length; i ++) { + LinkLabel.Piece piece = label.pieces[i]; + + if (piece.link == null) { + text_region.Union (piece.region); continue; + } - dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (label.GetPieceColor (label.pieces[i], i)), - rectf, label.string_format); + Color color = LinkLabelGetPieceColor (label, piece, i); - LinkLabel.Link link = label.pieces[i].link; - if (link != null && link.Focused) { - Rectangle rect = new Rectangle ((int)rectf.X, (int)rectf.Y, - (int)rectf.Width, (int)rectf.Height); - CPDrawFocusRectangle (dc, rect, label.ForeColor, label.BackColor); + if ( (label.LinkBehavior == LinkBehavior.AlwaysUnderline) || + (label.LinkBehavior == LinkBehavior.SystemDefault) || + ((label.LinkBehavior == LinkBehavior.HoverUnderline) && piece.link.Hovered) ) + font = link_font; + else + font = label.Font; + + dc.Clip = piece.region; + dc.Clip.Intersect (clip_rectangle); + dc.DrawString (label.Text, font, ResPool.GetSolidBrush (color), label.ClientRectangle, label.string_format); + + // Draw focus rectangle + if ((piece.link != null) && piece.link.Focused) { + foreach (RectangleF rect in piece.region.GetRegionScans (dc.Transform)) + ControlPaint.DrawFocusRectangle (dc, Rectangle.Round (rect), label.ForeColor, label.BackColor); } } + + // Draw normal text (without links). + if (!text_region.IsEmpty (dc)) { + dc.Clip = text_region; + dc.Clip.Intersect (clip_rectangle); + if (!dc.Clip.IsEmpty (dc)) + dc.DrawString(label.Text, label.Font, ResPool.GetSolidBrush(label.ForeColor), label.ClientRectangle, label.string_format); + } } + #endregion // LinkLabel + #region ListBox public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e) @@ -1721,7 +2254,7 @@ namespace System.Windows.Forms } // Draw corner between the two scrollbars - if (control.h_scroll.Visible == true && control.h_scroll.Visible == true) { + if (control.h_scroll.Visible == true && control.v_scroll.Visible == true) { Rectangle rect = new Rectangle (); rect.X = control.h_scroll.Location.X + control.h_scroll.Width; rect.Width = control.v_scroll.Width; @@ -1742,7 +2275,7 @@ namespace System.Windows.Forms // border is drawn directly in the Paint method if (details && control.HeaderStyle != ColumnHeaderStyle.None) { - dc.FillRectangle (GetControlBackBrush (control.BackColor), + dc.FillRectangle (SystemBrushes.Control, 0, 0, control.TotalWidth, control.Font.Height + 5); if (control.Columns.Count > 0) { foreach (ColumnHeader col in control.Columns) { @@ -1754,15 +2287,16 @@ namespace System.Windows.Forms else state = ButtonState.Flat; this.CPDrawButton (dc, rect, state); - rect.X += 3; - rect.Width -= 8; + rect.X += 8; + rect.Width -= 13; if (rect.Width <= 0) continue; + dc.DrawString (col.Text, DefaultFont, SystemBrushes.ControlText, rect, col.Format); } - int right = control.Columns [control.Columns.Count - 1].Rect.Right - control.h_marker; + int right = control.GetReorderedColumn (control.Columns.Count - 1).Rect.Right - control.h_marker; if (right < control.Right) { Rectangle rect = control.Columns [0].Rect; rect.X = right; @@ -1795,22 +2329,17 @@ namespace System.Windows.Forms protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item) { - int col_offset; - if (control.View == View.Details && control.Columns.Count > 0) - col_offset = control.Columns [0].Rect.X; - else - col_offset = 0; - Rectangle rect_checkrect = item.CheckRectReal; - rect_checkrect.X += col_offset; Rectangle icon_rect = item.GetBounds (ItemBoundsPortion.Icon); - icon_rect.X += col_offset; Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire); - full_rect.X += col_offset; Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label); - text_rect.X += col_offset; +#if NET_2_0 + // Tile view doesn't support CheckBoxes + if (control.CheckBoxes && control.View != View.Tile) { +#else if (control.CheckBoxes) { +#endif if (control.StateImageList == null) { // Make sure we've got at least a line width of 1 int check_wd = Math.Max (3, rect_checkrect.Width / 6); @@ -1833,31 +2362,42 @@ namespace System.Windows.Forms // adjustments to get the check-mark at the right place rect.X ++; rect.Y ++; // following logic is taken from DrawFrameControl method + int x_offset = rect.Width / 5; + int y_offset = rect.Height / 3; for (int i = 0; i < check_wd; i++) { - dc.DrawLine (check_pen, rect.Left + check_wd / 2, - rect.Top + check_wd + i, - rect.Left + check_wd / 2 + 2 * scale, - rect.Top + check_wd + 2 * scale + i); + dc.DrawLine (check_pen, rect.Left + x_offset, + rect.Top + y_offset + i, + rect.Left + x_offset + 2 * scale, + rect.Top + y_offset + 2 * scale + i); dc.DrawLine (check_pen, - rect.Left + check_wd / 2 + 2 * scale, - rect.Top + check_wd + 2 * scale + i, - rect.Left + check_wd / 2 + 6 * scale, - rect.Top + check_wd - 2 * scale + i); + rect.Left + x_offset + 2 * scale, + rect.Top + y_offset + 2 * scale + i, + rect.Left + x_offset + 6 * scale, + rect.Top + y_offset - 2 * scale + i); } } } else { - if (item.Checked && control.StateImageList.Images.Count > 1) - control.StateImageList.Draw (dc, - rect_checkrect.Location, 1); - else if (! item.Checked && control.StateImageList.Images.Count > 0) - control.StateImageList.Draw (dc, - rect_checkrect.Location, 0); + int simage_idx; + if (item.Checked) +#if NET_2_0 + simage_idx = control.StateImageList.Images.Count > 1 ? 1 : -1; +#else + simage_idx = control.StateImageList.Images.Count > 1 ? 1 : 0; +#endif + else + simage_idx = control.StateImageList.Images.Count > 0 ? 0 : -1; + + if (simage_idx > -1) + control.StateImageList.Draw (dc, rect_checkrect.Location, simage_idx); } } - ImageList image_list = control.View == View.LargeIcon ? control.LargeImageList : - control.SmallImageList; + ImageList image_list = control.View == View.LargeIcon +#if NET_2_0 + || control.View == View.Tile +#endif + ? control.LargeImageList : control.SmallImageList; if (image_list != null) { int idx; @@ -1875,7 +2415,7 @@ namespace System.Windows.Forms // draw the item text // format for the item text StringFormat format = new StringFormat (); - if (control.View == View.SmallIcon) + if (control.View == View.SmallIcon || control.View == View.LargeIcon) format.LineAlignment = StringAlignment.Near; else format.LineAlignment = StringAlignment.Center; @@ -1888,11 +2428,21 @@ namespace System.Windows.Forms format.FormatFlags = StringFormatFlags.LineLimit; else format.FormatFlags = StringFormatFlags.NoWrap; - + + if ((control.View == View.LargeIcon && !item.Focused) + || control.View == View.Details +#if NET_2_0 + || control.View == View.Tile +#endif + ) + format.Trimming = StringTrimming.EllipsisCharacter; + Rectangle highlight_rect = text_rect; - if (control.View == View.Details && !control.FullRowSelect) { + if (control.View == View.Details) { // Adjustments for Details view Size text_size = Size.Ceiling (dc.MeasureString (item.Text, item.Font)); - highlight_rect.Width = text_size.Width + 4; + + if (!control.FullRowSelect) // Selection shouldn't be outside the item bounds + highlight_rect.Width = Math.Min (text_size.Width + 4, text_rect.Width); } if (item.Selected && control.Focused) @@ -1907,11 +2457,30 @@ namespace System.Windows.Forms (item.Selected && control.Focused) ? SystemBrushes.HighlightText : this.ResPool.GetSolidBrush (item.ForeColor); - if (item.Text != null && item.Text.Length > 0) { - if (item.Selected && control.Focused) - dc.DrawString (item.Text, item.Font, textBrush, highlight_rect, format); - else - dc.DrawString (item.Text, item.Font, textBrush, text_rect, format); +#if NET_2_0 + // Tile view renders its Text in a different fashion + if (control.View == View.Tile) { + // Item.Text is drawn using its first subitem's bounds + dc.DrawString (item.Text, item.Font, textBrush, item.SubItems [0].Bounds, format); + + int count = Math.Min (control.Columns.Count, item.SubItems.Count); + for (int i = 1; i < count; i++) { + ListViewItem.ListViewSubItem sub_item = item.SubItems [i]; + if (sub_item.Text == null || sub_item.Text.Length == 0) + continue; + + Brush itemBrush = item.Selected && control.Focused ? + SystemBrushes.HighlightText : GetControlForeBrush (sub_item.ForeColor); + dc.DrawString (sub_item.Text, sub_item.Font, itemBrush, sub_item.Bounds, format); + } + } else +#endif + + if (item.Text != null && item.Text.Length > 0) { + if (item.Selected && control.Focused) + dc.DrawString (item.Text, item.Font, textBrush, highlight_rect, format); + else + dc.DrawString (item.Text, item.Font, textBrush, text_rect, format); } if (control.View == View.Details && control.Columns.Count > 0) { @@ -1953,6 +2522,12 @@ namespace System.Windows.Forms sub_item_font = subItem.Font; } + int sub_item_text_width = (int) Math.Ceiling (control.DeviceContext.MeasureString (subItem.Text, + sub_item_font).Width); + + format.Trimming = sub_item_text_width > sub_item_text_rect.Width ? StringTrimming.EllipsisCharacter : + StringTrimming.None; + if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) { Brush bg, text; if (control.Focused) { @@ -1991,7 +2566,7 @@ namespace System.Windows.Forms } } } - + if (item.Focused && control.Focused) { Rectangle focus_rect = highlight_rect; if (control.FullRowSelect && control.View == View.Details) { @@ -2041,9 +2616,18 @@ namespace System.Windows.Forms public override int ListViewGroupHeight { get { return 20; } } + + public override int ListViewTileWidthFactor { + get { return 22; } + } + + public override int ListViewTileHeightFactor { + get { return 3; } + } #endregion // ListView #region Menus + public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar) { item.X = x; @@ -2129,7 +2713,7 @@ namespace System.Windows.Forms menu.Height = 0; while (start < menu.MenuItems.Count) { - y = 2; + y = 3; max = 0; for (i = start; i < menu.MenuItems.Count; i++) { MenuItem item = menu.MenuItems [i]; @@ -2161,7 +2745,7 @@ namespace System.Windows.Forms menu.Height += 2; menu.Width += SM_CXBORDER; - menu.Height += SM_CYBORDER; + menu.Height += SM_CYBORDER; } // Draws a menu bar in a window @@ -2170,8 +2754,8 @@ namespace System.Windows.Forms if (menu.Height == 0) CalcMenuBarSize (dc, menu, rect.Width); - bool keynav = (menu as MainMenu).tracker.Navigating; - HotkeyPrefix hp = always_draw_hotkeys || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide; + bool keynav = (menu as MainMenu).tracker.hotkey_active; + HotkeyPrefix hp = MenuAccessKeysUnderlined || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide; string_format_menu_menubar_text.HotkeyPrefix = hp; string_format_menu_text.HotkeyPrefix = hp; @@ -2195,6 +2779,7 @@ namespace System.Windows.Forms bg_color = Color.White; else bg_color = Color.Black; + Bitmap bmp = new Bitmap (size.Width, size.Height); Graphics gr = Graphics.FromImage (bmp); Rectangle rect = new Rectangle (Point.Empty, size); @@ -2202,6 +2787,7 @@ namespace System.Windows.Forms CPDrawMenuGlyph (gr, rect, glyph, color); bmp.MakeTransparent (bg_color); gr.Dispose (); + return bmp; } @@ -2236,8 +2822,8 @@ namespace System.Windows.Forms if (item.BarBreak) { /* Draw vertical break bar*/ Rectangle rect = e.Bounds; rect.Y++; - rect.Width = 3; - rect.Height = item.MenuHeight - 6; + rect.Width = 3; + rect.Height = item.MenuHeight - 6; e.Graphics.DrawLine (SystemPens.ControlDark, rect.X, rect.Y , rect.X, rect.Y + rect.Height); @@ -2264,11 +2850,8 @@ namespace System.Windows.Forms } /* Draw background */ - Rectangle rect_back = e.Bounds; - rect_back.X++; - rect_back.Width -=2; if (!item.MenuBar) - e.Graphics.FillRectangle (brush_back, rect_back); + e.Graphics.FillRectangle (brush_back, e.Bounds); if (item.Enabled) { e.Graphics.DrawString (item.Text, e.Font, @@ -2293,7 +2876,7 @@ namespace System.Windows.Forms border_style = Border3DStyle.SunkenOuter; if (border_style != Border3DStyle.Adjust) - CPDrawBorder3D(e.Graphics, rect_back, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu); + CPDrawBorder3D(e.Graphics, e.Bounds, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu); } } else { if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) { @@ -2339,38 +2922,19 @@ namespace System.Windows.Forms public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect) { - + // Fill rectangle area dc.FillRectangle (SystemBrushes.Menu, cliparea); - Pen pen_cht = SystemPens.HighlightText; - Pen pen_ccd = SystemPens.ControlDark; - Pen pen_ccdd = SystemPens.ControlDarkDark; - - /* Draw menu borders */ - dc.DrawLine (pen_cht, - rect.X, rect.Y, rect.X + rect.Width, rect.Y); - - dc.DrawLine (pen_cht, - rect.X, rect.Y, rect.X, rect.Y + rect.Height); - - dc.DrawLine (pen_ccd, - rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height); - - dc.DrawLine (pen_ccdd, - rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height); - - dc.DrawLine (pen_ccd, - rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1); - - dc.DrawLine (pen_ccdd, - rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height); - - for (int i = 0; i < menu.MenuItems.Count; i++) + // Draw menu borders + CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides); + + // Draw menu items + for (int i = 0; i < menu.MenuItems.Count; i++) { if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) { MenuItem item = menu.MenuItems [i]; item.MenuHeight = menu.Height; - item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, - item.bounds, i, item.Status)); + item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item.bounds, i, item.Status)); + } } } @@ -2534,6 +3098,22 @@ namespace System.Windows.Forms string title_text = this_month.ToString ("MMMM yyyy"); dc.DrawString (title_text, mc.bold_font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, mc.centered_format); + if (mc.ShowYearUpDown) { + Rectangle year_rect; + Rectangle upRect, downRect; + ButtonState upState, downState; + + mc.GetYearNameRectangles (title_rect, row * mc.CalendarDimensions.Width + col, out year_rect, out upRect, out downRect); + dc.FillRectangle (ResPool.GetSolidBrush (SystemColors.Control), year_rect); + dc.DrawString (this_month.ToString ("yyyy"), mc.bold_font, ResPool.GetSolidBrush (Color.Black), year_rect, mc.centered_format); + + upState = mc.IsYearGoingUp ? ButtonState.Pushed : ButtonState.Normal; + downState = mc.IsYearGoingDown ? ButtonState.Pushed : ButtonState.Normal; + + ControlPaint.DrawScrollButton (dc, upRect, ScrollButton.Up, upState); + ControlPaint.DrawScrollButton (dc, downRect, ScrollButton.Down, downState); + } + // draw previous and next buttons if it's time if (row == 0 && col == 0) { @@ -2873,6 +3453,20 @@ namespace System.Windows.Forms dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip); dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2)); break; +#if NET_2_0 + case PictureBoxSizeMode.Zoom: + dc.FillRectangle (GetControlBackBrush (pb.BackColor), clip); + + Size image_size; + + if (((float)pb.Image.Width / (float)pb.Image.Height) >= ((float)client.Width / (float)client.Height)) + image_size = new Size (client.Width, (pb.Image.Height * client.Width) / pb.Image.Width); + else + image_size = new Size ((pb.Image.Width * client.Height) / pb.Image.Height, client.Height); + + dc.DrawImage (pb.Image, (client.Width / 2) - (image_size.Width / 2), (client.Height / 2) - (image_size.Height / 2), image_size.Width, image_size.Height); + break; +#endif default: dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip); // Normal, AutoSize @@ -2980,29 +3574,70 @@ namespace System.Windows.Forms #region ProgressBar public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl) { - Rectangle block_rect; - Rectangle client_area = ctrl.client_area; - int space_betweenblocks = 2; - int block_width; - int increment; - int barpos_pixels; + Rectangle client_area = ctrl.client_area; - block_width = (client_area.Height * 2 ) / 3; - barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum); - increment = block_width + space_betweenblocks; - /* Draw border */ CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl); /* Draw Blocks */ - block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height); - while ((block_rect.X - client_area.X) < barpos_pixels) { + int draw_mode = 0; + int max_blocks = int.MaxValue; + int start_pixel = client_area.X; +#if NET_2_0 + draw_mode = (int) ctrl.Style; +#endif + switch (draw_mode) { +#if NET_2_0 + case 1: { // Continuous + int pixels_to_draw; + pixels_to_draw = (int)(client_area.Width * ((double)(ctrl.Value - ctrl.Minimum) / (double)(ctrl.Maximum - ctrl.Minimum))); + dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), new Rectangle (client_area.X, client_area.Y, pixels_to_draw, client_area.Height)); + break; + } + case 2: // Marquee + if (XplatUI.ThemesEnabled) { + int ms_diff = (int) (DateTime.Now - ctrl.start).TotalMilliseconds; + double percent_done = (double) ms_diff % (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed; + max_blocks = 5; + start_pixel = client_area.X + (int) (client_area.Width * percent_done); + } - if (clip_rect.IntersectsWith (block_rect) == true) { - dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect); - } + goto case 0; +#endif + case 0: + default: // Blocks + Rectangle block_rect; + int space_betweenblocks = 2; + int block_width; + int increment; + int barpos_pixels; + int block_count = 0; + + block_width = (client_area.Height * 2) / 3; + barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum); + increment = block_width + space_betweenblocks; - block_rect.X += increment; + block_rect = new Rectangle (start_pixel, client_area.Y, block_width, client_area.Height); + while (true) { + if (max_blocks != int.MaxValue) { + if (block_count >= max_blocks) + break; + if (block_rect.X > client_area.Width) + block_rect.X -= client_area.Width; + } else { + if ((block_rect.X - client_area.X) >= barpos_pixels) + break; + } + + if (clip_rect.IntersectsWith (block_rect) == true) { + dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect); + } + + block_rect.X += increment; + block_count++; + } + break; + } } @@ -3221,6 +3856,7 @@ namespace System.Windows.Forms DrawInnerFocusRectangle( dc, text_rectangle, radio_button.BackColor ); } + // renders a radio button with the Flat and Popup FlatStyle protected virtual void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button) { @@ -3493,21 +4129,27 @@ namespace System.Windows.Forms #endregion // ScrollBar #region StatusBar - public override void DrawStatusBar (Graphics dc, Rectangle clip, StatusBar sb) { + public override void DrawStatusBar (Graphics real_dc, Rectangle clip, StatusBar sb) { Rectangle area = sb.ClientRectangle; int horz_border = 2; int vert_border = 2; + + Image backbuffer = new Bitmap (sb.ClientSize.Width, sb.ClientSize.Height, real_dc); + Graphics dc = Graphics.FromImage (backbuffer); bool is_color_control = sb.BackColor.ToArgb () == ColorControl.ToArgb (); Brush brush = is_color_control ? SystemBrushes.Control : ResPool.GetSolidBrush (sb.BackColor); dc.FillRectangle (brush, clip); - if (sb.Panels.Count == 0 && sb.Text != String.Empty) { + if (!sb.ShowPanels && sb.Text != String.Empty) { string text = sb.Text; StringFormat string_format = new StringFormat (); string_format.Trimming = StringTrimming.Character; string_format.FormatFlags = StringFormatFlags.NoWrap; + + if (text.Length > 127) + text = text.Substring (0, 127); if (text [0] == '\t') { string_format.Alignment = StringAlignment.Center; @@ -3538,6 +4180,10 @@ namespace System.Windows.Forms area = new Rectangle (area.Right - 16 - 2, area.Bottom - 12 - 1, 16, 16); CPDrawSizeGrip (dc, ColorControl, area); } + + real_dc.DrawImage (backbuffer, 0, 0); + dc.Dispose (); + backbuffer.Dispose (); } @@ -3627,7 +4273,10 @@ namespace System.Windows.Forms break; } + RectangleF clip_bounds = dc.ClipBounds; + dc.SetClip (area); dc.DrawString (text, panel.Parent.Font, br_forecolor, string_rect, string_format); + dc.SetClip (clip_bounds); if (panel.Icon != null) { dc.DrawIcon (panel.Icon, new Rectangle (icon_x, y, icon_width, icon_width)); @@ -3649,322 +4298,99 @@ namespace System.Windows.Forms } #endregion // StatusBar - public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab) - { - Brush brush = SystemBrushes.Control; - dc.FillRectangle (brush, area); - Rectangle panel_rect = GetTabPanelRectExt (tab); - - if (tab.Appearance == TabAppearance.Normal) { - CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorControl); - CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorControl); - } + #region TabControl - if (tab.Alignment == TabAlignment.Top) { - for (int r = tab.TabPages.Count; r > 0; r--) { - for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) { - if (i == tab.SelectedIndex) - continue; - if (r != tab.TabPages [i].Row) - continue; - Rectangle rect = tab.GetTabRect (i); - if (!rect.IntersectsWith (area)) - continue; - DrawTab (dc, tab.TabPages [i], tab, rect, false); - } - } - } else { - for (int r = 0; r < tab.TabPages.Count; r++) { - for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) { - if (i == tab.SelectedIndex) - continue; - if (r != tab.TabPages [i].Row) - continue; - Rectangle rect = tab.GetTabRect (i); - if (!rect.IntersectsWith (area)) - continue; - DrawTab (dc, tab.TabPages [i], tab, rect, false); - } - } - } + #region TabControl settings - if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) { - Rectangle rect = tab.GetTabRect (tab.SelectedIndex); - if (rect.IntersectsWith (area)) - DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true); - } + public override Size TabControlDefaultItemSize { + get { return ThemeElements.CurrentTheme.TabControlPainter.DefaultItemSize; } + } - if (tab.ShowSlider) { - Rectangle right = GetTabControlRightScrollRect (tab); - Rectangle left = GetTabControlLeftScrollRect (tab); - CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState); - CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState); - } + public override Point TabControlDefaultPadding { + get { return ThemeElements.CurrentTheme.TabControlPainter.DefaultPadding; } } - public override Rectangle GetTabControlLeftScrollRect (TabControl tab) - { - switch (tab.Alignment) { - case TabAlignment.Top: - return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17); - default: - Rectangle panel_rect = GetTabPanelRectExt (tab); - return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17); - } + public override int TabControlMinimumTabWidth { + get { return ThemeElements.CurrentTheme.TabControlPainter.MinimumTabWidth; } } - public override Rectangle GetTabControlRightScrollRect (TabControl tab) - { - switch (tab.Alignment) { - case TabAlignment.Top: - return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17); - default: - Rectangle panel_rect = GetTabPanelRectExt (tab); - return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17); - } + public override Rectangle TabControlSelectedDelta { + get { return ThemeElements.CurrentTheme.TabControlPainter.SelectedTabDelta; } } - public override Size TabControlDefaultItemSize { - get { return new Size (42, 21); } + public override int TabControlSelectedSpacing { + get { return ThemeElements.CurrentTheme.TabControlPainter.SelectedSpacing; } + } + + public override int TabPanelOffsetX { + get { return ThemeElements.CurrentTheme.TabControlPainter.TabPanelOffset.X; } + } + + public override int TabPanelOffsetY { + get { return ThemeElements.CurrentTheme.TabControlPainter.TabPanelOffset.Y; } } - public override Point TabControlDefaultPadding { - get { return new Point (6, 3); } + public override int TabControlColSpacing { + get { return ThemeElements.CurrentTheme.TabControlPainter.ColSpacing; } } - public override int TabControlMinimumTabWidth { - get { return 42; } + public override Point TabControlImagePadding { + get { return ThemeElements.CurrentTheme.TabControlPainter.ImagePadding; } } - public override Rectangle GetTabControlDisplayRectangle (TabControl tab) - { - Rectangle ext = GetTabPanelRectExt (tab); - // Account for border size - return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4); - } - - public override Size TabControlGetSpacing (TabControl tab) { - switch (tab.Appearance) { - case TabAppearance.Normal: - return new Size (1, -2); - case TabAppearance.Buttons: - return new Size (3, 3); - case TabAppearance.FlatButtons: - return new Size (9, 3); - default: - throw new Exception ("Invalid Appearance value: " + tab.Appearance); - } + public override int TabControlScrollerWidth { + get {return ThemeElements.CurrentTheme.TabControlPainter.ScrollerWidth; } } - protected virtual Rectangle GetTabPanelRectExt (TabControl tab) + + public override Size TabControlGetSpacing (TabControl tab) { - // Offset the tab from the top corner - Rectangle res = new Rectangle (tab.ClientRectangle.X + 2, - tab.ClientRectangle.Y, - tab.ClientRectangle.Width - 2, - tab.ClientRectangle.Height - 1); - - if (tab.TabCount == 0) - return res; - - int spacing = TabControlGetSpacing (tab).Height; - int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3; - - switch (tab.Alignment) { - case TabAlignment.Left: - res.X += offset; - res.Width -= offset; - break; - case TabAlignment.Right: - res.Width -= offset; - break; - case TabAlignment.Top: - res.Y += offset; - res.Height -= offset; - break; - case TabAlignment.Bottom: - res.Height -= offset; - break; + try { + return ThemeElements.CurrentTheme.TabControlPainter.RowSpacing (tab); + } catch { + throw new Exception ("Invalid Appearance value: " + tab.Appearance); } - - return res; } + #endregion - protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected) + public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab) { - int FlatButtonSpacing = 8; - Rectangle interior; - int res = bounds.Width; - - - - // we can't fill the background right away because the bounds might be adjusted if the tab is selected - - StringFormat string_format = new StringFormat (); - if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) { - dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds); - - // Separators - if (tab.Appearance == TabAppearance.FlatButtons) { - int width = bounds.Width; - bounds.Width += (FlatButtonSpacing - 2); - res = bounds.Width; - CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right); - bounds.Width = width; - } - - if (is_selected) { - CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom); - } else if (tab.Appearance != TabAppearance.FlatButtons) { - CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom); - } - - interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4); - - - string_format.Alignment = StringAlignment.Center; - string_format.LineAlignment = StringAlignment.Center; - string_format.FormatFlags = StringFormatFlags.NoWrap; - } else { - CPColor cpcolor = ResPool.GetCPColor (tab.BackColor); - - Pen light = ResPool.GetPen (cpcolor.LightLight); - - switch (tab.Alignment) { - - case TabAlignment.Top: - - dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds); - - dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3); - dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top); - dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top); - - dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom); - dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3); - dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom); - - interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8); - - string_format.Alignment = StringAlignment.Center; - string_format.LineAlignment = StringAlignment.Center; - string_format.FormatFlags = StringFormatFlags.NoWrap; - - break; - - case TabAlignment.Bottom: - - dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds); - - dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3); - dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1); - - dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1); - dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top); - - dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom); - dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3); - dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top); - - interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8); - - string_format.Alignment = StringAlignment.Center; - string_format.LineAlignment = StringAlignment.Center; - string_format.FormatFlags = StringFormatFlags.NoWrap; - - break; - - case TabAlignment.Left: - - dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds); - - dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3); - dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top); - dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top); - - dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1); - - dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom); - dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3); - - interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8); - - string_format.Alignment = StringAlignment.Center; - string_format.LineAlignment = StringAlignment.Center; - string_format.FormatFlags = StringFormatFlags.NoWrap; - string_format.FormatFlags = StringFormatFlags.DirectionVertical; - - break; - - default: - // TabAlignment.Right - - dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds); - - dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top); - dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3); - - dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1); - dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1); - - dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3); - dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom); - - interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8); - - string_format.Alignment = StringAlignment.Center; - string_format.LineAlignment = StringAlignment.Center; - string_format.FormatFlags = StringFormatFlags.NoWrap; - string_format.FormatFlags = StringFormatFlags.DirectionVertical; - - break; - } - } + ThemeElements.CurrentTheme.TabControlPainter.Draw (dc, area, tab); + } - if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) { - if (tab.Alignment == TabAlignment.Left) { - int wo = interior.Width / 2; - int ho = interior.Height / 2; - dc.TranslateTransform (interior.X + wo, interior.Y + ho); - dc.RotateTransform (180); - dc.DrawString (page.Text, page.Font, SystemBrushes.ControlText, 0, 0, string_format); - dc.ResetTransform (); - } else { - Rectangle str_rect = interior; + public override Rectangle TabControlGetLeftScrollRect (TabControl tab) + { + return ThemeElements.CurrentTheme.TabControlPainter.GetLeftScrollRect (tab); + } - if (tab.ImageList != null && page.ImageIndex >= 0 && page.ImageIndex < tab.ImageList.Images.Count) { - tab.ImageList.Draw (dc, new Point (interior.X, interior.Y), page.ImageIndex); - str_rect.X += tab.ImageList.ImageSize.Width + 2; - str_rect.Width -= tab.ImageList.ImageSize.Width + 2; - } - dc.DrawString (page.Text, page.Font, - SystemBrushes.ControlText, - str_rect, string_format); - } - } else if (page.Text != null) { - DrawItemState state = DrawItemState.None; - if (page == tab.SelectedTab) - state |= DrawItemState.Selected; - DrawItemEventArgs e = new DrawItemEventArgs (dc, - tab.Font, bounds, tab.IndexForTabPage (page), - state, page.ForeColor, page.BackColor); - tab.OnDrawItemInternal (e); - return res; - } + public override Rectangle TabControlGetRightScrollRect (TabControl tab) + { + return ThemeElements.CurrentTheme.TabControlPainter.GetRightScrollRect (tab); + } - if (page.Parent.Focused && is_selected) { - CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor); - } + public override Rectangle TabControlGetDisplayRectangle (TabControl tab) + { + return ThemeElements.CurrentTheme.TabControlPainter.GetDisplayRectangle (tab); + } - return res; + public override Rectangle TabControlGetPanelRect (TabControl tab) + { + return ThemeElements.CurrentTheme.TabControlPainter.GetTabPanelRect (tab); } + #endregion + #region ToolBar public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control) { StringFormat format = new StringFormat (); format.Trimming = StringTrimming.EllipsisCharacter; format.LineAlignment = StringAlignment.Center; + if (control.ShowKeyboardCuesInternal) + format.HotkeyPrefix = HotkeyPrefix.Show; + else + format.HotkeyPrefix = HotkeyPrefix.Hide; + if (control.TextAlign == ToolBarTextAlign.Underneath) format.Alignment = StringAlignment.Center; else @@ -4009,93 +4435,93 @@ namespace System.Windows.Forms } } - foreach (ToolBarButton button in control.Buttons) - if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle)) - DrawToolBarButton (dc, control, button, format); + foreach (ToolBarItem item in control.items) + if (item.Button.Visible && clip_rectangle.IntersectsWith (item.Rectangle)) + DrawToolBarButton (dc, control, item, format); format.Dispose (); } - protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format) + protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format) { - bool is_flat = control.Appearance == ToolBarAppearance.Flat; - - DrawToolBarButtonBorder (dc, button, is_flat); + bool is_flat = (control.Appearance == ToolBarAppearance.Flat); + + DrawToolBarButtonBorder (dc, item, is_flat); - switch (button.Style) { + switch (item.Button.Style) { case ToolBarButtonStyle.DropDownButton: if (control.DropDownArrows) - DrawToolBarDropDownArrow (dc, button, is_flat); - DrawToolBarButtonContents (dc, control, button, format); + DrawToolBarDropDownArrow (dc, item, is_flat); + DrawToolBarButtonContents (dc, control, item, format); break; case ToolBarButtonStyle.Separator: if (is_flat) - DrawToolBarSeparator (dc, button); + DrawToolBarSeparator (dc, item); break; case ToolBarButtonStyle.ToggleButton: - DrawToolBarToggleButtonBackground (dc, button); - DrawToolBarButtonContents (dc, control, button, format); + DrawToolBarToggleButtonBackground (dc, item); + DrawToolBarButtonContents (dc, control, item, format); break; default: - DrawToolBarButtonContents (dc, control, button, format); + DrawToolBarButtonContents (dc, control, item, format); break; } } const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom; - protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarButton button, bool is_flat) + protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarItem item, bool is_flat) { - if (button.Style == ToolBarButtonStyle.Separator) + if (item.Button.Style == ToolBarButtonStyle.Separator) return; Border3DStyle style; if (is_flat) { - if (button.Pushed || button.Pressed) + if (item.Button.Pushed || item.Pressed) style = Border3DStyle.SunkenOuter; - else if (button.Hilight) + else if (item.Hilight) style = Border3DStyle.RaisedInner; else return; } else { - if (button.Pushed || button.Pressed) + if (item.Button.Pushed || item.Pressed) style = Border3DStyle.Sunken; else style = Border3DStyle.Raised; } - Rectangle rect = button.Rectangle; - if ((button.Style == ToolBarButtonStyle.DropDownButton) && (button.Parent.DropDownArrows) && is_flat) + Rectangle rect = item.Rectangle; + if ((item.Button.Style == ToolBarButtonStyle.DropDownButton) && (item.Button.Parent.DropDownArrows) && is_flat) rect.Width -= ToolBarDropDownWidth; CPDrawBorder3D (dc, rect, style, all_sides); } - protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarButton button) + protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarItem item) { - Rectangle area = button.Rectangle; + Rectangle area = item.Rectangle; int offset = (int) SystemPens.Control.Width + 1; dc.DrawLine (SystemPens.ControlDark, area.X + 1, area.Y, area.X + 1, area.Bottom); dc.DrawLine (SystemPens.ControlLight, area.X + offset, area.Y, area.X + offset, area.Bottom); } - protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarButton button) + protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarItem item) { Brush brush; - Rectangle area = button.Rectangle; + Rectangle area = item.Rectangle; area.X += ToolBarImageGripWidth; area.Y += ToolBarImageGripWidth; area.Width -= 2 * ToolBarImageGripWidth; area.Height -= 2 * ToolBarImageGripWidth; - if (button.Pushed) + if (item.Button.Pushed) brush = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, ColorControlLightLight); - else if (button.PartialPush) + else if (item.Button.PartialPush) brush = SystemBrushes.ControlLight; else brush = SystemBrushes.Control; @@ -4103,23 +4529,23 @@ namespace System.Windows.Forms dc.FillRectangle (brush, area); } - protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat) + protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat) { - Rectangle rect = button.Rectangle; - rect.X = button.Rectangle.Right - ToolBarDropDownWidth; + Rectangle rect = item.Rectangle; + rect.X = item.Rectangle.Right - ToolBarDropDownWidth; rect.Width = ToolBarDropDownWidth; if (is_flat) { - if (button.dd_pressed) + if (item.DDPressed) CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides); - else if (button.Pushed || button.Pressed) + else if (item.Button.Pushed || item.Pressed) CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides); - else if (button.Hilight) + else if (item.Hilight) CPDrawBorder3D (dc, rect, Border3DStyle.RaisedInner, all_sides); } else { - if (button.dd_pressed) + if (item.DDPressed) CPDrawBorder3D (dc, rect, Border3DStyle.Flat, all_sides); - else if (button.Pushed || button.Pressed) + else if (item.Button.Pushed || item.Pressed) CPDrawBorder3D (dc, Rectangle.Inflate(rect, -1, -1), Border3DStyle.SunkenOuter, all_sides); else CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides); @@ -4129,7 +4555,7 @@ namespace System.Windows.Forms PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height / 2)); // Increase vertical and horizontal position by 1 when button is pressed - if (button.Pressed || button.Pushed || button.dd_pressed) { + if (item.Pressed || item.Button.Pushed || item.DDPressed) { ddCenter.X += 1; ddCenter.Y += 1; } @@ -4143,37 +4569,37 @@ namespace System.Windows.Forms dc.FillPolygon (SystemBrushes.ControlText, vertices); } - protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format) + protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format) { - if (button.Image != null) { - int x = button.ImageRectangle.X + ToolBarImageGripWidth; - int y = button.ImageRectangle.Y + ToolBarImageGripWidth; + if (item.Button.Image != null) { + int x = item.ImageRectangle.X + ToolBarImageGripWidth; + int y = item.ImageRectangle.Y + ToolBarImageGripWidth; // Increase vertical and horizontal position by 1 when button is pressed - if (button.Pressed || button.Pushed) { + if (item.Pressed || item.Button.Pushed) { x += 1; y += 1; } - if (button.Enabled) - dc.DrawImage (button.Image, x, y); + if (item.Button.Enabled) + dc.DrawImage (item.Button.Image, x, y); else - CPDrawImageDisabled (dc, button.Image, x, y, ColorControl); + CPDrawImageDisabled (dc, item.Button.Image, x, y, ColorControl); } - Rectangle text_rect = button.TextRectangle; + Rectangle text_rect = item.TextRectangle; if (text_rect.Width <= 0 || text_rect.Height <= 0) return; - if (button.Pressed || button.Pushed) { + if (item.Pressed || item.Button.Pushed) { text_rect.X += 1; text_rect.Y += 1; } - if (button.Enabled) - dc.DrawString (button.Text, control.Font, SystemBrushes.ControlText, text_rect, format); + if (item.Button.Enabled) + dc.DrawString (item.Button.Text, control.Font, SystemBrushes.ControlText, text_rect, format); else - CPDrawStringDisabled (dc, button.Text, control.Font, control.BackColor, text_rect, format); + CPDrawStringDisabled (dc, item.Button.Text, control.Font, control.BackColor, text_rect, format); } // Grip width for the ToolBar @@ -4212,28 +4638,281 @@ namespace System.Windows.Forms } } - public override bool ToolBarInvalidateEntireButton { - get { return false; } - } - #endregion // ToolBar #region ToolTip - public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) { + public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) + { + Rectangle text_rect = Rectangle.Inflate (control.ClientRectangle, -2, -1); + dc.FillRectangle(SystemBrushes.Info, control.ClientRectangle); dc.DrawRectangle(SystemPens.WindowFrame, 0, 0, control.Width-1, control.Height-1); - dc.DrawString(control.Text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.ClientRectangle, control.string_format); + dc.DrawString(control.Text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), text_rect, control.string_format); } - public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) { + public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) + { SizeF sizef; - sizef = tt.DeviceContext.MeasureString(text, tt.Font); + sizef = tt.DeviceContext.MeasureString(text, tt.Font, SizeF.Empty, tt.string_format); return new Size((int)sizef.Width+8, (int)sizef.Height+3); // Need space for the border } #endregion // ToolTip + #region BalloonWindow +#if NET_2_0 + NotifyIcon.BalloonWindow balloon_window; + + public override void ShowBalloonWindow (IntPtr handle, int timeout, string title, string text, ToolTipIcon icon) + { + Control control = Control.FromHandle(handle); + + if (control == null) + return; + + if (balloon_window != null) { + balloon_window.Close (); + balloon_window.Dispose (); + } + + balloon_window = new NotifyIcon.BalloonWindow (handle); + balloon_window.Title = title; + balloon_window.Text = text; + balloon_window.Icon = icon; + balloon_window.Timeout = timeout; + balloon_window.Show (); + } + + private const int balloon_iconsize = 16; + private const int balloon_bordersize = 8; + + public override void DrawBalloonWindow (Graphics dc, Rectangle clip, NotifyIcon.BalloonWindow control) + { + Brush solidbrush = ResPool.GetSolidBrush (this.ColorInfoText); + Rectangle rect = control.ClientRectangle; + int iconsize = (control.Icon == ToolTipIcon.None) ? 0 : balloon_iconsize; + + // Rectangle borders and background. + dc.FillRectangle (ResPool.GetSolidBrush (ColorInfo), rect); + dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), 0, 0, rect.Width - 1, rect.Height - 1); + + // Icon + Image image; + switch (control.Icon) { + case ToolTipIcon.Info: { + image = ThemeEngine.Current.Images(UIIcon.MessageBoxInfo, balloon_iconsize); + break; + } + + case ToolTipIcon.Warning: { + image = ThemeEngine.Current.Images(UIIcon.MessageBoxError, balloon_iconsize); + break; + } + + case ToolTipIcon.Error: { + image = ThemeEngine.Current.Images(UIIcon.MessageBoxWarning, balloon_iconsize); + break; + } + + default: { + image = null; + break; + } + } + + if (control.Icon != ToolTipIcon.None) + dc.DrawImage (image, new Rectangle (balloon_bordersize, balloon_bordersize, iconsize, iconsize)); + + // Title + Rectangle titlerect = new Rectangle (rect.X + balloon_bordersize + iconsize + (iconsize > 0 ? balloon_bordersize : 0), + rect.Y + balloon_bordersize, + rect.Width - ((3 * balloon_bordersize) + iconsize), + rect.Height - (2 * balloon_bordersize)); + + Font titlefont = new Font (control.Font.FontFamily, control.Font.Size, control.Font.Style | FontStyle.Bold, control.Font.Unit); + dc.DrawString (control.Title, titlefont, solidbrush, titlerect, control.Format); + + // Text + Rectangle textrect = new Rectangle (rect.X + balloon_bordersize, + rect.Y + balloon_bordersize, + rect.Width - (2 * balloon_bordersize), + rect.Height - (2 * balloon_bordersize)); + + StringFormat textformat = control.Format; + textformat.LineAlignment = StringAlignment.Far; + dc.DrawString (control.Text, control.Font, solidbrush, textrect, textformat); + } + + public override Rectangle BalloonWindowRect (NotifyIcon.BalloonWindow control) + { + Rectangle deskrect = Screen.GetWorkingArea (control); + SizeF maxsize = new SizeF (250, 200); + + SizeF titlesize = control.DeviceContext.MeasureString (control.Title, control.Font, maxsize, control.Format); + SizeF textsize = control.DeviceContext.MeasureString (control.Text, control.Font, maxsize, control.Format); + + if (titlesize.Height < balloon_iconsize) + titlesize.Height = balloon_iconsize; + + Rectangle rect = new Rectangle (); + rect.Height = (int) (titlesize.Height + textsize.Height + (3 * balloon_bordersize)); + rect.Width = (int) ((titlesize.Width > textsize.Width) ? titlesize.Width : textsize.Width) + (2 * balloon_bordersize); + rect.X = deskrect.Width - rect.Width - 2; + rect.Y = deskrect.Height - rect.Height - 2; + + return rect; + } +#endif + #endregion // BalloonWindow + #region TrackBar + public override int TrackBarValueFromMousePosition (int x, int y, TrackBar tb) + { + int result = tb.Value; + int value_pos = tb.Value; + float pixels_betweenticks; + Rectangle thumb_pos = Rectangle.Empty, thumb_area = Rectangle.Empty; + Point channel_startpoint = Point.Empty, na_point = Point.Empty; + + GetTrackBarDrawingInfo (tb, out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out na_point, out na_point); + + /* Convert thumb position from mouse position to value*/ + if (tb.Orientation == Orientation.Vertical) { + value_pos = (int)((thumb_area.Bottom - y -(float)pixels_betweenticks / 2) / (float)pixels_betweenticks); + + if (value_pos + tb.Minimum > tb.Maximum) + value_pos = tb.Maximum - tb.Minimum; + else if (value_pos + tb.Minimum < tb.Minimum) + value_pos = 0; + + result = value_pos + tb.Minimum; + } else { + value_pos = (int) ((x - channel_startpoint.X - (float) pixels_betweenticks / 2) / (float) pixels_betweenticks); + + if (value_pos + tb.Minimum > tb.Maximum) + value_pos = tb.Maximum - tb.Minimum; + else if (value_pos + tb.Minimum < tb.Minimum) + value_pos = 0; + + result = value_pos + tb.Minimum; + } + + return result; + } + + private void GetTrackBarDrawingInfo (TrackBar tb, out float pixels_betweenticks, out Rectangle thumb_area, out Rectangle thumb_pos, out Point channel_startpoint, out Point bottomtick_startpoint, out Point toptick_startpoint) + { + thumb_area = Rectangle.Empty; + thumb_pos = Rectangle.Empty; + + if (tb.Orientation == Orientation.Vertical) { + toptick_startpoint = new Point (); + bottomtick_startpoint = new Point (); + channel_startpoint = new Point (); + float pixel_len; + const int space_from_right = 8; + const int space_from_left = 8; + const int space_from_bottom = 11; + Rectangle area = tb.ClientRectangle; + + switch (tb.TickStyle) { + case TickStyle.BottomRight: + case TickStyle.None: + channel_startpoint.Y = 8; + channel_startpoint.X = 9; + bottomtick_startpoint.Y = 13; + bottomtick_startpoint.X = 24; + break; + case TickStyle.TopLeft: + channel_startpoint.Y = 8; + channel_startpoint.X = 19; + toptick_startpoint.Y = 13; + toptick_startpoint.X = 8; + break; + case TickStyle.Both: + channel_startpoint.Y = 8; + channel_startpoint.X = 18; + bottomtick_startpoint.Y = 13; + bottomtick_startpoint.X = 32; + toptick_startpoint.Y = 13; + toptick_startpoint.X = 8; + break; + default: + break; + } + + thumb_area.X = area.X + channel_startpoint.X; + thumb_area.Y = area.Y + channel_startpoint.Y; + thumb_area.Height = area.Height - space_from_right - space_from_left; + thumb_area.Width = 4; + + pixel_len = thumb_area.Height - 11; + if (tb.Maximum == tb.Minimum) { + pixels_betweenticks = 0; + } else { + pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum); + } + + thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int)(pixels_betweenticks * (float)(tb.Value - tb.Minimum)); + + /* Draw thumb fixed 10x22 size */ + thumb_pos.Width = 10; + thumb_pos.Height = 22; + } else { + toptick_startpoint = new Point (); + bottomtick_startpoint = new Point (); + channel_startpoint = new Point (); + float pixel_len; + const int space_from_right = 8; + const int space_from_left = 8; + Rectangle area = tb.ClientRectangle; + + switch (tb.TickStyle) { + case TickStyle.BottomRight: + case TickStyle.None: + channel_startpoint.X = 8; + channel_startpoint.Y = 9; + bottomtick_startpoint.X = 13; + bottomtick_startpoint.Y = 24; + break; + case TickStyle.TopLeft: + channel_startpoint.X = 8; + channel_startpoint.Y = 19; + toptick_startpoint.X = 13; + toptick_startpoint.Y = 8; + break; + case TickStyle.Both: + channel_startpoint.X = 8; + channel_startpoint.Y = 18; + bottomtick_startpoint.X = 13; + bottomtick_startpoint.Y = 32; + toptick_startpoint.X = 13; + toptick_startpoint.Y = 8; + break; + default: + break; + } + + thumb_area.X = area.X + channel_startpoint.X; + thumb_area.Y = area.Y + channel_startpoint.Y; + thumb_area.Width = area.Width - space_from_right - space_from_left; + thumb_area.Height = 4; + + pixel_len = thumb_area.Width - 11; + if (tb.Maximum == tb.Minimum) { + pixels_betweenticks = 0; + } else { + pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum); + } + + thumb_pos.X = channel_startpoint.X + (int)(pixels_betweenticks * (float) (tb.Value - tb.Minimum)); + + /* Draw thumb fixed 10x22 size */ + thumb_pos.Width = 10; + thumb_pos.Height = 22; + } + } + private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb, ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb, float ticks, int value_pos, bool mouse_value) { @@ -4243,41 +4922,9 @@ namespace System.Windows.Forms Point channel_startpoint = new Point (); float pixel_len; float pixels_betweenticks; - const int space_from_right = 8; - const int space_from_left = 8; - const int space_from_bottom = 11; Rectangle area = tb.ClientRectangle; - switch (tb.TickStyle) { - case TickStyle.BottomRight: - case TickStyle.None: - channel_startpoint.Y = 8; - channel_startpoint.X = 9; - bottomtick_startpoint.Y = 13; - bottomtick_startpoint.X = 24; - break; - case TickStyle.TopLeft: - channel_startpoint.Y = 8; - channel_startpoint.X = 19; - toptick_startpoint.Y = 13; - toptick_startpoint.X = 8; - break; - case TickStyle.Both: - channel_startpoint.Y = 8; - channel_startpoint.X = 18; - bottomtick_startpoint.Y = 13; - bottomtick_startpoint.X = 32; - toptick_startpoint.Y = 13; - toptick_startpoint.X = 8; - break; - default: - break; - } - - thumb_area.X = area.X + channel_startpoint.X; - thumb_area.Y = area.Y + channel_startpoint.Y; - thumb_area.Height = area.Height - space_from_right - space_from_left; - thumb_area.Width = 4; + GetTrackBarDrawingInfo (tb, out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out bottomtick_startpoint, out toptick_startpoint); /* Draw channel */ dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y, @@ -4289,43 +4936,12 @@ namespace System.Windows.Forms dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X + 3, channel_startpoint.Y, 1, thumb_area.Height); - pixel_len = thumb_area.Height - 11; - pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum); - - /* Convert thumb position from mouse position to value*/ - if (mouse_value) { - if (tb.mouse_moved) { - value_pos += (int) pixels_betweenticks / 2; - if (value_pos < thumb_area.Bottom) { - value_pos = (int) ((thumb_area.Bottom - value_pos - (int)(thumb_pos.Width / 2)) / pixels_betweenticks); - } else { - value_pos = 0; - } - - if (value_pos + tb.Minimum > tb.Maximum) - value_pos = tb.Maximum - tb.Minimum; - else if (value_pos + tb.Minimum < tb.Minimum) - value_pos = 0; - - tb.Value = value_pos + tb.Minimum; - } else { - value_pos = tb.Value - tb.Minimum; - } - } - - // thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos); - thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int) (pixels_betweenticks * (float) value_pos); - - /* Draw thumb fixed 10x22 size */ - thumb_pos.Width = 10; - thumb_pos.Height = 22; - switch (tb.TickStyle) { case TickStyle.BottomRight: case TickStyle.None: { thumb_pos.X = channel_startpoint.X - 8; - Pen pen = SystemPens.ControlLight; + Pen pen = SystemPens.ControlLightLight; dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10); dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y); dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4); @@ -4348,7 +4964,7 @@ namespace System.Windows.Forms case TickStyle.TopLeft: { thumb_pos.X = channel_startpoint.X - 10; - Pen pen = SystemPens.ControlLight; + Pen pen = SystemPens.ControlLightLight; dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y); dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4); @@ -4372,8 +4988,8 @@ namespace System.Windows.Forms case TickStyle.Both: { thumb_pos.X = area.X + 10; - - Pen pen = SystemPens.ControlLight; + + Pen pen = SystemPens.ControlLightLight; dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9); dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y); @@ -4458,40 +5074,9 @@ namespace System.Windows.Forms Point channel_startpoint = new Point (); float pixel_len; float pixels_betweenticks; - const int space_from_right = 8; - const int space_from_left = 8; Rectangle area = tb.ClientRectangle; - - switch (tb.TickStyle) { - case TickStyle.BottomRight: - case TickStyle.None: - channel_startpoint.X = 8; - channel_startpoint.Y = 9; - bottomtick_startpoint.X = 13; - bottomtick_startpoint.Y = 24; - break; - case TickStyle.TopLeft: - channel_startpoint.X = 8; - channel_startpoint.Y = 19; - toptick_startpoint.X = 13; - toptick_startpoint.Y = 8; - break; - case TickStyle.Both: - channel_startpoint.X = 8; - channel_startpoint.Y = 18; - bottomtick_startpoint.X = 13; - bottomtick_startpoint.Y = 32; - toptick_startpoint.X = 13; - toptick_startpoint.Y = 8; - break; - default: - break; - } - - thumb_area.X = area.X + channel_startpoint.X; - thumb_area.Y = area.Y + channel_startpoint.Y; - thumb_area.Width = area.Width - space_from_right - space_from_left; - thumb_area.Height = 4; + + GetTrackBarDrawingInfo (tb , out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out bottomtick_startpoint, out toptick_startpoint); /* Draw channel */ dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y, @@ -4503,41 +5088,12 @@ namespace System.Windows.Forms dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X, channel_startpoint.Y +3, thumb_area.Width, 1); - pixel_len = thumb_area.Width - 11; - pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum); - - /* Convert thumb position from mouse position to value*/ - if (mouse_value) { - if (tb.mouse_moved) { - value_pos += (int) pixels_betweenticks / 2; - if (value_pos >= channel_startpoint.X) { - value_pos = (int)(((float) (value_pos - channel_startpoint.X - (int)(thumb_pos.Width / 2))) / pixels_betweenticks); - } else - value_pos = 0; - - if (value_pos + tb.Minimum > tb.Maximum) - value_pos = tb.Maximum - tb.Minimum; - else if(value_pos + tb.Minimum < tb.Minimum) - value_pos = 0; - - tb.Value = value_pos + tb.Minimum; - } else { - value_pos = tb.Value - tb.Minimum; - } - } - - thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos); - - /* Draw thumb fixed 10x22 size */ - thumb_pos.Width = 10; - thumb_pos.Height = 22; - switch (tb.TickStyle) { case TickStyle.BottomRight: case TickStyle.None: { thumb_pos.Y = channel_startpoint.Y - 8; - Pen pen = SystemPens.ControlLight; + Pen pen = SystemPens.ControlLightLight; dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y); dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16); dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4); @@ -4559,7 +5115,7 @@ namespace System.Windows.Forms case TickStyle.TopLeft: { thumb_pos.Y = channel_startpoint.Y - 10; - Pen pen = SystemPens.ControlLight; + Pen pen = SystemPens.ControlLightLight; dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16); dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y); @@ -4583,7 +5139,7 @@ namespace System.Windows.Forms case TickStyle.Both: { thumb_pos.Y = area.Y + 10; - Pen pen = SystemPens.ControlLight; + Pen pen = SystemPens.ControlLightLight; dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y); dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19); @@ -4734,7 +5290,7 @@ namespace System.Windows.Forms public override int ManagedWindowBorderWidth (InternalWindowManager wm) { - return 3; + return 4; } public override int ManagedWindowIconWidth (InternalWindowManager wm) @@ -4744,24 +5300,76 @@ namespace System.Windows.Forms public override void ManagedWindowSetButtonLocations (InternalWindowManager wm) { + TitleButtons buttons = wm.TitleButtons; + Form form = wm.form; + + buttons.HelpButton.Visible = form.HelpButton; + + foreach (TitleButton button in buttons) { + button.Visible = false; + } + + switch (form.FormBorderStyle) { + case FormBorderStyle.None: + if (form.WindowState != FormWindowState.Normal) + goto case FormBorderStyle.Sizable; + break; + case FormBorderStyle.FixedToolWindow: + case FormBorderStyle.SizableToolWindow: + buttons.CloseButton.Visible = true; + if (form.WindowState != FormWindowState.Normal) + goto case FormBorderStyle.Sizable; + break; + case FormBorderStyle.FixedSingle: + case FormBorderStyle.Fixed3D: + case FormBorderStyle.FixedDialog: + case FormBorderStyle.Sizable: + switch (form.WindowState) { + case FormWindowState.Normal: + buttons.MinimizeButton.Visible = true; + buttons.MaximizeButton.Visible = true; + buttons.RestoreButton.Visible = false; + break; + case FormWindowState.Maximized: + buttons.MinimizeButton.Visible = true; + buttons.MaximizeButton.Visible = false; + buttons.RestoreButton.Visible = true; + break; + case FormWindowState.Minimized: + buttons.MinimizeButton.Visible = false; + buttons.MaximizeButton.Visible = true; + buttons.RestoreButton.Visible = true; + break; + } + buttons.CloseButton.Visible = true; + break; + } + int bw = ManagedWindowBorderWidth (wm); Size btsize = ManagedWindowButtonSize (wm); int btw = btsize.Width; int bth = btsize.Height; - + int top = bw + 2; + int left = form.Width - bw - btw - 2; + if ((!wm.IsToolWindow || wm.IsMinimized) && wm.HasBorders) { - if (!wm.IsMaximized) { - wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - btw - 2, - bw + 2, btw, bth); - wm.maximize_button.Rectangle = new Rectangle (wm.close_button.Rectangle.Left - 2 - btw, - bw + 2, btw, bth); - wm.minimize_button.Rectangle = new Rectangle (wm.maximize_button.Rectangle.Left - btw, - bw + 2, btw, bth); - } else { - // Maximized + buttons.CloseButton.Rectangle = new Rectangle (left, top, btw, bth); + left -= 2 + btw; + + if (buttons.MaximizeButton.Visible) { + buttons.MaximizeButton.Rectangle = new Rectangle (left, top, btw, bth); + left -= 2 + btw; + } + if (buttons.RestoreButton.Visible) { + buttons.RestoreButton.Rectangle = new Rectangle (left, top, btw, bth); + left -= 2 + btw; } + + buttons.MinimizeButton.Rectangle = new Rectangle (left, top, btw, bth); + left -= 2 + btw; } else if (wm.IsToolWindow) { - wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - 2 - btw, bw + 2, btw, bth); + buttons.CloseButton.Rectangle = new Rectangle (left, top, btw, bth); + left -= 2 + btw; } } @@ -4772,37 +5380,41 @@ namespace System.Windows.Forms int bdwidth = ManagedWindowBorderWidth (wm); Color titlebar_color = Color.FromArgb (255, 10, 36, 106); Color titlebar_color2 = Color.FromArgb (255, 166, 202, 240); + Color color = ThemeEngine.Current.ColorControlDark; + Color color2 = Color.FromArgb (255, 192, 192, 192); +#if debug + Console.WriteLine (DateTime.Now.ToLongTimeString () + " DrawManagedWindowDecorations"); + dc.FillRectangle (Brushes.Black, clip); +#endif + if (wm.HasBorders) { - Pen pen = new Pen(ColorControl, 1); + Pen pen = ResPool.GetPen (ColorControl); Rectangle borders = new Rectangle (0, 0, form.Width, form.Height); - // The 3d border is only 2 pixels wide, so we draw the innermost pixel ourselves - dc.DrawRectangle (new Pen (ColorControl, 1), 2, 2, form.Width - 5, form.Height - 5); - ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised); - - if (!wm.IsMaximized) { - borders.Y += tbheight + bdwidth; - borders.X += bdwidth; - borders.Height -= tbheight + bdwidth * 2 + 1; - borders.Width -= bdwidth * 2 + 1; - + ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised); + // The 3d border is only 2 pixels wide, so we draw the innermost pixels ourselves + borders = new Rectangle (2, 2, form.Width - 5, form.Height - 5); + for (int i = 2; i < bdwidth; i++) { dc.DrawRectangle (pen, borders); - } + borders.Inflate (-1, -1); + } } - Color color = ThemeEngine.Current.ColorControlDark; - Color color2 = Color.FromArgb (255, 192, 192, 192); - if (wm.IsActive () && !wm.IsMaximized) { + + bool draw_titlebar_enabled = false; + if (wm.Form.Parent != null && wm.Form.Parent is Form) { + draw_titlebar_enabled = false; + } else if (wm.IsActive && !wm.IsMaximized) { + draw_titlebar_enabled = true; + } + if (draw_titlebar_enabled) { color = titlebar_color; color2 = titlebar_color2; } - Rectangle tb = new Rectangle (bdwidth, bdwidth, - form.Width - (bdwidth * 2), tbheight); + Rectangle tb = new Rectangle (bdwidth, bdwidth, form.Width - (bdwidth * 2), tbheight - 1); // HACK: For now always draw the titlebar until we get updates better - // Rectangle vis = Rectangle.Intersect (tb, pe.ClipRectangle); - //if (vis != Rectangle.Empty) if (tb.Width > 0 && tb.Height > 0) { using (System.Drawing.Drawing2D.LinearGradientBrush gradient = new LinearGradientBrush (tb, color, color2, LinearGradientMode.Horizontal)) { @@ -4810,16 +5422,17 @@ namespace System.Windows.Forms } } - dc.DrawLine (new Pen (SystemColors.ControlLight, 1), bdwidth, - tbheight + bdwidth, form.Width - (bdwidth * 2), - tbheight + bdwidth); + // Draw the line just beneath the title bar + dc.DrawLine (ResPool.GetPen (SystemColors.Control), bdwidth, + tbheight + bdwidth - 1, form.Width - bdwidth - 1, + tbheight + bdwidth - 1); if (!wm.IsToolWindow) { tb.X += 18; // Room for the icon and the buttons tb.Width = (form.Width - 62) - tb.X; } - if (form.Text != null) { + if (form.Text != null && form.Text != string.Empty) { StringFormat format = new StringFormat (); format.FormatFlags = StringFormatFlags.NoWrap; format.Trimming = StringTrimming.EllipsisCharacter; @@ -4832,21 +5445,21 @@ namespace System.Windows.Forms } if (wm.HasBorders) { - if (!wm.IsToolWindow && form.Icon != null) { + bool draw_icon = false; +#if NET_2_0 + draw_icon = !wm.IsToolWindow && form.Icon != null && form.ShowIcon; +#else + draw_icon = !wm.IsToolWindow && form.Icon != null; +#endif + if (draw_icon) { Rectangle icon = new Rectangle (bdwidth + 3, bdwidth + 2, wm.IconWidth, wm.IconWidth); if (icon.IntersectsWith (clip)) dc.DrawIcon (form.Icon, icon); } - - if (!wm.IsMaximized) { - if (!wm.IsToolWindow || wm.IsMinimized) { - DrawTitleButton (dc, wm.minimize_button, clip); - DrawTitleButton (dc, wm.maximize_button, clip); - } - DrawTitleButton (dc, wm.close_button, clip); - } else { - // DrawMaximizedButtons (pe, form.ActiveMenu); + + foreach (TitleButton button in wm.TitleButtons.AllButtons) { + DrawTitleButton (dc, button, clip); } } } @@ -4867,8 +5480,12 @@ namespace System.Windows.Forms height - 5); } - private void DrawTitleButton (Graphics dc, InternalWindowManager.TitleButton button, Rectangle clip) + private void DrawTitleButton (Graphics dc, TitleButton button, Rectangle clip) { + if (!button.Visible) { + return; + } + if (!button.Rectangle.IntersectsWith (clip)) return; @@ -4893,7 +5510,7 @@ namespace System.Windows.Forms CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl); } - protected virtual void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color) + public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color) { Pen penTopLeft; Pen penTopLeftInner; @@ -4955,6 +5572,8 @@ namespace System.Windows.Forms break; } + bool inner = ((style != Border3DStyle.RaisedOuter) && (style != Border3DStyle.SunkenOuter)); + if ((sides & Border3DSide.Middle) != 0) { Brush brush = is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (control_color); graphics.FillRectangle (brush, rect); @@ -4962,25 +5581,25 @@ namespace System.Windows.Forms if ((sides & Border3DSide.Left) != 0) { graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top); - if (rect.Width > 2) + if ((rect.Width > 2) && inner) graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top); } if ((sides & Border3DSide.Top) != 0) { graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top); - if (rect.Height > 2) + if ((rect.Height > 2) && inner) graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1); } if ((sides & Border3DSide.Right) != 0) { graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1); - if (rect.Width > 3) + if ((rect.Width > 3) && inner) graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2); } if ((sides & Border3DSide.Bottom) != 0) { graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1); - if (rect.Height > 3) + if ((rect.Height > 3) && inner) graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2); } } @@ -5107,7 +5726,7 @@ namespace System.Windows.Forms public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state) { - Pen check_pen = SystemPens.ControlDarkDark; + Pen check_pen = Pens.Black; Rectangle cb_rect = new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); @@ -5480,31 +6099,20 @@ namespace System.Windows.Forms switch(glyph) { case MenuGlyph.Arrow: { - Point[] arrow = new Point[3]; - Point P1; - Point P2; - Point P3; - int centerX; - int centerY; - int shiftX; - - rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2); - centerX=rect.Left+rect.Width/2; - centerY=rect.Top+rect.Height/2; - shiftX=Math.Max(1, rect.Width/8); - - rect.X-=shiftX; - centerX-=shiftX; - - P1=new Point(centerX, rect.Top); - P2=new Point(centerX, rect.Bottom); - P3=new Point(rect.Right, centerY); - - arrow[0]=P1; - arrow[1]=P2; - arrow[2]=P3; - - graphics.FillPolygon(brush, arrow, FillMode.Winding); + float height = rectangle.Height * 0.7f; + float width = height / 2.0f; + + PointF ddCenter = new PointF (rectangle.X + ((rectangle.Width-width) / 2.0f), rectangle.Y + (rectangle.Height / 2.0f)); + + PointF [] vertices = new PointF [3]; + vertices [0].X = ddCenter.X; + vertices [0].Y = ddCenter.Y - (height / 2.0f); + vertices [1].X = ddCenter.X; + vertices [1].Y = ddCenter.Y + (height / 2.0f); + vertices [2].X = ddCenter.X + width + 0.1f; + vertices [2].Y = ddCenter.Y; + + graphics.FillPolygon (brush, vertices); return; } @@ -5520,17 +6128,17 @@ namespace System.Windows.Forms } case MenuGlyph.Checkmark: { - int Scale; + Pen pen = ResPool.GetPen (color); + lineWidth = Math.Max (2, rectangle.Width / 6); + rect = new Rectangle(rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height- lineWidth * 2); - lineWidth=Math.Max(2, rectangle.Width/6); - Scale=Math.Max(1, rectangle.Width/12); - - rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2); + int Scale = Math.Max (1, rectangle.Width / 12); + int top = (rect.Y + lineWidth + ((rect.Height - ((2 * Scale) + lineWidth)) / 2)); for (int i=0; i