2
// <copyright see="prj:///doc/copyright.txt"/>
3
// <license see="prj:///doc/license.txt"/>
4
// <owner name="Oakland Software Incorporated" email="general@oaklandsoftware.com"/>
5
// <version>$Revision$</version>
9
using System.Collections;
10
using System.Diagnostics;
12
using System.Reflection;
13
using System.Windows.Forms;
19
internal interface IHasControl
26
internal const int SPLITTER_SIZE = 3;
27
internal const int BUTTON_HEIGHT = 23;
28
internal const int BUTTON_WIDTH_PAD = 15;
30
Object ie = AppDomain.CreateInstance(ie);
32
internal const bool SHOW_WINDOW = true;
34
protected static void InvokeWithSHDocVw(String uriStr)
37
Assembly shdocvw = null;
38
foreach (Assembly assy in AppDomain.CurrentDomain.GetAssemblies())
40
if (assy.GetName().Name.Equals("SHDocVw"))
47
throw new Exception("SHDocVw assembly not found");
49
shdocvw.GetType("SHDocVw.InternetExplorerClass", true);
50
ConstructorInfo ieCons = ieType.GetConstructor(new Type[0]);
54
("InternetExplorerClass constructor not found");
56
ie = ieCons.Invoke(null);
60
("Unable to create SHDocVw/InternetExplorer");
62
MethodInfo mi = ieType.GetMethod("Navigate");
63
mi.Invoke(ie, new Object[] { uriStr, null, null, null, null });
64
PropertyInfo visProp = ieType.GetProperty("Visible");
65
visProp.SetValue(ie, true, null);
66
PropertyInfo hwndProp = ieType.GetProperty("HWND");
67
int hwnd = (int)hwndProp.GetValue(ie, null);
68
Windows.SetForegroundWindow(hwnd);
71
protected static void InvokeWithProcessStart(String uriStr)
73
ProcessStartInfo psi = new ProcessStartInfo();
74
/* Simply using Process.Start(e.Link.LinkData.ToString());
75
does not work on all pc's! */
76
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
78
/* Start is an internal command in WinNT/2000/XP */
79
psi.FileName = "cmd.exe";
80
psi.Arguments = "/c start " + uriStr;
84
/* Start is an external command in Win9x */
85
psi.FileName = "start.exe";
86
psi.Arguments = uriStr;
88
/* Hide the command prompt window */
89
psi.WindowStyle = ProcessWindowStyle.Hidden;
90
//Console.WriteLine("psi.FileName: " + psi.FileName);
91
//Console.WriteLine("psi.Arguments: " + psi.Arguments);
95
internal static void InvokeBrowser(String url)
97
InvokeBrowser(url, SHOW_WINDOW);
100
internal static void InvokeBrowser(Uri url)
102
InvokeBrowser(url, SHOW_WINDOW);
105
internal static void InvokeBrowser(String uri, bool showWindow)
107
string uriInput = uri;
108
if (!uri.StartsWith("http:"))
109
uriInput = "http://" + uri;
110
InvokeBrowser(new Uri(uriInput), showWindow);
113
internal static void InvokeBrowser(Uri uri, bool showWindow)
116
TraceUtil.WriteLineInfo(null, "Invoke browser: " + uri);
117
String uriStr = uri.AbsoluteUri;
120
InvokeWithProcessStart(uriStr);
121
} catch (Exception ex) {
122
TraceUtil.WriteLineWarning(null,
123
"Invoke browser Process.Start ["
125
// If Process.Start did not work, then that means
126
// SHDocVw is loaded, try invoking with that using
127
// reflection. If MSFT ever fixes that bug, then this
128
// code can be removed
129
InvokeWithSHDocVw(uriStr);
131
} catch (Exception ex) {
132
TraceUtil.WriteLineError(null,
138
// Makes a transparent, read only text box used to describe
140
internal static RichTextBox MakeDescText(String text, Control con)
142
RichTextBox tb = new RichTextBox();
145
tb.BorderStyle = BorderStyle.None;
150
tb.HideSelection = true;
151
tb.BackColor = con.BackColor;
152
// Get number of actual lines the text box needs
153
// given the current width
154
int lines = (1 + tb.GetLineFromCharIndex(tb.TextLength));
155
tb.Height = tb.PreferredHeight * lines;
159
// Makes a button with the specified text
160
internal static Button MakeButton(String text)
162
Button b = new Button();
163
Graphics g = b.CreateGraphics();
164
SizeF size = g.MeasureString(text, b.Font);
165
b.Height = BUTTON_HEIGHT;
166
int proposedWidth = (int)(size.Width + BUTTON_WIDTH_PAD);
167
if (b.Width < proposedWidth)
168
b.Width = proposedWidth;
174
internal static int SetMaxWidth(Control con, String text, int maxWidth)
176
Graphics g = con.CreateGraphics();
177
int width = (int)g.MeasureString(text, con.Font).Width;
178
if (width > maxWidth)
184
internal static String MakeGuidStr(Guid guid)
186
return "{" + guid + "}";
189
// Adds the specified list of controls to the specified
190
// control in reverse order so that the layout works
192
internal static void AddControls(Control control, ArrayList controls)
194
AddControls(control, controls, 0);
197
internal static void AddControls(Control control, ArrayList controls, int tabOffset)
201
int len = controls.Count;
202
Control[] c = new Control[len];
203
Array.Copy(controls.ToArray(), c, len);
204
control.Controls.AddRange(c);
205
for (int i = 0; i < len; i++)
206
control.Controls[i].TabIndex = len - i + tabOffset;
209
// Adds the specified list control containers to specified
210
// control in reverse order so that the layout works
212
internal static void AddHasControls(Control control, ArrayList hasControls)
214
AddHasControls(control, hasControls, 0);
217
internal static void AddHasControls(Control control, ArrayList hasControls, int tabOffset)
221
hasControls.Reverse();
222
int len = hasControls.Count;
223
Control[] c = new Control[len];
224
for (int i = 0; i < len; i++) {
225
c[i] = ((IHasControl)hasControls[i]).GetControl();
226
c[i].TabIndex = len - i + tabOffset;
228
control.Controls.AddRange(c);
231
// Works around a problem that some objects (notably Cursor)
232
// throw in their Equals method
233
internal static bool ContainsHack(ArrayList a, Object obj)
235
return FindHack(a, obj) != null;
238
internal static Object FindHack(ArrayList a, Object obj)
240
foreach (Object arrayObj in a) {
242
if (arrayObj.Equals(obj))
251
internal static bool IsArrayListEqual(ArrayList al1, ArrayList al2)
253
if (al1 == null && al2 == null)
255
if (al1 == null || al2 == null ||
256
al1.Count != al2.Count)
259
for (int i = 0; i < al2.Count; i++) {
260
if (al2[i] != al1[i]) {