Esempio n. 1
0
            private unsafe void OnPaint()
            {
                using var hdc  = new User32.BeginPaintScope(Handle);
                using var save = new Gdi32.SaveDcScope(hdc);

                MirrorDcIfNeeded(hdc);

                for (int i = 0; i < _items.Count; i++)
                {
                    ControlItem item   = _items[i];
                    Rectangle   bounds = item.GetIconBounds(_provider.Region.Size);
                    User32.DrawIconEx(
                        hdc,
                        bounds.X - _windowBounds.X,
                        bounds.Y - _windowBounds.Y,
                        _provider.Region,
                        bounds.Width, bounds.Height);
                }
            }
Esempio n. 2
0
            public unsafe void Update(bool timerCaused)
            {
                IconRegion iconRegion = _provider.Region;
                Size       size       = iconRegion.Size;

                _windowBounds = Rectangle.Empty;
                for (int i = 0; i < _items.Count; i++)
                {
                    ControlItem item       = _items[i];
                    Rectangle   iconBounds = item.GetIconBounds(size);
                    if (_windowBounds.IsEmpty)
                    {
                        _windowBounds = iconBounds;
                    }
                    else
                    {
                        _windowBounds = Rectangle.Union(_windowBounds, iconBounds);
                    }
                }

                using var windowRegion = new Region(new Rectangle(0, 0, 0, 0));

                for (int i = 0; i < _items.Count; i++)
                {
                    ControlItem item       = _items[i];
                    Rectangle   iconBounds = item.GetIconBounds(size);
                    iconBounds.X -= _windowBounds.X;
                    iconBounds.Y -= _windowBounds.Y;

                    bool showIcon = true;
                    if (!item.ToolTipShown)
                    {
                        switch (_provider.BlinkStyle)
                        {
                        case ErrorBlinkStyle.NeverBlink:
                            // always show icon
                            break;

                        case ErrorBlinkStyle.BlinkIfDifferentError:
                            showIcon = (item.BlinkPhase == 0) || (item.BlinkPhase > 0 && (item.BlinkPhase & 1) == (i & 1));
                            break;

                        case ErrorBlinkStyle.AlwaysBlink:
                            showIcon = ((i & 1) == 0) == _provider._showIcon;
                            break;
                        }
                    }

                    if (showIcon)
                    {
                        iconRegion.Region.Translate(iconBounds.X, iconBounds.Y);
                        windowRegion.Union(iconRegion.Region);
                        iconRegion.Region.Translate(-iconBounds.X, -iconBounds.Y);
                    }

                    if (_tipWindow is not null)
                    {
                        ComCtl32.TTF flags = ComCtl32.TTF.SUBCLASS;
                        if (_provider.RightToLeft)
                        {
                            flags |= ComCtl32.TTF.RTLREADING;
                        }

                        var toolInfo = new ComCtl32.ToolInfoWrapper <ErrorWindow>(this, item.Id, flags, item.Error, iconBounds);
                        toolInfo.SendMessage(_tipWindow, (User32.WM)ComCtl32.TTM.SETTOOLINFOW);
                    }

                    if (timerCaused && item.BlinkPhase > 0)
                    {
                        item.BlinkPhase--;
                    }
                }

                if (timerCaused)
                {
                    _provider._showIcon = !_provider._showIcon;
                }

                using var hdc  = new User32.GetDcScope(Handle);
                using var save = new Gdi32.SaveDcScope(hdc);
                MirrorDcIfNeeded(hdc);

                using Graphics g             = hdc.CreateGraphics();
                using var windowRegionHandle = new Gdi32.RegionScope(windowRegion, g);
                if (User32.SetWindowRgn(this, windowRegionHandle, BOOL.TRUE) != 0)
                {
                    // The HWnd owns the region.
                    windowRegionHandle.RelinquishOwnership();
                }

                User32.SetWindowPos(
                    new HandleRef(this, Handle),
                    User32.HWND_TOP,
                    _windowBounds.X,
                    _windowBounds.Y,
                    _windowBounds.Width,
                    _windowBounds.Height,
                    User32.SWP.NOACTIVATE);
                User32.InvalidateRect(new HandleRef(this, Handle), null, BOOL.FALSE);
            }