htmlImage
Inline image class
[Previous] [Main] [Next]


Description
htmlImage encapsulates the <IMG SRC> tag. It is used to specify images to be displayed in a document. An image can be a plain image that it simply displayed, or it can contain an embedded URL that is opened when the user clicks on it. An image can also be an image map, containing one or more clickable areas associated with different URL's.  
 
The Image() method specifies the location of the image file to display. You can also specify a low-resolution version of the image using the LowResImage() method. On some browsers, including Netscape Navigator, the low-resolution image will load and display first to give the user something to see while the larger image is loaded.  
 
Some browsers cannot display certain types of images. You can use the AlternateText() method to specify text that will be displayed in lieu of the image in such cases. Many browsers will temporarily display the alternate text while the image loads.  
 
The Height() and Width() methods control the onscreen image dimensions. If the dimensions are specified, the browser will display a placeholder of the appropriate size while loading other page elements instead of waiting for the image to load first.  
 
If using client-side image maps, an image map object (created using htmlImageMap) can be specified by name using the UseMap() method. If UseMap() is used, the image map object must be explicitly added to the page in which the image appears.  
 
The htmlImage class contains an htmlImageMap object has a private member variable. If the member variable contains image map information, it's contents will be output along with the image during execution. For convenience, the << insertion operator and Add() methods are overloaded to allow htmlImageMap or htmlArea objects to be directly added to the image without using UseMap(), and without the need to explicitly add the image map to the page. If the image map name has not been assigned (via htmlImageMap::Name() ), htmlImage will generate a unique name for the map based on an internally incremented counter.  
 
Declaration
#include <dcmicro/htmlpp/image.h>  
 
Hierarchy
htmlimage.gif  
 
See Also
htmlImageMap, htmlArea  
 
Related Constants/Definitions
typedef enum {  
   align_default = 0,  
   align_left,  
   align_center,  
   align_right,  
   align_justify  
} Alignment ;  
 
typedef enum {  
   valign_default = 0,  
   valign_top = align_justify + 1,  
   valign_middle,  
   valign_bottom,  
   valign_baseline  
} VerticalAlignment ;  
 
Constructors
htmlImage()  
Constructs an empty object.  
 
htmlImage( const String& image_url )  
Constructs an image object for the specified image_url.  
 
htmlImage( const String& image_url, const String& alternate_text )  
Constructs an image object for the specified image_url, including alternate_text as the text alternative.  
 
htmlImage( const String& image_url, Alignment h_align )  
Constructs an image object for the specified image_url, horizontally aligned as specified.  
 
htmlImage( const String& image_url, VerticalAlignment v_align )  
Constructs an image object for the specified image_url, vertically aligned as specified.  
 
htmlImage(const String& image_url,  
   const String& alternate_text,  
   Alignment h_align )  
Constructs an image object for the specified image_url, horizontally aligned as specified, including alternate_text as the text alternative.  
 
htmlImage(const String& image_url,  
   const String& alternate_text,  
   VerticalAlignment v_align )  
Constructs an image object for the specified image_url, vertically aligned as specified, including alternate_text as the text alternative.  
 
htmlImage( const htmlImage& rhs )  
Copy constructor.  
 
Destructor
virtual ~htmlImage()  
Destroys the object.  
 
Member Methods
=      htmlImage& operator=( const htmlImage& rhs )  
Replaces the contents with rhs and returns a pointer to the object.  
 
<<      htmlImage& operator<< ( const htmlImageMap& map )  
Replaces the internal private htmlImageMap object for the image with map and returns a reference to the image. This is an alternative to using UseMap() to specifiy an image map by name. Once added, map does not need to be added separately to the page.  
 
<<      htmlImage& operator<< ( const htmlArea& area )  
Adds the area object to the internal private htmlImageMap object for the image and returns a reference to the image. You can use this method to add htmlArea objects directly to an image without an intermediate htmlImageMap object.  
 
Add      virtual htmlObject FAR * Add( const htmlImageMap& map )  
Replaces the internal private htmlImageMap object for the image with map and returns a pointer to the object. This is an alternative to using UseMap() to specifiy an image map by name. Once added, map does not need to be added separately to the page.  
 
Add      virtual htmlObject FAR * Add( const htmlArea& area )  
Adds the area object to the internal private htmlImageMap object for the image and returns a pointer to the object. You can use this method to add htmlArea objects directly to an image without an intermediate htmlImageMap object.  
 
Image   htmlImage& Image( const String& image_url )  
Set the source for the image to image_url, and returns a reference to the object.  
 
Image   String Image() const  
Returns the image source URL.  
 
LowResImagehtmlImage& LowResImage( const String& image_url )  
Sets the low-resolution image source to image_url, and returns a reference to the object.  
 
LowResImageString LowResImage() const  
Returns the low-resolution image source URL, or an empty string if not set.  
 
AlternateText   htmlImage& AlternateText( const String& alternate_text )  
Sets the text alternative for the image to alternate_text, and returns a reference to the object.  

AlternateText   String AlternateText() const  
Retruns the alternative text for the image, or an empty string if not set.  
 
Align      htmlImage& Align( Alignment h_align )  
Sets the horizontal alignment for the image to h_align, and returns a reference to the object. Align() and VAlign() are mutually exclusive.  

VAlign   htmlImage& VAlign( VerticalAlignment v_align )  
Sets the vertical alignment for the image to v_align, and returns a reference to the object. Align() and VAlign() are mutually exclusive.  

Align      int Align() const  
Returns the horizontal or vertical alignment for the image as an integer, or align_default if not set.  

Height   htmlImage& Height( int pixels )  
Sets the image height in pixels, and returns a reference to the object. If pixels is a negative value, the attribute is cleared.  

Height   int Height() const  
Returns the image height in pixels, or zero if not set.  
 
Width   htmlImage& Width( int pixels )  
Sets the image width in pixels, and returns a reference to the object. If pixels is a negative value, the attribute is cleared.  

Width   int Width() const  
Returns the image width in pixels, or zero if not set.  
 
Border   htmlImage& Border( int pixels )  
Sets the size of the image border to pixels, and returns a reference to the object. If pixels is a negative value, the attribute is cleared.  

Border   int Border() const  
Returns the image border size in pixels, or zero if not set.  
 
HSpace   htmlImage& HSpace( int pixels )  
Sets the horizontal space between the image and it's surroundings, and 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   htmlImage& VSpace( int pixels )  
Sets the vertical space between the image and it's surroundings, and 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.  

UseMap   htmlImage& UseMap( const String& name )  
Sets the client-side image map to name, and returns a reference to the object. The image map specified by name must reside on the same page that contains the image object. Image maps are created using the htmlImageMap class. As an alternative, you can use the << insertion operator to add an htmlImageMap object directly to the image, without having to explicitly add the image map to the page.  

UseMap   htmlImage& UseMap( const String& url, const String& name )  
Sets the client-side image map to name within the specified url, and returns a reference to the object.  
 
Name   htmlImage& Name( const String& name )  
Sets the name by which JavaScript can refer to the image to name, and returns a reference to the object.  
 
Name   String Name() const  
Returns the image name as a string.  
 
Clone   htmlObject FAR * Clone() const  
Returns a base-class pointer to a deep copy of the object.  
 
Print      void Print( ostream& os ) const  
Outputs the object to os.  
 
Example Use
 
#include <stdio.h>  
#include <stdlib.h>  
#include <dcmicro/htmlpp/htmlpp.h>  
 
int main( void )  
{  
   htmlCgi   server ;  
   htmlPage  page( "html++ example application" ) ;  
 
   htmlParagraph  p ;  
 
   //  Create a simple hyperlink to another page  
   page << htmlHyperLink( "http://www.dcmicro.com""Click here" )  
        << " to jump to DC Micro Development's home page."  
        << p ;  
 
   //  Create a hyperlinked image  
   page << "Click on the image "  
       << htmlHyperLink( "http://www.dcmicro.com/crusher/get_crusher.html",  
          htmlImage( "http://www.dcmicro.com/images/gc.gif",   
                          "Download demo" ) )  
      << " to download a demo of Crusher."  
      << p ;  
 
   //  Create a hyperlink to a specific location  
   //  within another page  
   page << "To find out about annual support options, "  
       << htmlHyperLink( "http://www.dcmicro.com/crusher/pricing.html",  
             "Support""click here." )  
        << p ;  
 
   server << page ;  
   return 0 ;  
}  
 
Program Output
 
Content-Type: text/html  
<HTML>  
<HEAD>  
<TITLE>html++ example application</TITLE>  
</HEAD>  
<BODY>  
<A HREF="http://www.dcmicro.com">Click here</A> to jump to DC Micro Development's home page.<P></P>  
Click on the image  
<A HREF="http://www.dcmicro.com/crusher/get_crusher.html">  
<IMG SRC="http://www.dcmicro.com/images/gc.gif" ALT="Download demo"></IMG></A> to download a demo of Crusher.<P></P>  
To find out about annual support options,  
<A HREF="http://www.dcmicro.com/crusher/pricing.html#Support">click here.</A><P></P>  
</BODY>  
</HTML>  
 
hyperlink.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.