* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThemeWin32Classic.cs
index c576afdd6b54496485d597137c73a94853aa0ae5..b2d26b3100b4a55b0fb50c5017abb231f03136ee 100644 (file)
@@ -32,6 +32,7 @@ using System.Drawing;
 using System.Drawing.Drawing2D;
 using System.Drawing.Imaging;
 using System.Drawing.Text;
+using System.Text;
 
 namespace System.Windows.Forms
 {
@@ -862,18 +863,31 @@ namespace System.Windows.Forms
                                }
                        }
                }
-               
+
                public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
                {
                        Rectangle modified_area = clip;
                        modified_area.Intersect (grid.caption_area);
 
                        g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor),
-                               modified_area);
+                                        modified_area);
 
                        g.DrawString (grid.CaptionText, grid.CaptionFont,
-                               ResPool.GetSolidBrush (grid.CaptionForeColor),
-                               grid.caption_area);
+                                     ResPool.GetSolidBrush (grid.CaptionForeColor),
+                                     grid.caption_area);
+
+                       if (modified_area.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)) {
+                               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)
@@ -948,26 +962,20 @@ namespace System.Windows.Forms
 
                        g.SetClip (grid.ParentRowsArea);
 
-                       object[] parentRows = grid.parentRows.ToArray();
+                       object[] parentRows = grid.dataSourceStack.ToArray();
                        
                        Region current_clip;
                        for (int row = 0; row < parentRows.Length; row++) {
-                               Console.WriteLine ("row {0}", row);
-
                                rect_row.Y = grid.ParentRowsArea.Y + row * rect_row.Height;
 
-                               Console.WriteLine ("rect_row = {0}", rect_row);
-
-                               if (clip.IntersectsWith (rect_row) == false) {
-                                       Console.WriteLine ("doesn't intersect");
+                               if (clip.IntersectsWith (rect_row) == false)
                                        continue;
-                               }
 
                                current_clip = new Region (rect_row);
                                current_clip.Intersect (clip);
                                g.Clip = current_clip;
 
-                               DataGridPaintParentRow (g, rect_row, (DataGridParentRow)parentRows[parentRows.Length - row - 1], grid);
+                               DataGridPaintParentRow (g, rect_row, (DataGridDataSource)parentRows[parentRows.Length - row - 1], grid);
 
                                current_clip.Dispose ();
                        }
@@ -975,7 +983,7 @@ namespace System.Windows.Forms
                        g.ResetClip ();
                }
 
-               public override void DataGridPaintParentRow (Graphics g, Rectangle bounds, DataGridParentRow row, DataGrid grid)
+               public override void DataGridPaintParentRow (Graphics g, Rectangle bounds, DataGridDataSource row, DataGrid grid)
                {
                        //Console.WriteLine ("drawing parent row {0}", row);
 
@@ -1066,46 +1074,42 @@ 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_current_row = row == grid.CurrentCell.RowNumber;
+
                        // Background
                        g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor),
                                bounds);
-                               
-                       if (grid.ShowEditRow && grid.RowsCount > 0 && row == grid.RowsCount  && !(row == grid.CurrentCell.RowNumber && grid.IsChanging == true)) {
-                               
+
+                       // Draw arrow
+                       if (is_current_row) {
+                               if (grid.IsChanging) {
+                                       g.DrawString ("...", grid.Font,
+                                                     ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
+                                                     bounds);
+                               } else {
+                                       Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
+                                       DataGridPaintRowHeaderArrow (g, rect, grid);
+                               }
+                       }
+                       else if (is_add_row) {
                                g.DrawString ("*", grid.Font, ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
-                                       bounds);
-                               
-                       } else {
-                               if (grid.FlatMode == false) {
-                               
-                                       // Paint Borders
-                                       g.DrawLine (ResPool.GetPen (ColorControlLight),
-                                                   bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
+                                             bounds);
+                       }
 
-                                       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);
+                       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 (ColorControlDark),
-                                                   bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y  + bounds.Height -1);
-                               }
+                               g.DrawLine (ResPool.GetPen (ColorControlLight),
+                                           bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
 
-                               // Draw arrow
-                               if (row == grid.CurrentCell.RowNumber) {
-       
-                                       if (grid.IsChanging == true) {
-                                               g.DrawString ("...", grid.Font,
-                                                       ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
-                                                       bounds);
-       
-                                       } else {
-                                               
-                                               Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
-                                               DataGridPaintRowHeaderArrow (g, rect, grid);
-                                       }
-                               }
+                               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);
                        }
                }
                
@@ -1114,43 +1118,39 @@ namespace System.Windows.Forms
                        Rectangle rect_row = new Rectangle ();
                        Rectangle not_usedarea = new Rectangle ();
 
-                       int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
+                       int rowcnt = grid.VisibleRowCount;
                        
-                       if (grid.ShowEditRow && grid.RowsCount > 0) {
-                               rowcnt--;
-                       }                       
+                       bool showing_add_row = false;
+
+                       if (grid.ListManager.Count < grid.Rows.Length) {
+                               /* the table has an add row */
+
+                               if (grid.FirstVisibleRow + grid.VisibleRowCount >= grid.Rows.Length) {
+                                       showing_add_row = true;
+                               }
+                       }
 
-                       if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
-                               rowcnt++;
-                       }                       
-                       
                        rect_row.Width = cells.Width;
-                       for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {                                                             
+                       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;
                                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;
                                if (clip.IntersectsWith (rect_row)) {
-                                       if (grid.CurrentTableStyle.HasRelations)
+                                       if (grid.CurrentTableStyle.HasRelations
+                                           && !(showing_add_row && row == grid.Rows.Length - 1))
                                                DataGridPaintRelationRow (g, row, rect_row, false, clip, grid);
                                        else
-                                               DataGridPaintRow (g, row, rect_row, false, clip, grid);
-                               }
-                       }
-
-                       // XXX
-                       if (grid.ShowEditRow && grid.RowsCount > 0 && grid.FirstVisibleRow + grid.VisibleRowCount == grid.RowsCount + 1) {
-                               rect_row.Y = rect_row.Y + rect_row.Height;
-                               rect_row.Height = grid.RowHeight;
-                               if (clip.IntersectsWith (rect_row)) {
-                                       DataGridPaintRow (g, rowcnt, rect_row, true, clip, grid);
+                                               DataGridPaintRow (g, row, rect_row, showing_add_row && row == grid.Rows.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.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height;
                        not_usedarea.Y = rect_row.Y + rect_row.Height;
-                       not_usedarea.Width = rect_row.Width = cells.Width + grid.RowHeadersArea.Width;
+                       not_usedarea.Width = cells.Width + grid.RowHeadersArea.Width;
                        not_usedarea.X = 0;
 
                        g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
@@ -1201,6 +1201,24 @@ namespace System.Windows.Forms
                        DataGridPaintRowContents (g, row, nested_rect, is_newrow, clip, grid);
 
                        if (grid.Rows[row].IsExpanded) {
+                               // XXX we should create this in the
+                               // datagrid and cache it for use by
+                               // the theme instead of doing it each
+                               // time through here
+                               string[] relations = grid.CurrentTableStyle.Relations;
+                               StringBuilder relation_builder = new StringBuilder ("");
+
+                               for (int i = 0; i < relations.Length; i ++) {
+                                       if (i > 0)
+                                               relation_builder.Append ("\n");
+
+                                       relation_builder.Append (relations[i]);
+                               }
+                               string relation_text = relation_builder.ToString ();
+
+                               StringFormat string_format = new StringFormat ();
+                               string_format.FormatFlags |= StringFormatFlags.NoWrap;
+
 
                                //Region prev_clip = g.Clip;
                                //Region current_clip;
@@ -1218,7 +1236,11 @@ namespace System.Windows.Forms
                                g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.CurrentTableStyle.BackColor),
                                                 rect_cell);
 
-                               Rectangle outline = grid.Rows[row].relation_link.Bounds;
+
+                               /* draw the line leading from the +/- to the relation area */
+                               Rectangle outline = grid.Rows[row].relation_area;
+                               outline.Y = rect_cell.Y;
+                               outline.Height --;
 
                                g.DrawLine (pen,
                                            icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height,
@@ -1228,6 +1250,11 @@ namespace System.Windows.Forms
                                            icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2,
                                            outline.X, outline.Y + outline.Height / 2);
 
+                               g.DrawRectangle (pen, outline);
+
+                               g.DrawString (relation_text, grid.LinkFont, ResPool.GetSolidBrush (grid.LinkColor),
+                                             outline, string_format);
+
                                if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
                                        Rectangle not_usedarea = new Rectangle ();
                                        not_usedarea.X = rect_cell.X + rect_cell.Width;