home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / advframe / winview / hwinobj.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  4.5 KB  |  187 lines

  1. //************************************************************
  2. // Advanced Frame - Window Viewer 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 <ipopmenu.hpp>
  9. #include "hwinobj.hpp"
  10. #include "iconview.hpp"
  11. #include "infoview.hpp"
  12. #include "winview.h"
  13.  
  14. HWindowObject::HWindowObject( const HWindow&     hwindow,
  15.                               unsigned long      iconId,
  16.                               IContainerControl* cnr )
  17.   : IContainerObject( IString(), iconId ),
  18.     objCnr( cnr ),
  19.     ficonView( 0 ),
  20.     finfoView( 0 ),
  21.     fhwindow( hwindow )
  22. {
  23.    IString wintext = hwindow.text();
  24.    if ( wintext.length() > 20 )
  25.       wintext.remove(21);
  26.    wintext = hwindow.asHexString() + IString(" \"") + wintext +
  27.              IString("\"");
  28.    this->setIconText( wintext );
  29. }
  30.  
  31. HWindowObject::~HWindowObject()
  32. {
  33.   if (ficonView)
  34.      ficonView->invalidateObject();
  35.   if (finfoView)
  36.      finfoView->invalidateObject();
  37. }
  38.  
  39. HWindowObject& HWindowObject::openIconView( )
  40. {
  41.    this->iconView().open();
  42.    return *this;
  43. }
  44.  
  45. HWindowObject& HWindowObject::openInfoView( )
  46. {
  47.    this->infoView().open();
  48.    return *this;
  49. }
  50.  
  51. // This function is called by the container handler
  52. // when the object is double-clicked.  Open the icon
  53. // view if it is available; otherwise, open the
  54. // information view.
  55. void HWindowObject::handleOpen ( IContainerControl* )
  56. {
  57.    if (this->isIconViewAvailable() )
  58.      this->iconView().open();
  59.    else
  60.      this->infoView().open();
  61. }
  62.  
  63. HWindowObjectView& HWindowObject::iconView ( )
  64. {
  65.   if ( !ficonView )
  66.     {
  67.     ficonView = this -> newIconView();
  68.     }
  69.   return *ficonView;
  70. }
  71.  
  72. HWindowObjectView& HWindowObject::infoView ( )
  73. {
  74.   if ( !finfoView )
  75.     {
  76.     finfoView = this -> newInfoView();
  77.     }
  78.   return *finfoView;
  79. }
  80.  
  81. // Icon view is available as long as the object has children.
  82. Boolean HWindowObject::isIconViewAvailable( ) const
  83. {
  84.   IContainerControl::ObjectCursor cursor( *(this->container()),
  85.                                            this);
  86.   return cursor.setToFirst() ;
  87. }
  88.  
  89. // This function allocates a new icon view.
  90. HWindowObjectView* HWindowObject::newIconView ( )
  91. {
  92.   HWindowObjectView* view = new IconView( *this );
  93.   return view;
  94. }
  95.  
  96. // This function allocates a new info view.
  97. HWindowObjectView* HWindowObject::newInfoView ( )
  98. {
  99.   HWindowObjectView* view = new InfoView( *this );
  100.   return view;
  101. }
  102.  
  103. HWindowObject& HWindowObject::viewClosed( HWindowObjectView* view )
  104. {
  105.   if (view == this->finfoView)
  106.      this->finfoView = 0;
  107.   if (view == this->ficonView)
  108.      this->ficonView = 0;
  109.   return *this;
  110. }
  111.  
  112. IContainerControl* HWindowObject::container ( ) const
  113. {
  114.   return objCnr;
  115. }
  116.  
  117. const HWindow& HWindowObject::hWindow( ) const
  118. {
  119.   return fhwindow;
  120. }
  121.  
  122. HWindowObjectView& HWindowObjectView::open ( )
  123. {
  124.   if ( isMinimized() )
  125.     restore();
  126.   setFocus();
  127.   show();
  128.   return *this;
  129. }
  130.  
  131. HWindowObjectView::HWindowObjectView ( IWindow*       client,
  132.                                        HWindowObject& object,
  133.                                        const IString& viewName )
  134.   : IFrameWindow( 0, 0, object.container()->parent(),
  135.                   nextShellRect().scaleBy( 0.5, 0.5 ),
  136.                   classDefaultStyle | noMoveWithOwner ),
  137.     viewTitle( this ),
  138.     viewObj( &object )
  139. {
  140.   viewTitle.setObjectText( object.iconText() );
  141.   viewTitle.setViewText( viewName );
  142.   setIcon( object.icon() );
  143.   setClient( client );
  144.   client->setOwner( this );
  145.   setAutoDeleteObject( true );
  146. }
  147.  
  148. HWindowObjectView::~HWindowObjectView ( )
  149. {
  150.   if ( viewObj )
  151.     viewObj -> viewClosed( this );
  152. }
  153.  
  154. HWindowObject* HWindowObjectView::object ( ) const
  155. {
  156.   return viewObj;
  157. }
  158.  
  159. HWindowObjectView& HWindowObjectView::invalidateObject ( )
  160. {
  161.   viewTitle.setObjectText("<invalid>");
  162.   viewObj = 0;
  163.   return *this;
  164. }
  165.  
  166. MenuHandler::MenuHandler( ) :
  167.   ICnrMenuHandler( )
  168. { }
  169.  
  170. IBase::Boolean   MenuHandler::makePopUpMenu( IMenuEvent& event )
  171. {
  172.   Boolean result = false;
  173.   IContainerControl* pcnr =
  174.      (IContainerControl*)(event.dispatchingWindow());
  175.   IContainerObject* pobj = popupMenuObject();
  176.   if (pcnr && pobj)
  177.     {
  178.     pcnr->setCursor( pobj );
  179.     IPopUpMenu* popup = new IPopUpMenu(POPUP_MENU, pcnr);
  180.     popup->setAutoDeleteObject();
  181.     popup->show(event.mousePosition());
  182.     result = true;
  183.     }
  184.   return result;
  185. }
  186.  
  187.