320c3071e1bf00fd11040f75111f04a58b56ec62
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms.Design / ComponentEditorPage.cs
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    (ClassDevelopment@A-SoftTech.com)
24 //
25
26 using System.ComponentModel;
27 using System.Drawing;
28 using System.Runtime.InteropServices;
29
30 namespace System.Windows.Forms.Design
31 {
32 #if NET_2_0
33         [ClassInterfaceAttribute (ClassInterfaceType.AutoDispatch)]
34         [ComVisible (true)]
35 #endif
36         public abstract class ComponentEditorPage : Panel
37         {
38                 private bool commitOnDeactivate = false;
39                 private IComponent component;
40                 private bool firstActivate = true;
41                 private Icon icon;
42                 private int loading = 0;
43                 private bool loadRequired = false;
44                 private IComponentEditorPageSite pageSite;
45
46                 public ComponentEditorPage ()
47                 {
48                 }
49
50 #if NET_2_0
51                 [Browsable (false)]
52                 [EditorBrowsable (EditorBrowsableState.Never)]
53                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
54                 new public virtual bool AutoSize {
55                         get { return base.AutoSize; }
56                         set { base.AutoSize = value; }
57                 }
58 #endif
59
60                 public bool CommitOnDeactivate
61                 {
62                         get { return commitOnDeactivate; }
63                         set { commitOnDeactivate = value; }
64                 }
65
66                 protected IComponent Component {
67                         get { return component; }
68                         set { component = value; }
69                 }
70
71                 [MonoTODO ("Find out what this does.")]
72                 protected override CreateParams CreateParams {
73                         get {
74                                 throw new NotImplementedException ();
75                         }
76                 }
77
78                 protected bool FirstActivate {
79                         get { return firstActivate; }
80                         set { firstActivate = value; }
81                 }
82
83                 public Icon Icon {
84                         get { return icon; }
85                         set { icon = value; }
86                 }
87
88                 protected int Loading {
89                         get { return loading; }
90                         set { loading = value; }
91                 }
92
93                 protected bool LoadRequired {
94                         get { return loadRequired; }
95                         set { loadRequired = value; }
96                 }
97
98                 protected IComponentEditorPageSite PageSite {
99                         get { return pageSite; }
100                         set { pageSite = value; }
101                 }
102
103                 public virtual string Title {
104                         get { return base.Text; }
105                 }
106
107                 public virtual void Activate ()
108                 {
109                         Visible = true;
110                         firstActivate = false;
111                         if (loadRequired) {
112                                 EnterLoadingMode ();
113                                 LoadComponent ();
114                                 ExitLoadingMode ();
115                         }
116                 }
117
118                 public virtual void ApplyChanges ()
119                 {
120                         SaveComponent ();
121                 }
122
123                 public virtual void Deactivate ()
124                 {
125                         Visible = false;
126                 }
127
128                 protected void EnterLoadingMode ()
129                 {
130                         loading++;
131                 }
132
133                 protected void ExitLoadingMode ()
134                 {
135                         loading--;
136                 }
137
138                 public virtual Control GetControl ()
139                 {
140                         return this;
141                 }
142
143                 protected IComponent GetSelectedComponent ()
144                 {
145                         return component;
146                 }
147
148                 protected bool IsFirstActivate ()
149                 {
150                         return firstActivate;
151                 }
152
153                 protected bool IsLoading ()
154                 {
155                         return (loading != 0);
156                 }
157
158                 public virtual bool IsPageMessage (ref Message msg)
159                 {
160                         return PreProcessMessage (ref msg);
161                 }
162
163                 protected abstract void LoadComponent ();
164
165                 [MonoTODO ("Find out what this does.")]
166                 public virtual void OnApplyComplete ()
167                 {
168                 }
169
170                 protected virtual void ReloadComponent ()
171                 {
172                         loadRequired = true;
173                 }
174
175                 protected abstract void SaveComponent ();
176
177                 public virtual void SetComponent (IComponent component)
178                 {
179                         this.component = component;
180                         ReloadComponent ();
181                 }
182
183                 [MonoTODO ("Find out what this does.")]
184                 protected virtual void SetDirty ()
185                 {
186                 }
187
188                 public virtual void SetSite (IComponentEditorPageSite site)
189                 {
190                         pageSite = site;
191                         pageSite.GetControl ().Controls.Add (this);
192
193                 }
194
195                 public virtual void ShowHelp ()
196                 {
197                 }
198
199                 public virtual bool SupportsHelp ()
200                 {
201                         return false;
202                 }
203
204                 #region Public Events
205 #if NET_2_0
206                 [Browsable (false)]
207                 [EditorBrowsable (EditorBrowsableState.Never)]
208                 public new event EventHandler AutoSizeChanged {
209                         add { base.AutoSizeChanged += value; }
210                         remove { base.AutoSizeChanged -= value; }
211                 }
212 #endif
213                 #endregion
214         }
215 }