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

  1. /* 
  2.     DDEADS.CPP -
  3.     
  4.     This file:
  5.  
  6.         Declares DDE functions to simulate the DDEADS functions
  7.         in R12.  These functions are not fully implemented, they
  8.         are only used to show the usage of DDE classes.
  9.  
  10.         A fully implemented C version of DDEADS is provided.
  11.         This file is compiled as DDEADSPP.EXE.
  12.  
  13.     Function:
  14.  
  15.     (xload "ddeadspp")  
  16.     (ddedrawing) Poke current tables and entities to EXCEL.
  17.  
  18.  
  19.     (C) Copyright 1988-1994 by Autodesk, Inc.
  20.  
  21.     This program is copyrighted by Autodesk, Inc. and is  licensed
  22.     to you under the following conditions.  You may not distribute
  23.     or  publish the source code of this program in any form.   You
  24.     may  incorporate this code in object form in derivative  works
  25.     provided  such  derivative  works  are  (i.) are  designed and
  26.     intended  to  work  solely  with  Autodesk, Inc. products, and
  27.     (ii.)  contain  Autodesk's  copyright  notice  "(C)  Copyright
  28.     1988-1994 by Autodesk, Inc."
  29.  
  30.     AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  31.     AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  32.     CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  33.     DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  34.     UNINTERRUPTED OR ERROR FREE.
  35.  
  36. */
  37. #include    "ddeads.h"
  38.  
  39. //-----------------------------------------------------------------------------
  40. ADS_FUNC_INFO       app_funs[] = 
  41. {
  42. /*                                                                    */
  43. /*      Function                               Type            Name   */
  44. /*                                                                    */
  45.   ADS_FUNC_INFO( ADS_FUNC( fddedlgstart ),   ADS_VOID_FUNC,  "DDEDLGSTART"   )
  46. , ADS_FUNC_INFO( ADS_FUNC( fddedialog ),     ADS_VOID_FUNC,  "DDEDIALOG"     )
  47. , ADS_FUNC_INFO( ADS_FUNC( fddedrawing ),    ADS_INT_FUNC,   "DDEDRAWING"    )
  48. , ADS_FUNC_INFO( ADS_FUNC( fddeblocks ),     ADS_INT_FUNC,   "DDEBLOCKS"     )
  49. , ADS_FUNC_INFO( ADS_FUNC( fddesset ),       ADS_INT_FUNC,   "DDESSET"       )
  50. , ADS_FUNC_INFO( ADS_FUNC( fddeupdate ),     ADS_INT_FUNC,   "DDEUPDATE"     )
  51. , ADS_FUNC_INFO( ADS_FUNC( fddeformat ),     ADS_INT_FUNC,   "DDEFORMAT"     )
  52. , ADS_FUNC_INFO( ADS_FUNC( fddedefaults ),   ADS_INT_FUNC,   "DDEDEFAULTS"   )
  53. , ADS_FUNC_INFO( ADS_FUNC( doddetransfer ),  ADS_INT_FUNC,   "ACADDDEFUN"    )
  54. };
  55.  
  56. /******************************************************************************
  57. *                                                                             *
  58. *                        DDEADS_APP member functions                          *
  59. *                                                                             *
  60. ******************************************************************************/
  61. //-----------------------------------------------------------------------------
  62. //
  63. // return TRUE if any of the entities changed
  64. //
  65. BOOL DDEADS_APP::ImportDrawing()
  66. {
  67.     ads_name    ename;
  68.     int         total_ent = 0;
  69.     BOOL        ret_val = FALSE;
  70.  
  71.     if ( !CurChannel() )
  72.     {
  73.         return FALSE;
  74.     }
  75.     //
  76.     // Entities
  77.     //
  78.     if ( ads_entnext( NULL, ename ) != RTERROR )
  79.     {
  80.         ads_printf( "\nCheck Ads entity #: " );
  81.         ShowLife();
  82.         do
  83.         {
  84.             total_ent++;
  85.             struct resbuf *rb;
  86.             rb = ads_entget( ename );
  87.             if ( ShowLife( total_ent ) )
  88.             {
  89.                 if ( CurChannel()->ModifyDDEEntity( rb ) > 0 )
  90.                 {
  91.                     ret_val = TRUE;
  92.                 }
  93.             }
  94.             ads_relrb( rb );
  95.         }
  96.         while ( UserBrk() == FALSE && ads_entnext( ename, ename ) != RTERROR );
  97.     }
  98.     ads_printf( "\nDone!\n");
  99.     return ret_val;
  100. }
  101.  
  102. //-----------------------------------------------------------------------------
  103. BOOL DDEADS_APP::StartHotLink()
  104. {
  105.     return CurChannel()->Link();
  106. }
  107.  
  108. //-----------------------------------------------------------------------------
  109. int DDEADS_APP::ExportDrawing()
  110. {
  111.     if ( !CurChannel() )
  112.     {
  113.         DDE_CLIENT_CONNECTION *conx;// = DDE_GLOBAL::excel_connection;
  114.         conx = new EXCEL_CLIENT_CONNECTION ( *( DDE_GLOBAL::excel_server_info ) );
  115.         AddChannel( conx );
  116.  
  117.         DDE_CLIENT_CONNECTION *cur = CurChannel();
  118.  
  119.         cur->Init( ADS_STRING( "Excel" )
  120.                     , ADS_STRING( "Sheet1" )
  121.                     , ADS_STRING( "R1C1" ) );
  122.         cur->SetupConnection();
  123.     }
  124.     if ( CurChannel()->BeginSend() == TRUE )
  125.     {
  126.         int  total_ent = 0;
  127.         char temp_buf[ 256 ];
  128.  
  129.         ads_printf( "\nSend Ads tables to spread sheet\n" );
  130.         int total_table = CurChannel()->SendAdsAllTables();
  131.         wsprintf( temp_buf, "\nDone, number of tables sent: %d", total_table );
  132.         ads_printf( temp_buf );
  133.     
  134.         ads_printf( "\nSend Ads entities to Spread sheet\n" );
  135.         total_ent = CurChannel()->SendAdsAllEntities();
  136.         ads_printf( "\nDone, number of entities sent: " );
  137.     
  138.         CurChannel()->EndSend();
  139.         return total_ent;
  140.     }
  141.     else
  142.     {
  143.         return -1;
  144.     }
  145. }
  146.  
  147. //-----------------------------------------------------------------------------
  148. DDEADS_APP::DDEADS_APP( int argc, char **argv ) 
  149.                     : ADS_APP( argc, argv )
  150. {
  151.     for ( int i = 0; i < ARRAY_SIZE( app_funs ); i++ )
  152.     {
  153.         if ( InsertExternFunc( app_funs[i] ) == -1 )
  154.         {
  155.             return;
  156.         }
  157.     }
  158. }
  159.  
  160.  
  161. /******************************************************************************
  162. *                                                                             *
  163. *                        DDEADS exported "C" functions                        *
  164. *                                                                             *
  165. ******************************************************************************/
  166. //----------------------------------------------------------------------------
  167. int     doddetransfer( struct resbuf * )
  168. {
  169.     ads_printf( "doddetranfer called\n" );
  170.     DDEADS_APP  *app = ( DDEADS_APP* )GetAdsApp();
  171.  
  172.     app->ImportDrawing();
  173.  
  174.     return 0;
  175. }
  176.  
  177. //-----------------------------------------------------------------------------
  178. void fddedlgstart( struct resbuf * )
  179. {
  180.     ads_printf( "fddedlgstart called" );
  181. }
  182.  
  183. //-----------------------------------------------------------------------------
  184. void fddedialog( struct resbuf * )
  185. {
  186.     ads_printf( "fddedialog called" );
  187. }
  188.  
  189. //-----------------------------------------------------------------------------
  190. int fddeblocks( struct resbuf * )
  191. {
  192.     ads_printf( "fddeblocks called" );
  193.     return 1;
  194. }
  195.  
  196. //-----------------------------------------------------------------------------
  197. int fddesset( struct resbuf * )
  198. {
  199.     ads_printf( "fddesset called" );
  200.     return 1;
  201. }
  202.  
  203. //-----------------------------------------------------------------------------
  204. int fddeupdate( struct resbuf * )
  205. {
  206.     ads_printf( "fddeupdate called" );
  207.     return 1;
  208. }
  209.  
  210. //-----------------------------------------------------------------------------
  211. int fddeformat( struct resbuf * )
  212. {
  213.     ads_printf( "fddeformat called" );
  214.     return 1;
  215. }
  216.  
  217. //-----------------------------------------------------------------------------
  218. int fddedefaults( struct resbuf * )
  219. {
  220.     ads_printf( "fddedefaults called" );
  221.     return 1;
  222. }
  223.  
  224. //-----------------------------------------------------------------------------
  225. int fddedrawing( struct resbuf * )
  226. {
  227.     int total_ent = 0;
  228.  
  229.     DDEADS_APP  *app = ( DDEADS_APP* )GetAdsApp();
  230.     if ( total_ent = app->ExportDrawing() )
  231.     {
  232.         app->StartHotLink();
  233.     }
  234.     return total_ent;
  235. }
  236.  
  237. /******************************************************************************
  238. *                                                                             *
  239. *                                 CHANNELS                                    *
  240. *                                                                             *
  241. ******************************************************************************/
  242. //-----------------------------------------------------------------------------
  243. int CHANNELS::Add( DDE_CLIENT_CONNECTION* new_connx )
  244. {
  245.     CLIENT_CHANNEL* new_chnl = new CLIENT_CHANNEL( new_connx );
  246.     
  247.     if ( tail )
  248.     {
  249.         tail->next = new_chnl;
  250.         tail = new_chnl;
  251.         new_chnl = NULL;
  252.     }
  253.     else// first one
  254.     {
  255.         tail = new_chnl;
  256.         head = tail;
  257.         current = head;
  258.     }
  259.     return ++count;
  260. }
  261.  
  262. //-----------------------------------------------------------------------------
  263. int CHANNELS::Remove( int chnl )
  264. {
  265.     ASSERT( head != NULL );
  266.  
  267.     if ( count == 1 )
  268.     {
  269.         delete head;
  270.         head = tail = current = NULL;
  271.         return 1;
  272.     }
  273.  
  274.     CLIENT_CHANNEL *chnl_before= head;
  275.     for ( int i = 0; i < chnl - 1; i++ ) // go to the one before
  276.     {
  277.         ASSERT( i < count );
  278.         chnl_before = chnl_before->next;
  279.     }
  280.     CLIENT_CHANNEL *target_chnl = chnl_before->next;
  281.     if ( target_chnl == current )
  282.     {
  283.         current = head;
  284.     }
  285.     chnl_before->next = chnl_before->next->next;
  286.     delete target_chnl;
  287.     return --count;
  288. }
  289.  
  290. /******************************************************************************
  291. *                                                                             *
  292. *                        ADS main entry point                                 *
  293. *                                                                             *
  294. ******************************************************************************/
  295. //-----------------------------------------------------------------------------
  296. void main( int argc, char **argv )
  297. {
  298.     main_app = new DDEADS_APP( argc, argv );
  299.     if ( main_app->Valid() )
  300.     {
  301.         main_app->Run();
  302.     }
  303.     delete main_app;
  304.     main_app = NULL;
  305. }
  306.