Author: everaldo
Date: 2007-03-11 21:16:06 -0500 (Sun, 11 Mar 2007)
New Revision: 74082

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LinkLabel.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs
Log:
2007-03-11  Everaldo Canuto  <[EMAIL PROTECTED]>

        * Theme.cs: GetLinkFont abstract method added.
        
        * LinkLabel.cs: 
        - Remove CalcTrimRectangle, no longer needed.
        - Factor also remove, position issues must be fixed in libgdiplus.
        - Move GetPieceColor to ThemeWin32Classic.cs as it is theme related.
        - GetPieceFont, CreateLinkFont and link_font removed, theme must be 
        care about font used to draw links.
        - Set TabStop to true when control is "Selectable", control is 
selectable
        when have one or more links. Fixes #80501 (test case is also added).
        - Set the LinkArea values after links change, LinkArea values must be
        based in first link position and size, a test case was created.
        - Fix ControlStyles.Selectable value, now is based on LinkArea value, 
        the attribute must be true LinkArea.Length > 0. The same was applied to
        TabStop.
        
        * ThemeWin32Classic.cs: 
        - LinkLabelGetPieceColor and LinkLabelGetPieceFont created and used 
        in draw method.
        - Use CPDrawStringDisabled to draw disabled text instead of hard code 
        color change.
        - Draw focus rectangle for every parts focused, including parts that 
        is on another line, its because regions returns various rectangles
        and not only one. Needed to mimic W32 look.
        - Uses Graphics.Clip to delimite region painted, it mean that now 
        complete text is passed to DrawString, with this we solve layout
        issues without create another text renderer.
        - Uses Region.Intersect to fix some flickers problems, now only needed
        parts will redrawed.
        - This changes fixes #79614 and some other unreported issues, on Linux 
        some layout problems still remain, the problem is under 
        MeasureCharacterRanges but it is an libgdiplus bug.



Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-03-12 02:01:42 UTC (rev 74081)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-03-12 02:16:06 UTC (rev 74082)
@@ -1,3 +1,38 @@
+2007-03-11  Everaldo Canuto  <[EMAIL PROTECTED]>
+
+       * Theme.cs: GetLinkFont abstract method added.
+       
+       * LinkLabel.cs: 
+       - Remove CalcTrimRectangle, no longer needed.
+       - Factor also remove, position issues must be fixed in libgdiplus.
+       - Move GetPieceColor to ThemeWin32Classic.cs as it is theme related.
+       - GetPieceFont, CreateLinkFont and link_font removed, theme must be 
+       care about font used to draw links.
+       - Set TabStop to true when control is "Selectable", control is 
selectable
+       when have one or more links. Fixes #80501 (test case is also added).
+       - Set the LinkArea values after links change, LinkArea values must be
+       based in first link position and size, a test case was created.
+       - Fix ControlStyles.Selectable value, now is based on LinkArea value, 
+       the attribute must be true LinkArea.Length > 0. The same was applied to
+       TabStop.
+       
+       * ThemeWin32Classic.cs: 
+       - LinkLabelGetPieceColor and LinkLabelGetPieceFont created and used 
+       in draw method.
+       - Use CPDrawStringDisabled to draw disabled text instead of hard code 
+       color change.
+       - Draw focus rectangle for every parts focused, including parts that 
+       is on another line, its because regions returns various rectangles
+       and not only one. Needed to mimic W32 look.
+       - Uses Graphics.Clip to delimite region painted, it mean that now 
+       complete text is passed to DrawString, with this we solve layout
+       issues without create another text renderer.
+       - Uses Region.Intersect to fix some flickers problems, now only needed
+       parts will redrawed.
+       - This changes fixes #79614 and some other unreported issues, on Linux 
+       some layout problems still remain, the problem is under 
+       MeasureCharacterRanges but it is an libgdiplus bug.
+
 2007-03-10  Gert Driesen  <[EMAIL PROTECTED]>
 
        * TextBox.cs: Set for foreground color.

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LinkLabel.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LinkLabel.cs     
2007-03-12 02:01:42 UTC (rev 74081)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LinkLabel.cs     
2007-03-12 02:16:06 UTC (rev 74082)
@@ -71,10 +71,8 @@
                internal Link[] sorted_links;
                private bool link_visited;
                internal Piece[] pieces;
-               internal Font link_font;
                private Cursor override_cursor;
                private DialogResult dialog_result;
-               internal Rectangle factor;
 
                private Link active_link;
                private Link hovered_link;
@@ -97,7 +95,6 @@
                        link_behavior = LinkBehavior.SystemDefault;
                        link_visited = false;
                        pieces = null;
-                       link_font = null;                       
                        focused_index = -1;
 
                        string_format.FormatFlags = StringFormatFlags.NoClip;
@@ -277,7 +274,6 @@
                protected override void CreateHandle ()
                {
                        base.CreateHandle ();
-                       CreateLinkFont ();
                        CreateLinkPieces ();                    
                }
 
@@ -290,7 +286,6 @@
                protected override void OnFontChanged (EventArgs e)
                {
                        base.OnFontChanged (e);
-                       CreateLinkFont ();
                        CreateLinkPieces ();
                }
 
@@ -510,7 +505,6 @@
                protected override void SetBoundsCore (int x, int y, int width, 
int height, BoundsSpecified specified)
                {
                        base.SetBoundsCore (x, y, width, height, specified);
-                       CreateLinkFont ();
                        CreateLinkPieces();
                }
 
@@ -552,45 +546,32 @@
                        return rv;
                }
 
-               internal Rectangle CalcTrimRectangle ()
-               {
-                       const string text = "X12"; // Magic
-                       
-                       // Measure total area including padding area.
-                       SizeF size = DeviceContext.MeasureString (text, 
link_font);
-                       Rectangle rect = new Rectangle (0, 0, (int) size.Width, 
(int) size.Height);
-                       
-                       // Measure only font area without padding area.
-                       CharacterRange[] ranges = { new CharacterRange(0, 
text.Length) };
-                       string_format.SetMeasurableCharacterRanges (ranges);
-                       Region[] regions = DeviceContext.MeasureCharacterRanges 
(text, link_font, rect, string_format);
-                       
-                       // Calculate diference.
-                       RectangleF rectf = regions [0].GetBounds 
(DeviceContext);
-                       
-                       return new Rectangle ((int) rectf.X, (int) rectf.Y,
-                                                       rect.Width - (int) 
rectf.Width - ((int) rectf.X * 2),
-                                                       rect.Height - (int) 
rectf.Height - ((int) rectf.Y * 2));
-               }
-
                private void CreateLinkPieces ()
                {
                        if (Text.Length == 0) {
                                SetStyle (ControlStyles.Selectable, false);
+                               TabStop = false;
                                return;
                        }
+                       
+                       if (Links.Count == 1 && Links[0].Start == 0 &&  
Links[0].Length == -1)
+                               Links[0].Length = Text.Length;
 
-                       SetStyle (ControlStyles.Selectable, Links.Count > 0);
+                       SortLinks ();
 
+                       // Set the LinkArea values based on first link.
+                       if (Links.Count > 0) {
+                               link_area.Start = Links[0].Start;
+                               link_area.Length = Links[0].Length;
+                       }
+
+                       TabStop = (LinkArea.Length > 0);
+                       SetStyle (ControlStyles.Selectable, TabStop);
+
                        /* don't bother doing the rest if our handle hasn't 
been created */
                        if (!IsHandleCreated)
                                return;
 
-                       if (Links.Count == 1 && Links[0].Start == 0 &&  
Links[0].Length == -1)
-                               Links[0].Length = Text.Length;
-
-                       SortLinks ();
-
                        ArrayList pieces_list = new ArrayList ();
 
                        int current_end = 0;
@@ -630,14 +611,13 @@
                        string_format.SetMeasurableCharacterRanges (ranges);
 
                        Region[] regions = DeviceContext.MeasureCharacterRanges 
(Text,
-                                                                               
 link_font,
+                                                                               
 ThemeEngine.Current.GetLinkFont (this),
                                                                                
 ClientRectangle,
                                                                                
 string_format);
 
                        for (int i = 0; i < pieces.Length; i ++)
                                pieces[i].region = regions[i];
 
-                       factor = CalcTrimRectangle ();
                        Invalidate ();
                }
 
@@ -666,65 +646,6 @@
                        }
                }
                
-               internal Font GetPieceFont (Piece piece)
-               {
-                       if (piece.link == null)
-                               return Font;
-
-                       switch (link_behavior) {                                
-                               case LinkBehavior.AlwaysUnderline:
-                               case LinkBehavior.SystemDefault: // Depends on 
IE configuration
-                               {
-                                       return link_font;
-                               }                               
-                               case LinkBehavior.HoverUnderline:
-                               {
-                                       if (piece.link.Hovered) {
-                                               return link_font;
-                                       } else {
-                                               return Font;
-                                       }                                       
                        
-                               }
-                               
-                               case LinkBehavior.NeverUnderline:               
                
-                               default:
-                                       return Font;                            
        
-                       }
-                       
-               }               
-               
-
-               internal Color GetPieceColor (Piece piece, int i)
-               {
-                       Color color;
-
-                       if (Enabled == false)
-                               return DisabledLinkColor;
-
-                       if (piece.link == null)
-                               return ForeColor;
-
-                       if (!piece.link.Enabled)
-                               color = DisabledLinkColor;
-                       else if (piece.link.Active)
-                               color = ActiveLinkColor;
-                       else if ((LinkVisited && i == 0) || piece.link.Visited 
== true)
-                               color = VisitedLinkColor;
-                       else
-                               color = LinkColor;
-
-                       return color;
-               }
-
-               private void CreateLinkFont ()
-               {
-                       if (link_font != null)
-                               link_font.Dispose ();
-                               
-                       link_font  = new Font (Font.FontFamily, Font.Size, 
Font.Style | FontStyle.Underline,
-                                              Font.Unit);
-               }
-
                #endregion // Private Methods
 
                //

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs 
2007-03-12 02:01:42 UTC (rev 74081)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs 
2007-03-12 02:16:06 UTC (rev 74082)
@@ -722,6 +722,7 @@
                #endregion      // ComboBox
 
                #region Control
+               public abstract Font GetLinkFont (Control control);
                #endregion      // Control
                
                #region Datagrid

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs 
    2007-03-12 02:01:42 UTC (rev 74081)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs 
    2007-03-12 02:16:06 UTC (rev 74082)
@@ -123,6 +123,13 @@
                }
                #endregion      // Internal Methods
 
+               #region Control
+               public override Font GetLinkFont (Control control) 
+               {
+                       return new Font (control.Font.FontFamily, 
control.Font.Size, control.Font.Style | FontStyle.Underline, 
control.Font.Unit); 
+               }
+               #endregion      // Control
+
                #region OwnerDraw Support
                public  override void DrawOwnerDrawBackground 
(DrawItemEventArgs e)
                {
@@ -2094,6 +2101,27 @@
                #endregion      // Label
 
                #region LinkLabel
+
+               private Color LinkLabelGetPieceColor (LinkLabel label, 
LinkLabel.Piece piece, int i)
+               {
+                       if (!label.Enabled)
+                               return label.DisabledLinkColor;
+
+                       if (piece.link == null)
+                               return label.ForeColor;
+
+                       if (!piece.link.Enabled)
+                               return label.DisabledLinkColor;
+                               
+                       if (piece.link.Active)
+                               return label.ActiveLinkColor;
+                               
+                       if ((label.LinkVisited && i == 0) || piece.link.Visited)
+                               return label.VisitedLinkColor;
+                       
+                       return label.LinkColor;
+               }
+               
                public override void DrawLinkLabel (Graphics dc, Rectangle 
clip_rectangle, LinkLabel label)
                {
                        dc.FillRectangle (GetControlBackBrush 
(label.BackColor), clip_rectangle);
@@ -2101,30 +2129,57 @@
                        if (label.pieces == null)
                                return;
 
+                       // Paint all text as disabled.
+                       if (!label.Enabled) {
+                               dc.SetClip (clip_rectangle);
+                               CPDrawStringDisabled (dc, label.Text, 
label.Font, label.BackColor, label.ClientRectangle, label.string_format);
+                               return;
+                       }
+
+                       Font font, link_font = GetLinkFont (label);
+                       
+                       Region text_region = new Region (new Rectangle());
+
+                       // Draw links.
                        for (int i = 0; i < label.pieces.Length; i ++) {
+                               LinkLabel.Piece piece = label.pieces[i];
                                
-                               Rectangle rect = Rectangle.Round 
(label.pieces[i].region.GetBounds (dc));
-
-                               if (!clip_rectangle.IntersectsWith (rect))
+                               if (piece.link == null) {
+                                       text_region.Union (piece.region);
                                        continue;
+                               }
 
-                               LinkLabel.Link link = label.pieces[i].link;
-                               if (link != null && link.Focused)
-                                       CPDrawFocusRectangle (dc, rect, 
label.ForeColor, label.BackColor);
+                               Color color = LinkLabelGetPieceColor (label, 
piece, i);
 
-                               // To adjust diference between measurement and 
draw string.
-                               Rectangle rectf = label.factor;
-                               rect.X      -= rectf.X;
-                               rect.Y      -= rectf.Y;
-                               rect.Width  += rectf.Width;
-                               rect.Height += rectf.Height;
-
-                               dc.DrawString (label.pieces[i].text, 
label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush 
(label.GetPieceColor (label.pieces[i], i)),
-                                              rect, label.string_format);
-
+                               if ( (label.LinkBehavior == 
LinkBehavior.AlwaysUnderline) || 
+                                        (label.LinkBehavior == 
LinkBehavior.SystemDefault) ||
+                                        ((label.LinkBehavior == 
LinkBehavior.HoverUnderline) && piece.link.Hovered) )
+                                       font = link_font;
+                               else
+                                       font = label.Font;
+                               
+                               dc.Clip = piece.region;
+                               dc.Clip.Intersect (clip_rectangle);
+                               dc.DrawString (label.Text, font, 
ResPool.GetSolidBrush (color), label.ClientRectangle, label.string_format);
+                       
+                               // Draw focus rectangle
+                               if ((piece.link != null) && piece.link.Focused) 
{
+                                       foreach (RectangleF rect in 
piece.region.GetRegionScans (dc.Transform))
+                                               ControlPaint.DrawFocusRectangle 
(dc, Rectangle.Round (rect), label.ForeColor, label.BackColor);
+                               }
                        }
+                       
+                       // Draw normal text (without links).
+                       if (!text_region.IsEmpty (dc)) {
+                               dc.Clip = text_region;
+                               dc.Clip.Intersect (clip_rectangle);
+                               if (!dc.Clip.IsEmpty (dc))
+                                       dc.DrawString(label.Text, label.Font, 
ResPool.GetSolidBrush(label.ForeColor), label.ClientRectangle, 
label.string_format);
+                       }
                }
+               
                #endregion      // LinkLabel
+
                #region ListBox
 
                public override void DrawListBoxItem (ListBox ctrl, 
DrawItemEventArgs e)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to