Ejemplo n.º 1
0
        /// <summary>
        /// Overrides the <c>MouseClick</c> event. Selects the row in this
        /// <c>Propanel</c> that's clicked, starts or applies/cancels edit.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseClick(MouseEventArgs e)
        {
#if Clicks
            logfile.Log("Propanel.OnMouseClick() " + e.Button + " _tabOverride= " + _tabOverride);
#endif
            if ((ModifierKeys & (Keys.Control | Keys.Alt)) == Keys.None)
            {
                if (!_editor.Visible)
                {
                    if (e.Button == MouseButtons.Left &&
                        _grid.RangeSelect == 0 &&
                        ((ModifierKeys & Keys.Shift) == Keys.None ||
                         _tabOverride != TABFASTEDIT_Bypass))
                    {
                        if ((_r = _grid.getSelectedRowOrCells(true)) != -1)
                        {
                            _grid._editor.Visible = false;                             // edit result default on YataGrid's editor (if visible).

                            if (_tabOverride == TABFASTEDIT_Bypass)
                            {
                                _c = (e.Y + _scroll.Value) / _heightr;
                            }
                            else
                            {
                                _c = _tabOverride;
                            }

                            if (_grid.getSelectedRow() == -1)
                            {
                                for (int c = 0; c != _grid.ColCount; ++c)
                                {
                                    _grid[_r, c].selected = false;
                                }

                                _grid.SelectCell(_grid[_r, _c]);
                            }
                            else
                            {
                                _grid.EnsureDisplayedRow(_r);
                            }

                            EnsureDisplayed(_c);


                            if (!_grid.Readonly && e.X > _widthVars)
                            {
#if Clicks
                                logfile.Log(". . start edit");
#endif
                                _editRect.X = _widthVars;
                                _editRect.Y = _c * _heightr + 1;

                                _editor.Left = _editRect.X + 5;                                 // cf YataGrid.EditCell() ->
                                _editor.Top  = _editRect.Y + 1 - _scroll.Value;
                                _editor.Text = _grid[_r, _c].text;

                                _editor.SelectionStart  = 0;
                                _editor.SelectionLength = _editor.Text.Length;

                                _editor.Visible = true;
                                _editor.Focus();
                            }
                            else
                            {
#if Clicks
                                logfile.Log(". . select grid");
#endif
                                _grid.Select();
                            }

                            _grid.Invalidator(YataGrid.INVALID_GRID
                                              | YataGrid.INVALID_FROZ
                                              | YataGrid.INVALID_PROP);
                        }
                        else
                        {
#if Clicks
                            logfile.Log(". select grid");
#endif
                            _grid.Select();
                        }
                    }
                }
                else if ((ModifierKeys & Keys.Shift) == Keys.None)                 // _editor.Visible
                {
                    switch (e.Button)
                    {
                    case MouseButtons.Left:                             // accept edit
#if Clicks
                        logfile.Log(". accept edit");
#endif
                        _bypassleaveditor = true;
                        editresultaccept(true);
                        break;

                    case MouseButtons.Right:                             // cancel edit
#if Clicks
                        logfile.Log(". cancel edit");
#endif
                        _bypassleaveditor = true;
                        editresultcancel(true);
                        break;

                    default:
#if Clicks
                        logfile.Log(". edit result default");
#endif
                        _editor.Visible = false;
                        _grid.Select();
                        break;
                    }
                }
            }
        }