Beispiel #1
0
        /// <summary>
        /// Ensure that the window doesn't overlap docked toolbars on desktop (like taskbar)
        /// </summary>
        /// <param name="m">The message.</param>
        /// <returns></returns>
        private bool CalculateMaxSize(ref Message m)
        {
            if (_owner.SkiningForm.Parent == null)
            {
                // create minMax info for maximize data
                MINMAXINFO info           = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO));
                Rectangle  rect           = SystemInformation.WorkingArea;
                Size       fullBorderSize = new Size(SystemInformation.Border3DSize.Width + SystemInformation.BorderSize.Width,
                                                     SystemInformation.Border3DSize.Height + SystemInformation.BorderSize.Height);

                info.ptMaxPosition.x = rect.Left - fullBorderSize.Width;
                info.ptMaxPosition.y = rect.Top - fullBorderSize.Height;
                info.ptMaxSize.x     = rect.Width + fullBorderSize.Width * 2;
                info.ptMaxSize.y     = rect.Height + fullBorderSize.Height * 2;

                info.ptMinTrackSize.y += FormExtenders.GetCaptionHeight(_owner.SkiningForm);


                if (!_owner.SkiningForm.MaximumSize.IsEmpty)
                {
                    info.ptMaxSize.x      = Math.Min(info.ptMaxSize.x, _owner.SkiningForm.MaximumSize.Width);
                    info.ptMaxSize.y      = Math.Min(info.ptMaxSize.y, _owner.SkiningForm.MaximumSize.Height);
                    info.ptMaxTrackSize.x = Math.Min(info.ptMaxTrackSize.x, _owner.SkiningForm.MaximumSize.Width);
                    info.ptMaxTrackSize.y = Math.Min(info.ptMaxTrackSize.y, _owner.SkiningForm.MaximumSize.Height);
                }

                if (!_owner.SkiningForm.MinimumSize.IsEmpty)
                {
                    info.ptMinTrackSize.x = Math.Max(info.ptMinTrackSize.x, _owner.SkiningForm.MinimumSize.Width);
                    info.ptMinTrackSize.y = Math.Max(info.ptMinTrackSize.y, _owner.SkiningForm.MinimumSize.Height);
                }

                // set wished maximize size
                Marshal.StructureToPtr(info, m.LParam, true);

                m.Result = (IntPtr)0;
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        protected override void WndProc(ref Message m)
        {
            bool supressOriginalMessage = false;

            if (IsProcessNcArea)
            {
                switch ((Win32Messages)m.Msg)
                {
                // update form data on style change
                case Win32Messages.STYLECHANGED:
                    _owner.Skin.UpdateStyle();
                    if (_owner.Skin != null)
                    {
                        _owner.Skin.OnSetRegion(_owner.SkiningForm.Size);
                    }
                    break;

                    #region Handle Form Activation
                case Win32Messages.ACTIVATEAPP:
                    // redraw
                    if (_owner.Skin != null)
                    {
                        _owner.Skin.FormIsActive = (int)m.WParam != 0;
                    }
                    _owner.Skin.OnNcPaint(true);
                    break;

                case Win32Messages.ACTIVATE:
                    // Set active state and redraw
                    _owner.Skin.FormIsActive = ((int)WAFlags.WA_ACTIVE == (int)m.WParam || (int)WAFlags.WA_CLICKACTIVE == (int)m.WParam);
                    _owner.Skin.OnNcPaint(true);
                    break;

                case Win32Messages.MDIACTIVATE:
                    // set active and redraw on activation
                    if (m.WParam == _owner.SkiningForm.Handle)
                    {
                        _owner.Skin.FormIsActive = false;
                    }
                    else if (m.LParam == _owner.SkiningForm.Handle)
                    {
                        _owner.Skin.FormIsActive = true;
                    }
                    _owner.Skin.OnNcPaint(true);
                    break;
                    #endregion

                    #region Handle Mouse Processing
                // Set Pressed button on mousedown
                case Win32Messages.NCLBUTTONDOWN:
                    supressOriginalMessage = _owner.Skin.OnMouseDown(ref m);
                    break;

                // Set hovered button on mousemove
                case Win32Messages.NCMOUSEMOVE:
                    _owner.Skin.OnMouseMove(ref m);
                    break;

                // perform button actions if a button was clicked
                case Win32Messages.NCLBUTTONUP:
                    // Handle button up
                    supressOriginalMessage = _owner.Skin.OnMouseUp(m);

                    break;

                // restore button states on mouseleave
                case Win32Messages.NCMOUSELEAVE:
                case Win32Messages.MOUSELEAVE:
                case Win32Messages.MOUSEHOVER:
                    _owner.Skin.OnMouseLeave();
                    break;
                    #endregion

                    #region Size Processing

                // Set region as window is shown
                case Win32Messages.SHOWWINDOW:
                    if (_owner.Skin != null)
                    {
                        _owner.Skin.OnSetRegion(_owner.SkiningForm.Size);
                    }
                    break;

                // adjust region on resize
                case Win32Messages.SIZE:
                    _owner.Skin.OnSize(m);
                    break;

                // ensure that the window doesn't overlap docked toolbars on desktop (like taskbar)
                case Win32Messages.GETMINMAXINFO:
                    supressOriginalMessage = CalculateMaxSize(ref m);
                    break;

                // update region on resize
                case Win32Messages.WINDOWPOSCHANGING:
                    WINDOWPOS wndPos = (WINDOWPOS)m.GetLParam(typeof(WINDOWPOS));
                    if ((wndPos.flags & (int)SWPFlags.SWP_NOSIZE) == 0)
                    {
                        if (_owner.Skin != null)
                        {
                            _owner.Skin.OnSetRegion(new Size(wndPos.cx, wndPos.cy));
                        }
                    }
                    break;

                // remove region on maximize or repaint on resize
                case Win32Messages.WINDOWPOSCHANGED:
                    if (_owner.SkiningForm.WindowState == FormWindowState.Maximized)
                    {
                        _owner.SkiningForm.Region = null;
                    }

                    WINDOWPOS wndPos2 = (WINDOWPOS)m.GetLParam(typeof(WINDOWPOS));
                    if ((wndPos2.flags & (int)SWPFlags.SWP_NOSIZE) == 0)
                    {
                        _owner.Skin.UpdateCaption();
                        _owner.Skin.OnNcPaint(true);
                    }
                    break;
                    #endregion

                    #region Non Client Area Handling
                // paint the non client area
                case Win32Messages.NCPAINT:
                    if (_owner.Skin.OnNcPaint(true))
                    {
                        m.Result = (IntPtr)1;
                        supressOriginalMessage = true;
                    }
                    break;

                // calculate the non client area size
                case Win32Messages.NCCALCSIZE:
                    if (m.WParam == (IntPtr)1)
                    {
                        if (_owner.SkiningForm.MdiParent != null)
                        {
                            break;
                        }
                        // add caption height to non client area
                        NCCALCSIZE_PARAMS p = (NCCALCSIZE_PARAMS)m.GetLParam(typeof(NCCALCSIZE_PARAMS));
                        p.rect0.Top += FormExtenders.GetCaptionHeight(_owner.SkiningForm);
                        Marshal.StructureToPtr(p, m.LParam, true);
                    }
                    break;

                // non client hit test
                case Win32Messages.NCHITTEST:
                    if (_owner.Skin.OnNcHitTest(ref m))
                    {
                        supressOriginalMessage = true;
                    }
                    break;
                    #endregion
                }
            }

            if (!supressOriginalMessage)
            {
                base.WndProc(ref m);
            }
        }
Beispiel #3
0
        protected internal override bool OnNcPaint(SkinningFormPaintData paintData)
        {
            if (SkiningForm == null)
            {
                return(false);
            }

            bool isMaximized = SkiningForm.WindowState == FormWindowState.Maximized;
            bool isMinimized = SkiningForm.WindowState == FormWindowState.Minimized;

            // prepare bounds
            Rectangle windowBounds = paintData.BaseData.Bounds;

            windowBounds.Location = Point.Empty;

            Rectangle captionBounds = windowBounds;
            Size      borderSize    = paintData.Borders;

            captionBounds.Height = borderSize.Height + paintData.CaptionHeight;

            Rectangle textBounds = captionBounds;
            Rectangle iconBounds = captionBounds;

            iconBounds.Inflate(-borderSize.Width, 0);
            iconBounds.Y      += borderSize.Height;
            iconBounds.Height -= borderSize.Height;

            // Draw Caption
            bool active = paintData.Active;

            _skinSetting._formCaption.Draw(paintData.BaseData.Graphics, captionBounds, active ? 0 : 1);

            // Paint Icon
            if (paintData.HasMenu && SkiningForm.Icon != null)
            {
                iconBounds.Size = paintData.IconSize;
                Icon tmpIcon = new Icon(SkiningForm.Icon, paintData.IconSize);
                iconBounds.Y = captionBounds.Y + (captionBounds.Height - iconBounds.Height) / 2;
                paintData.BaseData.Graphics.DrawIcon(tmpIcon, iconBounds);
                textBounds.X      = iconBounds.Right;
                iconBounds.Width -= iconBounds.Right;
            }

            // Paint Icons
            foreach (CaptionButtonPaintData data in paintData.CaptionButtons)
            {
                ControlPaintHelper painter = paintData.IsSmallCaption ? _skinSetting._formCaptionButtonSmall : _skinSetting._formCaptionButton;

                // Get Indices for imagestrip
                int iconIndex       = 0;
                int backgroundIndex = 0;
                FormExtenders.GetButtonData(data, paintData.Active, out iconIndex, out backgroundIndex);

                // get imageStrip for button icon
                ImageStrip iconStrip;
                switch (data.HitTest)
                {
                case HitTest.HTCLOSE:
                    iconStrip = paintData.IsSmallCaption ? _skinSetting._formCloseIconSmall : _skinSetting._formCloseIcon;
                    break;

                case HitTest.HTMAXBUTTON:
                    if (isMaximized)
                    {
                        iconStrip = paintData.IsSmallCaption ? _skinSetting._formRestoreIconSmall : _skinSetting._formRestoreIcon;
                    }
                    else
                    {
                        iconStrip = paintData.IsSmallCaption ? _skinSetting._formMaximizeIconSmall : _skinSetting._formMaximizeIcon;
                    }
                    break;

                case HitTest.HTMINBUTTON:
                    if (isMinimized)
                    {
                        iconStrip = paintData.IsSmallCaption ? _skinSetting._formRestoreIconSmall : _skinSetting._formRestoreIcon;
                    }
                    else
                    {
                        iconStrip = paintData.IsSmallCaption ? _skinSetting._formMinimizeIconSmall : _skinSetting._formMinimizeIcon;
                    }
                    break;

                default:
                    continue;
                }

                // draw background
                if (backgroundIndex >= 0)
                {
                    painter.Draw(paintData.BaseData.Graphics, data.BaseData.Bounds, backgroundIndex);
                }

                // draw Icon
                Rectangle b = data.BaseData.Bounds;
                b.Y += 1;
                if (iconIndex >= 0)
                {
                    iconStrip.Draw(paintData.BaseData.Graphics, iconIndex, b, Rectangle.Empty,
                                   DrawingAlign.Center, DrawingAlign.Center);
                }
                // Ensure textbounds
                textBounds.Width -= data.BaseData.Bounds.Width;
            }

            // draw text
            if (!string.IsNullOrEmpty(paintData.Text) && !textBounds.IsEmpty)
            {
                TextFormatFlags flags = TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis | TextFormatFlags.PreserveGraphicsClipping;
                if (_skinSetting._formIsTextCentered)
                {
                    flags = flags | TextFormatFlags.HorizontalCenter;
                }
                Font font = paintData.IsSmallCaption ? SystemFonts.SmallCaptionFont : SystemFonts.CaptionFont;
                TextRenderer.DrawText(paintData.BaseData.Graphics, paintData.Text, font, textBounds,
                                      paintData.Active ? _skinSetting._formActiveTitleColor : _skinSetting._formInactiveTitleColor, flags);
            }

            // exclude caption area from painting
            Region region = paintData.BaseData.Graphics.Clip;

            region.Exclude(captionBounds);
            paintData.BaseData.Graphics.Clip = region;

            // Paint borders and corners
            _skinSetting._formBorder.DrawFrame(paintData.BaseData.Graphics, windowBounds, paintData.Active ? 0 : 1);

            paintData.BaseData.Graphics.ResetClip();
            return(true);
        }