2006-11-28 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls.WebParts / WebPart.cs
1 //
2 // System.Web.UI.WebControls.WebParts.Part
3 //
4 // Authors: Chris Toshok <toshok@novell.com>
5 //
6 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
15 // 
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
18 // 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 //
27
28 #if NET_2_0
29 using System;
30
31 namespace System.Web.UI.WebControls.WebParts
32 {
33         public abstract class WebPart : Part, IWebPart, IWebActionable
34 #if IWebEditableInterface
35           , IWebEditable
36 #endif
37         {
38                 [Flags]
39                 enum Allow {
40                         Close      = 0x01,
41                         Connect    = 0x02,
42                         Edit       = 0x04,
43                         Hide       = 0x08,
44                         Minimize   = 0x10,
45                         ZoneChange = 0x20
46                 }
47
48
49                 WebPartVerbCollection verbs = new WebPartVerbCollection();
50                 Allow allow;
51                 string auth_filter;
52                 string catalog_icon_url;
53                 WebPartExportMode exportMode = WebPartExportMode.None;
54                 string  titleIconImageUrl,       
55                                 titleUrl,                       
56                                 helpUrl;
57                 bool isStatic, hidden, isClosed, hasSharedData, hasUserData;
58                 WebPartHelpMode helpMode = WebPartHelpMode.Navigate;
59                 int zoneIndex ;
60
61                 protected WebPart ()
62                 {
63                         verbs = new WebPartVerbCollection();
64                         allow = Allow.Close | Allow.Connect | Allow.Edit | Allow.Hide | Allow.Minimize | Allow.ZoneChange;
65                         auth_filter = "";
66                         catalog_icon_url = "";
67                         titleIconImageUrl       = string.Empty;
68                         titleUrl                = string.Empty;
69                         helpUrl                 = string.Empty;
70                         isStatic                = false;
71                         hasUserData             = false;
72                         hasSharedData   = false;
73                         hidden = false;
74                         isClosed = false;
75                 }
76
77 #if IWebEditableInterface
78                 [MonoTODO("Not implemented")]
79                 public virtual EditorPartCollection CreateEditorParts ()
80                 {
81                         throw new NotImplementedException ();
82                 }
83 #endif
84
85                 [MonoTODO("Not implemented")]
86                 protected void SetPersonalizationDirty ()
87                 {
88                         throw new NotImplementedException ();
89                 }
90
91                 [MonoTODO("Not implemented")]
92                 public static void SetPersonalizationDirty (Control control)
93                 {
94                         throw new NotImplementedException ();
95                 }
96
97                 protected override void TrackViewState ()
98                 {
99                         base.TrackViewState();
100
101                         foreach (IStateManager verb in verbs) {
102                                 verb.TrackViewState();
103                         }
104                 }
105
106                 protected internal virtual void OnClosing (EventArgs e)
107                 { /* no base class implementation */ }
108
109                 protected internal virtual void OnConnectModeChanged (EventArgs e)
110                 { /* no base class implementation */ }
111
112                 protected internal virtual void OnDeleting (EventArgs e)
113                 { /* no base class implementation */ }
114
115                 protected internal virtual void OnEditModeChanged (EventArgs e)
116                 { /* no base class implementation */ }
117
118                 [WebSysDescriptionAttribute ("")]
119                 [WebCategoryAttribute ("Behavior")]
120                 public virtual bool AllowClose 
121                 {
122                         get {
123                                 return (allow & Allow.Close) != 0;
124                         }
125                         set {
126                                 if (value)
127                                         allow |= Allow.Close;
128                                 else
129                                         allow &= ~Allow.Close;
130                         }
131                 }
132
133                 [WebSysDescriptionAttribute ("")]
134                 [WebCategoryAttribute ("Behavior")]
135                 public virtual bool AllowConnect 
136                 {
137                         get {
138                                 return (allow & Allow.Connect) != 0;
139                         }
140                         set {
141                                 if (value)
142                                         allow |= Allow.Connect;
143                                 else
144                                         allow &= ~Allow.Connect;
145                         }
146                 }
147
148                 [WebSysDescriptionAttribute ("")]
149                 [WebCategoryAttribute ("Behavior")]
150                 public virtual bool AllowEdit 
151                 {
152                         get {
153                                 return (allow & Allow.Edit) != 0;
154                         }
155                         set {
156                                 if (value)
157                                         allow |= Allow.Edit;
158                                 else
159                                         allow &= ~Allow.Edit;
160                         }
161                 }
162
163                 [WebSysDescriptionAttribute ("")]
164                 [WebCategoryAttribute ("Behavior")]
165                 public virtual bool AllowHide 
166                 {
167                         get {
168                                 return (allow & Allow.Hide) != 0;
169                         }
170                         set {
171                                 if (value)
172                                         allow |= Allow.Hide;
173                                 else
174                                         allow &= ~Allow.Hide;
175                         }
176                 }
177
178                 [WebSysDescriptionAttribute ("")]
179                 [WebCategoryAttribute ("Behavior")]
180                 public virtual bool AllowMinimize 
181                 {
182                         get {
183                                 return (allow & Allow.Minimize) != 0;
184                         }
185                         set {
186                                 if (value)
187                                         allow |= Allow.Minimize;
188                                 else
189                                         allow &= ~Allow.Minimize;
190                         }
191                 }
192
193                 [WebSysDescriptionAttribute ("")]
194                 [WebCategoryAttribute ("Behavior")]
195                 public virtual bool AllowZoneChange 
196                 {
197                         get {
198                                 return (allow & Allow.ZoneChange) != 0;
199                         }
200                         set {
201                                 if (value)
202                                         allow |= Allow.ZoneChange;
203                                 else
204                                         allow &= ~Allow.ZoneChange;
205                         }
206                 }
207
208                 public virtual string AuthorizationFilter 
209                 {
210                         get {
211                                 return auth_filter;
212                         }
213                         set {
214                                 auth_filter = value;
215                         }
216                 }
217
218                 public virtual string CatalogIconImageUrl 
219                 {
220                         get {
221                                 return catalog_icon_url;
222                         }
223                         set {
224                                 catalog_icon_url = value;
225                         }
226                 }
227
228                 public override PartChromeState ChromeState 
229                 {
230                         get {
231                                 return base.ChromeState;
232                         }
233                         set {
234                                 base.ChromeState = value;
235                         }
236                 }
237
238                 public override PartChromeType ChromeType 
239                 {
240                         get {
241                                 return base.ChromeType;
242                         }
243                         set {
244                                 base.ChromeType = value;
245                         }
246                 }
247
248                 [MonoTODO("Not implemented")]
249                 public string ConnectErrorMessage 
250                 {
251                         get {
252                                 return "";
253                         }
254                 }
255
256                 public override string Description 
257                 {
258                         get {
259                                 return base.Description;
260                         }
261                         set {
262                                 base.Description = value;
263                         }
264                 }
265
266                 [MonoTODO("Not implemented")]
267                 /* msdn2 lists this as an override, but it doesn't appear to work with our implementation */
268                 public /*override*/ ContentDirection Direction 
269                 {
270                         get {
271                                 throw new NotImplementedException ();
272                         }
273                         set {
274                                 throw new NotImplementedException ();
275                         }
276                 }
277
278                 public string DisplayTitle 
279                 {
280                         get {
281                                 return "Untitled";
282                         }
283                 }
284
285                 public virtual WebPartExportMode ExportMode 
286                 {
287                         get {
288                                 return exportMode;
289                         }
290                         set {
291                                 exportMode = value;
292                         }
293                 }
294
295                 public bool HasSharedData 
296                 {
297                         get {
298                                 return hasSharedData;
299                         }
300                 }
301
302                 public bool HasUserData 
303                 {
304                         get {
305                                 return hasUserData;
306                         }
307                 }
308
309                 public override Unit Height 
310                 {
311                         get {
312                                 return base.Height;
313                         }
314                         set {
315                                 base.Height = value;
316                         }
317                 }
318
319                 public virtual WebPartHelpMode HelpMode 
320                 {
321                         get {
322                                 return helpMode;
323                         }
324                         set {
325                                 helpMode = value;
326                         }
327                 }
328
329                 public virtual string HelpUrl 
330                 {
331                         get {
332                                 return helpUrl;
333                         }
334                         set {
335                                 helpUrl = value;
336                         }
337                 }
338
339                 public virtual bool Hidden 
340                 {
341                         get {
342                                 return hidden;
343                         }
344                         set {
345                                 hidden = value;
346                         }
347                 }
348
349                 public virtual string ImportErrorMessage 
350                 {
351                         get {
352                                 return ViewState.GetString("ImportErrorMessage", "Cannot import this Web Part.");
353                         }
354                         set {
355                                 ViewState ["ImportErrorMessage"] = value;
356                         }
357                 }
358
359                 public bool IsClosed 
360                 {
361                         get {
362                                 return isClosed;
363                         }
364                 }
365
366                 public bool IsShared 
367                 {
368                         get {
369                                 return false;
370                         }
371                 }
372
373                 public bool IsStandalone 
374                 {
375                         get {
376                                 return true;
377                         }
378                 }
379
380                 public bool IsStatic 
381                 {
382                         get {
383                                 return isStatic;
384                         }
385                 }
386
387                 public virtual string Subtitle 
388                 {
389                         get {
390                                 return string.Empty;
391                         }
392                 }
393
394                 public override string Title 
395                 {
396                         get {
397                                 return base.Title;
398                         }
399                         set {
400                                 base.Title = value;
401                         }
402                 }
403
404                 public virtual string TitleIconImageUrl 
405                 {
406                         get {
407                                 return titleIconImageUrl;
408                         }
409                         set {
410                                 titleIconImageUrl = value;
411                         }
412                 }
413
414                 public virtual string TitleUrl 
415                 {
416                         get {
417                                 return titleUrl;
418                         }
419                         set {
420                                 titleUrl = value;
421                         }
422                 }
423
424                 public virtual WebPartVerbCollection Verbs 
425                 {
426                         get {
427                                 return verbs;
428                         }
429                 }
430
431 #if IWebEditableInterface
432                 [MonoTODO("Not implemented")]
433                 public virtual object WebBrowsableObject 
434                 {
435                         get {
436                                 throw new NotImplementedException ();
437                         }
438                 }
439 #endif
440
441 #if notyet
442                 [MonoTODO("Not implemented")]
443                 protected WebPartManager WebPartManager 
444                 {
445                         get {
446                                 throw new NotImplementedException ();
447                         }
448                 }
449 #endif
450
451                 public override Unit Width 
452                 {
453                         get {
454                                 return base.Width;
455                         }
456                         set {
457                                 base.Width = value;
458                         }
459                 }
460
461 #if notyet
462                 [MonoTODO("Not implemented")]
463                 public WebPartZoneBase Zone 
464                 {
465                         get {
466                                 throw new NotImplementedException ();
467                         }
468                 }
469 #endif
470
471                 public int ZoneIndex 
472                 {
473                         get {
474                                 return zoneIndex;
475                         }
476                 }
477         }
478
479 }
480
481 #endif