home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / ADS / CPP / DDE / DDEMISC.H < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  12.7 KB  |  321 lines

  1. /* 
  2.     DDEMISC.H -
  3.     
  4.     This file:
  5.  
  6.         Has miscellaneous function declarations used in ADS 
  7.         DDE C++ classes.
  8.         
  9.  
  10.     (C) Copyright 1988-1994 by Autodesk, Inc.
  11.  
  12.     This program is copyrighted by Autodesk, Inc. and is  licensed
  13.     to you under the following conditions.  You may not distribute
  14.     or  publish the source code of this program in any form.   You
  15.     may  incorporate this code in object form in derivative  works
  16.     provided  such  derivative  works  are  (i.) are  designed and
  17.     intended  to  work  solely  with  Autodesk, Inc. products, and
  18.     (ii.)  contain  Autodesk's  copyright  notice  "(C)  Copyright
  19.     1988-1994 by Autodesk, Inc."
  20.  
  21.     AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  22.     AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  23.     CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  24.     DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  25.     UNINTERRUPTED OR ERROR FREE.
  26.  
  27. */
  28. #ifndef DDEMISC_H
  29. #define DDEMISC_H
  30.  
  31. #include "ddeinc.h"
  32.  
  33. //-----------------------------------------------------------------------------
  34. struct  DDETHIS_LOOKUP;
  35. struct  DDE_INSTANCE;
  36. struct  DDE_STRING_HANDLE;
  37. struct  DDE_HCONV;
  38.  
  39.  
  40. //-----------------------------------------------------------------------------
  41. #define MAX_ADS_INSTANCE      20
  42. #define POKE_BUFFER_SIZE    4*1024
  43. #define TAB                 '\t'
  44. #define NEW_LINE            '\n'
  45.  
  46.  
  47. /******************************************************************************
  48. *                                                                             *
  49. *                           DDETHIS_LOOKUP class                              *
  50. *                                                                             *
  51. ******************************************************************************/
  52. //-----------------------------------------------------------------------------
  53. typedef ADS_OBJ const*  ADS_OBJ_THIS;
  54. struct  ADS_THIS_LOOKUP
  55. {
  56.     HCONV               conv_id;
  57.     ADS_OBJ_THIS        ads_this;
  58. };
  59.  
  60. /******************************************************************************
  61. *                                                                             *
  62. *                           ADS_INSTANCE class                                 *
  63. *                                                                             *
  64. ******************************************************************************/
  65. //-----------------------------------------------------------------------------
  66. struct  ADS_INSTANCE
  67. {
  68.     int                 num_instance;
  69.     ADS_THIS_LOOKUP     ads_instances[ MAX_ADS_INSTANCE ];
  70.                         ADS_INSTANCE();
  71.     BOOL                RemoveInstanceIndex( int this_index );
  72.     BOOL                RemoveInstance( ADS_OBJ_THIS _this );
  73.     int                 GetNumInstances() { return num_instance; }
  74.     int                 AddInstanceIndex( ADS_OBJ_THIS new_this
  75.                                         , HCONV h_conv );
  76.     ADS_OBJ_THIS   This(HCONV _conv_id);
  77. };
  78.  
  79. //-----------------------------------------------------------------------------
  80. inline ADS_INSTANCE::ADS_INSTANCE()
  81.     num_instance = 0; 
  82.     for ( int i = 0; i < MAX_ADS_INSTANCE; i++ )
  83.     {
  84.         ads_instances[ i ].ads_this = NULL;
  85.         ads_instances[ i ].conv_id = 0;
  86.     }
  87. }
  88.  
  89. //-----------------------------------------------------------------------------
  90. inline BOOL ADS_INSTANCE::RemoveInstance( ADS_OBJ_THIS _this )
  91. {
  92.     for ( int i = 0; i < num_instance; i++ )
  93.     {
  94.         if ( ads_instances[ i ].ads_this == _this )
  95.         {
  96.             return RemoveInstanceIndex( i );
  97.         }
  98.     }
  99.     return FALSE;
  100. }
  101.  
  102. //-----------------------------------------------------------------------------
  103. inline BOOL ADS_INSTANCE::RemoveInstanceIndex( int this_index )
  104. {
  105.     if ( ads_instances[ this_index ].ads_this != NULL )
  106.     {
  107.         ads_instances[ this_index ].ads_this = NULL;
  108.         ads_instances[ this_index ].conv_id = 0;
  109.         num_instance--;
  110.         //
  111.         // Packing...
  112.         //
  113.         for ( int i = this_index
  114.             ; ( ads_instances[ i+1 ].ads_this != NULL ) && ( i+1 < MAX_ADS_INSTANCE )
  115.             ; i++ )
  116.         {
  117.             ads_instances[ i ].ads_this = ads_instances[ i+1 ].ads_this;
  118.             ads_instances[ i ].conv_id = ads_instances[ i+1 ].conv_id;
  119.             ads_instances[ i+1 ].ads_this = NULL;
  120.             ads_instances[ i+1 ].conv_id = 0;
  121.         }
  122.         return TRUE;
  123.     }
  124.     else
  125.     {
  126.         return FALSE;
  127.     }
  128. }
  129. //-----------------------------------------------------------------------------
  130. inline int ADS_INSTANCE::AddInstanceIndex( ADS_OBJ_THIS new_this
  131.                                         , HCONV h_conv )
  132. {
  133.     ASSERT ( new_this != NULL && h_conv != NULL && num_instance < MAX_ADS_INSTANCE );
  134.     
  135.     if ( num_instance < MAX_ADS_INSTANCE )
  136.     {
  137.         ads_instances[ num_instance ].ads_this = new_this;
  138.         ads_instances[ num_instance ].conv_id = h_conv;
  139.         num_instance++;
  140.         return num_instance;
  141.     }
  142.     return -1;
  143. }
  144. //-----------------------------------------------------------------------------
  145. inline ADS_OBJ_THIS ADS_INSTANCE::This(HCONV _conv_id)
  146.     ASSERT ( _conv_id != NULL );
  147.  
  148.     for ( int i = 0; i < num_instance; i++)
  149.     {
  150.         if ( _conv_id == ads_instances[ i ].conv_id )
  151.         {
  152.             ASSERT ( ads_instances[ i ].ads_this != NULL );
  153.             return ads_instances[ i ].ads_this;
  154.         }
  155.     }
  156.     return NULL;
  157. }
  158.  
  159.  
  160. /******************************************************************************
  161. *                                                                             *
  162. *                                 DDE_HCONV                                   *
  163. *                                                                             *
  164. ******************************************************************************/
  165. struct DDE_HCONV : ADS_OBJ
  166. {
  167.     HCONV           cur_conv;
  168.     DDE_CONNECTION  *conx;
  169.     SERVER_INFO     *server;
  170.                     
  171.                     DDE_HCONV( DDE_CONNECTION* _conx
  172.                             , SERVER_INFO *_server 
  173.                             , PCONVCONTEXT pcc );
  174.                     DDE_HCONV()
  175.                     { 
  176.                         cur_conv = NULL;
  177.                         conx = NULL;
  178.                         server = NULL; 
  179.                     }
  180.                     DDE_HCONV( const DDE_HCONV& src )
  181.                     {
  182.                         cur_conv = src.cur_conv;
  183.                         conx = src.conx;
  184.                         server = src.server;
  185.                     }
  186.  
  187.                     ~DDE_HCONV();
  188.  
  189.     BOOL            DisConnect();
  190.     HCONV           NewConv( DDE_CONNECTION *_conx
  191.                             , SERVER_INFO *_server 
  192.                             , PCONVCONTEXT pcc );
  193.     virtual BOOL    Valid() { return cur_conv != NULL; }
  194.                     operator HCONV( ){ return cur_conv; }
  195. };
  196.  
  197.  
  198. /******************************************************************************
  199. *                                                                             *
  200. *                            DDE_STRING_HANDLE                                *
  201. *                                                                             *
  202. ******************************************************************************/
  203. //-----------------------------------------------------------------------------
  204. struct      DDE_STRING_HANDLE : ADS_OBJ
  205. {
  206.     DDE_CONNECTION      *conx;
  207.     HSZ                 handle;
  208.     HSZ                 Handle() { return handle; }
  209.     ADS_STRING          string;
  210.     virtual HSZ         NewHandle( ADS_STRING& s );
  211.                         DDE_STRING_HANDLE( DDE_CONNECTION* _conx );
  212.     virtual             ~DDE_STRING_HANDLE();
  213.     BOOL                IsSameDDEString( char *_string );
  214.     BOOL                IsSameDDEString( ADS_STRING& _string );
  215.     virtual BOOL        Valid()
  216.                         {
  217.                             return ( conx && handle );
  218.                         }
  219.                         operator HSZ( ) { return handle; }
  220. private:
  221.     //
  222.     // No time to implement this...
  223.     //
  224.     DDE_STRING_HANDLE&  operator=( const DDE_STRING_HANDLE& );
  225.                         DDE_STRING_HANDLE( const DDE_STRING_HANDLE& );
  226. };
  227.  
  228. /******************************************************************************
  229. *                                                                             *
  230. *                              DDE_SERVICE                                    *
  231. *                                                                             *
  232. ******************************************************************************/
  233. struct DDE_SERVICE : DDE_STRING_HANDLE
  234. {
  235.                     DDE_SERVICE( DDE_CONNECTION *_conx )
  236.                     : DDE_STRING_HANDLE( _conx ) {}
  237.                                 operator HSZ( ) { return handle; }
  238. };
  239.  
  240. /******************************************************************************
  241. *                                                                             *
  242. *                               DDE_TOPIC                                     *
  243. *                                                                             *
  244. ******************************************************************************/
  245. struct DDE_TOPIC : DDE_STRING_HANDLE
  246. {
  247.                     DDE_TOPIC( DDE_CONNECTION *_conx ) 
  248.                     : DDE_STRING_HANDLE( _conx ) {}
  249.                                 operator HSZ( ) { return handle; }
  250. };
  251.  
  252. /******************************************************************************
  253. *                                                                             *
  254. *                               DDE_ITEM                                      *
  255. *                                                                             *
  256. *   DDE_ITEM is the abstract layer to represent the transfer item in a dde    *
  257. *   communication.  Since all dde communication transfers have different      *
  258. *   ways of building, reseting the item                                       *
  259. *                                                                             *
  260. ******************************************************************************/
  261. struct DDE_ITEM : DDE_STRING_HANDLE
  262. {
  263.     virtual void                Reset(){ string = ""; }
  264.     virtual HSZ                 Range(){ return Handle(); }
  265.     virtual HSZ                 ConstructDDEString( ADS_STRING& string );
  266.                                 DDE_ITEM( DDE_CONNECTION *_conx )
  267.                                 : DDE_STRING_HANDLE( _conx ) {}
  268.                                 operator HSZ( ) { return handle; }
  269. };
  270.  
  271. /******************************************************************************
  272. *                                                                             *
  273. *                           EXCEL_ITEM                                        *
  274. *                                                                             *
  275. *                                                                             *
  276. ******************************************************************************/
  277. struct EXCEL_ITEM : DDE_ITEM
  278. {
  279.     int                         max_range_row;
  280.     int                         max_range_col;
  281.     static ADS_STRING           init_string;
  282.  
  283.     virtual void                Reset(){}
  284.     HSZ                         hrange;
  285.     virtual HSZ                 Range();
  286.     ADS_STRING                  range_string;
  287.  
  288.     virtual HSZ                 ConstructDDEString( ADS_STRING& );
  289.                                 ~EXCEL_ITEM();
  290.                                 EXCEL_ITEM( DDE_CONNECTION *_conx )
  291.                                 : DDE_ITEM( _conx ) 
  292.                                 {
  293.                                     range_string = "";
  294.                                     hrange = 0;
  295.                                     max_range_row = 1;
  296.                                     max_range_col = 1;
  297.                                     NewHandle( init_string );
  298.                                 }
  299.                                 operator HSZ( ) { return handle; }
  300. };
  301.  
  302. //-----------------------------------------------------------------------------
  303. // inliners
  304. //-----------------------------------------------------------------------------
  305. inline BOOL DDE_STRING_HANDLE::IsSameDDEString( char *_string )
  306. {
  307.     return ( _string == string );
  308. }
  309.  
  310. //-----------------------------------------------------------------------------
  311. inline BOOL DDE_STRING_HANDLE::IsSameDDEString( ADS_STRING& _string )
  312. {
  313.     return ( _string == string );
  314. }
  315.  
  316.  
  317. #endif
  318.  
  319.