Ejemplo n.º 1
0
        /// <summary>
        /// Draw the text.
        /// </summary>
        /// <param name="hdc"></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 DrawText(IntPtr hdc, Color color, Rectangle rect, int topOffset, int orientation, FontDescription fontDescription, String text,
                                    ContentAlignment contentAlignment, int flags, bool rightToLeft)
        {
            NativeWindowCommon.SetBkMode(hdc, NativeWindowCommon.TRANSPARENT);
            NativeWindowCommon.SetTextColor(hdc, ColorTranslator.ToWin32(color));

#if !PocketPC
            // QCR #439182 & 430913: the font is used for a control before even being initialized.
            // TODO: We need a better fix that avoids calling get_Font() for logical controls that are not initialized properly.
            if (fontDescription == null)
            {
                fontDescription = new FontDescription(Control.DefaultFont);
            }
#endif

            NativeWindowCommon.RECT rc = new NativeWindowCommon.RECT();
            rc.left   = rect.Left;
            rc.right  = rect.Right;
            rc.top    = rect.Top + topOffset;
            rc.bottom = rect.Bottom;

#if !PocketPC
            if (orientation != 0)
            {
                PrintRotatedText(hdc, fontDescription, orientation, text, rect, contentAlignment, rc, rightToLeft);
            }
            else
#endif
            {
                IntPtr hFont = fontDescription.FontHandle;
                NativeWindowCommon.SelectObject(hdc, hFont);
                NativeWindowCommon.DrawText(hdc, text, text.Length, ref rc, flags);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// draw header section title
        /// </summary>
        /// <param name="hdc"></param>
        /// <param name="rc"></param>
        internal void DrawTitle(IntPtr hdc, NativeWindowCommon.RECT rc, int index, bool supportsMultilineText, bool addEndEllipsesFlag, bool rightToLeftLayout)
        {
            Header.HeaderRenderer.GetTitleTextRect(index, ref rc);

            using (Graphics gr = Graphics.FromHdc(hdc))
            {
                //draw sort icon
                if (SortMark != HeaderSectionSortMarks.Non && !HasFilter)
                {
                    int iconWindth = SortIconWidth();
                    DrawSortMark(hdc, rc, gr);
                    rc.right -= iconWindth + Header.SORT_ICON_LEFT_RIGHT_MARGIN;
                }

                if (HasFilter)
                {
                    rc.right -= HeaderSection.FILTER_WIDTH + Header.SORT_ICON_LEFT_RIGHT_MARGIN;
                }

                //draw ... in the end of text if width is too short
                int width  = rc.right - rc.left;
                int format = NativeWindowCommon.DT_EDITCONTROL | NativeWindowCommon.DT_EXTERNALLEADING;

                if (supportsMultilineText)
                {
                    format |= NativeWindowCommon.DT_WORDBREAK;
                }

                StringBuilder stringBuilder = new StringBuilder(Text);

                if (addEndEllipsesFlag)
                {
                    //for windows CE && orientated fonts DT_END_ELLIPSIS style is not supported
                    //http://support.microsoft.com/kb/249678
                    format |= NativeWindowCommon.DT_END_ELLIPSIS;
                }

                if (Environment.OSVersion.Platform == PlatformID.WinCE)
                {
                    if (Text.IndexOf("\n") != -1)
                    {
                        SizeF size = gr.MeasureString(text, Font);
                        int   cur, len = cur = text.Length;
                        while (size.Width > width && cur > 1)
                        {
                            cur = --len;
                            stringBuilder.Length = len;
                            while (cur > 1 && len - cur < 3)
                            {
                                stringBuilder[--cur] = '.';
                            }
                            size = gr.MeasureString(stringBuilder.ToString(), Font);
                        }
                    }
                }



                NativeWindowCommon.SetBkMode(hdc, NativeWindowCommon.TRANSPARENT);
                NativeWindowCommon.SetTextColor(hdc, ColorTranslator.ToWin32(Color));
#if !PocketPC
                if (FontOrientation != 0)
                {
                    Rectangle rectangle = new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);

                    ControlRenderer.PrintRotatedText(hdc, FontDescription, FontOrientation, stringBuilder.ToString(), rectangle, ContentAlignment, rc, rightToLeftLayout);
                }
                else
#endif
                {
                    //text flags are exactly the same as DrawText DT_*** flags
                    format |= (int)Utils.ContentAlignment2TextFlags(ContentAlignment);
                    if (isSingleLine())
                    {
                        format |= NativeWindowCommon.DT_SINGLELINE;
                    }

                    IntPtr hFont = FontDescription.FontHandle;
                    NativeWindowCommon.SelectObject(hdc, hFont);
                    NativeWindowCommon.DrawText(hdc, stringBuilder.ToString(), stringBuilder.Length, ref rc, format);
                }
#if !PocketPC
                //Set the rectangle back
                if (HasFilter)
                {
                    rc.right += HeaderSection.FILTER_WIDTH + Header.SORT_ICON_LEFT_RIGHT_MARGIN;
                    DrawFilter(hdc, rc);
                }
#endif
            }
        }