home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / cnr / treedet / treedetc.cpp < prev    next >
Text File  |  1996-10-29  |  5KB  |  161 lines

  1. //************************************************************
  2. // Container - Combined Tree and Details View
  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 <icnrobj.hpp>
  9. #include <itrace.hpp>
  10. #include  "treedetc.hpp"
  11.  
  12. DetailsTreeContainer ::  DetailsTreeContainer( unsigned long id,
  13.                       IWindow*  parent,
  14.                       IWindow*  owner)
  15.     : IContainerControl (id, parent, owner), 
  16.       scrollBegun(false)
  17. {
  18.   IFUNCTRACE_DEVELOP()
  19. }
  20.  
  21. DetailsTreeContainer ::  ~DetailsTreeContainer( )
  22. {
  23.   IFUNCTRACE_DEVELOP()
  24. }
  25.  
  26.  
  27. DetailsTreeContainer&  DetailsTreeContainer::setFont ( const IFont& fm )
  28. {
  29.    // If fontChangeStarted is true. we are being called because a
  30.    // font has been dropped on the details view.  In this case we
  31.    // just pass the setFont up the chain for processing
  32.  
  33.    if(!fontChangeStarted()) {
  34.      if(isVisible())
  35.        disableUpdate();
  36.      if(detailsContainer().isVisible())
  37.        detailsContainer().disableUpdate();
  38.    }
  39.  
  40.    // Set the font of this window
  41.    Inherited::setFont(fm);
  42.  
  43.    if(!fontChangeStarted()) {
  44.      // Set the font of the details window
  45.      detailsContainer().setFont(fm);
  46.   
  47.      // Turn visibility back on and refresh
  48.      if(detailsContainer().isVisible()) {
  49.        detailsContainer().enableUpdate();
  50.        // Refresh the canvas
  51.        detailsContainer().parent()->refresh();
  52.      }
  53.  
  54.      if(isVisible()) {
  55.        enableUpdate();
  56.        parent()->refresh();
  57.      }
  58.    }
  59.    return *this;
  60. }
  61.  
  62. DetailsTreeContainer& DetailsTreeContainer :: addObject( 
  63.                           const IContainerObject* newObject,
  64.                           IContainerObject* parentObject)
  65. {
  66.   // Pass tree view request to the base class
  67.   Inherited::addObject(newObject,  parentObject);
  68.  
  69.   // Handle the details view
  70.   // If no parent add as last
  71.   if(!parentObject) {
  72.      detailsContainer().addObject(newObject);
  73.      detailsContainer().expand((IContainerObject*)newObject);
  74.   }
  75.   else if (isExpanded(parentObject)){
  76.      // We will defer an add request until the parent is expanded
  77.      // If the parent is expanded, add after the last child of the parent
  78.      IContainerControl::ObjectCursor childCursor(*this, parentObject);
  79.      childCursor.setToLast();
  80.      if (childCursor.isValid())
  81.           detailsContainer().addObjectAfter(newObject,
  82.                      detailsContainer().objectAt(childCursor));
  83.      else
  84.           detailsContainer().addObjectAfter(newObject, parentObject);
  85.   }
  86.  
  87.   return *this;
  88. }
  89.  
  90. DetailsTreeContainer& DetailsTreeContainer :: addObjectAfter( 
  91.                           const IContainerObject* newObject,
  92.                           const IContainerObject* afterObject,
  93.                                 IContainerObject* parentObject)
  94. {
  95.   Boolean addedToDetails = true;
  96.  
  97.   if(!parentObject)
  98.     detailsContainer().addObjectAfter(newObject, afterObject);
  99.   else if(isExpanded(parentObject))
  100.     detailsContainer().addObjectAfter(newObject, afterObject);
  101.   else
  102.      addedToDetails = false;
  103.  
  104.   Inherited::addObjectAfter(newObject, afterObject, parentObject);
  105.   return *this;
  106. }
  107.  
  108. DetailsTreeContainer& DetailsTreeContainer :: removeObject( 
  109.                           IContainerObject* object,
  110.                           Boolean fAllContainers)
  111. {
  112.   Inherited::removeObject(object, fAllContainers);
  113.   if(!fAllContainers && 
  114.      detailsContainer().containsObject(object))
  115.        detailsContainer().removeObject(object);
  116.   return *this;
  117. }
  118.  
  119. DetailsTreeContainer& DetailsTreeContainer :: removeObjectAt ( 
  120.                         IContainerControl::ObjectCursor& cursor)
  121. {
  122.   Inherited::removeObjectAt(cursor);
  123.   if (detailsContainer().containsObject(cursor.current()))
  124.     detailsContainer().removeObjectAt(cursor);
  125.   return *this;
  126. }
  127.  
  128. DetailsTreeContainer& DetailsTreeContainer :: removeObjectAt ( 
  129.                         IContainerControl::TextCursor& cursor)
  130. {
  131.   Inherited::removeObjectAt(cursor);
  132.   if (detailsContainer().containsObject(cursor.current()))
  133.     detailsContainer().removeObjectAt(cursor);
  134.   return *this;
  135. }
  136.  
  137. DetailsTreeContainer& DetailsTreeContainer :: removeSelectedObjects ( )
  138. {
  139.   // Note: we are Assuming that we are ONLY a tree view where just a
  140.   // single object can be selected. 
  141.   IContainerControl::ObjectCursor cursor(*this,
  142.                                    IContainerObject::selected);
  143.   // It is assumed that a selected object has been added to the details
  144.   // view container.
  145.   cursor.setToFirst();
  146.   if(cursor.isValid()) {
  147.     IContainerObject* pobj = objectAt(cursor);
  148.     Inherited::removeSelectedObjects();
  149.     detailsContainer().removeObject(pobj);
  150.   }
  151.   return *this;
  152. }
  153.  
  154. DetailsTreeContainer& DetailsTreeContainer :: removeAllObjects ( )
  155. {
  156.   Inherited::removeAllObjects();
  157.   detailsContainer().removeAllObjects();
  158.   return *this;
  159. }
  160.  
  161.