Esempio n. 1
0
        internal virtual Size_ InternalGetPreferredSize(Size_ proposed)
        {
            Size_ size;

            if (Text == string.Empty)
            {
                size = new Size_(0, Font.Height);
            }
            else
            {
                size        = Size_.Ceiling(TextRenderer.MeasureString(Text, Font, req_witdthsize, string_format));
                size.Width += 3;
            }

            size.Width  += Padding.Horizontal;
            size.Height += Padding.Vertical;

            if (!use_compatible_text_rendering)
            {
                return(size);
            }

            if (border_style == BorderStyle.None)
            {
                size.Height += 3;
            }
            else
            {
                size.Height += 6;
            }

            return(size);
        }
Esempio n. 2
0
        internal virtual Size InternalGetPreferredSize(Size proposed)
        {
            Size bordersAndPaddings = new Size(Padding.Horizontal, Padding.Vertical);
            Size size;

            if (use_compatible_text_rendering)
            {
                bordersAndPaddings.Height += border_style == BorderStyle.None ? 3 : 6;
            }

            if (Text == string.Empty)
            {
                size = new Size(0, Font.Height);
            }
            else
            {
                size        = Size.Ceiling(TextRenderer.MeasureString(Text, Font, proposed.Width <= 1 ? int.MaxValue : (proposed.Width - bordersAndPaddings.Width), string_format));
                size.Width += 3;
            }

            return(size + bordersAndPaddings);
        }
Esempio n. 3
0
        private bool IsFontFamilyFixedPitch(FontFamily family)
        {
            FontStyle fs;

            if (family.IsStyleAvailable(FontStyle.Regular))
            {
                fs = FontStyle.Regular;
            }
            else if (family.IsStyleAvailable(FontStyle.Bold))
            {
                fs = FontStyle.Bold;
            }
            else if (family.IsStyleAvailable(FontStyle.Italic))
            {
                fs = FontStyle.Italic;
            }
            else if (family.IsStyleAvailable(FontStyle.Strikeout))
            {
                fs = FontStyle.Strikeout;
            }
            else if (family.IsStyleAvailable(FontStyle.Underline))
            {
                fs = FontStyle.Underline;
            }
            else
            {
                return(false);
            }

            Font f = new Font(family.Name, 10, fs);

            if (TextRenderer.MeasureString("i", f).Width == TextRenderer.MeasureString("w", f).Width)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        internal static Size_ MeasureTextInternal(IDeviceContext dc, string text, Font font, Size_ proposedSize, TextFormatFlags flags, bool useMeasureString)
        {
            if (!useMeasureString && !XplatUI.RunningOnUnix)
            {
                // Tell DrawText to calculate Size_ instead of draw
                flags |= (TextFormatFlags)1024;                         // DT_CALCRECT

                IntPtr hdc = dc.GetHdc();

                XplatUIWin32.RECT r = XplatUIWin32.RECT.FromRectangle(new Rectangle_(Point_.Empty, proposedSize));

                IntPtr prevobj;

                if (font != null)
                {
                    prevobj = SelectObject(hdc, font.ToHfont());
                    Win32DrawText(hdc, text, text.Length, ref r, (int)flags);
                    prevobj = SelectObject(hdc, prevobj);
                    DeleteObject(prevobj);
                }
                else
                {
                    Win32DrawText(hdc, text, text.Length, ref r, (int)flags);
                }

                dc.ReleaseHdc();

                // Really, I am just making something up here, which as far as I can tell, MS
                // just makes something up as well.  This will require lots of tweaking to match MS.  :(
                Size_ retval = r.ToRectangle().Size;

                if (retval.Width > 0 && (flags & TextFormatFlags.NoPadding) == 0)
                {
                    retval.Width += 6;
                    retval.Width += (int)retval.Height / 8;
                }

                return(retval);
            }
            else
            {
                StringFormat sf = FlagsToStringFormat(flags);

                Size_ retval;

                int proposedWidth;
                if (proposedSize.Width == 0)
                {
                    proposedWidth = Int32.MaxValue;
                }
                else
                {
                    proposedWidth = proposedSize.Width;
                    if ((flags & TextFormatFlags.NoPadding) == 0)
                    {
                        proposedWidth -= 9;
                    }
                }
                if (dc is Graphics)
                {
                    retval = (dc as Graphics).MeasureString(text, font, proposedWidth, sf).ToSize();
                }
                else
                {
                    retval = TextRenderer.MeasureString(text, font, proposedWidth, sf).ToSize();
                }

                if (retval.Width > 0 && (flags & TextFormatFlags.NoPadding) == 0)
                {
                    retval.Width += 9;
                }

                return(retval);
            }
        }
Esempio n. 5
0
            private void InitFormsSize()
            {
                int tb_width = 0;

                // Max width of messagebox must be 60% of screen width
                int max_width = (int)(Screen.GetWorkingArea(this).Width * 0.6);

                // First we have to know the size of text + image
                Drawing.SizeF tsize = TextRenderer.MeasureString(msgbox_text, this.Font, max_width);
                text_rect.Size = tsize;

                if (icon_image != null)
                {
                    tsize.Width += icon_image.Width + 10;
                    if (icon_image.Height > tsize.Height)
                    {
                        // Place text middle-right
                        text_rect.Location = new Point(icon_image.Width + space_image_text + space_border, (int)((icon_image.Height / 2) - (tsize.Height / 2)) + space_border);
                    }
                    else
                    {
                        text_rect.Location = new Point(icon_image.Width + space_image_text + space_border, 2 + space_border);
                    }
                    if (tsize.Height < icon_image.Height)
                    {
                        tsize.Height = icon_image.Height;
                    }
                }
                else
                {
                    text_rect.Location = new Point(space_border + button_space, space_border);
                }
                tsize.Height += space_border * 2;

                // Now we want to know the amount of buttons
                int buttoncount;

                switch (msgbox_buttons)
                {
                case MessageBoxButtons.OK:
                    buttoncount = 1;
                    break;

                case MessageBoxButtons.OKCancel:
                    buttoncount = 2;
                    break;

                case MessageBoxButtons.AbortRetryIgnore:
                    buttoncount = 3;
                    break;

                case MessageBoxButtons.YesNoCancel:
                    buttoncount = 3;
                    break;

                case MessageBoxButtons.YesNo:
                    buttoncount = 2;
                    break;

                case MessageBoxButtons.RetryCancel:
                    buttoncount = 2;
                    break;

                default:
                    buttoncount = 0;
                    break;
                }
                if (show_help)
                {
                    buttoncount++;
                }

                // Calculate the width based on amount of buttons
                tb_width = (button_width + button_space) * buttoncount;

                // The form caption can also make us bigger
                SizeF caption = TextRenderer.MeasureString(Text, new Font(DefaultFont, FontStyle.Bold));

                // Use the bigger of the caption size (plus some arbitrary borders/close button)
                // or the text size, up to 60% of the screen (max_size)
                Size new_size = new SizeF(Math.Min(Math.Max(caption.Width + 40, tsize.Width), max_width), tsize.Height).ToSize();

                // Now we choose the good size for the form
                if (new_size.Width > tb_width)
                {
                    this.ClientSize = new Size(new_size.Width + (space_border * 2), Height = new_size.Height + (space_border * 4));
                }
                else
                {
                    this.ClientSize = new Size(tb_width + (space_border * 2), Height = new_size.Height + (space_border * 4));
                }

                // Now we set the left of the buttons
                button_left = (this.ClientSize.Width / 2) - (tb_width / 2) + 5;
                AddButtons();
                size_known = true;

                // Still needs to implement defaultButton and options
                switch (msgbox_default)
                {
                case MessageBoxDefaultButton.Button2: {
                    if (this.buttons[1] != null)
                    {
                        ActiveControl = this.buttons[1];
                    }
                    break;
                }

                case MessageBoxDefaultButton.Button3: {
                    if (this.buttons[2] != null)
                    {
                        ActiveControl = this.buttons[2];
                    }
                    break;
                }
                }
            }
Esempio n. 6
0
        private void CalcPanelSizes()
        {
            if (panels == null || !show_panels)
            {
                return;
            }

            if (Width == 0 || Height == 0)
            {
                return;
            }

            int       border  = 2;
            int       gap     = ThemeEngine.Current.StatusBarHorzGapWidth;
            int       taken   = 0;
            ArrayList springs = null;

            taken = border;
            for (int i = 0; i < panels.Count; i++)
            {
                StatusBarPanel p = panels [i];

                if (p.AutoSize == StatusBarPanelAutoSize.None)
                {
                    taken += p.Width;
                    taken += gap;
                    continue;
                }
                if (p.AutoSize == StatusBarPanelAutoSize.Contents)
                {
                    int len = (int)(TextRenderer.MeasureString(p.Text, Font).Width + 0.5F);
                    if (p.Icon != null)
                    {
                        len += 21;
                    }
                    p.SetWidth(len + 8);
                    taken += p.Width;
                    taken += gap;
                    continue;
                }
                if (p.AutoSize == StatusBarPanelAutoSize.Spring)
                {
                    if (springs == null)
                    {
                        springs = new ArrayList();
                    }
                    springs.Add(p);
                    taken += gap;
                    continue;
                }
            }

            if (springs != null)
            {
                int spring_total = springs.Count;
                int total_width  = Width - taken - (SizingGrip ? ThemeEngine.Current.StatusBarSizeGripWidth : 0);
                for (int i = 0; i < spring_total; i++)
                {
                    StatusBarPanel p     = (StatusBarPanel)springs[i];
                    int            width = total_width / spring_total;
                    p.SetWidth(width >= p.MinWidth ? width : p.MinWidth);
                }
            }

            taken = border;
            for (int i = 0; i < panels.Count; i++)
            {
                StatusBarPanel p = panels [i];
                p.X    = taken;
                taken += p.Width + gap;
            }
        }
Esempio n. 7
0
			private void InitFormsSize ()
			{
				int tb_width = 0;

				// Max width of messagebox must be 60% of screen width
				int max_width = (int) (Screen.GetWorkingArea (this).Width * 0.6);
				if (max_width > 500) {
					float dx;
					using (Graphics g = this.CreateGraphics ()) {
						dx = g.DpiX;
					}
					int new_max_width = (int) (dx * 5.0);	// aim for text no wider than 5.0 inches
					if (new_max_width < max_width)
						max_width = new_max_width;
				}
				// First we have to know the Size_ of text + image
				int iconImageWidth = 0;
				if (icon_image != null)
					iconImageWidth = icon_image.Width + 10;
				SizeF_ tsize = TextRenderer.MeasureText (msgbox_text, this.Font, new Size_ (max_width - iconImageWidth, int.MaxValue), TextFormatFlags.WordBreak);
				text_rect = new RectangleF ();
				text_rect.Height = tsize.Height;

				if (icon_image != null) {
					tsize.Width += iconImageWidth;
					if(icon_image.Height > tsize.Height) {
						// Place text middle-right
						text_rect.Location = new Point_ (icon_image.Width + space_image_text + space_border, (int)((icon_image.Height/2)-(tsize.Height/2)) + space_border);
					} else {
						text_rect.Location = new Point_ (icon_image.Width + space_image_text + space_border, 2 + space_border);
					}
					if (tsize.Height < icon_image.Height)
						tsize.Height = icon_image.Height;
				} else {
					text_rect.Location = new Point_ (space_border + button_space, space_border);
				}
				tsize.Height += space_border * 2;
				text_rect.Height += space_border;

				// Now we want to know the amount of buttons
				int buttoncount;
				switch (msgbox_buttons) {
					case MessageBoxButtons.OK:
						buttoncount = 1;
						break;

					case MessageBoxButtons.OKCancel:
						buttoncount = 2;
						break;

					case MessageBoxButtons.AbortRetryIgnore:
						buttoncount = 3;
						break;

					case MessageBoxButtons.YesNoCancel:
						buttoncount = 3;
						break;

					case MessageBoxButtons.YesNo:
						buttoncount = 2;
						break;

					case MessageBoxButtons.RetryCancel:
						buttoncount = 2;
						break;
					
					default:
						buttoncount = 0;
						break;
				
				}
				if (show_help)
					buttoncount ++;
				
				// Calculate the width based on amount of buttons 
				tb_width = (button_width + button_space) * buttoncount;  

				// The form caption can also make us bigger
				SizeF_ caption = TextRenderer.MeasureString (Text, new Font (DefaultFont, FontStyle.Bold));
				
				// Use the bigger of the caption Size_ (plus some arbitrary borders/close button)
				// or the text size, up to 60% of the screen (max_size)
				Size_ new_size = new SizeF_ (Math.Min (Math.Max (caption.Width + 40, tsize.Width), max_width), tsize.Height).ToSize ();
				
				// Now we choose the good Size_ for the form
				if (new_size.Width > tb_width)
					this.ClientSize = new Size_ (new_size.Width + (space_border * 2), Height = new_size.Height + (space_border * 4));
				else
					this.ClientSize = new Size_ (tb_width + (space_border * 2), Height = new_size.Height + (space_border * 4));

				text_rect.Width = new_size.Width - iconImageWidth;

				// Now we set the left of the buttons
				button_left = (this.ClientSize.Width / 2) - (tb_width / 2) + 5;
				AddButtons ();
				size_known = true;

				// Still needs to implement defaultButton and options
				switch(msgbox_default) {
					case MessageBoxDefaultButton.Button2: {
						if (this.buttons[1] != null) {
							ActiveControl = this.buttons[1];
						}
						break;
					}

					case MessageBoxDefaultButton.Button3: {
						if (this.buttons[2] != null) {
							ActiveControl = this.buttons[2];
						}
						break;
					}
				}
			}