Пример #1
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            using (new LayoutSuspender(_chevronBar))
            {
                //////
                // Calculate the rectangles
                Size sizeToolbarMin = _chevronBar.MinSize;

                _rectBounds = ClientRectangle;

                // Client rect within the control's borders
                _rectInBorder = ClientRectangle;
                _rectInBorder.Inflate(-2, -2);                   // Exclude the borders

                // Exclude the grip
                _rectWithoutGrip = _grip.OnLayout(_rectInBorder);

                // The innermost client rect
                _rectClientPadded = _rectWithoutGrip;
                _rectClientPadded.Inflate(-2, -1);

                // Size of the labels
                _sizeTitle         = JetLinkLabel.GetTextSize(this, Text, Font);
                _sizeNoItemsBanner = JetLinkLabel.GetTextSize(this, _sNoItemsBanner, _fontNoItemsBanner, _rectClientPadded.Size, _dtfNoItemsBannerFormatFlags);

                if (_numShortcuts != 0)
                {                 // There are shortcuts. Include the toolbar and (possibly) the title
                    if (_rectClientPadded.Width >= sizeToolbarMin.Width + c_nAfterTitlePadding + _sizeTitle.Width)
                    {             // Title fits
                        //_rectTitle = new Rectangle( _rectClientPadded.Location, new Size( _sizeTitle.Width, _rectClientPadded.Height ) );
                        _rectTitle   = new Rectangle(new Point(_rectClientPadded.Left, _rectClientPadded.Top + (_rectClientPadded.Height - _sizeTitle.Height) / 2), _sizeTitle);
                        _rectToolbar = new Rectangle(_rectTitle.Right + c_nAfterTitlePadding, _rectClientPadded.Top, _rectClientPadded.Width - (_rectTitle.Width + c_nAfterTitlePadding), _rectClientPadded.Height);
                    }
                    else
                    {                     // Title does not fit
                        _rectTitle   = Rectangle.Empty;
                        _rectToolbar = _rectClientPadded;
                    }
                    _rectNoItemsBanner = Rectangle.Empty;
                }
                else
                {                 // No shortcuts, display just the no-items-banner
                    _rectTitle   = Rectangle.Empty;
                    _rectToolbar = Rectangle.Empty;

                    // Align the banner
                    Size sizeFit = new Size
                                   (
                        _sizeNoItemsBanner.Width < _rectClientPadded.Width ? _sizeNoItemsBanner.Width : _rectClientPadded.Width,
                        _sizeNoItemsBanner.Height < _rectClientPadded.Height ? _sizeNoItemsBanner.Height : _rectClientPadded.Height
                                   );
                    _rectNoItemsBanner = new Rectangle(
                        new Point
                        (
                            _rectClientPadded.Left,                                                 // H-Align left
                            _rectClientPadded.Top + (_rectClientPadded.Height - sizeFit.Height) / 2 // V-center
                        ),
                        sizeFit);
                }

                /////////////////////
                // Apply the layout
                _chevronBar.Visible = _rectToolbar != Rectangle.Empty;
                _chevronBar.Bounds  = _rectToolbar;
            }

            // Apply the visual changes
            Invalidate(false);
        }