Example #1
0
        /// <summary>
        /// Find the ideal size to fit all the commands inside.
        /// </summary>
        /// <param name="states">Collection of additional state for commands.</param>
        /// <param name="details">Lookup interface for calculations.</param>
        /// <returns>Bounding rectangle covering all commands.</returns>
        public Rectangle FindIdealSize(CommandStateCollection states,
                                       ICommandDetails details)
        {
            // Peform layout of commands
            Rectangle rectLayout = InternalLayoutCommands(states, details, true);

            // Track total width or height required
            int total = 0;

            // Process all commands
            for (int i = 0; i < _states.Count; i++)
            {
                CommandState state = _states[i];

                // Add the size it needs for drawing in direction
                total += WithFlowLength(state.DrawRect.Size);
            }

            // Modify the return rectangle with calculated total
            if (_details.Direction == LayoutDirection.Horizontal)
            {
                rectLayout.Width = total;
            }
            else
            {
                rectLayout.Height = total;
            }

            // Clear out any temporary working values
            ClearDown();

            // Peform layout of commands
            return(rectLayout);
        }
Example #2
0
        /// <summary>
        /// Perform sizing and positioning of commands.
        /// </summary>
        /// <param name="states">Collection of additional state for commands.</param>
        /// <param name="details">Lookup interface for calculations.</param>
        /// <returns>Bounding rectangle covering all commands.</returns>
        public Rectangle LayoutCommands(CommandStateCollection states,
                                        ICommandDetails details)
        {
            // Peform layout of commands
            Rectangle rectLayout = InternalLayoutCommands(states, details, false);

            // Clear out any temporary working values
            ClearDown();

            return(rectLayout);
        }
Example #3
0
        private void Prepare(Graphics g,
                             CommandStateCollection states,
                             ICommandDetails details,
                             bool findIdealSize)
        {
            // Cache useful information
            _states  = states;
            _details = details;

            // Initialize simple working values
            _maximumTangent = 0;
            _finished       = false;

            // If try to find ideal size then give it unlimited space
            if (findIdealSize)
            {
                _layoutRect = new Rectangle(0, 0, MAXIMUM, MAXIMUM);
            }
            else
            {
                _layoutRect = _details.LayoutRect;
            }

            // Starting position depends on orientation
            if (_details.Direction == LayoutDirection.Horizontal)
            {
                _leftSpace = _layoutRect.Left;
            }
            else
            {
                _leftSpace = _layoutRect.Top;
            }

            // Amount of free space to use depends on orientation
            _freeSpace = WithFlowLength(_layoutRect);

            // Ask each command for its requested raw size
            CalculateRawCommandSize(g);

            // Adjust size of button commands to reflect detail properties
            AdjustButtonSizes();
        }
Example #4
0
        private void InternalConstruct()
        {
            // Create internal state objects
            _details = new CommandDetails(this);
            _engine  = new SingleLayoutEngine();
            _states  = new CommandStateCollection();
            _padding = new Padding();

            // Define state
            _initCount       = 0;
            _layoutRequired  = false;
            _mouseDownButton = MouseButtons.None;
            _mouseCapture    = false;
            _currentCmdState = null;
            _tooltipCmdState = null;

            // Hook into padding changed events
            _padding.PaddingChanged += new EventHandler(OnPaddingChanged);

            // Create exposed/internal collections of commands
            _externals = new CommandBaseCollection();
            _internals = new CommandBaseCollection();

            // Hook into command collection modifications
            _externals.Clearing += new CollectionClear(OnCommandsClearing);
            _externals.Cleared  += new CollectionClear(OnCommandsCleared);
            _externals.Inserted += new CollectionChange(OnCommandInserted);
            _externals.Removed  += new CollectionChange(OnCommandRemoved);
            _internals.Clearing += new CollectionClear(OnCommandsClearing);
            _internals.Cleared  += new CollectionClear(OnCommandsCleared);
            _internals.Inserted += new CollectionChange(OnCommandInserted);
            _internals.Removed  += new CollectionChange(OnCommandRemoved);

            // Need a timer so that when the mouse hovers we can show tooltips
            _hoverTimer       = new Timer();
            _hoverTimer.Tick += new EventHandler(OnMouseHoverTick);

            // Need a timer so that we can send updates to top level commands
            _updateTimer       = new Timer();
            _updateTimer.Tick += new EventHandler(OnUpdateTick);
        }
Example #5
0
        private Rectangle InternalLayoutCommands(CommandStateCollection states,
                                                 ICommandDetails details,
                                                 bool findIdealSize)
        {
            Rectangle returnRect = Rectangle.Empty;

            using (Graphics g = details.HostControl.CreateGraphics())
            {
                // Prepare state for processing
                Prepare(g, states, details, findIdealSize);

                // Position the most important 'System' commands first, followed by
                // the less important 'Near' commands and lastly the 'Far' commands
                // which have the lowest priority of all.
                CalculateByPosition(g, Position.System, false);
                CalculateByPosition(g, Position.Near, true);
                CalculateByPosition(g, Position.Far, false);

                // Calculate the final positions depending on maximum values encountered
                CalculateFinalPositions();

                returnRect = _layoutRect;

                // Calculate the actual area we have decided to use
                if (_details.Direction == LayoutDirection.Horizontal)
                {
                    returnRect.Height = _maximumTangent;
                }
                else
                {
                    returnRect.Width = _maximumTangent;
                }
            }

            return(returnRect);
        }
Example #6
0
 private void ClearDown()
 {
     _states  = null;
     _details = null;
 }