New test.
[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
29 namespace System.Windows.Forms.Design
30 {
31         public abstract class ComponentEditorPage : Panel
32         {
33                 private bool commitOnDeactivate = false;
34                 private IComponent component;
35                 private bool firstActivate = true;
36                 private Icon icon;
37                 private int loading = 0;
38                 private bool loadRequired = false;
39                 private IComponentEditorPageSite pageSite;
40
41                 public ComponentEditorPage ()
42                 {
43                 }
44
45                 public bool CommitOnDeactivate {
46                         get { return commitOnDeactivate; }
47                         set { commitOnDeactivate = value; }
48                 }
49
50                 protected IComponent Component {
51                         get { return component; }
52                         set { component = value; }
53                 }
54
55                 [MonoTODO ("Find out what this does.")]
56                 protected override CreateParams CreateParams {
57                         get {
58                                 throw new NotImplementedException ();
59                         }
60                 }
61
62                 protected bool FirstActivate {
63                         get { return firstActivate; }
64                         set { firstActivate = value; }
65                 }
66
67                 public Icon Icon {
68                         get { return icon; }
69                         set { icon = value; }
70                 }
71
72                 protected int Loading {
73                         get { return loading; }
74                         set { loading = value; }
75                 }
76
77                 protected bool LoadRequired {
78                         get { return loadRequired; }
79                         set { loadRequired = value; }
80                 }
81
82                 protected IComponentEditorPageSite PageSite {
83                         get { return pageSite; }
84                         set { pageSite = value; }
85                 }
86
87                 public virtual string Title {
88                         get { return base.Text; }
89                 }
90
91                 public virtual void Activate ()
92                 {
93                         Visible = true;
94                         firstActivate = false;
95                         if (loadRequired) {
96                                 EnterLoadingMode ();
97                                 LoadComponent ();
98                                 ExitLoadingMode ();
99                         }
100                 }
101
102                 public virtual void ApplyChanges ()
103                 {
104                         SaveComponent ();
105                 }
106
107                 public virtual void Deactivate ()
108                 {
109                         Visible = false;
110                 }
111
112                 protected void EnterLoadingMode ()
113                 {
114                         loading++;
115                 }
116
117                 protected void ExitLoadingMode ()
118                 {
119                         loading--;
120                 }
121
122                 public virtual Control GetControl ()
123                 {
124                         return this;
125                 }
126
127                 protected IComponent GetSelectedComponent ()
128                 {
129                         return component;
130                 }
131
132                 protected bool IsFirstActivate ()
133                 {
134                         return firstActivate;
135                 }
136
137                 protected bool IsLoading ()
138                 {
139                         return (loading != 0);
140                 }
141
142                 public virtual bool IsPageMessage (ref Message msg)
143                 {
144                         return PreProcessMessage (ref msg);
145                 }
146
147                 protected abstract void LoadComponent ();
148
149                 [MonoTODO ("Find out what this does.")]
150                 public virtual void OnApplyComplete ()
151                 {
152                 }
153
154                 protected virtual void ReloadComponent ()
155                 {
156                         loadRequired = true;
157                 }
158
159                 protected abstract void SaveComponent ();
160
161                 public virtual void SetComponent (IComponent component)
162                 {
163                         this.component = component;
164                         ReloadComponent ();
165                 }
166
167                 [MonoTODO ("Find out what this does.")]
168                 protected virtual void SetDirty ()
169                 {
170                 }
171
172                 public virtual void SetSite (IComponentEditorPageSite site)
173                 {
174                         pageSite = site;
175                         pageSite.GetControl ().Controls.Add (this);
176
177                 }
178
179                 public virtual void ShowHelp ()
180                 {
181                 }
182
183                 public virtual bool SupportsHelp ()
184                 {
185                         return false;
186                 }
187         }
188 }