htmlContainer
Generic group container object for other html++ objects
[Previous] [Main] [Next]


Description
htmlContainer acts a general-purpose, generic, group container for other htmlObject-derived objects. It's commonly used to collect text, tables, forms, or other objects for temporary storage, often as part of an application that needs to assemble various page components before use.  
 
Declaration
#include <dcmicro/htmlpp/contain.h>  
 
Hierarchy
htmlcontainer.gif  
 
See Also
None.  
 
Related Constants/Definitions
None.  
 
Constructors
htmlContainer()  
Constructs an empty object.  
 
htmlContainer( const htmlContainer& rhs )  
Copy constructor.  
 
Destructors
virtual ~htmlContainer()  
Destroys the object.  
 
Member Methods
ClonehtmlObject FAR * Clone() const  
Returns a base-class pointer to a deep copy of the object.  
 
Example Use
 
#include <stdio.h>  
#include <stdlib.h>  
#include <dcmicro/htmlpp/htmlpp.h>  
 
//  Derive a class from htmlTable to implement a style  
//  object comprised of a heading arranged vertically  
//  above a content section. The object is organized  
//  as a 2 row x 1 column table.  
class Style : public htmlTable  
{  
  public :  
   Style( const String& face,   
           int width = 400,  
           int cell_padding = 5,  
           ColorType heading_color = 0xCCCCCC,   
           ColorType content_color = COLOR_DEFAULT ) ;  
} ;  
 
 
Style :: Style  
(  
   const String& face,   
   int           width,   
   int           cell_padding,   
   ColorType     heading_color,   
   ColorType     content_color  
)  
{  
   //  Default font if empty string is specified  
   String font = "arial, helvetica" ;  
   if ( face != "" )  
      font = face ;  
 
   //  Settings for the heading row  
   htmlTableRow  r ;  
   r.BackgroundColor( heading_color )  
   .VAlign( valign_middle )  
   .Align( align_left ) ;  
 
   //  Settings for the rest of the table  
   //  (essentially the content row).  
   BackgroundColor( content_color ) ;  
   Border( 0 ) ;  
   Width( width ) ;  
   CellSpacing( 0 ) ;  
   CellPadding( cell_padding ) ;  
 
   //  Create objects that act as placeholders in  
   //  the rows for the heading and content sections.  
   //  These objects can be replaced by name using the  
   //  standard Replace() method.  
   htmlText  heading_object ;  
   heading_object.Key( "heading" ) ;  
 
   htmlText  content_object ;  
   content_object.Key( "content" ) ;  
 
   //  Output rows to the table  
   *this << ( r << ( htmlFont(font, -1) << htmlBold(heading_object) ) )  
        << ( htmlFont(font, -1) << content_object << htmlParagraph() ) ;  
}  
 
//  Demonstrate use of htmlContainer,   
//  htmlObject::Replace(), and derivation of htmlTable  
//  to create "style" objects (similar to style sheets  
//  in word processors) for outputting consistently  
//  formatted text and data.  
int main( void )  
{  
   htmlCgi   server ;  
   htmlPage  page( "html++ example application" ) ;  
 
   //  Create two objects using identical styles  
   Style c1( "", 125 ) ;  
   Style c1a( c1 ) ;  
 
   //  Create two more objects using different  
   //  style settings  
   Style c2( "", 300, 5, 0xCCCC99, 0xffffcc ) ;  
   Style c3( "", 300, 5, 0xCCCC99, 0xeeeeee ) ;  
 
   //  Use the Replace() method to populate each  
   //  style object.  
   c1.Replace( "heading""News and Information" ) ;  
   c1.Replace( "content""This is the body of the text" ) ;  
     
   c1a.Replace( "heading""Sports and Entertainment" ) ;  
   c1a.Replace( "content""The New York Yankees ended a three game winning streak..." ) ;  
 
   //  Put a lot more data in the c2 and c3 style  
   //  objects. We use the htmlContainer class to  
   //  hold the content, since it acts like any other  
   //  htmlGroup-derived object except that it won't  
   //  affect formatting.  
   htmlContainer content ;  
   content << htmlBold( htmlFont("arial, helvetica", -1, COLOR_RED) << "Top stories this week:" ) ;  
   content << htmlParagraph()   
           << "Yahoo's home page hacked."   
           << htmlParagraph()  
           << "Apple stock enjoys a holiday rebound."  
           << htmlParagraph()  
           << "html++ becomes tool of choice for C++ web developers." ;  
 
   c2.Replace( "heading""In Other News" ) ;  
   c2.Replace( "content", content ) ;  
 
   c3.Replace( "heading""Industry Highlights" ) ;  
   c3.Replace( "content""Call 1-800-775-1073 to learn about the "  
                         "Crusher! Data Compression Toolkits." ) ;  
 
   //  Since the Style object inherits from  
   //  htmlTable, you can add rows to it like  
   //  any other table.  
   c3 << "Additional data can be added using the << operator "  
        "but, unless fonts and other attributes are "  
         "specified, browser defaults will be used." ;  
 
   //  Create a 2x2 table to hold each style object  
   //  in a separate cell. The 2nd column occupies  
   //  two rows.  
   htmlTable      table ;  
   htmlTableCell  column2 ;  
   column2.RowSpan( 2 ) << c1 << c1a ;  
   table << ( htmlTableRow(align_left,valign_top) << c2 << column2 )  
         << ( htmlTableRow(align_left,valign_top) << c3 ) ;  
 
   //  Output the table to the page  
   page << table ;  
 
   server << page ;  
   return 0 ;  
}  
 
Program Output
 
<HTML>  
<HEAD>  
<TITLE>html++ example application</TITLE>  
</HEAD>  
<BODY>  
 
<TABLE>  
 
<TR ALIGN="LEFT" VALIGN="TOP">  
<TD>  
<TABLE BGCOLOR="#ffffcc" BORDER="0" WIDTH="300" CELLSPACING="0" CELLPADDING="5">  
<TR BGCOLOR="#cccc99" VALIGN="MIDDLE" ALIGN="LEFT">  
<TD><FONT FACE="arial, helvetica" SIZE="-1"><B>In Other News</B></FONT></TD></TR>  
<TR><TD><FONT FACE="arial, helvetica" SIZE="-1"><B><FONT FACE="arial, helvetica" SIZE="-1" COLOR="#ff0000">Top stories this week:</FONT></B><P></P>  
Yahoo's home page hacked.<P></P>  
Apple stock enjoys a holiday rebound.<P></P>  
html++ becomes tool of choice for C++ web developers.<P></P>  
</FONT></TD></TR>  
</TABLE>  
</TD>  
 
<TD ROWSPAN="2">  
 
<TABLE BORDER="0" WIDTH="125" CELLSPACING="0" CELLPADDING="5">  
<TR BGCOLOR="#cccccc" VALIGN="MIDDLE" ALIGN="LEFT">  
<TD><FONT FACE="arial, helvetica" SIZE="-1"><B>News and Information</B></FONT></TD></TR>  
<TR><TD><FONT FACE="arial, helvetica" SIZE="-1">This is the body of the text<P></P></FONT></TD></TR>  
</TABLE>  
 
<TABLE BORDER="0" WIDTH="125" CELLSPACING="0" CELLPADDING="5">  
<TR BGCOLOR="#cccccc" VALIGN="MIDDLE" ALIGN="LEFT">  
<TD><FONT FACE="arial, helvetica" SIZE="-1"><B>Sports and Entertainment</B></FONT></TD></TR>  
<TR><TD><FONT FACE="arial, helvetica" SIZE="-1">The New York Yankees ended a three game winning streak...<P></P></FONT></TD></TR>  
</TABLE>  
 
</TD></TR>  
 
<TR ALIGN="LEFT" VALIGN="TOP">  
<TD>  
<TABLE BGCOLOR="#eeeeee" BORDER="0" WIDTH="300" CELLSPACING="0" CELLPADDING="5">  
<TR BGCOLOR="#cccc99" VALIGN="MIDDLE" ALIGN="LEFT"><TD><FONT FACE="arial, helvetica" SIZE="-1"><B>Industry Highlights</B></FONT></TD>  
</TR>  
<TR><TD><FONT FACE="arial, helvetica" SIZE="-1">Call 1-800-775-1073 to learn about the Crusher! Data Compression Toolkits.<P></P>  
</FONT></TD>  
</TR>  
<TR><TD>Additional data can be added using the &lt;&lt; operator but, unless fonts and other attributes are specified, browser defaults will be used.</TD>  
</TR>  
</TABLE>  
</TD>  
</TR>  
</TABLE>  
 
</BODY>  
</HTML>  
 
 
container.gif  


©1998 DC Micro Development. All rights reserved.
No portion of this document may be c opied or reproduced without expressed written consent.
html++ is a trademark of DC Micro Development.