Exemple #1
0
        /// <summary>
        /// Resets the width of a specified col based on the cells in rows
        /// <paramref name="r"/> to <paramref name="r"/> +
        /// <paramref name="range"/>.
        /// </summary>
        /// <param name="c">col</param>
        /// <param name="r">first row to consider as changed (default -1 if
        /// deleting rows and/or no extant text-widths have changed; ie, no
        /// text-widths need to be re-measured)</param>
        /// <param name="range">range of rows to consider as changed (default 0
        /// for a single row)</param>
        internal void Colwidth(int c, int r = -1, int range = 0)
        {
            Col col = Cols[c];

            int colwidth = col._widthtext + _padHoriSort;
            int widthtext;

            if (r != -1)             // re-calc '_widthtext' regardless of what happens below ->
            {
                string text;

                int rend = r + range;
                for (; r <= rend; ++r)
                {
                    if ((text = this[r, c].text) == gs.Stars)                    // bingo.
                    {
                        widthtext = _wStars;
                    }
                    else
                    {
                        widthtext = YataGraphics.MeasureWidth(text, Font);
                    }

                    this[r, c]._widthtext = widthtext;

                    if (widthtext > colwidth)
                    {
                        colwidth = widthtext;
                    }
                }
            }

            if (!col.UserSized)                 // ie. don't resize a col that user has adjusted. If it needs to
            {                                   // be forced (eg. on reload) unflag UserSized on all cols first.
                int totalwidth = col.width();

                if ((colwidth += _padHori * 2) > totalwidth)
                {
                    col.width(colwidth);
                }
                else if (colwidth < totalwidth)                 // recalc width on the entire col
                {
                    if (c == 0 || _wId > colwidth)
                    {
                        colwidth = _wId;
                    }

                    for (r = 0; r != RowCount; ++r)
                    {
                        widthtext = this[r, c]._widthtext + _padHori * 2;

                        if (widthtext > colwidth)
                        {
                            colwidth = widthtext;
                        }
                    }
                    col.width(colwidth, true);
                }

                if (range == 0 && totalwidth != colwidth)                       // if range >0 let Calibrate() handle multiple
                {                                                               // cols or at least the scrollers and do the UI-update
                    InitScroll();
                    Invalidator(INVALID_GRID | INVALID_COLS);
                }
            }

            if (Propanel != null && Propanel.Visible)
            {
                Propanel.widthValcol();                 // TODO: Re-calc the 'c' col only.
            }
        }
Exemple #2
0
        /// <summary>
        /// Overrides the <c>MouseDown</c> handler on this
        /// <c>YataPanelFrozen</c>. Accepts or cancels an active edit.
        /// <list type="bullet">
        /// <item><c>LMB</c> - accept edit</item>
        /// <item><c>RMB</c> - cancel edit</item>
        /// <item><c>MMB</c> - accept or cancel based on
        /// <c><see cref="Settings._acceptedit">Settings._acceptedit</see></c></item>
        /// </list>
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
#if Clicks
            logfile.Log("YataPanelFrozen.OnMouseDown() e.Button= " + e.Button);
#endif
            if (ModifierKeys == Keys.None)
            {
                if (_grid._editor.Visible)
                {
#if Clicks
                    logfile.Log(". _grid._editor.Visible");
#endif
                    switch (e.Button)
                    {
                    case MouseButtons.Left:                             // accept edit
#if Clicks
                        logfile.Log(". . accept edit");
#endif
                        _grid._bypassleaveditor = true;
                        _grid.editresultaccept();
                        break;

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

                    default:
#if Clicks
                        logfile.Log(". . default edit result");
#endif
                        _grid._editor.Visible = false;                                 // do this or else the leave event fires twice.
                        break;
                    }
                }
                else
                {
                    Propanel propanel = _grid.Propanel;
                    if (propanel != null && propanel._editor.Visible)
                    {
#if Clicks
                        logfile.Log(". _grid.Propanel._editor.Visible");
#endif
                        switch (e.Button)
                        {
                        case MouseButtons.Left:                                 // accept edit
#if Clicks
                            logfile.Log(". . accept edit");
#endif
                            propanel._bypassleaveditor = true;
                            propanel.editresultaccept();
                            break;

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

                        default:
#if Clicks
                            logfile.Log(". . default edit result");
#endif
                            propanel._editor.Visible = false;                                     // do this or else the leave event fires twice.
                            break;
                        }
                    }
                }
            }

            _grid.Select();
        }
Exemple #3
0
        /// <summary>
        /// Scrolls the table by the mousewheel.
        /// </summary>
        /// <param name="e"></param>
        /// <remarks>Fired from the form's <c>MouseWheel</c> event to catch all
        /// unhandled <c>MouseWheel</c> events hovered on the app (without
        /// firing twice).</remarks>
        internal void Scroll(MouseEventArgs e)
        {
            if ((ModifierKeys & Keys.Alt) == Keys.None)
            {
                if (Propanel != null && Propanel._scroll.Visible &&
                    e.X > Propanel.Left && e.X < Propanel.Left + Propanel.Width)
                {
                    if ((ModifierKeys & (Keys.Shift | Keys.Control)) == Keys.None)
                    {
                        Propanel.Scroll(e);
                    }
                }
                else if (!_editor.Visible)
                {
                    //logfile.Log("(" + System.IO.Path.GetFileNameWithoutExtension(Fullpath) + ") YataGrid.Scroll()");
                    if (_visVert && (!_visHori || (ModifierKeys & Keys.Control) == Keys.None))
                    {
                        int h;
                        if ((ModifierKeys & Keys.Shift) == Keys.Shift)                         // shift grid vertically 1 visible-height per delta
                        {
                            h = Height - HeightColhead - (_visHori ? _scrollHori.Height : 0);
                        }
                        else
                        {
                            h = HeightRow;
                        }

                        if (e.Delta > 0)
                        {
                            if (_scrollVert.Value - h < 0)
                            {
                                _scrollVert.Value = 0;
                            }
                            else
                            {
                                _scrollVert.Value -= h;
                            }
                        }
                        else if (e.Delta < 0)
                        {
                            if (_scrollVert.Value + h > MaxVert)
                            {
                                _scrollVert.Value = MaxVert;
                            }
                            else
                            {
                                _scrollVert.Value += h;
                            }
                        }
                    }
                    else if (_visHori)
                    {
                        int w;
                        if ((ModifierKeys & Keys.Shift) == Keys.Shift)                         // shift grid horizontally 1 visible-width per delta
                        {
                            w = Width - getLeft() - (_visVert ? _scrollVert.Width : 0);
                        }
                        else
                        {
                            w = HeightRow;
                        }

                        if (e.Delta > 0)
                        {
                            if (_scrollHori.Value - w < 0)
                            {
                                _scrollHori.Value = 0;
                            }
                            else
                            {
                                _scrollHori.Value -= w;
                            }
                        }
                        else if (e.Delta < 0)
                        {
                            if (_scrollHori.Value + w > MaxHori)
                            {
                                _scrollHori.Value = MaxHori;
                            }
                            else
                            {
                                _scrollHori.Value += w;
                            }
                        }
                    }
                }
            }
        }