'This code is copyright (C) 2005 by HigherMath and Cal Moffett, all rights reserved.
'It is placed here as a work sample and
may not be used for any other purpose.
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace CCXI_Table
'The CCXI Table control has three style
sections, one each for the
'THEAD, TBODY and TFOOT
sections of the table. Since they are
mostly
'the same, this
class handles the interactions with the property window
'in the IDE for
all three.
'It inherits from the WebControl
in order to make use of its intrinsic
'styles. Some
new elements are added and many are turned off.
'ToolboxItem(False) means do not display this control in the IDE's toolbox.
<ToolboxItem(False)> Public Class CCXItableStyle
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer
Private gobjHorizontalAlign
As New HorizontalAlign
Private gobjVerticalAlign
As New VerticalAlign
Private gstrBackImageUrl As String = ""
'Bindable
means that the property can be bound to a database value
'at runtime.
'Category places the property within a
category in the property window
'if the
category is present.
'The Description will show up at the
bottom of the propery window if this
'property is
selected.
'NotifyParent
enables the parent control to redraw when the property
'is changed.
<Bindable(True), NotifyParentProperty(True), Category("Appearance"),
Description("The background image of the table.")> _
Public
Property [BackImageUrl]() As String
Get
Return gstrBackImageUrl
End Get
Set(ByVal Value As String)
gstrBackImageUrl
= Value
End Set
End Property
'Setting Browsable
to False takes these properties off the list
'because they
are irrelevant. We have to do this because these
'properties
have been inherited from WebControl.
<Browsable(False)> Public Overrides Property AccessKey() As String
Get
End Get
Set(ByVal Value As String)
End Set
End Property
<Browsable(False)> Public Overrides Property ID() As String
Get
End Get
Set(ByVal Value As String)
End Set
End Property
<Browsable(False)> Public Overrides Property BorderColor() As System.Drawing.Color
Get
End Get
Set(ByVal Value As System.Drawing.Color)
End Set
End Property
<Browsable(False)> Public Overrides Property BorderStyle() As System.Web.UI.WebControls.BorderStyle
Get
End Get
Set(ByVal Value As System.Web.UI.WebControls.BorderStyle)
End Set
End Property
<Browsable(False)> Public Overrides Property BorderWidth() As System.Web.UI.WebControls.Unit
Get
End Get
Set(ByVal Value As System.Web.UI.WebControls.Unit)
End Set
End Property
<Browsable(False)> Public Overrides Property Height() As System.Web.UI.WebControls.Unit
Get
End Get
Set(ByVal Value As System.Web.UI.WebControls.Unit)
End Set
End Property
<Browsable(False)> Public Overrides Property Width() As System.Web.UI.WebControls.Unit
Get
End Get
Set(ByVal Value As System.Web.UI.WebControls.Unit)
End Set
End Property
'Now, let's add some styles that are
relevant to tables
<Bindable(True), NotifyParentProperty(True), Category("Misc"),
Description("The horizontal alignment of the cell contents within this
table section.")> _
Public
Property HorizontalAlign() As System.Web.UI.WebControls.HorizontalAlign
Get
Return gobjHorizontalAlign
End Get
Set(ByVal Value As System.Web.UI.WebControls.HorizontalAlign)
gobjHorizontalAlign
= Value
End Set
End Property
<Bindable(True), NotifyParentProperty(True), Category("Misc"),
Description("The vertical alignment of the cell contents within this table
section.")> _
Public
Property VerticalAlign() As System.Web.UI.WebControls.VerticalAlign
Get
Return gobjVerticalAlign
End Get
Set(ByVal Value As System.Web.UI.WebControls.VerticalAlign)
gobjVerticalAlign
= Value
End Set
End Property
'Since our control does a much better
job than MIcrosoft's table control
'at
displaying its layout at design time, we will notify the designer
'of these
property changes so that the layout can be updated for the user
'to see.
<NotifyParentProperty(True)> Public Overrides Property BackColor() As System.Drawing.Color
Get
Return MyBase.BackColor
End Get
Set(ByVal Value As System.Drawing.Color)
MyBase.BackColor
= Value
End Set
End Property
<NotifyParentProperty(True)> Public Overrides Property CssClass() As String
Get
Return MyBase.CssClass
End Get
Set(ByVal Value As String)
MyBase.CssClass
= Value
End Set
End Property
<NotifyParentProperty(True)> Public Overrides Property Enabled() As
Boolean
Get
Return MyBase.Enabled
End Get
Set(ByVal Value As Boolean)
MyBase.Enabled
= Value
End Set
End Property
<NotifyParentProperty(True)> Public Overrides Property EnableViewState() As Boolean
Get
Return MyBase.EnableViewState
End Get
Set(ByVal Value As Boolean)
MyBase.EnableViewState
= Value
End Set
End Property
<NotifyParentProperty(True)> Public Overrides Property ForeColor() As System.Drawing.Color
Get
Return MyBase.ForeColor
End Get
Set(ByVal Value As System.Drawing.Color)
MyBase.ForeColor
= Value
End Set
End Property
End Class
'The CCXItableElement
class handles each of the table parts:
'TBODY, THEAD and
TFOOT. It inherits from the Table
control
'because each
table element, in fact, functions as a miniature
'table.
Friend Class
CCXItableElement
Inherits System.Web.UI.WebControls.Table
Implements INamingContainer
Public garyFieldNames
As New ArrayList
Private gobjTableStyle
As New CCXItableStyle
Private gpropTableTagKey As HtmlTextWriterTag = HtmlTextWriterTag.Tbody
'This is where the table style (above)
is attached to each
'of the table
elements.
<NotifyParentProperty(True)> Public ReadOnly
Property TableStyle()
As CCXItableStyle
Get
Return gobjTableStyle
End Get
End Property
'When the table element is rendered as
HTML, this is the tag that is output.
'It defaults to TBODY but should be
changed when this control is
'initialized
to THEAD or TFOOT if appropriate.
'We cannot change the overridden TagKey property to not be readonly
so
'we must
invent our own equivalent property and store the value locally.
'And we must override the 2 related readonly properties to return our
'local value.
Public Property
TableTagKey() As HtmlTextWriterTag
Get
Return gpropTableTagKey
End Get
Set(ByVal Value As HtmlTextWriterTag)
gpropTableTagKey
= Value
End Set
End Property
Protected Overrides ReadOnly
Property TagKey() As HtmlTextWriterTag
Get
Return gpropTableTagKey
End Get
End Property
Protected Overrides ReadOnly
Property TagName() As String
Get
Return TagKey.ToString
End Get
End Property
'When the control is rendered as HTML
either for ASP or for the client-side
'XML data island, this routine will
"gather" all the relevant attributes
'and styles
and output appropriate HTML. For tables, most of these
'attributes
are same when individual cells or rows or the entire table
'is being
rendered. However, there are a few specific to table, row or cell.
'Thus one of the optional parameters
must be supplied for whichever of these
'entities is
being rendered.
Private Sub
GatherAttributes(ByVal
output As System.Web.UI.HtmlTextWriter,
_
ByVal objControl As System.Web.UI.WebControls.WebControl,
_
Optional
ByVal objTableStyle As CCXItableStyle = Nothing, _
Optional
ByVal objTableRow As WebControls.TableRow = Nothing,
_
Optional
ByVal objTableCell As WebControls.TableCell = Nothing)
With objControl
Dim strColor
As String =
""
Dim strFontFamilies
As String = Join(.Font.Names, ",")
Dim strFontSize
As String =
""
Dim strTextDecoration
As String =
""
Select Case .Font.Size.Type
Case FontSize.AsUnit
strFontSize
= .Font.Size.Unit.ToString
Case FontSize.Large
strFontSize
= "large"
Case FontSize.Larger
strFontSize
= "larger"
Case FontSize.Medium
strFontSize
= "medium"
Case FontSize.Small
strFontSize
= "small"
Case FontSize.Smaller
strFontSize
= "smaller"
Case FontSize.XLarge
strFontSize
= "x-large"
Case FontSize.XSmall
strFontSize
= "x-small"
Case FontSize.XXLarge
strFontSize
= "xx-large"
Case FontSize.XXSmall
strFontSize
= "xx-small"
Case Else
strFontSize = ""
End Select
If strFontSize
<> "" Then
output.AddStyleAttribute(HtmlTextWriterStyle.FontSize, strFontSize)
End If
If .Font.Names.Length
> 0 AndAlso strFontFamilies.Length > 0 Then
output.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, strFontFamilies)
End If
If .Font.Strikeout
Then strTextDecoration
&= " line-through"
If .Font.Overline
Then strTextDecoration
&= " overline"
If .Font.Underline
Then strTextDecoration
&= " underline"
If strTextDecoration
<> "" Then
output.AddStyleAttribute(HtmlTextWriterStyle.TextDecoration,
strTextDecoration)
End If
If .Font.Italic
Then
output.AddStyleAttribute(HtmlTextWriterStyle.FontStyle,
"italic")
End If
If .Font.Bold
Then
output.AddStyleAttribute(HtmlTextWriterStyle.FontWeight,
"bold")
End If
With .ForeColor
If Not .IsEmpty Then
strColor
= IIf(.IsNamedColor, .Name,
_
"#"
& Hex(.R).PadLeft(2,
"0") & Hex(.G).PadLeft(2,
"0") & Hex(.B).PadLeft(2,
"0"))
output.AddStyleAttribute(HtmlTextWriterStyle.Color, strColor)
End If
End With
If Not
.AccessKey Is Nothing Then
With .AccessKey
If .Length > 0 Then
output.AddAttribute(HtmlTextWriterAttribute.Accesskey,
.ToString)
End If
End With
End If
With .Height
If Not .IsEmpty Then
output.AddStyleAttribute(HtmlTextWriterStyle.Height, .ToString)
End If
End With
With .Width
If Not .IsEmpty Then
output.AddStyleAttribute(HtmlTextWriterStyle.Width, .ToString)
End If
End With
With .BackColor
If Not .IsEmpty Then
strColor
= IIf(.IsNamedColor, .Name,
_
"#"
& Hex(.R).PadLeft(2,
"0") & Hex(.G).PadLeft(2,
"0") & Hex(.B).PadLeft(2,
"0"))
output.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor,
strColor)
End If
End With
With .BorderColor
If Not .IsEmpty Then
strColor
= IIf(.IsNamedColor, .Name,
_
"#"
& Hex(.R).PadLeft(2,
"0") & Hex(.G).PadLeft(2,
"0") & Hex(.B).PadLeft(2,
"0"))
output.AddStyleAttribute(HtmlTextWriterStyle.BorderColor, strColor)
End If
End With
If .BorderStyle
<> BorderStyle.NotSet Then
output.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle,
.BorderStyle.ToString)
End If
With .BorderWidth
If Not .IsEmpty Then
output.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth,
.ToString)
End If
End With
.CssClass = .CssClass.Trim
If .CssClass.Length
> 0 Then
output.AddAttribute(HtmlTextWriterAttribute.Class, .CssClass)
End If
.ToolTip = .ToolTip.Trim
If .ToolTip.Length
> 0 Then
output.AddAttribute(HtmlTextWriterAttribute.Title,
.ToolTip)
End If
If .TabIndex
> 0 Then
output.AddAttribute(HtmlTextWriterAttribute.Tabindex,
.TabIndex.ToString)
End If
If Not
.Enabled Then
output.AddAttribute(HtmlTextWriterAttribute.Disabled,
"disabled")
End If
End With
If Not
objTableStyle Is Nothing Then
With objTableStyle
.BackImageUrl = .BackImageUrl.Trim
If .BackImageUrl.Length
> 0 Then
output.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "url("
& objTableStyle.BackImageUrl & ")")
End If
With .HorizontalAlign
If objTableStyle.HorizontalAlign
= HorizontalAlign.NotSet Then
If Me.TagKey <> HtmlTextWriterTag.Tbody Then
output.AddAttribute(HtmlTextWriterAttribute.Align, .Center.ToString)
End If
Else
output.AddAttribute(HtmlTextWriterAttribute.Align, .ToString)
End If
End With
With .VerticalAlign
If objTableStyle.VerticalAlign
= VerticalAlign.NotSet Then
If Me.TagKey <> HtmlTextWriterTag.Tbody Then
output.AddAttribute(HtmlTextWriterAttribute.Valign, .Middle.ToString)
End If
Else
output.AddAttribute(HtmlTextWriterAttribute.Valign, .ToString)
End If
End With
End With
End If
If Not
objTableRow Is Nothing Then
With objTableRow
With .HorizontalAlign
If objTableRow.HorizontalAlign
= HorizontalAlign.NotSet Then
If Me.TagKey <> HtmlTextWriterTag.Tbody Then
output.AddAttribute(HtmlTextWriterAttribute.Align, .Center.ToString)
End If