home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / ADDON.PAK / PROJECT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  7.7 KB  |  231 lines

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3.   project.cpp
  4.   Created: 10/24/95
  5.   Copyright (c) 1995, Borland International
  6.   $Revision:   1.18  $
  7.    
  8. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/  
  9.  
  10. #ifndef __AOEXPCH_H
  11.   #include "aoexpch.h"
  12. #endif
  13. #pragma hdrstop
  14.  
  15. #include <ideaddon\iproj.h>
  16. #include <ideaddon\ioption.h>
  17. #include "project.h"
  18.  
  19. //.............................................................................
  20. ProjectTestA::ProjectTestA() {
  21.   _projectClient = NULL;
  22.   _curProjectName = NULL;
  23.   _projectServer = GET_INTERFACE( IProjectServer );
  24.   if ( _projectServer ) {
  25.     registerForEvents();
  26.   }
  27. }
  28. //.............................................................................
  29. ProjectTestA::~ProjectTestA() {
  30.   if ( _projectClient ) {
  31.     if ( _projectServer ) {
  32.       _projectClient->AddRef(); 
  33.       _projectServer->UnregisterProjectClient( _projectClient );
  34.     }
  35.     _projectClient->Release();
  36.     _projectClient = 0;
  37.   }
  38.   if ( _projectServer ) {
  39.     _projectServer->Release();
  40.   }
  41.   if ( _curProjectName ) {
  42.     _curProjectName->Release();
  43.   }
  44. }
  45. //.............................................................................
  46. BOOL ProjectTestA::registerForEvents() {
  47.   if ( !_projectClient ) {
  48.     _projectClient = new ProjectClientImpl( this, _projectServer );
  49.   }
  50.   if ( _projectServer ) {
  51.     _projectClient->AddRef();
  52.     _projectServer->RegisterProjectClient( _projectClient );
  53.     return TRUE;
  54.   }
  55.   return FALSE;
  56. }
  57. //.............................................................................
  58. BOOL ProjectTestA::Init() {
  59.   OutStr( "ProjectTestA::Init()" );
  60.  
  61.   if ( _projectServer && _projectClient ) {
  62.     OutStr( "ProjectServer and ProjectClient objects are alive." );
  63.     _projectClient->ShowEvents( TRUE );
  64.   }   
  65.   return TRUE;
  66. }
  67. //.............................................................................
  68. void ProjectTestA::UnInit() {
  69.   OutStr( "ProjectTestA::UnInit()" );
  70.   if ( _projectClient ) {
  71.     _projectClient->ShowEvents( FALSE );
  72.   }
  73.  
  74. }
  75. //.............................................................................
  76. const char * ProjectTestA::GetName() {
  77.   return "Project Test A";
  78. }
  79. //.............................................................................
  80. const char * ProjectTestA::GetTestDescription( int testNum ) {
  81.   switch ( testNum ) {
  82.     case 1: 
  83.       return "Shows the number of selected project nodes.";
  84.     case 2: 
  85.       return "Returns info about the top node.";
  86.     case 3:
  87.       return "Show info about the current node.";
  88.     case 4:
  89.       return "Show info about the parent node.";
  90.   }
  91.   return "This test not implemented.";
  92. }  
  93. //.............................................................................
  94. void ProjectTestA::showNodeInfo( ProjectNode node ) {
  95.   IProjectNodeInfo * info = _projectServer->QueryNodeInfo( node );
  96.   if ( info ) {
  97.     OutStr( FormatStr( "Node info for node %u follows...", node ) );
  98.     ShowPolyStr( "Name = ", info->GetName(), TRUE );
  99.     ShowPolyStr( "Type = ", info->GetNodeType(), TRUE );
  100.     ShowPolyStr( "Description = ", info->GetDescription(), TRUE );
  101.     ShowPolyStr( "InputLocation = ", info->GetInputLocation(), TRUE );
  102.     ShowPolyStr( "OutputLocation = ", info->GetOutputLocation(), TRUE );
  103.     info->Release();
  104.   }
  105. }
  106. //.............................................................................
  107. void ProjectTestA::DoTest( int testNum ) {
  108.   if ( !_projectServer ) {
  109.     OutStr( "Project Server not initialized!" );
  110.     return;
  111.   }
  112.   switch ( testNum ) {
  113.     case 1: {
  114.       int numNodes;  // num selected nodes
  115.       _projectServer->QuerySelectedNodes( &numNodes );
  116.       OutStr( FormatStr( "%d Nodes selected.", numNodes ) );
  117.       break;
  118.     }
  119.     case 2: { // top node info
  120.       ProjectNode node = _projectServer->QueryTopNode();
  121.       showNodeInfo( node );
  122.       break;
  123.     }
  124.     case 3: { // current node info
  125.       int numNodes;
  126.       ProjectNode * nodes = _projectServer->QuerySelectedNodes( &numNodes );
  127.       if ( numNodes ) {
  128.         OutStr( "Current node found..." );
  129.         showNodeInfo( nodes[0] );
  130.       }
  131.       else {
  132.         OutStr( "No node selected." );
  133.       }
  134.       break;
  135.     }
  136.     case 4: { // node parent info
  137.       int numNodes;
  138.       ProjectNode * nodes = _projectServer->QuerySelectedNodes( &numNodes );
  139.       if ( numNodes ) {
  140.         IProjectNodeInfo * info = _projectServer->QueryNodeInfo( nodes[0] );
  141.         if ( info ) {
  142.           ProjectNode parent = info->GetParent();
  143.           if ( parent ) {
  144.             OutStr( "Parent node found..." );
  145.             showNodeInfo( parent );
  146.           }
  147.           else {
  148.             OutStr( "No parent node found." );
  149.           }
  150.           info->Release();
  151.         }
  152.       }
  153.       else {
  154.         OutStr( "No node selected." );
  155.       }
  156.       break;
  157.     }
  158.     default: {
  159.       OutStr( FormatStr( "Test #%d Not Implemented!", testNum ) );
  160.     }
  161.   }
  162. }
  163. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  164.  
  165.   ProjectClientImpl 
  166.    
  167. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/  
  168. void ProjectClientImpl::ShowPolyStr( const char * label, IPolyString * ps, BOOL release ) {
  169.   if ( _showEvents ) {
  170.     _testObj->ShowPolyStr( label, ps, release );
  171.   }
  172. }
  173. //.............................................................................
  174. IPolyString * ProjectClientImpl::nodeName( ProjectNode node ) {
  175.   //
  176.   // The caller of this method must Release() the returned polystring
  177.   //
  178.   if ( _projectServer ) {
  179.     IProjectNodeInfo * info = _projectServer->QueryNodeInfo( node );
  180.     if ( info ) {
  181.       return info->GetName();
  182.     }
  183.   }
  184.   return NULL;
  185. }
  186. //.............................................................................
  187. void ProjectClientImpl::OpenNotify( IPolyString * projectName ) {
  188.   if ( _curProjectName ) {
  189.     _curProjectName->Release();
  190.     _curProjectName = NULL;
  191.   }
  192.   if ( projectName ) {
  193.     _curProjectName = projectName;
  194.   }
  195.   ShowPolyStr( "Project Opening", _curProjectName, FALSE );
  196. }
  197. //.............................................................................
  198. void ProjectClientImpl::CloseNotify() {
  199.   ShowPolyStr( "Project Closing", _curProjectName, FALSE );
  200. }
  201. //.............................................................................
  202. void ProjectClientImpl::NodeDeleteNotify( ProjectNode node ) {
  203.   ShowPolyStr( "Node Delete", nodeName( node ), TRUE );
  204. }
  205. //.............................................................................
  206. void ProjectClientImpl::NodeAddNotify( ProjectNode node ) {
  207.   ShowPolyStr( "Node Add", nodeName( node ), TRUE );
  208. }
  209. //.............................................................................
  210. void ProjectClientImpl::NodeCopyNotify( ProjectNode node, ProjectNode newParent, BOOL reference ) {
  211.   ShowPolyStr( "Node Copied", nodeName( node ), TRUE );
  212.   ShowPolyStr( "-- new parent", nodeName( newParent ), TRUE );
  213.   if ( reference ) {
  214.     _testObj->OutStr( "-- this was a reference copy." );
  215.   }
  216. }
  217. //.............................................................................
  218. void ProjectClientImpl::NodeMoveNotify( ProjectNode node, ProjectNode oldParent ) {
  219.   ShowPolyStr( "Node Moved", nodeName( node ), TRUE );
  220.   ShowPolyStr( "-- old parent", nodeName( oldParent ), TRUE );
  221. //.............................................................................
  222. void ProjectClientImpl::NodeChangeNotify( ProjectNode node ) {
  223.   ShowPolyStr( "Node Changed", nodeName( node ), TRUE );
  224. }
  225. //.............................................................................
  226. void ProjectClientImpl::DependencyQueryResponder( ProjectNode /*node*/, 
  227.                           IPolyString * /*outputName*/ ) {}
  228.  
  229.   
  230.