Merge pull request #1345 from mattleibow/websocket-continuation-frame-fix
[mono.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / ThreadExceptionDialog.cs
1 //
2 // System.Windows.Forms.ThreadExceptionDialog.cs
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Authors:
24 //              Marek Safar     marek.safar@seznam.cz
25 //
26 // Copyright (C) Novell Inc., 2004
27
28 // COMPLETE - BUT DISABLED TEXTBOX
29
30 using System;
31 using System.Drawing;
32 using System.Text;
33 using System.Reflection;
34 using System.ComponentModel;
35 using System.Runtime.InteropServices;
36
37 namespace System.Windows.Forms
38 {
39         [ComVisible (true)]
40         [ClassInterface (ClassInterfaceType.AutoDispatch)]
41         public class ThreadExceptionDialog: Form
42         {
43                 Exception e;
44                 bool details;
45
46                 private System.Windows.Forms.Button buttonIgnore;
47                 private System.Windows.Forms.Button buttonAbort;
48                 private System.Windows.Forms.Button buttonDetails;
49                 private System.Windows.Forms.Label labelException;
50                 private System.Windows.Forms.Label label1;
51                 private System.Windows.Forms.TextBox textBoxDetails;
52                 private System.Windows.Forms.Label helpText;
53
54                 private void InitializeComponent()
55                 {
56                         this.helpText = new System.Windows.Forms.Label();
57                         this.buttonAbort = new System.Windows.Forms.Button();
58                         this.buttonIgnore = new System.Windows.Forms.Button();
59                         this.buttonDetails = new System.Windows.Forms.Button();
60                         this.labelException = new System.Windows.Forms.Label();
61                         this.textBoxDetails = new System.Windows.Forms.TextBox();
62                         this.label1 = new System.Windows.Forms.Label();
63                         this.SuspendLayout();
64                         // 
65                         // helpText
66                         // 
67                         this.helpText.Location = new System.Drawing.Point(60, 8);
68                         this.helpText.Name = "helpText";
69                         this.helpText.Size = new System.Drawing.Size(356, 40);
70                         this.helpText.TabIndex = 0;
71                         this.helpText.Text = "An unhandled exception has occurred in you application. If you click Ignore the a" +
72                                 "pplication will ignore this error and attempt to continue. If you click Abort, t" +
73                                 "he application will quit immediately.";
74                         // 
75                         // buttonAbort
76                         // 
77                         this.buttonAbort.DialogResult = System.Windows.Forms.DialogResult.Abort;
78                         this.buttonAbort.Location = new System.Drawing.Point(332, 112);
79                         this.buttonAbort.Name = "buttonAbort";
80                         this.buttonAbort.Size = new System.Drawing.Size(85, 23);
81                         this.buttonAbort.TabIndex = 4;
82                         this.buttonAbort.Text = "&Abort";
83                         this.buttonAbort.Click += new System.EventHandler(this.buttonAbort_Click);
84                         // 
85                         // buttonIgnore
86                         // 
87                         this.buttonIgnore.DialogResult = System.Windows.Forms.DialogResult.Ignore;
88                         this.buttonIgnore.Location = new System.Drawing.Point(236, 112);
89                         this.buttonIgnore.Name = "buttonIgnore";
90                         this.buttonIgnore.Size = new System.Drawing.Size(85, 23);
91                         this.buttonIgnore.TabIndex = 3;
92                         this.buttonIgnore.Text = "&Ignore";
93                         // 
94                         // buttonDetails
95                         // 
96                         this.buttonDetails.Location = new System.Drawing.Point(140, 112);
97                         this.buttonDetails.Name = "buttonDetails";
98                         this.buttonDetails.Size = new System.Drawing.Size(85, 23);
99                         this.buttonDetails.TabIndex = 2;
100                         this.buttonDetails.Text = "Show &Details";
101                         this.buttonDetails.Click += new System.EventHandler(this.buttonDetails_Click);
102                         // 
103                         // labelException
104                         // 
105                         this.labelException.Location = new System.Drawing.Point(60, 64);
106                         this.labelException.Name = "labelException";
107                         this.labelException.Size = new System.Drawing.Size(356, 32);
108                         this.labelException.TabIndex = 1;
109                         // 
110                         // textBoxDetails
111                         // 
112                         this.textBoxDetails.Location = new System.Drawing.Point(8, 168);
113                         this.textBoxDetails.Multiline = true;
114                         this.textBoxDetails.Name = "textBoxDetails";
115                         this.textBoxDetails.ReadOnly = true;
116                         this.textBoxDetails.ScrollBars = System.Windows.Forms.ScrollBars.Both;
117                         this.textBoxDetails.Size = new System.Drawing.Size(408, 196);
118                         this.textBoxDetails.TabIndex = 5;
119                         this.textBoxDetails.TabStop = false;
120                         this.textBoxDetails.Text = "";
121                         this.textBoxDetails.WordWrap = false;
122                         // 
123                         // label1
124                         // 
125                         this.label1.Location = new System.Drawing.Point(8, 148);
126                         this.label1.Name = "label1";
127                         this.label1.Size = new System.Drawing.Size(100, 16);
128                         this.label1.TabIndex = 0;
129                         this.label1.Text = "Exception details";
130                         // 
131                         // ThreadExceptionDialog
132                         // 
133                         this.AcceptButton = this.buttonIgnore;
134                         this.CancelButton = this.buttonAbort;
135                         this.ClientSize = new System.Drawing.Size(428, 374);
136                         this.Controls.Add(this.label1);
137                         this.Controls.Add(this.textBoxDetails);
138                         this.Controls.Add(this.labelException);
139                         this.Controls.Add(this.buttonDetails);
140                         this.Controls.Add(this.buttonIgnore);
141                         this.Controls.Add(this.buttonAbort);
142                         this.Controls.Add(this.helpText);
143                         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
144                         this.MaximizeBox = false;
145                         this.MinimizeBox = false;
146                         this.Name = "ThreadExceptionDialog";
147                         this.ShowInTaskbar = false;
148                         this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
149                         this.TopMost = true;
150                         this.Paint += new PaintEventHandler (PaintHandler);
151                         this.ResumeLayout(false);
152                 }
153         
154                 public ThreadExceptionDialog (Exception t)
155                 {
156                         this.e = t;
157                         InitializeComponent ();
158
159                         this.labelException.Text = t.Message;
160                         if (Form.ActiveForm != null)
161                                 this.Text = Form.ActiveForm.Text;
162                         else
163                                 this.Text = "Mono";
164                         this.buttonAbort.Enabled = Application.AllowQuit;
165                         RefreshDetails ();
166                         FillExceptionDetails ();
167                 }
168
169                 void buttonDetails_Click(object sender, System.EventArgs e)
170                 {
171                         details = !details;
172                         RefreshDetails ();
173                 }
174
175                 void FillExceptionDetails ()
176                 {
177                         StringBuilder sb = new StringBuilder ();
178                         sb.Append (e.ToString ());
179                         sb.Append (Environment.NewLine + Environment.NewLine);
180                         sb.Append ("Loaded assemblies:" + Environment.NewLine + Environment.NewLine);
181
182                         foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
183                                 AssemblyName an = a.GetName ();
184                                 sb.AppendFormat ("Name:\t{0}" + Environment.NewLine, an.Name);
185                                 sb.AppendFormat ("Version:\t{0}" + Environment.NewLine, an.Version);
186                                 sb.AppendFormat ("Location:\t{0}" + Environment.NewLine, an.CodeBase);
187                                 sb.Append (Environment.NewLine);
188                         }
189                         textBoxDetails.Text = sb.ToString ();
190                 }
191
192                 void RefreshDetails ()
193                 {
194                         if (details) {
195                                 buttonDetails.Text = "Hide &Details";
196                                 Height = 410;
197                                 label1.Visible = true;
198                                 textBoxDetails.Visible = true;
199                                 return;
200                         }
201                         buttonDetails.Text = "Show &Details";
202                         label1.Visible = false;
203                         textBoxDetails.Visible = false;
204                         Height = 180;
205                 }
206
207                 void buttonAbort_Click(object sender, System.EventArgs e)
208                 {
209                         Application.Exit ();
210                 }
211
212                 void PaintHandler (object o, PaintEventArgs args)
213                 {
214                         Graphics g = args.Graphics;
215                         g.DrawIcon (SystemIcons.Error, 15, 10);
216                 }
217
218                 [Browsable (false)]
219                 [EditorBrowsable (EditorBrowsableState.Never)]
220                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
221                 public override bool AutoSize {
222                         get { return base.AutoSize; }
223                         set { base.AutoSize = value; }
224                 }
225
226                 [Browsable (false)]
227                 [EditorBrowsable (EditorBrowsableState.Never)]
228                 public new event EventHandler AutoSizeChanged {
229                         add { base.AutoSizeChanged += value; }
230                         remove { base.AutoSizeChanged -= value; }
231                 }
232         }
233 }