home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / advframe / mdi / editwin.cpp next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  3.8 KB  |  175 lines

  1. //************************************************************
  2. // Advanced Frame - MDI Frame 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 <ifiledlg.hpp>
  9. #include "editwin.hpp"
  10. #include "mdi.h"
  11.  
  12. MainWindow :: MainWindow ( )
  13.   : frame( WND_MAIN, 0, 0,
  14.            MI_WINDOWS, MI_FIRSTCHILD,
  15.            IFrameWindow::nextShellRect(),
  16.            IFrameWindow::defaultStyle() |
  17.            IFrameWindow::menuBar | IFrameWindow::minimizedIcon,
  18.            "Simple Viewer" ),
  19.     menu( &frame, IMenuBar::wrapper ),
  20.     handler( *this )
  21. {
  22.   menu.disableItem( MI_CLOSE );
  23.   handler.handleEventsFor( &frame );
  24.   frame.setFocus().show();
  25. }
  26.  
  27. MainWindow& MainWindow::openChild( )
  28. {
  29.   IFileDialog dialog( 0, &frame );
  30.   if (dialog.pressedOK())
  31.      {
  32.      EditWindow* win = new EditWindow( frame, dialog.fileName() );
  33.      win->open();
  34.      menu.enableItem( MI_CLOSE );
  35.      }
  36.   return *this;
  37. }
  38.  
  39. MainWindow& MainWindow::closeChild( )
  40. {
  41.   MDIWindow* child = frame.activeChild();
  42.   if (child)
  43.     child->close();
  44.   if ( !frame.activeChild() )
  45.     menu.disableItem( MI_CLOSE );
  46.   return *this;
  47. }
  48.  
  49. MainWindow& MainWindow::restoreChild( )
  50. {
  51.   MDIWindow* child = frame.activeChild();
  52.   if (child)
  53.     child->restore();
  54.   return *this;
  55. }
  56.  
  57. MainWindow& MainWindow::minimizeChild( )
  58. {
  59.   MDIWindow* child = frame.activeChild();
  60.   if (child)
  61.     child->minimize();
  62.   return *this;
  63. }
  64.  
  65. MainWindow& MainWindow::activateChild( unsigned long childId )
  66. {
  67.   frame.activateChild( childId );
  68.   return *this;
  69. }
  70.  
  71. MainWindow& MainWindow::arrange( )
  72. {
  73.    frame.arrange();
  74.    return *this;
  75. }
  76.  
  77. MainWindow& MainWindow::cascade( )
  78. {
  79.    frame.cascade();
  80.    return *this;
  81. }
  82.  
  83. MainWindow& MainWindow::tile( Boolean horizontal )
  84. {
  85.    frame.tile(horizontal);
  86.    return *this;
  87. }
  88.  
  89. MainWindow& MainWindow::close( )
  90. {
  91.    frame.close();
  92.    return *this;
  93. }
  94.  
  95. EditWindow :: EditWindow ( MDIWindow&     parent,
  96.                            const IString& filename )
  97.    : MDIWindow( MI_FIRSTCHILD, &parent,
  98.            IRectangle(IPoint(10,10),
  99.                       parent.size()).scaleBy( 0.8, 0.8 ),
  100.            IFrameWindow::defaultStyle() |
  101.            IFrameWindow::minimizedIcon ),
  102.     fname( filename ),
  103.     title( this ),
  104.     fclient(IC_FRAME_CLIENT_ID, this, this )
  105. {
  106.   setAutoDeleteObject( true );
  107.   title.setText( fname );
  108.   try
  109.     {
  110.     fclient.importFromFile( fname );
  111.     }
  112.   catch (IAccessError& )
  113.     {
  114.     // Catch exception if new file.
  115.     }
  116.   setClient( &fclient );
  117. }
  118.  
  119. EditWindow& EditWindow::open( )
  120. {
  121.    this->setFocus();
  122.    this->show();
  123.    return *this;
  124. }
  125.  
  126. EditWindow& EditWindow::close( )
  127. {
  128.    MDIWindow::close();
  129.    return *this;
  130. }
  131.  
  132.  
  133. CommandHandler::CommandHandler( MainWindow& frame ) :
  134.   fframe( frame )
  135. { }
  136.  
  137. IBase::Boolean CommandHandler::command( ICommandEvent& event )
  138. {
  139.    switch (event.commandId())
  140.       {
  141.       case MI_EXIT     :
  142.          fframe.close();
  143.          break;
  144.       case MI_OPEN :
  145.          fframe.openChild();
  146.          break;
  147.       case MI_CLOSE :
  148.       case IC_ID_CLOSE :
  149.          fframe.closeChild();
  150.          break;
  151.       case IC_ID_RESTORE :
  152.          fframe.restoreChild();
  153.          break;
  154.       case IC_ID_MINIMIZE :
  155.          fframe.minimizeChild();
  156.          break;
  157.       case MI_CASCADE :
  158.          fframe.cascade();
  159.          break;
  160.       case MI_TILEH :
  161.          fframe.tile( true );
  162.          break;
  163.       case MI_TILEV :
  164.          fframe.tile( false );
  165.          break;
  166.       case MI_ARRANGE :
  167.          fframe.arrange( );
  168.          break;
  169.       default:
  170.          fframe.activateChild( event.commandId() );
  171.       }
  172.    return false;
  173. }
  174.  
  175.