home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / notebook / smrtguid / smrttext.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  4.1 KB  |  121 lines

  1. //************************************************************
  2. // Notebook Control - Smart Guide Notebook 
  3. //
  4. // Classes:  TextSmartPage 
  5. //
  6. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  7. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  8. // All Rights Reserved.
  9. //************************************************************
  10. #include <irect.hpp>
  11. #include <imcelcv.hpp>
  12. #include <istattxt.hpp>
  13. #include <istring.hpp>
  14. #include <ifont.hpp>
  15. #include <imle.hpp>
  16. #include <icolor.hpp>
  17. #include "smrtguid.hpp"
  18.  
  19. IWindow* TextSmartPage::createAndOrphanPage (
  20.                                 IWindow*          parent,
  21.                                 IWindow*          owner,
  22.                                 const IRectangle& initialRect)
  23. {
  24.    // Create the multicell to house all control in the page.
  25.    IMultiCellCanvas::Style style(IMultiCellCanvas::classDefaultStyle);
  26.    style = style &~ IWindow::visible;
  27.    fMultiCellCanvas = new IMultiCellCanvas( WID_TEXTCANVAS,
  28.                                             parent,
  29.                                             owner,
  30.                                             initialRect, 
  31.                                             style);
  32.  
  33.    // Create a static for the label
  34.    IStaticText* staticLabel = new IStaticText ( WID_TEXTLABEL,
  35.                                                 fMultiCellCanvas,
  36.                                                 fMultiCellCanvas);
  37.  
  38.    // Create a read-only MLE for the text.
  39.    IMultiLineEdit::Style mleStyle = IWindow::visible
  40.                                   | IMultiLineEdit::wordWrap
  41.                                   | IMultiLineEdit::verticalScroll
  42.                                   | IMultiLineEdit::readOnly;
  43.    IMultiLineEdit* text     = new IMultiLineEdit( WID_TEXTTEXT,
  44.                                                   fMultiCellCanvas,
  45.                                                   fMultiCellCanvas,
  46.                                                   IRectangle(),
  47.                                                   mleStyle   );
  48.  
  49.  
  50.    // Put the text in the Label, change the foreground to blue,
  51.    // and request auto delete of the window.
  52.    (*staticLabel)
  53.      .setText             ( fPageLabel)
  54.      .setForegroundColor  ( IColor::blue)
  55.      .setAutoDeleteObject ( );
  56.  
  57.    // Call setMinimumSize to keep the label from determining the
  58.    // minimum width of the window.
  59.    IFont staticFont(staticLabel);
  60.    unsigned long staticHeight = staticFont.maxCharHeight();
  61.    unsigned long staticWidth = staticFont.avgCharWidth()*10;
  62.    staticLabel->setMinimumSize (ISize(staticWidth, staticHeight));
  63.  
  64.    // Put the text in the MLE.
  65.    if (fPageTextFile.length() != 0)
  66.      text->importFromFile(fPageTextFile);
  67.    else
  68.      text->setText(fPageText);
  69.    text->setTop(1);
  70.  
  71.  
  72.    // Change the background of the text to white,
  73.    // and request auto delete of control.
  74.    (*text)
  75.      .setBackgroundColor  ( IColor::white)
  76.      .setAutoDeleteObject ( );
  77.  
  78.    // Add the cells to the canvas.
  79.    (*fMultiCellCanvas)
  80.      .addToCell      ( staticLabel, 1, 2, 2)
  81.      .addToCell      ( text,        2, 4)
  82.      .setRowHeight   ( 1, 2, false)
  83.      .setRowHeight   ( 3, 5, false)
  84.      .setRowHeight   ( 5, 3, false)
  85.      .setColumnWidth ( 1, 5, false)
  86.      .setColumnWidth ( 2, 5, true)
  87.      .setColumnWidth ( 3, 5, false)
  88.      .setAutoDeleteObject( );
  89.  
  90.   fMultiCellCanvas->setRowHeight(4, 2, true);
  91.   fMultiCellCanvas->show();
  92.   return fMultiCellCanvas;
  93. }
  94.  
  95. TextSmartPage& TextSmartPage::setPageLabel   ( const IString& pageLabel)
  96. { fPageLabel = pageLabel; return *this; }
  97.  
  98. TextSmartPage& TextSmartPage::setPageText    ( const IString& pageText)
  99. { fPageText = pageText; return *this; }
  100.  
  101. TextSmartPage& TextSmartPage::setPageTextFile( const IString& pageTextFile)
  102. { fPageTextFile = pageTextFile; return *this; }
  103.  
  104. IString TextSmartPage::pageLabel      ( ) const
  105. { return fPageLabel; }
  106.  
  107. IString TextSmartPage::pageText       ( ) const
  108. { return fPageText; }
  109.  
  110. IString TextSmartPage::pageTextFile   ( ) const
  111. { return fPageTextFile; }
  112.  
  113.  
  114. ISize TextSmartPage::minimumSize     ( ) const
  115. {
  116.    return ISize(300,100);
  117.  
  118. }
  119.  
  120.  
  121.