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

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3.   cmdtest.cpp
  4.   Created: 10/24/95
  5.   Copyright (c) 1995, Borland International
  6.   $Revision:   1.17  $
  7.  
  8. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
  9. #ifndef __AOEXPCH_H
  10.   #include "aoexpch.h"
  11. #endif
  12. #pragma hdrstop
  13.  
  14. #include "cmdtest.h"
  15. #include "tests.hrc"
  16.  
  17. extern HINSTANCE ghInst;
  18.  
  19. BOOL PASCAL Enabler();
  20. static BOOL okToEnable = TRUE;
  21.  
  22. //.............................................................................
  23. CmdTestA::CmdTestA()
  24.   {
  25.   _startInitFailed = TRUE;
  26.   _cmdServer  = GET_INTERFACE(ICommandServer);
  27.   if ( _cmdServer )
  28.     {
  29.     ICommand *cmd = _cmdServer->CreateCommand();
  30.     if ( cmd )
  31.       {
  32.       HBITMAP smallBmp = LoadBitmap( ghInst, MAKEINTRESOURCE(BITMAP_1) );
  33.       HBITMAP largeBmp = LoadBitmap( ghInst, MAKEINTRESOURCE(BITMAP_2) );
  34.  
  35.       // Fill in the cmd
  36.       cmd->SetName( ::MakePolyString ("AnotherFileOpen") );
  37.       cmd->SetDescription( ::MakePolyString ("Another File Open") );
  38.       cmd->SetScriptCommand( ::MakePolyString ("IDE.FileOpen();") );
  39.       cmd->SetToolTip( ::MakePolyString ("A test of the command interface") );
  40.       cmd->SetHelpHint( ::MakePolyString ("A test of the command interface")  );
  41.       cmd->SetHelpId( 0 );
  42.       cmd->SetHelpFile( NULL );
  43.       cmd->SetIcons( smallBmp, largeBmp );
  44.       cmd->SetEnableFunction( Enabler );
  45.       cmd->SetUserData( 0 );
  46.  
  47.       cmd->AddRef();
  48.       _cmdServer->AddCommand( cmd, TRUE );  // ask for continuos query of the enabler
  49.       _startInitFailed = FALSE;
  50.       }
  51.     }
  52.   }
  53. //.............................................................................
  54. CmdTestA::~CmdTestA()
  55.   {
  56.   UnInit();
  57.   if ( _cmdServer )
  58.     {
  59.     _cmdServer->Release();
  60.     _cmdServer = NULL;
  61.     }
  62.   }
  63. //.............................................................................
  64. BOOL CmdTestA::Init()
  65.   {
  66.   if ( _startInitFailed )
  67.     {
  68.     OutStr( "CmdTestA was inited at startup but failed :-(" );
  69.     }
  70.   else
  71.     {
  72.     OutStr( "CmdTestA was inited at startup." );
  73.     OutStr( "...You should find our test bitmap in the available buttons list." );
  74.     }
  75.   return FALSE;
  76. }
  77. //.............................................................................
  78. void CmdTestA::UnInit()
  79.   {
  80.   OutStr( "CmdTestA::UnInit() is a no-op" );
  81.   }
  82. //.............................................................................
  83. const char * CmdTestA::GetName()
  84.   {
  85.   return "Command test";
  86.   }
  87. //.............................................................................
  88. const char * CmdTestA::GetTestDescription( int testNum )
  89.   {
  90.   switch ( testNum )
  91.     {
  92.     case 1:
  93.       return "Toggle command enable/disable";
  94.     }
  95.   return "This test not implemented.";
  96.   }
  97. //.............................................................................
  98. void CmdTestA::DoTest( int testNum )
  99.   {
  100.   if ( !_cmdServer )
  101.     {
  102.     OutStr( "Command Server not initialized!" );
  103.     return;
  104.     }
  105.   switch ( testNum )
  106.     {
  107.     case 1:
  108.       okToEnable = !okToEnable;
  109.       OutStr( FormatStr(
  110.             "our command is now %s.", okToEnable?
  111.             "enabled" : "disabled" ) );
  112.       break;
  113.     default:
  114.       {
  115.       OutStr( FormatStr( "Test #%d Not Implemented!", testNum ) );
  116.       }
  117.     }
  118.   }
  119.  
  120.  
  121. BOOL PASCAL Enabler() {
  122.   return okToEnable;
  123. }
  124.