/DeveloperBranches/Ken/Previous/UIDesigner/ControlProviders/Bases/BaseControlProvider.cs

# · C# · 224 lines · 195 code · 29 blank · 0 comment · 14 complexity · e50e1345ea4ea6a2ea5528457be87daf MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.ComponentModel;
  6. using DDW;
  7. using UIDesigner.FieldHandlers;
  8. using System.Drawing;
  9. using System.Windows.Forms;
  10. using UIDesigner.FieldHandlers.Bases;
  11. using System.ComponentModel.Design.Serialization;
  12. namespace UIDesigner.ControlProviders.Bases
  13. {
  14. public abstract class BaseControlProvider : IControlProvider
  15. {
  16. protected AFDesignerHost m_objHost;
  17. public abstract void AddBindings(Control ctrlBinding, BaseNode objBase, string strBindingSourceProperty);
  18. public abstract Control AddControls(string strOption, IComponent ctrlParent, BaseNode objBase, bool bDefault, bool bPreview, int nTabIndex, List<Rectangle> rgLocationRects, List<char> rgMnemonics);
  19. public abstract Control AddControls(string strOption, TableLayoutPanel ctrlParent, BaseNode objBase, bool bDefault, bool bPreview, int nTabIndex, List<TableLayoutPanelCellPosition> rgTableLayoutPanelCellPositions, List<char> rgMnemonics);
  20. public abstract void NegotiateLayout(string strOption, IComponent ctrlParent, BaseNode objBase, LayoutMode eLayoutMode, ref int nTabIndex, out LayoutStyle eLayoutStyle, out int nLabelAlignment, out Size szControlSize);
  21. public BaseControlProvider(AFDesignerHost objHost)
  22. {
  23. m_objHost = objHost;
  24. }
  25. public virtual bool SupportsOption(string strOption)
  26. {
  27. foreach (Attribute objAttr in this.GetType().GetCustomAttributes(true))
  28. {
  29. ControlProviderAttribute objProviderAttr = objAttr as ControlProviderAttribute;
  30. if (objProviderAttr != null)
  31. {
  32. if (objProviderAttr.SupportedOptions.Contains<string>(strOption))
  33. {
  34. return true;
  35. }
  36. }
  37. }
  38. return false;
  39. }
  40. protected BindingSource GetBindingSource(string strBindingSourceProperty)
  41. {
  42. foreach (IComponent objComponent in m_objHost.Container.Components)
  43. {
  44. if (objComponent.Site.Name == strBindingSourceProperty)
  45. {
  46. return (BindingSource) objComponent;
  47. }
  48. }
  49. return (BindingSource) m_objHost.CreateComponent(typeof(BindingSource), strBindingSourceProperty);
  50. }
  51. protected string HandleName(string strName)
  52. {
  53. string strNewName = m_objHost.HandleName(strName);
  54. return strNewName;
  55. }
  56. protected string HandleName(BaseNode objBase)
  57. {
  58. if (objBase is ParamDeclNode)
  59. {
  60. PredefinedTypeNode objType = objBase.Type as PredefinedTypeNode;
  61. string strPrefix;
  62. string strName;
  63. if (objType != null)
  64. {
  65. strPrefix = BaseFieldHandler.GetVariablePrefix(objType.Identifier.GenericIdentifier);
  66. }
  67. else
  68. {
  69. strPrefix = BaseFieldHandler.GetVariablePrefix("object");
  70. }
  71. if (objBase.Name.StartsWith(strPrefix))
  72. {
  73. strName = objBase.Name.Substring(strPrefix.Length);
  74. return strName;
  75. }
  76. }
  77. return objBase.Name;
  78. }
  79. protected string HandleMnemonics(string strName, List<char> rgMnemonics)
  80. {
  81. int nIndex = 0;
  82. char ch = strName[0];
  83. string strNewName = null;
  84. while (rgMnemonics.Contains(ch))
  85. {
  86. nIndex++;
  87. if (nIndex >= strName.Length)
  88. {
  89. return strName;
  90. }
  91. ch = strName[nIndex];
  92. }
  93. rgMnemonics.Add(ch);
  94. strNewName = strName.Substring(0, nIndex) + "&" + strName.Substring(nIndex, strName.Length - nIndex);
  95. return strNewName;
  96. }
  97. protected static string GetControlPrefix(Type objType)
  98. {
  99. string strName = objType.Name;
  100. string strPrefix = null;
  101. while (strPrefix == null)
  102. {
  103. switch (strName)
  104. {
  105. case "CheckBox":
  106. strPrefix = "chk";
  107. break;
  108. case "CheckedListBox":
  109. strPrefix = "lst";
  110. break;
  111. case "ComboBox":
  112. strPrefix = "cbo";
  113. break;
  114. case "Control":
  115. strPrefix = "ctrl";
  116. break;
  117. case "DomainUpDown":
  118. strPrefix = "txt";
  119. break;
  120. case "Form":
  121. strPrefix = "frm";
  122. break;
  123. case "Label":
  124. strPrefix = "lbl";
  125. break;
  126. case "ListBox":
  127. strPrefix = "lst";
  128. break;
  129. case "ListViewContainer":
  130. strPrefix = "lst";
  131. break;
  132. case "MaskedTextBox":
  133. strPrefix = "txt";
  134. break;
  135. case "NumericUpDown":
  136. strPrefix = "txt";
  137. break;
  138. case "OrderedListBox":
  139. strPrefix = "lst";
  140. break;
  141. case "OrderedListView":
  142. strPrefix = "lst";
  143. break;
  144. case "RichTextBox":
  145. strPrefix = "txt";
  146. break;
  147. case "SerialCode":
  148. strPrefix = "txt";
  149. break;
  150. case "StateDropdown":
  151. strPrefix = "cbo";
  152. break;
  153. case "SubForm":
  154. strPrefix = "ctrl";
  155. break;
  156. case "TextBox":
  157. strPrefix = "txt";
  158. break;
  159. case "TimeDropDown":
  160. strPrefix = "cbo";
  161. break;
  162. default:
  163. objType = objType.BaseType;
  164. strName = objType.Name;
  165. break;
  166. }
  167. }
  168. return strPrefix;
  169. }
  170. protected static bool HasGetter(BaseNode objBase)
  171. {
  172. return BaseFieldHandler.HasGetter(objBase);
  173. }
  174. protected static bool HasSetter(BaseNode objBase)
  175. {
  176. return BaseFieldHandler.HasSetter(objBase);
  177. }
  178. protected static string GetPrettyName(BaseNode objBase)
  179. {
  180. return BaseFieldHandler.GetPrettyName(objBase);
  181. }
  182. protected static string GetPrettyDescription(BaseNode objBase)
  183. {
  184. return BaseFieldHandler.GetPrettyDescription(objBase);
  185. }
  186. public static bool IsReadOnlyResult(BaseNode objBase)
  187. {
  188. return BaseFieldHandler.IsReadOnlyResult(objBase);
  189. }
  190. public static bool IsWriteOnlyResult(BaseNode objBase)
  191. {
  192. return BaseFieldHandler.IsWriteOnlyResult(objBase);
  193. }
  194. }
  195. }