public void UpdateIcons()
        {
            var icons = NotificationAreaProxy.GetVisibleIcons();

            this.Controls.Clear();

            this.SuspendLayout();

            ShowButton();

            // add a button for each icon and calculate its position
            Native.ABEdge edge  = this.MainForm.TaskbarLocation;
            int           index = _buttonVisible && _showButtonOnTheSameLine && edge != Native.ABEdge.Left ? 1 : 0;
            int           top   = _buttonVisible && !_showButtonOnTheSameLine ? 30 : (Native.IsThemeActive() == 0 ? 0 : 4);

            foreach (var icon in icons)
            {
                var button = new NotificationIcon(icon);
                this.Controls.Add(button);

                button.Init();
                button.AutoSize = false;
                button.Padding  = new System.Windows.Forms.Padding(0);
                button.Margin   = new System.Windows.Forms.Padding(0);

                button.Left = index * button.Width + HMargin;
                button.Top  = top + 1;

                index++;

                if ((index + 1) * button.Width + HMargin > this.Width)
                {
                    index = _buttonVisible && (edge == Native.ABEdge.Bottom || edge == Native.ABEdge.Top) ? 1 : 0;
                    top  += button.Height;
                }
            }
            this.ResumeLayout();

            CalculateSize(icons.Count);
        }
Exemple #2
0
        /// <summary>
        /// Move taskbar to specific side and rearrange all controls
        /// </summary>
        /// <param name="notify">If TRUE it will broadcast a message, so that all windows can adjust their size based on the new workarea </param>
        /// <param name="location">Where to move it</param>
        public void SetPosition(bool notify, Native.ABEdge location)
        {
            TaskbarPropertiesManager.Instance.Properties.SetTaskbarLocation(CurrentScreen.DeviceName, location);
            ABSetPos(notify);
            DisplayStartMenu();

            bool isVisualTheme = Native.IsThemeActive() != 0;

            btnShowDesktop.CalculateSizeAndPosition();

            FlowDirection direction;

            if (location == Native.ABEdge.Top ||
                location == Native.ABEdge.Bottom)
            {
                direction = FlowDirection.LeftToRight;

                pnlClock.Dock   = DockStyle.Right;
                pnlClock.Width  = ClockPanel.PanelWidth;
                pnlClock.Height = pnlNotificationBorder.Height;

                if (pnlNotificationArea.Visible)
                {
                    pnlNotificationArea.CalculateSize(NotificationAreaProxy.GetVisibleIcons().Count);
                    pnlNotificationArea.UpdateIcons();
                    pnlNotificationArea.Left = 1;
                    pnlNotificationArea.Top  = 0;
                }

                pnlNotificationBorder.Width = (pnlClock.Visible ? pnlClock.Width : 0)
                                              + (pnlNotificationArea.Visible ? pnlNotificationArea.Width + 5 : 0)
                                              + btnShowDesktop.Width;

                pnlProgramsFlow.Width  = this.Width - (_startButton != null ? 54 : 0) - pnlNotificationBorder.Width - 10;
                pnlProgramsFlow.Height = this.Height;
                pnlProgramsFlow.Left   = (_startButton != null ? 54 : 0);
                pnlProgramsFlow.Top    = 0;

                if (!isVisualTheme)
                {
                    pnlNotificationBorder.Height = location == Native.ABEdge.Bottom ? this.Height - 6 : this.Height - 9;
                    pnlNotificationBorder.Top    = location == Native.ABEdge.Bottom ? 4 : 3;
                    pnlNotificationBorder.Left   = pnlProgramsFlow.Right + 8;
                }
                else
                {
                    pnlNotificationBorder.Height = this.Height;
                    pnlNotificationBorder.Top    = 0;
                    pnlNotificationBorder.Left   = this.Width - pnlNotificationBorder.Width;
                }

                if (location == Native.ABEdge.Bottom)
                {
                    this.pnlResize.Dock = System.Windows.Forms.DockStyle.Top;
                }
                else
                {
                    this.pnlResize.Dock = System.Windows.Forms.DockStyle.Bottom;
                }
                this.pnlResize.Height = 4;

                if (!TaskbarPropertiesManager.Instance.Properties.Locked)
                {
                    this.pnlResize.Cursor = System.Windows.Forms.Cursors.SizeNS;
                }
                else
                {
                    this.pnlResize.Cursor = System.Windows.Forms.Cursors.Default;
                }
            }
            else
            {
                direction = FlowDirection.TopDown;

                pnlClock.Dock   = DockStyle.Bottom;
                pnlClock.Width  = pnlNotificationBorder.Width;
                pnlClock.Height = 55;

                if (pnlNotificationArea.Visible)
                {
                    pnlNotificationArea.CalculateSize(NotificationAreaProxy.GetVisibleIcons().Count);
                    pnlNotificationArea.UpdateIcons();
                    pnlNotificationArea.Left = 0;
                    pnlNotificationArea.Top  = 2;
                }

                pnlNotificationBorder.Height = (pnlClock.Visible ? pnlClock.Height : 0)
                                               + (pnlNotificationArea.Visible ? pnlNotificationArea.Height : 0)
                                               + btnShowDesktop.Height;

                pnlProgramsFlow.Height = this.Height - (_startButton != null ? 45 : 0) - pnlNotificationBorder.Height - 10;
                pnlProgramsFlow.Width  = this.Width;
                pnlProgramsFlow.Left   = 0;
                pnlProgramsFlow.Top    = (_startButton != null ? 45 : 0);

                if (!isVisualTheme)
                {
                    pnlNotificationBorder.Width = this.Width - 6;
                    pnlNotificationBorder.Left  = (location == Native.ABEdge.Left ? 2 : 4);
                    pnlNotificationBorder.Top   = pnlProgramsFlow.Bottom + 8;
                }
                else
                {
                    pnlNotificationBorder.Width = this.Width;
                    pnlNotificationBorder.Left  = 0;
                    pnlNotificationBorder.Top   = this.Height - pnlNotificationBorder.Height;
                }

                if (location == Native.ABEdge.Left)
                {
                    this.pnlResize.Dock = System.Windows.Forms.DockStyle.Right;
                }
                else
                {
                    this.pnlResize.Dock = System.Windows.Forms.DockStyle.Left;
                }
                this.pnlResize.Width = 4;

                if (!TaskbarPropertiesManager.Instance.Properties.Locked)
                {
                    this.pnlResize.Cursor = System.Windows.Forms.Cursors.SizeWE;
                }
                else
                {
                    this.pnlResize.Cursor = System.Windows.Forms.Cursors.Default;
                }
            }

            pnlClock.RefreshProperties();

            flowPanel.SuspendLayout();

            flowPanel.FlowDirection = direction;
            flowPanel.RefreshProperties();

            if (tooltipManager.ToolTipWindow != null)
            {
                tooltipManager.ToolTipWindow.RefreshProperties();
            }

            if ((location == Native.ABEdge.Right ||
                 location == Native.ABEdge.Left) &&
                Native.IsThemeActive() == 0)
            {
                flowPanel.Padding = new Padding(3, 0, 6, 0);
            }
            else
            {
                flowPanel.Padding = new Padding(0);
            }

            flowPanel.ResumeLayout();

            Refresh();

            if (notify)
            {
                TaskbarPropertiesManager.Instance.Save();
            }
        }