void drawingarea_ButtonPressEvent(object o, ButtonPressEventArgs args) { if (args.Event.Button == 1) { int row = (int)args.Event.Y / ConstantHeight + (int)vscrollbar1.Value; OffsetCursor(row - CurrentRow); if (!HasFocus) { GrabFocus(); } } if (ItemClickedEvent != null) { // genereate event ItemClicked(row, column) ColumnControl.Column[] columns = mColumnControl.GetVisibleColumnsInDrawOrder(); int dx = -(int)hscrollbar1.Value; for (int c = 0; c < columns.Length; c++) { ColumnControl.Column column = columns[c]; int columnIndex = column.SortOrder; int xwidth = column.Width + mColumnControl.GripperWidth; if (args.Event.X >= dx && args.Event.X <= dx + xwidth) { ItemClickedEvent(args, SelectedRow, column.Tag); break; } dx += xwidth; } } }
void drawingarea_MotionNotifyEvent(object o, MotionNotifyEventArgs args) { var evnt = args.Event; int h = ConstantHeight + (int)vscrollbar1.Value; if (h == 0) { return; } int row = (int)evnt.Y / h; if (ItemHoveredEvent != null) { // genereate event ItemClicked(row, column) ColumnControl.Column[] columns = mColumnControl.GetVisibleColumnsInDrawOrder(); int dx = -(int)hscrollbar1.Value; for (int c = 0; c < columns.Length; c++) { ColumnControl.Column column = columns[c]; int columnIndex = column.SortOrder; int xwidth = column.Width + mColumnControl.GripperWidth; if (evnt.X >= dx && evnt.X <= dx + xwidth) { ItemHoveredEvent(row, column.Tag); break; } dx += xwidth; } } }
void drawingarea_ButtonPressEvent(object o, ButtonPressEventArgs args) { var evnt = args.Event; if (evnt.TriggersContextMenu()) { if (OwnerDrawPopupEvent != null) { Menu menu = new Menu(); var item = new TaggedLocalizedMenuItem("Header"); var submenu = PrepareHeaderSelectPopupMenu(); item.Submenu = submenu; menu.Add(item); menu.Add(new SeparatorMenuItem()); OwnerDrawPopupEvent(menu, evnt.Time); } else { ShowDockPopupMenu(evnt.Time); } } else if (evnt.Button == Mouse.LEFT_MOUSE_BUTTON) { int row = (int)evnt.Y / ConstantHeight + (int)vscrollbar1.Value; OffsetCursor(row - CurrentRow, true); if (!HasFocus) { GrabFocus(); } if (ItemClickedEvent != null) { // genereate event ItemClicked(row, column) ColumnControl.Column[] columns = mColumnControl.GetVisibleColumnsInDrawOrder(); int dx = -(int)hscrollbar1.Value; for (int c = 0; c < columns.Length; c++) { ColumnControl.Column column = columns[c]; int columnIndex = column.SortOrder; int xwidth = column.Width + mColumnControl.GripperWidth; if (evnt.X >= dx && evnt.X <= dx + xwidth) { ItemClickedEvent(args, CurrentRow, column.Tag); break; } dx += xwidth; } } } }
// TODO throw away this function, use ShowContextMenu() from class TreeViewExtensions internal void ShowDockPopupMenu(uint time) { Menu menu = new Menu(); ColumnControl.Column[] columns = mColumnControl.GetColumns(); foreach (ColumnControl.Column c in columns) { TaggedLocalizedCheckedMenuItem item = new TaggedLocalizedCheckedMenuItem(c.Name); item.Active = c.Visible; item.Tag = c; item.Activated += (object sender, EventArgs e) => { TaggedLocalizedCheckedMenuItem it = sender as TaggedLocalizedCheckedMenuItem; ColumnControl.Column ct = it.Tag as ColumnControl.Column; // TODO: change column visibility, recalculate column control and redraw all //ct.Visible = !ct.Visible; }; menu.Add(item); } menu.ShowAll(); menu.Popup(null, null, null, 3, time); }
protected void OnDrawingareaExposeEvent(object o, Gtk.ExposeEventArgs args) { Gdk.EventExpose expose = args.Args[0] as Gdk.EventExpose; Gdk.Window win = expose.Window; int width, height; win.GetSize(out width, out height); Gdk.Rectangle exposeRect = expose.Area; bool fulldraw = width == exposeRect.Width && height == exposeRect.Height; win.DrawRectangle(Style.LightGC(StateType.Normal), true, exposeRect); if (GetContentDelegate == null) { return; // todo: an error message could be displayed } int offset = (int)vscrollbar1.Value; if (fulldraw) { TopVisibleRow = offset; BottomVisibleRow = offset; } int hscrollRange = 0; int dy = exposeRect.Top; offset += dy / ConstantHeight; dy -= dy % ConstantHeight; Gdk.GC backgound = new Gdk.GC((Gdk.Drawable)base.GdkWindow); Gdk.GC text = new Gdk.GC((Gdk.Drawable)base.GdkWindow); ColumnControl.Column[] columns = mColumnControl.GetVisibleColumnsInDrawOrder(); for (int row = offset; row < RowCount; row++) { int dx = -(int)hscrollbar1.Value; Gdk.Rectangle rect = new Gdk.Rectangle(dx, dy, 0, ConstantHeight); System.Drawing.Color backColor = System.Drawing.Color.WhiteSmoke; System.Drawing.Color textColor = System.Drawing.Color.Black; if (isRowSelected(row)) { if (HasFocus) { backColor = System.Drawing.Color.DarkGray; } else { backColor = System.Drawing.Color.LightGray; } } else { if (GetColorDelegate != null) { GetColorDelegate(row, ref backColor, ref textColor); } } backgound.RgbFgColor = new Gdk.Color(backColor.R, backColor.G, backColor.B); text.RgbFgColor = new Gdk.Color(textColor.R, textColor.G, textColor.B); for (int c = 0; c < columns.Length; c++) { ColumnControl.Column column = columns[c]; int columnIndex = column.SortOrder; int xwidth = column.Width; if (dx > exposeRect.Right) { break; } rect = new Gdk.Rectangle(rect.Left, rect.Top, xwidth + mColumnControl.GripperWidth, ConstantHeight); if (c == columns.Length - 1) { rect.Width = Math.Max(rect.Width, exposeRect.Right - rect.Left + 1); } object content = GetContentDelegate(row, columnIndex); if (content is Gdk.Pixbuf) { Gdk.Pixbuf image = (Gdk.Pixbuf)content; win.DrawRectangle(backgound, true, rect); dx += 2; image.RenderToDrawable(win, text, 0, 0, dx, dy, image.Width, image.Height, Gdk.RgbDither.Normal, 0, 0); dx += xwidth + mColumnControl.GripperWidth - 2; rect.Offset(xwidth + mColumnControl.GripperWidth, 0); } else { LineLayout.SetText(content.ToString()); win.DrawRectangle(backgound, true, rect); dx += 2; win.DrawLayout(text, dx, dy, LineLayout); dx += xwidth + mColumnControl.GripperWidth - 2; rect.Offset(xwidth + mColumnControl.GripperWidth, 0); } } hscrollRange = Math.Max(hscrollRange, dx + rect.Width); dy += ConstantHeight; if (dy > exposeRect.Bottom) { break; } if (fulldraw && exposeRect.Height - dy >= ConstantHeight) { BottomVisibleRow++; } } if (fulldraw) { int pageSize = BottomVisibleRow - TopVisibleRow; if (vscrollbar1.Adjustment.PageSize != pageSize) { vscrollbar1.Adjustment.PageSize = pageSize; vscrollbar1.Adjustment.PageIncrement = pageSize; } hscrollRange += (int)hscrollbar1.Value; if (hscrollRange > 0) { hscrollbar1.SetRange(0, hscrollRange); } // position current row inside visible area // TODO: please think about, because of double redraw a more sophisticated solution could be possible if (CurrentRow >= 0 && CurrentRow < RowCount) { if (CurrentRow < TopVisibleRow) { OffsetCursor(TopVisibleRow - CurrentRow); } else if (CurrentRow > BottomVisibleRow) { OffsetCursor(BottomVisibleRow - CurrentRow); } } } #if DEBUG2 if (ComponentManager != null) { String t1 = String.Format("Expose.Area={0}, size={1}.{2}", expose.Area.ToString(), width, height); String t2 = String.Format("{0} T={1} B={2}", fulldraw ? "FULL" : "PART", TopVisibleRow, BottomVisibleRow); ComponentManager.MessageWriteLineInvoke(String.Format("{0} {1}", t1, t2)); } #endif }