/* Hardcoded colour values not exposed in the API constants in all configurations */
protected static readonly Color arrow_color = Color.Black;
protected static readonly Color pen_ticks_color = Color.Black;
- protected static readonly Color progressbarblock_color = Color.FromArgb (255, 0, 0, 128);
protected static StringFormat string_format_menu_text;
protected static StringFormat string_format_menu_shortcut;
protected static StringFormat string_format_menu_menubar_text;
check_or_radio_checked = ((RadioButton)button).Checked;
}
- if ((button.Focused || button.paint_as_acceptbutton) && button.Enabled && !check_or_radio) {
+ if (button.Focused && button.Enabled && !check_or_radio) {
// shrink the rectangle for the normal button drawing inside the focus rectangle
borderRectangle = Rectangle.Inflate (button.ClientRectangle, -1, -1);
} else {
if (button is CheckBox)
check_size = (button as CheckBox).Appearance == Appearance.Normal ? 13 : 0;
- glyphArea = new Rectangle (0, (button.Height - check_size) / 2, check_size, check_size);
+ glyphArea = new Rectangle (0, 2, check_size, check_size);
+
+ Rectangle content_rect = button.ClientRectangle;
+ ContentAlignment align = ContentAlignment.TopLeft;;
+
+ if (button is CheckBox)
+ align = (button as CheckBox).CheckAlign;
+ else if (button is RadioButton)
+ align = (button as RadioButton).CheckAlign;
+
+ switch (align) {
+ case ContentAlignment.BottomCenter:
+ glyphArea.Y = button.Height - check_size;
+ glyphArea.X = (button.Width - check_size) / 2 - 2;
+ break;
+ case ContentAlignment.BottomLeft:
+ glyphArea.Y = button.Height - check_size - 2;
+ content_rect.Width -= check_size;
+ content_rect.Offset (check_size, 0);
+ break;
+ case ContentAlignment.BottomRight:
+ glyphArea.Y = button.Height - check_size - 2;
+ glyphArea.X = button.Width - check_size;
+ content_rect.Width -= check_size;
+ break;
+ case ContentAlignment.MiddleCenter:
+ glyphArea.Y = (button.Height - check_size) / 2;
+ glyphArea.X = (button.Width - check_size) / 2;
+ break;
+ case ContentAlignment.MiddleLeft:
+ glyphArea.Y = (button.Height - check_size) / 2;
+ content_rect.Width -= check_size;
+ content_rect.Offset (check_size, 0);
+ break;
+ case ContentAlignment.MiddleRight:
+ glyphArea.Y = (button.Height - check_size) / 2;
+ glyphArea.X = button.Width - check_size;
+ content_rect.Width -= check_size;
+ break;
+ case ContentAlignment.TopCenter:
+ glyphArea.X = (button.Width - check_size) / 2;
+ break;
+ case ContentAlignment.TopLeft:
+ content_rect.Width -= check_size;
+ content_rect.Offset (check_size, 0);
+ break;
+ case ContentAlignment.TopRight:
+ glyphArea.X = button.Width - check_size;
+ content_rect.Width -= check_size;
+ break;
+ }
Image image = button.Image;
string text = button.Text;
- Rectangle content_rect = button.ClientRectangle;
- content_rect.Width -= check_size;
- content_rect.Offset (check_size, 0);
Size proposed = Size.Empty;
public override void ComboBoxDrawBackground (ComboBox comboBox, Graphics g, Rectangle clippingArea, FlatStyle style)
{
if (!comboBox.Enabled)
- g.FillRectangle (ResPool.GetSolidBrush (ColorControl), comboBox.Bounds);
+ g.FillRectangle (ResPool.GetSolidBrush (ColorControl), comboBox.ClientRectangle);
if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
g.FillRectangle (ResPool.GetSolidBrush (comboBox.Parent.BackColor), comboBox.ClientRectangle);
public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
{
- Rectangle modified_area = clip;
- modified_area.Intersect (grid.caption_area);
+ Rectangle bounds = clip;
+ bounds.Intersect (grid.caption_area);
- g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor),
- modified_area);
+ // Background
+ g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor), bounds);
- 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),
- text_rect);
+ // Bottom line
+ g.DrawLine (ResPool.GetPen (grid.CurrentTableStyle.CurrentHeaderForeColor),
+ bounds.X, bounds.Y + bounds.Height -1,
+ bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
- if (modified_area.IntersectsWith (grid.back_button_rect)) {
+ // Caption text
+ if (grid.CaptionText != String.Empty) {
+ 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),
+ text_rect);
+ }
+
+ // Back button
+ if (bounds.IntersectsWith (grid.back_button_rect)) {
g.DrawImage (grid.back_button_image, grid.back_button_rect);
if (grid.back_button_mouseover) {
CPDrawBorder3D (g, grid.back_button_rect, grid.back_button_active ? Border3DStyle.Sunken : Border3DStyle.Raised, all_sides);
}
}
- if (modified_area.IntersectsWith (grid.parent_rows_button_rect)) {
+
+ // Rows button
+ if (bounds.IntersectsWith (grid.parent_rows_button_rect)) {
g.DrawImage (grid.parent_rows_button_image, grid.parent_rows_button_rect);
if (grid.parent_rows_button_mouseover) {
CPDrawBorder3D (g, grid.parent_rows_button_rect, grid.parent_rows_button_active ? Border3DStyle.Sunken : Border3DStyle.Raised, all_sides);
public override void DataGridPaintColumnHeaders (Graphics g, Rectangle clip, DataGrid grid)
{
+ if (!grid.CurrentTableStyle.ColumnHeadersVisible)
+ return;
+
Rectangle columns_area = grid.column_headers_area;
- if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { // Paint corner shared between row and column header
+ // Paint corner shared between row and column header
+ if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
Rectangle rect_bloc = grid.column_headers_area;
rect_bloc.Width = grid.RowHeaderWidth;
if (clip.IntersectsWith (rect_bloc)) {
- if (grid.VisibleColumnCount > 0)
+ if (grid.FlatMode)
g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
else
- g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), rect_bloc);
+ CPDrawBorder3D (g, rect_bloc, Border3DStyle.RaisedInner,
+ Border3DSide.Left | Border3DSide.Right |
+ Border3DSide.Top | Border3DSide.Bottom | Border3DSide.Middle,
+ grid.CurrentTableStyle.CurrentHeaderBackColor);
}
columns_area.X += grid.RowHeaderWidth;
columns_area.Width -= grid.RowHeaderWidth;
}
- // Set unused area
- Rectangle column_headers_area_complete = columns_area;
- column_headers_area_complete.Width = grid.column_headers_max_width;
-
- if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
- column_headers_area_complete.Width -= grid.RowHeaderWidth;
- }
-
// Set column painting
Rectangle rect_columnhdr = new Rectangle ();
int col_pixel;
current_clip.Intersect (prev_clip);
g.Clip = current_clip;
- grid.CurrentTableStyle.GridColumnStyles[column].PaintHeader (g, rect_columnhdr, column);
+ DataGridPaintColumnHeader (g, rect_columnhdr, grid, column);
current_clip.Dispose ();
}
g.Clip = prev_clip;
- 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;
+ Rectangle not_usedarea = grid.column_headers_area;
+ not_usedarea.X = (column_cnt == 0) ? grid.RowHeaderWidth : rect_columnhdr.X + rect_columnhdr.Width;
+ not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - not_usedarea.X;
g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
-
+ }
+
+ public override void DataGridPaintColumnHeader (Graphics g, Rectangle bounds, DataGrid grid, int col)
+ {
+ // Background
+ g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.HeaderBackColor), bounds);
+
+ // Paint Borders
+ if (!grid.FlatMode) {
+ g.DrawLine (ResPool.GetPen (ColorControlLightLight),
+ bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
+
+ if (col == 0) {
+ g.DrawLine (ResPool.GetPen (ColorControlLightLight),
+ bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height);
+ } else {
+ g.DrawLine (ResPool.GetPen (ColorControlLightLight),
+ bounds.X, bounds.Y + 2, bounds.X, bounds.Y + bounds.Height - 3);
+ }
+
+ if (col == (grid.VisibleColumnCount -1)) {
+ g.DrawLine (ResPool.GetPen (ColorControlDark),
+ bounds.X + bounds.Width - 1, bounds.Y,
+ bounds.X + bounds.Width - 1, bounds.Y + bounds.Height);
+ } else {
+ g.DrawLine (ResPool.GetPen (ColorControlDark),
+ bounds.X + bounds.Width - 1, bounds.Y + 2,
+ bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 3);
+ }
+
+ g.DrawLine (ResPool.GetPen (ColorControlDark),
+ bounds.X, bounds.Y + bounds.Height - 1,
+ bounds.X + bounds.Width, bounds.Y + bounds.Height - 1);
+ }
+
+ bounds.X += 2;
+ bounds.Width -= 2;
+
+ DataGridColumnStyle style = grid.CurrentTableStyle.GridColumnStyles[col];
+
+ if (style.ArrowDrawingMode != DataGridColumnStyle.ArrowDrawing.No)
+ bounds.Width -= 16;
+
+ // Caption
+ StringFormat format = new StringFormat ();
+ format.FormatFlags |= StringFormatFlags.NoWrap;
+ format.LineAlignment = StringAlignment.Center;
+ format.Trimming = StringTrimming.Character;
+
+ g.DrawString (style.HeaderText, grid.CurrentTableStyle.HeaderFont,
+ ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
+ bounds, format);
+
+ // Arrow (6 x 6)
+ if (style.ArrowDrawingMode != DataGridColumnStyle.ArrowDrawing.No) {
+ Point pnt = new Point (bounds.X + bounds.Width + 4, bounds.Y + ((bounds.Height - 6)/2));
+
+ if (style.ArrowDrawingMode == DataGridColumnStyle.ArrowDrawing.Ascending) {
+ g.DrawLine (SystemPens.ControlLightLight, pnt.X + 6, pnt.Y + 6, pnt.X + 3, pnt.Y);
+ g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y + 6, pnt.X + 6, pnt.Y + 6);
+ g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y + 6, pnt.X + 3, pnt.Y);
+ } else {
+ g.DrawLine (SystemPens.ControlLightLight, pnt.X + 6, pnt.Y, pnt.X + 3, pnt.Y + 6);
+ g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y, pnt.X + 6, pnt.Y);
+ g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y, pnt.X + 3, pnt.Y + 6);
+ }
+ }
}
public override void DataGridPaintParentRows (Graphics g, Rectangle clip, DataGrid grid)
public override void DataGridPaintParentRow (Graphics g, Rectangle bounds, DataGridDataSource row, DataGrid grid)
{
- //Console.WriteLine ("drawing parent row {0}", row);
-
// Background
g.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
bounds);
text_size = g.MeasureString (table_name, bold_font).ToSize();
text_rect = new Rectangle(new Point(bounds.X + 3, bounds.Y + bounds.Height - text_size.Height), text_size);
- //Console.WriteLine ("drawing text at {0}", text_rect);
-
g.DrawString (table_name,
bold_font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
text_rect.Size = g.MeasureString (text, grid.Font).ToSize();
text_rect.Y = bounds.Y + bounds.Height - text_rect.Height; // XXX
- //Console.WriteLine ("drawing text at {0}", text_rect);
-
g.DrawString (text,
grid.Font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
}
- if (grid.FlatMode == false) {
-
- // Paint Borders
- g.DrawLine (ResPool.GetPen (ColorControlLight),
- bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
-
- g.DrawLine (ResPool.GetPen (ColorControlLight),
- bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
-
- g.DrawLine (ResPool.GetPen (ColorControlDark),
- bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
-
- g.DrawLine (ResPool.GetPen (ColorControlDark),
- bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
+ // Paint Borders
+ if (!grid.FlatMode) {
+ CPDrawBorder3D (g, bounds, Border3DStyle.RaisedInner,
+ Border3DSide.Left | Border3DSide.Right |
+ Border3DSide.Top | Border3DSide.Bottom);
}
}
(grid.CurrentTableStyle.CurrentHeaderForeColor), arrow, FillMode.Winding);
}
+ public override void DataGridPaintRowHeaderStar (Graphics g, Rectangle bounds, DataGrid grid)
+ {
+ int x = bounds.X + 4;
+ int y = bounds.Y + 3;
+ Pen pen = ResPool.GetPen (grid.CurrentTableStyle.CurrentHeaderForeColor);
+
+ g.DrawLine (pen, x + 4, y, x + 4, y + 8);
+ g.DrawLine (pen, x, y + 4, x + 8, y + 4);
+ g.DrawLine (pen, x + 1, y + 1, x + 7, y + 7);
+ g.DrawLine (pen, x + 7, y + 1, x + 1, y + 7);
+ }
+
public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid)
{
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);
+ g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), bounds);
// Draw arrow
if (is_current_row) {
}
}
else if (is_add_row) {
- g.DrawString ("*", grid.Font, ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
- bounds);
+ DataGridPaintRowHeaderStar (g, bounds, grid);
}
- if (grid.FlatMode == false && !is_add_row) {
- // Paint Borders
- g.DrawLine (ResPool.GetPen (ColorControlLight),
- bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
-
- g.DrawLine (ResPool.GetPen (ColorControlLight),
- bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
-
- g.DrawLine (ResPool.GetPen (ColorControlDark),
- bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
-
- g.DrawLine (ResPool.GetPen (ColorControlDark),
- bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
+ if (!grid.FlatMode && !is_add_row) {
+ CPDrawBorder3D (g, bounds, Border3DStyle.RaisedInner,
+ Border3DSide.Left | Border3DSide.Right |
+ Border3DSide.Top | Border3DSide.Bottom);
}
}
// PaintCells at row, column
int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
+ DataGridCell current_cell = grid.CurrentCell;
if (column_cnt > 0) {
Region prev_clip = g.Clip;
current_clip.Intersect (prev_clip);
g.Clip = current_clip;
+ Brush colBackBrush = backBrush;
+ Brush colForeBrush = foreBrush;
+
+ // If we are in the precise cell we are editing, then use the normal colors
+ // even if we are selected.
+ if (grid.is_editing && column == current_cell.ColumnNumber && row == current_cell.RowNumber) {
+ colBackBrush = ResPool.GetSolidBrush (grid.BackColor);
+ colForeBrush = ResPool.GetSolidBrush (grid.ForeColor);
+ }
+
if (is_newrow) {
grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell,
- backBrush,
- foreBrush);
+ colBackBrush,
+ colForeBrush);
} else {
grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
- backBrush,
- foreBrush,
+ colBackBrush,
+ colForeBrush,
grid.RightToLeft == RightToLeft.Yes);
}
if (!clip_rectangleF.IntersectsWith (fd.drawing_rectangle))
continue;
- text = fd.GetText (dtp.Value);
+ text = dtp.editing_part_index == i ? dtp.editing_text : fd.GetText (dtp.Value);
PointF text_position = new PointF ();
SizeF text_size;
else
text_format.FormatFlags |= StringFormatFlags.NoClip;
- if (fd.is_selected) {
+ if (fd.Selected) {
dc.FillRectangle (SystemBrushes.Highlight, text_rect);
dc.DrawString (text, dtp.Font, SystemBrushes.HighlightText, text_rect, text_format);
owner_draw = DrawListViewItemOwnerDraw (dc, item, i);
if (!owner_draw)
#endif
+ {
DrawListViewItem (dc, control, item);
+ if (control.View == View.Details)
+ DrawListViewSubItems (dc, control, item);
+ }
}
}
#if NET_2_0
- if (control.ShowGroups && control.View != View.List && control.Groups.Count > 0) {
+ if (control.UsingGroups) {
// Use InternalCount instead of Count to take into account Default Group as needed
for (int i = 0; i < control.Groups.InternalCount; i++) {
ListViewGroup group = control.Groups.GetInternalGroup (i);
ListViewInsertionMark insertion_mark = control.InsertionMark;
int insertion_mark_index = insertion_mark.Index;
- if (insertion_mark.Bounds != Rectangle.Empty &&
+ if (Application.VisualStylesEnabled && insertion_mark.Bounds != Rectangle.Empty &&
(control.View != View.Details && control.View != View.List) &&
insertion_mark_index > -1 && insertion_mark_index < control.Items.Count) {
#endif
// draw the gridlines
+#if NET_2_0
+ if (details && control.GridLines && !control.UsingGroups) {
+#else
if (details && control.GridLines) {
+#endif
+ Size control_size = control.ClientSize;
int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
- 2 : control.Font.Height + 2;
+ 0 : control.header_control.Height;
// draw vertical gridlines
- foreach (ColumnHeader col in control.Columns)
- dc.DrawLine (SystemPens.Control,
- col.Rect.Right, top,
- col.Rect.Right, control.TotalHeight);
- // draw horizontal gridlines
- ListViewItem last_item = null;
- foreach (ListViewItem item in control.Items) {
+ foreach (ColumnHeader col in control.Columns) {
+ int column_right = col.Rect.Right - control.h_marker;
dc.DrawLine (SystemPens.Control,
- item.GetBounds (ItemBoundsPortion.Entire).Left, item.GetBounds (ItemBoundsPortion.Entire).Top,
- control.TotalWidth, item.GetBounds (ItemBoundsPortion.Entire).Top);
- last_item = item;
+ column_right, top,
+ column_right, control_size.Height);
}
- // draw a line after at the bottom of the last item
- if (last_item != null) {
- dc.DrawLine (SystemPens.Control,
- last_item.GetBounds (ItemBoundsPortion.Entire).Left,
- last_item.GetBounds (ItemBoundsPortion.Entire).Bottom,
- control.TotalWidth,
- last_item.GetBounds (ItemBoundsPortion.Entire).Bottom);
+ // draw horizontal gridlines
+ int item_height = control.ItemSize.Height;
+ if (item_height == 0)
+ item_height = control.Font.Height + 2;
+
+ int y = top + item_height - (control.v_marker % item_height); // scroll bar offset
+ while (y < control_size.Height) {
+ dc.DrawLine (SystemPens.Control, 0, y, control_size.Width, y);
+ y += item_height;
}
}
if (rect.Width <= 0)
continue;
- dc.DrawString (col.Text, control.Font,
- SystemBrushes.ControlText,
- rect, col.Format);
+#if NET_2_0
+ int image_index;
+ if (control.SmallImageList == null)
+ image_index = -1;
+ else
+ image_index = col.ImageKey == String.Empty ? col.ImageIndex : control.SmallImageList.Images.IndexOfKey (col.ImageKey);
+
+ if (image_index > -1 && image_index < control.SmallImageList.Images.Count) {
+ int image_width = control.SmallImageList.ImageSize.Width + 5;
+ int text_width = (int)dc.MeasureString (col.Text, control.Font).Width;
+ int x_origin = rect.X;
+
+ switch (col.TextAlign) {
+ case HorizontalAlignment.Left:
+ break;
+ case HorizontalAlignment.Right:
+ x_origin = rect.Right - (text_width + image_width);
+ break;
+ case HorizontalAlignment.Center:
+ x_origin = (rect.Width - (text_width + image_width)) / 2 + rect.X;
+ break;
+ }
+
+ if (x_origin < rect.X)
+ x_origin = rect.X;
+
+ control.SmallImageList.Draw (dc, new Point (x_origin, rect.Y), image_index);
+ rect.X += image_width;
+ rect.Width -= image_width;
+ }
+#endif
+
+ dc.DrawString (col.Text, control.Font, SystemBrushes.ControlText, rect, col.Format);
}
int right = control.GetReorderedColumn (control.Columns.Count - 1).Rect.Right - control.h_marker;
if (right < control.Right) {
int count = Math.Min (item.ListView.Columns.Count, item.SubItems.Count);
// Do system drawing for subitems if no owner draw is done
- for (int j = 0; j < count; j++)
- if (!DrawListViewSubItemOwnerDraw (dc, item, item_state, j))
- DrawListViewSubItem (dc, item.ListView, item, j);
+ for (int j = 0; j < count; j++) {
+ if (!DrawListViewSubItemOwnerDraw (dc, item, item_state, j)) {
+ if (j == 0) // The first sub item contains the main item semantics
+ DrawListViewItem (dc, item.ListView, item);
+ else
+ DrawListViewSubItem (dc, item.ListView, item, j);
+ }
+ }
}
return true;
#if NET_2_0
// Tile view renders its Text in a different fashion
- if (control.View == View.Tile) {
+ if (control.View == View.Tile && Application.VisualStylesEnabled) {
// Item.Text is drawn using its first subitem's bounds
dc.DrawString (item.Text, item.Font, textBrush, item.SubItems [0].Bounds, format);
dc.DrawString (item.Text, font, textBrush, text_rect, format);
}
- if (control.View == View.Details && control.Columns.Count > 0) {
- // draw subitems for details view
- ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
- int count = (control.Columns.Count < subItems.Count ?
- control.Columns.Count : subItems.Count);
-
- if (count > 0) {
- // 0th subitem is the item already drawn
- for (int index = 1; index < count; index++)
- DrawListViewSubItem (dc, control, item, index);
-
- // Fill in selection for remaining columns if Column.Count > SubItems.Count
- ColumnHeader col;
- Rectangle sub_item_rect = text_rect;
- 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) {
width += col.Width;
focus_rect = new Rectangle (0, full_rect.Y, width, full_rect.Height);
}
- if (item.Selected)
- CPDrawFocusRectangle (dc, focus_rect, ColorHighlightText, ColorHighlight);
- else
- CPDrawFocusRectangle (dc, focus_rect, control.ForeColor, control.BackColor);
+ if (control.ShowFocusCues) {
+ if (item.Selected)
+ CPDrawFocusRectangle (dc, focus_rect, ColorHighlightText, ColorHighlight);
+ else
+ CPDrawFocusRectangle (dc, focus_rect, control.ForeColor, control.BackColor);
+ }
}
format.Dispose ();
}
+ protected virtual void DrawListViewSubItems (Graphics dc, ListView control, ListViewItem item)
+ {
+ int columns_count = control.Columns.Count;
+ int count = Math.Min (item.SubItems.Count, columns_count);
+ // 0th item already done (in this case)
+ for (int i = 1; i < count; i++)
+ DrawListViewSubItem (dc, control, item, i);
+
+ // Fill in selection for remaining columns if Column.Count > SubItems.Count
+ Rectangle sub_item_rect = item.GetBounds (ItemBoundsPortion.Label);
+ if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) {
+ for (int index = count; index < columns_count; index++) {
+ ColumnHeader col = control.Columns [index];
+ sub_item_rect.X = col.Rect.X - control.h_marker;
+ sub_item_rect.Width = col.Wd;
+ dc.FillRectangle (control.Focused ? SystemBrushes.Highlight : SystemBrushes.Control,
+ sub_item_rect);
+ }
+ }
+ }
+
protected virtual void DrawListViewSubItem (Graphics dc, ListView control, ListViewItem item, int index)
{
ListViewItem.ListViewSubItem subItem = item.SubItems [index];
ColumnHeader col = control.Columns [index];
StringFormat format = new StringFormat ();
format.Alignment = col.Format.Alignment;
+ format.LineAlignment = StringAlignment.Center;
format.FormatFlags = StringFormatFlags.NoWrap;
format.Trimming = StringTrimming.EllipsisCharacter;
Rectangle header_bounds = group.HeaderBounds;
text_bounds.Offset (8, 0);
text_bounds.Inflate (-8, 0);
- Size text_size = control.text_size;
+ int text_height = control.Font.Height + 2; // add a tiny padding between the text and the group line
Font font = new Font (control.Font, control.Font.Style | FontStyle.Bold);
Brush brush = new LinearGradientBrush (new Point (header_bounds.Left, 0), new Point (header_bounds.Left + ListViewGroupLineWidth, 0),
sformat.LineAlignment = StringAlignment.Near;
dc.DrawString (group.Header, font, SystemBrushes.ControlText, text_bounds, sformat);
- dc.DrawLine (pen, header_bounds.Left, header_bounds.Top + text_size.Height, header_bounds.Left + ListViewGroupLineWidth,
- header_bounds.Top + text_size.Height);
+ dc.DrawLine (pen, header_bounds.Left, header_bounds.Top + text_height, header_bounds.Left + ListViewGroupLineWidth,
+ header_bounds.Top + text_height);
sformat.Dispose ();
font.Dispose ();
// Sizing
public override int ListViewGetHeaderHeight (ListView listView, Font font)
+ {
+ return ListViewGetHeaderHeight (font);
+ }
+
+ static int ListViewGetHeaderHeight (Font font)
{
return font.Height + 5;
}
+ public static int ListViewGetHeaderHeight ()
+ {
+ return ListViewGetHeaderHeight (ThemeEngine.Current.DefaultFont);
+ }
+
public override Size ListViewCheckBoxSize {
get { return new Size (16, 16); }
}
brush_text,
rect_text, string_format);
- if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
- string str = item.GetShortCutText ();
- Rectangle rect = rect_text;
- rect.X = item.XTab;
- rect.Width -= item.XTab;
-
- e.Graphics.DrawString (str, e.Font, brush_text,
- rect, string_format_menu_shortcut);
- }
-
if (item.MenuBar) {
Border3DStyle border_style = Border3DStyle.Adjust;
if ((item.Status & DrawItemState.HotLight) != 0)
e.Graphics.DrawString (item.Text, e.Font, Brushes.White,
new RectangleF(rect_text.X + 1, rect_text.Y + 1, rect_text.Width, rect_text.Height),
string_format);
+
}
e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect_text, string_format);
}
+ if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
+ string str = item.GetShortCutText ();
+ Rectangle rect = rect_text;
+ rect.X = item.XTab;
+ rect.Width -= item.XTab;
+
+ if (item.Enabled) {
+ e.Graphics.DrawString (str, e.Font, brush_text, rect, string_format_menu_shortcut);
+ } else {
+ if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
+ e.Graphics.DrawString (str, e.Font, Brushes.White,
+ new RectangleF(rect.X + 1, rect.Y + 1, rect.Width, rect_text.Height),
+ string_format_menu_shortcut);
+
+ }
+ e.Graphics.DrawString (str, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect, string_format_menu_shortcut);
+ }
+ }
+
/* Draw arrow */
if (item.MenuBar == false && (item.IsPopup || item.MdiList)) {
public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
Rectangle client = pb.ClientRectangle;
+#if NET_2_0
+ client = new Rectangle (client.Left + pb.Padding.Left, client.Top + pb.Padding.Top, client.Width - pb.Padding.Horizontal, client.Height - pb.Padding.Vertical);
+#endif
+
// FIXME - instead of drawing the whole picturebox every time
// intersect the clip rectangle with the drawn picture and only draw what's needed,
// Also, we only need a background fill where no image goes
if (pb.Image != null) {
switch (pb.SizeMode) {
case PictureBoxSizeMode.StretchImage:
- dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
+ dc.DrawImage (pb.Image, client.Left, client.Top, client.Width, client.Height);
break;
case PictureBoxSizeMode.CenterImage:
#endif
default:
// Normal, AutoSize
- dc.DrawImage(pb.Image, 0, 0, pb.Image.Width, pb.Image.Height);
+ dc.DrawImage (pb.Image, client.Left, client.Top, pb.Image.Width, pb.Image.Height);
break;
}
case 1: { // Continuous
int pixels_to_draw;
pixels_to_draw = (int)(client_area.Width * ((double)(ctrl.Value - ctrl.Minimum) / (double)(Math.Max(ctrl.Maximum - ctrl.Minimum, 1))));
- dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), new Rectangle (client_area.X, client_area.Y, pixels_to_draw, client_area.Height));
+ dc.FillRectangle (ResPool.GetSolidBrush (ctrl.ForeColor), new Rectangle (client_area.X, client_area.Y, pixels_to_draw, client_area.Height));
break;
}
case 2: // Marquee
case 0:
default: // Blocks
Rectangle block_rect;
- int space_betweenblocks = 2;
+ int space_betweenblocks = ProgressBarChunkSpacing;
int block_width;
int increment;
int barpos_pixels;
int block_count = 0;
- block_width = (client_area.Height * 2) / 3;
+ block_width = ProgressBarGetChunkSize (client_area.Height);
+ block_width = Math.Max (block_width, 0); // block_width is used to break out the loop below, it must be >= 0!
barpos_pixels = (int)(((double)(ctrl.Value - ctrl.Minimum) * client_area.Width) / (Math.Max (ctrl.Maximum - ctrl.Minimum, 1)));
increment = block_width + space_betweenblocks;
}
if (clip_rect.IntersectsWith (block_rect) == true) {
- dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
+ dc.FillRectangle (ResPool.GetSolidBrush (ctrl.ForeColor), block_rect);
}
block_rect.X += increment;
}
}
+ public const int ProgressBarChunkSpacing = 2;
+
+ public static int ProgressBarGetChunkSize ()
+ {
+ return ProgressBarGetChunkSize (ProgressBarDefaultHeight);
+ }
+
+ static int ProgressBarGetChunkSize (int progressBarClientAreaHeight)
+ {
+ int size = (progressBarClientAreaHeight * 2) / 3;
+ return size;
+ }
+
+ const int ProgressBarDefaultHeight = 23;
+
public override Size ProgressBarDefaultSize {
get {
- return new Size (100, 23);
+ return new Size (100, ProgressBarDefaultHeight);
}
}
return;
}
- if (panel.Text == String.Empty)
- return;
-
string text = panel.Text;
StringFormat string_format = new StringFormat ();
string_format.Trimming = StringTrimming.Character;
string_format.FormatFlags = StringFormatFlags.NoWrap;
- if (text [0] == '\t') {
+ if (text != null && text.Length > 0 && text [0] == '\t') {
string_format.Alignment = StringAlignment.Center;
text = text.Substring (1);
if (text [0] == '\t') {
break;
case HorizontalAlignment.Center:
len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
- x = (panel.Width / 2) + (len / 2);
+ x = area.Left + ((panel.Width - len) / 2);
+
string_rect = new Rectangle (x, y,
area.Right - x - border_size,
area.Bottom - y - border_size);
ThemeElements.CurrentTheme.TabControlPainter.Draw (dc, area, tab);
}
- public override Rectangle TabControlGetLeftScrollRect (TabControl tab)
- {
- return ThemeElements.CurrentTheme.TabControlPainter.GetLeftScrollRect (tab);
- }
-
- public override Rectangle TabControlGetRightScrollRect (TabControl tab)
- {
- return ThemeElements.CurrentTheme.TabControlPainter.GetRightScrollRect (tab);
- }
-
public override Rectangle TabControlGetDisplayRectangle (TabControl tab)
{
return ThemeElements.CurrentTheme.TabControlPainter.GetDisplayRectangle (tab);
{
ToolTipDrawBackground (dc, clip_rectangle, control);
- Rectangle text_rect = Rectangle.Inflate (control.ClientRectangle, -2, -1);
+ TextFormatFlags flags = TextFormatFlags.HidePrefix;
#if NET_2_0
Color foreground = control.ForeColor;
+ if (control.title.Length > 0) {
+ Font bold_font = new Font (control.Font, control.Font.Style | FontStyle.Bold);
+ TextRenderer.DrawTextInternal (dc, control.title, bold_font, control.title_rect,
+ foreground, flags, false);
+ bold_font.Dispose ();
+ }
+
+ if (control.icon != null)
+ dc.DrawIcon (control.icon, control.icon_rect);
#else
Color foreground = this.ColorInfoText;
#endif
- TextFormatFlags flags = TextFormatFlags.HidePrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter;
- TextRenderer.DrawTextInternal (dc, control.Text, control.Font, text_rect, foreground, flags, false);
+
+ TextRenderer.DrawTextInternal (dc, control.Text, control.Font, control.text_rect, foreground, flags, false);
}
protected virtual void ToolTipDrawBackground (Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text)
{
Size size = TextRenderer.MeasureTextInternal (text, tt.Font, false);
-
size.Width += 4;
size.Height += 3;
-
+ Rectangle text_rect = new Rectangle (Point.Empty, size);
+ text_rect.Inflate (-2, -1);
+ tt.text_rect = text_rect;
+#if NET_2_0
+ tt.icon_rect = tt.title_rect = Rectangle.Empty;
+
+ Size title_size = Size.Empty;
+ if (tt.title.Length > 0) {
+ Font bold_font = new Font (tt.Font, tt.Font.Style | FontStyle.Bold);
+ title_size = TextRenderer.MeasureTextInternal (tt.title, bold_font, false);
+ bold_font.Dispose ();
+ }
+
+ Size icon_size = Size.Empty;
+ if (tt.icon != null)
+ icon_size = new Size (size.Height, size.Height);
+
+ if (icon_size != Size.Empty || title_size != Size.Empty) {
+ int padding = 8;
+ int top_area_width = 0;
+ int top_area_height = icon_size.Height > title_size.Height ? icon_size.Height : title_size.Height;
+ Size text_size = size;
+ Point location = new Point (padding, padding);
+
+ if (icon_size != Size.Empty) {
+ tt.icon_rect = new Rectangle (location, icon_size);
+ top_area_width = icon_size.Width + padding;
+ }
+
+ if (title_size != Size.Empty) {
+ Rectangle title_rect = new Rectangle (location, new Size (title_size.Width, top_area_height));
+ if (icon_size != Size.Empty)
+ title_rect.X += icon_size.Width + padding;
+
+ tt.title_rect = title_rect;
+ top_area_width += title_size.Width;
+ }
+
+ tt.text_rect = new Rectangle (new Point (location.X, location.Y + top_area_height + padding),
+ text_size);
+
+ size.Height += padding + top_area_height;
+ if (top_area_width > size.Width)
+ size.Width = top_area_width;
+
+ // margins
+ size.Width += padding * 2;
+ size.Height += padding * 2;
+ }
+#endif
+
return size;
}
balloon_window.Show ();
}
+ public override void HideBalloonWindow (IntPtr handle)
+ {
+ if (balloon_window == null || balloon_window.OwnerHandle != handle)
+ return;
+
+ balloon_window.Close ();
+ balloon_window.Dispose ();
+ balloon_window = null;
+ }
+
private const int balloon_iconsize = 16;
private const int balloon_bordersize = 8;
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;
+ thumb_area.Width = TrackBarVerticalTrackWidth;
pixel_len = thumb_area.Height - 11;
if (tb.Maximum == tb.Minimum) {
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;
+ thumb_area.Height = TrackBarHorizontalTrackHeight;
pixel_len = thumb_area.Width - 11;
if (tb.Maximum == tb.Minimum) {
}
protected virtual Size TrackBarGetThumbSize (TrackBar trackBar)
+ {
+ return TrackBarGetThumbSize ();
+ }
+
+ public static Size TrackBarGetThumbSize ()
{
/* Draw thumb fixed 10x22 size */
return new Size (10, 22);
}
+ public const int TrackBarVerticalTrackWidth = 4;
+
+ public const int TrackBarHorizontalTrackHeight = 4;
+
#region Ticks
protected interface ITrackBarTickPainter
{
public override int ManagedWindowBorderWidth (InternalWindowManager wm)
{
- if (wm is ToolWindowManager && wm.form.FormBorderStyle == FormBorderStyle.FixedToolWindow)
+ if ((wm.IsToolWindow && wm.form.FormBorderStyle == FormBorderStyle.FixedToolWindow) ||
+ wm.IsMinimized)
return 3;
else
return 4;
break;
}
+ // Respect MinimizeBox/MaximizeBox
+ if (form.MinimizeBox == false && form.MaximizeBox == false) {
+ buttons.MinimizeButton.Visible = false;
+ buttons.MaximizeButton.Visible = false;
+ } else if (form.MinimizeBox == false)
+ buttons.MinimizeButton.State = ButtonState.Inactive;
+ else if (form.MaximizeBox == false)
+ buttons.MaximizeButton.State = ButtonState.Inactive;
+
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;
+ int left = form.Width - bw - btw - ManagedWindowSpacingAfterLastTitleButton;
if ((!wm.IsToolWindow || wm.IsMinimized) && wm.HasBorders) {
buttons.CloseButton.Rectangle = new Rectangle (left, top, btw, bth);
}
}
- public override void DrawManagedWindowDecorations (Graphics dc, Rectangle clip, InternalWindowManager wm)
+ protected virtual Rectangle ManagedWindowDrawTitleBarAndBorders (Graphics dc, Rectangle clip, InternalWindowManager wm)
{
Form form = wm.Form;
int tbheight = ManagedWindowTitleBarHeight (wm);
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
-
Pen pen = ResPool.GetPen (ColorControl);
Rectangle borders = new Rectangle (0, 0, form.Width, form.Height);
ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised);
}
}
- // 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.IsMinimized)
+ // 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);
+ return tb;
+ }
- if (!wm.IsToolWindow) {
- tb.X += 18; // Room for the icon and the buttons
- tb.Width = (form.Width - 62) - tb.X;
+ public override void DrawManagedWindowDecorations (Graphics dc, Rectangle clip, InternalWindowManager wm)
+ {
+#if debug
+ Console.WriteLine (DateTime.Now.ToLongTimeString () + " DrawManagedWindowDecorations");
+ dc.FillRectangle (Brushes.Black, clip);
+#endif
+ Rectangle tb = ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
+
+ Form form = wm.Form;
+ if (wm.ShowIcon) {
+ Rectangle icon = ManagedWindowGetTitleBarIconArea (wm);
+ if (icon.IntersectsWith (clip))
+ dc.DrawIcon (form.Icon, icon);
+ const int SpacingBetweenIconAndCaption = 2;
+ tb.Width -= icon.Right + SpacingBetweenIconAndCaption - tb.X ;
+ tb.X = icon.Right + SpacingBetweenIconAndCaption;
}
+
+ foreach (TitleButton button in wm.TitleButtons.AllButtons) {
+ tb.Width -= Math.Max (0, tb.Right - DrawTitleButton (dc, button, clip, form));
+ }
+ const int SpacingBetweenCaptionAndLeftMostButton = 3;
+ tb.Width -= SpacingBetweenCaptionAndLeftMostButton;
string window_caption = form.Text;
window_caption = window_caption.Replace (Environment.NewLine, string.Empty);
ThemeEngine.Current.ResPool.GetSolidBrush (Color.White),
tb, format);
}
-
- if (wm.ShowIcon) {
- Rectangle icon = ManagedWindowGetTitleBarIconArea (wm);
- if (icon.IntersectsWith (clip))
- dc.DrawIcon (form.Icon, icon);
- }
-
- foreach (TitleButton button in wm.TitleButtons.AllButtons) {
- DrawTitleButton (dc, button, clip);
- }
}
public override Size ManagedWindowButtonSize (InternalWindowManager wm)
height - 5);
}
- private void DrawTitleButton (Graphics dc, TitleButton button, Rectangle clip)
+ private int DrawTitleButton (Graphics dc, TitleButton button, Rectangle clip, Form form)
{
if (!button.Visible) {
- return;
+ return int.MaxValue;
}
- if (!button.Rectangle.IntersectsWith (clip))
- return;
+ if (button.Rectangle.IntersectsWith (clip)) {
+ ManagedWindowDrawTitleButton (dc, button, clip, form);
+ }
+ return button.Rectangle.Left;
+ }
+ protected virtual void ManagedWindowDrawTitleButton (Graphics dc, TitleButton button, Rectangle clip, Form form)
+ {
dc.FillRectangle (SystemBrushes.Control, button.Rectangle);
ControlPaint.DrawCaptionButton (dc, button.Rectangle,
result.Height -= 4;
return result;
}
+
+ public override bool ManagedWindowTitleButtonHasHotElementStyle (TitleButton button, Form form)
+ {
+ return false;
+ }
+
+ public override void ManagedWindowDrawMenuButton (Graphics dc, TitleButton button, Rectangle clip, InternalWindowManager wm)
+ {
+ dc.FillRectangle (SystemBrushes.Control, button.Rectangle);
+ ControlPaint.DrawCaptionButton (dc, button.Rectangle,
+ button.Caption, button.State);
+ }
+
+ public override void ManagedWindowOnSizeInitializedOrChanged (Form form)
+ {
+ }
#endregion
#region ControlPaint
}
- [MonoTODO]
+ [MonoInternalNote ("Does not respect Mixed")]
public override void CPDrawMixedCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state)
{
CPDrawCheckBox (graphics, rectangle, state);