home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / LANCELOT / LGOODIES.CPP < prev    next >
C/C++ Source or Header  |  1995-04-07  |  12KB  |  241 lines

  1. /******************************************************************************
  2. * FILE NAME: lgoodies.cpp                                                     *
  3. *                                                                             *
  4. * Classes:                                                                    *
  5. *   LAskUser                                                                  *
  6. *   LAskUserCommandHandler                                                    *
  7. *   LWindow                                                                   *
  8. *                                                                             *
  9. * COPYRIGHT:                                                                  *
  10. *   Licensed Materials - Property of IBM                                      *
  11. *   (C) Copyright IBM Corporation 1992, 1995                                  *
  12. *   All Rights Reserved                                                       *
  13. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  14. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  15. ******************************************************************************/
  16. #include "lgoodies.hpp"
  17. #include "lancelot.h"
  18.  
  19. /******************************************************************************
  20. * Class LAskUser - Constructor                                                *
  21. *   Up to 4 lines of text can be added to this frame window                   *
  22. ******************************************************************************/
  23. LAskUser::LAskUser( unsigned long id, IWindow* parent, IWindow* owner,
  24.                     const IString& theText1,
  25.                     const IString& theText2,
  26.                     const IString& theText3,
  27.                     const IString& theText4 )
  28.      :IFrameWindow         ( id, parent, owner, IRectangle(),
  29.                              titleBar | dialogBackground
  30.                              | dialogBorder | systemMenu ),
  31.       title                ( this, STR_ASKUSER_TITLE ),
  32.       canvas               ( ID_ASKUSER_CANVAS, this, this ),
  33.       bCanvas              ( ID_ASKUSER_BUTTON_CANVAS, &canvas, &canvas ),
  34.       staticText1          ( ID_ASKUSER_TEXT, &canvas, &canvas, IRectangle(),
  35.                              IStaticText::classDefaultStyle
  36.                              | IStaticText::wordBreak ),
  37.       staticText2          ( ID_ASKUSER_TEXT, &canvas, &canvas, IRectangle(),
  38.                              IStaticText::classDefaultStyle
  39.                              | IStaticText::wordBreak ),
  40.       staticText3          ( ID_ASKUSER_TEXT, &canvas, &canvas, IRectangle(),
  41.                              IStaticText::classDefaultStyle
  42.                              | IStaticText::wordBreak ),
  43.       staticText4          ( ID_ASKUSER_TEXT, &canvas, &canvas, IRectangle(),
  44.                              IStaticText::classDefaultStyle
  45.                              | IStaticText::wordBreak ),
  46.       entry                ( ID_ASKUSER_ENTRY, &canvas, &canvas, IRectangle(),
  47.                              IEntryField::classDefaultStyle
  48.                              | IControl::tabStop ),
  49.       okButton             ( ID_BUTTON_OK, &bCanvas, &bCanvas, IRectangle(),
  50.                              IPushButton::classDefaultStyle
  51.                              | IPushButton::defaultButton
  52.                              | IControl::tabStop | IControl::group ),
  53.       cancelButton         ( ID_BUTTON_CANCEL, &bCanvas, &bCanvas, IRectangle(),
  54.                              IPushButton::classDefaultStyle ),
  55.       cmdHdr               ( this ),
  56.       ok                   ( false )
  57. {
  58. /*-----------------------------------------------------------------------------
  59. | Set the text for each static text object                                    |
  60. -----------------------------------------------------------------------------*/
  61.    staticText1.setText( theText1 );
  62.    staticText2.setText( theText2 );
  63.    staticText3.setText( theText3 );
  64.    staticText4.setText( theText4 );
  65.    okButton.setText( STR_OK );
  66.    cancelButton.setText( STR_CANCEL );
  67.  
  68. /*-----------------------------------------------------------------------------
  69. | Add the objects to the canvas                                               |
  70. -----------------------------------------------------------------------------*/
  71.    canvas.addToCell( &staticText1,  2,  2, 10,  1 );
  72.    canvas.addToCell( &staticText2,  2,  3, 10,  1 );
  73.    canvas.addToCell( &staticText3,  2,  4, 10,  1 );
  74.    canvas.addToCell( &staticText4,  2,  5, 10,  1 );
  75.    canvas.addToCell( &entry,        2,  7, 10,  2 );
  76.    canvas.addToCell( &bCanvas,      3, 11 );
  77.  
  78. /*-----------------------------------------------------------------------------
  79. | Set the client to be the canvas                                             |
  80. -----------------------------------------------------------------------------*/
  81.     setClient( &canvas );
  82.  
  83. /*-----------------------------------------------------------------------------
  84. | Start handling command events                                               |
  85. -----------------------------------------------------------------------------*/
  86.     cmdHdr.handleEventsFor( this );
  87.  
  88. /*-----------------------------------------------------------------------------
  89. | Resize the window based on the minimum size of the canvas                   |
  90. -----------------------------------------------------------------------------*/
  91. #ifndef IC_MOTIF
  92.    moveSizeToClient( IRectangle( IPoint(
  93.                      IWindow::desktopWindow()->size().width()/2,
  94.                      IWindow::desktopWindow()->size().height()/2 ),
  95.                      canvas.minimumSize() ) );
  96. #else
  97.    moveSizeTo( IRectangle( IPoint(
  98.                IWindow::desktopWindow()->size().width()/2,
  99.                IWindow::desktopWindow()->size().height()/2 ),
  100.                canvas.minimumSize() ) );
  101. #endif
  102.  
  103. /*-----------------------------------------------------------------------------
  104. | Center the frame window                                                     |
  105. -----------------------------------------------------------------------------*/
  106.    moveSizeTo( rect().centerAt( IWindow::desktopWindow()->rect().center() ) );
  107.  
  108. /*-----------------------------------------------------------------------------
  109. | Set focus to the entryfield                                                 |
  110. | Show the frame window modally                                               |
  111. -----------------------------------------------------------------------------*/
  112.    entry.setFocus();
  113.    showModally();
  114. }
  115.  
  116.  
  117. /******************************************************************************
  118. * Class LAskUser - Destructor                                                 *
  119. ******************************************************************************/
  120. LAskUser::~LAskUser()
  121. {
  122.    cmdHdr.stopHandlingEventsFor( this );
  123. }
  124.  
  125.  
  126. /******************************************************************************
  127. * Class LAskUserCommandHandler - Constructor for command handler              *
  128. *                                                                             *
  129. * Create yourself as an ICommandHandler                                       *
  130. * Store the owner window                                                      *
  131. ******************************************************************************/
  132. LAskUserCommandHandler::LAskUserCommandHandler( LAskUser* owner )
  133.      :ICommandHandler(),
  134.       theOwner( owner )
  135. {}
  136.  
  137.  
  138. /******************************************************************************
  139. * Class LAskUserCommandHandler - Destructor                                   *
  140. ******************************************************************************/
  141. LAskUserCommandHandler::~LAskUserCommandHandler()
  142. {}
  143.  
  144.  
  145. /******************************************************************************
  146. * Class LAskUserCommandHandler :: command()                                   *
  147. *   Handle any command events for the frame window                            *
  148. ******************************************************************************/
  149. IBase::Boolean LAskUserCommandHandler::command( ICommandEvent& event )
  150. {
  151.    Boolean
  152.       retCode = false;
  153.  
  154.    switch ( event.commandId() )
  155.    {
  156. /*-----------------------------------------------------------------------------
  157. | If the user pressed the OK button,                                          |
  158. | - Set the pressed OK button flag to true                                    |
  159. | - Dismiss the frame window                                                  |
  160. -----------------------------------------------------------------------------*/
  161.       case ID_BUTTON_OK:
  162.       {
  163.          theOwner->setOk( true );
  164.          theOwner->dismiss();
  165.          retCode = true;
  166.          break;
  167.       }
  168. /*-----------------------------------------------------------------------------
  169. | If the user pressed the CANCEL button,                                      |
  170. | - Set the pressed OK button flag to false                                   |
  171. | - Dismiss the frame window                                                  |
  172. -----------------------------------------------------------------------------*/
  173.       case ID_BUTTON_CANCEL:
  174.       {
  175.          theOwner->setOk( false );
  176.          theOwner->dismiss();
  177.          retCode = true;
  178.          break;
  179.       }
  180.    }
  181.  
  182.    return retCode;
  183. }
  184.  
  185.  
  186. /******************************************************************************
  187. * Class LFrameWindow - Constructor                                            *
  188. *   Common frame window functions.                                            *
  189. ******************************************************************************/
  190. LFrameWindow::LFrameWindow()
  191. {}
  192.  
  193.  
  194. /******************************************************************************
  195. * Class LFrameWindow - Destructor                                             *
  196. ******************************************************************************/
  197. LFrameWindow::~LFrameWindow()
  198. {}
  199.  
  200.  
  201. /******************************************************************************
  202. * Class LFrameWindow::bestFit()                                               *
  203. *   If a frame window spans past the desktop window size,                     *
  204. *   recalculate the best location for the frame window.                       *
  205. ******************************************************************************/
  206. IPoint LFrameWindow::bestFit( IFrameWindow* frameWin )
  207. {
  208.    int
  209.       oldXPosition = frameWin->rect().left(),
  210.       oldYPosition = frameWin->rect().bottom();
  211.  
  212.    if ( oldXPosition < 0 )
  213.       oldXPosition = 0;
  214.    if ( oldYPosition < 0 )
  215.       oldYPosition = 0;
  216.  
  217.    ISize
  218.       desktopSize( IWindow::desktopWindow()->size() );
  219.    int
  220.       newXPosition = frameWin->rect().right() - desktopSize.width(),
  221.       newYPosition = frameWin->rect().top() - desktopSize.height();
  222.    if ( newXPosition > 0 )
  223.    {
  224.       newXPosition = oldXPosition - newXPosition;
  225.       if ( newXPosition < 0 )
  226.          newXPosition = 0;
  227.    }
  228.    else
  229.       newXPosition = oldXPosition;
  230.    if ( newYPosition > 0 )
  231.    {
  232.       newYPosition = oldYPosition - newYPosition;
  233.       if ( newYPosition < 0 )
  234.          newYPosition = 0;
  235.    }
  236.    else
  237.       newYPosition = oldYPosition;
  238.  
  239.    return IPoint( newXPosition, newYPosition );
  240. }
  241.