protected void CustomPaint()
        {
            using (Graphics g = this.CreateGraphics())
            {
                base.Paint(g);

                if (!MainForm.IsHidden)
                {
                    if (Native.IsThemeActive() != 0)
                    {
                        if (_decorator == null)
                        {
                            var taskbarLocation = this.MainForm.TaskbarLocation;

                            bool leftToRight = taskbarLocation == Native.ABEdge.Top || taskbarLocation == Native.ABEdge.Bottom;
                            _decorator = new PushPanelDecorator(true, Width, Height, Padding, this);
                        }
                        _decorator.Paint(g, _isClicked, _hover);
                    }
                    NotificationAreaProxy.PaintIcon(_data.BitmapIndex,
                        (this.Width - ButtonConstants.SmallIconSize) / 2,
                        (this.Height - ButtonConstants.SmallIconSize) / 2, this.Handle);
                }
            }

            // Tell Windows that the button is now rendered. This will prevent it from calling paint again until actually needed.
            Native.RECT rect = new Native.RECT()
            {
                left = this.ClientRectangle.Left,
                right = this.ClientRectangle.Right,
                top = this.ClientRectangle.Top,
                bottom = this.ClientRectangle.Bottom
            };
            Native.ValidateRect(this.Handle, ref rect);
        }
Ejemplo n.º 2
0
        public DualMonitorForm()
        {
            InitializeComponent();

            NotificationAreaProxy.HookNotificationArea(this.Handle);
            RunningTasksProxy.HookRunningApps(this.Handle);

            HookWindows();
        }
        void button_Click(object sender, EventArgs e)
        {
            Button       button = sender as Button;
            Point        location = button.PointToScreen(button.Location);
            int          x, y;
            AnchorStyles anchor;

            // calculate position for more icons window
            Rectangle taskbarBounds = MainForm.Bounds;

            switch (this.MainForm.TaskbarLocation)
            {
            case Native.ABEdge.Left:
                x      = taskbarBounds.Right;
                y      = location.Y + button.Height / 2;
                anchor = AnchorStyles.Left;
                break;

            case Native.ABEdge.Top:
                x      = location.X + button.Width / 2;
                y      = taskbarBounds.Bottom;
                anchor = AnchorStyles.Top;
                break;

            case Native.ABEdge.Right:
                x      = taskbarBounds.Left;
                y      = location.Y + button.Height / 2;
                anchor = AnchorStyles.Right;
                break;

            case Native.ABEdge.Bottom:
                x      = location.X + button.Width / 2;
                y      = taskbarBounds.Top;
                anchor = AnchorStyles.Bottom;
                break;

            default:
                return;
            }

            _moreIconsVisible = !_moreIconsVisible;
            NotificationAreaProxy.ShowMoreIcons(_moreIconsVisible, x, y, anchor);

            if (_moreIconsVisible)
            {
                HookManager.MouseClick += HookManager_MouseClick;
            }
            else
            {
                HookManager.MouseClick -= HookManager_MouseClick;
            }
        }
        public void Initialize()
        {
            _buttonVisible = NotificationAreaProxy.IsShowMoreButtonVisible();

            _button = new MoreIconsButton();

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

            if (isVisualTheme)
            {
                _button.Width  = ButtonConstants.NotifButtonWidth;
                _button.Height = ButtonConstants.NotifButtonWidth;
            }
            _button.Click += new EventHandler(button_Click);

            TryUpdateIcons();
        }
 public void DispatchMessage(Message m)
 {
     if (this.Visible)
     {
         int index = (int)m.WParam;
         if (index == -1)
         {
             _buttonVisible = NotificationAreaProxy.IsShowMoreButtonVisible();
             UpdateIcons();
         }
         else
         {
             // only update icon, not tooltip
             UpdateIcon(index);
         }
     }
 }
        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);
        }
        protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs mevent)
        {
            base.OnMouseUp(mevent);
            Invalidate();

            if (mevent.Button == System.Windows.Forms.MouseButtons.Right)
            {
                NotificationAreaProxy.RightClickIcon(_data.Data);
            }
            else if (mevent.Button == System.Windows.Forms.MouseButtons.Left)
            {
                // use timer to detect double clicks
                // we can't use the OnDoubleClick event because it doesn't work if we handle OnMouseDown (in base class)
                if (!_singleClickTimer.Enabled)
                {
                    _singleClickTimer.Start();
                }
                else
                {
                    NotificationAreaProxy.DefaultAction(_data.Data);
                    _singleClickTimer.Stop();
                }
            }
        }
Ejemplo n.º 8
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();
            }
        }
 void _singleClickTimer_Tick(object sender, EventArgs e)
 {
     NotificationAreaProxy.LeftClickIcon(_data.Data);
     _singleClickTimer.Stop();
 }