2 // System.Windows.Forms.Application
5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) 2002 Ximian, Inc
12 using Microsoft
.Win32
;
13 using System
.ComponentModel
;
14 using System
.Threading
;
15 using System
.Globalization
;
16 using System
.Reflection
;
17 using System
.Collections
;
18 using System
.Runtime
.CompilerServices
;
21 namespace System
.Windows
.Forms
24 public sealed class Application
26 static private ApplicationContext applicationContext
= null;
27 static private bool messageLoopStarted
= false;
28 static private bool messageLoopStopRequest
= false;
29 static private ArrayList messageFilters
= new ArrayList ();
30 static private string safeTopLevelCaptionFormat
;
31 static private bool showingException
= false;
33 //For signiture compatablity. Prevents the auto creation of public constructor
34 private Application (){
37 // --- (public) Properties ---
38 public static bool AllowQuit
{
39 // according to docs return false if embbedded in a
40 // browser, not (yet?) embedded in a browser
46 public static string CommonAppDataPath
{
48 String cadp
= Environment
.GetFolderPath(
49 Environment
.SpecialFolder
.CommonApplicationData
);
51 cadp
= Environment
.GetFolderPath(
52 Environment
.SpecialFolder
.ApplicationData
);
53 char c
= Path
.DirectorySeparatorChar
;
54 cadp
+= c
+ CompanyName
+ c
+ ProductName
+c
+ ProductVersion
;
61 public static RegistryKey CommonAppDataRegistry
{
62 get{throw new NotImplementedException ();}
66 public static string CompanyName
{
68 Type t
= Assembly
.GetEntryAssembly().EntryPoint
.ReflectedType
;
69 String ret1
= (t
.Namespace
== "") ?
71 t
.Namespace
.Substring (0,t
.Namespace
.IndexOf('.'));
74 AssemblyCompanyAttribute
[] attrs
=(AssemblyCompanyAttribute
[]) Assembly
.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute
),true);
75 if ((attrs
!= null) && (attrs
[0] != null))
76 return attrs
[0].Company
;
87 public static CultureInfo CurrentCulture
89 get{ return CultureInfo.CurrentCulture; }
90 set{ Thread.CurrentThread.CurrentCulture = value; }
94 public static InputLanguage CurrentInputLanguage
{
95 get { throw new NotImplementedException (); }
100 public static string ExecutablePath
{
101 get { return Assembly.GetExecutingAssembly().Location; }
105 public static string LocalUserAppDataPath
{
107 String cadp
= Environment
.GetFolderPath(
108 Environment
.SpecialFolder
.LocalApplicationData
);
110 cadp
= Environment
.GetFolderPath(
111 Environment
.SpecialFolder
.ApplicationData
);
112 char c
= Path
.DirectorySeparatorChar
;
113 cadp
+= c
+ CompanyName
+ c
+ ProductName
+c
+ ProductVersion
;
118 public static bool MessageLoop
{
119 get {return messageLoopStarted;}
125 public static string ProductName
{
128 Type t
= Assembly
.GetEntryAssembly().EntryPoint
.ReflectedType
;
129 String ret1
= (t
.Namespace
== "") ?
131 t
.Namespace
.Substring (t
.Namespace
.LastIndexOf('.')+1);
134 AssemblyProductAttribute
[] attrs
=(AssemblyProductAttribute
[]) Assembly
.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute
),true);
135 if (attrs
!= null && attrs
[0] != null)
136 return attrs
[0].Product
;
145 public static string ProductVersion
{
147 return Assembly
.GetEntryAssembly().GetName().Version
.ToString();
152 public static string SafeTopLevelCaptionFormat
{
153 get{return safeTopLevelCaptionFormat;}
154 set{safeTopLevelCaptionFormat = value;}
158 public static string StartupPath
{
160 String exe
= Assembly
.GetEntryAssembly().GetName().CodeBase
;
162 exe
= exe
.Substring (7);
163 return new FileInfo(exe
).DirectoryName
;
168 public static string UserAppDataPath
{
170 String cadp
= Environment
.GetFolderPath(
171 Environment
.SpecialFolder
.ApplicationData
);
172 char c
= Path
.DirectorySeparatorChar
;
173 cadp
+= c
+ CompanyName
+ c
+ ProductName
+c
+ ProductVersion
;
179 // Registry key not yet defined
180 public static RegistryKey UserAppDataRegistry
{
181 get { throw new NotImplementedException (); }
184 public static void AddMessageFilter (IMessageFilter
value) {
185 messageFilters
.Add (value);
189 public static void DoEvents (){
190 while (Gtk
.Application
.EventsPending())
191 Gtk
.Application
.RunIteration();
195 public static void EnableVisualStyles (){
201 public static void Exit () {
203 Gtk
.Application
.Quit();
204 System
.Environment
.Exit(0);
207 public static void ExitThread (){
208 messageLoopStopRequest
= true;
212 public static ApartmentState
OleRequired (){
213 throw new NotImplementedException ();
217 public static void OnThreadException (Exception t
){
219 if(Application
.ThreadException
!= null)
220 Application
.ThreadException(null, new ThreadExceptionEventArgs(t
));
222 if (!showingException
) {
224 /*showingException = true;
226 Form excepForm = new Form();
227 excepForm.ClientSize = new System.Drawing.Size(400, 250);
229 TextBox txtLabel = new TextBox();
230 txtLabel.Location = new System.Drawing.Point(30, 30);
231 txtLabel.ReadOnly = true;
232 txtLabel.Multiline = true;
233 txtLabel.Size = new System.Drawing.Size(310, 50);
234 txtLabel.Text = "The application has produced an exception. Press 'Continue' if you want the application to try to continue its execution";
235 excepForm.Controls.Add(txtLabel);
237 TextBox txtError = new TextBox();
238 txtError.Location = new System.Drawing.Point(30, 110);
239 txtError.ReadOnly = true;
240 txtLabel.Multiline = true;
241 txtError.Size = new System.Drawing.Size(310, 50);
242 txtError.Text = t.Message;
243 excepForm.Controls.Add(txtError);
245 StackButton stackbtn = new StackButton(t);
246 stackbtn.Location = new System.Drawing.Point(30, 200);
247 stackbtn.Size = new System.Drawing.Size(100, 30);
248 stackbtn.Text = "Stack Trace";
249 excepForm.Controls.Add(stackbtn);
251 ContinueButton continuebtn = new ContinueButton(excepForm);
252 continuebtn.Location = new System.Drawing.Point(160, 200);
253 continuebtn.Size = new System.Drawing.Size(100, 30);
254 continuebtn.Text = "Continue";
255 excepForm.Controls.Add(continuebtn);
257 QuitButton quitbtn = new QuitButton();
258 quitbtn.Location = new System.Drawing.Point(290, 200);
259 quitbtn.Size = new System.Drawing.Size(100, 30);
260 quitbtn.Text = "Quit";
261 excepForm.Controls.Add(quitbtn);
263 excepForm.ShowDialog();
264 showingException = false;*/
272 public static void RemoveMessageFilter (IMessageFilter
value){
273 messageFilters
.Remove (value);
275 public static void Run (ApplicationContext context
){
276 applicationContext
= context
;
277 applicationContext
.MainForm
.Show ();
278 applicationContext
.ThreadExit
+= new EventHandler( ApplicationFormClosed
);
282 //[TypeAttributes.BeforeFieldInit]
284 public static void Run (Form mainForm
){
285 // Documents say this parameter name should be mainform,
286 // but the verifier says context.
287 ApplicationContext context
= new ApplicationContext (mainForm
);
291 public static void Run(){
292 messageLoopStarted
= true;
293 Gtk
.Application
.Run();
298 static private void ApplicationFormClosed (object o
, EventArgs args
){
303 public static event EventHandler ApplicationExit
;
304 public static event EventHandler Idle
;
305 public static event ThreadExceptionEventHandler ThreadException
;
306 public static event EventHandler ThreadExit
;