| 0: | // ClassBrowserIcons.cs | |
| 1: | // Copyright (C) 2001 Mike Krueger | |
| 2: | // | |
| 3: | // This program is free software; you can redistribute it and/or modify | |
| 4: | // it under the terms of the GNU General Public License as published by | |
| 5: | // the Free Software Foundation; either version 2 of the License, or | |
| 6: | // (at your option) any later version. | |
| 7: | // | |
| 8: | // This program is distributed in the hope that it will be useful, | |
| 9: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11: | // GNU General Public License for more details. | |
| 12: | // | |
| 13: | // You should have received a copy of the GNU General Public License | |
| 14: | // along with this program; if not, write to the Free Software | |
| 15: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 16: | ||
| 17: | using System; | |
| 18: | using System.IO; | |
| 19: | using System.Runtime.InteropServices; | |
| 20: | using System.Collections; | |
| 21: | using System.Drawing; | |
| 22: | using System.Reflection; | |
| 23: | using System.Resources; | |
| 24: | using System.Diagnostics; | |
| 25: | using System.Windows.Forms; | |
| 26: | using SharpDevelop.Internal.Parser; | |
| 27: | ||
| 28: | using SharpDevelop.Internal.Modules; | |
| 29: | using SharpDevelop.Tool.Data; | |
| 30: | ||
| 31: | namespace SharpDevelop.Tool.Function { | |
| 32: | ||
| 33: | public class ClassBrowserIcons | |
| 34: | { | |
| 35: | public static int NAMESPACEINDEX = 3; | |
| 36: | public static int COMBINEINDEX = 46; | |
| 37: | public static int LITERALINDEX = 47; | |
| 38: | ||
| 39: | public static int CLASSINDEX = 14; | |
| 40: | public static int STRUCTINDEX = CLASSINDEX + 1 * 4; | |
| 41: | public static int INTERFACEINDEX = CLASSINDEX + 2 * 4; | |
| 42: | public static int ENUMINDEX = CLASSINDEX + 3 * 4; | |
| 43: | public static int METHODINDEX = CLASSINDEX + 4 * 4; | |
| 44: | public static int PROPERTYINDEX = CLASSINDEX + 5 * 4; | |
| 45: | public static int FIELDINDEX = CLASSINDEX + 6 * 4; | |
| 46: | public static int DELEGATEINDEX = CLASSINDEX + 7 * 4; | |
| 47: | ||
| 48: | public static ImageList imglist = new ImageList(); | |
| 49: | ||
| 50: | static int GetModify(ArrayList list) | |
| 51: | { | |
| 52: | foreach (string str in list) { | |
| 53: | switch (str.ToUpper()) { | |
| 54: | case "PUBLIC": | |
| 55: | return 0; | |
| 56: | case "PROTECTED": | |
| 57: | return 2; | |
| 58: | case "INTERNAL": | |
| 59: | return 1; | |
| 60: | } | |
| 61: | } | |
| 62: | return 3; | |
| 63: | } | |
| 64: | ||
| 65: | ||
| 66: | public static int GetIcon(Method method) | |
| 67: | { | |
| 68: | return METHODINDEX + GetModify(method.Modifier); | |
| 69: | } | |
| 70: | public static int GetIcon(Property method) | |
| 71: | { | |
| 72: | return PROPERTYINDEX + GetModify(method.Modifier); | |
| 73: | } | |
| 74: | public static int GetIcon(Field method) | |
| 75: | { | |
| 76: | return FIELDINDEX + GetModify(method.Modifier); | |
| 77: | } | |
| 78: | public static int GetIcon(Event method) | |
| 79: | { | |
| 80: | return DELEGATEINDEX + GetModify(method.Modifier); | |
| 81: | } | |
| 82: | ||
| 83: | public static int GetIcon(MethodBase methodinfo) | |
| 84: | { | |
| 85: | if (methodinfo.IsAssembly) | |
| 86: | return METHODINDEX + 1; | |
| 87: | ||
| 88: | if (methodinfo.IsPrivate) | |
| 89: | return METHODINDEX + 3; | |
| 90: | ||
| 91: | if (methodinfo.IsFamily ) // protected | |
| 92: | return METHODINDEX + 2; | |
| 93: | ||
| 94: | return METHODINDEX; | |
| 95: | } | |
| 96: | ||
| 97: | public static int GetIcon(FieldInfo fieldinfo) | |
| 98: | { | |
| 99: | if (fieldinfo.IsLiteral) | |
| 100: | return 13; | |
| 101: | ||
| 102: | if (fieldinfo.IsAssembly) | |
| 103: | return FIELDINDEX + 1; | |
| 104: | ||
| 105: | if (fieldinfo.IsPrivate) | |
| 106: | return FIELDINDEX + 3; | |
| 107: | ||
| 108: | if (!(fieldinfo.IsPrivate || fieldinfo.IsPublic)) | |
| 109: | return FIELDINDEX + 2; | |
| 110: | ||
| 111: | return FIELDINDEX; | |
| 112: | } | |
| 113: | ||
| 114: | public static int GetIcon(PropertyInfo propertyinfo) | |
| 115: | { | |
| 116: | if (propertyinfo.CanRead && propertyinfo.GetGetMethod() != null) | |
| 117: | return PROPERTYINDEX + GetIcon(propertyinfo.GetGetMethod()) - METHODINDEX; | |
| 118: | ||
| 119: | if (propertyinfo.CanWrite && propertyinfo.GetSetMethod() != null) | |
| 120: | return PROPERTYINDEX + GetIcon(propertyinfo.GetSetMethod()) - METHODINDEX; | |
| 121: | return PROPERTYINDEX; | |
| 122: | } | |
| 123: | ||
| 124: | public static int GetIcon(EventInfo eventinfo) | |
| 125: | { | |
| 126: | return 12; | |
| 127: | } | |
| 128: | ||
| 129: | public static int GetIcon(System.Type type) | |
| 130: | { | |
| 131: | int BASE = CLASSINDEX; | |
| 132: | ||
| 133: | if (type.IsValueType) | |
| 134: | BASE = STRUCTINDEX; | |
| 135: | ||
| 136: | if (type.IsEnum) | |
| 137: | BASE = ENUMINDEX; | |
| 138: | ||
| 139: | if (type.IsInterface) | |
| 140: | BASE = INTERFACEINDEX; | |
| 141: | ||
| 142: | if (type.IsNestedPrivate) { | |
| 143: | return BASE + 3; | |
| 144: | } else | |
| 145: | if (type.IsNotPublic) { | |
| 146: | return BASE + 2; | |
| 147: | } else | |
| 148: | if (type.IsNestedAssembly) { | |
| 149: | return BASE + 1; | |
| 150: | } | |
| 151: | return BASE; | |
| 152: | } | |
| 153: | ||
| 154: | public static string GetDeclaration(MethodInfo methodinfo) | |
| 155: | { | |
| 156: | string text = ""; | |
| 157: | ||
| 158: | if (methodinfo.IsPrivate) { // private | |
| 159: | text += "private "; | |
| 160: | } else | |
| 161: | if (methodinfo.IsFamily ) { // protected | |
| 162: | text += "protected "; | |
| 163: | } else | |
| 164: | text += "public "; | |
| 165: | ||
| 166: | if (methodinfo.IsStatic) | |
| 167: | text += "static "; | |
| 168: | ||
| 169: | if (methodinfo.IsAbstract) | |
| 170: | text += "abstract "; | |
| 171: | ||
| 172: | text += GetTypeString(methodinfo.ReturnType.ToString()) + " " + methodinfo.Name +"("; | |
| 173: | ParameterInfo[] pinfo = methodinfo.GetParameters(); | |
| 174: | for (int i = 0; i < pinfo.Length; ++i) { | |
| 175: | string typetxt = pinfo[i].ParameterType.ToString(); | |
| 176: | if (typetxt[typetxt.Length-1] == '&') { | |
| 177: | typetxt = "ref " + typetxt.Substring(0, typetxt.Length-1); | |
| 178: | } | |
| 179: | text += GetTypeString(typetxt) + " " + pinfo[i].Name + ((i < pinfo.Length - 1) ? ", " : ""); | |
| 180: | } | |
| 181: | text += ");"; | |
| 182: | return text; | |
| 183: | } | |
| 184: | ||
| 185: | public static string GetTypeString(string type) | |
| 186: | { | |
| 187: | string newtype = Char.ToLower(type[0]) + type.Substring(1); | |
| 188: | string[,] types = new string[,] { | |
| 189: | {"System.Void", "void"}, | |
| 190: | {"System.Object", "object"}, | |
| 191: | {"System.Boolean", "bool"}, | |
| 192: | {"System.Byte", "byte"}, | |
| 193: | {"System.SByte", "sbyte"}, | |
| 194: | {"System.Char", "char"}, | |
| 195: | {"System.Enum", "enum"}, | |
| 196: | {"System.Int16", "short"}, | |
| 197: | {"System.Int32", "int"}, | |
| 198: | {"System.Int64", "long"}, | |
| 199: | {"System.UInt16", "ushort"}, | |
| 200: | {"System.UInt32", "uint"}, | |
| 201: | {"System.UInt64", "ulong"}, | |
| 202: | {"System.Single", "float"}, | |
| 203: | {"System.Double", "double"}, | |
| 204: | {"System.Decimal", "decimal"}, | |
| 205: | {"System.String", "string"} | |
| 206: | }; | |
| 207: | ||
| 208: | if (type.EndsWith("[]")) { | |
| 209: | return "System.Array"; | |
| 210: | } | |
| 211: | ||
| 212: | for (int i = 0; i < types.GetLength(0); ++i) { | |
| 213: | if (newtype == types[i, 1]) { | |
| 214: | return types[i, 0]; | |
| 215: | } | |
| 216: | } | |
| 217: | return type; | |
| 218: | } | |
| 219: | ||
| 220: | public static void InitIcons() | |
| 221: | { | |
| 222: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Assembly")); | |
| 223: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.OpenAssembly")); | |
| 224: | ||
| 225: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Library")); | |
| 226: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.NameSpace")); | |
| 227: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.SubTypes")); | |
| 228: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.SuperTypes")); | |
| 229: | ||
| 230: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ClosedFolderBitmap")); | |
| 231: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.OpenFolderBitmap")); | |
| 232: | ||
| 233: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Reference")); | |
| 234: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ClosedReferenceFolder")); | |
| 235: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.OpenReferenceFolder")); | |
| 236: | ||
| 237: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ResourceFileIcon")); | |
| 238: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Event")); | |
| 239: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Literal")); | |
| 240: | ||
| 241: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Class")); //14 | |
| 242: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalClass")); | |
| 243: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedClass")); | |
| 244: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateClass")); | |
| 245: | ||
| 246: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Struct")); | |
| 247: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalStruct")); | |
| 248: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedStruct")); | |
| 249: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateStruct")); | |
| 250: | ||
| 251: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Interface")); | |
| 252: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalInterface")); | |
| 253: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedInterface")); | |
| 254: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateInterface")); | |
| 255: | ||
| 256: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Enum")); | |
| 257: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalEnum")); | |
| 258: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedEnum")); | |
| 259: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateEnum")); | |
| 260: | ||
| 261: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Method")); | |
| 262: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalMethod")); | |
| 263: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedMethod")); | |
| 264: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateMethod")); | |
| 265: | ||
| 266: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Property")); | |
| 267: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalProperty")); | |
| 268: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedProperty")); | |
| 269: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateProperty")); | |
| 270: | ||
| 271: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Field")); | |
| 272: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalField")); | |
| 273: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedField")); | |
| 274: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateField")); | |
| 275: | ||
| 276: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Delegate")); | |
| 277: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.InternalDelegate")); | |
| 278: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.ProtectedDelegate")); | |
| 279: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.PrivateDelegate")); | |
| 280: | ||
| 281: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.CombineIcon")); // 46 | |
| 282: | imglist.Images.Add(Resource.GetBitmap("Icons.16x16.Literal")); // 47 | |
| 283: | } | |
| 284: | } | |
| 285: | } |
This page was automatically generated by SharpDevelop.