|
htmlTable
Table class | [Previous] [Main] [Next] |
| htmlTable encapsulates the <TABLE></TABLE> tags. It is used to define a table of rows and columns. Use the htmlTableRow class to create rows, the htmlTableHeading class to define row or column headings, and the htmlTableCell class to define data cells. Tables can also contain a caption, created using the htmlTableCaption object or via one of the constructor arguments.
| |
|
| |
| The width of the border surrounding a table can be specified using the Border() method, and the default background color of the table can be controlled using the BackgroundColor() method. Individual rows and cells can have their own background colors as well.
| |
|
| |
| The CellSpacing() method controls the distance between cells, while the CellPadding() method is used to control the distance between the border and each cell's content.
| |
|
| |
| #include <dcmicro/htmlpp/table.h>
| |
|
| |
| |
|
| |
| htmlTableRow, htmlTableCell, htmlTableCaption, htmlTableHeading
| |
|
| |
| typedef enum {
| |
| align_default = 0,
| |
| align_left,
| |
| align_center,
| |
| align_right,
| |
| align_justify
| |
| } Alignment ;
| |
|
| |
| htmlTable()
| |
| Constructs an empty table object.
| |
|
| |
| htmlTable( | const htmlObject& caption,
| |
| VerticalAlignment v_align = valign_default )
| ||
| Constructs an empty table object, setting and aligning the specified caption.
| |
|
| |
| htmlTable( | const String& caption,
| |
| VerticalAlignment v_align = valign_default )
| ||
| Constructs an empty table object, setting and aligning the string caption as the caption.
| |
|
| |
| htmlTable( const htmlTableCaption& caption )
| |
| Constructs an empty table object, using the specified caption object.
| |
|
| |
| htmlTable( const htmlTable& rhs )
| |
| Copy constructor.
| |
|
| |
| virtual ~htmlTable()
| |
| Destroys the object.
| |
|
| |
| = | htmlTable& operator= ( const htmlTable& rhs )
| |
| Replaces the table contents with rhs, and returns a reference to the object.
| |
|
| |
| Add | virtual htmlObject FAR * Add( const htmlObject& element )
| |
| Adds element as a row to the table, and returns a pointer to the new object. If element is a not a htmlTableRow object, if will first be converted to one.
| |
|
| |
| Add | virtual htmlObject FAR * Add( const String& text )
| |
| Adds text as a row to the table, and returns a pointer to the new object.
| |
|
| |
| Align | htmlTable& Align( Alignment align )
| |
| Sets the horizontal alignment of the entire table to align, and returns a reference to the object.
| |
|
| |
|
|
| |
| Align | int Align() const
| |
| Returns the horizontal alignment of the entire table as an integer, or align_default if not set.
| |
|
| |
| BackgoundColor | htmlTable& BackgroundColor(
| |
| ColorType background_color )
| ||
| Set the default background color of the entire table to background_color, then returns a reference to the object. If COLOR_DEFAULT is specified, the browser default color will be used. Corresponds to the BGCOLOR attribute.
| |
|
| |
| BackgoundColor | ColorType BackgroundColor() const
| |
| Returns the current setting for the table's background color, or COLOR_DEFAULT if not set.
| |
|
| |
| Border | htmlTable& Border( int border )
| |
| Sets the table border width to border pixels, and returns a reference to the object. If border is a negative value, the attribute is cleared.
| |
|
| |
| Border | int Border() const
| |
| Returns the table border width in pixels, or zero if not set.
| |
| Caption | htmlTable& Caption( const htmlObject& element )
| |
| Sets the table caption to element, and returns a reference to the object. If element is not already a htmlTableCaption object, it will be converted.
| |
|
| |
| Caption | htmlTable& Caption( const String& text )
| |
| Sets the table caption to text, and returns a reference to the object.
| |
|
| |
| Caption | htmlTableCaption& Caption() const
| |
| Returns a reference to the table caption object.
| |
|
| |
| CellPadding | htmlTable& CellPadding( int padding )
| |
| Sets the cell padding for the table, the distance between the border and each cell's content, to padding pixels and returns a reference to the object. If padding is a negative value, the attribute is cleared.
| |
|
| |
| CellPadding | int CellPadding() const
| |
| Returns the cell padding for the table in pixels, or zero if not set.
| |
|
| |
| CellSpacing | htmlTable& CellSpacing( int spacing )
| |
| Sets the cell spacing for the table, the distance between cells, to spacing pixels and returns a reference to the object. If spacing is a negative value, the attribute is cleared.
| |
|
| |
| CellSpacing | int CellSpacing() const
| |
| Returns the cell spacing for the table in pixels, or zero if not set.
| |
|
| |
| HSpace | htmlTable& HSpace( int pixels )
| |
| Sets the horizontal distance between the left and right edges of the table and any surrounding content to pixels, then returns a reference to the object. If pixels is a negative value, the attribute is cleared.
| |
|
| |
| HSpace | int HSpace() const
| |
| Returns the horizontal space setting in pixels, or zero if not set.
| |
|
| |
| VSpace | htmlTable& VSpace( int pixels )
| |
| Sets the vertical distance between the top and bottom edges of the table and any surrounding content to pixels, then returns a reference to the object. If pixels is a negative value, the attribute is cleared.
| |
|
| |
| VSpace | int VSpace() const
| |
| Returns the vertical space setting in pixels, or zero if not set.
| |
|
| |
| Width | htmlTable& Width( int pixels )
| |
| Sets the table width in pixels to pixels, and returns a reference to the object. If pixels is a negative value, the attribute is cleared.
| |
|
| |
| Width | htmlTable& Width( const String& percent )
| |
| Sets the table width, as a percentage of the display width, to percent, and returns a reference to the object.
| |
|
| |
| Width | int Width() const
| |
| Returns the table width as an integer.
| |
|
| |
| Width | String WidthAsString() const
| |
| Returns the table width as a string.
| |
|
| |
| void Print( ostream& os ) const
| ||
| Outputs the table to os.
| |
|
| |
| Clone | htmlObject FAR * Clone() const
| |
| Returns a base-class pointer to a deep copy of the object.
| |
|
| |
|
| |
| #include <stdio.h>
| |
| #include <stdlib.h>
| |
| #include <dcmicro/htmlpp/htmlpp.h>
| |
|
| |
| // Define a structure to hold data
| |
| // about each employee.
| |
| typedef struct {
| |
| char * name ;
| |
| char * phone ;
| |
| char * city ;
| |
| } EmployeeInfo, * PEmployeeInfo ;
| |
|
| |
| // Create an array of all employees
| |
| EmployeeInfo Employee_Table[] = {
| |
| { "John Smith", "245-7748", "Lexington" },
| |
| { "Larry Jenkins", "233-4456", "Lexington" },
| |
| { "Susan Wall", "294-3345", "Georgetown" }
| |
| } ;
| |
|
| |
| int main( void )
| |
| {
| |
| htmlCgi server ;
| |
| htmlPage page( "html++ example application" ) ;
| |
|
| |
| // Create a table object with a caption
| |
| htmlTable table( "Employee Information" ) ;
| |
|
| |
| // Set the table width to 80% of the display
| |
| table.Width( "80%" ) ;
| |
|
| |
| // Use a border two pixels wide
| |
| table.Border( 2 ) ;
| |
|
| |
| // Loop for each element in the array
| |
| for ( int i = 0 ;
| |
| i < NUMBER_OF_ELEMENTS(Employee_Table) ;
| |
| i++ )
| |
| {
| |
| // Create a pointer to the particular
| |
| // array element for easier access.
| |
| PEmployeeInfo emp = &Employee_Table[i] ;
| |
|
| |
| // Create a row object, specifying that
| |
| // the cells in this row will be centered.
| |
| htmlTableRow row ;
| |
| row.Align( align_center ) ;
| |
|
| |
| // Add each member of the array in a
| |
| // separate cell.
| |
| row << htmlTableCell( emp->name )
| |
| << htmlTableCell( emp->phone )
| |
| << htmlTableCell( emp->city ) ;
| |
|
| |
| // Add the new row to the table.
| |
| table << row ;
| |
| }
| |
|
| |
| // Add the newly constructed table to the page
| |
| page << table ;
| |
|
| |
| server << page ;
| |
| return 0 ;
| |
| }
| |
|
| |
|
| |
| Content-Type: text/html
| |
| <HTML>
| |
| <HEAD>
| |
| <TITLE>html++ example application</TITLE>
| |
| </HEAD>
| |
| <BODY>
| |
| <TABLE WIDTH="80%" BORDER="2">
| |
| <CAPTION>Employee Information</CAPTION>
| |
| <TR ALIGN="CENTER"><TD>John Smith</TD>
| |
| <TD>245-7748</TD>
| |
| <TD>Lexington</TD>
| |
| </TR>
| |
| <TR ALIGN="CENTER"><TD>Larry Jenkins</TD>
| |
| <TD>233-4456</TD>
| |
| <TD>Lexington</TD>
| |
| </TR>
| |
| <TR ALIGN="CENTER"><TD>Susan Wall</TD>
| |
| <TD>294-3345</TD>
| |
| <TD>Georgetown</TD>
| |
| </TR>
| |
| </TABLE>
| |
| </BODY>
| |
| </HTML>
| |
|
| |
| |
