home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / static / textstyl / textstyl.cpp < prev   
Text File  |  1996-10-29  |  5KB  |  166 lines

  1. //************************************************************
  2. // Static Controls - Style Example
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. // All Rights Reserved.
  7. //************************************************************
  8. #include <iapp.hpp>
  9. #include <ifont.hpp>
  10. #include <iframe.hpp>
  11. #include <istattxt.hpp>
  12. #include <istring.hpp>
  13. #include <icconst.h>
  14.  
  15. void main ( )
  16. {
  17.   IFrameWindow frame( "Static Text Style Example" );
  18.  
  19.   // Illustrate the different alignment styles.
  20.   IStaticText
  21.      topLeftAndClient( IC_FRAME_CLIENT_ID, &frame, &frame ),
  22.      topCenter       (2, &frame, &frame),
  23.      topRight        (3, &frame, &frame),
  24.      centerLeft      (4, &frame, &frame),
  25.      centered        (5, &frame, &frame),
  26.      centerRight     (6, &frame, &frame),
  27.      bottomLeft      (7, &frame, &frame),
  28.      bottomCenter    (8, &frame, &frame),
  29.      bottomRight     (9, &frame, &frame);
  30.   
  31.   IFont font( &topLeftAndClient );     
  32.   unsigned long lineHeight = font.maxCharHeight();
  33.   unsigned long alignmentHeight = (lineHeight*3)/2;
  34.  
  35.   // Use a smaller font for the alignment styles.
  36.   font
  37.     .setName("Times New Roman")
  38.     .setPointSize(9);
  39.  
  40.   // Set the alignment, text, and new font size.
  41.   topLeftAndClient
  42.     .setAlignment(IStaticText::topLeft)
  43.     .setText("Top-left")
  44.     .setFont(font);
  45.   topCenter
  46.     .setAlignment(IStaticText::topCenter)
  47.     .setText("Top-center")
  48.     .setFont(font);
  49.   topRight 
  50.     .setAlignment(IStaticText::topRight)
  51.     .setText("Top-right")
  52.     .setFont(font);
  53.   centerLeft     
  54.     .setAlignment(IStaticText::centerLeft)
  55.     .setText("Center-left")
  56.     .setFont(font);
  57.   centered 
  58.     .setAlignment(IStaticText::centerCenter)
  59.     .setText("Centered")
  60.     .setFont(font);
  61.   centerRight
  62.     .setAlignment(IStaticText::centerRight)
  63.     .setText("Center-right")
  64.     .setFont(font);
  65.   bottomLeft 
  66.     .setAlignment(IStaticText::bottomLeft)
  67.     .setText("Bottom-left")
  68.     .setFont(font);
  69.   bottomCenter 
  70.     .setAlignment(IStaticText::bottomCenter)
  71.     .setText("Bottom-center")
  72.     .setFont(font);
  73.   bottomRight   
  74.     .setAlignment(IStaticText::bottomRight)
  75.     .setText("Bottom-right")
  76.     .setFont(font);
  77.  
  78.   // Illustrate the different drawing styles.
  79.   IStaticText multiStyle( 11, &frame, &frame );
  80.   multiStyle
  81.    .enableStrikeout()
  82.    .enableUnderscore()
  83.    .enableHalftone()
  84.    .setAlignment( IStaticText::topLeftWrapped )
  85.    .setText( "Strike-out + underscore + half-tone"
  86.                + IString( " + top-left-wrapped" ));
  87.  
  88.   IStaticText halftone( 12, &frame, &frame );
  89.   halftone
  90.    .enableHalftone()
  91.    .setText( "Half-tone style" );
  92.  
  93.   IStaticText underscore( 13, &frame, &frame );
  94.   underscore
  95.    .enableUnderscore()
  96.    .setText( "Underscore style" );
  97.  
  98.   IStaticText strikeout( 14, &frame, &frame );
  99.   strikeout
  100.    .enableStrikeout()
  101.    .setText( "Strike-out style" );
  102.  
  103.   IStaticText mnemonic( 15, &frame, &frame, IRectangle(),
  104.                         IStaticText::classDefaultStyle
  105.                           | IStaticText::mnemonic );
  106.   // Mnemonics are platform-specific.
  107.   #ifdef IC_PM
  108.     mnemonic.setText( "~Mnemonic style" );
  109.   #else
  110.     mnemonic.setText( "&Mnemonic style" );
  111.   #endif
  112.  
  113.   // Position the static text controls.
  114.   frame
  115.    .setClient( &topLeftAndClient )
  116.    .addExtension( &multiStyle,
  117.                   IFrameWindow::belowClient,
  118.                   2 * lineHeight )
  119.    .addExtension( &halftone,
  120.                   IFrameWindow::belowClient,
  121.                   lineHeight )
  122.    .addExtension( &underscore,
  123.                   IFrameWindow::belowClient,
  124.                   lineHeight )
  125.    .addExtension( &strikeout,
  126.                   IFrameWindow::belowClient,
  127.                   lineHeight )
  128.    .addExtension( &mnemonic,
  129.                   IFrameWindow::belowClient,
  130.                   lineHeight )
  131.    .addExtension( &bottomRight,
  132.                   IFrameWindow::belowClient,
  133.                   alignmentHeight )
  134.    .addExtension( &bottomCenter,
  135.                   IFrameWindow::belowClient,
  136.                   alignmentHeight )
  137.    .addExtension( &bottomLeft,
  138.                   IFrameWindow::belowClient,
  139.                   alignmentHeight )
  140.    .addExtension( ¢erRight,
  141.                   IFrameWindow::belowClient,
  142.                   alignmentHeight )
  143.    .addExtension( ¢ered,
  144.                   IFrameWindow::belowClient,
  145.                   alignmentHeight )
  146.    .addExtension( ¢erLeft,
  147.                   IFrameWindow::belowClient,
  148.                   alignmentHeight )
  149.    .addExtension( &topRight,
  150.                   IFrameWindow::belowClient,
  151.                   alignmentHeight )
  152.    .addExtension( &topCenter,
  153.                   IFrameWindow::belowClient,
  154.                   alignmentHeight );
  155.  
  156.   // Size and show the window now (needed for proper
  157.   // alignment of the text strings).
  158.   frame
  159.    .sizeTo( ISize( 450, 472 ))
  160.    .moveTo( IPoint( 10, 10 ))
  161.    .setFocus()
  162.    .show();
  163.  
  164.   IApplication::current().run();
  165. }
  166.