Ejemplo n.º 1
0
 private void HandleHeaderResizerMouseDown(int itemIndex, ColumnResizeSide resizeSide, MouseEventArgs e)
 {
     _columnResizeProcess = ColumnResizeProcess.FromActiveColumn(Columns, itemIndex, resizeSide, e.Location);
 }
Ejemplo n.º 2
0
 protected override void OnMouseUp(MouseEventArgs e)
 {
     if(_draggedHeaderIndex != -1)
     {
         if(_headerDragHelper.IsDragging)
         {
             if(_draggedHeaderPositionIndex != _draggedHeaderIndex)
             {
                 _columns.Changed -= OnColumnsChanged;
                 _columns.RemoveAt(_draggedHeaderIndex);
                 if(_draggedHeaderPositionIndex > _draggedHeaderIndex)
                 {
                     --_draggedHeaderPositionIndex;
                 }
                 _columns.Insert(_draggedHeaderPositionIndex, _draggedHeader);
                 _columns.Changed += OnColumnsChanged;
             }
             _draggedHeaderIndex = -1;
             UpdateColumnOffsets();
             Invalidate(ClientArea);
         }
         else
         {
             _columns[_draggedHeaderIndex].NotifyClick();
             _draggedHeaderIndex = -1;
             Invalidate(_headersArea);
         }
     }
     if(_headerDragHelper.IsTracking)
     {
         _headerDragHelper.Stop();
     }
     if(_columnResizeProcess != null)
     {
         _columnResizeProcess.Update(e.Location);
         _columnResizeProcess = null;
     }
     base.OnMouseUp(e);
 }
Ejemplo n.º 3
0
 protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
 {
     e.IsInputKey = true;
     switch(e.KeyCode)
     {
         case Keys.Enter:
             if(_itemFocus.IsTracked)
             {
                 var item = _itemFocus.Item;
                 item.Activate();
             }
             break;
         case Keys.Escape:
             if(_columnResizeProcess != null)
             {
                 _columnResizeProcess.Cancel();
                 _columnResizeProcess = null;
             }
             break;
         case Keys.Right:
             if(_itemPlainList.Count == 0) return;
             if(_itemFocus.Index < 0 || _itemFocus.Index >= _itemPlainList.Count)
             {
                 FocusAndSelectItem(0);
             }
             else
             {
                 var item = _itemPlainList[_itemFocus.Index];
                 if(item.Items.Count == 0) return;
                 if(item.IsExpanded)
                 {
                     FocusAndSelectItem(_itemFocus.Index + 1);
                 }
                 else
                 {
                     item.IsExpanded = true;
                 }
             }
             break;
         case Keys.Left:
             if(_itemPlainList.Count == 0) return;
             if(_itemFocus.Index < 0 || _itemFocus.Index >= _itemPlainList.Count)
             {
                 FocusAndSelectItem(_itemPlainList.Count - 1);
             }
             else
             {
                 var item = _itemPlainList[_itemFocus.Index];
                 if(item.IsExpanded)
                 {
                     if(_showRootTreeLines || item.Level != 0)
                     {
                         item.IsExpanded = false;
                     }
                 }
                 else
                 {
                     if(item.Parent == null) return;
                     FocusAndSelectItem(_itemPlainList.IndexOf(item.Parent));
                 }
             }
             break;
         case Keys.Home:
             if(_itemPlainList.Count == 0) return;
             if(_itemFocus.Index != 0)
             {
                 FocusAndSelectItem(0);
             }
             else
             {
                 EnsureVisible(_itemFocus.Index);
             }
             break;
         case Keys.End:
             if(_itemPlainList.Count == 0) return;
             if(_itemFocus.Index != _itemPlainList.Count - 1)
             {
                 FocusAndSelectItem(_itemPlainList.Count - 1);
             }
             else
             {
                 EnsureVisible(_itemFocus.Index);
             }
             break;
         case Keys.PageUp:
             if(_itemPlainList.Count == 0) return;
             {
                 var index = _itemFocus.Index - GetItemsOnPage();
                 if(index < 0) index = 0;
                 if(_itemFocus.Index != index)
                 {
                     FocusAndSelectItem(index);
                 }
                 else
                 {
                     EnsureVisible(_itemFocus.Index);
                 }
             }
             break;
         case Keys.PageDown:
             if(_itemPlainList.Count == 0) return;
             {
                 var index = _itemFocus.Index + GetItemsOnPage();
                 if(index >= _itemPlainList.Count) index = _itemPlainList.Count - 1;
                 if(_itemFocus.Index != index)
                 {
                     FocusAndSelectItem(index);
                 }
                 else
                 {
                     EnsureVisible(_itemFocus.Index);
                 }
             }
             break;
         case Keys.Up:
             if(_itemPlainList.Count == 0) return;
             if(_itemFocus.Index > 0)
             {
                 int index = _itemFocus.Index - 1;
                 if(Control.ModifierKeys == Keys.Control)
                 {
                     FocusItem(index);
                 }
                 else
                 {
                     FocusAndSelectItem(index);
                 }
             }
             break;
         case Keys.Down:
             if(_itemPlainList.Count == 0) return;
             if(_itemFocus.Index < _itemPlainList.Count - 1)
             {
                 int index = _itemFocus.Index + 1;
                 if(Control.ModifierKeys == Keys.Control)
                 {
                     FocusItem(index);
                 }
                 else
                 {
                     FocusAndSelectItem(index);
                 }
             }
             break;
         case Keys.Space:
             switch(_selectedItems.Count)
             {
                 case 0:
                     if(_itemFocus.IsTracked)
                     {
                         FocusAndSelectItem(_itemFocus.Index);
                     }
                     break;
                 default:
                     if(Control.ModifierKeys == Keys.Control)
                     {
                         if(_itemFocus.IsTracked)
                         {
                             var item = _itemPlainList[_itemFocus.Index];
                             if(item.IsSelected)
                             {
                                 _selectedItems.Remove(item);
                                 InvalidateItem(_itemFocus.Index);
                             }
                             else if(_multiselect)
                             {
                                 _selectedItems.Add(item);
                                 InvalidateItem(_itemFocus.Index);
                             }
                         }
                     }
                     else
                     {
                         if(_selectedItems.Count == 1)
                         {
                             if(_showCheckBoxes)
                             {
                                 var item = _selectedItems[0];
                                 switch(item.CheckedState)
                                 {
                                     case CheckedState.Checked:
                                         item.CheckedState = CheckedState.Unchecked;
                                         break;
                                     case CheckedState.Unchecked:
                                         item.CheckedState = CheckedState.Checked;
                                         break;
                                 }
                             }
                             else
                             {
                                 FocusAndSelectItem(_itemFocus.Index);
                             }
                         }
                     }
                     break;
             }
             break;
         case Keys.A:
             if(_multiselect && Control.ModifierKeys == Keys.Control)
             {
                 if(_selectedItems.Count != _itemPlainList.Count)
                 {
                     _selectedItems.Clear();
                     _selectedItems.AddRange(_itemPlainList);
                     Invalidate(_itemsArea);
                 }
             }
             break;
         case (Keys)0x5D:
             {
                 ToolStripDropDown menu;
                 var p = _itemsArea.Location;
                 p.X += _itemHeight / 2;
                 int columnIndex = -1;
                 CustomListBoxColumn column = null;
                 for(int i = 0; i < _columns.Count; ++i)
                 {
                     if(_columns[i].IsVisible)
                     {
                         columnIndex = i;
                         column = _columns[i];
                         break;
                     }
                 }
                 switch(_selectedItems.Count)
                 {
                     case 0:
                         {
                             var args = new ContextMenuRequestEventArgs(column, columnIndex, p.X, p.Y);
                             Events.Raise(ContextMenuRequestedEvent, this, args);
                             if(args.OverrideDefaultMenu)
                             {
                                 menu = args.ContextMenu;
                             }
                             else
                             {
                                 menu = GetFreeSpaceContextMenu(args);
                             }
                         }
                         break;
                     case 1:
                         {
                             var index = _itemPlainList.IndexOf(_selectedItems[0]);
                             EnsureVisible(index);
                             p.Y = GetItemY1Offset(index) + _itemsArea.Top + _itemHeight / 2;
                             var args = new ItemContextMenuRequestEventArgs(_selectedItems[0], column, columnIndex, p.X, p.Y);
                             Events.Raise(ItemContextMenuRequestedEvent, this, args);
                             if(args.OverrideDefaultMenu)
                             {
                                 menu = args.ContextMenu;
                             }
                             else
                             {
                                 menu = _selectedItems[0].GetContextMenu(args);
                             }
                         }
                         break;
                     default:
                         {
                             var args = new ItemsContextMenuRequestEventArgs(_selectedItems, column, columnIndex, p.X, p.Y);
                             Events.Raise(ItemsContextMenuRequestedEvent, this, args);
                             if(args.OverrideDefaultMenu)
                             {
                                 menu = args.ContextMenu;
                             }
                             else
                             {
                                 menu = GetMultiselectContextMenu(args);
                             }
                         }
                         break;
                 }
                 if(menu != null)
                 {
                     menu.Renderer = Style.ToolStripRenderer;
                     menu.Show(this, p, ToolStripDropDownDirection.Default);
                 }
             }
             break;
         default:
             e.IsInputKey = false;
             break;
     }
     base.OnPreviewKeyDown(e);
 }
Ejemplo n.º 4
0
 protected override void OnDoubleClick(EventArgs e)
 {
     _columnResizeProcess = null;
     switch(_oldHitTestResult.Area)
     {
         case HitTestArea.Item:
             if(_oldHitTestResult.ItemPart >= 0 && _itemFocus.IsTracked && _itemFocus.Index >= 0 && _itemFocus.Index < _itemPlainList.Count)
             {
                 var item = _itemPlainList[_itemFocus.Index];
                 item.OnDoubleClick(_mouseDownX, _mouseDownY);
                 if(_itemActivation == ItemActivation.DoubleClick)
                 {
                     item.Activate();
                 }
             }
             break;
         case HitTestArea.Header:
             bool isOverLeftResizeGrip  = _oldHitTestResult.ItemPart == ColumnHitTestResults.LeftResizer;
             bool isOverRightResizeGrip = _oldHitTestResult.ItemPart == ColumnHitTestResults.RightResizer;
             if(isOverLeftResizeGrip || isOverRightResizeGrip)
             {
                 var index = _oldHitTestResult.ItemIndex;
                 if(index != -1)
                 {
                     var autosizingColumn = _columns[index];
                     if(isOverLeftResizeGrip)
                     {
                         var previousColumn = _columns.FindPrevious(index, column => column.IsVisible);
                         if(previousColumn != null && previousColumn.SizeMode == ColumnSizeMode.Sizeable)
                         {
                             autosizingColumn = previousColumn;
                         }
                     }
                     else
                     {
                         if(autosizingColumn.SizeMode != ColumnSizeMode.Sizeable)
                         {
                             var nextColumn = _columns.FindNext(index, column => column.IsVisible);
                             if(nextColumn != null && nextColumn.SizeMode == ColumnSizeMode.Sizeable)
                             {
                                 autosizingColumn = nextColumn;
                             }
                         }
                     }
                     if(autosizingColumn != null && autosizingColumn.SizeMode == ColumnSizeMode.Sizeable)
                     {
                         autosizingColumn.AutoSize();
                     }
                 }
             }
             break;
     }
     base.OnDoubleClick(e);
 }