X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mcs%2Fclass%2FManaged.Windows.Forms%2FSystem.Windows.Forms%2FThemeWin32Classic.cs;h=463bd7ecf56a9aef6fb02dacd7f2e7cce92fa439;hb=02ac0e4ead739c140ca2e28414b393a5d5b0e5c2;hp=eb84ca75c7e45c3b5545c3c46fa8b3e89ba3fae6;hpb=182bb211a1c29c22578de7b3ff245136fb63d43f;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 eb84ca75c7e..463bd7ecf56 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs @@ -28,6 +28,7 @@ // using System.ComponentModel; +using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; @@ -54,18 +55,19 @@ namespace System.Windows.Forms protected static StringFormat string_format_menu_shortcut; protected static StringFormat string_format_menu_menubar_text; static ImageAttributes imagedisabled_attributes = null; - const int SEPARATOR_HEIGHT = 5; + const int SEPARATOR_HEIGHT = 6; + 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 */ string_format_menu_text = new StringFormat (); @@ -147,7 +149,7 @@ namespace System.Windows.Forms dc.FillRectangle (is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle); // First, draw the image - if ((button.image != null) || (button.image_list != null)) + if (button.FlatStyle != FlatStyle.System && ((button.image != null) || (button.image_list != null))) ButtonBase_DrawImage(button, dc); // Draw the button: Draw border, etc. @@ -158,7 +160,7 @@ namespace System.Windows.Forms ButtonBase_DrawFocus(button, dc); // Now the text - if (button.text != null && button.text != String.Empty) + if (button.Text != null && button.Text != String.Empty) ButtonBase_DrawText(button, dc); } @@ -346,7 +348,7 @@ namespace System.Windows.Forms } if (button.Enabled) { - dc.DrawImage(i, image_x, image_y); + dc.DrawImage(i, image_x, image_y, image_width, image_height); } else { CPDrawImageDisabled(dc, i, image_x, image_y, ColorControl); @@ -386,12 +388,12 @@ namespace System.Windows.Forms } if (button.Enabled) { - dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format); + dc.DrawString(button.Text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format); } else { if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) { - dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format); + dc.DrawString(button.Text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format); } else { - CPDrawStringDisabled (dc, button.text, button.Font, button.BackColor, text_rect, button.text_format); + CPDrawStringDisabled (dc, button.Text, button.Font, button.BackColor, text_rect, button.text_format); } } } @@ -618,7 +620,7 @@ namespace System.Windows.Forms if ( checkbox.Focused && checkbox.appearance != Appearance.Button && checkbox.Enabled ) DrawInnerFocusRectangle( dc, text_rectangle, checkbox.BackColor ); } - + // renders a checkBox with the Flat and Popup FlatStyle protected virtual void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox) { @@ -873,9 +875,13 @@ namespace System.Windows.Forms g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor), modified_area); + Rectangle text_rect = grid.caption_area; + text_rect.Y += text_rect.Height / 2 - grid.CaptionFont.Height / 2; + text_rect.Height = grid.CaptionFont.Height; + g.DrawString (grid.CaptionText, grid.CaptionFont, ResPool.GetSolidBrush (grid.CaptionForeColor), - grid.caption_area); + text_rect); if (modified_area.IntersectsWith (grid.back_button_rect)) { g.DrawImage (grid.back_button_image, grid.back_button_rect); @@ -927,6 +933,8 @@ namespace System.Windows.Forms int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount; for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) { + if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false) + continue; col_pixel = grid.GetColumnStartingPixel (column); rect_columnhdr.X = columns_area.X + col_pixel - grid.HorizPixelOffset; @@ -998,7 +1006,10 @@ namespace System.Windows.Forms text_format.LineAlignment = StringAlignment.Center; text_format.Alignment = StringAlignment.Near; - string table_name = ((ITypedList)row.view.DataView).GetListName (null) + ": "; + string table_name = ""; + if (row.view is DataRowView) + table_name = ((ITypedList)((DataRowView)row.view).DataView).GetListName (null) + ": "; + // XXX else? Rectangle text_rect; Size text_size; @@ -1075,12 +1086,12 @@ namespace System.Windows.Forms public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid) { - bool is_add_row = grid.ShowEditRow && row == grid.Rows.Length - 1; + bool is_add_row = grid.ShowEditRow && row == grid.DataGridRows.Length - 1; bool is_current_row = row == grid.CurrentCell.RowNumber; // Background g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), - bounds); + bounds); // Draw arrow if (is_current_row) { @@ -1123,10 +1134,10 @@ namespace System.Windows.Forms bool showing_add_row = false; - if (grid.RowsCount < grid.Rows.Length) { + if (grid.RowsCount < grid.DataGridRows.Length) { /* the table has an add row */ - if (grid.FirstVisibleRow + grid.VisibleRowCount >= grid.Rows.Length) { + if (grid.FirstVisibleRow + grid.VisibleRowCount >= grid.DataGridRows.Length) { showing_add_row = true; } } @@ -1134,25 +1145,31 @@ namespace System.Windows.Forms rect_row.Width = cells.Width + grid.RowHeadersArea.Width; for (int r = 0; r < rowcnt; r++) { int row = grid.FirstVisibleRow + r; - if (row == grid.Rows.Length - 1) - rect_row.Height = grid.Rows[row].Height; + if (row == grid.DataGridRows.Length - 1) + rect_row.Height = grid.DataGridRows[row].Height; else - rect_row.Height = grid.Rows[row + 1].VerticalOffset - grid.Rows[row].VerticalOffset; - rect_row.Y = cells.Y + grid.Rows[row].VerticalOffset - grid.Rows[grid.FirstVisibleRow].VerticalOffset; + rect_row.Height = grid.DataGridRows[row + 1].VerticalOffset - grid.DataGridRows[row].VerticalOffset; + rect_row.Y = cells.Y + grid.DataGridRows[row].VerticalOffset - grid.DataGridRows[grid.FirstVisibleRow].VerticalOffset; if (clip.IntersectsWith (rect_row)) { if (grid.CurrentTableStyle.HasRelations - && !(showing_add_row && row == grid.Rows.Length - 1)) + && !(showing_add_row && row == grid.DataGridRows.Length - 1)) DataGridPaintRelationRow (g, row, rect_row, false, clip, grid); else - DataGridPaintRow (g, row, rect_row, showing_add_row && row == grid.Rows.Length - 1, clip, grid); + DataGridPaintRow (g, row, rect_row, showing_add_row && row == grid.DataGridRows.Length - 1, clip, grid); } } - // XXX this should be moved elsewhere and turned into 1 g.FillRectangle call, not grid.Rows.Length separate calls + not_usedarea.X = 0; + // the rowcnt == 0 check is needed because + // otherwise we'd draw over the caption on + // empty datasources (since rect_row would be + // Empty) + if (rowcnt == 0) + not_usedarea.Y = cells.Y; + else + not_usedarea.Y = rect_row.Y + rect_row.Height; not_usedarea.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height; - not_usedarea.Y = rect_row.Y + rect_row.Height; not_usedarea.Width = cells.Width + grid.RowHeadersArea.Width; - not_usedarea.X = 0; g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea); } @@ -1196,12 +1213,12 @@ namespace System.Windows.Forms Rectangle nested_rect = row_rect; - if (grid.Rows[row].IsExpanded) - nested_rect.Height -= grid.Rows[row].RelationHeight; + if (grid.DataGridRows[row].IsExpanded) + nested_rect.Height -= grid.DataGridRows[row].RelationHeight; DataGridPaintRowContents (g, row, nested_rect, is_newrow, clip, grid); - if (grid.Rows[row].IsExpanded) { + if (grid.DataGridRows[row].IsExpanded) { // XXX we should create this in the // datagrid and cache it for use by // the theme instead of doing it each @@ -1225,21 +1242,25 @@ namespace System.Windows.Forms //Region current_clip; Rectangle rect_cell = row_rect; - rect_cell.X = row_rect.X + grid.GetColumnStartingPixel (grid.FirstVisibleColumn) - grid.HorizPixelOffset; + rect_cell.X = nested_rect.X + grid.GetColumnStartingPixel (grid.FirstVisibleColumn) - grid.HorizPixelOffset; rect_cell.Y += nested_rect.Height; - rect_cell.Height = grid.Rows[row].RelationHeight; - rect_cell.Width = 0; + rect_cell.Height = grid.DataGridRows[row].RelationHeight; + rect_cell.Width = 0; int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount; - for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) + for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) { + if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false) + continue; rect_cell.Width += grid.CurrentTableStyle.GridColumnStyles[column].Width; + } + rect_cell.Width = Math.Max (rect_cell.Width, grid.DataGridRows[row].relation_area.Width); g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.CurrentTableStyle.BackColor), rect_cell); /* draw the line leading from the +/- to the relation area */ - Rectangle outline = grid.Rows[row].relation_area; + Rectangle outline = grid.DataGridRows[row].relation_area; outline.Y = rect_cell.Y; outline.Height --; @@ -1276,7 +1297,7 @@ namespace System.Windows.Forms int col_pixel; Color backcolor, forecolor; Brush backBrush, foreBrush; - Rectangle not_usedarea = new Rectangle (); + Rectangle not_usedarea = Rectangle.Empty; rect_cell.Y = row_rect.Y; rect_cell.Height = row_rect.Height; @@ -1301,48 +1322,56 @@ namespace System.Windows.Forms // PaintCells at row, column int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount; - Region prev_clip = g.Clip; - Region current_clip; + if (column_cnt > 0) { + Region prev_clip = g.Clip; + Region current_clip; - for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) { + for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) { + if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false) + continue; - col_pixel = grid.GetColumnStartingPixel (column); + col_pixel = grid.GetColumnStartingPixel (column); - rect_cell.X = row_rect.X + col_pixel - grid.HorizPixelOffset; - rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width; + rect_cell.X = row_rect.X + col_pixel - grid.HorizPixelOffset; + rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width; - if (clip.IntersectsWith (rect_cell)) { - current_clip = new Region (rect_cell); - current_clip.Intersect (row_rect); - current_clip.Intersect (prev_clip); - g.Clip = current_clip; + if (clip.IntersectsWith (rect_cell)) { + current_clip = new Region (rect_cell); + current_clip.Intersect (row_rect); + current_clip.Intersect (prev_clip); + g.Clip = current_clip; - if (is_newrow) { - grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell, - backBrush, - foreBrush); - } else { - grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row, - backBrush, - foreBrush, - grid.RightToLeft == RightToLeft.Yes); - } + if (is_newrow) { + grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell, + backBrush, + foreBrush); + } else { + grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row, + backBrush, + foreBrush, + grid.RightToLeft == RightToLeft.Yes); + } - current_clip.Dispose (); + current_clip.Dispose (); + } } - } - g.Clip = prev_clip; + g.Clip = prev_clip; - if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) { - not_usedarea.X = rect_cell.X + rect_cell.Width; - not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width; - not_usedarea.Y = row_rect.Y; - not_usedarea.Height = row_rect.Height; - if (clip.IntersectsWith (not_usedarea)) - g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), - not_usedarea); + if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) { + not_usedarea.X = rect_cell.X + rect_cell.Width; + not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width; + not_usedarea.Y = row_rect.Y; + not_usedarea.Height = row_rect.Height; + } + } + else { + not_usedarea = row_rect; } + + if (!not_usedarea.IsEmpty && clip.IntersectsWith (not_usedarea)) + g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), + not_usedarea); } public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow, @@ -1364,42 +1393,147 @@ namespace System.Windows.Forms #endregion // Datagrid #region DateTimePicker - - public override void DrawDateTimePicker (Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) { - // if not showing the numeric updown control then render border - if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) { - // draw the outer border - Rectangle button_bounds = dtp.ClientRectangle; - this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor); - - // deflate by the border width - if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) { - button_bounds.Inflate (-2,-2); + + public override void DrawDateTimePicker(Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) + { + + if (!clip_rectangle.IntersectsWith (dtp.ClientRectangle)) + return; + + // draw the outer border + Rectangle button_bounds = dtp.ClientRectangle; + this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor); + + // deflate by the border width + if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) { + 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, state); + } else { + ButtonState up_state = dtp.is_up_pressed ? ButtonState.Pushed : ButtonState.Normal; + ButtonState down_state = dtp.is_down_pressed ? ButtonState.Pushed : ButtonState.Normal; + Rectangle up_bounds = dtp.drop_down_arrow_rect; + Rectangle down_bounds = dtp.drop_down_arrow_rect; + + up_bounds.Height = up_bounds.Height / 2; + down_bounds.Y = up_bounds.Height; + down_bounds.Height = dtp.Height - up_bounds.Height; + if (down_bounds.Height > up_bounds.Height) + { + down_bounds.Y += 1; + down_bounds.Height -= 1; + } + + up_bounds.Inflate (-1, -1); + down_bounds.Inflate (-1, -1); + + ControlPaint.DrawScrollButton (dc, up_bounds, ScrollButton.Up, up_state); + ControlPaint.DrawScrollButton (dc, down_bounds, ScrollButton.Down, down_state); } } // render the date part - if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) { - // fill the background - dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect); - - // fill the currently highlighted area - if (dtp.hilight_date_area != Rectangle.Empty) { - dc.FillRectangle (SystemBrushes.Highlight, dtp.hilight_date_area); + if (!clip_rectangle.IntersectsWith (dtp.date_area_rect)) + return; + + // fill the background + dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect); + + // Update date_area_rect if we are drawing the checkbox + Rectangle date_area_rect = dtp.date_area_rect; + if (dtp.ShowCheckBox) { + Rectangle check_box_rect = dtp.CheckBoxRect; + date_area_rect.X = date_area_rect.X + check_box_rect.Width + DateTimePicker.check_box_space * 2; + date_area_rect.Width = date_area_rect.Width - check_box_rect.Width - DateTimePicker.check_box_space * 2; + + ButtonState bs = dtp.Checked ? ButtonState.Checked : ButtonState.Normal; + CPDrawCheckBox(dc, check_box_rect, bs); + + if (dtp.is_checkbox_selected) + CPDrawFocusRectangle (dc, check_box_rect, dtp.foreground_color, dtp.background_color); + } + + // render each text part + using (StringFormat text_format = StringFormat.GenericTypographic) + { + text_format.LineAlignment = StringAlignment.Near; + text_format.Alignment = StringAlignment.Near; + text_format.FormatFlags = text_format.FormatFlags | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox; + text_format.FormatFlags &= ~StringFormatFlags.NoClip; + + // Calculate the rectangles for each part + if (dtp.part_data.Length > 0 && dtp.part_data[0].drawing_rectangle.IsEmpty) + { + Graphics gr = dc; + for (int i = 0; i < dtp.part_data.Length; i++) + { + DateTimePicker.PartData fd = dtp.part_data[i]; + RectangleF text_rect = new RectangleF(); + string text = fd.GetText(dtp.Value); + text_rect.Size = gr.MeasureString (text, dtp.Font, 250, text_format); + if (!fd.is_literal) + text_rect.Width = Math.Max (dtp.CalculateMaxWidth(fd.value, gr, text_format), text_rect.Width); + + if (i > 0) { + text_rect.X = dtp.part_data[i - 1].drawing_rectangle.Right; + } else { + text_rect.X = date_area_rect.X; + } + text_rect.Y = 2; + text_rect.Inflate (1, 0); + fd.drawing_rectangle = text_rect; + } } // draw the text part - // TODO: if date format is CUstom then we need to draw the dates as separate parts - StringFormat text_format = new StringFormat(); - text_format.LineAlignment = StringAlignment.Center; - text_format.Alignment = StringAlignment.Near; - dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format); - text_format.Dispose (); + Brush text_brush = ResPool.GetSolidBrush (dtp.ShowCheckBox && dtp.Checked == false ? + SystemColors.GrayText : dtp.ForeColor); // Use GrayText if Checked is false + RectangleF clip_rectangleF = clip_rectangle; + + for (int i = 0; i < dtp.part_data.Length; i++) + { + DateTimePicker.PartData fd = dtp.part_data [i]; + string text; + + if (!clip_rectangleF.IntersectsWith (fd.drawing_rectangle)) + continue; + + text = fd.GetText (dtp.Value); + + PointF text_position = new PointF (); + SizeF text_size; + RectangleF text_rect; + + text_size = dc.MeasureString (text, dtp.Font, 250, text_format); + text_position.X = (fd.drawing_rectangle.Left + fd.drawing_rectangle.Width / 2) - text_size.Width / 2; + text_position.Y = (fd.drawing_rectangle.Top + fd.drawing_rectangle.Height / 2) - text_size.Height / 2; + text_rect = new RectangleF (text_position, text_size); + text_rect = RectangleF.Intersect (text_rect, date_area_rect); + + if (text_rect.IsEmpty) + break; + + if (text_rect.Right >= date_area_rect.Right) + text_format.FormatFlags &= ~StringFormatFlags.NoClip; + else + text_format.FormatFlags |= StringFormatFlags.NoClip; + + if (fd.is_selected) { + dc.FillRectangle (SystemBrushes.Highlight, text_rect); + dc.DrawString (text, dtp.Font, SystemBrushes.HighlightText, text_rect, text_format); + + } else { + dc.DrawString (text, dtp.Font, text_brush, text_rect, text_format); + } + + if (fd.drawing_rectangle.Right > date_area_rect.Right) + break; // the next part would be not be visible, so don't draw anything more. + } } } @@ -1418,22 +1552,26 @@ namespace System.Windows.Forms text_format.HotkeyPrefix = HotkeyPrefix.Show; size = dc.MeasureString (box.Text, box.Font); - width = ((int) size.Width) + 7; + width = 0; + + if (size.Width > 0) { + width = ((int) size.Width) + 7; - if (width > box.Width - 16) - width = box.Width - 16; + if (width > box.Width - 16) + width = box.Width - 16; + } y = box.Font.Height / 2; - + + // Clip the are that the text will be in + Region prev_clip = dc.Clip; + dc.SetClip (new Rectangle (10, 0, width, box.Font.Height), CombineMode.Exclude); /* Draw group box*/ CPDrawBorder3D (dc, new Rectangle (0, y, box.Width, box.Height - y), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, box.BackColor); - + dc.Clip = prev_clip; + /* Text */ if (box.Text.Length != 0) { - Pen pen = ResPool.GetPen (box.BackColor); - dc.DrawLine (pen, 9, y, 8 + width, y); - dc.DrawLine (pen, 9, y + 1, 8 + width, y + 1); - if (box.Enabled) { dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format); } else { @@ -1583,7 +1721,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; @@ -1616,15 +1754,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; @@ -1672,7 +1811,12 @@ namespace System.Windows.Forms 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); @@ -1718,14 +1862,23 @@ namespace System.Windows.Forms } } - if (control.View == View.LargeIcon) { - if (item.ImageIndex > -1 && control.LargeImageList != null && - item.ImageIndex < control.LargeImageList.Images.Count) - control.LargeImageList.Draw (dc, icon_rect.Location, item.ImageIndex); - } else { - if (item.ImageIndex > -1 && control.SmallImageList != null && - item.ImageIndex < control.SmallImageList.Images.Count) - control.SmallImageList.Draw (dc, icon_rect.Location, item.ImageIndex); + 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; + +#if NET_2_0 + if (item.ImageKey != String.Empty) + idx = image_list.Images.IndexOfKey (item.ImageKey); + else +#endif + idx = item.ImageIndex; + + if (idx > -1 && idx < image_list.Images.Count) + image_list.Draw (dc, icon_rect.Location, idx); } // draw the item text @@ -1740,7 +1893,9 @@ namespace System.Windows.Forms else format.Alignment = StringAlignment.Near; - if (!control.LabelWrap) + if (control.LabelWrap) + format.FormatFlags = StringFormatFlags.LineLimit; + else format.FormatFlags = StringFormatFlags.NoWrap; Rectangle highlight_rect = text_rect; @@ -1751,6 +1906,8 @@ namespace System.Windows.Forms if (item.Selected && control.Focused) dc.FillRectangle (SystemBrushes.Highlight, highlight_rect); + else if (item.Selected && !control.HideSelection) + dc.FillRectangle (SystemBrushes.Control, highlight_rect); else dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect); @@ -1759,6 +1916,25 @@ namespace System.Windows.Forms (item.Selected && control.Focused) ? SystemBrushes.HighlightText : this.ResPool.GetSolidBrush (item.ForeColor); +#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); @@ -1805,12 +1981,20 @@ namespace System.Windows.Forms sub_item_font = subItem.Font; } - if (item.Selected && control.Focused && control.FullRowSelect) { - dc.FillRectangle (SystemBrushes.Highlight, sub_item_rect); + if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) { + Brush bg, text; + if (control.Focused) { + bg = SystemBrushes.Highlight; + text = SystemBrushes.HighlightText; + } else { + bg = SystemBrushes.Control; + text = sub_item_fore_br; + } + + dc.FillRectangle (bg, sub_item_rect); if (subItem.Text != null && subItem.Text.Length > 0) dc.DrawString (subItem.Text, sub_item_font, - SystemBrushes.HighlightText, - sub_item_text_rect, format); + text, sub_item_text_rect, format); } else { dc.FillRectangle (sub_item_back_br, sub_item_rect); if (subItem.Text != null && subItem.Text.Length > 0) @@ -1819,9 +2003,23 @@ namespace System.Windows.Forms sub_item_text_rect, format); } } + + // Fill in selection for remaining columns if Column.Count > SubItems.Count + if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) { + for (int index = count; index < control.Columns.Count; index++) + { + col = control.Columns [index]; + sub_item_rect.X = col.Rect.X - control.h_marker; + sub_item_rect.Width = col.Wd; + if (control.Focused) + dc.FillRectangle (SystemBrushes.Highlight, sub_item_rect); + else + dc.FillRectangle (SystemBrushes.Control, sub_item_rect); + } + } } } - + if (item.Focused && control.Focused) { Rectangle focus_rect = highlight_rect; if (control.FullRowSelect && control.View == View.Details) { @@ -1867,6 +2065,18 @@ namespace System.Windows.Forms public override Size ListViewDefaultSize { get { return new Size (121, 97); } } + + 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 @@ -1882,8 +2092,8 @@ namespace System.Windows.Forms } if (item.Separator == true) { - item.Height = SEPARATOR_HEIGHT / 2; - item.Width = -1; + item.Height = SEPARATOR_HEIGHT; + item.Width = SEPARATOR_MIN_WIDTH; return; } @@ -1955,7 +2165,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]; @@ -1981,13 +2191,13 @@ namespace System.Windows.Forms } menu.Width = x; - + //space for border menu.Width += 2; menu.Height += 2; menu.Width += SM_CXBORDER; - menu.Height += SM_CYBORDER; + menu.Height += SM_CYBORDER; } // Draws a menu bar in a window @@ -2021,6 +2231,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); @@ -2028,6 +2239,7 @@ namespace System.Windows.Forms CPDrawMenuGlyph (gr, rect, glyph, color); bmp.MakeTransparent (bg_color); gr.Dispose (); + return bmp; } @@ -2045,11 +2257,13 @@ namespace System.Windows.Forms string_format = string_format_menu_text; if (item.Separator == true) { + int liney = e.Bounds.Y + (e.Bounds.Height / 2); + e.Graphics.DrawLine (SystemPens.ControlDark, - e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y); + e.Bounds.X, liney, e.Bounds.X + e.Bounds.Width, liney); e.Graphics.DrawLine (SystemPens.ControlLight, - e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1); + e.Bounds.X, liney + 1, e.Bounds.X + e.Bounds.Width, liney + 1); return; } @@ -2060,8 +2274,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); @@ -2088,11 +2302,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, @@ -2117,7 +2328,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) { @@ -2130,7 +2341,7 @@ namespace System.Windows.Forms } /* Draw arrow */ - if (item.MenuBar == false && item.IsPopup || item.MdiList) { + if (item.MenuBar == false && (item.IsPopup || item.MdiList)) { int cx = MenuCheckSize.Width; int cy = MenuCheckSize.Height; @@ -2163,38 +2374,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)); + } } } @@ -2271,15 +2463,13 @@ namespace System.Windows.Forms StringFormat text_format = new StringFormat(); text_format.LineAlignment = StringAlignment.Center; text_format.Alignment = StringAlignment.Near; - Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold); Rectangle today_rect = new Rectangle ( today_offset + client_rectangle.X, Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0), Math.Max(client_rectangle.Width - today_offset, 0), date_cell_size.Height); - dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, GetControlForeBrush (mc.ForeColor), today_rect, text_format); + dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), mc.bold_font, GetControlForeBrush (mc.ForeColor), today_rect, text_format); text_format.Dispose (); - bold_font.Dispose (); } } @@ -2349,13 +2539,8 @@ namespace System.Windows.Forms Size title_size = (Size)((object)mc.title_size); Size date_cell_size = (Size)((object)mc.date_cell_size); DateTime current_month = (DateTime)((object)mc.current_month); + DateTime sunday = new DateTime(2006, 10, 1); - // set up some standard string formating variables - StringFormat text_format = new StringFormat(); - text_format.LineAlignment = StringAlignment.Center; - text_format.Alignment = StringAlignment.Center; - - // draw the title back ground DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col); Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height); @@ -2363,7 +2548,23 @@ namespace System.Windows.Forms dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect); // draw the title string title_text = this_month.ToString ("MMMM yyyy"); - dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format); + 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) @@ -2416,7 +2617,7 @@ namespace System.Windows.Forms day_name_rect.Y, date_cell_size.Width, date_cell_size.Height); - dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format); + dc.DrawString (sunday.AddDays (i + (int) first_day_of_week).ToString ("ddd"), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, mc.centered_format); } // draw the vertical divider @@ -2474,7 +2675,7 @@ namespace System.Windows.Forms mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), date_rect, - text_format); + mc.centered_format); } date_rect.Offset(date_cell_size.Width, 0); } @@ -2518,7 +2719,6 @@ namespace System.Windows.Forms rectangle.X + date_cell_size.Width - 1, rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset); } - text_format.Dispose (); } // draws the pervious or next button @@ -2602,18 +2802,18 @@ namespace System.Windows.Forms date_color = mc.ForeColor; } - + const int inflate = -1; if (date == mc.SelectionStart && date == mc.SelectionEnd) { // see if the date is in the start of selection date_color = mc.BackColor; // draw the left hand of the back ground - Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3); - dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359); + Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate); + dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 360); } else if (date == mc.SelectionStart) { // see if the date is in the start of selection date_color = mc.BackColor; // draw the left hand of the back ground - Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3); + Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate); dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180); // fill the other side as a straight rect if (date < mc.SelectionEnd) @@ -2627,7 +2827,7 @@ namespace System.Windows.Forms // see if it is the end of selection date_color = mc.BackColor; // draw the left hand of the back ground - Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3); + Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate); dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180); // fill the other side as a straight rect if (date > mc.SelectionStart) { @@ -2639,26 +2839,15 @@ namespace System.Windows.Forms // now see if it's in the middle date_color = mc.BackColor; // draw the left hand of the back ground - Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3); + Rectangle selection_rect = Rectangle.Inflate (rectangle, 0, inflate); dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect); } - // set up some standard string formating variables - StringFormat text_format = new StringFormat(); - text_format.LineAlignment = StringAlignment.Center; - text_format.Alignment = StringAlignment.Center; - - // establish if it's a bolded font - Font font; - if (mc.IsBoldedDate (date)) { - font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold); - } else { - font = mc.Font; - } + Font font = mc.IsBoldedDate (date) ? mc.bold_font : mc.Font; // just draw the date now - dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format); + dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, mc.centered_format); // today circle if needed if (mc.ShowTodayCircle && date == DateTime.Now.Date) { @@ -2670,7 +2859,6 @@ namespace System.Windows.Forms Pen pen = ResPool.GetDashPen (Color.Black, DashStyle.Dot); dc.DrawRectangle (pen, interior); } - text_format.Dispose (); } private void DrawTodayCircle (Graphics dc, Rectangle rectangle) { @@ -2778,6 +2966,8 @@ namespace System.Windows.Forms { int padding = 8; PreviewPageInfo[] pis = preview.page_infos; + if (pis == null) + return; int page_x, page_y; @@ -3772,9 +3962,16 @@ namespace System.Windows.Forms dc.DrawString (page.Text, page.Font, SystemBrushes.ControlText, 0, 0, string_format); dc.ResetTransform (); } else { + Rectangle str_rect = interior; + + 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, - interior, string_format); + str_rect, string_format); } } else if (page.Text != null) { DrawItemState state = DrawItemState.None; @@ -3787,7 +3984,7 @@ namespace System.Windows.Forms return res; } - if (page.parent.Focused && is_selected) { + if (page.Parent.Focused && is_selected) { CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor); } @@ -3903,8 +4100,12 @@ namespace System.Windows.Forms else style = Border3DStyle.Raised; } + + Rectangle rect = button.Rectangle; + if ((button.Style == ToolBarButtonStyle.DropDownButton) && (button.Parent.DropDownArrows) && is_flat) + rect.Width -= ToolBarDropDownWidth; - CPDrawBorder3D (dc, button.Rectangle, style, all_sides); + CPDrawBorder3D (dc, rect, style, all_sides); } protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarButton button) @@ -3917,18 +4118,21 @@ namespace System.Windows.Forms protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarButton button) { + Brush brush; Rectangle area = button.Rectangle; area.X += ToolBarImageGripWidth; area.Y += ToolBarImageGripWidth; area.Width -= 2 * ToolBarImageGripWidth; area.Height -= 2 * ToolBarImageGripWidth; - + if (button.Pushed) - dc.FillRectangle (SystemBrushes.ControlLightLight, area); + brush = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, ColorControlLightLight); else if (button.PartialPush) - dc.FillRectangle (SystemBrushes.ControlLight, area); + brush = SystemBrushes.ControlLight; else - dc.FillRectangle (SystemBrushes.Control, area); + brush = SystemBrushes.Control; + + dc.FillRectangle (brush, area); } protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat) @@ -3936,20 +4140,32 @@ namespace System.Windows.Forms Rectangle rect = button.Rectangle; rect.X = button.Rectangle.Right - ToolBarDropDownWidth; rect.Width = ToolBarDropDownWidth; - - if (button.dd_pressed) { - CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides); - CPDrawBorder3D (dc, rect, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right); - } else if (button.Pushed || button.Pressed) - CPDrawBorder3D (dc, rect, Border3DStyle.Sunken, all_sides); - else if (is_flat) { - if (button.Hilight) - CPDrawBorder3D (dc, rect, Border3DStyle.RaisedOuter, all_sides); - } else - CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides); - + + if (is_flat) { + if (button.dd_pressed) + CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides); + else if (button.Pushed || button.Pressed) + CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides); + else if (button.Hilight) + CPDrawBorder3D (dc, rect, Border3DStyle.RaisedInner, all_sides); + } else { + if (button.dd_pressed) + CPDrawBorder3D (dc, rect, Border3DStyle.Flat, all_sides); + else if (button.Pushed || button.Pressed) + CPDrawBorder3D (dc, Rectangle.Inflate(rect, -1, -1), Border3DStyle.SunkenOuter, all_sides); + else + CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides); + } + PointF [] vertices = new PointF [3]; - PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height/2.0f)); + 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) { + ddCenter.X += 1; + ddCenter.Y += 1; + } + vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f; vertices [0].Y = ddCenter.Y; vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f; @@ -3964,6 +4180,13 @@ namespace System.Windows.Forms if (button.Image != null) { int x = button.ImageRectangle.X + ToolBarImageGripWidth; int y = button.ImageRectangle.Y + ToolBarImageGripWidth; + + // Increase vertical and horizontal position by 1 when button is pressed + if (button.Pressed || button.Pushed) { + x += 1; + y += 1; + } + if (button.Enabled) dc.DrawImage (button.Image, x, y); else @@ -3974,6 +4197,11 @@ namespace System.Windows.Forms if (text_rect.Width <= 0 || text_rect.Height <= 0) return; + if (button.Pressed || button.Pushed) { + text_rect.X += 1; + text_rect.Y += 1; + } + if (button.Enabled) dc.DrawString (button.Text, control.Font, SystemBrushes.ControlText, text_rect, format); else @@ -4016,17 +4244,13 @@ 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) { - dc.FillRectangle(SystemBrushes.Info, control.client_rect); + 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.client_rect, control.string_format); + dc.DrawString(control.Text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.ClientRectangle, control.string_format); } public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) { @@ -4098,15 +4322,23 @@ namespace System.Windows.Forms /* Convert thumb position from mouse position to value*/ if (mouse_value) { - if (value_pos < thumb_area.Bottom) - value_pos = (int) ((thumb_area.Bottom - value_pos) / pixels_betweenticks); - else - value_pos = 0; - - if (value_pos + tb.Minimum > tb.Maximum) - value_pos = tb.Maximum - tb.Minimum; + 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; + 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); @@ -4242,7 +4474,7 @@ namespace System.Windows.Forms Does not matter the size of the control, Win32 always draws: - Ticks starting from pixel 13, 8 - Channel starting at pos 8, 19 and ends at Width - 8 - - Autosize makes always the control 40 pixels height + - Autosize makes always the control 45 pixels high - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum) */ @@ -4304,15 +4536,22 @@ namespace System.Windows.Forms /* Convert thumb position from mouse position to value*/ if (mouse_value) { - if (value_pos >= channel_startpoint.X) - value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks); - else - value_pos = 0; + 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; - if (value_pos + tb.Minimum > tb.Maximum) - value_pos = tb.Maximum - tb.Minimum; - - tb.Value = value_pos + tb.Minimum; + 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); @@ -4470,13 +4709,8 @@ namespace System.Windows.Forms dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle); } - if (tb.Focused) { - Brush brush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black); - dc.FillRectangle (brush, area.X, area.Y, area.Width - 1, 1); - dc.FillRectangle (brush, area.X, area.Y + area.Height - 1, area.Width - 1, 1); - dc.FillRectangle (brush, area.X, area.Y, 1, area.Height - 1); - dc.FillRectangle (brush, area.X + area.Width - 1, area.Y, 1, area.Height - 1); + CPDrawFocusRectangle(dc, area, tb.ForeColor, tb.BackColor); } if (tb.Orientation == Orientation.Vertical) { @@ -4564,19 +4798,32 @@ namespace System.Windows.Forms Form form = wm.Form; int tbheight = ManagedWindowTitleBarHeight (wm); int bdwidth = ManagedWindowBorderWidth (wm); - Color titlebar_color = Color.FromArgb (255, 0, 0, 255); - + Color titlebar_color = Color.FromArgb (255, 10, 36, 106); + Color titlebar_color2 = Color.FromArgb (255, 166, 202, 240); + if (wm.HasBorders) { + Pen pen = new Pen(ColorControl, 1); 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; + + dc.DrawRectangle (pen, borders); + } } Color color = ThemeEngine.Current.ColorControlDark; - - if (wm.IsActive () && !wm.IsMaximized) + Color color2 = Color.FromArgb (255, 192, 192, 192); + if (wm.IsActive () && !wm.IsMaximized) { color = titlebar_color; + color2 = titlebar_color2; + } Rectangle tb = new Rectangle (bdwidth, bdwidth, form.Width - (bdwidth * 2), tbheight); @@ -4584,8 +4831,13 @@ namespace System.Windows.Forms // HACK: For now always draw the titlebar until we get updates better // Rectangle vis = Rectangle.Intersect (tb, pe.ClipRectangle); //if (vis != Rectangle.Empty) - dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color), tb); - + if (tb.Width > 0 && tb.Height > 0) { + using (System.Drawing.Drawing2D.LinearGradientBrush gradient = new LinearGradientBrush (tb, color, color2, LinearGradientMode.Horizontal)) + { + dc.FillRectangle (gradient, tb); + } + } + dc.DrawLine (new Pen (SystemColors.ControlLight, 1), bdwidth, tbheight + bdwidth, form.Width - (bdwidth * 2), tbheight + bdwidth); @@ -4602,7 +4854,7 @@ namespace System.Windows.Forms format.LineAlignment = StringAlignment.Center; if (tb.IntersectsWith (clip)) - dc.DrawString (form.Text, form.Font, + dc.DrawString (form.Text, WindowBorderFont, ThemeEngine.Current.ResPool.GetSolidBrush (Color.White), tb, format); } @@ -4651,7 +4903,7 @@ namespace System.Windows.Forms dc.FillRectangle (SystemBrushes.Control, button.Rectangle); ControlPaint.DrawCaptionButton (dc, button.Rectangle, - button.Caption, ButtonState.Normal); + button.Caption, button.State); } #region ControlPaint @@ -4731,6 +4983,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); @@ -4738,29 +4992,42 @@ namespace System.Windows.Forms if ((sides & Border3DSide.Left) != 0) { graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top); - graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top); + 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); - graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1); + 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); - graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2); + 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); - graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2); + if ((rect.Height > 3) && inner) + graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2); } } public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state) + { + CPDrawButtonInternal (dc, rectangle, state, SystemPens.ControlDarkDark, SystemPens.ControlDark, SystemPens.ControlLight); + } + + private void CPDrawButtonInternal (Graphics dc, Rectangle rectangle, ButtonState state, Pen DarkPen, Pen NormalPen, Pen LightPen) { // sadly enough, the rectangle gets always filled with a hatchbrush - dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2); + dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, + Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255), + ColorControl.G, ColorControl.B), + ColorControl), + rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2); if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) { dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4); @@ -4773,41 +5040,41 @@ namespace System.Windows.Forms if ((state & ButtonState.Checked) == ButtonState.Checked) { dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4); - Pen pen = SystemPens.ControlDarkDark; + Pen pen = DarkPen; dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y); - pen = SystemPens.ControlDark; + pen = NormalPen; dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3); dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1); - pen = SystemPens.ControlLight; + pen = LightPen; dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1); dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1); } else if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) { - Pen pen = SystemPens.ControlDarkDark; + Pen pen = DarkPen; dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y); - pen = SystemPens.ControlDark; + pen = NormalPen; dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3); dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1); - pen = SystemPens.ControlLight; + pen = LightPen; dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1); dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1); } else if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) { - Pen pen = SystemPens.ControlLight; + Pen pen = LightPen; dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y); dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2); - pen = SystemPens.ControlDark; + pen = NormalPen; dc.DrawLine (pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2); dc.DrawLine (pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3); - pen = SystemPens.ControlDarkDark; + pen = DarkPen; dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1); dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2); } @@ -4818,7 +5085,7 @@ namespace System.Windows.Forms Rectangle captionRect; int lineWidth; - CPDrawButton(graphics, rectangle, state); + CPDrawButtonInternal (graphics, rectangle, state, SystemPens.ControlDarkDark, SystemPens.ControlDark, SystemPens.ControlLightLight); if (rectangle.Width