**** Merged from MCS ****
[mono-project.git] / mcs / class / Microsoft.VisualBasic / Microsoft.VisualBasic / Interaction.cs
blobb976d1ae2a67997329487a413ba585dac2239e8e
1 //
2 // Interaction.cs
3 //
4 // Author:
5 // Chris J Breisch (cjbreisch@altavista.net)
6 // Joerg Rosenkranz (JoergR@voelcker.com)
7 //
8 // (C) 2002 Chris J Breisch
9 // (C) 2004 Joerg Rosenkranz
13 // Copyright (c) 2002-2003 Mainsoft Corporation.
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
23 //
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
26 //
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System;
37 using System.Reflection;
38 using System.Collections;
39 using System.Diagnostics;
40 using System.Runtime.InteropServices;
41 using Microsoft.VisualBasic.CompilerServices;
43 //using Windows.Drawing;
44 //using System.Windows.Forms;
46 namespace Microsoft.VisualBasic {
47 [StandardModule]
48 [StructLayoutAttribute(LayoutKind.Auto)]
49 sealed public class Interaction {
51 private Interaction (){}
53 // Declarations
54 // Constructors
55 // Properties
56 // Methods
57 //[MonoTODO]
58 public static System.Int32 Shell (System.String Pathname,
59 [Optional, __DefaultArgumentValue(2)] AppWinStyle Style,
60 [Optional, __DefaultArgumentValue(false)] System.Boolean Wait,
61 [Optional, __DefaultArgumentValue(-1)] System.Int32 Timeout)
63 Process prcs = new Process();
65 ProcessWindowStyle PWinStyle = 0;
66 switch (Style){
67 case AppWinStyle.Hide:
68 PWinStyle = ProcessWindowStyle.Hidden;
69 break;
70 case AppWinStyle.NormalFocus:
71 PWinStyle = ProcessWindowStyle.Normal;
72 break;
73 case AppWinStyle.MinimizedFocus:
74 PWinStyle = ProcessWindowStyle.Minimized;
75 break;
76 case AppWinStyle.MaximizedFocus:
77 PWinStyle = ProcessWindowStyle.Maximized;
78 break;
79 case AppWinStyle.NormalNoFocus:
80 PWinStyle = ProcessWindowStyle.Normal; //ToDo: no focus is not set
81 break;
82 case AppWinStyle.MinimizedNoFocus:
83 PWinStyle = ProcessWindowStyle.Minimized; //ToDo: no focus is not set
84 break;
87 prcs.StartInfo.FileName = Pathname;
88 prcs.StartInfo.WindowStyle = PWinStyle;
90 try
92 if(prcs.Start())
94 if (Wait)
96 if (Timeout == -1)
97 prcs.WaitForExit();
98 else
99 prcs.WaitForExit(Timeout);
101 return prcs.Id;
103 else
104 return 0;
106 catch (System.ComponentModel.Win32Exception e){
107 throw new System.IO.FileNotFoundException (
108 Utils.GetResourceString(53));
112 [MonoTODO]
113 public static void AppActivate (System.Int32 ProcessId)
115 throw new NotImplementedException ();
118 [MonoTODO]
119 public static void AppActivate (System.String Title)
121 throw new NotImplementedException ();
124 [MonoTODO]
125 public static System.String InputBox (System.String Prompt,
126 [Optional, __DefaultArgumentValue("")] System.String Title,
127 [Optional, __DefaultArgumentValue("")] System.String DefaultResponse,
128 [Optional, __DefaultArgumentValue(-1)] System.Int32 XPos,
129 [Optional, __DefaultArgumentValue(-1)] System.Int32 YPos)
131 throw new NotImplementedException ();
134 public static System.Object IIf (System.Boolean Expression, System.Object TruePart, System.Object FalsePart)
136 return Expression ? TruePart : FalsePart;
139 public static System.String Partition (System.Int64 number, System.Int64 start, System.Int64 stop, System.Int64 interval)
141 String stopStr = "";
142 String startStr = "";
143 long startNumber = 0;
144 int spacesCount = 0;
145 long endNumber = 0;
147 if (start < 0)
148 throw new ArgumentException(
149 Utils.GetResourceString("Argument_InvalidValue1", "Start"));
150 if (stop <= start)
151 throw new ArgumentException(
152 Utils.GetResourceString("Argument_InvalidValue1", "Stop"));
153 if (interval < 1)
154 throw new ArgumentException(
155 Utils.GetResourceString("Argument_InvalidValue1", "Interval"));
157 if (number < start)
158 endNumber = start - 1;
159 else {
160 if (number > stop)
161 startNumber = stop + 1;
162 else {
163 if (interval == 1){
164 startNumber = number;
165 endNumber = number;
167 else {
168 endNumber = start-1;
169 while (endNumber < number)
170 endNumber += interval;
171 startNumber = endNumber - interval + 1;
173 if (endNumber > stop)
174 endNumber = stop;
175 if (startNumber < start)
176 startNumber = start;
181 startStr = startNumber.ToString();
182 stopStr = endNumber.ToString();
184 if (stopStr.Length > startStr.Length)
185 spacesCount = stopStr.Length;
186 else
187 spacesCount = startStr.Length;
189 return startStr.PadLeft(spacesCount) + ":" + stopStr.PadRight(spacesCount);
192 public static System.Object Switch (params System.Object[] VarExpr)
194 int counter;
195 int index;
197 if (VarExpr == null)
198 return null;
200 counter = VarExpr.Length;
201 index = 0;
203 if (counter % 2 != 0)
204 throw new ArgumentException(
205 Utils.GetResourceString("Argument_InvalidValue1", "VarExpr"));
207 do {
208 if((bool)VarExpr[index])
209 return VarExpr[index + 1];
210 index += 2;
211 counter = counter - 2;
213 while (counter > 0);
215 return null;
218 [MonoTODO]
219 public static void DeleteSetting (System.String AppName,
220 [Optional, __DefaultArgumentValue(null)] System.String Section,
221 [Optional, __DefaultArgumentValue(null)] System.String Key)
223 throw new NotImplementedException ();
226 [MonoTODO]
227 public static System.String[,] GetAllSettings (System.String AppName, System.String Section)
229 throw new NotImplementedException ();
232 [MonoTODO]
233 public static System.String GetSetting (System.String AppName,
234 System.String Section,
235 System.String Key,
236 [Optional, __DefaultArgumentValue("")] System.String Default)
238 throw new NotImplementedException ();
241 [MonoTODO]
242 public static void SaveSetting (System.String AppName, System.String Section, System.String Key, System.String Setting)
244 throw new NotImplementedException ();
247 [MonoTODO]
248 public static System.Object CreateObject (System.String ProgId,
249 [Optional, __DefaultArgumentValue("")] System.String ServerName)
251 throw new NotImplementedException ();
254 [MonoTODO]
255 public static System.Object GetObject ([Optional, __DefaultArgumentValue(null)] System.String PathName,
256 [Optional, __DefaultArgumentValue(null)] System.String Class)
258 throw new NotImplementedException ();
262 public static Object CallByName (Object objRef, String name, CallType userCallType, Object[] args)
264 Object retVal = null;
265 Type[] argsType = null;
268 if(args != null && args.Length != 0) {
269 argsType = new Type[args.Length];
271 for(int i = 0; i < args.Length; i++)
272 argsType[i] = args[i].GetType();
274 /*else
275 argsType = new Type[0];*/
277 Type objType = objRef.GetType();
281 MethodInfo methodInfo = null;
283 if(userCallType == CallType.Method) {
284 Console.WriteLine("Method");
285 methodInfo = objType.GetMethod(name, argsType);
287 else if(userCallType == CallType.Get) {
288 Console.WriteLine("GetMethod");
289 methodInfo = objType.GetProperty(name).GetGetMethod();
291 else if(userCallType == CallType.Set) {
293 Console.WriteLine("SetMethod");
294 methodInfo = objType.GetProperty(name).GetSetMethod();
297 return methodInfo.Invoke(objRef, args);
300 catch (Exception exp)
302 throw new ArgumentException();
308 public static System.Object Choose (System.Double Index, System.Object[] Choice)
310 int i;
312 i = (int) Math.Round(Conversion.Fix(Index) - 1.0);
313 if(Choice.Rank != 1)
314 throw new ArgumentException(Utils.GetResourceString("Argument_RankEQOne1", "Choice"));
316 if(i < 0 || i > Choice.GetUpperBound(0))
317 return null;
318 else
319 return Choice[i];
323 public static System.String Environ (System.Int32 Expression)
325 int index = 0;
326 Exception e;
328 // Console.WriteLine("Coming Here"+Expression);
330 IDictionary envVars = Environment.GetEnvironmentVariables();
332 foreach(DictionaryEntry de in envVars) {
333 if(++index == Expression) {
334 if( (object) de.Value == null)
335 return "";
336 else
337 return String.Concat(de.Key, "=" , de.Value);
340 // Console.WriteLine("Exiting the loop");
342 return "";
346 public static System.String Environ (System.String Expression)
348 Exception e;
349 if (Expression == null) {
350 e = ExceptionUtils.VbMakeExceptionEx(5, Utils.GetResourceString("Argument_InvalidValue1", Expression));
351 throw e;
354 string var = Environment.GetEnvironmentVariable (Expression);
355 return var != null ? var : "";
358 public static void Beep ()
360 Console.WriteLine("\a");
364 public static System.String Command ()
366 string [] args = Environment.GetCommandLineArgs ();
368 if (args != null && args.Length > 1) {
369 return string.Join (" ", args, 1, args.Length - 1);
370 } else {
371 return "";
375 [MonoTODO]
376 public static MsgBoxResult MsgBox (System.Object Prompt,
377 [Optional, __DefaultArgumentValue(0)]MsgBoxStyle Buttons,
378 [Optional, __DefaultArgumentValue(null)] System.Object Title)
380 throw new NotImplementedException ();
381 /* //MessageButtons msgBoxButtons = 0;
382 MessageBoxIcon msgBoxIcon = 0;
383 MessageBoxDefaultButton msgBoxDefaultButton = 0;
384 MessageBoxOptions msgBoxOptions = 0;
387 int IconsMask = MsgBoxStyle.Critical | MsgBoxStyle.Question | MsgBoxStyle.Exclamation | MsgBoxStyle.Information;
389 int ButtonsMask = MsgBoxStyle.OKOnly |MsgBoxStyle.OKCancel | MsgBoxStyle.AbortRetryIgnore |
390 MsgBoxStyle.YesNoCancel |
391 MsgBoxStyle.YesNo | MsgBoxStyle.RetryCancel;
393 int DefaultButtonMask = MsgBoxStyle.DeafultButton1 | MsgBoxStyle.DefaultButton2 |
394 MsgBoxStyle.DefaultButton3;
396 int OptionsMask = MsgBoxStyle.MsgBoxRight | MsgBoxStyle.MsgBoxRtlReading;
399 switch(Buttons & IconMask) {
400 case MsgBoxStyle.OKOnly:
401 msgBoxButtons = MessageBoxButtons.OK;
402 break;
404 case MsgBoxStyle.OKCancel:
405 msgBoxButtons = MessageBoxButtons.OK;
406 break;
408 case MsgBoxStyle.AbortRetryIgnore:
409 msgBoxButtons = MessageBoxButtons.OKCancel;
410 break;
412 case MsgBoxStyle.YesNoCancel:
413 msgBoxButtons = MessageBoxButtons.YesNoCancel;
414 break;
416 case MsgBoxStyle.YesNo:
417 msgBoxButtons = MessageBoxButtons.YesNo;
418 break;
420 case MsgBoxStyle.RetryCancel:
421 msgBoxButtons = MessageBoxButtons.RetryCancel;
422 break;
424 default:
425 // handle error
426 break;
431 switch(Buttons & IconMask) {
433 case MsgBoxStyle.Critical:
434 msgBoxIcon = MessageBoxIcon.Error;
435 break;
437 case MsgBoxStyle.Question:
438 msgBoxIcon = MessageBoxIcon.Question;
439 break;
441 case MsgBoxStyle.Exclamation:
442 msgBoxIcon = MessageBoxIcon.Exclamation;
443 break;
445 case MsgBoxStyle.Information:
446 msgBoxIcon = MessageBoxIcon.Information;
447 break;
449 default:
450 // handle error
451 break;
454 switch(Buttons & DefaultButtonMask) {
455 case MsgBoxStyle.DefaultButton1:
456 msgBoxDefaultButton = MessageBoxDefaultButton.Button1;
457 break;
458 case MsgBoxStyle.DefaultButton2:
459 msgBoxDefaultButton = MessageBoxDefaultButton.Button2;
460 break;
461 case MsgBoxStyle.DefaultButton3:
462 msgBoxDefaultButton = MessageBoxDefaultButton.Button3;
463 break;
464 default:
465 //handle error
466 break;
469 switch(Buttons & OptionsMask) {
470 default:
471 break;
475 } */