Beispiel #1
0
 public Column(string headerText, string footerText, Cell cell, double width, string sortKey)
 {
     HeaderText   = headerText;
     FooterText   = footerText;
     HeaderCell   = new CellTextHeader();
     FooterCell   = new CellTextFooter();
     ListCell     = cell;
     this.width   = width;
     this.sortKey = sortKey;
     isSortable   = !string.IsNullOrEmpty(sortKey);
 }
        private void PaintRows(Rectangle clip)
        {
            sort_column_index = -1;
            for (int i = 0; i < column_cache.Length; i++)
            {
                if (!column_cache [i].Column.Visible)
                {
                    continue;
                }

                Column column = column_cache [i].Column;
                if (sortModel == null)
                {
                    continue;
                }

                CellTextHeader column_cell = column.HeaderCell as CellTextHeader;
                if (column_cell == null)
                {
                    continue;
                }

                if (column.IsSortable && sortModel.SortColumn == column)
                {
                    sort_column_index = i;
                }
            }

            if (sort_column_index != -1 && (!pressed_column_is_dragging || pressed_column_index != sort_column_index))
            {
                CachedColumn col = column_cache [sort_column_index];
                Theme.DrawRowRule(cairo_context,
                                  list_rendering_alloc.X + col.X1 - (int)hadjustment.Value,
                                  header_rendering_alloc.Bottom + Theme.BorderWidth,
                                  col.Width, list_rendering_alloc.Height + Theme.InnerBorderWidth * 2);
            }

            clip.Intersect(list_rendering_alloc);
            cairo_context.Rectangle(clip.X, clip.Y, clip.Width, clip.Height);
            cairo_context.Clip();

            cell_context.Clip             = clip;
            cell_context.TextAsForeground = false;

            int vadjustment_value = (int)vadjustment.Value;
            int first_row         = vadjustment_value / RowHeight;
            int last_row;

            try {
                last_row = Math.Min(model.Count, first_row + RowsInView);
            } catch (DbConnectionLostException) {
                last_row = first_row + RowsInView;
            }
            int offset = list_rendering_alloc.Y - vadjustment_value % RowHeight;

            Rectangle selected_focus_alloc = Rectangle.Zero;
            Rectangle single_list_alloc    = new Rectangle();

            single_list_alloc.X      = list_rendering_alloc.X - (int)(hadjustment.Value);
            single_list_alloc.Y      = offset;
            single_list_alloc.Width  = list_rendering_alloc.Width;
            single_list_alloc.Height = RowHeight;

            int selection_height = 0;
            int selection_y      = 0;

            selected_rows.Clear();

            for (int ri = first_row; ri < last_row; ri++)
            {
                if (Selection != null && Selection.Contains(ri))
                {
                    if (selection_height == 0)
                    {
                        selection_y = single_list_alloc.Y;
                    }

                    selection_height += single_list_alloc.Height;
                    selected_rows.Add(ri);

                    if (Selection.FocusedCell.Row == ri)
                    {
                        selected_focus_alloc = single_list_alloc;
                    }
                }
                else
                {
                    if (rules_hint && ri % 2 != 0)
                    {
                        Theme.DrawRowRule(cairo_context, list_rendering_alloc.X, single_list_alloc.Y,
                                          single_list_alloc.Width, single_list_alloc.Height);
                    }

                    if (ri == drag_reorder_row_index && Reorderable)
                    {
                        cairo_context.Save();
                        cairo_context.LineWidth = 1.0;
                        cairo_context.Antialias = Cairo.Antialias.None;
                        cairo_context.MoveTo(single_list_alloc.Left, single_list_alloc.Top);
                        cairo_context.LineTo(single_list_alloc.Right, single_list_alloc.Top);
                        cairo_context.Color = Theme.Colors.GetWidgetColor(GtkColorClass.Text, StateType.Normal);
                        cairo_context.Stroke();
                        cairo_context.Restore();
                    }

                    if (Selection != null && Selection.FocusedCell.Row == ri && !Selection.Contains(ri) && AllowSelect)
                    {
                        CairoCorners corners = CairoCorners.All;

                        if (Selection.Contains(ri - 1))
                        {
                            corners &= ~(CairoCorners.TopLeft | CairoCorners.TopRight);
                        }

                        if (Selection.Contains(ri + 1))
                        {
                            corners &= ~(CairoCorners.BottomLeft | CairoCorners.BottomRight);
                        }

                        Theme.DrawRowSelection(cairo_context, single_list_alloc.X, single_list_alloc.Y,
                                               single_list_alloc.Width, single_list_alloc.Height, false, true,
                                               Theme.Colors.GetWidgetColor(GtkColorClass.Background, StateType.Selected), corners);
                    }

                    if (selection_height > 0)
                    {
                        Theme.DrawRowSelection(cairo_context, list_rendering_alloc.X, selection_y, list_rendering_alloc.Width, selection_height);
                        selection_height = 0;
                    }

                    PaintRow(ri, single_list_alloc, StateType.Normal);
                }

                single_list_alloc.Y += single_list_alloc.Height;
            }

            if (selection_height > 0)
            {
                Theme.DrawRowSelection(cairo_context, list_rendering_alloc.X, selection_y,
                                       list_rendering_alloc.Width, selection_height);
            }

            if (Selection != null && Selection.Count > 1 &&
                !selected_focus_alloc.Equals(Rectangle.Zero) && HasFocus)
            {
                Theme.DrawRowSelection(cairo_context, selected_focus_alloc.X, selected_focus_alloc.Y,
                                       selected_focus_alloc.Width, selected_focus_alloc.Height, false, true,
                                       Theme.Colors.GetWidgetColor(GtkColorClass.Dark, StateType.Selected));
            }

            foreach (int ri in selected_rows)
            {
                single_list_alloc.Y = offset + ((ri - first_row) * single_list_alloc.Height);
                PaintRow(ri, single_list_alloc, StateType.Selected);
            }

            cairo_context.ResetClip();
        }