(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Windows.Forms / Gtk / Application.cs
blobe74e41fe3d5f266f528ebbcfedddb780a4aa0366
1 //
2 // System.Windows.Forms.Application
3 //
4 // Author:
5 // Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) 2002 Ximian, Inc
8 //
10 using System;
11 using System.Drawing;
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;
19 using System.IO;
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
41 get{return true;}
45 [MonoTODO]
46 public static string CommonAppDataPath{
47 get{
48 String cadp = Environment.GetFolderPath(
49 Environment.SpecialFolder.CommonApplicationData);
50 if (cadp == "")
51 cadp = Environment.GetFolderPath(
52 Environment.SpecialFolder.ApplicationData);
53 char c = Path.DirectorySeparatorChar;
54 cadp += c + CompanyName + c + ProductName +c + ProductVersion;
55 return cadp;
60 [MonoTODO]
61 public static RegistryKey CommonAppDataRegistry {
62 get{throw new NotImplementedException ();}
65 [MonoTODO]
66 public static string CompanyName{
67 get{
68 Type t = Assembly.GetEntryAssembly().EntryPoint.ReflectedType;
69 String ret1 = (t.Namespace == "") ?
70 t.Name :
71 t.Namespace.Substring (0,t.Namespace.IndexOf('.'));
73 try{
74 AssemblyCompanyAttribute[] attrs =(AssemblyCompanyAttribute[]) Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute),true);
75 if ((attrs != null) && (attrs[0] != null))
76 return attrs[0].Company;
78 catch (Exception){
81 return ret1;
86 [MonoTODO]
87 public static CultureInfo CurrentCulture
89 get{ return CultureInfo.CurrentCulture; }
90 set{ Thread.CurrentThread.CurrentCulture = value; }
93 [MonoTODO]
94 public static InputLanguage CurrentInputLanguage {
95 get { throw new NotImplementedException (); }
96 set {return;}
99 [MonoTODO]
100 public static string ExecutablePath{
101 get { return Assembly.GetExecutingAssembly().Location; }
104 [MonoTODO]
105 public static string LocalUserAppDataPath {
106 get{
107 String cadp = Environment.GetFolderPath(
108 Environment.SpecialFolder.LocalApplicationData);
109 if (cadp == "")
110 cadp = Environment.GetFolderPath(
111 Environment.SpecialFolder.ApplicationData);
112 char c = Path.DirectorySeparatorChar;
113 cadp += c + CompanyName + c + ProductName +c + ProductVersion;
114 return cadp;
118 public static bool MessageLoop{
119 get {return messageLoopStarted;}
124 [MonoTODO]
125 public static string ProductName{
126 get{
128 Type t = Assembly.GetEntryAssembly().EntryPoint.ReflectedType;
129 String ret1 = (t.Namespace == "") ?
130 t.Name :
131 t.Namespace.Substring (t.Namespace.LastIndexOf('.')+1);
133 try{
134 AssemblyProductAttribute[] attrs =(AssemblyProductAttribute[]) Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute),true);
135 if (attrs != null && attrs[0] != null)
136 return attrs[0].Product;
138 catch (Exception){
140 return ret1;
144 [MonoTODO]
145 public static string ProductVersion{
146 get {
147 return Assembly.GetEntryAssembly().GetName().Version.ToString();
151 [MonoTODO]
152 public static string SafeTopLevelCaptionFormat{
153 get{return safeTopLevelCaptionFormat;}
154 set{safeTopLevelCaptionFormat = value;}
157 [MonoTODO]
158 public static string StartupPath {
159 get{
160 String exe = Assembly.GetEntryAssembly().GetName().CodeBase;
161 //Remove "file://"
162 exe = exe.Substring (7);
163 return new FileInfo(exe).DirectoryName;
167 [MonoTODO]
168 public static string UserAppDataPath{
169 get{
170 String cadp = Environment.GetFolderPath(
171 Environment.SpecialFolder.ApplicationData);
172 char c = Path.DirectorySeparatorChar;
173 cadp += c + CompanyName + c + ProductName +c + ProductVersion;
174 return cadp;
178 [MonoTODO]
179 // Registry key not yet defined
180 public static RegistryKey UserAppDataRegistry {
181 get { throw new NotImplementedException (); }
183 // --- Methods ---
184 public static void AddMessageFilter (IMessageFilter value) {
185 messageFilters.Add (value);
188 //Compact Framework
189 public static void DoEvents (){
190 while (Gtk.Application.EventsPending())
191 Gtk.Application.RunIteration();
193 [MonoTODO]
194 //.NET version 1.1
195 public static void EnableVisualStyles (){
196 return;
199 //Compact Framework
200 [MonoTODO]
201 public static void Exit () {
202 DoEvents();
203 Gtk.Application.Quit();
204 System.Environment.Exit(0);
207 public static void ExitThread (){
208 messageLoopStopRequest = true;
211 [MonoTODO]
212 public static ApartmentState OleRequired (){
213 throw new NotImplementedException ();
216 [MonoTODO]
217 public static void OnThreadException (Exception t){
219 if(Application.ThreadException != null)
220 Application.ThreadException(null, new ThreadExceptionEventArgs(t));
221 else{
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 );
279 Run();
282 //[TypeAttributes.BeforeFieldInit]
283 [MonoTODO]
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);
288 Run (context);
291 public static void Run(){
292 messageLoopStarted = true;
293 Gtk.Application.Run();
297 [MonoTODO]
298 static private void ApplicationFormClosed (object o, EventArgs args){
299 Exit();
302 // --- Events ---
303 public static event EventHandler ApplicationExit;
304 public static event EventHandler Idle;
305 public static event ThreadExceptionEventHandler ThreadException;
306 public static event EventHandler ThreadExit;