[Mono-winforms-list] Bug in System.Windows.Forms.Control:get_ContainsFocus ()?

2006-06-21 Thread Paddy Joy

Hi,

I'm porting an application from MS. NET to Mono and I have encountered 
the following, maybe it's a bug or maybe it's just bad coding :-)  

The attached code sends Mono into a loop until it eventually crashes 
with a segmentation error (When button1 is clicked). Should I report 
this as a bug or is this just dodgy code to override the get_Focused 
method like this?


Compile with:

mcs base.cs -r:System.Windows.Forms -r:System.Data -r:System.Drawing

run mono base.exe

Click on button1.

Code and trace attached.

Thanks,
Paddy
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication4
{
	/// summary
	/// Summary description for Form1.
	/// /summary
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		/// summary
		/// Required designer variable.
		/// /summary
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// summary
		/// Clean up any resources being used.
		/// /summary
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
if (components != null) 
{
	components.Dispose();
}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// summary
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// /summary
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new testbutton();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(96, 32);
			this.button1.Name = button1;
			this.button1.TabIndex = 0;
			this.button1.Text = button1;
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(96, 80);
			this.button2.Name = button2;
			this.button2.TabIndex = 1;
			this.button2.Text = button2;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 262);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Name = Form1;
			this.Text = Form1;
			this.ResumeLayout(false);

		}
		#endregion

		/// summary
		/// The main entry point for the application.
		/// /summary
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			Console.Write(button2.Focused);
		}
	}

	public class testbutton : System.Windows.Forms.Button 
	{
		
		public testbutton()
		{


		}

		public override bool Focused
		{
			get
			{
return base.ContainsFocus;
			}
		}
 


	}
}


. . . . . . . . . . . . . . . . . . . . . . . . . . ENTER: 
System.Windows.Forms.Button:OnClick 
(System.EventArgs)(this:0x5c2a8[System.Windows.Forms.Button WindowsForm.exe], 
[System.EventArgs:0x2ff68], )
. . . . . . . . . . . . . . . . . . . . . . . . . . . ENTER: 
System.Windows.Forms.Control:OnClick 
(System.EventArgs)(this:0x5c2a8[System.Windows.Forms.Button WindowsForm.exe], 
[System.EventArgs:0x2ff68], )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . ENTER: (wrapper 
delegate-invoke) System.MulticastDelegate:invoke_void_object_EventArgs 
(object,System.EventArgs)(this:0x4c5a0[System.EventHandler WindowsForm.exe], 
[System.Windows.Forms.Button:0x5c2a8], [System.EventArgs:0x2ff68], )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . ENTER: 
WindowsApplication4.Form1:button1_Click 
(object,System.EventArgs)(this:0x3[WindowsApplication4.Form1 
WindowsForm.exe], [System.Windows.Forms.Button:0x5c2a8], 
[System.EventArgs:0x2ff68], )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ENTER: 
WindowsApplication4.testbutton:get_Focused 
()(this:0x5c000[WindowsApplication4.testbutton WindowsForm.exe], )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ENTER: 
System.Windows.Forms.Control:get_ContainsFocus 
()(this:0x5c000[WindowsApplication4.testbutton WindowsForm.exe], )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ENTER: 
WindowsApplication4.testbutton:get_Focused 
()(this:0x5c000[WindowsApplication4.testbutton WindowsForm.exe], )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ENTER: 
System.Windows.Forms.Control:get_ContainsFocus 
()(this:0x5c000[WindowsApplication4.testbutton WindowsForm.exe], )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ENTER: 
WindowsApplication4.testbutton:get_Focused 
()(this:0x5c000[WindowsApplication4.testbutton WindowsForm.exe], )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 

Re: [Mono-winforms-list] Bug in System.Windows.Forms.Control:get_ContainsFocus ()?

2006-06-21 Thread PFJ
Hi,

 So do you think it could be a bug with resolving the base class? It 
 seems from the trace that it is going into a continuous loop, like it is 
 calling ContainsFocus on itself.

To be honest, all I saw was the segfault rather than the tonnes of
output. The baseclass seems to be working fine as well

I did the following to your code and if you run it, you'll see that the
baseclass is fine

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WinApp4
{
  public class Form1 : System.Windows.Forms.Form
  {
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.ComponentModel.Container components = null;

public Form1()
{
  InitializeComponent();
}

protected override void Dispose(bool disposing)
{
  if (disposing)
  {
if (components != null)
{
  components.Dispose();
}
  }
  base.Dispose(disposing);
}

private void InitializeComponent()
{
  this.button1 = new System.Windows.Forms.Button();
  this.button2 = new System.Windows.Forms.Button();
  this.SuspendLayout();

  this.button1.Location = new System.Drawing.Point(96, 32);
  this.button1.Name = button1;
  this.button1.TabIndex = 0;
  this.button1.Text = button1;
  this.button1.Click += new System.EventHandler(this.button1_Click);

  this.button2.Location = new System.Drawing.Point(96, 80);
  this.button2.Name = button2;
  this.button2.TabIndex = 1;
  this.button2.Text = button2;
  this.button2.Click += new System.EventHandler(this.button2_Click);

  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  this.ClientSize = new System.Drawing.Size(292, 262);
  this.Controls.Add(this.button2);
  this.Controls.Add(this.button1);
  this.Name = Form1;
  this.Text = Form1;
  this.ResumeLayout(false);
}

[STAThread]
static void Main()
{
  Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
  Console.Write(base.ContainsFocus);
}

private void button2_Click(object sender, System.EventArgs e)
{
  Console.WriteLine(base.ContainsFocus);
}
  }
}

The output (at least on my box) is

True (button 1 pressed - no return feed)
TrueTrue (button 2 pressed)

From the looks of the original code, you've created the second button,
but never properly instantated it (it is declared as private swf.button
button2 at the start, but never created using this.button2 = new
swf.button()). That (to me) is the most likely candidate for the
breakage.

TTFN

Paul

-- 
Logic, my dear Zoe, is merely the ability to be wrong with authority -
Dr Who

___
Mono-winforms-list maillist  -  Mono-winforms-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list


Re: [Mono-winforms-list] Bug in System.Windows.Forms.Control:get_ContainsFocus ()?

2006-06-21 Thread Paddy Joy
How about this code, I'm pretty sure that it instantiates button2 
correctly now but still gives the segmentation error.

I have declared the button with:
private testbutton button2;

and instantiated it with:
this.button2 = new testbutton();

Thanks for the help,
Paddy


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication4
{
/// summary
/// Summary description for Form1.
/// /summary
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private testbutton button2;
/// summary
/// Required designer variable.
/// /summary
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// summary
/// Clean up any resources being used.
/// /summary
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// summary
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// /summary
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new testbutton();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(96, 32);
this.button1.Name = button1;
this.button1.TabIndex = 0;
this.button1.Text = button1;
this.button1.Click += new 
System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(96, 80);
this.button2.Name = button2;
this.button2.TabIndex = 1;
this.button2.Text = button2;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 262);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = Form1;
this.Text = Form1;
this.ResumeLayout(false);

}
#endregion

/// summary
/// The main entry point for the application.
/// /summary
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
Console.Write(button2.Focused);
}
}

public class testbutton : System.Windows.Forms.Button
{

public testbutton()
{


}

public override bool Focused
{
get
{
return base.ContainsFocus;
}
}
 


}
}

 
 Hi,

   
 So do you think it could be a bug with resolving the base class? It 
 seems from the trace that it is going into a continuous loop, like it is 
 calling ContainsFocus on itself.
 

 To be honest, all I saw was the segfault rather than the tonnes of
 output. The baseclass seems to be working fine as well

 I did the following to your code and if you run it, you'll see that the
 baseclass is fine

 using System;
 using System.Drawing;
 using System.Collections;
 using System.ComponentModel;
 using System.Windows.Forms;
 using System.Data;

 namespace WinApp4
 {
   public class Form1 : System.Windows.Forms.Form
   {
 private System.Windows.Forms.Button button1;
 private System.Windows.Forms.Button button2;
 private System.ComponentModel.Container components = null;

 public Form1()
 {
   InitializeComponent();
 }

 protected override void Dispose(bool disposing)
 {
   if (disposing)
   {
 if (components != null)
 {
   components.Dispose();
   }
   }
   base.Dispose(disposing);
 }

 private void InitializeComponent()
 {
   this.button1 = new System.Windows.Forms.Button();
   this.button2 = new System.Windows.Forms.Button();
   this.SuspendLayout();

   this.button1.Location = new System.Drawing.Point(96, 32);
   this.button1.Name = button1;
   this.button1.TabIndex = 0;
   this.button1.Text = button1;
   this.button1.Click += new 

Re: [Mono-winforms-list] Bug in System.Windows.Forms.Control:get_ContainsFocus ()?

2006-06-21 Thread Rafael Teixeira
Hi Paddy,

Why do you return base.ContainFocus instead of base.Focused from your
overriden Focused? That way you are introducing infinite recursion as
Control.ContainsFocus calls Control.Focused, that in your case is
overriden.

In truth, unless this is just some small code to show the problem, I
don't see any need to override Focused... Even more to change its
semantics.

Anyway if that code works in MS.NET, we should not rely on Focused to
determine partially the value of ContainsFocus (ContainsFocus also
checks children if the Control per se isn't with focus). Test it in
MS.NEt and if it works OK, please fill a bug for MWF, thanks.

:|

On 6/21/06, Paddy Joy [EMAIL PROTECTED] wrote:
 How about this code, I'm pretty sure that it instantiates button2
 correctly now but still gives the segmentation error.

 I have declared the button with:
 private testbutton button2;

 and instantiated it with:
 this.button2 = new testbutton();

 Thanks for the help,
 Paddy


 using System;
 using System.Drawing;
 using System.Collections;
 using System.ComponentModel;
 using System.Windows.Forms;
 using System.Data;

 namespace WindowsApplication4
 {
 /// summary
 /// Summary description for Form1.
 /// /summary
 public class Form1 : System.Windows.Forms.Form
 {
 private System.Windows.Forms.Button button1;
 private testbutton button2;
 /// summary
 /// Required designer variable.
 /// /summary
 private System.ComponentModel.Container components = null;

 public Form1()
 {
 //
 // Required for Windows Form Designer support
 //
 InitializeComponent();

 //
 // TODO: Add any constructor code after InitializeComponent call
 //
 }

 /// summary
 /// Clean up any resources being used.
 /// /summary
 protected override void Dispose( bool disposing )
 {
 if( disposing )
 {
 if (components != null)
 {
 components.Dispose();
 }
 }
 base.Dispose( disposing );
 }

 #region Windows Form Designer generated code
 /// summary
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// /summary
 private void InitializeComponent()
 {
 this.button1 = new System.Windows.Forms.Button();
 this.button2 = new testbutton();
 this.SuspendLayout();
 //
 // button1
 //
 this.button1.Location = new System.Drawing.Point(96, 32);
 this.button1.Name = button1;
 this.button1.TabIndex = 0;
 this.button1.Text = button1;
 this.button1.Click += new
 System.EventHandler(this.button1_Click);
 //
 // button2
 //
 this.button2.Location = new System.Drawing.Point(96, 80);
 this.button2.Name = button2;
 this.button2.TabIndex = 1;
 this.button2.Text = button2;
 //
 // Form1
 //
 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
 this.ClientSize = new System.Drawing.Size(292, 262);
 this.Controls.Add(this.button2);
 this.Controls.Add(this.button1);
 this.Name = Form1;
 this.Text = Form1;
 this.ResumeLayout(false);

 }
 #endregion

 /// summary
 /// The main entry point for the application.
 /// /summary
 [STAThread]
 static void Main()
 {
 Application.Run(new Form1());
 }

 private void button1_Click(object sender, System.EventArgs e)
 {
 Console.Write(button2.Focused);
 }
 }

 public class testbutton : System.Windows.Forms.Button
 {

 public testbutton()
 {


 }

 public override bool Focused
 {
 get
 {
 return base.ContainsFocus;
 }
 }



 }
 }


  Hi,
 
 
  So do you think it could be a bug with resolving the base class? It
  seems from the trace that it is going into a continuous loop, like it is
  calling ContainsFocus on itself.
 
 
  To be honest, all I saw was the segfault rather than the tonnes of
  output. The baseclass seems to be working fine as well
 
  I did the following to your code and if you run it, you'll see that the
  baseclass is fine
 
  using System;
  using System.Drawing;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;
 
  namespace WinApp4
  {
public class Form1 : System.Windows.Forms.Form
{
  private System.Windows.Forms.Button button1;
  private 

Re: [Mono-winforms-list] Bug in System.Windows.Forms.Control:get_ContainsFocus ()?

2006-06-21 Thread Paddy Joy
Hi Rafael,

Yes this problem exists in a much larger application involving lots of 
custom controls, I have just created this code to demonstrate the 
problem as simply as possible.

I have tested the code in MS .NET and it works ok and returns False to 
the console as expected so I have logged a bug 
http://bugzilla.ximian.com/show_bug.cgi?id=78685

Thanks for your help,
Paddy


Rafael Teixeira wrote:
 Hi Paddy,

 Why do you return base.ContainFocus instead of base.Focused from your
 overriden Focused? That way you are introducing infinite recursion as
 Control.ContainsFocus calls Control.Focused, that in your case is
 overriden.

 In truth, unless this is just some small code to show the problem, I
 don't see any need to override Focused... Even more to change its
 semantics.

 Anyway if that code works in MS.NET, we should not rely on Focused to
 determine partially the value of ContainsFocus (ContainsFocus also
 checks children if the Control per se isn't with focus). Test it in
 MS.NEt and if it works OK, please fill a bug for MWF, thanks.

 :|

 On 6/21/06, Paddy Joy [EMAIL PROTECTED] wrote:
 How about this code, I'm pretty sure that it instantiates button2
 correctly now but still gives the segmentation error.

 I have declared the button with:
 private testbutton button2;

 and instantiated it with:
 this.button2 = new testbutton();

 Thanks for the help,
 Paddy


 using System;
 using System.Drawing;
 using System.Collections;
 using System.ComponentModel;
 using System.Windows.Forms;
 using System.Data;

 namespace WindowsApplication4
 {
 /// summary
 /// Summary description for Form1.
 /// /summary
 public class Form1 : System.Windows.Forms.Form
 {
 private System.Windows.Forms.Button button1;
 private testbutton button2;
 /// summary
 /// Required designer variable.
 /// /summary
 private System.ComponentModel.Container components = null;

 public Form1()
 {
 //
 // Required for Windows Form Designer support
 //
 InitializeComponent();

 //
 // TODO: Add any constructor code after 
 InitializeComponent call
 //
 }

 /// summary
 /// Clean up any resources being used.
 /// /summary
 protected override void Dispose( bool disposing )
 {
 if( disposing )
 {
 if (components != null)
 {
 components.Dispose();
 }
 }
 base.Dispose( disposing );
 }

 #region Windows Form Designer generated code
 /// summary
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// /summary
 private void InitializeComponent()
 {
 this.button1 = new System.Windows.Forms.Button();
 this.button2 = new testbutton();
 this.SuspendLayout();
 //
 // button1
 //
 this.button1.Location = new System.Drawing.Point(96, 32);
 this.button1.Name = button1;
 this.button1.TabIndex = 0;
 this.button1.Text = button1;
 this.button1.Click += new
 System.EventHandler(this.button1_Click);
 //
 // button2
 //
 this.button2.Location = new System.Drawing.Point(96, 80);
 this.button2.Name = button2;
 this.button2.TabIndex = 1;
 this.button2.Text = button2;
 //
 // Form1
 //
 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
 this.ClientSize = new System.Drawing.Size(292, 262);
 this.Controls.Add(this.button2);
 this.Controls.Add(this.button1);
 this.Name = Form1;
 this.Text = Form1;
 this.ResumeLayout(false);

 }
 #endregion

 /// summary
 /// The main entry point for the application.
 /// /summary
 [STAThread]
 static void Main()
 {
 Application.Run(new Form1());
 }

 private void button1_Click(object sender, System.EventArgs e)
 {
 Console.Write(button2.Focused);
 }
 }

 public class testbutton : System.Windows.Forms.Button
 {

 public testbutton()
 {


 }

 public override bool Focused
 {
 get
 {
 return base.ContainsFocus;
 }
 }



 }
 }


  Hi,
 
 
  So do you think it could be a bug with resolving the base class? It
  seems from the trace that it is going into a continuous loop, like 
 it is
  calling ContainsFocus on itself.
 
 
  To be honest, all I saw was the segfault rather than the tonnes of
  output. The baseclass