Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hdc"></param>
        /// <param name="fontDescription"></param>
        /// <param name="orientation"></param>
        /// <param name="text"></param>
        /// <param name="rectangle"></param>
        /// <param name="contentAlignment"></param>
        /// <param name="rect"></param>
        internal static void PrintRotatedText(IntPtr hdc, FontDescription fontDescription, int orientation, string text, Rectangle rectangle, ContentAlignment contentAlignment,
                                              NativeWindowCommon.RECT rect, bool rightToLeft)
        {
            IntPtr hFont;
            Point  point;

            // get the original font and its LOGFONT
            NativeWindowCommon.LOGFONT logfont = fontDescription.LogFont;
            // Set the rotation angle
            logfont.lfEscapement = logfont.lfOrientation = orientation;

            // create the new, rotated font
            hFont = NativeWindowCommon.CreateFontIndirect(logfont);
            NativeWindowCommon.SelectObject(hdc, hFont);

            point = CalculateStartCoordinates(hdc, rectangle, orientation, text, contentAlignment);

            uint fuOptions = NativeWindowCommon.ETO_CLIPPED;

            if (rightToLeft)
            {
                fuOptions = NativeWindowCommon.ETO_RTLREADING;
            }

            NativeWindowCommon.ExtTextOut(hdc, point.X, point.Y, fuOptions, ref rect, text, (uint)text.Length, null);

            NativeWindowCommon.DeleteObject(hFont);
        }
Esempio n. 2
0
 public virtual void Dispose()
 {
     NativeWindowCommon.DeleteObject(HeaderDividerPen);
     if (TitleBrush != IntPtr.Zero)
     {
         NativeWindowCommon.DeleteObject(TitleBrush);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Returns the font text metrics for true type and non true type fonts assigned to control according to mgFont.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="mgFont"></param>
        /// <returns></returns>
        public static PointF GetFontMetricsByMgFont(Control control, MgFont mgFont)
        {
            PointF retPoint;

            lock (_metricsMgFontCache)
            {
                if (!_metricsMgFontCache.TryGetValue(mgFont, out retPoint))
                {
#if PocketPC
                    // In PocketPC, Panels don't have CreateGraphics. We go up the parents
                    // tree until we find a non-panel one.
                    while (control is Panel)
                    {
                        control = control.Parent;
                    }
#endif

                    using (Graphics g = control.CreateGraphics())
                    {
                        int dpiY = (int)g.DpiY;

                        NativeWindowCommon.LOGFONT nativeLogFont = new NativeWindowCommon.LOGFONT();

                        nativeLogFont.lfFaceName = mgFont.TypeFace;
                        nativeLogFont.lfHeight   = -NativeWindowCommon.MulDiv(mgFont.Height, dpiY, 72);

                        // Set the rotation angle
                        nativeLogFont.lfEscapement = nativeLogFont.lfOrientation = mgFont.Orientation;
                        nativeLogFont.lfItalic     = Convert.ToByte(mgFont.Italic);
                        nativeLogFont.lfStrikeOut  = Convert.ToByte(mgFont.Strikethrough);
                        nativeLogFont.lfUnderline  = Convert.ToByte(mgFont.Underline);

                        if (mgFont.Bold)
                        {
                            nativeLogFont.lfWeight = (int)NativeWindowCommon.FontWeight.FW_BOLD;
                        }
                        else
                        {
                            nativeLogFont.lfWeight = (int)NativeWindowCommon.FontWeight.FW_NORMAL;
                        }

                        nativeLogFont.lfCharSet = (byte)mgFont.CharSet;
                        IntPtr hFont = NativeWindowCommon.CreateFontIndirect(nativeLogFont);

                        // use the font in the DC
                        GetTextMetrics(g, hFont, mgFont.TypeFace, mgFont.Height, out retPoint);

                        //Release the resources.
                        nativeLogFont = null;
                        NativeWindowCommon.DeleteObject(hFont);
                    }

                    _metricsMgFontCache.Add(mgFont, retPoint);
                }
            }

            return(retPoint);
        }
Esempio n. 4
0
        /// <summary>
        /// Draw the text supporting clipping according to ClipRegion.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="color"></param>
        /// <param name="rect"></param>
        /// <param name="topOffset"></param>
        /// <param name="orientation"></param>
        /// <param name="fontDescription"></param>
        /// <param name="text"></param>
        /// <param name="contentAlignment"></param>
        /// <param name="flags"></param>
        public static void ClipSupportingDrawText(Graphics g, Color color, Rectangle rect, int topOffset, int orientation, FontDescription fontDescription, String text,
                                                  ContentAlignment contentAlignment, int flags, bool rightToLeft)
        {
            IntPtr region = IntPtr.Zero;
            IntPtr currentclippedRegion = g.Clip.GetHrgn(g);
            bool   IsRegionInfinite     = g.Clip.IsInfinite(g);
            IntPtr hdc = g.GetHdc();

            NativeWindowCommon.SetBkMode(hdc, NativeWindowCommon.TRANSPARENT);
            NativeWindowCommon.SetTextColor(hdc, ColorTranslator.ToWin32(color));

            // Text rectangle as clip Region
            IntPtr clipRegion = NativeWindowCommon.CreateRectRgn(rect.Left, rect.Top, rect.Right, rect.Bottom);

            // If Text starts above control, it needs to clip
            if (topOffset < 0)
            {
                // if current graphics is already clipped, then we need to merge with current text rectangle clip
                if (!IsRegionInfinite)
                {
                    NativeWindowCommon.CombineRgn(currentclippedRegion, currentclippedRegion, clipRegion, NativeWindowCommon.RGN_AND);
                }
            }

            if (IsRegionInfinite)
            {
                // If there is no clip region on graphics, set text rectangle as clip region
                region = clipRegion;
            }
            else if (currentclippedRegion != IntPtr.Zero)
            {
                // use intersected region as clip region
                region = currentclippedRegion;
            }

            // Select resultant clipped region on DC
            if (region != IntPtr.Zero)
            {
                NativeWindowCommon.SelectClipRgn(hdc, region);
            }


            if (clipRegion != IntPtr.Zero)
            {
                NativeWindowCommon.DeleteObject(clipRegion);
            }

            // Draw text
            DrawText(hdc, color, rect, topOffset, orientation, fontDescription, text, contentAlignment, flags, rightToLeft);

            // release objects
            g.ReleaseHdc(hdc);
            if (currentclippedRegion != IntPtr.Zero)
            {
                g.Clip.ReleaseHrgn(currentclippedRegion);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Draw Header section filter
        /// </summary>
        /// <param name="hdc"></param>
        /// <param name="rct"></param>
        /// <param name="g"></param>
        public void DrawFilter(IntPtr hdc, NativeWindowCommon.RECT rct)
        {
            //Filter line drawing
            int x       = rct.right - FILTER_WIDTH;
            int bottomY = 0;

            Header.HeaderRenderer.DrawLine(hdc, new Point(x, bottomY), new Point(x, Header.FilterHeight));

            //Filter highlight drawing
            NativeWindowCommon.RECT rectHighlight = new NativeWindowCommon.RECT()
            {
                bottom = Header.FilterHeight,
                top    = 0,
                left   = rct.right - FILTER_WIDTH + 1,
                right  = rct.right + 1
            };

            if ((FilterColor != Color.Empty) && !Header.OnSectionResize)
            {
                if (Header.TitleColor != Color.Empty)
                {
                    Header.HighlightBrush = NativeWindowCommon.CreateSolidBrush(ColorTranslator.ToWin32(FilterColor));
                }
                else
                {
                    Header.HighlightBrush = NativeWindowCommon.CreateSolidBrush(ColorTranslator.ToWin32(Color.FromArgb(255, 149, 202, 255)));
                }
                NativeWindowCommon.FillRect(hdc, ref rectHighlight, Header.HighlightBrush);
                NativeWindowCommon.DeleteObject(Header.HighlightBrush);
            }

            int filterWidthIcon = FILTER_WIDTH / 3;

            //Filter arrow drawing
            NativeWindowCommon.POINT[] points = new NativeWindowCommon.POINT[3];
            //right
            points[0].x = rct.right - filterWidthIcon;
            points[0].y = rct.top + (rct.bottom - rct.top) / 2 - 2;

            // center point
            points[1].x = rct.right - FILTER_WIDTH / 2;
            points[1].y = points[0].y + filterWidthIcon / 2;

            // left point
            points[2].x = points[0].x - filterWidthIcon;
            points[2].y = points[0].y;

            NativeWindowCommon.SelectObject(hdc, Header.FilterBrush);
            NativeWindowCommon.SelectObject(hdc, Header.FilterPen);
            NativeWindowCommon.Polygon(hdc, points, 3);
        }
Esempio n. 6
0
        protected override void Dispose(bool bDisposing)
        {
            if (this.hBitmap != IntPtr.Zero)
            {
                NativeWindowCommon.DeleteObject(this.hBitmap);
                this.hBitmap = IntPtr.Zero;
            }

            if (bDisposing && this.collection != null)
            {
                this.collection.Remove(this);
            }

            base.Dispose(bDisposing);
        }
Esempio n. 7
0
        internal void _SetBitmap(Bitmap bitmap)
        {
            if (this.hBitmap != IntPtr.Zero)
            {
                NativeWindowCommon.DeleteObject(this.hBitmap);
                this.hBitmap = IntPtr.Zero;
            }

            this.bitmap = bitmap;

            if (this.bitmap != null)
            {
                this.fFormat |= NativeHeader.HDF_BITMAP;
            }
            else
            {
                this.fFormat &= (~NativeHeader.HDF_BITMAP);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Paint the border
        /// </summary>
        /// <param name="m"></param>
        private void WMNCPaint(ref Message m)
        {
            IntPtr hDC = NativeWindowCommon.GetWindowDC(m.HWnd);

            if (hDC != IntPtr.Zero)
            {
                IntPtr hrgnWindow = IntPtr.Zero;
                IntPtr hrgnClient = IntPtr.Zero;
                try
                {
                    Rectangle rect = new Rectangle(1, 1, Width - 2, Height - 2);
                    hrgnWindow = NativeWindowCommon.CreateRectRgn(0, 0, Width, Height);
                    hrgnClient = NativeWindowCommon.CreateRectRgn(rect.Left, rect.Top, rect.Right, rect.Bottom);

                    //Creates the union of two combined regions except for any overlapping areas.
                    NativeWindowCommon.CombineRgn(hrgnWindow, hrgnWindow, hrgnClient, NativeWindowCommon.RGN_XOR);
                    NativeWindowCommon.SelectClipRgn(hDC, hrgnWindow);

                    using (Graphics g = Graphics.FromHdc(hDC))
                    {
                        g.Clear(VisualStyleInformation.TextControlBorder);
                    }
                    m.Result = IntPtr.Zero;
                }
                finally
                {
                    NativeWindowCommon.ReleaseDC(m.HWnd, hDC);
                    if (hrgnWindow != IntPtr.Zero)
                    {
                        NativeWindowCommon.DeleteObject(hrgnWindow);
                    }
                    if (hrgnClient != IntPtr.Zero)
                    {
                        NativeWindowCommon.DeleteObject(hrgnClient);
                    }
                }
            }
        }
Esempio n. 9
0
        /// <summary> Load image from resource. </summary>
        /// <param name="name"></param>
        /// <param name="loadAsIcon"></param>
        /// <returns></returns>
        private static Image LoadImageFromResource(String name)
        {
            Image  image        = null;
            string resourceName = name.Substring(1);

            int indexOfDot = resourceName.IndexOf('.');

            if (indexOfDot != -1)
            {
                string resourceFile = resourceName.Substring(0, indexOfDot);
                resourceName = resourceName.Substring(indexOfDot + 1);

                //TODO: load the library and the image from managed assembly as well.
                IntPtr hLib   = user32.LoadLibrary(resourceFile);
                IntPtr imgPtr = NativeWindowCommon.LoadImage(hLib, resourceName, NativeWindowCommon.IMAGE_BITMAP, 0, 0, 0);

                if (imgPtr != IntPtr.Zero)
                {
                    try
                    {
                        image = (Image)(Image.FromHbitmap(imgPtr).Clone());
                    }
                    finally
                    {
                        NativeWindowCommon.DeleteObject(imgPtr);
                    }
                }
            }
            else
            {
                if (ImageLoader != null)
                {
                    image = (Image)ImageLoader.GetResourceObject(resourceName);
                }
            }

            return(image);
        }
Esempio n. 10
0
 /// <summary>
 /// update the title brush
 /// </summary>
 public void UpdateTitleBrush()
 {
     NativeWindowCommon.DeleteObject(TitleBrush);
     TitleBrush = HeaderBackColor == Color.Empty ? IntPtr.Zero :
                  NativeWindowCommon.CreateSolidBrush(ColorTranslator.ToWin32(HeaderBackColor));
 }
Esempio n. 11
0
 /// <summary>
 /// update the divider pen
 /// </summary>
 public void UpdateDividerPen()
 {
     NativeWindowCommon.DeleteObject(HeaderDividerPen); //Release previous
     HeaderDividerPen = NativeWindowCommon.CreatePen(NativeWindowCommon.PS_SOLID, 1, ColorTranslator.ToWin32(GetDividerColor()));
 }