1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
//
// This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
// project.
//
// Copyright (C) 1998-2012 OpenLink Software
//
// This project is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; only version 2 of the License, dated June 1991.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
//
//
// tabcontrol2.cs: sample user control.
//
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace Mono.Controls
{
[ParseChildren(false)]
public class TabContent : Control
{
string label;
public TabContent ()
{
}
protected override void Render (HtmlTextWriter writer)
{
if (this.Parent.GetType () != typeof (Tabs2))
throw new ApplicationException ("TabContent can only be rendered inside Tabs2");
base.Render (writer);
}
public string Label
{
get {
if (label == null)
return "* You did not set a label for this control *";
return label;
}
set {
label = value;
}
}
}
[ParseChildren(false)]
public class Tabs2 : UserControl, IPostBackEventHandler, IParserAccessor
{
Hashtable localValues;
ArrayList titles;
public Tabs2 ()
{
titles = new ArrayList ();
localValues = new Hashtable ();
}
private void AddTab (TabContent tabContent)
{
string title = tabContent.Label;
Controls.Add (tabContent);
titles.Add (title);
if (Controls.Count == 1)
CurrentTabName = title;
}
protected override object SaveViewState ()
{
return new Triplet (base.SaveViewState (), localValues, titles);
}
protected override void LoadViewState (object savedState)
{
if (savedState != null) {
Triplet saved = (Triplet) savedState;
base.LoadViewState (saved.First);
localValues = saved.Second as Hashtable;
titles = saved.Third as ArrayList;
}
}
protected override void OnPreRender (EventArgs e)
{
base.OnPreRender (e);
Page.GetPostBackEventReference (this);
foreach (TabContent content in Controls) {
if (content.Label == CurrentTabName)
content.Visible = true;
else
content.Visible = false;
}
}
void IPostBackEventHandler.RaisePostBackEvent (string argument)
{
if (argument == null)
return;
if (CurrentTabName != argument)
CurrentTabName = argument;
}
protected override ControlCollection CreateControlCollection ()
{
return new ControlCollection (this);
}
protected override void AddParsedSubObject (object obj)
{
if (obj is LiteralControl)
return; // Ignore plain text
if (!(obj is TabContent))
throw new ArgumentException ("Tabs2 Only allows TabContent controls inside.",
"obj");
AddTab ((TabContent) obj);
}
void IParserAccessor.AddParsedSubObject (object obj)
{
AddParsedSubObject (obj);
}
private void RenderBlank (HtmlTextWriter writer)
{
writer.WriteBeginTag ("td");
writer.WriteAttribute ("bgcolor", TabBackColor);
writer.WriteAttribute ("width", BlankWidth.ToString ());
writer.Write (">");
writer.Write (" ");
writer.WriteEndTag ("td");
}
private void RenderTabs (HtmlTextWriter writer)
{
writer.WriteBeginTag ("tr");
writer.Write (">");
writer.WriteLine ();
if (titles.Count > 0)
RenderBlank (writer);
string currentTab = CurrentTabName;
string key;
int end = titles.Count;
for (int i = 0; i < end; i++) {
key = (string) titles [i];
writer.WriteBeginTag ("td");
writer.WriteAttribute ("width", Width.ToString ());
writer.WriteAttribute ("align", Align.ToString ());
if (key == currentTab) {
writer.WriteAttribute ("bgcolor", CurrentTabBackColor);
writer.Write (">");
writer.WriteBeginTag ("font");
writer.WriteAttribute ("color", CurrentTabColor);
writer.Write (">");
writer.Write (key);
writer.WriteEndTag ("font");
} else {
writer.WriteAttribute ("bgcolor", TabBackColor);
writer.Write (">");
writer.WriteBeginTag ("a");
string postbackEvent = String.Empty;
if (Page != null)
postbackEvent = Page.GetPostBackClientHyperlink (
this, key);
writer.WriteAttribute ("href", postbackEvent);
writer.Write (">");
writer.Write (key);
writer.WriteEndTag ("a");
}
writer.WriteEndTag ("td");
RenderBlank (writer);
writer.WriteLine ();
}
writer.WriteEndTag ("tr");
writer.WriteBeginTag ("tr");
writer.Write (">");
writer.WriteLine ();
writer.WriteBeginTag ("td");
writer.WriteAttribute ("colspan", "10");
writer.WriteAttribute ("bgcolor", CurrentTabBackColor);
writer.Write (">");
writer.WriteBeginTag ("img");
writer.WriteAttribute ("width", "1");
writer.WriteAttribute ("height", "1");
writer.WriteAttribute ("alt", "");
writer.Write (">");
writer.WriteEndTag ("td");
writer.WriteEndTag ("tr");
}
protected override void Render (HtmlTextWriter writer)
{
if (Page != null)
Page.VerifyRenderingInServerForm (this);
if (Controls.Count == 0)
return;
writer.WriteBeginTag ("table");
writer.WriteAttribute ("border", "0");
writer.WriteAttribute ("cellpadding", "0");
writer.WriteAttribute ("cellspacing", "0");
writer.Write (">");
writer.WriteBeginTag ("tbody");
writer.Write (">");
writer.WriteLine ();
RenderTabs (writer);
writer.WriteEndTag ("tbody");
writer.WriteEndTag ("table");
writer.WriteLine ();
base.RenderChildren (writer);
}
public int BlankWidth
{
get {
object o = localValues ["BlankWidth"];
if (o == null)
return 15;
return (int) o;
}
set {
localValues ["BlankWidth"] = value;
}
}
public int Width
{
get {
object o = localValues ["Width"];
if (o == null)
return 120;
return (int) o;
}
set {
localValues ["Width"] = value;
}
}
public string Align
{
get {
object o = localValues ["Align"];
if (o == null)
return "center";
return (string) o;
}
set {
localValues ["Align"] = value;
}
}
public string CurrentTabName
{
get {
object o = localValues ["CurrentTabName"];
if (o == null)
return String.Empty;
return (string) localValues ["CurrentTabName"];
}
set {
localValues ["CurrentTabName"] = value;
}
}
public string CurrentTabColor
{
get {
object o = localValues ["CurrentTabColor"];
if (o == null)
return "#FFFFFF";
return (string) localValues ["CurrentTabColor"];
}
set {
localValues ["CurrentTabColor"] = value;
}
}
public string CurrentTabBackColor
{
get {
object o = localValues ["CurrentTabBackColor"];
if (o == null)
return "#3366CC";
return (string) localValues ["CurrentTabBackColor"];
}
set {
localValues ["CurrentTabBackColor"] = value;
}
}
public string TabBackColor
{
get {
object o = localValues ["TabBackColor"];
if (o == null)
return "#efefef";
return (string) localValues ["TabBackColor"];
}
set {
localValues ["TabBackColor"] = value;
}
}
}
}
|