Esempio n. 1
0
        public static bool SetViewportExtEx(HandleRef hDC, int x, int y, [In, Out] IntNativeMethods.SIZE size)
        {
            bool retVal = IntSetViewportExtEx(hDC, x, y, size);

            DbgUtil.AssertWin32(retVal, "SetViewportExtEx([hdc=0x{0:X8}], x=[{1}], y=[{2}], [out size]) failed.", hDC.Handle, x, y);
            return(retVal);
        }
Esempio n. 2
0
        /// <devdoc>
        ///    <para>
        ///       Returns the Size of the given text using the specified font if not null, otherwise the font currently
        ///       set in the dc is used.
        ///       This method is used to get the size in points of a line of text; it uses GetTextExtentPoint32 function
        ///       which computes the width and height of the text ignoring TAB\CR\LF characters.
        ///       A text extent is the distance between the beginning of the space and a character that will fit in the space.
        ///    </para>
        /// </devdoc>
        public Size GetTextExtent(string text, WindowsFont font)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(Size.Empty);
            }

            IntNativeMethods.SIZE size = new IntNativeMethods.SIZE();

            HandleRef hdc = new HandleRef(null, this.dc.Hdc);

            if (font != null)
            {
                this.dc.SelectFont(font);
            }

            IntUnsafeNativeMethods.GetTextExtentPoint32(hdc, text, size);

            // Unselect, but not from Measurement DC as it keeps the same
            // font selected for perf reasons.
            if (font != null && !MeasurementDCInfo.IsMeasurementDC(this.dc))
            {
                this.dc.ResetFont();
            }

            return(new Size(size.cx, size.cy));
        }
Esempio n. 3
0
        public static bool GetViewportExtEx(HandleRef hdc, [In, Out] IntNativeMethods.SIZE lpSize)
        {
            bool retVal = IntGetViewportExtEx(hdc, lpSize);

            DbgUtil.AssertWin32(retVal, "GetViewportExtEx([hdc=0x{0:X8}], [out size]) failed.", hdc.Handle);
            return(retVal);
        }
Esempio n. 4
0
        /// <devdoc>
        ///     Sets the DC Viewport extent to the specified value and returns its previous value; extent values are in device units.
        /// </devdoc>
        public Size SetViewportExtent(Size newExtent)
        {
            IntNativeMethods.SIZE oldExtent = new IntNativeMethods.SIZE();

            IntUnsafeNativeMethods.SetViewportExtEx(new HandleRef(this, this.Hdc), newExtent.Width, newExtent.Height, oldExtent);

            return(oldExtent.ToSize());
        }
Esempio n. 5
0
        public static int GetTextExtentPoint32(HandleRef hDC, string text, [In, Out] IntNativeMethods.SIZE size)
        {
            int byteCount = text.Length;
            int retVal    = GetTextExtentPoint32W(hDC, text, text.Length, size);

            DbgUtil.AssertWin32(retVal != 0, "GetTextExtentPoint32(hdc=[0x{0:X8}], text=[{1}], size=[{2}] failed.", hDC.Handle, text, size);
            return(retVal);
        }
Esempio n. 6
0
            private void DrawTreeItem(string itemText, int imageIndex, IntPtr dc, System.Windows.Forms.NativeMethods.RECT rcIn, int state, int backColor, int textColor)
            {
                IntNativeMethods.SIZE size      = new IntNativeMethods.SIZE();
                IntNativeMethods.RECT lpRect    = new IntNativeMethods.RECT();
                IntNativeMethods.RECT rect      = new IntNativeMethods.RECT(rcIn.left, rcIn.top, rcIn.right, rcIn.bottom);
                ImageList             imageList = base.ImageList;
                IntPtr zero = IntPtr.Zero;

                if ((state & 2) != 0)
                {
                    zero = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(base.Parent, base.Parent.FontHandle));
                }
                if (((state & 1) != 0) && (this.hbrushDither != IntPtr.Zero))
                {
                    this.FillRectDither(dc, rcIn);
                    System.Windows.Forms.SafeNativeMethods.SetBkMode(new HandleRef(null, dc), 1);
                }
                else
                {
                    System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), backColor);
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 6, ref rect, null, 0, null);
                }
                IntUnsafeNativeMethods.GetTextExtentPoint32(new HandleRef(null, dc), itemText, size);
                lpRect.left   = (rect.left + 0x10) + 8;
                lpRect.top    = rect.top + (((rect.bottom - rect.top) - size.cy) >> 1);
                lpRect.bottom = lpRect.top + size.cy;
                lpRect.right  = rect.right;
                System.Windows.Forms.SafeNativeMethods.SetTextColor(new HandleRef(null, dc), textColor);
                IntUnsafeNativeMethods.DrawText(new HandleRef(null, dc), itemText, ref lpRect, 0x8804);
                System.Windows.Forms.SafeNativeMethods.ImageList_Draw(new HandleRef(imageList, imageList.Handle), imageIndex, new HandleRef(null, dc), 4, rect.top + (((rect.bottom - rect.top) - 0x10) >> 1), 1);
                if ((state & 2) != 0)
                {
                    int clr = System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlLightLight));
                    lpRect.left   = rect.left;
                    lpRect.top    = rect.top;
                    lpRect.bottom = rect.top + 1;
                    lpRect.right  = rect.right;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null);
                    lpRect.bottom = rect.bottom;
                    lpRect.right  = rect.left + 1;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null);
                    System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlDark));
                    lpRect.left   = rect.left;
                    lpRect.right  = rect.right;
                    lpRect.top    = rect.bottom - 1;
                    lpRect.bottom = rect.bottom;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null);
                    lpRect.left = rect.right - 1;
                    lpRect.top  = rect.top;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null);
                    System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), clr);
                }
                if (zero != IntPtr.Zero)
                {
                    System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(null, zero));
                }
            }
Esempio n. 7
0
        public static int GetTextExtentPoint32(HandleRef hDC, string text, [In, Out] IntNativeMethods.SIZE size)
        {
            int retVal;
            int byteCount = text.Length;

            if (Marshal.SystemDefaultCharSize == 1)
            {
                // Convert Unicode string to ANSI.
                byteCount = IntUnsafeNativeMethods.WideCharToMultiByte(IntNativeMethods.CP_ACP, 0, text, text.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
                byte[] textBytes = new byte[byteCount];
                IntUnsafeNativeMethods.WideCharToMultiByte(IntNativeMethods.CP_ACP, 0, text, text.Length, textBytes, textBytes.Length, IntPtr.Zero, IntPtr.Zero);

                byteCount = Math.Min(text.Length, IntNativeMethods.MaxTextLengthInWin9x);
                retVal    = GetTextExtentPoint32A(hDC, textBytes, byteCount, size);
            }
            else
            {
                retVal = GetTextExtentPoint32W(hDC, text, text.Length, size);
            }

            DbgUtil.AssertWin32(retVal != 0, "GetTextExtentPoint32(hdc=[0x{0:X8}], text=[{1}], size=[{2}] failed.", hDC.Handle, text, size);
            return(retVal);
        }
Esempio n. 8
0
 public static extern int GetTextExtentPoint32A(HandleRef hDC, byte[] lpszString, int byteCount, [In, Out] IntNativeMethods.SIZE size);
Esempio n. 9
0
 public static extern int GetTextExtentPoint32W(HandleRef hDC, string text, int len, [In, Out] IntNativeMethods.SIZE size);
        private SizeF GetFontAutoScaleDimensions() 
        {
            SizeF retval = SizeF.Empty;

            // Windows uses CreateCompatibleDC(NULL) to get a
            // memory DC for the monitor the application is currently
            // on.
            IntPtr dc = UnsafeNativeMethods.CreateCompatibleDC(NativeMethods.NullHandleRef);
            if (dc == IntPtr.Zero) {
                throw new Win32Exception();
            }

            HandleRef hdc = new HandleRef(this, dc);

            try {
                // We clone the Windows scaling function here as closely as
                // possible.  They use textmetric for height, and textmetric
                // for width of fixed width fonts.  For variable width fonts
                // they use GetTextExtentPoint32 and pass in a long a-Z string.
                // We must do the same here if our dialogs are to scale in a
                // similar fashion.

                HandleRef hfont = new HandleRef(this, FontHandle);
                HandleRef hfontOld = new HandleRef(this, SafeNativeMethods.SelectObject(hdc, hfont));

                try {
                    NativeMethods.TEXTMETRIC tm = new NativeMethods.TEXTMETRIC();
                    SafeNativeMethods.GetTextMetrics(hdc, ref tm);

                    retval.Height = tm.tmHeight;

                    if ((tm.tmPitchAndFamily & NativeMethods.TMPF_FIXED_PITCH) != 0) {
                        IntNativeMethods.SIZE size = new IntNativeMethods.SIZE();
                        IntUnsafeNativeMethods.GetTextExtentPoint32(hdc, fontMeasureString, size);
                        // Note: intentional integer round off here for Win32 compat
                        //retval.Width = (float)(((size.cx / 26) + 1) / 2);
                        retval.Width = (int)Math.Round(((float)size.cx) / ((float)fontMeasureString.Length));
                    }
                    else {
                        retval.Width = tm.tmAveCharWidth;
                    }
                }
                finally {
                    SafeNativeMethods.SelectObject(hdc, hfontOld);
                }
            }
            finally {
                UnsafeNativeMethods.DeleteCompatibleDC(hdc);
            }

            return retval;
        }
 public virtual void PopupDialog(int row)
 {
     GridEntry gridEntryFromRow = this.GetGridEntryFromRow(row);
     if (gridEntryFromRow != null)
     {
         if ((this.dropDownHolder != null) && this.dropDownHolder.GetUsed())
         {
             this.CloseDropDown();
         }
         else
         {
             bool needsDropDownButton = gridEntryFromRow.NeedsDropDownButton;
             bool enumerable = gridEntryFromRow.Enumerable;
             bool needsCustomEditorButton = gridEntryFromRow.NeedsCustomEditorButton;
             if (enumerable && !needsDropDownButton)
             {
                 this.DropDownListBox.Items.Clear();
                 object propertyValue = gridEntryFromRow.PropertyValue;
                 object[] propertyValueList = gridEntryFromRow.GetPropertyValueList();
                 int num = 0;
                 IntPtr dC = System.Windows.Forms.UnsafeNativeMethods.GetDC(new HandleRef(this.DropDownListBox, this.DropDownListBox.Handle));
                 IntPtr handle = this.Font.ToHfont();
                 System.Internal.HandleCollector.Add(handle, System.Windows.Forms.NativeMethods.CommonHandles.GDI);
                 System.Windows.Forms.NativeMethods.TEXTMETRIC lptm = new System.Windows.Forms.NativeMethods.TEXTMETRIC();
                 int currentValueIndex = -1;
                 try
                 {
                     handle = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(this.DropDownListBox, dC), new HandleRef(this.Font, handle));
                     currentValueIndex = this.GetCurrentValueIndex(gridEntryFromRow);
                     if ((propertyValueList != null) && (propertyValueList.Length > 0))
                     {
                         IntNativeMethods.SIZE size = new IntNativeMethods.SIZE();
                         for (int i = 0; i < propertyValueList.Length; i++)
                         {
                             string propertyTextValue = gridEntryFromRow.GetPropertyTextValue(propertyValueList[i]);
                             this.DropDownListBox.Items.Add(propertyTextValue);
                             IntUnsafeNativeMethods.GetTextExtentPoint32(new HandleRef(this.DropDownListBox, dC), propertyTextValue, size);
                             num = Math.Max(size.cx, num);
                         }
                     }
                     System.Windows.Forms.SafeNativeMethods.GetTextMetrics(new HandleRef(this.DropDownListBox, dC), ref lptm);
                     num += (2 + lptm.tmMaxCharWidth) + SystemInformation.VerticalScrollBarWidth;
                     handle = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(this.DropDownListBox, dC), new HandleRef(this.Font, handle));
                 }
                 finally
                 {
                     System.Windows.Forms.SafeNativeMethods.DeleteObject(new HandleRef(this.Font, handle));
                     System.Windows.Forms.UnsafeNativeMethods.ReleaseDC(new HandleRef(this.DropDownListBox, this.DropDownListBox.Handle), new HandleRef(this.DropDownListBox, dC));
                 }
                 if (currentValueIndex != -1)
                 {
                     this.DropDownListBox.SelectedIndex = currentValueIndex;
                 }
                 this.SetFlag(0x40, false);
                 this.DropDownListBox.Height = Math.Max(lptm.tmHeight + 2, Math.Min(200, this.DropDownListBox.PreferredHeight));
                 this.DropDownListBox.Width = Math.Max(num, this.GetRectangle(row, 2).Width);
                 try
                 {
                     bool flag4 = this.DropDownListBox.Items.Count > (this.DropDownListBox.Height / this.DropDownListBox.ItemHeight);
                     this.SetFlag(0x400, flag4);
                     this.DropDownControl(this.DropDownListBox);
                 }
                 finally
                 {
                     this.SetFlag(0x400, false);
                 }
                 this.Refresh();
             }
             else if (needsCustomEditorButton || needsDropDownButton)
             {
                 try
                 {
                     this.SetFlag(0x10, true);
                     this.Edit.DisableMouseHook = true;
                     try
                     {
                         this.SetFlag(0x400, gridEntryFromRow.UITypeEditor.IsDropDownResizable);
                         gridEntryFromRow.EditPropertyValue(this);
                     }
                     finally
                     {
                         this.SetFlag(0x400, false);
                     }
                 }
                 finally
                 {
                     this.SetFlag(0x10, false);
                     this.Edit.DisableMouseHook = false;
                 }
                 this.Refresh();
                 if (this.FocusInside)
                 {
                     this.SelectGridEntry(gridEntryFromRow, false);
                 }
             }
         }
     }
 }
 public Size SetViewportExtent(Size newExtent)
 {
     IntNativeMethods.SIZE size = new IntNativeMethods.SIZE();
     IntUnsafeNativeMethods.SetViewportExtEx(new HandleRef(this, this.Hdc), newExtent.Width, newExtent.Height, size);
     return size.ToSize();
 }
Esempio n. 13
0
            private void DrawTreeItem(string itemText, int imageIndex, IntPtr dc, NativeMethods.RECT rcIn,
                                        int state, int backColor, int textColor) {
                IntNativeMethods.SIZE size = new IntNativeMethods.SIZE();
                IntNativeMethods.RECT rc2 = new IntNativeMethods.RECT();
                IntNativeMethods.RECT rc = new IntNativeMethods.RECT(rcIn.left, rcIn.top, rcIn.right, rcIn.bottom);
                ImageList imagelist = this.ImageList;
                IntPtr hfontOld = IntPtr.Zero;

                // Select the font of the dialog, so we don't get the underlined font
                // when the item is being tracked
                if ((state & STATE_HOT) != 0)
                    hfontOld = SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(Parent, ((Control)Parent).FontHandle));

                // Fill the background
                if (((state & STATE_SELECTED) != 0) && (hbrushDither != IntPtr.Zero)) {
                    FillRectDither(dc, rcIn);
                    SafeNativeMethods.SetBkMode(new HandleRef(null, dc), NativeMethods.TRANSPARENT);
                }
                else {
                    SafeNativeMethods.SetBkColor(new HandleRef(null, dc), backColor);
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_CLIPPED | NativeMethods.ETO_OPAQUE, ref rc, null, 0, null);
                }

                // Get the height of the font
                IntUnsafeNativeMethods.GetTextExtentPoint32(new HandleRef(null, dc), itemText, size);

                // Draw the caption
                rc2.left = rc.left + SIZE_ICON_X + 2 * PADDING_HORZ;
                rc2.top = rc.top + (((rc.bottom - rc.top) - size.cy) >> 1);
                rc2.bottom = rc2.top + size.cy;
                rc2.right = rc.right;
                SafeNativeMethods.SetTextColor(new HandleRef(null, dc), textColor);
                IntUnsafeNativeMethods.DrawText(new HandleRef(null, dc), itemText, ref rc2,
                                 IntNativeMethods.DT_LEFT | IntNativeMethods.DT_VCENTER | IntNativeMethods.DT_END_ELLIPSIS | IntNativeMethods.DT_NOPREFIX);

                SafeNativeMethods.ImageList_Draw(new HandleRef(imagelist, imagelist.Handle), imageIndex, new HandleRef(null, dc),
                                       PADDING_HORZ, rc.top + (((rc.bottom - rc.top) - SIZE_ICON_Y) >> 1),
                                       NativeMethods.ILD_TRANSPARENT);

                // Draw the hot-tracking border if needed
                if ((state & STATE_HOT) != 0) {
                    int savedColor;

                    // top left
                    savedColor = SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlLightLight));
                    rc2.left = rc.left;
                    rc2.top = rc.top;
                    rc2.bottom = rc.top + 1;
                    rc2.right = rc.right;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null);
                    rc2.bottom = rc.bottom;
                    rc2.right = rc.left + 1;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null);

                    // bottom right
                    SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlDark));
                    rc2.left = rc.left;
                    rc2.right = rc.right;
                    rc2.top = rc.bottom - 1;
                    rc2.bottom = rc.bottom;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null);
                    rc2.left = rc.right - 1;
                    rc2.top = rc.top;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null);

                    SafeNativeMethods.SetBkColor(new HandleRef(null, dc), savedColor);
                }

                if (hfontOld != IntPtr.Zero)
                    SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(null, hfontOld));
            }
        /// <devdoc>
        ///    <para>
        ///       Returns the Size of the given text using the specified font if not null, otherwise the font currently 
        ///       set in the dc is used.
        ///       This method is used to get the size in points of a line of text; it uses GetTextExtentPoint32 function 
        ///       which computes the width and height of the text ignoring TAB\CR\LF characters. 
        ///       A text extent is the distance between the beginning of the space and a character that will fit in the space.
        ///    </para>
        /// </devdoc>
        public Size GetTextExtent(string text, WindowsFont font)
        {
            if (string.IsNullOrEmpty(text))
            {
                return Size.Empty;
            }

            IntNativeMethods.SIZE size = new IntNativeMethods.SIZE();

            HandleRef hdc = new HandleRef(null, this.dc.Hdc);

            if (font != null)
            {
                this.dc.SelectFont(font);
            }

            IntUnsafeNativeMethods.GetTextExtentPoint32(hdc, text, size);

            // Unselect, but not from Measurement DC as it keeps the same
            // font selected for perf reasons.
            if (font != null && !MeasurementDCInfo.IsMeasurementDC(this.dc)) {
                this.dc.ResetFont();
            }

            return new Size(size.cx, size.cy);
        }
 public Size GetTextExtent(string text, WindowsFont font)
 {
     if (string.IsNullOrEmpty(text))
     {
         return Size.Empty;
     }
     IntNativeMethods.SIZE size = new IntNativeMethods.SIZE();
     HandleRef hDC = new HandleRef(null, this.dc.Hdc);
     if (font != null)
     {
         this.dc.SelectFont(font);
     }
     IntUnsafeNativeMethods.GetTextExtentPoint32(hDC, text, size);
     if ((font != null) && !MeasurementDCInfo.IsMeasurementDC(this.dc))
     {
         this.dc.ResetFont();
     }
     return new Size(size.cx, size.cy);
 }
Esempio n. 16
0
 public static extern bool IntGetViewportExtEx(HandleRef hdc, [In, Out] IntNativeMethods.SIZE lpSize);
 private void DrawTreeItem(string itemText, int imageIndex, IntPtr dc, System.Windows.Forms.NativeMethods.RECT rcIn, int state, int backColor, int textColor)
 {
     IntNativeMethods.SIZE size = new IntNativeMethods.SIZE();
     IntNativeMethods.RECT lpRect = new IntNativeMethods.RECT();
     IntNativeMethods.RECT rect = new IntNativeMethods.RECT(rcIn.left, rcIn.top, rcIn.right, rcIn.bottom);
     ImageList imageList = base.ImageList;
     IntPtr zero = IntPtr.Zero;
     if ((state & 2) != 0)
     {
         zero = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(base.Parent, base.Parent.FontHandle));
     }
     if (((state & 1) != 0) && (this.hbrushDither != IntPtr.Zero))
     {
         this.FillRectDither(dc, rcIn);
         System.Windows.Forms.SafeNativeMethods.SetBkMode(new HandleRef(null, dc), 1);
     }
     else
     {
         System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), backColor);
         IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 6, ref rect, null, 0, null);
     }
     IntUnsafeNativeMethods.GetTextExtentPoint32(new HandleRef(null, dc), itemText, size);
     lpRect.left = (rect.left + 0x10) + 8;
     lpRect.top = rect.top + (((rect.bottom - rect.top) - size.cy) >> 1);
     lpRect.bottom = lpRect.top + size.cy;
     lpRect.right = rect.right;
     System.Windows.Forms.SafeNativeMethods.SetTextColor(new HandleRef(null, dc), textColor);
     IntUnsafeNativeMethods.DrawText(new HandleRef(null, dc), itemText, ref lpRect, 0x8804);
     System.Windows.Forms.SafeNativeMethods.ImageList_Draw(new HandleRef(imageList, imageList.Handle), imageIndex, new HandleRef(null, dc), 4, rect.top + (((rect.bottom - rect.top) - 0x10) >> 1), 1);
     if ((state & 2) != 0)
     {
         int clr = System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlLightLight));
         lpRect.left = rect.left;
         lpRect.top = rect.top;
         lpRect.bottom = rect.top + 1;
         lpRect.right = rect.right;
         IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null);
         lpRect.bottom = rect.bottom;
         lpRect.right = rect.left + 1;
         IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null);
         System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlDark));
         lpRect.left = rect.left;
         lpRect.right = rect.right;
         lpRect.top = rect.bottom - 1;
         lpRect.bottom = rect.bottom;
         IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null);
         lpRect.left = rect.right - 1;
         lpRect.top = rect.top;
         IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, 2, ref lpRect, null, 0, null);
         System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(null, dc), clr);
     }
     if (zero != IntPtr.Zero)
     {
         System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(null, zero));
     }
 }
Esempio n. 18
0
 public static extern bool IntSetViewportExtEx(HandleRef hDC, int x, int y, [In, Out] IntNativeMethods.SIZE size);
Esempio n. 19
0
        public virtual void PopupDialog(int row) {
            Debug.WriteLineIf(CompModSwitches.DebugGridView.TraceVerbose,  "PropertyGridView:PopupDialog");
            GridEntry gridEntry = GetGridEntryFromRow(row);
            if (gridEntry != null) {
                if (dropDownHolder != null && dropDownHolder.GetUsed()) {
                    CloseDropDown();
                    return;
                }

                bool fBtnDropDown = gridEntry.NeedsDropDownButton;
                bool fEnum = gridEntry.Enumerable;
                bool fBtnDialog = gridEntry.NeedsCustomEditorButton;
                if (fEnum && !fBtnDropDown) {
                    DropDownListBox.Items.Clear();
                    object value = gridEntry.PropertyValue;
                    object[] rgItems = gridEntry.GetPropertyValueList();
                    int maxWidth = 0;

                    // The listbox draws with GDI, not GDI+.  So, we
                    // use a normal DC here.
                    //
                    IntPtr hdc = UnsafeNativeMethods.GetDC(new HandleRef(DropDownListBox, DropDownListBox.Handle));
                    IntPtr hFont = Font.ToHfont();
                    System.Internal.HandleCollector.Add(hFont, NativeMethods.CommonHandles.GDI);
                    NativeMethods.TEXTMETRIC tm = new NativeMethods.TEXTMETRIC();
                    int iSel = -1;
                    try {
                        hFont = SafeNativeMethods.SelectObject(new HandleRef(DropDownListBox, hdc), new HandleRef(Font, hFont));
                        
                        iSel = GetCurrentValueIndex(gridEntry);
                        if (rgItems != null && rgItems.Length > 0) {
                            string s;
                            IntNativeMethods.SIZE textSize = new IntNativeMethods.SIZE();
                            
                            for (int i = 0; i < rgItems.Length; i++) {
                                s = gridEntry.GetPropertyTextValue(rgItems[i]);
                                DropDownListBox.Items.Add(s);        
                                IntUnsafeNativeMethods.GetTextExtentPoint32(new HandleRef(DropDownListBox, hdc), s, textSize);
                                maxWidth = Math.Max((int) textSize.cx, maxWidth);
                            }
                        }
                        SafeNativeMethods.GetTextMetrics(new HandleRef(DropDownListBox, hdc), ref tm);
                        
                        // border + padding + scrollbar
                        maxWidth += 2 + tm.tmMaxCharWidth + SystemInformation.VerticalScrollBarWidth;
                        
                        hFont = SafeNativeMethods.SelectObject(new HandleRef(DropDownListBox, hdc), new HandleRef(Font, hFont));
                    }
                    finally {
                        SafeNativeMethods.DeleteObject(new HandleRef(Font, hFont));
                        UnsafeNativeMethods.ReleaseDC(new HandleRef(DropDownListBox, DropDownListBox.Handle), new HandleRef(DropDownListBox, hdc));
                    }
                    
                    // [....], 4/25/1998 - must check for -1 and not call the set...
                    if (iSel != -1) {
                        DropDownListBox.SelectedIndex = iSel;
                    }
                    SetFlag(FlagDropDownCommit, false);
                    DropDownListBox.Height = Math.Max(tm.tmHeight + 2, Math.Min(maxListBoxHeight, DropDownListBox.PreferredHeight));
                    DropDownListBox.Width = Math.Max(maxWidth, GetRectangle(row,ROWVALUE).Width);
                    try {
                        bool resizable = DropDownListBox.Items.Count > (DropDownListBox.Height / DropDownListBox.ItemHeight);
                        SetFlag(FlagResizableDropDown, resizable);
                        DropDownControl(DropDownListBox);
                    }
                    finally {
                        SetFlag(FlagResizableDropDown, false);
                    }
                    
                    Refresh();
                }
                else if (fBtnDialog || fBtnDropDown) {
                     try {
                        SetFlag(FlagInPropertySet, true);
                        Edit.DisableMouseHook = true;

                        try {
                            SetFlag(FlagResizableDropDown, gridEntry.UITypeEditor.IsDropDownResizable);
                            gridEntry.EditPropertyValue(this);
                        }
                        finally {
                            SetFlag(FlagResizableDropDown, false);
                        }
                     }
                     finally {
                        SetFlag(FlagInPropertySet, false);
                        Edit.DisableMouseHook = false;
                     }
                     Refresh();
                     
                     // as/urt  31468 -- we can't do this because
                     // some dialogs are non-modal, and
                     // this will pull focus from them.
                     // See ASURT 31468.
                     //
                     //if (fBtnDialog) {
                     //      this.Focus();
                     //}
                     
                     if (FocusInside) {
                        SelectGridEntry(gridEntry, false);
                     }
                }
            }
        }
Esempio n. 20
0
            private void DrawTreeItem(string itemText, int imageIndex, IntPtr dc, NativeMethods.RECT rcIn,
                                      int state, int backColor, int textColor)
            {
                IntNativeMethods.SIZE size      = new IntNativeMethods.SIZE();
                IntNativeMethods.RECT rc2       = new IntNativeMethods.RECT();
                IntNativeMethods.RECT rc        = new IntNativeMethods.RECT(rcIn.left, rcIn.top, rcIn.right, rcIn.bottom);
                ImageList             imagelist = this.ImageList;
                IntPtr hfontOld = IntPtr.Zero;

                // Select the font of the dialog, so we don't get the underlined font
                // when the item is being tracked
                if ((state & STATE_HOT) != 0)
                {
                    hfontOld = SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(Parent, ((Control)Parent).FontHandle));
                }

                // Fill the background
                if (((state & STATE_SELECTED) != 0) && (hbrushDither != IntPtr.Zero))
                {
                    FillRectDither(dc, rcIn);
                    SafeNativeMethods.SetBkMode(new HandleRef(null, dc), NativeMethods.TRANSPARENT);
                }
                else
                {
                    SafeNativeMethods.SetBkColor(new HandleRef(null, dc), backColor);
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_CLIPPED | NativeMethods.ETO_OPAQUE, ref rc, null, 0, null);
                }

                // Get the height of the font
                IntUnsafeNativeMethods.GetTextExtentPoint32(new HandleRef(null, dc), itemText, size);

                // Draw the caption
                rc2.left   = rc.left + SIZE_ICON_X + 2 * PADDING_HORZ;
                rc2.top    = rc.top + (((rc.bottom - rc.top) - size.cy) >> 1);
                rc2.bottom = rc2.top + size.cy;
                rc2.right  = rc.right;
                SafeNativeMethods.SetTextColor(new HandleRef(null, dc), textColor);
                IntUnsafeNativeMethods.DrawText(new HandleRef(null, dc), itemText, ref rc2,
                                                IntNativeMethods.DT_LEFT | IntNativeMethods.DT_VCENTER | IntNativeMethods.DT_END_ELLIPSIS | IntNativeMethods.DT_NOPREFIX);

                SafeNativeMethods.ImageList_Draw(new HandleRef(imagelist, imagelist.Handle), imageIndex, new HandleRef(null, dc),
                                                 PADDING_HORZ, rc.top + (((rc.bottom - rc.top) - SIZE_ICON_Y) >> 1),
                                                 NativeMethods.ILD_TRANSPARENT);

                // Draw the hot-tracking border if needed
                if ((state & STATE_HOT) != 0)
                {
                    int savedColor;

                    // top left
                    savedColor = SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlLightLight));
                    rc2.left   = rc.left;
                    rc2.top    = rc.top;
                    rc2.bottom = rc.top + 1;
                    rc2.right  = rc.right;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null);
                    rc2.bottom = rc.bottom;
                    rc2.right  = rc.left + 1;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null);

                    // bottom right
                    SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlDark));
                    rc2.left   = rc.left;
                    rc2.right  = rc.right;
                    rc2.top    = rc.bottom - 1;
                    rc2.bottom = rc.bottom;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null);
                    rc2.left = rc.right - 1;
                    rc2.top  = rc.top;
                    IntUnsafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null);

                    SafeNativeMethods.SetBkColor(new HandleRef(null, dc), savedColor);
                }

                if (hfontOld != IntPtr.Zero)
                {
                    SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(null, hfontOld));
                }
            }
 private SizeF GetFontAutoScaleDimensions()
 {
     SizeF empty = SizeF.Empty;
     IntPtr handle = System.Windows.Forms.UnsafeNativeMethods.CreateCompatibleDC(System.Windows.Forms.NativeMethods.NullHandleRef);
     if (handle == IntPtr.Zero)
     {
         throw new Win32Exception();
     }
     HandleRef hDC = new HandleRef(this, handle);
     try
     {
         HandleRef hObject = new HandleRef(this, base.FontHandle);
         HandleRef ref4 = new HandleRef(this, System.Windows.Forms.SafeNativeMethods.SelectObject(hDC, hObject));
         try
         {
             System.Windows.Forms.NativeMethods.TEXTMETRIC lptm = new System.Windows.Forms.NativeMethods.TEXTMETRIC();
             System.Windows.Forms.SafeNativeMethods.GetTextMetrics(hDC, ref lptm);
             empty.Height = lptm.tmHeight;
             if ((lptm.tmPitchAndFamily & 1) != 0)
             {
                 IntNativeMethods.SIZE size = new IntNativeMethods.SIZE();
                 IntUnsafeNativeMethods.GetTextExtentPoint32(hDC, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", size);
                 empty.Width = (int) Math.Round((double) (((float) size.cx) / ((float) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".Length)));
                 return empty;
             }
             empty.Width = lptm.tmAveCharWidth;
             return empty;
         }
         finally
         {
             System.Windows.Forms.SafeNativeMethods.SelectObject(hDC, ref4);
         }
     }
     finally
     {
         System.Windows.Forms.UnsafeNativeMethods.DeleteCompatibleDC(hDC);
     }
     return empty;
 }