ComponentEditorPage.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Andreas Nahr ([email protected])
  24. //
  25. using System.ComponentModel;
  26. using System.Drawing;
  27. using System.Runtime.InteropServices;
  28. namespace System.Windows.Forms.Design
  29. {
  30. [ClassInterfaceAttribute (ClassInterfaceType.AutoDispatch)]
  31. [ComVisible (true)]
  32. public abstract class ComponentEditorPage : Panel
  33. {
  34. private bool commitOnDeactivate = false;
  35. private IComponent component;
  36. private bool firstActivate = true;
  37. private Icon icon;
  38. private int loading = 0;
  39. private bool loadRequired = false;
  40. private IComponentEditorPageSite pageSite;
  41. public ComponentEditorPage ()
  42. {
  43. }
  44. [Browsable (false)]
  45. [EditorBrowsable (EditorBrowsableState.Never)]
  46. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  47. new public virtual bool AutoSize {
  48. get { return base.AutoSize; }
  49. set { base.AutoSize = value; }
  50. }
  51. public bool CommitOnDeactivate
  52. {
  53. get { return commitOnDeactivate; }
  54. set { commitOnDeactivate = value; }
  55. }
  56. protected IComponent Component {
  57. get { return component; }
  58. set { component = value; }
  59. }
  60. [MonoTODO ("Find out what this does.")]
  61. protected override CreateParams CreateParams {
  62. get {
  63. throw new NotImplementedException ();
  64. }
  65. }
  66. protected bool FirstActivate {
  67. get { return firstActivate; }
  68. set { firstActivate = value; }
  69. }
  70. public Icon Icon {
  71. get { return icon; }
  72. set { icon = value; }
  73. }
  74. protected int Loading {
  75. get { return loading; }
  76. set { loading = value; }
  77. }
  78. protected bool LoadRequired {
  79. get { return loadRequired; }
  80. set { loadRequired = value; }
  81. }
  82. protected IComponentEditorPageSite PageSite {
  83. get { return pageSite; }
  84. set { pageSite = value; }
  85. }
  86. public virtual string Title {
  87. get { return base.Text; }
  88. }
  89. public virtual void Activate ()
  90. {
  91. Visible = true;
  92. firstActivate = false;
  93. if (loadRequired) {
  94. EnterLoadingMode ();
  95. LoadComponent ();
  96. ExitLoadingMode ();
  97. }
  98. }
  99. public virtual void ApplyChanges ()
  100. {
  101. SaveComponent ();
  102. }
  103. public virtual void Deactivate ()
  104. {
  105. Visible = false;
  106. }
  107. protected void EnterLoadingMode ()
  108. {
  109. loading++;
  110. }
  111. protected void ExitLoadingMode ()
  112. {
  113. loading--;
  114. }
  115. public virtual Control GetControl ()
  116. {
  117. return this;
  118. }
  119. protected IComponent GetSelectedComponent ()
  120. {
  121. return component;
  122. }
  123. protected bool IsFirstActivate ()
  124. {
  125. return firstActivate;
  126. }
  127. protected bool IsLoading ()
  128. {
  129. return (loading != 0);
  130. }
  131. public virtual bool IsPageMessage (ref Message msg)
  132. {
  133. return PreProcessMessage (ref msg);
  134. }
  135. protected abstract void LoadComponent ();
  136. [MonoTODO ("Find out what this does.")]
  137. public virtual void OnApplyComplete ()
  138. {
  139. }
  140. protected virtual void ReloadComponent ()
  141. {
  142. loadRequired = true;
  143. }
  144. protected abstract void SaveComponent ();
  145. public virtual void SetComponent (IComponent component)
  146. {
  147. this.component = component;
  148. ReloadComponent ();
  149. }
  150. [MonoTODO ("Find out what this does.")]
  151. protected virtual void SetDirty ()
  152. {
  153. }
  154. public virtual void SetSite (IComponentEditorPageSite site)
  155. {
  156. pageSite = site;
  157. pageSite.GetControl ().Controls.Add (this);
  158. }
  159. public virtual void ShowHelp ()
  160. {
  161. }
  162. public virtual bool SupportsHelp ()
  163. {
  164. return false;
  165. }
  166. #region Public Events
  167. [Browsable (false)]
  168. [EditorBrowsable (EditorBrowsableState.Never)]
  169. public new event EventHandler AutoSizeChanged {
  170. add { base.AutoSizeChanged += value; }
  171. remove { base.AutoSizeChanged -= value; }
  172. }
  173. #endregion
  174. }
  175. }