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

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3.   tool2.cpp
  4.   Created: 12/21/95
  5.   Copyright (c) 1987, 1995 Borland International Inc.  All Rights Reserved.
  6.   $Revision:   1.15  $
  7.    
  8. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/  
  9. #ifndef __AOEXPCH_H
  10.   #include "aoexpch.h"
  11. #endif
  12. #pragma hdrstop
  13.  
  14. #include "tool2.h"
  15.  
  16. const char * toolName = "myTool";
  17.  
  18. //.............................................................................
  19. ToolTestC::ToolTestC() {
  20.   _projectClient = new ProjectClient;
  21.   _toolInvoker = new ToolInvoker;
  22.  
  23.   _projectClient->RegisterToolTest( this );
  24.   _toolServer = GET_INTERFACE( IToolServer );
  25.   _projectServer = GET_INTERFACE( IProjectServer );
  26.  
  27.  
  28.   if ( _projectServer ) {
  29.     _projectClient->AddRef();
  30.     _projectServer->RegisterProjectClient( _projectClient );
  31.     IProjectServer2 * ps2 = GET_INTERFACE( IProjectServer2 );
  32.     if ( ps2 ) {  // this interface not available on BCW versions < 5.01
  33.       _projectClient->AddRef();
  34.       ps2->RegisterProjectSaveClient( _projectClient );
  35.       ps2->Release();
  36.     }
  37.   }
  38.   _toolName = MakePolyString( toolName );
  39.   OutStr( "Registers MyTool, invoke it from the Tool menu to test." );
  40. }
  41. //.............................................................................
  42. ToolTestC::~ToolTestC() {
  43.   IProjectServer2 * ps2 = GET_INTERFACE( IProjectServer2 );
  44.   if ( ps2 ) {  // this interface not available on BCW versions < 5.01
  45.     _projectClient->AddRef();
  46.     ps2->UnregisterProjectSaveClient( _projectClient );
  47.     ps2->Release();
  48.   }
  49.   _projectClient->AddRef();
  50.   _projectServer->UnregisterProjectClient( _projectClient );
  51.   _projectClient->Release();
  52.   _projectClient = 0;
  53.  
  54.   _toolInvoker->Release();
  55.  
  56.   if ( _projectServer ) {
  57.     _projectServer->Release();
  58.   }
  59.   _toolName->Release();
  60. }
  61. //.............................................................................
  62. void ToolTestC::RegisterTool() {
  63.   IToolInfo * toolInfo;
  64.   ToolObj tool;
  65.   if ( !_toolServer ) {
  66.     return;
  67.   }
  68.   _toolName->AddRef();
  69.   tool = _toolServer->ToolFind( _toolName );
  70.   if ( tool ) {
  71.     _toolServer->ToolRemove( tool );
  72.   }
  73.   toolInfo = _toolServer->CreateToolInfoInstance();
  74.   if ( !toolInfo ) {
  75.     return;
  76.   }
  77.   toolInfo->SetTypes( TT_Viewer );
  78.   _toolName->AddRef();
  79.   toolInfo->SetName( _toolName );
  80.   toolInfo->SetFlags( TIFlag_OnToolsMenu );
  81.   toolInfo->SetMenuName( MakePolyString( "&My Tool" ) );
  82.   _toolInvoker->AddRef();
  83.   toolInfo->SetImplementor( _toolInvoker );
  84.   _toolServer->ToolAdd( toolInfo );
  85. }
  86. //.............................................................................
  87.   void ToolTestC::UnregisterTool() {
  88.   if ( !_toolServer ) {
  89.     return;
  90.   }
  91.   _toolName->AddRef();
  92.   ToolObj tool = _toolServer->ToolFind( _toolName );
  93.   if ( tool ) {
  94.     _toolServer->ToolRemove( tool );
  95.   }
  96. }
  97. //.............................................................................
  98. void ProjectClient::OpenNotify( IPolyString * projectName ) {
  99.   if ( _toolTest ) {
  100.     _toolTest->RegisterTool();
  101.   }
  102.   projectName->Release();
  103. }  
  104. //.............................................................................
  105. void ProjectClient::CloseNotify() {}
  106. //.............................................................................
  107. void ProjectClient::BeforeSaveNotify() {
  108.   //
  109.   // Yank the add-on tool before the project is saved, so it will not
  110.   // appear in the project if it is loaded when this add-on isn't installed.
  111.   //
  112.   if ( _toolTest ) {
  113.     _toolTest->UnregisterTool();
  114.   }
  115. //.............................................................................
  116. void ProjectClient::AfterSaveNotify() {
  117.   //
  118.   // Now that the project has been saved, we must re-install the add-on tool.
  119.   //
  120.   if ( _toolTest ) {
  121.     _toolTest->RegisterTool();
  122.   }
  123. }
  124. //.............................................................................
  125. ToolReturn ToolInvoker::Execute( 
  126.                 IPolyString * /* cmdLine */, 
  127.                 ProjectNode * /* nodeArray */, 
  128.                 int /* numNodes */ ) {
  129.  
  130.   MessageBox( 0, "Hey!", "ToolInvoked", MB_OK );
  131.   return TR_Success;
  132.   
  133. }                 
  134.