diff options
author | Jordi Mas i Hernandez <jordi@mono-cvs.ximian.com> | 2004-09-07 13:40:15 +0400 |
---|---|---|
committer | Jordi Mas i Hernandez <jordi@mono-cvs.ximian.com> | 2004-09-07 13:40:15 +0400 |
commit | e4da82786db9da5f440430917171ba477275e0fb (patch) | |
tree | 10eb79c5c7c484f0c4e3d7d90029054787db8131 /mcs | |
parent | 6d2121de5586c7abe3716a5190ff3aea0da65e9b (diff) |
LinkLabel fixes, methods, multiple links
svn path=/trunk/mcs/; revision=33483
Diffstat (limited to 'mcs')
4 files changed, 188 insertions, 127 deletions
diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Label.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Label.cs index 09946dd6bf5..6ef893452dc 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Label.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Label.cs @@ -24,9 +24,12 @@ // Peter Bartok, pbartok@novell.com // // -// $Revision: 1.13 $ +// $Revision: 1.14 $ // $Modtime: $ // $Log: Label.cs,v $ +// Revision 1.14 2004/09/07 09:40:15 jordi +// LinkLabel fixes, methods, multiple links +// // Revision 1.13 2004/09/04 17:10:18 jordi // Refresh when font changed // @@ -72,8 +75,7 @@ namespace System.Windows.Forms private ImageList image_list; internal ContentAlignment image_align; internal StringFormat string_format; - internal ContentAlignment text_align; - protected Rectangle paint_area = new Rectangle (); + internal ContentAlignment text_align; static SizeF req_witdthsize = new SizeF (0,0); #region Events @@ -443,6 +445,7 @@ namespace System.Windows.Forms { base.OnFontChanged (e); CalcPreferredHeight (); + Refresh (); } @@ -552,14 +555,11 @@ namespace System.Windows.Forms } internal void Draw () - { - paint_area.Width = Width; - paint_area.Height = Height; - - ThemeEngine.Current.DrawLabel (DeviceContext, paint_area, BorderStyle, Text, + { + ThemeEngine.Current.DrawLabel (DeviceContext, ClientRectangle, BorderStyle, Text, ForeColor, BackColor, Font, string_format, Enabled); - DrawImage (DeviceContext, Image, paint_area, image_align); + DrawImage (DeviceContext, Image, ClientRectangle, image_align); } private void OnHandleCreatedLB (Object o, EventArgs e) diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LinkLabel.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LinkLabel.cs index eeb6b5e38e7..ad1d9b1661d 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LinkLabel.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LinkLabel.cs @@ -28,11 +28,14 @@ // // TODO: // - Change the cursor to a hand cursor when you are over a link (when cursors are available) +// - Focus handeling // -// -// $Revision: 1.7 $ +// $Revision: 1.8 $ // $Modtime: $ // $Log: LinkLabel.cs,v $ +// Revision 1.8 2004/09/07 09:40:15 jordi +// LinkLabel fixes, methods, multiple links +// // Revision 1.7 2004/08/21 22:32:14 pbartok // - Signature Fixes // @@ -75,11 +78,13 @@ namespace System.Windows.Forms public int end; public LinkLabel.Link link; // Empty link indicates regular text public RectangleF rect; + public bool clicked; public Piece () { start = end = 0; link = null; + clicked = false; } } @@ -94,6 +99,8 @@ namespace System.Windows.Forms private Font link_font; private bool link_click; private Piece[] pieces; + private Cursor override_cursor; + private DialogResult dialog_result; #region Events public event LinkLabelLinkClickedEventHandler LinkClicked; @@ -101,13 +108,13 @@ namespace System.Windows.Forms public LinkLabel () { - link_area = new LinkArea (); - link_behavior = LinkBehavior.SystemDefault; link_collection = new LinkCollection (this); + LinkArea = new LinkArea (0, -1); + link_behavior = LinkBehavior.SystemDefault; link_visited = false; link_click = false; pieces = null; - + ActiveLinkColor = Color.Red; DisabledLinkColor = ThemeEngine.Current.ColorGrayText; LinkColor = Color.FromArgb (255, 0, 0, 255); @@ -163,10 +170,14 @@ namespace System.Windows.Forms public LinkArea LinkArea { get { return link_area;} - set { - if (value.Start <0 || value.Length >0) - throw new ArgumentException(); - + set { + + if (value.Start <0 || value.Length > 0) + throw new ArgumentException (); + + if (!value.IsEmpty) + Links.Add (value.Start, value.Length); + link_area = value; Refresh (); } @@ -186,7 +197,6 @@ namespace System.Windows.Forms public LinkLabel.LinkCollection Links { get { return link_collection;} - set { link_collection = value;} } public bool LinkVisited { @@ -199,7 +209,11 @@ namespace System.Windows.Forms Refresh (); } } - +
+ protected Cursor OverrideCursor { + get { return override_cursor;} + set { override_cursor = value;} + } public override string Text { get { return base.Text; } @@ -214,35 +228,32 @@ namespace System.Windows.Forms #endregion // Public Properties - [MonoTODO] DialogResult IButtonControl.DialogResult { - get { throw new NotImplementedException (); } - set { throw new NotImplementedException (); } + get { return dialog_result; } + set { dialog_result = value; } } - [MonoTODO] + void IButtonControl.NotifyDefault (bool value) { - throw new NotImplementedException (); + } - [MonoTODO] void IButtonControl.PerformClick () { throw new NotImplementedException (); } - #region Protected Instance Methods + #region Public Methods protected override AccessibleObject CreateAccessibilityInstance() { return base.CreateAccessibilityInstance(); } protected override void CreateHandle () - { + { CreateLinkFont (); CreateLinkPieces (); - base.CreateHandle(); } @@ -250,15 +261,17 @@ namespace System.Windows.Forms protected override void OnEnabledChanged (EventArgs e) { base.OnEnabledChanged (e); + Refresh (); } protected override void OnFontChanged (EventArgs e) { base.OnFontChanged (e); CreateLinkFont (); + Refresh (); } - protected override void OnGotFocus( EventArgs e) + protected override void OnGotFocus (EventArgs e) { base.OnGotFocus(e); } @@ -267,6 +280,12 @@ namespace System.Windows.Forms { base.OnKeyDown(e); } +
+ protected virtual void OnLinkClicked (LinkLabelLinkClickedEventArgs e) + { + if (LinkClicked != null) + LinkClicked (this, e); + } protected override void OnLostFocus (EventArgs e) { @@ -278,21 +297,15 @@ namespace System.Windows.Forms if (!Enabled) return; base.OnMouseDown(e); - Point pnt = new Point (e.X, e.Y); + this.Capture = true; - if (Links.Count == 0) { - if (paint_area.Contains (pnt)) { - link_click = true; - Refresh (); - } - } - else { - for (int i = 0; i < pieces.Length; i++) { - if (pieces[i].rect.Contains (pnt)) { - link_click = true; + for (int i = 0; i < pieces.Length; i++) { + if (pieces[i].rect.Contains (e.X, e.Y)) { + if (pieces[i].link!= null) { + pieces[i].clicked = true; Refresh (); - break; } + break; } } } @@ -314,74 +327,105 @@ namespace System.Windows.Forms if (!Enabled) return; base.OnMouseUp (e); - Point pnt = new Point (e.X, e.Y); + this.Capture = false; - if (Links.Count == 0) { - if (paint_area.Contains (pnt)) { - link_click = false; + for (int i = 0; i < pieces.Length; i++) { + if (pieces[i].link!= null && pieces[i].clicked == true) { if (LinkClicked != null) - LinkClicked (this, new LinkLabelLinkClickedEventArgs (new Link ())); + LinkClicked (this, new LinkLabelLinkClickedEventArgs (pieces[i].link)); + pieces[i].clicked = false; Refresh (); } } - else { - for (int i = 0; i < pieces.Length; i++) { - if (pieces[i].rect.Contains (pnt)) { - link_click = false; + } - if ((LinkClicked != null) && (pieces[i].link != null)) - LinkClicked (this, new LinkLabelLinkClickedEventArgs (pieces[i].link)); + protected override void OnPaint (PaintEventArgs pevent) + { + if (Width <= 0 || Height <= 0 || Visible == false) + return; - Refresh (); - break; - } - } - } + Draw (); + pevent.Graphics.DrawImage (ImageBuffer, 0, 0); + } - if (paint_area.Contains (new Point (e.X, e.Y))) { + protected override void OnPaintBackground(PaintEventArgs e) + { + } - link_click = false; - Refresh (); - } + protected override void OnTextAlignChanged (EventArgs e) + { + base.OnTextAlignChanged (e); + Refresh (); } - protected override void OnPaint (PaintEventArgs e) + protected override void OnTextChanged (EventArgs e) { - base.OnPaint (e); + base.OnTextChanged (e); + Refresh (); } +
+ protected Link PointInLink (int x, int y) + { + for (int i = 0; i < pieces.Length; i++) { + if (pieces[i].rect.Contains (x,y) && pieces[i].link != null) + return pieces[i].link; + } - protected override void OnPaintBackground(PaintEventArgs e) + return null; + } + + protected override bool ProcessDialogKey (Keys keyData) { - base.OnPaint (e); + return base.ProcessDialogKey (keyData); } - protected override void OnTextAlignChanged (EventArgs e) + protected override void Select (bool directed, bool forward) { - base.OnTabIndexChanged(e); + base.Select (directed, forward); } - protected override void OnTextChanged (EventArgs e) + public void Select () { - base.OnTabIndexChanged(e); + base.Select (); } - #endregion // Protected instance methods - - internal void CreateLinkPieces () +
+ protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified) { - //Console.WriteLine ("CreateLinkPieces:" + Links.Count); + base.SetBoundsCore (x, y, width, height, specified); + Refresh (); + } + protected override void WndProc (ref Message m) + { + base.WndProc (ref m); + } + + #endregion //Public Methods + + #region Private Methods + + internal void CreateLinkPieces () + { if (Links.Count == 0) return; - int num_pieces = (Links.Count * 2) + 1; - pieces = new Piece [num_pieces]; int cur_piece = 0; - //Console.WriteLine ("pieces: " + num_pieces); + if (Links.Count == 1 && Links[0].Start == 0 && Links[0].Length == -1) { + pieces = new Piece [1]; + pieces[cur_piece] = new Piece(); + pieces[cur_piece].start = 0; + pieces[cur_piece].end = Text.Length; + pieces[cur_piece].link = Links[0]; + pieces[cur_piece].text = Text; + pieces[cur_piece].rect = ClientRectangle; + return; + } + pieces = new Piece [(Links.Count * 2) + 1]; pieces[cur_piece] = new Piece(); pieces[cur_piece].start = 0; @@ -397,14 +441,14 @@ namespace System.Windows.Forms cur_piece++; /* New link*/ - pieces[cur_piece] = new Piece(); + pieces[cur_piece] = new Piece (); } pieces[cur_piece].start = Links[l].Start; pieces[cur_piece].end = Links[l].Start + Links[l].Length; pieces[cur_piece].link = Links[l]; pieces[cur_piece].text = Text.Substring (pieces[cur_piece].start, - pieces[cur_piece].end - pieces[cur_piece].start); + pieces[cur_piece].end - pieces[cur_piece].start); cur_piece++; /* Push link*/ pieces[cur_piece] = new Piece(); @@ -426,10 +470,14 @@ namespace System.Windows.Forms Region[] charRegions = new Region [pieces.Length]; string_format.SetMeasurableCharacterRanges (charRanges); - charRegions = DeviceContext.MeasureCharacterRanges (Text, Font, paint_area, string_format); - for (int i = 0; i < pieces.Length; i++) + charRegions = DeviceContext.MeasureCharacterRanges (Text, Font, ClientRectangle, string_format); + + for (int i = 0; i < pieces.Length; i++) { + //RectangleF[] f = charRegions[i].GetRegionScans (new Matrix()); pieces[i].rect = charRegions[i].GetBounds (DeviceContext); + Console.WriteLine (pieces[i].rect); + } if (Visible && IsHandleCreated) Refresh (); @@ -438,7 +486,7 @@ namespace System.Windows.Forms /* Check if the links overlap */ internal void CheckLinks () - { + { for (int i = 0; i < Links.Count; i++) { for (int l = 0; l < Links.Count; l++) { if (i==l) continue; @@ -446,42 +494,51 @@ namespace System.Windows.Forms if (((Links[i].Start + Links[i].Length) >= Links[l].Start && Links[i].Start + Links[i].Length <= Links[l].Start + Links[l].Length) || (Links[i].Start >= Links[l].Start && - Links[i].Start <= Links[l].Start + Links[l].Length)) - throw new InvalidOperationException ("Overlapping link regions."); + Links[i].Start <= Links[l].Start + Links[l].Length)) + throw new InvalidOperationException ("Overlapping link regions."); } } } - internal void Draw () + private Color GetLinkColor (Piece piece, int i) { Color color; - if (Visible == false) return; - - if (Enabled == false) + if (Enabled == false || + (piece.link != null && piece.link.Enabled == false)) color = DisabledLinkColor; else - if (link_click == true) + if (piece.clicked == true) color = ActiveLinkColor; else - if (LinkVisited == true) + if ((LinkVisited == true && i == 0) || + (piece.link != null && piece.link.Visited == true)) color = VisitedLinkColor; else color = LinkColor; - if (Links.Count == 0 || pieces == null) { + return color; + } - ThemeEngine.Current.DrawLabel (DeviceContext, paint_area, BorderStyle, Text, - color, BackColor, link_font, string_format, - true /* We paint ourselfs the disabled status*/); + internal void Draw () + { + Color color; + + //dc.FillRectangle (label_br_back_color, area); + ThemeEngine.Current.DrawBorderStyle (DeviceContext, ClientRectangle, BorderStyle); + + if (Links.Count == 1 && Links[0].Start == 0 && Links[0].Length == -1) { - DrawImage (DeviceContext, Image, paint_area, image_align); + color = GetLinkColor (pieces[0], 0); + DeviceContext.DrawString (Text, Font, new SolidBrush (color), + ClientRectangle, string_format); return; } - for (int i = 0; i < pieces.Length; i++) { + color = GetLinkColor (pieces[i], i); + if (pieces[i].link == null) DeviceContext.DrawString (pieces[i].text, Font, new SolidBrush (Color.Black), pieces[i].rect.X, pieces[i].rect.Y, string_format); @@ -490,7 +547,7 @@ namespace System.Windows.Forms pieces[i].rect.X, pieces[i].rect.Y, string_format); } - DrawImage (DeviceContext, Image, paint_area, image_align); + DrawImage (DeviceContext, Image, ClientRectangle, image_align); } private void CreateLinkFont () @@ -499,6 +556,8 @@ namespace System.Windows.Forms Font.Unit); } + #endregion // Private Methods + // // System.Windows.Forms.LinkLabel.Link // @@ -597,6 +656,9 @@ namespace System.Windows.Forms public LinkCollection (LinkLabel owner) { + if (owner==null) + throw new ArgumentNullException (); + this.owner = owner; } @@ -605,7 +667,7 @@ namespace System.Windows.Forms } public bool IsReadOnly { - get { return collection.IsReadOnly; } + get { return false; } } public virtual LinkLabel.Link this[int index] { @@ -625,16 +687,7 @@ namespace System.Windows.Forms public Link Add (int start, int length) { - Link link = new Link (); - int idx; - - link.Length = length; - link.Start = start; - - idx = collection.Add (link); - owner.CheckLinks (); - owner.CreateLinkPieces (); - return (Link)collection[idx]; + return Add (start, length, null); } @@ -643,15 +696,19 @@ namespace System.Windows.Forms Link link = new Link (); int idx; + if (Count == 1 && this[0].Start == 0 + && this[0].Length == -1) { + Console.WriteLine ("Clear list"); + Clear (); + } + link.Length = length; link.Start = start; link.LinkData = o; - idx = collection.Add (link); owner.CheckLinks (); owner.CreateLinkPieces (); - return (Link) collection[idx]; } @@ -661,6 +718,11 @@ namespace System.Windows.Forms owner.CreateLinkPieces (); } + public bool Contains (LinkLabel.Link link) + { + return collection.Contains (link); + } + public IEnumerator GetEnumerator () { return collection.GetEnumerator (); @@ -687,7 +749,7 @@ namespace System.Windows.Forms } bool IList.IsFixedSize { - get {return collection.IsFixedSize;} + get {return false;} } object IList.this[int index] { @@ -695,26 +757,19 @@ namespace System.Windows.Forms set { collection[index] = value; } } - object ICollection.SyncRoot { - [MonoTODO] get { - throw new NotImplementedException (); - } + get {return this;} } bool ICollection.IsSynchronized { - [MonoTODO] get { - throw new NotImplementedException (); - } + get {return false;} } - [MonoTODO] - void ICollection.CopyTo (Array dest,int index) + void ICollection.CopyTo (Array dest, int index) { - throw new NotImplementedException (); + collection.CopyTo (dest, index); } - int IList.Add (object control) { return collection.Add (control); @@ -741,5 +796,4 @@ namespace System.Windows.Forms } } } - } diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs index feba4ffd189..5ba9e24a2f0 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs @@ -23,9 +23,12 @@ // Jordi Mas i Hernandez, jordi@ximian.com // // -// $Revision: 1.6 $ +// $Revision: 1.7 $ // $Modtime: $ // $Log: Theme.cs,v $ +// Revision 1.7 2004/09/07 09:40:15 jordi +// LinkLabel fixes, methods, multiple links +// // Revision 1.6 2004/09/02 16:32:54 jordi // implements resource pool for pens, brushes, and hatchbruses // @@ -310,6 +313,8 @@ namespace System.Windows.Forms public abstract void DrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format); + + public abstract void DrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style); /* Methods that draw complete controls diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs index 10eadd481fa..719fd07fd8c 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs @@ -25,9 +25,12 @@ // // // -// $Revision: 1.33 $ +// $Revision: 1.34 $ // $Modtime: $ // $Log: ThemeWin32Classic.cs,v $ +// Revision 1.34 2004/09/07 09:40:15 jordi +// LinkLabel fixes, methods, multiple links +// // Revision 1.33 2004/09/05 08:03:51 jordi // fixes bugs, adds flashing on certain situations // @@ -2425,9 +2428,8 @@ namespace System.Windows.Forms area.Y + 2, area.Width - 4, area.Height - 4); } - - private void DrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) + public override void DrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) { switch (border_style){ case BorderStyle.Fixed3D: |